Skip to contentSkip to conversation

add ADD_ADDR echo flag support

PATCH Superseded Geliang Tang 2 participants 5 messages Aug 13, 2020 – Aug 18, 2020

Subsystems (3)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Geliang Tang

author
#0 lore raw

v2 cover add ADD_ADDR echo flag support

v2:
- add ADD_ADDR mibs
- add selftests for ADD_ADDR

v1:
- mptcp: send out ADD_ADDR with echo flag

Geliang Tang (3):
mptcp: send out ADD_ADDR with echo flag
mptcp: add ADD_ADDR related mibs
selftests: mptcp: add ADD_ADDR mibs check function

 net/mptcp/mib.c                               |  2 +
 net/mptcp/mib.h                               |  2 +
 net/mptcp/options.c                           | 33 +++++++++-----
 net/mptcp/pm.c                                |  1 +
 net/mptcp/pm_netlink.c                        |  1 +
 net/mptcp/protocol.h                          |  1 +
 .../testing/selftests/net/mptcp/mptcp_join.sh | 45 +++++++++++++++++++
 7 files changed, 74 insertions(+), 11 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/3 mptcp: send out ADD_ADDR with echo flag

When the ADD_ADDR suboption has been received, we need to send out the same ADD_ADDR suboption with echo-flag=1, and no HMAC.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/options.c    | 30 +++++++++++++++++++-----------
 net/mptcp/pm.c         |  1 +
 net/mptcp/pm_netlink.c |  1 +
 net/mptcp/protocol.h   |  1 +
 4 files changed, 22 insertions(+), 11 deletions(-)
net/mptcp/options.c +19 -11
index a5ecf004a152..6aa9a48322d7 100644
@@ -243,7 +243,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
 		mp_opt->add_addr = 1;
 		mp_opt->port = 0;
 		mp_opt->addr_id = *ptr++;
-		pr_debug("ADD_ADDR: id=%d", mp_opt->addr_id);
+		pr_debug("ADD_ADDR: id=%d, echo=%d", mp_opt->addr_id, mp_opt->echo);
 		if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
 			memcpy((u8 *)&mp_opt->addr.s_addr, (u8 *)ptr, 4);
 			ptr += 4;
@@ -580,6 +580,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk,
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 	struct mptcp_addr_info saddr;
+	bool echo = READ_ONCE(msk->pm.add_addr_echo);
 	int len;
 
 	if (!mptcp_pm_should_add_signal(msk) ||
@@ -595,22 +596,26 @@ static bool mptcp_established_options_add_addr(struct sock *sk,
 	if (saddr.family == AF_INET) {
 		opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
 		opts->addr = saddr.addr;
-		opts->ahmac = add_addr_generate_hmac(msk->local_key,
-						     msk->remote_key,
-						     opts->addr_id,
-						     &opts->addr);
+		if (!echo) {
+			opts->ahmac = add_addr_generate_hmac(msk->local_key,
+							     msk->remote_key,
+							     opts->addr_id,
+							     &opts->addr);
+		}
 	}
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
 	else if (saddr.family == AF_INET6) {
 		opts->suboptions |= OPTION_MPTCP_ADD_ADDR6;
 		opts->addr6 = saddr.addr6;
-		opts->ahmac = add_addr6_generate_hmac(msk->local_key,
-						      msk->remote_key,
-						      opts->addr_id,
-						      &opts->addr6);
+		if (!echo) {
+			opts->ahmac = add_addr6_generate_hmac(msk->local_key,
+							      msk->remote_key,
+							      opts->addr_id,
+							      &opts->addr6);
+		}
 	}
 #endif
-	pr_debug("addr_id=%d, ahmac=%llu", opts->addr_id, opts->ahmac);
+	pr_debug("addr_id=%d, ahmac=%llu, echo=%d", opts->addr_id, opts->ahmac, echo);
 
 	return true;
 }
@@ -884,8 +889,11 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 			addr.addr6 = mp_opt.addr6;
 		}
 #endif
-		if (!mp_opt.echo)
+		if (!mp_opt.echo) {
+			WRITE_ONCE(msk->pm.add_addr_echo, true);
+			mptcp_pm_announce_addr(msk, &addr);
 			mptcp_pm_add_addr_received(msk, &addr);
+		}
 		mp_opt.add_addr = 0;
 	}
 
net/mptcp/pm.c +1 -0
index b3712771f268..c66cbc53cbed 100644
@@ -230,6 +230,7 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
 	WRITE_ONCE(msk->pm.rm_addr_signal, false);
 	WRITE_ONCE(msk->pm.accept_addr, false);
 	WRITE_ONCE(msk->pm.accept_subflow, false);
+	WRITE_ONCE(msk->pm.add_addr_echo, false);
 	msk->pm.status = 0;
 
 	spin_lock_init(&msk->pm.lock);
net/mptcp/pm_netlink.c +1 -0
index 8d29eae2a0c1..d670a7e02731 100644
@@ -203,6 +203,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 			struct mptcp_pm_addr_entry *clone = NULL;
 
 			msk->pm.add_addr_signaled++;
+			WRITE_ONCE(msk->pm.add_addr_echo, false);
 			mptcp_pm_announce_addr(msk, &local->addr);
 
 			clone = kmemdup(local, sizeof(*local), GFP_ATOMIC);
net/mptcp/protocol.h +1 -0
index ceca1ddea9f8..c4bc0d8f0995 100644
@@ -169,6 +169,7 @@ struct mptcp_pm_data {
 	bool		work_pending;
 	bool		accept_addr;
 	bool		accept_subflow;
+	bool		add_addr_echo;
 	u8		add_addr_signaled;
 	u8		add_addr_accepted;
 	u8		local_addr_used;
Signature · 1 line
2.17.1
#2 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 1/3] mptcp: send out ADD_ADDR with echo flag

Hi Geilang,

Thanks for the patch. Some comments below.

Quoted 25 lines · Geliang Tang

When the ADD_ADDR suboption has been received, we need to send out the same ADD_ADDR suboption with echo-flag=1, and no HMAC.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>

---

net/mptcp/options.c    | 30 +++++++++++++++++++-----------
net/mptcp/pm.c         |  1 +
net/mptcp/pm_netlink.c |  1 +
net/mptcp/protocol.h   |  1 +
4 files changed, 22 insertions(+), 11 deletions(-)
net/mptcp/options.c +1 -1
index a5ecf004a152..6aa9a48322d7 100644
@@ -243,7 +243,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
 		mp_opt->add_addr = 1;
 		mp_opt->port = 0;
 		mp_opt->addr_id = *ptr++;
-		pr_debug("ADD_ADDR: id=%d", mp_opt->addr_id);
+		pr_debug("ADD_ADDR: id=%d, echo=%d", mp_opt->addr_id, mp_opt->echo);
 		if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
 			memcpy((u8 *)&mp_opt->addr.s_addr, (u8 *)ptr, 4);
 			ptr += 4;

net/mptcp/options.c static bool mptcp_established_options_add_addr(struct sock *sk, · line 583

Quoted 4 lines
net/mptcp/options.c +1 -0
@@ -580,6 +580,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk,
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 	struct mptcp_addr_info saddr;
+	bool echo = READ_ONCE(msk->pm.add_addr_echo);

I think it's important to access msk->pm.add_addr_echo and msk->pm_msk->pm.add_addr_signal in a way that makes sure the values have not been updated separately, so we can guarantee there is not a race condition where the 'echo' bit gets read before a parallel thread modifies it along with other add_addr information. Might be easier to coordinate these accesses inside mptcp_pm_add_addr_signal() - that function could also have an output parameter for the echo bit.

Quoted 41 lines
net/mptcp/options.c +13 -9
 	int len;
 
 	if (!mptcp_pm_should_add_signal(msk) ||
@@ -595,22 +596,26 @@ static bool mptcp_established_options_add_addr(struct sock *sk,
 	if (saddr.family == AF_INET) {
 		opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
 		opts->addr = saddr.addr;
-		opts->ahmac = add_addr_generate_hmac(msk->local_key,
-						     msk->remote_key,
-						     opts->addr_id,
-						     &opts->addr);
+		if (!echo) {
+			opts->ahmac = add_addr_generate_hmac(msk->local_key,
+							     msk->remote_key,
+							     opts->addr_id,
+							     &opts->addr);
+		}
 	}
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
 	else if (saddr.family == AF_INET6) {
 		opts->suboptions |= OPTION_MPTCP_ADD_ADDR6;
 		opts->addr6 = saddr.addr6;
-		opts->ahmac = add_addr6_generate_hmac(msk->local_key,
-						      msk->remote_key,
-						      opts->addr_id,
-						      &opts->addr6);
+		if (!echo) {
+			opts->ahmac = add_addr6_generate_hmac(msk->local_key,
+							      msk->remote_key,
+							      opts->addr_id,
+							      &opts->addr6);
+		}
 	}
 #endif
-	pr_debug("addr_id=%d, ahmac=%llu", opts->addr_id, opts->ahmac);
+	pr_debug("addr_id=%d, ahmac=%llu, echo=%d", opts->addr_id, opts->ahmac, echo);
 
 	return true;
 }
@@ -884,8 +889,11 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 			addr.addr6 = mp_opt.addr6;

net/mptcp/options.c void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb, · line 898

Quoted 10 lines
net/mptcp/options.c +4 -1
 		}
 #endif
-		if (!mp_opt.echo)
+		if (!mp_opt.echo) {
+			WRITE_ONCE(msk->pm.add_addr_echo, true);
+			mptcp_pm_announce_addr(msk, &addr);
 			mptcp_pm_add_addr_received(msk, &addr);
+		}
 		mp_opt.add_addr = 0;
 	}

I think the echo should not happen this early. mptcp_pm_add_add_received() might return without doing anything with the address, and in that case the echo should not be sent. For a user space path manager, the echo might be delayed for a while. Instead the path manager should be responsible for requesting the echo when the address has been fully accepted and processed. This would also allow writing msk->pm.add_addr_echo with the appropriate lock held, so there would not be conflicts between outgoing ADD_ADDRs and echoes.

Quoted 18 lines
net/mptcp/pm.c +1 -0
index b3712771f268..c66cbc53cbed 100644
@@ -230,6 +230,7 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
 	WRITE_ONCE(msk->pm.rm_addr_signal, false);
 	WRITE_ONCE(msk->pm.accept_addr, false);
 	WRITE_ONCE(msk->pm.accept_subflow, false);
+	WRITE_ONCE(msk->pm.add_addr_echo, false);
 	msk->pm.status = 0;
 
 	spin_lock_init(&msk->pm.lock);
net/mptcp/pm_netlink.c +0 -0
index 8d29eae2a0c1..d670a7e02731 100644

net/mptcp/pm_netlink.c static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) · line 207

Quoted 5 lines
net/mptcp/pm_netlink.c +1 -0
@@ -203,6 +203,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 			struct mptcp_pm_addr_entry *clone = NULL;
 
 			msk->pm.add_addr_signaled++;
+			WRITE_ONCE(msk->pm.add_addr_echo, false);
 			mptcp_pm_announce_addr(msk, &local->addr);

I suggest adding a parameter to mptcp_pm_announce_addr() for the echo bit, and setting msk->pm.add_addr_echo inside that function.

Quoted 16 lines
net/mptcp/pm_netlink.c +0 -0
 			clone = kmemdup(local, sizeof(*local), GFP_ATOMIC);
net/mptcp/protocol.h +1 -0
index ceca1ddea9f8..c4bc0d8f0995 100644
@@ -169,6 +169,7 @@ struct mptcp_pm_data {
 	bool		work_pending;
 	bool		accept_addr;
 	bool		accept_subflow;
+	bool		add_addr_echo;
 	u8		add_addr_signaled;
 	u8		add_addr_accepted;
 	u8		local_addr_used;
Signature · 1 line
2.17.1

Best regards,

--
Mat Martineau
Intel

author
#3 lore raw

PATCH v2 2/3 mptcp: add ADD_ADDR related mibs

In reply to Geliang Tang

This patch added two mibs for ADD_ADDR, MPTCP_MIB_ADDADDR for receiving of the ADD_ADDR suboption with echo-flag=0, and MPTCP_MIB_ECHOADD for receiving the ADD_ADDR suboption with echo-flag=1.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/mib.c     | 2 ++
 net/mptcp/mib.h     | 2 ++
 net/mptcp/options.c | 3 +++
 3 files changed, 7 insertions(+)
net/mptcp/mib.c +2 -0
index e71d3eebd924..376217405214 100644
@@ -27,6 +27,8 @@ static const struct snmp_mib mptcp_snmp_list[] = {
 	SNMP_MIB_ITEM("OFOMerge", MPTCP_MIB_OFOMERGE),
 	SNMP_MIB_ITEM("NoDSSInWindow", MPTCP_MIB_NODSSWINDOW),
 	SNMP_MIB_ITEM("DuplicateData", MPTCP_MIB_DUPDATA),
+	SNMP_MIB_ITEM("AddAddr", MPTCP_MIB_ADDADDR),
+	SNMP_MIB_ITEM("EchoAdd", MPTCP_MIB_ECHOADD),
 	SNMP_MIB_ITEM("RmAddr", MPTCP_MIB_RMADDR),
 	SNMP_MIB_SENTINEL
 };
net/mptcp/mib.h +2 -0
index 6d73818bbf7b..0b98a5e94c92 100644
@@ -20,6 +20,8 @@ enum linux_mptcp_mib_field {
 	MPTCP_MIB_OFOMERGE,		/* Segments merged in OoO queue */
 	MPTCP_MIB_NODSSWINDOW,		/* Segments not in MPTCP windows */
 	MPTCP_MIB_DUPDATA,		/* Segments discarded due to duplicate DSS */
+	MPTCP_MIB_ADDADDR,		/* Received ADD_ADDR with echo-flag=0 */
+	MPTCP_MIB_ECHOADD,		/* Received ADD_ADDR with echo-flag=1 */
 	MPTCP_MIB_RMADDR,		/* Received RM_ADDR */
 	__MPTCP_MIB_MAX
 };
net/mptcp/options.c +3 -0
index 6aa9a48322d7..9372ccd4a687 100644
@@ -893,6 +893,9 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 			WRITE_ONCE(msk->pm.add_addr_echo, true);
 			mptcp_pm_announce_addr(msk, &addr);
 			mptcp_pm_add_addr_received(msk, &addr);
+			__MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDR);
+		} else {
+			__MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADD);
 		}
 		mp_opt.add_addr = 0;
 	}
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH v2 3/3 selftests: mptcp: add ADD_ADDR mibs check function

In reply to Geliang Tang

This patch added the ADD_ADDR related mibs counter check function chk_add_nr(). This function check both ADD_ADDR and ADD_ADDR with echo flag.

The output looks like this:

07 unused signal address syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ]
08 signal address syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ]
09 subflow and signal syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ]
10 multiple subflows and signal syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ]
11 remove subflow and signal syn[ ok ] - synack[ ok ] - ack[ ok ]
add[ ok ] - echo [ ok ]

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 45 +++++++++++++++++++
 1 file changed, 45 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +45 -0
index 68c4243e2b22..4c46307c607b 100755
@@ -281,6 +281,43 @@ chk_join_nr()
 	fi
 }
 
+chk_add_nr()
+{
+	local add_nr=$1
+	local echo_nr=$2
+	local count
+	local dump_stats
+
+	printf "%-39s %s" " " "add"
+	count=`ip netns exec $ns2 nstat -as | grep MPTcpExtAddAddr | awk '{print $2}'`
+	[ -z "$count" ] && count=0
+	if [ "$count" != "$add_nr" ]; then
+		echo "[fail] got $count JOIN[s] ack expected $add_nr"
+		ret=1
+		dump_stats=1
+	else
+		echo -n "[ ok ]"
+	fi
+
+	echo -n " - echo "
+	count=`ip netns exec $ns1 nstat -as | grep MPTcpExtEchoAdd | awk '{print $2}'`
+	[ -z "$count" ] && count=0
+	if [ "$count" != "$echo_nr" ]; then
+		echo "[fail] got $count JOIN[s] ack expected $echo_nr"
+		ret=1
+		dump_stats=1
+	else
+		echo " [ ok ]"
+	fi
+
+	if [ "${dump_stats}" = 1 ]; then
+		echo Server ns stats
+		ip netns exec $ns1 nstat -as | grep MPTcp
+		echo Client ns stats
+		ip netns exec $ns2 nstat -as | grep MPTcp
+	fi
+}
+
 chk_rm_nr()
 {
 	local rm_nr_server=$1
@@ -374,6 +411,7 @@ reset
 ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "unused signal address" 0 0 0
+chk_add_nr 1 1
 
 # accept and use add_addr
 reset
@@ -382,6 +420,7 @@ 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 10.0.1.1
 chk_join_nr "signal address" 1 1 1
+chk_add_nr 1 1
 
 # accept and use add_addr with an additional subflow
 # note: signal address in server ns and local addresses in client ns must
@@ -394,6 +433,7 @@ ip netns exec $ns2 ./pm_nl_ctl limits 1 2
 ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "subflow and signal" 2 2 2
+chk_add_nr 1 1
 
 # accept and use add_addr with additional subflows
 reset
@@ -404,6 +444,7 @@ ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
 ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "multiple subflows and signal" 3 3 3
+chk_add_nr 1 1
 
 # remove subflow and signal
 reset
@@ -428,6 +469,7 @@ do_remove_addr()
 }
 do_transfer $ns1 $ns2 MPTCP MPTCP 10.0.1.1 do_remove_addr
 chk_join_nr "remove subflow and signal" 2 2 1
+chk_add_nr 1 1
 chk_rm_nr 1 1
 
 # single subflow, syncookies
@@ -463,6 +505,7 @@ 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 10.0.1.1
 chk_join_nr "signal address with syn cookies" 1 1 1
+chk_add_nr 1 1
 
 # test cookie with subflow and signal
 reset_with_cookies
@@ -472,6 +515,7 @@ ip netns exec $ns2 ./pm_nl_ctl limits 1 2
 ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "subflow and signal w cookies" 2 2 2
+chk_add_nr 1 1
 
 # accept and use add_addr with additional subflows
 reset_with_cookies
@@ -482,5 +526,6 @@ ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
 ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
 run_tests $ns1 $ns2 10.0.1.1
 chk_join_nr "subflows and signal w. cookies" 3 3 3
+chk_add_nr 1 1
 
 exit $ret
Signature · 1 line
2.17.1