Skip to content

Commit 24430f8

Browse files
geliangtangdavem330
authored andcommitted
mptcp: add address into userspace pm list
Add the address into userspace_pm_local_addr_list when the subflow is created. Make sure it can be found in mptcp_nl_cmd_remove(). And delete it in the new helper mptcp_userspace_pm_delete_local_addr(). By doing this, the "REMOVE" command also works with subflows that have been created via the "SUB_CREATE" command instead of restricting to the addresses that have been announced via the "ANNOUNCE" command. Fixes: d9a4594 ("mptcp: netlink: Add MPTCP_PM_CMD_REMOVE") Link: multipath-tcp/mptcp_net-next#379 Cc: stable@vger.kernel.org Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net> Signed-off-by: Geliang Tang <geliang.tang@suse.com> Signed-off-by: Mat Martineau <martineau@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 48d73f6 commit 24430f8

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

net/mptcp/pm_userspace.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
7979
return ret;
8080
}
8181

82+
/* If the subflow is closed from the other peer (not via a
83+
* subflow destroy command then), we want to keep the entry
84+
* not to assign the same ID to another address and to be
85+
* able to send RM_ADDR after the removal of the subflow.
86+
*/
87+
static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk,
88+
struct mptcp_pm_addr_entry *addr)
89+
{
90+
struct mptcp_pm_addr_entry *entry, *tmp;
91+
92+
list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_list, list) {
93+
if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) {
94+
/* TODO: a refcount is needed because the entry can
95+
* be used multiple times (e.g. fullmesh mode).
96+
*/
97+
list_del_rcu(&entry->list);
98+
kfree(entry);
99+
return 0;
100+
}
101+
}
102+
103+
return -EINVAL;
104+
}
105+
82106
int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
83107
unsigned int id,
84108
u8 *flags, int *ifindex)
@@ -251,6 +275,7 @@ int mptcp_nl_cmd_sf_create(struct sk_buff *skb, struct genl_info *info)
251275
struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
252276
struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
253277
struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
278+
struct mptcp_pm_addr_entry local = { 0 };
254279
struct mptcp_addr_info addr_r;
255280
struct mptcp_addr_info addr_l;
256281
struct mptcp_sock *msk;
@@ -302,12 +327,24 @@ int mptcp_nl_cmd_sf_create(struct sk_buff *skb, struct genl_info *info)
302327
goto create_err;
303328
}
304329

330+
local.addr = addr_l;
331+
err = mptcp_userspace_pm_append_new_local_addr(msk, &local);
332+
if (err < 0) {
333+
GENL_SET_ERR_MSG(info, "did not match address and id");
334+
goto create_err;
335+
}
336+
305337
lock_sock(sk);
306338

307339
err = __mptcp_subflow_connect(sk, &addr_l, &addr_r);
308340

309341
release_sock(sk);
310342

343+
spin_lock_bh(&msk->pm.lock);
344+
if (err)
345+
mptcp_userspace_pm_delete_local_addr(msk, &local);
346+
spin_unlock_bh(&msk->pm.lock);
347+
311348
create_err:
312349
sock_put((struct sock *)msk);
313350
return err;
@@ -420,7 +457,11 @@ int mptcp_nl_cmd_sf_destroy(struct sk_buff *skb, struct genl_info *info)
420457
ssk = mptcp_nl_find_ssk(msk, &addr_l, &addr_r);
421458
if (ssk) {
422459
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
460+
struct mptcp_pm_addr_entry entry = { .addr = addr_l };
423461

462+
spin_lock_bh(&msk->pm.lock);
463+
mptcp_userspace_pm_delete_local_addr(msk, &entry);
464+
spin_unlock_bh(&msk->pm.lock);
424465
mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN);
425466
mptcp_close_ssk(sk, ssk, subflow);
426467
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW);

0 commit comments

Comments
 (0)