From 91c8baa54fc93373f8a4bda1b64128b242cecacf Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Wed, 16 Oct 2024 17:12:36 +0800 Subject: [PATCH] mptcp: implement userspace pm others interfaces 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 --- net/mptcp/pm_userspace.c | 86 +++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 27 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 0ab37f31eee9ff..f07c77dca84b8d 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -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 *) @@ -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; @@ -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]; @@ -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; @@ -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; } @@ -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) { @@ -621,7 +647,7 @@ 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); @@ -629,6 +655,12 @@ int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, 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) { @@ -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;