]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
mptcp: remove id 0 address
authorGeliang Tang <geliangtang@gmail.com>
Wed, 31 Mar 2021 00:08:53 +0000 (17:08 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 31 Mar 2021 00:42:23 +0000 (17:42 -0700)
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 <pabeni@redhat.com>
Suggested-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/mptcp/pm_netlink.c

index e00397f2abf1a0db14c1224577e031de48252eb3..cadafafa1049faada7378ce53a7db355a975c6d1 100644 (file)
@@ -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) {