Florian Westphal | fc51895 | 2020-03-27 14:48:50 -0700 | [diff] [blame] | 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), |
Paolo Abeni | 5695eb8 | 2021-04-01 16:19:42 -0700 | [diff] [blame] | 13 | SNMP_MIB_ITEM("MPCapableSYNTX", MPTCP_MIB_MPCAPABLEACTIVE), |
| 14 | SNMP_MIB_ITEM("MPCapableSYNACKRX", MPTCP_MIB_MPCAPABLEACTIVEACK), |
Florian Westphal | fc51895 | 2020-03-27 14:48:50 -0700 | [diff] [blame] | 15 | SNMP_MIB_ITEM("MPCapableACKRX", MPTCP_MIB_MPCAPABLEPASSIVEACK), |
| 16 | SNMP_MIB_ITEM("MPCapableFallbackACK", MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK), |
| 17 | SNMP_MIB_ITEM("MPCapableFallbackSYNACK", MPTCP_MIB_MPCAPABLEACTIVEFALLBACK), |
Paolo Abeni | a16195e | 2021-04-01 16:19:41 -0700 | [diff] [blame] | 18 | SNMP_MIB_ITEM("MPFallbackTokenInit", MPTCP_MIB_TOKENFALLBACKINIT), |
Florian Westphal | fc51895 | 2020-03-27 14:48:50 -0700 | [diff] [blame] | 19 | SNMP_MIB_ITEM("MPTCPRetrans", MPTCP_MIB_RETRANSSEGS), |
| 20 | SNMP_MIB_ITEM("MPJoinNoTokenFound", MPTCP_MIB_JOINNOTOKEN), |
| 21 | SNMP_MIB_ITEM("MPJoinSynRx", MPTCP_MIB_JOINSYNRX), |
| 22 | SNMP_MIB_ITEM("MPJoinSynAckRx", MPTCP_MIB_JOINSYNACKRX), |
| 23 | SNMP_MIB_ITEM("MPJoinSynAckHMacFailure", MPTCP_MIB_JOINSYNACKMAC), |
| 24 | SNMP_MIB_ITEM("MPJoinAckRx", MPTCP_MIB_JOINACKRX), |
| 25 | SNMP_MIB_ITEM("MPJoinAckHMacFailure", MPTCP_MIB_JOINACKMAC), |
| 26 | SNMP_MIB_ITEM("DSSNotMatching", MPTCP_MIB_DSSNOMATCH), |
| 27 | SNMP_MIB_ITEM("InfiniteMapRx", MPTCP_MIB_INFINITEMAPRX), |
Paolo Abeni | 06285da | 2021-06-21 15:54:37 -0700 | [diff] [blame] | 28 | SNMP_MIB_ITEM("DSSNoMatchTCP", MPTCP_MIB_DSSTCPMISMATCH), |
Geliang Tang | fe3ab1c | 2021-06-17 16:46:18 -0700 | [diff] [blame] | 29 | SNMP_MIB_ITEM("DataCsumErr", MPTCP_MIB_DATACSUMERR), |
Paolo Abeni | 06242e4 | 2020-09-14 10:01:14 +0200 | [diff] [blame] | 30 | SNMP_MIB_ITEM("OFOQueueTail", MPTCP_MIB_OFOQUEUETAIL), |
| 31 | SNMP_MIB_ITEM("OFOQueue", MPTCP_MIB_OFOQUEUE), |
| 32 | SNMP_MIB_ITEM("OFOMerge", MPTCP_MIB_OFOMERGE), |
| 33 | SNMP_MIB_ITEM("NoDSSInWindow", MPTCP_MIB_NODSSWINDOW), |
| 34 | SNMP_MIB_ITEM("DuplicateData", MPTCP_MIB_DUPDATA), |
Geliang Tang | a877de06 | 2020-09-24 08:29:51 +0800 | [diff] [blame] | 35 | SNMP_MIB_ITEM("AddAddr", MPTCP_MIB_ADDADDR), |
| 36 | SNMP_MIB_ITEM("EchoAdd", MPTCP_MIB_ECHOADD), |
Geliang Tang | 2fbdd9e | 2021-02-01 15:09:19 -0800 | [diff] [blame] | 37 | SNMP_MIB_ITEM("PortAdd", MPTCP_MIB_PORTADD), |
| 38 | SNMP_MIB_ITEM("MPJoinPortSynRx", MPTCP_MIB_JOINPORTSYNRX), |
| 39 | SNMP_MIB_ITEM("MPJoinPortSynAckRx", MPTCP_MIB_JOINPORTSYNACKRX), |
| 40 | SNMP_MIB_ITEM("MPJoinPortAckRx", MPTCP_MIB_JOINPORTACKRX), |
| 41 | SNMP_MIB_ITEM("MismatchPortSynRx", MPTCP_MIB_MISMATCHPORTSYNRX), |
| 42 | SNMP_MIB_ITEM("MismatchPortAckRx", MPTCP_MIB_MISMATCHPORTACKRX), |
Geliang Tang | 7a7e52e | 2020-09-24 08:29:56 +0800 | [diff] [blame] | 43 | SNMP_MIB_ITEM("RmAddr", MPTCP_MIB_RMADDR), |
| 44 | SNMP_MIB_ITEM("RmSubflow", MPTCP_MIB_RMSUBFLOW), |
Geliang Tang | 0be2ac2 | 2021-01-08 16:48:01 -0800 | [diff] [blame] | 45 | SNMP_MIB_ITEM("MPPrioTx", MPTCP_MIB_MPPRIOTX), |
| 46 | SNMP_MIB_ITEM("MPPrioRx", MPTCP_MIB_MPPRIORX), |
Geliang Tang | eb7f336 | 2021-08-24 16:26:18 -0700 | [diff] [blame] | 47 | SNMP_MIB_ITEM("MPFailTx", MPTCP_MIB_MPFAILTX), |
| 48 | SNMP_MIB_ITEM("MPFailRx", MPTCP_MIB_MPFAILRX), |
Paolo Abeni | ce599c5 | 2021-07-09 17:20:51 -0700 | [diff] [blame] | 49 | SNMP_MIB_ITEM("RcvPruned", MPTCP_MIB_RCVPRUNED), |
Paolo Abeni | fc1b4e3 | 2021-08-13 15:15:46 -0700 | [diff] [blame] | 50 | SNMP_MIB_ITEM("SubflowStale", MPTCP_MIB_SUBFLOWSTALE), |
| 51 | SNMP_MIB_ITEM("SubflowRecover", MPTCP_MIB_SUBFLOWRECOVER), |
Florian Westphal | fc51895 | 2020-03-27 14:48:50 -0700 | [diff] [blame] | 52 | SNMP_MIB_SENTINEL |
| 53 | }; |
| 54 | |
| 55 | /* mptcp_mib_alloc - allocate percpu mib counters |
| 56 | * |
| 57 | * These are allocated when the first mptcp socket is created so |
| 58 | * we do not waste percpu memory if mptcp isn't in use. |
| 59 | */ |
| 60 | bool mptcp_mib_alloc(struct net *net) |
| 61 | { |
| 62 | struct mptcp_mib __percpu *mib = alloc_percpu(struct mptcp_mib); |
| 63 | |
| 64 | if (!mib) |
| 65 | return false; |
| 66 | |
| 67 | if (cmpxchg(&net->mib.mptcp_statistics, NULL, mib)) |
| 68 | free_percpu(mib); |
| 69 | |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | void mptcp_seq_show(struct seq_file *seq) |
| 74 | { |
Eric Dumazet | acbd0c8 | 2021-09-29 18:03:33 -0700 | [diff] [blame] | 75 | unsigned long sum[ARRAY_SIZE(mptcp_snmp_list) - 1]; |
Florian Westphal | fc51895 | 2020-03-27 14:48:50 -0700 | [diff] [blame] | 76 | struct net *net = seq->private; |
| 77 | int i; |
| 78 | |
| 79 | seq_puts(seq, "MPTcpExt:"); |
| 80 | for (i = 0; mptcp_snmp_list[i].name; i++) |
| 81 | seq_printf(seq, " %s", mptcp_snmp_list[i].name); |
| 82 | |
| 83 | seq_puts(seq, "\nMPTcpExt:"); |
| 84 | |
Eric Dumazet | acbd0c8 | 2021-09-29 18:03:33 -0700 | [diff] [blame] | 85 | memset(sum, 0, sizeof(sum)); |
| 86 | if (net->mib.mptcp_statistics) |
| 87 | snmp_get_cpu_field_batch(sum, mptcp_snmp_list, |
| 88 | net->mib.mptcp_statistics); |
Florian Westphal | fc51895 | 2020-03-27 14:48:50 -0700 | [diff] [blame] | 89 | |
| 90 | for (i = 0; mptcp_snmp_list[i].name; i++) |
Eric Dumazet | acbd0c8 | 2021-09-29 18:03:33 -0700 | [diff] [blame] | 91 | seq_printf(seq, " %lu", sum[i]); |
| 92 | |
Florian Westphal | fc51895 | 2020-03-27 14:48:50 -0700 | [diff] [blame] | 93 | seq_putc(seq, '\n'); |
| 94 | } |