From patchwork Tue Mar 5 11:04:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13582113 X-Patchwork-Delegate: kuba@kernel.org 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 3A7A15A4C9; Tue, 5 Mar 2024 11:04:42 +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=1709636683; cv=none; b=CL/ID/ap38oE0fY06cyKsVjGHw9FbCDzKb9KoK6tldMNfsRF+HsLE1X6TaGBEHXnGq3lBap/sIAiBQ1SLYOQ75KO4jYf+JsiQcqLRhv9Ppd9HsqPy8m465WWdpK3bW6gAyH9FSk8mHxfID6XOXYgCw722ZGIoXjvkOZfIKrfV5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709636683; c=relaxed/simple; bh=P/wdeWQa0W3b+O5lwhLDozduBxcngBMm9JDLN+WGduM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QP10qN028kFF0BMPObdi1TH2frWpi+vTZL9DaRG9pBayLRk07d2+YlwGDSgP23CBEUD2ZsWNoNH7EIQaPafH5gfH3dCPQVT+Zw5ASxJtbI3ATcFKOT9xiqxInjlaKR1lNRobptHSa5keWW4lxzgFft0KJ7Bak8KEGPdkWBj4524= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BR1S5fEo; 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="BR1S5fEo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1472C43390; Tue, 5 Mar 2024 11:04:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709636682; bh=P/wdeWQa0W3b+O5lwhLDozduBxcngBMm9JDLN+WGduM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BR1S5fEoZsz1bBQVWzTSK40M6v9eBP8CCcp3i9PiFSCaj2eRenKYjm6jKD79jD8/B 8ogvVNpRfOjRThuQaBEs5Fx8c+VIaHtAkQ6hKRgSZLq/1U7nf7m68V6mFbtvSKE4ZD o78J9v/9cfaKrtXeJKgErl9KcsvKkPBh1smOqvzlJqnBE5J39+tm8k/ktdHdLdCv+7 MunHPZg9PEf2TQW7NDLaXXKx3F+nFboglM/UXI4KuUMtZ8PV8XfRDN+GF9A6u9xmri Uq93U5huzkcXq0ArzotDiZE50xMEJ0xWAU9MjNkmnKPA15uN4+EWC3NeySXclgR8QT 7U/cZhUlhOEyA== From: "Matthieu Baerts (NGI0)" Date: Tue, 05 Mar 2024 12:04:30 +0100 Subject: [PATCH net-next 1/4] mptcp: drop duplicate header inclusions Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-1-c436ba5e569b@kernel.org> References: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-0-c436ba5e569b@kernel.org> In-Reply-To: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-0-c436ba5e569b@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Geliang Tang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2998; i=matttbe@kernel.org; h=from:subject:message-id; bh=HA1tmoL01hr3DXbYFWkVkYbZaNlDbfZMyOwEbhewj4w=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBl5vxDNFiGxhHposnm2lR7WNXn7U29kq+wYr8W4 jfOtiwnAbGJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZeb8QwAKCRD2t4JPQmmg cxxsEADgdU6yF3Gm4w0rwIhzT8Hl02+fcezmjXOsGdfghYbErWVGDH51LAMrxTd2a7mdVs985lb P6YC6pgmb23vA6XsyYk91C+W8mQlEyXx2EyROQbhHZ9deNf39p4+gJ9jq9hLPGYlFx2BK4Y397q O0b+DZHvJ2Iao74Y/ujEyEpkfaSK3vs+6rloQ6cHd9EBiGRGPvc85loW7uXxVIn2BlEKNUdc57D 55NpfHHV+dRzoQGdWwLPBl0AzTSX2KNHNj23mplqd9aogFxiT6HOYbtS4rt5ECIe8zDXl+Jj1Cx +CwxPDNN3GdUU3+Lq4NsBQmSfD8NMeivRjOVZbav0VSyyOL+E1ErVDEvNc+g2ES/AaFJ+RjIykw aMqcEWv34dj9AuZJmpvNmd2BvO+ohBpH1jr0UDbcXHybSg03B5mTblqcuzPr/YlUEUpYHICt+AF mhHTMcjB3ngXhDpc5ZQF2BWMkJBUNFn7w6LjA7wN48jhr28ie3GFr13gRMDT6697LBL8zLW5QRV HEjKErT59vvWrt4fceTneKZJd2CNlCF727x5Ru7Oimmg+QKv8kMXpbkRTHDG+zDrL2qFLcP3RzV hRl68CSlVVFKyPPZmQ2OI7hGb+/FuFGPBos/+xquM4Xna3SoBMnqxCApULAuYkYi5F1+t6eirjg +49jMaa0kXTVaNQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Patchwork-Delegate: kuba@kernel.org From: Geliang Tang The headers net/tcp.h, net/genetlink.h and uapi/linux/mptcp.h are included in protocol.h already, no need to include them again directly. This patch removes these duplicate header inclusions. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/diag.c | 1 - net/mptcp/mptcp_diag.c | 1 - net/mptcp/pm.c | 1 - net/mptcp/pm_netlink.c | 3 --- net/mptcp/protocol.c | 1 - net/mptcp/subflow.c | 2 -- 6 files changed, 9 deletions(-) diff --git a/net/mptcp/diag.c b/net/mptcp/diag.c index 7017dd60659d..3ae46b545d2c 100644 --- a/net/mptcp/diag.c +++ b/net/mptcp/diag.c @@ -10,7 +10,6 @@ #include #include #include -#include #include "protocol.h" static int subflow_get_info(struct sock *sk, struct sk_buff *skb) diff --git a/net/mptcp/mptcp_diag.c b/net/mptcp/mptcp_diag.c index bd8ff5950c8d..0566dd793810 100644 --- a/net/mptcp/mptcp_diag.c +++ b/net/mptcp/mptcp_diag.c @@ -10,7 +10,6 @@ #include #include #include -#include #include "protocol.h" static int sk_diag_dump(struct sock *sk, struct sk_buff *skb, diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index b4bdd92a5648..28e5d514bf20 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -6,7 +6,6 @@ #define pr_fmt(fmt) "MPTCP: " fmt #include -#include #include #include "protocol.h" diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 16f8bd47f4b8..a900df9f173d 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -8,12 +8,9 @@ #include #include -#include #include #include #include -#include -#include #include "protocol.h" #include "mib.h" diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 99367c40de0d..3a1967bc7bad 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #if IS_ENABLED(CONFIG_MPTCP_IPV6) #include diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 6403c56f2902..1626dd20c68f 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -15,13 +15,11 @@ #include #include #include -#include #if IS_ENABLED(CONFIG_MPTCP_IPV6) #include #include #endif #include -#include #include "protocol.h" #include "mib.h" From patchwork Tue Mar 5 11:04:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13582114 X-Patchwork-Delegate: kuba@kernel.org 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 16FE15A7BF; Tue, 5 Mar 2024 11:04:46 +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=1709636687; cv=none; b=KoAyjNgP7oPn713yimMBe0Wugdo4+Lb9Os2URmgd9kMuICXKRX9mlufBOQEAhV3cWmjyCWb7or+1sG3hBciQJy02j8Ae0vNt6KR9Ghj6LzQMnKMmB1I3oCPGhx0SRRo7dv/Kvjs+1SvPDUJfOxz6n1/GJjSGD/1lcKZj2iW40qg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709636687; c=relaxed/simple; bh=bgIk6inGq4FyMlpZMs4Z8bMwM0OVrGjbDRx+RQWEfuM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RVCtmmNgUZKTh5NCZPxHw7hw/VyPx3a3qTMHQZF8wU7x4Vx3/3TDUa5E4itAn/ocsfwANN03IIwKMGoOuRiX5wcsc3YfYFUB3STcJYXqJUGIYouIpMHwH9YS1vf/M06J5sQ2WPqsdMj1Ts4UTD6NMjznLXVFpGMFCnltD0W+NcU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=flNMWQrv; 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="flNMWQrv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FAADC433C7; Tue, 5 Mar 2024 11:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709636686; bh=bgIk6inGq4FyMlpZMs4Z8bMwM0OVrGjbDRx+RQWEfuM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=flNMWQrvl9jaNNEJg+U/xijyeTQ1ReqamdY5cDvr4zPpTKNH/NCcxDLs5CfMH/VK9 Af/ipwSSRICt3xbwYX2VF6HodOyP1w6cjW3qcf23k7xyMWqum2JOobv/xMV4XNgje7 1n6wpVojYwUFwPtmNX7OZAp9vlrUruEt2f8kfY3FszBu/5EVO5GskwJMhltt8DgfEd wM4UpRF2fD4hXEqacNgOp5oiJmcQwWHsnmn4305NnURooGOAhDnrVPSQx7I3+yVwvJ WldKb5+aEcj+tzH31GGLc/DXnW0Pt/hxI0czzt3kGL4oXl4TVEW8T69QyaXhH2f15b TQXdhFf9u5R7g== From: "Matthieu Baerts (NGI0)" Date: Tue, 05 Mar 2024 12:04:31 +0100 Subject: [PATCH net-next 2/4] mptcp: update set_flags interfaces Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-2-c436ba5e569b@kernel.org> References: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-0-c436ba5e569b@kernel.org> In-Reply-To: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-0-c436ba5e569b@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Geliang Tang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=8079; i=matttbe@kernel.org; h=from:subject:message-id; bh=zcfL+hVSRVcd3We9+/Z0qTngvpzqVTGLYq75WGmtTDk=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBl5vxD9RxHH517NGulcJm4QVv2TFVc5OipQULtS zM2Oo0FPlCJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZeb8QwAKCRD2t4JPQmmg c45zEADKvbkg3/8LhNjs1638j70/Sym6rXj0RlLaH/hbGVRajsRsuO2jGIuUSofg0vlzpL2X/Ql 2GCqohRYkMZJgq70vgRvv+nn37vcEh2X7k1dCXRPrT0NLvDs2iJXepVAnIZJfSOH7WaPbm6MmNf LKjJJ8ovqLs6GR5MKdpct7cRZiz2Jyh36F2v2fNY1Oy7C17V3P1xhkg/bQWp+nRjrvLeE6BJPHA 4YKL57qVhDw0WIadWzyVuHZrmwem1sUkmfV0c0VL+brG7+LaTZ3WCEm3BNJxC9EeCG7D7Y4VfZ/ q9+0HGzmTXVWnRnGu/JEoPW4LRcAmIw7bwXsAq0hBRPp7440vrVqcMarnRiQwW0xiiJ4mF4F9UR Uh1FFagYzb8jnbTPb+3/riZJCnl/nChp3MYhRu0uyIDR+rkkOBztK5TOj1PStHCHTkGEBUT4u1R toUGdPo+fM2EyqMUIdW7r/PtG7HO2H5AVZlPhImsjOkf++aT+nI2H5oticSBZo9hABlHSt0uQgv TYi/0Tak92/cm266MYr/YYFfp2M866oPAqi7O6ODdQFIWRfI4iuQwt+ya7NC9Y+56ZHtgdPK6Hg k3cbv5NlG2LWtlsPP9pmM643bLxId54/+AGcOgfZ7b4y95v9eZv60XMbsjRzqvzw+mDpKdtcOm5 MnN92LlRaWj2VyQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Patchwork-Delegate: kuba@kernel.org From: Geliang Tang This patch updates set_flags interfaces, make it more similar to the interfaces of dump_addr and get_addr: mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm.c | 10 +++--- net/mptcp/pm_netlink.c | 80 ++++++++++++++++++++++-------------------------- net/mptcp/pm_userspace.c | 32 +++++++++++++++---- net/mptcp/protocol.h | 10 ++---- 4 files changed, 69 insertions(+), 63 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 28e5d514bf20..55406720c607 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -456,13 +456,11 @@ 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 net *net, struct nlattr *token, - struct mptcp_pm_addr_entry *loc, - struct mptcp_pm_addr_entry *rem, u8 bkup) +int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) { - if (token) - return mptcp_userspace_pm_set_flags(net, token, loc, rem, bkup); - return mptcp_pm_nl_set_flags(net, loc, bkup); + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) + return mptcp_userspace_pm_set_flags(skb, info); + return mptcp_pm_nl_set_flags(skb, info); } void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index a900df9f173d..c799fe84dfd3 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1887,66 +1887,58 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } -int mptcp_pm_nl_set_flags(struct net *net, struct mptcp_pm_addr_entry *addr, u8 bkup) +int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) { - struct pm_nl_pernet *pernet = pm_nl_get_pernet(net); + struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }; + struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP | MPTCP_PM_ADDR_FLAG_FULLMESH; - struct mptcp_pm_addr_entry *entry; - u8 lookup_by_id = 0; - - if (addr->addr.family == AF_UNSPEC) { - lookup_by_id = 1; - if (!addr->addr.id) - return -EOPNOTSUPP; - } - - spin_lock_bh(&pernet->lock); - entry = __lookup_addr(pernet, &addr->addr, lookup_by_id); - if (!entry) { - spin_unlock_bh(&pernet->lock); - return -EINVAL; - } - if ((addr->flags & MPTCP_PM_ADDR_FLAG_FULLMESH) && - (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { - spin_unlock_bh(&pernet->lock); - return -EINVAL; - } - - changed = (addr->flags ^ entry->flags) & mask; - entry->flags = (entry->flags & ~mask) | (addr->flags & mask); - *addr = *entry; - spin_unlock_bh(&pernet->lock); - - mptcp_nl_set_flags(net, &addr->addr, bkup, changed); - return 0; -} - -int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info) -{ - struct mptcp_pm_addr_entry remote = { .addr = { .family = AF_UNSPEC }, }; - struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }; - struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; - struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; struct net *net = sock_net(skb->sk); + struct mptcp_pm_addr_entry *entry; + struct pm_nl_pernet *pernet; + u8 lookup_by_id = 0; u8 bkup = 0; int ret; + pernet = pm_nl_get_pernet(net); + ret = mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; - if (attr_rem) { - ret = mptcp_pm_parse_entry(attr_rem, info, false, &remote); - if (ret < 0) - return ret; + if (addr.addr.family == AF_UNSPEC) { + lookup_by_id = 1; + if (!addr.addr.id) + return -EOPNOTSUPP; } if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup = 1; - return mptcp_pm_set_flags(net, token, &addr, &remote, bkup); + spin_lock_bh(&pernet->lock); + entry = __lookup_addr(pernet, &addr.addr, lookup_by_id); + if (!entry) { + spin_unlock_bh(&pernet->lock); + return -EINVAL; + } + if ((addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) && + (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { + spin_unlock_bh(&pernet->lock); + return -EINVAL; + } + + changed = (addr.flags ^ entry->flags) & mask; + entry->flags = (entry->flags & ~mask) | (addr.flags & mask); + addr = *entry; + spin_unlock_bh(&pernet->lock); + + mptcp_nl_set_flags(net, &addr.addr, bkup, changed); + 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) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index b9809d988693..7ef3b69852f0 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -546,14 +546,19 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info return err; } -int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token, - struct mptcp_pm_addr_entry *loc, - struct mptcp_pm_addr_entry *rem, u8 bkup) +int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) { + struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; + struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, }; + struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; + struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; + struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; + struct net *net = sock_net(skb->sk); struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; u32 token_val; + u8 bkup = 0; token_val = nla_get_u32(token); @@ -566,12 +571,27 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token, if (!mptcp_pm_is_userspace(msk)) goto set_flags_err; - if (loc->addr.family == AF_UNSPEC || - rem->addr.family == AF_UNSPEC) + ret = mptcp_pm_parse_entry(attr, info, false, &loc); + if (ret < 0) goto set_flags_err; + if (attr_rem) { + ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem); + if (ret < 0) + goto set_flags_err; + } + + if (loc.addr.family == AF_UNSPEC || + rem.addr.family == AF_UNSPEC) { + ret = -EINVAL; + goto set_flags_err; + } + + if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP) + bkup = 1; + lock_sock(sk); - ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, &rem->addr, bkup); + ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup); release_sock(sk); set_flags_err: diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index de9f0ff6dd30..f16edef6026a 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -970,13 +970,9 @@ int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id, u8 *flags, int *ifindex); -int mptcp_pm_set_flags(struct net *net, struct nlattr *token, - struct mptcp_pm_addr_entry *loc, - struct mptcp_pm_addr_entry *rem, u8 bkup); -int mptcp_pm_nl_set_flags(struct net *net, struct mptcp_pm_addr_entry *addr, u8 bkup); -int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token, - struct mptcp_pm_addr_entry *loc, - struct mptcp_pm_addr_entry *rem, u8 bkup); +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, const struct mptcp_addr_info *addr, bool echo); From patchwork Tue Mar 5 11:04:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13582115 X-Patchwork-Delegate: kuba@kernel.org 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 E6B835B20F; Tue, 5 Mar 2024 11:04: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=1709636690; cv=none; b=qT2ME+Nl+uw7paY9EKFF3Oi5ciJYUmmxPBP+EleUd7tNu9zb2SXFeL7KtcXjZQ5yNJRdsGC6dBU5jf2ODQhPw+K6C8mBqUTpFICiwYT1mPyK/joiIE/Q7pZ4drGtMg7IOQMtrtprXJM0AlQrfLlGaOQNhppJbXLxM6ttLWr4PVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709636690; c=relaxed/simple; bh=SR02P7ZjycQ0WA/qACfPhFmEuLcrv2LV85aCKTnWlH4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l29ckcQAYpK4sJlUH2RuNvtraAZvGEn/pBSSrmvjG2Rbc+a+2Ha0g8O+9dfOiM9a+3cdEgxIOsKWbB+p6f5KIsApH/ejsQlFCj/NVj+7866SnwgEKrv9oeBrp/COXqcLKVLFJMecd1FdjKkJuGyvw7AKalt6fpmmXfYMva1THpM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eXme+5hK; 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="eXme+5hK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12F26C433F1; Tue, 5 Mar 2024 11:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709636689; bh=SR02P7ZjycQ0WA/qACfPhFmEuLcrv2LV85aCKTnWlH4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eXme+5hKyN1CbU61OeHxp1d2p0O5RSx7DZMvgYo+Hqu/FTB7o9qiLCkPlnoBpld7S u/A4yhPVwEyhHsRXlK6l/ymSXixiEdE3udYKDkjsAYeR9mrHQULdZ7b7frdAi0+eCM Aekf0mY/Xwr+UvcvWGeScDhZ31P5c413e4d8SOwf6t0YFY8rgVkeaqSJibgMjpMn6a 5tTIEZXOpoK5sbBtQhit2fg23N2wflaBs8Ehxiwsv0WXvVtm35j12/q2ZIg4wiqefy E25YUUEUJBDHO+dz+iNsuGzlwdMuuq/CgwyqnCO1Z9GskxnRhQtx1u7J0yyDwTaS6n rGGXCVtdDZAhQ== From: "Matthieu Baerts (NGI0)" Date: Tue, 05 Mar 2024 12:04:32 +0100 Subject: [PATCH net-next 3/4] mptcp: set error messages for set_flags Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-3-c436ba5e569b@kernel.org> References: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-0-c436ba5e569b@kernel.org> In-Reply-To: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-0-c436ba5e569b@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Geliang Tang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2584; i=matttbe@kernel.org; h=from:subject:message-id; bh=JweTqcXP1xdyvdf6NgU0IrJbdbJn8RoJdxUpyS0t0pM=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBl5vxDUoyU0GvJ2GdK9lieXgEEjzXeT0i5SznEP XWBPdoqfuGJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZeb8QwAKCRD2t4JPQmmg czFKEADHOui264xrXbXWVU5Q+NBiKp2u3AXg9P0PERZdK81hNtahMdUnuNtAgCi1+SdWGqXoIC9 R8SJCGB3MRd+KJS2xX+Qj++JhGcMrDVr3/DKjX2lOU0vF23NstPOkX00FvVqib3zVxyoIdsJcXl JPrgLiBpF8Ss7rtwT0ugnWHyWFw7nbh9djV1Y3O9LUaV762Mezr5bPJtOKaVLRCuHztuiRh4uSL fKTLTDHr4yfxg/rU0pZqqkFcbApJqkbe13h+CWDlNs5IofXpRemy0I7M/R7rfpRNZIop863Gs9K nuXMbBAKwun5bCrdSVF1YrfSowaGcwzb5Rd7oS50pQ0roAyhO04FEd/P92VJVwBs9Tf4BWmsFw7 +o42nl+79xiya4sNUphVWN0cIw1umGLMdwORBv+m/g/N6gS5siJm1SJjDc5Nsg33FI4cvUaGFXy H7qXTaeIF77Kc6vdmKfnZjtgd3vIJ3Wkb2aneRZ1QeUWJHTVOFNElx1EqcBp5IX+njGohXznueH cR3dlvWzAYCqm7JG9dC68ZsoJeDjRRPyvxFaFmS83nQMqTe2WCWPrZ6qjcGrjTx2Zs7040hnaua DpXXP2LIv+LHRtTYhP6fczjqL652SEwsy567q0e9QLYlqwxyQKEyI7zkglNsn//ITaMxzFibJq2 IWVF2dt8Vagf6PA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Patchwork-Delegate: kuba@kernel.org From: Geliang Tang In addition to returning the error value, this patch also sets an error messages with GENL_SET_ERR_MSG or NL_SET_ERR_MSG_ATTR both for pm_netlink.c and pm_userspace.c. It will help the userspace to identify the issue. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_netlink.c | 6 +++++- net/mptcp/pm_userspace.c | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index c799fe84dfd3..354083b8386f 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1908,8 +1908,10 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) if (addr.addr.family == AF_UNSPEC) { lookup_by_id = 1; - if (!addr.addr.id) + if (!addr.addr.id) { + GENL_SET_ERR_MSG(info, "missing required inputs"); return -EOPNOTSUPP; + } } if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP) @@ -1919,11 +1921,13 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) entry = __lookup_addr(pernet, &addr.addr, lookup_by_id); if (!entry) { spin_unlock_bh(&pernet->lock); + GENL_SET_ERR_MSG(info, "address not found"); return -EINVAL; } if ((addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) && (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { spin_unlock_bh(&pernet->lock); + GENL_SET_ERR_MSG(info, "invalid addr flags"); return -EINVAL; } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 7ef3b69852f0..9f5d422d5ef6 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -563,13 +563,17 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) token_val = nla_get_u32(token); msk = mptcp_token_get_sock(net, token_val); - if (!msk) + if (!msk) { + NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); return ret; + } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) + if (!mptcp_pm_is_userspace(msk)) { + GENL_SET_ERR_MSG(info, "userspace PM not selected"); goto set_flags_err; + } ret = mptcp_pm_parse_entry(attr, info, false, &loc); if (ret < 0) @@ -583,6 +587,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) if (loc.addr.family == AF_UNSPEC || rem.addr.family == AF_UNSPEC) { + GENL_SET_ERR_MSG(info, "invalid address families"); ret = -EINVAL; goto set_flags_err; } From patchwork Tue Mar 5 11:04:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13582116 X-Patchwork-Delegate: kuba@kernel.org 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 C9F935B671; Tue, 5 Mar 2024 11:04: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=1709636692; cv=none; b=MnHxqphvn6L9BbZrcyJm6nUt9heVxAYNXbmKMKZAZ5EukDYgTsA0QfP67aYhzsMhsEGY7V2zRGCNAjrSJnGQQkvrBj2HmhoozGZJMnM4hPItGTfZXoNkrDYDr/PUpng923AxZL9uDZHInalyUolMiMr97PZgJUEj5FIEbqiWZOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709636692; c=relaxed/simple; bh=VrgfVfXGL+bniwIr+Gqdl6c583H+xRtQ0rR4oYPIcrM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JB/+MobWQqzX2+5BMgJBuDxDoPFtapMyCEGoz7wdIo4kfxX+fCkzjBdM6RpPpX6dnwIaeBRzII6hdCmBkbiVSElrv68AwJPF4D4I8ROwppehWTorQyuJZugMzi4iHhAy2OnTpTUDTjCZoW9dq1y5E+j7rJ3BFsLsxGuWMh4FTtY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KI7o8Snd; 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="KI7o8Snd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6D97C43399; Tue, 5 Mar 2024 11:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709636692; bh=VrgfVfXGL+bniwIr+Gqdl6c583H+xRtQ0rR4oYPIcrM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KI7o8SndIscczSWBa0jSe5sXWiSDqkpwTMxTvZHwnyBl2vOBXKsC7mzoELrAIJ8AP Aus7KDMJTEtC4yWqTzrTtKsjX734wFEKPepsIp/n4O6xK/dj8/Qrf6aNqy1G5HxEFK kWXboG3D5EchpXWmm4UFeX9b7ljgIYbf2ONyBWa/4qN4kndKsleTxNMyExN/kTnrwV jHQ7PkSvg1QNLQ3eee6z7ubdgK+3jFW5QtJdvNomxv6hG1JdxNXv1FOdufJXDH/xgg 5FDUGqHvB+Mnz/5o3LvkkN1PlqxIgiiHlqpQdfXYhHaaTfkPFn7o4liwc/C7XcqTds aCqtndlWcFu2w== From: "Matthieu Baerts (NGI0)" Date: Tue, 05 Mar 2024 12:04:33 +0100 Subject: [PATCH net-next 4/4] mptcp: drop lookup_by_id in lookup_addr Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-4-c436ba5e569b@kernel.org> References: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-0-c436ba5e569b@kernel.org> In-Reply-To: <20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-0-c436ba5e569b@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Geliang Tang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2274; i=matttbe@kernel.org; h=from:subject:message-id; bh=IRouLJLzOQvuPh1nmmYUU3MxKdU5480lf2zN3s0oVSE=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBl5vxDaCTvgU0QiI3890Plw4yMOhTvTcmFlgLYX g0H4OYsbQeJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZeb8QwAKCRD2t4JPQmmg c/eFD/9U61UobHCI0eQctMtjgjY/zwtcGDFKiKx0mdpkxf70WmgWiSJIZYaqJTZYDwJQlEFzhEK tUs5/vXMS5KLs+1cHEzEg4gJrbuXCA5MqnfiBT8cTX0ERQTityTNiyAQbijClmBO3r32qidykpA b0OKdFDbu83C+pa9NYwrkPm/IDkTkgGwRYEPLLEGxUUf+znTaf6cLQCrdVHfkk6P/8Y9QSe9N2q xTSMEr8Z3s1MlbIvlEMztm+tvsb3tiFaUoYxdtFRiWyiFBimYdFT5B99yT4eLyJeZ59QMsT9Gdy fLDZZ9MG9P4zRjodU/bkZD+07B38W9Q8QfVVnTaIT3eHs6PDGLpcavRVgsLJInpRrrsilvClkLb SqvmQhibf0rin8ZEYvkVTMNGxY9K1Dlk9CvJydtTpz3zpLreW/WIqVWWiE5h3c9EmRaHUxKdov5 GOgFUEQ38wP+5nR76MHCNYtar0KfLIDWTOe8oO7NO04T6EuFr3/NX7HaL0tVPRIHg4pR5prxkDD GgsTp1eQONh5GHeLG5oepkHMhp4ROlt1rkQ0jaSZBXdD3cyLISuxCPtrTsfGIslTxlUkR0Bq0pd 7GNc5+umCmR47oktMO776uqO+cAOT0zi8JDuyo02EriDQl7eNdztQ7XbJ78sXw0YfJY9nNbwrMx sdS/9uSd6pgV/fw== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Patchwork-Delegate: kuba@kernel.org From: Geliang Tang When the lookup_by_id parameter of __lookup_addr() is true, it's the same as __lookup_addr_by_id(), it can be replaced by __lookup_addr_by_id() directly. So drop this parameter, let __lookup_addr() only looks up address on the local address list by comparing addresses in it, not address ids. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_netlink.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 354083b8386f..5c17d39146ea 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -499,15 +499,12 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id) } static struct mptcp_pm_addr_entry * -__lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info, - bool lookup_by_id) +__lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info) { struct mptcp_pm_addr_entry *entry; list_for_each_entry(entry, &pernet->local_addr_list, list) { - if ((!lookup_by_id && - mptcp_addresses_equal(&entry->addr, info, entry->addr.port)) || - (lookup_by_id && entry->addr.id == info->id)) + if (mptcp_addresses_equal(&entry->addr, info, entry->addr.port)) return entry; } return NULL; @@ -537,7 +534,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) mptcp_local_address((struct sock_common *)msk->first, &mpc_addr); rcu_read_lock(); - entry = __lookup_addr(pernet, &mpc_addr, false); + entry = __lookup_addr(pernet, &mpc_addr); if (entry) { __clear_bit(entry->addr.id, msk->pm.id_avail_bitmap); msk->mpc_endpoint_id = entry->addr.id; @@ -1918,7 +1915,8 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) bkup = 1; spin_lock_bh(&pernet->lock); - entry = __lookup_addr(pernet, &addr.addr, lookup_by_id); + entry = lookup_by_id ? __lookup_addr_by_id(pernet, addr.addr.id) : + __lookup_addr(pernet, &addr.addr); if (!entry) { spin_unlock_bh(&pernet->lock); GENL_SET_ERR_MSG(info, "address not found");