net/ipv4/ip_tunnel_core.c
Source file repositories/reference/linux-study-clean/net/ipv4/ip_tunnel_core.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/ip_tunnel_core.c- Extension
.c- Size
- 32767 bytes
- Lines
- 1198
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/kernel.hlinux/skbuff.hlinux/netdevice.hlinux/in.hlinux/if_arp.hlinux/init.hlinux/in6.hlinux/inetdevice.hlinux/netfilter_ipv4.hlinux/etherdevice.hlinux/if_ether.hlinux/if_vlan.hlinux/static_key.hnet/ip.hnet/icmp.hnet/protocol.hnet/ip_tunnels.hnet/ip6_tunnel.hnet/ip6_checksum.hnet/arp.hnet/checksum.hnet/dsfield.hnet/inet_ecn.hnet/xfrm.hnet/net_namespace.hnet/netns/generic.hnet/rtnetlink.hnet/dst_metadata.hnet/geneve.hnet/vxlan.hnet/erspan.h
Detected Declarations
function iptunnel_xmitfunction __iptunnel_pull_headerfunction iptunnel_handle_offloadsfunction iptunnel_pmtud_build_icmpfunction iptunnel_pmtud_check_icmpfunction iptunnel_pmtud_build_icmpv6function iptunnel_pmtud_check_icmpv6function skb_tunnel_check_pmtufunction ip_tun_parse_opts_genevefunction ip_tun_parse_opts_vxlanfunction ip_tun_parse_opts_erspanfunction ip_tun_parse_optsfunction nla_for_each_attrfunction ip_tun_get_optlenfunction ip_tun_set_optsfunction ip_tun_build_statefunction ip_tun_destroy_statefunction ip_tun_fill_encap_opts_genevefunction ip_tun_fill_encap_opts_vxlanfunction ip_tun_fill_encap_opts_erspanfunction ip_tun_fill_encap_optsfunction ip_tun_fill_encap_infofunction ip_tun_opts_nlsizefunction ip_tun_encap_nlsizefunction ip_tun_cmp_encapfunction ip6_tun_build_statefunction ip6_tun_fill_encap_infofunction ip6_tun_encap_nlsizefunction ip_tunnel_core_initfunction ip_tunnel_need_metadatafunction ip_tunnel_unneed_metadatafunction ip_tunnel_parse_protocolfunction ip_tunnel_netlink_encap_parmsfunction ip_tunnel_netlink_parmsexport iptun_encapsexport ip6tun_encapsexport iptunnel_xmitexport __iptunnel_pull_headerexport iptunnel_metadata_replyexport iptunnel_handle_offloadsexport skb_tunnel_check_pmtuexport ip_tunnel_metadata_cntexport ip_tunnel_need_metadataexport ip_tunnel_unneed_metadataexport ip_tunnel_parse_protocolexport ip_tunnel_header_opsexport ip_tunnel_netlink_encap_parmsexport ip_tunnel_netlink_parms
Annotated Snippet
if (dev) {
net_crit_ratelimited("Dead loop on virtual device %s (net %llu), fix it urgently!\n",
dev->name, dev_net(dev)->net_cookie);
DEV_STATS_INC(dev, tx_errors);
}
ip_rt_put(rt);
kfree_skb_reason(skb, SKB_DROP_REASON_RECURSION_LIMIT);
return;
}
dev_xmit_recursion_inc();
skb_scrub_packet(skb, xnet);
skb_clear_hash_if_not_l4(skb);
skb_dst_set(skb, &rt->dst);
memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
IPCB(skb)->flags = ipcb_flags;
/* Push down and install the IP header. */
skb_push(skb, sizeof(struct iphdr));
skb_reset_network_header(skb);
iph = ip_hdr(skb);
iph->version = 4;
iph->ihl = sizeof(struct iphdr) >> 2;
iph->frag_off = ip_mtu_locked(&rt->dst) ? 0 : df;
iph->protocol = proto;
iph->tos = tos;
iph->daddr = dst;
iph->saddr = src;
iph->ttl = ttl;
__ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);
err = ip_local_out(net, sk, skb);
if (dev) {
if (unlikely(net_xmit_eval(err)))
pkt_len = 0;
iptunnel_xmit_stats(dev, pkt_len);
}
dev_xmit_recursion_dec();
}
EXPORT_SYMBOL_GPL(iptunnel_xmit);
int __iptunnel_pull_header(struct sk_buff *skb, int hdr_len,
__be16 inner_proto, bool raw_proto, bool xnet)
{
if (unlikely(!pskb_may_pull(skb, hdr_len)))
return -ENOMEM;
skb_pull_rcsum(skb, hdr_len);
if (!raw_proto && inner_proto == htons(ETH_P_TEB)) {
struct ethhdr *eh;
if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
return -ENOMEM;
eh = (struct ethhdr *)skb->data;
if (likely(eth_proto_is_802_3(eh->h_proto)))
skb->protocol = eh->h_proto;
else
skb->protocol = htons(ETH_P_802_2);
} else {
skb->protocol = inner_proto;
}
skb_clear_hash_if_not_l4(skb);
__vlan_hwaccel_clear_tag(skb);
skb_set_queue_mapping(skb, 0);
skb_scrub_packet(skb, xnet);
return iptunnel_pull_offloads(skb);
}
EXPORT_SYMBOL_GPL(__iptunnel_pull_header);
struct metadata_dst *iptunnel_metadata_reply(struct metadata_dst *md,
gfp_t flags)
{
IP_TUNNEL_DECLARE_FLAGS(tun_flags) = { };
struct metadata_dst *res;
struct ip_tunnel_info *dst, *src;
if (!md || md->type != METADATA_IP_TUNNEL ||
md->u.tun_info.mode & IP_TUNNEL_INFO_TX)
return NULL;
Annotation
- Immediate include surface: `linux/types.h`, `linux/kernel.h`, `linux/skbuff.h`, `linux/netdevice.h`, `linux/in.h`, `linux/if_arp.h`, `linux/init.h`, `linux/in6.h`.
- Detected declarations: `function iptunnel_xmit`, `function __iptunnel_pull_header`, `function iptunnel_handle_offloads`, `function iptunnel_pmtud_build_icmp`, `function iptunnel_pmtud_check_icmp`, `function iptunnel_pmtud_build_icmpv6`, `function iptunnel_pmtud_check_icmpv6`, `function skb_tunnel_check_pmtu`, `function ip_tun_parse_opts_geneve`, `function ip_tun_parse_opts_vxlan`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
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.