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("MPCapableSYNTX", MPTCP_MIB_MPCAPABLEACTIVE), 14 SNMP_MIB_ITEM("MPCapableSYNACKRX", MPTCP_MIB_MPCAPABLEACTIVEACK), 15 SNMP_MIB_ITEM("MPCapableACKRX", MPTCP_MIB_MPCAPABLEPASSIVEACK), 16 SNMP_MIB_ITEM("MPCapableFallbackACK", MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK), 17 SNMP_MIB_ITEM("MPCapableFallbackSYNACK", MPTCP_MIB_MPCAPABLEACTIVEFALLBACK), 18 SNMP_MIB_ITEM("MPCapableSYNTXDrop", MPTCP_MIB_MPCAPABLEACTIVEDROP), 19 SNMP_MIB_ITEM("MPCapableSYNTXDisabled", MPTCP_MIB_MPCAPABLEACTIVEDISABLED), 20 SNMP_MIB_ITEM("MPFallbackTokenInit", MPTCP_MIB_TOKENFALLBACKINIT), 21 SNMP_MIB_ITEM("MPTCPRetrans", MPTCP_MIB_RETRANSSEGS), 22 SNMP_MIB_ITEM("MPJoinNoTokenFound", MPTCP_MIB_JOINNOTOKEN), 23 SNMP_MIB_ITEM("MPJoinSynRx", MPTCP_MIB_JOINSYNRX), 24 SNMP_MIB_ITEM("MPJoinSynBackupRx", MPTCP_MIB_JOINSYNBACKUPRX), 25 SNMP_MIB_ITEM("MPJoinSynAckRx", MPTCP_MIB_JOINSYNACKRX), 26 SNMP_MIB_ITEM("MPJoinSynAckBackupRx", MPTCP_MIB_JOINSYNACKBACKUPRX), 27 SNMP_MIB_ITEM("MPJoinSynAckHMacFailure", MPTCP_MIB_JOINSYNACKMAC), 28 SNMP_MIB_ITEM("MPJoinAckRx", MPTCP_MIB_JOINACKRX), 29 SNMP_MIB_ITEM("MPJoinAckHMacFailure", MPTCP_MIB_JOINACKMAC), 30 SNMP_MIB_ITEM("MPJoinSynTx", MPTCP_MIB_JOINSYNTX), 31 SNMP_MIB_ITEM("MPJoinSynTxCreatSkErr", MPTCP_MIB_JOINSYNTXCREATSKERR), 32 SNMP_MIB_ITEM("MPJoinSynTxBindErr", MPTCP_MIB_JOINSYNTXBINDERR), 33 SNMP_MIB_ITEM("MPJoinSynTxConnectErr", MPTCP_MIB_JOINSYNTXCONNECTERR), 34 SNMP_MIB_ITEM("DSSNotMatching", MPTCP_MIB_DSSNOMATCH), 35 SNMP_MIB_ITEM("DSSCorruptionFallback", MPTCP_MIB_DSSCORRUPTIONFALLBACK), 36 SNMP_MIB_ITEM("DSSCorruptionReset", MPTCP_MIB_DSSCORRUPTIONRESET), 37 SNMP_MIB_ITEM("InfiniteMapTx", MPTCP_MIB_INFINITEMAPTX), 38 SNMP_MIB_ITEM("InfiniteMapRx", MPTCP_MIB_INFINITEMAPRX), 39 SNMP_MIB_ITEM("DSSNoMatchTCP", MPTCP_MIB_DSSTCPMISMATCH), 40 SNMP_MIB_ITEM("DataCsumErr", MPTCP_MIB_DATACSUMERR), 41 SNMP_MIB_ITEM("OFOQueueTail", MPTCP_MIB_OFOQUEUETAIL), 42 SNMP_MIB_ITEM("OFOQueue", MPTCP_MIB_OFOQUEUE), 43 SNMP_MIB_ITEM("OFOMerge", MPTCP_MIB_OFOMERGE), 44 SNMP_MIB_ITEM("NoDSSInWindow", MPTCP_MIB_NODSSWINDOW), 45 SNMP_MIB_ITEM("DuplicateData", MPTCP_MIB_DUPDATA), 46 SNMP_MIB_ITEM("AddAddr", MPTCP_MIB_ADDADDR), 47 SNMP_MIB_ITEM("AddAddrTx", MPTCP_MIB_ADDADDRTX), 48 SNMP_MIB_ITEM("AddAddrTxDrop", MPTCP_MIB_ADDADDRTXDROP), 49 SNMP_MIB_ITEM("EchoAdd", MPTCP_MIB_ECHOADD), 50 SNMP_MIB_ITEM("EchoAddTx", MPTCP_MIB_ECHOADDTX), 51 SNMP_MIB_ITEM("EchoAddTxDrop", MPTCP_MIB_ECHOADDTXDROP), 52 SNMP_MIB_ITEM("PortAdd", MPTCP_MIB_PORTADD), 53 SNMP_MIB_ITEM("AddAddrDrop", MPTCP_MIB_ADDADDRDROP), 54 SNMP_MIB_ITEM("MPJoinPortSynRx", MPTCP_MIB_JOINPORTSYNRX), 55 SNMP_MIB_ITEM("MPJoinPortSynAckRx", MPTCP_MIB_JOINPORTSYNACKRX), 56 SNMP_MIB_ITEM("MPJoinPortAckRx", MPTCP_MIB_JOINPORTACKRX), 57 SNMP_MIB_ITEM("MismatchPortSynRx", MPTCP_MIB_MISMATCHPORTSYNRX), 58 SNMP_MIB_ITEM("MismatchPortAckRx", MPTCP_MIB_MISMATCHPORTACKRX), 59 SNMP_MIB_ITEM("RmAddr", MPTCP_MIB_RMADDR), 60 SNMP_MIB_ITEM("RmAddrDrop", MPTCP_MIB_RMADDRDROP), 61 SNMP_MIB_ITEM("RmAddrTx", MPTCP_MIB_RMADDRTX), 62 SNMP_MIB_ITEM("RmAddrTxDrop", MPTCP_MIB_RMADDRTXDROP), 63 SNMP_MIB_ITEM("RmSubflow", MPTCP_MIB_RMSUBFLOW), 64 SNMP_MIB_ITEM("MPPrioTx", MPTCP_MIB_MPPRIOTX), 65 SNMP_MIB_ITEM("MPPrioRx", MPTCP_MIB_MPPRIORX), 66 SNMP_MIB_ITEM("MPFailTx", MPTCP_MIB_MPFAILTX), 67 SNMP_MIB_ITEM("MPFailRx", MPTCP_MIB_MPFAILRX), 68 SNMP_MIB_ITEM("MPFastcloseTx", MPTCP_MIB_MPFASTCLOSETX), 69 SNMP_MIB_ITEM("MPFastcloseRx", MPTCP_MIB_MPFASTCLOSERX), 70 SNMP_MIB_ITEM("MPRstTx", MPTCP_MIB_MPRSTTX), 71 SNMP_MIB_ITEM("MPRstRx", MPTCP_MIB_MPRSTRX), 72 SNMP_MIB_ITEM("RcvPruned", MPTCP_MIB_RCVPRUNED), 73 SNMP_MIB_ITEM("SubflowStale", MPTCP_MIB_SUBFLOWSTALE), 74 SNMP_MIB_ITEM("SubflowRecover", MPTCP_MIB_SUBFLOWRECOVER), 75 SNMP_MIB_ITEM("SndWndShared", MPTCP_MIB_SNDWNDSHARED), 76 SNMP_MIB_ITEM("RcvWndShared", MPTCP_MIB_RCVWNDSHARED), 77 SNMP_MIB_ITEM("RcvWndConflictUpdate", MPTCP_MIB_RCVWNDCONFLICTUPDATE), 78 SNMP_MIB_ITEM("RcvWndConflict", MPTCP_MIB_RCVWNDCONFLICT), 79 SNMP_MIB_ITEM("MPCurrEstab", MPTCP_MIB_CURRESTAB), 80 SNMP_MIB_ITEM("Blackhole", MPTCP_MIB_BLACKHOLE), 81 SNMP_MIB_SENTINEL 82 }; 83 84 /* mptcp_mib_alloc - allocate percpu mib counters 85 * 86 * These are allocated when the first mptcp socket is created so 87 * we do not waste percpu memory if mptcp isn't in use. 88 */ 89 bool mptcp_mib_alloc(struct net *net) 90 { 91 struct mptcp_mib __percpu *mib = alloc_percpu(struct mptcp_mib); 92 93 if (!mib) 94 return false; 95 96 if (cmpxchg(&net->mib.mptcp_statistics, NULL, mib)) 97 free_percpu(mib); 98 99 return true; 100 } 101 102 void mptcp_seq_show(struct seq_file *seq) 103 { 104 unsigned long sum[ARRAY_SIZE(mptcp_snmp_list) - 1]; 105 struct net *net = seq->private; 106 int i; 107 108 seq_puts(seq, "MPTcpExt:"); 109 for (i = 0; mptcp_snmp_list[i].name; i++) 110 seq_printf(seq, " %s", mptcp_snmp_list[i].name); 111 112 seq_puts(seq, "\nMPTcpExt:"); 113 114 memset(sum, 0, sizeof(sum)); 115 if (net->mib.mptcp_statistics) 116 snmp_get_cpu_field_batch(sum, mptcp_snmp_list, 117 net->mib.mptcp_statistics); 118 119 for (i = 0; mptcp_snmp_list[i].name; i++) 120 seq_printf(seq, " %lu", sum[i]); 121 122 seq_putc(seq, '\n'); 123 } 124