Skip to content

Commit

Permalink
mptcp: fix subflow accounting on close
Browse files Browse the repository at this point in the history
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: a88c9e4 ("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>
  • Loading branch information
Paolo Abeni authored and kuba-moo committed May 14, 2022
1 parent 04c494e commit 95d6865
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
5 changes: 2 additions & 3 deletions net/mptcp/pm.c
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions net/mptcp/protocol.h
Expand Up @@ -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);

Expand Down
12 changes: 9 additions & 3 deletions net/mptcp/subflow.c
Expand Up @@ -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);
Expand Down Expand Up @@ -1492,6 +1492,12 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
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;
}

Expand Down

0 comments on commit 95d6865

Please sign in to comment.