From: Geliang Tang <[email protected]>

This patch added a new function mptcp_nl_remove_id_zero_address to
remove the id 0 address.

In this function, traverse all the existing msk sockets to find the
msk matched the input IP address. Then fill the removing list with
id 0, and pass it to mptcp_pm_remove_addr and mptcp_pm_remove_subflow.

Suggested-by: Paolo Abeni <[email protected]>
Suggested-by: Matthieu Baerts <[email protected]>
Reviewed-by: Mat Martineau <[email protected]>
Signed-off-by: Geliang Tang <[email protected]>
---
 net/mptcp/pm_netlink.c | 43 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index e00397f2abf1..cadafafa1049 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1156,6 +1156,41 @@ static void mptcp_pm_free_addr_entry(struct 
mptcp_pm_addr_entry *entry)
        }
 }
 
+static int mptcp_nl_remove_id_zero_address(struct net *net,
+                                          struct mptcp_addr_info *addr)
+{
+       struct mptcp_rm_list list = { .nr = 0 };
+       long s_slot = 0, s_num = 0;
+       struct mptcp_sock *msk;
+
+       list.ids[list.nr++] = 0;
+
+       while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
+               struct sock *sk = (struct sock *)msk;
+               struct mptcp_addr_info msk_local;
+
+               if (list_empty(&msk->conn_list))
+                       goto next;
+
+               local_address((struct sock_common *)msk, &msk_local);
+               if (!addresses_equal(&msk_local, addr, addr->port))
+                       goto next;
+
+               lock_sock(sk);
+               spin_lock_bh(&msk->pm.lock);
+               mptcp_pm_remove_addr(msk, &list);
+               mptcp_pm_nl_rm_subflow_received(msk, &list);
+               spin_unlock_bh(&msk->pm.lock);
+               release_sock(sk);
+
+next:
+               sock_put(sk);
+               cond_resched();
+       }
+
+       return 0;
+}
+
 static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
 {
        struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
@@ -1168,6 +1203,14 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, 
struct genl_info *info)
        if (ret < 0)
                return ret;
 
+       /* the zero id address is special: the first address used by the msk
+        * always gets such an id, so different subflows can have different zero
+        * id addresses. Additionally zero id is not accounted for in id_bitmap.
+        * Let's use an 'mptcp_rm_list' instead of the common remove code.
+        */
+       if (addr.addr.id == 0)
+               return mptcp_nl_remove_id_zero_address(sock_net(skb->sk), 
&addr.addr);
+
        spin_lock_bh(&pernet->lock);
        entry = __lookup_addr_by_id(pernet, addr.addr.id);
        if (!entry) {
-- 
2.31.1

Reply via email to