Skip to contentSkip to conversation

mptcp: support for rfc6824 MP CAPABLE hanshake

PATCH Superseded Christoph Paasch 5 participants 19 messages Dec 2, 2019 – Dec 5, 2019

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Christoph Paasch

author
#0 lore raw

cover mptcp: support for rfc6824 MP CAPABLE hanshake

Second iteration of the v1 MP_CAPABLE handshake, adding the handling of the option-space issue.

The patches apply just before "mptcp: add basic kselftest for mptcp".

Christoph Paasch (2):
mptcp: parse and emit MP_CAPABLE option according to v1 spec.
mptcp: process MP_CAPABLE data option.

Paolo Abeni (1):
mptcp: move from sha1 (v0) to sha256 (v1)

 include/linux/tcp.h   |   3 +-
 include/net/mptcp.h   |  11 +-
 net/ipv4/tcp_input.c  |   2 +-
 net/ipv4/tcp_output.c |   2 +-
 net/mptcp/Kconfig     |  10 ++
 net/mptcp/crypto.c    | 139 +++++++++++++++----------
 net/mptcp/options.c   | 229 ++++++++++++++++++++++++++++++++----------
 net/mptcp/protocol.c  |  22 ++--
 net/mptcp/protocol.h  |  18 ++--
 net/mptcp/subflow.c   |  43 +++++++-
 10 files changed, 349 insertions(+), 130 deletions(-)
Signature · 1 line
2.23.0
author
#1 lore raw

PATCH 1/3 mptcp: move from sha1 (v0) to sha256 (v1)

From: Paolo Abeni <pabeni(a)redhat.com>

For simplicity's sake use directly sha256 primitives (and pull them as a required build dep).
Add optional, boot-time self-tests for the hmac function.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>
---
 net/mptcp/Kconfig    |  10 ++++
 net/mptcp/crypto.c   | 139 ++++++++++++++++++++++++++-----------------
 net/mptcp/options.c  |   9 ++-
 net/mptcp/protocol.h |   4 +-
 4 files changed, 103 insertions(+), 59 deletions(-)
net/mptcp/Kconfig +10 -0
index c1a99f07a4cd..5db56d2218c5 100644
@@ -3,6 +3,7 @@ config MPTCP
 	bool "MPTCP: Multipath TCP"
 	depends on INET
 	select SKB_EXTENSIONS
+	select CRYPTO_LIB_SHA256
 	help
 	  Multipath TCP (MPTCP) connections send and receive data over multiple
 	  subflows in order to utilize multiple network paths. Each subflow
@@ -14,3 +15,12 @@ config MPTCP_IPV6
 	depends on MPTCP
 	select IPV6
 	default y
+
+config MPTCP_HMAC_TEST
+	bool "Tests for MPTCP HMAC implementation"
+	default n
+	help
+	  This option enable boot time self-test for the HMAC implementation
+	  used by the MPTCP code
+
+	  Say N if you are unsure.
net/mptcp/crypto.c +84 -55

176 lines not on this page · raw message

net/mptcp/options.c +7 -2
index 2f014332cdef..1cb0bd687b6b 100644
@@ -9,6 +9,11 @@
 #include <net/mptcp.h>
 #include "protocol.h"
 
+static bool mptcp_cap_flag_sha256(u8 flags)
+{
+	return (flags & MPTCP_CAP_FLAG_MASK) == MPTCP_CAP_HMAC_SHA256;
+}
+
 void mptcp_parse_option(const unsigned char *ptr, int opsize,
 			struct tcp_options_received *opt_rx)
 {
@@ -33,7 +38,7 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
 			break;
 
 		mp_opt->flags = *ptr++;
-		if (!((mp_opt->flags & MPTCP_CAP_FLAG_MASK) == MPTCP_CAP_HMAC_SHA1) ||
+		if (!mptcp_cap_flag_sha256(mp_opt->flags) ||
 		    (mp_opt->flags & MPTCP_CAP_EXTENSIBILITY))
 			break;
 
@@ -434,7 +439,7 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
 		*ptr++ = htonl((TCPOPT_MPTCP << 24) | (len << 16) |
 			       (MPTCPOPT_MP_CAPABLE << 12) |
 			       ((MPTCP_VERSION_MASK & 0) << 8) |
-			       MPTCP_CAP_HMAC_SHA1);
+			       MPTCP_CAP_HMAC_SHA256);
 		put_unaligned_be64(opts->sndr_key, ptr);
 		ptr += 2;
 		if ((OPTION_MPTCP_MPC_SYNACK |
net/mptcp/protocol.h +2 -2
index 542aa9b67a60..dcdd3dcd19c6 100644
@@ -41,7 +41,7 @@
 #define MPTCP_VERSION_MASK	(0x0F)
 #define MPTCP_CAP_CHECKSUM_REQD	BIT(7)
 #define MPTCP_CAP_EXTENSIBILITY	BIT(6)
-#define MPTCP_CAP_HMAC_SHA1	BIT(0)
+#define MPTCP_CAP_HMAC_SHA256	BIT(0)
 #define MPTCP_CAP_FLAG_MASK	(0x3F)
 
 /* MPTCP DSS flags */
@@ -201,7 +201,7 @@ static inline void mptcp_crypto_key_gen_sha(u64 *key, u32 *token, u64 *idsn)
 }
 
 void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
-			   u32 *hash_out);
+			   void *hash_out);
 
 static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
 {
Signature · 1 line
2.23.0
#2 lore raw

[MPTCP] Re: [PATCH 1/3] mptcp: move from sha1 (v0) to sha256 (v1)

Hi Christoph, Paolo,

Quoted 8 lines · Christoph Paasch

From: Paolo Abeni <pabeni(a)redhat.com>

For simplicity's sake use directly sha256 primitives (and pull them as a required build dep).
Add optional, boot-time self-tests for the hmac function.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>

Sorry for this detail but regarding the Signed-off-by, should I write this instead?

Co-developed-by Christoph Paasch <cpaasch(a)apple.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>

Or do we have a "Signed-off-by" here from Christoph because you (Christoph) are the sender of this patch here? But can we keep it if you are not the one who will send this patch to netdev? :)

The rest looks good to me!

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

[MPTCP] Re: [PATCH 1/3] mptcp: move from sha1 (v0) to sha256 (v1)

Quoted 15 lines · Matthieu Baerts

Hi Christoph, Paolo,

Quoted 8 lines · Christoph Paasch

From: Paolo Abeni <pabeni(a)redhat.com>

For simplicity's sake use directly sha256 primitives (and pull them as a required build dep).
Add optional, boot-time self-tests for the hmac function.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>

Sorry for this detail but regarding the Signed-off-by, should I write this instead?

Quoted 6 lines
Co-developed-by Christoph Paasch <cpaasch(a)apple.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>

Or do we have a "Signed-off-by" here from Christoph because you (Christoph) are the sender of this patch here?

Likely the 2nd option ;)

Quoted 2 lines

But can we keep it if you
are not the one who will send this patch to netdev? :)

Not a big deal to me, but strictly speaking I think keeping it for netdev submission would be correct only if Christoph will do the netdev submission, too.

Note: before the submission it would be good to review once again the tag correctness.

Cheers,

Paolo

#4 lore raw

[MPTCP] Re: [PATCH 1/3] mptcp: move from sha1 (v0) to sha256 (v1)

Hi Paolo,

Quoted 23 lines · Paolo Abeni
Quoted 15 lines · Matthieu Baerts

Hi Christoph, Paolo,

Quoted 8 lines · Christoph Paasch

From: Paolo Abeni <pabeni(a)redhat.com>

For simplicity's sake use directly sha256 primitives (and pull them as a required build dep).
Add optional, boot-time self-tests for the hmac function.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>

Sorry for this detail but regarding the Signed-off-by, should I write this instead?

Quoted 6 lines
Co-developed-by Christoph Paasch <cpaasch(a)apple.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>

Or do we have a "Signed-off-by" here from Christoph because you (Christoph) are the sender of this patch here?

Quoted 8 lines

Likely the 2nd option ;)

Quoted 2 lines

But can we keep it if you
are not the one who will send this patch to netdev? :)

Not a big deal to me, but strictly speaking I think keeping it for netdev submission would be correct only if Christoph will do the netdev submission, too.

So for you, when we apply this, better to only keep one your signed-off and add the signed-off of the submitter (probably Mat)?

Quoted 2 lines

Note: before the submission it would be good to review once again the tag correctness.

Good idea!
I think we should also review the whole commit messages in general. Maybe some are no longer up to date after all the squashes we did :)

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

[MPTCP] Re: [PATCH 1/3] mptcp: move from sha1 (v0) to sha256 (v1)

Quoted 31 lines · Matthieu Baerts

Hi Paolo,

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

Hi Christoph, Paolo,

Quoted 8 lines · Christoph Paasch

From: Paolo Abeni <pabeni(a)redhat.com>

For simplicity's sake use directly sha256 primitives (and pull them as a required build dep).
Add optional, boot-time self-tests for the hmac function.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>

Sorry for this detail but regarding the Signed-off-by, should I write this instead?

Quoted 6 lines
Co-developed-by Christoph Paasch <cpaasch(a)apple.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>

Or do we have a "Signed-off-by" here from Christoph because you (Christoph) are the sender of this patch here?

Likely the 2nd option ;)

Quoted 2 lines

But can we keep it if you
are not the one who will send this patch to netdev? :)

Quoted 6 lines
Quoted 3 lines

Not a big deal to me, but strictly speaking I think keeping it for netdev submission would be correct only if Christoph will do the netdev submission, too.

So for you, when we apply this, better to only keep one your signed-off and add the signed-off of the submitter (probably Mat)?

Exactly!

Quoted 6 lines
Quoted 2 lines

Note: before the submission it would be good to review once again the tag correctness.

Good idea!
I think we should also review the whole commit messages in general. Maybe some are no longer up to date after all the squashes we did :)

+1!

Cheers,

Paolo

author
#6 lore raw

[MPTCP] Re: [PATCH 1/3] mptcp: move from sha1 (v0) to sha256 (v1)

In reply to Paolo Abeni
Quoted 28 lines · Paolo Abeni
Quoted 15 lines · Matthieu Baerts

Hi Christoph, Paolo,

Quoted 8 lines · Christoph Paasch

From: Paolo Abeni <pabeni(a)redhat.com>

For simplicity's sake use directly sha256 primitives (and pull them as a required build dep).
Add optional, boot-time self-tests for the hmac function.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>

Sorry for this detail but regarding the Signed-off-by, should I write this instead?

Quoted 6 lines
Co-developed-by Christoph Paasch <cpaasch(a)apple.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>

Or do we have a "Signed-off-by" here from Christoph because you (Christoph) are the sender of this patch here?

Likely the 2nd option ;)

Quoted 2 lines

But can we keep it if you
are not the one who will send this patch to netdev? :)

Quoted 6 lines

Not a big deal to me, but strictly speaking I think keeping it for netdev submission would be correct only if Christoph will do the netdev submission, too.

Note: before the submission it would be good to review once again the tag correctness.

Yes, sorry for the added Signed-off-by. My script applies patches from e-mails with "-s" and I forgot to remove this one here.

Thanks,
Christoph

#7 lore raw

[MPTCP] Re: [PATCH 1/3] mptcp: move from sha1 (v0) to sha256 (v1)

In reply to Christoph Paasch

Hi -

This patch 1/3 looks good to me. Farewell mptcp.org interop!

Peter.

Quoted 279 lines · Christoph Paasch

From: Paolo Abeni <pabeni(a)redhat.com>

For simplicity's sake use directly sha256 primitives (and pull them as a required build dep).
Add optional, boot-time self-tests for the hmac function.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>
---
 net/mptcp/Kconfig    |  10 ++++
 net/mptcp/crypto.c   | 139 ++++++++++++++++++++++++++-----------------
 net/mptcp/options.c  |   9 ++-
 net/mptcp/protocol.h |   4 +-
 4 files changed, 103 insertions(+), 59 deletions(-)
net/mptcp/Kconfig +10 -0
index c1a99f07a4cd..5db56d2218c5 100644
@@ -3,6 +3,7 @@ config MPTCP
 	bool "MPTCP: Multipath TCP"
 	depends on INET
 	select SKB_EXTENSIONS
+	select CRYPTO_LIB_SHA256
 	help
 	  Multipath TCP (MPTCP) connections send and receive data over multiple
 	  subflows in order to utilize multiple network paths. Each subflow
@@ -14,3 +15,12 @@ config MPTCP_IPV6
 	depends on MPTCP
 	select IPV6
 	default y
+
+config MPTCP_HMAC_TEST
+	bool "Tests for MPTCP HMAC implementation"
+	default n
+	help
+	  This option enable boot time self-test for the HMAC implementation
+	  used by the MPTCP code
+
+	  Say N if you are unsure.
net/mptcp/crypto.c +84 -55
index ccb9f7effdcd..68f1758b96c2 100644
@@ -21,67 +21,36 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/cryptohash.h>
+#include <crypto/sha.h>
 #include <asm/unaligned.h>
 
 #include "protocol.h"
 
-struct sha1_state {
-	u32 workspace[SHA_WORKSPACE_WORDS];
-	u32 digest[SHA_DIGEST_WORDS];
-	unsigned int count;
-};
-
-static void sha1_init(struct sha1_state *state)
-{
-	sha_init(state->digest);
-	state->count = 0;
-}
-
-static void sha1_update(struct sha1_state *state, u8 *input)
-{
-	sha_transform(state->digest, input, state->workspace);
-	state->count += SHA_MESSAGE_BYTES;
-}
-
-static void sha1_pad_final(struct sha1_state *state, u8 *input, unsigned length,
-			   __be32 *mptcp_hashed_key)
-{
-	int i;
-
-	input[length] = 0x80;
-	memset(&input[length + 1], 0, SHA_MESSAGE_BYTES - length - 9);
-	put_unaligned_be64((length + state->count) << 3,
-			   &input[SHA_MESSAGE_BYTES - 8]);
-
-	sha_transform(state->digest, input, state->workspace);
-	for (i = 0; i < SHA_DIGEST_WORDS; ++i)
-		put_unaligned_be32(state->digest[i], &mptcp_hashed_key[i]);
-
-	memzero_explicit(state->workspace, SHA_WORKSPACE_WORDS << 2);
-}
+#define SHA256_DIGEST_WORDS (SHA256_DIGEST_SIZE / 4)
 
 void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn)
 {
-	__be32 mptcp_hashed_key[SHA_DIGEST_WORDS];
-	u8 input[SHA_MESSAGE_BYTES];
-	struct sha1_state state;
+	__be32 mptcp_hashed_key[SHA256_DIGEST_WORDS];
+	__be64 input = cpu_to_be64(key);
+	struct sha256_state state;
 
-	sha1_init(&state);
-	put_unaligned_be64(key, input);
-	sha1_pad_final(&state, input, 8, mptcp_hashed_key);
+	sha256_init(&state);
+	sha256_update(&state, (__force u8 *)&input, sizeof(input));
+	sha256_final(&state, (u8 *)mptcp_hashed_key);
 
 	if (token)
 		*token = be32_to_cpu(mptcp_hashed_key[0]);
 	if (idsn)
-		*idsn = be64_to_cpu(*((__be64 *)&mptcp_hashed_key[3]));
+		*idsn = be64_to_cpu(*((__be64 *)&mptcp_hashed_key[6]));
 }
 
 void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
-			    u32 *hash_out)
+			   void *hmac)
 {
-	u8 input[SHA_MESSAGE_BYTES * 2];
-	struct sha1_state state;
+	u8 input[SHA256_BLOCK_SIZE + SHA256_DIGEST_SIZE];
+	__be32 mptcp_hashed_key[SHA256_DIGEST_WORDS];
+	__be32 *hash_out = (__force __be32 *)hmac;
+	struct sha256_state state;
 	u8 key1be[8];
 	u8 key2be[8];
 	int i;
@@ -96,17 +65,16 @@ void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
 	for (i = 0; i < 8; i++)
 		input[i + 8] ^= key2be[i];
 
-	put_unaligned_be32(nonce1, &input[SHA_MESSAGE_BYTES]);
-	put_unaligned_be32(nonce2, &input[SHA_MESSAGE_BYTES + 4]);
+	put_unaligned_be32(nonce1, &input[SHA256_BLOCK_SIZE]);
+	put_unaligned_be32(nonce2, &input[SHA256_BLOCK_SIZE + 4]);
 
-	sha1_init(&state);
-	sha1_update(&state, input);
+	sha256_init(&state);
+	sha256_update(&state, input, SHA256_BLOCK_SIZE + 8);
 
 	/* emit sha256(K1 || msg) on the second input block, so we can
 	 * reuse 'input' for the last hashing
 	 */
-	sha1_pad_final(&state, &input[SHA_MESSAGE_BYTES], 8,
-		       (__force __be32 *)&input[SHA_MESSAGE_BYTES]);
+	sha256_final(&state, &input[SHA256_BLOCK_SIZE]);
 
 	/* Prepare second part of hmac */
 	memset(input, 0x5C, SHA_MESSAGE_BYTES);
@@ -115,8 +83,69 @@ void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
 	for (i = 0; i < 8; i++)
 		input[i + 8] ^= key2be[i];
 
-	sha1_init(&state);
-	sha1_update(&state, input);
-	sha1_pad_final(&state, &input[SHA_MESSAGE_BYTES], SHA_DIGEST_WORDS << 2,
-		      (__be32*)hash_out);
+	sha256_init(&state);
+	sha256_update(&state, input, SHA256_BLOCK_SIZE + SHA256_DIGEST_SIZE);
+	sha256_final(&state, (u8 *)mptcp_hashed_key);
+
+	/* takes only first 160 bits */
+	for (i = 0; i < 5; i++)
+		hash_out[i] = mptcp_hashed_key[i];
+}
+
+#ifdef CONFIG_MPTCP_HMAC_TEST
+struct test_cast {
+	char *key;
+	char *msg;
+	char *result;
+};
+
+/* we can't reuse RFC 4231 test vectors, as we have constraint on the
+ * input and key size, and we truncate the output.
+ */
+static struct test_cast tests[] = {
+	{
+		.key = "0b0b0b0b0b0b0b0b",
+		.msg = "48692054",
+		.result = "8385e24fb4235ac37556b6b886db106284a1da67",
+	},
+	{
+		.key = "aaaaaaaaaaaaaaaa",
+		.msg = "dddddddd",
+		.result = "2c5e219164ff1dca1c4a92318d847bb6b9d44492",
+	},
+	{
+		.key = "0102030405060708",
+		.msg = "cdcdcdcd",
+		.result = "e73b9ba9969969cefb04aa0d6df18ec2fcc075b6",
+	},
+};
+
+static void __init crypto_test(void)
+{
+	char hmac[20], hmac_hex[41];
+	u32 nonce1, nonce2;
+	u64 key1, key2;
+	int i, j;
+
+	for (i = 0; i < ARRAY_SIZE(tests); ++i) {
+		/* mptcp hmap will convert to be before computing the hmac */
+		key1 = be64_to_cpu(*((__be64 *)&tests[i].key[0]));
+		key2 = be64_to_cpu(*((__be64 *)&tests[i].key[8]));
+		nonce1 = be32_to_cpu(*((__be32 *)&tests[i].msg[0]));
+		nonce2 = be32_to_cpu(*((__be32 *)&tests[i].msg[4]));
+
+		mptcp_crypto_hmac_sha(key1, key2, nonce1, nonce2, hmac);
+		for (j = 0; j < 20; ++j)
+			sprintf(&hmac_hex[j << 1], "%02x", hmac[j] & 0xff);
+		hmac_hex[40] = 0;
+
+		if (memcmp(hmac_hex, tests[i].result, 40))
+			pr_err("test %d failed, got %s expected %s", i,
+			       hmac_hex, tests[i].result);
+		else
+			pr_info("test %d [ ok ]", i);
+	}
 }
+
+late_initcall(crypto_test);
+#endif
net/mptcp/options.c +7 -2
index 2f014332cdef..1cb0bd687b6b 100644
@@ -9,6 +9,11 @@
 #include <net/mptcp.h>
 #include "protocol.h"
 
+static bool mptcp_cap_flag_sha256(u8 flags)
+{
+	return (flags & MPTCP_CAP_FLAG_MASK) == MPTCP_CAP_HMAC_SHA256;
+}
+
 void mptcp_parse_option(const unsigned char *ptr, int opsize,
 			struct tcp_options_received *opt_rx)
 {
@@ -33,7 +38,7 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
 			break;
 
 		mp_opt->flags = *ptr++;
-		if (!((mp_opt->flags & MPTCP_CAP_FLAG_MASK) == MPTCP_CAP_HMAC_SHA1) ||
+		if (!mptcp_cap_flag_sha256(mp_opt->flags) ||
 		    (mp_opt->flags & MPTCP_CAP_EXTENSIBILITY))
 			break;
 
@@ -434,7 +439,7 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
 		*ptr++ = htonl((TCPOPT_MPTCP << 24) | (len << 16) |
 			       (MPTCPOPT_MP_CAPABLE << 12) |
 			       ((MPTCP_VERSION_MASK & 0) << 8) |
-			       MPTCP_CAP_HMAC_SHA1);
+			       MPTCP_CAP_HMAC_SHA256);
 		put_unaligned_be64(opts->sndr_key, ptr);
 		ptr += 2;
 		if ((OPTION_MPTCP_MPC_SYNACK |
net/mptcp/protocol.h +2 -2
index 542aa9b67a60..dcdd3dcd19c6 100644
@@ -41,7 +41,7 @@
 #define MPTCP_VERSION_MASK	(0x0F)
 #define MPTCP_CAP_CHECKSUM_REQD	BIT(7)
 #define MPTCP_CAP_EXTENSIBILITY	BIT(6)
-#define MPTCP_CAP_HMAC_SHA1	BIT(0)
+#define MPTCP_CAP_HMAC_SHA256	BIT(0)
 #define MPTCP_CAP_FLAG_MASK	(0x3F)
 
 /* MPTCP DSS flags */
@@ -201,7 +201,7 @@ static inline void mptcp_crypto_key_gen_sha(u64 *key, u32 *token, u64 *idsn)
 }
 
 void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
-			   u32 *hash_out);
+			   void *hash_out);
 
 static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
 {
author
#8 lore raw

PATCH 2/3 mptcp: parse and emit MP_CAPABLE option according to v1 spec.

In reply to Christoph Paasch

This implements MP_CAPABLE options parsing and writing according the the RFC 6824 bis - MPTCP v1.
Local key is sent on syn/ack, and both keys are sent on 3rd ack. MP_CAPABLE messages len are updated accordingly.
We need the skbuff to emit correctly the above, so we push the skbuff struct as an argument all the way from tcp code to the relevant mptcp callbacks.

When processing incoming MP_CAPABLE + data, build a full blown DSS-like map info, to simplify later processing.
On child socket creation, we need to record the remote key, if available.

RFC -> v1:
- rebase on top of "mptcp: Add IPv6 support"
- explicitly assumes TCP option space is not exhausted

Signed-off-by Christoph Paasch <cpaasch(a)apple.com>
---
 include/linux/tcp.h   |   3 +-
 include/net/mptcp.h   |  11 +--
 net/ipv4/tcp_input.c  |   2 +-
 net/ipv4/tcp_output.c |   2 +-
 net/mptcp/options.c   | 172 ++++++++++++++++++++++++++++++++----------
 net/mptcp/protocol.c  |   2 +-
 net/mptcp/protocol.h  |   6 +-
 net/mptcp/subflow.c   |  14 +++-
 8 files changed, 159 insertions(+), 53 deletions(-)
include/linux/tcp.h +2 -1
index 4b3ab4226ba8..5760f16823c8 100644
@@ -114,7 +114,8 @@ struct tcp_options_received {
 			data_fin:1,
 			use_ack:1,
 			ack64:1,
-			__unused:3;
+			mp_capable_map:1,
+			__unused:2;
 	} mptcp;
 #endif
 };
include/net/mptcp.h +6 -5
index 6349c68e380b..6d82ff9b6a0b 100644
@@ -23,7 +23,8 @@ struct mptcp_ext {
 			data_fin:1,
 			use_ack:1,
 			ack64:1,
-			__unused:2;
+			mp_capable_map:1,
+			__unused:1;
 };
 
 struct mptcp_out_options {
@@ -49,10 +50,10 @@ static inline bool rsk_is_mptcp(const struct request_sock *req)
 	return tcp_rsk(req)->is_mptcp;
 }
 
-void mptcp_parse_option(const unsigned char *ptr, int opsize,
-			struct tcp_options_received *opt_rx);
-bool mptcp_syn_options(struct sock *sk, unsigned int *size,
-		       struct mptcp_out_options *opts);
+void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr,
+			int opsize, struct tcp_options_received *opt_rx);
+bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
+		       unsigned int *size, struct mptcp_out_options *opts);
 void mptcp_rcv_synsent(struct sock *sk);
 bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 			  struct mptcp_out_options *opts);
net/ipv4/tcp_input.c +1 -1
index d1ab9edfb764..16bd46a097d5 100644
@@ -3922,7 +3922,7 @@ void tcp_parse_options(const struct net *net,
 				break;
 #endif
 			case TCPOPT_MPTCP:
-				mptcp_parse_option(ptr, opsize, opt_rx);
+				mptcp_parse_option(skb, ptr, opsize, opt_rx);
 				break;
 
 			case TCPOPT_FASTOPEN:
net/ipv4/tcp_output.c +1 -1
index 8b2f2a8b9a23..82ebb1a4d669 100644
@@ -682,7 +682,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
 	if (sk_is_mptcp(sk)) {
 		unsigned int size;
 
-		if (mptcp_syn_options(sk, &size, &opts->mptcp)) {
+		if (mptcp_syn_options(sk, skb, &size, &opts->mptcp)) {
 			opts->options |= OPTION_MPTCP;
 			remaining -= size;
 		}
net/mptcp/options.c +132 -40

274 lines not on this page · raw message

net/mptcp/protocol.c +1 -1
index 6d959559aa1a..4b000f842d6b 100644
@@ -707,7 +707,7 @@ static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk)
 	msk->subflow = ssock;
 	subflow = mptcp_subflow_ctx(msk->subflow->sk);
 	subflow->request_mptcp = 1; /* @@ if MPTCP enabled */
-	subflow->request_version = 0; /* currently only v0 supported */
+	subflow->request_version = 1; /* only v1 supported */
 
 	sock_hold(ssock->sk);
 
net/mptcp/protocol.h +4 -2
index dcdd3dcd19c6..bdff743cf2b3 100644
@@ -27,9 +27,10 @@
 #define MPTCPOPT_MP_FASTCLOSE	7
 
 /* MPTCP suboption lengths */
-#define TCPOLEN_MPTCP_MPC_SYN		12
-#define TCPOLEN_MPTCP_MPC_SYNACK	20
+#define TCPOLEN_MPTCP_MPC_SYN		4
+#define TCPOLEN_MPTCP_MPC_SYNACK	12
 #define TCPOLEN_MPTCP_MPC_ACK		20
+#define TCPOLEN_MPTCP_MPC_ACK_DATA	22
 #define TCPOLEN_MPTCP_DSS_BASE		4
 #define TCPOLEN_MPTCP_DSS_ACK32		4
 #define TCPOLEN_MPTCP_DSS_ACK64		8
@@ -103,6 +104,7 @@ struct mptcp_subflow_context {
 	u64	remote_key;
 	u64	idsn;
 	u64	map_seq;
+	u32	snd_isn;
 	u32	token;
 	u32	rel_write_seq;
 	u32	map_subflow_seq;
net/mptcp/subflow.c +12 -2
index 37b3ae10c042..96cc80f8d751 100644
@@ -81,7 +81,6 @@ static void subflow_init_req(struct request_sock *req,
 			subflow_req->version = listener->request_version;
 		else
 			subflow_req->version = rx_opt.mptcp.version;
-		subflow_req->remote_key = rx_opt.mptcp.sndr_key;
 		subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
 	}
 }
@@ -183,11 +182,22 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 					  bool *own_req)
 {
 	struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk);
+	struct mptcp_subflow_request_sock *subflow_req;
+	struct tcp_options_received opt_rx;
 	struct sock *child;
 
 	pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn);
 
-	/* if the sk is MP_CAPABLE, we already received the client key */
+	/* if the sk is MP_CAPABLE, we need to fetch the client key */
+	subflow_req = mptcp_subflow_rsk(req);
+	if (subflow_req->mp_capable) {
+		opt_rx.mptcp.mp_capable = 0;
+		mptcp_get_options(skb, &opt_rx);
+		if (!opt_rx.mptcp.mp_capable)
+			subflow_req->mp_capable = 0;
+		else
+			subflow_req->remote_key = opt_rx.mptcp.sndr_key;
+	}
 
 	child = listener->icsk_af_ops->syn_recv_sock(sk, skb, req, dst,
 						     req_unhash, own_req);
Signature · 1 line
2.23.0
#9 lore raw

[MPTCP] Re: [PATCH 2/3] mptcp: parse and emit MP_CAPABLE option according to v1 spec.

Hi Christoph,

Thank you for the new version of the patch!

I have mostly a few questions, maybe no need to modify the code ;-)

I also added Paolo in cc. Because you supported Christoph for this task, don't hesitate to share some answers if you already have them (not to wait for West US coast to be up :-) )

Quoted 2 lines · Christoph Paasch

This implements MP_CAPABLE options parsing and writing according the the RFC 6824 bis - MPTCP v1.

(detail: according "to" the → I can fix that when applying it)

Quoted 6 lines

Local key is sent on syn/ack, and both keys are sent on 3rd ack. MP_CAPABLE messages len are updated accordingly.
We need the skbuff to emit correctly the above, so we push the skbuff struct as an argument all the way from tcp code to the relevant mptcp callbacks.

Quoted 7 lines

When processing incoming MP_CAPABLE + data, build a full blown DSS-like map info, to simplify later processing.
On child socket creation, we need to record the remote key, if available.

RFC -> v1:
- rebase on top of "mptcp: Add IPv6 support"
- explicitly assumes TCP option space is not exhausted

I guess I can remove these 3 lines when applying it, right?

Quoted 2 lines
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>

[...]

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

Quoted 7 lines
net/mptcp/options.c +1 -2
@@ -29,12 +29,24 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
  	 * 10-17: Receiver key (optional)
  	 */
  	case MPTCPOPT_MP_CAPABLE:
-		if (opsize != TCPOLEN_MPTCP_MPC_SYN &&
-		    opsize != TCPOLEN_MPTCP_MPC_SYNACK)
+		/* strict size checking */

Good idea, even for a v0 (but no need to change the patches v0 of course)

Quoted 8 lines
net/mptcp/options.c +8 -0
+		if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) {
+			if (skb->len > tcp_hdr(skb)->doff << 2)
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK;
+		} else {
+			if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK)
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYNACK;

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

Quoted 10 lines
net/mptcp/options.c +6 -1
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYN;
+		}
+		if (opsize != expected_opsize)
  			break;
 
+		/* only support V1 of the protocol */
  		mp_opt->version = *ptr++ & MPTCP_VERSION_MASK;
-		if (mp_opt->version != 0)
+		if (mp_opt->version != 1)

I don't know if you saw my previous comment but if we are parsing a SYN here, should we not accept all versions > 0 and reply that the highest version we support is v1? It seems that's what the RFC recommends and it seems important if we want to allow newer / experimental versions to exist. When we receive a SYN+ACK, I am not sure if we can "accept" receiving versions higher than the max we support.

Quoted 29 lines
net/mptcp/options.c +9 -10
  			break;
 
  		mp_opt->flags = *ptr++;
@@ -59,19 +71,29 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
  			break;
 
  		mp_opt->mp_capable = 1;
-		mp_opt->sndr_key = get_unaligned_be64(ptr);
-		ptr += 8;
-
-		if (opsize == TCPOLEN_MPTCP_MPC_SYNACK) {
+		if (opsize >= TCPOLEN_MPTCP_MPC_SYNACK) { > +			mp_opt->sndr_key = get_unaligned_be64(ptr);
+			ptr += 8;
+		}
+		if (opsize >= TCPOLEN_MPTCP_MPC_ACK) {
  			mp_opt->rcvr_key = get_unaligned_be64(ptr);
  			ptr += 8;
-			pr_debug("MP_CAPABLE flags=%x, sndr=%llu, rcvr=%llu",
-				 mp_opt->flags, mp_opt->sndr_key,
-				 mp_opt->rcvr_key);
-		} else {
-			pr_debug("MP_CAPABLE flags=%x, sndr=%llu",
-				 mp_opt->flags, mp_opt->sndr_key);
  		}
+		if (opsize == TCPOLEN_MPTCP_MPC_ACK_DATA) {
+			/* Section 3.1.:
+			 * "the data parameters in a MP_CAPABLE are semantically
+			 * equivalent to those in a DSS option and can be used
+			 * interchangeably."

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

Quoted 10 lines
net/mptcp/options.c +10 -0
+			 */
+			mp_opt->dss = 1;
+			mp_opt->use_map = 1;
+			mp_opt->mp_capable_map = 1;
+			mp_opt->data_len = get_unaligned_be16(ptr);
+			ptr += 2;
+		}
+		pr_debug("MP_CAPABLE flags=%x, optlen=%d sndr=%llu, rcvr=%llu len=%d",
+			 mp_opt->flags, opsize, mp_opt->sndr_key,
+			 mp_opt->rcvr_key, mp_opt->data_len);

(detail: should we also print the version if we accept that the other supports a newer one but can also be compatible with the older ones?)

Quoted 3 lines
net/mptcp/options.c +0 -0
  		break;
 
  	/* MPTCPOPT_MP_JOIN

[...]

Quoted 128 lines
net/mptcp/options.c +63 -16
@@ -272,20 +303,58 @@ void mptcp_rcv_synsent(struct sock *sk)
  	}
  }
 
-static bool mptcp_established_options_mp(struct sock *sk, unsigned int *size,
+static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
+					 unsigned int *size,
  					 unsigned int remaining,
  					 struct mptcp_out_options *opts)
  {
  	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
-
-	if (!subflow->fourth_ack) {
-		opts->suboptions = OPTION_MPTCP_MPC_ACK;
+	struct mptcp_ext *mpext;
+	unsigned int data_len;
+
+	pr_debug("subflow=%p fourth_ack=%d seq=%x:%x remaining=%d", subflow,
+		 subflow->fourth_ack, subflow->snd_isn,
+		 skb ? TCP_SKB_CB(skb)->seq : 0, remaining);
+
+	if (subflow->mp_capable && !subflow->fourth_ack && skb &&
+	    subflow->snd_isn == TCP_SKB_CB(skb)->seq) {
+		/* When skb is not available, we better over-estimate the
+		 * emitted options len. A full DSS option is longer than
+		 * TCPOLEN_MPTCP_MPC_ACK_DATA, so let's the caller try to fit
+		 * that.
+		 */
+		mpext = mptcp_get_ext(skb);
+		data_len = mpext ? mpext->data_len : 0;
  		opts->sndr_key = subflow->local_key;
  		opts->rcvr_key = subflow->remote_key;
+
+		/* Section 3.1.
+		 * The MP_CAPABLE option is carried on the SYN, SYN/ACK, and ACK
+		 * packets that start the first subflow of an MPTCP connection,
+		 * as well as the first packet that carries data
+		 */
+		if (data_len > 0) {
+			opts->suboptions = OPTION_MPTCP_MPC_ACK;
+
+			/* we will check ext_copy.data_len in
+			 * mptcp_write_options() to discriminate between
+			 * TCPOLEN_MPTCP_MPC_ACK_DATA and TCPOLEN_MPTCP_MPC_ACK
+			 */
+			opts->ext_copy.data_len = data_len;
+			*size = ALIGN(TCPOLEN_MPTCP_MPC_ACK_DATA, 4);
+			pr_debug("subflow=%p, local_key=%llu, remote_key=%llu map_len=%d",
+				 subflow, subflow->local_key,
+				 subflow->remote_key, opts->ext_copy.data_len);
+			return true;
+		}
+
+		/* plain MP_CAPABLE + ack */
+		opts->suboptions = OPTION_MPTCP_MPC_ACK;
+		opts->ext_copy.data_len = 0;
  		*size = TCPOLEN_MPTCP_MPC_ACK;
-		subflow->fourth_ack = 1;
  		pr_debug("subflow=%p, local_key=%llu, remote_key=%llu",
-			 subflow, subflow->local_key, subflow->remote_key);
+			 subflow, subflow->local_key,
+			 subflow->remote_key);
  		return true;
  	}
  	return false;
@@ -348,7 +417,7 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
  	if (!mptcp_subflow_ctx(sk)->mp_capable)
  		return false;
 
-	if (mptcp_established_options_mp(sk, &opt_size, remaining, opts))
+	if (mptcp_established_options_mp(sk, skb, &opt_size, remaining, opts))
  		ret = true;
  	else if (mptcp_established_options_dss(sk, skb, &opt_size, remaining,
  						 opts))
@@ -374,11 +443,9 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
  	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("subflow_req=%p, local_key=%llu, remote_key=%llu",
-			 subflow_req, subflow_req->local_key,
-			 subflow_req->remote_key);
+		pr_debug("req=%p, local_key=%llu",
+			 subflow_req, subflow_req->local_key);
  		return true;
  	}
  	return false;
@@ -406,11 +473,23 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
  	memset(mpext, 0, sizeof(*mpext));
 
  	if (mp_opt->use_map) {
-		mpext->data_seq = mp_opt->data_seq;
-		mpext->subflow_seq = mp_opt->subflow_seq;
+		if (mp_opt->mp_capable_map) {
+			/* this is an MP_CAPABLE carrying MPTCP data
+			 * we know this map the first chunk of data
+			 */
+			mptcp_crypto_key_sha(subflow->remote_key, NULL,
+					     &mpext->data_seq);
+			mpext->data_seq++;
+			mpext->subflow_seq = 1;
+			mpext->dsn64 = 1;
+			mpext->mp_capable_map = 1;
+		} else {
+			mpext->data_seq = mp_opt->data_seq;
+			mpext->subflow_seq = mp_opt->subflow_seq;
+			mpext->dsn64 = mp_opt->dsn64;
+		}
  		mpext->data_len = mp_opt->data_len;
  		mpext->use_map = 1;
-		mpext->dsn64 = mp_opt->dsn64;
  	}
 
  	if (mp_opt->use_ack) {
@@ -424,8 +503,7 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 
  void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
  {
-	if ((OPTION_MPTCP_MPC_SYN |
-	     OPTION_MPTCP_MPC_SYNACK |
+	if ((OPTION_MPTCP_MPC_SYN | OPTION_MPTCP_MPC_SYNACK |
  	     OPTION_MPTCP_MPC_ACK) & opts->suboptions) {
  		u8 len;
 
@@ -433,22 +511,36 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
  			len = TCPOLEN_MPTCP_MPC_SYN;
  		else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)

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

Quoted 10 lines
net/mptcp/options.c +3 -1
  			len = TCPOLEN_MPTCP_MPC_SYNACK;
+		else if (opts->ext_copy.data_len)
+			len = TCPOLEN_MPTCP_MPC_ACK_DATA;
  		else
  			len = TCPOLEN_MPTCP_MPC_ACK;
 
  		*ptr++ = htonl((TCPOPT_MPTCP << 24) | (len << 16) |
  			       (MPTCPOPT_MP_CAPABLE << 12) |
-			       ((MPTCP_VERSION_MASK & 0) << 8) |
+			       ((MPTCP_VERSION_MASK & 1) << 8) |

Why do you have to change the bit we need from the mask here?

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

Quoted 4 lines
net/mptcp/options.c +3 -0
  			       MPTCP_CAP_HMAC_SHA256);
+
+		if (!((OPTION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) &
+		    opts->suboptions))

(a detail but why not checking only for SYN?)

if (OPTION_MPTCP_MPC_SYN | & opts->suboptions)

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

Quoted 10 lines
net/mptcp/options.c +3 -5
+			goto mp_capable_done;
+
  		put_unaligned_be64(opts->sndr_key, ptr);
  		ptr += 2;
-		if ((OPTION_MPTCP_MPC_SYNACK |
-		     OPTION_MPTCP_MPC_ACK) & opts->suboptions) {
-			put_unaligned_be64(opts->rcvr_key, ptr);
-			ptr += 2;
-		}
+		if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))

(a detail but here as well, can we not check only for SYNACK?)

Quoted 16 lines
net/mptcp/options.c +11 -0
+			goto mp_capable_done;
+
+		put_unaligned_be64(opts->rcvr_key, ptr);
+		ptr += 2;
+		if (!opts->ext_copy.data_len)
+			goto mp_capable_done;
+
+		put_unaligned_be32(opts->ext_copy.data_len << 16 |
+				   TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
+		ptr += 1;
  	}
 
+mp_capable_done:
  	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/protocol.h line 31

Quoted 12 lines
net/mptcp/protocol.h +2 -2
index dcdd3dcd19c6..bdff743cf2b3 100644
@@ -27,9 +27,10 @@
  #define MPTCPOPT_MP_FASTCLOSE	7
 
  /* MPTCP suboption lengths */
-#define TCPOLEN_MPTCP_MPC_SYN		12
-#define TCPOLEN_MPTCP_MPC_SYNACK	20
+#define TCPOLEN_MPTCP_MPC_SYN		4
+#define TCPOLEN_MPTCP_MPC_SYNACK	12

This (and other changes) will conflict with Davide's patch but don't worry, easy to resolve.

Quoted 5 lines
net/mptcp/protocol.h +1 -0
  #define TCPOLEN_MPTCP_MPC_ACK		20
+#define TCPOLEN_MPTCP_MPC_ACK_DATA	22
  #define TCPOLEN_MPTCP_DSS_BASE		4
  #define TCPOLEN_MPTCP_DSS_ACK32		4
  #define TCPOLEN_MPTCP_DSS_ACK64		8

[...]

Quoted 20 lines
net/mptcp/subflow.c +2 -1
index 37b3ae10c042..96cc80f8d751 100644
@@ -81,7 +81,6 @@ static void subflow_init_req(struct request_sock *req,
  			subflow_req->version = listener->request_version;
  		else
  			subflow_req->version = rx_opt.mptcp.version;
-		subflow_req->remote_key = rx_opt.mptcp.sndr_key;
  		subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
  	}
  }
@@ -183,11 +182,22 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
  					  bool *own_req)
  {
  	struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk);
+	struct mptcp_subflow_request_sock *subflow_req;
+	struct tcp_options_received opt_rx;
  	struct sock *child;
 

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

Quoted 10 lines
net/mptcp/subflow.c +7 -1
  	pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn);
 
-	/* if the sk is MP_CAPABLE, we already received the client key */
+	/* if the sk is MP_CAPABLE, we need to fetch the client key */
+	subflow_req = mptcp_subflow_rsk(req);
+	if (subflow_req->mp_capable) {
+		opt_rx.mptcp.mp_capable = 0;
+		mptcp_get_options(skb, &opt_rx);
+		if (!opt_rx.mptcp.mp_capable)
+			subflow_req->mp_capable = 0;

Does that mean that syn_recv_sock() will do a fallback to TCP?

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

Quoted 7 lines
net/mptcp/subflow.c +3 -0
+		else
+			subflow_req->remote_key = opt_rx.mptcp.sndr_key;
+	}
 
  	child = listener->icsk_af_ops->syn_recv_sock(sk, skb, req, dst,
  						     req_unhash, own_req);

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

[MPTCP] Re: [PATCH 2/3] mptcp: parse and emit MP_CAPABLE option according to v1 spec.

Quoted 10 lines · Matthieu Baerts

Hi Christoph,

Thank you for the new version of the patch!

I have mostly a few questions, maybe no need to modify the code ;-)

I also added Paolo in cc. Because you supported Christoph for this task, don't hesitate to share some answers if you already have them (not to wait for West US coast to be up :-) )

Quoted 5 lines
Quoted 2 lines · Christoph Paasch

This implements MP_CAPABLE options parsing and writing according the the RFC 6824 bis - MPTCP v1.

(detail: according "to" the → I can fix that when applying it)

Thank you!

Quoted 10 lines
Quoted 10 lines

Local key is sent on syn/ack, and both keys are sent on 3rd ack. MP_CAPABLE messages len are updated accordingly.
We need the skbuff to emit correctly the above, so we push the skbuff struct as an argument all the way from tcp code to the relevant mptcp callbacks.

When processing incoming MP_CAPABLE + data, build a full blown DSS-like map info, to simplify later processing.
On child socket creation, we need to record the remote key, if available.

Quoted 5 lines
Quoted 3 lines

RFC -> v1:
- rebase on top of "mptcp: Add IPv6 support"
- explicitly assumes TCP option space is not exhausted

I guess I can remove these 3 lines when applying it, right?

I guess so, too.

Quoted 28 lines
Quoted 1 line
Signed-off-by Christoph Paasch <cpaasch(a)apple.com>

[...]

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

Quoted 7 lines
net/mptcp/options.c +1 -2
@@ -29,12 +29,24 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
  	 * 10-17: Receiver key (optional)
  	 */
  	case MPTCPOPT_MP_CAPABLE:
-		if (opsize != TCPOLEN_MPTCP_MPC_SYN &&
-		    opsize != TCPOLEN_MPTCP_MPC_SYNACK)
+		/* strict size checking */

Good idea, even for a v0 (but no need to change the patches v0 of course)

Quoted 14 lines
net/mptcp/options.c +12 -0
+		if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) {
+			if (skb->len > tcp_hdr(skb)->doff << 2)
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK;
+		} else {
+			if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK)
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYNACK;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYN;
+		}
+		if (opsize != expected_opsize)
  			break;
 
Quoted 8 lines

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

Quoted 4 lines
net/mptcp/options.c +2 -1
+		/* only support V1 of the protocol */
  		mp_opt->version = *ptr++ & MPTCP_VERSION_MASK;
-		if (mp_opt->version != 0)
+		if (mp_opt->version != 1)

I don't know if you saw my previous comment but if we are parsing a SYN here, should we not accept all versions > 0 and reply that the highest version we support is v1?

Yep, sorry for the missing answer, so far. I think we can add easily that later, if/when newer/experimental version will surface. This code preserve the behaviour we already have with v0, I think we can keep as- is.

Quoted 31 lines
(quoted diff) +0 -0
@@ -59,19 +71,29 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
 >   			break;
Quoted 29 lines
net/mptcp/options.c +14 -10
  		mp_opt->mp_capable = 1;
-		mp_opt->sndr_key = get_unaligned_be64(ptr);
-		ptr += 8;
-
-		if (opsize == TCPOLEN_MPTCP_MPC_SYNACK) {
+		if (opsize >= TCPOLEN_MPTCP_MPC_SYNACK) { > +			mp_opt->sndr_key = get_unaligned_be64(ptr);
+			ptr += 8;
+		}
+		if (opsize >= TCPOLEN_MPTCP_MPC_ACK) {
  			mp_opt->rcvr_key = get_unaligned_be64(ptr);
  			ptr += 8;
-			pr_debug("MP_CAPABLE flags=%x, sndr=%llu, rcvr=%llu",
-				 mp_opt->flags, mp_opt->sndr_key,
-				 mp_opt->rcvr_key);
-		} else {
-			pr_debug("MP_CAPABLE flags=%x, sndr=%llu",
-				 mp_opt->flags, mp_opt->sndr_key);
  		}
+		if (opsize == TCPOLEN_MPTCP_MPC_ACK_DATA) {
+			/* Section 3.1.:
+			 * "the data parameters in a MP_CAPABLE are semantically
+			 * equivalent to those in a DSS option and can be used
+			 * interchangeably."
+			 */
+			mp_opt->dss = 1;
+			mp_opt->use_map = 1;
+			mp_opt->mp_capable_map = 1;
+			mp_opt->data_len = get_unaligned_be16(ptr);
Quoted 8 lines

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

Quoted 5 lines
net/mptcp/options.c +5 -0
+			ptr += 2;
+		}
+		pr_debug("MP_CAPABLE flags=%x, optlen=%d sndr=%llu, rcvr=%llu len=%d",
+			 mp_opt->flags, opsize, mp_opt->sndr_key,
+			 mp_opt->rcvr_key, mp_opt->data_len);

(detail: should we also print the version if we accept that the other supports a newer one but can also be compatible with the older ones?)

yes, if/when we will do that! ;)

Quoted 9 lines
Quoted 9 lines
net/mptcp/options.c +2 -0
@@ -433,22 +511,36 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
  			len = TCPOLEN_MPTCP_MPC_SYN;
  		else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)
  			len = TCPOLEN_MPTCP_MPC_SYNACK;
+		else if (opts->ext_copy.data_len)
+			len = TCPOLEN_MPTCP_MPC_ACK_DATA;
  		else
  			len = TCPOLEN_MPTCP_MPC_ACK;
 
Quoted 6 lines

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

Quoted 4 lines
net/mptcp/options.c +1 -1
  		*ptr++ = htonl((TCPOPT_MPTCP << 24) | (len << 16) |
  			       (MPTCPOPT_MP_CAPABLE << 12) |
-			       ((MPTCP_VERSION_MASK & 0) << 8) |
+			       ((MPTCP_VERSION_MASK & 1) << 8) |

Why do you have to change the bit we need from the mask here?

I guess the above is clearer after rebasing patch "mptcp: Add ADD_ADDR handling", which introduces the mptcp_option() helper.

The above statement set the version number inside the MP_CAPABLE option to 1 (the mask is unchanged, the code changes the version value to 1)

Quoted 7 lines

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

Quoted 5 lines
net/mptcp/options.c +3 -0
  			       MPTCP_CAP_HMAC_SHA256);
+
+		if (!((OPTION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) &
+		    opts->suboptions))

(a detail but why not checking only for SYN?)

Yep, that would be equivalent. I guess the logic above is checking for whatever options need to process more data.

Quoted 4 lines
Quoted 4 lines
net/mptcp/options.c +2 -0
+			goto mp_capable_done;
+
  		put_unaligned_be64(opts->sndr_key, ptr);
  		ptr += 2;
Quoted 8 lines

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

Quoted 6 lines
net/mptcp/options.c +1 -5
-		if ((OPTION_MPTCP_MPC_SYNACK |
-		     OPTION_MPTCP_MPC_ACK) & opts->suboptions) {
-			put_unaligned_be64(opts->rcvr_key, ptr);
-			ptr += 2;
-		}
+		if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))

(a detail but here as well, can we not check only for SYNACK?)

I'm sorry I did not get it. Could you please re-phrase?

Quoted 10 lines
Quoted 10 lines
net/mptcp/subflow.c +2 -0
@@ -183,11 +182,22 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
  					  bool *own_req)
  {
  	struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk);
+	struct mptcp_subflow_request_sock *subflow_req;
+	struct tcp_options_received opt_rx;
  	struct sock *child;
 
  	pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn);
 
Quoted 10 lines

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

Quoted 8 lines
net/mptcp/subflow.c +7 -1
-	/* if the sk is MP_CAPABLE, we already received the client key */
+	/* if the sk is MP_CAPABLE, we need to fetch the client key */
+	subflow_req = mptcp_subflow_rsk(req);
+	if (subflow_req->mp_capable) {
+		opt_rx.mptcp.mp_capable = 0;
+		mptcp_get_options(skb, &opt_rx);
+		if (!opt_rx.mptcp.mp_capable)
+			subflow_req->mp_capable = 0;

Does that mean that syn_recv_sock() will do a fallback to TCP?

AFAICS, yes. I guess pktdrill will help testing this code ;)

Thank you for the in-depth review!

Paolo

#11 lore raw

[MPTCP] Re: [PATCH 2/3] mptcp: parse and emit MP_CAPABLE option according to v1 spec.

Hi Paolo,

Quoted 1 line · Paolo Abeni

On Tue, 2019-12-03 at 11:39 +0100, Matthieu Baerts wrote:

[...]

Quoted 33 lines
Quoted 24 lines

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

Quoted 7 lines
net/mptcp/options.c +1 -2
@@ -29,12 +29,24 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
   	 * 10-17: Receiver key (optional)
   	 */
   	case MPTCPOPT_MP_CAPABLE:
-		if (opsize != TCPOLEN_MPTCP_MPC_SYN &&
-		    opsize != TCPOLEN_MPTCP_MPC_SYNACK)
+		/* strict size checking */

Good idea, even for a v0 (but no need to change the patches v0 of course)

Quoted 14 lines
net/mptcp/options.c +12 -0
+		if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) {
+			if (skb->len > tcp_hdr(skb)->doff << 2)
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK;
+		} else {
+			if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK)
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYNACK;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYN;
+		}
+		if (opsize != expected_opsize)
   			break;
 
Quoted 8 lines

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

Quoted 4 lines
net/mptcp/options.c +2 -1
+		/* only support V1 of the protocol */
   		mp_opt->version = *ptr++ & MPTCP_VERSION_MASK;
-		if (mp_opt->version != 0)
+		if (mp_opt->version != 1)

I don't know if you saw my previous comment but if we are parsing a SYN here, should we not accept all versions > 0 and reply that the highest version we support is v1?

Quoted 4 lines

Yep, sorry for the missing answer, so far. I think we can add easily that later, if/when newer/experimental version will surface. This code preserve the behaviour we already have with v0, I think we can keep as- is.

The problem with this code is that if someone develops a version higher than 1, it will not be compatible with our MPTCP upstream one, not because he/she didn't implement a fallback to an older version or the new version isn't backward compatible but because the Linux upstream version doesn't allow that:

    C                              S (MPTCP upstream)
    |---- SYN(MP_CAPABLE v2) ----> |
    |                              |
    | <--- SYN (without MPTCP) --- |

I am sure we can fix that later but better to do that as soon as possible :) (I can propose a patch after it is applied if it is OK for you)

Quoted 18 lines
Quoted 1 line

Review >

Quoted 1 line
(quoted diff) +0 -0
@@ -433,22 +511,36 @@> 

Paolo
void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)

Quoted 8 lines
Quoted 8 lines
net/mptcp/options.c +2 -0
   			len = TCPOLEN_MPTCP_MPC_SYN;
   		else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)
   			len = TCPOLEN_MPTCP_MPC_SYNACK;
+		else if (opts->ext_copy.data_len)
+			len = TCPOLEN_MPTCP_MPC_ACK_DATA;
   		else
   			len = TCPOLEN_MPTCP_MPC_ACK;
 
Quoted 6 lines

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

Quoted 4 lines
net/mptcp/options.c +1 -1
   		*ptr++ = htonl((TCPOPT_MPTCP << 24) | (len << 16) |
   			       (MPTCPOPT_MP_CAPABLE << 12) |
-			       ((MPTCP_VERSION_MASK & 0) << 8) |
+			       ((MPTCP_VERSION_MASK & 1) << 8) |

Why do you have to change the bit we need from the mask here?

Quoted 5 lines

I guess the above is clearer after rebasing patch "mptcp: Add ADD_ADDR handling", which introduces the mptcp_option() helper.

The above statement set the version number inside the MP_CAPABLE option to 1 (the mask is unchanged, the code changes the version value to 1)

Oh yes, sorry, I was expecting to find "subflow->request_version" where we set the version 1.

Maybe clearer with a "#define MPTCP_VERSION 0x1" but a detail :)

Quoted 26 lines
Quoted 4 lines

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

Quoted 4 lines
net/mptcp/options.c +2 -0
   			       MPTCP_CAP_HMAC_SHA256);
+
+		if (!((OP> 

Paolo
TION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) &

Quoted 3 lines

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

Quoted 1 line
net/mptcp/options.c +1 -0
+		    opts->suboptions))

(a detail but why not checking only for SYN?)

Yep, that would be equivalent. I guess the logic above is checking for whatever options need to process more data.

Quoted 4 lines
Quoted 4 lines
net/mptcp/options.c +2 -0
+			goto mp_capable_done;
+
   		put_unaligned_be64(opts->sndr_key, ptr);
   		ptr += 2;
Quoted 8 lines

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

Quoted 6 lines
net/mptcp/options.c +1 -5
-		if ((OPTION_MPTCP_MPC_SYNACK |
-		     OPTION_MPTCP_MPC_ACK) & opts->suboptions) {
-			put_unaligned_be64(opts->rcvr_key, ptr);
-			ptr += 2;
-		}
+		if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))

(a detail but here as well, can we not check only for SYNACK?)

Quoted 1 line

I'm sorry I did not get it. Could you please re-phrase?

sorry, it is just that here, we are looking if we don't have a SYN_ACK if I am not mistaken. So instead of:

if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))

we could have:

if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)

no? The result is the same, maybe just clearer.

Quoted 22 lines
Quoted 11 lines
Quoted 11 lines
net/mptcp/subflow.c +2 -0
@@ -183,11 +182,22 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
   					  bool *own_req)
   {
   	struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk);
+	struct mptcp_subflow_request_sock *subflow_req;
+	struct tcp_options_received opt_rx;
   	struct sock *child;
 
   	pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn);
 
Quoted 10 lines

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

Quoted 8 lines
net/mptcp/subflow.c +7 -1
-	/* if the sk is MP_CAPABLE, we already received the client key */
+	/* if the sk is MP_CAPABLE, we need to fetch the client key */
+	subflow_req = mptcp_subflow_rsk(req);
+	if (subflow_req->mp_capable) {
+		opt_rx.mptcp.mp_capable = 0;
+		mptcp_get_options(skb, &opt_rx);
+		if (!opt_rx.mptcp.mp_capable)
+			subflow_req->mp_capable = 0;

Does that mean that syn_recv_sock() will do a fallback to TCP?

Quoted 1 line

AFAICS, yes. I guess pktdrill will help testing this code ;)

Could be good to test because it is not clear what will happen :-)

Quoted 1 line

Thank you for the in-depth review!

You are welcome.

Do you know if anybody else would like to review it? I will wait a bit before applying it :)

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

[MPTCP] Re: [PATCH 2/3] mptcp: parse and emit MP_CAPABLE option according to v1 spec.

Quoted 51 lines · Matthieu Baerts

Hi Paolo,

Quoted 1 line · Paolo Abeni

On Tue, 2019-12-03 at 11:39 +0100, Matthieu Baerts wrote:

[...]

Quoted 33 lines
Quoted 24 lines

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

Quoted 7 lines
net/mptcp/options.c +1 -2
@@ -29,12 +29,24 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
   	 * 10-17: Receiver key (optional)
   	 */
   	case MPTCPOPT_MP_CAPABLE:
-		if (opsize != TCPOLEN_MPTCP_MPC_SYN &&
-		    opsize != TCPOLEN_MPTCP_MPC_SYNACK)
+		/* strict size checking */

Good idea, even for a v0 (but no need to change the patches v0 of course)

Quoted 14 lines
net/mptcp/options.c +12 -0
+		if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) {
+			if (skb->len > tcp_hdr(skb)->doff << 2)
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK;
+		} else {
+			if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK)
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYNACK;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYN;
+		}
+		if (opsize != expected_opsize)
   			break;
 
Quoted 8 lines

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

Quoted 4 lines
net/mptcp/options.c +2 -1
+		/* only support V1 of the protocol */
   		mp_opt->version = *ptr++ & MPTCP_VERSION_MASK;
-		if (mp_opt->version != 0)
+		if (mp_opt->version != 1)

I don't know if you saw my previous comment but if we are parsing a SYN here, should we not accept all versions > 0 and reply that the highest version we support is v1?

Quoted 4 lines

Yep, sorry for the missing answer, so far. I think we can add easily that later, if/when newer/experimental version will surface. This code preserve the behaviour we already have with v0, I think we can keep as- is.

The problem with this code is that if someone develops a version higher than 1, it will not be compatible with our MPTCP upstream one, not because he/she didn't implement a fallback to an older version or the new version isn't backward compatible but because the Linux upstream version doesn't allow that:

Quoted 7 lines
    C                              S (MPTCP upstream)
    |---- SYN(MP_CAPABLE v2) ----> |
    |                              |
    | <--- SYN (without MPTCP) --- |

I am sure we can fix that later but better to do that as soon as possible :) (I can propose a patch after it is applied if it is OK for you)

Ok, but I would wait at least for a v2 RFC to surface!!!

Quoted 60 lines
Quoted 19 lines
Quoted 2 lines

Review >

Quoted 2 lines
(quoted diff) +0 -0
@@ -433,22 +511,36 @@> 

Paolo
void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)

Quoted 8 lines
Quoted 8 lines
net/mptcp/options.c +2 -0
   			len = TCPOLEN_MPTCP_MPC_SYN;
   		else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)
   			len = TCPOLEN_MPTCP_MPC_SYNACK;
+		else if (opts->ext_copy.data_len)
+			len = TCPOLEN_MPTCP_MPC_ACK_DATA;
   		else
   			len = TCPOLEN_MPTCP_MPC_ACK;
 
Quoted 6 lines

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

Quoted 4 lines
net/mptcp/options.c +1 -1
   		*ptr++ = htonl((TCPOPT_MPTCP << 24) | (len << 16) |
   			       (MPTCPOPT_MP_CAPABLE << 12) |
-			       ((MPTCP_VERSION_MASK & 0) << 8) |
+			       ((MPTCP_VERSION_MASK & 1) << 8) |

Why do you have to change the bit we need from the mask here?

Quoted 5 lines

I guess the above is clearer after rebasing patch "mptcp: Add ADD_ADDR handling", which introduces the mptcp_option() helper.

The above statement set the version number inside the MP_CAPABLE option to 1 (the mask is unchanged, the code changes the version value to 1)

Oh yes, sorry, I was expecting to find "subflow->request_version" where we set the version 1.

Maybe clearer with a "#define MPTCP_VERSION 0x1" but a detail :)

Quoted 25 lines
Quoted 3 lines

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

Quoted 3 lines
net/mptcp/options.c +2 -0
   			       MPTCP_CAP_HMAC_SHA256);
+
+		if (!((OP> 

Paolo
TION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) &

Quoted 3 lines

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

Quoted 1 line
net/mptcp/options.c +1 -0
+		    opts->suboptions))

(a detail but why not checking only for SYN?)

Yep, that would be equivalent. I guess the logic above is checking for whatever options need to process more data.

Quoted 4 lines
Quoted 4 lines
net/mptcp/options.c +2 -0
+			goto mp_capable_done;
+
   		put_unaligned_be64(opts->sndr_key, ptr);
   		ptr += 2;
Quoted 8 lines

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

Quoted 6 lines
net/mptcp/options.c +1 -5
-		if ((OPTION_MPTCP_MPC_SYNACK |
-		     OPTION_MPTCP_MPC_ACK) & opts->suboptions) {
-			put_unaligned_be64(opts->rcvr_key, ptr);
-			ptr += 2;
-		}
+		if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))

(a detail but here as well, can we not check only for SYNACK?)

Quoted 1 line

I'm sorry I did not get it. Could you please re-phrase?

sorry, it is just that here, we are looking if we don't have a SYN_ACK if I am not mistaken. So instead of:

Quoted 7 lines
   if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))

we could have:

   if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)

no? The result is the same, maybe just clearer.

Yep, the check is equivalent.

To be honest it's not clearer to me, because the protocol says we need to fetch more data if this is a MPC_ACK (and we don't have anything todo if it's not).

Quoted 23 lines
Quoted 21 lines
Quoted 10 lines
Quoted 10 lines
net/mptcp/subflow.c +2 -0
@@ -183,11 +182,22 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
   					  bool *own_req)
   {
   	struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk);
+	struct mptcp_subflow_request_sock *subflow_req;
+	struct tcp_options_received opt_rx;
   	struct sock *child;
 
   	pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn);
 
Quoted 10 lines

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

Quoted 8 lines
net/mptcp/subflow.c +7 -1
-	/* if the sk is MP_CAPABLE, we already received the client key */
+	/* if the sk is MP_CAPABLE, we need to fetch the client key */
+	subflow_req = mptcp_subflow_rsk(req);
+	if (subflow_req->mp_capable) {
+		opt_rx.mptcp.mp_capable = 0;
+		mptcp_get_options(skb, &opt_rx);
+		if (!opt_rx.mptcp.mp_capable)
+			subflow_req->mp_capable = 0;

Does that mean that syn_recv_sock() will do a fallback to TCP?

Quoted 1 line

AFAICS, yes. I guess pktdrill will help testing this code ;)

Quoted 8 lines

Could be good to test because it is not clear what will happen :-)

Quoted 1 line

Thank you for the in-depth review!

You are welcome.

Do you know if anybody else would like to review it? I will wait a bit before applying it :)

I think it would be nice to squash/flush the pending patches soon, because I think it would be nice to have as much time as possible to polish the series. (e.g. I think we may want to squash somt part of the recent Florian's patches into the 2nd chunk part)

Cheers,

Paolo

#13 lore raw

[MPTCP] Re: [PATCH 2/3] mptcp: parse and emit MP_CAPABLE option according to v1 spec.

Quoted 57 lines · Paolo Abeni
Quoted 56 lines · Matthieu Baerts

Hi Paolo,

Quoted 1 line · Paolo Abeni

On Tue, 2019-12-03 at 11:39 +0100, Matthieu Baerts wrote:

[...]

Quoted 33 lines
Quoted 24 lines

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

Quoted 7 lines
net/mptcp/options.c +1 -2
@@ -29,12 +29,24 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
    	 * 10-17: Receiver key (optional)
    	 */
    	case MPTCPOPT_MP_CAPABLE:
-		if (opsize != TCPOLEN_MPTCP_MPC_SYN &&
-		    opsize != TCPOLEN_MPTCP_MPC_SYNACK)
+		/* strict size checking */

Good idea, even for a v0 (but no need to change the patches v0 of course)

Quoted 14 lines
net/mptcp/options.c +12 -0
+		if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) {
+			if (skb->len > tcp_hdr(skb)->doff << 2)
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK;
+		} else {
+			if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK)
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYNACK;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYN;
+		}
+		if (opsize != expected_opsize)
    			break;
 
Quoted 8 lines

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

Quoted 4 lines
net/mptcp/options.c +2 -1
+		/* only support V1 of the protocol */
    		mp_opt->version = *ptr++ & MPTCP_VERSION_MASK;
-		if (mp_opt->version != 0)
+		if (mp_opt->version != 1)

I don't know if you saw my previous comment but if we are parsing a SYN here, should we not accept all versions > 0 and reply that the highest version we support is v1?

Quoted 4 lines

Yep, sorry for the missing answer, so far. I think we can add easily that later, if/when newer/experimental version will surface. This code preserve the behaviour we already have with v0, I think we can keep as- is.

The problem with this code is that if someone develops a version higher than 1, it will not be compatible with our MPTCP upstream one, not because he/she didn't implement a fallback to an older version or the new version isn't backward compatible but because the Linux upstream version doesn't allow that:

     C                              S (MPTCP upstream)
     |---- SYN(MP_CAPABLE v2) ----> |
     |                              |
     | <--- SYN (without MPTCP) --- |
Quoted 4 lines
Quoted 2 lines

I am sure we can fix that later but better to do that as soon as possible :) (I can propose a patch after it is applied if it is OK for you)

Ok, but I would wait at least for a v2 RFC to surface!!!

OK, no problem for me!

Quoted 66 lines
Quoted 66 lines
Quoted 19 lines
Quoted 2 lines

Review >

Quoted 2 lines
(quoted diff) +0 -0
@@ -433,22 +511,36 @@>

Paolo
void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)

Quoted 8 lines
Quoted 8 lines
net/mptcp/options.c +2 -0
    			len = TCPOLEN_MPTCP_MPC_SYN;
    		else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)
    			len = TCPOLEN_MPTCP_MPC_SYNACK;
+		else if (opts->ext_copy.data_len)
+			len = TCPOLEN_MPTCP_MPC_ACK_DATA;
    		else
    			len = TCPOLEN_MPTCP_MPC_ACK;
 
Quoted 6 lines

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

Quoted 4 lines
net/mptcp/options.c +1 -1
    		*ptr++ = htonl((TCPOPT_MPTCP << 24) | (len << 16) |
    			       (MPTCPOPT_MP_CAPABLE << 12) |
-			       ((MPTCP_VERSION_MASK & 0) << 8) |
+			       ((MPTCP_VERSION_MASK & 1) << 8) |

Why do you have to change the bit we need from the mask here?

Quoted 5 lines

I guess the above is clearer after rebasing patch "mptcp: Add ADD_ADDR handling", which introduces the mptcp_option() helper.

The above statement set the version number inside the MP_CAPABLE option to 1 (the mask is unchanged, the code changes the version value to 1)

Oh yes, sorry, I was expecting to find "subflow->request_version" where we set the version 1.

Maybe clearer with a "#define MPTCP_VERSION 0x1" but a detail :)

Quoted 25 lines
Quoted 3 lines

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

Quoted 3 lines
net/mptcp/options.c +2 -0
    			       MPTCP_CAP_HMAC_SHA256);
+
+		if (!((OP>

Paolo
TION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) &

Quoted 3 lines

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

Quoted 1 line
net/mptcp/options.c +1 -0
+		    opts->suboptions))

(a detail but why not checking only for SYN?)

Yep, that would be equivalent. I guess the logic above is checking for whatever options need to process more data.

Quoted 4 lines
Quoted 4 lines
net/mptcp/options.c +2 -0
+			goto mp_capable_done;
+
    		put_unaligned_be64(opts->sndr_key, ptr);
    		ptr += 2;
Quoted 8 lines

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

Quoted 6 lines
net/mptcp/options.c +1 -5
-		if ((OPTION_MPTCP_MPC_SYNACK |
-		     OPTION_MPTCP_MPC_ACK) & opts->suboptions) {
-			put_unaligned_be64(opts->rcvr_key, ptr);
-			ptr += 2;
-		}
+		if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))

(a detail but here as well, can we not check only for SYNACK?)

Quoted 1 line

I'm sorry I did not get it. Could you please re-phrase?

sorry, it is just that here, we are looking if we don't have a SYN_ACK if I am not mistaken. So instead of:

    if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))

we could have:

    if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)
Quoted 7 lines
Quoted 1 line

no? The result is the same, maybe just clearer.

Yep, the check is equivalent.

To be honest it's not clearer to me, because the protocol says we need to fetch more data if this is a MPC_ACK (and we don't have anything todo if it's not).

OK, maybe Christoph had something else in mind when he wrote this! Fine to keep it but if we do some other modifications later, maybe better and clearer to simplify these if-statements :)

Quoted 29 lines
Quoted 29 lines
Quoted 21 lines
Quoted 10 lines
Quoted 10 lines
net/mptcp/subflow.c +2 -0
@@ -183,11 +182,22 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
    					  bool *own_req)
    {
    	struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk);
+	struct mptcp_subflow_request_sock *subflow_req;
+	struct tcp_options_received opt_rx;
    	struct sock *child;
 
    	pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn);
 
Quoted 10 lines

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

Quoted 8 lines
net/mptcp/subflow.c +7 -1
-	/* if the sk is MP_CAPABLE, we already received the client key */
+	/* if the sk is MP_CAPABLE, we need to fetch the client key */
+	subflow_req = mptcp_subflow_rsk(req);
+	if (subflow_req->mp_capable) {
+		opt_rx.mptcp.mp_capable = 0;
+		mptcp_get_options(skb, &opt_rx);
+		if (!opt_rx.mptcp.mp_capable)
+			subflow_req->mp_capable = 0;

Does that mean that syn_recv_sock() will do a fallback to TCP?

Quoted 1 line

AFAICS, yes. I guess pktdrill will help testing this code ;)

Could be good to test because it is not clear what will happen :-)

Quoted 1 line

Thank you for the in-depth review!

You are welcome.

Quoted 7 lines
Quoted 2 lines

Do you know if anybody else would like to review it? I will wait a bit before applying it :)

I think it would be nice to squash/flush the pending patches soon, because I think it would be nice to have as much time as possible to polish the series. (e.g. I think we may want to squash somt part of the recent Florian's patches into the 2nd chunk part)

OK! I propose to wait until tomorrow (afternoon for us) for additional reviews and squash this + Mat (Data FIN) and Florian (joins) patches + hopefully Davide (fix for v0) and yours (sendmsg)!

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

[MPTCP] Re: [PATCH 2/3] mptcp: parse and emit MP_CAPABLE option according to v1 spec.

Quoted 59 lines · Matthieu Baerts
Quoted 58 lines · Paolo Abeni
Quoted 57 lines · Matthieu Baerts

Hi Paolo,

Quoted 1 line · Paolo Abeni

On Tue, 2019-12-03 at 11:39 +0100, Matthieu Baerts wrote:

[...]

Quoted 34 lines
Quoted 25 lines

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

Quoted 8 lines
net/mptcp/options.c +1 -2
@@ -29,12 +29,24 @@ void mptcp_parse_option(const unsigned char *ptr, 
 int opsize,
    	 * 10-17: Receiver key (optional)
    	 */
    	case MPTCPOPT_MP_CAPABLE:
-		if (opsize != TCPOLEN_MPTCP_MPC_SYN &&
-		    opsize != TCPOLEN_MPTCP_MPC_SYNACK)
+		/* strict size checking */

Good idea, even for a v0 (but no need to change the patches v0 of course)

Quoted 13 lines
net/mptcp/options.c +12 -0
+		if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) {
+			if (skb->len > tcp_hdr(skb)->doff << 2)
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK;
+		} else {
+			if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK)
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYNACK;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYN;
+		}
+		if (opsize != expected_opsize)
    			break;
Quoted 8 lines

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

Quoted 4 lines
net/mptcp/options.c +1 -1
    +		/* only support V1 of the protocol */
    		mp_opt->version = *ptr++ & MPTCP_VERSION_MASK;
-		if (mp_opt->version != 0)
+		if (mp_opt->version != 1)

I don't know if you saw my previous comment but if we are parsing a SYN here, should we not accept all versions > 0 and reply that the highest version we support is v1?

Quoted 4 lines

Yep, sorry for the missing answer, so far. I think we can add easily that later, if/when newer/experimental version will surface. This code preserve the behaviour we already have with v0, I think we can keep as- is.

The problem with this code is that if someone develops a version higher than 1, it will not be compatible with our MPTCP upstream one, not because he/she didn't implement a fallback to an older version or the new version isn't backward compatible but because the Linux upstream version doesn't allow that:

     C                              S (MPTCP upstream)
     |---- SYN(MP_CAPABLE v2) ----> |
     |                              |
     | <--- SYN (without MPTCP) --- |
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I am sure we can fix that later but better to do that as soon as possible :)
(I can propose a patch after it is applied if it is OK for you)

Ok, but I would wait at least for a v2 RFC to surface!!!

OK, no problem for me!

Section 3.1 of RFC6824bis does say to send the SYNACK with the highest number supported (as long as the SYN specifies MPTCP v1 or later), which puts all of the compatibility work on the peer. Since that seems to have been added with version negotiation and future compatibility in mind, I think it makes sense to only break here if mp_opt->version == 0. Any potential future MPTCP RFCs will be assuming a v1 server will respond with a MPTCPv1 SYNACK.

That said, forcing a fallback with v2+ would still let two hosts connect with regular TCP, so we're not breaking the RFC. But this seems to be a one-line change for us, we can let the peer from the future figure out if it wants to fall back to MPTCPv1 or TCP.

Mat

Quoted 112 lines
Quoted 66 lines
Quoted 66 lines
Quoted 19 lines
Quoted 3 lines

Review >

Quoted 3 lines
(quoted diff) +0 -0
@@ -433,22 +511,36 @@>

Paolo
void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)

Quoted 5 lines
Quoted 5 lines
net/mptcp/options.c +2 -0
    			len = TCPOLEN_MPTCP_MPC_SYN;
    		else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)
    			len = TCPOLEN_MPTCP_MPC_SYNACK;
+		else if (opts->ext_copy.data_len)
+			len = TCPOLEN_MPTCP_MPC_ACK_DATA;
Quoted 8 lines

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

Quoted 6 lines
net/mptcp/options.c +1 -1
    		else
    			len = TCPOLEN_MPTCP_MPC_ACK;
        		*ptr++ = htonl((TCPOPT_MPTCP << 24) | (len << 16) |
    			       (MPTCPOPT_MP_CAPABLE << 12) |
-			       ((MPTCP_VERSION_MASK & 0) << 8) |
+			       ((MPTCP_VERSION_MASK & 1) << 8) |

Why do you have to change the bit we need from the mask here?

Quoted 5 lines

I guess the above is clearer after rebasing patch "mptcp: Add ADD_ADDR handling", which introduces the mptcp_option() helper.

The above statement set the version number inside the MP_CAPABLE option to 1 (the mask is unchanged, the code changes the version value to 1)

Oh yes, sorry, I was expecting to find "subflow->request_version" where we set the version 1.

Maybe clearer with a "#define MPTCP_VERSION 0x1" but a detail :)

Quoted 25 lines
Quoted 3 lines

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

Quoted 3 lines
net/mptcp/options.c +2 -0
    			       MPTCP_CAP_HMAC_SHA256);
+
+		if (!((OP>

Paolo
TION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) &

Quoted 3 lines

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

Quoted 1 line
net/mptcp/options.c +1 -0
+		    opts->suboptions))

(a detail but why not checking only for SYN?)

Yep, that would be equivalent. I guess the logic above is checking for whatever options need to process more data.

Quoted 4 lines
Quoted 4 lines
net/mptcp/options.c +2 -0
+			goto mp_capable_done;
+
    		put_unaligned_be64(opts->sndr_key, ptr);
    		ptr += 2;
Quoted 8 lines

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

Quoted 6 lines
net/mptcp/options.c +1 -5
-		if ((OPTION_MPTCP_MPC_SYNACK |
-		     OPTION_MPTCP_MPC_ACK) & opts->suboptions) {
-			put_unaligned_be64(opts->rcvr_key, ptr);
-			ptr += 2;
-		}
+		if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))

(a detail but here as well, can we not check only for SYNACK?)

Quoted 1 line

I'm sorry I did not get it. Could you please re-phrase?

sorry, it is just that here, we are looking if we don't have a SYN_ACK if I am not mistaken. So instead of:

    if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))

we could have:

    if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)
Quoted 7 lines
Quoted 1 line

no? The result is the same, maybe just clearer.

Yep, the check is equivalent.

To be honest it's not clearer to me, because the protocol says we need to fetch more data if this is a MPC_ACK (and we don't have anything todo if it's not).

OK, maybe Christoph had something else in mind when he wrote this! Fine to keep it but if we do some other modifications later, maybe better and clearer to simplify these if-statements :)

Quoted 34 lines
Quoted 33 lines
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
(quoted diff) +2 -0
@@ -183,11 +182,22 @@ static struct sock *subflow_syn_recv_sock(const 
 struct sock *sk,
    					  bool *own_req)
    {
    	struct mptcp_subflow_context *listener = 
 mptcp_subflow_ctx(sk);
+	struct mptcp_subflow_request_sock *subflow_req;
+	struct tcp_options_received opt_rx;
    	struct sock *child;
        	pr_debug("listener=%p, req=%p, conn=%p", listener, req, 
 listener->conn);
    -	/* if the sk is MP_CAPABLE, we already received the client 

key */

net/mptcp/subflow.c +1 -0
+	/* if the sk is MP_CAPABLE, we need to fetch the client key */
Quoted 8 lines

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

Quoted 6 lines
net/mptcp/subflow.c +6 -0
+	subflow_req = mptcp_subflow_rsk(req);
+	if (subflow_req->mp_capable) {
+		opt_rx.mptcp.mp_capable = 0;
+		mptcp_get_options(skb, &opt_rx);
+		if (!opt_rx.mptcp.mp_capable)
+			subflow_req->mp_capable = 0;

Does that mean that syn_recv_sock() will do a fallback to TCP?

Quoted 1 line

AFAICS, yes. I guess pktdrill will help testing this code ;)

Could be good to test because it is not clear what will happen :-)

Quoted 1 line

Thank you for the in-depth review!

You are welcome.

Do you know if anybody else would like to review it? I will wait a bit before applying it :)

Quoted 9 lines
Quoted 4 lines

I think it would be nice to squash/flush the pending patches soon, because I think it would be nice to have as much time as possible to polish the series. (e.g. I think we may want to squash somt part of the recent Florian's patches into the 2nd chunk part)

OK! I propose to wait until tomorrow (afternoon for us) for additional reviews and squash this + Mat (Data FIN) and Florian (joins) patches + hopefully Davide (fix for v0) and yours (sendmsg)!

--
Mat Martineau
Intel

#15 lore raw

[MPTCP] Re: [PATCH 2/3] mptcp: parse and emit MP_CAPABLE option according to v1 spec.

In reply to Christoph Paasch
Quoted 33 lines · Christoph Paasch

This implements MP_CAPABLE options parsing and writing according the the RFC 6824 bis - MPTCP v1.
Local key is sent on syn/ack, and both keys are sent on 3rd ack. MP_CAPABLE messages len are updated accordingly.
We need the skbuff to emit correctly the above, so we push the skbuff struct as an argument all the way from tcp code to the relevant mptcp callbacks.

When processing incoming MP_CAPABLE + data, build a full blown DSS-like map info, to simplify later processing.
On child socket creation, we need to record the remote key, if available.

RFC -> v1:
- rebase on top of "mptcp: Add IPv6 support"
- explicitly assumes TCP option space is not exhausted

Signed-off-by Christoph Paasch <cpaasch(a)apple.com>
---
 include/linux/tcp.h   |   3 +-
 include/net/mptcp.h   |  11 +--
 net/ipv4/tcp_input.c  |   2 +-
 net/ipv4/tcp_output.c |   2 +-
 net/mptcp/options.c   | 172 ++++++++++++++++++++++++++++++++----------
 net/mptcp/protocol.c  |   2 +-
 net/mptcp/protocol.h  |   6 +-
 net/mptcp/subflow.c   |  14 +++-
 8 files changed, 159 insertions(+), 53 deletions(-)
include/linux/tcp.h +0 -0
index 4b3ab4226ba8..5760f16823c8 100644

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

Quoted 5 lines
include/linux/tcp.h +1 -1
@@ -114,7 +114,8 @@ struct tcp_options_received {
 			data_fin:1,
 			use_ack:1,
 			ack64:1,
-			__unused:3;
+			mp_capable_map:1,

My only comment for this patch is can we use shorter name for this field like all the others? Maybe mpc_map? But don't redo patchset for just this change.

Peter.

Quoted 422 lines
include/linux/tcp.h +1 -0
+			__unused:2;
 	} mptcp;
 #endif
 };
include/net/mptcp.h +6 -5
index 6349c68e380b..6d82ff9b6a0b 100644
@@ -23,7 +23,8 @@ struct mptcp_ext {
 			data_fin:1,
 			use_ack:1,
 			ack64:1,
-			__unused:2;
+			mp_capable_map:1,
+			__unused:1;
 };
 
 struct mptcp_out_options {
@@ -49,10 +50,10 @@ static inline bool rsk_is_mptcp(const struct request_sock *req)
 	return tcp_rsk(req)->is_mptcp;
 }
 
-void mptcp_parse_option(const unsigned char *ptr, int opsize,
-			struct tcp_options_received *opt_rx);
-bool mptcp_syn_options(struct sock *sk, unsigned int *size,
-		       struct mptcp_out_options *opts);
+void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr,
+			int opsize, struct tcp_options_received *opt_rx);
+bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
+		       unsigned int *size, struct mptcp_out_options *opts);
 void mptcp_rcv_synsent(struct sock *sk);
 bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 			  struct mptcp_out_options *opts);
net/ipv4/tcp_input.c +1 -1
index d1ab9edfb764..16bd46a097d5 100644
@@ -3922,7 +3922,7 @@ void tcp_parse_options(const struct net *net,
 				break;
 #endif
 			case TCPOPT_MPTCP:
-				mptcp_parse_option(ptr, opsize, opt_rx);
+				mptcp_parse_option(skb, ptr, opsize, opt_rx);
 				break;
 
 			case TCPOPT_FASTOPEN:
net/ipv4/tcp_output.c +1 -1
index 8b2f2a8b9a23..82ebb1a4d669 100644
@@ -682,7 +682,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
 	if (sk_is_mptcp(sk)) {
 		unsigned int size;
 
-		if (mptcp_syn_options(sk, &size, &opts->mptcp)) {
+		if (mptcp_syn_options(sk, skb, &size, &opts->mptcp)) {
 			opts->options |= OPTION_MPTCP;
 			remaining -= size;
 		}
net/mptcp/options.c +132 -40
index 1cb0bd687b6b..299af8e5456d 100644
@@ -14,8 +14,8 @@ static bool mptcp_cap_flag_sha256(u8 flags)
 	return (flags & MPTCP_CAP_FLAG_MASK) == MPTCP_CAP_HMAC_SHA256;
 }
 
-void mptcp_parse_option(const unsigned char *ptr, int opsize,
-			struct tcp_options_received *opt_rx)
+void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr,
+			int opsize, struct tcp_options_received *opt_rx)
 {
 	struct mptcp_options_received *mp_opt = &opt_rx->mptcp;
 	u8 subtype = *ptr >> 4;
@@ -29,12 +29,24 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
 	 * 10-17: Receiver key (optional)
 	 */
 	case MPTCPOPT_MP_CAPABLE:
-		if (opsize != TCPOLEN_MPTCP_MPC_SYN &&
-		    opsize != TCPOLEN_MPTCP_MPC_SYNACK)
+		/* strict size checking */
+		if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) {
+			if (skb->len > tcp_hdr(skb)->doff << 2)
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_ACK;
+		} else {
+			if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK)
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYNACK;
+			else
+				expected_opsize = TCPOLEN_MPTCP_MPC_SYN;
+		}
+		if (opsize != expected_opsize)
 			break;
 
+		/* only support V1 of the protocol */
 		mp_opt->version = *ptr++ & MPTCP_VERSION_MASK;
-		if (mp_opt->version != 0)
+		if (mp_opt->version != 1)
 			break;
 
 		mp_opt->flags = *ptr++;
@@ -59,19 +71,29 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
 			break;
 
 		mp_opt->mp_capable = 1;
-		mp_opt->sndr_key = get_unaligned_be64(ptr);
-		ptr += 8;
-
-		if (opsize == TCPOLEN_MPTCP_MPC_SYNACK) {
+		if (opsize >= TCPOLEN_MPTCP_MPC_SYNACK) {
+			mp_opt->sndr_key = get_unaligned_be64(ptr);
+			ptr += 8;
+		}
+		if (opsize >= TCPOLEN_MPTCP_MPC_ACK) {
 			mp_opt->rcvr_key = get_unaligned_be64(ptr);
 			ptr += 8;
-			pr_debug("MP_CAPABLE flags=%x, sndr=%llu, rcvr=%llu",
-				 mp_opt->flags, mp_opt->sndr_key,
-				 mp_opt->rcvr_key);
-		} else {
-			pr_debug("MP_CAPABLE flags=%x, sndr=%llu",
-				 mp_opt->flags, mp_opt->sndr_key);
 		}
+		if (opsize == TCPOLEN_MPTCP_MPC_ACK_DATA) {
+			/* Section 3.1.:
+			 * "the data parameters in a MP_CAPABLE are semantically
+			 * equivalent to those in a DSS option and can be used
+			 * interchangeably."
+			 */
+			mp_opt->dss = 1;
+			mp_opt->use_map = 1;
+			mp_opt->mp_capable_map = 1;
+			mp_opt->data_len = get_unaligned_be16(ptr);
+			ptr += 2;
+		}
+		pr_debug("MP_CAPABLE flags=%x, optlen=%d sndr=%llu, rcvr=%llu len=%d",
+			 mp_opt->flags, opsize, mp_opt->sndr_key,
+			 mp_opt->rcvr_key, mp_opt->data_len);
 		break;
 
 	/* MPTCPOPT_MP_JOIN
@@ -105,6 +127,11 @@ void mptcp_parse_option(const unsigned char *ptr, int opsize,
 		pr_debug("DSS");
 		ptr++;
 
+		/* we must clear 'mp_capable_map' be able to detect MP_CAPABLE
+		 * map vs DSS map in mptcp_incoming_options(), and reconstruct
+		 * map info accordingly
+		 */
+		mp_opt->mp_capable_map = 0;
 		mp_opt->dss_flags = (*ptr++) & MPTCP_DSS_FLAG_MASK;
 		mp_opt->data_fin = (mp_opt->dss_flags & MPTCP_DSS_DATA_FIN) != 0;
 		mp_opt->dsn64 = (mp_opt->dss_flags & MPTCP_DSS_DSN64) != 0;
@@ -238,18 +265,22 @@ void mptcp_get_options(const struct sk_buff *skb,
 			if (opsize > length)
 				return;	/* don't parse partial options */
 			if (opcode == TCPOPT_MPTCP)
-				mptcp_parse_option(ptr, opsize, opt_rx);
+				mptcp_parse_option(skb, ptr, opsize, opt_rx);
 			ptr += opsize - 2;
 			length -= opsize;
 		}
 	}
 }
 
-bool mptcp_syn_options(struct sock *sk, unsigned int *size,
-		       struct mptcp_out_options *opts)
+bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
+		       unsigned int *size, struct mptcp_out_options *opts)
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 
+	/* we will use snd_isn to detect first pkt [re]transmission
+	 * in mptcp_established_options_mp()
+	 */
+	subflow->snd_isn = TCP_SKB_CB(skb)->end_seq;
 	if (subflow->request_mptcp) {
 		pr_debug("local_key=%llu", subflow->local_key);
 		opts->suboptions = OPTION_MPTCP_MPC_SYN;
@@ -272,20 +303,58 @@ void mptcp_rcv_synsent(struct sock *sk)
 	}
 }
 
-static bool mptcp_established_options_mp(struct sock *sk, unsigned int *size,
+static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
+					 unsigned int *size,
 					 unsigned int remaining,
 					 struct mptcp_out_options *opts)
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
-
-	if (!subflow->fourth_ack) {
-		opts->suboptions = OPTION_MPTCP_MPC_ACK;
+	struct mptcp_ext *mpext;
+	unsigned int data_len;
+
+	pr_debug("subflow=%p fourth_ack=%d seq=%x:%x remaining=%d", subflow,
+		 subflow->fourth_ack, subflow->snd_isn,
+		 skb ? TCP_SKB_CB(skb)->seq : 0, remaining);
+
+	if (subflow->mp_capable && !subflow->fourth_ack && skb &&
+	    subflow->snd_isn == TCP_SKB_CB(skb)->seq) {
+		/* When skb is not available, we better over-estimate the
+		 * emitted options len. A full DSS option is longer than
+		 * TCPOLEN_MPTCP_MPC_ACK_DATA, so let's the caller try to fit
+		 * that.
+		 */
+		mpext = mptcp_get_ext(skb);
+		data_len = mpext ? mpext->data_len : 0;
 		opts->sndr_key = subflow->local_key;
 		opts->rcvr_key = subflow->remote_key;
+
+		/* Section 3.1.
+		 * The MP_CAPABLE option is carried on the SYN, SYN/ACK, and ACK
+		 * packets that start the first subflow of an MPTCP connection,
+		 * as well as the first packet that carries data
+		 */
+		if (data_len > 0) {
+			opts->suboptions = OPTION_MPTCP_MPC_ACK;
+
+			/* we will check ext_copy.data_len in
+			 * mptcp_write_options() to discriminate between
+			 * TCPOLEN_MPTCP_MPC_ACK_DATA and TCPOLEN_MPTCP_MPC_ACK
+			 */
+			opts->ext_copy.data_len = data_len;
+			*size = ALIGN(TCPOLEN_MPTCP_MPC_ACK_DATA, 4);
+			pr_debug("subflow=%p, local_key=%llu, remote_key=%llu map_len=%d",
+				 subflow, subflow->local_key,
+				 subflow->remote_key, opts->ext_copy.data_len);
+			return true;
+		}
+
+		/* plain MP_CAPABLE + ack */
+		opts->suboptions = OPTION_MPTCP_MPC_ACK;
+		opts->ext_copy.data_len = 0;
 		*size = TCPOLEN_MPTCP_MPC_ACK;
-		subflow->fourth_ack = 1;
 		pr_debug("subflow=%p, local_key=%llu, remote_key=%llu",
-			 subflow, subflow->local_key, subflow->remote_key);
+			 subflow, subflow->local_key,
+			 subflow->remote_key);
 		return true;
 	}
 	return false;
@@ -348,7 +417,7 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
 	if (!mptcp_subflow_ctx(sk)->mp_capable)
 		return false;
 
-	if (mptcp_established_options_mp(sk, &opt_size, remaining, opts))
+	if (mptcp_established_options_mp(sk, skb, &opt_size, remaining, opts))
 		ret = true;
 	else if (mptcp_established_options_dss(sk, skb, &opt_size, remaining,
 						 opts))
@@ -374,11 +443,9 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 	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("subflow_req=%p, local_key=%llu, remote_key=%llu",
-			 subflow_req, subflow_req->local_key,
-			 subflow_req->remote_key);
+		pr_debug("req=%p, local_key=%llu",
+			 subflow_req, subflow_req->local_key);
 		return true;
 	}
 	return false;
@@ -406,11 +473,23 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 	memset(mpext, 0, sizeof(*mpext));
 
 	if (mp_opt->use_map) {
-		mpext->data_seq = mp_opt->data_seq;
-		mpext->subflow_seq = mp_opt->subflow_seq;
+		if (mp_opt->mp_capable_map) {
+			/* this is an MP_CAPABLE carrying MPTCP data
+			 * we know this map the first chunk of data
+			 */
+			mptcp_crypto_key_sha(subflow->remote_key, NULL,
+					     &mpext->data_seq);
+			mpext->data_seq++;
+			mpext->subflow_seq = 1;
+			mpext->dsn64 = 1;
+			mpext->mp_capable_map = 1;
+		} else {
+			mpext->data_seq = mp_opt->data_seq;
+			mpext->subflow_seq = mp_opt->subflow_seq;
+			mpext->dsn64 = mp_opt->dsn64;
+		}
 		mpext->data_len = mp_opt->data_len;
 		mpext->use_map = 1;
-		mpext->dsn64 = mp_opt->dsn64;
 	}
 
 	if (mp_opt->use_ack) {
@@ -424,8 +503,7 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 
 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
 {
-	if ((OPTION_MPTCP_MPC_SYN |
-	     OPTION_MPTCP_MPC_SYNACK |
+	if ((OPTION_MPTCP_MPC_SYN | OPTION_MPTCP_MPC_SYNACK |
 	     OPTION_MPTCP_MPC_ACK) & opts->suboptions) {
 		u8 len;
 
@@ -433,22 +511,36 @@ void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
 			len = TCPOLEN_MPTCP_MPC_SYN;
 		else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions)
 			len = TCPOLEN_MPTCP_MPC_SYNACK;
+		else if (opts->ext_copy.data_len)
+			len = TCPOLEN_MPTCP_MPC_ACK_DATA;
 		else
 			len = TCPOLEN_MPTCP_MPC_ACK;
 
 		*ptr++ = htonl((TCPOPT_MPTCP << 24) | (len << 16) |
 			       (MPTCPOPT_MP_CAPABLE << 12) |
-			       ((MPTCP_VERSION_MASK & 0) << 8) |
+			       ((MPTCP_VERSION_MASK & 1) << 8) |
 			       MPTCP_CAP_HMAC_SHA256);
+
+		if (!((OPTION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) &
+		    opts->suboptions))
+			goto mp_capable_done;
+
 		put_unaligned_be64(opts->sndr_key, ptr);
 		ptr += 2;
-		if ((OPTION_MPTCP_MPC_SYNACK |
-		     OPTION_MPTCP_MPC_ACK) & opts->suboptions) {
-			put_unaligned_be64(opts->rcvr_key, ptr);
-			ptr += 2;
-		}
+		if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))
+			goto mp_capable_done;
+
+		put_unaligned_be64(opts->rcvr_key, ptr);
+		ptr += 2;
+		if (!opts->ext_copy.data_len)
+			goto mp_capable_done;
+
+		put_unaligned_be32(opts->ext_copy.data_len << 16 |
+				   TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
+		ptr += 1;
 	}
 
+mp_capable_done:
 	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/protocol.c +1 -1
index 6d959559aa1a..4b000f842d6b 100644
@@ -707,7 +707,7 @@ static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk)
 	msk->subflow = ssock;
 	subflow = mptcp_subflow_ctx(msk->subflow->sk);
 	subflow->request_mptcp = 1; /* @@ if MPTCP enabled */
-	subflow->request_version = 0; /* currently only v0 supported */
+	subflow->request_version = 1; /* only v1 supported */
 
 	sock_hold(ssock->sk);
 
net/mptcp/protocol.h +4 -2
index dcdd3dcd19c6..bdff743cf2b3 100644
@@ -27,9 +27,10 @@
 #define MPTCPOPT_MP_FASTCLOSE	7
 
 /* MPTCP suboption lengths */
-#define TCPOLEN_MPTCP_MPC_SYN		12
-#define TCPOLEN_MPTCP_MPC_SYNACK	20
+#define TCPOLEN_MPTCP_MPC_SYN		4
+#define TCPOLEN_MPTCP_MPC_SYNACK	12
 #define TCPOLEN_MPTCP_MPC_ACK		20
+#define TCPOLEN_MPTCP_MPC_ACK_DATA	22
 #define TCPOLEN_MPTCP_DSS_BASE		4
 #define TCPOLEN_MPTCP_DSS_ACK32		4
 #define TCPOLEN_MPTCP_DSS_ACK64		8
@@ -103,6 +104,7 @@ struct mptcp_subflow_context {
 	u64	remote_key;
 	u64	idsn;
 	u64	map_seq;
+	u32	snd_isn;
 	u32	token;
 	u32	rel_write_seq;
 	u32	map_subflow_seq;
net/mptcp/subflow.c +12 -2
index 37b3ae10c042..96cc80f8d751 100644
@@ -81,7 +81,6 @@ static void subflow_init_req(struct request_sock *req,
 			subflow_req->version = listener->request_version;
 		else
 			subflow_req->version = rx_opt.mptcp.version;
-		subflow_req->remote_key = rx_opt.mptcp.sndr_key;
 		subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
 	}
 }
@@ -183,11 +182,22 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 					  bool *own_req)
 {
 	struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk);
+	struct mptcp_subflow_request_sock *subflow_req;
+	struct tcp_options_received opt_rx;
 	struct sock *child;
 
 	pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn);
 
-	/* if the sk is MP_CAPABLE, we already received the client key */
+	/* if the sk is MP_CAPABLE, we need to fetch the client key */
+	subflow_req = mptcp_subflow_rsk(req);
+	if (subflow_req->mp_capable) {
+		opt_rx.mptcp.mp_capable = 0;
+		mptcp_get_options(skb, &opt_rx);
+		if (!opt_rx.mptcp.mp_capable)
+			subflow_req->mp_capable = 0;
+		else
+			subflow_req->remote_key = opt_rx.mptcp.sndr_key;
+	}
 
 	child = listener->icsk_af_ops->syn_recv_sock(sk, skb, req, dst,
 						     req_unhash, own_req);
author
#16 lore raw

PATCH 3/3 mptcp: process MP_CAPABLE data option.

In reply to Christoph Paasch

This patch implement the handling of MP_CAPABLE + data option, as per RFC 6824 bis - MPTCP v1.

On the server side we can receive the remote key after that the connection is established. We need to explicitly track the 'missing remote key' status and avoid emtting mptcp ack till we get such info.

When a late/retransmitted/OoO pkt carrying MP_CAPABLE[+data] option is received, we have to propagate the mptcp seq number info to the msk socket. To avoid ABBA locking issue, explicitly check for that in recvmsg(), where we own msk and subflow sock locks.

The above also means that an established mp_capable subflow - still waiting for the remote key - can be 'downgraded' to plain TCP.

Such change could potentially block forever reader waiting for new data - as they hook to msk, while later wake-up after the downgrade will be on subflow only.

The above issue is not handled here, we likely have to get rid of msk->fallback to handle that cleanly.

Signed-off-by Christoph Paasch <cpaasch(a)apple.com>
---
 net/mptcp/options.c  | 48 +++++++++++++++++++++++++++++++++++---------
 net/mptcp/protocol.c | 20 ++++++++++++------
 net/mptcp/protocol.h |  8 ++++++--
 net/mptcp/subflow.c  | 37 +++++++++++++++++++++++++++++-----
 4 files changed, 91 insertions(+), 22 deletions(-)
net/mptcp/options.c +39 -9
index 299af8e5456d..0b80a24c34b4 100644
@@ -299,6 +299,7 @@ void mptcp_rcv_synsent(struct sock *sk)
 	pr_debug("subflow=%p", subflow);
 	if (subflow->request_mptcp && tp->rx_opt.mptcp.mp_capable) {
 		subflow->mp_capable = 1;
+		subflow->can_ack = 1;
 		subflow->remote_key = tp->rx_opt.mptcp.sndr_key;
 	}
 }
@@ -365,6 +366,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 					  unsigned int remaining,
 					  struct mptcp_out_options *opts)
 {
+	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	unsigned int dss_size = 0;
 	struct mptcp_ext *mpext;
 	struct mptcp_sock *msk;
@@ -383,6 +385,11 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 			opts->ext_copy = *mpext;
 	}
 
+	opts->ext_copy.use_ack = 0;
+	msk = mptcp_sk(subflow->conn);
+	if (!msk || !READ_ONCE(msk->can_ack))
+		return false;
+
 	ack_size = TCPOLEN_MPTCP_DSS_ACK64;
 
 	/* Add kind/length/subtype/flag overhead if mapping is not populated */
@@ -391,15 +398,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 
 	dss_size += ack_size;
 
-	msk = mptcp_sk(mptcp_subflow_ctx(sk)->conn);
-	if (msk) {
-		opts->ext_copy.data_ack = msk->ack_seq;
-	} else {
-		mptcp_crypto_key_sha(mptcp_subflow_ctx(sk)->remote_key,
-				     NULL, &opts->ext_copy.data_ack);
-		opts->ext_copy.data_ack++;
-	}
-
+	opts->ext_copy.data_ack = msk->ack_seq;
 	opts->ext_copy.ack64 = 1;
 	opts->ext_copy.use_ack = 1;
 
@@ -451,6 +450,35 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 	return false;
 }
 
+static bool check_fourth_ack(struct mptcp_subflow_context *subflow,
+			     struct sk_buff *skb,
+			     struct mptcp_options_received *mp_opt)
+{
+	/* here we can process OoO, in-window pkts, only in-sequence 4th ack
+	 * are relevant
+	 */
+	if (likely(subflow->fourth_ack ||
+		   TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1))
+		return true;
+
+	if (mp_opt->use_ack)
+		subflow->fourth_ack = 1;
+
+	if (subflow->can_ack)
+		return true;
+
+	/* if still waiting for remote/client key, we exepct an
+	 * MP_CAPABLE + data as first establish packet
+	 */
+	if (!mp_opt->mp_capable) {
+		subflow->mp_capable = 0;
+		return false;
+	}
+	subflow->remote_key = mp_opt->sndr_key;
+	subflow->can_ack = 1;
+	return true;
+}
+
 void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 			    struct tcp_options_received *opt_rx)
 {
@@ -462,6 +490,8 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 		return;
 
 	mp_opt = &opt_rx->mptcp;
+	if (!check_fourth_ack(subflow, skb, mp_opt))
+		return;
 
 	if (!mp_opt->dss)
 		return;
net/mptcp/protocol.c +14 -6
index 4b000f842d6b..1076f0887cd5 100644
@@ -347,6 +347,12 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 
 		lock_sock(ssk);
 		while (mptcp_subflow_data_available(ssk) && !done) {
+			if (unlikely(!msk->can_ack)) {
+				msk->remote_key = subflow->remote_key;
+				msk->ack_seq = subflow->map_seq;
+				msk->can_ack = true;
+			}
+
 			/* try to read as much data as available */
 			map_remaining = subflow->map_data_len -
 					mptcp_subflow_get_map_offset(subflow);
@@ -505,17 +511,20 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 		__mptcp_init_sock(new_mptcp_sock);
 
 		msk = mptcp_sk(new_mptcp_sock);
-		msk->remote_key = subflow->remote_key;
 		msk->local_key = subflow->local_key;
 		msk->token = subflow->token;
 
 		mptcp_token_update_accept(new_sock->sk, new_mptcp_sock);
 		msk->subflow = NULL;
 
-		mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
-		ack_seq++;
-		msk->ack_seq = ack_seq;
+		if (subflow->can_ack) {
+			msk->can_ack = true;
+			msk->remote_key = subflow->remote_key;
+			mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
+			ack_seq++;
+			msk->ack_seq = ack_seq;
+		}
 		newsk = new_mptcp_sock;
 		list_add(&subflow->node, &msk->conn_list);
 		bh_unlock_sock(new_mptcp_sock);
@@ -527,8 +536,6 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 		 * the receive path and process the pending ones
 		 */
 		lock_sock(new_sock->sk);
-		subflow->map_seq = ack_seq;
-		subflow->map_subflow_seq = 1;
 		subflow->rel_write_seq = 1;
 		subflow->tcp_sock = new_sock;
 		subflow->conn = new_mptcp_sock;
@@ -656,6 +663,7 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 		msk->write_seq = subflow->idsn + 1;
 		ack_seq++;
 		msk->ack_seq = ack_seq;
+		msk->can_ack = 1;
 		subflow->map_seq = ack_seq;
 		subflow->map_subflow_seq = 1;
 		subflow->rel_write_seq = 1;
net/mptcp/protocol.h +6 -2
index bdff743cf2b3..7630d8860319 100644
@@ -66,6 +66,7 @@ struct mptcp_sock {
 	u64		ack_seq;
 	u32		token;
 	unsigned long	flags;
+	bool		can_ack;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 };
@@ -80,9 +81,10 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
 
 struct mptcp_subflow_request_sock {
 	struct	tcp_request_sock sk;
-	u8	mp_capable : 1,
+	u16	mp_capable : 1,
 		mp_join : 1,
 		backup : 1,
+		remote_key_valid : 1,
 		version : 4;
 	u64	local_key;
 	u64	remote_key;
@@ -116,8 +118,10 @@ struct mptcp_subflow_context {
 		fourth_ack : 1,	    /* send initial DSS */
 		conn_finished : 1,
 		map_valid : 1,
+		mp_capable_map : 1,
 		data_avail : 1,
-		rx_eof : 1;
+		rx_eof : 1,
+		can_ack : 1;	    /* only after processing the remote a key */
 
 	struct	socket *tcp_sock;   /* underlying tcp_sock */
 	struct	sock *conn;	    /* parent mptcp_sock */
net/mptcp/subflow.c +32 -5
index 96cc80f8d751..255e3762b39c 100644
@@ -61,6 +61,7 @@ static void subflow_init_req(struct request_sock *req,
 	mptcp_get_options(skb, &rx_opt);
 
 	subflow_req->mp_capable = 0;
+	subflow_req->remote_key_valid = 0;
 
 #ifdef CONFIG_TCP_MD5SIG
 	/* no MPTCP if MD5SIG is enabled on this socket or we may run out of
@@ -188,17 +189,28 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 
 	pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn);
 
-	/* if the sk is MP_CAPABLE, we need to fetch the client key */
+	/* if the sk is MP_CAPABLE, we try to fetch the client key */
 	subflow_req = mptcp_subflow_rsk(req);
 	if (subflow_req->mp_capable) {
+		if (TCP_SKB_CB(skb)->seq != subflow_req->ssn_offset + 1) {
+			/* here we can receive and accept an in-window,
+			 * out-of-order pkt, which will not carry the MP_CAPABLE
+			 * opt even on mptcp enabled paths
+			 */
+			goto create_child;
+		}
+
 		opt_rx.mptcp.mp_capable = 0;
 		mptcp_get_options(skb, &opt_rx);
-		if (!opt_rx.mptcp.mp_capable)
-			subflow_req->mp_capable = 0;
-		else
+		if (opt_rx.mptcp.mp_capable) {
 			subflow_req->remote_key = opt_rx.mptcp.sndr_key;
+			subflow_req->remote_key_valid = 1;
+		} else {
+			subflow_req->mp_capable = 0;
+		}
 	}
 
+create_child:
 	child = listener->icsk_af_ops->syn_recv_sock(sk, skb, req, dst,
 						     req_unhash, own_req);
 
@@ -363,6 +375,7 @@ static enum mapping_status get_mapping_status(struct sock *ssk)
 	subflow->map_subflow_seq = mpext->subflow_seq;
 	subflow->map_data_len = mpext->data_len;
 	subflow->map_valid = 1;
+	subflow->mp_capable_map = mpext->mp_capable_map;
 	pr_debug("new map seq=%llu subflow_seq=%u data_len=%u",
 		 subflow->map_seq, subflow->map_subflow_seq,
 		 subflow->map_data_len);
@@ -414,6 +427,16 @@ static bool subflow_check_data_avail(struct sock *ssk)
 		if (WARN_ON_ONCE(!skb))
 			return false;
 
+		/* if msk lacks the remote key, this subflow must provide an
+		 * MP_CAPABLE-based mapping
+		 */
+		if (unlikely(!READ_ONCE(msk->ack_seq))) {
+			if (subflow->mp_capable_map)
+				break;
+			ssk->sk_err = EBADMSG;
+			goto fatal;
+		}
+
 		old_ack = READ_ONCE(msk->ack_seq);
 		ack_seq = mptcp_subflow_get_mapped_dsn(subflow);
 		pr_debug("msk ack_seq=%llx subflow ack_seq=%llx", old_ack,
@@ -651,8 +674,12 @@ static void subflow_ulp_clone(const struct request_sock *req,
 	new_ctx->tcp_sk_data_ready = old_ctx->tcp_sk_data_ready;
 
 	if (subflow_req->mp_capable) {
+		/* see comments in subflow_syn_recv_sock(), MPTCP connection
+		 * is fully establishged only after we receive the remote key
+		 */
 		new_ctx->mp_capable = 1;
-		new_ctx->fourth_ack = 1;
+		new_ctx->fourth_ack = subflow_req->remote_key_valid;
+		new_ctx->can_ack = subflow_req->remote_key_valid;
 		new_ctx->remote_key = subflow_req->remote_key;
 		new_ctx->local_key = subflow_req->local_key;
 		new_ctx->token = subflow_req->token;
Signature · 1 line
2.23.0
#17 lore raw

[MPTCP] Re: [PATCH 3/3] mptcp: process MP_CAPABLE data option.

Hi, uh, Christoph,

Quoted 93 lines · Christoph Paasch

This patch implement the handling of MP_CAPABLE + data option, as per RFC 6824 bis - MPTCP v1.

On the server side we can receive the remote key after that the connection is established. We need to explicitly track the 'missing remote key' status and avoid emtting mptcp ack till we get such info.

When a late/retransmitted/OoO pkt carrying MP_CAPABLE[+data] option is received, we have to propagate the mptcp seq number info to the msk socket. To avoid ABBA locking issue, explicitly check for that in recvmsg(), where we own msk and subflow sock locks.

The above also means that an established mp_capable subflow - still waiting for the remote key - can be 'downgraded' to plain TCP.

Such change could potentially block forever reader waiting for new data - as they hook to msk, while later wake-up after the downgrade will be on subflow only.

The above issue is not handled here, we likely have to get rid of msk->fallback to handle that cleanly.

Signed-off-by Christoph Paasch <cpaasch(a)apple.com>
---
 net/mptcp/options.c  | 48 +++++++++++++++++++++++++++++++++++---------
 net/mptcp/protocol.c | 20 ++++++++++++------
 net/mptcp/protocol.h |  8 ++++++--
 net/mptcp/subflow.c  | 37 +++++++++++++++++++++++++++++-----
 4 files changed, 91 insertions(+), 22 deletions(-)
net/mptcp/options.c +18 -9
index 299af8e5456d..0b80a24c34b4 100644
@@ -299,6 +299,7 @@ void mptcp_rcv_synsent(struct sock *sk)
 	pr_debug("subflow=%p", subflow);
 	if (subflow->request_mptcp && tp->rx_opt.mptcp.mp_capable) {
 		subflow->mp_capable = 1;
+		subflow->can_ack = 1;
 		subflow->remote_key = tp->rx_opt.mptcp.sndr_key;
 	}
 }
@@ -365,6 +366,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 					  unsigned int remaining,
 					  struct mptcp_out_options *opts)
 {
+	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	unsigned int dss_size = 0;
 	struct mptcp_ext *mpext;
 	struct mptcp_sock *msk;
@@ -383,6 +385,11 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 			opts->ext_copy = *mpext;
 	}
 
+	opts->ext_copy.use_ack = 0;
+	msk = mptcp_sk(subflow->conn);
+	if (!msk || !READ_ONCE(msk->can_ack))
+		return false;
+
 	ack_size = TCPOLEN_MPTCP_DSS_ACK64;
 
 	/* Add kind/length/subtype/flag overhead if mapping is not populated */
@@ -391,15 +398,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
 
 	dss_size += ack_size;
 
-	msk = mptcp_sk(mptcp_subflow_ctx(sk)->conn);
-	if (msk) {
-		opts->ext_copy.data_ack = msk->ack_seq;
-	} else {
-		mptcp_crypto_key_sha(mptcp_subflow_ctx(sk)->remote_key,
-				     NULL, &opts->ext_copy.data_ack);
-		opts->ext_copy.data_ack++;
-	}
-
+	opts->ext_copy.data_ack = msk->ack_seq;
 	opts->ext_copy.ack64 = 1;
 	opts->ext_copy.use_ack = 1;
 
@@ -451,6 +450,35 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 	return false;
 }
 
+static bool check_fourth_ack(struct mptcp_subflow_context *subflow,
+			     struct sk_buff *skb,
+			     struct mptcp_options_received *mp_opt)
+{
+	/* here we can process OoO, in-window pkts, only in-sequence 4th ack
+	 * are relevant
+	 */
+	if (likely(subflow->fourth_ack ||
+		   TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1))
+		return true;

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

Quoted 10 lines
net/mptcp/options.c +10 -0
+
+	if (mp_opt->use_ack)
+		subflow->fourth_ack = 1;
+
+	if (subflow->can_ack)
+		return true;
+
+	/* if still waiting for remote/client key, we exepct an
+	 * MP_CAPABLE + data as first establish packet
+	 */

Maybe this comment can clearly state that this is a fallback? "If the first established packet does not contain MP_CAPABLE + data then fallback to TCP".

Quoted 129 lines
net/mptcp/options.c +11 -0
+	if (!mp_opt->mp_capable) {
+		subflow->mp_capable = 0;
+		return false;
+	}
+	subflow->remote_key = mp_opt->sndr_key;
+	subflow->can_ack = 1;
+	return true;
+}
+
 void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 			    struct tcp_options_received *opt_rx)
 {
@@ -462,6 +490,8 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 		return;
 
 	mp_opt = &opt_rx->mptcp;
+	if (!check_fourth_ack(subflow, skb, mp_opt))
+		return;
 
 	if (!mp_opt->dss)
 		return;
net/mptcp/protocol.c +14 -6
index 4b000f842d6b..1076f0887cd5 100644
@@ -347,6 +347,12 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 
 		lock_sock(ssk);
 		while (mptcp_subflow_data_available(ssk) && !done) {
+			if (unlikely(!msk->can_ack)) {
+				msk->remote_key = subflow->remote_key;
+				msk->ack_seq = subflow->map_seq;
+				msk->can_ack = true;
+			}
+
 			/* try to read as much data as available */
 			map_remaining = subflow->map_data_len -
 					mptcp_subflow_get_map_offset(subflow);
@@ -505,17 +511,20 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 		__mptcp_init_sock(new_mptcp_sock);
 
 		msk = mptcp_sk(new_mptcp_sock);
-		msk->remote_key = subflow->remote_key;
 		msk->local_key = subflow->local_key;
 		msk->token = subflow->token;
 
 		mptcp_token_update_accept(new_sock->sk, new_mptcp_sock);
 		msk->subflow = NULL;
 
-		mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
-		ack_seq++;
-		msk->ack_seq = ack_seq;
+		if (subflow->can_ack) {
+			msk->can_ack = true;
+			msk->remote_key = subflow->remote_key;
+			mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq);
+			ack_seq++;
+			msk->ack_seq = ack_seq;
+		}
 		newsk = new_mptcp_sock;
 		list_add(&subflow->node, &msk->conn_list);
 		bh_unlock_sock(new_mptcp_sock);
@@ -527,8 +536,6 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 		 * the receive path and process the pending ones
 		 */
 		lock_sock(new_sock->sk);
-		subflow->map_seq = ack_seq;
-		subflow->map_subflow_seq = 1;
 		subflow->rel_write_seq = 1;
 		subflow->tcp_sock = new_sock;
 		subflow->conn = new_mptcp_sock;
@@ -656,6 +663,7 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 		msk->write_seq = subflow->idsn + 1;
 		ack_seq++;
 		msk->ack_seq = ack_seq;
+		msk->can_ack = 1;
 		subflow->map_seq = ack_seq;
 		subflow->map_subflow_seq = 1;
 		subflow->rel_write_seq = 1;
net/mptcp/protocol.h +6 -2
index bdff743cf2b3..7630d8860319 100644
@@ -66,6 +66,7 @@ struct mptcp_sock {
 	u64		ack_seq;
 	u32		token;
 	unsigned long	flags;
+	bool		can_ack;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 };
@@ -80,9 +81,10 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
 
 struct mptcp_subflow_request_sock {
 	struct	tcp_request_sock sk;
-	u8	mp_capable : 1,
+	u16	mp_capable : 1,
 		mp_join : 1,
 		backup : 1,
+		remote_key_valid : 1,
 		version : 4;
 	u64	local_key;
 	u64	remote_key;
@@ -116,8 +118,10 @@ struct mptcp_subflow_context {
 		fourth_ack : 1,	    /* send initial DSS */
 		conn_finished : 1,
 		map_valid : 1,
+		mp_capable_map : 1,
 		data_avail : 1,
-		rx_eof : 1;
+		rx_eof : 1,
+		can_ack : 1;	    /* only after processing the remote a key */
 
 	struct	socket *tcp_sock;   /* underlying tcp_sock */
 	struct	sock *conn;	    /* parent mptcp_sock */
net/mptcp/subflow.c +1 -0
index 96cc80f8d751..255e3762b39c 100644
@@ -61,6 +61,7 @@ static void subflow_init_req(struct request_sock *req,
 	mptcp_get_options(skb, &rx_opt);
 
 	subflow_req->mp_capable = 0;
+	subflow_req->remote_key_valid = 0;
 
 #ifdef CONFIG_TCP_MD5SIG
 	/* no MPTCP if MD5SIG is enabled on this socket or we may run out of

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

Quoted 5 lines
net/mptcp/subflow.c +1 -1
@@ -188,17 +189,28 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 
 	pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn);
 
-	/* if the sk is MP_CAPABLE, we need to fetch the client key */
+	/* if the sk is MP_CAPABLE, we try to fetch the client key */

Maybe this comment should be moved down to where the code fetching the remote key is now that more code has been added here.

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

Quoted 9 lines
net/mptcp/subflow.c +7 -0
 	subflow_req = mptcp_subflow_rsk(req);
 	if (subflow_req->mp_capable) {
+		if (TCP_SKB_CB(skb)->seq != subflow_req->ssn_offset + 1) {
+			/* here we can receive and accept an in-window,
+			 * out-of-order pkt, which will not carry the MP_CAPABLE
+			 * opt even on mptcp enabled paths
+			 */
+			goto create_child;
+		}

So this means we will create the child socket even without receiving the MP_CAPABLE ACK? Will there be side-effects of there are a lot of such packets?

Quoted 44 lines
net/mptcp/subflow.c +18 -3
+
 		opt_rx.mptcp.mp_capable = 0;
 		mptcp_get_options(skb, &opt_rx);
-		if (!opt_rx.mptcp.mp_capable)
-			subflow_req->mp_capable = 0;
-		else
+		if (opt_rx.mptcp.mp_capable) {
 			subflow_req->remote_key = opt_rx.mptcp.sndr_key;
+			subflow_req->remote_key_valid = 1;
+		} else {
+			subflow_req->mp_capable = 0;
+		}
 	}
 
+create_child:
 	child = listener->icsk_af_ops->syn_recv_sock(sk, skb, req, dst,
 						     req_unhash, own_req);
 
@@ -363,6 +375,7 @@ static enum mapping_status get_mapping_status(struct sock *ssk)
 	subflow->map_subflow_seq = mpext->subflow_seq;
 	subflow->map_data_len = mpext->data_len;
 	subflow->map_valid = 1;
+	subflow->mp_capable_map = mpext->mp_capable_map;
 	pr_debug("new map seq=%llu subflow_seq=%u data_len=%u",
 		 subflow->map_seq, subflow->map_subflow_seq,
 		 subflow->map_data_len);
@@ -414,6 +427,16 @@ static bool subflow_check_data_avail(struct sock *ssk)
 		if (WARN_ON_ONCE(!skb))
 			return false;
 
+		/* if msk lacks the remote key, this subflow must provide an
+		 * MP_CAPABLE-based mapping
+		 */
+		if (unlikely(!READ_ONCE(msk->ack_seq))) {
+			if (subflow->mp_capable_map)
+				break;
+			ssk->sk_err = EBADMSG;
+			goto fatal;
+		}
+
 		old_ack = READ_ONCE(msk->ack_seq);
 		ack_seq = mptcp_subflow_get_mapped_dsn(subflow);
 		pr_debug("msk ack_seq=%llx subflow ack_seq=%llx", old_ack,

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

Quoted 5 lines
net/mptcp/subflow.c +2 -0
@@ -651,8 +674,12 @@ static void subflow_ulp_clone(const struct request_sock *req,
 	new_ctx->tcp_sk_data_ready = old_ctx->tcp_sk_data_ready;
 
 	if (subflow_req->mp_capable) {
+		/* see comments in subflow_syn_recv_sock(), MPTCP connection
+		 * is fully establishged only after we receive the remote key

Detail: "established".

Peter.

Quoted 8 lines
net/mptcp/subflow.c +3 -1
+		 */
 		new_ctx->mp_capable = 1;
-		new_ctx->fourth_ack = 1;
+		new_ctx->fourth_ack = subflow_req->remote_key_valid;
+		new_ctx->can_ack = subflow_req->remote_key_valid;
 		new_ctx->remote_key = subflow_req->remote_key;
 		new_ctx->local_key = subflow_req->local_key;
 		new_ctx->token = subflow_req->token;
#18 lore raw

[MPTCP] Re: [PATCH 3/3] mptcp: process MP_CAPABLE data option.

Quoted 10 lines · Peter Krystad
(quoted diff) +0 -0
@@ -188,17 +189,28 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,

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

Quoted 5 lines
net/mptcp/subflow.c +1 -1
 	pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn);
 
-	/* if the sk is MP_CAPABLE, we need to fetch the client key */
+	/* if the sk is MP_CAPABLE, we try to fetch the client key */

Maybe this comment should be moved down to where the code fetching the remote key is now that more code has been added here.

Quoted 12 lines

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

Quoted 9 lines
net/mptcp/subflow.c +7 -0
 	subflow_req = mptcp_subflow_rsk(req);
 	if (subflow_req->mp_capable) {
+		if (TCP_SKB_CB(skb)->seq != subflow_req->ssn_offset + 1) {
+			/* here we can receive and accept an in-window,
+			 * out-of-order pkt, which will not carry the MP_CAPABLE
+			 * opt even on mptcp enabled paths
+			 */
+			goto create_child;
+		}

So this means we will create the child socket even without receiving the MP_CAPABLE ACK? Will there be side-effects of there are a lot of such packets?

The RFC says we must always create such sockets (if e.g. middle-boxes drop the 3rd MP_CAPABLE opt) so we can't escape this scenario.

The worst effect I can think of is:

- a new socket being created server side with mp_capable = 1,
- user-space calls recvmsg()/sendmsg() and blocks
- the 3rd ack is received without the MP_CAPABLE opt, and the socket fallback to plain tcp.
- will ever the kernel wake the user-space on the fallback socket?

AFAICS, with the last patches from Florian both recvmsg() and sendmsg() will be woken-up correctly - but than we have to explicitly check for fallback.

Anyhow I think we need some pktdrill to test this in a reliable way, I would not overlookup too much at it now.

Thanks,

Paolo