Skip to contentSkip to conversation

Correctly handle port field in ADD_ADDR option

PATCH In review Peter Krystad 3 participants 5 messages Mar 20, 2020

Subsystems (3)
lore
Share & tools
lore

Peter Krystad

author
#0 lore raw

cover Correctly handle port field in ADD_ADDR option

Existing code allows ADD_ADDR option lengths that include the port field, so we should correctly parse options with those lengths.

Peter Krystad (2):
mptcp: Parse optional port field of ADD_ADDR
mptcp: Include ADD_ADDR port value for path manager

 include/linux/tcp.h |  1 +
 net/mptcp/options.c | 11 +++++++++++
 2 files changed, 12 insertions(+)
Signature · 1 line
2.17.2
author
#1 lore raw

PATCH 1/2 mptcp: Parse optional port field of ADD_ADDR

Since we allow the option lengths that include the port field we should correctly parse the field if present.

squashto: Add ADD_ADDR handling

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 include/linux/tcp.h |  1 +
 net/mptcp/options.c | 11 +++++++++++
 2 files changed, 12 insertions(+)
include/linux/tcp.h +1 -0
index 41e5a0e3622f..1225db308957 100644
@@ -109,6 +109,7 @@ struct mptcp_options_received {
 #endif
 	};
 	u64	ahmac;
+	u16	port;
 };
 #endif
 
net/mptcp/options.c +11 -0
index 9b90bdc419ac..d9e0d82fd1b9 100644
@@ -205,16 +205,27 @@ void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr,
 		}
 
 		mp_opt->add_addr = 1;
+		mp_opt->port = 0;
 		mp_opt->addr_id = *ptr++;
 		pr_debug("ADD_ADDR: id=%d", mp_opt->addr_id);
 		if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
 			memcpy((u8 *)&mp_opt->addr.s_addr, (u8 *)ptr, 4);
 			ptr += 4;
+			if (opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT ||
+			    opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT) {
+				mp_opt->port = get_unaligned_be16(ptr);
+				ptr += 2;
+			}
 		}
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
 		else {
 			memcpy(mp_opt->addr6.s6_addr, (u8 *)ptr, 16);
 			ptr += 16;
+			if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT ||
+			    opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) {
+				mp_opt->port = get_unaligned_be16(ptr);
+				ptr += 2;
+			}
 		}
 #endif
 		if (!mp_opt->echo) {
Signature · 1 line
2.17.2
author
#2 lore raw

PATCH 2/2 mptcp: Include ADD_ADDR port value for path manager

In reply to Peter Krystad

Include the port value in the addr info passed to
mptcp_pm_add_addr_received().

squashto: Add path manager interface

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mptcp/options.c +1 -1
index d951f7d325a3..e8cb7d836cb7 100644
@@ -652,7 +652,7 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 	if (mp_opt->add_addr && add_addr_hmac_valid(msk, mp_opt)) {
 		struct mptcp_addr_info addr;
 
-		addr.port = 0;
+		addr.port = htons(mp_opt->port);
 		addr.id = mp_opt->addr_id;
 		if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
 			addr.family = AF_INET;
Signature · 1 line
2.17.2
#3 lore raw
In reply to Peter Krystad
Quoted 4 lines · Peter Krystad

Existing code allows ADD_ADDR option lengths that include the port field, so we should correctly parse options with those lengths.

Quoted 8 lines

Peter Krystad (2):
mptcp: Parse optional port field of ADD_ADDR
mptcp: Include ADD_ADDR port value for path manager

include/linux/tcp.h | 1 +
net/mptcp/options.c | 11 +++++++++++

2 files changed, 12 insertions(+)

Both patches look good to me - and they apply cleanly to the current export branch.

--
Mat Martineau
Intel

#4 lore raw

Hi Peter, Mat,

Quoted 11 lines · Mat Martineau
Quoted 8 lines · Peter Krystad

Existing code allows ADD_ADDR option lengths that include the port field, so we should correctly parse options with those lengths.

Peter Krystad (2):
 mptcp: Parse optional port field of ADD_ADDR
 mptcp: Include ADD_ADDR port value for path manager

Quoted 7 lines
Quoted 4 lines

include/linux/tcp.h |  1 +
net/mptcp/options.c | 11 +++++++++++

2 files changed, 12 insertions(+)

Both patches look good to me - and they apply cleanly to the current export branch.

Thank you for the patches and the reviews!

- 6b71141d6040: "squashed" patch 1/2 in "mptcp: Add ADD_ADDR handling"
- 49bd5a76f678..212bed34defa: result

- 3dc91a03e4e8: "squashed" patch 2/2 in "mptcp: Add path manager interface"
- 212bed34defa..19b9d67eec8a: result

Tests + export are in progress!

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