Skip to content

Commit 17163f2

Browse files
Florian Westphalklassert
authored andcommitted
xfrm: minor update to sdb and xfrm_policy comments
The spd is no longer maintained as a linear list. We also haven't been caching bundles in the xfrm_policy struct since 2010. While at it, add kdoc style comments for the xfrm_policy structure and extend the description of the current rbtree based search to mention why it needs to search the candidate set. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 08c2182 commit 17163f2

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

include/net/xfrm.h

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@
6767
- instance of a transformer, struct xfrm_state (=SA)
6868
- template to clone xfrm_state, struct xfrm_tmpl
6969
70-
SPD is plain linear list of xfrm_policy rules, ordered by priority.
70+
SPD is organized as hash table (for policies that meet minimum address prefix
71+
length setting, net->xfrm.policy_hthresh). Other policies are stored in
72+
lists, sorted into rbtree ordered by destination and source address networks.
73+
See net/xfrm/xfrm_policy.c for details.
74+
7175
(To be compatible with existing pfkeyv2 implementations,
7276
many rules with priority of 0x7fffffff are allowed to exist and
7377
such rules are ordered in an unpredictable way, thanks to bsd folks.)
7478
75-
Lookup is plain linear search until the first match with selector.
76-
7779
If "action" is "block", then we prohibit the flow, otherwise:
7880
if "xfrms_nr" is zero, the flow passes untransformed. Otherwise,
7981
policy entry has list of up to XFRM_MAX_DEPTH transformations,
@@ -86,8 +88,6 @@
8688
|---. child .-> dst -. xfrm .-> xfrm_state #3
8789
|---. child .-> NULL
8890
89-
Bundles are cached at xrfm_policy struct (field ->bundles).
90-
9191
9292
Resolution of xrfm_tmpl
9393
-----------------------
@@ -526,6 +526,36 @@ struct xfrm_policy_queue {
526526
unsigned long timeout;
527527
};
528528

529+
/**
530+
* struct xfrm_policy - xfrm policy
531+
* @xp_net: network namespace the policy lives in
532+
* @bydst: hlist node for SPD hash table or rbtree list
533+
* @byidx: hlist node for index hash table
534+
* @lock: serialize changes to policy structure members
535+
* @refcnt: reference count, freed once it reaches 0
536+
* @pos: kernel internal tie-breaker to determine age of policy
537+
* @timer: timer
538+
* @genid: generation, used to invalidate old policies
539+
* @priority: priority, set by userspace
540+
* @index: policy index (autogenerated)
541+
* @if_id: virtual xfrm interface id
542+
* @mark: packet mark
543+
* @selector: selector
544+
* @lft: liftime configuration data
545+
* @curlft: liftime state
546+
* @walk: list head on pernet policy list
547+
* @polq: queue to hold packets while aqcuire operaion in progress
548+
* @bydst_reinsert: policy tree node needs to be merged
549+
* @type: XFRM_POLICY_TYPE_MAIN or _SUB
550+
* @action: XFRM_POLICY_ALLOW or _BLOCK
551+
* @flags: XFRM_POLICY_LOCALOK, XFRM_POLICY_ICMP
552+
* @xfrm_nr: number of used templates in @xfrm_vec
553+
* @family: protocol family
554+
* @security: SELinux security label
555+
* @xfrm_vec: array of templates to resolve state
556+
* @rcu: rcu head, used to defer memory release
557+
* @xdo: hardware offload state
558+
*/
529559
struct xfrm_policy {
530560
possible_net_t xp_net;
531561
struct hlist_node bydst;

net/xfrm/xfrm_policy.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ struct xfrm_pol_inexact_node {
109109
* 4. saddr:any list from saddr tree
110110
*
111111
* This result set then needs to be searched for the policy with
112-
* the lowest priority. If two results have same prio, youngest one wins.
112+
* the lowest priority. If two candidates have the same priority, the
113+
* struct xfrm_policy pos member with the lower number is used.
114+
*
115+
* This replicates previous single-list-search algorithm which would
116+
* return first matching policy in the (ordered-by-priority) list.
113117
*/
114118

115119
struct xfrm_pol_inexact_key {

0 commit comments

Comments
 (0)