From 47f0900e82dc39392381113c15c4add32c2f9edb Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Wed, 9 Aug 2023 15:06:37 +0800 Subject: [PATCH] mptcp: remove id 0 subflow & address This patch adds the ability to send RM_ADDR for local ID 0 and the ability to remove id 0 subflow. Put id 0 into a removing list, pass it to mptcp_pm_remove_addr() to remve id 0 address and pass it to mptcp_pm_nl_rm_subflow_received() to remove id 0 subflow. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/379 Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index d042d32beb4df0..38629ebc4ec6d9 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -239,6 +239,21 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info) goto remove_err; } + if (id_val == 0) { + struct mptcp_rm_list list = { .nr = 0 }; + + list.ids[list.nr++] = 0; + + lock_sock((struct sock *)msk); + spin_lock_bh(&msk->pm.lock); + mptcp_pm_remove_addr(msk, &list); + spin_unlock_bh(&msk->pm.lock); + release_sock((struct sock *)msk); + + err = 0; + goto remove_err; + } + lock_sock((struct sock *)msk); list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { @@ -399,14 +414,16 @@ int mptcp_nl_cmd_sf_destroy(struct sk_buff *skb, struct genl_info *info) struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; + struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_addr_info addr_l; struct mptcp_addr_info addr_r; struct mptcp_sock *msk; struct sock *sk, *ssk; int err = -EINVAL; u32 token_val; + u8 id_val; - if (!laddr || !raddr || !token) { + if (((!laddr || !raddr) && !id) || !token) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } @@ -424,6 +441,27 @@ int mptcp_nl_cmd_sf_destroy(struct sk_buff *skb, struct genl_info *info) goto destroy_err; } + if (id) { + id_val = nla_get_u8(id); + if (id_val == 0) { + struct mptcp_rm_list list = { .nr = 0 }; + + list.ids[list.nr++] = 0; + + sk = (struct sock *)msk; + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); + mptcp_pm_nl_rm_subflow_received(msk, &list); + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + + err = 0; + } else { + err = -EINVAL; + } + goto destroy_err; + } + err = mptcp_pm_parse_addr(laddr, info, &addr_l); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr");