Skip to contentSkip to conversation

mptcp: msk diag support

PATCH In review Paolo Abeni 3 participants 10 messages Jun 25, 2020 – Jun 26, 2020

Subsystems (4)
lore
Share & tools
lore

Paolo Abeni

author
#0 lore raw

cover mptcp: msk diag support

This introduces basic mptcp sockets diag support.
As IPPROTO_MPTCP excedes 8 bits, we need some changes at the inet_diag level:
a new attribute is introduced to allow user-space providing u32 protocol values.

Patch 2 introduces new token APIs to allow traversing the existing msks, while patch 3 bring in the actual diag implementation.

Paolo Abeni (3):
inet_diag: support for wider protocol numbers
mptcp: add msk interations helpers
mptcp: add MPTCP socket diag interface

 include/uapi/linux/inet_diag.h |   1 +
 include/uapi/linux/mptcp.h     |  15 ++++
 net/core/sock.c                |   1 +
 net/ipv4/inet_diag.c           |  63 +++++++++----
 net/mptcp/Kconfig              |   4 +
 net/mptcp/Makefile             |   2 +
 net/mptcp/mptcp_diag.c         | 160 +++++++++++++++++++++++++++++++++
 net/mptcp/options.c            |   6 +-
 net/mptcp/protocol.h           |   3 +
 net/mptcp/token.c              |  83 +++++++++++++++++
 10 files changed, 318 insertions(+), 20 deletions(-)
 create mode 100644 net/mptcp/mptcp_diag.c
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH 1/3 inet_diag: support for wider protocol numbers

After commit bf9765145b85 ("sock: Make sk_protocol a 16-bit value") the current size of 'sdiag_protocol' is not sufficient to represent the possible protocol values.

This change introduces a new inet diag request attribute to let user space specify the relevant protocol number using u32 values.

The attribute is parsed by inet diag core on get/dump command and the extended protocol value, if available, is preferred to 'sdiag_protocol' to lookup the diag handler.

The parse attributed are exposed to all the diag handlers via the cb->data.

Note that inet_diag_dump_one_icsk() is left unmodified, as it will not be used by protocol using the extended attribute.

Suggested-by David S. Miller <davem(a)davemloft.net>
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 include/uapi/linux/inet_diag.h |  1 +
 net/core/sock.c                |  1 +
 net/ipv4/inet_diag.c           | 63 +++++++++++++++++++++++++---------
 3 files changed, 48 insertions(+), 17 deletions(-)
include/uapi/linux/inet_diag.h +1 -0
index e6f183ee8417..5ba122c1949a 100644
@@ -65,6 +65,7 @@ enum {
 	INET_DIAG_REQ_NONE,
 	INET_DIAG_REQ_BYTECODE,
 	INET_DIAG_REQ_SK_BPF_STORAGES,
+	INET_DIAG_REQ_PROTOCOL,
 	__INET_DIAG_REQ_MAX,
 };
 
net/core/sock.c +1 -0
index 6c4acf1f0220..b359e29bb737 100644
@@ -3573,6 +3573,7 @@ int sock_load_diag_module(int family, int protocol)
 #ifdef CONFIG_INET
 	if (family == AF_INET &&
 	    protocol != IPPROTO_RAW &&
+	    protocol < MAX_INET_PROTOS &&
 	    !rcu_access_pointer(inet_protos[protocol]))
 		return -ENOENT;
 #endif
net/ipv4/inet_diag.c +46 -17

131 lines not on this page · raw message

Signature · 1 line
2.26.2
author
#2 lore raw

PATCH 2/3 mptcp: add msk interations helpers

In reply to Paolo Abeni

mptcp_token_iter_start(), mptcp_token_iter_next() and mptcp_token_iter_stop() allow traversing all the MPTCP sockets inside the token container with a quite standard iterator semantic.

Will be used by the next patch.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.h |  3 ++
 net/mptcp/token.c    | 83 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)
net/mptcp/protocol.h +3 -0
index 2c3deede2469..835d7781ecd7 100644
@@ -398,6 +398,9 @@ int mptcp_token_new_connect(struct sock *sk);
 void mptcp_token_accept(struct mptcp_subflow_request_sock *r,
 			struct mptcp_sock *msk);
 struct mptcp_sock *mptcp_token_get_sock(u32 token);
+struct mptcp_sock *mptcp_token_iter_start(long *s_slot, long *s_num);
+struct mptcp_sock *mptcp_token_iter_next(long *s_slot, long *s_num);
+void mptcp_token_iter_stop(long slot);
 void mptcp_token_destroy(struct mptcp_sock *msk);
 
 void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn);
net/mptcp/token.c +83 -0

89 lines not on this page · raw message

Signature · 1 line
2.26.2
author
#3 lore raw

PATCH 3/3 mptcp: add MPTCP socket diag interface

In reply to Paolo Abeni

exposes basic inet socket attribute, plus some MPTCP socket fields comprising PM status and MPTCP-level sequence numbers.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 include/uapi/linux/mptcp.h |  15 ++++
 net/mptcp/Kconfig          |   4 +
 net/mptcp/Makefile         |   2 +
 net/mptcp/mptcp_diag.c     | 160 +++++++++++++++++++++++++++++++++++++
 net/mptcp/options.c        |   6 +-
 5 files changed, 184 insertions(+), 3 deletions(-)
 create mode 100644 net/mptcp/mptcp_diag.c
include/uapi/linux/mptcp.h +15 -0
index 5f2c77082d9e..69a6d5a0c56d 100644
@@ -86,4 +86,19 @@ enum {
 	__MPTCP_PM_CMD_AFTER_LAST
 };
 
+struct mptcp_info {
+	__u8	mptcpi_subflows;
+	__u8	mptcpi_add_addr_signal;
+	__u8	mptcpi_add_addr_accepted;
+	__u8	mptcpi_subflows_max;
+	__u8	mptcpi_add_addr_signal_max;
+	__u8	mptcpi_add_addr_accepted_max;
+	__u8	mptcpi_fallback;
+	__u8	mptcpi_can_ack;
+	__u32	mptcpi_token;
+	__u64	mptcpi_write_seq;
+	__u64	mptcpi_snd_una;
+	__u64	mptcpi_rcv_nxt;
+};
+
 #endif /* _UAPI_MPTCP_H */
net/mptcp/Kconfig +4 -0
index 0ec787d8b9a2..97c29caa65f3 100644
@@ -14,6 +14,10 @@ config MPTCP
 
 if MPTCP
 
+config INET_MPTCP_DIAG
+	depends on INET_DIAG
+	def_tristate INET_DIAG
+
 config MPTCP_IPV6
 	bool "MPTCP: IPv6 support for Multipath TCP"
 	select IPV6
net/mptcp/Makefile +2 -0
index c53f9b845523..2360cbd27d59 100644
@@ -4,6 +4,8 @@ obj-$(CONFIG_MPTCP) += mptcp.o
 mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \
 	   mib.o pm_netlink.o
 
+obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.o
+
 mptcp_crypto_test-objs := crypto_test.o
 mptcp_token_test-objs := token_test.o
 obj-$(CONFIG_MPTCP_KUNIT_TESTS) += mptcp_crypto_test.o mptcp_token_test.o
net/mptcp/mptcp_diag.c new file +160 -0

160 lines not on this page · raw message

net/mptcp/options.c +3 -3
index f464f8669dfc..46470194b8ca 100644
@@ -451,9 +451,9 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
 }
 
 static void mptcp_write_data_fin(struct mptcp_subflow_context *subflow,
-				 struct mptcp_ext *ext)
+				 struct sk_buff *skb, struct mptcp_ext *ext)
 {
-	if (!ext->use_map) {
+	if (!ext->use_map || !skb->len) {
 		/* RFC6824 requires a DSS mapping with specific values
 		 * if DATA_FIN is set but no data payload is mapped
 		 */
@@ -505,7 +505,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 			opts->ext_copy = *mpext;
 
 		if (skb && tcp_fin && subflow->data_fin_tx_enable)
-			mptcp_write_data_fin(subflow, &opts->ext_copy);
+			mptcp_write_data_fin(subflow, skb, &opts->ext_copy);
 		ret = true;
 	}
 
Signature · 1 line
2.26.2
#4 lore raw

[MPTCP] Re: [PATCH 3/3] mptcp: add MPTCP socket diag interface

Hello,

Quoted 193 lines · Paolo Abeni

exposes basic inet socket attribute, plus some MPTCP socket fields comprising PM status and MPTCP-level sequence numbers.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 include/uapi/linux/mptcp.h |  15 ++++
 net/mptcp/Kconfig          |   4 +
 net/mptcp/Makefile         |   2 +
 net/mptcp/mptcp_diag.c     | 160 +++++++++++++++++++++++++++++++++++++
 net/mptcp/options.c        |   6 +-
 5 files changed, 184 insertions(+), 3 deletions(-)
 create mode 100644 net/mptcp/mptcp_diag.c
include/uapi/linux/mptcp.h +15 -0
index 5f2c77082d9e..69a6d5a0c56d 100644
@@ -86,4 +86,19 @@ enum {
 	__MPTCP_PM_CMD_AFTER_LAST
 };
 
+struct mptcp_info {
+	__u8	mptcpi_subflows;
+	__u8	mptcpi_add_addr_signal;
+	__u8	mptcpi_add_addr_accepted;
+	__u8	mptcpi_subflows_max;
+	__u8	mptcpi_add_addr_signal_max;
+	__u8	mptcpi_add_addr_accepted_max;
+	__u8	mptcpi_fallback;
+	__u8	mptcpi_can_ack;
+	__u32	mptcpi_token;
+	__u64	mptcpi_write_seq;
+	__u64	mptcpi_snd_una;
+	__u64	mptcpi_rcv_nxt;
+};
+
 #endif /* _UAPI_MPTCP_H */
net/mptcp/Kconfig +4 -0
index 0ec787d8b9a2..97c29caa65f3 100644
@@ -14,6 +14,10 @@ config MPTCP
 
 if MPTCP
 
+config INET_MPTCP_DIAG
+	depends on INET_DIAG
+	def_tristate INET_DIAG
+
 config MPTCP_IPV6
 	bool "MPTCP: IPv6 support for Multipath TCP"
 	select IPV6
net/mptcp/Makefile +2 -0
index c53f9b845523..2360cbd27d59 100644
@@ -4,6 +4,8 @@ obj-$(CONFIG_MPTCP) += mptcp.o
 mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \
 	   mib.o pm_netlink.o
 
+obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.o
+
 mptcp_crypto_test-objs := crypto_test.o
 mptcp_token_test-objs := token_test.o
 obj-$(CONFIG_MPTCP_KUNIT_TESTS) += mptcp_crypto_test.o mptcp_token_test.o
net/mptcp/mptcp_diag.c new file +122 -0
new file mode 100644
index 000000000000..a7c801b7f575
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0
+/* MPTCP socket monitoring support
+ *
+ * Copyright (c) 2020 Red Hat
+ *
+ * Author: Paolo Abeni <pabeni(a)redhat.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/net.h>
+#include <linux/inet_diag.h>
+#include <net/netlink.h>
+#include <uapi/linux/mptcp.h>
+#include "protocol.h"
+
+static int sk_diag_dump(struct sock *sk, struct sk_buff *skb,
+			struct netlink_callback *cb,
+			const struct inet_diag_req_v2 *req,
+			struct nlattr *bc, bool net_admin)
+{
+	if (!inet_diag_bc_sk(bc, sk))
+		return 0;
+
+	return inet_sk_diag_fill(sk, inet_csk(sk), skb, cb, req, NLM_F_MULTI,
+				 net_admin);
+}
+
+static int mptcp_diag_dump_one(struct netlink_callback *cb,
+			       const struct inet_diag_req_v2 *req)
+{
+	struct sk_buff *in_skb = cb->skb;
+	struct mptcp_sock *msk = NULL;
+	struct sk_buff *rep;
+	int err = -ENOENT;
+	struct net *net;
+	struct sock *sk;
+
+	net = sock_net(in_skb->sk);
+	msk = mptcp_token_get_sock(req->id.idiag_cookie[0]);
+	if (!msk)
+		goto out_nosk;
+
+	err = -ENOMEM;
+	sk = (struct sock *)msk;
+	rep = nlmsg_new(nla_total_size(sizeof(struct inet_diag_msg)) +
+			inet_diag_msg_attrs_size() +
+			nla_total_size(sizeof(struct mptcp_info)) +
+			nla_total_size(sizeof(struct inet_diag_meminfo)) + 64,
+			GFP_KERNEL);
+	if (!rep)
+		goto out;
+
+	err = inet_sk_diag_fill(sk, inet_csk(sk), rep, cb, req, 0,
+				netlink_net_capable(in_skb, CAP_NET_ADMIN));
+	if (err < 0) {
+		WARN_ON(err == -EMSGSIZE);
+		kfree_skb(rep);
+		goto out;
+	}
+	err = netlink_unicast(net->diag_nlsk, rep, NETLINK_CB(in_skb).portid,
+			      MSG_DONTWAIT);
+	if (err > 0)
+		err = 0;
+out:
+	sock_put(sk);
+
+out_nosk:
+	return err;
+}
+
+static void mptcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
+			    const struct inet_diag_req_v2 *r)
+{
+	bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN);
+	struct net *net = sock_net(skb->sk);
+	struct inet_diag_dump_data *cb_data;
+	struct mptcp_sock *msk;
+	struct nlattr *bc;
+
+	cb_data = cb->data;
+	bc = cb_data->inet_diag_nla_bc;
+
+	for (msk = mptcp_token_iter_start(&cb->args[0], &cb->args[1]);
+	     msk; msk = mptcp_token_iter_next(&cb->args[0], &cb->args[1])) {
+		struct inet_sock *inet;
+		struct sock *sk;
+
+		inet = (struct inet_sock *)msk;
+		sk = (struct sock *)msk;
+		if (!net_eq(sock_net(sk), net))
+			continue;
+		if (!(r->idiag_states & (1 << sk->sk_state)))
+			continue;
+		if (r->sdiag_family != AF_UNSPEC &&
+		    sk->sk_family != r->sdiag_family)
+			continue;
+		if (r->id.idiag_sport != inet->inet_sport &&
+		    r->id.idiag_sport)
+			continue;
+		if (r->id.idiag_dport != inet->inet_dport &&
+		    r->id.idiag_dport)
+			continue;
+
+		if (sk_diag_dump(sk, skb, cb, r, bc, net_admin) < 0) {
+			mptcp_token_iter_stop(cb->args[0]);
+			break;
+		}
+	}
+}
+
+static void mptcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
+				void *_info)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct mptcp_info *info = _info;
+	u8 val;
+
+	r->idiag_rqueue = sk_rmem_alloc_get(sk);
+	r->idiag_wqueue = sk_wmem_alloc_get(sk);
+	if (!info)
+		return;
+

net/mptcp/mptcp_diag.c line 132

Quoted 10 lines
net/mptcp/mptcp_diag.c new file +10 -0
+	info->mptcpi_subflows = READ_ONCE(msk->pm.subflows);
+	info->mptcpi_add_addr_signal = READ_ONCE(msk->pm.add_addr_signaled);
+	info->mptcpi_add_addr_accepted = READ_ONCE(msk->pm.add_addr_accepted);
+	info->mptcpi_subflows_max = READ_ONCE(msk->pm.subflows_max);
+	val = READ_ONCE(msk->pm.add_addr_signal_max);
+	info->mptcpi_add_addr_signal_max = val;
+	val = READ_ONCE(msk->pm.add_addr_accept_max);
+	info->mptcpi_add_addr_accepted_max = val;
+	info->mptcpi_fallback = test_bit(MPTCP_FALLBACK_DONE, &msk->flags);
+	info->mptcpi_can_ack = READ_ONCE(msk->can_ack);

I'm not sure about the can_ack attribute. Isn't it the opposite of mptcpci_fallback?

Also, should we make binary attribtues like fallback just a single bit to safe space?

Christoph

Quoted 58 lines
net/mptcp/mptcp_diag.c new file +28 -0
+	info->mptcpi_token = READ_ONCE(msk->token);
+	info->mptcpi_write_seq = READ_ONCE(msk->write_seq);
+	info->mptcpi_snd_una = atomic64_read(&msk->snd_una);
+	info->mptcpi_rcv_nxt = READ_ONCE(msk->ack_seq);
+}
+
+static const struct inet_diag_handler mptcp_diag_handler = {
+	.dump		 = mptcp_diag_dump,
+	.dump_one	 = mptcp_diag_dump_one,
+	.idiag_get_info  = mptcp_diag_get_info,
+	.idiag_type	 = IPPROTO_MPTCP,
+	.idiag_info_size = sizeof(struct mptcp_info),
+};
+
+int __init mptcp_diag_init(void)
+{
+	return inet_diag_register(&mptcp_diag_handler);
+}
+
+static void __exit mptcp_diag_exit(void)
+{
+	inet_diag_unregister(&mptcp_diag_handler);
+}
+
+module_init(mptcp_diag_init);
+module_exit(mptcp_diag_exit);
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 2-262 /* AF_INET - IPPROTO_MPTCP */);
net/mptcp/options.c +3 -3
index f464f8669dfc..46470194b8ca 100644
@@ -451,9 +451,9 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
 }
 
 static void mptcp_write_data_fin(struct mptcp_subflow_context *subflow,
-				 struct mptcp_ext *ext)
+				 struct sk_buff *skb, struct mptcp_ext *ext)
 {
-	if (!ext->use_map) {
+	if (!ext->use_map || !skb->len) {
 		/* RFC6824 requires a DSS mapping with specific values
 		 * if DATA_FIN is set but no data payload is mapped
 		 */
@@ -505,7 +505,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 			opts->ext_copy = *mpext;
 
 		if (skb && tcp_fin && subflow->data_fin_tx_enable)
-			mptcp_write_data_fin(subflow, &opts->ext_copy);
+			mptcp_write_data_fin(subflow, skb, &opts->ext_copy);
 		ret = true;
 	}
 
Signature · 4 lines
2.26.2
_______________________________________________
mptcp mailing list -- mptcp(a)lists.01.org
To unsubscribe send an email to mptcp-leave(a)lists.01.org
author
#5 lore raw

[MPTCP] Re: [PATCH 3/3] mptcp: add MPTCP socket diag interface

Quoted 201 lines · Christoph Paasch

Hello,

Quoted 198 lines · Paolo Abeni

exposes basic inet socket attribute, plus some MPTCP socket fields comprising PM status and MPTCP-level sequence numbers.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 include/uapi/linux/mptcp.h |  15 ++++
 net/mptcp/Kconfig          |   4 +
 net/mptcp/Makefile         |   2 +
 net/mptcp/mptcp_diag.c     | 160 +++++++++++++++++++++++++++++++++++++
 net/mptcp/options.c        |   6 +-
 5 files changed, 184 insertions(+), 3 deletions(-)
 create mode 100644 net/mptcp/mptcp_diag.c
include/uapi/linux/mptcp.h +15 -0
index 5f2c77082d9e..69a6d5a0c56d 100644
@@ -86,4 +86,19 @@ enum {
 	__MPTCP_PM_CMD_AFTER_LAST
 };
 
+struct mptcp_info {
+	__u8	mptcpi_subflows;
+	__u8	mptcpi_add_addr_signal;
+	__u8	mptcpi_add_addr_accepted;
+	__u8	mptcpi_subflows_max;
+	__u8	mptcpi_add_addr_signal_max;
+	__u8	mptcpi_add_addr_accepted_max;
+	__u8	mptcpi_fallback;
+	__u8	mptcpi_can_ack;
+	__u32	mptcpi_token;
+	__u64	mptcpi_write_seq;
+	__u64	mptcpi_snd_una;
+	__u64	mptcpi_rcv_nxt;
+};
+
 #endif /* _UAPI_MPTCP_H */
net/mptcp/Kconfig +4 -0
index 0ec787d8b9a2..97c29caa65f3 100644
@@ -14,6 +14,10 @@ config MPTCP
 
 if MPTCP
 
+config INET_MPTCP_DIAG
+	depends on INET_DIAG
+	def_tristate INET_DIAG
+
 config MPTCP_IPV6
 	bool "MPTCP: IPv6 support for Multipath TCP"
 	select IPV6
net/mptcp/Makefile +2 -0
index c53f9b845523..2360cbd27d59 100644
@@ -4,6 +4,8 @@ obj-$(CONFIG_MPTCP) += mptcp.o
 mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \
 	   mib.o pm_netlink.o
 
+obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.o
+
 mptcp_crypto_test-objs := crypto_test.o
 mptcp_token_test-objs := token_test.o
 obj-$(CONFIG_MPTCP_KUNIT_TESTS) += mptcp_crypto_test.o mptcp_token_test.o
net/mptcp/mptcp_diag.c new file +127 -0
new file mode 100644
index 000000000000..a7c801b7f575
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0
+/* MPTCP socket monitoring support
+ *
+ * Copyright (c) 2020 Red Hat
+ *
+ * Author: Paolo Abeni <pabeni(a)redhat.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/net.h>
+#include <linux/inet_diag.h>
+#include <net/netlink.h>
+#include <uapi/linux/mptcp.h>
+#include "protocol.h"
+
+static int sk_diag_dump(struct sock *sk, struct sk_buff *skb,
+			struct netlink_callback *cb,
+			const struct inet_diag_req_v2 *req,
+			struct nlattr *bc, bool net_admin)
+{
+	if (!inet_diag_bc_sk(bc, sk))
+		return 0;
+
+	return inet_sk_diag_fill(sk, inet_csk(sk), skb, cb, req, NLM_F_MULTI,
+				 net_admin);
+}
+
+static int mptcp_diag_dump_one(struct netlink_callback *cb,
+			       const struct inet_diag_req_v2 *req)
+{
+	struct sk_buff *in_skb = cb->skb;
+	struct mptcp_sock *msk = NULL;
+	struct sk_buff *rep;
+	int err = -ENOENT;
+	struct net *net;
+	struct sock *sk;
+
+	net = sock_net(in_skb->sk);
+	msk = mptcp_token_get_sock(req->id.idiag_cookie[0]);
+	if (!msk)
+		goto out_nosk;
+
+	err = -ENOMEM;
+	sk = (struct sock *)msk;
+	rep = nlmsg_new(nla_total_size(sizeof(struct inet_diag_msg)) +
+			inet_diag_msg_attrs_size() +
+			nla_total_size(sizeof(struct mptcp_info)) +
+			nla_total_size(sizeof(struct inet_diag_meminfo)) + 64,
+			GFP_KERNEL);
+	if (!rep)
+		goto out;
+
+	err = inet_sk_diag_fill(sk, inet_csk(sk), rep, cb, req, 0,
+				netlink_net_capable(in_skb, CAP_NET_ADMIN));
+	if (err < 0) {
+		WARN_ON(err == -EMSGSIZE);
+		kfree_skb(rep);
+		goto out;
+	}
+	err = netlink_unicast(net->diag_nlsk, rep, NETLINK_CB(in_skb).portid,
+			      MSG_DONTWAIT);
+	if (err > 0)
+		err = 0;
+out:
+	sock_put(sk);
+
+out_nosk:
+	return err;
+}
+
+static void mptcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
+			    const struct inet_diag_req_v2 *r)
+{
+	bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN);
+	struct net *net = sock_net(skb->sk);
+	struct inet_diag_dump_data *cb_data;
+	struct mptcp_sock *msk;
+	struct nlattr *bc;
+
+	cb_data = cb->data;
+	bc = cb_data->inet_diag_nla_bc;
+
+	for (msk = mptcp_token_iter_start(&cb->args[0], &cb->args[1]);
+	     msk; msk = mptcp_token_iter_next(&cb->args[0], &cb->args[1])) {
+		struct inet_sock *inet;
+		struct sock *sk;
+
+		inet = (struct inet_sock *)msk;
+		sk = (struct sock *)msk;
+		if (!net_eq(sock_net(sk), net))
+			continue;
+		if (!(r->idiag_states & (1 << sk->sk_state)))
+			continue;
+		if (r->sdiag_family != AF_UNSPEC &&
+		    sk->sk_family != r->sdiag_family)
+			continue;
+		if (r->id.idiag_sport != inet->inet_sport &&
+		    r->id.idiag_sport)
+			continue;
+		if (r->id.idiag_dport != inet->inet_dport &&
+		    r->id.idiag_dport)
+			continue;
+
+		if (sk_diag_dump(sk, skb, cb, r, bc, net_admin) < 0) {
+			mptcp_token_iter_stop(cb->args[0]);
+			break;
+		}
+	}
+}
+
+static void mptcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
+				void *_info)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct mptcp_info *info = _info;
+	u8 val;
+
+	r->idiag_rqueue = sk_rmem_alloc_get(sk);
+	r->idiag_wqueue = sk_wmem_alloc_get(sk);
+	if (!info)
+		return;
+
+	info->mptcpi_subflows = READ_ONCE(msk->pm.subflows);
+	info->mptcpi_add_addr_signal = READ_ONCE(msk->pm.add_addr_signaled);
+	info->mptcpi_add_addr_accepted = READ_ONCE(msk->pm.add_addr_accepted);
+	info->mptcpi_subflows_max = READ_ONCE(msk->pm.subflows_max);
+	val = READ_ONCE(msk->pm.add_addr_signal_max);
Quoted 8 lines

net/mptcp/mptcp_diag.c line 132

Quoted 5 lines
net/mptcp/mptcp_diag.c new file +5 -0
+	info->mptcpi_add_addr_signal_max = val;
+	val = READ_ONCE(msk->pm.add_addr_accept_max);
+	info->mptcpi_add_addr_accepted_max = val;
+	info->mptcpi_fallback = test_bit(MPTCP_FALLBACK_DONE, &msk->flags);
+	info->mptcpi_can_ack = READ_ONCE(msk->can_ack);

I'm not sure about the can_ack attribute. Isn't it the opposite of mptcpci_fallback?

'can_ack' becomes true when the peer receives the other's end key. Depending on when fallback happens, we can have both can_ack and fallback set. Possibly we may consider renaming the field.

Quoted 2 lines

Also, should we make binary attribtues like fallback just a single bit to safe space?

I can replace 'can_ack' and 'fallback' with a 32bit flags. Perhaps I can use a better name for the first bit (suggestion welcome!) I would opt for 'remote_key', WDYT?

Thanks!

Paolo

#6 lore raw

[MPTCP] Re: [PATCH 3/3] mptcp: add MPTCP socket diag interface

Quoted 1 line · Paolo Abeni

I can replace 'can_ack' and 'fallback' with a 32bit flags.

I support this: in the future we might want to add additinal states to control TCP fallback (specifically, add the possibility to disallow it)

Quoted 2 lines

Perhaps I can use a better name for the first bit (suggestion welcome!) I would opt for 'remote_key', WDYT?

this variable becomes true when it's possible to use the 64-bit key received by the peer, generate the DACK4 / DACK8 number (probably it's used also for other purposes, right?) if so, what about 'remote_key_valid' ?

thanks!

Signature · 1 line
davide
#7 lore raw

[MPTCP] Re: [PATCH 3/3] mptcp: add MPTCP socket diag interface

Quoted 5 lines · Davide Caratti
Quoted 1 line · Paolo Abeni

I can replace 'can_ack' and 'fallback' with a 32bit flags.

I support this: in the future we might want to add additinal states to control TCP fallback (specifically, add the possibility to disallow it)

+1 for 32bit flags.

Quoted 7 lines
Quoted 2 lines

Perhaps I can use a better name for the first bit (suggestion welcome!) I would opt for 'remote_key', WDYT?

this variable becomes true when it's possible to use the 64-bit key received by the peer, generate the DACK4 / DACK8 number (probably it's used also for other purposes, right?) if so, what about 'remote_key_valid' ?

Or "remote_key_set" or "remote_key_received" ?

Because "valid" has a notion that the remote-key could also become "invalid", which is not really the case.

Christoph

author
#8 lore raw
In reply to Paolo Abeni
Quoted 13 lines · Paolo Abeni

This introduces basic mptcp sockets diag support.
As IPPROTO_MPTCP excedes 8 bits, we need some changes at the inet_diag level:
a new attribute is introduced to allow user-space providing u32 protocol values.

Patch 2 introduces new token APIs to allow traversing the existing msks, while patch 3 bring in the actual diag implementation.

Paolo Abeni (3):
inet_diag: support for wider protocol numbers
mptcp: add msk interations helpers
mptcp: add MPTCP socket diag interface

Quoted 12 lines
 include/uapi/linux/inet_diag.h |   1 +
 include/uapi/linux/mptcp.h     |  15 ++++
 net/core/sock.c                |   1 +
 net/ipv4/inet_diag.c           |  63 +++++++++----
 net/mptcp/Kconfig              |   4 +
 net/mptcp/Makefile             |   2 +
 net/mptcp/mptcp_diag.c         | 160 +++++++++++++++++++++++++++++++++
 net/mptcp/options.c            |   6 +-
 net/mptcp/protocol.h           |   3 +
 net/mptcp/token.c              |  83 +++++++++++++++++
 10 files changed, 318 insertions(+), 20 deletions(-)
 create mode 100644 net/mptcp/mptcp_diag.c

Additional note: I'll try do add some basic functional self-tests using mptcp_connect and iproute2 tool. Will create a new script in the mptcp self-tests dir

/P

author
#9 lore raw

PATCH 4/4 selftests/mptcp: add diag interface tests

In reply to Paolo Abeni

basic functional test, triggering the msk diag interface code. Require appropriate iproute2 support, skip elsewhere.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>

---
appending to the already posted series, to avoid re-spamming the other patches. This already catched a bug in patch 3, so v2 will be needed in any case;)

---
 tools/testing/selftests/net/mptcp/diag.sh     | 122 ++++++++++++++++++
 .../selftests/net/mptcp/mptcp_connect.c       |  14 +-
 2 files changed, 132 insertions(+), 4 deletions(-)
 create mode 100755 tools/testing/selftests/net/mptcp/diag.sh
tools/testing/selftests/net/mptcp/diag.sh new file +122 -0
new file mode 100755
index 000000000000..287ed95e75d9
@@ -0,0 +1,122 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
+ns="ns1-$rndh"
+ksft_skip=4
+test_cnt=1
+ret=0
+pids=()
+
+flush_pids()
+{
+	# mptcp_connect in join mode will sleep a bit before completing,
+	# give it some time
+	sleep 1.1
+
+	for pid in ${pids[@]}; do
+		[ -d /proc/$pid ] && kill -9 $pid >/dev/null 2>&1
+	done
+	pids=()
+}
+
+cleanup()
+{
+	ip netns del $ns
+	for pid in ${pids[@]}; do
+		[ -d /proc/$pid ] && kill -9 $pid >/dev/null 2>&1
+	done
+}
+
+ip -Version > /dev/null 2>&1
+if [ $? -ne 0 ];then
+	echo "SKIP: Could not run test without ip tool"
+	exit $ksft_skip
+fi
+ss -h | grep -q MPTCP
+if [ $? -ne 0 ];then
+	echo "SKIP: ss tool does not support MPTCP"
+	exit $ksft_skip
+fi
+
+__chk_nr()
+{
+	local condition="$1"
+	local expected=$2
+	local msg nr
+
+	shift 2
+	msg=$*
+	nr=$(ss -inmHMN $ns | $condition)
+
+	printf "%-50s" "$msg"
+	if [ $nr != $expected ]; then
+		echo "[ fail ] expected $expected found $nr"
+		ret=$test_cnt
+	else
+		echo "[  ok  ]"
+	fi
+	test_cnt=$((test_cnt+1))
+}
+
+chk_msk_nr()
+{
+	__chk_nr "grep -c token:" $*
+}
+
+chk_msk_fallback_nr()
+{
+		__chk_nr "grep -c fallback" $*
+}
+
+chk_msk_ack_nr()
+{
+		__chk_nr "grep -c can_ack" $*
+}
+
+
+trap cleanup EXIT
+ip netns add $ns
+ip -n $ns link set dev lo up
+
+echo "a" | ip netns exec $ns ./mptcp_connect -p 10000 -l 0.0.0.0 -t 100 >/dev/null &
+sleep 0.1
+pids[0]=$!
+chk_msk_nr 0 "no msk on netns creation"
+
+echo "b" | ip netns exec $ns ./mptcp_connect -p 10000 127.0.0.1 -j -t 100 >/dev/null &
+sleep 0.1
+pids[1]=$!
+chk_msk_nr 2 "after MPC handshake "
+chk_msk_ack_nr 2 "....chk ack"
+chk_msk_fallback_nr 0 "....chk no fallback"
+flush_pids
+
+
+echo "a" | ip netns exec $ns ./mptcp_connect -p 10001 -s TCP -l 0.0.0.0 -t 100 >/dev/null &
+pids[0]=$!
+sleep 0.1
+echo "b" | ip netns exec $ns ./mptcp_connect -p 10001 127.0.0.1 -j -t 100 >/dev/null &
+pids[1]=$!
+sleep 0.1
+chk_msk_fallback_nr 1 "check fallback"
+flush_pids
+
+NR_CLIENTS=100
+for I in `seq 1 $NR_CLIENTS`; do
+	echo "a" | ip netns exec $ns ./mptcp_connect -p $((I+10001)) -l 0.0.0.0 -t 100 -w 2 >/dev/null  &
+	pids[$((I*2))]=$!
+done
+sleep 0.1
+
+for I in `seq 1 $NR_CLIENTS`; do
+	echo "b" | ip netns exec $ns ./mptcp_connect -p $((I+10001)) 127.0.0.1 -t 100 -w 2 >/dev/null &
+	pids[$((I*2 + 1))]=$!
+done
+sleep 1.5
+
+chk_msk_nr $((NR_CLIENTS*2)) "many msk socket present"
+sleep 2
+flush_pids
+
+exit $ret
\ No newline at end of file
tools/testing/selftests/net/mptcp/mptcp_connect.c +10 -4
index cedee5b952ba..76899d6ef8e2 100644
@@ -52,11 +52,12 @@ static int pf = AF_INET;
 static int cfg_sndbuf;
 static int cfg_rcvbuf;
 static bool cfg_join;
+static int cfg_wait;
 
 static void die_usage(void)
 {
 	fprintf(stderr, "Usage: mptcp_connect [-6] [-u] [-s MPTCP|TCP] [-p port] [-m mode]"
-		"[-l] connect_address\n");
+		"[-l] [-w sec] connect_address\n");
 	fprintf(stderr, "\t-6 use ipv6\n");
 	fprintf(stderr, "\t-t num -- set poll timeout to num\n");
 	fprintf(stderr, "\t-S num -- set SO_SNDBUF to num\n");
@@ -65,6 +66,7 @@ static void die_usage(void)
 	fprintf(stderr, "\t-m [MPTCP|TCP] -- use tcp or mptcp sockets\n");
 	fprintf(stderr, "\t-s [mmap|poll] -- use poll (default) or mmap\n");
 	fprintf(stderr, "\t-u -- check mptcp ulp\n");
+	fprintf(stderr, "\t-w num -- wait num sec before closing the socket\n");
 	exit(1);
 }
 
@@ -418,8 +420,8 @@ static int copyfd_io_poll(int infd, int peerfd, int outfd)
 	}
 
 	/* leave some time for late join/announce */
-	if (cfg_join)
-		usleep(400000);
+	if (cfg_wait)
+		usleep(cfg_wait);
 
 	close(peerfd);
 	return 0;
@@ -812,11 +814,12 @@ static void parse_opts(int argc, char **argv)
 {
 	int c;
 
-	while ((c = getopt(argc, argv, "6jlp:s:hut:m:S:R:")) != -1) {
+	while ((c = getopt(argc, argv, "6jlp:s:hut:m:S:R:w:")) != -1) {
 		switch (c) {
 		case 'j':
 			cfg_join = true;
 			cfg_mode = CFG_MODE_POLL;
+			cfg_wait = 400000;
 			break;
 		case 'l':
 			listen_mode = true;
@@ -850,6 +853,9 @@ static void parse_opts(int argc, char **argv)
 		case 'R':
 			cfg_rcvbuf = parse_int(optarg);
 			break;
+		case 'w':
+			cfg_wait = atoi(optarg)*1000000;
+			break;
 		}
 	}
 
Signature · 1 line
2.26.2