net/ipv6/ip6_tunnel.c
Source file repositories/reference/linux-study-clean/net/ipv6/ip6_tunnel.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv6/ip6_tunnel.c- Extension
.c- Size
- 60732 bytes
- Lines
- 2446
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/capability.hlinux/errno.hlinux/types.hlinux/sockios.hlinux/icmp.hlinux/if.hlinux/in.hlinux/ip.hlinux/net.hlinux/in6.hlinux/netdevice.hlinux/if_arp.hlinux/icmpv6.hlinux/init.hlinux/route.hlinux/rtnetlink.hlinux/netfilter_ipv6.hlinux/slab.hlinux/hash.hlinux/etherdevice.hlinux/uaccess.hlinux/atomic.hnet/icmp.hnet/ip.hnet/ip_tunnels.hnet/ipv6.hnet/ip6_route.hnet/addrconf.hnet/ip6_tunnel.hnet/xfrm.hnet/dsfield.h
Detected Declarations
struct ip6_tnl_netstruct ipv6_tel_txoptionfunction HASHfunction ip6_tnl_mpls_supportedfunction ip6_tnl_lookupfunction for_each_ip_tunnel_rcufunction ip6_tnl_bucketfunction ip6_tnl_linkfunction ip6_tnl_unlinkfunction ip6_dev_freefunction ip6_tnl_create2function ip6_tnl_locatefunction ip6_tnl_dev_uninitfunction ip6_tnl_parse_tlv_enc_limfunction ip6_tnl_errfunction ip4ip6_errfunction ip6ip6_errfunction mplsip6_errfunction ip4ip6_dscp_ecn_decapsulatefunction ip6ip6_dscp_ecn_decapsulatefunction mplsip6_dscp_ecn_decapsulatefunction ip6_tnl_get_capfunction ip6_tnl_rcv_ctlfunction __ip6_tnl_rcvfunction ip6_tnl_rcvfunction ipxip6_rcvfunction ip4ip6_rcvfunction ip6ip6_rcvfunction mplsip6_rcvfunction init_tel_txoptfunction ip6_tnl_addr_conflictfunction ip6_tnl_xmit_ctlfunction ip6_tnl_xmitfunction ipxip6_tnl_xmitfunction ip6_tnl_start_xmitfunction ip6_tnl_link_configfunction ip6_tnl_changefunction ip6_tnl_updatefunction ip6_tnl0_updatefunction ip6_tnl_parm_from_userfunction ip6_tnl_parm_to_userfunction ip6_tnl_ioctlfunction ip6_tnl_change_mtufunction ip6_tnl_get_iflinkfunction ip6_tnl_encap_add_opsfunction ip6_tnl_encap_del_opsfunction ip6_tnl_encap_setupfunction ip6_tnl_fill_forward_path
Annotated Snippet
static const struct net_device_ops ip6_tnl_netdev_ops = {
.ndo_init = ip6_tnl_dev_init,
.ndo_uninit = ip6_tnl_dev_uninit,
.ndo_start_xmit = ip6_tnl_start_xmit,
.ndo_siocdevprivate = ip6_tnl_siocdevprivate,
.ndo_change_mtu = ip6_tnl_change_mtu,
.ndo_get_stats64 = dev_get_tstats64,
.ndo_get_iflink = ip6_tnl_get_iflink,
.ndo_fill_forward_path = ip6_tnl_fill_forward_path,
};
#define IPXIPX_FEATURES (NETIF_F_SG | \
NETIF_F_FRAGLIST | \
NETIF_F_HIGHDMA | \
NETIF_F_GSO_SOFTWARE | \
NETIF_F_HW_CSUM)
/**
* ip6_tnl_dev_setup - setup virtual tunnel device
* @dev: virtual device associated with tunnel
*
* Description:
* Initialize function pointers and device parameters
**/
static void ip6_tnl_dev_setup(struct net_device *dev)
{
dev->netdev_ops = &ip6_tnl_netdev_ops;
dev->header_ops = &ip_tunnel_header_ops;
dev->needs_free_netdev = true;
dev->priv_destructor = ip6_dev_free;
dev->type = ARPHRD_TUNNEL6;
dev->flags |= IFF_NOARP;
dev->addr_len = sizeof(struct in6_addr);
dev->lltx = true;
dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
netif_keep_dst(dev);
dev->features |= IPXIPX_FEATURES;
dev->hw_features |= IPXIPX_FEATURES;
/* This perm addr will be used as interface identifier by IPv6 */
dev->addr_assign_type = NET_ADDR_RANDOM;
eth_random_addr(dev->perm_addr);
}
/**
* ip6_tnl_dev_init_gen - general initializer for all tunnel devices
* @dev: virtual device associated with tunnel
**/
static inline int
ip6_tnl_dev_init_gen(struct net_device *dev)
{
struct ip6_tnl *t = netdev_priv(dev);
int ret;
int t_hlen;
t->dev = dev;
ret = dst_cache_init(&t->dst_cache, GFP_KERNEL);
if (ret)
return ret;
ret = gro_cells_init(&t->gro_cells, dev);
if (ret)
goto destroy_dst;
t->tun_hlen = 0;
t->hlen = t->encap_hlen + t->tun_hlen;
t_hlen = t->hlen + sizeof(struct ipv6hdr);
dev->type = ARPHRD_TUNNEL6;
dev->mtu = ETH_DATA_LEN - t_hlen;
if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
dev->mtu -= 8;
dev->min_mtu = ETH_MIN_MTU;
dev->max_mtu = IP6_MAX_MTU - dev->hard_header_len - t_hlen;
netdev_hold(dev, &t->dev_tracker, GFP_KERNEL);
netdev_lockdep_set_classes(dev);
return 0;
destroy_dst:
dst_cache_destroy(&t->dst_cache);
return ret;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/capability.h`, `linux/errno.h`, `linux/types.h`, `linux/sockios.h`, `linux/icmp.h`, `linux/if.h`, `linux/in.h`.
- Detected declarations: `struct ip6_tnl_net`, `struct ipv6_tel_txoption`, `function HASH`, `function ip6_tnl_mpls_supported`, `function ip6_tnl_lookup`, `function for_each_ip_tunnel_rcu`, `function ip6_tnl_bucket`, `function ip6_tnl_link`, `function ip6_tnl_unlink`, `function ip6_dev_free`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.