From nobody Sun Dec 22 03:21:11 2024 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 DAD7F4C79 for ; Sat, 7 Dec 2024 01:08:12 +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=1733533692; cv=none; b=Jf1sLAh4iXT65E7RS8zy5Ph8QKwx5mF9/UFN3SX5rWCaDJTEft5xI2yVues4XurbUq+Gav7YKiYy7f1MpMbdQH1F5eqDj2L9faRvHsZBWQz09w8AWfrJtHMHKQdxd5XFEdpbt6ZWDxTE541QrS//1OIxs2r0vuwZIjEbkptafx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733533692; c=relaxed/simple; bh=xi3n30NKy6jcAWd6CK0ffRX8YNgG4baU8O7YcFiv/VE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GUe0q3eSi/VHM2u0wlRZ6RuD+JAs4cWTo9U899FBGi4JHy/3ueFjBYDk7ImClOHvmQbf7GsdHOdWhrsGQnom7hA6oAUSUgwiuKW8rrF28m0F3bgHJATHaIW5zW9ZaNhtkMvD3cDIWW1CMY+lrPo3rY/xzyxVn9ARHLUjEI1RpY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IwGNLp23; 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="IwGNLp23" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2FD8C4CEDF; Sat, 7 Dec 2024 01:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733533692; bh=xi3n30NKy6jcAWd6CK0ffRX8YNgG4baU8O7YcFiv/VE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IwGNLp23o0qHThSIAB1GUgERdKuWCvX03wawEOCojWF/26Rp8/Ao9lxRRo1qbCuXi HBQ1yXr5C8XhenVLQ1V7sE6j+eTTh0s1kjVYtzOnQobO0/lGiRK593seaKHTynAMRi PQWLBAeUHjZl53OswSCMH3gM/qJXHAZNV1m/r5n0KCAM2xTdEGiCRi1mrSH6veTr2j B4Uk0/c3c6NIDRFT2pNvXbj/TAuL5aLqatgoqJVfhEZsNTO83a4lAc7T4VQ+9CT0JE 4ABG2tXUZSE9DolQGvQ5aQf8qxhNn+uFxmzzAMmsBOZ3M77jvRFvaTL//AZPOMWFNG z2DxgrAYeNe4Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 1/7] mptcp: make three pm wrappers static Date: Sat, 7 Dec 2024 09:07:21 +0800 Message-ID: <846e62f86b915ad161e1750729051e1be03da56f.1733533215.git.geliang@kernel.org> 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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" =20 #include "mib.h" +#include "mptcp_pm_gen.h" =20 /* path manager command handlers */ =20 @@ -433,14 +434,19 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struc= t sock_common *skc) return mptcp_pm_nl_is_backup(msk, &skc_local); } =20 -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); } =20 -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 =3D genl_info_dump(cb); =20 @@ -449,13 +455,24 @@ int mptcp_pm_dump_addr(struct sk_buff *msg, struct ne= tlink_callback *cb) return mptcp_pm_nl_dump_addr(msg, cb); } =20 -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); } =20 +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 =3D 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; } =20 -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; } =20 -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 =3D info->attrs[id]; @@ -2035,11 +2024,6 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struc= t genl_info *info) return 0; } =20 -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, gf= p_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 *in= fo); int mptcp_pm_announce_addr(struct mptcp_sock *msk, @@ -1128,12 +1127,10 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_so= ck *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_add= r_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); --=20 2.45.2 From nobody Sun Dec 22 03:21:11 2024 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 E65064C79 for ; Sat, 7 Dec 2024 01:08:13 +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=1733533694; cv=none; b=RKs0pFA1DU8zkGwxSivGCHEdH5FxnOQPtvZXYzetBW/KOdHb/K2o4NqcWH0A4Q81fMBD0Hw6+/Cu7R72nubgTT5R5dqFzFFZ0nWke431teUhoUGuDuDYVutVYNwYN5cTJSIgeeR8ob9LyG2MXaIoEQBhu7Nn8jzg/bZH6YusInQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733533694; c=relaxed/simple; bh=4PR3+3EI82K1GTjuzSmmEENHBxePC37jhoptFJjxEZA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=konlbI/QFjVMNdPCchsjPhIWMIBlf3jO48DisRvLUPajK5uKsiMu+dkJgHm8vsatgs8mOrVjNBi6Frpt4CLGUz1V3LKDM+7hvWV3GpLV6Zj8O11t/xQI7FjApieBxiS37falsEDzVK/N1BewOffZI5InFS/vDuneL88cTv9sXv0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lqrRZluP; 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="lqrRZluP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C730CC4CED2; Sat, 7 Dec 2024 01:08:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733533693; bh=4PR3+3EI82K1GTjuzSmmEENHBxePC37jhoptFJjxEZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lqrRZluPICplK24siYr4G7JB8aS6/iEYBrsllh/yb58/t0ZZCjB8y65g3qGNse1Xq 48r1IFsXr+rEt0eJQ1rryiaXx9XX4D4odYxsfe6T6RwUJvGhhis8EGsSifMF0mrerP 6cdd3D2/UUDbfywYsBQ8K54pU3f/gE6aGpaCl4syV5/bMCOe08Lk2G9MMG3nNOexSz RYjGqDAklbA9fAk1JsXZRrxT/qVY7xBFSesuy9BqIGn0a+PSYK+6QaprZ4haJbS0yE XrEgfqSJl5CYlnmbUXjgcrcD68xhn3eheKiUF907ryE7uLkCT2c2bUzrHJ9M8Hb9dI 4IJWhNL3l/raQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 2/7] mptcp: drop skb parameter of get_addr Date: Sat, 7 Dec 2024 09:07:22 +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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The first parameters "skb" of all three 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, struc= t sock_common *skc) return mptcp_pm_nl_is_backup(msk, &skc_local); } =20 -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); } =20 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); } =20 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; } =20 -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 =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet =3D 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; } =20 -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 =3D 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); =20 static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *= subflow) { --=20 2.45.2 From nobody Sun Dec 22 03:21:11 2024 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 1F73722C6DC for ; Sat, 7 Dec 2024 01:08:14 +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=1733533695; cv=none; b=aFS2kBs/g77F2F5nO+CN0tsCkzqi9zUL1PPbflBpym88K4ucxvRxAHqYhS+dIWcyv+HJ6/JTzzkYemNj/FSiKkiVsqQDrxVGEhFb5UMrZDNZ4JaDtr2qHaAxG38MxjIJQwOMrYEQiJKKsv/dT287t4Eiol3jaJe4jxMrqa6X6RI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733533695; c=relaxed/simple; bh=6wFV6SujP9LXSCo+prbGEDjJKAk8kNqth8UTWHaVhz0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gKoYALc+OQfrm1MfZcXRcwWqdsoL1ua6OE9AeYfrP7jdw5C0gdpqqHeRvyB6Lk/MHoh5GgWObMLJZOtVObUkdhOWV/+UOyeiQDKR0v6s6pNHsyMvnfVFrimdnAyJ2e3yfxWYQ8+5LOIDH09k6GIGg+kzjom4gohM/pRdSbkvfoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q32IsdAC; 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="Q32IsdAC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E89FAC4CED1; Sat, 7 Dec 2024 01:08:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733533694; bh=6wFV6SujP9LXSCo+prbGEDjJKAk8kNqth8UTWHaVhz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q32IsdACzFaSieIvhxK+jebU4TEFQKL0TTmOAypUvKPidzWT4xHSziHVvKXOjR4xI +66ivPHA61jdntbmd5/PfDywnmggrPIy0ATuVwpVfy+2Fl6DqES73Jhg1/DvJLl9ea JCEo9GcD2xeSWtePNwFDCnYr7ARZh2KAV9e+0sUjDEI3DZYDigoiAIa/wJkyOVLWeR 9WxU0UlPB5mpG/YFvYArldQs8ly1D4jXlPbEqR8uvngMNKo8hF+GJt975EdGhFXC7a 1U7pDb7TneRxEq/UYB+phToqVtU7TYFFGL2vtNvQiOAUAMJRVKgNVIYfbVC1CtRYg3 tfA17Xj2S8jgg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 3/7] mptcp: add id parameter for get_addr Date: Sat, 7 Dec 2024 09:07: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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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, struc= t sock_common *skc) return mptcp_pm_nl_is_backup(msk, &skc_local); } =20 -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); } =20 int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_get_addr(info); + struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; + struct mptcp_pm_addr_entry addr; + int ret; + + ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); + if (ret < 0) + return ret; + + return mptcp_pm_get_addr(addr.addr.id, info); } =20 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; } =20 -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 =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet =3D 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; =20 - ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - return ret; - msg =3D 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) } =20 rcu_read_lock(); - entry =3D __lookup_addr_by_id(pernet, addr.addr.id); + entry =3D __lookup_addr_by_id(pernet, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret =3D -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; } =20 -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 =3D 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 =3D -EINVAL; @@ -679,10 +678,6 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) =20 sk =3D (struct sock *)msk; =20 - ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - goto out; - msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { ret =3D -ENOMEM; @@ -699,7 +694,7 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) =20 lock_sock(sk); spin_lock_bh(&msk->pm.lock); - entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id); + entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret =3D -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); =20 static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *= subflow) { --=20 2.45.2 From nobody Sun Dec 22 03:21:11 2024 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 29BC622C6DC for ; Sat, 7 Dec 2024 01:08:15 +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=1733533696; cv=none; b=AdK2kxKvdQw+/5z7z8zsNd4CtVJinzkDnrVd1y2oe1Ykr/4QX3e74OAR0QcAD5YmQMQl5lc9rOmkEHUN7x1Ur2jDBEvfKK2sKP7Gtq5qqf2aEFt20Ffo+jWz8girZtV6KkiAEOOTmjfN1UW1ms560IuV769g/LPgqg8gLHvMB1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733533696; c=relaxed/simple; bh=3W8MExl9zIcqR8Zyz3r8AmqznSKWrI50ntDkiRouaHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DZaRu0qci1w9+75xER/YWO9pFOFar8gjY+7Y6pvtT0HG7R/dTYJCyt93CdnBM50jjrsTctcLWesjfmkxtUk9tpaEsWmKWMRfouO/hwsqyO47iTT3HKVKSDt3aFSEW8YHepgnTc9ByXT4ENVQtfExvhsX8KO422FJQqtB5OO0ueA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pm6XVb/U; 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="pm6XVb/U" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 154C9C4CED2; Sat, 7 Dec 2024 01:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733533695; bh=3W8MExl9zIcqR8Zyz3r8AmqznSKWrI50ntDkiRouaHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pm6XVb/Uq6r9+8u7oGSwS71j+8SUcZWUfxtMR3el0f3wdvkzcwhkO1AVcJymgIzZS 21vn0YE4XdGHd5jboZsh4OEqYUk7CN50qoq5lxvMriq5tCKDZazBpBfbz6XREXHcy5 GYFFvUBMMCQiYMuEsdFFMxCdYx9DNWH/lPTuU/evrghBn9ZkY8OMHheF5Cu+Nwf3kg NocGsFKh+cbU9znGSJqysrq+YG/ZstVm4XjdCapxXuN6Rx1hF3HVbgRjrVzg/JfeMD 6hk0hBtJ0yDRRbjaHq9YhQtj/ghAVs+J+gUq1Ik4otxjTer8d8dzw9Xilf73nSOuGJ /1/tHF7BhtNyQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 4/7] mptcp: reuse sending nlmsg code in get_addr Date: Sat, 7 Dec 2024 09:07:24 +0800 Message-ID: <0c8358438b3ff44b76f95972f437a3b4a63c1190.1733533215.git.geliang@kernel.org> 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D 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 =3D get_entry(); *copy =3D *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, struc= t sock_common *skc) return mptcp_pm_nl_is_backup(msk, &skc_local); } =20 -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); } =20 int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct mptcp_pm_addr_entry addr; + struct sk_buff *msg; + void *reply; int ret; =20 ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; =20 - return mptcp_pm_get_addr(addr.addr.id, info); + msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + reply =3D 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 =3D -EMSGSIZE; + goto fail; + } + + ret =3D mptcp_pm_get_addr(addr.addr.id, &addr, info); + if (ret) { + GENL_SET_ERR_MSG(info, "address not found"); + goto fail; + } + + ret =3D mptcp_nl_fill_addr(msg, &addr); + if (ret) + goto fail; + + genlmsg_end(msg, reply); + ret =3D genlmsg_reply(msg, info); + return ret; + +fail: + nlmsg_free(msg); + return ret; } =20 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; } =20 -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 =3D genl_info_pm_nl(info); struct mptcp_pm_addr_entry *entry; - struct sk_buff *msg; - void *reply; - int ret; - - msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) - return -ENOMEM; - - reply =3D 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 =3D -EMSGSIZE; - goto fail; - } + int ret =3D -EINVAL; =20 rcu_read_lock(); entry =3D __lookup_addr_by_id(pernet, id); - if (!entry) { - GENL_SET_ERR_MSG(info, "address not found"); - ret =3D -EINVAL; - goto unlock_fail; + if (entry) { + *addr =3D *entry; + ret =3D 0; } - - ret =3D mptcp_nl_fill_addr(msg, entry); - if (ret) - goto unlock_fail; - - genlmsg_end(msg, reply); - ret =3D genlmsg_reply(msg, info); - rcu_read_unlock(); - return ret; - -unlock_fail: rcu_read_unlock(); =20 -fail: - nlmsg_free(msg); return ret; } =20 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; } =20 -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 =3D -EINVAL; struct sock *sk; - void *reply; =20 msk =3D mptcp_userspace_pm_get_sock(info); if (!msk) @@ -678,46 +677,16 @@ int mptcp_userspace_pm_get_addr(u8 id, struct genl_in= fo *info) =20 sk =3D (struct sock *)msk; =20 - msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) { - ret =3D -ENOMEM; - goto out; - } - - reply =3D 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 =3D -EMSGSIZE; - goto fail; - } - lock_sock(sk); spin_lock_bh(&msk->pm.lock); entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id); - if (!entry) { - GENL_SET_ERR_MSG(info, "address not found"); - ret =3D -EINVAL; - goto unlock_fail; + if (entry) { + *addr =3D *entry; + ret =3D 0; } - - ret =3D mptcp_nl_fill_addr(msg, entry); - if (ret) - goto unlock_fail; - - genlmsg_end(msg, reply); - ret =3D genlmsg_reply(msg, info); spin_unlock_bh(&msk->pm.lock); release_sock(sk); - sock_put(sk); - return ret; =20 -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); =20 static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *= subflow) { --=20 2.45.2 From nobody Sun Dec 22 03:21:11 2024 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 4451722C6DC for ; Sat, 7 Dec 2024 01:08:17 +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=1733533697; cv=none; b=Uk4MSPDteP8vEFRWojJ9BHrsZjurPkJD/DpwVJpE3DDDZhf0/HHf8DFopSk+wBzzmIH6lb+Ka/DcdSoIDB+2jIn0D3HCGGc0hqYuvglr1nGWklDPL2ykoT1htGqCDdBI34hJD5VE5OB1cYPAQ8hsA+8ylkV070rb88UU83aouxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733533697; c=relaxed/simple; bh=WkWJXcTwp5kr+PZqhVhA2BxQTLn2ts8KOXrstxbG+kE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fqyNy0RImKsnbbodoVcgGIJ/0fGmc5Db/k2VBtwcYrBjDRSk/dzLdqXL6HpgCYe/h7gdInHTu4UceOEBrtTkieZeWMO06NfrO5uQCWDN+cgBEjucbmaDp03vSeT+/AEbBxgzccrXZE9za0kBUK3mMatokxExwydTxIBChh2bBkA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kUiqNXts; 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="kUiqNXts" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3431DC4CED1; Sat, 7 Dec 2024 01:08:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733533696; bh=WkWJXcTwp5kr+PZqhVhA2BxQTLn2ts8KOXrstxbG+kE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kUiqNXtsT0b5v3j2cHkfLmETxOBez8EE/V5+cwQDnPaj1xNuiw37b441cFFmJOkfU nJuPKTZedkGBshzXbHdJr1z1vp1HiRdQgsGfZO2c5lPMbEvFkggE8/lTnfaSc4UZKZ MK34kvkt13foEBmgGQ77r7qYO9z7/6P0u8NgQaZhXZSg/YPHnE+s7MEMPKAJ8CHp7b QtbuycR5KiltD7MgwQ/BZ7qnsjPrLrqEmMcL3mKXAQCgfJXENfNE6ch6xVOBJjqMpC DcZb41ytAUiy2/3iFN5qUhC6XcXOxs8rBoN1ebt4nN86A7EOlY2A+0VbY6RVcUg+Vh UEyeGQoFtGqLg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 5/7] mptcp: change info of get_addr as const Date: Sat, 7 Dec 2024 09:07:25 +0800 Message-ID: <49e8fea42b8e1acad5cf5f8db6d16b16eea647d0.1733533215.git.geliang@kernel.org> 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) } =20 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, } =20 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 =3D genl_info_pm_nl(info); + struct net *net =3D genl_info_net(info); struct mptcp_pm_addr_entry *entry; + struct pm_nl_pernet *pernet; int ret =3D -EINVAL; =20 + pernet =3D pm_nl_get_pernet(net); + rcu_read_lock(); entry =3D __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, } =20 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); =20 static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *= subflow) { --=20 2.45.2 From nobody Sun Dec 22 03:21:11 2024 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 2ED1822C6DC for ; Sat, 7 Dec 2024 01:08:18 +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=1733533698; cv=none; b=GBjI8OAH1d+fo5HDXm8rJpmF8GssAF7TH+pJR6VYkB3tJxesnM2BDX5wIWqa6ja3vnvTl4rzTsQy21GUKV7XWS+NV+IFrpwht04tfnost7JDplu2nNbYjOuBjuo5Xh14ir8BDldRtqo95mW4Q2k2KrGsOLR/9kfwgiCodXUDYrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733533698; c=relaxed/simple; bh=CuIEFEZApZ9JnwuCGToFSs/8+n5+3Z1R5r06rOc2Lok=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lEhWI4YnAodOXPMiVCjvI6FTtCI9Z/WW1JMvzMyZydwSxyt0+pOGPU6D8B8kOGAWlaQaWYVyAjzwT+Dn9o8tJncbUb4FZMCpGWWTlOBZAjGS+XPz8ZiN7qU9ofDzbJ5UZF/OjFnxBGIx3mJybA1nxr3HfF/xtPk9+pKj+Fqaw6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WCTRlEqH; 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="WCTRlEqH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55C97C4CED2; Sat, 7 Dec 2024 01:08:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733533698; bh=CuIEFEZApZ9JnwuCGToFSs/8+n5+3Z1R5r06rOc2Lok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WCTRlEqHuXznQ/EB052t+UagqbaSYtMCbeu/NE75CxltNy2uY1Yy9NLZltwlBbOoO QMF4rpMPH+Nwzao3/OEbNzXQHgZ4XWBkBb9Bghefo8JSnhb/k9jWm7SS2jEJWletd+ nU2KU2O3S1DAZDbwo6sKKKyWmrD/j+awhCiNu5dUW6TF7BSHyec0JpCua2fEAXGwXq 263FkZLQi5G3LYgIbzElHa1oD6rmDagxL8oVCko8ckr2azB6RFaqzD52oLQQ7prV/z 4khvntGgfjRP5wRkh3xv7Pg4XPrk1wD2ZnMlp4N9z3eWmYLUNZ4gQxk9QlvU2v+Id1 /+MWvUuI4ywtA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 6/7] mptcp: add info parameter for dump_addr Date: Sat, 7 Dec 2024 09:07:26 +0800 Message-ID: <0eab2e0554e9a00403109e2deec8989235490dee.1733533215.git.geliang@kernel.org> 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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, st= ruct genl_info *info) return ret; } =20 -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 =3D 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); } =20 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 =3D genl_info_dump(cb); + + return mptcp_pm_dump_addr(msg, cb, info); } =20 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, } =20 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 =3D sock_net(msg->sk); + struct net *net =3D genl_info_net(info); struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; int id =3D 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) } =20 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 =3D genl_info_dump(cb); struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret =3D -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, stru= ct 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_add= r_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, --=20 2.45.2 From nobody Sun Dec 22 03:21:11 2024 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 4C00B22C6DC for ; Sat, 7 Dec 2024 01:08: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=1733533699; cv=none; b=jFZ1t5W7RdMNdlRpgotIywaEMtefveBj/hUtgN0eFxRl1aAb57EroPuT33fRvQz9E9E+MqrrNuFx3UJ95GJztKh6D2ei7db8eyGug2jcHANcTUY2M9yAiuLoFcLoZrJ6w0385/NyxjJCaJ8CAJitYg2c+V1zf+nRmLIDrO3c/5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733533699; c=relaxed/simple; bh=gwt2KH+LvrEn821v0dBq/BqW3QDkNIQLjCr/zqpXe0A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OR5khSpIJ2GpVoHIgSfbKaJltMFHBU8lOPWxmcfhgF9ErgC/L8CnixYlny+UxYheIXX0uExqNP+UXOX5GF8pWtTdOcwSSE0TyJ0gHlOVyR9B7+cRfDh1QiilywUdaLXWT3XM7oMbz4JqkmCE0csga/TPIbWCPbFpFkMhbcHoF3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FNiWZK7G; 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="FNiWZK7G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 776DCC4CEDF; Sat, 7 Dec 2024 01:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733533699; bh=gwt2KH+LvrEn821v0dBq/BqW3QDkNIQLjCr/zqpXe0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FNiWZK7G9iq3IREkFdRpVr32S2GEpBDQOzcmpMcDrFs3HNOIWaI9pek4iSHcc52gv 8vYClpoE8mZ5SmTv8h1z5u0CGpzzOl7ir8bo/wKh+Hoa7/G12ZaCdjQ/R52WwgY+Lt 3zo+vIzoDPMqhwf26aIV1oO1+tBSs2ZcuqLxWYQCPg/OB9/xFElP1ysUaMNZ999xTe 261x6gLv6cWUOL+luwbNw87FVzi0PI6jNWrKMIxWnDzV3u8fg0RWlYwREgqHFlOopN wkiQsU7Jlz9GnX4Im9iRALH0VBVtO1Wr/ewxkPyS+rKlxuRqgSzxDda+1t2KWJ/ri/ BNwQ0Op153a+g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 7/7] mptcp: reuse sending nlmsg code in dump_addr Date: Sat, 7 Dec 2024 09:07:27 +0800 Message-ID: <7b12fbbff77bbdbddbb06bb5207df219e105668f.1733533215.git.geliang@kernel.org> 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang A new type mptcp_pm_addr_id_bitmap_t is defined to easily modify dump_addr() interface of the path managers to accept an id_bitmap 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. 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 =3D 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 --- include/net/mptcp.h | 7 +++++++ net/mptcp/pm.c | 42 +++++++++++++++++++++++++++++++++++---- net/mptcp/pm_netlink.c | 35 +++----------------------------- net/mptcp/pm_userspace.c | 43 ++++++++++++++-------------------------- net/mptcp/protocol.h | 9 ++------- 5 files changed, 65 insertions(+), 71 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; =20 +/* 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); =20 diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 0aaf16319c34..b862a8e4c706 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -485,20 +485,54 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) return ret; } =20 -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); } =20 int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, struct netlink_callback *cb) { const struct genl_info *info =3D genl_info_dump(cb); + mptcp_pm_addr_id_bitmap_t *bitmap; + struct mptcp_pm_addr_entry entry; + int id =3D cb->args[0]; + void *hdr; + int i; =20 - return mptcp_pm_dump_addr(msg, cb, info); + bitmap =3D (mptcp_pm_addr_id_bitmap_t *)cb->ctx; + + mptcp_pm_dump_addr(bitmap, info); + + for (i =3D 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 <=3D id) + continue; + + hdr =3D 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 =3D entry.addr.id; + genlmsg_end(msg, hdr); + } + } + + cb->args[0] =3D id; + return msg->len; } =20 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_add= r_entry *addr, return ret; } =20 -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 =3D genl_info_net(info); - struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; - int id =3D cb->args[0]; - void *hdr; - int i; =20 pernet =3D pm_nl_get_pernet(net); =20 rcu_read_lock(); - for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, pernet->id_bitmap)) { - entry =3D __lookup_addr_by_id(pernet, i); - if (!entry) - break; - - if (entry->addr.id <=3D id) - continue; - - hdr =3D 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 =3D entry->addr.id; - genlmsg_end(msg, hdr); - } - } + bitmap_copy(bitmap->map, pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); rcu_read_unlock(); =20 - cb->args[0] =3D id; - return msg->len; + return 0; } =20 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 7dc417255e8f..dd6a1f62c268 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -614,20 +614,25 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb,= struct genl_info *info) return ret; } =20 -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) { - struct id_bitmap { - DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); - } *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 =3D -EINVAL; struct sock *sk; - void *hdr; - - bitmap =3D (struct id_bitmap *)cb->ctx; =20 msk =3D mptcp_userspace_pm_get_sock(info); if (!msk) @@ -637,27 +642,9 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, =20 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 =3D 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 =3D mptcp_userspace_pm_reset_bitmap(msk, bitmap); spin_unlock_bh(&msk->pm.lock); release_sock(sk); - ret =3D msg->len; =20 sock_put(sk); return ret; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 1f9c66f53865..ed629320ba56 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -208,9 +208,6 @@ enum mptcp_addr_signal_status { MPTCP_RM_ADDR_SIGNAL, }; =20 -/* 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; @@ -1127,11 +1124,9 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_soc= k *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_add= r_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); --=20 2.45.2