MPTCP Linux Development
 help / color / Atom feed
* [PATCH v7 0/4] mptcp: fix conflicts when using pm.add_signal in ADD_ADDR/echo and RM_ADDR process
@ 2021-06-30 10:24 Yonglong Li
  2021-06-30 10:24 ` [PATCH v7 1/5] mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other Yonglong Li
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Yonglong Li @ 2021-06-30 10:24 UTC (permalink / raw)
  To: mptcp; +Cc: mathew.j.martineau, geliangtang, Yonglong Li

fix issue: ADD_ADDR and RM_ADDR use pm.add_signal to mark event, so 
in some case pm.add_signal will be flush when ADD_ADDR/RM_ADDR in 
process.

fix issue: if ADD_ADDR and ADD_ADDR-echo process at the same time, 
only one event can write pm.add_signal. so ADD_ADDR will process 
after add_timer timeout or ADD_ADDR-echo will not be process.

Patch 1 fix ADD_ADDR and RM_ADDR maybe clear addr_signal each other.

Patch 2 and 3 deal ADD_ADDR and ADD_ADDR-echo with separately to fix 
conflicts in using pm.addr_signal porcess.

Patch 4 MPTCP_ADD_ADDR_IPV6 and MPTCP_ADD_ADDR_PORT is not necessary.

v1->v2:
 - remove READ_ONCE under the pm spin lock.

v2->v3:
 - Patch 2: mptcp_pm_should_add_addr => mptcp_pm_should_add_signal_addr
 - Patch 3: avoid read-modify-write of msk->pm.addr_signal and change  
   mptcp_pm_add_addr_signal to return void.

v3->v4:
 - Patch 1: use ~(BIT(MPTCP_ADD_ADDR_SIGNAL) | BIT(MPTCP_ADD_ADDR_ECHO)) 
   instead of BIT(MPTCP_RM_ADDR_SIGNAL)
 - Patch 3: simple the code; init flags; fix wrong goto logic code; 

v4->v5:
 - Patch 3: simple the code of 'mptcp_established_options_add_addr'

v5->v6:
 - Patch2: fix fails of 'mptcp_join.sh -t'. In mptcp_pm_add_addr_send_ack 
   without MPTCP_ADD_ADDR_SIGNAL check so pure ack can not be sent for 
   ADD_ADDR. That cause ADD_ADDR can not be sent in time.
 - Patch3: refactor some code according Geliang's suggestions.
 - Patch4: modify commit comment

v6->v7:
 - Patch1: use reverse xmas tree order for variables definition
 - Patch3: refactor some code according Geliang's suggestions.
 - add a Patch4: remove some double-check

Yonglong Li (5):
  mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other
  mptcp: make MPTCP_ADD_ADDR_SIGNAL and MPTCP_ADD_ADDR_ECHO separate
  mptcp: build ADD_ADDR/echo-ADD_ADDR option according pm.add_signal
  mptcp: remove some double-check
  mptcp: remove MPTCP_ADD_ADDR_IPV6 and MPTCP_ADD_ADDR_PORT

 include/net/mptcp.h    |  3 ++-
 net/mptcp/options.c    | 64 ++++++++++++++++++++++-------------------------
 net/mptcp/pm.c         | 68 +++++++++++++++++++++++++++++++-------------------
 net/mptcp/pm_netlink.c | 10 +++-----
 net/mptcp/protocol.h   | 45 +++++++++++++++++----------------
 5 files changed, 103 insertions(+), 87 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v7 1/5] mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other
  2021-06-30 10:24 [PATCH v7 0/4] mptcp: fix conflicts when using pm.add_signal in ADD_ADDR/echo and RM_ADDR process Yonglong Li
@ 2021-06-30 10:24 ` Yonglong Li
  2021-06-30 10:37   ` Geliang Tang
  2021-06-30 10:24 ` [PATCH v7 2/5] mptcp: make MPTCP_ADD_ADDR_SIGNAL and MPTCP_ADD_ADDR_ECHO separate Yonglong Li
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Yonglong Li @ 2021-06-30 10:24 UTC (permalink / raw)
  To: mptcp; +Cc: mathew.j.martineau, geliangtang, Yonglong Li

ADD_ADDR share pm.addr_signal with RM_ADDR, so after RM_ADDR/ADD_ADDR
done we should not clean ADD_ADDR/RM_ADDR's addr_signal.

Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
---
 net/mptcp/pm.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 9d00fa6..50079e5 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -253,6 +253,7 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 			      struct mptcp_addr_info *saddr, bool *echo, bool *port)
 {
 	int ret = false;
+	u8 add_addr;
 
 	spin_lock_bh(&msk->pm.lock);
 
@@ -267,7 +268,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 		goto out_unlock;
 
 	*saddr = msk->pm.local;
-	WRITE_ONCE(msk->pm.addr_signal, 0);
+	add_addr = msk->pm.addr_signal & ~(BIT(MPTCP_ADD_ADDR_SIGNAL) | BIT(MPTCP_ADD_ADDR_ECHO));
+	WRITE_ONCE(msk->pm.addr_signal, add_addr);
 	ret = true;
 
 out_unlock:
@@ -279,6 +281,7 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 			     struct mptcp_rm_list *rm_list)
 {
 	int ret = false, len;
+	u8 rm_addr;
 
 	spin_lock_bh(&msk->pm.lock);
 
@@ -286,16 +289,17 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 	if (!mptcp_pm_should_rm_signal(msk))
 		goto out_unlock;
 
+	rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
 	len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
 	if (len < 0) {
-		WRITE_ONCE(msk->pm.addr_signal, 0);
+		WRITE_ONCE(msk->pm.addr_signal, rm_addr);
 		goto out_unlock;
 	}
 	if (remaining < len)
 		goto out_unlock;
 
 	*rm_list = msk->pm.rm_list_tx;
-	WRITE_ONCE(msk->pm.addr_signal, 0);
+	WRITE_ONCE(msk->pm.addr_signal, rm_addr);
 	ret = true;
 
 out_unlock:
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v7 2/5] mptcp: make MPTCP_ADD_ADDR_SIGNAL and MPTCP_ADD_ADDR_ECHO separate
  2021-06-30 10:24 [PATCH v7 0/4] mptcp: fix conflicts when using pm.add_signal in ADD_ADDR/echo and RM_ADDR process Yonglong Li
  2021-06-30 10:24 ` [PATCH v7 1/5] mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other Yonglong Li
@ 2021-06-30 10:24 ` Yonglong Li
  2021-06-30 10:24 ` [PATCH v7 3/5] mptcp: build ADD_ADDR/echo-ADD_ADDR option according pm.add_signal Yonglong Li
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Yonglong Li @ 2021-06-30 10:24 UTC (permalink / raw)
  To: mptcp; +Cc: mathew.j.martineau, geliangtang, Yonglong Li

MPTCP_ADD_ADDR_SIGNAL only for action of sending ADD_ADDR
MPTCP_ADD_ADDR_ECHO only for action of sending echo ADD_ADDR
add a mptcp_addr_info in struct mptcp_out_options for echo ADD_ADDR

to prepare for the next patch.

Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
---
 net/mptcp/pm.c         | 16 ++++++++++------
 net/mptcp/pm_netlink.c |  4 ++--
 net/mptcp/protocol.h   |  6 ++++++
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 50079e5..0dc9021 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -18,19 +18,23 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 {
 	u8 add_addr = READ_ONCE(msk->pm.addr_signal);
 
-	pr_debug("msk=%p, local_id=%d", msk, addr->id);
+	pr_debug("msk=%p, local_id=%d, echo:%d", msk, addr->id, echo);
 
 	lockdep_assert_held(&msk->pm.lock);
 
-	if (add_addr) {
-		pr_warn("addr_signal error, add_addr=%d", add_addr);
+	if (add_addr &
+	    (echo ? BIT(MPTCP_ADD_ADDR_ECHO) : BIT(MPTCP_ADD_ADDR_SIGNAL))) {
+		pr_warn("addr_signal error, add_addr=%d, echo=%d", add_addr, echo);
 		return -EINVAL;
 	}
 
-	msk->pm.local = *addr;
-	add_addr |= BIT(MPTCP_ADD_ADDR_SIGNAL);
-	if (echo)
+	if (echo) {
+		msk->pm.remote = *addr;
 		add_addr |= BIT(MPTCP_ADD_ADDR_ECHO);
+	} else {
+		msk->pm.local = *addr;
+		add_addr |= BIT(MPTCP_ADD_ADDR_SIGNAL);
+	}
 	if (addr->family == AF_INET6)
 		add_addr |= BIT(MPTCP_ADD_ADDR_IPV6);
 	if (addr->port)
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index d4732a4..0f302d2 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -317,14 +317,14 @@ static void mptcp_pm_add_timer(struct timer_list *timer)
 	if (!entry->addr.id)
 		return;
 
-	if (mptcp_pm_should_add_signal(msk)) {
+	if (mptcp_pm_should_add_signal_addr(msk)) {
 		sk_reset_timer(sk, timer, jiffies + TCP_RTO_MAX / 8);
 		goto out;
 	}
 
 	spin_lock_bh(&msk->pm.lock);
 
-	if (!mptcp_pm_should_add_signal(msk)) {
+	if (!mptcp_pm_should_add_signal_addr(msk)) {
 		pr_debug("retransmit ADD_ADDR id=%d", entry->addr.id);
 		mptcp_pm_announce_addr(msk, &entry->addr, false);
 		mptcp_pm_add_addr_send_ack(msk);
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 160c2ab..a0b0ec0 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -708,6 +708,12 @@ void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
 
 static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk)
 {
+	return READ_ONCE(msk->pm.addr_signal) &
+		(BIT(MPTCP_ADD_ADDR_SIGNAL) | BIT(MPTCP_ADD_ADDR_ECHO));
+}
+
+static inline bool mptcp_pm_should_add_signal_addr(struct mptcp_sock *msk)
+{
 	return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_ADD_ADDR_SIGNAL);
 }
 
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v7 3/5] mptcp: build ADD_ADDR/echo-ADD_ADDR option according pm.add_signal
  2021-06-30 10:24 [PATCH v7 0/4] mptcp: fix conflicts when using pm.add_signal in ADD_ADDR/echo and RM_ADDR process Yonglong Li
  2021-06-30 10:24 ` [PATCH v7 1/5] mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other Yonglong Li
  2021-06-30 10:24 ` [PATCH v7 2/5] mptcp: make MPTCP_ADD_ADDR_SIGNAL and MPTCP_ADD_ADDR_ECHO separate Yonglong Li
@ 2021-06-30 10:24 ` Yonglong Li
  2021-06-30 11:14   ` Geliang Tang
  2021-06-30 10:24 ` [PATCH v7 4/5] mptcp: remove some double-check Yonglong Li
  2021-06-30 10:24 ` [PATCH v7 5/5] mptcp: remove MPTCP_ADD_ADDR_IPV6 and MPTCP_ADD_ADDR_PORT Yonglong Li
  4 siblings, 1 reply; 13+ messages in thread
From: Yonglong Li @ 2021-06-30 10:24 UTC (permalink / raw)
  To: mptcp; +Cc: mathew.j.martineau, geliangtang, Yonglong Li

according MPTCP_ADD_ADDR_SIGNAL and MPTCP_ADD_ADDR_ECHO flag build
ADD_ADDR/echo-ADD_ADDR option

add a suboptions type OPTION_MPTCP_ADD_ECHO to mark as echo option

Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
---
 include/net/mptcp.h  |  3 ++-
 net/mptcp/options.c  | 54 +++++++++++++++++++++++++++++-----------------------
 net/mptcp/pm.c       | 35 +++++++++++++++++++++++-----------
 net/mptcp/protocol.h | 25 ++++++++++++++++--------
 4 files changed, 73 insertions(+), 44 deletions(-)

diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index d61bbbf..d2c6ebe 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -61,7 +61,8 @@ struct mptcp_out_options {
 	u64 sndr_key;
 	u64 rcvr_key;
 	u64 ahmac;
-	struct mptcp_addr_info addr;
+	struct mptcp_addr_info local;
+	struct mptcp_addr_info remote;
 	struct mptcp_rm_list rm_list;
 	u8 join_id;
 	u8 backup;
diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 1aec016..cceff0a 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -655,13 +655,16 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 	bool drop_other_suboptions = false;
 	unsigned int opt_size = *size;
-	bool echo;
-	bool port;
-	int len;
+	u8 add_addr;
+	int len = 0;
 
-	if ((mptcp_pm_should_add_signal_ipv6(msk) ||
-	     mptcp_pm_should_add_signal_port(msk) ||
-	     mptcp_pm_should_add_signal_echo(msk)) &&
+	if (!mptcp_pm_should_add_signal(msk) ||
+	    !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr))
+		return false;
+
+	if (((add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) ||
+	     ((add_addr & BIT(MPTCP_ADD_ADDR_SIGNAL)) &&
+	      (opts->local.family == AF_INET6 || opts->local.port))) &&
 	    skb && skb_is_tcp_pure_ack(skb)) {
 		pr_debug("drop other suboptions");
 		opts->suboptions = 0;
@@ -671,11 +674,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 		drop_other_suboptions = true;
 	}
 
-	if (!mptcp_pm_should_add_signal(msk) ||
-	    !(mptcp_pm_add_addr_signal(msk, remaining, &opts->addr, &echo, &port)))
-		return false;
-
-	len = mptcp_add_addr_len(opts->addr.family, echo, port);
+	len = mptcp_add_addr_len(msk, opts);
 	if (remaining < len)
 		return false;
 
@@ -683,13 +682,16 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 	if (drop_other_suboptions)
 		*size -= opt_size;
 	opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
-	if (!echo) {
+	if (!(add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) &&
+	    (add_addr & BIT(MPTCP_ADD_ADDR_SIGNAL))) {
 		opts->ahmac = add_addr_generate_hmac(msk->local_key,
 						     msk->remote_key,
-						     &opts->addr);
+						     &opts->local);
 	}
-	pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d",
-		 opts->addr.id, opts->ahmac, echo, ntohs(opts->addr.port));
+
+	pr_debug("addr_signal:%x, echo=%d, local_addr_id=%d, ahmac=%llu, local_port=%d, remote_addr_id=%d, remote_port=%d",
+		 add_addr, (opts->ahmac == 0), opts->local.id,
+		 opts->ahmac, ntohs(opts->local.port), opts->remote.id, ntohs(opts->remote.port));
 
 	return true;
 }
@@ -1229,15 +1231,19 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 
 mp_capable_done:
 	if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
+		struct mptcp_addr_info *addr = &opts->remote;
 		u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
 		u8 echo = MPTCP_ADDR_ECHO;
 
+		if (opts->ahmac)
+			addr = &opts->local;
+
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-		if (opts->addr.family == AF_INET6)
+		if (addr->family == AF_INET6)
 			len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
 #endif
 
-		if (opts->addr.port)
+		if (addr->port)
 			len += TCPOLEN_MPTCP_PORT_LEN;
 
 		if (opts->ahmac) {
@@ -1246,25 +1252,25 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 		}
 
 		*ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
-				      len, echo, opts->addr.id);
-		if (opts->addr.family == AF_INET) {
-			memcpy((u8 *)ptr, (u8 *)&opts->addr.addr.s_addr, 4);
+				      len, echo, addr->id);
+		if (addr->family == AF_INET) {
+			memcpy((u8 *)ptr, (u8 *)&addr->addr.s_addr, 4);
 			ptr += 1;
 		}
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-		else if (opts->addr.family == AF_INET6) {
-			memcpy((u8 *)ptr, opts->addr.addr6.s6_addr, 16);
+		else if (addr->family == AF_INET6) {
+			memcpy((u8 *)ptr, addr->addr6.s6_addr, 16);
 			ptr += 4;
 		}
 #endif
 
-		if (!opts->addr.port) {
+		if (!addr->port) {
 			if (opts->ahmac) {
 				put_unaligned_be64(opts->ahmac, ptr);
 				ptr += 2;
 			}
 		} else {
-			u16 port = ntohs(opts->addr.port);
+			u16 port = ntohs(addr->port);
 
 			if (opts->ahmac) {
 				u8 *bptr = (u8 *)ptr;
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 0dc9021..9c5b15c 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -253,11 +253,11 @@ void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
 
 /* path manager helpers */
 
-bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			      struct mptcp_addr_info *saddr, bool *echo, bool *port)
+bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
+			      unsigned int opt_size, unsigned int remaining,
+			      struct mptcp_out_options *opts,  u8 *add_addr)
 {
-	int ret = false;
-	u8 add_addr;
+	int ret = false, len;
 
 	spin_lock_bh(&msk->pm.lock);
 
@@ -265,18 +265,31 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 	if (!mptcp_pm_should_add_signal(msk))
 		goto out_unlock;
 
-	*echo = mptcp_pm_should_add_signal_echo(msk);
-	*port = mptcp_pm_should_add_signal_port(msk);
+	opts->local = msk->pm.local;
+	opts->remote = msk->pm.remote;
+	*add_addr = msk->pm.addr_signal;
+
+	if (((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)) ||
+	     ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_SIGNAL)) &&
+	      (msk->pm.local.family == AF_INET6 || msk->pm.local.port))) &&
+	    skb && skb_is_tcp_pure_ack(skb)) {
+		remaining += opt_size;
+	}
 
-	if (remaining < mptcp_add_addr_len(msk->pm.local.family, *echo, *port))
+	len = mptcp_add_addr_len(msk, opts);
+	if (remaining < len)
 		goto out_unlock;
 
-	*saddr = msk->pm.local;
-	add_addr = msk->pm.addr_signal & ~(BIT(MPTCP_ADD_ADDR_SIGNAL) | BIT(MPTCP_ADD_ADDR_ECHO));
-	WRITE_ONCE(msk->pm.addr_signal, add_addr);
-	ret = true;
+	if ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)))
+		WRITE_ONCE(msk->pm.addr_signal, msk->pm.addr_signal & ~BIT(MPTCP_ADD_ADDR_ECHO));
+	else
+		WRITE_ONCE(msk->pm.addr_signal, msk->pm.addr_signal & ~BIT(MPTCP_ADD_ADDR_SIGNAL));
 
+	ret = true;
 out_unlock:
+	if ((mptcp_pm_should_add_signal_echo(msk)) && (mptcp_pm_should_add_signal_addr(msk)))
+		mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
+
 	spin_unlock_bh(&msk->pm.lock);
 	return ret;
 }
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index a0b0ec0..caa4a60 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -737,16 +737,24 @@ static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
 	return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_RM_ADDR_SIGNAL);
 }
 
-static inline unsigned int mptcp_add_addr_len(int family, bool echo, bool port)
+static inline unsigned int mptcp_add_addr_len(struct mptcp_sock *msk,
+					      struct mptcp_out_options *opts)
 {
-	u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
+	u8 len = 0;
+	struct mptcp_addr_info *addr = &opts->remote;
 
-	if (family == AF_INET6)
-		len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
-	if (!echo)
+	if (mptcp_pm_should_add_signal_addr(msk)) {
+		addr = &opts->local;
 		len += MPTCPOPT_THMAC_LEN;
+	}
+
+	if (addr->family == AF_INET6)
+		len += TCPOLEN_MPTCP_ADD_ADDR6_BASE;
+	else
+		len += TCPOLEN_MPTCP_ADD_ADDR_BASE;
+
 	/* account for 2 trailing 'nop' options */
-	if (port)
+	if (addr->port)
 		len += TCPOLEN_MPTCP_PORT_LEN + TCPOLEN_MPTCP_PORT_ALIGN;
 
 	return len;
@@ -760,8 +768,9 @@ static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
 	return TCPOLEN_MPTCP_RM_ADDR_BASE + roundup(rm_list->nr - 1, 4) + 1;
 }
 
-bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			      struct mptcp_addr_info *saddr, bool *echo, bool *port);
+bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
+			      unsigned int opt_size, unsigned int remaining,
+			      struct mptcp_out_options *opts,  u8 *add_addr);
 bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 			     struct mptcp_rm_list *rm_list);
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v7 4/5] mptcp: remove some double-check
  2021-06-30 10:24 [PATCH v7 0/4] mptcp: fix conflicts when using pm.add_signal in ADD_ADDR/echo and RM_ADDR process Yonglong Li
                   ` (2 preceding siblings ...)
  2021-06-30 10:24 ` [PATCH v7 3/5] mptcp: build ADD_ADDR/echo-ADD_ADDR option according pm.add_signal Yonglong Li
@ 2021-06-30 10:24 ` Yonglong Li
  2021-06-30 10:57   ` Geliang Tang
  2021-06-30 10:24 ` [PATCH v7 5/5] mptcp: remove MPTCP_ADD_ADDR_IPV6 and MPTCP_ADD_ADDR_PORT Yonglong Li
  4 siblings, 1 reply; 13+ messages in thread
From: Yonglong Li @ 2021-06-30 10:24 UTC (permalink / raw)
  To: mptcp; +Cc: mathew.j.martineau, geliangtang, Yonglong Li

remove some double-check in mptcp_established_options_add_addr() and
mptcp_established_options_rm_addr()

Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
---
 net/mptcp/options.c  | 14 ++------------
 net/mptcp/pm.c       | 21 +++++++++++----------
 net/mptcp/protocol.h |  4 ++--
 3 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index cceff0a..0711fc1 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -659,7 +659,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 	int len = 0;
 
 	if (!mptcp_pm_should_add_signal(msk) ||
-	    !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr))
+	    !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr, &len))
 		return false;
 
 	if (((add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) ||
@@ -674,10 +674,6 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
 		drop_other_suboptions = true;
 	}
 
-	len = mptcp_add_addr_len(msk, opts);
-	if (remaining < len)
-		return false;
-
 	*size = len;
 	if (drop_other_suboptions)
 		*size -= opt_size;
@@ -707,13 +703,7 @@ static bool mptcp_established_options_rm_addr(struct sock *sk,
 	int i, len;
 
 	if (!mptcp_pm_should_rm_signal(msk) ||
-	    !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list)))
-		return false;
-
-	len = mptcp_rm_addr_len(&rm_list);
-	if (len < 0)
-		return false;
-	if (remaining < len)
+	    !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, &len)))
 		return false;
 
 	*size = len;
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 9c5b15c..2311ea5 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -255,9 +255,9 @@ void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
 
 bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
 			      unsigned int opt_size, unsigned int remaining,
-			      struct mptcp_out_options *opts,  u8 *add_addr)
+			      struct mptcp_out_options *opts,  u8 *add_addr, int *len)
 {
-	int ret = false, len;
+	int ret = false;
 
 	spin_lock_bh(&msk->pm.lock);
 
@@ -276,8 +276,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
 		remaining += opt_size;
 	}
 
-	len = mptcp_add_addr_len(msk, opts);
-	if (remaining < len)
+	*len = mptcp_add_addr_len(msk, opts);
+	if (remaining < *len)
 		goto out_unlock;
 
 	if ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)))
@@ -287,17 +287,18 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
 
 	ret = true;
 out_unlock:
+	spin_unlock_bh(&msk->pm.lock);
+
 	if ((mptcp_pm_should_add_signal_echo(msk)) && (mptcp_pm_should_add_signal_addr(msk)))
 		mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
 
-	spin_unlock_bh(&msk->pm.lock);
 	return ret;
 }
 
 bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			     struct mptcp_rm_list *rm_list)
+			     struct mptcp_rm_list *rm_list, int *len)
 {
-	int ret = false, len;
+	int ret = false;
 	u8 rm_addr;
 
 	spin_lock_bh(&msk->pm.lock);
@@ -307,12 +308,12 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 		goto out_unlock;
 
 	rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
-	len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
-	if (len < 0) {
+	*len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
+	if (*len < 0) {
 		WRITE_ONCE(msk->pm.addr_signal, rm_addr);
 		goto out_unlock;
 	}
-	if (remaining < len)
+	if (remaining < *len)
 		goto out_unlock;
 
 	*rm_list = msk->pm.rm_list_tx;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index caa4a60..5d7c9d7 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -770,9 +770,9 @@ static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
 
 bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
 			      unsigned int opt_size, unsigned int remaining,
-			      struct mptcp_out_options *opts,  u8 *add_addr);
+			      struct mptcp_out_options *opts,  u8 *add_addr, int *len);
 bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			     struct mptcp_rm_list *rm_list);
+			     struct mptcp_rm_list *rm_list, int *len);
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
 
 void __init mptcp_pm_nl_init(void);
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v7 5/5] mptcp: remove MPTCP_ADD_ADDR_IPV6 and MPTCP_ADD_ADDR_PORT
  2021-06-30 10:24 [PATCH v7 0/4] mptcp: fix conflicts when using pm.add_signal in ADD_ADDR/echo and RM_ADDR process Yonglong Li
                   ` (3 preceding siblings ...)
  2021-06-30 10:24 ` [PATCH v7 4/5] mptcp: remove some double-check Yonglong Li
@ 2021-06-30 10:24 ` Yonglong Li
  4 siblings, 0 replies; 13+ messages in thread
From: Yonglong Li @ 2021-06-30 10:24 UTC (permalink / raw)
  To: mptcp; +Cc: mathew.j.martineau, geliangtang, Yonglong Li

MPTCP_ADD_ADDR_PORT and MPTCP_ADD_ADDR_PORT are not necessary, we
can get these info from pm.local or pm.remote

Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
---
 net/mptcp/pm.c         |  4 ----
 net/mptcp/pm_netlink.c |  6 ++----
 net/mptcp/protocol.h   | 12 ------------
 3 files changed, 2 insertions(+), 20 deletions(-)

diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 2311ea5..c99df2d 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -35,10 +35,6 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 		msk->pm.local = *addr;
 		add_addr |= BIT(MPTCP_ADD_ADDR_SIGNAL);
 	}
-	if (addr->family == AF_INET6)
-		add_addr |= BIT(MPTCP_ADD_ADDR_IPV6);
-	if (addr->port)
-		add_addr |= BIT(MPTCP_ADD_ADDR_PORT);
 	WRITE_ONCE(msk->pm.addr_signal, add_addr);
 	return 0;
 }
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 0f302d2..bfa9d6d 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -543,10 +543,8 @@ void mptcp_pm_nl_addr_send_ack(struct mptcp_sock *msk)
 		bool slow;
 
 		spin_unlock_bh(&msk->pm.lock);
-		pr_debug("send ack for %s%s%s",
-			 mptcp_pm_should_add_signal(msk) ? "add_addr" : "rm_addr",
-			 mptcp_pm_should_add_signal_ipv6(msk) ? " [ipv6]" : "",
-			 mptcp_pm_should_add_signal_port(msk) ? " [port]" : "");
+		pr_debug("send ack for %s",
+			 mptcp_pm_should_add_signal(msk) ? "add_addr" : "rm_addr");
 
 		slow = lock_sock_fast(ssk);
 		tcp_send_ack(ssk);
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 5d7c9d7..534a4a6 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -175,8 +175,6 @@ enum mptcp_pm_status {
 enum mptcp_addr_signal_status {
 	MPTCP_ADD_ADDR_SIGNAL,
 	MPTCP_ADD_ADDR_ECHO,
-	MPTCP_ADD_ADDR_IPV6,
-	MPTCP_ADD_ADDR_PORT,
 	MPTCP_RM_ADDR_SIGNAL,
 };
 
@@ -722,16 +720,6 @@ static inline bool mptcp_pm_should_add_signal_echo(struct mptcp_sock *msk)
 	return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_ADD_ADDR_ECHO);
 }
 
-static inline bool mptcp_pm_should_add_signal_ipv6(struct mptcp_sock *msk)
-{
-	return READ_ONCE(msk->pm.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.addr_signal) & BIT(MPTCP_ADD_ADDR_PORT);
-}
-
 static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
 {
 	return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_RM_ADDR_SIGNAL);
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v7 1/5] mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other
  2021-06-30 10:24 ` [PATCH v7 1/5] mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other Yonglong Li
@ 2021-06-30 10:37   ` Geliang Tang
  2021-07-02  6:23     ` Yonglong Li
  0 siblings, 1 reply; 13+ messages in thread
From: Geliang Tang @ 2021-06-30 10:37 UTC (permalink / raw)
  To: Yonglong Li; +Cc: mptcp, Mat Martineau

Yonglong Li <liyonglong@chinatelecom.cn> 于2021年6月30日周三 下午6:24写道:

>
> ADD_ADDR share pm.addr_signal with RM_ADDR, so after RM_ADDR/ADD_ADDR
> done we should not clean ADD_ADDR/RM_ADDR's addr_signal.
>
> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
> ---
>  net/mptcp/pm.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> index 9d00fa6..50079e5 100644
> --- a/net/mptcp/pm.c
> +++ b/net/mptcp/pm.c
> @@ -253,6 +253,7 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>                               struct mptcp_addr_info *saddr, bool *echo, bool *port)
>  {
>         int ret = false;
> +       u8 add_addr;
>
>         spin_lock_bh(&msk->pm.lock);
>
> @@ -267,7 +268,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>                 goto out_unlock;
>
>         *saddr = msk->pm.local;
> -       WRITE_ONCE(msk->pm.addr_signal, 0);
> +       add_addr = msk->pm.addr_signal & ~(BIT(MPTCP_ADD_ADDR_SIGNAL) | BIT(MPTCP_ADD_ADDR_ECHO));
> +       WRITE_ONCE(msk->pm.addr_signal, add_addr);
>         ret = true;
>
>  out_unlock:

This part is removed in patch 3, why we need to add it here?

> @@ -279,6 +281,7 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>                              struct mptcp_rm_list *rm_list)
>  {
>         int ret = false, len;
> +       u8 rm_addr;
>
>         spin_lock_bh(&msk->pm.lock);
>
> @@ -286,16 +289,17 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>         if (!mptcp_pm_should_rm_signal(msk))
>                 goto out_unlock;
>
> +       rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
>         len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
>         if (len < 0) {
> -               WRITE_ONCE(msk->pm.addr_signal, 0);
> +               WRITE_ONCE(msk->pm.addr_signal, rm_addr);
>                 goto out_unlock;
>         }
>         if (remaining < len)
>                 goto out_unlock;
>
>         *rm_list = msk->pm.rm_list_tx;
> -       WRITE_ONCE(msk->pm.addr_signal, 0);
> +       WRITE_ONCE(msk->pm.addr_signal, rm_addr);
>         ret = true;
>
>  out_unlock:
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v7 4/5] mptcp: remove some double-check
  2021-06-30 10:24 ` [PATCH v7 4/5] mptcp: remove some double-check Yonglong Li
@ 2021-06-30 10:57   ` Geliang Tang
  2021-07-02  6:22     ` Yonglong Li
  0 siblings, 1 reply; 13+ messages in thread
From: Geliang Tang @ 2021-06-30 10:57 UTC (permalink / raw)
  To: Yonglong Li; +Cc: mptcp, Mat Martineau

As I said in v6, I prefer to keep these double check code, no need to
remove them.

Yonglong Li <liyonglong@chinatelecom.cn> 于2021年6月30日周三 下午6:24写道:
>
> remove some double-check in mptcp_established_options_add_addr() and
> mptcp_established_options_rm_addr()
>
> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
> ---
>  net/mptcp/options.c  | 14 ++------------
>  net/mptcp/pm.c       | 21 +++++++++++----------
>  net/mptcp/protocol.h |  4 ++--
>  3 files changed, 15 insertions(+), 24 deletions(-)
>
> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> index cceff0a..0711fc1 100644
> --- a/net/mptcp/options.c
> +++ b/net/mptcp/options.c
> @@ -659,7 +659,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>         int len = 0;
>
>         if (!mptcp_pm_should_add_signal(msk) ||
> -           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr))
> +           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr, &len))
>                 return false;
>
>         if (((add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) ||
> @@ -674,10 +674,6 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>                 drop_other_suboptions = true;
>         }
>
> -       len = mptcp_add_addr_len(msk, opts);
> -       if (remaining < len)
> -               return false;
> -
>         *size = len;
>         if (drop_other_suboptions)
>                 *size -= opt_size;
> @@ -707,13 +703,7 @@ static bool mptcp_established_options_rm_addr(struct sock *sk,
>         int i, len;
>
>         if (!mptcp_pm_should_rm_signal(msk) ||
> -           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list)))
> -               return false;
> -
> -       len = mptcp_rm_addr_len(&rm_list);
> -       if (len < 0)
> -               return false;
> -       if (remaining < len)
> +           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, &len)))
>                 return false;
>
>         *size = len;
> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> index 9c5b15c..2311ea5 100644
> --- a/net/mptcp/pm.c
> +++ b/net/mptcp/pm.c
> @@ -255,9 +255,9 @@ void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
>
>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>                               unsigned int opt_size, unsigned int remaining,
> -                             struct mptcp_out_options *opts,  u8 *add_addr)
> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len)
>  {
> -       int ret = false, len;
> +       int ret = false;
>
>         spin_lock_bh(&msk->pm.lock);
>
> @@ -276,8 +276,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>                 remaining += opt_size;
>         }
>
> -       len = mptcp_add_addr_len(msk, opts);
> -       if (remaining < len)
> +       *len = mptcp_add_addr_len(msk, opts);
> +       if (remaining < *len)
>                 goto out_unlock;
>
>         if ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)))
> @@ -287,17 +287,18 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>
>         ret = true;
>  out_unlock:
> +       spin_unlock_bh(&msk->pm.lock);
> +
>         if ((mptcp_pm_should_add_signal_echo(msk)) && (mptcp_pm_should_add_signal_addr(msk)))
>                 mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
>
> -       spin_unlock_bh(&msk->pm.lock);
>         return ret;
>  }
>
>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> -                            struct mptcp_rm_list *rm_list)
> +                            struct mptcp_rm_list *rm_list, int *len)
>  {
> -       int ret = false, len;
> +       int ret = false;
>         u8 rm_addr;
>
>         spin_lock_bh(&msk->pm.lock);
> @@ -307,12 +308,12 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>                 goto out_unlock;
>
>         rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
> -       len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
> -       if (len < 0) {
> +       *len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
> +       if (*len < 0) {
>                 WRITE_ONCE(msk->pm.addr_signal, rm_addr);
>                 goto out_unlock;
>         }
> -       if (remaining < len)
> +       if (remaining < *len)
>                 goto out_unlock;
>
>         *rm_list = msk->pm.rm_list_tx;
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index caa4a60..5d7c9d7 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -770,9 +770,9 @@ static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
>
>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>                               unsigned int opt_size, unsigned int remaining,
> -                             struct mptcp_out_options *opts,  u8 *add_addr);
> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len);
>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> -                            struct mptcp_rm_list *rm_list);
> +                            struct mptcp_rm_list *rm_list, int *len);
>  int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
>
>  void __init mptcp_pm_nl_init(void);
> --
> 1.8.3.1
>
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v7 3/5] mptcp: build ADD_ADDR/echo-ADD_ADDR option according pm.add_signal
  2021-06-30 10:24 ` [PATCH v7 3/5] mptcp: build ADD_ADDR/echo-ADD_ADDR option according pm.add_signal Yonglong Li
@ 2021-06-30 11:14   ` Geliang Tang
  2021-07-02  6:15     ` Yonglong Li
  0 siblings, 1 reply; 13+ messages in thread
From: Geliang Tang @ 2021-06-30 11:14 UTC (permalink / raw)
  To: Yonglong Li; +Cc: mptcp, Mat Martineau

Hi Yonglong,

Thank you for this new patch!

Yonglong Li <liyonglong@chinatelecom.cn> 于2021年6月30日周三 下午6:24写道:
>
> according MPTCP_ADD_ADDR_SIGNAL and MPTCP_ADD_ADDR_ECHO flag build
> ADD_ADDR/echo-ADD_ADDR option
>
> add a suboptions type OPTION_MPTCP_ADD_ECHO to mark as echo option
>
> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
> ---
>  include/net/mptcp.h  |  3 ++-
>  net/mptcp/options.c  | 54 +++++++++++++++++++++++++++++-----------------------
>  net/mptcp/pm.c       | 35 +++++++++++++++++++++++-----------
>  net/mptcp/protocol.h | 25 ++++++++++++++++--------
>  4 files changed, 73 insertions(+), 44 deletions(-)
>
> diff --git a/include/net/mptcp.h b/include/net/mptcp.h
> index d61bbbf..d2c6ebe 100644
> --- a/include/net/mptcp.h
> +++ b/include/net/mptcp.h
> @@ -61,7 +61,8 @@ struct mptcp_out_options {
>         u64 sndr_key;
>         u64 rcvr_key;
>         u64 ahmac;
> -       struct mptcp_addr_info addr;
> +       struct mptcp_addr_info local;
> +       struct mptcp_addr_info remote;
>         struct mptcp_rm_list rm_list;
>         u8 join_id;
>         u8 backup;
> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> index 1aec016..cceff0a 100644
> --- a/net/mptcp/options.c
> +++ b/net/mptcp/options.c
> @@ -655,13 +655,16 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>         struct mptcp_sock *msk = mptcp_sk(subflow->conn);
>         bool drop_other_suboptions = false;
>         unsigned int opt_size = *size;
> -       bool echo;
> -       bool port;
> -       int len;
> +       u8 add_addr;
> +       int len = 0;
>
> -       if ((mptcp_pm_should_add_signal_ipv6(msk) ||
> -            mptcp_pm_should_add_signal_port(msk) ||
> -            mptcp_pm_should_add_signal_echo(msk)) &&
> +       if (!mptcp_pm_should_add_signal(msk) ||
> +           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr))
> +               return false;
> +
> +       if (((add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) ||
> +            ((add_addr & BIT(MPTCP_ADD_ADDR_SIGNAL)) &&
> +             (opts->local.family == AF_INET6 || opts->local.port))) &&
>             skb && skb_is_tcp_pure_ack(skb)) {
>                 pr_debug("drop other suboptions");
>                 opts->suboptions = 0;
> @@ -671,11 +674,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>                 drop_other_suboptions = true;
>         }
>
> -       if (!mptcp_pm_should_add_signal(msk) ||
> -           !(mptcp_pm_add_addr_signal(msk, remaining, &opts->addr, &echo, &port)))
> -               return false;
> -
> -       len = mptcp_add_addr_len(opts->addr.family, echo, port);
> +       len = mptcp_add_addr_len(msk, opts);
>         if (remaining < len)
>                 return false;
>
> @@ -683,13 +682,16 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>         if (drop_other_suboptions)
>                 *size -= opt_size;
>         opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
> -       if (!echo) {
> +       if (!(add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) &&
> +           (add_addr & BIT(MPTCP_ADD_ADDR_SIGNAL))) {
>                 opts->ahmac = add_addr_generate_hmac(msk->local_key,
>                                                      msk->remote_key,
> -                                                    &opts->addr);
> +                                                    &opts->local);
>         }
> -       pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d",
> -                opts->addr.id, opts->ahmac, echo, ntohs(opts->addr.port));
> +

Drop this blank line.

> +       pr_debug("addr_signal:%x, echo=%d, local_addr_id=%d, ahmac=%llu, local_port=%d, remote_addr_id=%d, remote_port=%d",
> +                add_addr, (opts->ahmac == 0), opts->local.id,
> +                opts->ahmac, ntohs(opts->local.port), opts->remote.id, ntohs(opts->remote.port));
>
>         return true;
>  }
> @@ -1229,15 +1231,19 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
>
>  mp_capable_done:
>         if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
> +               struct mptcp_addr_info *addr = &opts->remote;
>                 u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
>                 u8 echo = MPTCP_ADDR_ECHO;
>
> +               if (opts->ahmac)
> +                       addr = &opts->local;
> +
>  #if IS_ENABLED(CONFIG_MPTCP_IPV6)
> -               if (opts->addr.family == AF_INET6)
> +               if (addr->family == AF_INET6)
>                         len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
>  #endif
>
> -               if (opts->addr.port)
> +               if (addr->port)
>                         len += TCPOLEN_MPTCP_PORT_LEN;
>
>                 if (opts->ahmac) {
> @@ -1246,25 +1252,25 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
>                 }
>
>                 *ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
> -                                     len, echo, opts->addr.id);
> -               if (opts->addr.family == AF_INET) {
> -                       memcpy((u8 *)ptr, (u8 *)&opts->addr.addr.s_addr, 4);
> +                                     len, echo, addr->id);
> +               if (addr->family == AF_INET) {
> +                       memcpy((u8 *)ptr, (u8 *)&addr->addr.s_addr, 4);
>                         ptr += 1;
>                 }
>  #if IS_ENABLED(CONFIG_MPTCP_IPV6)
> -               else if (opts->addr.family == AF_INET6) {
> -                       memcpy((u8 *)ptr, opts->addr.addr6.s6_addr, 16);
> +               else if (addr->family == AF_INET6) {
> +                       memcpy((u8 *)ptr, addr->addr6.s6_addr, 16);
>                         ptr += 4;
>                 }
>  #endif
>
> -               if (!opts->addr.port) {
> +               if (!addr->port) {
>                         if (opts->ahmac) {
>                                 put_unaligned_be64(opts->ahmac, ptr);
>                                 ptr += 2;
>                         }
>                 } else {
> -                       u16 port = ntohs(opts->addr.port);
> +                       u16 port = ntohs(addr->port);
>
>                         if (opts->ahmac) {
>                                 u8 *bptr = (u8 *)ptr;
> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> index 0dc9021..9c5b15c 100644
> --- a/net/mptcp/pm.c
> +++ b/net/mptcp/pm.c
> @@ -253,11 +253,11 @@ void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
>
>  /* path manager helpers */
>
> -bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> -                             struct mptcp_addr_info *saddr, bool *echo, bool *port)
> +bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
> +                             unsigned int opt_size, unsigned int remaining,
> +                             struct mptcp_out_options *opts,  u8 *add_addr)
>  {
> -       int ret = false;
> -       u8 add_addr;
> +       int ret = false, len;
>
>         spin_lock_bh(&msk->pm.lock);
>
> @@ -265,18 +265,31 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>         if (!mptcp_pm_should_add_signal(msk))
>                 goto out_unlock;
>
> -       *echo = mptcp_pm_should_add_signal_echo(msk);
> -       *port = mptcp_pm_should_add_signal_port(msk);
> +       opts->local = msk->pm.local;
> +       opts->remote = msk->pm.remote;
> +       *add_addr = msk->pm.addr_signal;
> +
> +       if (((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)) ||
> +            ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_SIGNAL)) &&
> +             (msk->pm.local.family == AF_INET6 || msk->pm.local.port))) &&
> +           skb && skb_is_tcp_pure_ack(skb)) {
> +               remaining += opt_size;
> +       }

Move it back to mptcp_established_options_add_addr, if so, no need to
add the opt_size argument too.

>
> -       if (remaining < mptcp_add_addr_len(msk->pm.local.family, *echo, *port))
> +       len = mptcp_add_addr_len(msk, opts);
> +       if (remaining < len)
>                 goto out_unlock;
>
> -       *saddr = msk->pm.local;
> -       add_addr = msk->pm.addr_signal & ~(BIT(MPTCP_ADD_ADDR_SIGNAL) | BIT(MPTCP_ADD_ADDR_ECHO));
> -       WRITE_ONCE(msk->pm.addr_signal, add_addr);
> -       ret = true;
> +       if ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)))
> +               WRITE_ONCE(msk->pm.addr_signal, msk->pm.addr_signal & ~BIT(MPTCP_ADD_ADDR_ECHO));
> +       else
> +               WRITE_ONCE(msk->pm.addr_signal, msk->pm.addr_signal & ~BIT(MPTCP_ADD_ADDR_SIGNAL));
>

Drop this blank line.

> +       ret = true;
>  out_unlock:
> +       if ((mptcp_pm_should_add_signal_echo(msk)) && (mptcp_pm_should_add_signal_addr(msk)))
> +               mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
> +

Again, why we need these two lines?

>         spin_unlock_bh(&msk->pm.lock);
>         return ret;
>  }
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index a0b0ec0..caa4a60 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -737,16 +737,24 @@ static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
>         return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_RM_ADDR_SIGNAL);
>  }
>
> -static inline unsigned int mptcp_add_addr_len(int family, bool echo, bool port)
> +static inline unsigned int mptcp_add_addr_len(struct mptcp_sock *msk,
> +                                             struct mptcp_out_options *opts)
>  {
> -       u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
> +       u8 len = 0;
> +       struct mptcp_addr_info *addr = &opts->remote;

Use the reverse xmas tree order.

Thanks,
-Geliang

>
> -       if (family == AF_INET6)
> -               len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
> -       if (!echo)
> +       if (mptcp_pm_should_add_signal_addr(msk)) {
> +               addr = &opts->local;
>                 len += MPTCPOPT_THMAC_LEN;
> +       }
> +
> +       if (addr->family == AF_INET6)
> +               len += TCPOLEN_MPTCP_ADD_ADDR6_BASE;
> +       else
> +               len += TCPOLEN_MPTCP_ADD_ADDR_BASE;
> +
>         /* account for 2 trailing 'nop' options */
> -       if (port)
> +       if (addr->port)
>                 len += TCPOLEN_MPTCP_PORT_LEN + TCPOLEN_MPTCP_PORT_ALIGN;
>
>         return len;
> @@ -760,8 +768,9 @@ static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
>         return TCPOLEN_MPTCP_RM_ADDR_BASE + roundup(rm_list->nr - 1, 4) + 1;
>  }
>
> -bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> -                             struct mptcp_addr_info *saddr, bool *echo, bool *port);
> +bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
> +                             unsigned int opt_size, unsigned int remaining,
> +                             struct mptcp_out_options *opts,  u8 *add_addr);
>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>                              struct mptcp_rm_list *rm_list);
>  int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v7 3/5] mptcp: build ADD_ADDR/echo-ADD_ADDR option according pm.add_signal
  2021-06-30 11:14   ` Geliang Tang
@ 2021-07-02  6:15     ` Yonglong Li
  0 siblings, 0 replies; 13+ messages in thread
From: Yonglong Li @ 2021-07-02  6:15 UTC (permalink / raw)
  To: Geliang Tang; +Cc: mptcp, Mat Martineau

Hi Geliang,
Thanks for your reviews.

On 2021/6/30 19:14, Geliang Tang wrote:
> Hi Yonglong,
> 
> Thank you for this new patch!
> 
> Yonglong Li <liyonglong@chinatelecom.cn> 于2021年6月30日周三 下午6:24写道:
>>
>> according MPTCP_ADD_ADDR_SIGNAL and MPTCP_ADD_ADDR_ECHO flag build
>> ADD_ADDR/echo-ADD_ADDR option
>>
>> add a suboptions type OPTION_MPTCP_ADD_ECHO to mark as echo option
>>
>> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
>> ---
>>  include/net/mptcp.h  |  3 ++-
>>  net/mptcp/options.c  | 54 +++++++++++++++++++++++++++++-----------------------
>>  net/mptcp/pm.c       | 35 +++++++++++++++++++++++-----------
>>  net/mptcp/protocol.h | 25 ++++++++++++++++--------
>>  4 files changed, 73 insertions(+), 44 deletions(-)
>>
>> diff --git a/include/net/mptcp.h b/include/net/mptcp.h
>> index d61bbbf..d2c6ebe 100644
>> --- a/include/net/mptcp.h
>> +++ b/include/net/mptcp.h
>> @@ -61,7 +61,8 @@ struct mptcp_out_options {
>>         u64 sndr_key;
>>         u64 rcvr_key;
>>         u64 ahmac;
>> -       struct mptcp_addr_info addr;
>> +       struct mptcp_addr_info local;
>> +       struct mptcp_addr_info remote;
>>         struct mptcp_rm_list rm_list;
>>         u8 join_id;
>>         u8 backup;
>> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
>> index 1aec016..cceff0a 100644
>> --- a/net/mptcp/options.c
>> +++ b/net/mptcp/options.c
>> @@ -655,13 +655,16 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>>         struct mptcp_sock *msk = mptcp_sk(subflow->conn);
>>         bool drop_other_suboptions = false;
>>         unsigned int opt_size = *size;
>> -       bool echo;
>> -       bool port;
>> -       int len;
>> +       u8 add_addr;
>> +       int len = 0;
>>
>> -       if ((mptcp_pm_should_add_signal_ipv6(msk) ||
>> -            mptcp_pm_should_add_signal_port(msk) ||
>> -            mptcp_pm_should_add_signal_echo(msk)) &&
>> +       if (!mptcp_pm_should_add_signal(msk) ||
>> +           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr))
>> +               return false;
>> +
>> +       if (((add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) ||
>> +            ((add_addr & BIT(MPTCP_ADD_ADDR_SIGNAL)) &&
>> +             (opts->local.family == AF_INET6 || opts->local.port))) &&
>>             skb && skb_is_tcp_pure_ack(skb)) {
>>                 pr_debug("drop other suboptions");
>>                 opts->suboptions = 0;
>> @@ -671,11 +674,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>>                 drop_other_suboptions = true;
>>         }
>>
>> -       if (!mptcp_pm_should_add_signal(msk) ||
>> -           !(mptcp_pm_add_addr_signal(msk, remaining, &opts->addr, &echo, &port)))
>> -               return false;
>> -
>> -       len = mptcp_add_addr_len(opts->addr.family, echo, port);
>> +       len = mptcp_add_addr_len(msk, opts);
>>         if (remaining < len)
>>                 return false;
>>
>> @@ -683,13 +682,16 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>>         if (drop_other_suboptions)
>>                 *size -= opt_size;
>>         opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
>> -       if (!echo) {
>> +       if (!(add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) &&
>> +           (add_addr & BIT(MPTCP_ADD_ADDR_SIGNAL))) {
>>                 opts->ahmac = add_addr_generate_hmac(msk->local_key,
>>                                                      msk->remote_key,
>> -                                                    &opts->addr);
>> +                                                    &opts->local);
>>         }
>> -       pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d",
>> -                opts->addr.id, opts->ahmac, echo, ntohs(opts->addr.port));
>> +
> 
> Drop this blank line.
> 
>> +       pr_debug("addr_signal:%x, echo=%d, local_addr_id=%d, ahmac=%llu, local_port=%d, remote_addr_id=%d, remote_port=%d",
>> +                add_addr, (opts->ahmac == 0), opts->local.id,
>> +                opts->ahmac, ntohs(opts->local.port), opts->remote.id, ntohs(opts->remote.port));
>>
>>         return true;
>>  }
>> @@ -1229,15 +1231,19 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
>>
>>  mp_capable_done:
>>         if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
>> +               struct mptcp_addr_info *addr = &opts->remote;
>>                 u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
>>                 u8 echo = MPTCP_ADDR_ECHO;
>>
>> +               if (opts->ahmac)
>> +                       addr = &opts->local;
>> +
>>  #if IS_ENABLED(CONFIG_MPTCP_IPV6)
>> -               if (opts->addr.family == AF_INET6)
>> +               if (addr->family == AF_INET6)
>>                         len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
>>  #endif
>>
>> -               if (opts->addr.port)
>> +               if (addr->port)
>>                         len += TCPOLEN_MPTCP_PORT_LEN;
>>
>>                 if (opts->ahmac) {
>> @@ -1246,25 +1252,25 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
>>                 }
>>
>>                 *ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
>> -                                     len, echo, opts->addr.id);
>> -               if (opts->addr.family == AF_INET) {
>> -                       memcpy((u8 *)ptr, (u8 *)&opts->addr.addr.s_addr, 4);
>> +                                     len, echo, addr->id);
>> +               if (addr->family == AF_INET) {
>> +                       memcpy((u8 *)ptr, (u8 *)&addr->addr.s_addr, 4);
>>                         ptr += 1;
>>                 }
>>  #if IS_ENABLED(CONFIG_MPTCP_IPV6)
>> -               else if (opts->addr.family == AF_INET6) {
>> -                       memcpy((u8 *)ptr, opts->addr.addr6.s6_addr, 16);
>> +               else if (addr->family == AF_INET6) {
>> +                       memcpy((u8 *)ptr, addr->addr6.s6_addr, 16);
>>                         ptr += 4;
>>                 }
>>  #endif
>>
>> -               if (!opts->addr.port) {
>> +               if (!addr->port) {
>>                         if (opts->ahmac) {
>>                                 put_unaligned_be64(opts->ahmac, ptr);
>>                                 ptr += 2;
>>                         }
>>                 } else {
>> -                       u16 port = ntohs(opts->addr.port);
>> +                       u16 port = ntohs(addr->port);
>>
>>                         if (opts->ahmac) {
>>                                 u8 *bptr = (u8 *)ptr;
>> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
>> index 0dc9021..9c5b15c 100644
>> --- a/net/mptcp/pm.c
>> +++ b/net/mptcp/pm.c
>> @@ -253,11 +253,11 @@ void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
>>
>>  /* path manager helpers */
>>
>> -bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>> -                             struct mptcp_addr_info *saddr, bool *echo, bool *port)
>> +bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>> +                             unsigned int opt_size, unsigned int remaining,
>> +                             struct mptcp_out_options *opts,  u8 *add_addr)
>>  {
>> -       int ret = false;
>> -       u8 add_addr;
>> +       int ret = false, len;
>>
>>         spin_lock_bh(&msk->pm.lock);
>>
>> @@ -265,18 +265,31 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>>         if (!mptcp_pm_should_add_signal(msk))
>>                 goto out_unlock;
>>
>> -       *echo = mptcp_pm_should_add_signal_echo(msk);
>> -       *port = mptcp_pm_should_add_signal_port(msk);
>> +       opts->local = msk->pm.local;
>> +       opts->remote = msk->pm.remote;
>> +       *add_addr = msk->pm.addr_signal;
>> +
>> +       if (((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)) ||
>> +            ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_SIGNAL)) &&
>> +             (msk->pm.local.family == AF_INET6 || msk->pm.local.port))) &&
>> +           skb && skb_is_tcp_pure_ack(skb)) {
>> +               remaining += opt_size;
>> +       }
> 
> Move it back to mptcp_established_options_add_addr, if so, no need to
> add the opt_size argument too.
ok.

> 
>>
>> -       if (remaining < mptcp_add_addr_len(msk->pm.local.family, *echo, *port))
>> +       len = mptcp_add_addr_len(msk, opts);
>> +       if (remaining < len)
>>                 goto out_unlock;
>>
>> -       *saddr = msk->pm.local;
>> -       add_addr = msk->pm.addr_signal & ~(BIT(MPTCP_ADD_ADDR_SIGNAL) | BIT(MPTCP_ADD_ADDR_ECHO));
>> -       WRITE_ONCE(msk->pm.addr_signal, add_addr);
>> -       ret = true;
>> +       if ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)))
>> +               WRITE_ONCE(msk->pm.addr_signal, msk->pm.addr_signal & ~BIT(MPTCP_ADD_ADDR_ECHO));
>> +       else
>> +               WRITE_ONCE(msk->pm.addr_signal, msk->pm.addr_signal & ~BIT(MPTCP_ADD_ADDR_SIGNAL));
>>
> 
> Drop this blank line.
> 
>> +       ret = true;
>>  out_unlock:
>> +       if ((mptcp_pm_should_add_signal_echo(msk)) && (mptcp_pm_should_add_signal_addr(msk)))
>> +               mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
>> +
> 
> Again, why we need these two lines?sorry, these two lines is usless now.

> 
>>         spin_unlock_bh(&msk->pm.lock);
>>         return ret;
>>  }
>> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
>> index a0b0ec0..caa4a60 100644
>> --- a/net/mptcp/protocol.h
>> +++ b/net/mptcp/protocol.h
>> @@ -737,16 +737,24 @@ static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
>>         return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_RM_ADDR_SIGNAL);
>>  }
>>
>> -static inline unsigned int mptcp_add_addr_len(int family, bool echo, bool port)
>> +static inline unsigned int mptcp_add_addr_len(struct mptcp_sock *msk,
>> +                                             struct mptcp_out_options *opts)
>>  {
>> -       u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
>> +       u8 len = 0;
>> +       struct mptcp_addr_info *addr = &opts->remote;
> 
> Use the reverse xmas tree order.
sorry.

> 
> Thanks,
> -Geliang
> 
>>
>> -       if (family == AF_INET6)
>> -               len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
>> -       if (!echo)
>> +       if (mptcp_pm_should_add_signal_addr(msk)) {
>> +               addr = &opts->local;
>>                 len += MPTCPOPT_THMAC_LEN;
>> +       }
>> +
>> +       if (addr->family == AF_INET6)
>> +               len += TCPOLEN_MPTCP_ADD_ADDR6_BASE;
>> +       else
>> +               len += TCPOLEN_MPTCP_ADD_ADDR_BASE;
>> +
>>         /* account for 2 trailing 'nop' options */
>> -       if (port)
>> +       if (addr->port)
>>                 len += TCPOLEN_MPTCP_PORT_LEN + TCPOLEN_MPTCP_PORT_ALIGN;
>>
>>         return len;
>> @@ -760,8 +768,9 @@ static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
>>         return TCPOLEN_MPTCP_RM_ADDR_BASE + roundup(rm_list->nr - 1, 4) + 1;
>>  }
>>
>> -bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>> -                             struct mptcp_addr_info *saddr, bool *echo, bool *port);
>> +bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>> +                             unsigned int opt_size, unsigned int remaining,
>> +                             struct mptcp_out_options *opts,  u8 *add_addr);
>>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>>                              struct mptcp_rm_list *rm_list);
>>  int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
>> --
>> 1.8.3.1
>>
> 

-- 
Li YongLong

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v7 4/5] mptcp: remove some double-check
  2021-06-30 10:57   ` Geliang Tang
@ 2021-07-02  6:22     ` Yonglong Li
  2021-07-02  8:06       ` Geliang Tang
  0 siblings, 1 reply; 13+ messages in thread
From: Yonglong Li @ 2021-07-02  6:22 UTC (permalink / raw)
  To: Geliang Tang; +Cc: mptcp, Mat Martineau

Hi Geliang,

I think these double check is unnecessary. the reason to keep them is?
I think keep "!mptcp_pm_should_add_signal(msk)" you said in v6 is reasonable,
It can avoid to get pm.lock in process of sending packets. But the other double
check is useless.

On 2021/6/30 18:57, Geliang Tang wrote:
> As I said in v6, I prefer to keep these double check code, no need to
> remove them.
> 
> Yonglong Li <liyonglong@chinatelecom.cn> 于2021年6月30日周三 下午6:24写道:
>>
>> remove some double-check in mptcp_established_options_add_addr() and
>> mptcp_established_options_rm_addr()
>>
>> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
>> ---
>>  net/mptcp/options.c  | 14 ++------------
>>  net/mptcp/pm.c       | 21 +++++++++++----------
>>  net/mptcp/protocol.h |  4 ++--
>>  3 files changed, 15 insertions(+), 24 deletions(-)
>>
>> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
>> index cceff0a..0711fc1 100644
>> --- a/net/mptcp/options.c
>> +++ b/net/mptcp/options.c
>> @@ -659,7 +659,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>>         int len = 0;
>>
>>         if (!mptcp_pm_should_add_signal(msk) ||
>> -           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr))
>> +           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr, &len))
>>                 return false;
>>
>>         if (((add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) ||
>> @@ -674,10 +674,6 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
>>                 drop_other_suboptions = true;
>>         }
>>
>> -       len = mptcp_add_addr_len(msk, opts);
>> -       if (remaining < len)
>> -               return false;
>> -
>>         *size = len;
>>         if (drop_other_suboptions)
>>                 *size -= opt_size;
>> @@ -707,13 +703,7 @@ static bool mptcp_established_options_rm_addr(struct sock *sk,
>>         int i, len;
>>
>>         if (!mptcp_pm_should_rm_signal(msk) ||
>> -           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list)))
>> -               return false;
>> -
>> -       len = mptcp_rm_addr_len(&rm_list);
>> -       if (len < 0)
>> -               return false;
>> -       if (remaining < len)
>> +           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, &len)))
>>                 return false;
>>
>>         *size = len;
>> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
>> index 9c5b15c..2311ea5 100644
>> --- a/net/mptcp/pm.c
>> +++ b/net/mptcp/pm.c
>> @@ -255,9 +255,9 @@ void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
>>
>>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>>                               unsigned int opt_size, unsigned int remaining,
>> -                             struct mptcp_out_options *opts,  u8 *add_addr)
>> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len)
>>  {
>> -       int ret = false, len;
>> +       int ret = false;
>>
>>         spin_lock_bh(&msk->pm.lock);
>>
>> @@ -276,8 +276,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>>                 remaining += opt_size;
>>         }
>>
>> -       len = mptcp_add_addr_len(msk, opts);
>> -       if (remaining < len)
>> +       *len = mptcp_add_addr_len(msk, opts);
>> +       if (remaining < *len)
>>                 goto out_unlock;
>>
>>         if ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)))
>> @@ -287,17 +287,18 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>>
>>         ret = true;
>>  out_unlock:
>> +       spin_unlock_bh(&msk->pm.lock);
>> +
>>         if ((mptcp_pm_should_add_signal_echo(msk)) && (mptcp_pm_should_add_signal_addr(msk)))
>>                 mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
>>
>> -       spin_unlock_bh(&msk->pm.lock);
>>         return ret;
>>  }
>>
>>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>> -                            struct mptcp_rm_list *rm_list)
>> +                            struct mptcp_rm_list *rm_list, int *len)
>>  {
>> -       int ret = false, len;
>> +       int ret = false;
>>         u8 rm_addr;
>>
>>         spin_lock_bh(&msk->pm.lock);
>> @@ -307,12 +308,12 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>>                 goto out_unlock;
>>
>>         rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
>> -       len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
>> -       if (len < 0) {
>> +       *len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
>> +       if (*len < 0) {
>>                 WRITE_ONCE(msk->pm.addr_signal, rm_addr);
>>                 goto out_unlock;
>>         }
>> -       if (remaining < len)
>> +       if (remaining < *len)
>>                 goto out_unlock;
>>
>>         *rm_list = msk->pm.rm_list_tx;
>> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
>> index caa4a60..5d7c9d7 100644
>> --- a/net/mptcp/protocol.h
>> +++ b/net/mptcp/protocol.h
>> @@ -770,9 +770,9 @@ static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
>>
>>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
>>                               unsigned int opt_size, unsigned int remaining,
>> -                             struct mptcp_out_options *opts,  u8 *add_addr);
>> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len);
>>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>> -                            struct mptcp_rm_list *rm_list);
>> +                            struct mptcp_rm_list *rm_list, int *len);
>>  int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
>>
>>  void __init mptcp_pm_nl_init(void);
>> --
>> 1.8.3.1
>>
>>
> 

-- 
Li YongLong

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v7 1/5] mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other
  2021-06-30 10:37   ` Geliang Tang
@ 2021-07-02  6:23     ` Yonglong Li
  0 siblings, 0 replies; 13+ messages in thread
From: Yonglong Li @ 2021-07-02  6:23 UTC (permalink / raw)
  To: Geliang Tang; +Cc: mptcp, Mat Martineau



On 2021/6/30 18:37, Geliang Tang wrote:
> Yonglong Li <liyonglong@chinatelecom.cn> 于2021年6月30日周三 下午6:24写道:
> 
>>
>> ADD_ADDR share pm.addr_signal with RM_ADDR, so after RM_ADDR/ADD_ADDR
>> done we should not clean ADD_ADDR/RM_ADDR's addr_signal.
>>
>> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
>> ---
>>  net/mptcp/pm.c | 10 +++++++---
>>  1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
>> index 9d00fa6..50079e5 100644
>> --- a/net/mptcp/pm.c
>> +++ b/net/mptcp/pm.c
>> @@ -253,6 +253,7 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>>                               struct mptcp_addr_info *saddr, bool *echo, bool *port)
>>  {
>>         int ret = false;
>> +       u8 add_addr;
>>
>>         spin_lock_bh(&msk->pm.lock);
>>
>> @@ -267,7 +268,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>>                 goto out_unlock;
>>
>>         *saddr = msk->pm.local;
>> -       WRITE_ONCE(msk->pm.addr_signal, 0);
>> +       add_addr = msk->pm.addr_signal & ~(BIT(MPTCP_ADD_ADDR_SIGNAL) | BIT(MPTCP_ADD_ADDR_ECHO));
>> +       WRITE_ONCE(msk->pm.addr_signal, add_addr);
>>         ret = true;
>>
>>  out_unlock:
> 
> This part is removed in patch 3, why we need to add it here?
I will remove it in next patch.

> 
>> @@ -279,6 +281,7 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>>                              struct mptcp_rm_list *rm_list)
>>  {
>>         int ret = false, len;
>> +       u8 rm_addr;
>>
>>         spin_lock_bh(&msk->pm.lock);
>>
>> @@ -286,16 +289,17 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
>>         if (!mptcp_pm_should_rm_signal(msk))
>>                 goto out_unlock;
>>
>> +       rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
>>         len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
>>         if (len < 0) {
>> -               WRITE_ONCE(msk->pm.addr_signal, 0);
>> +               WRITE_ONCE(msk->pm.addr_signal, rm_addr);
>>                 goto out_unlock;
>>         }
>>         if (remaining < len)
>>                 goto out_unlock;
>>
>>         *rm_list = msk->pm.rm_list_tx;
>> -       WRITE_ONCE(msk->pm.addr_signal, 0);
>> +       WRITE_ONCE(msk->pm.addr_signal, rm_addr);
>>         ret = true;
>>
>>  out_unlock:
>> --
>> 1.8.3.1
>>
> 

-- 
Li YongLong

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v7 4/5] mptcp: remove some double-check
  2021-07-02  6:22     ` Yonglong Li
@ 2021-07-02  8:06       ` Geliang Tang
  0 siblings, 0 replies; 13+ messages in thread
From: Geliang Tang @ 2021-07-02  8:06 UTC (permalink / raw)
  To: Yonglong Li; +Cc: mptcp, Mat Martineau

Yonglong Li <liyonglong@chinatelecom.cn> 于2021年7月2日周五 下午2:22写道:
>
> Hi Geliang,
>
> I think these double check is unnecessary. the reason to keep them is?
> I think keep "!mptcp_pm_should_add_signal(msk)" you said in v6 is reasonable,
> It can avoid to get pm.lock in process of sending packets. But the other double
> check is useless.

The length re-check is for the no-spin-lock optimization too.

These code is no harm for yours, why can't you keep it there. :)

-Geliang


>
> On 2021/6/30 18:57, Geliang Tang wrote:
> > As I said in v6, I prefer to keep these double check code, no need to
> > remove them.
> >
> > Yonglong Li <liyonglong@chinatelecom.cn> 于2021年6月30日周三 下午6:24写道:
> >>
> >> remove some double-check in mptcp_established_options_add_addr() and
> >> mptcp_established_options_rm_addr()
> >>
> >> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
> >> ---
> >>  net/mptcp/options.c  | 14 ++------------
> >>  net/mptcp/pm.c       | 21 +++++++++++----------
> >>  net/mptcp/protocol.h |  4 ++--
> >>  3 files changed, 15 insertions(+), 24 deletions(-)
> >>
> >> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> >> index cceff0a..0711fc1 100644
> >> --- a/net/mptcp/options.c
> >> +++ b/net/mptcp/options.c
> >> @@ -659,7 +659,7 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
> >>         int len = 0;
> >>
> >>         if (!mptcp_pm_should_add_signal(msk) ||
> >> -           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr))
> >> +           !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, opts, &add_addr, &len))
> >>                 return false;
> >>
> >>         if (((add_addr & BIT(MPTCP_ADD_ADDR_ECHO)) ||
> >> @@ -674,10 +674,6 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
> >>                 drop_other_suboptions = true;
> >>         }
> >>
> >> -       len = mptcp_add_addr_len(msk, opts);
> >> -       if (remaining < len)
> >> -               return false;
> >> -
> >>         *size = len;
> >>         if (drop_other_suboptions)
> >>                 *size -= opt_size;
> >> @@ -707,13 +703,7 @@ static bool mptcp_established_options_rm_addr(struct sock *sk,
> >>         int i, len;
> >>
> >>         if (!mptcp_pm_should_rm_signal(msk) ||
> >> -           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list)))
> >> -               return false;
> >> -
> >> -       len = mptcp_rm_addr_len(&rm_list);
> >> -       if (len < 0)
> >> -               return false;
> >> -       if (remaining < len)
> >> +           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, &len)))
> >>                 return false;
> >>
> >>         *size = len;
> >> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> >> index 9c5b15c..2311ea5 100644
> >> --- a/net/mptcp/pm.c
> >> +++ b/net/mptcp/pm.c
> >> @@ -255,9 +255,9 @@ void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
> >>
> >>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
> >>                               unsigned int opt_size, unsigned int remaining,
> >> -                             struct mptcp_out_options *opts,  u8 *add_addr)
> >> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len)
> >>  {
> >> -       int ret = false, len;
> >> +       int ret = false;
> >>
> >>         spin_lock_bh(&msk->pm.lock);
> >>
> >> @@ -276,8 +276,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
> >>                 remaining += opt_size;
> >>         }
> >>
> >> -       len = mptcp_add_addr_len(msk, opts);
> >> -       if (remaining < len)
> >> +       *len = mptcp_add_addr_len(msk, opts);
> >> +       if (remaining < *len)
> >>                 goto out_unlock;
> >>
> >>         if ((msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_ECHO)))
> >> @@ -287,17 +287,18 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
> >>
> >>         ret = true;
> >>  out_unlock:
> >> +       spin_unlock_bh(&msk->pm.lock);
> >> +
> >>         if ((mptcp_pm_should_add_signal_echo(msk)) && (mptcp_pm_should_add_signal_addr(msk)))
> >>                 mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
> >>
> >> -       spin_unlock_bh(&msk->pm.lock);
> >>         return ret;
> >>  }
> >>
> >>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> >> -                            struct mptcp_rm_list *rm_list)
> >> +                            struct mptcp_rm_list *rm_list, int *len)
> >>  {
> >> -       int ret = false, len;
> >> +       int ret = false;
> >>         u8 rm_addr;
> >>
> >>         spin_lock_bh(&msk->pm.lock);
> >> @@ -307,12 +308,12 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> >>                 goto out_unlock;
> >>
> >>         rm_addr = msk->pm.addr_signal & ~BIT(MPTCP_RM_ADDR_SIGNAL);
> >> -       len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
> >> -       if (len < 0) {
> >> +       *len = mptcp_rm_addr_len(&msk->pm.rm_list_tx);
> >> +       if (*len < 0) {
> >>                 WRITE_ONCE(msk->pm.addr_signal, rm_addr);
> >>                 goto out_unlock;
> >>         }
> >> -       if (remaining < len)
> >> +       if (remaining < *len)
> >>                 goto out_unlock;
> >>
> >>         *rm_list = msk->pm.rm_list_tx;
> >> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> >> index caa4a60..5d7c9d7 100644
> >> --- a/net/mptcp/protocol.h
> >> +++ b/net/mptcp/protocol.h
> >> @@ -770,9 +770,9 @@ static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
> >>
> >>  bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, struct sk_buff *skb,
> >>                               unsigned int opt_size, unsigned int remaining,
> >> -                             struct mptcp_out_options *opts,  u8 *add_addr);
> >> +                             struct mptcp_out_options *opts,  u8 *add_addr, int *len);
> >>  bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
> >> -                            struct mptcp_rm_list *rm_list);
> >> +                            struct mptcp_rm_list *rm_list, int *len);
> >>  int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
> >>
> >>  void __init mptcp_pm_nl_init(void);
> >> --
> >> 1.8.3.1
> >>
> >>
> >
>
> --
> Li YongLong

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, back to index

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-30 10:24 [PATCH v7 0/4] mptcp: fix conflicts when using pm.add_signal in ADD_ADDR/echo and RM_ADDR process Yonglong Li
2021-06-30 10:24 ` [PATCH v7 1/5] mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other Yonglong Li
2021-06-30 10:37   ` Geliang Tang
2021-07-02  6:23     ` Yonglong Li
2021-06-30 10:24 ` [PATCH v7 2/5] mptcp: make MPTCP_ADD_ADDR_SIGNAL and MPTCP_ADD_ADDR_ECHO separate Yonglong Li
2021-06-30 10:24 ` [PATCH v7 3/5] mptcp: build ADD_ADDR/echo-ADD_ADDR option according pm.add_signal Yonglong Li
2021-06-30 11:14   ` Geliang Tang
2021-07-02  6:15     ` Yonglong Li
2021-06-30 10:24 ` [PATCH v7 4/5] mptcp: remove some double-check Yonglong Li
2021-06-30 10:57   ` Geliang Tang
2021-07-02  6:22     ` Yonglong Li
2021-07-02  8:06       ` Geliang Tang
2021-06-30 10:24 ` [PATCH v7 5/5] mptcp: remove MPTCP_ADD_ADDR_IPV6 and MPTCP_ADD_ADDR_PORT Yonglong Li

MPTCP Linux Development

Archives are clonable:
	git clone --mirror https://lore.kernel.org/mptcp/0 mptcp/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 mptcp mptcp/ https://lore.kernel.org/mptcp \
		mptcp@lists.linux.dev
	public-inbox-index mptcp

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/dev.linux.lists.mptcp


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git