net/xfrm/xfrm_policy.c
Source file repositories/reference/linux-study-clean/net/xfrm/xfrm_policy.c
File Facts
- System
- Linux kernel
- Corpus path
net/xfrm/xfrm_policy.c- Extension
.c- Size
- 115575 bytes
- Lines
- 4737
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/err.hlinux/slab.hlinux/kmod.hlinux/list.hlinux/spinlock.hlinux/workqueue.hlinux/notifier.hlinux/netdevice.hlinux/netfilter.hlinux/module.hlinux/cache.hlinux/cpu.hlinux/audit.hlinux/rhashtable.hlinux/if_tunnel.hlinux/icmp.hnet/dst.hnet/flow.hnet/inet_ecn.hnet/xfrm.hnet/ip.hnet/gre.hnet/mip6.hnet/snmp.hnet/espintcp.hnet/inet_dscp.hxfrm_hash.h
Detected Declarations
struct xfrm_flostruct xfrm_pol_inexact_nodestruct xfrm_pol_inexact_keystruct xfrm_pol_inexact_binstruct xfrm_pol_inexact_candidatesstruct xfrm_flow_keysenum xfrm_pol_inexact_candidate_typefunction xfrm_pol_hold_rcufunction __xfrm4_selector_matchfunction __xfrm6_selector_matchfunction xfrm_selector_matchfunction make_jiffiesfunction xfrm_policy_timerfunction xfrm_policy_destroy_rcufunction xfrm_policy_destroyfunction xfrm_policy_killfunction idx_hashfunction __get_hash_threshfunction xfrm_dst_hash_transferfunction xfrm_idx_hash_transferfunction hlist_for_each_entry_safefunction xfrm_new_hash_maskfunction xfrm_bydst_resizefunction xfrm_byidx_resizefunction xfrm_bydst_should_resizefunction xfrm_byidx_should_resizefunction xfrm_spd_getinfofunction xfrm_hash_resizefunction xfrm_policy_inexact_alloc_binfunction xfrm_pol_inexact_addr_use_any_listfunction xfrm_policy_inexact_insert_use_any_listfunction xfrm_pol_inexact_node_initfunction xfrm_pol_inexact_node_allocfunction xfrm_policy_addr_deltafunction xfrm_policy_inexact_list_reinsertfunction list_for_each_entry_reversefunction hlist_for_each_entryfunction xfrm_policy_inexact_node_reinsertfunction hlist_for_each_entryfunction xfrm_policy_inexact_node_mergefunction hlist_for_each_entryfunction xfrm_policy_inexact_insert_nodefunction xfrm_policy_inexact_gc_treefunction __xfrm_policy_inexact_prune_binfunction __xfrm_policy_inexact_flushfunction xfrm_policy_inexact_alloc_chainfunction xfrm_policy_inexact_insertfunction xfrm_policy_is_dead_or_sk
Annotated Snippet
struct xfrm_flo {
struct dst_entry *dst_orig;
u8 flags;
};
/* prefixes smaller than this are stored in lists, not trees. */
#define INEXACT_PREFIXLEN_IPV4 16
#define INEXACT_PREFIXLEN_IPV6 48
struct xfrm_pol_inexact_node {
struct rb_node node;
union {
xfrm_address_t addr;
struct rcu_head rcu;
};
u8 prefixlen;
struct rb_root root;
/* the policies matching this node, can be empty list */
struct hlist_head hhead;
};
/* xfrm inexact policy search tree:
* xfrm_pol_inexact_bin = hash(dir,type,family,if_id);
* |
* +---- root_d: sorted by daddr:prefix
* | |
* | xfrm_pol_inexact_node
* | |
* | +- root: sorted by saddr/prefix
* | | |
* | | xfrm_pol_inexact_node
* | | |
* | | + root: unused
* | | |
* | | + hhead: saddr:daddr policies
* | |
* | +- coarse policies and all any:daddr policies
* |
* +---- root_s: sorted by saddr:prefix
* | |
* | xfrm_pol_inexact_node
* | |
* | + root: unused
* | |
* | + hhead: saddr:any policies
* |
* +---- coarse policies and all any:any policies
*
* Lookups return four candidate lists:
* 1. any:any list from top-level xfrm_pol_inexact_bin
* 2. any:daddr list from daddr tree
* 3. saddr:daddr list from 2nd level daddr tree
* 4. saddr:any list from saddr tree
*
* This result set then needs to be searched for the policy with
* the lowest priority. If two candidates have the same priority, the
* struct xfrm_policy pos member with the lower number is used.
*
* This replicates previous single-list-search algorithm which would
* return first matching policy in the (ordered-by-priority) list.
*/
struct xfrm_pol_inexact_key {
possible_net_t net;
u32 if_id;
u16 family;
u8 dir, type;
};
struct xfrm_pol_inexact_bin {
struct xfrm_pol_inexact_key k;
struct rhash_head head;
/* list containing '*:*' policies */
struct hlist_head hhead;
seqcount_spinlock_t count;
/* tree sorted by daddr/prefix */
struct rb_root root_d;
/* tree sorted by saddr/prefix */
struct rb_root root_s;
/* slow path below */
struct list_head inexact_bins;
struct rcu_head rcu;
};
enum xfrm_pol_inexact_candidate_type {
Annotation
- Immediate include surface: `linux/err.h`, `linux/slab.h`, `linux/kmod.h`, `linux/list.h`, `linux/spinlock.h`, `linux/workqueue.h`, `linux/notifier.h`, `linux/netdevice.h`.
- Detected declarations: `struct xfrm_flo`, `struct xfrm_pol_inexact_node`, `struct xfrm_pol_inexact_key`, `struct xfrm_pol_inexact_bin`, `struct xfrm_pol_inexact_candidates`, `struct xfrm_flow_keys`, `enum xfrm_pol_inexact_candidate_type`, `function xfrm_pol_hold_rcu`, `function __xfrm4_selector_match`, `function __xfrm6_selector_match`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.