net/ipv4/xfrm4_input.c
Source file repositories/reference/linux-study-clean/net/ipv4/xfrm4_input.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/xfrm4_input.c- Extension
.c- Size
- 5550 bytes
- Lines
- 232
- 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/slab.hlinux/module.hlinux/string.hlinux/netfilter.hlinux/netfilter_ipv4.hnet/ip.hnet/xfrm.hnet/protocol.hnet/gro.h
Detected Declarations
function xfrm4_rcv_encap_finish2function xfrm4_rcv_encap_finishfunction xfrm4_transport_finishfunction __xfrm4_udp_encap_rcvfunction xfrm4_udp_encap_rcvfunction xfrm4_rcvexport xfrm4_udp_encap_rcvexport xfrm4_gro_udp_encap_rcvexport xfrm4_rcv
Annotated Snippet
if (len == 1 && udpdata[0] == 0xff) {
return -EINVAL;
} else if (len > sizeof(struct ip_esp_hdr) && udpdata32[0] != 0) {
/* ESP Packet without Non-ESP header */
len = sizeof(struct udphdr);
} else
/* Must be an IKE packet.. pass it through */
return 1;
break;
}
/* At this point we are sure that this is an ESPinUDP packet,
* so we need to remove 'len' bytes from the packet (the UDP
* header and optional ESP marker bytes) and then modify the
* protocol to ESP, and then call into the transform receiver.
*/
if (skb_unclone(skb, GFP_ATOMIC))
return -EINVAL;
/* Now we can update and verify the packet length... */
iph = ip_hdr(skb);
iphlen = iph->ihl << 2;
iph->tot_len = htons(ntohs(iph->tot_len) - len);
if (skb->len < iphlen + len) {
/* packet is too small!?! */
return -EINVAL;
}
/* pull the data buffer up to the ESP header and set the
* transport header to point to ESP. Keep UDP on the stack
* for later.
*/
if (pull) {
__skb_pull(skb, len);
skb_reset_transport_header(skb);
} else {
skb_set_transport_header(skb, len);
}
/* process ESP */
return 0;
}
/* If it's a keepalive packet, then just eat it.
* If it's an encapsulated packet, then pass it to the
* IPsec xfrm input.
* Returns 0 if skb passed to xfrm or was dropped.
* Returns >0 if skb should be passed to UDP.
* Returns <0 if skb should be resubmitted (-ret is protocol)
*/
int xfrm4_udp_encap_rcv(struct sock *sk, struct sk_buff *skb)
{
int ret;
ret = __xfrm4_udp_encap_rcv(sk, skb, true);
if (!ret)
return xfrm4_rcv_encap(skb, IPPROTO_ESP, 0,
udp_sk(sk)->encap_type);
if (ret < 0) {
kfree_skb(skb);
return 0;
}
return ret;
}
EXPORT_SYMBOL(xfrm4_udp_encap_rcv);
struct sk_buff *xfrm4_gro_udp_encap_rcv(struct sock *sk, struct list_head *head,
struct sk_buff *skb)
{
int offset = skb_gro_offset(skb);
const struct net_offload *ops;
struct sk_buff *pp = NULL;
int len, dlen;
__u8 *udpdata;
__be32 *udpdata32;
len = skb->len - offset;
dlen = offset + min(len, 8);
udpdata = skb_gro_header(skb, dlen, offset);
udpdata32 = (__be32 *)udpdata;
if (unlikely(!udpdata))
return NULL;
rcu_read_lock();
ops = rcu_dereference(inet_offloads[IPPROTO_ESP]);
if (!ops || !ops->callbacks.gro_receive)
goto out;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/module.h`, `linux/string.h`, `linux/netfilter.h`, `linux/netfilter_ipv4.h`, `net/ip.h`, `net/xfrm.h`, `net/protocol.h`.
- Detected declarations: `function xfrm4_rcv_encap_finish2`, `function xfrm4_rcv_encap_finish`, `function xfrm4_transport_finish`, `function __xfrm4_udp_encap_rcv`, `function xfrm4_udp_encap_rcv`, `function xfrm4_rcv`, `export xfrm4_udp_encap_rcv`, `export xfrm4_gro_udp_encap_rcv`, `export xfrm4_rcv`.
- 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.