net/ipv4/ip_gre.c
Source file repositories/reference/linux-study-clean/net/ipv4/ip_gre.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/ip_gre.c- Extension
.c- Size
- 49374 bytes
- Lines
- 1871
- 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.
- 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/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/if_vlan.hlinux/init.hlinux/in6.hlinux/inetdevice.hlinux/igmp.hlinux/netfilter_ipv4.hlinux/etherdevice.hlinux/if_ether.hnet/flow.hnet/sock.hnet/ip.hnet/icmp.hnet/protocol.hnet/ip_tunnels.hnet/arp.hnet/checksum.hnet/dsfield.hnet/inet_ecn.hnet/xfrm.hnet/net_namespace.h
Detected Declarations
function ipgre_errfunction gre_errfunction is_erspan_type1function erspan_rcvfunction __ipgre_rcvfunction ipgre_rcvfunction gre_rcvfunction __gre_xmitfunction gre_handle_offloadsfunction gre_fb_xmitfunction erspan_fb_xmitfunction gre_fill_metadata_dstfunction ipgre_xmitfunction erspan_xmitfunction gre_tap_xmitfunction ipgre_link_updatefunction ipgre_tunnel_ctlfunction ipgre_headerfunction ipgre_header_parsefunction ipgre_openfunction ipgre_closefunction ipgre_tunnel_setupfunction __gre_tunnel_initfunction ipgre_tunnel_initfunction ipgre_init_netfunction ipgre_exit_rtnlfunction ipgre_tunnel_validatefunction ipgre_tap_validatefunction erspan_validatefunction ipgre_netlink_parmsfunction erspan_netlink_parmsfunction ipgre_netlink_encap_parmsfunction gre_tap_initfunction erspan_tunnel_initfunction ipgre_tap_setupfunction ipgre_newlink_encap_setupfunction ipgre_newlinkfunction erspan_newlinkfunction ipgre_changelinkfunction erspan_changelinkfunction ipgre_get_sizefunction ipgre_fill_infofunction erspan_fill_infofunction erspan_setupfunction ipgre_tap_init_netfunction ipgre_tap_exit_rtnlfunction erspan_init_netfunction erspan_exit_rtnl
Annotated Snippet
static const struct net_device_ops ipgre_netdev_ops = {
.ndo_init = ipgre_tunnel_init,
.ndo_uninit = ip_tunnel_uninit,
#ifdef CONFIG_NET_IPGRE_BROADCAST
.ndo_open = ipgre_open,
.ndo_stop = ipgre_close,
#endif
.ndo_start_xmit = ipgre_xmit,
.ndo_siocdevprivate = ip_tunnel_siocdevprivate,
.ndo_change_mtu = ip_tunnel_change_mtu,
.ndo_get_stats64 = dev_get_tstats64,
.ndo_get_iflink = ip_tunnel_get_iflink,
.ndo_tunnel_ctl = ipgre_tunnel_ctl,
};
#define GRE_FEATURES (NETIF_F_SG | \
NETIF_F_FRAGLIST | \
NETIF_F_HIGHDMA | \
NETIF_F_HW_CSUM)
static void ipgre_tunnel_setup(struct net_device *dev)
{
dev->netdev_ops = &ipgre_netdev_ops;
dev->type = ARPHRD_IPGRE;
ip_tunnel_setup(dev, ipgre_net_id);
}
static void __gre_tunnel_init(struct net_device *dev)
{
struct ip_tunnel *tunnel;
tunnel = netdev_priv(dev);
tunnel->tun_hlen = gre_calc_hlen(tunnel->parms.o_flags);
tunnel->parms.iph.protocol = IPPROTO_GRE;
tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen;
dev->needed_headroom = tunnel->hlen + sizeof(tunnel->parms.iph);
dev->features |= GRE_FEATURES;
dev->hw_features |= GRE_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, tunnel->parms.o_flags))
return;
if (test_bit(IP_TUNNEL_CSUM_BIT, tunnel->parms.o_flags) &&
tunnel->encap.type != TUNNEL_ENCAP_NONE)
return;
dev->features |= NETIF_F_GSO_SOFTWARE;
dev->hw_features |= NETIF_F_GSO_SOFTWARE;
dev->lltx = true;
}
static int ipgre_tunnel_init(struct net_device *dev)
{
struct ip_tunnel *tunnel = netdev_priv(dev);
struct iphdr *iph = &tunnel->parms.iph;
__gre_tunnel_init(dev);
__dev_addr_set(dev, &iph->saddr, 4);
memcpy(dev->broadcast, &iph->daddr, 4);
dev->flags = IFF_NOARP;
netif_keep_dst(dev);
dev->addr_len = 4;
if (iph->daddr && !tunnel->collect_md) {
#ifdef CONFIG_NET_IPGRE_BROADCAST
if (ipv4_is_multicast(iph->daddr)) {
if (!iph->saddr)
return -EINVAL;
dev->flags = IFF_BROADCAST;
dev->header_ops = &ipgre_header_ops;
dev->hard_header_len = tunnel->hlen + sizeof(*iph);
dev->needed_headroom = 0;
}
#endif
} else if (!tunnel->collect_md) {
dev->header_ops = &ipgre_header_ops;
dev->hard_header_len = tunnel->hlen + sizeof(*iph);
dev->needed_headroom = 0;
}
return ip_tunnel_init(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: `function ipgre_err`, `function gre_err`, `function is_erspan_type1`, `function erspan_rcv`, `function __ipgre_rcv`, `function ipgre_rcv`, `function gre_rcv`, `function __gre_xmit`, `function gre_handle_offloads`, `function gre_fb_xmit`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern 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.