net/xfrm/xfrm_state.c
Source file repositories/reference/linux-study-clean/net/xfrm/xfrm_state.c
File Facts
- System
- Linux kernel
- Corpus path
net/xfrm/xfrm_state.c- Extension
.c- Size
- 88509 bytes
- Lines
- 3559
- 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/compat.hlinux/workqueue.hnet/xfrm.hlinux/pfkeyv2.hlinux/ipsec.hlinux/module.hlinux/cache.hlinux/audit.hlinux/uaccess.hlinux/ktime.hlinux/slab.hlinux/interrupt.hlinux/kernel.hcrypto/aead.hxfrm_hash.h
Detected Declarations
struct xfrm_hash_state_ptrsfunction xfrm_state_hold_rcufunction xfrm_dst_hashfunction xfrm_src_hashfunction xfrm_spi_hashfunction xfrm_seq_hashfunction xfrm_hash_transferfunction hlist_for_each_entry_safefunction xfrm_hash_new_sizefunction xfrm_hash_resizefunction xfrm_register_typefunction xfrm_unregister_typefunction xfrm_put_typefunction xfrm_register_type_offloadfunction xfrm_unregister_type_offloadfunction xfrm_set_type_offloadfunction xfrm_register_mode_cbsfunction xfrm_unregister_mode_cbsfunction xfrm_state_freefunction xfrm_state_gc_destroyfunction xfrm_state_gc_taskfunction xfrm_timer_handlerfunction xfrm_dev_state_deletefunction xfrm_dev_state_freefunction __xfrm_state_destroyfunction __xfrm_state_deletefunction xfrm_state_deletefunction xfrm_state_flush_secctx_checkfunction hlist_for_each_entryfunction xfrm_dev_state_flush_secctx_checkfunction hlist_for_each_entryfunction xfrm_state_flush_secctx_checkfunction xfrm_dev_state_flush_secctx_checkfunction xfrm_state_flushfunction hlist_for_each_entryfunction xfrm_dev_state_flushfunction hlist_for_each_entryfunction xfrm_sad_getinfofunction __xfrm4_init_tempselfunction __xfrm6_init_tempselfunction xfrm_init_tempstatefunction xfrm_hash_ptrs_getfunction hlist_for_each_entry_rcufunction hlist_for_each_entry_rcufunction hlist_for_each_entry_rcufunction __xfrm_state_locatefunction xfrm_hash_grow_checkfunction xfrm_state_look_at
Annotated Snippet
struct xfrm_hash_state_ptrs {
const struct hlist_head *bydst;
const struct hlist_head *bysrc;
const struct hlist_head *byspi;
unsigned int hmask;
};
static void xfrm_hash_ptrs_get(const struct net *net, struct xfrm_hash_state_ptrs *ptrs)
{
unsigned int sequence;
do {
sequence = read_seqcount_begin(&net->xfrm.xfrm_state_hash_generation);
ptrs->bydst = xfrm_state_deref_check(net->xfrm.state_bydst, net);
ptrs->bysrc = xfrm_state_deref_check(net->xfrm.state_bysrc, net);
ptrs->byspi = xfrm_state_deref_check(net->xfrm.state_byspi, net);
ptrs->hmask = net->xfrm.state_hmask;
} while (read_seqcount_retry(&net->xfrm.xfrm_state_hash_generation, sequence));
}
static struct xfrm_state *__xfrm_state_lookup_all(const struct xfrm_hash_state_ptrs *state_ptrs,
u32 mark,
const xfrm_address_t *daddr,
__be32 spi, u8 proto,
unsigned short family,
struct xfrm_dev_offload *xdo)
{
unsigned int h = __xfrm_spi_hash(daddr, spi, proto, family, state_ptrs->hmask);
struct xfrm_state *x;
hlist_for_each_entry_rcu(x, state_ptrs->byspi + h, byspi) {
#ifdef CONFIG_XFRM_OFFLOAD
if (xdo->type == XFRM_DEV_OFFLOAD_PACKET) {
if (x->xso.type != XFRM_DEV_OFFLOAD_PACKET)
/* HW states are in the head of list, there is
* no need to iterate further.
*/
break;
/* Packet offload: both policy and SA should
* have same device.
*/
if (xdo->dev != x->xso.dev)
continue;
} else if (x->xso.type == XFRM_DEV_OFFLOAD_PACKET)
/* Skip HW policy for SW lookups */
continue;
#endif
if (x->props.family != family ||
x->id.spi != spi ||
x->id.proto != proto ||
!xfrm_addr_equal(&x->id.daddr, daddr, family))
continue;
if ((mark & x->mark.m) != x->mark.v)
continue;
if (!xfrm_state_hold_rcu(x))
continue;
return x;
}
return NULL;
}
static struct xfrm_state *__xfrm_state_lookup(const struct xfrm_hash_state_ptrs *state_ptrs,
u32 mark,
const xfrm_address_t *daddr,
__be32 spi, u8 proto,
unsigned short family)
{
unsigned int h = __xfrm_spi_hash(daddr, spi, proto, family, state_ptrs->hmask);
struct xfrm_state *x;
hlist_for_each_entry_rcu(x, state_ptrs->byspi + h, byspi) {
if (x->props.family != family ||
x->id.spi != spi ||
x->id.proto != proto ||
!xfrm_addr_equal(&x->id.daddr, daddr, family))
continue;
if ((mark & x->mark.m) != x->mark.v)
continue;
if (!xfrm_state_hold_rcu(x))
continue;
return x;
}
return NULL;
}
Annotation
- Immediate include surface: `linux/compat.h`, `linux/workqueue.h`, `net/xfrm.h`, `linux/pfkeyv2.h`, `linux/ipsec.h`, `linux/module.h`, `linux/cache.h`, `linux/audit.h`.
- Detected declarations: `struct xfrm_hash_state_ptrs`, `function xfrm_state_hold_rcu`, `function xfrm_dst_hash`, `function xfrm_src_hash`, `function xfrm_spi_hash`, `function xfrm_seq_hash`, `function xfrm_hash_transfer`, `function hlist_for_each_entry_safe`, `function xfrm_hash_new_size`, `function xfrm_hash_resize`.
- 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.