Skip to contentSkip to conversation

remove address when netlink flush addrs and testcase

PATCH In review Geliang Tang 4 participants 8 messages Nov 30, 2020 – Dec 7, 2020

Subsystems (3)
lore
Share & tools
lore

Geliang Tang

author
#0 lore raw

v2 cover remove address when netlink flush addrs and testcase

v2:
- update the testcase.

This patchset removes address when netlink do flush addrs command, and adds the testcase for flush addrs command.

Geliang Tang (2):
mptcp: remove address when netlink flush addrs
selftests: mptcp: add the flush addrs testcase

 net/mptcp/pm_netlink.c                        | 15 ++++--
 .../testing/selftests/net/mptcp/mptcp_join.sh | 50 +++++++++++++------
 2 files changed, 46 insertions(+), 19 deletions(-)
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH v2 1/2 mptcp: remove address when netlink flush addrs

When the PM netlink flushs the addresses, invoke the remove address function mptcp_nl_remove_subflow_and_signal_addr to remove the addresses and the subflows. Since this function should not be invoked under lock, move __flush_addrs out of the pernet->lock.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm_netlink.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
net/mptcp/pm_netlink.c +10 -5
index ba31065ef462..4f1b7f44c03b 100644
@@ -962,13 +962,14 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
 	return ret;
 }
 
-static void __flush_addrs(struct pm_nl_pernet *pernet)
+static void __flush_addrs(struct net *net, struct list_head *list)
 {
-	while (!list_empty(&pernet->local_addr_list)) {
+	while (!list_empty(list)) {
 		struct mptcp_pm_addr_entry *cur;
 
-		cur = list_entry(pernet->local_addr_list.next,
+		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);
 		kfree_rcu(cur, rcu);
 	}
@@ -985,11 +986,13 @@ 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);
 
 	spin_lock_bh(&pernet->lock);
-	__flush_addrs(pernet);
+	list_splice_init(&pernet->local_addr_list, &free_list);
 	__reset_counters(pernet);
 	spin_unlock_bh(&pernet->lock);
+	__flush_addrs(sock_net(skb->sk), &free_list);
 	return 0;
 }
 
@@ -1253,10 +1256,12 @@ static void __net_exit pm_nl_exit_net(struct list_head *net_list)
 	struct net *net;
 
 	list_for_each_entry(net, net_list, exit_list) {
+		struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
+
 		/* net is removed from namespace list, can't race with
 		 * other modifiers
 		 */
-		__flush_addrs(net_generic(net, pm_nl_pernet_id));
+		__flush_addrs(net, &pernet->local_addr_list);
 	}
 }
 
Signature · 1 line
2.26.2
author
#2 lore raw

PATCH v2 2/2 selftests: mptcp: add the flush addrs testcase

This patch added the flush addrs testcase. In do_transfer, if the number of removing addresses is less than 8, use the del addr command to remove the addresses one by one. If the number is more than 8, use the flush addrs command to remove the addresses.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 50 +++++++++++++------
 1 file changed, 36 insertions(+), 14 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +36 -14
index 38d756f5e366..00a3ed10bb85 100755
@@ -264,27 +264,37 @@ do_transfer()
 	cpid=$!
 
 	if [ $rm_nr_ns1 -gt 0 ]; then
-		counter=1
-		sleep 1
+		if [ $rm_nr_ns1 -lt 8 ]; then
+			counter=1
+			sleep 1
 
-		while [ $counter -le $rm_nr_ns1 ]
-		do
-			ip netns exec ${listener_ns} ./pm_nl_ctl del $counter
+			while [ $counter -le $rm_nr_ns1 ]
+			do
+				ip netns exec ${listener_ns} ./pm_nl_ctl del $counter
+				sleep 1
+				let counter+=1
+			done
+		else
 			sleep 1
-			let counter+=1
-		done
+			ip netns exec ${listener_ns} ./pm_nl_ctl flush
+		fi
 	fi
 
 	if [ $rm_nr_ns2 -gt 0 ]; then
-		counter=1
-		sleep 1
+		if [ $rm_nr_ns2 -lt 8 ]; then
+			counter=1
+			sleep 1
 
-		while [ $counter -le $rm_nr_ns2 ]
-		do
-			ip netns exec ${connector_ns} ./pm_nl_ctl del $counter
+			while [ $counter -le $rm_nr_ns2 ]
+			do
+				ip netns exec ${connector_ns} ./pm_nl_ctl del $counter
+				sleep 1
+				let counter+=1
+			done
+		else
 			sleep 1
-			let counter+=1
-		done
+			ip netns exec ${connector_ns} ./pm_nl_ctl flush
+		fi
 	fi
 
 	wait $cpid
@@ -749,6 +759,18 @@ chk_join_nr "remove subflows and signal" 3 3 3
 chk_add_nr 1 1
 chk_rm_nr 2 2
 
+# subflows and signal, flush
+reset
+ip netns exec $ns1 ./pm_nl_ctl limits 0 3
+ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal
+ip netns exec $ns2 ./pm_nl_ctl limits 1 3
+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 and signal" 3 3 3
+chk_add_nr 1 1
+chk_rm_nr 2 2
+
 # subflow IPv6
 reset
 ip netns exec $ns1 ./pm_nl_ctl limits 0 1
Signature · 1 line
2.26.2
#3 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 1/2] mptcp: remove address when netlink flush addrs

In reply to Geliang Tang
Quoted 19 lines · Geliang Tang

When the PM netlink flushs the addresses, invoke the remove address function mptcp_nl_remove_subflow_and_signal_addr to remove the addresses and the subflows. Since this function should not be invoked under lock, move __flush_addrs out of the pernet->lock.

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

---
net/mptcp/pm_netlink.c | 15 ++++++++++-----

1 file changed, 10 insertions(+), 5 deletions(-)
net/mptcp/pm_netlink.c +0 -1
index ba31065ef462..4f1b7f44c03b 100644
@@ -962,13 +962,14 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
 	return ret;
 }
 
-static void __flush_addrs(struct pm_nl_pernet *pernet)

net/mptcp/pm_netlink.c static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info) · line 972

Quoted 10 lines
net/mptcp/pm_netlink.c +4 -2
+static void __flush_addrs(struct net *net, struct list_head *list)
 {
-	while (!list_empty(&pernet->local_addr_list)) {
+	while (!list_empty(list)) {
 		struct mptcp_pm_addr_entry *cur;
 
-		cur = list_entry(pernet->local_addr_list.next,
+		cur = list_entry(list->next,
 				 struct mptcp_pm_addr_entry, list);
+		mptcp_nl_remove_subflow_and_signal_addr(net, &cur->addr);

I do think it makes sense to treat a 'flush' the same as a MPTCP_PM_CMD_DEL_ADDR on every entry in the list, so the patch is ok with me. I think I'll add an item to next week's meeting to talk about what happens when the last subflow is closed this way.

Mat

Quoted 34 lines
net/mptcp/pm_netlink.c +6 -2
 		list_del_rcu(&cur->list);
 		kfree_rcu(cur, rcu);
 	}
@@ -985,11 +986,13 @@ 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);
 
 	spin_lock_bh(&pernet->lock);
-	__flush_addrs(pernet);
+	list_splice_init(&pernet->local_addr_list, &free_list);
 	__reset_counters(pernet);
 	spin_unlock_bh(&pernet->lock);
+	__flush_addrs(sock_net(skb->sk), &free_list);
 	return 0;
 }
 
@@ -1253,10 +1256,12 @@ static void __net_exit pm_nl_exit_net(struct list_head *net_list)
 	struct net *net;
 
 	list_for_each_entry(net, net_list, exit_list) {
+		struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
+
 		/* net is removed from namespace list, can't race with
 		 * other modifiers
 		 */
-		__flush_addrs(net_generic(net, pm_nl_pernet_id));
+		__flush_addrs(net, &pernet->local_addr_list);
 	}
 }
 
Signature · 1 line
2.26.2

--
Mat Martineau
Intel

author
#4 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 1/2] mptcp: remove address when netlink flush addrs

Hi Mat,

Quoted 28 lines · Mat Martineau <mathew.j.martineau(a)linux.intel.com> 于2020年12月4日周五 上午10:16写道:
Quoted 25 lines · Geliang Tang

When the PM netlink flushs the addresses, invoke the remove address function mptcp_nl_remove_subflow_and_signal_addr to remove the addresses and the subflows. Since this function should not be invoked under lock, move __flush_addrs out of the pernet->lock.

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

---
net/mptcp/pm_netlink.c | 15 ++++++++++-----

1 file changed, 10 insertions(+), 5 deletions(-)
net/mptcp/pm_netlink.c +2 -2
index ba31065ef462..4f1b7f44c03b 100644
@@ -962,13 +962,14 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
      return ret;
 }
 
-static void __flush_addrs(struct pm_nl_pernet *pernet)
+static void __flush_addrs(struct net *net, struct list_head *list)
 {
-     while (!list_empty(&pernet->local_addr_list)) {
+     while (!list_empty(list)) {
              struct mptcp_pm_addr_entry *cur;
 
Quoted 9 lines

net/mptcp/pm_netlink.c static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info) · line 972

Quoted 4 lines
net/mptcp/pm_netlink.c +2 -1
-             cur = list_entry(pernet->local_addr_list.next,
+             cur = list_entry(list->next,
                               struct mptcp_pm_addr_entry, list);
+             mptcp_nl_remove_subflow_and_signal_addr(net, &cur->addr);

I do think it makes sense to treat a 'flush' the same as a MPTCP_PM_CMD_DEL_ADDR on every entry in the list, so the patch is ok with me. I think I'll add an item to next week's meeting to talk about what happens when the last subflow is closed this way.

Do you mean the subflow whose local_id and remote_id are all 0? This subflow will not be closed by mptcp_nl_remove_subflow_and_signal_addr. This fuction will ignore the zero id, so the zero id subflow will not be closed.

-Geliang

Quoted 41 lines

Mat

Quoted 33 lines
net/mptcp/pm_netlink.c +6 -3
              list_del_rcu(&cur->list);
              kfree_rcu(cur, rcu);
      }
@@ -985,11 +986,13 @@ 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);
 
      spin_lock_bh(&pernet->lock);
-     __flush_addrs(pernet);
+     list_splice_init(&pernet->local_addr_list, &free_list);
      __reset_counters(pernet);
      spin_unlock_bh(&pernet->lock);
+     __flush_addrs(sock_net(skb->sk), &free_list);
      return 0;
 }
 
@@ -1253,10 +1256,12 @@ static void __net_exit pm_nl_exit_net(struct list_head *net_list)
      struct net *net;
 
      list_for_each_entry(net, net_list, exit_list) {
+             struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
+
              /* net is removed from namespace list, can't race with
               * other modifiers
               */
-             __flush_addrs(net_generic(net, pm_nl_pernet_id));
+             __flush_addrs(net, &pernet->local_addr_list);
      }
 }
 
--
Quoted 1 line

2.26.2

--
Mat Martineau
Intel

#5 lore raw

[MPTCP] Re: [MPTCP][PATCH v2 mptcp-next 1/2] mptcp: remove address when netlink flush addrs

Quoted 41 lines · Geliang Tang

Hi Mat,

Quoted 28 lines · Mat Martineau <mathew.j.martineau(a)linux.intel.com> 于2020年12月4日周五 上午10:16写道:
Quoted 25 lines · Geliang Tang

When the PM netlink flushs the addresses, invoke the remove address function mptcp_nl_remove_subflow_and_signal_addr to remove the addresses and the subflows. Since this function should not be invoked under lock, move __flush_addrs out of the pernet->lock.

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

---
net/mptcp/pm_netlink.c | 15 ++++++++++-----

1 file changed, 10 insertions(+), 5 deletions(-)
net/mptcp/pm_netlink.c +2 -2
index ba31065ef462..4f1b7f44c03b 100644
@@ -962,13 +962,14 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
      return ret;
 }
 
-static void __flush_addrs(struct pm_nl_pernet *pernet)
+static void __flush_addrs(struct net *net, struct list_head *list)
 {
-     while (!list_empty(&pernet->local_addr_list)) {
+     while (!list_empty(list)) {
              struct mptcp_pm_addr_entry *cur;
 
Quoted 9 lines

net/mptcp/pm_netlink.c static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info) · line 972

Quoted 4 lines
net/mptcp/pm_netlink.c +2 -1
-             cur = list_entry(pernet->local_addr_list.next,
+             cur = list_entry(list->next,
                               struct mptcp_pm_addr_entry, list);
+             mptcp_nl_remove_subflow_and_signal_addr(net, &cur->addr);

I do think it makes sense to treat a 'flush' the same as a MPTCP_PM_CMD_DEL_ADDR on every entry in the list, so the patch is ok with me. I think I'll add an item to next week's meeting to talk about what happens when the last subflow is closed this way.

Quoted 4 lines

Do you mean the subflow whose local_id and remote_id are all 0? This subflow will not be closed by mptcp_nl_remove_subflow_and_signal_addr. This fuction will ignore the zero id, so the zero id subflow will not be closed.

I mean something slightly different. If the zero id subflow has already been closed for some other reason, flushing the other subflows would leave the connection with no subflows at all. This may be the right thing to do, but is also worth discussing!

Mat

Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
net/mptcp/pm_netlink.c +6 -2
              list_del_rcu(&cur->list);
              kfree_rcu(cur, rcu);
      }
@@ -985,11 +986,13 @@ 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);
 
      spin_lock_bh(&pernet->lock);
-     __flush_addrs(pernet);
+     list_splice_init(&pernet->local_addr_list, &free_list);
      __reset_counters(pernet);
      spin_unlock_bh(&pernet->lock);
+     __flush_addrs(sock_net(skb->sk), &free_list);
      return 0;
 }
 
@@ -1253,10 +1256,12 @@ static void __net_exit pm_nl_exit_net(struct list_head *net_list)
      struct net *net;
 
      list_for_each_entry(net, net_list, exit_list) {
+             struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
+
              /* net is removed from namespace list, can't race with
               * other modifiers
               */
-             __flush_addrs(net_generic(net, pm_nl_pernet_id));
+             __flush_addrs(net, &pernet->local_addr_list);
      }
 }
 
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

--
2.26.2

--
Mat Martineau
Intel

#6 lore raw
In reply to Geliang Tang
Quoted 6 lines · Geliang Tang

v2:
- update the testcase.

This patchset removes address when netlink do flush addrs command, and adds the testcase for flush addrs command.

Quoted 7 lines

Geliang Tang (2):
mptcp: remove address when netlink flush addrs
selftests: mptcp: add the flush addrs testcase

 net/mptcp/pm_netlink.c                        | 15 ++++--
 .../testing/selftests/net/mptcp/mptcp_join.sh | 50 +++++++++++++------
 2 files changed, 46 insertions(+), 19 deletions(-)

Both patches LGTM, thanks!

Paolo

#7 lore raw
In reply to Geliang Tang

Hi Geliang, Paolo, Mat,

Quoted 9 lines · Geliang Tang

v2:
- update the testcase.

This patchset removes address when netlink do flush addrs command, and adds the testcase for flush addrs command.

Geliang Tang (2):
mptcp: remove address when netlink flush addrs
selftests: mptcp: add the flush addrs testcase

Thank you for the patches and the reviews!

For both, I added Paolo's Acked-by and Mat's Reviewed-by tags. I hope I properly understood the answers!

These two patches have been applied after other patches from Geliang.

- 104e1f51ec45: mptcp: remove address when netlink flushes addrs
- 56330abd80b3: selftests: mptcp: add the flush addrs testcase
- Results: 8e81e32d0db6..f8649f5ba21e

Tests + export will be started soon!

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net