Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang committed Oct 25, 2024
1 parent 2e9e078 commit 74c551e
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions net/mptcp/pm_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,17 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in
static int userspace_pm_address_announce(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local)
{
int err;
int err = -EINVAL;

if (local->addr.id == 0 || !(local->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
pr_debug("invalid addr id or flags\n");
return -EINVAL;
goto announce_err;
}

err = mptcp_userspace_pm_append_new_local_addr(msk, local, false);
if (err < 0) {
pr_debug("did not match address and id\n");
return err;
goto announce_err;
}

spin_lock_bh(&msk->pm.lock);
Expand All @@ -237,7 +237,9 @@ static int userspace_pm_address_announce(struct mptcp_sock *msk,

spin_unlock_bh(&msk->pm.lock);

return 0;
err = 0;
announce_err:
return err;
}

int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
Expand Down Expand Up @@ -312,16 +314,19 @@ static int userspace_pm_address_remove(struct mptcp_sock *msk, u8 id)
{
struct sock *sk = (struct sock *)msk;
struct mptcp_pm_addr_entry *match;
int err = -EINVAL;

if (id == 0)
return mptcp_userspace_pm_remove_id_zero_address(msk);
if (id == 0) {
err = mptcp_userspace_pm_remove_id_zero_address(msk);
goto out;
}

spin_lock_bh(&msk->pm.lock);
match = mptcp_userspace_pm_lookup_addr_by_id(msk, id);
spin_unlock_bh(&msk->pm.lock);
if (!match) {
pr_debug("address with specified id not found\n");
return -EINVAL;
goto out;
}

mptcp_pm_remove_addr_entry(msk, match);
Expand All @@ -331,7 +336,9 @@ static int userspace_pm_address_remove(struct mptcp_sock *msk, u8 id)
sock_kfree_s(sk, match, sizeof(*match));
spin_unlock_bh(&msk->pm.lock);

return 0;
err = 0;
out:
return err;
}

int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
Expand Down Expand Up @@ -372,23 +379,23 @@ static int userspace_pm_subflow_create(struct mptcp_sock *msk,
struct mptcp_addr_info *remote)
{
struct sock *sk = (struct sock *)msk;
int err;
int err = -EINVAL;

if (local->flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
pr_debug("invalid addr flags\n");
return -EINVAL;
goto create_err;
}
local->flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW;

if (!mptcp_pm_addr_families_match(sk, &local->addr, remote)) {
pr_debug("families mismatch\n");
return -EINVAL;
goto create_err;
}

err = mptcp_userspace_pm_append_new_local_addr(msk, local, false);
if (err < 0) {
pr_debug("did not match address and id\n");
return err;
goto create_err;
}

err = __mptcp_subflow_connect(sk, local, remote);
Expand All @@ -399,6 +406,7 @@ static int userspace_pm_subflow_create(struct mptcp_sock *msk,
msk->pm.subflows++;
spin_unlock_bh(&msk->pm.lock);

create_err:
return err;
}

Expand Down Expand Up @@ -501,8 +509,8 @@ static int userspace_pm_subflow_destroy(struct mptcp_sock *msk,
struct mptcp_addr_info *remote)
{
struct sock *sk = (struct sock *)msk;
int err = -EINVAL;
struct sock *ssk;
int err = -ESRCH;

#if IS_ENABLED(CONFIG_MPTCP_IPV6)
if (local->addr.family == AF_INET && ipv6_addr_v4mapped(&remote->addr6)) {
Expand All @@ -516,27 +524,29 @@ static int userspace_pm_subflow_destroy(struct mptcp_sock *msk,
#endif
if (local->addr.family != remote->family) {
pr_debug("address families do not match\n");
return -EINVAL;
goto destroy_err;
}

if (!local->addr.port || !remote->port) {
pr_debug("missing local or remote port\n");
return -EINVAL;
goto destroy_err;
}

ssk = mptcp_nl_find_ssk(msk, &local->addr, remote);
if (ssk) {
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);

spin_lock_bh(&msk->pm.lock);
mptcp_userspace_pm_delete_local_addr(msk, local);
spin_unlock_bh(&msk->pm.lock);
mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN);
mptcp_close_ssk(sk, ssk, subflow);
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW);
err = 0;
if (!ssk) {
err = -ESRCH;
goto destroy_err;
}

spin_lock_bh(&msk->pm.lock);
mptcp_userspace_pm_delete_local_addr(msk, local);
spin_unlock_bh(&msk->pm.lock);
mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN);
mptcp_close_ssk(sk, ssk, mptcp_subflow_ctx(ssk));
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW);
err = 0;

destroy_err:
return err;
}

Expand Down Expand Up @@ -591,12 +601,13 @@ static int userspace_pm_set_flags(struct mptcp_sock *msk,
struct mptcp_addr_info *rem)
{
struct mptcp_pm_addr_entry *entry;
int ret = -EINVAL;
u8 bkup = 0;

if (loc->addr.family == AF_UNSPEC ||
rem->family == AF_UNSPEC) {
pr_debug("invalid address families\n");
return -EINVAL;
goto set_flags_err;
}

if (loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP)
Expand All @@ -612,7 +623,10 @@ static int userspace_pm_set_flags(struct mptcp_sock *msk,
}
spin_unlock_bh(&msk->pm.lock);

return mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, rem, bkup);
ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, rem, bkup);

set_flags_err:
return ret;
}

int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc,
Expand Down

0 comments on commit 74c551e

Please sign in to comment.