linux/net/mptcp/mib.c
<<
>>
Prefs
   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
  11static 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("MPFallbackTokenInit", MPTCP_MIB_TOKENFALLBACKINIT),
  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),
  28        SNMP_MIB_ITEM("DSSNoMatchTCP", MPTCP_MIB_DSSTCPMISMATCH),
  29        SNMP_MIB_ITEM("DataCsumErr", MPTCP_MIB_DATACSUMERR),
  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),
  35        SNMP_MIB_ITEM("AddAddr", MPTCP_MIB_ADDADDR),
  36        SNMP_MIB_ITEM("EchoAdd", MPTCP_MIB_ECHOADD),
  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),
  43        SNMP_MIB_ITEM("RmAddr", MPTCP_MIB_RMADDR),
  44        SNMP_MIB_ITEM("RmSubflow", MPTCP_MIB_RMSUBFLOW),
  45        SNMP_MIB_ITEM("MPPrioTx", MPTCP_MIB_MPPRIOTX),
  46        SNMP_MIB_ITEM("MPPrioRx", MPTCP_MIB_MPPRIORX),
  47        SNMP_MIB_ITEM("RcvPruned", MPTCP_MIB_RCVPRUNED),
  48        SNMP_MIB_SENTINEL
  49};
  50
  51/* mptcp_mib_alloc - allocate percpu mib counters
  52 *
  53 * These are allocated when the first mptcp socket is created so
  54 * we do not waste percpu memory if mptcp isn't in use.
  55 */
  56bool mptcp_mib_alloc(struct net *net)
  57{
  58        struct mptcp_mib __percpu *mib = alloc_percpu(struct mptcp_mib);
  59
  60        if (!mib)
  61                return false;
  62
  63        if (cmpxchg(&net->mib.mptcp_statistics, NULL, mib))
  64                free_percpu(mib);
  65
  66        return true;
  67}
  68
  69void mptcp_seq_show(struct seq_file *seq)
  70{
  71        struct net *net = seq->private;
  72        int i;
  73
  74        seq_puts(seq, "MPTcpExt:");
  75        for (i = 0; mptcp_snmp_list[i].name; i++)
  76                seq_printf(seq, " %s", mptcp_snmp_list[i].name);
  77
  78        seq_puts(seq, "\nMPTcpExt:");
  79
  80        if (!net->mib.mptcp_statistics) {
  81                for (i = 0; mptcp_snmp_list[i].name; i++)
  82                        seq_puts(seq, " 0");
  83
  84                seq_putc(seq, '\n');
  85                return;
  86        }
  87
  88        for (i = 0; mptcp_snmp_list[i].name; i++)
  89                seq_printf(seq, " %lu",
  90                           snmp_fold_field(net->mib.mptcp_statistics,
  91                                           mptcp_snmp_list[i].entry));
  92        seq_putc(seq, '\n');
  93}
  94