From nobody Sat Jan 4 23:01:12 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 1BCC31A83FB for ; Mon, 30 Dec 2024 13:24:26 +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=1735565067; cv=none; b=QjJEz9DtkDBAlFCtj5+HCsijJIhlUu9uV958LpPI6C+HjJVVzxbJh7DapteuHp9yKFlbPygY4ttgyV/FDd6p7Ausn+Ck/wJvFZqfi0p1r14G++EKWb8LX2Z6pJqopiwgseCOF3XTGwFGAAqzcLH7RpxG4V8K2OZpZdmadAwplSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565067; c=relaxed/simple; bh=ME2LpurMH8/i1zBciCwO+JKPkbJaoLsObzAYsTNbxXU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nUPajKb0ypZSLRhV4MSQtAn7J/+9hy2xLbhaurjjeiL4G//11uqQNIoPCwMHBwgDBfHen7Oq6ICTCOVQtfD4UsN40nkDkIUZKFiVND0IA0yrfNSxNkXWUj6CqeplnhPkmgi5EDEvdAvaB4YkI0udeEkBdsULyl43cUg2jYWEKfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e7/ZsxYf; 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="e7/ZsxYf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12716C4CED0; Mon, 30 Dec 2024 13:24:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735565066; bh=ME2LpurMH8/i1zBciCwO+JKPkbJaoLsObzAYsTNbxXU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=e7/ZsxYfrKGyIlqPpDdue9ym3ONzb4MDfyVQ9GNhJKGrB4GlR/GzkWLYUNiB+gc3L FR6WtqfH6QyCC/IF8XLVOwTBQgrCyh7GBfLgWJB6dcp4qylEUJINw56npHA82puxf2 vWW6GYFXKP4wW5UG/r8ZFUcym+qi2O1HNzOmjmGSzi2q4JRQr0kz2Lu5DAdit0f9a3 9SyqWXwFho1V+A/6kWDAfiCBG1LjnIQqWxX/XPGVm6Pbimw0i6tMnY+NB8bM9M0GkI GYyGB7H90GVNUMdt7FcfjU5K0t42wdPEcH8OGuO981/GO7Dw3Gm39H59bjPSiIHHjs 86T4yZ2+J4kgQ== From: "Matthieu Baerts (NGI0)" Date: Mon, 30 Dec 2024 14:24:08 +0100 Subject: [PATCH mptcp-next v6 1/7] mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241230-genl_req_attr_check-v6-1-3ec9103559e7@kernel.org> References: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> In-Reply-To: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7581; i=matttbe@kernel.org; h=from:subject:message-id; bh=ME2LpurMH8/i1zBciCwO+JKPkbJaoLsObzAYsTNbxXU=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBncp8JvQbtCrRzLD3GF3gIUUQPgFljtFVFY6zyI 1jBjMllqgKJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ3KfCQAKCRD2t4JPQmmg c9uWEADmjXDXZ+7I0JOSfW1arteZmdxGxVTRhsIHLKQ/tOp+Ss6HnvDFpFqVbsIch+CXhREE/a2 S0FIvfe1US9AOGfSFYSMqgIFiPOLsKBeNV0BK7vrVBs4V0XTZcEV4AYLRrt05uBgS2nL3tdjbPt FVk9mCRSwpdKtsn9U4pYNhnXfMwzbKmkiaBhlu1VtAjfqDswRN5zTzcZmcm32OW/g6Vgvcqdrw7 0MxqnEs8esV8YA72r1OR1Tzcu1uu3yGz5IfpEZJriWoXgvLLss/aKpvwoaBXbBpEgDoC7BjNVLV bOYYHAiQtQ9IljsXyBrgzxLHu5hP3Qnv0w9yNpFUyEOirIUXU2aUBr2yYKhftirQo2BksS+e1hG njPWwVSRwGWKfx4e5XKZ1wmx0HiH5YyPrH04u8H+feYbo4xb10rt9m4YZEdv17WsTL2nzvyQMBt 7FZhMuwFFrRkON2MLNbF0ebxvirDUf8PDodsOG1jr52t5lx5trItzYadNn6D5nUcR7CYbDS/vM4 S4QwKGJEVvcVKLXS2jLnhdIn0UrN49ry/PdMmAnuKEDAJyTJPpxV6zM+GXN8moV9/aNtyCTNKBC y5cAXqF4uOqv9pm7fgFZ09z9H8NpAXwbd1N65MtT/eq3294byGfLpctFqLifYQ30vzEki+vUuHQ Z1gjbLlo2WR5/Ew== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Instead of only returning a text message with GENL_SET_ERR_MSG(), NL_SET_ERR_MSG_ATTR() can help the userspace developers by also reporting which attribute is faulty. When the error is specific to an attribute, NL_SET_ERR_MSG_ATTR() is now used. The error messages have not been modified in this commit. mptcp_userspace_pm_remove_id_zero_address() has been modified to set the missing attribute. Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_netlink.c | 23 ++++++++++++++--------- net/mptcp/pm_userspace.c | 27 +++++++++++++++++---------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 98ac73938bd8196e196d5ee8c264784ba8d37645..49c34494e156ff6c3277b107c38= 40ee29dd3afbb 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1403,18 +1403,21 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, = struct genl_info *info) return ret; =20 if (addr.addr.port && !address_use_port(&addr)) { - GENL_SET_ERR_MSG(info, "flags must have signal and not subflow when usin= g port"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "flags must have signal and not subflow when using port"); return -EINVAL; } =20 if (addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL && addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) { - GENL_SET_ERR_MSG(info, "flags mustn't have both signal and fullmesh"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "flags mustn't have both signal and fullmesh"); return -EINVAL; } =20 if (addr.flags & MPTCP_PM_ADDR_FLAG_IMPLICIT) { - GENL_SET_ERR_MSG(info, "can't create IMPLICIT endpoint"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "can't create IMPLICIT endpoint"); return -EINVAL; } =20 @@ -1608,7 +1611,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) spin_lock_bh(&pernet->lock); entry =3D __lookup_addr_by_id(pernet, addr.addr.id); if (!entry) { - GENL_SET_ERR_MSG(info, "address not found"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found"); spin_unlock_bh(&pernet->lock); return -EINVAL; } @@ -1790,7 +1793,7 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct = genl_info *info) rcu_read_lock(); entry =3D __lookup_addr_by_id(pernet, addr.addr.id); if (!entry) { - GENL_SET_ERR_MSG(info, "address not found"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found"); ret =3D -EINVAL; goto unlock_fail; } @@ -1875,7 +1878,8 @@ static int parse_limit(struct genl_info *info, int id= , unsigned int *limit) =20 *limit =3D nla_get_u32(attr); if (*limit > MPTCP_PM_ADDR_MAX) { - GENL_SET_ERR_MSG(info, "limit greater than maximum"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "limit greater than maximum"); return -EINVAL; } return 0; @@ -2003,7 +2007,8 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct= genl_info *info) if (addr.addr.family =3D=3D AF_UNSPEC) { lookup_by_id =3D 1; if (!addr.addr.id) { - GENL_SET_ERR_MSG(info, "missing required inputs"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "missing required inputs"); return -EOPNOTSUPP; } } @@ -2016,13 +2021,13 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, stru= ct genl_info *info) __lookup_addr(pernet, &addr.addr); if (!entry) { spin_unlock_bh(&pernet->lock); - GENL_SET_ERR_MSG(info, "address not found"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, "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"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, "invalid addr flags"); return -EINVAL; } =20 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index a3d477059b11c3a5618dbb6256434a8e55845995..72d4861e497eef5a516fc1c3ec1= 659807ffedd53 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -190,7 +190,8 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(c= onst struct genl_info *in } =20 if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); + NL_SET_ERR_MSG_ATTR(info->extack, token, + "invalid request; userspace PM not selected"); sock_put((struct sock *)msk); return NULL; } @@ -224,14 +225,16 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, st= ruct genl_info *info) } =20 if (addr_val.addr.id =3D=3D 0 || !(addr_val.flags & MPTCP_PM_ADDR_FLAG_SI= GNAL)) { - GENL_SET_ERR_MSG(info, "invalid addr id or flags"); + NL_SET_ERR_MSG_ATTR(info->extack, addr, + "invalid addr id or flags"); err =3D -EINVAL; goto announce_err; } =20 err =3D mptcp_userspace_pm_append_new_local_addr(msk, &addr_val, false); if (err < 0) { - GENL_SET_ERR_MSG(info, "did not match address and id"); + NL_SET_ERR_MSG_ATTR(info->extack, addr, + "did not match address and id"); goto announce_err; } =20 @@ -254,7 +257,8 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, stru= ct genl_info *info) } =20 static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *ms= k, - struct genl_info *info) + struct genl_info *info, + struct nlattr *attr) { struct mptcp_rm_list list =3D { .nr =3D 0 }; struct mptcp_subflow_context *subflow; @@ -270,7 +274,8 @@ static int mptcp_userspace_pm_remove_id_zero_address(st= ruct mptcp_sock *msk, } } if (!has_id_0) { - GENL_SET_ERR_MSG(info, "address with id 0 not found"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "address with id 0 not found"); goto remove_err; } =20 @@ -330,7 +335,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct= genl_info *info) sk =3D (struct sock *)msk; =20 if (id_val =3D=3D 0) { - err =3D mptcp_userspace_pm_remove_id_zero_address(msk, info); + err =3D mptcp_userspace_pm_remove_id_zero_address(msk, info, id); goto out; } =20 @@ -339,7 +344,8 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct= genl_info *info) spin_lock_bh(&msk->pm.lock); match =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); if (!match) { - GENL_SET_ERR_MSG(info, "address with specified id not found"); + NL_SET_ERR_MSG_ATTR(info->extack, id, + "address with specified id not found"); spin_unlock_bh(&msk->pm.lock); release_sock(sk); goto out; @@ -389,7 +395,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb= , struct genl_info *info) } =20 if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) { - GENL_SET_ERR_MSG(info, "invalid addr flags"); + NL_SET_ERR_MSG_ATTR(info->extack, laddr, "invalid addr flags"); err =3D -EINVAL; goto create_err; } @@ -409,7 +415,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb= , struct genl_info *info) =20 err =3D mptcp_userspace_pm_append_new_local_addr(msk, &entry, false); if (err < 0) { - GENL_SET_ERR_MSG(info, "did not match address and id"); + NL_SET_ERR_MSG_ATTR(info->extack, laddr, + "did not match address and id"); goto create_err; } =20 @@ -702,7 +709,7 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb, spin_lock_bh(&msk->pm.lock); entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id); if (!entry) { - GENL_SET_ERR_MSG(info, "address not found"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, "address not found"); ret =3D -EINVAL; goto unlock_fail; } --=20 2.47.1 From nobody Sat Jan 4 23:01:12 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 159401A3031 for ; Mon, 30 Dec 2024 13:24:27 +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=1735565069; cv=none; b=BzsZ4eOlYLZ4aopk8i3Eb2PaNMmjCxLeL0CbLfQvfDMHiPqBMLaoPoqadpxc07Ciy8w6RBmkyElryn4y6E7DaDW/J2PsSkwLYdlWBY/tnNQLexAusYlZxdC6lUj4iZJ7BlkIueHuQU1pgBUKOnewLefZ5pI4smHPdxxfO7PvSbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565069; c=relaxed/simple; bh=VuUWBl+yDbg5KEAuDjQHLbXMDdBhUxR/KJHYliGw0Qo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k7B1UI9MTUO6tq8oBbY/w/bNdVzxZrNtObTeGpH+Wb4IcvVIx/wXJ8qKbofglj3PrOErTVkP1M+ShgXKBWu3Er3Ig4X4HJAQwHtRxX9tjir1KJzoWPfITVG/wpLEAj7iYBKf0R3+FXoMq3geRlqzvDGZSc/xz9Uk0xT03lqJAZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EVfFa2f/; 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="EVfFa2f/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11A60C4CED2; Mon, 30 Dec 2024 13:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735565067; bh=VuUWBl+yDbg5KEAuDjQHLbXMDdBhUxR/KJHYliGw0Qo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EVfFa2f/EIggVgkJkU1WWfI5RwAju5b/CJ86Y7ERfbtPW9tcfFl3IcnG3ZXL9Oasu sEmF0mgAsBDuDwR98itEYe6l7d9+ZbqJrv/mz/vffOgHpVgFf4u+01yQVHx9yDmq0y u17Pyu2JK2MZ6F7i1vpf22YeYXY7rh0ULEOv7qAC8Epg0zwHSA1YILuVJSMOjLMcZz C+mBbSIBz2rhkzFKocD7pQC/M/l877qnNI7IJR/vuzOWQxVhsejqT8KPkoOqMZAT6m 5HC/zxje1aBNKZTmjBhaJEV5skTa65N1UsHzCgMSgHwgGHuJR6lLvmee+o1qJzX0XW vhuVHI6A6vFhA== From: "Matthieu Baerts (NGI0)" Date: Mon, 30 Dec 2024 14:24:09 +0100 Subject: [PATCH mptcp-next v6 2/7] mptcp: pm: more precise error messages Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241230-genl_req_attr_check-v6-2-3ec9103559e7@kernel.org> References: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> In-Reply-To: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2558; i=matttbe@kernel.org; h=from:subject:message-id; bh=VuUWBl+yDbg5KEAuDjQHLbXMDdBhUxR/KJHYliGw0Qo=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBncp8J7p5F/oerlf+nr7K/S/qBGun/pzEz7vXH/ OrPnAWEWp+JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ3KfCQAKCRD2t4JPQmmg c2sxEACmUDEym0fBJdtapAaTRkuZLvLVxZrDRdt6fcBekYfig7NKxcMj00Dp7hW+ZAe1KNqLmNa nyhstVrwBJrQ+sFLUAYfC4JNRJy5W1mlZULJvmi9nyC9T8QrbUO1rU3V1B1P7z3gng9IYH7TvSb wld4LbrU6a1MSv+cXJ/a0N5F6wbowMM1fiz0A/oxP/iAHYuqSV27/ThX6lzXgtfBPlMnuGJ/F/M ItuibJDWEAhQTIGqh8ZgVVpRxB43hYByWeffFFQUhjDuNlGeQfLCCZ3SV91O9QMMmdnDBjIICP0 gdFjkTBgcrZmk3s06B7ZNdmGAGS2yeVhfAE2Lgq2QNKTz9Yto+y2KRtESc+uNYYph41OnMqpn2R hbwknqrCi5bhR/AEbqRkzFdZcp61tqYVwLQ2RDTYIBHTzM7VH+UYsKonvi8Gk4w4ruwpSc4goYD XlCKz5R/6xKwSFkL/EQZ/jhInBxDoJRSGxY9EAk/VPTq6YW1dT1hBowiD33GA8iBGp/qN++VIlE srRs9dO40QSP9LdycbIapTmdu/mF3GO6SH38Im4OsxyjsGO9lfyPYURpW9mMhwcpr/YStKuHek+ 5YrssrYxrKJTgJhGQWDKV/LNIdhb3imVBfum3TysWkyNwD/5sQfgaxtAQi0hnaG9p/NmJGLX4SM KsotF5Mbc22Eoqg== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Some errors reported by the userspace PM were vague: "this or that is invalid". It is easier for the userspace to know which part is wrong, instead of having to guess that. By splitting some error messages, NL_SET_ERR_MSG_ATTR() can be used instead of GENL_SET_ERR_MSG() in order to give an additional hint to the userspace developers about which attribute is wrong. Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 72d4861e497eef5a516fc1c3ec1659807ffedd53..9c0bec588c498e0aa78acf4018d= b509abe90cad2 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -224,9 +224,14 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, str= uct genl_info *info) goto announce_err; } =20 - if (addr_val.addr.id =3D=3D 0 || !(addr_val.flags & MPTCP_PM_ADDR_FLAG_SI= GNAL)) { - NL_SET_ERR_MSG_ATTR(info->extack, addr, - "invalid addr id or flags"); + if (addr_val.addr.id =3D=3D 0) { + NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr id"); + err =3D -EINVAL; + goto announce_err; + } + + if (!(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { + NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr flags"); err =3D -EINVAL; goto announce_err; } @@ -537,8 +542,14 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *s= kb, struct genl_info *info goto destroy_err; } =20 - if (!addr_l.addr.port || !addr_r.port) { - GENL_SET_ERR_MSG(info, "missing local or remote port"); + if (!addr_l.addr.port) { + NL_SET_ERR_MSG_ATTR(info->extack, laddr, "missing local port"); + err =3D -EINVAL; + goto destroy_err; + } + + if (!addr_r.port) { + NL_SET_ERR_MSG_ATTR(info->extack, raddr, "missing remote port"); err =3D -EINVAL; goto destroy_err; } @@ -592,9 +603,16 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, = struct genl_info *info) goto set_flags_err; } =20 - if (loc.addr.family =3D=3D AF_UNSPEC || - rem.addr.family =3D=3D AF_UNSPEC) { - GENL_SET_ERR_MSG(info, "invalid address families"); + if (loc.addr.family =3D=3D AF_UNSPEC) { + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "invalid local address family"); + ret =3D -EINVAL; + goto set_flags_err; + } + + if (rem.addr.family =3D=3D AF_UNSPEC) { + NL_SET_ERR_MSG_ATTR(info->extack, attr_rem, + "invalid remote address family"); ret =3D -EINVAL; goto set_flags_err; } --=20 2.47.1 From nobody Sat Jan 4 23:01:12 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 AD0711A8406 for ; Mon, 30 Dec 2024 13:24:28 +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=1735565068; cv=none; b=Zxq/Ae//eNSm/TrzxgCO9ryk7bGnMCLNrdEg0KKmdfpw7VcDMjScL/PsPAF5Gb2p+H9JXQWBcjXcK7IGUZj/APt23uTjRRcqbE1IujHDtrdNUz/w0HxK416C4bUUk0Vgqkr15Q6h7sK8PDib/BO5cCcpXvUFkzVQOQP/6OXfqT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565068; c=relaxed/simple; bh=jU3KoUk61mM6lLOZmdsm0ye4ezUmGBGTaSB9Fi8Wid0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hTMuBxb9HoZjYYHazryJALLNuo44vp8+6YXINY6h71RkpdHnnlEvNLhr0fOb8V623SxcmbGLn3Oz2pJqVak1TRlXRZErhzQkZjbLlP79SbYCkZSkgb13stda/LD9mK0UOXfjwc2r6DR6aTME/uhdiSyE0EkLTMrNqvc4B6iyAFk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uieXrGCW; 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="uieXrGCW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E1AEC4CEDE; Mon, 30 Dec 2024 13:24:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735565068; bh=jU3KoUk61mM6lLOZmdsm0ye4ezUmGBGTaSB9Fi8Wid0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=uieXrGCWMMtwcZgMPG97j12x4LBs/DIbJbj7S38z6wq26oO1/JsXCxA8UpPt1sPjK S0yfKbTNbGDHUcM7Vx8NndcvoNdkzW8FKvwYu8xPvPrHIhrSQ2JW+5LgL/GT/rkbAl 8EMXQwkUPng0pacNQxDPiZAU49PvXcAR+wqKNeFbbFRnwp+AnrRHqeswYta7m9D/MH p0a/JF3KvOfgX/tjgmrUWyPrG+58sRnk5zVIvpR93tGcMIaoeOl5gYtHUayM2X9P36 00koo53+q/75+qntgE0/ysL+LkP4+nIEfOfzOD0bNZtRSyyfRIsI7yDBaBG45i/A2j 2HBG/8NpahKSg== From: "Matthieu Baerts (NGI0)" Date: Mon, 30 Dec 2024 14:24:10 +0100 Subject: [PATCH mptcp-next v6 3/7] mptcp: pm: improve error messages Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241230-genl_req_attr_check-v6-3-3ec9103559e7@kernel.org> References: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> In-Reply-To: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2948; i=matttbe@kernel.org; h=from:subject:message-id; bh=jU3KoUk61mM6lLOZmdsm0ye4ezUmGBGTaSB9Fi8Wid0=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBncp8KthzMuhUPEpGvfofoyBBc8RKH29eJpF7eG yRQp2uCAAiJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ3KfCgAKCRD2t4JPQmmg c6JNEACyjUMh6BDLMzW/dBEqSKbtg6R4l+CfGdpCMHAhgtfIcY5+l/WHd/kKPuQRZU77jvsIhyD S7wNZie6oeqlv00IlxXDBiQi0aXrHnHH5m0FIYM8pEKyQ5iM6tcy9iqWqCOATStN8GbczVkHIDF y5sw3EUiON+aYACulJ7IDWWV/yl2wWZy34SFw50lo5RRnBL1fYl9LctwVRffVZdKknnrcmg1RMV sdvmkOXw/AydwAgTBB1TxlkDLAYHMYb5Kmkqxh74Ebir3sD4GnKo7/KhZ+ZG7IWoJh3eBlCbf0Y mIrw+hTs6isMOlpMZcnHEZjen5iYWKISn5RMSmQOZOYFnS0nxLoHRNCSu8X+43QWiLqluc+ROCV yyb2FM9yD8/sJUYc+I07lDUJ1U8IqJjplDX2s+FBvSW8C6Rf7tGanAuIAinuwVm5qdlTFWaewv/ WIsgWcX+EhVCwnic+AnR64l+NfG4NnrwSv1wRqXbSWKwkCHikuXzJlTbtg0KgtWgJcdPtSRlLER F2QJy7K0ljULQKHoBIXbKRcGITWBnQMbYVbrukwOcEb6J9GHAZNjjuMcS2Dh9EaEaTjIkriuIJK fCW9tXGMOXq/fnuCqBSE7xrepoNF2u/dT2kG6W5HFXt/ia7ytCd2LlkiE9JIorWjtdZq83VR7bS SQDb5lFMFPpIqDA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Some error messages were: - too generic: "missing input", "invalid request" - not precise enough: "limit greater than maximum" but what's the max? - missing: subflow not found, or connect error. This can be easily improved by being more precise, or adding new error messages. Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_netlink.c | 7 ++++--- net/mptcp/pm_userspace.c | 9 ++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 49c34494e156ff6c3277b107c3840ee29dd3afbb..3bb213e2a967e87d4244dc0f1ba= 58d3ba21fb371 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1878,8 +1878,9 @@ static int parse_limit(struct genl_info *info, int id= , unsigned int *limit) =20 *limit =3D nla_get_u32(attr); if (*limit > MPTCP_PM_ADDR_MAX) { - NL_SET_ERR_MSG_ATTR(info->extack, attr, - "limit greater than maximum"); + NL_SET_ERR_MSG_ATTR_FMT(info->extack, attr, + "limit greater than maximum (%u)", + MPTCP_PM_ADDR_MAX); return -EINVAL; } return 0; @@ -2008,7 +2009,7 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct= genl_info *info) lookup_by_id =3D 1; if (!addr.addr.id) { NL_SET_ERR_MSG_ATTR(info->extack, attr, - "missing required inputs"); + "missing address ID"); return -EOPNOTSUPP; } } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 9c0bec588c498e0aa78acf4018db509abe90cad2..a8f73b082460ba00f7fa998cf76= 46368f8201e2e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -191,7 +191,7 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(c= onst struct genl_info *in =20 if (!mptcp_pm_is_userspace(msk)) { NL_SET_ERR_MSG_ATTR(info->extack, token, - "invalid request; userspace PM not selected"); + "userspace PM not selected"); sock_put((struct sock *)msk); return NULL; } @@ -433,6 +433,9 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb= , struct genl_info *info) err =3D __mptcp_subflow_connect(sk, &local, &addr_r); release_sock(sk); =20 + if (err) + GENL_SET_ERR_MSG_FMT(info, "connect error: %d", err); + spin_lock_bh(&msk->pm.lock); if (err) mptcp_userspace_pm_delete_local_addr(msk, &entry); @@ -557,6 +560,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *sk= b, struct genl_info *info lock_sock(sk); ssk =3D mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r); if (!ssk) { + GENL_SET_ERR_MSG(info, "subflow not found"); err =3D -ESRCH; goto release_sock; } @@ -634,6 +638,9 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, s= truct genl_info *info) ret =3D mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup); release_sock(sk); =20 + if (ret) + GENL_SET_ERR_MSG(info, "subflow not found"); + set_flags_err: sock_put(sk); return ret; --=20 2.47.1 From nobody Sat Jan 4 23:01:12 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 AB1101A3031 for ; Mon, 30 Dec 2024 13:24:29 +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=1735565069; cv=none; b=Twu8rbpw6QVXAX/+kaKipD2rV09SnyXdvORirQsaAW6FLlinySg2P5Q/onixL9C+Z9c+KAbzPF+5KsGcAkjyDrmZFcLJ9SkxW3Itx5kK5fr53HB7tVcpr5mDhD3tpi25mC1H5In/PvtSLg7o5LAbmMpx+JHHGg612O0ooWW4rZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565069; c=relaxed/simple; bh=+yEsBe/bkX0Z2vEd3NoAFa3ayX8jZXlA8naKMkwogqA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uMK/XLEPahnNVZ6RspzucTuymtF+fnXfId/W7qHkxi34HIDWoyyM4mBo3RLkZqlRYpCU5nNgjNr3w0RPZO+pKEPJIjifcuCIt9djrAHdvXvmgBK3G0GvFTOnuSqfCdIt7YaLak8n4FDLsbSHicvftsuX0Ii0hLLDX6DrFcLEVJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i5Ex7r3H; 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="i5Ex7r3H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A94EC4AF0C; Mon, 30 Dec 2024 13:24:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735565069; bh=+yEsBe/bkX0Z2vEd3NoAFa3ayX8jZXlA8naKMkwogqA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=i5Ex7r3HtfkBXLF6ePUicSAltdiOnSluVvxiveNiMXN1t8xrgBqvrhv4sfNLbvqbV MgetcZ/Xr16rD6AodBnOP7f9dvvyWve0kPrkK5cyLWVhODm7uLUXoajLbl5D4fl5U2 MY0MXptD2Qe57Hp45TszBqJkthbT/E0RbWeg1ToPUoORS9JyZP6WufxjNZPBagl5FZ 6jmsK4985La1pLknQZQVJVbvOj0SJlkLPcyljGgqpSvp/dg7ZOtKwoBF0O9DDyk39/ mxKfl8zQ36Cfs/CkOuJLBlTbqNPlpOMZd4sOc6151+niHz4LaB92Q4z+rmkEw7NG32 fHSaRYRg8bhvw== From: "Matthieu Baerts (NGI0)" Date: Mon, 30 Dec 2024 14:24:11 +0100 Subject: [PATCH mptcp-next v6 4/7] mptcp: pm: userspace: flags: clearer msg if no remote addr Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241230-genl_req_attr_check-v6-4-3ec9103559e7@kernel.org> References: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> In-Reply-To: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1951; i=matttbe@kernel.org; h=from:subject:message-id; bh=+yEsBe/bkX0Z2vEd3NoAFa3ayX8jZXlA8naKMkwogqA=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBncp8KAqzlOzQiMxw27bPlYFhLZclZZ0PEnAIH0 s42tPx9jwSJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ3KfCgAKCRD2t4JPQmmg cyCgEACph6SVbIfBke3xxyZqewjIMU2lCBW8WbJFr+uPzRtCJwWpvyEbgN0GGUsxKXFxl/OpECp tW2F1Skk3bSmT1nWIgwWuBACM+rzc7kSpAQHyOmzRw5ZZVDvfyVJNRY2F9KXh1CZUCueRutUKDk KuLTOKH97Mys/gjKAJP61xzVBGRrKG0Ss8qPjDAJA2Emu7o5RtElH1eql5FuVa5Qxzb21FvoN/B 2owKsRqJmRw6WDxs9WEe0LuCSuT+FCfZc3t6Obp+JxFNYnH+xpgQP3F5GPkMP5682NYJl0NO1gK 3C/+ScTD1UOlS/pZ9dn9bIIDeU6QSkyPY/ZKBArt2PyZpz+7+SOGXYN8k3DIiafBo4mR90a+5ce 2t2N4JrCulmoAHiPH7T9AUidS2cgzNyErbJSY3bybkYm3WcJTZM6BiXXAabbvCHQeznSTpf3y4r zdO6QeFma104g2JXbS2uc1FcTPOhP/dTG7Ps5yXbXmbUQEAGDCJAZ+BgjFKAvNmZwWsDuZYuF0z TMhBRfpO19Qtk3w5UonhI0mzVmLWaFlvewhfZ/MIxC7L1hh3wZZ+C3kiorSZeKbp5kqkdAQdGnQ SFnqgpT0J1U8n5mZu+endkPAflEAuR6wml3fLi4lUX+QPPFTQZVfFgVJrEy7KNtzuIs6v/lsyZc UOLInmBE5SrSUPw== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Since its introduction in commit 892f396c8e68 ("mptcp: netlink: issue MP_PRIO signals from userspace PMs"), it was mandatory to specify the remote address, because of the 'if (rem->addr.family =3D=3D AF_UNSPEC)' check done later one. In theory, this attribute can be optional, but it sounds better to be precise to avoid sending the MP_PRIO on the wrong subflow, e.g. if there are multiple subflows attached to the same local ID. This can be relaxed later on if there is a need to act on multiple subflows with one command. For the moment, the check to see if attr_rem is NULL can be removed, because mptcp_pm_parse_entry() will do this check as well, no need to do that differently here. While at it, move the parsing after the check linked to the local attribute. Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index a8f73b082460ba00f7fa998cf7646368f8201e2e..2f82ac49db35ec34dcc0b9208f4= ac12edc6ab254 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -601,12 +601,6 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, = struct genl_info *info) if (ret < 0) goto set_flags_err; =20 - if (attr_rem) { - ret =3D mptcp_pm_parse_entry(attr_rem, info, false, &rem); - if (ret < 0) - goto set_flags_err; - } - if (loc.addr.family =3D=3D AF_UNSPEC) { NL_SET_ERR_MSG_ATTR(info->extack, attr, "invalid local address family"); @@ -614,6 +608,10 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, = struct genl_info *info) goto set_flags_err; } =20 + ret =3D mptcp_pm_parse_entry(attr_rem, info, false, &rem); + if (ret < 0) + goto set_flags_err; + if (rem.addr.family =3D=3D AF_UNSPEC) { NL_SET_ERR_MSG_ATTR(info->extack, attr_rem, "invalid remote address family"); --=20 2.47.1 From nobody Sat Jan 4 23:01:12 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 AAA831A3031 for ; Mon, 30 Dec 2024 13:24:30 +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=1735565070; cv=none; b=LVw2SnO7xyfuwh5ok0Tpl1+kfoEfiprubPJDwVIgkr7d5cTybqtZl2Mnp2iukqS0k9TJe7GLn+oW/gL0Zdy4cJWIemOONxikhOPqqBTJ+uZssOq3e3oGTpndtCXOTZMt4jyAFc3/zooMRYeqN+73n6XF/lmshjp8e9a6UQTTZ0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565070; c=relaxed/simple; bh=NP3CqdrzwEvGrN1QuKO2/2KU9MSDxh8HE3q6m8scA80=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AvsCqlyK2ohjUvh14pK3AxKsk07OYon3JJQsdN84jrjST2Ljpl+UlPtcIDRH0DVsxFDUuA5e5K0s2E+JRC+ssgvMDFptFrHg8HbwhvRPEJ2fo+bu48MSsJeoaR7QHtGwH2ghz1O5bOxH7f8qEcEXwBnSQNXOQyCQ8aP/g1Mb1/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TCYQ74AG; 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="TCYQ74AG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0804BC4CED2; Mon, 30 Dec 2024 13:24:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735565070; bh=NP3CqdrzwEvGrN1QuKO2/2KU9MSDxh8HE3q6m8scA80=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TCYQ74AGTkeCyymLUECq4fp/nnt7xvNaxLsxpnliWQDT4s12MSepZJq4LZ3KCzDhZ LidpfPvdVo9laTfBxw49kbXvBkUxzonKuDU/ve5LAKOhflV3FaE9C6fR4+2Ab9G5kq ccB/NyIVgiFbF7FMZ1nmz1UhaMYDsyL4dJe/s479QmExpMokTwvD/zUA1WuZ8tZdXY QD69/4UHIEVbuvwoNQjejgkWhx/x6+ddPgzZ5qAamrOi8VaLKElVeN8Ho2GwYjI2G2 x7bVtCc3CXDPOi/HmzA+SRQkcxJkFLn8r3m0hQoLyH3UVyWaeYr0Bg0XMu6s43ukV+ //1I1dp3q8cfQ== From: "Matthieu Baerts (NGI0)" Date: Mon, 30 Dec 2024 14:24:12 +0100 Subject: [PATCH mptcp-next v6 5/7] mptcp: pm: userspace: use GENL_REQ_ATTR_CHECK Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241230-genl_req_attr_check-v6-5-3ec9103559e7@kernel.org> References: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> In-Reply-To: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5959; i=matttbe@kernel.org; h=from:subject:message-id; bh=rraPATvWMQ2H2oGt+iR2mS/awMhG76R6xhIwVn1noaw=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBncp8KHkZX2HmjvkvSfVcCRKBEp3FBrdm3nludZ oIe3H3flamJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ3KfCgAKCRD2t4JPQmmg c8UGD/9lFHuI4RQl7F1XBoHNtXW5cpvVqfi/4oV6cd0Jfc2MQO9PEtNfLHfy1Kg2rbCS8RJCkyC kI5fOO3bYxmk+Cg4hld0cr0d7yXx5ftiwO63f+C2RRK6VeKD+Lmefuh9UXGCM3vs4Q/+XQ0rMct LyhtLfWZflT8/RXe5/Fj/rgWjQF45q9bFpP8hlZ5/tIPDRC/sSt31w3k8lU6030p6fp+GZsHPs/ ay+n5W00T04Jk+/IoH6pr67LVvQgZHBxVCqPf5SCfUyZtrPVfAPRD2Mi3zfrHoZT07xBzm8Svpc SNRKRLDjt484FC4NwbA9c+BjOBpmFB0zAWy/f0Kso08qA7B9cktzxyNRp71uxaEpVsIBylY42Vn rUHmD3Kvc/Hy9Wo0gxY/+yWBSrBfv1c80V4NwpnE54ZSIVlE0aDQ1gtsoKWL+1sjimuxaE4GaTO NAIxsEWikVUFPTNOrRbC2PxRqOzsitsH9l1oe+ryoul8C6/ShaeqslI09NAZZD/jXqtN1LFfEc4 9oc2+i02+gOZ9mDxyKc7Ic3L57JYVtjeheHT3F8bFrRDnicDN3s7ZrS6gUXx8ISKBEmjBGE6IGR B8XeM6Rg8R0AEIsBZKqIIqLqaHHm44KFrK09jy0yAgnpA5ggafO50bjaC+SLbhaOiguavy7i7D8 Zsfsde8Sr0/95Mg== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang A more general way to check if MPTCP_PM_ATTR_* exists in 'info' is to use GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_*) instead of directly reading info->attrs[MPTCP_PM_ATTR_*] and then checking if it's NULL. So this patch uses GENL_REQ_ATTR_CHECK() for userspace PM in mptcp_pm_nl_announce_doit(), mptcp_pm_nl_remove_doit(), mptcp_pm_nl_subflow_create_doit(), mptcp_pm_nl_subflow_destroy_doit() and mptcp_userspace_pm_get_sock(). Suggested-by: Jakub Kicinski Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 2f82ac49db35ec34dcc0b9208f4ac12edc6ab254..d6595cf3d8f8f9d4e2fd5150503= 2ed2dc894738c 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -175,14 +175,13 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *= msk, =20 static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_in= fo *info) { - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct mptcp_sock *msk; + struct nlattr *token; =20 - if (!token) { - GENL_SET_ERR_MSG(info, "missing required token"); + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_TOKEN)) return NULL; - } =20 + token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; msk =3D mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token)); if (!msk) { NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); @@ -201,16 +200,14 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock= (const struct genl_info *in =20 int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *addr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry addr_val; struct mptcp_sock *msk; + struct nlattr *addr; int err =3D -EINVAL; struct sock *sk; =20 - if (!addr) { - GENL_SET_ERR_MSG(info, "missing required address"); + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR)) return err; - } =20 msk =3D mptcp_userspace_pm_get_sock(info); if (!msk) @@ -218,6 +215,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, stru= ct genl_info *info) =20 sk =3D (struct sock *)msk; =20 + addr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; err =3D mptcp_pm_parse_entry(addr, info, true, &addr_val); if (err < 0) { GENL_SET_ERR_MSG(info, "error parsing local address"); @@ -319,18 +317,17 @@ void mptcp_pm_remove_addr_entry(struct mptcp_sock *ms= k, =20 int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; struct mptcp_sock *msk; + struct nlattr *id; int err =3D -EINVAL; struct sock *sk; u8 id_val; =20 - if (!id) { - GENL_SET_ERR_MSG(info, "missing required ID"); + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_LOC_ID)) return err; - } =20 + id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; id_val =3D nla_get_u8(id); =20 msk =3D mptcp_userspace_pm_get_sock(info); @@ -373,19 +370,17 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, stru= ct genl_info *info) =20 int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info = *info) { - struct nlattr *raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry entry =3D { 0 }; struct mptcp_addr_info addr_r; + struct nlattr *raddr, *laddr; struct mptcp_pm_local local; struct mptcp_sock *msk; int err =3D -EINVAL; struct sock *sk; =20 - if (!laddr || !raddr) { - GENL_SET_ERR_MSG(info, "missing required address(es)"); + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR) || + GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE)) return err; - } =20 msk =3D mptcp_userspace_pm_get_sock(info); if (!msk) @@ -393,6 +388,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb= , struct genl_info *info) =20 sk =3D (struct sock *)msk; =20 + laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; err =3D mptcp_pm_parse_entry(laddr, info, true, &entry); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -406,6 +402,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb= , struct genl_info *info) } entry.flags |=3D MPTCP_PM_ADDR_FLAG_SUBFLOW; =20 + raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; err =3D mptcp_pm_parse_addr(raddr, info, &addr_r); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr"); @@ -498,18 +495,16 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_so= ck *msk, =20 int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info= *info) { - struct nlattr *raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry addr_l; struct mptcp_addr_info addr_r; + struct nlattr *raddr, *laddr; struct mptcp_sock *msk; struct sock *sk, *ssk; int err =3D -EINVAL; =20 - if (!laddr || !raddr) { - GENL_SET_ERR_MSG(info, "missing required address(es)"); + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR) || + GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE)) return err; - } =20 msk =3D mptcp_userspace_pm_get_sock(info); if (!msk) @@ -517,12 +512,14 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *= skb, struct genl_info *info =20 sk =3D (struct sock *)msk; =20 + laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; err =3D mptcp_pm_parse_entry(laddr, info, true, &addr_l); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); goto destroy_err; } =20 + raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; err =3D mptcp_pm_parse_addr(raddr, info, &addr_r); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr"); --=20 2.47.1 From nobody Sat Jan 4 23:01:12 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 0F3D81A9B27 for ; Mon, 30 Dec 2024 13:24:31 +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=1735565072; cv=none; b=VQhSl9MLziUZoWVeWbb0leULVfd5EBCxI7erdfxS8huQssYrpji4Ig5A/eUKT0lJAaFdIk+BVVn+CukzcfQFlRPW8nsYs/2NMWE8iqgXZND1Okv9Y3Ex/9a4frmbe58GBh7aPzFiYNMu7N7eySO027axI1GYcc9BsYh8y5JtIdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565072; c=relaxed/simple; bh=hrvA2kH30fANO2NkkdujBKZC6DPYfuVrTB8Zvum9+18=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uPE+mlPrfL1B4GB0DivOdQQW1HuiPJnNXH1D/Y0s8dD2iSFc0H5CgCgUSMkB2zJ8agTaSlooDeT0cHsJxp7S5kXj1+QSNyBCPR5KMrs3+VmBpXmRTlENK6ggiLVeARXVgSA+LOCg0oGlSjW8VcBj2mYG0yoJ/xjtzRyt3mRDM8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a9uGE31b; 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="a9uGE31b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07639C4CED2; Mon, 30 Dec 2024 13:24:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735565071; bh=hrvA2kH30fANO2NkkdujBKZC6DPYfuVrTB8Zvum9+18=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=a9uGE31behvwM7mp2KoCQnngrzYFMEX+OoV5BXdN/roqgf1VHYw19nbkForwCP6Tc iSSPXuobLqtuhSdfqfr8K8i6QLxZzNz+yYe6ucR5NBVvKCqBxHLhUoeGxbYNKNakzt tvM+KQXWuGBfuWlbQO+bNtQDbbymbHLUUvhtkE1DLOs51iRsBx4y3OjVhKS0VXqVJf jCG3KN4dKLfO1ACDA1xh1LYUm5mLNu4fL+QecbFUEzVLJZFFTNsaEvu+Xg4q32i36+ 9VkkR2mBeSrYpAj6TSP735pgGYaiSN47bzYKKfwRFvMMIu90BbXNluGFzXJmqvCPiw /R0veBZTaA+9A== From: "Matthieu Baerts (NGI0)" Date: Mon, 30 Dec 2024 14:24:13 +0100 Subject: [PATCH mptcp-next v6 6/7] mptcp: pm: remove duplicated error messages Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241230-genl_req_attr_check-v6-6-3ec9103559e7@kernel.org> References: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> In-Reply-To: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2681; i=matttbe@kernel.org; h=from:subject:message-id; bh=hrvA2kH30fANO2NkkdujBKZC6DPYfuVrTB8Zvum9+18=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBncp8K0YVqRsoHo/fpQKn6+9DRhoIxqVZQHofZu wKVtQfxx5aJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ3KfCgAKCRD2t4JPQmmg c4qZD/4ptvi7XpAPiQ1JJap3wruVHkRr5WBuu7X3Wp37VlV30xRZKju/vWEL/xWDXqXTINPM0VS ceLmVj9v+5kPzZ0ZXnpbjrEFBGmBvom+r+Xs6KkzdouVD2T5qGjS0NPvnI8x0bvWqzQt/XihM8I 5eCRh83swy0TmzOzCqum3eYgK/KS3iEQaHYYOSb6lzhljqYtMvKz2ZVLS8m0CFXm/MawHp4ZBoV V6mNceLdjzRWtKvrXpEbFUXr0fOPf4RM9+1t62wiCcKjekgpwGzmlniSXS99w7CaOuUUqJj9uQY G+ECso7X+AC9ZC/6akExKHWcLUPkUWyfeIGLobP6JnCOIr6+rx1YMGT6LRlhPKG7hry87rV/U2t wwfIUss2GqJi75GUQgVr9TSkxdw1wq2WqO9DFw28thF2gySbEGoZwjn4W4eBJH6GeQkLxswkODe 164LTRQbsZpCfLvx7OSgynLJEJyl8jViItAvjEQq/MjhtiottEz6UgeySQIqolMztYy8l17xmTI dNue8MFY2k8QAluKgl8XqXuK6hP5nFXuWk82t0fy/GhMPuaXZvBsPvjC2HlufrWO4WkZqLZfYBn qHhZ/otFL6LqGxSV52Nt0c0MJbRdKWRU5KngfMZfPl7gT2BhOuyxjntSfl2J+BgwnckBPk8wBfJ CkTabUzA7zqsUng== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 mptcp_pm_parse_entry() and mptcp_pm_parse_addr() will already set a error message in case of parsing issue. Then, no need to override this error message with another less precise one: "error parsing address". Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index d6595cf3d8f8f9d4e2fd51505032ed2dc894738c..51943ca6ddb607e1dfea393525c= ccf5cbed7cfac 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -217,10 +217,8 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, str= uct genl_info *info) =20 addr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; err =3D mptcp_pm_parse_entry(addr, info, true, &addr_val); - if (err < 0) { - GENL_SET_ERR_MSG(info, "error parsing local address"); + if (err < 0) goto announce_err; - } =20 if (addr_val.addr.id =3D=3D 0) { NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr id"); @@ -390,10 +388,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *sk= b, struct genl_info *info) =20 laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; err =3D mptcp_pm_parse_entry(laddr, info, true, &entry); - if (err < 0) { - NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); + if (err < 0) goto create_err; - } =20 if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "invalid addr flags"); @@ -404,10 +400,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *sk= b, struct genl_info *info) =20 raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; err =3D mptcp_pm_parse_addr(raddr, info, &addr_r); - if (err < 0) { - NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr"); + if (err < 0) goto create_err; - } =20 if (!mptcp_pm_addr_families_match(sk, &entry.addr, &addr_r)) { GENL_SET_ERR_MSG(info, "families mismatch"); @@ -514,17 +508,13 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *= skb, struct genl_info *info =20 laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; err =3D mptcp_pm_parse_entry(laddr, info, true, &addr_l); - if (err < 0) { - NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); + if (err < 0) goto destroy_err; - } =20 raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; err =3D mptcp_pm_parse_addr(raddr, info, &addr_r); - if (err < 0) { - NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr"); + if (err < 0) goto destroy_err; - } =20 #if IS_ENABLED(CONFIG_MPTCP_IPV6) if (addr_l.addr.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_r.addr6= )) { --=20 2.47.1 From nobody Sat Jan 4 23:01:12 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 AF0B11A9B32 for ; Mon, 30 Dec 2024 13:24:32 +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=1735565072; cv=none; b=UZaqMX2BO/aBFtCiQf6EEwgoxz/muKPpf8khy/U67AfdtY7Q/I+eU3NSX4lDsSinFl2KrRjbYfe3vUyqz9gtVYhSysYbeRJYQdd57bIOAtZBXcsgLwCnhXG2zK4p/xSoWNa7TpV8xHlEkf65Sm9i89t4hqIP6Dpx8BQKHvCQqdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565072; c=relaxed/simple; bh=qG9KX7q0Egfe+Y0A5OUlue3yr+URZ6TAi5q24fBvYbg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AXr9C9FK9031qhlWFDkQkaptQZ4wxFHZ2xNQ1a8Ga0MPQPsoIsm9YRqjhcNolDF5NS+mcAtoBa2Ys2ylYeb+QK5AzsV2Fm+eKoMNqjBwBJD6eYjnieFnbpKX7jCi/bXLG6v8PFP41D8vfr/Ez1ZlSNlhwYaUsKbL1cOCoBDaAmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mJRf+AEF; 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="mJRf+AEF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05A9BC4CED0; Mon, 30 Dec 2024 13:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735565072; bh=qG9KX7q0Egfe+Y0A5OUlue3yr+URZ6TAi5q24fBvYbg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mJRf+AEFFvvcIPAUE/p0yogDJxr92YHUDOgDwwcckW1877LQwTQdFVnhHkaGIy/8w DXDulcazU6cNSHIb454eXe/Lb9OG0jdjHcL2fMzSc8uccgSjlWMYN4qeC+fz6WBy7D 6moFVt+HkyTIsMsL4IIXb87b7w1oaCxnWcLePxj/uril6zZHtdtYfIe+7ddCS+W35Y Nv3qYtGZNABmltkSUy7vaA9zS4Fw5nfYUnDRQVTh3t64OFbh0ppwX6wtPoSQzWQ3sy uOkpSCCLDlskBk1a//vL2rSePb5urxrllqR4djNakKbLorktgmGVSiLjBCXkAkhKa/ AEE9Soj6hmAvg== From: "Matthieu Baerts (NGI0)" Date: Mon, 30 Dec 2024 14:24:14 +0100 Subject: [PATCH mptcp-next v6 7/7] mptcp: pm: mark missing address attributes Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241230-genl_req_attr_check-v6-7-3ec9103559e7@kernel.org> References: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> In-Reply-To: <20241230-genl_req_attr_check-v6-0-3ec9103559e7@kernel.org> To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6102; i=matttbe@kernel.org; h=from:subject:message-id; bh=qG9KX7q0Egfe+Y0A5OUlue3yr+URZ6TAi5q24fBvYbg=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBncp8KTQv5s7mFJWefiKEWzQiqlScPe2E8ui/le DxiW8M+AMSJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ3KfCgAKCRD2t4JPQmmg c1hTEAC2fifDJYjrpQlHzNmwKeC849244UQMr5SAhcpkTKaUr785I7fQT54DMIqMB9Vc0zvUaul xnwfW9FA7ndrFc8WRnCd9Xo986CPhuxwCdJVuTpW7t/ETCxMBcP5D23a62FWFMqxLZrV5RWJtHU frtSvlbxN6n0u/YAxXjSe2WtAwUuYDospyIUW8OqUKoqE0Vm1kweD1Sq48qqw4XqZZAGiu4JT2p ksmpHPwrlYD8MgamMSWLjbrFMXBdPJsc6S94JrbdVSdugz2TIbArjIBFy0jYWQ0Lx+yEfETHcVY Dk+jkqiUL5VS+XKNDRkGkUoEPMi7DDyt+tT491W9Lxy4bvUL1EJprjqShzXzqxvrJmg0/jjDjnR F+rBsUova3BurDL77OQRAA1HbL7S3z2fFa6Kn2rMK2+WptKv1oiguaNhFJSenpLN0/qdyd9jtIw RZKNJlEOp921JEHGRxBWYVEd3XVqPtE9sGr5jfY2kDoHb7dnKBS/YzD4T41pTpF/fa3BWOlbkYt lbi9lcJyhzM3IlybeDetkG3DjyE0zdQqvL81USepKt0amJxODdFmbM7VXd72689KFnKlQ4vJ0dK w1b0zjBuPJRy0os6AkfAqlDrUgwNCcGIvPFS/t7VHha9cB85dft9XT6dkroNYdLfQR3YMIrR5dL S7gudptMFq67joQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 mptcp_pm_parse_entry() will check if the given attribute is defined. If not, it will return a generic error: "missing address info". It might then not be clear for the userspace developer which attribute is missing, especially when the command takes multiple addresses. By using GENL_REQ_ATTR_CHECK(), the userspace will get a hint about which attribute is missing, making thing clearer. Note that this is what was already done for most of the other MPTCP NL commands, this patch simply adds the missing ones. Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_netlink.c | 26 +++++++++++++++++++++----- net/mptcp/pm_userspace.c | 15 ++++++++++++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 3bb213e2a967e87d4244dc0f1ba58d3ba21fb371..1eaaf91eb978b5e85dd5fc11d61= 6ba48809e2915 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1393,11 +1393,15 @@ static bool mptcp_pm_has_addr_attr_id(const struct = nlattr *attr, =20 int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, 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 nlattr *attr; int ret; =20 + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR)) + return -EINVAL; + + attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; ret =3D mptcp_pm_parse_entry(attr, info, true, &addr); if (ret < 0) return ret; @@ -1590,12 +1594,16 @@ static int mptcp_nl_remove_id_zero_address(struct n= et *net, =20 int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, 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; unsigned int addr_max; + struct nlattr *attr; int ret; =20 + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR)) + return -EINVAL; + + attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; @@ -1767,13 +1775,17 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, =20 int mptcp_pm_nl_get_addr(struct sk_buff *skb, 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 sk_buff *msg; + struct nlattr *attr; void *reply; int ret; =20 + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR)) + return -EINVAL; + + attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; @@ -1989,18 +2001,20 @@ static int mptcp_nl_set_flags(struct net *net, int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) { struct mptcp_pm_addr_entry addr =3D { .addr =3D { .family =3D AF_UNSPEC }= , }; - struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; u8 changed, mask =3D MPTCP_PM_ADDR_FLAG_BACKUP | MPTCP_PM_ADDR_FLAG_FULLMESH; struct net *net =3D sock_net(skb->sk); struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; + struct nlattr *attr; u8 lookup_by_id =3D 0; u8 bkup =3D 0; int ret; =20 - pernet =3D pm_nl_get_pernet(net); + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR)) + return -EINVAL; =20 + attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; @@ -2017,6 +2031,8 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct= genl_info *info) if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup =3D 1; =20 + pernet =3D pm_nl_get_pernet(net); + spin_lock_bh(&pernet->lock); entry =3D lookup_by_id ? __lookup_addr_by_id(pernet, addr.addr.id) : __lookup_addr(pernet, &addr.addr); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 51943ca6ddb607e1dfea393525cccf5cbed7cfac..f5515b2305f41fafa7ef0627ed8= 38b9d0db14aa9 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -570,20 +570,24 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb,= struct genl_info *info) { struct mptcp_pm_addr_entry loc =3D { .addr =3D { .family =3D AF_UNSPEC },= }; struct mptcp_pm_addr_entry rem =3D { .addr =3D { .family =3D AF_UNSPEC },= }; - struct nlattr *attr_rem =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry *entry; + struct nlattr *attr, *attr_rem; struct mptcp_sock *msk; int ret =3D -EINVAL; struct sock *sk; u8 bkup =3D 0; =20 + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR) || + GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE)) + return ret; + msk =3D mptcp_userspace_pm_get_sock(info); if (!msk) return ret; =20 sk =3D (struct sock *)msk; =20 + attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; ret =3D mptcp_pm_parse_entry(attr, info, false, &loc); if (ret < 0) goto set_flags_err; @@ -595,6 +599,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, s= truct genl_info *info) goto set_flags_err; } =20 + attr_rem =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; ret =3D mptcp_pm_parse_entry(attr_rem, info, false, &rem); if (ret < 0) goto set_flags_err; @@ -683,20 +688,24 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, int mptcp_userspace_pm_get_addr(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct mptcp_pm_addr_entry addr, *entry; struct mptcp_sock *msk; struct sk_buff *msg; + struct nlattr *attr; int ret =3D -EINVAL; struct sock *sk; void *reply; =20 + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR)) + return ret; + msk =3D mptcp_userspace_pm_get_sock(info); if (!msk) return ret; =20 sk =3D (struct sock *)msk; =20 + attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) goto out; --=20 2.47.1