From 792fc35c5369488f8503b7469605f6b06badefc4 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Mon, 6 Jan 2025 17:41:39 +0800 Subject: [PATCH] fix Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 11 +++++---- net/mptcp/pm_userspace.c | 23 ++++++++++--------- .../bpf/progs/mptcp_bpf_userspace_pm.c | 16 ++++++------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index cdc42f358670..9d83f4c973bc 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -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)) @@ -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; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 2358432cdfc3..dfe098712bc6 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -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"); @@ -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, @@ -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; diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_userspace_pm.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_userspace_pm.c index f64205d68e9a..15956d428fd1 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_userspace_pm.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_userspace_pm.c @@ -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")