Skip to contentSkip to conversation

MP_JOIN handling WIP

RFC Superseded Peter Krystad 3 participants 9 messages Jun 12, 2019 – Jun 17, 2019

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Peter Krystad

author
#0 lore raw

v2 cover MP_JOIN handling WIP

Current state of MP_JOIN handling. As I mentioned this is not functional yet but am sharing for visibility. The intent of this patchset is to complete the handshake for a second subflow in the incoming direction. Sending an outgoing SYN with MP_JOIN and the data path is not addressed.

v2 - pr_debug() cleanup and single mptcp_established() hook were
address in other already-merged patchsets
- split path manager skeleton into its own commit
- cleaned up logic in subflow_syn_recv_sock
- rebase onto Florian's locking change
- namespace for token table NOT addressed

Peter Krystad (3):
mptcp: Add path manager interface
mptcp: Add ADD_ADDR handling
mptcp: Add handling of incoming MP_JOIN requests

 include/linux/tcp.h      |  12 ++++
 include/net/mptcp.h      |  28 +++++++-
 include/net/tcp.h        |   6 ++
 net/ipv4/tcp_minisocks.c |   6 ++
 net/mptcp/Makefile       |   2 +-
 net/mptcp/options.c      | 150 ++++++++++++++++++++++++++++++++++++---
 net/mptcp/pm.c           |  67 +++++++++++++++++
 net/mptcp/protocol.c     |  25 +++++++
 net/mptcp/protocol.h     |  53 +++++++++++++-
 net/mptcp/subflow.c      |  54 ++++++++++++--
 net/mptcp/token.c        | 124 ++++++++++++++++++++++++++++++++
 11 files changed, 503 insertions(+), 24 deletions(-)
 create mode 100644 net/mptcp/pm.c
Signature · 1 line
2.17.2
author
#1 lore raw

RFC v2 1/3 mptcp: Add path manager interface

Add enough of a path manager interface to allow sending of ADD_ADDR when an incoming MPTCP connection is created. Capable of sending only a single IPv4 ADD_ADDR option. The 'pm_data' element of the connection sock will need to be expanded to handle multiple interfaces and IPv6.

This is a skeleton interface definition for events generated by MPTCP.

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/Makefile   |  2 +-
 net/mptcp/pm.c       | 57 ++++++++++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.c |  4 ++++
 net/mptcp/protocol.h | 23 +++++++++++++++++-
 4 files changed, 84 insertions(+), 2 deletions(-)
 create mode 100644 net/mptcp/pm.c
net/mptcp/Makefile +1 -1
index 178ae81d8b66..7fe7aa64eda0 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_MPTCP) += mptcp.o
 
-mptcp-y := protocol.o subflow.o options.o token.o crypto.o
+mptcp-y := protocol.o subflow.o options.o token.o crypto.o pm.o
net/mptcp/pm.c new file +57 -0

57 lines not on this page · raw message

net/mptcp/protocol.c +4 -0
index 941988387ea0..a1a42ed7810a 100644
@@ -632,6 +632,8 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 		token_update_accept(new_sock->sk, new_mptcp_sock);
 		msk->subflow = NULL;
 
+		pm_new_connection(msk);
+
 		crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
 		ack_seq++;
@@ -757,6 +759,8 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 		msk->token = subflow->token;
 		pr_debug("msk=%p, token=%u", msk, msk->token);
 
+		pm_new_connection(msk);
+
 		crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
 		ack_seq++;
net/mptcp/protocol.h +22 -1
index a4f0e7d3bd62..d0c2c280c8c3 100644
@@ -15,7 +15,7 @@
 #define MPTCPOPT_MP_JOIN	1
 #define MPTCPOPT_DSS		2
 #define MPTCPOPT_ADD_ADDR	3
-#define MPTCPOPT_REMOVE_ADDR	4
+#define MPTCPOPT_RM_ADDR	4
 #define MPTCPOPT_MP_PRIO	5
 #define MPTCPOPT_MP_FAIL	6
 #define MPTCPOPT_MP_FASTCLOSE	7
@@ -36,6 +36,15 @@
 #define MPTCP_DSS_HAS_ACK	BIT(0)
 #define MPTCP_DSS_FLAG_MASK	(0x1F)
 
+struct pm_data {
+	u8 addr_id;
+	sa_family_t family;
+	union {
+		struct in_addr addr;
+		struct in6_addr addr6;
+	};
+};
+
 /* MPTCP connection sock */
 struct mptcp_sock {
 	/* inet_connection_sock must be the first member */
@@ -47,6 +56,7 @@ struct mptcp_sock {
 	u32		token;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
+	struct pm_data	pm;
 };
 
 #define mptcp_for_each_subflow(__msk, __subflow)			\
@@ -146,6 +156,17 @@ void crypto_key_sha1(u64 key, u32 *token, u64 *idsn);
 void crypto_hmac_sha1(u64 key1, u64 key2, u32 *hash_out,
 		     int arg_num, ...);
 
+void pm_new_connection(struct mptcp_sock *msk);
+void pm_fully_established(struct mptcp_sock *msk);
+void pm_connection_closed(struct mptcp_sock *msk);
+void pm_subflow_established(struct mptcp_sock *msk, u8 id);
+void pm_subflow_closed(struct mptcp_sock *msk, u8 id);
+void pm_add_addr(struct mptcp_sock *msk, const struct in_addr *addr, u8 id);
+void pm_add_addr6(struct mptcp_sock *msk, const struct in6_addr *addr, u8 id);
+void pm_rm_addr(struct mptcp_sock *msk, u8 id);
+bool pm_addr_signal(struct mptcp_sock *msk, unsigned *size,
+		    unsigned int remaining, struct mptcp_out_options *opts);
+
 static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
 {
 	return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP);
Signature · 1 line
2.17.2
author
#2 lore raw

RFC v2 2/3 mptcp: Add ADD_ADDR handling

In reply to Peter Krystad

Add handling for sending and receiving the ADD_ADDR, ADD_ADDR6, and RM_ADDR suboptions.

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 include/linux/tcp.h  |  6 +++
 include/net/mptcp.h  | 14 +++++--
 include/net/tcp.h    |  3 ++
 net/mptcp/options.c  | 89 +++++++++++++++++++++++++++++++++++++++++---
 net/mptcp/pm.c       | 12 +++++-
 net/mptcp/protocol.h |  5 +++
 6 files changed, 119 insertions(+), 10 deletions(-)
include/linux/tcp.h +6 -0
index 5f3784989d85..393e9be41c8e 100644
@@ -122,6 +122,12 @@ struct tcp_options_received {
 			use_ack:1,
 			ack64:1,
 			__unused:2;
+		u8	add_addr : 1,
+			rm_addr : 1,
+			family : 4;
+		u8	addr_id;
+		struct	in_addr	addr;
+		struct	in6_addr addr6;
 	} mptcp;
 #endif
 };
include/net/mptcp.h +11 -3
index e0bd45e49db1..d1534f8f0f38 100644
@@ -25,15 +25,23 @@ struct mptcp_ext {
 };
 
 /* MPTCP option subtypes */
-#define OPTION_MPTCP_MPC_SYN	BIT(0)
-#define OPTION_MPTCP_MPC_SYNACK	BIT(1)
-#define OPTION_MPTCP_MPC_ACK	BIT(2)
+#define OPTION_MPTCP_MPC_SYN		BIT(0)
+#define OPTION_MPTCP_MPC_SYNACK		BIT(1)
+#define OPTION_MPTCP_MPC_ACK		BIT(2)
+#define OPTION_MPTCP_ADD_ADDR		BIT(6)
+#define OPTION_MPTCP_ADD_ADDR6		BIT(7)
+#define OPTION_MPTCP_RM_ADDR		BIT(8)
 
 struct mptcp_out_options {
 #if IS_ENABLED(CONFIG_MPTCP)
 	u16 suboptions;
 	u64 sndr_key;
 	u64 rcvr_key;
+	struct in_addr addr;
+#if IS_ENABLED(CONFIG_IPV6)
+	struct in6_addr addr6;
+#endif
+	u8 addr_id;
 	struct mptcp_ext ext_copy;
 #endif
 };
include/net/tcp.h +3 -0
index 0e939724b22c..6de16196d4aa 100644
@@ -221,6 +221,9 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);
 #define TCPOLEN_MPTCP_DSS_MAP32		10
 #define TCPOLEN_MPTCP_DSS_MAP64		14
 #define TCPOLEN_MPTCP_DSS_CHECKSUM	2
+#define TCPOLEN_MPTCP_ADD_ADDR		8
+#define TCPOLEN_MPTCP_ADD_ADDR6		20
+#define TCPOLEN_MPTCP_RM_ADDR		4
 
 /* Flags in tp->nonagle */
 #define TCP_NAGLE_OFF		1	/* Nagle's algo is disabled */
net/mptcp/options.c +83 -6

128 lines not on this page · raw message

net/mptcp/pm.c +11 -1
index 954360a3af2f..9458ced2c9f4 100644
@@ -51,7 +51,17 @@ void pm_rm_addr(struct mptcp_sock *msk, u8 id)
 bool pm_addr_signal(struct mptcp_sock *msk, unsigned *size,
 		    unsigned int remaining, struct mptcp_out_options *opts)
 {
-	pr_debug("msk=%p", msk);
+	if (msk && msk->addr_signal) {
+		pr_debug("msk=%p", msk);
+		if (msk->pm.family == AF_INET &&
+		    remaining >= TCPOLEN_MPTCP_ADD_ADDR) {
+			msk->addr_signal = 0;
+			opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
+			opts->addr_id = msk->pm.addr_id;
+			opts->addr.s_addr = msk->pm.addr.s_addr;
+			return true;
+		}
+	}
 
 	return false;
 }
net/mptcp/protocol.h +5 -0
index d0c2c280c8c3..28a1a2c7568c 100644
@@ -22,6 +22,10 @@
 
 #define MPTCPOPT_VERSION_MASK	0x0F
 
+#define MPTCP_ADDR_FAMILY_MASK	0x0F
+#define MPTCP_ADDR_IPVERSION_4	4
+#define MPTCP_ADDR_IPVERSION_6	6
+
 /* MPTCP handshake flags */
 #define MPTCP_CAP_CHECKSUM_REQD	BIT(7)
 #define MPTCP_CAP_EXTENSIBILITY	BIT(6)
@@ -57,6 +61,7 @@ struct mptcp_sock {
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 	struct pm_data	pm;
+	u8		addr_signal;
 };
 
 #define mptcp_for_each_subflow(__msk, __subflow)			\
Signature · 1 line
2.17.2
#3 lore raw

Re: [MPTCP] [RFC v2 2/3] mptcp: Add ADD_ADDR handling

Hi,

Thank you for following up on this!

Quoted 5 lines · Peter Krystad
include/linux/tcp.h +0 -0
index 5f3784989d85..393e9be41c8e 100644

include/linux/tcp.h struct tcp_options_received { · line 130

Quoted 9 lines
include/linux/tcp.h +6 -0
@@ -122,6 +122,12 @@ struct tcp_options_received {
 			use_ack:1,
 			ack64:1,
 			__unused:2;
+		u8	add_addr : 1,
+			rm_addr : 1,
+			family : 4;
+		u8	addr_id;
+		struct	in_addr	addr;
+		struct	in6_addr addr6;

I'm unsure if it's too early for ipv6 bit ?!?
What about an union for addr and addr6? Or perhaps use directly 'struct inetpeer_addr'? The same consideration for mptcp_out_options below.

include/net/tcp.h void tcp_time_wait(struct sock *sk, int state, int timeo); · line 226

Quoted 11 lines
include/net/tcp.h +3 -0
index 0e939724b22c..6de16196d4aa 100644
@@ -221,6 +221,9 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);
 #define TCPOLEN_MPTCP_DSS_MAP32		10
 #define TCPOLEN_MPTCP_DSS_MAP64		14
 #define TCPOLEN_MPTCP_DSS_CHECKSUM	2
+#define TCPOLEN_MPTCP_ADD_ADDR		8
+#define TCPOLEN_MPTCP_ADD_ADDR6		20
+#define TCPOLEN_MPTCP_RM_ADDR		4

Not related to this patch, but possibly we can move this definition to net/mptcp/protocol.h ? tcp core code shold not need to be aware of them.

Quoted 23 lines
include/net/tcp.h +0 -0
 /* Flags in tp->nonagle */
 #define TCP_NAGLE_OFF		1	/* Nagle's algo is disabled */
net/mptcp/options.c +10 -1
index d285a33cd480..469f384ff108 100644
@@ -161,12 +161,41 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
 	 * 4 or 16 bytes of address (depending on ip version)
 	 * 0 or 2 bytes of port (depending on length)
 	 */
+	case MPTCPOPT_ADD_ADDR:
+		if (opsize != TCPOLEN_MPTCP_ADD_ADDR &&
+		    opsize != TCPOLEN_MPTCP_ADD_ADDR6)
+			break;
+
+		mp_opt->family = *ptr++ & MPTCP_ADDR_FAMILY_MASK;
+		if (mp_opt->family != MPTCP_ADDR_IPVERSION_4 &&
+		    mp_opt->family != MPTCP_ADDR_IPVERSION_6)
+			break;
 
-	/* MPTCPOPT_REMOVE_ADDR
+		mp_opt->add_addr = 1;

net/mptcp/options.c void mptcp_parse_option(const unsigned char *ptr, int opsize, · line 184

Quoted 10 lines
net/mptcp/options.c +10 -0
+		mp_opt->addr_id = *ptr++;
+		if (opsize == TCPOLEN_MPTCP_ADD_ADDR) {
+			mp_opt->addr.s_addr = get_unaligned_be32(ptr);
+			pr_debug("ADD_ADDR: addr=%x, id=%d",
+				 mp_opt->addr.s_addr, mp_opt->addr_id);
+		} else {
+			memcpy(mp_opt->addr6.s6_addr, (u8 *) ptr, 16);
+			pr_debug("ADD_ADDR: addr6=, id=%d", mp_opt->addr_id);
+		}
+		break;

I think we should also check that mp_opt->family matches opsize, or we could end-up with e.g. mp_opt->family == MPTCP_ADDR_IPVERSION_6 and only mp_opt->addr set.

[...]

net/mptcp/options.c void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts) · line 498

Quoted 10 lines
net/mptcp/options.c +6 -0
@@ -441,6 +490,34 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
 		}
 	}
 
+	if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
+		*ptr++ = htonl((TCPOPT_MPTCP << 24) |
+			       (TCPOLEN_MPTCP_ADD_ADDR << 16) |
+			       (MPTCPOPT_ADD_ADDR << 12) |
+			       (MPTCP_ADDR_IPVERSION_4 <<  8) |
+			       (opts->addr_id));

Perhaps add a macro/inline function for the above?

net/mptcp/options.c void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts) · line 502

Quoted 4 lines
net/mptcp/options.c +4 -0
+		*ptr++ = htonl(opts->addr.s_addr);
+	}
+
+#if IS_ENABLED(CONFIG_MPTCP)

IS_ENABLED(CONFIG_MPTCP) should be always 1 here, right ? :-P

Quoted 29 lines
net/mptcp/options.c +18 -0
+	if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) {
+		*ptr++ = htonl((TCPOPT_MPTCP << 24) |
+			       (TCPOLEN_MPTCP_ADD_ADDR6 << 16) |
+			       (MPTCPOPT_ADD_ADDR << 12) |
+			       (MPTCP_ADDR_IPVERSION_6 <<  8) |
+			       (opts->addr_id));
+		memcpy((u8 *) ptr, opts->addr6.s6_addr, 16);
+		ptr += 4;
+	}
+#endif
+
+	if (OPTION_MPTCP_RM_ADDR & opts->suboptions) {
+		*ptr++ = htonl((TCPOPT_MPTCP << 24) |
+			       (TCPOLEN_MPTCP_RM_ADDR << 16) |
+			       (MPTCPOPT_RM_ADDR << 12) |
+			       (opts->addr_id));
+	}
+
 	if (opts->ext_copy.use_ack || opts->ext_copy.use_map) {
 		struct mptcp_ext *mpext = &opts->ext_copy;
 		u8 len = TCPOLEN_MPTCP_DSS_BASE;
net/mptcp/pm.c +0 -0
index 954360a3af2f..9458ced2c9f4 100644
@@ -51,7 +51,17 @@ void pm_rm_addr(struct mptcp_sock *msk, u8 id)
 bool pm_addr_signal(struct mptcp_sock *msk, unsigned *size,
 		    unsigned int remaining, struct mptcp_out_options *opts)
 {

net/mptcp/pm.c void pm_rm_addr(struct mptcp_sock *msk, u8 id) · line 62

Quoted 10 lines
net/mptcp/pm.c +9 -1
-	pr_debug("msk=%p", msk);
+	if (msk && msk->addr_signal) {
+		pr_debug("msk=%p", msk);
+		if (msk->pm.family == AF_INET &&
+		    remaining >= TCPOLEN_MPTCP_ADD_ADDR) {
+			msk->addr_signal = 0;
+			opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
+			opts->addr_id = msk->pm.addr_id;
+			opts->addr.s_addr = msk->pm.addr.s_addr;
+			return true;

I think upstream prefers keeping the expected/main code path with no indentation; something alike:

    if (!msk || !msk->addr_signal)
	return false

    if (msk->pm.family != AF_INET ||
        remaining < TCPOLEN_MPTCP_ADD_ADDR)
	return false

    msk->addr_signal = 0;
    opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
    opts->addr_id = msk->pm.addr_id;
    opts->addr.s_addr = msk->pm.addr.s_addr;
    return true;

Cheers,

Paolo

author
#4 lore raw

Re: [MPTCP] [RFC v2 2/3] mptcp: Add ADD_ADDR handling

Hi Paolo -

Thank-you for your comments. Please see below.

Quoted 15 lines · Paolo Abeni

Hi,

Thank you for following up on this!

Quoted 10 lines · Peter Krystad
include/linux/tcp.h +2 -0
index 5f3784989d85..393e9be41c8e 100644
@@ -122,6 +122,12 @@ struct tcp_options_received {
 			use_ack:1,
 			ack64:1,
 			__unused:2;
+		u8	add_addr : 1,
+			rm_addr : 1,
Quoted 8 lines

include/linux/tcp.h struct tcp_options_received { · line 130

Quoted 4 lines
include/linux/tcp.h +4 -0
+			family : 4;
+		u8	addr_id;
+		struct	in_addr	addr;
+		struct	in6_addr addr6;

I'm unsure if it's too early for ipv6 bit ?!?
What about an union for addr and addr6? Or perhaps use directly 'struct inetpeer_addr'? The same consideration for mptcp_out_options below.

I'm inclined to include ipv6 here because this is capturing incoming options so it may arrive even though we do not support. I'll make them both a union.

Quoted 16 lines

include/net/tcp.h void tcp_time_wait(struct sock *sk, int state, int timeo); · line 226

Quoted 12 lines
include/net/tcp.h +3 -0
index 0e939724b22c..6de16196d4aa 100644
@@ -221,6 +221,9 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);
 #define TCPOLEN_MPTCP_DSS_MAP32		10
 #define TCPOLEN_MPTCP_DSS_MAP64		14
 #define TCPOLEN_MPTCP_DSS_CHECKSUM	2
+#define TCPOLEN_MPTCP_ADD_ADDR		8
+#define TCPOLEN_MPTCP_ADD_ADDR6		20
+#define TCPOLEN_MPTCP_RM_ADDR		4

Not related to this patch, but possibly we can move this definition to net/mptcp/protocol.h ? tcp core code shold not need to be aware of them.

Sure, I submitted a seperate patchset for this.

Quoted 21 lines
Quoted 21 lines
include/net/tcp.h +0 -0
 /* Flags in tp->nonagle */
 #define TCP_NAGLE_OFF		1	/* Nagle's algo is disabled */
net/mptcp/options.c +9 -0
index d285a33cd480..469f384ff108 100644
@@ -161,12 +161,41 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
 	 * 4 or 16 bytes of address (depending on ip version)
 	 * 0 or 2 bytes of port (depending on length)
 	 */
+	case MPTCPOPT_ADD_ADDR:
+		if (opsize != TCPOLEN_MPTCP_ADD_ADDR &&
+		    opsize != TCPOLEN_MPTCP_ADD_ADDR6)
+			break;
+
+		mp_opt->family = *ptr++ & MPTCP_ADDR_FAMILY_MASK;
+		if (mp_opt->family != MPTCP_ADDR_IPVERSION_4 &&
+		    mp_opt->family != MPTCP_ADDR_IPVERSION_6)
+			break;
 
Quoted 16 lines

net/mptcp/options.c void mptcp_parse_option(const unsigned char *ptr, int opsize, · line 184

Quoted 12 lines
net/mptcp/options.c +11 -1
-	/* MPTCPOPT_REMOVE_ADDR
+		mp_opt->add_addr = 1;
+		mp_opt->addr_id = *ptr++;
+		if (opsize == TCPOLEN_MPTCP_ADD_ADDR) {
+			mp_opt->addr.s_addr = get_unaligned_be32(ptr);
+			pr_debug("ADD_ADDR: addr=%x, id=%d",
+				 mp_opt->addr.s_addr, mp_opt->addr_id);
+		} else {
+			memcpy(mp_opt->addr6.s6_addr, (u8 *) ptr, 16);
+			pr_debug("ADD_ADDR: addr6=, id=%d", mp_opt->addr_id);
+		}
+		break;

I think we should also check that mp_opt->family matches opsize, or we could end-up with e.g. mp_opt->family == MPTCP_ADDR_IPVERSION_6 and only mp_opt->addr set.

Will revise.

Quoted 6 lines

[...]

Quoted 4 lines
net/mptcp/options.c +0 -0
@@ -441,6 +490,34 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
 		}
 	}
 
Quoted 8 lines

net/mptcp/options.c void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts) · line 498

Quoted 6 lines
net/mptcp/options.c +6 -0
+	if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
+		*ptr++ = htonl((TCPOPT_MPTCP << 24) |
+			       (TCPOLEN_MPTCP_ADD_ADDR << 16) |
+			       (MPTCPOPT_ADD_ADDR << 12) |
+			       (MPTCP_ADDR_IPVERSION_4 <<  8) |
+			       (opts->addr_id));

Perhaps add a macro/inline function for the above?

Good idea, will add.

Quoted 7 lines

net/mptcp/options.c void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts) · line 502

Quoted 5 lines
net/mptcp/options.c +4 -0
+		*ptr++ = htonl(opts->addr.s_addr);
+	}
+
+#if IS_ENABLED(CONFIG_MPTCP)

IS_ENABLED(CONFIG_MPTCP) should be always 1 here, right ? :-P

Hah!

Quoted 34 lines
Quoted 34 lines
net/mptcp/options.c +18 -0
+	if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) {
+		*ptr++ = htonl((TCPOPT_MPTCP << 24) |
+			       (TCPOLEN_MPTCP_ADD_ADDR6 << 16) |
+			       (MPTCPOPT_ADD_ADDR << 12) |
+			       (MPTCP_ADDR_IPVERSION_6 <<  8) |
+			       (opts->addr_id));
+		memcpy((u8 *) ptr, opts->addr6.s6_addr, 16);
+		ptr += 4;
+	}
+#endif
+
+	if (OPTION_MPTCP_RM_ADDR & opts->suboptions) {
+		*ptr++ = htonl((TCPOPT_MPTCP << 24) |
+			       (TCPOLEN_MPTCP_RM_ADDR << 16) |
+			       (MPTCPOPT_RM_ADDR << 12) |
+			       (opts->addr_id));
+	}
+
 	if (opts->ext_copy.use_ack || opts->ext_copy.use_map) {
 		struct mptcp_ext *mpext = &opts->ext_copy;
 		u8 len = TCPOLEN_MPTCP_DSS_BASE;
net/mptcp/pm.c +4 -1
index 954360a3af2f..9458ced2c9f4 100644
@@ -51,7 +51,17 @@ void pm_rm_addr(struct mptcp_sock *msk, u8 id)
 bool pm_addr_signal(struct mptcp_sock *msk, unsigned *size,
 		    unsigned int remaining, struct mptcp_out_options *opts)
 {
-	pr_debug("msk=%p", msk);
+	if (msk && msk->addr_signal) {
+		pr_debug("msk=%p", msk);
+		if (msk->pm.family == AF_INET &&
+		    remaining >= TCPOLEN_MPTCP_ADD_ADDR) {
Quoted 8 lines

net/mptcp/pm.c void pm_rm_addr(struct mptcp_sock *msk, u8 id) · line 62

Quoted 5 lines
net/mptcp/pm.c +5 -0
+			msk->addr_signal = 0;
+			opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
+			opts->addr_id = msk->pm.addr_id;
+			opts->addr.s_addr = msk->pm.addr.s_addr;
+			return true;

I think upstream prefers keeping the expected/main code path with no indentation; something alike:

OK.

I will include all of these in v3 patchset.

Peter.

Quoted 17 lines
    if (!msk || !msk->addr_signal)
	return false

    if (msk->pm.family != AF_INET ||
        remaining < TCPOLEN_MPTCP_ADD_ADDR)
	return false

    msk->addr_signal = 0;
    opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
    opts->addr_id = msk->pm.addr_id;
    opts->addr.s_addr = msk->pm.addr.s_addr;
    return true;

Cheers,

Paolo

author
#5 lore raw

RFC v2 3/3 mptcp: Add handling of incoming MP_JOIN requests

In reply to Peter Krystad

Process the MP_JOIN option in a SYN packet with the same flow as MP_CAPABLE but when the third ACK is received add the subflow to the MPTCP socket subflow list instead of adding it to the TCP socket accept queue.

The subflow is added at the end of the subflow list so it will not interfere with the existing subflows operation and no data is expected to be transmitted on it.

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 include/linux/tcp.h      |   6 ++
 include/net/mptcp.h      |  14 +++++
 include/net/tcp.h        |   3 +
 net/ipv4/tcp_minisocks.c |   6 ++
 net/mptcp/options.c      |  61 +++++++++++++++++--
 net/mptcp/protocol.c     |  21 +++++++
 net/mptcp/protocol.h     |  25 +++++++-
 net/mptcp/subflow.c      |  54 ++++++++++++++---
 net/mptcp/token.c        | 124 +++++++++++++++++++++++++++++++++++++++
 9 files changed, 301 insertions(+), 13 deletions(-)
include/linux/tcp.h +6 -0
index 393e9be41c8e..9dbf36b02bbe 100644
@@ -112,8 +112,14 @@ struct tcp_options_received {
 		u8      mp_capable : 1,
 			mp_join : 1,
 			dss : 1,
+			backup : 1,
 			version : 4;
 		u8      flags;
+		u8      join_id;
+		u32     token;
+		u32     nonce;
+		u64     thmac;
+		u8      hmac[20];
 		u8	dss_flags;
 		u8	use_map:1,
 			dsn64:1,
include/net/mptcp.h +14 -0
index d1534f8f0f38..4cd9cc3c92c9 100644
@@ -28,6 +28,9 @@ struct mptcp_ext {
 #define OPTION_MPTCP_MPC_SYN		BIT(0)
 #define OPTION_MPTCP_MPC_SYNACK		BIT(1)
 #define OPTION_MPTCP_MPC_ACK		BIT(2)
+#define OPTION_MPTCP_MPJ_SYN		BIT(3)
+#define OPTION_MPTCP_MPJ_SYNACK		BIT(4)
+#define OPTION_MPTCP_MPJ_ACK		BIT(5)
 #define OPTION_MPTCP_ADD_ADDR		BIT(6)
 #define OPTION_MPTCP_ADD_ADDR6		BIT(7)
 #define OPTION_MPTCP_RM_ADDR		BIT(8)
@@ -42,6 +45,10 @@ struct mptcp_out_options {
 	struct in6_addr addr6;
 #endif
 	u8 addr_id;
+	u8 join_id;
+	u8 backup;
+	u32 nonce;
+	u64 thmac;
 	struct mptcp_ext ext_copy;
 #endif
 };
@@ -81,6 +88,8 @@ static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
 
 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
 
+bool mptcp_sk_is_subflow(const struct sock *sk);
+
 #else
 
 static inline void mptcp_init(void)
@@ -138,5 +147,10 @@ static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
 	return false;
 }
 
+static inline book mptcp_sk_is_subflow(const struct sock *sk)
+{
+	return false;
+}
+
 #endif /* CONFIG_MPTCP */
 #endif /* __NET_MPTCP_H */
include/net/tcp.h +3 -0
index 6de16196d4aa..edabb529a320 100644
@@ -215,6 +215,9 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);
 #define TCPOLEN_MPTCP_MPC_SYN		12
 #define TCPOLEN_MPTCP_MPC_SYNACK	20
 #define TCPOLEN_MPTCP_MPC_ACK		20
+#define TCPOLEN_MPTCP_MPJ_SYN		12
+#define TCPOLEN_MPTCP_MPJ_SYNACK	16
+#define TCPOLEN_MPTCP_MPJ_ACK		24
 #define TCPOLEN_MPTCP_DSS_BASE		4
 #define TCPOLEN_MPTCP_DSS_ACK32		4
 #define TCPOLEN_MPTCP_DSS_ACK64		8
net/ipv4/tcp_minisocks.c +6 -0
index 11011e8386dc..b5344b1a19e8 100644
@@ -766,6 +766,12 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
 	if (!child)
 		goto listen_overflow;
 
+	if (own_req && sk_is_mptcp(child) && mptcp_sk_is_subflow(child)) {
+		inet_csk_reqsk_queue_drop(sk, req);
+		reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req);
+		return child;
+	}
+
 	sock_rps_save_rxhash(child, skb);
 	tcp_synack_rtt_meas(child, req);
 	*req_stolen = !own_req;
net/mptcp/options.c +57 -4

98 lines not on this page · raw message

net/mptcp/protocol.c +21 -0
index a1a42ed7810a..6468f0d8ef04 100644
@@ -777,6 +777,27 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 	inet_sk_state_store(sk, TCP_ESTABLISHED);
 }
 
+void mptcp_finish_join(struct sock *conn, struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(conn);
+	struct subflow_context *subflow = subflow_ctx(sk);
+
+	pr_debug("msk=%p, subflow=%p", msk, subflow);
+
+	local_bh_disable();
+	bh_lock_sock_nested(sk);
+	list_add_tail(&subflow->node, &msk->conn_list);
+	bh_unlock_sock(sk);
+	local_bh_enable();
+}
+
+bool mptcp_sk_is_subflow(const struct sock *sk)
+{
+	struct subflow_context *subflow = subflow_ctx(sk);
+
+	return subflow->mp_join == 1;
+}
+
 static struct proto mptcp_prot = {
 	.name		= "MPTCP",
 	.owner		= THIS_MODULE,
net/mptcp/protocol.h +23 -2
index 28a1a2c7568c..8c78480adce1 100644
@@ -21,6 +21,8 @@
 #define MPTCPOPT_MP_FASTCLOSE	7
 
 #define MPTCPOPT_VERSION_MASK	0x0F
+#define MPTCPOPT_BACKUP		(1 << 0)
+#define MPTCPOPT_HMAC_LEN	20
 
 #define MPTCP_ADDR_FAMILY_MASK	0x0F
 #define MPTCP_ADDR_IPVERSION_4	4
@@ -79,11 +81,16 @@ struct subflow_request_sock {
 		checksum : 1,
 		backup : 1,
 		version : 4;
+	u8	local_id;
+	u8	remote_id;
 	u64	local_key;
 	u64	remote_key;
 	u64	idsn;
 	u32	token;
 	u32	ssn_offset;
+	u64	thmac;
+	u32	local_nonce;
+	u32	remote_nonce;
 };
 
 static inline
@@ -106,15 +113,23 @@ struct subflow_context {
 	u16	map_data_len;
 	u16	request_mptcp : 1,  /* send MP_CAPABLE */
 		request_cksum : 1,
-		mp_capable : 1,	    /* remote is MPTCP capable */
+		mp_capable : 1,     /* remote is MPTCP capable */
+		mp_join : 1,        /* remote is JOINing */
 		fourth_ack : 1,     /* send initial DSS */
 		version : 4,
 		conn_finished : 1,
 		use_checksum : 1,
-		map_valid : 1;
+		map_valid : 1,
+		backup : 1;
+	u32	remote_nonce;
+	u64	thmac;
+	u32	local_nonce;
+	u8	local_id;
+	u8	remote_id;
 
 	struct  socket *tcp_sock;  /* underlying tcp_sock */
 	struct  sock *conn;        /* parent mptcp_sock */
+
 	void	(*tcp_sk_data_ready)(struct sock *sk);
 };
 
@@ -137,13 +152,19 @@ void mptcp_get_options(const struct sk_buff *skb,
 		       struct tcp_options_received *opt_rx);
 
 void mptcp_finish_connect(struct sock *sk, int mp_capable);
+void mptcp_finish_join(struct sock *conn, struct sock *sk);
 
 void token_init(void);
 void token_new_request(struct request_sock *req, const struct sk_buff *skb);
+int token_join_request(struct request_sock *req, const struct sk_buff *skb);
+int token_join_valid(struct request_sock *req,
+		     struct tcp_options_received *rx_opt);
 void token_destroy_request(u32 token);
 void token_new_connect(struct sock *sk);
 void token_new_accept(struct sock *sk);
+int token_new_join(struct sock *sk);
 void token_update_accept(struct sock *sk, struct sock *conn);
+void token_release(u32 token);
 void token_destroy(u32 token);
 
 void crypto_init(void);
net/mptcp/subflow.c +47 -7

91 lines not on this page · raw message

net/mptcp/token.c +124 -0

154 lines not on this page · raw message

Signature · 1 line
2.17.2
#6 lore raw

Re: [MPTCP] [RFC v2 3/3] mptcp: Add handling of incoming MP_JOIN requests

Hi again,

[...]

net/mptcp/options.c bool mptcp_synack_options(const struct request_sock *req, unsigned int *size, · line 456

Quoted 11 lines · Peter Krystad
net/mptcp/options.c +2 -1
@@ -419,11 +448,23 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 		opts->sndr_key = subflow_req->local_key;
 		opts->rcvr_key = subflow_req->remote_key;
 		*size = TCPOLEN_MPTCP_MPC_SYNACK;
-		pr_debug("subflow_req=%p, local_key=%llu, remote_key=%llu",
+		pr_debug("req=%p, local_key=%llu, remote_key=%llu",
 			 subflow_req, subflow_req->local_key,
 			 subflow_req->remote_key);
 		return true;
 	}
+	if (subflow_req->mp_join) {

Here I'm a bit lost... I think we should always enter the previos block statement. The current relevant code will become:

     if (subflow_req->mp_capable) {
                opts->suboptions = OPTION_MPTCP_MPC_SYNACK;
                opts->sndr_key = subflow_req->local_key;
                opts->rcvr_key = subflow_req->remote_key;
                *size = TCPOLEN_MPTCP_MPC_SYNACK;
                pr_debug("local_key=%llu", subflow_req->local_key);
                pr_debug("remote_key=%llu", subflow_req->remote_key);
                return true;
     }
     if (subflow_req->mp_join) {

and mp_capable should be set, so we should never enter the 'if (subflow_req->mp_join) {' branch, right? What I'm missing here?!?

net/mptcp/protocol.c void mptcp_finish_connect(struct sock *sk, int mp_capable) · line 783

Quoted 12 lines
net/mptcp/protocol.c +4 -0
index a1a42ed7810a..6468f0d8ef04 100644
@@ -777,6 +777,27 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 	inet_sk_state_store(sk, TCP_ESTABLISHED);
 }
 
+void mptcp_finish_join(struct sock *conn, struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(conn);
+	struct subflow_context *subflow = subflow_ctx(sk);

Very minor thing: we should apply the reverse X-mass tree order to variable declaration.

net/mptcp/subflow.c static void subflow_v4_init_req(struct request_sock *req, · line 72

Quoted 9 lines
net/mptcp/subflow.c +1 -0
index a31f58990c86..9a475f83d446 100644
@@ -69,8 +69,21 @@ static void subflow_v4_init_req(struct request_sock *req,
 		token_new_request(req, skb);
 		pr_debug("syn seq=%u", TCP_SKB_CB(skb)->seq);
 		subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
+	} else if (rx_opt.mptcp.mp_join && listener->request_mptcp) {

Here I'm lost again, aren't we always going to enter only the previous block statement? I expect to have MP_CAPABLE and MP_JOIN option in the same packet?!?

Quoted 18 lines
net/mptcp/subflow.c +12 -0
+		subflow_req->mp_join = 1;
+		subflow_req->backup = rx_opt.mptcp.backup;
+		subflow_req->remote_id = rx_opt.mptcp.join_id;
+		subflow_req->token = rx_opt.mptcp.token;
+		subflow_req->remote_nonce = rx_opt.mptcp.nonce;
+		pr_debug("token=%u, remote_nonce=%u", subflow_req->token,
+			 subflow_req->remote_nonce);
+		if (token_join_request(req, skb)) {
+			subflow_req->mp_join = 0;
+			// @@ need to trigger RST
+		}
 	} else {
 		subflow_req->mp_capable = 0;
+		subflow_req->mp_join = 0;
 	}
 }
 

net/mptcp/subflow.c static struct sock *subflow_syn_recv_sock(const struct sock *sk, · line 151

Quoted 4 lines
net/mptcp/subflow.c +1 -0
@@ -135,6 +148,13 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 		    (subflow_req->local_key != opt_rx.mptcp.rcvr_key) ||
 		    (subflow_req->remote_key != opt_rx.mptcp.sndr_key))
 			return NULL;
+	} else if (subflow_req->mp_join) {

Here similar situation... shouldn't we have a single invocation to mptcp_get_options()?!?

Quoted 55 lines
net/mptcp/subflow.c +25 -7
+		opt_rx.mptcp.mp_join = 0;
+		mptcp_get_options(skb, &opt_rx);
+		if ((!opt_rx.mptcp.mp_join) ||
+		    (token_join_valid(req, &opt_rx))) {
+			return NULL;
+		}
 	}
 
 	child = tcp_v4_syn_recv_sock(sk, skb, req, dst, req_unhash, own_req);
@@ -142,18 +162,28 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 	if (child && *own_req) {
 		struct subflow_context *ctx = subflow_ctx(child);
 
-		if (!ctx) {
-			pr_debug("Closing child socket");
-			inet_sk_set_state(child, TCP_CLOSE);
-			sock_set_flag(child, SOCK_DEAD);
-			inet_csk_destroy_sock(child);
-			child = NULL;
-		} else if (ctx->mp_capable) {
+		if (!ctx)
+			goto close_child;
+
+		if (ctx->mp_capable) {
 			token_new_accept(child);
+		} else if (ctx->mp_join) {
+			if (token_new_join(child)) {
+				goto close_child;
+			} else {
+				mptcp_finish_join(ctx->conn, child);
+			}
 		}
 	}
 
 	return child;
+
+close_child:
+	pr_debug("closing child socket");
+	inet_sk_set_state(child, TCP_CLOSE);
+	sock_set_flag(child, SOCK_DEAD);
+	inet_csk_destroy_sock(child);
+	return NULL;
 }
 
 static struct inet_connection_sock_af_ops subflow_specific;
@@ -223,6 +253,8 @@ static void subflow_ulp_release(struct sock *sk)
 
 	pr_debug("subflow=%p", ctx);
 
+	token_release(ctx->token);
+
 	kfree(ctx);
 }
 

net/mptcp/subflow.c static void subflow_ulp_clone(const struct request_sock *req, · line 291

Quoted 4 lines
net/mptcp/subflow.c +1 -0
@@ -256,6 +288,14 @@ static void subflow_ulp_clone(const struct request_sock *req,
 		new_ctx->ssn_offset = subflow_req->ssn_offset;
 		new_ctx->idsn = subflow_req->idsn;
 		pr_debug("token=%u", new_ctx->token);
+	} else if (subflow_req->mp_join) {

Possibly 'else' is not required here ?!? Something alike:

pr_debug("token=%u", new_ctx->token);
+ }
+ if (subflow_req->mp_join) {

net/mptcp/subflow.c static void subflow_ulp_clone(const struct request_sock *req, · line 300

Quoted 9 lines
net/mptcp/subflow.c +7 -0
+		new_ctx->mp_join = 1;
+		new_ctx->fourth_ack = 1;
+		new_ctx->backup = subflow_req->backup;
+		new_ctx->local_id = subflow_req->local_id;
+		new_ctx->token = subflow_req->token;
+		new_ctx->thmac = subflow_req->thmac;
+		pr_debug("token=%u", new_ctx->token);
 	}
 }

Cheers,

Paolo

author
#7 lore raw

Re: [MPTCP] [RFC v2 3/3] mptcp: Add handling of incoming MP_JOIN requests

Quoted 30 lines · Paolo Abeni

Hi again,

[...]

net/mptcp/options.c bool mptcp_synack_options(const struct request_sock *req, unsigned int *size, · line 456

Quoted 11 lines · Peter Krystad
net/mptcp/options.c +2 -1
@@ -419,11 +448,23 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 		opts->sndr_key = subflow_req->local_key;
 		opts->rcvr_key = subflow_req->remote_key;
 		*size = TCPOLEN_MPTCP_MPC_SYNACK;
-		pr_debug("subflow_req=%p, local_key=%llu, remote_key=%llu",
+		pr_debug("req=%p, local_key=%llu, remote_key=%llu",
 			 subflow_req, subflow_req->local_key,
 			 subflow_req->remote_key);
 		return true;
 	}
+	if (subflow_req->mp_join) {

Here I'm a bit lost... I think we should always enter the previos block statement. The current relevant code will become:

     if (subflow_req->mp_capable) {
                opts->suboptions = OPTION_MPTCP_MPC_SYNACK;
                opts->sndr_key = subflow_req->local_key;
                opts->rcvr_key = subflow_req->remote_key;
                *size = TCPOLEN_MPTCP_MPC_SYNACK;
                pr_debug("local_key=%llu", subflow_req->local_key);
                pr_debug("remote_key=%llu", subflow_req->remote_key);
                return true;
     }
     if (subflow_req->mp_join) {
Quoted 2 lines

and mp_capable should be set, so we should never enter the 'if (subflow_req->mp_join) {' branch, right? What I'm missing here?!?

Well, the code is missing an 'else' that would make things more clear. These meaning of these fields in the request_sock are 'saw an mp_capable option in the SYN' or 'saw an mp_join option in the SYN'. Only one of them will be true at a time and an else can be used. I will add the else.

Quoted 9 lines
Quoted 9 lines
net/mptcp/protocol.c +0 -0
index a1a42ed7810a..6468f0d8ef04 100644
@@ -777,6 +777,27 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 	inet_sk_state_store(sk, TCP_ESTABLISHED);
 }
 
Quoted 7 lines

net/mptcp/protocol.c void mptcp_finish_connect(struct sock *sk, int mp_capable) · line 783

Quoted 4 lines
net/mptcp/protocol.c +4 -0
+void mptcp_finish_join(struct sock *conn, struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(conn);
+	struct subflow_context *subflow = subflow_ctx(sk);

Very minor thing: we should apply the reverse X-mass tree order to variable declaration.

Will fix.

Quoted 14 lines

net/mptcp/subflow.c static void subflow_v4_init_req(struct request_sock *req, · line 72

Quoted 10 lines
net/mptcp/subflow.c +1 -0
index a31f58990c86..9a475f83d446 100644
@@ -69,8 +69,21 @@ static void subflow_v4_init_req(struct request_sock *req,
 		token_new_request(req, skb);
 		pr_debug("syn seq=%u", TCP_SKB_CB(skb)->seq);
 		subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
+	} else if (rx_opt.mptcp.mp_join && listener->request_mptcp) {

Here I'm lost again, aren't we always going to enter only the previous block statement? I expect to have MP_CAPABLE and MP_JOIN option in the same packet?!?

No, MP_CAPABLE and MP_JOIN should never be in the same packet. MP_JOIN carries the token that identifies the MPTCP connection that was established with a MP_CAPABLE exchange. I will add a check here to verify that the packet does not contain both.

Quoted 17 lines
Quoted 17 lines
net/mptcp/subflow.c +12 -0
+		subflow_req->mp_join = 1;
+		subflow_req->backup = rx_opt.mptcp.backup;
+		subflow_req->remote_id = rx_opt.mptcp.join_id;
+		subflow_req->token = rx_opt.mptcp.token;
+		subflow_req->remote_nonce = rx_opt.mptcp.nonce;
+		pr_debug("token=%u, remote_nonce=%u", subflow_req->token,
+			 subflow_req->remote_nonce);
+		if (token_join_request(req, skb)) {
+			subflow_req->mp_join = 0;
+			// @@ need to trigger RST
+		}
 	} else {
 		subflow_req->mp_capable = 0;
+		subflow_req->mp_join = 0;
 	}
 }
 
Quoted 8 lines

net/mptcp/subflow.c static struct sock *subflow_syn_recv_sock(const struct sock *sk, · line 151

Quoted 5 lines
net/mptcp/subflow.c +1 -0
@@ -135,6 +148,13 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 		    (subflow_req->local_key != opt_rx.mptcp.rcvr_key) ||
 		    (subflow_req->remote_key != opt_rx.mptcp.sndr_key))
 			return NULL;
+	} else if (subflow_req->mp_join) {

Here similar situation... shouldn't we have a single invocation to mptcp_get_options()?!?

No. This is the processing for the final ACK of the 3-way handshake, we are checking that if we received MP_JOIN in the initial SYN then we also get one in the final ACK, and that the HMAC checks out. Likewise the previous clause validates that an MP_CAPABLE was received in the final ACK and the keys are correct.

Quoted 55 lines
Quoted 55 lines
net/mptcp/subflow.c +25 -7
+		opt_rx.mptcp.mp_join = 0;
+		mptcp_get_options(skb, &opt_rx);
+		if ((!opt_rx.mptcp.mp_join) ||
+		    (token_join_valid(req, &opt_rx))) {
+			return NULL;
+		}
 	}
 
 	child = tcp_v4_syn_recv_sock(sk, skb, req, dst, req_unhash, own_req);
@@ -142,18 +162,28 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 	if (child && *own_req) {
 		struct subflow_context *ctx = subflow_ctx(child);
 
-		if (!ctx) {
-			pr_debug("Closing child socket");
-			inet_sk_set_state(child, TCP_CLOSE);
-			sock_set_flag(child, SOCK_DEAD);
-			inet_csk_destroy_sock(child);
-			child = NULL;
-		} else if (ctx->mp_capable) {
+		if (!ctx)
+			goto close_child;
+
+		if (ctx->mp_capable) {
 			token_new_accept(child);
+		} else if (ctx->mp_join) {
+			if (token_new_join(child)) {
+				goto close_child;
+			} else {
+				mptcp_finish_join(ctx->conn, child);
+			}
 		}
 	}
 
 	return child;
+
+close_child:
+	pr_debug("closing child socket");
+	inet_sk_set_state(child, TCP_CLOSE);
+	sock_set_flag(child, SOCK_DEAD);
+	inet_csk_destroy_sock(child);
+	return NULL;
 }
 
 static struct inet_connection_sock_af_ops subflow_specific;
@@ -223,6 +253,8 @@ static void subflow_ulp_release(struct sock *sk)
 
 	pr_debug("subflow=%p", ctx);
 
+	token_release(ctx->token);
+
 	kfree(ctx);
 }
 
Quoted 7 lines

net/mptcp/subflow.c static void subflow_ulp_clone(const struct request_sock *req, · line 291

Quoted 5 lines
net/mptcp/subflow.c +1 -0
@@ -256,6 +288,14 @@ static void subflow_ulp_clone(const struct request_sock *req,
 		new_ctx->ssn_offset = subflow_req->ssn_offset;
 		new_ctx->idsn = subflow_req->idsn;
 		pr_debug("token=%u", new_ctx->token);
+	} else if (subflow_req->mp_join) {

Possibly 'else' is not required here ?!? Something alike:

No, it is fine, previous reasons apply.

Peter.

Quoted 20 lines
(quoted diff) +2 -0
 		pr_debug("token=%u", new_ctx->token);
+	}
+	if (subflow_req->mp_join) {

net/mptcp/subflow.c static void subflow_ulp_clone(const struct request_sock *req, · line 300

Quoted 11 lines
net/mptcp/subflow.c +7 -0
+		new_ctx->mp_join = 1;
+		new_ctx->fourth_ack = 1;
+		new_ctx->backup = subflow_req->backup;
+		new_ctx->local_id = subflow_req->local_id;
+		new_ctx->token = subflow_req->token;
+		new_ctx->thmac = subflow_req->thmac;
+		pr_debug("token=%u", new_ctx->token);
 	}
 }

Cheers,

Paolo

#8 lore raw
In reply to Peter Krystad

Hi Peter, Paolo,

Quoted 13 lines · Peter Krystad

Current state of MP_JOIN handling. As I mentioned this is not functional yet but am sharing for visibility. The intent of this patchset is to complete the handshake for a second subflow in the incoming direction. Sending an outgoing SYN with MP_JOIN and the data path is not addressed.

v2 - pr_debug() cleanup and single mptcp_established() hook were
address in other already-merged patchsets
- split path manager skeleton into its own commit
- cleaned up logic in subflow_syn_recv_sock
- rebase onto Florian's locking change
- namespace for token table NOT addressed

Quoted 4 lines

Peter Krystad (3):
mptcp: Add path manager interface
mptcp: Add ADD_ADDR handling
mptcp: Add handling of incoming MP_JOIN requests

Thank you for the patches and the review!

I added these 3 patches at the end but I also took the liberty to:

- move new TCPOLEN macros from include/net/tcp.h to net/mptcp/protocol.h

- apply this patch (50cab8858b7f) in "mptcp: Add handling of incoming MP_JOIN requests" to fix a compilation error when CONFIG_MPTCP was not used.

-static inline boo*k* mptcp_sk_is_subflow(const struct sock *sk) +static inline boo*l* mptcp_sk_is_subflow(const struct sock *sk)

Apparently there is no book called mptcp_sk_is_subflow() yet, maybe a good idea of name ;-)

I just re-ran the tests with these new patches and this time, I have an error with KASAN and PROVE_LOCKING, same as the one I saw a few hours ago:

00:19:46.711 # ns1  MPTCP -> ns3  (10.0.2.2:10010) TCP  	[ OK ]
00:19:48.368 # ns1  TCP   -> ns3  (10.0.2.2:10011) MPTCP	[ OK ]
00:19:49.865 # ns1  MPTCP -> ns3  (10.0.3.2:10012) MPTCP	main_loop_s:

timed out
00:20:20.940 # copyfd_io: poll timed out (events: POLLIN 1, POLLOUT 4) 00:20:20.943 # [ FAIL ] client exit code 2, server 2 00:20:20.943 # \nnetns ns3 socket stat for 10012:
00:20:21.081 # State Recv-Q Send-Q Local Address:Port
Peer Address:Port
00:20:21.082 # SYN-RECV 0 0 10.0.3.2:10012

      10.0.1.1:39530    timer:(on,990ms,4) cwnd:2 retrans:4/0 reordering:0

00:20:21.086 # \nnetns ns1 socket stat for 10012:
00:20:21.130 # State Recv-Q Send-Q Local Address:Port
Peer Address:Port
00:20:21.130 # FIN-WAIT-1 0 57345 10.0.1.1:39530

      10.0.3.2:10012    timer:(on,21sec,7) rto:25.72 cwnd:1 ssthresh:7
retrans:7/0 reordering:0
00:20:21.146 # ns1  MPTCP -> ns4  (10.0.3.1:10013) MPTCP	[ OK ]
00:20:26.032 # ns1  MPTCP -> ns4  (10.0.3.1:10014) TCP  	[ OK ]

But for the rest, the other tests are good.

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