Skip to contentSkip to conversation

MPTCP: IPv4-mapped IPv6 addressing for subflows

PATCH Applied Mat Martineau 2 participants 7 messages Jan 25, 2021 – Jan 28, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover MPTCP: IPv4-mapped IPv6 addressing for subflows

This patch series from the MPTCP tree adds support for IPv4-mapped IPv6 addressing that was missing when multiple subflows were first implemented.

Patches 1 and 2 handle the conversion and comparison of the mapped addresses.

Patch 3 contains a minor refactor in the path manager's handling of addresses.

Patches 4 and 5 add selftests for the new functionality and adjust the selftest timeout.

Geliang Tang (1):
selftests: mptcp: add IPv4-mapped IPv6 testcases

Matthieu Baerts (4):
mptcp: support MPJoin with IPv4 mapped in v6 sk
mptcp: pm nl: support IPv4 mapped in v6 addresses
mptcp: pm nl: reduce variable scope
selftests: increase timeout to 10 min

 net/mptcp/pm_netlink.c                        | 39 +++++++---
 net/mptcp/subflow.c                           | 24 ++++--
 .../testing/selftests/net/mptcp/mptcp_join.sh | 75 +++++++++++++++++++
 tools/testing/selftests/net/mptcp/settings    |  2 +-
 4 files changed, 120 insertions(+), 20 deletions(-)

base-commit: a61e4b60761fa7fa2cfde6682760763537ce5549

Signature · 1 line
2.30.0
#1 lore raw

PATCH 1/5 mptcp: support MPJoin with IPv4 mapped in v6 sk

From: Matthieu Baerts <matthieu.baerts(a)tessares.net>

With an IPv4 mapped in v6 socket, we were trying to call inet6_bind() with an IPv4 address resulting in a -EINVAL error because the given addr_len -- size of the address structure -- was too short.

We now make sure to use address structures for the same family as the MPTCP socket for both the bind() and the connect(). It means we convert v4 addresses to v4 mapped in v6 or the opposite if needed.

Fixes ec3edaa7ca6c ("mptcp: Add handling of outgoing MP_JOIN requests")
Co-developed-by Geliang Tang <geliangtang(a)gmail.com>
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
Signed-off-by Matthieu Baerts <matthieu.baerts(a)tessares.net>
Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 net/mptcp/subflow.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
net/mptcp/subflow.c +17 -7
index 721059916c96..586156281e5a 100644
@@ -1085,21 +1085,31 @@ void mptcpv6_handle_mapped(struct sock *sk, bool mapped)
 #endif
 
 static void mptcp_info2sockaddr(const struct mptcp_addr_info *info,
-				struct sockaddr_storage *addr)
+				struct sockaddr_storage *addr,
+				unsigned short family)
 {
 	memset(addr, 0, sizeof(*addr));
-	addr->ss_family = info->family;
+	addr->ss_family = family;
 	if (addr->ss_family == AF_INET) {
 		struct sockaddr_in *in_addr = (struct sockaddr_in *)addr;
 
-		in_addr->sin_addr = info->addr;
+		if (info->family == AF_INET)
+			in_addr->sin_addr = info->addr;
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+		else if (ipv6_addr_v4mapped(&info->addr6))
+			in_addr->sin_addr.s_addr = info->addr6.s6_addr32[3];
+#endif
 		in_addr->sin_port = info->port;
 	}
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
 	else if (addr->ss_family == AF_INET6) {
 		struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)addr;
 
-		in6_addr->sin6_addr = info->addr6;
+		if (info->family == AF_INET)
+			ipv6_addr_set_v4mapped(info->addr.s_addr,
+					       &in6_addr->sin6_addr);
+		else
+			in6_addr->sin6_addr = info->addr6;
 		in6_addr->sin6_port = info->port;
 	}
 #endif
@@ -1143,11 +1153,11 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 	subflow->remote_key = msk->remote_key;
 	subflow->local_key = msk->local_key;
 	subflow->token = msk->token;
-	mptcp_info2sockaddr(loc, &addr);
+	mptcp_info2sockaddr(loc, &addr, ssk->sk_family);
 
 	addrlen = sizeof(struct sockaddr_in);
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-	if (loc->family == AF_INET6)
+	if (addr.ss_family == AF_INET6)
 		addrlen = sizeof(struct sockaddr_in6);
 #endif
 	ssk->sk_bound_dev_if = loc->ifindex;
@@ -1163,7 +1173,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 	subflow->remote_id = remote_id;
 	subflow->request_join = 1;
 	subflow->request_bkup = !!(loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
-	mptcp_info2sockaddr(remote, &addr);
+	mptcp_info2sockaddr(remote, &addr, ssk->sk_family);
 
 	mptcp_add_pending_subflow(msk, subflow);
 	err = kernel_connect(sf, (struct sockaddr *)&addr, addrlen, O_NONBLOCK);
Signature · 1 line
2.30.0
#2 lore raw

PATCH 2/5 mptcp: pm nl: support IPv4 mapped in v6 addresses

In reply to Mat Martineau

From: Matthieu Baerts <matthieu.baerts(a)tessares.net>

On one side, we can allow the creation of subflows between v4 mapped in v6 and v4 addresses. For that we look for v4mapped addresses between the local address we want to select and the remote one.

On the other side, we also properly deal with received v4mapped addresses, either announced ones or set via Netlink.

Fixes 01cacb00b35c ("mptcp: add netlink-based PM")
Suggested-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
Co-developed-by Geliang Tang <geliangtang(a)gmail.com>
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
Signed-off-by Matthieu Baerts <matthieu.baerts(a)tessares.net>
Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 net/mptcp/pm_netlink.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)
net/mptcp/pm_netlink.c +24 -9
index 9b1f6298bbdb..f0afff6ba015 100644
@@ -60,15 +60,20 @@ static bool addresses_equal(const struct mptcp_addr_info *a,
 {
 	bool addr_equals = false;
 
-	if (a->family != b->family)
-		return false;
-
-	if (a->family == AF_INET)
-		addr_equals = a->addr.s_addr == b->addr.s_addr;
+	if (a->family == b->family) {
+		if (a->family == AF_INET)
+			addr_equals = a->addr.s_addr == b->addr.s_addr;
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-	else
-		addr_equals = !ipv6_addr_cmp(&a->addr6, &b->addr6);
+		else
+			addr_equals = !ipv6_addr_cmp(&a->addr6, &b->addr6);
+	} else if (a->family == AF_INET) {
+		if (ipv6_addr_v4mapped(&b->addr6))
+			addr_equals = a->addr.s_addr == b->addr6.s6_addr32[3];
+	} else if (b->family == AF_INET) {
+		if (ipv6_addr_v4mapped(&a->addr6))
+			addr_equals = a->addr6.s6_addr32[3] == b->addr.s_addr;
 #endif
+	}
 
 	if (!addr_equals)
 		return false;
@@ -137,6 +142,7 @@ select_local_address(const struct pm_nl_pernet *pernet,
 		     struct mptcp_sock *msk)
 {
 	struct mptcp_pm_addr_entry *entry, *ret = NULL;
+	struct sock *sk = (struct sock *)msk;
 
 	rcu_read_lock();
 	__mptcp_flush_join_list(msk);
@@ -144,11 +150,20 @@ select_local_address(const struct pm_nl_pernet *pernet,
 		if (!(entry->addr.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW))
 			continue;
 
+		if (entry->addr.family != sk->sk_family) {
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+			if ((entry->addr.family == AF_INET &&
+			     !ipv6_addr_v4mapped(&sk->sk_v6_daddr)) ||
+			    (sk->sk_family == AF_INET &&
+			     !ipv6_addr_v4mapped(&entry->addr.addr6)))
+#endif
+				continue;
+		}
+
 		/* avoid any address already in use by subflows and
 		 * pending join
 		 */
-		if (entry->addr.family == ((struct sock *)msk)->sk_family &&
-		    !lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) {
+		if (!lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) {
 			ret = entry;
 			break;
 		}
Signature · 1 line
2.30.0
#3 lore raw

PATCH 3/5 mptcp: pm nl: reduce variable scope

In reply to Mat Martineau

From: Matthieu Baerts <matthieu.baerts(a)tessares.net>

To avoid confusions like when working on the previous patch, better to declare and assign this variable only where it is needed.

Signed-off-by Matthieu Baerts <matthieu.baerts(a)tessares.net>
Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 net/mptcp/pm_netlink.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/mptcp/pm_netlink.c +3 -3
index f0afff6ba015..83976b9ee99b 100644
@@ -325,7 +325,6 @@ void mptcp_pm_free_anno_list(struct mptcp_sock *msk)
 
 static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 {
-	struct mptcp_addr_info remote = { 0 };
 	struct sock *sk = (struct sock *)msk;
 	struct mptcp_pm_addr_entry *local;
 	struct pm_nl_pernet *pernet;
@@ -359,13 +358,14 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 	/* check if should create a new subflow */
 	if (msk->pm.local_addr_used < msk->pm.local_addr_max &&
 	    msk->pm.subflows < msk->pm.subflows_max) {
-		remote_address((struct sock_common *)sk, &remote);
-
 		local = select_local_address(pernet, msk);
 		if (local) {
+			struct mptcp_addr_info remote = { 0 };
+
 			msk->pm.local_addr_used++;
 			msk->pm.subflows++;
 			check_work_pending(msk);
+			remote_address((struct sock_common *)sk, &remote);
 			spin_unlock_bh(&msk->pm.lock);
 			__mptcp_subflow_connect(sk, &local->addr, &remote);
 			spin_lock_bh(&msk->pm.lock);
Signature · 1 line
2.30.0
#4 lore raw

PATCH 4/5 selftests: mptcp: add IPv4-mapped IPv6 testcases

In reply to Mat Martineau

From: Geliang Tang <geliangtang(a)gmail.com>

Here, we make sure we support IPv4-mapped in IPv6 addresses in different contexts:

- a v4-mapped address is received by the PM and can be used as v4.
- a v4 address is received by the PM and can be used even with a v4 mapped socket.

We also make sure we don't try to establish subflows between v4 and v6 addresses, e.g. if a real v6 address ends with a valid v4 address.

Co-developed-by Matthieu Baerts <matthieu.baerts(a)tessares.net>
Signed-off-by Matthieu Baerts <matthieu.baerts(a)tessares.net>
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +75 -0
index f74cd993b168..be34b9ccbd20 100755
@@ -790,6 +790,81 @@ chk_join_nr "remove subflow and signal IPv6" 2 2 2
 chk_add_nr 1 1
 chk_rm_nr 1 1
 
+# subflow IPv4-mapped to IPv4-mapped
+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 "::ffff:10.0.3.2" flags subflow
+run_tests $ns1 $ns2 "::ffff:10.0.1.1"
+chk_join_nr "single subflow IPv4-mapped" 1 1 1
+
+# signal address IPv4-mapped with IPv4-mapped sk
+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 "::ffff:10.0.2.1" flags signal
+run_tests $ns1 $ns2 "::ffff:10.0.1.1"
+chk_join_nr "signal address IPv4-mapped" 1 1 1
+chk_add_nr 1 1
+
+# subflow v4-map-v6
+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
+run_tests $ns1 $ns2 "::ffff:10.0.1.1"
+chk_join_nr "single subflow v4-map-v6" 1 1 1
+
+# signal address v4-map-v6
+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
+run_tests $ns1 $ns2 "::ffff:10.0.1.1"
+chk_join_nr "signal address v4-map-v6" 1 1 1
+chk_add_nr 1 1
+
+# subflow v6-map-v4
+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 "::ffff:10.0.3.2" flags subflow
+run_tests $ns1 $ns2 10.0.1.1
+chk_join_nr "single subflow v6-map-v4" 1 1 1
+
+# signal address v6-map-v4
+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 "::ffff:10.0.2.1" flags signal
+run_tests $ns1 $ns2 10.0.1.1
+chk_join_nr "signal address v6-map-v4" 1 1 1
+chk_add_nr 1 1
+
+# no subflow IPv6 to v4 address
+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 dead:beef:2::2 flags subflow
+run_tests $ns1 $ns2 10.0.1.1
+chk_join_nr "no JOIN with diff families v4-v6" 0 0 0
+
+# no subflow IPv6 to v4 address even if v6 has a valid v4 at the end
+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 dead:beef:2::10.0.3.2 flags subflow
+run_tests $ns1 $ns2 10.0.1.1
+chk_join_nr "no JOIN with diff families v4-v6-2" 0 0 0
+
+# no subflow IPv4 to v6 address, no need to slow down too then
+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
+run_tests $ns1 $ns2 dead:beef:1::1
+chk_join_nr "no JOIN with diff families v6-v4" 0 0 0
+
 # single subflow, backup
 reset
 ip netns exec $ns1 ./pm_nl_ctl limits 0 1
Signature · 1 line
2.30.0
#5 lore raw

PATCH 5/5 selftests: increase timeout to 10 min

In reply to Mat Martineau

From: Matthieu Baerts <matthieu.baerts(a)tessares.net>

On slow systems with kernel debug settings, we can reach the current timeout when all tests are executed.

Likely some tests need be improved to remove some 'sleep' and wait (less) for a specific action. This can also improve stability.

Signed-off-by Matthieu Baerts <matthieu.baerts(a)tessares.net>
Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 tools/testing/selftests/net/mptcp/settings | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/settings +1 -1
index 026384c189c9..a62d2fa1275c 100644
@@ -1 +1 @@
-timeout=450
+timeout=600
Signature · 1 line
2.30.0
#6 lore raw
In reply to Mat Martineau

Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

Quoted 8 lines · On Mon, 25 Jan 2021 10:58:59 -0800 you wrote:

This patch series from the MPTCP tree adds support for IPv4-mapped IPv6 addressing that was missing when multiple subflows were first implemented.

Patches 1 and 2 handle the conversion and comparison of the mapped addresses.

[...]

Here is the summary with links:
- [net-next,1/5] mptcp: support MPJoin with IPv4 mapped in v6 sk

    https://git.kernel.org/netdev/net-next/c/50a13bc3945c
  - [net-next,2/5] mptcp: pm nl: support IPv4 mapped in v6 addresses
    https://git.kernel.org/netdev/net-next/c/7b9b0f7e1230
  - [net-next,3/5] mptcp: pm nl: reduce variable scope
    https://git.kernel.org/netdev/net-next/c/1f2f1931b2a8
  - [net-next,4/5] selftests: mptcp: add IPv4-mapped IPv6 testcases
    https://git.kernel.org/netdev/net-next/c/a6094788031d
  - [net-next,5/5] selftests: increase timeout to 10 min
    https://git.kernel.org/netdev/net-next/c/9c2cadefde48

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html