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 Jan 6, 2025
1 parent 642f51c commit 792fc35
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
11 changes: 7 additions & 4 deletions net/mptcp/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,8 @@ static int mptcp_pm_set_flags(struct mptcp_pm_addr_entry *local,
int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
{
struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, };
struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
struct mptcp_addr_info rem = { .family = AF_UNSPEC, };
struct nlattr *attr_loc;
struct nlattr *attr_loc, *attr_rem;
int ret;

if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR))
Expand All @@ -576,14 +575,18 @@ int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
return ret;

if (loc.addr.family == AF_UNSPEC) {
if (!loc.addr.id) {
if (!info->attrs[MPTCP_PM_ATTR_TOKEN] && !loc.addr.id) {
NL_SET_ERR_MSG_ATTR(info->extack, attr_loc,
"missing address ID");
return -EOPNOTSUPP;
}
}

if (attr_rem) {
if (info->attrs[MPTCP_PM_ATTR_TOKEN]) {
if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE))
return -EINVAL;

attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
ret = mptcp_pm_parse_addr(attr_rem, info, &rem);
if (ret < 0)
return ret;
Expand Down
23 changes: 12 additions & 11 deletions net/mptcp/pm_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
msk->pm.ops->subflow_destroy(msk, &addr_l, &addr_r) :
userspace_pm_subflow_destroy(msk, &addr_l, &addr_r);
release_sock(sk);

if (err)
GENL_SET_ERR_MSG(info, "subflow not found");

Expand All @@ -618,18 +619,16 @@ static int userspace_pm_set_flags(struct mptcp_sock *msk,
spin_lock_bh(&msk->pm.lock);
entry = lookup_by_id ? mptcp_userspace_pm_lookup_addr_by_id(msk, local->addr.id) :
mptcp_userspace_pm_lookup_addr(msk, &local->addr);
if (!entry) {
spin_unlock_bh(&msk->pm.lock);
return -EINVAL;
if (entry) {
if (bkup)
entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
else
entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP;
}

if (bkup)
entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
else
entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP;
spin_unlock_bh(&msk->pm.lock);

return mptcp_pm_nl_mp_prio_send_ack(msk, &entry->addr, remote, bkup);
return mptcp_pm_nl_mp_prio_send_ack(msk, entry ? &entry->addr : &local->addr,
remote, bkup);
}

int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,
Expand All @@ -651,8 +650,10 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,
msk->pm.ops->set_flags(msk, local, remote) :
userspace_pm_set_flags(msk, local, remote);
release_sock(sk);
if (ret)
GENL_SET_ERR_MSG(info, "mp_prio send ack failed");

/* mptcp_pm_nl_mp_prio_send_ack() only fails in one case */
if (ret < 0)
GENL_SET_ERR_MSG(info, "subflow not found");

sock_put(sk);
return ret;
Expand Down
16 changes: 7 additions & 9 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_userspace_pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,16 @@ int BPF_PROG(mptcp_pm_set_flags, struct mptcp_sock *msk,
bpf_spin_lock_bh(&msk->pm.lock);
entry = lookup_by_id ? mptcp_userspace_pm_lookup_addr_by_id(msk, local->addr.id) :
mptcp_userspace_pm_lookup_addr(msk, &local->addr);
if (!entry) {
bpf_spin_unlock_bh(&msk->pm.lock);
return -EINVAL;
if (entry) {
if (bkup)
entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
else
entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP;
}

if (bkup)
entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
else
entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP;
bpf_spin_unlock_bh(&msk->pm.lock);

return mptcp_pm_nl_mp_prio_send_ack(msk, &entry->addr, remote, bkup);
return mptcp_pm_nl_mp_prio_send_ack(msk, entry ? &entry->addr : &local->addr,
remote, bkup);
}

SEC(".struct_ops.link")
Expand Down

0 comments on commit 792fc35

Please sign in to comment.