From patchwork Tue Apr 1 04:30:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14034338 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E33618FC9D for ; Tue, 1 Apr 2025 04:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743481819; cv=none; b=KGk/Nm8u/TMB0luNvMT/VjB9hjlo8Gptn7jBHjL7r4UMBkudLXdXYFMA23Q7X9sqfvCgqgJX5WmSpDUPhjmXuSIVWIDnwSsx0BTzCmuYbEcVizj2OdUFcPuhbDfUmykRJ5jaTNLNRcqAAjYcVgjyHiSva9SntI2Rtj9Ovv0fTQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743481819; c=relaxed/simple; bh=vHtAa3nM/zZD0isUYfhzEiHNsZPc8HB1lHvljXHsHsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l//hueFhR0neigipF8wuhFhThT4vMnqqFflf1hJzBOUmSkn4kOL1RMugO6wNTRQA163bOfFkRv2azbgDrNSP2iBEDTcGhATSm4oQYdCQK/EquSSRglnkHfP0ZwHL/4EHAW5bYfzSZ8OrjjCDyzPOOtq4R6O/sBtYH5nsIkMwe74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FAlMHHMw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FAlMHHMw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6A73C4CEE8; Tue, 1 Apr 2025 04:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743481818; bh=vHtAa3nM/zZD0isUYfhzEiHNsZPc8HB1lHvljXHsHsY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FAlMHHMwn8dVRChmd17es203QZiS57N8bG72EvRjAugpkQLNGVRMVwpnhdwkDI591 9rVViNiFfJwMwU1NBSZ7C66wfoFE6pxjGJldWIG6LPqPbfECikGvoGJtaZmimGlq4r 8EJ0x8weripDDBEfbpnY9I10LQYSmKoZQX7IgsxXAns7aQGxINFTge6UfM/DLIvmy7 JrqMSJEEnPhxWp1vOsbtGEa8JSKueklW6vuE6nmg86ErQ54ajpmBgHPvZtd6uN33ET XejqwopBrh8C7Fg5VZmAGsHhaHrKwGMsIeZS4R89kxVFcbgTP1JrdpIPPtVZRBj7UJ aWivlGcTHFRHg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 1/4] mptcp: pm: add accept_address helper Date: Tue, 1 Apr 2025 12:30:08 +0800 Message-ID: <26c904d198ab1a642f947e65a4f9bac40771a1b9.1743481566.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Extract the code in mptcp_pm_add_addr_received() to test whether the address can be accepted into a new helper mptcp_pm_accept_address() to simplify the code. For this, mptcp_pm_is_init_remote_addr() needs to be exported in protocol.h. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 8 +++----- net/mptcp/protocol.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index d576b03a64e1..f37ddd6111de 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -104,8 +104,8 @@ void mptcp_remote_address(const struct sock_common *skc, #endif } -static bool mptcp_pm_is_init_remote_addr(struct mptcp_sock *msk, - const struct mptcp_addr_info *remote) +bool mptcp_pm_is_init_remote_addr(struct mptcp_sock *msk, + const struct mptcp_addr_info *remote) { struct mptcp_addr_info mpc_remote; @@ -598,9 +598,7 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, } else { __MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP); } - /* id0 should not have a different address */ - } else if ((addr->id == 0 && !mptcp_pm_is_init_remote_addr(msk, addr)) || - (addr->id > 0 && !READ_ONCE(pm->accept_addr))) { + } else if (!mptcp_pm_accept_address(msk, addr)) { mptcp_pm_announce_addr(msk, addr, true); mptcp_pm_add_addr_send_ack(msk); } else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) { diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 134b46b53014..910d422d64fa 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1015,6 +1015,8 @@ void mptcp_pm_subflow_established(struct mptcp_sock *msk); bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk); void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, const struct mptcp_subflow_context *subflow); +bool mptcp_pm_is_init_remote_addr(struct mptcp_sock *msk, + const struct mptcp_addr_info *remote); void mptcp_pm_add_addr_received(const struct sock *ssk, const struct mptcp_addr_info *addr); void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk, @@ -1209,6 +1211,14 @@ static inline bool mptcp_pm_accept_subflow(struct mptcp_sock *msk) return ret; } +static inline bool mptcp_pm_accept_address(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) +{ + /* id0 should not have a different address */ + return !((addr->id == 0 && !mptcp_pm_is_init_remote_addr(msk, addr)) || + (addr->id > 0 && !READ_ONCE(msk->pm.accept_addr))); +} + void mptcp_sockopt_sync_locked(struct mptcp_sock *msk, struct sock *ssk); static inline struct mptcp_ext *mptcp_get_ext(const struct sk_buff *skb) From patchwork Tue Apr 1 04:30:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14034339 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 787CD19309C for ; Tue, 1 Apr 2025 04:30:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743481821; cv=none; b=eh3l+LzUBNKSQZeSOPVWFikHurEIhRp+oIx7u8GhNcfBNAHDP77umaVkuOAFdaFlKr4XEBm5HAO+XrEmHMtRfF/TsjK3L/KEqL364lOXvyN/U/P2jiWvMxemoMyrXZ0DchGenbCNyJ4VkyLm5jb7D/fKUBDmloSSkCbXB1DGxaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743481821; c=relaxed/simple; bh=l38BQoX6CJhk7VAP8TTYDh6GDT4L6IvBrFy/K9nk4SE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=drPvqKyCxpCimjK1KMLv2SSlqATwuLEpwTpvb0laS9bWBwMgXbHaB5exF2rCYERvJZOoQZdBex/YQ5rfKnwOnjii3dT9HomiFG+IY30p5PmXhCsFOhN4Qc3SAUJN6cjXu0V6dm27sY14PPCAz/4qH0ZADgKNGsu9GKEjQAz1iKM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LNbyDZwm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LNbyDZwm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FDB0C4CEE9; Tue, 1 Apr 2025 04:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743481820; bh=l38BQoX6CJhk7VAP8TTYDh6GDT4L6IvBrFy/K9nk4SE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LNbyDZwmEDCioFW4RPguFkub3ZNteMxQaZhww2DmfmiCbktWU3Qn+iL4A+inhjdF0 roPDMkk+lrGF58dLO4SRTTZ8uXxCndCKG9k+137tTNM6zn9LyvH18j0N7wygYolVSp CjzNCyDAdbjrs6Yrsxv5B21lMxdtRpf2Ma4L4Lda1kdme+t1w9J8l8w/gtaWjR3L0l Clt10ihc7Wp3bsPwEopw9KyV3ERge91KVCShEj6Z7tBlnA18833qCYyoUSHK4j3sI5 DSEEeOAbBtQ4cbpg/4Go4cy+SW9M4mOt8fm+yfC0GhNjjT9q1+dOQceW+Jh3iWsPe0 aA6tQer4hFaew== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 2/4] mptcp: pm: add accept_new_address() interface Date: Tue, 1 Apr 2025 12:30:09 +0800 Message-ID: <94e82037a2f86ba85bc0f7c5ada46424b785073b.1743481566.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Similar to the accept_new_subflow() interface, this patch adds a mandatory accept_new_address() interface for struct mptcp_pm_ops, which is used to determine whether an ADD_ADDR address is accepted by PM. This interface is called in mptcp_pm_add_addr_received(). If the address is not accepted, increase MPTCP_MIB_ADDADDRDROP counter and return. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 4 ++++ net/mptcp/pm.c | 17 ++++++++--------- net/mptcp/pm_kernel.c | 8 ++++++++ net/mptcp/pm_userspace.c | 7 +++++++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 1eae68c9e662..d6bb030b14c6 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -129,6 +129,10 @@ struct mptcp_pm_ops { void (*established)(struct mptcp_sock *msk); void (*subflow_established)(struct mptcp_sock *msk); + /* required */ + bool (*accept_new_address)(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr); + char name[MPTCP_PM_NAME_MAX]; struct module *owner; struct list_head list; diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index f37ddd6111de..519beb8cadfa 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -589,22 +589,21 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, mptcp_event_addr_announced(ssk, addr); + if (!pm->ops->accept_new_address(msk, addr)) { + MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_ADDADDRDROP); + return; + } + spin_lock_bh(&pm->lock); if (mptcp_pm_is_userspace(msk)) { - if (mptcp_userspace_pm_active(msk)) { - mptcp_pm_announce_addr(msk, addr, true); - mptcp_pm_add_addr_send_ack(msk); - } else { - __MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP); - } + mptcp_pm_announce_addr(msk, addr, true); + mptcp_pm_add_addr_send_ack(msk); } else if (!mptcp_pm_accept_address(msk, addr)) { mptcp_pm_announce_addr(msk, addr, true); mptcp_pm_add_addr_send_ack(msk); } else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) { pm->remote = *addr; - } else { - __MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP); } spin_unlock_bh(&pm->lock); @@ -1046,7 +1045,7 @@ struct mptcp_pm_ops *mptcp_pm_find(const char *name) int mptcp_pm_validate(struct mptcp_pm_ops *pm_ops) { if (!pm_ops->get_local_id || !pm_ops->get_priority || - !pm_ops->accept_new_subflow) { + !pm_ops->accept_new_subflow || !pm_ops->accept_new_address) { pr_err("%s does not implement required ops\n", pm_ops->name); return -EINVAL; } diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index 000f4f173ad5..defd8312a764 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -1413,6 +1413,13 @@ static bool mptcp_pm_kernel_accept_new_subflow(struct mptcp_sock *msk, return ret; } +static bool mptcp_pm_kernel_accept_new_address(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) +{ + return !(mptcp_pm_accept_address(msk, addr) && + msk->pm.status & BIT(MPTCP_PM_ADD_ADDR_RECEIVED)); +} + static void mptcp_pm_kernel_init(struct mptcp_sock *msk) { bool subflows_allowed = !!mptcp_pm_get_subflows_max(msk); @@ -1439,6 +1446,7 @@ struct mptcp_pm_ops mptcp_pm_kernel = { .accept_new_subflow = mptcp_pm_kernel_accept_new_subflow, .established = mptcp_pm_kernel_established, .subflow_established = mptcp_pm_kernel_subflow_established, + .accept_new_address = mptcp_pm_kernel_accept_new_address, .init = mptcp_pm_kernel_init, .name = "kernel", .owner = THIS_MODULE, diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 31da3b9f4cc8..b09582c0118d 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -689,6 +689,12 @@ static bool mptcp_pm_userspace_accept_new_subflow(struct mptcp_sock *msk, return mptcp_userspace_pm_active(msk); } +static bool mptcp_pm_userspace_accept_new_address(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) +{ + return mptcp_userspace_pm_active(msk); +} + static void mptcp_pm_userspace_release(struct mptcp_sock *msk) { mptcp_userspace_pm_free_local_addr_list(msk); @@ -698,6 +704,7 @@ static struct mptcp_pm_ops mptcp_pm_userspace = { .get_local_id = mptcp_pm_userspace_get_local_id, .get_priority = mptcp_pm_userspace_get_priority, .accept_new_subflow = mptcp_pm_userspace_accept_new_subflow, + .accept_new_address = mptcp_pm_userspace_accept_new_address, .release = mptcp_pm_userspace_release, .name = "userspace", .owner = THIS_MODULE, From patchwork Tue Apr 1 04:30:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14034340 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31BD71BFE00 for ; Tue, 1 Apr 2025 04:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743481823; cv=none; b=LXURrugnCMGJFp1ekQ2/XSWF9DT8Pvl0a2kbS+u/7i7OpnRSiv8byeckfsuDzvyfb6/CDRgO89921jzTZDHMeDCKoYVv3Q66We7jPwDCeU/0phZEvecOSIuN2MH2FbasXdWL6ScmMqpe373AxFRnLQlpuONPEUA0hjrkANXLqq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743481823; c=relaxed/simple; bh=u0kJ6SsfbEqXkn9bPrklhCaVJ3IU1BPK7SABFK0nBOI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J3Uo6sOmk/e1nvPScPoI4laSFoHWzn/IFExXVg4IYlILs9C28UHb9ajMfbR7yrSYZKwqGAWtPSMsqZt16Au6If0mYwZuR2VdsXfflUykbH7VqvQuQIu6yUkkKltt/7fHKQrBTJunA0wo62iRkahDOJEFHocYeZloE0ZPsMRuI7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SmpZE5tn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SmpZE5tn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92D6BC4CEEA; Tue, 1 Apr 2025 04:30:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743481822; bh=u0kJ6SsfbEqXkn9bPrklhCaVJ3IU1BPK7SABFK0nBOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SmpZE5tnqGiOkiVCG+q7bUKMafj3H+GvRhFsre98WryGfYKc40sGdXFVh0t1cvPyT JtVKlGOtKwrBDViyP/O2JsYpWKTkR8cTS/JH3/b+lMtI4l0RSOgNL2nWKcvkw7uY+w AOQGu3IikVjgcEh+PWeUydNmaqdQdbRcev1xGdVU6XaoKfLlobV7NhbgQPfBRUtHfp hq7BxfI59s75rw3HqX1MYTwduP6L/LRccKUri8yohky0gixKUldASdmBdM3CSZchfi 14IC9v2ekY38Bx+9TeU/eb2jM1ZxMZc3JaaYFdDz16DbQrOb1rancw8bD9uTOovLjy JLmT2ID/xTGiQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 3/4] mptcp: pm: add add_addr_received() interface Date: Tue, 1 Apr 2025 12:30:10 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch adds an optional .add_addr_received interface for struct mptcp_pm_ops and invokes it in mptcp_pm_worker(). __mptcp_pm_kernel_worker() helper can be dropped now. This interface is only implemented in the in-kernel PM as a wrapper of mptcp_pm_nl_add_addr_received(). ADD_ADDR echo is moved forward from mptcp_pm_nl_add_addr_received() to mptcp_pm_add_addr_received(). Signed-off-by: Geliang Tang --- include/net/mptcp.h | 3 +++ net/mptcp/pm.c | 22 ++++++++++------------ net/mptcp/pm_kernel.c | 23 +++++++---------------- net/mptcp/protocol.h | 1 - 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index d6bb030b14c6..d63d251932ac 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -133,6 +133,9 @@ struct mptcp_pm_ops { bool (*accept_new_address)(struct mptcp_sock *msk, const struct mptcp_addr_info *addr); + /* optional, call from the msk context */ + void (*add_addr_received)(struct mptcp_sock *msk); + char name[MPTCP_PM_NAME_MAX]; struct module *owner; struct list_head list; diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 519beb8cadfa..39d0ad715d26 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -596,15 +596,13 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, spin_lock_bh(&pm->lock); - if (mptcp_pm_is_userspace(msk)) { - mptcp_pm_announce_addr(msk, addr, true); - mptcp_pm_add_addr_send_ack(msk); - } else if (!mptcp_pm_accept_address(msk, addr)) { - mptcp_pm_announce_addr(msk, addr, true); - mptcp_pm_add_addr_send_ack(msk); - } else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) { + mptcp_pm_announce_addr(msk, addr, true); + mptcp_pm_add_addr_send_ack(msk); + + if (pm->ops->add_addr_received && + mptcp_pm_accept_address(msk, addr) && + mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) pm->remote = *addr; - } spin_unlock_bh(&pm->lock); } @@ -932,7 +930,8 @@ void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) void mptcp_pm_worker(struct mptcp_sock *msk) { - u8 status, mask = BIT(MPTCP_PM_ADD_ADDR_SEND_ACK) | + u8 status, mask = BIT(MPTCP_PM_ADD_ADDR_RECEIVED) | + BIT(MPTCP_PM_ADD_ADDR_SEND_ACK) | BIT(MPTCP_PM_RM_ADDR_RECEIVED) | BIT(MPTCP_PM_ESTABLISHED) | BIT(MPTCP_PM_SUBFLOW_ESTABLISHED); @@ -949,6 +948,8 @@ void mptcp_pm_worker(struct mptcp_sock *msk) spin_unlock_bh(&pm->lock); pr_debug("msk=%p status=%x\n", msk, status); + if (status & BIT(MPTCP_PM_ADD_ADDR_RECEIVED)) + pm->ops->add_addr_received(msk); if (status & BIT(MPTCP_PM_ADD_ADDR_SEND_ACK)) mptcp_pm_addr_send_ack(msk); if (status & BIT(MPTCP_PM_RM_ADDR_RECEIVED)) @@ -957,9 +958,6 @@ void mptcp_pm_worker(struct mptcp_sock *msk) pm->ops->established(msk); if (status & BIT(MPTCP_PM_SUBFLOW_ESTABLISHED)) pm->ops->subflow_established(msk); - spin_lock_bh(&pm->lock); - __mptcp_pm_kernel_worker(msk); - spin_unlock_bh(&pm->lock); } static void mptcp_pm_ops_init(struct mptcp_sock *msk, diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index defd8312a764..dff880b030d1 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -448,7 +448,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, return i; } -static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) +static void mptcp_pm_kernel_add_addr_received(struct mptcp_sock *msk) { struct mptcp_pm_local locals[MPTCP_PM_ADDR_MAX]; struct sock *sk = (struct sock *)msk; @@ -465,12 +465,11 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) msk->pm.add_addr_accepted, add_addr_accept_max, msk->pm.remote.family); + spin_lock_bh(&msk->pm.lock); remote = msk->pm.remote; - mptcp_pm_announce_addr(msk, &remote, true); - __mptcp_pm_addr_send_ack(msk); if (lookup_subflow_by_daddr(&msk->conn_list, &remote)) - return; + goto out; /* pick id 0 port, if none is provided the remote address */ if (!remote.port) @@ -481,7 +480,7 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) */ nr = fill_local_addresses_vec(msk, &remote, locals); if (nr == 0) - return; + goto out; spin_unlock_bh(&msk->pm.lock); for (i = 0; i < nr; i++) @@ -497,6 +496,8 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) msk->pm.subflows >= subflows_max) WRITE_ONCE(msk->pm.accept_addr, false); } +out: + spin_unlock_bh(&msk->pm.lock); } void mptcp_pm_nl_rm_addr(struct mptcp_sock *msk, u8 rm_id) @@ -1346,17 +1347,6 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk) return true; } -/* Called under PM lock */ -void __mptcp_pm_kernel_worker(struct mptcp_sock *msk) -{ - struct mptcp_pm_data *pm = &msk->pm; - - if (pm->status & BIT(MPTCP_PM_ADD_ADDR_RECEIVED)) { - pm->status &= ~BIT(MPTCP_PM_ADD_ADDR_RECEIVED); - mptcp_pm_nl_add_addr_received(msk); - } -} - static int __net_init pm_nl_init_net(struct net *net) { struct pm_nl_pernet *pernet = pm_nl_get_pernet(net); @@ -1447,6 +1437,7 @@ struct mptcp_pm_ops mptcp_pm_kernel = { .established = mptcp_pm_kernel_established, .subflow_established = mptcp_pm_kernel_subflow_established, .accept_new_address = mptcp_pm_kernel_accept_new_address, + .add_addr_received = mptcp_pm_kernel_add_addr_received, .init = mptcp_pm_kernel_init, .name = "kernel", .owner = THIS_MODULE, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 910d422d64fa..128c081810d9 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1167,7 +1167,6 @@ void __init mptcp_pm_kernel_register(void); void __init mptcp_pm_userspace_register(void); void __init mptcp_pm_nl_init(void); void mptcp_pm_worker(struct mptcp_sock *msk); -void __mptcp_pm_kernel_worker(struct mptcp_sock *msk); unsigned int mptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk); unsigned int mptcp_pm_get_add_addr_accept_max(const struct mptcp_sock *msk); unsigned int mptcp_pm_get_subflows_max(const struct mptcp_sock *msk); From patchwork Tue Apr 1 04:30:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14034341 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96D79192B90 for ; Tue, 1 Apr 2025 04:30:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743481824; cv=none; b=ChbNeUQnQMppvvjv97mxRFugE5EtmTAILW07xW3C+NZAFmNT+c5bDfra+1scL9F6AvFUKcGvNZMsWZBO2CRYbPQHncSli8cuM1/mKNsxPzjVs5fBZ75pQqhZxI2TS5X6lN/K0BuWBBcoln7rNP0ZuU4VwO4cghZZuQA1arEuqGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743481824; c=relaxed/simple; bh=0H55XYBfV79m/8lkr7BOgXjl+euDKNILcGKOhbo8Mys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e+YwU/kgR6xaAO+PAM8Psffc7KPWoUMaT8UV9JccN8VU79YEyI7wWUHGAHwkdPpX8T9QN5ReCJYHjAZPblNmuei9c1EFieJVfzPuHHjmr2AoYKIw4jR8wM6syiuDz23MnGtijLCqX9K3x9L1UmCMPVO41HwdyeOaJ/4oHyzR20Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=evJthCy7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="evJthCy7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F560C4CEE8; Tue, 1 Apr 2025 04:30:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743481824; bh=0H55XYBfV79m/8lkr7BOgXjl+euDKNILcGKOhbo8Mys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=evJthCy7mNLL0+X9nZeTwxydiEB7WVjZNdgIimSBO6WUf3R2HdsxDVcVS6S+3EHOm Bw1Wuyc3BKV3A3ioqn2JA3+noqok/SFzpUDqwII9MZXN41vIvWBTQWD5wahtrsbQNh 7nSzYWJ+y1iLGgTZUZkaOVd87MX4V0z7S3Huh12yYv+Evaw6MX0t9heq5QVavXxEtu mvjJj3QbjFVbZvPDq1rTS8XUL3BhWbFU9bZqT6cB5UgX9GJqeIieDR7Bf3NJ+Jhu/W TfRhCZ51DLvQWDtp+lylrNGnpWr7zQN/R8yVWVvXD1PdC0buVEGPnLEgzDSfbJ6GUU QbUq54sVV/qWQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 4/4] mptcp: pm: add rm_addr_received() interface Date: Tue, 1 Apr 2025 12:30:11 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch adds an optional .rm_addr_received interface for struct mptcp_pm_ops and invokes it in mptcp_pm_rm_addr_or_subflow(). This interface is only implemented in the in-kernel PM as a wrapper of mptcp_pm_nl_rm_addr(). Signed-off-by: Geliang Tang --- include/net/mptcp.h | 1 + net/mptcp/pm.c | 4 ++-- net/mptcp/pm_kernel.c | 3 ++- net/mptcp/protocol.h | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index d63d251932ac..6d4c9304157b 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -135,6 +135,7 @@ struct mptcp_pm_ops { /* optional, call from the msk context */ void (*add_addr_received)(struct mptcp_sock *msk); + void (*rm_addr_received)(struct mptcp_sock *msk, u8 rm_id); char name[MPTCP_PM_NAME_MAX]; struct module *owner; diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 39d0ad715d26..07b144ccc9f8 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -690,8 +690,8 @@ static void mptcp_pm_rm_addr_or_subflow(struct mptcp_sock *msk, if (rm_type == MPTCP_MIB_RMADDR) { __MPTCP_INC_STATS(sock_net(sk), rm_type); - if (removed && mptcp_pm_is_kernel(msk)) - mptcp_pm_nl_rm_addr(msk, rm_id); + if (removed && msk->pm.ops->rm_addr_received) + msk->pm.ops->rm_addr_received(msk, rm_id); } } } diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index dff880b030d1..b6c489a29c5d 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -500,7 +500,7 @@ static void mptcp_pm_kernel_add_addr_received(struct mptcp_sock *msk) spin_unlock_bh(&msk->pm.lock); } -void mptcp_pm_nl_rm_addr(struct mptcp_sock *msk, u8 rm_id) +static void mptcp_pm_kernel_rm_addr_received(struct mptcp_sock *msk, u8 rm_id) { if (rm_id && WARN_ON_ONCE(msk->pm.add_addr_accepted == 0)) { /* Note: if the subflow has been closed before, this @@ -1438,6 +1438,7 @@ struct mptcp_pm_ops mptcp_pm_kernel = { .subflow_established = mptcp_pm_kernel_subflow_established, .accept_new_address = mptcp_pm_kernel_accept_new_address, .add_addr_received = mptcp_pm_kernel_add_addr_received, + .rm_addr_received = mptcp_pm_kernel_rm_addr_received, .init = mptcp_pm_kernel_init, .name = "kernel", .owner = THIS_MODULE, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 128c081810d9..70addda39a5f 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1026,7 +1026,6 @@ void mptcp_pm_send_ack(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow, bool prio, bool backup); void __mptcp_pm_addr_send_ack(struct mptcp_sock *msk); -void mptcp_pm_nl_rm_addr(struct mptcp_sock *msk, u8 rm_id); void mptcp_pm_rm_subflow(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list); void mptcp_pm_rm_addr_received(struct mptcp_sock *msk,