net/ipv4/ipip.c
Source file repositories/reference/linux-study-clean/net/ipv4/ipip.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/ipip.c- Extension
.c- Size
- 18681 bytes
- Lines
- 703
- 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.
- 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/netfilter_ipv4.hlinux/if_ether.hnet/sock.hnet/ip.hnet/icmp.hnet/ip_tunnels.hnet/inet_ecn.hnet/xfrm.hnet/net_namespace.hnet/netns/generic.hnet/dst_metadata.h
Detected Declarations
function ipip_errfunction ipip_tunnel_rcvfunction ipip_rcvfunction mplsip_rcvfunction dev_queue_xmitfunction ipip_tunnel_ioctl_verify_protocolfunction ipip_tunnel_ctlfunction ipip_fill_forward_pathfunction ipip_tunnel_setupfunction ipip_tunnel_initfunction ipip_tunnel_validatefunction ipip_netlink_parmsfunction ipip_newlinkfunction ipip_changelinkfunction ipip_get_sizefunction ipip_fill_infofunction ipip_init_netfunction ipip_exit_rtnlfunction ipip_initfunction ipip_finimodule init ipip_init
Annotated Snippet
static const struct net_device_ops ipip_netdev_ops = {
.ndo_init = ipip_tunnel_init,
.ndo_uninit = ip_tunnel_uninit,
.ndo_start_xmit = ipip_tunnel_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 = ipip_tunnel_ctl,
.ndo_fill_forward_path = ipip_fill_forward_path,
};
#define IPIP_FEATURES (NETIF_F_SG | \
NETIF_F_FRAGLIST | \
NETIF_F_HIGHDMA | \
NETIF_F_GSO_SOFTWARE | \
NETIF_F_HW_CSUM)
static void ipip_tunnel_setup(struct net_device *dev)
{
dev->netdev_ops = &ipip_netdev_ops;
dev->header_ops = &ip_tunnel_header_ops;
dev->type = ARPHRD_TUNNEL;
dev->flags = IFF_NOARP;
dev->addr_len = 4;
dev->lltx = true;
netif_keep_dst(dev);
dev->features |= IPIP_FEATURES;
dev->hw_features |= IPIP_FEATURES;
ip_tunnel_setup(dev, ipip_net_id);
}
static int ipip_tunnel_init(struct net_device *dev)
{
struct ip_tunnel *tunnel = netdev_priv(dev);
__dev_addr_set(dev, &tunnel->parms.iph.saddr, 4);
memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
tunnel->tun_hlen = 0;
tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen;
return ip_tunnel_init(dev);
}
static int ipip_tunnel_validate(struct nlattr *tb[], struct nlattr *data[],
struct netlink_ext_ack *extack)
{
u8 proto;
if (!data || !data[IFLA_IPTUN_PROTO])
return 0;
proto = nla_get_u8(data[IFLA_IPTUN_PROTO]);
if (proto != IPPROTO_IPIP && proto != IPPROTO_MPLS && proto != 0)
return -EINVAL;
return 0;
}
static void ipip_netlink_parms(struct nlattr *data[],
struct ip_tunnel_parm_kern *parms,
bool *collect_md, __u32 *fwmark)
{
memset(parms, 0, sizeof(*parms));
parms->iph.version = 4;
parms->iph.protocol = IPPROTO_IPIP;
parms->iph.ihl = 5;
*collect_md = false;
if (!data)
return;
ip_tunnel_netlink_parms(data, parms);
if (data[IFLA_IPTUN_COLLECT_METADATA])
*collect_md = true;
if (data[IFLA_IPTUN_FWMARK])
*fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
}
static int ipip_newlink(struct net_device *dev,
struct rtnl_newlink_params *params,
struct netlink_ext_ack *extack)
{
struct ip_tunnel *t = netdev_priv(dev);
struct nlattr **data = params->data;
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 ipip_err`, `function ipip_tunnel_rcv`, `function ipip_rcv`, `function mplsip_rcv`, `function dev_queue_xmit`, `function ipip_tunnel_ioctl_verify_protocol`, `function ipip_tunnel_ctl`, `function ipip_fill_forward_path`, `function ipip_tunnel_setup`, `function ipip_tunnel_init`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern 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.