Skip to contentSkip to conversation

iproute: mptcp support

PATCH Superseded Paolo Abeni 3 participants 14 messages Apr 15, 2020 – Apr 17, 2020 Networking MPTCP

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Paolo Abeni

author
#0 lore raw

v2 cover iproute: mptcp support

This addresses the feedback from Davide, includes the 'ss' support - still from Davide and also a very tentative man page.

Any feedback welcome!

Davide Caratti (1):
ss: allow dumping MPTCP subflow information

Paolo Abeni (3):
uapi: update linux/mptcp.h
add support for mptcp netlink interface.
man: mptcp man page

 include/uapi/linux/mptcp.h |  89 ++++++++
 ip/Makefile                |   2 +-
 ip/ip.c                    |   3 +-
 ip/ip_common.h             |   1 +
 ip/ipmptcp.c               | 449 +++++++++++++++++++++++++++++++++++++
 man/man8/ip-mptcp.8        | 142 ++++++++++++
 misc/ss.c                  |  62 +++++
 7 files changed, 746 insertions(+), 2 deletions(-)
 create mode 100644 include/uapi/linux/mptcp.h
 create mode 100644 ip/ipmptcp.c
 create mode 100644 man/man8/ip-mptcp.8
Signature · 1 line
2.21.1
author
#1 lore raw

PATCH v2 1/4 uapi: update linux/mptcp.h

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 include/uapi/linux/mptcp.h | 89 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 include/uapi/linux/mptcp.h
include/uapi/linux/mptcp.h new file +89 -0
new file mode 100644
index 00000000..5f2c7708
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+#ifndef _UAPI_MPTCP_H
+#define _UAPI_MPTCP_H
+
+#include <linux/const.h>
+#include <linux/types.h>
+
+#define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
+#define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
+#define MPTCP_SUBFLOW_FLAG_JOIN_REM		_BITUL(2)
+#define MPTCP_SUBFLOW_FLAG_JOIN_LOC		_BITUL(3)
+#define MPTCP_SUBFLOW_FLAG_BKUP_REM		_BITUL(4)
+#define MPTCP_SUBFLOW_FLAG_BKUP_LOC		_BITUL(5)
+#define MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED	_BITUL(6)
+#define MPTCP_SUBFLOW_FLAG_CONNECTED		_BITUL(7)
+#define MPTCP_SUBFLOW_FLAG_MAPVALID		_BITUL(8)
+
+enum {
+	MPTCP_SUBFLOW_ATTR_UNSPEC,
+	MPTCP_SUBFLOW_ATTR_TOKEN_REM,
+	MPTCP_SUBFLOW_ATTR_TOKEN_LOC,
+	MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ,
+	MPTCP_SUBFLOW_ATTR_MAP_SEQ,
+	MPTCP_SUBFLOW_ATTR_MAP_SFSEQ,
+	MPTCP_SUBFLOW_ATTR_SSN_OFFSET,
+	MPTCP_SUBFLOW_ATTR_MAP_DATALEN,
+	MPTCP_SUBFLOW_ATTR_FLAGS,
+	MPTCP_SUBFLOW_ATTR_ID_REM,
+	MPTCP_SUBFLOW_ATTR_ID_LOC,
+	MPTCP_SUBFLOW_ATTR_PAD,
+	__MPTCP_SUBFLOW_ATTR_MAX
+};
+
+#define MPTCP_SUBFLOW_ATTR_MAX (__MPTCP_SUBFLOW_ATTR_MAX - 1)
+
+/* netlink interface */
+#define MPTCP_PM_NAME		"mptcp_pm"
+#define MPTCP_PM_CMD_GRP_NAME	"mptcp_pm_cmds"
+#define MPTCP_PM_VER		0x1
+
+/*
+ * ATTR types defined for MPTCP
+ */
+enum {
+	MPTCP_PM_ATTR_UNSPEC,
+
+	MPTCP_PM_ATTR_ADDR,				/* nested address */
+	MPTCP_PM_ATTR_RCV_ADD_ADDRS,			/* u32 */
+	MPTCP_PM_ATTR_SUBFLOWS,				/* u32 */
+
+	__MPTCP_PM_ATTR_MAX
+};
+
+#define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1)
+
+enum {
+	MPTCP_PM_ADDR_ATTR_UNSPEC,
+
+	MPTCP_PM_ADDR_ATTR_FAMILY,			/* u16 */
+	MPTCP_PM_ADDR_ATTR_ID,				/* u8 */
+	MPTCP_PM_ADDR_ATTR_ADDR4,			/* struct in_addr */
+	MPTCP_PM_ADDR_ATTR_ADDR6,			/* struct in6_addr */
+	MPTCP_PM_ADDR_ATTR_PORT,			/* u16 */
+	MPTCP_PM_ADDR_ATTR_FLAGS,			/* u32 */
+	MPTCP_PM_ADDR_ATTR_IF_IDX,			/* s32 */
+
+	__MPTCP_PM_ADDR_ATTR_MAX
+};
+
+#define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1)
+
+#define MPTCP_PM_ADDR_FLAG_SIGNAL			(1 << 0)
+#define MPTCP_PM_ADDR_FLAG_SUBFLOW			(1 << 1)
+#define MPTCP_PM_ADDR_FLAG_BACKUP			(1 << 2)
+
+enum {
+	MPTCP_PM_CMD_UNSPEC,
+
+	MPTCP_PM_CMD_ADD_ADDR,
+	MPTCP_PM_CMD_DEL_ADDR,
+	MPTCP_PM_CMD_GET_ADDR,
+	MPTCP_PM_CMD_FLUSH_ADDRS,
+	MPTCP_PM_CMD_SET_LIMITS,
+	MPTCP_PM_CMD_GET_LIMITS,
+
+	__MPTCP_PM_CMD_AFTER_LAST
+};
+
+#endif /* _UAPI_MPTCP_H */
Signature · 1 line
2.21.1
author
#2 lore raw

PATCH v2 2/4 add support for mptcp netlink interface.

In reply to Paolo Abeni

Implement basic commands to:
- manipulate MPTCP endpoints list
- manipulate MPTCP connection limits

Examples:
1. Allows multiple subflows per MPTCP connection

   $ ip mptcp limits set subflows 2

2. Accept ADD_ADDR announcement from the peer (server):

   $ ip mptcp limits set add_addr_accepted 2

3. Add a ipv4 address to be annunced for backup subflows:

   $ ip mptcp endpoint add 10.99.1.2 signal backup

4. Add an ipv6 address used as source for additional subflows:

   $ ip mptcp endpoint add 2001::2 subflow
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>

---
v1 -> v2:
- use NEXT_ARG_FWD() (Davide)
- 'del' -> 'delete'
RFC -> v1:
- many command name changes, as per ML discussion

---
 ip/Makefile    |   2 +-
 ip/ip.c        |   3 +-
 ip/ip_common.h |   1 +
 ip/ipmptcp.c   | 449 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 453 insertions(+), 2 deletions(-)
 create mode 100644 ip/ipmptcp.c
ip/Makefile +1 -1
index 5ab78d7d..8735b8e4 100644
@@ -11,7 +11,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \
     iplink_bridge.o iplink_bridge_slave.o ipfou.o iplink_ipvlan.o \
     iplink_geneve.o iplink_vrf.o iproute_lwtunnel.o ipmacsec.o ipila.o \
     ipvrf.o iplink_xstats.o ipseg6.o iplink_netdevsim.o iplink_rmnet.o \
-    ipnexthop.o
+    ipnexthop.o ipmptcp.o
 
 RTMONOBJ=rtmon.o
 
ip/ip.c +2 -1
index 90392c2a..4249df03 100644
@@ -51,7 +51,7 @@ static void usage(void)
 		"where  OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |\n"
 		"                   tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |\n"
 		"                   netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila |\n"
-		"                   vrf | sr | nexthop }\n"
+		"                   vrf | sr | nexthop | mptcp }\n"
 		"       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n"
 		"                    -h[uman-readable] | -iec | -j[son] | -p[retty] |\n"
 		"                    -f[amily] { inet | inet6 | mpls | bridge | link } |\n"
@@ -103,6 +103,7 @@ static const struct cmd {
 	{ "vrf",	do_ipvrf},
 	{ "sr",		do_seg6 },
 	{ "nexthop",	do_ipnh },
+	{ "mptcp",	do_mptcp },
 	{ "help",	do_help },
 	{ 0 }
 };
ip/ip_common.h +1 -0
index 879287e3..d604f755 100644
@@ -83,6 +83,7 @@ void vrf_reset(void);
 int netns_identify_pid(const char *pidstr, char *name, int len);
 int do_seg6(int argc, char **argv);
 int do_ipnh(int argc, char **argv);
+int do_mptcp(int argc, char **argv);
 
 int iplink_get(char *name, __u32 filt_mask);
 int iplink_ifla_xstats(int argc, char **argv);
ip/ipmptcp.c new file +449 -0

449 lines not on this page · raw message

Signature · 1 line
2.21.1
author
#7 lore raw

PATCH v2 3/4 ss: allow dumping MPTCP subflow information

In reply to Paolo Abeni

From: Davide Caratti <dcaratti(a)redhat.com>

[root(a)f31 packetdrill]# ss -tni

ESTAB 0 0 192.168.82.247:8080 192.0.2.1:35273

          cubic wscale:7,8 [...] tcp-ulp-mptcp flags: Mec token:0000(id:0)/5f856c60(id:0) seq:b810457db34209a5 sfseq:1 ssnoff:0 maplen:190
Signed-off-by Davide Caratti <dcaratti(a)redhat.com>
---
 misc/ss.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
misc/ss.c +62 -0
index 3ef151fb..3fac4be8 100644
@@ -53,6 +53,7 @@
 #include <linux/tipc_netlink.h>
 #include <linux/tipc_sockets_diag.h>
 #include <linux/tls.h>
+#include <linux/mptcp.h>
 
 /* AF_VSOCK/PF_VSOCK is only provided since glibc 2.18 */
 #ifndef PF_VSOCK
@@ -2836,6 +2837,59 @@ static void tcp_tls_conf(const char *name, struct rtattr *attr)
 	}
 }
 
+static void mptcp_subflow_info(struct rtattr *tb[])
+{
+	u_int32_t flags = 0;
+
+	if (tb[MPTCP_SUBFLOW_ATTR_FLAGS]) {
+		char caps[32 + 1] = { 0 }, *cap = &caps[0];
+
+		flags = rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_FLAGS]);
+
+		if (flags & MPTCP_SUBFLOW_FLAG_MCAP_REM)
+			*cap++ = 'M';
+		if (flags & MPTCP_SUBFLOW_FLAG_MCAP_LOC)
+			*cap++ = 'm';
+		if (flags & MPTCP_SUBFLOW_FLAG_JOIN_REM)
+			*cap++ = 'J';
+		if (flags & MPTCP_SUBFLOW_FLAG_JOIN_LOC)
+			*cap++ = 'j';
+		if (flags & MPTCP_SUBFLOW_FLAG_BKUP_REM)
+			*cap++ = 'B';
+		if (flags & MPTCP_SUBFLOW_FLAG_BKUP_LOC)
+			*cap++ = 'b';
+		if (flags & MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED)
+			*cap++ = 'e';
+		if (flags & MPTCP_SUBFLOW_FLAG_CONNECTED)
+			*cap++ = 'c';
+		if (flags & MPTCP_SUBFLOW_FLAG_MAPVALID)
+			*cap++ = 'v';
+		if (flags)
+			out(" flags:%s", caps);
+	}
+	if (tb[MPTCP_SUBFLOW_ATTR_TOKEN_REM] &&
+	    tb[MPTCP_SUBFLOW_ATTR_TOKEN_LOC] &&
+	    tb[MPTCP_SUBFLOW_ATTR_ID_REM] &&
+	    tb[MPTCP_SUBFLOW_ATTR_ID_LOC])
+		out(" token:%04x(id:%d)/%04x(id:%d)",
+		    rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_TOKEN_REM]),
+		    rta_getattr_u8(tb[MPTCP_SUBFLOW_ATTR_ID_REM]),
+		    rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_TOKEN_LOC]),
+		    rta_getattr_u8(tb[MPTCP_SUBFLOW_ATTR_ID_LOC]));
+	if (tb[MPTCP_SUBFLOW_ATTR_MAP_SEQ])
+		out(" seq:%llx",
+		    rta_getattr_u64(tb[MPTCP_SUBFLOW_ATTR_MAP_SEQ]));
+	if (tb[MPTCP_SUBFLOW_ATTR_MAP_SFSEQ])
+		out(" sfseq:%x",
+		    rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_MAP_SFSEQ]));
+	if (tb[MPTCP_SUBFLOW_ATTR_SSN_OFFSET])
+		out(" ssnoff:%x",
+		    rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_SSN_OFFSET]));
+	if (tb[MPTCP_SUBFLOW_ATTR_MAP_DATALEN])
+		out(" maplen:%x",
+		    rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_MAP_DATALEN]));
+}
+
 #define TCPI_HAS_OPT(info, opt) !!(info->tcpi_options & (opt))
 
 static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
@@ -3012,6 +3066,14 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
 			tcp_tls_conf("rxconf", tlsinfo[TLS_INFO_RXCONF]);
 			tcp_tls_conf("txconf", tlsinfo[TLS_INFO_TXCONF]);
 		}
+		if (ulpinfo[INET_ULP_INFO_MPTCP]) {
+			struct rtattr *sfinfo[MPTCP_SUBFLOW_ATTR_MAX + 1] =
+				{ 0 };
+
+			parse_rtattr_nested(sfinfo, MPTCP_SUBFLOW_ATTR_MAX,
+					    ulpinfo[INET_ULP_INFO_MPTCP]);
+			mptcp_subflow_info(sfinfo);
+		}
 	}
 }
 
Signature · 1 line
2.21.1
author
#10 lore raw

PATCH v2 4/4 man: mptcp man page

In reply to Paolo Abeni

describe the mptcp subcommands implemented so far.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 man/man8/ip-mptcp.8 | 142 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 142 insertions(+)
 create mode 100644 man/man8/ip-mptcp.8
man/man8/ip-mptcp.8 new file +142 -0
new file mode 100644
index 00000000..5ed0457b
@@ -0,0 +1,142 @@
+.TH IP\-MPTCP 8 "4 Apr 2020" "iproute2" "Linux"
+.SH "NAME"
+ip-mptcp \- MPTCP path manager configuration
+.SH "SYNOPSIS"
+.sp
+.ad l
+.in +8
+.ti -8
+.B ip
+.RI "[ " OPTIONS " ]"
+.B mptcp
+.RB "{ "
+.B endpoint
+.RB " | "
+.B limits
+.RB " | "
+.B help
+.RB " }"
+.sp
+
+.ti -8
+.BR "ip mptcp endpoint add "
+.IR IFADDR
+.RB "[ " dev
+.IR IFNAME " ]"
+.RB "[ " id
+.I ID
+.RB "] [ "
+.I FLAG-LIST
+.RB "] "
+
+.ti -8
+.BR "ip mptcp endpoint del id "
+.I ID
+
+.ti -8
+.BR "ip mptcp endpoint show "
+.RB "[ " id
+.I ID
+.RB "]"
+
+.ti -8
+.BR "ip mptcp endpoint flush"
+
+.ti -8
+.IR FLAG-LIST " := [ "  FLAG-LIST " ] " FLAG
+
+.ti -8
+.IR FLAG " := ["
+.B signal
+.RB "|"
+.B subflow
+.RB "|"
+.B backup
+.RB  "]"
+
+.ti -8
+.BR "ip mptcp limits set "
+.RB "[ "
+.B subflow
+.IR SUBFLOW_NR " ]"
+.RB "[ "
+.B add_addr_accepted
+.IR  ADD_ADDR_ACCEPTED_NR " ]"
+
+.ti -8
+.BR "ip mptcp limits show"
+
+.SH DESCRIPTION
+
+MPTCP is a transport protocol build on top of TCP that allows TCP
+connections to use multiple paths to maximize resource usage and increase
+redundancy. The ip-mptcp sub-commands allow configuring several aspects of the
+MPTCP path manager, which is in charge of subflows creation:
+
+.P
+The
+.B endpoint
+object specifies the IP addresses that will be used and/or announced for
+additional subflows:
+
+.TS
+l l.
+ip mptcp endpoint add	add new MPTCP endpoint
+ip mptcp endpoint delete	delete existing MPTCP endpoint
+ip mptcp endpoint show	get existing MPTCP endpoint
+ip mptcp endpoint flush	flush all existing MPTCP endpoints
+.TE
+
+.TP
+.IR ID
+is a unique numeric identifier for the given endpoint
+
+.TP
+.BR signal
+the endpoint will be announced/signaled to each peer via an ADD_ADDR MPTCP
+sub-option
+
+.TP
+.BR subflow
+If the MPTCP limits allow for additional subflows creation, the endpoint will
+be used as the source address to create an additional subflow after that
+the MPTCP connection is established.
+
+.TP
+.BR backup
+the endpoint will be announced as a backup address, if this is a
+.BR signal
+endpoint, or the subflow will be created as a backup one if this a
+.BR subflow
+endpoint
+
+.sp
+.PP
+The
+.B limits
+object specifies the constraints for subflow creations:
+
+.TS
+l l.
+ip mptcp limits show	get current MPTCP subflow creation limits
+ip mptcp limits set	change the MPTCP subflow creation limits
+.TE
+
+.TP
+.IR SUBFLOW_NR
+specifies the maximum number of additional subflows allowed for each MPTCP
+connection. Additional subflows can be created due to: incoming accepted
+ADD_ADDR option, local
+.BR subflow
+endpoints, additional subflows started by the peer.
+
+.TP
+.IR ADD_ADDR_ACCEPTED_NR
+specifies the maximum number of ADD_ADDR suboptions accepted for each MPTCP
+connection. The MPTCP path manager will try to create a new subflow for
+each accepted ADD_ADDR option, respecting the
+.IR SUBFLOW_NR
+limit.
+
+.SH AUTHOR
+Original Manpage by Paolo Abeni <pabeni(a)redhat.com>
Signature · 1 line
2.21.1
#3 lore raw

[MPTCP] Re: [PATCH v2 2/4] add support for mptcp netlink interface.

In reply to Paolo Abeni

Hi Paolo,

Quoted 8 lines · Paolo Abeni

Implement basic commands to:
- manipulate MPTCP endpoints list
- manipulate MPTCP connection limits

Examples:
1. Allows multiple subflows per MPTCP connection

    $ ip mptcp limits set subflows 2
Quoted 8 lines

2. Accept ADD_ADDR announcement from the peer (server):

    $ ip mptcp limits set add_addr_accepted 2

3. Add a ipv4 address to be annunced for backup subflows:

    $ ip mptcp endpoint add 10.99.1.2 signal backup

4. Add an ipv6 address used as source for additional subflows:

    $ ip mptcp endpoint add 2001::2 subflow

Thank you for looking at that!

(detail, there is a dot at the end of the subject)

(...)

Quoted 20 lines
ip/ipmptcp.c new file +14 -0
new file mode 100644
index 00000000..452629f4
@@ -0,0 +1,449 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <stdio.h>
+#include <string.h>
+#include <rt_names.h>
+#include <errno.h>
+
+#include <linux/genetlink.h>
+#include <linux/mptcp.h>
+
+#include "utils.h"
+#include "ip_common.h"
+#include "libgenl.h"
+#include "json_print.h"

ip/ipmptcp.c line 24

Quoted 10 lines
ip/ipmptcp.c new file +10 -0
+
+static void usage(void)
+{
+	fprintf(stderr,
+		"Usage:	ip mptcp endpoint add <address> [dev <name>] [id <id>] [signal] [subflow] [backup]\n"
+		"	ip mptcp endpoint delete id <id>\n"
+		"	ip mptcp endpoint show [id <id>]\n"
+		"	ip mptcp endpoint flush\n"
+		"	ip mptcp limits set [subflows <nr>] [add_addr_accepted <nr>]\n"
+		"	ip mptcp limits show\n");

detail: it seems to me that the arguments are usually presented with capital letters, extra spaces and new lines when it is too long, e.g.

"Usage: ip mptcp endpoint add ADDRESS [ dev NAME ] [ id ID ]\n"
" [ signal ] [ subflow ]\n"
" [ backup ]\n"
" ip mptcp endpoint delete id ID\n"
" ip mptcp endpoint show [ id ID ]\n"
" ip mptcp endpoint flush\n"
" ip mptcp limits set { subflows | add_addr_accepted } NR\n"
" ip mptcp limits show\n");

It seems you can also use an attribute expended later:

"Usage: ip mptcp endpoint add ADDRESS SELECTOR\n"
" ip mptcp endpoint delete id ID\n"
(...)
"SELECTOR := [ dev NAME ] [ id ID ] [ signal ] [ subflow ]\n"
" [ backup ]\n"

Quoted 35 lines
ip/ipmptcp.c new file +35 -0
+	exit(-1);
+}
+
+/* netlink socket */
+static struct rtnl_handle genl_rth = { .fd = -1 };
+static int genl_family = -1;
+
+#define MPTCP_BUFLEN	4096
+#define MPTCP_REQUEST(_req,  _cmd, _flags)	\
+	GENL_REQUEST(_req, MPTCP_BUFLEN, genl_family, 0,	\
+		     MPTCP_PM_VER, _cmd, _flags)
+
+/* Mapping from argument to address flag mask */
+static const struct {
+	const char *name;
+	unsigned long value;
+} mptcp_addr_flag_names[] = {
+	{ "signal",		MPTCP_PM_ADDR_FLAG_SIGNAL },
+	{ "subflow",		MPTCP_PM_ADDR_FLAG_SUBFLOW },
+	{ "backup",		MPTCP_PM_ADDR_FLAG_BACKUP },
+};
+
+static void print_mptcp_addr_flags(unsigned int flags)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(mptcp_addr_flag_names); i++) {
+		unsigned long mask = mptcp_addr_flag_names[i].value;
+
+		if (flags & mask) {
+			print_string(PRINT_FP, NULL, "%s ",
+				     mptcp_addr_flag_names[i].name);
+			print_bool(PRINT_JSON,
+				   mptcp_addr_flag_names[i].name, NULL, true);
+		}

ip/ipmptcp.c line 70

Quoted 10 lines
ip/ipmptcp.c new file +10 -0
+
+		flags &= ~mask;
+	}
+
+	if (flags) {
+		/* unknown flags */
+		SPRINT_BUF(b1);
+
+		snprintf(b1, sizeof(b1), "%02x", flags);
+		print_string(PRINT_ANY, "rawflags", "rawflags %s ", b1);

(it looks strange to me to end with a space even in json context but I don't know the code of iproute2 :) )

ip/ipmptcp.c line 79

Quoted 9 lines
ip/ipmptcp.c new file +9 -0
+	}
+}
+
+static int get_flags(const char *arg, __u32 *flags)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(mptcp_addr_flag_names); i++) {
+		if (strcmp(arg, mptcp_addr_flag_names[i].name))

(can we use strcmp or do they force strncmp() for the flags? or matches()?)

Quoted 17 lines
ip/ipmptcp.c new file +17 -0
+			continue;
+
+		*flags |= mptcp_addr_flag_names[i].value;
+		return 0;
+	}
+	return -1;
+}
+
+static int mptcp_parse_opt(int argc, char **argv, struct nlmsghdr *n,
+			 bool adding)
+{
+	struct rtattr *attr_addr;
+	bool addr_set = false;
+	inet_prefix address;
+	bool id_set = false;
+	__u32 index = 0;
+	__u32 flags = 0;

ip/ipmptcp.c line 106

Quoted 10 lines
ip/ipmptcp.c new file +10 -0
+	__u8 id = 0;
+
+	ll_init_map(&rth);
+	while (argc > 0) {
+		if (get_flags(*argv, &flags) == 0) {
+		} else if (!matches(*argv, "id")) {
+			NEXT_ARG();
+
+			if (get_u8(&id, *argv, 0)) {
+				invarg("invalid TTL\n", *argv);

detail: do you mean ID instead of TTL?

ip/ipmptcp.c line 106

Quoted 1 line
ip/ipmptcp.c new file +1 -0
+				return -1;

detail: it seems "invarg()" already does a "exit(-1)". So we can remove "return -1", same below.

And it prints:

"Error: argument \"%s\" is wrong: %s\n", <2nd arg>, <1st arg>

ip/ipmptcp.c line 118

Quoted 11 lines
ip/ipmptcp.c new file +11 -0
+			}
+			id_set = true;
+		} else if (!matches(*argv, "dev")) {
+			const char *ifname;
+
+			NEXT_ARG();
+
+			ifname = *argv;
+
+			if (check_ifname(ifname)) {
+				invarg("name", ifname);

Even if "invarg" already adds "\n", I see "\n" is always added at the end of the 1st arg.

And maybe here, we can say: "invalid interface name\n"

ip/ipmptcp.c line 125

Quoted 7 lines
ip/ipmptcp.c new file +7 -0
+				return -1;
+			}
+
+			index = ll_name_to_index(ifname);
+
+			if (!index) {
+				invarg("name", ifname);

maybe: "Device does not exist\n"

ip/ipmptcp.c line 138

Quoted 13 lines
ip/ipmptcp.c new file +13 -0
+				return -1;
+			}
+		} else if (get_addr(&address, *argv, AF_UNSPEC) == 0) {
+			addr_set = true;
+		} else {
+			invarg("unknown argument", *argv);
+			usage();
+		}
+		NEXT_ARG_FWD();
+	}
+
+	if (!addr_set && adding) {
+		fprintf(stderr, "mptcp: must set 'address' on add\n");

detail: it seems you can use missarg("ADDRESS") here. It does an exit(-1).

ip/ipmptcp.c line 143

Quoted 5 lines
ip/ipmptcp.c new file +5 -0
+		return -1;
+	}
+
+	if (!id_set && !adding) {
+		fprintf(stderr, "mptcp: must set 'id'\n");

detail: same here with missarg("ID").

Quoted 50 lines
ip/ipmptcp.c new file +50 -0
+		return -1;
+	}
+
+	attr_addr = addattr_nest(n, MPTCP_BUFLEN,
+				 MPTCP_PM_ATTR_ADDR | NLA_F_NESTED);
+	if (id_set)
+		addattr8(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_ID, id);
+	if (flags)
+		addattr32(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_FLAGS, flags);
+	if (index)
+		addattr32(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_IF_IDX, index);
+	if (addr_set) {
+		int type;
+
+		addattr16(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_FAMILY,
+			  address.family);
+		type = address.family == AF_INET ? MPTCP_PM_ADDR_ATTR_ADDR4 :
+						   MPTCP_PM_ADDR_ATTR_ADDR6;
+		addattr_l(n, MPTCP_BUFLEN, type, &address.data,
+			  address.bytelen);
+	}
+
+	addattr_nest_end(n, attr_addr);
+	return 0;
+}
+
+static int mptcp_addr_modify(int argc, char **argv, int cmd)
+{
+	MPTCP_REQUEST(req, cmd, NLM_F_REQUEST);
+	int ret;
+
+	ret = mptcp_parse_opt(argc, argv, &req.n, cmd == MPTCP_PM_CMD_ADD_ADDR);
+	if (ret)
+		return ret;
+
+	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
+		return -2;
+
+	return 0;
+}
+
+static int print_mptcp_addrinfo(struct rtattr *addrinfo)
+{
+	struct rtattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1];
+	__u8 family = AF_UNSPEC, addr_attr_type;
+	const char *ifname;
+	unsigned int flags;
+	int index;
+	__u16 id;
+

ip/ipmptcp.c line 203

Quoted 10 lines
ip/ipmptcp.c new file +10 -0
+	parse_rtattr_nested(tb, MPTCP_PM_ADDR_ATTR_MAX, addrinfo);
+
+	open_json_object(NULL);
+	if (tb[MPTCP_PM_ADDR_ATTR_FAMILY])
+		family = rta_getattr_u8(tb[MPTCP_PM_ADDR_ATTR_FAMILY]);
+
+	addr_attr_type = family == AF_INET ? MPTCP_PM_ADDR_ATTR_ADDR4 :
+					     MPTCP_PM_ADDR_ATTR_ADDR6;
+	if (tb[addr_attr_type]) {
+		print_string(PRINT_ANY, "address", "%s ",

(same here, is it OK to have a space at then end in a JSON context? Same below)

Quoted 160 lines
ip/ipmptcp.c new file +160 -0
+			     format_host_rta(family, tb[addr_attr_type]));
+	}
+	if (tb[MPTCP_PM_ADDR_ATTR_ID]) {
+		id = rta_getattr_u8(tb[MPTCP_PM_ADDR_ATTR_ID]);
+		print_uint(PRINT_ANY, "id", "id %u ", id);
+	}
+	if (tb[MPTCP_PM_ADDR_ATTR_FLAGS]) {
+		flags = rta_getattr_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
+		print_mptcp_addr_flags(flags);
+	}
+	if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX]) {
+		index = rta_getattr_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]);
+		ifname = index ? ll_index_to_name(index) : NULL;
+
+		if (ifname)
+			print_string(PRINT_ANY, "dev", "dev %s ", ifname);
+	}
+
+	close_json_object();
+	print_string(PRINT_FP, NULL, "\n", NULL);
+	fflush(stdout);
+
+	return 0;
+}
+
+static int print_mptcp_addr(struct nlmsghdr *n, void *arg)
+{
+	struct rtattr *tb[MPTCP_PM_ATTR_MAX + 1];
+	struct genlmsghdr *ghdr;
+	struct rtattr *addrinfo;
+	int len = n->nlmsg_len;
+
+	if (n->nlmsg_type != genl_family)
+		return 0;
+
+	len -= NLMSG_LENGTH(GENL_HDRLEN);
+	if (len < 0)
+		return -1;
+
+	ghdr = NLMSG_DATA(n);
+	parse_rtattr_flags(tb, MPTCP_PM_ATTR_MAX, (void *) ghdr + GENL_HDRLEN,
+			   len, NLA_F_NESTED);
+	addrinfo = tb[MPTCP_PM_ATTR_ADDR];
+	if (!addrinfo)
+		return -1;
+
+	ll_init_map(&rth);
+	return print_mptcp_addrinfo(addrinfo);
+}
+
+static int mptcp_addr_dump(void)
+{
+	MPTCP_REQUEST(req, MPTCP_PM_CMD_GET_ADDR, NLM_F_REQUEST | NLM_F_DUMP);
+
+	if (rtnl_send(&genl_rth, &req.n, req.n.nlmsg_len) < 0) {
+		perror("Cannot send show request");
+		exit(1);
+	}
+
+	new_json_obj(json);
+
+	if (rtnl_dump_filter(&genl_rth, print_mptcp_addr, stdout) < 0) {
+		fprintf(stderr, "Dump terminated\n");
+		delete_json_obj();
+		fflush(stdout);
+		return -2;
+	}
+
+	close_json_object();
+	fflush(stdout);
+	return 0;
+}
+
+static int mptcp_addr_show(int argc, char **argv)
+{
+	MPTCP_REQUEST(req, MPTCP_PM_CMD_GET_ADDR, NLM_F_REQUEST);
+	struct nlmsghdr *answer;
+	int ret;
+
+	if (!argv)
+		return mptcp_addr_dump();
+
+	ret = mptcp_parse_opt(argc, argv, &req.n, false);
+	if (ret)
+		return ret;
+
+	if (rtnl_talk(&genl_rth, &req.n, &answer) < 0)
+		return -2;
+
+	return print_mptcp_addr(answer, stdout);
+}
+
+static int mptcp_addr_flush(int argc, char **argv)
+{
+	MPTCP_REQUEST(req, MPTCP_PM_CMD_FLUSH_ADDRS, NLM_F_REQUEST);
+
+	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
+		return -2;
+
+	return 0;
+}
+
+static int mptcp_parse_limit(int argc, char **argv, struct nlmsghdr *n)
+{
+	bool set_rcv_add_addrs = false;
+	bool set_subflows = false;
+	__u32 rcv_add_addrs = 0;
+	__u32 subflows = 0;
+
+	while (argc > 0) {
+		if (!matches(*argv, "subflows")) {
+			NEXT_ARG();
+
+			if (get_u32(&subflows, *argv, 0)) {
+				invarg("invalid subflows\n", *argv);
+				return -1;
+			}
+			set_subflows = true;
+		} else if (!matches(*argv, "add_addr_accepted")) {
+			NEXT_ARG();
+
+			if (get_u32(&rcv_add_addrs, *argv, 0)) {
+				invarg("invalid add_addr_accepted\n", *argv);
+				return -1;
+			}
+			set_rcv_add_addrs = true;
+		} else {
+			invarg("unknown argument", *argv);
+			usage();
+		}
+		NEXT_ARG_FWD();
+	}
+
+	if (set_rcv_add_addrs)
+		addattr32(n, MPTCP_BUFLEN, MPTCP_PM_ATTR_RCV_ADD_ADDRS,
+			  rcv_add_addrs);
+	if (set_subflows)
+		addattr32(n, MPTCP_BUFLEN, MPTCP_PM_ATTR_SUBFLOWS, subflows);
+	return set_rcv_add_addrs || set_subflows;
+}
+
+static int print_mptcp_limit(struct nlmsghdr *n, void *arg)
+{
+	struct rtattr *tb[MPTCP_PM_ATTR_MAX + 1];
+	struct genlmsghdr *ghdr;
+	int len = n->nlmsg_len;
+	__u32 val;
+
+	if (n->nlmsg_type != genl_family)
+		return 0;
+
+	len -= NLMSG_LENGTH(GENL_HDRLEN);
+	if (len < 0)
+		return -1;
+
+	ghdr = NLMSG_DATA(n);
+	parse_rtattr(tb, MPTCP_PM_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
+
+	open_json_object(NULL);
+	if (tb[MPTCP_PM_ATTR_RCV_ADD_ADDRS]) {

ip/ipmptcp.c line 373

Quoted 10 lines
ip/ipmptcp.c new file +10 -0
+		val = rta_getattr_u32(tb[MPTCP_PM_ATTR_RCV_ADD_ADDRS]);
+
+		print_uint(PRINT_ANY, "add_addr_accepted",
+			   "add_addr_accepted %d ", val);
+	}
+
+	if (tb[MPTCP_PM_ATTR_SUBFLOWS]) {
+		val = rta_getattr_u32(tb[MPTCP_PM_ATTR_SUBFLOWS]);
+
+		print_uint(PRINT_ANY, "subflows", "subflows %d ", val);

(same here, OK to have the trailing whitespace for JSON?)

Quoted 22 lines
ip/ipmptcp.c new file +22 -0
+	}
+	print_string(PRINT_FP, NULL, "%s", "\n");
+	fflush(stdout);
+	close_json_object();
+	return 0;
+}
+
+static int mptcp_limit_get_set(int argc, char **argv, int cmd)
+{
+	bool do_get = cmd == MPTCP_PM_CMD_GET_LIMITS;
+	MPTCP_REQUEST(req, cmd, NLM_F_REQUEST);
+	struct nlmsghdr *answer;
+	int ret;
+
+	ret = mptcp_parse_limit(argc, argv, &req.n);
+	if (ret < 0)
+		return -1;
+
+	if (rtnl_talk(&genl_rth, &req.n, do_get ? &answer : NULL) < 0)
+		return -2;
+
+	if (do_get)

ip/ipmptcp.c line 405

Quoted 10 lines
ip/ipmptcp.c new file +10 -0
+		return print_mptcp_limit(answer, stdout);
+	return 0;
+}
+
+int do_mptcp(int argc, char **argv)
+{
+	if (argc == 0)
+		usage();
+
+	if (!matches(*argv, "help"))

It is maybe just me but it looks strange to see "!matches" when the goal is to see if it matches :-)

Maybe clearer with "matches(...) == 0" like in most of the code? (same below and above in this file)

Quoted 18 lines
ip/ipmptcp.c new file +18 -0
+		usage();
+
+	if (genl_init_handle(&genl_rth, MPTCP_PM_NAME, &genl_family))
+		exit(1);
+
+	if (!matches(*argv, "endpoint")) {
+		NEXT_ARG_FWD();
+		if (argc == 0)
+			return mptcp_addr_show(0, NULL);
+
+		if (!matches(*argv, "add"))
+			return mptcp_addr_modify(argc-1, argv+1,
+						 MPTCP_PM_CMD_ADD_ADDR);
+		if (!matches(*argv, "delete"))
+			return mptcp_addr_modify(argc-1, argv+1,
+						 MPTCP_PM_CMD_DEL_ADDR);
+		if (!matches(*argv, "show"))
+			return mptcp_addr_show(argc-1, argv+1);

ip/ipmptcp.c line 433

Quoted 10 lines
ip/ipmptcp.c new file +10 -0
+		if (!matches(*argv, "flush"))
+			return mptcp_addr_flush(argc-1, argv+1);
+
+		goto unknown;
+	}
+
+	if (!matches(*argv, "limits")) {
+		NEXT_ARG_FWD();
+		if (argc == 0)
+			return mptcp_limit_get_set(argc-1, argv+1,

Is it OK here with "argc-1" == -1?

Cheers,
Matt

Quoted 16 lines
ip/ipmptcp.c new file +16 -0
+						   MPTCP_PM_CMD_GET_LIMITS);
+
+		if (!matches(*argv, "set"))
+			return mptcp_limit_get_set(argc-1, argv+1,
+						   MPTCP_PM_CMD_SET_LIMITS);
+		if (!matches(*argv, "show"))
+			return mptcp_limit_get_set(argc-1, argv+1,
+						   MPTCP_PM_CMD_GET_LIMITS);
+	}
+
+unknown:
+	fprintf(stderr,
+		"Command \"%s\" is unknown, try \"ip mptcp help\".\n",
+		*argv);
+	exit(-1);
+}
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
#8 lore raw

[MPTCP] Re: [PATCH v2 3/4] ss: allow dumping MPTCP subflow information

In reply to Paolo Abeni

Hi Davide,

Quoted 6 lines · Paolo Abeni

From: Davide Caratti <dcaratti(a)redhat.com>

[root(a)f31 packetdrill]# ss -tni

ESTAB 0 0 192.168.82.247:8080 192.0.2.1:35273

           cubic wscale:7,8 [...] tcp-ulp-mptcp flags: Mec token:0000(id:0)/5f856c60(id:0) seq:b810457db34209a5 sfseq:1 ssnoff:0 maplen:190

Thank you for this patch!

For the output, should it not be "flags:Mec" without space? If no, I guess it should not contain space for the parsing (flags: Mec)

Is there a place where these flags can be explained?

Quoted 46 lines
Signed-off-by Davide Caratti <dcaratti(a)redhat.com>
---
  misc/ss.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 62 insertions(+)
misc/ss.c +26 -0
index 3ef151fb..3fac4be8 100644
@@ -53,6 +53,7 @@
  #include <linux/tipc_netlink.h>
  #include <linux/tipc_sockets_diag.h>
  #include <linux/tls.h>
+#include <linux/mptcp.h>
 
  /* AF_VSOCK/PF_VSOCK is only provided since glibc 2.18 */
  #ifndef PF_VSOCK
@@ -2836,6 +2837,59 @@ static void tcp_tls_conf(const char *name, struct rtattr *attr)
  	}
  }
 
+static void mptcp_subflow_info(struct rtattr *tb[])
+{
+	u_int32_t flags = 0;
+
+	if (tb[MPTCP_SUBFLOW_ATTR_FLAGS]) {
+		char caps[32 + 1] = { 0 }, *cap = &caps[0];
+
+		flags = rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_FLAGS]);
+
+		if (flags & MPTCP_SUBFLOW_FLAG_MCAP_REM)
+			*cap++ = 'M';
+		if (flags & MPTCP_SUBFLOW_FLAG_MCAP_LOC)
+			*cap++ = 'm';
+		if (flags & MPTCP_SUBFLOW_FLAG_JOIN_REM)
+			*cap++ = 'J';
+		if (flags & MPTCP_SUBFLOW_FLAG_JOIN_LOC)
+			*cap++ = 'j';
+		if (flags & MPTCP_SUBFLOW_FLAG_BKUP_REM)
+			*cap++ = 'B';
+		if (flags & MPTCP_SUBFLOW_FLAG_BKUP_LOC)
+			*cap++ = 'b';
+		if (flags & MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED)
+			*cap++ = 'e';
+		if (flags & MPTCP_SUBFLOW_FLAG_CONNECTED)
+			*cap++ = 'c';

misc/ss.c static void tcp_tls_conf(const char *name, struct rtattr *attr) · line 2874

Quoted 10 lines
misc/ss.c +10 -0
+		if (flags & MPTCP_SUBFLOW_FLAG_MAPVALID)
+			*cap++ = 'v';
+		if (flags)
+			out(" flags:%s", caps);
+	}
+	if (tb[MPTCP_SUBFLOW_ATTR_TOKEN_REM] &&
+	    tb[MPTCP_SUBFLOW_ATTR_TOKEN_LOC] &&
+	    tb[MPTCP_SUBFLOW_ATTR_ID_REM] &&
+	    tb[MPTCP_SUBFLOW_ATTR_ID_LOC])
+		out(" token:%04x(id:%d)/%04x(id:%d)",

For the id, I guess it is fine with %d (because it's a u8) and not %u? (Just to avoid possible warnings with the compiler ;-) )

Cheers,
Matt

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
#11 lore raw

[MPTCP] Re: [PATCH v2 4/4] man: mptcp man page

In reply to Paolo Abeni

Hi Paolo,

Quoted 1 line · Paolo Abeni

describe the mptcp subcommands implemented so far.

(...)

Quoted 5 lines
man/man8/ip-mptcp.8 new file +0 -0
new file mode 100644
index 00000000..5ed0457b

(...)

Quoted 10 lines

+.ti -8
+.BR "ip mptcp endpoint add "
+.IR IFADDR
+.RB "[ " dev
+.IR IFNAME " ]"
+.RB "[ " id
+.I ID
+.RB "] [ "
+.I FLAG-LIST
+.RB "] "

Should we show the same in the code for "usage()" (using FLAG-LIST)

Quoted 23 lines

+.ti -8
+.BR "ip mptcp endpoint del id "
+.I ID

man/man8/ip-mptcp.8 new file +20 -0
+
+.ti -8
+.BR "ip mptcp endpoint show "
+.RB "[ " id
+.I ID
+.RB "]"
+
+.ti -8
+.BR "ip mptcp endpoint flush"
+
+.ti -8
+.IR FLAG-LIST " := [ "  FLAG-LIST " ] " FLAG
+
+.ti -8
+.IR FLAG " := ["
+.B signal
+.RB "|"
+.B subflow
+.RB "|"
+.B backup

man/man8/ip-mptcp.8 line 64

Quoted 10 lines
man/man8/ip-mptcp.8 new file +10 -0
+.RB  "]"
+
+.ti -8
+.BR "ip mptcp limits set "
+.RB "[ "
+.B subflow
+.IR SUBFLOW_NR " ]"
+.RB "[ "
+.B add_addr_accepted
+.IR  ADD_ADDR_ACCEPTED_NR " ]"

Should it be?

set { subflow SUBFLOW_NR | add_addr_accepted ADD_ADDR_ACCEPTED_NR }

or:

set { subflow | add_addr_accepted } NR

man/man8/ip-mptcp.8 line 71

Quoted 7 lines
man/man8/ip-mptcp.8 new file +7 -0
+
+.ti -8
+.BR "ip mptcp limits show"
+
+.SH DESCRIPTION
+
+MPTCP is a transport protocol build on top of TCP that allows TCP

(I guess it could be nice if some English natives can have a look at this :) )
I think here you need s/build/built/

man/man8/ip-mptcp.8

Quoted 2 lines
man/man8/ip-mptcp.8 new file +2 -0
+connections to use multiple paths to maximize resource usage and increase
+redundancy.

Should we mention that the socket needs to be open using the MPTCP option?

Quoted 14 lines

The ip-mptcp sub-commands allow configuring several aspects of the

man/man8/ip-mptcp.8 new file +13 -0
+MPTCP path manager, which is in charge of subflows creation:
+
+.P
+The
+.B endpoint
+object specifies the IP addresses that will be used and/or announced for
+additional subflows:
+
+.TS
+l l.
+ip mptcp endpoint add	add new MPTCP endpoint
+ip mptcp endpoint delete	delete existing MPTCP endpoint
+ip mptcp endpoint show	get existing MPTCP endpoint

man/man8/ip-mptcp.8 line 96

Quoted 10 lines
man/man8/ip-mptcp.8 new file +10 -0
+ip mptcp endpoint flush	flush all existing MPTCP endpoints
+.TE
+
+.TP
+.IR ID
+is a unique numeric identifier for the given endpoint
+
+.TP
+.BR signal
+the endpoint will be announced/signaled to each peer via an ADD_ADDR MPTCP

s/signaled/signalled/

Cheers,
Matt

Quoted 47 lines
man/man8/ip-mptcp.8 new file +46 -0
+sub-option
+
+.TP
+.BR subflow
+If the MPTCP limits allow for additional subflows creation, the endpoint will
+be used as the source address to create an additional subflow after that
+the MPTCP connection is established.
+
+.TP
+.BR backup
+the endpoint will be announced as a backup address, if this is a
+.BR signal
+endpoint, or the subflow will be created as a backup one if this a
+.BR subflow
+endpoint
+
+.sp
+.PP
+The
+.B limits
+object specifies the constraints for subflow creations:
+
+.TS
+l l.
+ip mptcp limits show	get current MPTCP subflow creation limits
+ip mptcp limits set	change the MPTCP subflow creation limits
+.TE
+
+.TP
+.IR SUBFLOW_NR
+specifies the maximum number of additional subflows allowed for each MPTCP
+connection. Additional subflows can be created due to: incoming accepted
+ADD_ADDR option, local
+.BR subflow
+endpoints, additional subflows started by the peer.
+
+.TP
+.IR ADD_ADDR_ACCEPTED_NR
+specifies the maximum number of ADD_ADDR suboptions accepted for each MPTCP
+connection. The MPTCP path manager will try to create a new subflow for
+each accepted ADD_ADDR option, respecting the
+.IR SUBFLOW_NR
+limit.
+
+.SH AUTHOR
+Original Manpage by Paolo Abeni <pabeni(a)redhat.com>
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
author
#4 lore raw

[MPTCP] Re: [PATCH v2 2/4] add support for mptcp netlink interface.

In reply to Matthieu Baerts

Hi,

Thank you for the usual very detailed review! ;)

Quoted 51 lines · Matthieu Baerts

Hi Paolo,

Quoted 8 lines · Paolo Abeni

Implement basic commands to:
- manipulate MPTCP endpoints list
- manipulate MPTCP connection limits

Examples:
1. Allows multiple subflows per MPTCP connection

    $ ip mptcp limits set subflows 2
Quoted 8 lines

2. Accept ADD_ADDR announcement from the peer (server):

    $ ip mptcp limits set add_addr_accepted 2

3. Add a ipv4 address to be annunced for backup subflows:

    $ ip mptcp endpoint add 10.99.1.2 signal backup

4. Add an ipv6 address used as source for additional subflows:

    $ ip mptcp endpoint add 2001::2 subflow

Thank you for looking at that!

(detail, there is a dot at the end of the subject)

(...)

Quoted 25 lines
ip/ipmptcp.c new file +19 -0
new file mode 100644
index 00000000..452629f4
@@ -0,0 +1,449 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <stdio.h>
+#include <string.h>
+#include <rt_names.h>
+#include <errno.h>
+
+#include <linux/genetlink.h>
+#include <linux/mptcp.h>
+
+#include "utils.h"
+#include "ip_common.h"
+#include "libgenl.h"
+#include "json_print.h"
+
+static void usage(void)
+{
+	fprintf(stderr,
+		"Usage:	ip mptcp endpoint add <address> [dev <name>] [id <id>] [signal] [subflow] [backup]\n"
Quoted 8 lines

ip/ipmptcp.c line 24

Quoted 5 lines
ip/ipmptcp.c new file +5 -0
+		"	ip mptcp endpoint delete id <id>\n"
+		"	ip mptcp endpoint show [id <id>]\n"
+		"	ip mptcp endpoint flush\n"
+		"	ip mptcp limits set [subflows <nr>] [add_addr_accepted <nr>]\n"
+		"	ip mptcp limits show\n");

detail: it seems to me that the arguments are usually presented with capital letters, extra spaces and new lines when it is too long, e.g.

I think the 80 columns limit on code line is not enforced - actually breaking it will make 'help' more readable con common-size shell.

I propose to use capital letters and following indentation:

"Usage: ip mptcp endpoint add ADDRESS [dev NAME] [id ID]\n"
" [signal] [subflow] [backup]\n"
" ip mptcp endpoint delete id ID\n"
" ip mptcp endpoint show [id ID]\n"
" ip mptcp endpoint flush\n"
" ip mptcp limits set [subflows NR] [add_addr_accepted NR]\n"
" ip mptcp limits show\n");

Quoted 8 lines

"Usage: ip mptcp endpoint add ADDRESS [ dev NAME ] [ id ID ]\n"
" [ signal ] [ subflow ]\n"
" [ backup ]\n"
" ip mptcp endpoint delete id ID\n"
" ip mptcp endpoint show [ id ID ]\n"
" ip mptcp endpoint flush\n"
" ip mptcp limits set { subflows | add_addr_accepted } NR\n"

If I read correctly, this is a little different from what we support, as we can set bot 'subflow' and 'add_addr_accepted' in the same command.

This should also answer a question on patch 4/4 ;)

Quoted 3 lines
     "       ip mptcp limits show\n");

It seems you can also use an attribute expended later:

Yep, but I think it's not needed when the syntax is simple enough, as in this scenario.

Quoted 47 lines

"Usage: ip mptcp endpoint add ADDRESS SELECTOR\n"
" ip mptcp endpoint delete id ID\n"
(...)
"SELECTOR := [ dev NAME ] [ id ID ] [ signal ] [ subflow ]\n"
" [ backup ]\n"

Quoted 40 lines
ip/ipmptcp.c new file +40 -0
+	exit(-1);
+}
+
+/* netlink socket */
+static struct rtnl_handle genl_rth = { .fd = -1 };
+static int genl_family = -1;
+
+#define MPTCP_BUFLEN	4096
+#define MPTCP_REQUEST(_req,  _cmd, _flags)	\
+	GENL_REQUEST(_req, MPTCP_BUFLEN, genl_family, 0,	\
+		     MPTCP_PM_VER, _cmd, _flags)
+
+/* Mapping from argument to address flag mask */
+static const struct {
+	const char *name;
+	unsigned long value;
+} mptcp_addr_flag_names[] = {
+	{ "signal",		MPTCP_PM_ADDR_FLAG_SIGNAL },
+	{ "subflow",		MPTCP_PM_ADDR_FLAG_SUBFLOW },
+	{ "backup",		MPTCP_PM_ADDR_FLAG_BACKUP },
+};
+
+static void print_mptcp_addr_flags(unsigned int flags)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(mptcp_addr_flag_names); i++) {
+		unsigned long mask = mptcp_addr_flag_names[i].value;
+
+		if (flags & mask) {
+			print_string(PRINT_FP, NULL, "%s ",
+				     mptcp_addr_flag_names[i].name);
+			print_bool(PRINT_JSON,
+				   mptcp_addr_flag_names[i].name, NULL, true);
+		}
+
+		flags &= ~mask;
+	}
+
+	if (flags) {
Quoted 8 lines

ip/ipmptcp.c line 70

Quoted 5 lines
ip/ipmptcp.c new file +5 -0
+		/* unknown flags */
+		SPRINT_BUF(b1);
+
+		snprintf(b1, sizeof(b1), "%02x", flags);
+		print_string(PRINT_ANY, "rawflags", "rawflags %s ", b1);

(it looks strange to me to end with a space even in json context but I don't know the code of iproute2 :) )

It's just to keep the code simple, otherwise we have to check for 'last flag' condition.

Quoted 11 lines

ip/ipmptcp.c line 79

Quoted 9 lines
ip/ipmptcp.c new file +9 -0
+	}
+}
+
+static int get_flags(const char *arg, __u32 *flags)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(mptcp_addr_flag_names); i++) {
+		if (strcmp(arg, mptcp_addr_flag_names[i].name))

(can we use strcmp or do they force strncmp() for the flags? or matches()?)

ip address uses 'strcmp', so that exact match is enforced, while e.g. ip neigh uses 'matches'. I guess either would be fine.

Quoted 22 lines
Quoted 22 lines
ip/ipmptcp.c new file +21 -0
+			continue;
+
+		*flags |= mptcp_addr_flag_names[i].value;
+		return 0;
+	}
+	return -1;
+}
+
+static int mptcp_parse_opt(int argc, char **argv, struct nlmsghdr *n,
+			 bool adding)
+{
+	struct rtattr *attr_addr;
+	bool addr_set = false;
+	inet_prefix address;
+	bool id_set = false;
+	__u32 index = 0;
+	__u32 flags = 0;
+	__u8 id = 0;
+
+	ll_init_map(&rth);
+	while (argc > 0) {
Quoted 8 lines

ip/ipmptcp.c line 106

Quoted 6 lines
ip/ipmptcp.c new file +6 -0
+		if (get_flags(*argv, &flags) == 0) {
+		} else if (!matches(*argv, "id")) {
+			NEXT_ARG();
+
+			if (get_u8(&id, *argv, 0)) {
+				invarg("invalid TTL\n", *argv);

detail: do you mean ID instead of TTL?

yep!

Quoted 25 lines

ip/ipmptcp.c line 106

Quoted 2 lines
ip/ipmptcp.c new file +1 -0
+				return -1;

detail: it seems "invarg()" already does a "exit(-1)". So we can remove "return -1", same below.

And it prints:

   "Error: argument \"%s\" is wrong: %s\n", <2nd arg>, <1st arg>

ip/ipmptcp.c line 118

Quoted 11 lines
ip/ipmptcp.c new file +11 -0
+			}
+			id_set = true;
+		} else if (!matches(*argv, "dev")) {
+			const char *ifname;
+
+			NEXT_ARG();
+
+			ifname = *argv;
+
+			if (check_ifname(ifname)) {
+				invarg("name", ifname);

Even if "invarg" already adds "\n", I see "\n" is always added at the end of the 1st arg.

Quoted 1 line

And maybe here, we can say: "invalid interface name\n"

ok

Quoted 10 lines

ip/ipmptcp.c line 125

Quoted 8 lines
ip/ipmptcp.c new file +7 -0
+				return -1;
+			}
+
+			index = ll_name_to_index(ifname);
+
+			if (!index) {
+				invarg("name", ifname);

maybe: "Device does not exist\n"

ok, but with initial lower case letter.

Quoted 8 lines

ip/ipmptcp.c line 132

Quoted 8 lines
ip/ipmptcp.c new file +7 -0
+				return -1;
+			}
+		} else if (get_addr(&address, *argv, AF_UNSPEC) == 0) {
+			addr_set = true;
+		} else {
+			invarg("unknown argument", *argv);
+			usage();

here 'usage' is never reached, I'll drop it

Quoted 8 lines

ip/ipmptcp.c line 138

Quoted 6 lines
ip/ipmptcp.c new file +6 -0
+		}
+		NEXT_ARG_FWD();
+	}
+
+	if (!addr_set && adding) {
+		fprintf(stderr, "mptcp: must set 'address' on add\n");

detail: it seems you can use missarg("ADDRESS") here. It does an exit(-1).

ok

Quoted 8 lines

ip/ipmptcp.c line 143

Quoted 6 lines
ip/ipmptcp.c new file +5 -0
+		return -1;
+	}
+
+	if (!id_set && !adding) {
+		fprintf(stderr, "mptcp: must set 'id'\n");

detail: same here with missarg("ID").

ok

Quoted 56 lines
Quoted 56 lines
ip/ipmptcp.c new file +55 -0
+		return -1;
+	}
+
+	attr_addr = addattr_nest(n, MPTCP_BUFLEN,
+				 MPTCP_PM_ATTR_ADDR | NLA_F_NESTED);
+	if (id_set)
+		addattr8(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_ID, id);
+	if (flags)
+		addattr32(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_FLAGS, flags);
+	if (index)
+		addattr32(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_IF_IDX, index);
+	if (addr_set) {
+		int type;
+
+		addattr16(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_FAMILY,
+			  address.family);
+		type = address.family == AF_INET ? MPTCP_PM_ADDR_ATTR_ADDR4 :
+						   MPTCP_PM_ADDR_ATTR_ADDR6;
+		addattr_l(n, MPTCP_BUFLEN, type, &address.data,
+			  address.bytelen);
+	}
+
+	addattr_nest_end(n, attr_addr);
+	return 0;
+}
+
+static int mptcp_addr_modify(int argc, char **argv, int cmd)
+{
+	MPTCP_REQUEST(req, cmd, NLM_F_REQUEST);
+	int ret;
+
+	ret = mptcp_parse_opt(argc, argv, &req.n, cmd == MPTCP_PM_CMD_ADD_ADDR);
+	if (ret)
+		return ret;
+
+	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
+		return -2;
+
+	return 0;
+}
+
+static int print_mptcp_addrinfo(struct rtattr *addrinfo)
+{
+	struct rtattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1];
+	__u8 family = AF_UNSPEC, addr_attr_type;
+	const char *ifname;
+	unsigned int flags;
+	int index;
+	__u16 id;
+
+	parse_rtattr_nested(tb, MPTCP_PM_ADDR_ATTR_MAX, addrinfo);
+
+	open_json_object(NULL);
+	if (tb[MPTCP_PM_ADDR_ATTR_FAMILY])
+		family = rta_getattr_u8(tb[MPTCP_PM_ADDR_ATTR_FAMILY]);
Quoted 8 lines

ip/ipmptcp.c line 203

Quoted 5 lines
ip/ipmptcp.c new file +5 -0
+
+	addr_attr_type = family == AF_INET ? MPTCP_PM_ADDR_ATTR_ADDR4 :
+					     MPTCP_PM_ADDR_ATTR_ADDR6;
+	if (tb[addr_attr_type]) {
+		print_string(PRINT_ANY, "address", "%s ",

(same here, is it OK to have a space at then end in a JSON context? Same below)

'fdb' does the same. I guess it's ok.

Quoted 11 lines

ip/ipmptcp.c line 405

Quoted 5 lines
ip/ipmptcp.c new file +5 -0
+{
+	if (argc == 0)
+		usage();
+
+	if (!matches(*argv, "help"))

It is maybe just me but it looks strange to see "!matches" when the goal is to see if it matches :-)

Maybe clearer with "matches(...) == 0" like in most of the code? (same below and above in this file)

ok

Quoted 22 lines
Quoted 22 lines
ip/ipmptcp.c new file +22 -0
+		usage();
+
+	if (genl_init_handle(&genl_rth, MPTCP_PM_NAME, &genl_family))
+		exit(1);
+
+	if (!matches(*argv, "endpoint")) {
+		NEXT_ARG_FWD();
+		if (argc == 0)
+			return mptcp_addr_show(0, NULL);
+
+		if (!matches(*argv, "add"))
+			return mptcp_addr_modify(argc-1, argv+1,
+						 MPTCP_PM_CMD_ADD_ADDR);
+		if (!matches(*argv, "delete"))
+			return mptcp_addr_modify(argc-1, argv+1,
+						 MPTCP_PM_CMD_DEL_ADDR);
+		if (!matches(*argv, "show"))
+			return mptcp_addr_show(argc-1, argv+1);
+		if (!matches(*argv, "flush"))
+			return mptcp_addr_flush(argc-1, argv+1);
+
+		goto unknown;
Quoted 8 lines

ip/ipmptcp.c line 433

Quoted 6 lines
ip/ipmptcp.c new file +6 -0
+	}
+
+	if (!matches(*argv, "limits")) {
+		NEXT_ARG_FWD();
+		if (argc == 0)
+			return mptcp_limit_get_set(argc-1, argv+1,

Is it OK here with "argc-1" == -1?

It's ok because mptcp_limit_get_set checks for positive argc value, anyhow I'll change to '0, NULL'.

Quoted 4 lines

Cheers,
Matt

Quoted 15 lines
Quoted 5 lines
ip/ipmptcp.c new file +5 -0
+						   MPTCP_PM_CMD_GET_LIMITS);
+
+		if (!matches(*argv, "set"))
+			return mptcp_limit_get_set(argc-1, argv+1,
+						   MPTCP_PM_CMD_SET_LIMITS);

ip/ipmptcp.c line 448

Quoted 10 lines
ip/ipmptcp.c new file +10 -0
+		if (!matches(*argv, "show"))
+			return mptcp_limit_get_set(argc-1, argv+1,
+						   MPTCP_PM_CMD_GET_LIMITS);
+	}
+
+unknown:
+	fprintf(stderr,
+		"Command \"%s\" is unknown, try \"ip mptcp help\".\n",
+		*argv);
+	exit(-1);

and here invarg("unknown", *argv) would fit.

Quoted 1 line

ip/ipmptcp.c line 251

Quoted 1 line
ip/ipmptcp.c new file +1 -0
+}

Thanks!

/P

author
#12 lore raw

[MPTCP] Re: [PATCH v2 4/4] man: mptcp man page

In reply to Matthieu Baerts
Quoted 26 lines · Matthieu Baerts

Hi Paolo,

Quoted 1 line · Paolo Abeni

describe the mptcp subcommands implemented so far.

(...)

Quoted 5 lines
man/man8/ip-mptcp.8 new file +0 -0
new file mode 100644
index 00000000..5ed0457b

(...)

Quoted 10 lines

+.ti -8
+.BR "ip mptcp endpoint add "
+.IR IFADDR
+.RB "[ " dev
+.IR IFNAME " ]"
+.RB "[ " id
+.I ID
+.RB "] [ "
+.I FLAG-LIST
+.RB "] "

Quoted 1 line

Should we show the same in the code for "usage()" (using FLAG-LIST)

oks. I'll do that!

Quoted 36 lines
Quoted 23 lines

+.ti -8
+.BR "ip mptcp endpoint del id "
+.I ID

man/man8/ip-mptcp.8 new file +20 -0
+
+.ti -8
+.BR "ip mptcp endpoint show "
+.RB "[ " id
+.I ID
+.RB "]"
+
+.ti -8
+.BR "ip mptcp endpoint flush"
+
+.ti -8
+.IR FLAG-LIST " := [ "  FLAG-LIST " ] " FLAG
+
+.ti -8
+.IR FLAG " := ["
+.B signal
+.RB "|"
+.B subflow
+.RB "|"
+.B backup

man/man8/ip-mptcp.8 line 64

Quoted 10 lines
man/man8/ip-mptcp.8 new file +10 -0
+.RB  "]"
+
+.ti -8
+.BR "ip mptcp limits set "
+.RB "[ "
+.B subflow
+.IR SUBFLOW_NR " ]"
+.RB "[ "
+.B add_addr_accepted
+.IR  ADD_ADDR_ACCEPTED_NR " ]"

Should it be?

Quoted 5 lines
   set { subflow SUBFLOW_NR | add_addr_accepted ADD_ADDR_ACCEPTED_NR }

or:

set { subflow | add_addr_accepted } NR

I think that the text you suggest has different semantic.

Quoted 14 lines

man/man8/ip-mptcp.8 line 71

Quoted 9 lines
man/man8/ip-mptcp.8 new file +7 -0
+
+.ti -8
+.BR "ip mptcp limits show"
+
+.SH DESCRIPTION
+
+MPTCP is a transport protocol build on top of TCP that allows TCP

(I guess it could be nice if some English natives can have a look at this :) )
I think here you need s/build/built/

Quoted 4 lines

man/man8/ip-mptcp.8

Quoted 2 lines
man/man8/ip-mptcp.8 new file +2 -0
+connections to use multiple paths to maximize resource usage and increase
+redundancy.

Should we mention that the socket needs to be open using the MPTCP option?

I think that would should be in a different man page: man(7) mptcp in the kernel man pages.

Quoted 18 lines
Quoted 18 lines

The ip-mptcp sub-commands allow configuring several aspects of the

man/man8/ip-mptcp.8 new file +17 -0
+MPTCP path manager, which is in charge of subflows creation:
+
+.P
+The
+.B endpoint
+object specifies the IP addresses that will be used and/or announced for
+additional subflows:
+
+.TS
+l l.
+ip mptcp endpoint add	add new MPTCP endpoint
+ip mptcp endpoint delete	delete existing MPTCP endpoint
+ip mptcp endpoint show	get existing MPTCP endpoint
+ip mptcp endpoint flush	flush all existing MPTCP endpoints
+.TE
+
+.TP
Quoted 8 lines

man/man8/ip-mptcp.8 line 96

Quoted 6 lines

+.IR ID

man/man8/ip-mptcp.8 new file +5 -0
+is a unique numeric identifier for the given endpoint
+
+.TP
+.BR signal
+the endpoint will be announced/signaled to each peer via an ADD_ADDR MPTCP

s/signaled/signalled/

ok

Quoted 42 lines

Cheers,
Matt

Quoted 38 lines
man/man8/ip-mptcp.8 new file +38 -0
+sub-option
+
+.TP
+.BR subflow
+If the MPTCP limits allow for additional subflows creation, the endpoint will
+be used as the source address to create an additional subflow after that
+the MPTCP connection is established.
+
+.TP
+.BR backup
+the endpoint will be announced as a backup address, if this is a
+.BR signal
+endpoint, or the subflow will be created as a backup one if this a
+.BR subflow
+endpoint
+
+.sp
+.PP
+The
+.B limits
+object specifies the constraints for subflow creations:
+
+.TS
+l l.
+ip mptcp limits show	get current MPTCP subflow creation limits
+ip mptcp limits set	change the MPTCP subflow creation limits
+.TE
+
+.TP
+.IR SUBFLOW_NR
+specifies the maximum number of additional subflows allowed for each MPTCP
+connection. Additional subflows can be created due to: incoming accepted
+ADD_ADDR option, local
+.BR subflow
+endpoints, additional subflows started by the peer.
+
+.TP
+.IR ADD_ADDR_ACCEPTED_NR
Quoted 8 lines

man/man8/ip-mptcp.8 line 142

Quoted 8 lines
man/man8/ip-mptcp.8 new file +8 -0
+specifies the maximum number of ADD_ADDR suboptions accepted for each MPTCP
+connection. The MPTCP path manager will try to create a new subflow for
+each accepted ADD_ADDR option, respecting the
+.IR SUBFLOW_NR
+limit.
+
+.SH AUTHOR
+Original Manpage by Paolo Abeni <pabeni(a)redhat.com>

Thanks,

Paolo

#5 lore raw

[MPTCP] Re: [PATCH v2 2/4] add support for mptcp netlink interface.

In reply to Paolo Abeni

Hi Paolo,

Thank you for the answers!

Quoted 3 lines · Paolo Abeni

Hi,

Thank you for the usual very detailed review! ;)

I hope it is not too detailed and would slow you down! Please tell me if there are stuff I can skip in my future reviews :)

Quoted 62 lines · Matthieu Baerts
Quoted 51 lines

Hi Paolo,

Quoted 8 lines · Paolo Abeni

Implement basic commands to:
- manipulate MPTCP endpoints list
- manipulate MPTCP connection limits

Examples:
1. Allows multiple subflows per MPTCP connection

     $ ip mptcp limits set subflows 2
Quoted 8 lines

2. Accept ADD_ADDR announcement from the peer (server):

     $ ip mptcp limits set add_addr_accepted 2

3. Add a ipv4 address to be annunced for backup subflows:

     $ ip mptcp endpoint add 10.99.1.2 signal backup

4. Add an ipv6 address used as source for additional subflows:

     $ ip mptcp endpoint add 2001::2 subflow

Thank you for looking at that!

(detail, there is a dot at the end of the subject)

(...)

Quoted 25 lines
ip/ipmptcp.c new file +19 -0
new file mode 100644
index 00000000..452629f4
@@ -0,0 +1,449 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <stdio.h>
+#include <string.h>
+#include <rt_names.h>
+#include <errno.h>
+
+#include <linux/genetlink.h>
+#include <linux/mptcp.h>
+
+#include "utils.h"
+#include "ip_common.h"
+#include "libgenl.h"
+#include "json_print.h"
+
+static void usage(void)
+{
+	fprintf(stderr,
+		"Usage:	ip mptcp endpoint add <address> [dev <name>] [id <id>] [signal] [subflow] [backup]\n"
Quoted 8 lines

ip/ipmptcp.c line 24

Quoted 5 lines
ip/ipmptcp.c new file +5 -0
+		"	ip mptcp endpoint delete id <id>\n"
+		"	ip mptcp endpoint show [id <id>]\n"
+		"	ip mptcp endpoint flush\n"
+		"	ip mptcp limits set [subflows <nr>] [add_addr_accepted <nr>]\n"
+		"	ip mptcp limits show\n");

detail: it seems to me that the arguments are usually presented with capital letters, extra spaces and new lines when it is too long, e.g.

Quoted 2 lines

I think the 80 columns limit on code line is not enforced - actually breaking it will make 'help' more readable con common-size shell.

Indeed, I see in "ip link help" some lines that are longer than 80 chars but with a certain limit.

Quoted 10 lines

I propose to use capital letters and following indentation:

"Usage: ip mptcp endpoint add ADDRESS [dev NAME] [id ID]\n"
" [signal] [subflow] [backup]\n"
" ip mptcp endpoint delete id ID\n"
" ip mptcp endpoint show [id ID]\n"
" ip mptcp endpoint flush\n"
" ip mptcp limits set [subflows NR] [add_addr_accepted NR]\n"
" ip mptcp limits show\n");

When looking at the other help commands, it seems they prefer to have spaces on both sides of "[" and "]", so more like this:

"Usage: ip mptcp endpoint add ADDRESS [ dev NAME ] [ id ID ]\n"
" [ signal ] [ subflow ] [ backup ]\n"
" ip mptcp endpoint delete id ID\n"
" ip mptcp endpoint show [ id ID ]\n"
" ip mptcp endpoint flush\n"
" ip mptcp limits set [ subflows NR ] [ add_addr_accepted NR ]\n"
" ip mptcp limits show\n");

But maybe it is not mandatory.

Quoted 10 lines
Quoted 9 lines

"Usage: ip mptcp endpoint add ADDRESS [ dev NAME ] [ id ID ]\n"
" [ signal ] [ subflow ]\n"
" [ backup ]\n"
" ip mptcp endpoint delete id ID\n"
" ip mptcp endpoint show [ id ID ]\n"
" ip mptcp endpoint flush\n"
" ip mptcp limits set { subflows | add_addr_accepted } NR\n"

Quoted 5 lines

If I read correctly, this is a little different from what we support, as we can set bot 'subflow' and 'add_addr_accepted' in the same command.

This should also answer a question on patch 4/4 ;)

Indeed sorry I forgot both arguments can be used.

Quoted 8 lines
Quoted 5 lines

      "       ip mptcp limits show\n");

It seems you can also use an attribute expended later:

Yep, but I think it's not needed when the syntax is simple enough, as in this scenario.

Indeed but I am also fine with your FLAG-LIST :)

Quoted 56 lines
Quoted 47 lines

"Usage: ip mptcp endpoint add ADDRESS SELECTOR\n"
" ip mptcp endpoint delete id ID\n"
(...)
"SELECTOR := [ dev NAME ] [ id ID ] [ signal ] [ subflow ]\n"
" [ backup ]\n"

Quoted 40 lines
ip/ipmptcp.c new file +40 -0
+	exit(-1);
+}
+
+/* netlink socket */
+static struct rtnl_handle genl_rth = { .fd = -1 };
+static int genl_family = -1;
+
+#define MPTCP_BUFLEN	4096
+#define MPTCP_REQUEST(_req,  _cmd, _flags)	\
+	GENL_REQUEST(_req, MPTCP_BUFLEN, genl_family, 0,	\
+		     MPTCP_PM_VER, _cmd, _flags)
+
+/* Mapping from argument to address flag mask */
+static const struct {
+	const char *name;
+	unsigned long value;
+} mptcp_addr_flag_names[] = {
+	{ "signal",		MPTCP_PM_ADDR_FLAG_SIGNAL },
+	{ "subflow",		MPTCP_PM_ADDR_FLAG_SUBFLOW },
+	{ "backup",		MPTCP_PM_ADDR_FLAG_BACKUP },
+};
+
+static void print_mptcp_addr_flags(unsigned int flags)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(mptcp_addr_flag_names); i++) {
+		unsigned long mask = mptcp_addr_flag_names[i].value;
+
+		if (flags & mask) {
+			print_string(PRINT_FP, NULL, "%s ",
+				     mptcp_addr_flag_names[i].name);
+			print_bool(PRINT_JSON,
+				   mptcp_addr_flag_names[i].name, NULL, true);
+		}
+
+		flags &= ~mask;
+	}
+
+	if (flags) {
Quoted 8 lines

ip/ipmptcp.c line 70

Quoted 5 lines
ip/ipmptcp.c new file +5 -0
+		/* unknown flags */
+		SPRINT_BUF(b1);
+
+		snprintf(b1, sizeof(b1), "%02x", flags);
+		print_string(PRINT_ANY, "rawflags", "rawflags %s ", b1);

(it looks strange to me to end with a space even in json context but I don't know the code of iproute2 :) )

Quoted 2 lines

It's just to keep the code simple, otherwise we have to check for 'last flag' condition.

Yes, JSON supports doesn't make the code easy to do. It is maybe fine like that for upstream for the moment.

I was looking at print_flag() from ipmacsec.c. Some are also using arrays for JSON. We can wait for upstream feedback.

Quoted 13 lines
Quoted 12 lines

ip/ipmptcp.c line 79

Quoted 10 lines
ip/ipmptcp.c new file +9 -0
+	}
+}
+
+static int get_flags(const char *arg, __u32 *flags)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(mptcp_addr_flag_names); i++) {
+		if (strcmp(arg, mptcp_addr_flag_names[i].name))

(can we use strcmp or do they force strncmp() for the flags? or matches()?)

Quoted 2 lines

ip address uses 'strcmp', so that exact match is enforced, while e.g. ip neigh uses 'matches'. I guess either would be fine.

Fine for me as long as it is fine for upstream :-)

Quoted 71 lines
Quoted 22 lines
Quoted 22 lines
ip/ipmptcp.c new file +21 -0
+			continue;
+
+		*flags |= mptcp_addr_flag_names[i].value;
+		return 0;
+	}
+	return -1;
+}
+
+static int mptcp_parse_opt(int argc, char **argv, struct nlmsghdr *n,
+			 bool adding)
+{
+	struct rtattr *attr_addr;
+	bool addr_set = false;
+	inet_prefix address;
+	bool id_set = false;
+	__u32 index = 0;
+	__u32 flags = 0;
+	__u8 id = 0;
+
+	ll_init_map(&rth);
+	while (argc > 0) {
Quoted 8 lines

ip/ipmptcp.c line 106

Quoted 6 lines
ip/ipmptcp.c new file +6 -0
+		if (get_flags(*argv, &flags) == 0) {
+		} else if (!matches(*argv, "id")) {
+			NEXT_ARG();
+
+			if (get_u8(&id, *argv, 0)) {
+				invarg("invalid TTL\n", *argv);

detail: do you mean ID instead of TTL?

yep!

Quoted 25 lines

ip/ipmptcp.c line 106

Quoted 2 lines
ip/ipmptcp.c new file +1 -0
+				return -1;

detail: it seems "invarg()" already does a "exit(-1)". So we can remove "return -1", same below.

And it prints:

    "Error: argument \"%s\" is wrong: %s\n", <2nd arg>, <1st arg>

ip/ipmptcp.c line 118

Quoted 11 lines
ip/ipmptcp.c new file +11 -0
+			}
+			id_set = true;
+		} else if (!matches(*argv, "dev")) {
+			const char *ifname;
+
+			NEXT_ARG();
+
+			ifname = *argv;
+
+			if (check_ifname(ifname)) {
+				invarg("name", ifname);

Even if "invarg" already adds "\n", I see "\n" is always added at the end of the 1st arg.

Quoted 1 line

And maybe here, we can say: "invalid interface name\n"

ok

Quoted 10 lines

ip/ipmptcp.c line 125

Quoted 8 lines
ip/ipmptcp.c new file +7 -0
+				return -1;
+			}
+
+			index = ll_name_to_index(ifname);
+
+			if (!index) {
+				invarg("name", ifname);

maybe: "Device does not exist\n"

Quoted 1 line

ok, but with initial lower case letter.

it would make more sense but I see this sentence with the uppercase is used a bit everywhere, never with "d" in fact.

Quoted 98 lines
Quoted 9 lines

ip/ipmptcp.c line 132

Quoted 9 lines
ip/ipmptcp.c new file +7 -0
+				return -1;
+			}
+		} else if (get_addr(&address, *argv, AF_UNSPEC) == 0) {
+			addr_set = true;
+		} else {
+			invarg("unknown argument", *argv);
+			usage();

here 'usage' is never reached, I'll drop it

Quoted 8 lines

ip/ipmptcp.c line 138

Quoted 6 lines
ip/ipmptcp.c new file +6 -0
+		}
+		NEXT_ARG_FWD();
+	}
+
+	if (!addr_set && adding) {
+		fprintf(stderr, "mptcp: must set 'address' on add\n");

detail: it seems you can use missarg("ADDRESS") here. It does an exit(-1).

ok

Quoted 8 lines

ip/ipmptcp.c line 143

Quoted 6 lines
ip/ipmptcp.c new file +5 -0
+		return -1;
+	}
+
+	if (!id_set && !adding) {
+		fprintf(stderr, "mptcp: must set 'id'\n");

detail: same here with missarg("ID").

ok

Quoted 56 lines
Quoted 56 lines
ip/ipmptcp.c new file +55 -0
+		return -1;
+	}
+
+	attr_addr = addattr_nest(n, MPTCP_BUFLEN,
+				 MPTCP_PM_ATTR_ADDR | NLA_F_NESTED);
+	if (id_set)
+		addattr8(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_ID, id);
+	if (flags)
+		addattr32(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_FLAGS, flags);
+	if (index)
+		addattr32(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_IF_IDX, index);
+	if (addr_set) {
+		int type;
+
+		addattr16(n, MPTCP_BUFLEN, MPTCP_PM_ADDR_ATTR_FAMILY,
+			  address.family);
+		type = address.family == AF_INET ? MPTCP_PM_ADDR_ATTR_ADDR4 :
+						   MPTCP_PM_ADDR_ATTR_ADDR6;
+		addattr_l(n, MPTCP_BUFLEN, type, &address.data,
+			  address.bytelen);
+	}
+
+	addattr_nest_end(n, attr_addr);
+	return 0;
+}
+
+static int mptcp_addr_modify(int argc, char **argv, int cmd)
+{
+	MPTCP_REQUEST(req, cmd, NLM_F_REQUEST);
+	int ret;
+
+	ret = mptcp_parse_opt(argc, argv, &req.n, cmd == MPTCP_PM_CMD_ADD_ADDR);
+	if (ret)
+		return ret;
+
+	if (rtnl_talk(&genl_rth, &req.n, NULL) < 0)
+		return -2;
+
+	return 0;
+}
+
+static int print_mptcp_addrinfo(struct rtattr *addrinfo)
+{
+	struct rtattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1];
+	__u8 family = AF_UNSPEC, addr_attr_type;
+	const char *ifname;
+	unsigned int flags;
+	int index;
+	__u16 id;
+
+	parse_rtattr_nested(tb, MPTCP_PM_ADDR_ATTR_MAX, addrinfo);
+
+	open_json_object(NULL);
+	if (tb[MPTCP_PM_ADDR_ATTR_FAMILY])
+		family = rta_getattr_u8(tb[MPTCP_PM_ADDR_ATTR_FAMILY]);
Quoted 8 lines

ip/ipmptcp.c line 203

Quoted 5 lines
ip/ipmptcp.c new file +5 -0
+
+	addr_attr_type = family == AF_INET ? MPTCP_PM_ADDR_ATTR_ADDR4 :
+					     MPTCP_PM_ADDR_ATTR_ADDR6;
+	if (tb[addr_attr_type]) {
+		print_string(PRINT_ANY, "address", "%s ",

(same here, is it OK to have a space at then end in a JSON context? Same below)

Quoted 1 line

'fdb' does the same. I guess it's ok.

OK for me!

Quoted 46 lines
Quoted 10 lines

ip/ipmptcp.c line 405

Quoted 6 lines
ip/ipmptcp.c new file +5 -0
+{
+	if (argc == 0)
+		usage();
+
+	if (!matches(*argv, "help"))

It is maybe just me but it looks strange to see "!matches" when the goal is to see if it matches :-)

Quoted 2 lines

Maybe clearer with "matches(...) == 0" like in most of the code? (same below and above in this file)

ok

Quoted 22 lines
Quoted 22 lines
ip/ipmptcp.c new file +22 -0
+		usage();
+
+	if (genl_init_handle(&genl_rth, MPTCP_PM_NAME, &genl_family))
+		exit(1);
+
+	if (!matches(*argv, "endpoint")) {
+		NEXT_ARG_FWD();
+		if (argc == 0)
+			return mptcp_addr_show(0, NULL);
+
+		if (!matches(*argv, "add"))
+			return mptcp_addr_modify(argc-1, argv+1,
+						 MPTCP_PM_CMD_ADD_ADDR);
+		if (!matches(*argv, "delete"))
+			return mptcp_addr_modify(argc-1, argv+1,
+						 MPTCP_PM_CMD_DEL_ADDR);
+		if (!matches(*argv, "show"))
+			return mptcp_addr_show(argc-1, argv+1);
+		if (!matches(*argv, "flush"))
+			return mptcp_addr_flush(argc-1, argv+1);
+
+		goto unknown;
Quoted 8 lines

ip/ipmptcp.c line 433

Quoted 6 lines
ip/ipmptcp.c new file +6 -0
+	}
+
+	if (!matches(*argv, "limits")) {
+		NEXT_ARG_FWD();
+		if (argc == 0)
+			return mptcp_limit_get_set(argc-1, argv+1,

Is it OK here with "argc-1" == -1?

Quoted 2 lines

It's ok because mptcp_limit_get_set checks for positive argc value, anyhow I'll change to '0, NULL'.

Thank you for having checked!

Quoted 13 lines
Quoted 13 lines

Cheers,
Matt

Quoted 9 lines
ip/ipmptcp.c new file +9 -0
+						   MPTCP_PM_CMD_GET_LIMITS);
+
+		if (!matches(*argv, "set"))
+			return mptcp_limit_get_set(argc-1, argv+1,
+						   MPTCP_PM_CMD_SET_LIMITS);
+		if (!matches(*argv, "show"))
+			return mptcp_limit_get_set(argc-1, argv+1,
+						   MPTCP_PM_CMD_GET_LIMITS);
+	}
Quoted 8 lines
Quoted 6 lines

ip/ipmptcp.c line 448

Quoted 6 lines
ip/ipmptcp.c new file +6 -0
+
+unknown:
+	fprintf(stderr,
+		"Command \"%s\" is unknown, try \"ip mptcp help\".\n",
+		*argv);
+	exit(-1);

and here invarg("unknown", *argv) would fit.

It seems this last fprintf() is used almost everywhere. Maybe better not to use invarg() here?

Cheers,
Matt

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
#13 lore raw

[MPTCP] Re: [PATCH v2 4/4] man: mptcp man page

In reply to Paolo Abeni

Hi Paolo,

Thank you for your reply!

Quoted 6 lines · Paolo Abeni
Quoted 5 lines · Matthieu Baerts

On 15/04/2020 14:28, Paolo Abeni wrote: >>> diff --git a/man/man8/ip-mptcp.8 b/man/man8/ip-mptcp.8

Quoted 4 lines

new file mode 100644
index 00000000..5ed0457b

man/man8/ip-mptcp.8 new file +0 -0

(...)

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines

+.ti -8
+.BR "ip mptcp limits set "
+.RB "[ "
+.B subflow
+.IR SUBFLOW_NR " ]"
+.RB "[ "
+.B add_addr_accepted
+.IR ADD_ADDR_ACCEPTED_NR " ]"

Should it be?

Quoted 7 lines
Quoted 5 lines
    set { subflow SUBFLOW_NR | add_addr_accepted ADD_ADDR_ACCEPTED_NR }

or:

set { subflow | add_addr_accepted } NR

I think that the text you suggest has different semantic.

Indeed, my bad!

Quoted 12 lines
Quoted 12 lines

man/man8/ip-mptcp.8 line 71

Quoted 7 lines
man/man8/ip-mptcp.8 new file +7 -0
+
+.ti -8
+.BR "ip mptcp limits show"
+
+.SH DESCRIPTION
+
+MPTCP is a transport protocol build on top of TCP that allows TCP

(I guess it could be nice if some English natives can have a look at this :) )
I think here you need s/build/built/

Quoted 7 lines
Quoted 4 lines

man/man8/ip-mptcp.8

Quoted 2 lines
man/man8/ip-mptcp.8 new file +2 -0
+connections to use multiple paths to maximize resource usage and increase
+redundancy.

Should we mention that the socket needs to be open using the MPTCP option?

I think that would should be in a different man page: man(7) mptcp in the kernel man pages.

I was thinking about a small sentence just to say that this can be applied only to sockets created with IPPROTO_MPTCP and not to all existing TCP connections but fine also for me to skip this.

Cheers,
Matt

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
#9 lore raw

[MPTCP] Re: [PATCH v2 3/4] ss: allow dumping MPTCP subflow information

In reply to Matthieu Baerts
Quoted 7 lines · Matthieu Baerts

Hi Davide,

Quoted 4 lines · Paolo Abeni

From: Davide Caratti <dcaratti(a)redhat.com>

[root(a)f31 packetdrill]# ss -tni

Quoted 7 lines
Quoted 2 lines

ESTAB 0 0 192.168.82.247:8080 192.0.2.1:35273

           cubic wscale:7,8 [...] tcp-ulp-mptcp flags: Mec token:0000(id:0)/5f856c60(id:0) seq:b810457db34209a5 sfseq:1 ssnoff:0 maplen:190

Thank you for this patch!

For the output, should it not be "flags:Mec" without space? If no, I guess it should not contain space for the parsing (flags: Mec)

yes, there is an extra space after the ':', I will fix it.

Quoted 1 line

Is there a place where these flags can be explained?

the place might be ss.8, let me see if I can write something decent.

Quoted 51 lines
Quoted 51 lines
Signed-off-by Davide Caratti <dcaratti(a)redhat.com>
---
  misc/ss.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 62 insertions(+)
misc/ss.c +31 -0
index 3ef151fb..3fac4be8 100644
@@ -53,6 +53,7 @@
  #include <linux/tipc_netlink.h>
  #include <linux/tipc_sockets_diag.h>
  #include <linux/tls.h>
+#include <linux/mptcp.h>
 
  /* AF_VSOCK/PF_VSOCK is only provided since glibc 2.18 */
  #ifndef PF_VSOCK
@@ -2836,6 +2837,59 @@ static void tcp_tls_conf(const char *name, struct rtattr *attr)
  	}
  }
 
+static void mptcp_subflow_info(struct rtattr *tb[])
+{
+	u_int32_t flags = 0;
+
+	if (tb[MPTCP_SUBFLOW_ATTR_FLAGS]) {
+		char caps[32 + 1] = { 0 }, *cap = &caps[0];
+
+		flags = rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_FLAGS]);
+
+		if (flags & MPTCP_SUBFLOW_FLAG_MCAP_REM)
+			*cap++ = 'M';
+		if (flags & MPTCP_SUBFLOW_FLAG_MCAP_LOC)
+			*cap++ = 'm';
+		if (flags & MPTCP_SUBFLOW_FLAG_JOIN_REM)
+			*cap++ = 'J';
+		if (flags & MPTCP_SUBFLOW_FLAG_JOIN_LOC)
+			*cap++ = 'j';
+		if (flags & MPTCP_SUBFLOW_FLAG_BKUP_REM)
+			*cap++ = 'B';
+		if (flags & MPTCP_SUBFLOW_FLAG_BKUP_LOC)
+			*cap++ = 'b';
+		if (flags & MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED)
+			*cap++ = 'e';
+		if (flags & MPTCP_SUBFLOW_FLAG_CONNECTED)
+			*cap++ = 'c';
+		if (flags & MPTCP_SUBFLOW_FLAG_MAPVALID)
+			*cap++ = 'v';
+		if (flags)
+			out(" flags:%s", caps);
+	}
Quoted 8 lines

misc/ss.c static void tcp_tls_conf(const char *name, struct rtattr *attr) · line 2874

Quoted 5 lines
misc/ss.c +5 -0
+	if (tb[MPTCP_SUBFLOW_ATTR_TOKEN_REM] &&
+	    tb[MPTCP_SUBFLOW_ATTR_TOKEN_LOC] &&
+	    tb[MPTCP_SUBFLOW_ATTR_ID_REM] &&
+	    tb[MPTCP_SUBFLOW_ATTR_ID_LOC])
+		out(" token:%04x(id:%d)/%04x(id:%d)",

For the id, I guess it is fine with %d (because it's a u8) and not %u? (Just to avoid possible warnings with the compiler ;-) )

right, or even better %hhu so we don't do the implicit cast.

Signature · 1 line
davide
author
#6 lore raw

[MPTCP] Re: [PATCH v2 2/4] add support for mptcp netlink interface.

In reply to Matthieu Baerts
Quoted 13 lines · Matthieu Baerts
Quoted 12 lines · Paolo Abeni
Quoted 10 lines · Matthieu Baerts

ip/ipmptcp.c line 70

Quoted 6 lines · Paolo Abeni
ip/ipmptcp.c new file +6 -0
+	if (flags) {
+		/* unknown flags */
+		SPRINT_BUF(b1);
+
+		snprintf(b1, sizeof(b1), "%02x", flags);
+		print_string(PRINT_ANY, "rawflags", "rawflags %s ", b1);

(it looks strange to me to end with a space even in json context but I don't know the code of iproute2 :) )

Quoted 5 lines
Quoted 2 lines

It's just to keep the code simple, otherwise we have to check for 'last flag' condition.

Yes, JSON supports doesn't make the code easy to do. It is maybe fine like that for upstream for the moment.

reading the above again, it *should* not introduce whitespaces for
JSON: it will emit:

	<key>:<value>

where <key> is "rawflags" and <value> the hex flags

[...]

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
ip/ipmptcp.c new file +8 -0
+
+		if (!matches(*argv, "set"))
+			return mptcp_limit_get_set(argc-1, argv+1,
+						   MPTCP_PM_CMD_SET_LIMITS);
+		if (!matches(*argv, "show"))
+			return mptcp_limit_get_set(argc-1, argv+1,
+						   MPTCP_PM_CMD_GET_LIMITS);
+	}
Quoted 8 lines
Quoted 6 lines

ip/ipmptcp.c line 448

Quoted 6 lines
ip/ipmptcp.c new file +6 -0
+
+unknown:
+	fprintf(stderr,
+		"Command \"%s\" is unknown, try \"ip mptcp help\".\n",
+		*argv);
+	exit(-1);

and here invarg("unknown", *argv) would fit.

Quoted 2 lines

It seems this last fprintf() is used almost everywhere. Maybe better not to use invarg() here?

ok,

Paolo