Skip to contentSkip to conversation

add ADD_ADDR IPv6 support

PATCH Superseded Geliang Tang 2 participants 7 messages Oct 10, 2020 – Oct 13, 2020

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Geliang Tang

author
#0 lore raw

v4 cover add ADD_ADDR IPv6 support

v4:
- update the patches as Paolo suggested:
- change the 'add_addr_signal' type
- set MPTCP_ADD_ADDR_IPV6 in mptcp_pm_announce_addr
- add a new helper mptcp_send_dedicated_add_addr_packet to sent out a
new pure ACK packet
- drop other MPTCP suboptions in mptcp_established_options_add_addr

v3:
- drop other MPTCP suboptions instead of OPTION_TS

v2:
- avoid adding new field to tcp_sock, add new field in mptcp_pm_data.
- drop OPTION_TS in mptcp_established_options_add_addr, not in
tcp_established_options.

Geliang Tang (3):
mptcp: change add_addr_signal type
mptcp: send out dedicated ADD_ADDR packet
selftests: mptcp: add ADD_ADDR IPv6 test cases

 net/mptcp/options.c                           | 23 ++++++-
 net/mptcp/pm.c                                | 21 ++++---
 net/mptcp/pm_netlink.c                        | 37 +++++++++++
 net/mptcp/protocol.h                          | 13 +++-
 .../testing/selftests/net/mptcp/mptcp_join.sh | 61 ++++++++++++++++++-
 5 files changed, 140 insertions(+), 15 deletions(-)
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH v4 1/3 mptcp: change add_addr_signal type

This patch changed the 'add_addr_signal' type from bool to char, so that we could encode the addr type there.

Suggested-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm.c       | 12 ++++++------
 net/mptcp/protocol.h | 10 +++++++---
 2 files changed, 13 insertions(+), 9 deletions(-)
net/mptcp/pm.c +6 -6
index f9c88e2abb8e..5f453db36e54 100644
@@ -19,8 +19,9 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 	pr_debug("msk=%p, local_id=%d", msk, addr->id);
 
 	msk->pm.local = *addr;
-	WRITE_ONCE(msk->pm.add_addr_echo, echo);
-	WRITE_ONCE(msk->pm.add_addr_signal, true);
+	msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_SIGNAL);
+	if (echo)
+		msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_ECHO);
 	return 0;
 }
 
@@ -182,13 +183,13 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 	if (!mptcp_pm_should_add_signal(msk))
 		goto out_unlock;
 
-	*echo = READ_ONCE(msk->pm.add_addr_echo);
+	*echo = msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_ECHO);
 
 	if (remaining < mptcp_add_addr_len(msk->pm.local.family, *echo))
 		goto out_unlock;
 
 	*saddr = msk->pm.local;
-	WRITE_ONCE(msk->pm.add_addr_signal, false);
+	msk->pm.add_addr_signal = 0;
 	ret = true;
 
 out_unlock:
@@ -232,11 +233,10 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
 	msk->pm.subflows = 0;
 	msk->pm.rm_id = 0;
 	WRITE_ONCE(msk->pm.work_pending, false);
-	WRITE_ONCE(msk->pm.add_addr_signal, false);
+	msk->pm.add_addr_signal = 0;
 	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/protocol.h +7 -3
index 746413ab4f18..9eb2b1bff7f5 100644
@@ -165,6 +165,11 @@ enum mptcp_pm_status {
 	MPTCP_PM_SUBFLOW_ESTABLISHED,
 };
 
+enum mptcp_add_addr_status {
+	MPTCP_ADD_ADDR_SIGNAL,
+	MPTCP_ADD_ADDR_ECHO,
+};
+
 struct mptcp_pm_data {
 	struct mptcp_addr_info local;
 	struct mptcp_addr_info remote;
@@ -172,13 +177,12 @@ struct mptcp_pm_data {
 
 	spinlock_t	lock;		/*protects the whole PM data */
 
-	bool		add_addr_signal;
+	u8		add_addr_signal;
 	bool		rm_addr_signal;
 	bool		server_side;
 	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;
@@ -507,7 +511,7 @@ int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id);
 
 static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk)
 {
-	return READ_ONCE(msk->pm.add_addr_signal);
+	return msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_SIGNAL);
 }
 
 static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
Signature · 1 line
2.26.2
author
#2 lore raw

PATCH v4 2/3 mptcp: send out dedicated ADD_ADDR packet

When ADD_ADDR suboption includes an IPv6 address, the size is 28 octets. It will not fit when other MPTCP suboptions are included in this packet, e.g. DSS. So here we send out an ADD_ADDR dedicated packet to carry only ADD_ADDR suboption, no other MPTCP suboptions.

In mptcp_pm_announce_addr, we check whether this is an IPv6 ADD_ADDR. If it is, we set the flag MPTCP_ADD_ADDR_IPV6 to true. Then we call mptcp_send_dedicated_add_addr_packet to sent out a new pure ACK packet.

In mptcp_established_options_add_addr, we check whether this is a pure ACK packet for ADD_ADDR. If it is, we drop all other MPTCP suboptions in this packet, only put ADD_ADDR suboption in it.

Suggested-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/options.c    | 23 ++++++++++++++++++++---
 net/mptcp/pm.c         |  9 +++++++--
 net/mptcp/pm_netlink.c | 37 +++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.h   |  3 +++
 4 files changed, 67 insertions(+), 5 deletions(-)
net/mptcp/options.c +20 -3
index d601dd1ebe5e..7de9b5af72db 100644
@@ -243,7 +243,9 @@ 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, echo=%d", mp_opt->addr_id, mp_opt->echo);
+		pr_debug("ADD_ADDR%s: id=%d, echo=%d",
+			 (mp_opt->family == MPTCP_ADDR_IPVERSION_6) ? "6" : "",
+			 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;
@@ -572,17 +574,30 @@ static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 addr_id,
 }
 #endif
 
-static bool mptcp_established_options_add_addr(struct sock *sk,
+static bool mptcp_established_options_add_addr(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);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
+	bool drop_other_suboptions = false;
+	unsigned int opt_size = *size;
 	struct mptcp_addr_info saddr;
 	bool echo;
 	int len;
 
+	if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6) &&
+	    msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_SEND_ACK) &&
+	    skb && skb_is_tcp_pure_ack(skb)) {
+		msk->pm.add_addr_signal &= ~BIT(MPTCP_ADD_ADDR_IPV6);
+
+		pr_debug("drop other suboptions");
+		opts->suboptions = 0;
+		remaining += opt_size;
+		drop_other_suboptions = true;
+	}
+
 	if (!mptcp_pm_should_add_signal(msk) ||
 	    !(mptcp_pm_add_addr_signal(msk, remaining, &saddr, &echo)))
 		return false;
@@ -592,6 +607,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk,
 		return false;
 
 	*size = len;
+	if (drop_other_suboptions)
+		*size -= opt_size;
 	opts->addr_id = saddr.id;
 	if (saddr.family == AF_INET) {
 		opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
@@ -671,7 +688,7 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
 
 	*size += opt_size;
 	remaining -= opt_size;
-	if (mptcp_established_options_add_addr(sk, &opt_size, remaining, opts)) {
+	if (mptcp_established_options_add_addr(sk, skb, &opt_size, remaining, opts)) {
 		*size += opt_size;
 		remaining -= opt_size;
 		ret = true;
net/mptcp/pm.c +7 -2
index 5f453db36e54..da99f8e24702 100644
@@ -22,6 +22,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 	msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_SIGNAL);
 	if (echo)
 		msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_ECHO);
+	if (addr->family == AF_INET6)
+		msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_IPV6);
 	return 0;
 }
 
@@ -150,10 +152,13 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
 
 	spin_lock_bh(&pm->lock);
 
-	if (!READ_ONCE(pm->accept_addr))
+	if (!READ_ONCE(pm->accept_addr)) {
 		mptcp_pm_announce_addr(msk, addr, true);
-	else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED))
+		if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6))
+			mptcp_send_dedicated_add_addr_packet(msk);
+	} else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) {
 		pm->remote = *addr;
+	}
 
 	spin_unlock_bh(&pm->lock);
 }
net/mptcp/pm_netlink.c +37 -0
index ed60538df7b2..9ca0603bfa19 100644
@@ -229,6 +229,8 @@ 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);
+		if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6))
+			mptcp_send_dedicated_add_addr_packet(msk);
 		entry->retrans_times++;
 	}
 
@@ -306,6 +308,31 @@ void mptcp_pm_free_anno_list(struct mptcp_sock *msk)
 	}
 }
 
+void mptcp_send_dedicated_add_addr_packet(struct mptcp_sock *msk)
+{
+	struct mptcp_subflow_context *subflow;
+
+	if (list_empty(&msk->conn_list))
+		return;
+
+	mptcp_for_each_subflow(msk, subflow) {
+		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+		if (!(msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_SEND_ACK))) {
+			msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_SEND_ACK);
+
+			spin_unlock_bh(&msk->pm.lock);
+			pr_debug("send ack for add_addr6");
+			tcp_send_ack(ssk);
+			spin_lock_bh(&msk->pm.lock);
+
+			msk->pm.add_addr_signal &= ~BIT(MPTCP_ADD_ADDR_SEND_ACK);
+
+			return;
+		}
+	}
+}
+
 static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 {
 	struct mptcp_addr_info remote = { 0 };
@@ -329,6 +356,13 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 			if (mptcp_pm_alloc_anno_list(msk, local)) {
 				msk->pm.add_addr_signaled++;
 				mptcp_pm_announce_addr(msk, &local->addr, false);
+
+				if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6)) {
+					spin_unlock_bh(&msk->pm.lock);
+					msleep(500);
+					spin_lock_bh(&msk->pm.lock);
+					mptcp_send_dedicated_add_addr_packet(msk);
+				}
 			}
 		} else {
 			/* pick failed, avoid fourther attempts later */
@@ -399,6 +433,9 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
 	spin_lock_bh(&msk->pm.lock);
 
 	mptcp_pm_announce_addr(msk, &remote, true);
+
+	if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6))
+		mptcp_send_dedicated_add_addr_packet(msk);
 }
 
 void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
net/mptcp/protocol.h +3 -0
index 9eb2b1bff7f5..6aeedbd46c82 100644
@@ -168,6 +168,8 @@ enum mptcp_pm_status {
 enum mptcp_add_addr_status {
 	MPTCP_ADD_ADDR_SIGNAL,
 	MPTCP_ADD_ADDR_ECHO,
+	MPTCP_ADD_ADDR_IPV6,
+	MPTCP_ADD_ADDR_SEND_ACK,
 };
 
 struct mptcp_pm_data {
@@ -506,6 +508,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);
+void mptcp_send_dedicated_add_addr_packet(struct mptcp_sock *msk);
 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
#3 lore raw

PATCH v4 3/3 selftests: mptcp: add ADD_ADDR IPv6 test cases

This patch added IPv6 support for do_transfer, and the test cases for ADD_ADDR IPv6.

Suggested-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 61 ++++++++++++++++++-
 1 file changed, 60 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +60 -1
index 3767acb9bb12..97fd3cc4a855 100755
@@ -154,6 +154,12 @@ do_ping()
 	fi
 }
 
+# $1: IP address
+is_v6()
+{
+	[ -z "${1##*:*}" ]
+}
+
 do_transfer()
 {
 	listener_ns="$1"
@@ -194,7 +200,15 @@ do_transfer()
 		mptcp_connect="./mptcp_connect -r"
 	fi
 
-	ip netns exec ${listener_ns} $mptcp_connect -t $timeout -l -p $port -s ${srv_proto} 0.0.0.0 < "$sin" > "$sout" &
+	local local_addr
+	if is_v6 "${connect_addr}"; then
+		local_addr="::"
+	else
+		local_addr="0.0.0.0"
+	fi
+
+	ip netns exec ${listener_ns} $mptcp_connect -t $timeout -l -p $port \
+		-s ${srv_proto} ${local_addr} < "$sin" > "$sout" &
 	spid=$!
 
 	sleep 1
@@ -568,6 +582,51 @@ chk_join_nr "remove subflows and signal" 3 3 3
 chk_add_nr 1 1
 chk_rm_nr 2 2
 
+# subflow IPv6
+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:3::2 flags subflow
+run_tests $ns1 $ns2 dead:beef:1::1 0 0 slow
+chk_join_nr "single subflow IPv6" 1 1 1
+
+# add_address, unused IPv6
+reset
+ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
+run_tests $ns1 $ns2 dead:beef:1::1 0 0 slow
+chk_join_nr "unused signal address IPv6" 0 0 0
+chk_add_nr 1 1
+
+# signal address IPv6
+reset
+ip netns exec $ns1 ./pm_nl_ctl limits 0 1
+ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
+ip netns exec $ns2 ./pm_nl_ctl limits 1 1
+run_tests $ns1 $ns2 dead:beef:1::1 0 0 slow
+chk_join_nr "single address IPv6" 1 1 1
+chk_add_nr 1 1
+
+# single address IPv6, remove
+reset
+ip netns exec $ns1 ./pm_nl_ctl limits 0 1
+ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
+ip netns exec $ns2 ./pm_nl_ctl limits 1 1
+run_tests $ns1 $ns2 dead:beef:1::1 1 0 slow
+chk_join_nr "remove single address IPv6" 1 1 1
+chk_add_nr 1 1
+chk_rm_nr 0 0
+
+# subflow and signal IPv6, remove
+reset
+ip netns exec $ns1 ./pm_nl_ctl limits 0 2
+ip netns exec $ns1 ./pm_nl_ctl add dead:beef:2::1 flags signal
+ip netns exec $ns2 ./pm_nl_ctl limits 1 2
+ip netns exec $ns2 ./pm_nl_ctl add dead:beef:3::2 flags subflow
+run_tests $ns1 $ns2 dead:beef:1::1 1 1 slow
+chk_join_nr "remove subflow and signal IPv6" 2 2 2
+chk_add_nr 1 1
+chk_rm_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
#4 lore raw

[MPTCP] Re: [MPTCP][PATCH v4 mptcp-next 2/3] mptcp: send out dedicated ADD_ADDR packet

In reply to Geliang Tang
Quoted 47 lines · Geliang Tang

When ADD_ADDR suboption includes an IPv6 address, the size is 28 octets. It will not fit when other MPTCP suboptions are included in this packet, e.g. DSS. So here we send out an ADD_ADDR dedicated packet to carry only ADD_ADDR suboption, no other MPTCP suboptions.

In mptcp_pm_announce_addr, we check whether this is an IPv6 ADD_ADDR. If it is, we set the flag MPTCP_ADD_ADDR_IPV6 to true. Then we call mptcp_send_dedicated_add_addr_packet to sent out a new pure ACK packet.

In mptcp_established_options_add_addr, we check whether this is a pure ACK packet for ADD_ADDR. If it is, we drop all other MPTCP suboptions in this packet, only put ADD_ADDR suboption in it.

Suggested-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/options.c    | 23 ++++++++++++++++++++---
 net/mptcp/pm.c         |  9 +++++++--
 net/mptcp/pm_netlink.c | 37 +++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.h   |  3 +++
 4 files changed, 67 insertions(+), 5 deletions(-)
net/mptcp/options.c +4 -2
index d601dd1ebe5e..7de9b5af72db 100644
@@ -243,7 +243,9 @@ 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, echo=%d", mp_opt->addr_id, mp_opt->echo);
+		pr_debug("ADD_ADDR%s: id=%d, echo=%d",
+			 (mp_opt->family == MPTCP_ADDR_IPVERSION_6) ? "6" : "",
+			 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;
@@ -572,17 +574,30 @@ static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 addr_id,
 }
 #endif
 
-static bool mptcp_established_options_add_addr(struct sock *sk,
+static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *skb,
 					       unsigned int *size,
 					       unsigned int remaining,
 					       struct mptcp_out_options *opts)
 {

net/mptcp/options.c static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 addr_id, · line 591

Quoted 10 lines
net/mptcp/options.c +4 -0
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
+	bool drop_other_suboptions = false;
+	unsigned int opt_size = *size;
 	struct mptcp_addr_info saddr;
 	bool echo;
 	int len;
 
+	if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6) &&
+	    msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_SEND_ACK) &&

Why is the 'MPTCP_ADD_ADDR_SEND_ACK' bit required? can't we simply check the other conditions ???

Quoted 44 lines
net/mptcp/options.c +12 -1
+	    skb && skb_is_tcp_pure_ack(skb)) {
+		msk->pm.add_addr_signal &= ~BIT(MPTCP_ADD_ADDR_IPV6);
+
+		pr_debug("drop other suboptions");
+		opts->suboptions = 0;
+		remaining += opt_size;
+		drop_other_suboptions = true;
+	}
+
 	if (!mptcp_pm_should_add_signal(msk) ||
 	    !(mptcp_pm_add_addr_signal(msk, remaining, &saddr, &echo)))
 		return false;
@@ -592,6 +607,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk,
 		return false;
 
 	*size = len;
+	if (drop_other_suboptions)
+		*size -= opt_size;
 	opts->addr_id = saddr.id;
 	if (saddr.family == AF_INET) {
 		opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
@@ -671,7 +688,7 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
 
 	*size += opt_size;
 	remaining -= opt_size;
-	if (mptcp_established_options_add_addr(sk, &opt_size, remaining, opts)) {
+	if (mptcp_established_options_add_addr(sk, skb, &opt_size, remaining, opts)) {
 		*size += opt_size;
 		remaining -= opt_size;
 		ret = true;
net/mptcp/pm.c +2 -0
index 5f453db36e54..da99f8e24702 100644
@@ -22,6 +22,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 	msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_SIGNAL);
 	if (echo)
 		msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_ECHO);
+	if (addr->family == AF_INET6)
+		msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_IPV6);
 	return 0;
 }
 

net/mptcp/pm.c void mptcp_pm_add_addr_received(struct mptcp_sock *msk, · line 158

Quoted 9 lines
net/mptcp/pm.c +3 -2
@@ -150,10 +152,13 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
 
 	spin_lock_bh(&pm->lock);
 
-	if (!READ_ONCE(pm->accept_addr))
+	if (!READ_ONCE(pm->accept_addr)) {
 		mptcp_pm_announce_addr(msk, addr, true);
-	else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED))
+		if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6))
+			mptcp_send_dedicated_add_addr_packet(msk);

I *think* that moving the mptcp_send_dedicated_add_addr_packet() call outside the pm_lock will simplify the code,
as mptcp_send_dedicated_add_addr_packet() will not need to release/acquire it again and the move shoud not be problematic in all call-site.

I would try to set a local bool variable inside under the pm lock scope when the pure ack is needed and test such variable after releasing the lock itself.

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

Quoted 8 lines
net/mptcp/pm.c +4 -0
@@ -329,6 +356,13 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 			if (mptcp_pm_alloc_anno_list(msk, local)) {
 				msk->pm.add_addr_signaled++;
 				mptcp_pm_announce_addr(msk, &local->addr, false);
+
+				if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6)) {
+					spin_unlock_bh(&msk->pm.lock);
+					msleep(500);

???
I fear this is not upstream acceptable. Why such delay is needed? We need to resolve such need without the delay.

net/mptcp/pm.c void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) · line 438

Quoted 7 lines
net/mptcp/pm.c +3 -0
@@ -399,6 +433,9 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
 	spin_lock_bh(&msk->pm.lock);
 
 	mptcp_pm_announce_addr(msk, &remote, true);
+
+	if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6))
+		mptcp_send_dedicated_add_addr_packet(msk);

If mptcp_send_dedicated_add_addr_packet() is modified to avoid pm lock dance, the mptcp_pm_announce_addr() should be moved a bit above:

// -> here

	spin_unlock_bh(&msk->pm.lock);

// and here -> we should call mptcp_send_dedicated_add_addr_packet(msk);

        __mptcp_subflow_connect((struct sock *)msk, &local, &remote);

net/mptcp/pm.c void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) · line 441

Quoted 3 lines
net/mptcp/pm.c +0 -0
 }
 
 void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)

Please reach for me on IRC if the above feedback is confusing!

Cheers,

Paolo

author
#5 lore raw

[MPTCP] Re: [MPTCP][PATCH v4 mptcp-next 2/3] mptcp: send out dedicated ADD_ADDR packet

Hi Paolo,

Thanks for your reply.

Quoted 57 lines · Paolo Abeni <pabeni(a)redhat.com> 于2020年10月13日周二 上午12:18写道:
Quoted 55 lines · Geliang Tang

When ADD_ADDR suboption includes an IPv6 address, the size is 28 octets. It will not fit when other MPTCP suboptions are included in this packet, e.g. DSS. So here we send out an ADD_ADDR dedicated packet to carry only ADD_ADDR suboption, no other MPTCP suboptions.

In mptcp_pm_announce_addr, we check whether this is an IPv6 ADD_ADDR. If it is, we set the flag MPTCP_ADD_ADDR_IPV6 to true. Then we call mptcp_send_dedicated_add_addr_packet to sent out a new pure ACK packet.

In mptcp_established_options_add_addr, we check whether this is a pure ACK packet for ADD_ADDR. If it is, we drop all other MPTCP suboptions in this packet, only put ADD_ADDR suboption in it.

Suggested-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/options.c    | 23 ++++++++++++++++++++---
 net/mptcp/pm.c         |  9 +++++++--
 net/mptcp/pm_netlink.c | 37 +++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.h   |  3 +++
 4 files changed, 67 insertions(+), 5 deletions(-)
net/mptcp/options.c +6 -2
index d601dd1ebe5e..7de9b5af72db 100644
@@ -243,7 +243,9 @@ 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, echo=%d", mp_opt->addr_id, mp_opt->echo);
+             pr_debug("ADD_ADDR%s: id=%d, echo=%d",
+                      (mp_opt->family == MPTCP_ADDR_IPVERSION_6) ? "6" : "",
+                      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;
@@ -572,17 +574,30 @@ static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 addr_id,
 }
 #endif
 
-static bool mptcp_established_options_add_addr(struct sock *sk,
+static bool mptcp_established_options_add_addr(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);
      struct mptcp_sock *msk = mptcp_sk(subflow->conn);
+     bool drop_other_suboptions = false;
+     unsigned int opt_size = *size;
      struct mptcp_addr_info saddr;
      bool echo;
      int len;
 
Quoted 5 lines

net/mptcp/options.c static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 addr_id, · line 591

Quoted 2 lines
net/mptcp/options.c +2 -0
+     if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6) &&
+         msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_SEND_ACK) &&

Why is the 'MPTCP_ADD_ADDR_SEND_ACK' bit required? can't we simply check the other conditions ???

The other conditions, MPTCP_ADD_ADDR_IPV6 and pure ACK test, are not sufficient here, since there are some other ACK packets, which aren't sent by mptcp_send_dedicated_add_addr_packet, can meet these conditions. We can't drop suboptions in those ACK packets, we can only drop suboptions in the ACK packet sent by mptcp_send_dedicated_add_addr_packet.

So here I added a new bit MPTCP_ADD_ADDR_SEND_ACK, to identify the pure ACK packet which has been sent by mptcp_send_dedicated_add_addr_packet.

Quoted 65 lines
Quoted 45 lines
net/mptcp/options.c +12 -1
+         skb && skb_is_tcp_pure_ack(skb)) {
+             msk->pm.add_addr_signal &= ~BIT(MPTCP_ADD_ADDR_IPV6);
+
+             pr_debug("drop other suboptions");
+             opts->suboptions = 0;
+             remaining += opt_size;
+             drop_other_suboptions = true;
+     }
+
      if (!mptcp_pm_should_add_signal(msk) ||
          !(mptcp_pm_add_addr_signal(msk, remaining, &saddr, &echo)))
              return false;
@@ -592,6 +607,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk,
              return false;
 
      *size = len;
+     if (drop_other_suboptions)
+             *size -= opt_size;
      opts->addr_id = saddr.id;
      if (saddr.family == AF_INET) {
              opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
@@ -671,7 +688,7 @@ bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
 
      *size += opt_size;
      remaining -= opt_size;
-     if (mptcp_established_options_add_addr(sk, &opt_size, remaining, opts)) {
+     if (mptcp_established_options_add_addr(sk, skb, &opt_size, remaining, opts)) {
              *size += opt_size;
              remaining -= opt_size;
              ret = true;
net/mptcp/pm.c +2 -0
index 5f453db36e54..da99f8e24702 100644
@@ -22,6 +22,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
      msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_SIGNAL);
      if (echo)
              msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_ECHO);
+     if (addr->family == AF_INET6)
+             msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_IPV6);
      return 0;
 }
 

net/mptcp/pm.c void mptcp_pm_add_addr_received(struct mptcp_sock *msk, · line 158

Quoted 9 lines
net/mptcp/pm.c +3 -2
@@ -150,10 +152,13 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
 
      spin_lock_bh(&pm->lock);
 
-     if (!READ_ONCE(pm->accept_addr))
+     if (!READ_ONCE(pm->accept_addr)) {
              mptcp_pm_announce_addr(msk, addr, true);
-     else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED))
+             if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6))
+                     mptcp_send_dedicated_add_addr_packet(msk);

I *think* that moving the mptcp_send_dedicated_add_addr_packet() call outside the pm_lock will simplify the code,
as mptcp_send_dedicated_add_addr_packet() will not need to release/acquire it again and the move shoud not be problematic in all call-site.

I would try to set a local bool variable inside under the pm lock scope when the pure ack is needed and test such variable after releasing the lock itself.

Quoted 12 lines

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

Quoted 8 lines
net/mptcp/pm.c +4 -0
@@ -329,6 +356,13 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
                      if (mptcp_pm_alloc_anno_list(msk, local)) {
                              msk->pm.add_addr_signaled++;
                              mptcp_pm_announce_addr(msk, &local->addr, false);
+
+                             if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6)) {
+                                     spin_unlock_bh(&msk->pm.lock);
+                                     msleep(500);

???
I fear this is not upstream acceptable. Why such delay is needed? We need to resolve such need without the delay.

Sorry about the ugly code here. If we called mptcp_send_dedicated_add_addr_packet
with no delay in mptcp_pm_create_subflow_or_signal_addr, mptcp_send_dedicated_add_addr_packet can't work at this moment. Since msk->conn_list
is empty at the moment, there is no subflow to send out the ACK packet.

So I added the delay here to wait until the subflow has been added to the msk->conn_list.
I knew this code is acceptable, but I have no idea about how to fix this, please give me
some suggestions about it.

Thanks.

-Geliang

Quoted 29 lines

net/mptcp/pm.c void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) · line 438

Quoted 8 lines
net/mptcp/pm.c +3 -0
@@ -399,6 +433,9 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
      spin_lock_bh(&msk->pm.lock);
 
      mptcp_pm_announce_addr(msk, &remote, true);
+
+     if (msk->pm.add_addr_signal & BIT(MPTCP_ADD_ADDR_IPV6))
+             mptcp_send_dedicated_add_addr_packet(msk);

If mptcp_send_dedicated_add_addr_packet() is modified to avoid pm lock dance, the mptcp_pm_announce_addr() should be moved a bit above:

// -> here

        spin_unlock_bh(&msk->pm.lock);

// and here -> we should call mptcp_send_dedicated_add_addr_packet(msk);

        __mptcp_subflow_connect((struct sock *)msk, &local, &remote);

net/mptcp/pm.c void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) · line 441

Quoted 3 lines
net/mptcp/pm.c +0 -0
 }
 
 void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)

Please reach for me on IRC if the above feedback is confusing!

Cheers,

Paolo

#6 lore raw

[MPTCP] Re: [MPTCP][PATCH v4 mptcp-next 1/3] mptcp: change add_addr_signal type

In reply to Geliang Tang
Quoted 15 lines · Geliang Tang

This patch changed the 'add_addr_signal' type from bool to char, so that we could encode the addr type there.

Suggested-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm.c       | 12 ++++++------
 net/mptcp/protocol.h | 10 +++++++---
 2 files changed, 13 insertions(+), 9 deletions(-)
net/mptcp/pm.c +0 -0
index f9c88e2abb8e..5f453db36e54 100644

net/mptcp/pm.c int mptcp_pm_announce_addr(struct mptcp_sock *msk, · line 24

Quoted 8 lines
net/mptcp/pm.c +3 -2
@@ -19,8 +19,9 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 	pr_debug("msk=%p, local_id=%d", msk, addr->id);
 
 	msk->pm.local = *addr;
-	WRITE_ONCE(msk->pm.add_addr_echo, echo);
-	WRITE_ONCE(msk->pm.add_addr_signal, true);
+	msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_SIGNAL);
+	if (echo)
+		msk->pm.add_addr_signal |= BIT(MPTCP_ADD_ADDR_ECHO);

I think we need to preserve the barriers.

Under spin lock protection we need the WRITE_ONCE() when writing the field, outside the spinlock protection we need the READ_ONCE() to access it.

The above should be something alike:

	u8 add_addr = msk->pm.add_addr_signal;

	[...]
	add_addr |= BIT(MPTCP_ADD_ADDR_SIGNAL);
	if (echo)
		add_addr |= BIT(MPTCP_ADD_ADDR_ECHO);
	WRITE_ONCE(msk->pm.add_addr_signal, add_addr);

/P