net/xfrm/xfrm_output.c
Source file repositories/reference/linux-study-clean/net/xfrm/xfrm_output.c
File Facts
- System
- Linux kernel
- Corpus path
net/xfrm/xfrm_output.c- Extension
.c- Size
- 23481 bytes
- Lines
- 974
- 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/netfilter.hlinux/skbuff.hlinux/slab.hlinux/spinlock.hnet/dst.hnet/gso.hnet/icmp.hnet/inet_ecn.hnet/xfrm.hnet/ip6_route.hxfrm_inout.h
Detected Declarations
function xfrm_skb_check_spacefunction xfrm4_transport_outputfunction mip6_rthdr_offsetfunction xfrm6_hdr_offsetfunction xfrm6_transport_outputfunction xfrm6_ro_outputfunction xfrm4_beet_encap_addfunction xfrm4_tunnel_encap_addfunction xfrm6_tunnel_encap_addfunction xfrm6_beet_encap_addfunction nextheaderfunction xfrm6_prepare_outputfunction xfrm_outer_mode_outputfunction pktgen_xfrm_outer_mode_outputfunction xfrm_output_onefunction xfrm_output_resumefunction xfrm_dev_direct_outputfunction xfrm_output2function xfrm_output_gsofunction skb_list_walk_safefunction xfrm_get_inner_ipprotofunction xfrm_outputfunction xfrm4_tunnel_check_sizefunction xfrm4_extract_outputfunction xfrm6_tunnel_check_sizefunction xfrm6_extract_outputfunction xfrm_inner_extract_outputfunction xfrm_local_errorexport pktgen_xfrm_outer_mode_outputexport xfrm_output_resumeexport xfrm_outputexport xfrm4_tunnel_check_sizeexport xfrm6_tunnel_check_sizeexport xfrm_local_error
Annotated Snippet
switch (**nexthdr) {
case NEXTHDR_HOP:
break;
case NEXTHDR_ROUTING:
if (type == IPPROTO_ROUTING && offset + 3 <= packet_len) {
struct ipv6_rt_hdr *rt;
rt = (struct ipv6_rt_hdr *)(nh + offset);
if (rt->type != 0)
return offset;
}
found_rhdr = 1;
break;
case NEXTHDR_DEST:
/* HAO MUST NOT appear more than once.
* XXX: It is better to try to find by the end of
* XXX: packet if HAO exists.
*/
if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0) {
net_dbg_ratelimited("mip6: hao exists already, override\n");
return offset;
}
if (found_rhdr)
return offset;
break;
default:
return offset;
}
if (offset + sizeof(struct ipv6_opt_hdr) > packet_len)
return -EINVAL;
exthdr = (struct ipv6_opt_hdr *)(skb_network_header(skb) +
offset);
offset += ipv6_optlen(exthdr);
if (offset > IPV6_MAXPLEN)
return -EINVAL;
*nexthdr = &exthdr->nexthdr;
}
return -EINVAL;
}
#endif
#if IS_ENABLED(CONFIG_IPV6)
static int xfrm6_hdr_offset(struct xfrm_state *x, struct sk_buff *skb, u8 **prevhdr)
{
switch (x->type->proto) {
#if IS_ENABLED(CONFIG_IPV6_MIP6)
case IPPROTO_DSTOPTS:
case IPPROTO_ROUTING:
return mip6_rthdr_offset(skb, prevhdr, x->type->proto);
#endif
default:
break;
}
return ip6_find_1stfragopt(skb, prevhdr);
}
#endif
/* Add encapsulation header.
*
* The IP header and mutable extension headers will be moved forward to make
* space for the encapsulation header.
*/
static int xfrm6_transport_output(struct xfrm_state *x, struct sk_buff *skb)
{
#if IS_ENABLED(CONFIG_IPV6)
struct ipv6hdr *iph;
u8 *prevhdr;
int hdr_len;
iph = ipv6_hdr(skb);
if (!skb->inner_protocol)
skb_set_inner_transport_header(skb,
skb_transport_offset(skb));
hdr_len = xfrm6_hdr_offset(x, skb, &prevhdr);
if (hdr_len < 0)
return hdr_len;
skb_set_mac_header(skb,
(prevhdr - x->props.header_len) - skb->data);
skb_set_network_header(skb, -x->props.header_len);
skb->transport_header = skb->network_header + hdr_len;
__skb_pull(skb, hdr_len);
memmove(ipv6_hdr(skb), iph, hdr_len);
return 0;
Annotation
- Immediate include surface: `linux/errno.h`, `linux/module.h`, `linux/netdevice.h`, `linux/netfilter.h`, `linux/skbuff.h`, `linux/slab.h`, `linux/spinlock.h`, `net/dst.h`.
- Detected declarations: `function xfrm_skb_check_space`, `function xfrm4_transport_output`, `function mip6_rthdr_offset`, `function xfrm6_hdr_offset`, `function xfrm6_transport_output`, `function xfrm6_ro_output`, `function xfrm4_beet_encap_add`, `function xfrm4_tunnel_encap_add`, `function xfrm6_tunnel_encap_add`, `function xfrm6_beet_encap_add`.
- 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.