net/ipv6/sit.c
Source file repositories/reference/linux-study-clean/net/ipv6/sit.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv6/sit.c- Extension
.c- Size
- 46771 bytes
- Lines
- 1951
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- 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/socket.hlinux/sockios.hlinux/string.hlinux/net.hlinux/in6.hlinux/netdevice.hlinux/if_arp.hlinux/icmp.hlinux/slab.hlinux/uaccess.hlinux/init.hlinux/netfilter_ipv4.hlinux/if_ether.hnet/sock.hnet/snmp.hnet/ipv6.hnet/protocol.hnet/transp_v6.hnet/ip6_fib.hnet/ip6_route.hnet/ndisc.hnet/addrconf.hnet/ip.hnet/udp.hnet/icmp.hnet/ip_tunnels.hnet/inet_ecn.hnet/xfrm.h
Detected Declarations
struct sit_netfunction for_each_ip_tunnel_rcufunction __ipip6_bucketfunction ipip6_tunnel_unlinkfunction ipip6_tunnel_linkfunction ipip6_tunnel_clone_6rdfunction ipip6_tunnel_createfunction __ipip6_tunnel_locate_prlfunction ipip6_tunnel_get_prlfunction ipip6_tunnel_add_prlfunction prl_list_destroy_rcufunction ipip6_tunnel_del_prlfunction ipip6_tunnel_prl_ctlfunction isatap_chksrcfunction ipip6_tunnel_uninitfunction ipip6_errfunction is_spoofed_6rdfunction only_dnattedfunction packet_is_spoofedfunction ipip6_rcvfunction sit_tunnel_rcvfunction ipip_rcvfunction mplsip_rcvfunction check_6rdfunction try_6rdfunction ipip6_tunnel_dst_findfunction dev_queue_xmitfunction sit_tunnel_xmit__function sit_tunnel_xmitfunction ipip6_tunnel_bind_devfunction ipip6_tunnel_updatefunction ipip6_tunnel_update_6rdfunction ipip6_tunnel_get6rdfunction ipip6_tunnel_6rdctlfunction ipip6_valid_ip_protofunction __ipip6_tunnel_ioctl_validatefunction ipip6_tunnel_getfunction ipip6_tunnel_addfunction ipip6_tunnel_changefunction ipip6_tunnel_delfunction ipip6_tunnel_ctlfunction ipip6_tunnel_siocdevprivatefunction ipip6_dev_freefunction ipip6_tunnel_setupfunction ipip6_tunnel_initfunction ipip6_fb_tunnel_initfunction ipip6_validatefunction ipip6_netlink_parms
Annotated Snippet
static const struct net_device_ops ipip6_netdev_ops = {
.ndo_init = ipip6_tunnel_init,
.ndo_uninit = ipip6_tunnel_uninit,
.ndo_start_xmit = sit_tunnel_xmit,
.ndo_siocdevprivate = ipip6_tunnel_siocdevprivate,
.ndo_get_iflink = ip_tunnel_get_iflink,
.ndo_tunnel_ctl = ipip6_tunnel_ctl,
};
static void ipip6_dev_free(struct net_device *dev)
{
struct ip_tunnel *tunnel = netdev_priv(dev);
dst_cache_destroy(&tunnel->dst_cache);
}
#define SIT_FEATURES (NETIF_F_SG | \
NETIF_F_FRAGLIST | \
NETIF_F_HIGHDMA | \
NETIF_F_GSO_SOFTWARE | \
NETIF_F_HW_CSUM)
static void ipip6_tunnel_setup(struct net_device *dev)
{
struct ip_tunnel *tunnel = netdev_priv(dev);
int t_hlen = tunnel->hlen + sizeof(struct iphdr);
dev->netdev_ops = &ipip6_netdev_ops;
dev->header_ops = &ip_tunnel_header_ops;
dev->needs_free_netdev = true;
dev->priv_destructor = ipip6_dev_free;
dev->type = ARPHRD_SIT;
dev->mtu = ETH_DATA_LEN - t_hlen;
dev->min_mtu = IPV6_MIN_MTU;
dev->max_mtu = IP6_MAX_MTU - t_hlen;
dev->flags = IFF_NOARP;
netif_keep_dst(dev);
dev->addr_len = 4;
dev->lltx = true;
dev->features |= SIT_FEATURES;
dev->hw_features |= SIT_FEATURES;
dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
}
static int ipip6_tunnel_init(struct net_device *dev)
{
struct ip_tunnel *tunnel = netdev_priv(dev);
int err;
tunnel->dev = dev;
strscpy(tunnel->parms.name, dev->name);
ipip6_tunnel_bind_dev(dev);
err = dst_cache_init(&tunnel->dst_cache, GFP_KERNEL);
if (err)
return err;
netdev_hold(dev, &tunnel->dev_tracker, GFP_KERNEL);
netdev_lockdep_set_classes(dev);
return 0;
}
static void __net_init ipip6_fb_tunnel_init(struct net_device *dev)
{
struct ip_tunnel *tunnel = netdev_priv(dev);
struct iphdr *iph = &tunnel->parms.iph;
struct net *net = dev_net(dev);
struct sit_net *sitn = net_generic(net, sit_net_id);
iph->version = 4;
iph->protocol = IPPROTO_IPV6;
iph->ihl = 5;
iph->ttl = 64;
rcu_assign_pointer(sitn->tunnels_wc[0], tunnel);
}
static int ipip6_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 (!ipip6_valid_ip_proto(proto))
Annotation
- Immediate include surface: `linux/module.h`, `linux/capability.h`, `linux/errno.h`, `linux/types.h`, `linux/socket.h`, `linux/sockios.h`, `linux/string.h`, `linux/net.h`.
- Detected declarations: `struct sit_net`, `function for_each_ip_tunnel_rcu`, `function __ipip6_bucket`, `function ipip6_tunnel_unlink`, `function ipip6_tunnel_link`, `function ipip6_tunnel_clone_6rd`, `function ipip6_tunnel_create`, `function __ipip6_tunnel_locate_prl`, `function ipip6_tunnel_get_prl`, `function ipip6_tunnel_add_prl`.
- 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.