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 2, 2025
1 parent 1b78683 commit 269e9ed
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 194 deletions.
10 changes: 0 additions & 10 deletions net/mptcp/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,6 @@ __bpf_kfunc static bool bpf_ipv6_addr_v4mapped(const struct mptcp_addr_info *a)
return false;
}

__bpf_kfunc static void bpf_ipv6_addr_set_v4mapped(const __be32 addr,
struct mptcp_addr_info *v4mapped)
{
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
ipv6_addr_set_v4mapped(addr, &v4mapped->addr6);
#endif
}

__bpf_kfunc static void bpf_list_add_tail_rcu(struct list_head *new,
struct list_head *head)
{
Expand Down Expand Up @@ -755,7 +747,6 @@ BTF_ID_FLAGS(func, bpf_mptcp_sock_release, KF_RELEASE)
BTF_ID_FLAGS(func, bpf_spin_lock_bh)
BTF_ID_FLAGS(func, bpf_spin_unlock_bh)
BTF_ID_FLAGS(func, bpf_ipv6_addr_v4mapped)
BTF_ID_FLAGS(func, bpf_ipv6_addr_set_v4mapped)
BTF_ID_FLAGS(func, bpf_list_add_tail_rcu)
BTF_ID_FLAGS(func, bpf_list_del_rcu)
BTF_ID_FLAGS(func, bpf_pm_copy_entry)
Expand All @@ -769,7 +760,6 @@ BTF_ID_FLAGS(func, bpf_bitmap_zero)
BTF_ID_FLAGS(func, bpf_test_bit)
BTF_ID_FLAGS(func, bpf_set_bit)
BTF_ID_FLAGS(func, bpf_find_next_zero_bit)
BTF_ID_FLAGS(func, mptcp_pm_addr_families_match)
BTF_ID_FLAGS(func, mptcp_pm_remove_addr)
BTF_ID_FLAGS(func, mptcp_pm_remove_addr_entry, KF_SLEEPABLE)
BTF_ID_FLAGS(func, bpf_mptcp_subflow_connect, KF_SLEEPABLE)
Expand Down
16 changes: 14 additions & 2 deletions net/mptcp/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
*/
mptcp_local_address((struct sock_common *)msk, &msk_local);
mptcp_local_address((struct sock_common *)skc, &skc_local.addr);
pr_info("%s msk_local=%u(%pI4) skc_local.addr=%u(%pI4)\n", __func__, msk_local.id, &msk_local, skc_local.addr.id, &skc_local.addr);
if (mptcp_addresses_equal(&msk_local, &skc_local.addr, false)) {
pr_info("%s return 0\n", __func__);
pr_info("%s msk_local=%u(%pI4) skc_local.addr=%u(%pI4)\n",
__func__, msk_local.family, &msk_local.addr, skc_local.addr.family, &skc_local.addr.addr);
return 0;
}

Expand Down Expand Up @@ -575,10 +575,22 @@ int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info)
if (ret < 0)
return ret;

if (loc.addr.family == AF_UNSPEC) {
NL_SET_ERR_MSG_ATTR(info->extack, attr_loc,
"invalid local address family");
return -EINVAL;
}

if (attr_rem) {
ret = mptcp_pm_parse_addr(attr_rem, info, &rem);
if (ret < 0)
return ret;

if (rem.family == AF_UNSPEC) {
NL_SET_ERR_MSG_ATTR(info->extack, attr_rem,
"invalid remote address family");
return -EINVAL;
}
}

return mptcp_pm_set_flags(&loc, &rem, info);
Expand Down
181 changes: 79 additions & 102 deletions net/mptcp/pm_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,11 @@ 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 = -EINVAL;

if (local->addr.id == 0) {
pr_debug("invalid addr id\n");
goto announce_err;
}

if (!(local->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
pr_debug("invalid addr flags\n");
goto announce_err;
}
int err;

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

spin_lock_bh(&msk->pm.lock);

Expand All @@ -242,9 +230,7 @@ static int userspace_pm_address_announce(struct mptcp_sock *msk,

spin_unlock_bh(&msk->pm.lock);

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

int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
Expand All @@ -269,13 +255,25 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)
if (err < 0)
goto announce_err;

if (addr_val.addr.id == 0) {
NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr id");
err = -EINVAL;
goto announce_err;
}

if (!(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr flags");
err = -EINVAL;
goto announce_err;
}

lock_sock(sk);
err = msk->pm.ops->address_announce ?
msk->pm.ops->address_announce(msk, &addr_val) :
userspace_pm_address_announce(msk, &addr_val);
release_sock(sk);
if (err)
GENL_SET_ERR_MSG(info, "address_announce failed");
GENL_SET_ERR_MSG(info, "did not match address and id");

announce_err:
sock_put(sk);
Expand Down Expand Up @@ -329,21 +327,15 @@ void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk,
static int userspace_pm_address_remove(struct mptcp_sock *msk, u8 id)
{
struct mptcp_pm_addr_entry *entry;
int err = -EINVAL;

if (id == 0) {
err = mptcp_userspace_pm_remove_id_zero_address(msk);
if (err)
pr_debug("address with id 0 not found\n");
goto out;
}
if (id == 0)
return mptcp_userspace_pm_remove_id_zero_address(msk);

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

list_del_rcu(&entry->list);
Expand All @@ -353,9 +345,7 @@ static int userspace_pm_address_remove(struct mptcp_sock *msk, u8 id)

sock_kfree_s((struct sock *)msk, entry, sizeof(*entry));

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

int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
Expand Down Expand Up @@ -383,8 +373,14 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
msk->pm.ops->address_remove(msk, id_val) :
userspace_pm_address_remove(msk, id_val);
release_sock(sk);
if (err)
NL_SET_ERR_MSG_ATTR(info->extack, id, "address_remove failed");
if (err) {
if (id_val)
NL_SET_ERR_MSG_ATTR(info->extack, id,
"address with specified id not found");
else
NL_SET_ERR_MSG_ATTR(info->extack, id,
"address with id 0 not found");
}

sock_put(sk);
return err;
Expand All @@ -396,42 +392,25 @@ static int userspace_pm_subflow_create(struct mptcp_sock *msk,
{
struct sock *sk = (struct sock *)msk;
struct mptcp_pm_local local;
int err = -EINVAL;

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

if (!mptcp_pm_addr_families_match(sk, &entry->addr, remote)) {
pr_debug("families mismatch\n");
goto create_err;
}
int err;

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

local.addr = entry->addr;
local.flags = entry->flags;
local.ifindex = entry->ifindex;

err = __mptcp_subflow_connect(sk, &local, remote);
if (err)
pr_debug("connect error: %d\n", err);

spin_lock_bh(&msk->pm.lock);
if (err)
mptcp_userspace_pm_delete_local_addr(msk, entry);
else
msk->pm.subflows++;
spin_unlock_bh(&msk->pm.lock);

create_err:
return err;
return 0;
}

int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
Expand All @@ -458,18 +437,31 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
if (err < 0)
goto create_err;

if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "invalid addr flags");
err = -EINVAL;
goto create_err;
}
entry.flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW;

raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
err = mptcp_pm_parse_addr(raddr, info, &addr_r);
if (err < 0)
goto create_err;

if (!mptcp_pm_addr_families_match(sk, &entry.addr, &addr_r)) {
GENL_SET_ERR_MSG(info, "families mismatch");
err = -EINVAL;
goto create_err;
}

lock_sock(sk);
err = msk->pm.ops->subflow_create ?
msk->pm.ops->subflow_create(msk, &entry, &addr_r) :
userspace_pm_subflow_create(msk, &entry, &addr_r);
release_sock(sk);
if (err)
GENL_SET_ERR_MSG(info, "subflow_create failed");
GENL_SET_ERR_MSG_FMT(info, "connect error: %d", err);

create_err:
sock_put(sk);
Expand Down Expand Up @@ -528,36 +520,9 @@ static int userspace_pm_subflow_destroy(struct mptcp_sock *msk,
{
struct sock *ssk, *sk = (struct sock *)msk;

#if IS_ENABLED(CONFIG_MPTCP_IPV6)
if (local->addr.family == AF_INET && ipv6_addr_v4mapped(&remote->addr6)) {
ipv6_addr_set_v4mapped(local->addr.addr.s_addr, &local->addr.addr6);
local->addr.family = AF_INET6;
}
if (remote->family == AF_INET && ipv6_addr_v4mapped(&local->addr.addr6)) {
ipv6_addr_set_v4mapped(remote->addr.s_addr, &remote->addr6);
remote->family = AF_INET6;
}
#endif
if (local->addr.family != remote->family) {
pr_debug("address families do not match\n");
return -EINVAL;
}

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

if (!remote->port) {
pr_debug("missing remote port\n");
return -EINVAL;
}

ssk = mptcp_nl_find_ssk(msk, &local->addr, remote);
if (!ssk) {
pr_debug("subflow not found");
if (!ssk)
return -ESRCH;
}

spin_lock_bh(&msk->pm.lock);
mptcp_userspace_pm_delete_local_addr(msk, local);
Expand Down Expand Up @@ -598,13 +563,41 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
if (err < 0)
goto destroy_err;

#if IS_ENABLED(CONFIG_MPTCP_IPV6)
if (addr_l.addr.family == AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) {
ipv6_addr_set_v4mapped(addr_l.addr.addr.s_addr, &addr_l.addr.addr6);
addr_l.addr.family = AF_INET6;
}
if (addr_r.family == AF_INET && ipv6_addr_v4mapped(&addr_l.addr.addr6)) {
ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &addr_r.addr6);
addr_r.family = AF_INET6;
}
#endif
if (addr_l.addr.family != addr_r.family) {
GENL_SET_ERR_MSG(info, "address families do not match");
err = -EINVAL;
goto destroy_err;
}

if (!addr_l.addr.port) {
NL_SET_ERR_MSG_ATTR(info->extack, laddr, "missing local port");
err = -EINVAL;
goto destroy_err;
}

if (!addr_r.port) {
NL_SET_ERR_MSG_ATTR(info->extack, raddr, "missing remote port");
err = -EINVAL;
goto destroy_err;
}

lock_sock(sk);
err = msk->pm.ops->subflow_destroy ?
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_destroy failed");
GENL_SET_ERR_MSG(info, "subflow not found");

destroy_err:
sock_put(sk);
Expand All @@ -616,19 +609,8 @@ static int userspace_pm_set_flags(struct mptcp_sock *msk,
struct mptcp_addr_info *remote)
{
struct mptcp_pm_addr_entry *entry;
int ret = -EINVAL;
u8 bkup = 0;

if (local->addr.family == AF_UNSPEC) {
pr_debug("invalid local address family\n");
goto set_flags_err;
}

if (remote->family == AF_UNSPEC) {
pr_debug("invalid remote address family\n");
goto set_flags_err;
}

if (local->flags & MPTCP_PM_ADDR_FLAG_BACKUP)
bkup = 1;

Expand All @@ -642,12 +624,7 @@ static int userspace_pm_set_flags(struct mptcp_sock *msk,
}
spin_unlock_bh(&msk->pm.lock);

ret = mptcp_pm_nl_mp_prio_send_ack(msk, &local->addr, remote, bkup);
if (ret)
pr_debug("mp_prio send ack failed\n");

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

int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,
Expand All @@ -670,7 +647,7 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,
userspace_pm_set_flags(msk, local, remote);
release_sock(sk);
if (ret)
GENL_SET_ERR_MSG(info, "set_flags failed");
GENL_SET_ERR_MSG(info, "mp_prio send ack failed");

sock_put(sk);
return ret;
Expand Down
Loading

0 comments on commit 269e9ed

Please sign in to comment.