xref: /openbmc/linux/net/mptcp/mib.c (revision 002dff36)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 #include <linux/seq_file.h>
4 #include <net/ip.h>
5 #include <net/mptcp.h>
6 #include <net/snmp.h>
7 #include <net/net_namespace.h>
8 
9 #include "mib.h"
10 
11 static const struct snmp_mib mptcp_snmp_list[] = {
12 	SNMP_MIB_ITEM("MPCapableSYNRX", MPTCP_MIB_MPCAPABLEPASSIVE),
13 	SNMP_MIB_ITEM("MPCapableACKRX", MPTCP_MIB_MPCAPABLEPASSIVEACK),
14 	SNMP_MIB_ITEM("MPCapableFallbackACK", MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK),
15 	SNMP_MIB_ITEM("MPCapableFallbackSYNACK", MPTCP_MIB_MPCAPABLEACTIVEFALLBACK),
16 	SNMP_MIB_ITEM("MPTCPRetrans", MPTCP_MIB_RETRANSSEGS),
17 	SNMP_MIB_ITEM("MPJoinNoTokenFound", MPTCP_MIB_JOINNOTOKEN),
18 	SNMP_MIB_ITEM("MPJoinSynRx", MPTCP_MIB_JOINSYNRX),
19 	SNMP_MIB_ITEM("MPJoinSynAckRx", MPTCP_MIB_JOINSYNACKRX),
20 	SNMP_MIB_ITEM("MPJoinSynAckHMacFailure", MPTCP_MIB_JOINSYNACKMAC),
21 	SNMP_MIB_ITEM("MPJoinAckRx", MPTCP_MIB_JOINACKRX),
22 	SNMP_MIB_ITEM("MPJoinAckHMacFailure", MPTCP_MIB_JOINACKMAC),
23 	SNMP_MIB_ITEM("DSSNotMatching", MPTCP_MIB_DSSNOMATCH),
24 	SNMP_MIB_ITEM("InfiniteMapRx", MPTCP_MIB_INFINITEMAPRX),
25 	SNMP_MIB_SENTINEL
26 };
27 
28 /* mptcp_mib_alloc - allocate percpu mib counters
29  *
30  * These are allocated when the first mptcp socket is created so
31  * we do not waste percpu memory if mptcp isn't in use.
32  */
33 bool mptcp_mib_alloc(struct net *net)
34 {
35 	struct mptcp_mib __percpu *mib = alloc_percpu(struct mptcp_mib);
36 
37 	if (!mib)
38 		return false;
39 
40 	if (cmpxchg(&net->mib.mptcp_statistics, NULL, mib))
41 		free_percpu(mib);
42 
43 	return true;
44 }
45 
46 void mptcp_seq_show(struct seq_file *seq)
47 {
48 	struct net *net = seq->private;
49 	int i;
50 
51 	seq_puts(seq, "MPTcpExt:");
52 	for (i = 0; mptcp_snmp_list[i].name; i++)
53 		seq_printf(seq, " %s", mptcp_snmp_list[i].name);
54 
55 	seq_puts(seq, "\nMPTcpExt:");
56 
57 	if (!net->mib.mptcp_statistics) {
58 		for (i = 0; mptcp_snmp_list[i].name; i++)
59 			seq_puts(seq, " 0");
60 
61 		return;
62 	}
63 
64 	for (i = 0; mptcp_snmp_list[i].name; i++)
65 		seq_printf(seq, " %lu",
66 			   snmp_fold_field(net->mib.mptcp_statistics,
67 					   mptcp_snmp_list[i].entry));
68 	seq_putc(seq, '\n');
69 }
70