From patchwork Fri Dec 13 07:35:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13906630 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 795F0188CC9 for ; Fri, 13 Dec 2024 07:35:41 +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=1734075342; cv=none; b=ZOGcW1mYeIiTBrR2W2Px6ORL+03MupU6CsL8VOGU08Ek+vWwwyv33dCU+gcGbR9+ZIY7fp/1U5Z6f1y0OSgTldzJMPdN3r0eGhKrixLhmeVkMD+RIeAO24dW4Uni0OH06F/EvQg5pLCLLaNIIZaUN0KoxR4Z1RJq6Zzm+maEXjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734075342; c=relaxed/simple; bh=xi3n30NKy6jcAWd6CK0ffRX8YNgG4baU8O7YcFiv/VE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AV9zR6PDnc44pKAZMiBUFAwFcWgj8P3qlh93kPUYanB5bwJ1eUnI1kEMPveHniYGKSk75PBLlvvhSZ7RX/MrkVSFkFIwGOmCRA2jgVbTaLNlkcBTreurnUnCD/IHpG+b30ZlC7FuV5dt0Mi3ENdrKEJ/j44+dg8WnUt0p1yXoSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PshzT/j2; 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="PshzT/j2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 274A8C4CED1; Fri, 13 Dec 2024 07:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734075341; bh=xi3n30NKy6jcAWd6CK0ffRX8YNgG4baU8O7YcFiv/VE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PshzT/j2tGj3YFIx3RMA7EarbIehAIxX4QN9q1lHQu74b9f3Sp1SjCm/yG2TiRwim 69GnJybcgkEyYky/SjmoUnErEma0kHnWHB5EkbBV67c8k+7Why/cRcGztyLOWfVMPc QB2jk3TrI7CBM7Tqiw5C0HaZL05n7nRUoPgCVHasE8MpY9cNwwNTWxYYnqrqmsf97K nJmqqe+GvH4IDff8yfBMoftdsz0o5zN3MQGCdP9n9LDeZTllJvGe8j+3jgF5LudpYG ZL+PNNiSKpO5ERPyTgWQhduFrymvS8BgS3Y7Wfhki7WDon5OEsSEtDfCkLz1sAy0H5 6bQOi6bqKrNEw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 1/8] mptcp: make three pm wrappers static Date: Fri, 13 Dec 2024 15:35:22 +0800 Message-ID: <27f9dc45e43007e93483afbbb92a0dfac3e0ceab.1734074788.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 Three netlink functions: mptcp_pm_nl_get_addr_doit() mptcp_pm_nl_get_addr_dumpit() mptcp_pm_nl_set_flags_doit() are generic, implemented for each PM, in-kernel PM and userspace PM. It's clearer to move them from pm_netlink.c to pm.c. And the linked three path manager wrappers mptcp_pm_get_addr() mptcp_pm_dump_addr() mptcp_pm_set_flags() can be changed as static functions, no need to export them in protocol.h. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 23 ++++++++++++++++++++--- net/mptcp/pm_netlink.c | 16 ---------------- net/mptcp/protocol.h | 3 --- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 16c336c51940..a29be5ff73a6 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -10,6 +10,7 @@ #include "protocol.h" #include "mib.h" +#include "mptcp_pm_gen.h" /* path manager command handlers */ @@ -433,14 +434,19 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) return mptcp_pm_nl_is_backup(msk, &skc_local); } -int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) return mptcp_userspace_pm_get_addr(skb, info); return mptcp_pm_nl_get_addr(skb, info); } -int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) +int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) +{ + return mptcp_pm_get_addr(skb, info); +} + +static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { const struct genl_info *info = genl_info_dump(cb); @@ -449,13 +455,24 @@ int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) return mptcp_pm_nl_dump_addr(msg, cb); } -int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) +int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, + struct netlink_callback *cb) +{ + return mptcp_pm_dump_addr(msg, cb); +} + +static int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) return mptcp_userspace_pm_set_flags(skb, info); return mptcp_pm_nl_set_flags(skb, info); } +int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info) +{ + return mptcp_pm_set_flags(skb, info); +} + void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 98ac73938bd8..32367fcc728e 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1812,11 +1812,6 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) return ret; } -int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) -{ - return mptcp_pm_get_addr(skb, info); -} - int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { @@ -1860,12 +1855,6 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, return msg->len; } -int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, - struct netlink_callback *cb) -{ - return mptcp_pm_dump_addr(msg, cb); -} - static int parse_limit(struct genl_info *info, int id, unsigned int *limit) { struct nlattr *attr = info->attrs[id]; @@ -2035,11 +2024,6 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) return 0; } -int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info) -{ - return mptcp_pm_set_flags(skb, info); -} - static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp) { genlmsg_multicast_netns(&mptcp_genl_family, net, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 19a811220621..3bff78efd8ed 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1035,7 +1035,6 @@ bool mptcp_lookup_subflow_by_saddr(const struct list_head *list, const struct mptcp_addr_info *saddr); bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr); -int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info); int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info); int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info); int mptcp_pm_announce_addr(struct mptcp_sock *msk, @@ -1128,12 +1127,10 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_in bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); -int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info); int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info); int mptcp_userspace_pm_get_addr(struct sk_buff *skb, struct genl_info *info); From patchwork Fri Dec 13 07:35:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13906631 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 A61D1188CC9 for ; Fri, 13 Dec 2024 07:35:43 +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=1734075343; cv=none; b=tFOvKoEKBS+Ih2Xb2ssWcyKxXzrU1pJ5ChhkNhNTrBJDwpxukqbJSwzQYFJEL8aTOnJtKXqmxHLRn5Plvgfo9CVIvocxntlO+p0pmmwYuHYfB1uK/9emVptbTXe2pclGrj8jFe5igOTi15+VfwWtRBOjj2FV048IOYe+FnJEeAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734075343; c=relaxed/simple; bh=WP5zRwz20kYRmrXTrG67NeIVHf1GKhYrs69R3SdslX8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nc3pDLfYpr+hjNwa6u65K6R8OM4dweYjVRx0ygbIQRHxlpQ4il11I9kaYve2oAap+816kvVV8eZjzg/+C9Hx/qZYQrXdCD06Sw9sTsBmQF/0dB8pNX73xyqBx/fUNsD2viqDjDWm6Q4lDxd9BsIwYqr2nxBNq+J/RTXIFcoZ2G8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gQkyltYC; 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="gQkyltYC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06668C4CED0; Fri, 13 Dec 2024 07:35:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734075343; bh=WP5zRwz20kYRmrXTrG67NeIVHf1GKhYrs69R3SdslX8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gQkyltYCCtyc7Jhdw2O1JzgiTHVS3Ji1Q23t/3ofxey8TEdtT5vHMQpaPQgOBca/2 J1sCZ+jBBlskE1sOwnqd9OOTEBMRrOhsodlbJpmAVhowl3fFcv9DTO8/ql+jKQ6Pp7 dlvEtIsbfNMkugDMhD7huoZEk1NgJM97jVMRZcUf3/iDiZnArNzXByBnOTS8H6rJFW 8d3YtSxPY77MpH6P2Ng5K/o/miVXVlNKLGpNqLmhVq08C3IacRRBvUYZJzBT5lmrNW fmyPl0uTEXLLHbU3zMrYkhSH9HaRMEDgyJZ59zLm2ZubImwGHtc11QSwH6IsP2Ybe0 MW1TQ1ab5y4xQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 2/8] mptcp: drop skb parameter of get_addr Date: Fri, 13 Dec 2024 15:35:23 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 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 The first parameters 'skb' of get_addr() interfaces are now useless since mptcp_userspace_pm_get_sock() helper is used. This patch drops these useless parameters of them. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 8 ++++---- net/mptcp/pm_netlink.c | 2 +- net/mptcp/pm_userspace.c | 3 +-- net/mptcp/protocol.h | 5 ++--- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index a29be5ff73a6..526e5bca1fa1 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -434,16 +434,16 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) return mptcp_pm_nl_is_backup(msk, &skc_local); } -static int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_get_addr(struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(skb, info); - return mptcp_pm_nl_get_addr(skb, info); + return mptcp_userspace_pm_get_addr(info); + return mptcp_pm_nl_get_addr(info); } int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_get_addr(skb, info); + return mptcp_pm_get_addr(info); } static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 32367fcc728e..92b4dcc310d3 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1762,7 +1762,7 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } -int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) +int mptcp_pm_nl_get_addr(struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet = genl_info_pm_nl(info); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 740a10d669f8..ab92efec6618 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -663,8 +663,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } -int mptcp_userspace_pm_get_addr(struct sk_buff *skb, - struct genl_info *info) +int mptcp_userspace_pm_get_addr(struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct mptcp_pm_addr_entry addr, *entry; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 3bff78efd8ed..dd673b41f0ce 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1131,9 +1131,8 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info); -int mptcp_userspace_pm_get_addr(struct sk_buff *skb, - struct genl_info *info); +int mptcp_pm_nl_get_addr(struct genl_info *info); +int mptcp_userspace_pm_get_addr(struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Fri Dec 13 07:35:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13906632 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 996C3188CC9 for ; Fri, 13 Dec 2024 07:35:45 +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=1734075345; cv=none; b=PtEDG+R5kOTLYbPGpXTiMr0+vianNVPvabo/QVnKiElsy69Uy+bUmRE50EviDWsDhNnkUI+tBldsTJHyy53P0I49kCrJ/L0pTELDiphFiIdUY2vzfhq85AEfgJ5tfUNhf6NaOirh3YROX8ZkaTMYP1doGz4TAv2T/ZOcbA3Aikw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734075345; c=relaxed/simple; bh=C6xslp1ZK2nUVc/EnUSWzXI1hkokbBr4RXj0lOYurrw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tEKSgzdCBXF7tfY2BfZ4NlX1bd421wWhW95Fqo/J2zgIvxBjk1RDCGGBokIoJM7I0P8qsexOO0JD+RWyAoEVgcj6L3ePgbdUnYMghCQXpq2MKayPt3TZAmArVS4faM/RNCYUPxzkSnEJF3ZEJg/jo0Yw1GEIB/OOhBi1q/KK480= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mXJo7vkz; 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="mXJo7vkz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7092C4CED0; Fri, 13 Dec 2024 07:35:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734075345; bh=C6xslp1ZK2nUVc/EnUSWzXI1hkokbBr4RXj0lOYurrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mXJo7vkzwrWcbnkAZ6QzNqPfSraoIQWAoAqIzPxSg+rwRNaZo/oLcskrcwK99HdTq su7Aof6V0indBcsBpR27YhXB+4i2RhQJ9eRZPn6U5ehoAXvfTjLcC3OBP3OkjaQscj 7sIWmZRC4kAxov9ja+0KCqY85O+vCPRLczhBym84g4BsOsXooAn7yzY7hvfKOmhHf2 VL+5ls8jNAOUOT/ilID/4kl4ot8b9g1xjF9/gD0F3A0h9+jDyHLnhCsXiHjMB2kmX1 cBXjpwVJKRUxMuQgj2NEbQJ19XecE3TawSLdkiWxtl5vj5iCPzPHRrkOGZjbUyJZZV hCGQXnO5al2YQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 3/8] mptcp: add id parameter for get_addr Date: Fri, 13 Dec 2024 15:35:24 +0800 Message-ID: <737e168d74af571f6740cbe64b3a7f46ac981f7b.1734074788.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 The address id is parsed both in mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(), this makes the code somewhat repetitive. So this patch adds a new parameter 'id' for all get_addr() interfaces. The address id is only parsed in mptcp_pm_nl_get_addr_doit(), then pass it to both mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(). Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 16 ++++++++++++---- net/mptcp/pm_netlink.c | 11 +++-------- net/mptcp/pm_userspace.c | 11 +++-------- net/mptcp/protocol.h | 4 ++-- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 526e5bca1fa1..c7d323c7c7aa 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -434,16 +434,24 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) return mptcp_pm_nl_is_backup(msk, &skc_local); } -static int mptcp_pm_get_addr(struct genl_info *info) +static int mptcp_pm_get_addr(u8 id, struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(info); - return mptcp_pm_nl_get_addr(info); + return mptcp_userspace_pm_get_addr(id, info); + return mptcp_pm_nl_get_addr(id, info); } int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_get_addr(info); + struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; + struct mptcp_pm_addr_entry addr; + int ret; + + ret = mptcp_pm_parse_entry(attr, info, false, &addr); + if (ret < 0) + return ret; + + return mptcp_pm_get_addr(addr.addr.id, info); } static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 92b4dcc310d3..de6a8e7a4a1a 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1762,19 +1762,14 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } -int mptcp_pm_nl_get_addr(struct genl_info *info) +int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info) { - struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet = genl_info_pm_nl(info); - struct mptcp_pm_addr_entry addr, *entry; + struct mptcp_pm_addr_entry *entry; struct sk_buff *msg; void *reply; int ret; - ret = mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - return ret; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) return -ENOMEM; @@ -1788,7 +1783,7 @@ int mptcp_pm_nl_get_addr(struct genl_info *info) } rcu_read_lock(); - entry = __lookup_addr_by_id(pernet, addr.addr.id); + entry = __lookup_addr_by_id(pernet, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret = -EINVAL; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index ab92efec6618..40a018be243e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -663,10 +663,9 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } -int mptcp_userspace_pm_get_addr(struct genl_info *info) +int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info) { - struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; - struct mptcp_pm_addr_entry addr, *entry; + struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; struct sk_buff *msg; int ret = -EINVAL; @@ -679,10 +678,6 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) sk = (struct sock *)msk; - ret = mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - goto out; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { ret = -ENOMEM; @@ -699,7 +694,7 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) lock_sock(sk); spin_lock_bh(&msk->pm.lock); - entry = mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id); + entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret = -EINVAL; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index dd673b41f0ce..76a0cfe54723 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1131,8 +1131,8 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_pm_nl_get_addr(struct genl_info *info); -int mptcp_userspace_pm_get_addr(struct genl_info *info); +int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info); +int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Fri Dec 13 07:35:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13906633 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 85E91188CC9 for ; Fri, 13 Dec 2024 07:35:47 +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=1734075347; cv=none; b=Ew0xS7e775woI18cwkMW9x5A7KAXtKwdYdBC8eFMXh/9ajwg+4q+cowpE5He4K4Ose1ZTODTbN9yjYsoIZXpw5xwc1wgOYDliD1Y5Qk8vqSq8+e/dEDfpASaR2zQ553LG3LYU/RbsKoHiGWjzNz3SIPlh+in4DP2KSnySMBRThY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734075347; c=relaxed/simple; bh=3W8MExl9zIcqR8Zyz3r8AmqznSKWrI50ntDkiRouaHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QRHGPZzuoYb+sodS/DdFCoa/Xcg1vkpBkPGoDcVzJ9GNyQHx0W9T+b2tZSdClc6EtnnJCFeOZ3A4OY6LzqFjn3v4+3zQzaI1xs1drHc9cmEMpDfwVyjRxxgnoPZUVzyGvEZdGmdwQiGxpzscuME7W1/g7pk6kCN9n68VFGU5pjQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fazg+nA4; 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="fazg+nA4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA08AC4CED0; Fri, 13 Dec 2024 07:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734075347; bh=3W8MExl9zIcqR8Zyz3r8AmqznSKWrI50ntDkiRouaHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fazg+nA4XCZ7MrgfCfNokxOWt673RyK1wskMIkDWNivUKRWMfFpx2q0fbunJqaprb XiA3LKylYDaPvPoJs02DByshMSNPtNiRn1NxLBZLDJ6qag8+pB0AZq6bj7V5450NYb vRG2RfEmhMJKFTSWST0Sx3C3SKOHp7Pqly4B5tFAL1kuI9aMsUusmPIkxHwkTdtmhZ jK8VP4RJ//2sifPL2ESIrYTP5HRzaHO8YvAeGo7++UzQ8Getr83rBet0vnRtb4rYaN oboseBrQLjXOkdL9ivZr4hx3zo4FxJ8ILtCbWLu4cfVzv0+KwFg0dNQaWaTlZYQ5mi wOGJg7ZYMR7qg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 4/8] mptcp: reuse sending nlmsg code in get_addr Date: Fri, 13 Dec 2024 15:35:25 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 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 The netlink messages are sent both in mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(), this makes the code somewhat repetitive. This is because the netlink PM and userspace PM use different locks to protect the address entry that needs to be sent via the netlink message. The former uses rcu read lock, and the latter uses msk->pm.lock. The current get_addr() flow looks like this: lock(); entry = get_entry(); send_nlmsg(entry); unlock(); After holding the lock, get the entry from the list, send the entry, and finally release the lock. This patch changes the process by getting the entry while holding the lock, then making a copy of the entry so that the lock can be released. Finally, the copy of the entry is sent without locking: lock(); entry = get_entry(); *copy = *entry; unlock(); send_nlmsg(copy); This way we can reuse the send_nlmsg() code in get_addr() interfaces between the netlink PM and userspace PM. They only need to implement their own get_addr() interfaces to hold the different locks, get the entry from the different lists, then release the locks. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 39 ++++++++++++++++++++++++++++++++++---- net/mptcp/pm_netlink.c | 39 ++++++-------------------------------- net/mptcp/pm_userspace.c | 41 +++++----------------------------------- net/mptcp/protocol.h | 6 ++++-- 4 files changed, 50 insertions(+), 75 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index c7d323c7c7aa..9f3d82a86746 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -434,24 +434,55 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) return mptcp_pm_nl_is_backup(msk, &skc_local); } -static int mptcp_pm_get_addr(u8 id, struct genl_info *info) +static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(id, info); - return mptcp_pm_nl_get_addr(id, info); + return mptcp_userspace_pm_get_addr(id, addr, info); + return mptcp_pm_nl_get_addr(id, addr, info); } int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct mptcp_pm_addr_entry addr; + struct sk_buff *msg; + void *reply; int ret; ret = mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; - return mptcp_pm_get_addr(addr.addr.id, info); + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, + info->genlhdr->cmd); + if (!reply) { + GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); + ret = -EMSGSIZE; + goto fail; + } + + ret = mptcp_pm_get_addr(addr.addr.id, &addr, info); + if (ret) { + GENL_SET_ERR_MSG(info, "address not found"); + goto fail; + } + + ret = mptcp_nl_fill_addr(msg, &addr); + if (ret) + goto fail; + + genlmsg_end(msg, reply); + ret = genlmsg_reply(msg, info); + return ret; + +fail: + nlmsg_free(msg); + return ret; } static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index de6a8e7a4a1a..dce6a5b5ea4d 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1762,48 +1762,21 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } -int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info) +int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { struct pm_nl_pernet *pernet = genl_info_pm_nl(info); struct mptcp_pm_addr_entry *entry; - struct sk_buff *msg; - void *reply; - int ret; - - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) - return -ENOMEM; - - reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, - info->genlhdr->cmd); - if (!reply) { - GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); - ret = -EMSGSIZE; - goto fail; - } + int ret = -EINVAL; rcu_read_lock(); entry = __lookup_addr_by_id(pernet, id); - if (!entry) { - GENL_SET_ERR_MSG(info, "address not found"); - ret = -EINVAL; - goto unlock_fail; + if (entry) { + *addr = *entry; + ret = 0; } - - ret = mptcp_nl_fill_addr(msg, entry); - if (ret) - goto unlock_fail; - - genlmsg_end(msg, reply); - ret = genlmsg_reply(msg, info); - rcu_read_unlock(); - return ret; - -unlock_fail: rcu_read_unlock(); -fail: - nlmsg_free(msg); return ret; } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 40a018be243e..6dd5a3f1c0c7 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -663,14 +663,13 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } -int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info) +int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - struct sk_buff *msg; int ret = -EINVAL; struct sock *sk; - void *reply; msk = mptcp_userspace_pm_get_sock(info); if (!msk) @@ -678,46 +677,16 @@ int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info) sk = (struct sock *)msk; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) { - ret = -ENOMEM; - goto out; - } - - reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, - info->genlhdr->cmd); - if (!reply) { - GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); - ret = -EMSGSIZE; - goto fail; - } - lock_sock(sk); spin_lock_bh(&msk->pm.lock); entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id); - if (!entry) { - GENL_SET_ERR_MSG(info, "address not found"); - ret = -EINVAL; - goto unlock_fail; + if (entry) { + *addr = *entry; + ret = 0; } - - ret = mptcp_nl_fill_addr(msg, entry); - if (ret) - goto unlock_fail; - - genlmsg_end(msg, reply); - ret = genlmsg_reply(msg, info); spin_unlock_bh(&msk->pm.lock); release_sock(sk); - sock_put(sk); - return ret; -unlock_fail: - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); -fail: - nlmsg_free(msg); -out: sock_put(sk); return ret; } diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 76a0cfe54723..a80a0191e2cd 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1131,8 +1131,10 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info); -int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info); +int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info); +int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Fri Dec 13 07:35:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13906634 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 11448188CC9 for ; Fri, 13 Dec 2024 07:35:49 +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=1734075349; cv=none; b=alg4lEC49AgKt3yCXogJ7tbnspNwkbShIlkRfT+AcM8/aYHP9Apb4Jml1kwqWmDRk6igY+tXmNcuVVyRpuUF4X3WwE53RICEHk6b5p+xENroze5jBNB77Y9AjuV3vArmIu0UQxr3wx1SQBDeWNST40hONKTKKFuWcQditOphNMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734075349; c=relaxed/simple; bh=wuRqZaBq6Gt2EISuKHOha2Lra1rccqIq6gAmpG2gKko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o6Ae19fzgZoAK5PO/aTZa+8WZ4aDhk+z7+R9kxpt/WA8JZeHMk64ec6qw4C2hw3nze/Bxx111xXcxalxvAxiEme2fYnW4JIdlWwQjRUR5pLaFAniBoJx79OC4ATMr9Qv3HxKg2u0PYlWRO8Y2ht/ZWyC/kkjsfZm5LHPdd/tsP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bpfvoT4N; 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="bpfvoT4N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3577C4CED0; Fri, 13 Dec 2024 07:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734075348; bh=wuRqZaBq6Gt2EISuKHOha2Lra1rccqIq6gAmpG2gKko=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bpfvoT4N0YqfLQJjWvxxPb8I+WzBpb2nb4vV1hKdmg3YzXWOtq3fuwl2OAHPNfj7y QWEfO6dz3Lq3FboaKiNja9COPd6XXt5yjqq6jWInJogjo6XGD5GGLG9pDqDsM8JTi9 /xUqWDxta0AehzG8jIZ8tTImiYdFJoUo7z3OSoVYjsGc4xDNCJT6WHTw4HDlGIXNJd eam7zf8e37NZ/mrGzUSMb3Z0MI7dyUZHJbCuCT9t0/XJ96o0xB2V2cERi/JdIypO0h 3BTZ8BPVpuRGz3mv4hI7+ww0CdC7cI+P8Jq4H+JCmCbDWNRlTSuP+Cur7ciEUXKRHU OTXsvJh1bw7Kg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 5/8] mptcp: change info of get_addr as const Date: Fri, 13 Dec 2024 15:35:26 +0800 Message-ID: <42a61bb9dc5ab239e65723b0d5322e5684565ca5.1734074788.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 get_addr() interfaces will be invoked by dump_addr(), which using const parameters 'info', so this patch changes 'info' parameters of get_addr() as const too. Some adaptations are also needed. No longer use genl_info_pm_nl() because it doesn't accept a 'const' variable, but that's OK to get pernet via genl_info_net(). Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 2 +- net/mptcp/pm_netlink.c | 7 +++++-- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 9f3d82a86746..080c842e9e90 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -435,7 +435,7 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) } static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) return mptcp_userspace_pm_get_addr(id, addr, info); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index dce6a5b5ea4d..eb5f48e45187 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1763,12 +1763,15 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, } int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { - struct pm_nl_pernet *pernet = genl_info_pm_nl(info); + struct net *net = genl_info_net(info); struct mptcp_pm_addr_entry *entry; + struct pm_nl_pernet *pernet; int ret = -EINVAL; + pernet = pm_nl_get_pernet(net); + rcu_read_lock(); entry = __lookup_addr_by_id(pernet, id); if (entry) { diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 6dd5a3f1c0c7..7c5914012947 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -664,7 +664,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, } int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index a80a0191e2cd..a9fc30f20376 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1132,9 +1132,9 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info); + const struct genl_info *info); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info); + const struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Fri Dec 13 07:35:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13906635 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 27F39188CC9 for ; Fri, 13 Dec 2024 07:35:50 +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=1734075351; cv=none; b=IUC4gsQW3RiwKz+c4vYhsWQnxKQrnuj7bt2tHX8N+n5rjAAu3DLJY8ebd//WHyQZCWMH7i7ix8TqAN/1/kCDUmkGjRyKXOC8SQl01E2TF7Ew5bJ1hFgYTbk8mP/lO3HgXk8EO57GTeHBojQwQBVQ0nPhBOzHrGF2hCm4IB6dGyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734075351; c=relaxed/simple; bh=aTXVfyjBz7PlvKz/drFfOLhJMic597preliYPpLfbdg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uhfgtuDShuO6ddonea0lO1hy278Lky6+DmJ91kGEyRWkTquTeocvZgNS4GTNzbrmpT507k8HNs/KkfTJOmGS2xaofjArs9e0UVZVX6OE7aH5iFskSLuQYDK4n1I/qYJ2gDQIYri8l2q+pxCTny5pcBN/6ei6DlTYHml6IjZ1C4Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hgc53a7T; 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="hgc53a7T" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D212C4CED1; Fri, 13 Dec 2024 07:35:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734075350; bh=aTXVfyjBz7PlvKz/drFfOLhJMic597preliYPpLfbdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hgc53a7TE9HTZEZ6y18m2/hYvL41tCGAM/Vgru1MaOH5n9XlwvbsFXha9px2Ra2kS wKpz8WYYeQPYuO8xKSiy52uFLYNRvG2dKWVpPeKEaryhtyoyXVXdVSI9vmR+3Es45f Q7Ytx9nBW4neFSLurQ9KxeWdJfICvXVS/+JFVQKIncfdKB3MXlSCEBNZAsdm4E9TiX xR1lu4ZVn1W5aW3knB6zbpRFCVIWsbr634lt/ssBy7FkJvElzhCc/wispGizcNHQL8 prffALnMnnMkvUqSKJTOf+V7iNjrB5lzbLcxd1k5Vr/U8ybqrKeXYSPJgkWzm4Jn9t ke8kUsVmjuVXw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 6/8] mptcp: add info parameter for dump_addr Date: Fri, 13 Dec 2024 15:35:27 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 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 The genl_info information is useful for dump_addr() interface in both in-kernel PM and userspace PM. The former can use it to get pm_nl_pernet, the latter can use it to get msk through mptcp_userspace_pm_get_sock(). So this patch adds an 'info' parameter to dump_addr interface, so that 'info' can be obtained in mptcp_pm_nl_get_addr_dumpit() and then passed to mptcp_pm_nl_dump_addr() or mptcp_userspace_pm_dump_addr(), without having to get it again in these two functions. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 13 +++++++------ net/mptcp/pm_netlink.c | 5 +++-- net/mptcp/pm_userspace.c | 4 ++-- net/mptcp/protocol.h | 6 ++++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 080c842e9e90..0aaf16319c34 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -485,19 +485,20 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) return ret; } -static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) +static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb, + const struct genl_info *info) { - const struct genl_info *info = genl_info_dump(cb); - if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_dump_addr(msg, cb); - return mptcp_pm_nl_dump_addr(msg, cb); + return mptcp_userspace_pm_dump_addr(msg, cb, info); + return mptcp_pm_nl_dump_addr(msg, cb, info); } int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, struct netlink_callback *cb) { - return mptcp_pm_dump_addr(msg, cb); + const struct genl_info *info = genl_info_dump(cb); + + return mptcp_pm_dump_addr(msg, cb, info); } static int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index eb5f48e45187..0d826bfc4718 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1784,9 +1784,10 @@ int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, } int mptcp_pm_nl_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb) + struct netlink_callback *cb, + const struct genl_info *info) { - struct net *net = sock_net(msg->sk); + struct net *net = genl_info_net(info); struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; int id = cb->args[0]; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 7c5914012947..7dc417255e8f 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -615,12 +615,12 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) } int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb) + struct netlink_callback *cb, + const struct genl_info *info) { struct id_bitmap { DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); } *bitmap; - const struct genl_info *info = genl_info_dump(cb); struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret = -EINVAL; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index a9fc30f20376..1f9c66f53865 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1128,9 +1128,11 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); int mptcp_pm_nl_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb); + struct netlink_callback *cb, + const struct genl_info *info); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb); + struct netlink_callback *cb, + const struct genl_info *info); int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, const struct genl_info *info); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, From patchwork Fri Dec 13 07:35:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13906636 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 1CF23188CC9 for ; Fri, 13 Dec 2024 07:35:52 +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=1734075353; cv=none; b=UctagIevkFDaJK/Fy+lIm5l1luRqeXVG8nBtv8QJFuh92ArqDfDp4aj6rFG3Fytl36AFIO6X8qEir7DWVhUaGN4g+Xyt4ODX8eN1wQKZT4n8ppAoHRlkNhjmgjTZwhOSSw6avBYEP3dcHHlWWxvnFo4VQYWoFJJtFPV2SKZL0rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734075353; c=relaxed/simple; bh=dQdvA5+myEe9gkDTm+R/mFfs24TrgIwbsoP6o9nQhjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSF0PBDCPngrqwypnmKHsyDEef1irm+X+omua6b5utWV6A3URzb1v1VpxuPloKCEFP8khhVNjNU1q/BkElQusw3nwJcvSjhRU2mGWlfEPbz2ATVs8qm4knmvaFxWsJtO5jDLWkXN0tyDwZTjncoo6dEu2aarls6Gj5JAaXjJr2M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bdzCVyqF; 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="bdzCVyqF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66946C4CED0; Fri, 13 Dec 2024 07:35:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734075352; bh=dQdvA5+myEe9gkDTm+R/mFfs24TrgIwbsoP6o9nQhjc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bdzCVyqF2DWVTa2NxiOQ62kiz+karVRPgnQWhSRCclFpSp4S/yvKQKpc3BOVgFX50 YEIYgaxwPFEJQ0QAgtx9v13ZLKzPoyh1wgmiqbr50PEMG7d0YwnYW8JzPOfkCla/IV KbSdQdvYKB7u41pFMSU2QuMwY/D8hxGlnD0XpeWPGKG2YOeL4kjYI35cMVD5cH/t77 0wqh9ztVviOq8q4z18cIMKNOe8pNr3vkIt5OCZvKN6zzFxDhDXZZAEOh60Cw/eOIrB R82ZB6ov39/TDWggict2CwNiBuhnbZZ7Ykaiq4r2gpv2rcYAbvNqRaPNphiSvdRirW odPT+fUYT2QZQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 7/8] mptcp: add mptcp_pm_addr_id_bitmap_t type Date: Fri, 13 Dec 2024 15:35:28 +0800 Message-ID: <789602f25f9fc73043f85417b6e147c49d894b66.1734074788.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 defining types such as nodemask_t, dma_cap_mask_t and cpumask_t to simplify the use of bitmap, a new type for MPTCP userspace pm id bitmap, mptcp_pm_addr_id_bitmap_t is defined to easily modify dump_addr() interface of the path managers to accept an mptcp_pm_addr_id_bitmap_t type parameter. It also allows this parameter of dump_addr() can be modified by BPF program when implementing this interface of a BFP path manager. Because a dump_addr() interface that accepts an 'unsigned long *bitmap' or 'unsigned long bitmap[]' parameter is difficult to implement in BPF program. In addition, this also makes it easier for us to implement similar logic to mptcp_userspace_pm_append_new_local_addr() in BPF path manager, because there's no way to use DECLARE_BITMAP macro in BPF program, and it's not easy to reimplement it in BPF. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 7 +++++++ net/mptcp/pm_userspace.c | 14 ++++++-------- net/mptcp/protocol.h | 3 --- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 814b5f2e3ed5..220b1f60e8c1 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -120,6 +120,13 @@ struct mptcp_sched_ops { void (*release)(struct mptcp_sock *msk); } ____cacheline_aligned_in_smp; +/* max value of mptcp_addr_info.id */ +#define MPTCP_PM_MAX_ADDR_ID U8_MAX + +typedef struct { + DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); +} mptcp_pm_addr_id_bitmap_t; + #ifdef CONFIG_MPTCP void mptcp_init(void); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 7dc417255e8f..0d9bea3a04a2 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -47,15 +47,15 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry, bool needs_id) { - DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); struct mptcp_pm_addr_entry *match = NULL; struct sock *sk = (struct sock *)msk; + mptcp_pm_addr_id_bitmap_t id_bitmap; struct mptcp_pm_addr_entry *e; bool addr_match = false; bool id_match = false; int ret = -EINVAL; - bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_zero(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); spin_lock_bh(&msk->pm.lock); mptcp_for_each_userspace_pm_addr(msk, e) { @@ -69,7 +69,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, } else if (addr_match || id_match) { break; } - __set_bit(e->addr.id, id_bitmap); + __set_bit(e->addr.id, id_bitmap.map); } if (!match && !addr_match && !id_match) { @@ -84,7 +84,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, *e = *entry; if (!e->addr.id && needs_id) - e->addr.id = find_next_zero_bit(id_bitmap, + e->addr.id = find_next_zero_bit(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1, 1); list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list); @@ -618,16 +618,14 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb, const struct genl_info *info) { - struct id_bitmap { - DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); - } *bitmap; + mptcp_pm_addr_id_bitmap_t *bitmap; struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; void *hdr; - bitmap = (struct id_bitmap *)cb->ctx; + bitmap = (mptcp_pm_addr_id_bitmap_t *)cb->ctx; msk = mptcp_userspace_pm_get_sock(info); if (!msk) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 1f9c66f53865..da2cf524c5da 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -208,9 +208,6 @@ enum mptcp_addr_signal_status { MPTCP_RM_ADDR_SIGNAL, }; -/* max value of mptcp_addr_info.id */ -#define MPTCP_PM_MAX_ADDR_ID U8_MAX - struct mptcp_pm_data { struct mptcp_addr_info local; struct mptcp_addr_info remote; From patchwork Fri Dec 13 07:35:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13906637 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 C3B73188CC9 for ; Fri, 13 Dec 2024 07:35:54 +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=1734075354; cv=none; b=laJ0FHM1BMVmJ6cyZaoV6h4aFuEbpkqV/V1LSMBDw/D2ey1b+R30WDVEadaqTgebJqrZF7MjKnKVs0ClnHpb80UVbsv4QIJCifqcRogz+k3lO1gb/n5yVAIlHm0Hmz2ArpVpfKRgtHYDvC0CgmcYRkASeq5YO1xx7SP7tcNBUPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734075354; c=relaxed/simple; bh=4qlIe3plnXxnoCAfoAXspEXjYeFyZXnr92u5oCbCKro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=al0EzQzF/xiY9uBA9g5hOGAos7ITAUPosUitBreEYJ4gyhxBZMdxASKj4tgvLFk3WEtiY0zIRjzZvWo1jXsboePWdsrgu/5nYA3xqHIBKz/xLHhtwP/xokuOANBk6Gs2u94+h6lW5CZzT2y440lf44P6T6JM7/qmW+yjlGLEK/Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C3Wtbcvk; 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="C3Wtbcvk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40C66C4CED0; Fri, 13 Dec 2024 07:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734075354; bh=4qlIe3plnXxnoCAfoAXspEXjYeFyZXnr92u5oCbCKro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C3Wtbcvkm7kz6cbcAStTZc5YCtVFZZ6HslcsZ1w2An0YOFGrRd5XhTa/YED+kubD2 G+BRtMvjfmGiSs05SfvrSV+uTDhaXGkVYuhYXtHvBEky6yLLN/VE5SnHfKExYdLcsL efrfpYt4TpUQQsiQTa2nx8w+vXttjBoM02P4H7I1e3rs/vVAmpAqOYP7AF+WE+e1bS oF9oa8isRrhaW9xOyZKrmSoXdC2I/DnG0cguxBzHYB0v8FQ+fdv3E8Jk2XsVPIayS1 aBXQGHPvSGk/xbwULVMYJkNm51UBMCJwkEJdcnfiG/jOtxfbl2BEYSCkok872ODid3 OjOQhDnQOJWrg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 8/8] mptcp: reuse sending nlmsg code in dump_addr Date: Fri, 13 Dec 2024 15:35:29 +0800 Message-ID: <8d1c6172111ac7a9d140e451233b6baa15481e07.1734074788.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 With the help of get_addr(), we can modify dump_addr() interfaces to reuse send_nlmsg code between the netlink PM and userspace PM. The current dump_addr() flow looks like this: lock(); for_each_entry(entry) send_nlmsg(entry); unlock(); After holding the lock, get every entry by walking the address list, send each one looply, and finally release the lock. This set changes the process by copying the address list to an id bitmap while holding the lock, then release the lock immediately. After that, without locking, walking the copied id bitmap to get every copy of entry by using get_addr(), and send each one looply: lock(); for_each_entry(entry) set_bit(bitmap); unlock(); for_each_bit(bitmap) { copy = get_addr(); send_nlmsg(copy); } With this, we can reuse the send_nlmsg() code in dump_addr() interfaces between the netlink PM and userspace PM. They only need to implement their own dump_addr() interfaces to hold the different locks, copy the different address lists to an id bitmap, then release the locks. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 43 ++++++++++++++++++++++++++++++++++++---- net/mptcp/pm_netlink.c | 35 +++----------------------------- net/mptcp/pm_userspace.c | 41 ++++++++++++++------------------------ net/mptcp/protocol.h | 6 ++---- 4 files changed, 59 insertions(+), 66 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 0aaf16319c34..22c0ca77ca0d 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -485,20 +485,55 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) return ret; } -static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb, +static int mptcp_pm_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap, const struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_dump_addr(msg, cb, info); - return mptcp_pm_nl_dump_addr(msg, cb, info); + return mptcp_userspace_pm_dump_addr(bitmap, info); + return mptcp_pm_nl_dump_addr(bitmap, info); } int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, struct netlink_callback *cb) { const struct genl_info *info = genl_info_dump(cb); + mptcp_pm_addr_id_bitmap_t *bitmap; + struct mptcp_pm_addr_entry entry; + int id = cb->args[0]; + void *hdr; + int i; + + bitmap = (mptcp_pm_addr_id_bitmap_t *)cb->ctx; + + mptcp_pm_dump_addr(bitmap, info); + + for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { + if (test_bit(i, bitmap->map)) { + if (mptcp_pm_get_addr(i, &entry, info)) + break; + + if (id && entry.addr.id <= id) + continue; + + hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + &mptcp_genl_family, NLM_F_MULTI, + MPTCP_PM_CMD_GET_ADDR); + if (!hdr) + break; + + if (mptcp_nl_fill_addr(msg, &entry) < 0) { + genlmsg_cancel(msg, hdr); + break; + } + + id = entry.addr.id; + genlmsg_end(msg, hdr); + } + } - return mptcp_pm_dump_addr(msg, cb, info); + cb->args[0] = id; + return msg->len; } static int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 0d826bfc4718..831c440d6cc5 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1783,48 +1783,19 @@ int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, return ret; } -int mptcp_pm_nl_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb, +int mptcp_pm_nl_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap, const struct genl_info *info) { struct net *net = genl_info_net(info); - struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; - int id = cb->args[0]; - void *hdr; - int i; pernet = pm_nl_get_pernet(net); rcu_read_lock(); - for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, pernet->id_bitmap)) { - entry = __lookup_addr_by_id(pernet, i); - if (!entry) - break; - - if (entry->addr.id <= id) - continue; - - hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, - NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); - if (!hdr) - break; - - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } - - id = entry->addr.id; - genlmsg_end(msg, hdr); - } - } + bitmap_copy(bitmap->map, pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); rcu_read_unlock(); - cb->args[0] = id; - return msg->len; + return 0; } static int parse_limit(struct genl_info *info, int id, unsigned int *limit) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 0d9bea3a04a2..0db477b703a5 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -614,18 +614,25 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) return ret; } -int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb, - const struct genl_info *info) +static int mptcp_userspace_pm_reset_bitmap(struct mptcp_sock *msk, + mptcp_pm_addr_id_bitmap_t *bitmap) { - mptcp_pm_addr_id_bitmap_t *bitmap; struct mptcp_pm_addr_entry *entry; + + bitmap_zero(bitmap->map, MPTCP_PM_MAX_ADDR_ID + 1); + + mptcp_for_each_userspace_pm_addr(msk, entry) + __set_bit(entry->addr.id, bitmap->map); + + return 0; +} + +int mptcp_userspace_pm_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap, + const struct genl_info *info) +{ struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; - void *hdr; - - bitmap = (mptcp_pm_addr_id_bitmap_t *)cb->ctx; msk = mptcp_userspace_pm_get_sock(info); if (!msk) @@ -635,27 +642,9 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, lock_sock(sk); spin_lock_bh(&msk->pm.lock); - mptcp_for_each_userspace_pm_addr(msk, entry) { - if (test_bit(entry->addr.id, bitmap->map)) - continue; - - hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, - NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); - if (!hdr) - break; - - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } - - __set_bit(entry->addr.id, bitmap->map); - genlmsg_end(msg, hdr); - } + ret = mptcp_userspace_pm_reset_bitmap(msk, bitmap); spin_unlock_bh(&msk->pm.lock); release_sock(sk); - ret = msg->len; sock_put(sk); return ret; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index da2cf524c5da..ed629320ba56 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1124,11 +1124,9 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_in bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); -int mptcp_pm_nl_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb, +int mptcp_pm_nl_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap, const struct genl_info *info); -int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb, +int mptcp_userspace_pm_dump_addr(mptcp_pm_addr_id_bitmap_t *bitmap, const struct genl_info *info); int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, const struct genl_info *info);