net/ipv4/proc.c
Source file repositories/reference/linux-study-clean/net/ipv4/proc.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/proc.c- Extension
.c- Size
- 21854 bytes
- Lines
- 557
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- 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/types.hnet/net_namespace.hnet/icmp.hnet/protocol.hnet/tcp.hnet/mptcp.hnet/proto_memory.hnet/udp.hlinux/bottom_half.hlinux/inetdevice.hlinux/proc_fs.hlinux/seq_file.hlinux/export.hnet/sock.hnet/raw.h
Detected Declarations
function sockstat_seq_showfunction icmpmsg_put_linefunction icmpmsg_putfunction icmp_putfunction snmp_seq_show_ipstatsfunction snmp_seq_show_tcp_udpfunction snmp_seq_showfunction netstat_seq_showfunction ip_proc_init_netfunction ip_proc_exit_netfunction ip_misc_proc_init
Annotated Snippet
if (val) {
type[count] = i;
vals[count++] = val;
}
if (count == PERLINE) {
icmpmsg_put_line(seq, vals, type, count);
count = 0;
}
}
icmpmsg_put_line(seq, vals, type, count);
#undef PERLINE
}
static void icmp_put(struct seq_file *seq)
{
int i;
struct net *net = seq->private;
atomic_long_t *ptr = net->mib.icmpmsg_statistics->mibs;
seq_puts(seq, "\nIcmp: InMsgs InErrors InCsumErrors");
for (i = 0; icmpmibmap[i].name; i++)
seq_printf(seq, " In%s", icmpmibmap[i].name);
seq_puts(seq, " OutMsgs OutErrors OutRateLimitGlobal OutRateLimitHost");
for (i = 0; icmpmibmap[i].name; i++)
seq_printf(seq, " Out%s", icmpmibmap[i].name);
seq_printf(seq, "\nIcmp: %lu %lu %lu",
snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_INMSGS),
snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_INERRORS),
snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_CSUMERRORS));
for (i = 0; icmpmibmap[i].name; i++)
seq_printf(seq, " %lu",
atomic_long_read(ptr + icmpmibmap[i].index));
seq_printf(seq, " %lu %lu %lu %lu",
snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_OUTMSGS),
snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_OUTERRORS),
snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_RATELIMITGLOBAL),
snmp_fold_field(net->mib.icmp_statistics, ICMP_MIB_RATELIMITHOST));
for (i = 0; icmpmibmap[i].name; i++)
seq_printf(seq, " %lu",
atomic_long_read(ptr + (icmpmibmap[i].index | 0x100)));
}
/*
* Called from the PROCfs module. This outputs /proc/net/snmp.
*/
static int snmp_seq_show_ipstats(struct seq_file *seq, void *v)
{
const int cnt = ARRAY_SIZE(snmp4_ipstats_list);
u64 buff64[ARRAY_SIZE(snmp4_ipstats_list)];
struct net *net = seq->private;
int i;
memset(buff64, 0, sizeof(buff64));
seq_puts(seq, "Ip: Forwarding DefaultTTL");
for (i = 0; i < cnt; i++)
seq_printf(seq, " %s", snmp4_ipstats_list[i].name);
seq_printf(seq, "\nIp: %d %d",
IPV4_DEVCONF_ALL_RO(net, FORWARDING) ? 1 : 2,
READ_ONCE(net->ipv4.sysctl_ip_default_ttl));
BUILD_BUG_ON(offsetof(struct ipstats_mib, mibs) != 0);
snmp_get_cpu_field64_batch_cnt(buff64, snmp4_ipstats_list, cnt,
net->mib.ip_statistics,
offsetof(struct ipstats_mib, syncp));
for (i = 0; i < cnt; i++)
seq_printf(seq, " %llu", buff64[i]);
return 0;
}
static int snmp_seq_show_tcp_udp(struct seq_file *seq, void *v)
{
const int udp_cnt = ARRAY_SIZE(snmp4_udp_list);
const int tcp_cnt = ARRAY_SIZE(snmp4_tcp_list);
unsigned long buff[TCPUDP_MIB_MAX];
struct net *net = seq->private;
int i;
memset(buff, 0, tcp_cnt * sizeof(unsigned long));
seq_puts(seq, "\nTcp:");
for (i = 0; i < tcp_cnt; i++)
seq_printf(seq, " %s", snmp4_tcp_list[i].name);
seq_puts(seq, "\nTcp:");
snmp_get_cpu_field_batch_cnt(buff, snmp4_tcp_list,
tcp_cnt,
Annotation
- Immediate include surface: `linux/types.h`, `net/net_namespace.h`, `net/icmp.h`, `net/protocol.h`, `net/tcp.h`, `net/mptcp.h`, `net/proto_memory.h`, `net/udp.h`.
- Detected declarations: `function sockstat_seq_show`, `function icmpmsg_put_line`, `function icmpmsg_put`, `function icmp_put`, `function snmp_seq_show_ipstats`, `function snmp_seq_show_tcp_udp`, `function snmp_seq_show`, `function netstat_seq_show`, `function ip_proc_init_net`, `function ip_proc_exit_net`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.