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.

Dependency Surface

Detected Declarations

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

Implementation Notes