net/ipv6/ip6_gre.c
Source file repositories/reference/linux-study-clean/net/ipv6/ip6_gre.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv6/ip6_gre.c- Extension
.c- Size
- 60144 bytes
- Lines
- 2390
- 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/capability.hlinux/module.hlinux/types.hlinux/kernel.hlinux/slab.hlinux/uaccess.hlinux/skbuff.hlinux/netdevice.hlinux/in.hlinux/tcp.hlinux/udp.hlinux/if_arp.hlinux/init.hlinux/in6.hlinux/inetdevice.hlinux/igmp.hlinux/netfilter_ipv4.hlinux/etherdevice.hlinux/if_ether.hlinux/hash.hlinux/if_tunnel.hlinux/ip6_tunnel.hnet/sock.hnet/ip.hnet/ip_tunnels.hnet/icmp.hnet/protocol.hnet/addrconf.hnet/arp.hnet/checksum.hnet/dsfield.hnet/inet_ecn.h
Detected Declarations
struct ip6gre_netfunction HASH_ADDRfunction ip6gre_tunnel_matchfunction for_each_ip_tunnel_rcufunction for_each_ip_tunnel_rcufunction for_each_ip_tunnel_rcufunction for_each_ip_tunnel_rcufunction ip6gre_tunnel_link_mdfunction ip6erspan_tunnel_link_mdfunction ip6gre_tunnel_unlink_mdfunction ip6erspan_tunnel_unlink_mdfunction ip6gre_tunnel_linkfunction ip6gre_tunnel_unlinkfunction ip6erspan_tunnel_uninitfunction ip6gre_tunnel_uninitfunction ip6gre_errfunction ip6gre_rcvfunction ip6erspan_rcvfunction gre_rcvfunction gre_handle_offloadsfunction prepare_ip6gre_xmit_ipv4function prepare_ip6gre_xmit_ipv6function prepare_ip6gre_xmit_otherfunction __gre6_xmitfunction ip6gre_xmit_ipv4function ip6gre_xmit_ipv6function ip6gre_xmit_otherfunction ip6gre_tunnel_xmitfunction ip6erspan_tunnel_xmitfunction ip6gre_tnl_link_config_commonfunction ip6gre_tnl_link_config_routefunction ip6gre_calc_hlenfunction ip6gre_tnl_link_configfunction ip6gre_tnl_copy_tnl_parmfunction ip6gre_tnl_changefunction ip6gre_tnl_parm_from_userfunction ip6gre_tnl_parm_to_userfunction ip6gre_tunnel_siocdevprivatefunction ip6gre_headerfunction ip6gre_dev_freefunction ip6gre_tunnel_setupfunction ip6gre_tnl_init_featuresfunction ip6gre_tunnel_init_commonfunction ip6gre_tunnel_initfunction ip6gre_fb_tunnel_initfunction ip6gre_exit_rtnl_netfunction ip6gre_init_netfunction ip6gre_tunnel_validate
Annotated Snippet
static const struct net_device_ops ip6gre_netdev_ops = {
.ndo_init = ip6gre_tunnel_init,
.ndo_uninit = ip6gre_tunnel_uninit,
.ndo_start_xmit = ip6gre_tunnel_xmit,
.ndo_siocdevprivate = ip6gre_tunnel_siocdevprivate,
.ndo_change_mtu = ip6_tnl_change_mtu,
.ndo_get_iflink = ip6_tnl_get_iflink,
};
static void ip6gre_dev_free(struct net_device *dev)
{
struct ip6_tnl *t = netdev_priv(dev);
gro_cells_destroy(&t->gro_cells);
dst_cache_destroy(&t->dst_cache);
}
static void ip6gre_tunnel_setup(struct net_device *dev)
{
dev->netdev_ops = &ip6gre_netdev_ops;
dev->needs_free_netdev = true;
dev->priv_destructor = ip6gre_dev_free;
dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
dev->type = ARPHRD_IP6GRE;
dev->flags |= IFF_NOARP;
dev->addr_len = sizeof(struct in6_addr);
netif_keep_dst(dev);
/* This perm addr will be used as interface identifier by IPv6 */
dev->addr_assign_type = NET_ADDR_RANDOM;
eth_random_addr(dev->perm_addr);
}
#define GRE6_FEATURES (NETIF_F_SG | \
NETIF_F_FRAGLIST | \
NETIF_F_HIGHDMA | \
NETIF_F_HW_CSUM)
static void ip6gre_tnl_init_features(struct net_device *dev)
{
struct ip6_tnl *nt = netdev_priv(dev);
dev->features |= GRE6_FEATURES;
dev->hw_features |= GRE6_FEATURES;
/* TCP offload with GRE SEQ is not supported, nor can we support 2
* levels of outer headers requiring an update.
*/
if (test_bit(IP_TUNNEL_SEQ_BIT, nt->parms.o_flags))
return;
if (test_bit(IP_TUNNEL_CSUM_BIT, nt->parms.o_flags) &&
nt->encap.type != TUNNEL_ENCAP_NONE)
return;
dev->features |= NETIF_F_GSO_SOFTWARE;
dev->hw_features |= NETIF_F_GSO_SOFTWARE;
dev->lltx = true;
}
static int ip6gre_tunnel_init_common(struct net_device *dev)
{
struct ip6_tnl *tunnel;
int ret;
int t_hlen;
tunnel = netdev_priv(dev);
tunnel->dev = dev;
strscpy(tunnel->parms.name, dev->name);
ret = dst_cache_init(&tunnel->dst_cache, GFP_KERNEL);
if (ret)
return ret;
ret = gro_cells_init(&tunnel->gro_cells, dev);
if (ret)
goto cleanup_dst_cache_init;
t_hlen = ip6gre_calc_hlen(tunnel);
dev->mtu = ETH_DATA_LEN - t_hlen;
if (dev->type == ARPHRD_ETHER)
dev->mtu -= ETH_HLEN;
if (!(tunnel->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
dev->mtu -= 8;
if (tunnel->parms.collect_md) {
netif_keep_dst(dev);
}
Annotation
- Immediate include surface: `linux/capability.h`, `linux/module.h`, `linux/types.h`, `linux/kernel.h`, `linux/slab.h`, `linux/uaccess.h`, `linux/skbuff.h`, `linux/netdevice.h`.
- Detected declarations: `struct ip6gre_net`, `function HASH_ADDR`, `function ip6gre_tunnel_match`, `function for_each_ip_tunnel_rcu`, `function for_each_ip_tunnel_rcu`, `function for_each_ip_tunnel_rcu`, `function for_each_ip_tunnel_rcu`, `function ip6gre_tunnel_link_md`, `function ip6erspan_tunnel_link_md`, `function ip6gre_tunnel_unlink_md`.
- 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.