]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mptcp: fix subflow accounting on close
authorPaolo Abeni <pabeni@redhat.com>
Thu, 12 May 2022 23:26:41 +0000 (16:26 -0700)
committerJakub Kicinski <kuba@kernel.org>
Sat, 14 May 2022 00:04:30 +0000 (17:04 -0700)
If the PM closes a fully established MPJ subflow or the subflow
creation errors out in it's early stage the subflows counter is
not bumped accordingly.

This change adds the missing accounting, additionally taking care
of updating accordingly the 'accept_subflow' flag.

Fixes: 50839b6d97c8 ("mptcp: do not block subflows creation on errors")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/mptcp/pm.c
net/mptcp/protocol.h
net/mptcp/subflow.c

index 01809eef29b4bb50f25bb33238a331e942c4e646..aa51b100e03353d0dc2b8f170662bfbe9ad51370 100644 (file)
@@ -178,14 +178,13 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, const struct sock *ssk,
        struct mptcp_pm_data *pm = &msk->pm;
        bool update_subflows;
 
-       update_subflows = (ssk->sk_state == TCP_CLOSE) &&
-                         (subflow->request_join || subflow->mp_join);
+       update_subflows = subflow->request_join || subflow->mp_join;
        if (!READ_ONCE(pm->work_pending) && !update_subflows)
                return;
 
        spin_lock_bh(&pm->lock);
        if (update_subflows)
-               pm->subflows--;
+               __mptcp_pm_close_subflow(msk);
 
        /* Even if this subflow is not really established, tell the PM to try
         * to pick the next ones, if possible.
index 3c1a3036550f8410ba31d4d2c960d27c29c90186..f4ce28bb0fdcceaa38e01525775435be4d27de1b 100644 (file)
@@ -833,6 +833,20 @@ unsigned int mptcp_pm_get_add_addr_accept_max(const struct mptcp_sock *msk);
 unsigned int mptcp_pm_get_subflows_max(const struct mptcp_sock *msk);
 unsigned int mptcp_pm_get_local_addr_max(const struct mptcp_sock *msk);
 
+/* called under PM lock */
+static inline void __mptcp_pm_close_subflow(struct mptcp_sock *msk)
+{
+       if (--msk->pm.subflows < mptcp_pm_get_subflows_max(msk))
+               WRITE_ONCE(msk->pm.accept_subflow, true);
+}
+
+static inline void mptcp_pm_close_subflow(struct mptcp_sock *msk)
+{
+       spin_lock_bh(&msk->pm.lock);
+       __mptcp_pm_close_subflow(msk);
+       spin_unlock_bh(&msk->pm.lock);
+}
+
 void mptcp_sockopt_sync(struct mptcp_sock *msk, struct sock *ssk);
 void mptcp_sockopt_sync_locked(struct mptcp_sock *msk, struct sock *ssk);
 
index aba260f547daa1a10f2f5d32294b54b0a1f2e10b..8c37087f0d8460600c21e9c249ffb8f74bf17a14 100644 (file)
@@ -1422,20 +1422,20 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
        struct sockaddr_storage addr;
        int remote_id = remote->id;
        int local_id = loc->id;
+       int err = -ENOTCONN;
        struct socket *sf;
        struct sock *ssk;
        u32 remote_token;
        int addrlen;
        int ifindex;
        u8 flags;
-       int err;
 
        if (!mptcp_is_fully_established(sk))
-               return -ENOTCONN;
+               goto err_out;
 
        err = mptcp_subflow_create_socket(sk, &sf);
        if (err)
-               return err;
+               goto err_out;
 
        ssk = sf->sk;
        subflow = mptcp_subflow_ctx(ssk);
@@ -1492,6 +1492,12 @@ failed_unlink:
 failed:
        subflow->disposable = 1;
        sock_release(sf);
+
+err_out:
+       /* we account subflows before the creation, and this failures will not
+        * be caught by sk_state_change()
+        */
+       mptcp_pm_close_subflow(msk);
        return err;
 }