Skip to contentSkip to conversation

ADD_ADDR: ports support

PATCH Superseded Geliang Tang 2 participants 22 messages Oct 31, 2020 – Nov 5, 2020

Subsystems (3)

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Geliang Tang

author
#0 lore raw

v2 cover ADD_ADDR: ports support

v2:
- change mptcp_out_options's port field in CPU bype order.
- keep mptcp_options_received's port field in CPU bype order.
- add two new patches to simplify ADD_ADDR suboption writing.
- update mptcp_add_addr_len helper use adding up size.
- add more commit messages.

v1:
This series is the first version of ADD_ADDR ports support. I have solved the listener problem which I mentioned at the meeting on 15th of October by adding a new listening socket from the userspace (see patch 8). Up to now this patchset works well.

Geliang Tang (10):
mptcp: unify ADD_ADDR and echo suboptions writing
mptcp: unify ADD_ADDR and ADD_ADDR6 suboptions writing
mptcp: add port support for ADD_ADDR suboption writing
mptcp: use adding up size when get ADD_ADDR length
mptcp: add the outgoing ADD_ADDR port support
mptcp: send out dedicated packet for ADD_ADDR using port
mptcp: add port parameter for mptcp_pm_announce_addr
mptcp: deal with MPTCP_PM_ADDR_ATTR_PORT in PM netlink
selftests: mptcp: add port argument for pm_nl_ctl
selftests: mptcp: add testcases for ADD_ADDR with port

 include/net/mptcp.h                           |  1 +
 net/mptcp/options.c                           | 89 +++++++++++--------
 net/mptcp/pm.c                                | 14 +--
 net/mptcp/pm_netlink.c                        | 28 ++++--
 net/mptcp/protocol.h                          | 36 +++++---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 26 +++++-
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 18 ++++
 7 files changed, 153 insertions(+), 59 deletions(-)
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH v2 1/10 mptcp: unify ADD_ADDR and echo suboptions writing

There are two differences between ADD_ADDR suboption and ADD_ADDR echo
suboption: The length of the former is 8 octets longer than the length of the latter. The former's echo-flag is 0, and latter's echo-flag is 1.

This patch added two local variables, len and echo, to unify ADD_ADDR and ADD_ADDR echo suboptions writing.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/options.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)
net/mptcp/options.c +19 -18
index 248e3930c0cb..0fe3f224b00a 100644
@@ -1067,15 +1067,16 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 
 mp_capable_done:
 	if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
-		if (opts->ahmac)
-			*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
-					      TCPOLEN_MPTCP_ADD_ADDR, 0,
-					      opts->addr_id);
-		else
-			*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
-					      TCPOLEN_MPTCP_ADD_ADDR_BASE,
-					      MPTCP_ADDR_ECHO,
-					      opts->addr_id);
+		u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
+		u8 echo = MPTCP_ADDR_ECHO;
+
+		if (opts->ahmac) {
+			len += sizeof(opts->ahmac);
+			echo = 0;
+		}
+
+		*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
+				      len, echo, opts->addr_id);
 		memcpy((u8 *)ptr, (u8 *)&opts->addr.s_addr, 4);
 		ptr += 1;
 		if (opts->ahmac) {
@@ -1086,15 +1087,15 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
 	if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) {
-		if (opts->ahmac)
-			*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
-					      TCPOLEN_MPTCP_ADD_ADDR6, 0,
-					      opts->addr_id);
-		else
-			*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
-					      TCPOLEN_MPTCP_ADD_ADDR6_BASE,
-					      MPTCP_ADDR_ECHO,
-					      opts->addr_id);
+		u8 len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
+		u8 echo = MPTCP_ADDR_ECHO;
+
+		if (opts->ahmac) {
+			len += sizeof(opts->ahmac);
+			echo = 0;
+		}
+		*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
+				      len, echo, opts->addr_id);
 		memcpy((u8 *)ptr, opts->addr6.s6_addr, 16);
 		ptr += 4;
 		if (opts->ahmac) {
Signature · 1 line
2.26.2
author
#2 lore raw

PATCH v2 2/10 mptcp: unify ADD_ADDR and ADD_ADDR6 suboptions writing

The length of ADD_ADDR6 is 12 octets longer than ADD_ADDR. That's the only difference between them.

This patch dropped the duplicate code between ADD_ADDR and ADD_ADDR6 suboptions writing, and unify them into one.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/options.c | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
net/mptcp/options.c +12 -20
index 0fe3f224b00a..f69d6f3d6605 100644
@@ -1066,10 +1066,14 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 	}
 
 mp_capable_done:
-	if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
+	if ((OPTION_MPTCP_ADD_ADDR | OPTION_MPTCP_ADD_ADDR6) &
+	    opts->suboptions) {
 		u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
 		u8 echo = MPTCP_ADDR_ECHO;
 
+		if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions)
+			len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
+
 		if (opts->ahmac) {
 			len += sizeof(opts->ahmac);
 			echo = 0;
@@ -1077,33 +1081,21 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 
 		*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
 				      len, echo, opts->addr_id);
-		memcpy((u8 *)ptr, (u8 *)&opts->addr.s_addr, 4);
-		ptr += 1;
-		if (opts->ahmac) {
-			put_unaligned_be64(opts->ahmac, ptr);
-			ptr += 2;
+		if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
+			memcpy((u8 *)ptr, (u8 *)&opts->addr.s_addr, 4);
+			ptr += 1;
 		}
-	}
-
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-	if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) {
-		u8 len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
-		u8 echo = MPTCP_ADDR_ECHO;
-
-		if (opts->ahmac) {
-			len += sizeof(opts->ahmac);
-			echo = 0;
+		else if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) {
+			memcpy((u8 *)ptr, opts->addr6.s6_addr, 16);
+			ptr += 4;
 		}
-		*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
-				      len, echo, opts->addr_id);
-		memcpy((u8 *)ptr, opts->addr6.s6_addr, 16);
-		ptr += 4;
+#endif
 		if (opts->ahmac) {
 			put_unaligned_be64(opts->ahmac, ptr);
 			ptr += 2;
 		}
 	}
-#endif
 
 	if (OPTION_MPTCP_RM_ADDR & opts->suboptions) {
 		*ptr++ = mptcp_option(MPTCPOPT_RM_ADDR,
Signature · 1 line
2.26.2
author
#3 lore raw

PATCH v2 3/10 mptcp: add port support for ADD_ADDR suboption writing

In rfc8684, the length of ADD_ADDR suboption with IPv4 address and port is 18 octets, but mptcp_write_options is 32-bit aligned, so we need to pad it to 20 octets.

This patch added a new field 'port' in mptcp_out_options. When this field is set with a port number, we need to add up 4 octets for the ADD_ADDR suboption, and put the port number into the suboption.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 include/net/mptcp.h  |  1 +
 net/mptcp/options.c  | 27 ++++++++++++++++++++++++---
 net/mptcp/protocol.h | 10 +++++-----
 3 files changed, 30 insertions(+), 8 deletions(-)
include/net/mptcp.h +1 -0
index b6cf07143a8a..5694370be3d4 100644
@@ -46,6 +46,7 @@ struct mptcp_out_options {
 #endif
 	};
 	u8 addr_id;
+	u16 port;
 	u64 ahmac;
 	u8 rm_id;
 	u8 join_id;
net/mptcp/options.c +24 -3
index f69d6f3d6605..79dbdf499087 100644
@@ -1074,6 +1074,9 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 		if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions)
 			len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
 
+		if (opts->port)
+			len += TCPOLEN_MPTCP_PORT_LEN;
+
 		if (opts->ahmac) {
 			len += sizeof(opts->ahmac);
 			echo = 0;
@@ -1091,9 +1094,27 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 			ptr += 4;
 		}
 #endif
-		if (opts->ahmac) {
-			put_unaligned_be64(opts->ahmac, ptr);
-			ptr += 2;
+
+		if (!opts->port) {
+			if (opts->ahmac) {
+				put_unaligned_be64(opts->ahmac, ptr);
+				ptr += 2;
+			}
+		} else {
+			if (opts->ahmac) {
+				put_unaligned_be32(opts->port << 16 |
+						   opts->ahmac >> 48, ptr);
+				ptr += 1;
+				put_unaligned_be64(opts->ahmac << 16 |
+						   TCPOPT_NOP << 8 |
+						   TCPOPT_NOP, ptr);
+				ptr += 2;
+			} else {
+				put_unaligned_be32(opts->port << 16 |
+						   TCPOPT_NOP << 8 |
+						   TCPOPT_NOP, ptr);
+				ptr += 1;
+			}
 		}
 	}
 
net/mptcp/protocol.h +5 -5
index d29c6a4749eb..f303c46bcc29 100644
@@ -49,14 +49,14 @@
 #define TCPOLEN_MPTCP_DSS_MAP64		14
 #define TCPOLEN_MPTCP_DSS_CHECKSUM	2
 #define TCPOLEN_MPTCP_ADD_ADDR		16
-#define TCPOLEN_MPTCP_ADD_ADDR_PORT	18
+#define TCPOLEN_MPTCP_ADD_ADDR_PORT	20
 #define TCPOLEN_MPTCP_ADD_ADDR_BASE	8
-#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT	10
+#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT	12
 #define TCPOLEN_MPTCP_ADD_ADDR6		28
-#define TCPOLEN_MPTCP_ADD_ADDR6_PORT	30
+#define TCPOLEN_MPTCP_ADD_ADDR6_PORT	32
 #define TCPOLEN_MPTCP_ADD_ADDR6_BASE	20
-#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT	22
-#define TCPOLEN_MPTCP_PORT_LEN		2
+#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT	24
+#define TCPOLEN_MPTCP_PORT_LEN		4
 #define TCPOLEN_MPTCP_RM_ADDR_BASE	4
 
 /* MPTCP MP_JOIN flags */
Signature · 1 line
2.26.2
author
#4 lore raw

PATCH v2 4/10 mptcp: use adding up size when get ADD_ADDR length

This patch uses adding up size to get the ADD_ADDR suboption length rather than returning the ADD_ADDR size constants.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/protocol.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
net/mptcp/protocol.h +8 -4
index f303c46bcc29..ad3fdec98fdc 100644
@@ -546,10 +546,14 @@ static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
 
 static inline unsigned int mptcp_add_addr_len(int family, bool echo)
 {
-	if (family == AF_INET)
-		return echo ? TCPOLEN_MPTCP_ADD_ADDR_BASE
-			    : TCPOLEN_MPTCP_ADD_ADDR;
-	return echo ? TCPOLEN_MPTCP_ADD_ADDR6_BASE : TCPOLEN_MPTCP_ADD_ADDR6;
+	u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
+
+	if (family == AF_INET6)
+		len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
+	if (!echo)
+		len += 8; // Truncated HMAC
+
+	return len;
 }
 
 bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
Signature · 1 line
2.26.2
author
#5 lore raw

PATCH v2 5/10 mptcp: add the outgoing ADD_ADDR port support

This patch added a new add_addr_signal type named MPTCP_ADD_ADDR_PORT, to identify it is an address with port to be added.

It also added a new parameter 'port' for both mptcp_add_addr_len and mptcp_pm_add_addr_signal.

In mptcp_established_options_add_addr, we check whether the announced address is added with port. If it is, we put this port number to mptcp_out_options's port field.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/options.c  | 10 +++++++---
 net/mptcp/pm.c       |  5 +++--
 net/mptcp/protocol.h | 12 ++++++++++--
 3 files changed, 20 insertions(+), 7 deletions(-)
net/mptcp/options.c +7 -3
index 79dbdf499087..12535551c06f 100644
@@ -586,6 +586,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 	unsigned int opt_size = *size;
 	struct mptcp_addr_info saddr;
 	bool echo;
+	bool port;
 	int len;
 
 	if (mptcp_pm_should_add_signal_ipv6(msk) &&
@@ -597,10 +598,10 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 	}
 
 	if (!mptcp_pm_should_add_signal(msk) ||
-	    !(mptcp_pm_add_addr_signal(msk, remaining, &saddr, &echo)))
+	    !(mptcp_pm_add_addr_signal(msk, remaining, &saddr, &echo, &port)))
 		return false;
 
-	len = mptcp_add_addr_len(saddr.family, echo);
+	len = mptcp_add_addr_len(saddr.family, echo, port);
 	if (remaining < len)
 		return false;
 
@@ -608,6 +609,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 	if (drop_other_suboptions)
 		*size -= opt_size;
 	opts->addr_id = saddr.id;
+	if (port)
+		opts->port = ntohs(saddr.port);
 	if (saddr.family == AF_INET) {
 		opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
 		opts->addr = saddr.addr;
@@ -630,7 +633,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 		}
 	}
 #endif
-	pr_debug("addr_id=%d, ahmac=%llu, echo=%d", opts->addr_id, opts->ahmac, echo);
+	pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d",
+		 opts->addr_id, opts->ahmac, echo, opts->port);
 
 	return true;
 }
net/mptcp/pm.c +3 -2
index 75c5040e8d5d..6d4be02681fa 100644
@@ -188,7 +188,7 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id)
 /* path manager helpers */
 
 bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			      struct mptcp_addr_info *saddr, bool *echo)
+			      struct mptcp_addr_info *saddr, bool *echo, bool *port)
 {
 	int ret = false;
 
@@ -199,8 +199,9 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 		goto out_unlock;
 
 	*echo = mptcp_pm_should_add_signal_echo(msk);
+	*port = mptcp_pm_should_add_signal_port(msk);
 
-	if (remaining < mptcp_add_addr_len(msk->pm.local.family, *echo))
+	if (remaining < mptcp_add_addr_len(msk->pm.local.family, *echo, *port))
 		goto out_unlock;
 
 	*saddr = msk->pm.local;
net/mptcp/protocol.h +10 -2
index ad3fdec98fdc..be83a06b6881 100644
@@ -171,6 +171,7 @@ enum mptcp_add_addr_status {
 	MPTCP_ADD_ADDR_SIGNAL,
 	MPTCP_ADD_ADDR_ECHO,
 	MPTCP_ADD_ADDR_IPV6,
+	MPTCP_ADD_ADDR_PORT,
 };
 
 struct mptcp_pm_data {
@@ -539,12 +540,17 @@ static inline bool mptcp_pm_should_add_signal_ipv6(struct mptcp_sock *msk)
 	return READ_ONCE(msk->pm.add_addr_signal) & BIT(MPTCP_ADD_ADDR_IPV6);
 }
 
+static inline bool mptcp_pm_should_add_signal_port(struct mptcp_sock *msk)
+{
+	return READ_ONCE(msk->pm.add_addr_signal) & BIT(MPTCP_ADD_ADDR_PORT);
+}
+
 static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
 {
 	return READ_ONCE(msk->pm.rm_addr_signal);
 }
 
-static inline unsigned int mptcp_add_addr_len(int family, bool echo)
+static inline unsigned int mptcp_add_addr_len(int family, bool echo, bool port)
 {
 	u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
 
@@ -552,12 +558,14 @@ static inline unsigned int mptcp_add_addr_len(int family, bool echo)
 		len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
 	if (!echo)
 		len += 8; // Truncated HMAC
+	if (port)
+		len += TCPOLEN_MPTCP_PORT_LEN;
 
 	return len;
 }
 
 bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			      struct mptcp_addr_info *saddr, bool *echo);
+			      struct mptcp_addr_info *saddr, bool *echo, bool *port);
 bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 			     u8 *rm_id);
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
Signature · 1 line
2.26.2
author
#6 lore raw

PATCH v2 6/10 mptcp: send out dedicated packet for ADD_ADDR using port

The process is similar to that of the ADD_ADDR IPv6, this patch also sent out a pure ack for the ADD_ADDR using port.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/options.c    |  3 ++-
 net/mptcp/pm.c         |  3 ++-
 net/mptcp/pm_netlink.c | 14 +++++++++++---
 3 files changed, 15 insertions(+), 5 deletions(-)
net/mptcp/options.c +2 -1
index 12535551c06f..1d7e812087af 100644
@@ -589,7 +589,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 	bool port;
 	int len;
 
-	if (mptcp_pm_should_add_signal_ipv6(msk) &&
+	if ((mptcp_pm_should_add_signal_ipv6(msk) ||
+	     mptcp_pm_should_add_signal_port(msk)) &&
 	    skb && skb_is_tcp_pure_ack(skb)) {
 		pr_debug("drop other suboptions");
 		opts->suboptions = 0;
net/mptcp/pm.c +2 -1
index 6d4be02681fa..0c456747893e 100644
@@ -167,7 +167,8 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
 
 void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk)
 {
-	if (!mptcp_pm_should_add_signal_ipv6(msk))
+	if (!mptcp_pm_should_add_signal_ipv6(msk) &&
+	    !mptcp_pm_should_add_signal_port(msk))
 		return;
 
 	mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
net/mptcp/pm_netlink.c +11 -3
index 6180a8b39a3f..72d150e45067 100644
@@ -408,7 +408,8 @@ void mptcp_pm_nl_add_addr_send_ack(struct mptcp_sock *msk)
 {
 	struct mptcp_subflow_context *subflow;
 
-	if (!mptcp_pm_should_add_signal_ipv6(msk))
+	if (!mptcp_pm_should_add_signal_ipv6(msk) &&
+	    !mptcp_pm_should_add_signal_port(msk))
 		return;
 
 	__mptcp_flush_join_list(msk);
@@ -418,14 +419,21 @@ void mptcp_pm_nl_add_addr_send_ack(struct mptcp_sock *msk)
 		u8 add_addr;
 
 		spin_unlock_bh(&msk->pm.lock);
-		pr_debug("send ack for add_addr6");
+		if (mptcp_pm_should_add_signal_ipv6(msk))
+			pr_debug("send ack for add_addr6");
+		if (mptcp_pm_should_add_signal_port(msk))
+			pr_debug("send ack for add_addr_port");
+
 		lock_sock(ssk);
 		tcp_send_ack(ssk);
 		release_sock(ssk);
 		spin_lock_bh(&msk->pm.lock);
 
 		add_addr = READ_ONCE(msk->pm.add_addr_signal);
-		add_addr &= ~BIT(MPTCP_ADD_ADDR_IPV6);
+		if (mptcp_pm_should_add_signal_ipv6(msk))
+			add_addr &= ~BIT(MPTCP_ADD_ADDR_IPV6);
+		if (mptcp_pm_should_add_signal_port(msk))
+			add_addr &= ~BIT(MPTCP_ADD_ADDR_PORT);
 		WRITE_ONCE(msk->pm.add_addr_signal, add_addr);
 	}
 }
Signature · 1 line
2.26.2
author
#7 lore raw

PATCH v2 7/10 mptcp: add port parameter for mptcp_pm_announce_addr

This patch added a new parameter 'port' for mptcp_pm_announce_addr. If this parameter is true, we set the MPTCP_ADD_ADDR_PORT bit of the add_addr_signal. That means the announced address is added with a port number.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm.c         | 6 ++++--
 net/mptcp/pm_netlink.c | 9 ++++++---
 net/mptcp/protocol.h   | 2 +-
 3 files changed, 11 insertions(+), 6 deletions(-)
net/mptcp/pm.c +4 -2
index 0c456747893e..e63e14f4cf2a 100644
@@ -14,7 +14,7 @@
 
 int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 			   const struct mptcp_addr_info *addr,
-			   bool echo)
+			   bool echo, bool port)
 {
 	u8 add_addr = READ_ONCE(msk->pm.add_addr_signal);
 
@@ -26,6 +26,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 		add_addr |= BIT(MPTCP_ADD_ADDR_ECHO);
 	if (addr->family == AF_INET6)
 		add_addr |= BIT(MPTCP_ADD_ADDR_IPV6);
+	if (port)
+		add_addr |= BIT(MPTCP_ADD_ADDR_PORT);
 	WRITE_ONCE(msk->pm.add_addr_signal, add_addr);
 	return 0;
 }
@@ -156,7 +158,7 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
 	spin_lock_bh(&pm->lock);
 
 	if (!READ_ONCE(pm->accept_addr)) {
-		mptcp_pm_announce_addr(msk, addr, true);
+		mptcp_pm_announce_addr(msk, addr, true, addr->port);
 		mptcp_pm_add_addr_send_ack(msk);
 	} else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) {
 		pm->remote = *addr;
net/mptcp/pm_netlink.c +6 -3
index 72d150e45067..ab0e68426c9e 100644
@@ -228,7 +228,7 @@ static void mptcp_pm_add_timer(struct timer_list *timer)
 
 	if (!mptcp_pm_should_add_signal(msk)) {
 		pr_debug("retransmit ADD_ADDR id=%d", entry->addr.id);
-		mptcp_pm_announce_addr(msk, &entry->addr, false);
+		mptcp_pm_announce_addr(msk, &entry->addr, false, entry->addr.port);
 		mptcp_pm_add_addr_send_ack(msk);
 		entry->retrans_times++;
 	}
@@ -329,7 +329,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		if (local) {
 			if (mptcp_pm_alloc_anno_list(msk, local)) {
 				msk->pm.add_addr_signaled++;
-				mptcp_pm_announce_addr(msk, &local->addr, false);
+				mptcp_pm_announce_addr(msk, &local->addr, false, local->addr.port);
 				mptcp_pm_nl_add_addr_send_ack(msk);
 			}
 		} else {
@@ -377,6 +377,7 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
 	struct sock *sk = (struct sock *)msk;
 	struct mptcp_addr_info remote;
 	struct mptcp_addr_info local;
+	bool use_port = false;
 
 	pr_debug("accepted %d:%d remote family %d",
 		 msk->pm.add_addr_accepted, msk->pm.add_addr_accept_max,
@@ -393,6 +394,8 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
 	remote = msk->pm.remote;
 	if (!remote.port)
 		remote.port = sk->sk_dport;
+	else
+		use_port = true;
 	memset(&local, 0, sizeof(local));
 	local.family = remote.family;
 
@@ -400,7 +403,7 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
 	__mptcp_subflow_connect((struct sock *)msk, &local, &remote);
 	spin_lock_bh(&msk->pm.lock);
 
-	mptcp_pm_announce_addr(msk, &remote, true);
+	mptcp_pm_announce_addr(msk, &remote, true, use_port);
 	mptcp_pm_nl_add_addr_send_ack(msk);
 }
 
net/mptcp/protocol.h +1 -1
index be83a06b6881..56bdae38377b 100644
@@ -521,7 +521,7 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,
 
 int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 			   const struct mptcp_addr_info *addr,
-			   bool echo);
+			   bool echo, bool port);
 int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id);
 int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id);
 
Signature · 1 line
2.26.2
author
#8 lore raw

PATCH v2 8/10 mptcp: deal with MPTCP_PM_ADDR_ATTR_PORT in PM netlink

This patch added the MPTCP_PM_ADDR_ATTR_PORT filling and parsing in PM netlink.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm_netlink.c | 5 +++++
 1 file changed, 5 insertions(+)
net/mptcp/pm_netlink.c +5 -0
index ab0e68426c9e..069447424ddb 100644
@@ -725,6 +725,9 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
 	if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
 		entry->addr.flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
 
+	if (tb[MPTCP_PM_ADDR_ATTR_PORT])
+		entry->addr.port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
+
 	return 0;
 }
 
@@ -911,6 +914,8 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb,
 
 	if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_FAMILY, addr->family))
 		goto nla_put_failure;
+	if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_PORT, ntohs(addr->port)))
+		goto nla_put_failure;
 	if (nla_put_u8(skb, MPTCP_PM_ADDR_ATTR_ID, addr->id))
 		goto nla_put_failure;
 	if (nla_put_u32(skb, MPTCP_PM_ADDR_ATTR_FLAGS, entry->addr.flags))
Signature · 1 line
2.26.2
author
#9 lore raw

PATCH v2 9/10 selftests: mptcp: add port argument for pm_nl_ctl

This patch added a new argument for pm_nl_ctl tool. We can use it like this:

# pm_nl_ctl add 10.0.2.1 flags signal port 10100
# pm_nl_ctl dump
id 1 flags signal 10.0.2.1 10100
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
tools/testing/selftests/net/mptcp/pm_nl_ctl.c +18 -0
index b24a2f17d415..9e6f30d34d9a 100644
@@ -178,6 +178,7 @@ int add_addr(int fd, int pm_family, int argc, char *argv[])
 	struct nlmsghdr *nh;
 	u_int16_t family;
 	u_int32_t flags;
+	u_int16_t port;
 	int nest_start;
 	u_int8_t id;
 	int off = 0;
@@ -271,6 +272,16 @@ int add_addr(int fd, int pm_family, int argc, char *argv[])
 			rta->rta_len = RTA_LENGTH(4);
 			memcpy(RTA_DATA(rta), &ifindex, 4);
 			off += NLMSG_ALIGN(rta->rta_len);
+		} else if (!strcmp(argv[arg], "port")) {
+			if (++arg >= argc)
+				error(1, 0, " missing port value");
+
+			port = atoi(argv[arg]);
+			rta = (void *)(data + off);
+			rta->rta_type = MPTCP_PM_ADDR_ATTR_PORT;
+			rta->rta_len = RTA_LENGTH(2);
+			memcpy(RTA_DATA(rta), &port, 2);
+			off += NLMSG_ALIGN(rta->rta_len);
 		} else
 			error(1, 0, "unknown keyword %s", argv[arg]);
 	}
@@ -323,6 +334,7 @@ int del_addr(int fd, int pm_family, int argc, char *argv[])
 static void print_addr(struct rtattr *attrs, int len)
 {
 	uint16_t family = 0;
+	uint16_t port = 0;
 	char str[1024];
 	uint32_t flags;
 	uint8_t id;
@@ -330,12 +342,16 @@ static void print_addr(struct rtattr *attrs, int len)
 	while (RTA_OK(attrs, len)) {
 		if (attrs->rta_type == MPTCP_PM_ADDR_ATTR_FAMILY)
 			memcpy(&family, RTA_DATA(attrs), 2);
+		if (attrs->rta_type == MPTCP_PM_ADDR_ATTR_PORT)
+			memcpy(&port, RTA_DATA(attrs), 2);
 		if (attrs->rta_type == MPTCP_PM_ADDR_ATTR_ADDR4) {
 			if (family != AF_INET)
 				error(1, errno, "wrong IP (v4) for family %d",
 				      family);
 			inet_ntop(AF_INET, RTA_DATA(attrs), str, sizeof(str));
 			printf("%s", str);
+			if (port)
+				printf(" %d", port);
 		}
 		if (attrs->rta_type == MPTCP_PM_ADDR_ATTR_ADDR6) {
 			if (family != AF_INET6)
@@ -343,6 +359,8 @@ static void print_addr(struct rtattr *attrs, int len)
 				      family);
 			inet_ntop(AF_INET6, RTA_DATA(attrs), str, sizeof(str));
 			printf("%s", str);
+			if (port)
+				printf(" %d", port);
 		}
 		if (attrs->rta_type == MPTCP_PM_ADDR_ATTR_ID) {
 			memcpy(&id, RTA_DATA(attrs), 1);
Signature · 1 line
2.26.2
author
#10 lore raw

PATCH v2 10/10 selftests: mptcp: add testcases for ADD_ADDR with port

This patch added a new argument with_port for run_tests and do_transfer, and added the testcases for ADD_ADDR with port.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 26 ++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +25 -1
index 0eae628d1ffd..826d662a9bf8 100755
@@ -212,6 +212,7 @@ do_transfer()
 	rm_nr_ns1="$7"
 	rm_nr_ns2="$8"
 	speed="$9"
+	with_port="${10}"
 
 	port=$((10000+$TEST_COUNT))
 	TEST_COUNT=$((TEST_COUNT+1))
@@ -253,6 +254,11 @@ do_transfer()
 		-s ${srv_proto} ${local_addr} < "$sin" > "$sout" &
 	spid=$!
 
+	if [ "$with_port" -gt 0 ];then
+		ip netns exec ${listener_ns} $mptcp_connect -t $timeout -l -p $with_port \
+			-s ${srv_proto} ${local_addr} < "$sin" > "$sout" &
+	fi
+
 	sleep 1
 
 	if [ "$test_link_fail" -eq 0 ];then
@@ -348,6 +354,7 @@ run_tests()
 	rm_nr_ns1="${5:-0}"
 	rm_nr_ns2="${6:-0}"
 	speed="${7:-fast}"
+	with_port="${8:-0}"
 	lret=0
 	oldin=""
 
@@ -362,7 +369,7 @@ run_tests()
 	fi
 
 	do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} \
-		${test_linkfail} ${rm_nr_ns1} ${rm_nr_ns2} ${speed}
+		${test_linkfail} ${rm_nr_ns1} ${rm_nr_ns2} ${speed} ${with_port}
 	lret=$?
 
 	if [ "$test_linkfail" -eq 1 ];then
@@ -717,6 +724,23 @@ chk_join_nr "remove subflow and signal IPv6" 2 2 2
 chk_add_nr 1 1
 chk_rm_nr 1 1
 
+# subflow with port
+reset
+ip netns exec $ns1 ./pm_nl_ctl limits 0 1
+ip netns exec $ns2 ./pm_nl_ctl limits 0 1
+ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow port 10100
+run_tests $ns1 $ns2 10.0.1.1
+chk_join_nr "single subflow with port" 1 1 1
+
+# signal address with port
+reset
+ip netns exec $ns1 ./pm_nl_ctl limits 0 1
+ip netns exec $ns2 ./pm_nl_ctl limits 1 1
+ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
+run_tests $ns1 $ns2 10.0.1.1 0 0 0 fast 10100
+chk_join_nr "signal address with port" 1 1 1
+chk_add_nr 1 1
+
 # single subflow, syncookies
 reset_with_cookies
 ip netns exec $ns1 ./pm_nl_ctl limits 0 1
Signature · 1 line
2.26.2
#11 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 10/10] selftests: mptcp: add testcases for ADD_ADDR with port

Quoted 13 lines · Geliang Tang

This patch added a new argument with_port for run_tests and do_transfer, and added the testcases for ADD_ADDR with port.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
  .../testing/selftests/net/mptcp/mptcp_join.sh | 26 ++++++++++++++++++-
  1 file changed, 25 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +0 -0
index 0eae628d1ffd..826d662a9bf8 100755

tools/testing/selftests/net/mptcp/mptcp_join.sh do_transfer() · line 259

Quoted 6 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +3 -0
@@ -253,6 +254,11 @@ do_transfer()
  		-s ${srv_proto} ${local_addr} < "$sin" > "$sout" &
  	spid=$!
 
+	if [ "$with_port" -gt 0 ];then
+		ip netns exec ${listener_ns} $mptcp_connect -t $timeout -l -p $with_port \
+			-s ${srv_proto} ${local_addr} < "$sin" > "$sout" &

Sorry, I am not sure to understand: why do you establish a new connection if the port is set? Just to make sure we can also initiate a new connection directly to this port (I am not sure we want this)?

Quoted 5 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +2 -0
+	fi
+
  	sleep 1
 
  	if [ "$test_link_fail" -eq 0 ];then

(...)

tools/testing/selftests/net/mptcp/mptcp_join.sh chk_join_nr "remove subflow and signal IPv6" 2 2 2 · line 733

Quoted 11 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +7 -0
@@ -717,6 +724,23 @@ chk_join_nr "remove subflow and signal IPv6" 2 2 2
  chk_add_nr 1 1
  chk_rm_nr 1 1
 
+# subflow with port
+reset
+ip netns exec $ns1 ./pm_nl_ctl limits 0 1
+ip netns exec $ns2 ./pm_nl_ctl limits 0 1
+ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow port 10100
+run_tests $ns1 $ns2 10.0.1.1
+chk_join_nr "single subflow with port" 1 1 1

Should we also check that the second subflow was established on the correct port?

tools/testing/selftests/net/mptcp/mptcp_join.sh chk_join_nr "remove subflow and signal IPv6" 2 2 2 · line 742

Quoted 9 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +9 -0
+
+# signal address with port
+reset
+ip netns exec $ns1 ./pm_nl_ctl limits 0 1
+ip netns exec $ns2 ./pm_nl_ctl limits 1 1
+ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
+run_tests $ns1 $ns2 10.0.1.1 0 0 0 fast 10100
+chk_join_nr "signal address with port" 1 1 1
+chk_add_nr 1 1

Should we also check we announce the address with a port?

(note that we could also have a MIB counter we increase when we establish a port on a different port than the original one)

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
author
#12 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 10/10] selftests: mptcp: add testcases for ADD_ADDR with port

Hi Matt,

Thanks for your review.

Quoted 18 lines · Matthieu Baerts <matthieu.baerts(a)tessares.net> 于2020年11月4日周三 上午1:41写道:

Review

Quoted 9 lines · Geliang Tang

This patch added a new argument with_port for run_tests and do_transfer, and added the testcases for ADD_ADDR with port.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
  .../testing/selftests/net/mptcp/mptcp_join.sh | 26 ++++++++++++++++++-
  1 file changed, 25 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/tools/testing/selftests/net/mptcp/mptcp_join.sh

Quoted 7 lines

index 0eae628d1ffd..826d662a9bf8 100755

tools/testing/selftests/net/mptcp/mptcp_join.sh +0 -0
@@ -253,6 +254,11 @@ do_transfer()
              -s ${srv_proto} ${local_addr} < "$sin" > "$sout" &
      spid=$!
 
Quoted 9 lines

tools/testing/selftests/net/mptcp/mptcp_join.sh do_transfer() · line 258

Quoted 2 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +2 -0
+     if [ "$with_port" -gt 0 ];then
+             ip netns exec ${listener_ns} $mptcp_connect -t $timeout -l

-p $with_port \

tools/testing/selftests/net/mptcp/mptcp_join.sh do_transfer() · line 259

Quoted 1 line
tools/testing/selftests/net/mptcp/mptcp_join.sh +1 -0
+                     -s ${srv_proto} ${local_addr} < "$sin" > "$sout" &

Sorry, I am not sure to understand: why do you establish a new connection if the port is set? Just to make sure we can also initiate a new connection directly to this port (I am not sure we want this)?

Here I establish a new connection to listen for the new port. To make sure the peer can connect with it using the new port. If the new port isn't be listened, the peer's connection will fail.

Quoted 37 lines
Quoted 6 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +2 -0
+     fi
+
      sleep 1
 
      if [ "$test_link_fail" -eq 0 ];then

(...)

tools/testing/selftests/net/mptcp/mptcp_join.sh chk_join_nr "remove subflow and signal IPv6" 2 2 2 · line 733

Quoted 11 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +7 -0
@@ -717,6 +724,23 @@ chk_join_nr "remove subflow and signal IPv6" 2 2 2
  chk_add_nr 1 1
  chk_rm_nr 1 1
 
+# subflow with port
+reset
+ip netns exec $ns1 ./pm_nl_ctl limits 0 1
+ip netns exec $ns2 ./pm_nl_ctl limits 0 1
+ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow port 10100
+run_tests $ns1 $ns2 10.0.1.1
+chk_join_nr "single subflow with port" 1 1 1

Should we also check that the second subflow was established on the correct port?

tools/testing/selftests/net/mptcp/mptcp_join.sh chk_join_nr "remove subflow and signal IPv6" 2 2 2 · line 742

Quoted 9 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +9 -0
+
+# signal address with port
+reset
+ip netns exec $ns1 ./pm_nl_ctl limits 0 1
+ip netns exec $ns2 ./pm_nl_ctl limits 1 1
+ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
+run_tests $ns1 $ns2 10.0.1.1 0 0 0 fast 10100
+chk_join_nr "signal address with port" 1 1 1
+chk_add_nr 1 1

Should we also check we announce the address with a port?

Quoted 4 lines

(note that we could also have a MIB counter we increase when we establish a port on a different port than the original one)

I'll add the MIB counter in the next version.

-Geliang

Quoted 6 lines

Cheers,
Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

#13 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 10/10] selftests: mptcp: add testcases for ADD_ADDR with port

Hi Geliang,

Thank you for the replies!

Quoted 38 lines · Geliang Tang

Hi Matt,

Thanks for your review.

Matthieu Baerts <matthieu.baerts(a)tessares.net <mailto:matthieu.baerts(a)tessares.net>> 于2020年11月4日周三 上午1:41写道:

    On 31/10/2020 16:31, Geliang Tang wrote:
     > This patch added a new argument with_port for run_tests and
     > do_transfer, and added the testcases for ADD_ADDR with port.
     >
     > Signed-off-by: Geliang Tang <geliangtang(a)gmail.com
    <mailto:geliangtang(a)gmail.com>>
     > ---
     >   .../testing/selftests/net/mptcp/mptcp_join.sh | 26
    ++++++++++++++++++-
     >   1 file changed, 25 insertions(+), 1 deletion(-)
     >
     > diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh
    b/tools/testing/selftests/net/mptcp/mptcp_join.sh
     > index 0eae628d1ffd..826d662a9bf8 100755
     > --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
     > +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
     > @@ -253,6 +254,11 @@ do_transfer()
     >               -s ${srv_proto} ${local_addr} < "$sin" > "$sout" &
     >       spid=$!
     >
     > +     if [ "$with_port" -gt 0 ];then
     > +             ip netns exec ${listener_ns} $mptcp_connect -t
    $timeout -l -p $with_port \
     > +                     -s ${srv_proto} ${local_addr} < "$sin" >
    "$sout" &

    Sorry, I am not sure to understand: why do you establish a new
    connection if the port is set? Just to make sure we can also initiate a
    new connection directly to this port (I am not sure we want this)?
Quoted 3 lines

Here I establish a new connection to listen for the new port. To make sure the peer can connect with it using the new port. If the new port isn't be listened, the peer's connection will fail.

I see, thank you, I missed the "-l" with mptcp_connect, you are indeed in the listener ns, my bad!
Did we not want to have the kernel (e.g. via instructions given to the PM) creating another listening socket?

I don't know if we can ask to execute 2 binaries doing two listen's on different ports, maybe not good in term of security? Maybe safer if the same app is doing multiple bind's?

Quoted 7 lines

Should we also check we announce the address with a port?

(note that we could also have a MIB counter we increase when we establish a port on a different port than the original one)

I'll add the MIB counter in the next version.

Thanks!

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
#14 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 08/10] mptcp: deal with MPTCP_PM_ADDR_ATTR_PORT in PM netlink

In reply to Geliang Tang

Hi Geliang,

Quoted 23 lines · Geliang Tang

This patch added the MPTCP_PM_ADDR_ATTR_PORT filling and parsing in PM netlink.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
  net/mptcp/pm_netlink.c | 5 +++++
  1 file changed, 5 insertions(+)
net/mptcp/pm_netlink.c +3 -0
index ab0e68426c9e..069447424ddb 100644
@@ -725,6 +725,9 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
  	if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
  		entry->addr.flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
 
+	if (tb[MPTCP_PM_ADDR_ATTR_PORT])
+		entry->addr.port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
+
  	return 0;
  }
 

net/mptcp/pm_netlink.c static int mptcp_nl_fill_addr(struct sk_buff *skb, · line 917

Quoted 4 lines
net/mptcp/pm_netlink.c +1 -0
@@ -911,6 +914,8 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb,
 
  	if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_FAMILY, addr->family))
  		goto nla_put_failure;
+	if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_PORT, ntohs(addr->port)))

It looks strange to me to store something in "network" order. Do we not store everything in "host" order, no?

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
author
#15 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 08/10] mptcp: deal with MPTCP_PM_ADDR_ATTR_PORT in PM netlink

Hi Matt,

Quoted 28 lines · Matthieu Baerts <matthieu.baerts(a)tessares.net> 于2020年11月4日周三 上午1:29写道:

Hi Geliang,

net/mptcp/pm_netlink.c static int mptcp_pm_parse_addr(struct nlattr *attr,

Quoted 13 lines · Geliang Tang

This patch added the MPTCP_PM_ADDR_ATTR_PORT filling and parsing in PM netlink.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
  net/mptcp/pm_netlink.c | 5 +++++
  1 file changed, 5 insertions(+)
net/mptcp/pm_netlink.c +0 -0
index ab0e68426c9e..069447424ddb 100644
@@ -725,6 +725,9 @@ static int mptcp_pm_parse_addr(struct nlattr *attr,

struct genl_info *info,

net/mptcp/pm_netlink.c static int mptcp_pm_parse_addr(struct nlattr *attr, · line 726

Quoted 2 lines
net/mptcp/pm_netlink.c +0 -0
      if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
              entry->addr.flags =

nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);

net/mptcp/pm_netlink.c static int mptcp_pm_parse_addr(struct nlattr *attr, · line 728

Quoted 3 lines
net/mptcp/pm_netlink.c +2 -0
+     if (tb[MPTCP_PM_ADDR_ATTR_PORT])
+             entry->addr.port =

htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));

Quoted 4 lines
net/mptcp/pm_netlink.c +1 -0
+
      return 0;
  }
 
Quoted 10 lines

net/mptcp/pm_netlink.c static int mptcp_nl_fill_addr(struct sk_buff *skb, · line 917

Quoted 5 lines
net/mptcp/pm_netlink.c +1 -0
@@ -911,6 +914,8 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb,
 
      if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_FAMILY, addr->family))
              goto nla_put_failure;
+     if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_PORT, ntohs(addr->port)))

It looks strange to me to store something in "network" order. Do we not store everything in "host" order, no?

I think we can't. Since the 'skc_dport' in struct sock_common and the 'sin_port' in struct sockaddr_in are all defined as big-endian order. It's simply to keep the 'port' in struct mptcp_addr_info as a big-endian order too.

If we define mptcp_addr_info's port as a little-endian order, we can avoid this ntohs conversion in mptcp_nl_fill_addr, but we need add more other order conversions in other places, like:

in mptcp_info2sockaddr:

    in_addr->sin_port = htons(info->port);

in remote_address:

    addr->port = ntohs(skc->skc_dport);

-Geliang

Quoted 6 lines

Cheers,
Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

#16 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 08/10] mptcp: deal with MPTCP_PM_ADDR_ATTR_PORT in PM netlink

Hi Geliang,

Quoted 47 lines · Geliang Tang

Hi Matt,

Matthieu Baerts <matthieu.baerts(a)tessares.net <mailto:matthieu.baerts(a)tessares.net>> 于2020年11月4日周三 上午1:29写道:

    Hi Geliang,

    On 31/10/2020 16:31, Geliang Tang wrote:
     > This patch added the MPTCP_PM_ADDR_ATTR_PORT filling and parsing
    in PM
     > netlink.
     >
     > Signed-off-by: Geliang Tang <geliangtang(a)gmail.com
    <mailto:geliangtang(a)gmail.com>>
     > ---
     >   net/mptcp/pm_netlink.c | 5 +++++
     >   1 file changed, 5 insertions(+)
     >
     > diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
     > index ab0e68426c9e..069447424ddb 100644
     > --- a/net/mptcp/pm_netlink.c
     > +++ b/net/mptcp/pm_netlink.c
     > @@ -725,6 +725,9 @@ static int mptcp_pm_parse_addr(struct nlattr
    *attr, struct genl_info *info,
     >       if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
     >               entry->addr.flags =
    nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
     >
     > +     if (tb[MPTCP_PM_ADDR_ATTR_PORT])
     > +             entry->addr.port =
    htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
     > +
     >       return 0;
     >   }
     >
     > @@ -911,6 +914,8 @@ static int mptcp_nl_fill_addr(struct sk_buff
    *skb,
     >
     >       if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_FAMILY, addr->family))
     >               goto nla_put_failure;
     > +     if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_PORT,
    ntohs(addr->port)))

    It looks strange to me to store something in "network" order. Do we not
    store everything in "host" order, no?
Quoted 4 lines

I think we can't. Since the 'skc_dport' in struct sock_common and the 'sin_port' in struct sockaddr_in are all defined as big-endian order. It's simply to keep the 'port' in struct mptcp_addr_info as a big-endian order too.

That's right, thank you for pointing this to me! If this is tiddly linked with inet_dport and others, that's fine for me.

I have to admit it always confused me having these port numbers stored in network byte order... but I guess it is best to keep the same logic!

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
#17 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 04/10] mptcp: use adding up size when get ADD_ADDR length

In reply to Geliang Tang
Quoted 16 lines · Geliang Tang

This patch uses adding up size to get the ADD_ADDR suboption length rather than returning the ADD_ADDR size constants.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
  net/mptcp/protocol.h | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
net/mptcp/protocol.h +0 -0
index f303c46bcc29..ad3fdec98fdc 100644
@@ -546,10 +546,14 @@ static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
 
  static inline unsigned int mptcp_add_addr_len(int family, bool echo)
  {

net/mptcp/protocol.h static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk) · line 554

Quoted 10 lines
net/mptcp/protocol.h +6 -4
-	if (family == AF_INET)
-		return echo ? TCPOLEN_MPTCP_ADD_ADDR_BASE
-			    : TCPOLEN_MPTCP_ADD_ADDR;
-	return echo ? TCPOLEN_MPTCP_ADD_ADDR6_BASE : TCPOLEN_MPTCP_ADD_ADDR6;
+	u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
+
+	if (family == AF_INET6)
+		len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
+	if (!echo)
+		len += 8; // Truncated HMAC

I don't think these comments with "//" are accepted. Instead, should we not declare a new constant, e.g. TCPOLEN_MPTCP_ADD_ADDR_HMAC?

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
author
#18 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 04/10] mptcp: use adding up size when get ADD_ADDR length

Hi Matt,

Quoted 31 lines · Matthieu Baerts <matthieu.baerts(a)tessares.net> 于2020年11月4日周三 上午1:23写道:
Quoted 1 line · Geliang Tang

This patch uses adding up size to get the ADD_ADDR suboption length

rather

net/mptcp/protocol.h static inline bool

Quoted 12 lines

than returning the ADD_ADDR size constants.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
  net/mptcp/protocol.h | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
net/mptcp/protocol.h +0 -0
index f303c46bcc29..ad3fdec98fdc 100644
@@ -546,10 +546,14 @@ static inline bool

mptcp_pm_should_rm_signal(struct mptcp_sock *msk)

net/mptcp/protocol.h static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)

Quoted 7 lines
net/mptcp/protocol.h +0 -4
  static inline unsigned int mptcp_add_addr_len(int family, bool echo)
  {
-     if (family == AF_INET)
-             return echo ? TCPOLEN_MPTCP_ADD_ADDR_BASE
-                         : TCPOLEN_MPTCP_ADD_ADDR;
-     return echo ? TCPOLEN_MPTCP_ADD_ADDR6_BASE :

TCPOLEN_MPTCP_ADD_ADDR6;

net/mptcp/protocol.h static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk) · line 554

Quoted 6 lines
net/mptcp/protocol.h +6 -0
+     u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
+
+     if (family == AF_INET6)
+             len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
+     if (!echo)
+             len += 8; // Truncated HMAC
Quoted 4 lines

I don't think these comments with "//" are accepted. Instead, should we not declare a new constant, e.g. TCPOLEN_MPTCP_ADD_ADDR_HMAC?

Thanks, I'll fix this in the next version.

-Geliang

Quoted 6 lines

Cheers,
Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

#19 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 02/10] mptcp: unify ADD_ADDR and ADD_ADDR6 suboptions writing

In reply to Geliang Tang

Hi Geliang,

Quoted 5 lines · Geliang Tang

The length of ADD_ADDR6 is 12 octets longer than ADD_ADDR. That's the only difference between them.

This patch dropped the duplicate code between ADD_ADDR and ADD_ADDR6 suboptions writing, and unify them into one.

It is nice to avoid similar code but here, I think you are changing the behaviour if CONFIG_MPTCP_IPV6 is disabled. If I am not mistaken, we are going to reserve space but not write anything in it except the hmac.

For the moment, it is fine because we will not call mptcp_write_options with OPTION_MPTCP_ADD_ADDR6 but I don't know if we can safely take that into consideration for a "public" function called from TCP.

Maybe "safer" by using a helper taking different arguments for v4 and v6? In this case we could have something like:

	if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
		mptcp_write_add_addr_option(ptr, opts,
					   TCPOLEN_MPTCP_ADD_ADDR_BASE);
	}
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
	if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) {
		mptcp_write_add_addr_option(ptr, opts,
					  TCPOLEN_MPTCP_ADD_ADDR6_BASE);
	}

#endif

Or we add a comment mentioning we should not have OPTION_MPTCP_ADD_ADDR6 if IPV6 is disabled?

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
author
#20 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 02/10] mptcp: unify ADD_ADDR and ADD_ADDR6 suboptions writing

Hi Matt,

Quoted 9 lines · Matthieu Baerts <matthieu.baerts(a)tessares.net> 于2020年11月4日周三 上午1:23写道:

Hi Geliang,

Quoted 5 lines · Geliang Tang

The length of ADD_ADDR6 is 12 octets longer than ADD_ADDR. That's the only difference between them.

This patch dropped the duplicate code between ADD_ADDR and ADD_ADDR6 suboptions writing, and unify them into one.

Quoted 9 lines

It is nice to avoid similar code but here, I think you are changing the behaviour if CONFIG_MPTCP_IPV6 is disabled. If I am not mistaken, we are going to reserve space but not write anything in it except the hmac.

For the moment, it is fine because we will not call mptcp_write_options with OPTION_MPTCP_ADD_ADDR6 but I don't know if we can safely take that into consideration for a "public" function called from TCP.

Maybe "safer" by using a helper taking different arguments for v4 and

Quoted 13 lines

v6? In this case we could have something like:

        if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
                mptcp_write_add_addr_option(ptr, opts,
                                           TCPOLEN_MPTCP_ADD_ADDR_BASE);
        }
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
        if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) {
                mptcp_write_add_addr_option(ptr, opts,
                                          TCPOLEN_MPTCP_ADD_ADDR6_BASE);
        }
Quoted 6 lines

#endif

Or we add a comment mentioning we should not have OPTION_MPTCP_ADD_ADDR6 if IPV6 is disabled?

Thanks for your review. Should it be better to put all OPTION_MPTCP_ADD_ADDR6
into the IS_ENABLED(CONFIG_MPTCP_IPV6) condition? Something like:

if ((OPTION_MPTCP_ADD_ADDR
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
| OPTION_MPTCP_ADD_ADDR6

#endif
            ) & opts->suboptions) {
                u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
                u8 echo = MPTCP_ADDR_ECHO;
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
                if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions)
                        len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;

#endif

                if (opts->ahmac) {
                        len += sizeof(opts->ahmac);
                        echo = 0;
                }

                *ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
                                      len, echo, opts->addr_id);
                if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
                        memcpy((u8 *)ptr, (u8 *)&opts->addr.s_addr, 4);
                        ptr += 1;
                }
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
                else if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) {
                        memcpy((u8 *)ptr, opts->addr6.s6_addr, 16);
                        ptr += 4;
                }
#endif
                if (opts->ahmac) {
                        put_unaligned_be64(opts->ahmac, ptr);
                        ptr += 2;
                }
        }

Is this code acceptable?

-Geliang

Cheers,

Quoted 5 lines

Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

#21 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 02/10] mptcp: unify ADD_ADDR and ADD_ADDR6 suboptions writing

Hi Geliang,

Quoted 85 lines · Geliang Tang

Hi Matt,

Matthieu Baerts <matthieu.baerts(a)tessares.net <mailto:matthieu.baerts(a)tessares.net>> 于2020年11月4日周三 上午1:23写道:

Hi Geliang,

On 31/10/2020 16:24, Geliang Tang wrote:
> The length of ADD_ADDR6 is 12 octets longer than ADD_ADDR. That's the > only difference between them.
>
> This patch dropped the duplicate code between ADD_ADDR and ADD_ADDR6 > suboptions writing, and unify them into one.

It is nice to avoid similar code but here, I think you are changing the behaviour if CONFIG_MPTCP_IPV6 is disabled. If I am not mistaken, we are
going to reserve space but not write anything in it except the hmac.

For the moment, it is fine because we will not call mptcp_write_options with OPTION_MPTCP_ADD_ADDR6 but I don't know if we can safely take that into consideration for a "public" function called from TCP.

Maybe "safer" by using a helper taking different arguments for v4 and v6? In this case we could have something like:

        if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) { mptcp_write_add_addr_option(ptr, opts,

 TCPOLEN_MPTCP_ADD_ADDR_BASE);
        }

#if IS_ENABLED(CONFIG_MPTCP_IPV6)
        if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) { mptcp_write_add_addr_option(ptr, opts,

TCPOLEN_MPTCP_ADD_ADDR6_BASE);
        }
#endif

Or we add a comment mentioning we should not have OPTION_MPTCP_ADD_ADDR6
if IPV6 is disabled?

Thanks for your review. Should it be better to put all OPTION_MPTCP_ADD_ADDR6
into the IS_ENABLED(CONFIG_MPTCP_IPV6) condition? Something like:

        if ((OPTION_MPTCP_ADD_ADDR
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
           | OPTION_MPTCP_ADD_ADDR6
#endif
            ) & opts->suboptions) {
                u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE; u8 echo = MPTCP_ADDR_ECHO;

#if IS_ENABLED(CONFIG_MPTCP_IPV6)
                if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
#endif

                if (opts->ahmac) {
                        len += sizeof(opts->ahmac); echo = 0;
                }

                *ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR, len, echo, opts->addr_id); if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) { memcpy((u8 *)ptr, (u8 *)&opts->addr.s_addr, 4); ptr += 1;
                }
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
                else if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) { memcpy((u8 *)ptr, opts->addr6.s6_addr, 16); ptr += 4;
                }
#endif
                if (opts->ahmac) { put_unaligned_be64(opts->ahmac, ptr); ptr += 2;
                }
        }

Quoted 1 line

Is this code acceptable?

I don't know if it is clearer but that's typical with v6 :) (we could even drop the second "#if IS_ENABLED(CONFIG_MPTCP_IPV6)" if we want)

But it looks "safer" :)

Cheers,
Matt

PS: the HTML rendering makes the code a bit hard to read. May you turn on the option to switch to "plain text mode" only if you don't mind :)

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net