mptcp: add needs_id for netlink appending addr
commit 584f3894262634596532cf43a5e782e34a0ce374 upstream.
Just the same as userspace PM, a new parameter needs_id is added for
in-kernel PM mptcp_pm_nl_append_new_local_addr() too.
Add a new helper mptcp_pm_has_addr_attr_id() to check whether an address
ID is set from PM or not.
In mptcp_pm_nl_get_local_id(), needs_id is always true, but in
mptcp_pm_nl_add_addr_doit(), pass mptcp_pm_has_addr_attr_id() to
needs_it.
Fixes: efd5a4c04e
("mptcp: add the address ID assignment bitmap")
Cc: stable@vger.kernel.org
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
6931f9029a
commit
7e7a81f9f2
|
@ -904,7 +904,8 @@ static void __mptcp_pm_release_addr_entry(struct mptcp_pm_addr_entry *entry)
|
|||
}
|
||||
|
||||
static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
|
||||
struct mptcp_pm_addr_entry *entry)
|
||||
struct mptcp_pm_addr_entry *entry,
|
||||
bool needs_id)
|
||||
{
|
||||
struct mptcp_pm_addr_entry *cur, *del_entry = NULL;
|
||||
unsigned int addr_max;
|
||||
|
@ -952,7 +953,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
|
|||
}
|
||||
}
|
||||
|
||||
if (!entry->addr.id) {
|
||||
if (!entry->addr.id && needs_id) {
|
||||
find_next:
|
||||
entry->addr.id = find_next_zero_bit(pernet->id_bitmap,
|
||||
MPTCP_PM_MAX_ADDR_ID + 1,
|
||||
|
@ -963,7 +964,7 @@ find_next:
|
|||
}
|
||||
}
|
||||
|
||||
if (!entry->addr.id)
|
||||
if (!entry->addr.id && needs_id)
|
||||
goto out;
|
||||
|
||||
__set_bit(entry->addr.id, pernet->id_bitmap);
|
||||
|
@ -1095,7 +1096,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc
|
|||
entry->ifindex = 0;
|
||||
entry->flags = MPTCP_PM_ADDR_FLAG_IMPLICIT;
|
||||
entry->lsk = NULL;
|
||||
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
|
||||
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry, true);
|
||||
if (ret < 0)
|
||||
kfree(entry);
|
||||
|
||||
|
@ -1311,6 +1312,18 @@ next:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static bool mptcp_pm_has_addr_attr_id(const struct nlattr *attr,
|
||||
struct genl_info *info)
|
||||
{
|
||||
struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1];
|
||||
|
||||
if (!nla_parse_nested_deprecated(tb, MPTCP_PM_ADDR_ATTR_MAX, attr,
|
||||
mptcp_pm_addr_policy, info->extack) &&
|
||||
tb[MPTCP_PM_ADDR_ATTR_ID])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
|
||||
|
@ -1352,7 +1365,8 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
|
|||
goto out_free;
|
||||
}
|
||||
}
|
||||
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
|
||||
ret = mptcp_pm_nl_append_new_local_addr(pernet, entry,
|
||||
!mptcp_pm_has_addr_attr_id(attr, info));
|
||||
if (ret < 0) {
|
||||
GENL_SET_ERR_MSG_FMT(info, "too many addresses or duplicate one: %d", ret);
|
||||
goto out_free;
|
||||
|
|
Loading…
Reference in New Issue