Skip to content

Commit 24969fa

Browse files
Florian Westphalklassert
authored andcommitted
xfrm: policy: store inexact policies in an rhashtable
Switch packet-path lookups for inexact policies to rhashtable. In this initial version, we now no longer need to search policies with non-matching address family and type. Next patch will add the if_id as well so lookups from the xfrm interface driver only need to search inexact policies for that device. Future patches will augment the hlist in each rhash bucket with a tree and pre-sort policies according to daddr/prefix. A single rhashtable is used. In order to avoid a full rhashtable walk on netns exit, the bins get placed on a pernet list, i.e. we add almost no cost for network namespaces that had no xfrm policies. The inexact lists are kept in place, and policies are added to both the per-rhash-inexact list and a pernet one. The latter is needed for the control plane to handle migrate -- these requests do not consider the if_id, so if we'd remove the inexact_list now we would have to search all hash buckets and then figure out which matching policy candidate is the most recent one -- this appears a bit harder than just keeping the 'old' inexact list for this purpose. Signed-off-by: Florian Westphal <[email protected]> Acked-by: David S. Miller <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent cc1bb84 commit 24969fa

File tree

3 files changed

+335
-18
lines changed

3 files changed

+335
-18
lines changed

include/net/netns/xfrm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/list.h>
66
#include <linux/wait.h>
77
#include <linux/workqueue.h>
8+
#include <linux/rhashtable-types.h>
89
#include <linux/xfrm.h>
910
#include <net/dst_ops.h>
1011

@@ -53,6 +54,7 @@ struct netns_xfrm {
5354
unsigned int policy_count[XFRM_POLICY_MAX * 2];
5455
struct work_struct policy_hash_work;
5556
struct xfrm_policy_hthresh policy_hthresh;
57+
struct list_head inexact_bins;
5658

5759

5860
struct sock *nlsk;

include/net/xfrm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ struct xfrm_policy {
596596
u16 family;
597597
struct xfrm_sec_ctx *security;
598598
struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH];
599+
struct hlist_node bydst_inexact_list;
599600
struct rcu_head rcu;
600601
};
601602

0 commit comments

Comments
 (0)