Skip to contentSkip to conversation

RM_ADDR: remove a list of addrs

PATCH Superseded Geliang Tang 2 participants 12 messages Feb 1, 2021 – Feb 2, 2021

Subsystems (3)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Geliang Tang

author
#0 lore raw

v2 cover RM_ADDR: remove a list of addrs

v2:
- use an array of ids instead of a u64 map
- drop "mptcp: update the netlink event for rm_addr" in v1
- tag: export/20210131T062218

This patchset added the removing a list of addresses support for RM_ADDR. It addressed issue #140.

Geliang Tang (7):
mptcp: remove multi addrs on outgoing path
mptcp: remove multi addrs on incoming path
mptcp: remove multi addresses in PM
mptcp: remove multi subflows in PM
mptcp: implement mptcp_nl_remove_addrs_and_subflows
mptcp: remove a list of addrs when flushing
selftests: mptcp: add testcases for removing addrs

 include/net/mptcp.h                           |   4 +-
 net/mptcp/options.c                           |  55 +++--
 net/mptcp/pm.c                                |  28 +--
 net/mptcp/pm_netlink.c                        | 190 ++++++++++++++----
 net/mptcp/protocol.h                          |  26 ++-
 .../testing/selftests/net/mptcp/mptcp_join.sh |  23 +++
 6 files changed, 252 insertions(+), 74 deletions(-)
Signature · 1 line
2.29.2
author
#1 lore raw

PATCH v2 1/7 mptcp: remove multi addrs on outgoing path

This patch changed the member rm_id of struct mptcp_out_options as an array of the removing address ids, and renamed it to rm_ids. The array size was definced as a new macro MPTCP_RM_IDS_MAX.

Added a new function named mptcp_get_rm_ids_nr to get the number of address ids in the ids array.

In mptcp_established_options_rm_addr, invoked mptcp_pm_rm_addr_signal to get the ids array. According the number of addresses in it, calculated the padded RM_ADDR suboption length. And saved the ids array in struct mptcp_out_options's rm_ids member.

In mptcp_write_options, iterated each address id from struct mptcp_out_options's rm_ids member, set the zero ones as TCPOPT_NOP, then filled them into the RM_ADDR suboption.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 include/net/mptcp.h  |  4 +++-
 net/mptcp/options.c  | 40 ++++++++++++++++++++++++++++++++--------
 net/mptcp/pm.c       |  3 +--
 net/mptcp/protocol.h | 14 ++++++++++++--
 4 files changed, 48 insertions(+), 13 deletions(-)
include/net/mptcp.h +3 -1
index 5694370be3d4..1d33fea674d2 100644
@@ -34,6 +34,8 @@ struct mptcp_ext {
 	/* one byte hole */
 };
 
+#define MPTCP_RM_IDS_MAX	8
+
 struct mptcp_out_options {
 #if IS_ENABLED(CONFIG_MPTCP)
 	u16 suboptions;
@@ -48,7 +50,7 @@ struct mptcp_out_options {
 	u8 addr_id;
 	u16 port;
 	u64 ahmac;
-	u8 rm_id;
+	u8 rm_ids[MPTCP_RM_IDS_MAX];
 	u8 join_id;
 	u8 backup;
 	u32 nonce;
net/mptcp/options.c +32 -8
index bb874c5d663a..3ce7917327d1 100644
@@ -671,20 +671,27 @@ static bool mptcp_established_options_rm_addr(struct sock *sk,
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
-	u8 rm_id;
+	u8 rm_ids[MPTCP_RM_IDS_MAX], i, nr, align;
 
 	if (!mptcp_pm_should_rm_signal(msk) ||
-	    !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_id)))
+	    !(mptcp_pm_rm_addr_signal(msk, remaining, rm_ids)))
 		return false;
 
-	if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE)
+	nr = mptcp_get_rm_ids_nr(rm_ids);
+	if (nr > 1)
+		align = 5;
+	if (nr > 5)
+		align = 9;
+
+	if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE + align)
 		return false;
 
-	*size = TCPOLEN_MPTCP_RM_ADDR_BASE;
+	*size = TCPOLEN_MPTCP_RM_ADDR_BASE + align;
 	opts->suboptions |= OPTION_MPTCP_RM_ADDR;
-	opts->rm_id = rm_id;
+	memcpy(opts->rm_ids, rm_ids, MPTCP_RM_IDS_MAX);
 
-	pr_debug("rm_id=%d", opts->rm_id);
+	for (i = 0; i < nr; i++)
+		pr_debug("rm_ids[%d]=%d", i, opts->rm_ids[i]);
 
 	return true;
 }
@@ -1212,9 +1219,26 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 	}
 
 	if (OPTION_MPTCP_RM_ADDR & opts->suboptions) {
+		u8 i, nr;
+
+		nr = mptcp_get_rm_ids_nr(opts->rm_ids);
+		for (i = 0; i < MPTCP_RM_IDS_MAX; i++) {
+			if (!opts->rm_ids[i])
+				opts->rm_ids[i] = TCPOPT_NOP;
+		}
 		*ptr++ = mptcp_option(MPTCPOPT_RM_ADDR,
-				      TCPOLEN_MPTCP_RM_ADDR_BASE,
-				      0, opts->rm_id);
+				      TCPOLEN_MPTCP_RM_ADDR_BASE + nr,
+				      0, opts->rm_ids[0]);
+		if (nr > 1) {
+			put_unaligned_be32(opts->rm_ids[1] << 24 | opts->rm_ids[2] << 16 |
+					   opts->rm_ids[3] << 8 | opts->rm_ids[4], ptr);
+			ptr += 1;
+		}
+		if (nr > 5) {
+			put_unaligned_be32(opts->rm_ids[5] << 24 | opts->rm_ids[6] << 16 |
+					   opts->rm_ids[7] << 8 | TCPOPT_NOP, ptr);
+			ptr += 1;
+		}
 	}
 
 	if (OPTION_MPTCP_PRIO & opts->suboptions) {
net/mptcp/pm.c +1 -2
index 6fd4b2c1b076..764cd62c59ba 100644
@@ -258,7 +258,7 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 }
 
 bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			     u8 *rm_id)
+			     u8 rm_ids[])
 {
 	int ret = false;
 
@@ -271,7 +271,6 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 	if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE)
 		goto out_unlock;
 
-	*rm_id = msk->pm.rm_id;
 	WRITE_ONCE(msk->pm.addr_signal, 0);
 	ret = true;
 
net/mptcp/protocol.h +12 -2
index d31edbae8da8..411af3334a25 100644
@@ -60,7 +60,7 @@
 #define TCPOLEN_MPTCP_ADD_ADDR6_BASE	20
 #define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT	24
 #define TCPOLEN_MPTCP_PORT_LEN		4
-#define TCPOLEN_MPTCP_RM_ADDR_BASE	4
+#define TCPOLEN_MPTCP_RM_ADDR_BASE	3
 #define TCPOLEN_MPTCP_PRIO		3
 #define TCPOLEN_MPTCP_PRIO_ALIGN	4
 #define TCPOLEN_MPTCP_FASTCLOSE		12
@@ -289,6 +289,16 @@ struct mptcp_sock {
 #define mptcp_for_each_subflow(__msk, __subflow)			\
 	list_for_each_entry(__subflow, &((__msk)->conn_list), node)
 
+static inline u8 mptcp_get_rm_ids_nr(u8 rm_ids[])
+{
+	int i, nr = 0;
+
+	for (i = 0; i < MPTCP_RM_IDS_MAX && rm_ids[i]; i++)
+		nr++;
+
+	return nr;
+}
+
 static inline void msk_owned_by_me(const struct mptcp_sock *msk)
 {
 	sock_owned_by_me((const struct sock *)msk);
@@ -714,7 +724,7 @@ static inline unsigned int mptcp_add_addr_len(int family, bool echo, bool port)
 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_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			     u8 *rm_id);
+			     u8 rm_ids[]);
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
 
 void __init mptcp_pm_nl_init(void);
Signature · 1 line
2.29.2
author
#2 lore raw

PATCH v2 2/7 mptcp: remove multi addrs on incoming path

This patch changed the member rm_id in struct mptcp_options_received as an array of the removing address ids, and renamed it to rm_ids.

In mptcp_parse_option, parsed the RM_ADDR suboption and filled them into the ids array in struct mptcp_options_received.

In mptcp_incoming_options, passed this ids array to the function mptcp_pm_rm_addr_received.

It alse changed the parameter type of mptcp_pm_rm_addr_received.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/options.c  | 15 +++++++++++----
 net/mptcp/pm.c       |  9 +++++----
 net/mptcp/protocol.h |  4 ++--
 3 files changed, 18 insertions(+), 10 deletions(-)
net/mptcp/options.c +11 -4
index 3ce7917327d1..bd7a8b442088 100644
@@ -26,6 +26,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
 	int expected_opsize;
 	u8 version;
 	u8 flags;
+	u8 i, nr;
 
 	switch (subtype) {
 	case MPTCPOPT_MP_CAPABLE:
@@ -272,14 +273,20 @@ static void mptcp_parse_option(const struct sk_buff *skb,
 		break;
 
 	case MPTCPOPT_RM_ADDR:
-		if (opsize != TCPOLEN_MPTCP_RM_ADDR_BASE)
+		if (opsize < TCPOLEN_MPTCP_RM_ADDR_BASE + 1 ||
+		    opsize > TCPOLEN_MPTCP_RM_ADDR_BASE + MPTCP_RM_IDS_MAX)
 			break;
 
 		ptr++;
 
 		mp_opt->rm_addr = 1;
-		mp_opt->rm_id = *ptr++;
-		pr_debug("RM_ADDR: id=%d", mp_opt->rm_id);
+		memset(mp_opt->rm_ids, 0, MPTCP_RM_IDS_MAX);
+		nr = opsize - TCPOLEN_MPTCP_RM_ADDR_BASE;
+		for (i = 0; i < nr; i++)
+			mp_opt->rm_ids[i] = *ptr++;
+		pr_debug("RM_ADDR: ids_nr=%d", nr);
+		for (i = 0; i < nr; i++)
+			pr_debug(" -> id[%d]=%d", i, mp_opt->rm_ids[i]);
 		break;
 
 	case MPTCPOPT_MP_PRIO:
@@ -1040,7 +1047,7 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
 	}
 
 	if (mp_opt.rm_addr) {
-		mptcp_pm_rm_addr_received(msk, mp_opt.rm_id);
+		mptcp_pm_rm_addr_received(msk, mp_opt.rm_ids);
 		mp_opt.rm_addr = 0;
 	}
 
net/mptcp/pm.c +5 -4
index 764cd62c59ba..5ff59a84de2b 100644
@@ -205,17 +205,18 @@ void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk)
 	mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
 }
 
-void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id)
+void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_ids[])
 {
 	struct mptcp_pm_data *pm = &msk->pm;
+	u8 i;
 
-	pr_debug("msk=%p remote_id=%d", msk, rm_id);
+	pr_debug("msk=%p remote_ids_nr=%d", msk, mptcp_get_rm_ids_nr(rm_ids));
 
-	mptcp_event_addr_removed(msk, rm_id);
+	for (i = 0; i < MPTCP_RM_IDS_MAX && rm_ids[i]; i++)
+		mptcp_event_addr_removed(msk, rm_ids[i]);
 
 	spin_lock_bh(&pm->lock);
 	mptcp_pm_schedule_work(msk, MPTCP_PM_RM_ADDR_RECEIVED);
-	pm->rm_id = rm_id;
 	spin_unlock_bh(&pm->lock);
 }
 
net/mptcp/protocol.h +2 -2
index 411af3334a25..3930a92beeb4 100644
@@ -140,7 +140,7 @@ struct mptcp_options_received {
 		mpc_map:1,
 		__unused:2;
 	u8	addr_id;
-	u8	rm_id;
+	u8	rm_ids[MPTCP_RM_IDS_MAX];
 	union {
 		struct in_addr	addr;
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
@@ -660,7 +660,7 @@ void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id);
 void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
 				const struct mptcp_addr_info *addr);
 void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk);
-void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id);
+void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_ids[]);
 void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup);
 int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk,
 				 struct mptcp_addr_info *addr,
Signature · 1 line
2.29.2
author
#3 lore raw

PATCH v2 3/7 mptcp: remove multi addresses in PM

This patch changed the member rm_id of struct mptcp_pm_data as an array of the removing address ids, and renamed it to rm_ids. Used memset to initialize pm.rm_ids, and memcpy to copy it.

In mptcp_pm_nl_rm_addr_received, iterated each address id from pm.rm_ids, then shut down and closed each address id's subsocket.

In mptcp_pm_remove_anno_addr, put the single address id into an ids array, and passed it to mptcp_pm_remove_addr.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm.c         | 10 ++++++----
 net/mptcp/pm_netlink.c | 41 ++++++++++++++++++++++++-----------------
 net/mptcp/protocol.h   |  4 ++--
 3 files changed, 32 insertions(+), 23 deletions(-)
net/mptcp/pm.c +6 -4
index 5ff59a84de2b..f4d7f3afd1e5 100644
@@ -39,18 +39,18 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 	return 0;
 }
 
-int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id)
+int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_ids[])
 {
 	u8 rm_addr = READ_ONCE(msk->pm.addr_signal);
 
-	pr_debug("msk=%p, local_id=%d", msk, local_id);
+	pr_debug("msk=%p, local_ids_nr=%d", msk, mptcp_get_rm_ids_nr(local_ids));
 
 	if (rm_addr) {
 		pr_warn("addr_signal error, rm_addr=%d", rm_addr);
 		return -EINVAL;
 	}
 
-	msk->pm.rm_id = local_id;
+	memcpy(msk->pm.rm_ids, local_ids, MPTCP_RM_IDS_MAX);
 	rm_addr |= BIT(MPTCP_RM_ADDR_SIGNAL);
 	WRITE_ONCE(msk->pm.addr_signal, rm_addr);
 	return 0;
@@ -217,6 +217,7 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_ids[])
 
 	spin_lock_bh(&pm->lock);
 	mptcp_pm_schedule_work(msk, MPTCP_PM_RM_ADDR_RECEIVED);
+	memcpy(pm->rm_ids, rm_ids, MPTCP_RM_IDS_MAX);
 	spin_unlock_bh(&pm->lock);
 }
 
@@ -272,6 +273,7 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 	if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE)
 		goto out_unlock;
 
+	memcpy(rm_ids, msk->pm.rm_ids, MPTCP_RM_IDS_MAX);
 	WRITE_ONCE(msk->pm.addr_signal, 0);
 	ret = true;
 
@@ -291,7 +293,7 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
 	msk->pm.add_addr_accepted = 0;
 	msk->pm.local_addr_used = 0;
 	msk->pm.subflows = 0;
-	msk->pm.rm_id = 0;
+	memset(msk->pm.rm_ids, 0, MPTCP_RM_IDS_MAX);
 	WRITE_ONCE(msk->pm.work_pending, false);
 	WRITE_ONCE(msk->pm.addr_signal, 0);
 	WRITE_ONCE(msk->pm.accept_addr, false);
net/mptcp/pm_netlink.c +24 -17

72 lines not on this page · raw message

net/mptcp/protocol.h +2 -2
index 3930a92beeb4..5adf85e3fd15 100644
@@ -205,7 +205,7 @@ struct mptcp_pm_data {
 	u8		local_addr_used;
 	u8		subflows;
 	u8		status;
-	u8		rm_id;
+	u8		rm_ids[MPTCP_RM_IDS_MAX];
 };
 
 struct mptcp_data_frag {
@@ -674,7 +674,7 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,
 int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 			   const struct mptcp_addr_info *addr,
 			   bool echo, bool port);
-int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id);
+int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_ids[]);
 int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id);
 
 void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
Signature · 1 line
2.29.2
author
#4 lore raw

PATCH v2 4/7 mptcp: remove multi subflows in PM

This patch dealt with removing multi subflows in PM:

In mptcp_pm_remove_subflow, changed the input parameter local_id as an array of removing address ids, and passed the array to mptcp_pm_nl_rm_subflow_received.

In mptcp_pm_nl_rm_subflow_received, iterated each address id from the received ids array. Then shut down and closed each address id's subsocket.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm.c         |  6 +++---
 net/mptcp/pm_netlink.c | 41 ++++++++++++++++++++++++-----------------
 net/mptcp/protocol.h   |  4 ++--
 3 files changed, 29 insertions(+), 22 deletions(-)
net/mptcp/pm.c +3 -3
index f4d7f3afd1e5..611863beb48f 100644
@@ -56,12 +56,12 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_ids[])
 	return 0;
 }
 
-int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id)
+int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_ids[])
 {
-	pr_debug("msk=%p, local_id=%d", msk, local_id);
+	pr_debug("msk=%p, local_ids_nr=%d", msk, mptcp_get_rm_ids_nr(local_ids));
 
 	spin_lock_bh(&msk->pm.lock);
-	mptcp_pm_nl_rm_subflow_received(msk, local_id);
+	mptcp_pm_nl_rm_subflow_received(msk, local_ids);
 	spin_unlock_bh(&msk->pm.lock);
 	return 0;
 }
net/mptcp/pm_netlink.c +24 -17

76 lines not on this page · raw message

net/mptcp/protocol.h +2 -2
index 5adf85e3fd15..3a043eadd3f2 100644
@@ -675,7 +675,7 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 			   const struct mptcp_addr_info *addr,
 			   bool echo, bool port);
 int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_ids[]);
-int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id);
+int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_ids[]);
 
 void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
 		 const struct sock *ssk, gfp_t gfp);
@@ -730,7 +730,7 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
 void __init mptcp_pm_nl_init(void);
 void mptcp_pm_nl_data_init(struct mptcp_sock *msk);
 void mptcp_pm_nl_work(struct mptcp_sock *msk);
-void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, u8 rm_id);
+void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, u8 rm_ids[]);
 int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
 unsigned int mptcp_pm_get_add_addr_signal_max(struct mptcp_sock *msk);
 unsigned int mptcp_pm_get_add_addr_accept_max(struct mptcp_sock *msk);
Signature · 1 line
2.29.2
author
#5 lore raw

PATCH v2 5/7 mptcp: implement mptcp_nl_remove_addrs_and_subflows

This patch implemented the function to remove a list of addresses and subflows, named mptcp_nl_remove_addrs_and_subflows, which had a input parameter rm_ids as an ids array.

If the msk->conn_list is empty, only invoke mptcp_pm_remove_anno_addrs to remove the announced addresses. If it's not empty, invoke mptcp_pm_remove_anno_addrs_and_subflows to remove the announced addresses and the subflows.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm_netlink.c | 89 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)
net/mptcp/pm_netlink.c +89 -0
index dea5cf328ad4..b30e3dbf4287 100644
@@ -1198,6 +1198,95 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
 	return ret;
 }
 
+static void mptcp_pm_remove_anno_addrs(struct mptcp_sock *msk, u8 rm_ids[])
+{
+	u8 active_ids[MPTCP_RM_IDS_MAX] = { 0 }, i;
+	struct sock *sk = (struct sock *)msk;
+	struct net *net = sock_net(sk);
+	struct pm_nl_pernet *pernet;
+
+	pernet = net_generic(net, pm_nl_pernet_id);
+	spin_lock_bh(&pernet->lock);
+	for (i = 0; i < MPTCP_RM_IDS_MAX && rm_ids[i]; i++) {
+		struct mptcp_pm_addr_entry *entry;
+
+		entry = __lookup_addr_by_id(pernet, rm_ids[i]);
+		if (entry && remove_anno_list_by_saddr(msk, &entry->addr))
+			active_ids[i] = rm_ids[i];
+	}
+	spin_unlock_bh(&pernet->lock);
+
+	if (!mptcp_get_rm_ids_nr(active_ids))
+		return;
+
+	spin_lock_bh(&msk->pm.lock);
+	mptcp_pm_remove_addr(msk, active_ids);
+	spin_unlock_bh(&msk->pm.lock);
+}
+
+static void mptcp_pm_remove_anno_addrs_and_subflows(struct mptcp_sock *msk, u8 local_ids[])
+{
+	u8 subflow_ids[MPTCP_RM_IDS_MAX] = { 0 };
+	u8 address_ids[MPTCP_RM_IDS_MAX] = { 0 };
+	struct sock *sk = (struct sock *)msk;
+	struct net *net = sock_net(sk);
+	struct pm_nl_pernet *pernet;
+	int i;
+
+	pernet = net_generic(net, pm_nl_pernet_id);
+	spin_lock_bh(&pernet->lock);
+	for (i = 0; i < MPTCP_RM_IDS_MAX && local_ids[i]; i++) {
+		struct mptcp_pm_addr_entry *entry;
+
+		entry = __lookup_addr_by_id(pernet, local_ids[i]);
+		if (entry && lookup_subflow_by_saddr(&msk->conn_list, &entry->addr))
+			subflow_ids[i] = local_ids[i];
+		else if (entry && remove_anno_list_by_saddr(msk, &entry->addr))
+			address_ids[i] = local_ids[i];
+	}
+	spin_unlock_bh(&pernet->lock);
+
+	if (mptcp_get_rm_ids_nr(subflow_ids)) {
+		spin_lock_bh(&msk->pm.lock);
+		mptcp_pm_remove_addr(msk, subflow_ids);
+		spin_unlock_bh(&msk->pm.lock);
+		mptcp_pm_remove_subflow(msk, subflow_ids);
+	}
+	if (mptcp_get_rm_ids_nr(address_ids)) {
+		spin_lock_bh(&msk->pm.lock);
+		mptcp_pm_remove_addr(msk, address_ids);
+		spin_unlock_bh(&msk->pm.lock);
+	}
+}
+
+static void mptcp_nl_remove_addrs_and_subflows(struct net *net, u8 rm_ids[])
+{
+	long s_slot = 0, s_num = 0;
+	struct mptcp_sock *msk;
+
+	pr_debug("rm_ids_nr=%d", mptcp_get_rm_ids_nr(rm_ids));
+
+	if (!mptcp_get_rm_ids_nr(rm_ids))
+		return;
+
+	while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
+		struct sock *sk = (struct sock *)msk;
+
+		if (list_empty(&msk->conn_list)) {
+			mptcp_pm_remove_anno_addrs(msk, rm_ids);
+			goto next;
+		}
+
+		lock_sock(sk);
+		mptcp_pm_remove_anno_addrs_and_subflows(msk, rm_ids);
+		release_sock(sk);
+
+next:
+		sock_put(sk);
+		cond_resched();
+	}
+}
+
 static void __flush_addrs(struct net *net, struct list_head *list)
 {
 	while (!list_empty(list)) {
Signature · 1 line
2.29.2
author
#6 lore raw

PATCH v2 6/7 mptcp: remove a list of addrs when flushing

This patch invoked mptcp_nl_remove_addrs_and_subflows to remove a list of addresses when the netlink flushes addresses, instead of using mptcp_nl_remove_subflow_and_signal_addr to remove them one by one.

Since mptcp_nl_remove_subflow_and_signal_addr was dropped from __flush_addrs, __flush_addrs could be invoked under the locks. So dropped the useless free_list in mptcp_nl_cmd_flush_addrs and the unused parameter net in __flush_addrs.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm_netlink.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
net/mptcp/pm_netlink.c +13 -6
index b30e3dbf4287..da03f727d99e 100644
@@ -1287,14 +1287,13 @@ static void mptcp_nl_remove_addrs_and_subflows(struct net *net, u8 rm_ids[])
 	}
 }
 
-static void __flush_addrs(struct net *net, struct list_head *list)
+static void __flush_addrs(struct list_head *list)
 {
 	while (!list_empty(list)) {
 		struct mptcp_pm_addr_entry *cur;
 
 		cur = list_entry(list->next,
 				 struct mptcp_pm_addr_entry, list);
-		mptcp_nl_remove_subflow_and_signal_addr(net, &cur->addr);
 		list_del_rcu(&cur->list);
 		mptcp_pm_free_addr_entry(cur);
 	}
@@ -1311,15 +1310,23 @@ static void __reset_counters(struct pm_nl_pernet *pernet)
 static int mptcp_nl_cmd_flush_addrs(struct sk_buff *skb, struct genl_info *info)
 {
 	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
-	LIST_HEAD(free_list);
+	u8 rm_ids[MPTCP_RM_IDS_MAX] = { 0 }, i = 0;
+	struct mptcp_pm_addr_entry *entry;
+
+	spin_lock_bh(&pernet->lock);
+	list_for_each_entry(entry, &pernet->local_addr_list, list) {
+		if (entry->addr.id && i < MPTCP_RM_IDS_MAX)
+			rm_ids[i++] = entry->addr.id;
+	}
+	spin_unlock_bh(&pernet->lock);
+	mptcp_nl_remove_addrs_and_subflows(sock_net(skb->sk), rm_ids);
 
 	spin_lock_bh(&pernet->lock);
-	list_splice_init(&pernet->local_addr_list, &free_list);
+	__flush_addrs(&pernet->local_addr_list);
 	__reset_counters(pernet);
 	pernet->next_id = 1;
 	bitmap_zero(pernet->id_bitmap, MAX_ADDR_ID + 1);
 	spin_unlock_bh(&pernet->lock);
-	__flush_addrs(sock_net(skb->sk), &free_list);
 	return 0;
 }
 
@@ -1916,7 +1923,7 @@ static void __net_exit pm_nl_exit_net(struct list_head *net_list)
 		/* net is removed from namespace list, can't race with
 		 * other modifiers
 		 */
-		__flush_addrs(net, &pernet->local_addr_list);
+		__flush_addrs(&pernet->local_addr_list);
 	}
 }
 
Signature · 1 line
2.29.2
author
#7 lore raw

PATCH v2 7/7 selftests: mptcp: add testcases for removing addrs

This patch added the testcases for removing a list of addresses. Used the netlink to flush the addresses in the testcases.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +23 -0
index 964db9ed544f..45e1aff7a31c 100755
@@ -869,6 +869,29 @@ remove_tests()
 	chk_join_nr "flush subflows and signal" 3 3 3
 	chk_add_nr 1 1
 	chk_rm_nr 2 2
+
+	# subflows flush
+	reset
+	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
+	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
+	ip netns exec $ns2 ./pm_nl_ctl add 10.0.2.2 flags subflow id 150
+	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
+	ip netns exec $ns2 ./pm_nl_ctl add 10.0.4.2 flags subflow
+	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
+	chk_join_nr "flush subflows" 3 3 3
+	chk_rm_nr 3 3
+
+	# addresses flush
+	reset
+	ip netns exec $ns1 ./pm_nl_ctl limits 3 3
+	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal id 250
+	ip netns exec $ns1 ./pm_nl_ctl add 10.0.3.1 flags signal
+	ip netns exec $ns1 ./pm_nl_ctl add 10.0.4.1 flags signal
+	ip netns exec $ns2 ./pm_nl_ctl limits 3 3
+	run_tests $ns1 $ns2 10.0.1.1 0 -8 -8 slow
+	chk_join_nr "flush addresses" 3 3 3
+	chk_add_nr 3 3
+	chk_rm_nr 0 0
 }
 
 add_tests()
Signature · 1 line
2.29.2
#8 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 3/7] mptcp: remove multi addresses in PM

In reply to Geliang Tang
Quoted 44 lines · Geliang Tang

This patch changed the member rm_id of struct mptcp_pm_data as an array of the removing address ids, and renamed it to rm_ids. Used memset to initialize pm.rm_ids, and memcpy to copy it.

In mptcp_pm_nl_rm_addr_received, iterated each address id from pm.rm_ids, then shut down and closed each address id's subsocket.

In mptcp_pm_remove_anno_addr, put the single address id into an ids array, and passed it to mptcp_pm_remove_addr.

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

---

net/mptcp/pm.c         | 10 ++++++----
net/mptcp/pm_netlink.c | 41 ++++++++++++++++++++++++-----------------
net/mptcp/protocol.h   |  4 ++--
3 files changed, 32 insertions(+), 23 deletions(-)
net/mptcp/pm.c +3 -3
index 5ff59a84de2b..f4d7f3afd1e5 100644
@@ -39,18 +39,18 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 	return 0;
 }
 
-int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id)
+int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_ids[])
 {
 	u8 rm_addr = READ_ONCE(msk->pm.addr_signal);
 
-	pr_debug("msk=%p, local_id=%d", msk, local_id);
+	pr_debug("msk=%p, local_ids_nr=%d", msk, mptcp_get_rm_ids_nr(local_ids));
 
 	if (rm_addr) {
 		pr_warn("addr_signal error, rm_addr=%d", rm_addr);
 		return -EINVAL;
 	}
 
-	msk->pm.rm_id = local_id;
+	memcpy(msk->pm.rm_ids, local_ids, MPTCP_RM_IDS_MAX);
 	rm_addr |= BIT(MPTCP_RM_ADDR_SIGNAL);
 	WRITE_ONCE(msk->pm.addr_signal, rm_addr);
 	return 0;

net/mptcp/pm.c void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_ids[]) · line 220

Quoted 4 lines
net/mptcp/pm.c +1 -0
@@ -217,6 +217,7 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_ids[])
 
 	spin_lock_bh(&pm->lock);
 	mptcp_pm_schedule_work(msk, MPTCP_PM_RM_ADDR_RECEIVED);
+	memcpy(pm->rm_ids, rm_ids, MPTCP_RM_IDS_MAX);

Looks like a pre-existing issue, but seeing the different areas of code writing to pm->rm_ids, that array is getting used for both sending and receiving right? If an incoming rm_addr arrives at the same time the PM tries to send an rm_addr, it looks like we could end up overwriting the ids before they are processed.

Could have separate rm_ids for incoming and outgoing - that seems simpler than trying to keep track of what the list is currently in use for. What do you think?

Mat

Quoted 126 lines
net/mptcp/pm.c +2 -1
 	spin_unlock_bh(&pm->lock);
 }
 
@@ -272,6 +273,7 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 	if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE)
 		goto out_unlock;
 
+	memcpy(rm_ids, msk->pm.rm_ids, MPTCP_RM_IDS_MAX);
 	WRITE_ONCE(msk->pm.addr_signal, 0);
 	ret = true;
 
@@ -291,7 +293,7 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
 	msk->pm.add_addr_accepted = 0;
 	msk->pm.local_addr_used = 0;
 	msk->pm.subflows = 0;
-	msk->pm.rm_id = 0;
+	memset(msk->pm.rm_ids, 0, MPTCP_RM_IDS_MAX);
 	WRITE_ONCE(msk->pm.work_pending, false);
 	WRITE_ONCE(msk->pm.addr_signal, 0);
 	WRITE_ONCE(msk->pm.accept_addr, false);
net/mptcp/pm_netlink.c +24 -17
index f2a6e77c1dec..228cf5dfddd7 100644
@@ -574,36 +574,42 @@ static void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
 {
 	struct mptcp_subflow_context *subflow, *tmp;
 	struct sock *sk = (struct sock *)msk;
+	u8 i, nr;
 
-	pr_debug("address rm_id %d", msk->pm.rm_id);
+	nr = mptcp_get_rm_ids_nr(msk->pm.rm_ids);
+
+	pr_debug("address rm_ids_nr %d", nr);
 
 	msk_owned_by_me(msk);
 
-	if (!msk->pm.rm_id)
+	if (!nr)
 		return;
 
 	if (list_empty(&msk->conn_list))
 		return;
 
-	list_for_each_entry_safe(subflow, tmp, &msk->conn_list, node) {
-		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
-		int how = RCV_SHUTDOWN | SEND_SHUTDOWN;
+	for (i = 0; i < MPTCP_RM_IDS_MAX && msk->pm.rm_ids[i]; i++) {
+		list_for_each_entry_safe(subflow, tmp, &msk->conn_list, node) {
+			struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+			int how = RCV_SHUTDOWN | SEND_SHUTDOWN;
 
-		if (msk->pm.rm_id != subflow->remote_id)
-			continue;
+			if (msk->pm.rm_ids[i] != subflow->remote_id)
+				continue;
 
-		spin_unlock_bh(&msk->pm.lock);
-		mptcp_subflow_shutdown(sk, ssk, how);
-		mptcp_close_ssk(sk, ssk, subflow);
-		spin_lock_bh(&msk->pm.lock);
+			pr_debug(" -> address rm_ids[%d]=%u", i, msk->pm.rm_ids[i]);
+			spin_unlock_bh(&msk->pm.lock);
+			mptcp_subflow_shutdown(sk, ssk, how);
+			mptcp_close_ssk(sk, ssk, subflow);
+			spin_lock_bh(&msk->pm.lock);
 
-		msk->pm.add_addr_accepted--;
-		msk->pm.subflows--;
-		WRITE_ONCE(msk->pm.accept_addr, true);
+			msk->pm.add_addr_accepted--;
+			msk->pm.subflows--;
+			WRITE_ONCE(msk->pm.accept_addr, true);
 
-		__MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMADDR);
+			__MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMADDR);
 
-		break;
+			break;
+		}
 	}
 }
 
@@ -1070,12 +1076,13 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk,
 				      struct mptcp_addr_info *addr,
 				      bool force)
 {
+	u8 ids[MPTCP_RM_IDS_MAX] = { addr->id, 0, 0, 0, 0, 0, 0, 0 };
 	bool ret;
 
 	ret = remove_anno_list_by_saddr(msk, addr);
 	if (ret || force) {
 		spin_lock_bh(&msk->pm.lock);
-		mptcp_pm_remove_addr(msk, addr->id);
+		mptcp_pm_remove_addr(msk, ids);
 		spin_unlock_bh(&msk->pm.lock);
 	}
 	return ret;
net/mptcp/protocol.h +2 -2
index 3930a92beeb4..5adf85e3fd15 100644
@@ -205,7 +205,7 @@ struct mptcp_pm_data {
 	u8		local_addr_used;
 	u8		subflows;
 	u8		status;
-	u8		rm_id;
+	u8		rm_ids[MPTCP_RM_IDS_MAX];
 };
 
 struct mptcp_data_frag {
@@ -674,7 +674,7 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,
 int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 			   const struct mptcp_addr_info *addr,
 			   bool echo, bool port);
-int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id);
+int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_ids[]);
 int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id);
 
 void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
Signature · 4 lines
2.29.2
_______________________________________________
mptcp mailing list -- mptcp(a)lists.01.org
To unsubscribe send an email to mptcp-leave(a)lists.01.org

--
Mat Martineau
Intel

#9 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 2/7] mptcp: remove multi addrs on incoming path

In reply to Geliang Tang
Quoted 77 lines · Geliang Tang

This patch changed the member rm_id in struct mptcp_options_received as an array of the removing address ids, and renamed it to rm_ids.

In mptcp_parse_option, parsed the RM_ADDR suboption and filled them into the ids array in struct mptcp_options_received.

In mptcp_incoming_options, passed this ids array to the function mptcp_pm_rm_addr_received.

It alse changed the parameter type of mptcp_pm_rm_addr_received.

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

---

net/mptcp/options.c  | 15 +++++++++++----
net/mptcp/pm.c       |  9 +++++----
net/mptcp/protocol.h |  4 ++--
3 files changed, 18 insertions(+), 10 deletions(-)
net/mptcp/options.c +11 -4
index 3ce7917327d1..bd7a8b442088 100644
@@ -26,6 +26,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
 	int expected_opsize;
 	u8 version;
 	u8 flags;
+	u8 i, nr;
 
 	switch (subtype) {
 	case MPTCPOPT_MP_CAPABLE:
@@ -272,14 +273,20 @@ static void mptcp_parse_option(const struct sk_buff *skb,
 		break;
 
 	case MPTCPOPT_RM_ADDR:
-		if (opsize != TCPOLEN_MPTCP_RM_ADDR_BASE)
+		if (opsize < TCPOLEN_MPTCP_RM_ADDR_BASE + 1 ||
+		    opsize > TCPOLEN_MPTCP_RM_ADDR_BASE + MPTCP_RM_IDS_MAX)
 			break;
 
 		ptr++;
 
 		mp_opt->rm_addr = 1;
-		mp_opt->rm_id = *ptr++;
-		pr_debug("RM_ADDR: id=%d", mp_opt->rm_id);
+		memset(mp_opt->rm_ids, 0, MPTCP_RM_IDS_MAX);
+		nr = opsize - TCPOLEN_MPTCP_RM_ADDR_BASE;
+		for (i = 0; i < nr; i++)
+			mp_opt->rm_ids[i] = *ptr++;
+		pr_debug("RM_ADDR: ids_nr=%d", nr);
+		for (i = 0; i < nr; i++)
+			pr_debug(" -> id[%d]=%d", i, mp_opt->rm_ids[i]);
 		break;
 
 	case MPTCPOPT_MP_PRIO:
@@ -1040,7 +1047,7 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
 	}
 
 	if (mp_opt.rm_addr) {
-		mptcp_pm_rm_addr_received(msk, mp_opt.rm_id);
+		mptcp_pm_rm_addr_received(msk, mp_opt.rm_ids);
 		mp_opt.rm_addr = 0;
 	}
 
net/mptcp/pm.c +2 -1
index 764cd62c59ba..5ff59a84de2b 100644
@@ -205,17 +205,18 @@ void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk)
 	mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_SEND_ACK);
 }
 
-void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id)
+void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_ids[])
 {
 	struct mptcp_pm_data *pm = &msk->pm;
+	u8 i;
 

net/mptcp/pm.c void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk) · line 218

Quoted 10 lines
net/mptcp/pm.c +3 -3
-	pr_debug("msk=%p remote_id=%d", msk, rm_id);
+	pr_debug("msk=%p remote_ids_nr=%d", msk, mptcp_get_rm_ids_nr(rm_ids));
 
-	mptcp_event_addr_removed(msk, rm_id);
+	for (i = 0; i < MPTCP_RM_IDS_MAX && rm_ids[i]; i++)
+		mptcp_event_addr_removed(msk, rm_ids[i]);
 
 	spin_lock_bh(&pm->lock);
 	mptcp_pm_schedule_work(msk, MPTCP_PM_RM_ADDR_RECEIVED);
-	pm->rm_id = rm_id;

For this patch, I think 'pm->rm_id = rm_ids[0]' would be better to keep existing behavior for the first address ID.

Mat

Quoted 27 lines
net/mptcp/pm.c +0 -0
 	spin_unlock_bh(&pm->lock);
 }
 
net/mptcp/protocol.h +2 -2
index 411af3334a25..3930a92beeb4 100644
@@ -140,7 +140,7 @@ struct mptcp_options_received {
 		mpc_map:1,
 		__unused:2;
 	u8	addr_id;
-	u8	rm_id;
+	u8	rm_ids[MPTCP_RM_IDS_MAX];
 	union {
 		struct in_addr	addr;
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
@@ -660,7 +660,7 @@ void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id);
 void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
 				const struct mptcp_addr_info *addr);
 void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk);
-void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id);
+void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_ids[]);
 void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup);
 int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk,
 				 struct mptcp_addr_info *addr,
Signature · 1 line
2.29.2

--
Mat Martineau
Intel

#10 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 1/7] mptcp: remove multi addrs on outgoing path

In reply to Geliang Tang
Quoted 85 lines · Geliang Tang

This patch changed the member rm_id of struct mptcp_out_options as an array of the removing address ids, and renamed it to rm_ids. The array size was definced as a new macro MPTCP_RM_IDS_MAX.

Added a new function named mptcp_get_rm_ids_nr to get the number of address ids in the ids array.

In mptcp_established_options_rm_addr, invoked mptcp_pm_rm_addr_signal to get the ids array. According the number of addresses in it, calculated the padded RM_ADDR suboption length. And saved the ids array in struct mptcp_out_options's rm_ids member.

In mptcp_write_options, iterated each address id from struct mptcp_out_options's rm_ids member, set the zero ones as TCPOPT_NOP, then filled them into the RM_ADDR suboption.

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

---

include/net/mptcp.h  |  4 +++-
net/mptcp/options.c  | 40 ++++++++++++++++++++++++++++++++--------
net/mptcp/pm.c       |  3 +--
net/mptcp/protocol.h | 14 ++++++++++++--
4 files changed, 48 insertions(+), 13 deletions(-)
include/net/mptcp.h +3 -1
index 5694370be3d4..1d33fea674d2 100644
@@ -34,6 +34,8 @@ struct mptcp_ext {
 	/* one byte hole */
 };
 
+#define MPTCP_RM_IDS_MAX	8
+
 struct mptcp_out_options {
 #if IS_ENABLED(CONFIG_MPTCP)
 	u16 suboptions;
@@ -48,7 +50,7 @@ struct mptcp_out_options {
 	u8 addr_id;
 	u16 port;
 	u64 ahmac;
-	u8 rm_id;
+	u8 rm_ids[MPTCP_RM_IDS_MAX];
 	u8 join_id;
 	u8 backup;
 	u32 nonce;
net/mptcp/options.c +13 -6
index bb874c5d663a..3ce7917327d1 100644
@@ -671,20 +671,27 @@ static bool mptcp_established_options_rm_addr(struct sock *sk,
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
-	u8 rm_id;
+	u8 rm_ids[MPTCP_RM_IDS_MAX], i, nr, align;
 
 	if (!mptcp_pm_should_rm_signal(msk) ||
-	    !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_id)))
+	    !(mptcp_pm_rm_addr_signal(msk, remaining, rm_ids)))
 		return false;
 
-	if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE)
+	nr = mptcp_get_rm_ids_nr(rm_ids);
+	if (nr > 1)
+		align = 5;
+	if (nr > 5)
+		align = 9;
+
+	if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE + align)
 		return false;
 
-	*size = TCPOLEN_MPTCP_RM_ADDR_BASE;
+	*size = TCPOLEN_MPTCP_RM_ADDR_BASE + align;
 	opts->suboptions |= OPTION_MPTCP_RM_ADDR;
-	opts->rm_id = rm_id;
+	memcpy(opts->rm_ids, rm_ids, MPTCP_RM_IDS_MAX);
 
-	pr_debug("rm_id=%d", opts->rm_id);
+	for (i = 0; i < nr; i++)
+		pr_debug("rm_ids[%d]=%d", i, opts->rm_ids[i]);
 
 	return true;
 }

net/mptcp/options.c void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, · line 1228

Quoted 10 lines
net/mptcp/options.c +7 -0
@@ -1212,9 +1219,26 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
 	}
 
 	if (OPTION_MPTCP_RM_ADDR & opts->suboptions) {
+		u8 i, nr;
+
+		nr = mptcp_get_rm_ids_nr(opts->rm_ids);
+		for (i = 0; i < MPTCP_RM_IDS_MAX; i++) {
+			if (!opts->rm_ids[i])
+				opts->rm_ids[i] = TCPOPT_NOP;
+		}

Could also use this for loop to add up 'nr' rather than looping twice (the loop here and the one inside mptcp_get_rm_ids_nr()).

Quoted 53 lines
net/mptcp/options.c +12 -2
 		*ptr++ = mptcp_option(MPTCPOPT_RM_ADDR,
-				      TCPOLEN_MPTCP_RM_ADDR_BASE,
-				      0, opts->rm_id);
+				      TCPOLEN_MPTCP_RM_ADDR_BASE + nr,
+				      0, opts->rm_ids[0]);
+		if (nr > 1) {
+			put_unaligned_be32(opts->rm_ids[1] << 24 | opts->rm_ids[2] << 16 |
+					   opts->rm_ids[3] << 8 | opts->rm_ids[4], ptr);
+			ptr += 1;
+		}
+		if (nr > 5) {
+			put_unaligned_be32(opts->rm_ids[5] << 24 | opts->rm_ids[6] << 16 |
+					   opts->rm_ids[7] << 8 | TCPOPT_NOP, ptr);
+			ptr += 1;
+		}
 	}
 
 	if (OPTION_MPTCP_PRIO & opts->suboptions) {
net/mptcp/pm.c +1 -2
index 6fd4b2c1b076..764cd62c59ba 100644
@@ -258,7 +258,7 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 }
 
 bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			     u8 *rm_id)
+			     u8 rm_ids[])
 {
 	int ret = false;
 
@@ -271,7 +271,6 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 	if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE)
 		goto out_unlock;
 
-	*rm_id = msk->pm.rm_id;
 	WRITE_ONCE(msk->pm.addr_signal, 0);
 	ret = true;
 
net/mptcp/protocol.h +1 -1
index d31edbae8da8..411af3334a25 100644
@@ -60,7 +60,7 @@
 #define TCPOLEN_MPTCP_ADD_ADDR6_BASE	20
 #define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT	24
 #define TCPOLEN_MPTCP_PORT_LEN		4
-#define TCPOLEN_MPTCP_RM_ADDR_BASE	4
+#define TCPOLEN_MPTCP_RM_ADDR_BASE	3
 #define TCPOLEN_MPTCP_PRIO		3
 #define TCPOLEN_MPTCP_PRIO_ALIGN	4
 #define TCPOLEN_MPTCP_FASTCLOSE		12

net/mptcp/protocol.h struct mptcp_sock { · line 297

Quoted 9 lines
net/mptcp/protocol.h +6 -0
@@ -289,6 +289,16 @@ struct mptcp_sock {
 #define mptcp_for_each_subflow(__msk, __subflow)			\
 	list_for_each_entry(__subflow, &((__msk)->conn_list), node)
 
+static inline u8 mptcp_get_rm_ids_nr(u8 rm_ids[])
+{
+	int i, nr = 0;
+
+	for (i = 0; i < MPTCP_RM_IDS_MAX && rm_ids[i]; i++)
+		nr++;

'nr' isn't needed, can return i instead.

Quoted 18 lines
net/mptcp/protocol.h +5 -1
+
+	return nr;
+}
+
 static inline void msk_owned_by_me(const struct mptcp_sock *msk)
 {
 	sock_owned_by_me((const struct sock *)msk);
@@ -714,7 +724,7 @@ static inline unsigned int mptcp_add_addr_len(int family, bool echo, bool port)
 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_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-			     u8 *rm_id);
+			     u8 rm_ids[]);
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
 
 void __init mptcp_pm_nl_init(void);
Signature · 1 line
2.29.2

--
Mat Martineau
Intel

#11 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 1/7] mptcp: remove multi addrs on outgoing path

Quoted 140 lines · Mat Martineau
Quoted 87 lines · Geliang Tang

This patch changed the member rm_id of struct mptcp_out_options as an array of the removing address ids, and renamed it to rm_ids. The array size was definced as a new macro MPTCP_RM_IDS_MAX.

Added a new function named mptcp_get_rm_ids_nr to get the number of address ids in the ids array.

In mptcp_established_options_rm_addr, invoked mptcp_pm_rm_addr_signal to get the ids array. According the number of addresses in it, calculated the padded RM_ADDR suboption length. And saved the ids array in struct mptcp_out_options's rm_ids member.

In mptcp_write_options, iterated each address id from struct mptcp_out_options's rm_ids member, set the zero ones as TCPOPT_NOP, then filled them into the RM_ADDR suboption.

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

---

include/net/mptcp.h  |  4 +++-
net/mptcp/options.c  | 40 ++++++++++++++++++++++++++++++++--------
net/mptcp/pm.c       |  3 +--
net/mptcp/protocol.h | 14 ++++++++++++--
4 files changed, 48 insertions(+), 13 deletions(-)
include/net/mptcp.h +3 -1
index 5694370be3d4..1d33fea674d2 100644
@@ -34,6 +34,8 @@ struct mptcp_ext {
 	/* one byte hole */
 };
 
+#define MPTCP_RM_IDS_MAX	8
+
 struct mptcp_out_options {
 #if IS_ENABLED(CONFIG_MPTCP)
 	u16 suboptions;
@@ -48,7 +50,7 @@ struct mptcp_out_options {
 	u8 addr_id;
 	u16 port;
 	u64 ahmac;
-	u8 rm_id;
+	u8 rm_ids[MPTCP_RM_IDS_MAX];
 	u8 join_id;
 	u8 backup;
 	u32 nonce;
net/mptcp/options.c +13 -6
index bb874c5d663a..3ce7917327d1 100644
@@ -671,20 +671,27 @@ static bool mptcp_established_options_rm_addr(struct 
 sock *sk,
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
-	u8 rm_id;
+	u8 rm_ids[MPTCP_RM_IDS_MAX], i, nr, align;
 
 	if (!mptcp_pm_should_rm_signal(msk) ||
-	    !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_id)))
+	    !(mptcp_pm_rm_addr_signal(msk, remaining, rm_ids)))
 		return false;
 
-	if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE)
+	nr = mptcp_get_rm_ids_nr(rm_ids);
+	if (nr > 1)
+		align = 5;
+	if (nr > 5)
+		align = 9;
+
+	if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE + align)
 		return false;
 
-	*size = TCPOLEN_MPTCP_RM_ADDR_BASE;
+	*size = TCPOLEN_MPTCP_RM_ADDR_BASE + align;
 	opts->suboptions |= OPTION_MPTCP_RM_ADDR;
-	opts->rm_id = rm_id;
+	memcpy(opts->rm_ids, rm_ids, MPTCP_RM_IDS_MAX);
 
-	pr_debug("rm_id=%d", opts->rm_id);
+	for (i = 0; i < nr; i++)
+		pr_debug("rm_ids[%d]=%d", i, opts->rm_ids[i]);
 
 	return true;

}

net/mptcp/options.c +0 -0
@@ -1212,9 +1219,26 @@ void mptcp_write_options(__be32 *ptr, const struct 
 tcp_sock *tp,

net/mptcp/options.c void mptcp_write_options(__be32 *ptr, const struct · line 1229

Quoted 10 lines
net/mptcp/options.c +7 -0
 	}
 
 	if (OPTION_MPTCP_RM_ADDR & opts->suboptions) {
+		u8 i, nr;
+
+		nr = mptcp_get_rm_ids_nr(opts->rm_ids);
+		for (i = 0; i < MPTCP_RM_IDS_MAX; i++) {
+			if (!opts->rm_ids[i])
+				opts->rm_ids[i] = TCPOPT_NOP;
+		}

Could also use this for loop to add up 'nr' rather than looping twice (the loop here and the one inside mptcp_get_rm_ids_nr()).

Quoted 37 lines
net/mptcp/options.c +4 -2
 		*ptr++ = mptcp_option(MPTCPOPT_RM_ADDR,
-				      TCPOLEN_MPTCP_RM_ADDR_BASE,
-				      0, opts->rm_id);
+				      TCPOLEN_MPTCP_RM_ADDR_BASE + nr,
+				      0, opts->rm_ids[0]);
+		if (nr > 1) {
+			put_unaligned_be32(opts->rm_ids[1] << 24 | 

opts->rm_ids[2] << 16 |

net/mptcp/options.c +1 -0
+					   opts->rm_ids[3] << 8 | 

opts->rm_ids[4], ptr);

net/mptcp/options.c +4 -0
+			ptr += 1;
+		}
+		if (nr > 5) {
+			put_unaligned_be32(opts->rm_ids[5] << 24 | 

opts->rm_ids[6] << 16 |

net/mptcp/options.c +1 -0
+					   opts->rm_ids[7] << 8 | TCPOPT_NOP, 

ptr);

net/mptcp/options.c +2 -0
+			ptr += 1;
+		}
	}

	if (OPTION_MPTCP_PRIO & opts->suboptions) {
net/mptcp/pm.c +0 -0
index 6fd4b2c1b076..764cd62c59ba 100644
@@ -258,7 +258,7 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, 
 unsigned int remaining,
 }
 

bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,

net/mptcp/pm.c +1 -1
-			     u8 *rm_id)
+			     u8 rm_ids[])
{
	int ret = false;
Quoted 6 lines

net/mptcp/pm.c bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, · line 275

Quoted 6 lines
net/mptcp/pm.c +0 -1
@@ -271,7 +271,6 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, 
 unsigned int remaining,
 	if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE)
 		goto out_unlock;
 
-	*rm_id = msk->pm.rm_id;

One more thing - I think it would be better to set rm_ids[0] here (and clear the rest of the array) rather than leaving rm_ids unchanged. I realize it's changed later in the series but it's better to have working code here in case someone is trying to bisect.

Mat

Quoted 48 lines
Quoted 17 lines
net/mptcp/pm.c +0 -0
 	WRITE_ONCE(msk->pm.addr_signal, 0);
 	ret = true;
net/mptcp/protocol.h +1 -1
index d31edbae8da8..411af3334a25 100644
@@ -60,7 +60,7 @@
 #define TCPOLEN_MPTCP_ADD_ADDR6_BASE	20
 #define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT	24
 #define TCPOLEN_MPTCP_PORT_LEN		4
-#define TCPOLEN_MPTCP_RM_ADDR_BASE	4
+#define TCPOLEN_MPTCP_RM_ADDR_BASE	3
 #define TCPOLEN_MPTCP_PRIO		3
 #define TCPOLEN_MPTCP_PRIO_ALIGN	4
 #define TCPOLEN_MPTCP_FASTCLOSE		12

net/mptcp/protocol.h struct mptcp_sock { · line 297

Quoted 9 lines
net/mptcp/protocol.h +6 -0
@@ -289,6 +289,16 @@ struct mptcp_sock {
 #define mptcp_for_each_subflow(__msk, __subflow)			\
 	list_for_each_entry(__subflow, &((__msk)->conn_list), node)
 
+static inline u8 mptcp_get_rm_ids_nr(u8 rm_ids[])
+{
+	int i, nr = 0;
+
+	for (i = 0; i < MPTCP_RM_IDS_MAX && rm_ids[i]; i++)
+		nr++;

'nr' isn't needed, can return i instead.

Quoted 19 lines
net/mptcp/protocol.h +4 -0
+
+	return nr;
+}
+
 static inline void msk_owned_by_me(const struct mptcp_sock *msk)
 {
 	sock_owned_by_me((const struct sock *)msk);
@@ -714,7 +724,7 @@ static inline unsigned int mptcp_add_addr_len(int 
 family, bool echo, bool port)

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_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,

net/mptcp/protocol.h +1 -1
-			     u8 *rm_id);
+			     u8 rm_ids[]);

int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);

Quoted 11 lines
Quoted 3 lines

void __init mptcp_pm_nl_init(void);

Signature · 1 line
2.29.2

--
Mat Martineau
Intel
_______________________________________________
mptcp mailing list -- mptcp(a)lists.01.org
To unsubscribe send an email to mptcp-leave(a)lists.01.org

--
Mat Martineau
Intel