From nobody Wed Jan 22 04:57:35 2025 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 949051946B8 for ; Thu, 16 Jan 2025 07:27:08 +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=1737012428; cv=none; b=e7RoQeZ4MhmRIQcjC/ZqgsHmLtMbDDjqMD+S7yOl0eURc1OqxS0xxZEV5VeEgSsNhApJrzchnVZQi4vFu8Y6gYYnUX8dJsgbwHTxCU61Sc6+FqKzksRLiuLZxRfe+TouwVxhipUpSi6N0VIJuAPbMGIuKCCMkFLQ956xNmYxn/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737012428; c=relaxed/simple; bh=mReufQBMfhEAFgVxSJjYHyXTepa6JXN6QhJtShKUhQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TNm1i9e3sKhI33Qbb59VzYeqVWZ6jGsxTh3c90tCXcGDpL907t7oD5wZV2FXbrlQ64L8MJ01sD5b8HTRuzTI4ZrYYJZtqzv86XSdbUuAElxJxZVf4rOFjYGsbaxpgl4SZFqmQ4toC7PEUe5RwhOzatLmjj6m5fsttNC9fsMkPD4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S7XqfAn5; 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="S7XqfAn5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AD20C4CEE6; Thu, 16 Jan 2025 07:27:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737012428; bh=mReufQBMfhEAFgVxSJjYHyXTepa6JXN6QhJtShKUhQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S7XqfAn5jzW/64RUAc2kKE5hXT00O2cr6YH/ItcY5aag6BcQldLheAau6fjGQv7zv e1AZz07lwLlfTtf/307ly1wUS5zvOY7kGWLcq/UpnYll6eSre4TkL75OUJ/5cJHWQY /bXKrBgbd554SjiyIXJGIaCHO5Z24yVWybCsiRua6AjFdMqE9bXpvsNA9ayZjKaW4e tWZ5mcidqjVMYxZKJQI+FN0TB0gz/iyL7PbaX6HjGdKjAQAAbwtCAfevpZ6T6NK/XW wvBMBUojiXvtkj4dllABcb/iWAmviEzI0ql5mtCQu4C8BH6ekyu0doAByomQilx6i8 cNzr+ixvz/Tzw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 1/7] mptcp: add mptcp_pm_genl_fill_addr helper Date: Thu, 16 Jan 2025 15:26:53 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang To save some redundant code in dump_addr() interfaces of both the netlink PM and userspace PM, the code that calls netlink message helpers (genlmsg_put/cancel/end) and mptcp_nl_fill_addr() is wrapped into a new helper mptcp_pm_genl_fill_addr(). This helper will also be used in BPF path managers. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 21 +++++++++++++++++++++ net/mptcp/pm_netlink.c | 12 +----------- net/mptcp/pm_userspace.c | 12 +----------- net/mptcp/protocol.h | 3 +++ 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index b1f36dc1a091..16cacce6c10f 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -489,6 +489,27 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, str= uct genl_info *info) return ret; } =20 +int mptcp_pm_genl_fill_addr(struct sk_buff *msg, + struct netlink_callback *cb, + struct mptcp_pm_addr_entry *entry) +{ + void *hdr; + + 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) + return -EINVAL; + + if (mptcp_nl_fill_addr(msg, entry) < 0) { + genlmsg_cancel(msg, hdr); + return -EINVAL; + } + + genlmsg_end(msg, hdr); + return 0; +} + static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback= *cb) { const struct genl_info *info =3D genl_info_dump(cb); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index fef01692eaed..afd517ff260c 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1798,7 +1798,6 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, 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); @@ -1813,19 +1812,10 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, if (entry->addr.id <=3D id) continue; =20 - 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) + if (mptcp_pm_genl_fill_addr(msg, cb, entry)) break; =20 - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } - id =3D entry->addr.id; - genlmsg_end(msg, hdr); } } rcu_read_unlock(); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 277cf092a870..b50462b527bd 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -641,7 +641,6 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct mptcp_sock *msk; int ret =3D -EINVAL; struct sock *sk; - void *hdr; =20 bitmap =3D (struct id_bitmap *)cb->ctx; =20 @@ -657,19 +656,10 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, if (test_bit(entry->addr.id, bitmap->map)) continue; =20 - 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) + if (mptcp_pm_genl_fill_addr(msg, cb, entry)) break; =20 - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } - __set_bit(entry->addr.id, bitmap->map); - genlmsg_end(msg, hdr); } spin_unlock_bh(&msk->pm.lock); release_sock(sk); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 6fb536de9981..20941405a1ea 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1060,6 +1060,9 @@ void mptcp_fastopen_subflow_synack_set_params(struct = mptcp_subflow_context *subf struct request_sock *req); int mptcp_nl_fill_addr(struct sk_buff *skb, struct mptcp_pm_addr_entry *entry); +int mptcp_pm_genl_fill_addr(struct sk_buff *msg, + struct netlink_callback *cb, + struct mptcp_pm_addr_entry *entry); =20 static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk) { --=20 2.43.0