Skip to contentSkip to conversation

mptcp: add MIB counters

PATCH In review Florian Westphal 4 participants 6 messages Sep 30, 2019 – Oct 2, 2019

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author
#0 lore raw

v2 cover mptcp: add MIB counters

As mentioned earlier, here is v2 of the MIB counter patch set.

I've tossed all counters that aren't used (= have no spot that increments them).

Tests still pass, counters get incremented, you can show them via 'nstat' or "netststat -s".

author
#1 lore raw

PATCH v2 1/2 mptcp: add MIB counter infrastructure

Exported via same /proc file as the Linux TCP MIB counters, so "netstat -s" or "nstat" will show them automatically.

The MPTCP MIB counters are allocated in a distinct pcpu area in order to avoid bloating/wasting TCP pcpu memory.

Counters are allocated once the first MPTCP socket is created in a network namespace and free'd on exit.

If no sockets have been allocated, all-zero mptcp counters are shown.

The MIB counter list is taken from the multipath-tcp.org kernel, but only a few counters have been picked up so far. The counter list can be increased at any time later on.

Signed-off-by Florian Westphal <fw(a)strlen.de>

---
v2: only pick up counters that will be incremented in the next patch.

 include/net/mptcp.h     |  2 ++
 include/net/netns/mib.h |  3 ++
 net/ipv4/af_inet.c      |  4 +++
 net/ipv4/proc.c         |  2 ++
 net/mptcp/Makefile      |  2 +-
 net/mptcp/mib.c         | 65 +++++++++++++++++++++++++++++++++++++++++
 net/mptcp/mib.h         | 37 +++++++++++++++++++++++
 net/mptcp/protocol.c    | 14 ++++++---
 8 files changed, 124 insertions(+), 5 deletions(-)
 create mode 100644 net/mptcp/mib.c
 create mode 100644 net/mptcp/mib.h
include/net/mptcp.h +2 -0
index 50cd1b31ebdd..c4f4fdd57c74 100644
@@ -82,6 +82,7 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
 
 bool mptcp_sk_is_subflow(const struct sock *sk);
 
+void mptcp_seq_show(struct seq_file *seq);
 #else
 
 static inline void mptcp_init(void)
@@ -145,5 +146,6 @@ static inline bool mptcp_sk_is_subflow(const struct sock *sk)
 	return false;
 }
 
+static inline void mptcp_seq_show(struct seq_file *seq) { }
 #endif /* CONFIG_MPTCP */
 #endif /* __NET_MPTCP_H */
include/net/netns/mib.h +3 -0
index 830bdf345b17..59fcaef98fb8 100644
@@ -24,6 +24,9 @@ struct netns_mib {
 #ifdef CONFIG_XFRM_STATISTICS
 	DEFINE_SNMP_STAT(struct linux_xfrm_mib, xfrm_statistics);
 #endif
+#ifdef CONFIG_MPTCP
+	DEFINE_SNMP_STAT(struct mptcp_mib, mptcp_statistics);
+#endif
 };
 
 #endif
net/ipv4/af_inet.c +4 -0
index 70f92aaca411..3b2817267989 100644
@@ -1793,6 +1793,10 @@ static __net_exit void ipv4_mib_exit_net(struct net *net)
 	free_percpu(net->mib.net_statistics);
 	free_percpu(net->mib.ip_statistics);
 	free_percpu(net->mib.tcp_statistics);
+#ifdef CONFIG_MPTCP
+	/* allocated on demand, see mptcp_init_sock() */
+	free_percpu(net->mib.mptcp_statistics);
+#endif
 }
 
 static __net_initdata struct pernet_operations ipv4_mib_ops = {
net/ipv4/proc.c +2 -0
index cc90243ccf76..aeb9be9a9cdb 100644
@@ -32,6 +32,7 @@
 #include <net/icmp.h>
 #include <net/protocol.h>
 #include <net/tcp.h>
+#include <net/mptcp.h>
 #include <net/udp.h>
 #include <net/udplite.h>
 #include <linux/bottom_half.h>
@@ -483,6 +484,7 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
 					     offsetof(struct ipstats_mib, syncp)));
 
 	seq_putc(seq, '\n');
+	mptcp_seq_show(seq);
 	return 0;
 }
 
net/mptcp/Makefile +1 -1
index 289fdf4339c1..77da3f45cc97 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_MPTCP) += mptcp.o
 
-mptcp-y := protocol.o subflow.o options.o token.o crypto.o pm.o ctrl.o
+mptcp-y := protocol.o subflow.o options.o token.o crypto.o pm.o ctrl.o mib.o
net/mptcp/mib.c new file +65 -0

65 lines not on this page · raw message

net/mptcp/mib.h new file +37 -0
new file mode 100644
index 000000000000..d50b53e8209b
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+enum linux_mptcp_mib_field {
+	MPTCP_MIB_NUM = 0,
+	MPTCP_MIB_MPCAPABLEPASSIVE,	/* Received SYN with MP_CAPABLE */
+	MPTCP_MIB_MPCAPABLEPASSIVEACK,	/* Received third ACK with MP_CAPABLE */
+	MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK,/* Server-side fallback during 3-way handshake */
+	MPTCP_MIB_MPCAPABLEACTIVEFALLBACK, /* Client-side fallback during 3-way handshake */
+	MPTCP_MIB_RETRANSSEGS,		/* Segments retransmitted at the MPTCP-level */
+	MPTCP_MIB_JOINNOTOKEN,		/* Received MP_JOIN but the token was not found */
+	MPTCP_MIB_JOINSYNRX,		/* Received a SYN + MP_JOIN */
+	MPTCP_MIB_JOINACKMAC,		/* HMAC was wrong on ACK + MP_JOIN */
+	MPTCP_MIB_DSSNOMATCH,		/* Received a new mapping that did not match the previous one */
+	MPTCP_MIB_INFINITEMAPRX,	/* Received an infinite mapping */
+	__MPTCP_MIB_MAX
+};
+
+#define LINUX_MIB_MPTCP_MAX	__MPTCP_MIB_MAX
+struct mptcp_mib {
+	unsigned long mibs[LINUX_MIB_MPTCP_MAX];
+};
+
+static inline void MPTCP_INC_STATS(struct net *net,
+				   enum linux_mptcp_mib_field field)
+{
+	if (likely(net->mib.mptcp_statistics))
+		SNMP_INC_STATS(net->mib.mptcp_statistics, field);
+}
+
+static inline void __MPTCP_INC_STATS(struct net *net,
+				     enum linux_mptcp_mib_field field)
+{
+	if (likely(net->mib.mptcp_statistics))
+		__SNMP_INC_STATS(net->mib.mptcp_statistics, field);
+}
+
+bool mptcp_mib_alloc(struct net *net);
net/mptcp/protocol.c +10 -4
index 3b13e0576a9b..093c7dac997c 100644
@@ -18,6 +18,7 @@
 #include <net/tcp.h>
 #include <net/mptcp.h>
 #include "protocol.h"
+#include "mib.h"
 
 static struct percpu_counter mptcp_sockets_allocated;
 
@@ -862,16 +863,21 @@ static int __mptcp_init_sock(struct sock *sk)
 
 static int mptcp_init_sock(struct sock *sk)
 {
-	int ret = __mptcp_init_sock(sk);
+	struct net *net = sock_net(sk);
+	int ret;
+
+	if (!mptcp_is_enabled(net))
+		return -ENOPROTOOPT;
 
+	if (unlikely(!net->mib.mptcp_statistics) && !mptcp_mib_alloc(net))
+		return -ENOMEM;
+
+	ret = __mptcp_init_sock(sk);
 	if (ret)
 		return ret;
 
 	sk_sockets_allocated_inc(sk);
 
-	if (!mptcp_is_enabled(sock_net(sk)))
-		return -ENOPROTOOPT;
-
 	return 0;
 }
 
Signature · 1 line
2.21.0
author
#2 lore raw

PATCH v2 2/2 mptcp: increment MIB counters in a few places

In reply to Florian Westphal

Add initial use of the new MIB counters.
We can extend this later on as more features get added.

Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/protocol.c | 13 ++++++++++++-
 net/mptcp/subflow.c  | 21 +++++++++++++++++----
 2 files changed, 29 insertions(+), 5 deletions(-)
net/mptcp/protocol.c +12 -1
index 093c7dac997c..9858c9bdf644 100644
@@ -491,6 +491,7 @@ static enum mapping_status mptcp_get_mapping(struct sock *ssk)
 
 	if (mpext->data_len == 0) {
 		pr_err("Infinite mapping not handled");
+		MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_INFINITEMAPRX);
 		ret = MAPPING_MISSING;
 		goto del_out;
 	} else if (mpext->subflow_seq == 0 &&
@@ -514,8 +515,10 @@ static enum mapping_status mptcp_get_mapping(struct sock *ssk)
 		 */
 		if (subflow->map_seq != map_seq ||
 		    subflow->map_subflow_seq != mpext->subflow_seq ||
-		    subflow->map_data_len != mpext->data_len)
+		    subflow->map_data_len != mpext->data_len) {
+			MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSNOMATCH);
 			pr_warn("Replaced mapping before it was done");
+		}
 	}
 
 	subflow->map_seq = map_seq;
@@ -822,6 +825,7 @@ static void mptcp_retransmit(struct work_struct *work)
 		if (ret < 0)
 			break;
 
+		MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RETRANSSEGS);
 		copied += ret;
 		dfrag->data_len -= ret;
 	}
@@ -1002,7 +1006,10 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 		subflow->conn = new_mptcp_sock;
 		list_add(&subflow->node, &msk->conn_list);
 		bh_unlock_sock(new_mptcp_sock);
+
+		__MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPCAPABLEPASSIVEACK);
 		local_bh_enable();
+
 		inet_sk_state_store(newsk, TCP_ESTABLISHED);
 		release_sock(sk);
 	} else {
@@ -1010,6 +1017,8 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 		tcp_sk(newsk)->is_mptcp = 0;
 		new_sock->sk = NULL;
 		sock_release(new_sock);
+
+		MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK);
 	}
 
 	return newsk;
@@ -1158,6 +1167,8 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 		msk->subflow = NULL;
 		bh_unlock_sock(sk);
 		local_bh_enable();
+	} else {
+		MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPCAPABLEACTIVEFALLBACK);
 	}
 	inet_sk_state_store(sk, TCP_ESTABLISHED);
 }
net/mptcp/subflow.c +17 -4
index c86ce35580cd..c63ddd899acb 100644
@@ -17,6 +17,13 @@
 #include <net/tcp.h>
 #include <net/mptcp.h>
 #include "protocol.h"
+#include "mib.h"
+
+static inline void SUBFLOW_REQ_INC_STATS(struct request_sock *req,
+					 enum linux_mptcp_mib_field field)
+{
+	MPTCP_INC_STATS(sock_net(req_to_sk(req)), field);
+}
 
 static int subflow_rebuild_header(struct sock *sk)
 {
@@ -62,8 +69,7 @@ static bool subflow_token_join_request(struct request_sock *req,
 
 	msk = mptcp_token_get_sock(subflow_req->token);
 	if (!msk) {
-		pr_debug("subflow_req=%p, token=%u - not found\n",
-			 subflow_req, subflow_req->token);
+		SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINNOTOKEN);
 		return false;
 	}
 
@@ -103,8 +109,14 @@ static void subflow_v4_init_req(struct request_sock *req,
 	subflow_req->mp_capable = 0;
 	subflow_req->mp_join = 0;
 
-	if (rx_opt.mptcp.mp_capable && rx_opt.mptcp.mp_join)
-		return;
+	if (rx_opt.mptcp.mp_capable) {
+		SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_MPCAPABLEPASSIVE);
+
+		if (rx_opt.mptcp.mp_join)
+			return;
+	} else if (rx_opt.mptcp.mp_join) {
+		SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINSYNRX);
+	}
 
 	if (rx_opt.mptcp.mp_capable && listener->request_mptcp) {
 		int err;
@@ -180,6 +192,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
 			 subflow_ctx(sk), subflow->thmac,
 			 subflow->remote_nonce);
 		if (!subflow_thmac_valid(subflow)) {
+			MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINACKMAC);
 			subflow->mp_join = 0;
 			// @@ need to trigger RST
 			return;
Signature · 1 line
2.21.0
#3 lore raw
In reply to Florian Westphal

Hi,

Quoted 7 lines · Florian Westphal

As mentioned earlier, here is v2 of the MIB counter patch set.

I've tossed all counters that aren't used (= have no spot that increments them).

Tests still pass, counters get incremented, you can show them via 'nstat' or "netststat -s".

Thanks Florian, the patches LGTM!

/P

#4 lore raw
In reply to Florian Westphal
Quoted 8 lines · Florian Westphal

As mentioned earlier, here is v2 of the MIB counter patch set.

I've tossed all counters that aren't used (= have no spot that increments them).

Tests still pass, counters get incremented, you can show them via 'nstat' or "netststat -s".

Thanks for the updated patches, Florian. v2 looks good to me.

--
Mat Martineau
Intel

#5 lore raw

Hi Florian, Paolo, Mat,

Quoted 5 lines · Mat Martineau
Quoted 2 lines · Florian Westphal

As mentioned earlier, here is v2 of the MIB counter patch set.

Quoted 8 lines
Quoted 6 lines

I've tossed all counters that aren't used (= have no spot that increments them).

Tests still pass, counters get incremented, you can show them via 'nstat' or "netststat -s".

Thanks for the updated patches, Florian. v2 looks good to me.

Thank you for the patches and the reviews!

Just added at the end of the series.

I confirm that the tests are still passing!

Cheers,
Matt

Quoted 6 lines
Signature · 5 lines
Mat Martineau
Intel
_______________________________________________
mptcp mailing list -- mptcp(a)lists.01.org
To unsubscribe send an email to mptcp-leave(a)lists.01.org
Signature · 5 lines
Matthieu Baerts | R&D Engineer
matthieu.baerts(a)tessares.net
Tessares SA | Hybrid Access Solutions
www.tessares.net
1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium