Skip to contentSkip to conversation

mptcp: msk diag support

PATCH In review Paolo Abeni 3 participants 9 messages Jul 2, 2020 – Jul 6, 2020

Subsystems (4)
lore
Share & tools
lore

Paolo Abeni

author
#0 lore raw

v3 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.

Patch 4 includes some basic functional tests

v2 -> v3:
- changed token iterator APIs: use RCU && get_sock
- tests cleanup

v1 -> v2
- fixed dump issue on large dump
- use flags for fallback, etc
- patch 4

Paolo Abeni (4):
inet_diag: support for wider protocol numbers
mptcp: add msk interations helper
mptcp: add MPTCP socket diag interface
selftests/mptcp: add diag interface tests

 include/uapi/linux/inet_diag.h                |   1 +
 include/uapi/linux/mptcp.h                    |  17 ++
 net/core/sock.c                               |   1 +
 net/ipv4/inet_diag.c                          |  63 +++++--
 net/mptcp/Kconfig                             |   4 +
 net/mptcp/Makefile                            |   2 +
 net/mptcp/mptcp_diag.c                        | 169 ++++++++++++++++++
 net/mptcp/protocol.h                          |   2 +
 net/mptcp/token.c                             |  59 ++++++
 tools/testing/selftests/net/mptcp/Makefile    |   2 +-
 tools/testing/selftests/net/mptcp/diag.sh     | 122 +++++++++++++
 .../selftests/net/mptcp/mptcp_connect.c       |  22 ++-
 12 files changed, 442 insertions(+), 22 deletions(-)
 create mode 100644 net/mptcp/mptcp_diag.c
 create mode 100755 tools/testing/selftests/net/mptcp/diag.sh
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH v3 1/4 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 d832c650287c..d48cdfcb4055 100644
@@ -3575,6 +3575,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 v3 2/4 mptcp: add msk interations helper

In reply to Paolo Abeni

mptcp_token_iter_next() allow traversing all the MPTCP sockets inside the token container belonging to the given network namespace with a quite standard iterator semantic.

It will be used by the next patch, but keep the API generic, as we plan to use this later for PM's sake.

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

---
v2 -> v3:
- use a single iterator
- use rcu protection for traversing the hash
- acquire a reference to the returned socket
- use a netns argument

---
 net/mptcp/protocol.h |  2 ++
 net/mptcp/token.c    | 59 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
net/mptcp/protocol.h +2 -0
index 39bfec3f1586..e5baaef5ec89 100644
@@ -391,6 +391,8 @@ 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_next(const struct net *net, long *s_slot,
+					 long *s_num);
 void mptcp_token_destroy(struct mptcp_sock *msk);
 
 void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn);
net/mptcp/token.c +59 -0

65 lines not on this page · raw message

Signature · 1 line
2.26.2
author
#3 lore raw

PATCH v3 3/4 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>

---
v2 -> v3:
- update to new token APIs
- acquire socket lock for mptcp get info
- cond_resched() on each iteration
v1 -> v2:
- fix dump on skb full event
- use 'flags' for fallback, can_ack

---
 include/uapi/linux/mptcp.h |  17 ++++
 net/mptcp/Kconfig          |   4 +
 net/mptcp/Makefile         |   2 +
 net/mptcp/mptcp_diag.c     | 169 +++++++++++++++++++++++++++++++++++++
 4 files changed, 192 insertions(+)
 create mode 100644 net/mptcp/mptcp_diag.c
include/uapi/linux/mptcp.h +17 -0
index 5f2c77082d9e..9762660df741 100644
@@ -86,4 +86,21 @@ enum {
 	__MPTCP_PM_CMD_AFTER_LAST
 };
 
+#define MPTCP_INFO_FLAG_FALLBACK		_BITUL(0)
+#define MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED	_BITUL(1)
+
+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;
+	__u32	mptcpi_flags;
+	__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 +169 -0

169 lines not on this page · raw message

Signature · 1 line
2.26.2
author
#4 lore raw

PATCH v3 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>

---
v2 -> v3:
- update to new iproute2 output (ack -> remote_key)
- make the tests less fragile to timinig issue
v1 -> v2:
- include diag.sh in the makefile

---
 tools/testing/selftests/net/mptcp/Makefile    |   2 +-
 tools/testing/selftests/net/mptcp/diag.sh     | 122 ++++++++++++++++++
 .../selftests/net/mptcp/mptcp_connect.c       |  22 +++-
 3 files changed, 141 insertions(+), 5 deletions(-)
 create mode 100755 tools/testing/selftests/net/mptcp/diag.sh
tools/testing/selftests/net/mptcp/Makefile +1 -1
index f50976ee7d44..aa254aefc2c3 100644
@@ -5,7 +5,7 @@ KSFT_KHDR_INSTALL := 1
 
 CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g  -I$(top_srcdir)/usr/include
 
-TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh
+TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh diag.sh
 
 TEST_GEN_FILES = mptcp_connect pm_nl_ctl
 
tools/testing/selftests/net/mptcp/diag.sh new file +122 -0

122 lines not on this page · raw message

tools/testing/selftests/net/mptcp/mptcp_connect.c +18 -4
index cedee5b952ba..cad6f73a5fd0 100644
@@ -11,6 +11,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <strings.h>
+#include <signal.h>
 #include <unistd.h>
 
 #include <sys/poll.h>
@@ -36,6 +37,7 @@ extern int optind;
 
 static int  poll_timeout = 10 * 1000;
 static bool listen_mode;
+static bool quit;
 
 enum cfg_mode {
 	CFG_MODE_POLL,
@@ -52,11 +54,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,9 +68,15 @@ 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);
 }
 
+static void handle_signal(int nr)
+{
+	quit = true;
+}
+
 static const char *getxinfo_strerr(int err)
 {
 	if (err == EAI_SYSTEM)
@@ -418,8 +427,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 +821,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 +860,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;
 		}
 	}
 
@@ -865,6 +878,7 @@ int main(int argc, char *argv[])
 {
 	init_rng();
 
+	signal(SIGUSR1, handle_signal);
 	parse_opts(argc, argv);
 
 	if (tcpulp_audit)
Signature · 1 line
2.26.2
#5 lore raw
In reply to Paolo Abeni
Quoted 5 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.

Quoted 8 lines

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

Patch 4 includes some basic functional tests

v2 -> v3:
- changed token iterator APIs: use RCU && get_sock
- tests cleanup

Thanks for the v3 fixes Paolo, my concerns in v2 are addressed. There is the proto range checking issue Christoph noted in patch 1 to fix before merging.

Mat

Quoted 25 lines

v1 -> v2
- fixed dump issue on large dump
- use flags for fallback, etc
- patch 4

Paolo Abeni (4):
inet_diag: support for wider protocol numbers
mptcp: add msk interations helper
mptcp: add MPTCP socket diag interface
selftests/mptcp: add diag interface tests

include/uapi/linux/inet_diag.h                |   1 +
include/uapi/linux/mptcp.h                    |  17 ++
net/core/sock.c                               |   1 +
net/ipv4/inet_diag.c                          |  63 +++++--
net/mptcp/Kconfig                             |   4 +
net/mptcp/Makefile                            |   2 +
net/mptcp/mptcp_diag.c                        | 169 ++++++++++++++++++
net/mptcp/protocol.h                          |   2 +
net/mptcp/token.c                             |  59 ++++++
tools/testing/selftests/net/mptcp/Makefile    |   2 +-
tools/testing/selftests/net/mptcp/diag.sh     | 122 +++++++++++++
.../selftests/net/mptcp/mptcp_connect.c       |  22 ++-
12 files changed, 442 insertions(+), 22 deletions(-)
Quoted 9 lines

create mode 100644 net/mptcp/mptcp_diag.c
create mode 100755 tools/testing/selftests/net/mptcp/diag.sh

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

--
Mat Martineau
Intel

#6 lore raw

Hi Paolo, Mat,

Quoted 15 lines · Mat Martineau
Quoted 12 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.

Patch 4 includes some basic functional tests

Quoted 7 lines
Quoted 3 lines

v2 -> v3:
- changed token iterator APIs: use RCU && get_sock
- tests cleanup

Thanks for the v3 fixes Paolo, my concerns in v2 are addressed. There is the proto range checking issue Christoph noted in patch 1 to fix before merging.

Thank you for the patches and the reviews!

These patches have been added at the end.

Tests are re-running with INET_DIAG enabled. Export is going to be done soon after.

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
author
#7 lore raw
Quoted 25 lines · Matthieu Baerts

Hi Paolo, Mat,

Quoted 14 lines · Mat Martineau
Quoted 12 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.

Patch 4 includes some basic functional tests

Quoted 7 lines
Quoted 3 lines

v2 -> v3:
- changed token iterator APIs: use RCU && get_sock
- tests cleanup

Thanks for the v3 fixes Paolo, my concerns in v2 are addressed. There is the proto range checking issue Christoph noted in patch 1 to fix before merging.

Quoted 6 lines

Thank you for the patches and the reviews!

These patches have been added at the end.

Tests are re-running with INET_DIAG enabled. Export is going to be done soon after.

Note that diag self-tests requiere a version of iproute2 including the pending 2 patches, otherwise tests will be skipped - so no failure but also no tests.

Thanks,

Paolo

#8 lore raw

Hi Paolo,

Quoted 28 lines · Paolo Abeni
Quoted 27 lines · Matthieu Baerts

Hi Paolo, Mat,

Quoted 14 lines · Mat Martineau
Quoted 12 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.

Patch 4 includes some basic functional tests

Quoted 7 lines
Quoted 3 lines

v2 -> v3:
- changed token iterator APIs: use RCU && get_sock
- tests cleanup

Thanks for the v3 fixes Paolo, my concerns in v2 are addressed. There is the proto range checking issue Christoph noted in patch 1 to fix before merging.

Thank you for the patches and the reviews!

Quoted 8 lines
Quoted 4 lines

These patches have been added at the end.

Tests are re-running with INET_DIAG enabled. Export is going to be done soon after.

Note that diag self-tests requiere a version of iproute2 including the pending 2 patches, otherwise tests will be skipped - so no failure but also no tests.

Yes, my CI complained about the skipped test :)

I am currently ignoring the skipped test:
https://github.com/multipath-tcp/mptcp_net-next/commit/f7ccd2f70239265cd13d6017554a025a44e68d8a

Once the two others patches are merged in iproute2 repo, I will make sure this new selftest is correctly tested.

Cheers
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net