net/ipv4/ip_sockglue.c
Source file repositories/reference/linux-study-clean/net/ipv4/ip_sockglue.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/ip_sockglue.c- Extension
.c- Size
- 43064 bytes
- Lines
- 1786
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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.
- 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/types.hlinux/mm.hlinux/skbuff.hlinux/ip.hlinux/icmp.hlinux/inetdevice.hlinux/netdevice.hlinux/slab.hnet/sock.hnet/ip.hnet/icmp.hnet/tcp_states.hlinux/udp.hlinux/igmp.hlinux/netfilter.hlinux/route.hlinux/mroute.hnet/inet_ecn.hnet/route.hnet/xfrm.hnet/compat.hnet/checksum.hnet/transp_v6.hnet/ip_fib.hlinux/errqueue.hlinux/uaccess.h
Detected Declarations
function ip_cmsg_recv_pktinfofunction ip_cmsg_recv_ttlfunction ip_cmsg_recv_tosfunction ip_cmsg_recv_optsfunction ip_cmsg_recv_retoptsfunction ip_cmsg_recv_fragsizefunction ip_cmsg_recv_checksumfunction ip_cmsg_recv_securityfunction ip_cmsg_recv_dstaddrfunction ip_cmsg_recv_offsetfunction ip_cmsg_sendfunction for_each_cmsghdrfunction ip_ra_destroy_rcufunction ip_ra_controlfunction ipv4_icmp_error_rfc4884function ip_icmp_errorfunction ip_local_errorfunction ipv4_datagram_support_addrfunction ipv4_datagram_support_cmsgfunction ip_recv_errorfunction __ip_sock_set_tosfunction ip_sock_set_tosfunction ip_sock_set_freebindfunction ip_sock_set_recverrfunction ip_sock_set_mtu_discoverfunction ip_sock_set_pktinfofunction setsockopt_needs_rtnlfunction set_mcast_msfilterfunction copy_group_source_from_sockptrfunction do_mcast_group_sourcefunction ip_set_mcast_msfilterfunction compat_ip_set_mcast_msfilterfunction ip_mcast_join_leavefunction compat_ip_mcast_join_leavefunction do_ip_setsockoptfunction ipv4_pktinfo_preparefunction ip_setsockoptfunction getsockopt_needs_rtnlfunction ip_get_mcast_msfilterfunction compat_ip_get_mcast_msfilterfunction do_ip_getsockoptfunction ip_getsockoptexport ip_cmsg_recv_offsetexport ip_icmp_errorexport ip_sock_set_tosexport ip_sock_set_freebindexport ip_sock_set_recverrexport ip_sock_set_mtu_discover
Annotated Snippet
if (cmsg->cmsg_level == SOL_SOCKET) {
err = __sock_cmsg_send(sk, cmsg, &ipc->sockc);
if (err)
return err;
continue;
}
if (cmsg->cmsg_level != SOL_IP)
continue;
switch (cmsg->cmsg_type) {
case IP_RETOPTS:
err = cmsg->cmsg_len - sizeof(struct cmsghdr);
/* Our caller is responsible for freeing ipc->opt */
err = ip_options_get(net, &ipc->opt,
KERNEL_SOCKPTR(CMSG_DATA(cmsg)),
err < 40 ? err : 40);
if (err)
return err;
break;
case IP_PKTINFO:
{
struct in_pktinfo *info;
if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct in_pktinfo)))
return -EINVAL;
info = (struct in_pktinfo *)CMSG_DATA(cmsg);
if (info->ipi_ifindex)
ipc->oif = info->ipi_ifindex;
ipc->addr = info->ipi_spec_dst.s_addr;
break;
}
case IP_TTL:
if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
return -EINVAL;
val = *(int *)CMSG_DATA(cmsg);
if (val < 1 || val > 255)
return -EINVAL;
ipc->ttl = val;
break;
case IP_TOS:
if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)))
val = *(int *)CMSG_DATA(cmsg);
else if (cmsg->cmsg_len == CMSG_LEN(sizeof(u8)))
val = *(u8 *)CMSG_DATA(cmsg);
else
return -EINVAL;
if (val < 0 || val > 255)
return -EINVAL;
ipc->tos = val;
ipc->sockc.priority = rt_tos2priority(ipc->tos);
break;
case IP_PROTOCOL:
if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
return -EINVAL;
val = *(int *)CMSG_DATA(cmsg);
if (val < 1 || val > 255)
return -EINVAL;
ipc->protocol = val;
break;
default:
return -EINVAL;
}
}
return 0;
}
static void ip_ra_destroy_rcu(struct rcu_head *head)
{
struct ip_ra_chain *ra = container_of(head, struct ip_ra_chain, rcu);
sock_put(ra->saved_sk);
kfree(ra);
}
int ip_ra_control(struct sock *sk, unsigned char on,
void (*destructor)(struct sock *))
{
struct ip_ra_chain *ra, *new_ra;
struct ip_ra_chain __rcu **rap;
struct net *net = sock_net(sk);
if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num == IPPROTO_RAW)
return -EINVAL;
new_ra = on ? kmalloc_obj(*new_ra) : NULL;
if (on && !new_ra)
return -ENOMEM;
mutex_lock(&net->ipv4.ra_mutex);
for (rap = &net->ipv4.ra_chain;
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/mm.h`, `linux/skbuff.h`, `linux/ip.h`, `linux/icmp.h`, `linux/inetdevice.h`, `linux/netdevice.h`.
- Detected declarations: `function ip_cmsg_recv_pktinfo`, `function ip_cmsg_recv_ttl`, `function ip_cmsg_recv_tos`, `function ip_cmsg_recv_opts`, `function ip_cmsg_recv_retopts`, `function ip_cmsg_recv_fragsize`, `function ip_cmsg_recv_checksum`, `function ip_cmsg_recv_security`, `function ip_cmsg_recv_dstaddr`, `function ip_cmsg_recv_offset`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration 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.
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.