net/xfrm/xfrm_device.c
Source file repositories/reference/linux-study-clean/net/xfrm/xfrm_device.c
File Facts
- System
- Linux kernel
- Corpus path
net/xfrm/xfrm_device.c- Extension
.c- Size
- 14301 bytes
- Lines
- 583
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/errno.hlinux/module.hlinux/netdevice.hlinux/skbuff.hlinux/slab.hlinux/spinlock.hnet/dst.hnet/gso.hnet/xfrm.hlinux/notifier.h
Detected Declarations
function Copyrightfunction __xfrm_mode_tunnel_prepfunction __xfrm_mode_beet_prepfunction xfrm_outer_mode_prepfunction xmit_xfrm_check_overflowfunction skb_list_walk_safefunction xfrm_dev_state_addfunction xfrm_dev_policy_addfunction xfrm_dev_offload_okfunction xfrm_dev_resumefunction xfrm_dev_backlogfunction xfrm_api_checkfunction xfrm_dev_downfunction xfrm_dev_unregisterfunction xfrm_dev_eventfunction xfrm_dev_initexport validate_xmit_xfrmexport xfrm_dev_state_addexport xfrm_dev_policy_addexport xfrm_dev_offload_okexport xfrm_dev_resume
Annotated Snippet
unlikely(xmit_xfrm_check_overflow(skb)))) {
struct sk_buff *segs;
/* Packet got rerouted, fixup features and segment it. */
esp_features = esp_features & ~(NETIF_F_HW_ESP | NETIF_F_GSO_ESP);
segs = skb_gso_segment(skb, esp_features);
if (IS_ERR(segs)) {
kfree_skb(skb);
dev_core_stats_tx_dropped_inc(dev);
return NULL;
} else {
consume_skb(skb);
skb = segs;
}
}
if (!skb->next) {
esp_features |= skb->dev->gso_partial_features;
xfrm_outer_mode_prep(x, skb);
xo->flags |= XFRM_DEV_RESUME;
err = x->type_offload->xmit(x, skb, esp_features);
if (err) {
if (err == -EINPROGRESS)
return NULL;
XFRM_INC_STATS(xs_net(x), LINUX_MIB_XFRMOUTSTATEPROTOERROR);
kfree_skb(skb);
return NULL;
}
skb_push(skb, skb->data - skb_mac_header(skb));
return skb;
}
skb_list_walk_safe(skb, skb2, nskb) {
esp_features |= skb->dev->gso_partial_features;
skb_mark_not_on_list(skb2);
xo = xfrm_offload(skb2);
xo->flags |= XFRM_DEV_RESUME;
xfrm_outer_mode_prep(x, skb2);
err = x->type_offload->xmit(x, skb2, esp_features);
if (!err) {
skb2->next = nskb;
} else if (err != -EINPROGRESS) {
XFRM_INC_STATS(xs_net(x), LINUX_MIB_XFRMOUTSTATEPROTOERROR);
skb2->next = nskb;
kfree_skb_list(skb2);
return NULL;
} else {
if (skb == skb2)
skb = nskb;
else
pskb->next = nskb;
continue;
}
skb_push(skb2, skb2->data - skb_mac_header(skb2));
pskb = skb2;
}
return skb;
}
EXPORT_SYMBOL_GPL(validate_xmit_xfrm);
int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
const struct xfrm_user_offload *xuo,
struct netlink_ext_ack *extack)
{
int err;
struct dst_entry *dst;
struct net_device *dev;
struct xfrm_dev_offload *xso = &x->xso;
xfrm_address_t *saddr;
xfrm_address_t *daddr;
bool is_packet_offload;
if (xuo->flags &
~(XFRM_OFFLOAD_IPV6 | XFRM_OFFLOAD_INBOUND | XFRM_OFFLOAD_PACKET)) {
NL_SET_ERR_MSG(extack, "Unrecognized flags in offload request");
return -EINVAL;
}
Annotation
- Immediate include surface: `linux/errno.h`, `linux/module.h`, `linux/netdevice.h`, `linux/skbuff.h`, `linux/slab.h`, `linux/spinlock.h`, `net/dst.h`, `net/gso.h`.
- Detected declarations: `function Copyright`, `function __xfrm_mode_tunnel_prep`, `function __xfrm_mode_beet_prep`, `function xfrm_outer_mode_prep`, `function xmit_xfrm_check_overflow`, `function skb_list_walk_safe`, `function xfrm_dev_state_add`, `function xfrm_dev_policy_add`, `function xfrm_dev_offload_ok`, `function xfrm_dev_resume`.
- 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.