This patch tests MPTCP_PM_ADDR_FLAG_SET_ID flag when appending a new
address in mptcp_pm_nl_append_new_local_addr() in pm_netlink.c and in
mptcp_userspace_pm_append_new_local_addr() in pm_userspace.c. If this
flag is set, do not alloc new address ID from id_bitmap, just keep the
userspace set address ID.
Fixes: e5ed101a6028 ("mptcp: userspace pm allow creating id 0 subflow")
Signed-off-by: Geliang Tang <geliang.tang@linux.dev>
---
net/mptcp/pm_netlink.c | 7 +++++--
net/mptcp/pm_userspace.c | 9 +++++++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index dedc5a038b10..8a311b497603 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -949,7 +949,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
}
}
- if (!entry->addr.id) {
+ if (!entry->addr.id && !(entry->flags & MPTCP_PM_ADDR_FLAG_SET_ID)) {
find_next:
entry->addr.id = find_next_zero_bit(pernet->id_bitmap,
MPTCP_PM_MAX_ADDR_ID + 1,
@@ -960,9 +960,12 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
}
}
- if (!entry->addr.id)
+ if (!entry->addr.id && !(entry->flags & MPTCP_PM_ADDR_FLAG_SET_ID))
goto out;
+ if (entry->flags & MPTCP_PM_ADDR_FLAG_SET_ID)
+ entry->flags &= ~MPTCP_PM_ADDR_FLAG_SET_ID;
+
__set_bit(entry->addr.id, pernet->id_bitmap);
if (entry->addr.id > pernet->next_id)
pernet->next_id = entry->addr.id;
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 8134dbdc7005..ce8ae7aa5aad 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -41,8 +41,11 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
spin_lock_bh(&msk->pm.lock);
list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) {
addr_match = mptcp_addresses_equal(&e->addr, &entry->addr, true);
- if (addr_match && entry->addr.id == 0)
+ if (addr_match && entry->addr.id == 0 &&
+ !(entry->flags & MPTCP_PM_ADDR_FLAG_SET_ID))
entry->addr.id = e->addr.id;
+ else if (entry->flags & MPTCP_PM_ADDR_FLAG_SET_ID)
+ entry->flags &= ~MPTCP_PM_ADDR_FLAG_SET_ID;
id_match = (e->addr.id == entry->addr.id);
if (addr_match && id_match) {
match = e;
@@ -64,10 +67,12 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
}
*e = *entry;
- if (!e->addr.id)
+ if (!e->addr.id && !(e->flags & MPTCP_PM_ADDR_FLAG_SET_ID))
e->addr.id = find_next_zero_bit(id_bitmap,
MPTCP_PM_MAX_ADDR_ID + 1,
1);
+ else if (e->flags & MPTCP_PM_ADDR_FLAG_SET_ID)
+ e->flags &= ~MPTCP_PM_ADDR_FLAG_SET_ID;
list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list);
msk->pm.local_addr_used++;
ret = e->addr.id;
--
2.39.2