mptcp: unify pm set_flags interfaces
This patch unifies the three PM set_flags() interfaces: mptcp_pm_nl_set_flags() in mptcp/pm_netlink.c for the in-kernel PM and mptcp_userspace_pm_set_flags() in mptcp/pm_userspace.c for the userspace PM. They'll be switched in the common PM infterface mptcp_pm_set_flags() in mptcp/pm.c based on whether token is NULL or not. Signed-off-by: Geliang Tang <geliang.tang@suse.com> Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net> Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net> Reviewed-by: Larysa Zaremba <larysa.zaremba@intel.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
f40be0db0b
commit
6ba7ce8990
@ -448,6 +448,15 @@ int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id
|
||||
return mptcp_pm_nl_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);
|
||||
}
|
||||
|
||||
int mptcp_pm_set_flags(struct net *net, struct nlattr *token,
|
||||
struct mptcp_pm_addr_entry *loc,
|
||||
struct mptcp_pm_addr_entry *rem, u8 bkup)
|
||||
{
|
||||
if (token)
|
||||
return mptcp_userspace_pm_set_flags(net, token, loc, rem, bkup);
|
||||
return mptcp_pm_nl_set_flags(net, loc, bkup);
|
||||
}
|
||||
|
||||
void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
|
||||
{
|
||||
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
|
||||
|
@ -1882,18 +1882,50 @@ next:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mptcp_pm_nl_set_flags(struct net *net, struct mptcp_pm_addr_entry *addr, u8 bkup)
|
||||
{
|
||||
struct pm_nl_pernet *pernet = pm_nl_get_pernet(net);
|
||||
u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP |
|
||||
MPTCP_PM_ADDR_FLAG_FULLMESH;
|
||||
struct mptcp_pm_addr_entry *entry;
|
||||
u8 lookup_by_id = 0;
|
||||
|
||||
if (addr->addr.family == AF_UNSPEC) {
|
||||
lookup_by_id = 1;
|
||||
if (!addr->addr.id)
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
spin_lock_bh(&pernet->lock);
|
||||
entry = __lookup_addr(pernet, &addr->addr, lookup_by_id);
|
||||
if (!entry) {
|
||||
spin_unlock_bh(&pernet->lock);
|
||||
return -EINVAL;
|
||||
}
|
||||
if ((addr->flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
|
||||
(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
|
||||
spin_unlock_bh(&pernet->lock);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
changed = (addr->flags ^ entry->flags) & mask;
|
||||
entry->flags = (entry->flags & ~mask) | (addr->flags & mask);
|
||||
*addr = *entry;
|
||||
spin_unlock_bh(&pernet->lock);
|
||||
|
||||
mptcp_nl_set_flags(net, &addr->addr, bkup, changed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }, *entry;
|
||||
struct mptcp_pm_addr_entry remote = { .addr = { .family = AF_UNSPEC }, };
|
||||
struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, };
|
||||
struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
|
||||
struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
|
||||
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
|
||||
struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
|
||||
u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP |
|
||||
MPTCP_PM_ADDR_FLAG_FULLMESH;
|
||||
struct net *net = sock_net(skb->sk);
|
||||
u8 bkup = 0, lookup_by_id = 0;
|
||||
u8 bkup = 0;
|
||||
int ret;
|
||||
|
||||
ret = mptcp_pm_parse_entry(attr, info, false, &addr);
|
||||
@ -1908,34 +1940,8 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)
|
||||
|
||||
if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP)
|
||||
bkup = 1;
|
||||
if (addr.addr.family == AF_UNSPEC) {
|
||||
lookup_by_id = 1;
|
||||
if (!addr.addr.id)
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
if (token)
|
||||
return mptcp_userspace_pm_set_flags(net, token, &addr, &remote, bkup);
|
||||
|
||||
spin_lock_bh(&pernet->lock);
|
||||
entry = __lookup_addr(pernet, &addr.addr, lookup_by_id);
|
||||
if (!entry) {
|
||||
spin_unlock_bh(&pernet->lock);
|
||||
return -EINVAL;
|
||||
}
|
||||
if ((addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
|
||||
(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
|
||||
spin_unlock_bh(&pernet->lock);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
changed = (addr.flags ^ entry->flags) & mask;
|
||||
entry->flags = (entry->flags & ~mask) | (addr.flags & mask);
|
||||
addr = *entry;
|
||||
spin_unlock_bh(&pernet->lock);
|
||||
|
||||
mptcp_nl_set_flags(net, &addr.addr, bkup, changed);
|
||||
return 0;
|
||||
return mptcp_pm_set_flags(net, token, &addr, &remote, bkup);
|
||||
}
|
||||
|
||||
static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp)
|
||||
|
@ -827,6 +827,10 @@ int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int
|
||||
int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
|
||||
unsigned int id,
|
||||
u8 *flags, int *ifindex);
|
||||
int mptcp_pm_set_flags(struct net *net, struct nlattr *token,
|
||||
struct mptcp_pm_addr_entry *loc,
|
||||
struct mptcp_pm_addr_entry *rem, u8 bkup);
|
||||
int mptcp_pm_nl_set_flags(struct net *net, struct mptcp_pm_addr_entry *addr, u8 bkup);
|
||||
int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token,
|
||||
struct mptcp_pm_addr_entry *loc,
|
||||
struct mptcp_pm_addr_entry *rem, u8 bkup);
|
||||
|
Loading…
x
Reference in New Issue
Block a user