mptcp: introduce msk diag interface
Subsystems (5)
Paolo Abeni
maintainercover mptcp: introduce msk diag interface
This series implements the diag interface for the MPTCP sockets.
Since the MPTCP protocol value can't be represented with the current diag uAPI, the first patch introduces an extended attribute allowing user-space to specify lager protocol values.
The token APIs are then extended to allow traversing the whole token container.
Patch 3 carries the actual diag interface implementation, and later patch bring-in some functional self-tests.
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 | 65 +++++-- net/mptcp/Kconfig | 4 + net/mptcp/Makefile | 2 + net/mptcp/mptcp_diag.c | 169 ++++++++++++++++++ net/mptcp/protocol.h | 2 + net/mptcp/token.c | 61 ++++++- 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, 445 insertions(+), 23 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
Paolo Abeni
maintainerPATCH 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.
--- include/uapi/linux/inet_diag.h | 1 + net/core/sock.c | 1 + net/ipv4/inet_diag.c | 65 +++++++++++++++++++++++++--------- 3 files changed, 50 insertions(+), 17 deletions(-)
include/uapi/linux/inet_diag.h +1 -0
@@ -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
@@ -3566,6 +3566,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 +48 -17
133 lines not on this page · raw message
Signature · 1 line
2.26.2
Paolo Abeni
maintainerPATCH 2/4 mptcp: add msk interations helper
In reply to Paolo Abenimptcp_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.
That will be used by the next patch, but keep the API generic, as we plan to use this later for PM's sake.
Additionally export mptcp_token_get_sock(), as it also will be used by the diag module.
--- net/mptcp/protocol.h | 2 ++ net/mptcp/token.c | 61 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-)
net/mptcp/protocol.h +2 -0
@@ -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 +60 -1
73 lines not on this page · raw message
Signature · 1 line
2.26.2
Paolo Abeni
maintainerPATCH 3/4 mptcp: add MPTCP socket diag interface
In reply to Paolo Abeniexposes basic inet socket attribute, plus some MPTCP socket fields comprising PM status and MPTCP-level sequence numbers.
--- 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
@@ -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
@@ -13,6 +13,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
@@ -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
Jakub Kicinski
maintainerRe: [PATCH net-next 3/4] mptcp: add MPTCP socket diag interface
Quoted 5 lines · On Thu, 9 Jul 2020 15:12:41 +0200 Paolo Abeni wrote:
exposes basic inet socket attribute, plus some MPTCP socket fields comprising PM status and MPTCP-level sequence numbers.
Reviewed-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
Any idea why sparse says this:
include/net/sock.h:1612:31: warning: context imbalance in 'mptcp_diag_get_info' - unexpected unlock
? 🤨
Paolo Abeni
maintainerRe: [PATCH net-next 3/4] mptcp: add MPTCP socket diag interface
Quoted 4 lines · Jakub Kicinski
Quoted 3 lines · On Thu, 9 Jul 2020 15:12:41 +0200 Paolo Abeni wrote:
exposes basic inet socket attribute, plus some MPTCP socket fields comprising PM status and MPTCP-level sequence numbers.
Quoted 8 lines
Quoted 2 lines
Reviewed-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>Signed-off-by Paolo Abeni <pabeni(a)redhat.com>Any idea why sparse says this:
include/net/sock.h:1612:31: warning: context imbalance in 'mptcp_diag_get_info' - unexpected unlock? 🤨
AFAICS, that is a sparse false positive, tied
to unlock_sock_fast() usage.
unlock_sock_fast() conditionally releases the socket lock, according to it's bool argument, and that fools sparse check: any unlock_sock_fast() user splats it.
IMHO such warning should be addressed into [un]lock_sock_fast() function[s] - if possible at all. Outside the scope of this series.
Matthieu suggested adding some comment to note the above, but I boldly opposed, as current unlock_sock_fast() users don't do that.
Cheers,
Paolo
Jakub Kicinski
maintainerRe: [PATCH net-next 3/4] mptcp: add MPTCP socket diag interface
Quoted 21 lines · On Thu, 09 Jul 2020 20:00:09 +0200 Paolo Abeni wrote:
Quoted 4 lines · Jakub Kicinski
Quoted 3 lines · On Thu, 9 Jul 2020 15:12:41 +0200 Paolo Abeni wrote:
exposes basic inet socket attribute, plus some MPTCP socket fields comprising PM status and MPTCP-level sequence numbers.
Quoted 8 lines
Quoted 2 lines
Reviewed-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>Signed-off-by Paolo Abeni <pabeni(a)redhat.com>Any idea why sparse says this:
include/net/sock.h:1612:31: warning: context imbalance in 'mptcp_diag_get_info' - unexpected unlock? 🤨
AFAICS, that is a sparse false positive, tied
tounlock_sock_fast()usage.
unlock_sock_fast()conditionally releases the socket lock, according to it's bool argument, and that fools sparse check: anyunlock_sock_fast()user splats it.
Quoted 5 lines
IMHO such warning should be addressed into [un]lock_sock_fast() function[s] - if possible at all. Outside the scope of this series.
Matthieu suggested adding some comment to note the above, but I boldly opposed, as current
unlock_sock_fast()users don't do that.
Sounds reasonable, thanks!
Paolo Abeni
maintainerPATCH 4/4 selftests/mptcp: add diag interface tests
In reply to Paolo Abenibasic functional test, triggering the msk diag interface code. Require appropriate iproute2 support, skip elsewhere.
--- 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
@@ -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
@@ -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
David Miller
maintainerFrom: Paolo Abeni <pabeni(a)redhat.com>
Date: Thu, 9 Jul 2020 15:12:38 +0200
Quoted 11 lines
This series implements the diag interface for the MPTCP sockets.
Since the MPTCP protocol value can't be represented with the current diag uAPI, the first patch introduces an extended attribute allowing user-space to specify lager protocol values.
The token APIs are then extended to allow traversing the whole token container.
Patch 3 carries the actual diag interface implementation, and later patch bring-in some functional self-tests.
Series applied, thanks.