Skip to content

Commit

Permalink
mptcp: implement userspace pm others interfaces
Browse files Browse the repository at this point in the history
This patch implements get_local_id(), get_flags(), get_addr(), dump_addr()
and set_flags() interfaces of the userspace PM.

get_local_id() interface is the same as mptcp_userspace_pm_get_local_id(),
which now can be defined as a wrapper of the interface. While get_flags()
interface is the same as mptcp_userspace_pm_get_flags() too, which now can
be defined as a wrapper of get_flags() interface.

get_addr() interface is a wrapper of mptcp_userspace_pm_lookup_addr_by_id()
helper. While dump_addr() is a wrapper of mptcp_userspace_pm_set_bitmap()
helper. These two interfaces are invoked under holding both the msk socket
lock and the msk pm lock.

Extract set_flags() interface from function mptcp_userspace_pm_set_flags(),
only leave the code for obtaining msk through "info" in this function. This
interface is invoked under holding the msk socket lock.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed Oct 16, 2024
1 parent 292fda9 commit 91c8baa
Showing 1 changed file with 59 additions and 27 deletions.
86 changes: 59 additions & 27 deletions net/mptcp/pm_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id)
return NULL;
}

int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local)
static int userspace_pm_get_local_id(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local)
{
struct mptcp_pm_addr_entry *entry = NULL;
__be16 msk_sport = ((struct inet_sock *)
Expand All @@ -154,8 +154,14 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk,
return mptcp_userspace_pm_append_new_local_addr(msk, local, true);
}

u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk,
struct mptcp_addr_info *skc)
int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local)
{
return userspace_pm_get_local_id(msk, local);
}

static u8 userspace_pm_get_flags(struct mptcp_sock *msk,
struct mptcp_addr_info *skc)
{
struct mptcp_pm_addr_entry *entry;
u8 flags = 0;
Expand All @@ -169,6 +175,12 @@ u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk,
return flags;
}

u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk,
struct mptcp_addr_info *skc)
{
return userspace_pm_get_flags(msk, skc);
}

static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info)
{
struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
Expand Down Expand Up @@ -546,34 +558,24 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info
return err;
}

int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc,
struct mptcp_addr_info *rem,
struct genl_info *info)
static int userspace_pm_set_flags(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local,
struct mptcp_addr_info *remote)
{
struct mptcp_pm_addr_entry *entry;
struct mptcp_sock *msk;
int ret = -EINVAL;
struct sock *sk;
u8 bkup = 0;

msk = mptcp_userspace_pm_get_sock(info);
if (!msk)
return ret;

sk = (struct sock *)msk;

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

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

spin_lock_bh(&msk->pm.lock);
entry = mptcp_userspace_pm_lookup_addr(msk, &loc->addr);
entry = mptcp_userspace_pm_lookup_addr(msk, &local->addr);
if (entry) {
if (bkup)
entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP;
Expand All @@ -582,11 +584,29 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc,
}
spin_unlock_bh(&msk->pm.lock);

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

int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc,
struct mptcp_addr_info *rem,
struct genl_info *info)
{
struct mptcp_sock *msk;
int ret = -EINVAL;
struct sock *sk;

msk = mptcp_userspace_pm_get_sock(info);
if (!msk)
return ret;

sk = (struct sock *)msk;

lock_sock(sk);
ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, rem, bkup);
ret = userspace_pm_set_flags(msk, loc, rem);
release_sock(sk);
if (ret)
GENL_SET_ERR_MSG(info, "set_flags failed");

set_flags_err:
sock_put(sk);
return ret;
}
Expand All @@ -606,6 +626,12 @@ static int mptcp_userspace_pm_set_bitmap(struct mptcp_sock *msk,
return 0;
}

static int userspace_pm_dump_addr(struct mptcp_sock *msk,
struct mptcp_id_bitmap *bitmap)
{
return mptcp_userspace_pm_set_bitmap(msk, bitmap);
}

int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap,
const struct genl_info *info)
{
Expand All @@ -621,14 +647,20 @@ int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap,

lock_sock(sk);
spin_lock_bh(&msk->pm.lock);
ret = mptcp_userspace_pm_set_bitmap(msk, bitmap);
ret = userspace_pm_dump_addr(msk, bitmap);
spin_unlock_bh(&msk->pm.lock);
release_sock(sk);

sock_put(sk);
return ret;
}

static struct mptcp_pm_addr_entry *
userspace_pm_get_addr(struct mptcp_sock *msk, u8 id)
{
return mptcp_userspace_pm_lookup_addr_by_id(msk, id);
}

int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
const struct genl_info *info)
{
Expand All @@ -645,7 +677,7 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,

lock_sock(sk);
spin_lock_bh(&msk->pm.lock);
entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id);
entry = userspace_pm_get_addr(msk, id);
if (entry) {
*addr = *entry;
ret = 0;
Expand Down

0 comments on commit 91c8baa

Please sign in to comment.