From patchwork Fri Jan 10 07:30:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13933877 X-Patchwork-Delegate: matthieu.baerts@tessares.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 298AC14A08E for ; Fri, 10 Jan 2025 07:30:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494251; cv=none; b=dgYeP4IHVYtHfMTtohzp1obCY+kB7S6rnmHe2j8TRhlOcWDo201cF8AiCdYKEJxK8c7VquYKJVHRaCCH1HXtN4ABRFaTRtwTkqVgkwVfwYQiKUN0PBQ76YvEfdAuJ2yvuwWM7Thg1NJ03mO5WpKBxrCdSVHSkDXQ6OqrdmAhylc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494251; c=relaxed/simple; bh=5ZwuEaCyrh7/4JVc+sYIO1AdjSTMJWmfCVu+Im7GrHc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uVJvShbFcFOP1m3k1hFnRfdKpTjXFnVlXPSwaKbg6tUADY03BDCk69DUsrfWIkjF0PmvDlDZMxub+jz073pQxqU68SHpZ+GYujANAMH7tQ4NSMhqHbcSQu+C7D2QhdAvqoUW5dQRoZ+HSHrNGnOWan171tTi2OTaVUK/9F84k6s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZMrdcn9v; 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="ZMrdcn9v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74FA7C4CED6; Fri, 10 Jan 2025 07:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736494250; bh=5ZwuEaCyrh7/4JVc+sYIO1AdjSTMJWmfCVu+Im7GrHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZMrdcn9vMpcJFyynlpPaepYssa8EZRLkbc2AGRcwbTGNN1guRbkLAI1OncsNMJuW/ vbFxDUOfD3YENTKfur01Hj1Ur5wJY1BtpfaVDQjTrlYvs/ET7dF19kxSKRLt1C9V2J T+LR0Sl2HYf1o1HJflmrEr6Tg7c6rAtF6NECwltv4wc3Za9QaaFl766zTShojWNCY0 dMmaVD16sFSdzyfw6bqSJeQlO1I6CKMPCFHstNF8v0oOeBnHWhbcPRY1UQPstro1zu /K5Ya68wf7iAlgSIX/R/LygxrYz9C7M6U95T39tsDWzO05NeDyK6iI4mr4kcB04jJW MahcgGDuK3W2Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v9 1/8] mptcp: drop info of userspace_pm_remove_id_zero_address Date: Fri, 10 Jan 2025 15:30:35 +0800 Message-ID: <1a96bdebb079188a862447a2bb0983be12bd8320.1736493803.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang The only use of 'info' parameter of userspace_pm_remove_id_zero_address() is to set an error message into it. Plus, this helper will only fail when it cannot find any subflows with a local address ID 0. This patch drops this parameter and sets the error message where this function is called in mptcp_pm_nl_remove_doit(). Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index a3d477059b11..4de38bc03ab8 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -253,8 +253,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) return err; } -static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk, - struct genl_info *info) +static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk) { struct mptcp_rm_list list = { .nr = 0 }; struct mptcp_subflow_context *subflow; @@ -269,10 +268,8 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk, break; } } - if (!has_id_0) { - GENL_SET_ERR_MSG(info, "address with id 0 not found"); + if (!has_id_0) goto remove_err; - } list.ids[list.nr++] = 0; @@ -330,7 +327,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) sk = (struct sock *)msk; if (id_val == 0) { - err = mptcp_userspace_pm_remove_id_zero_address(msk, info); + err = mptcp_userspace_pm_remove_id_zero_address(msk); goto out; } @@ -339,7 +336,6 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) spin_lock_bh(&msk->pm.lock); match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); if (!match) { - GENL_SET_ERR_MSG(info, "address with specified id not found"); spin_unlock_bh(&msk->pm.lock); release_sock(sk); goto out; @@ -356,6 +352,11 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) err = 0; out: + if (err) + GENL_SET_ERR_MSG_FMT(info, + "address with id %u not found", + id_val); + sock_put(sk); return err; } From patchwork Fri Jan 10 07:30:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13933878 X-Patchwork-Delegate: matthieu.baerts@tessares.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E384514A08E for ; Fri, 10 Jan 2025 07:30: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=1736494253; cv=none; b=PqHtA0g5C5x78JQfQJaMm+dH7liCQM9onUgLS8Sr2I1LU7XCBnQDwN7hNYdXrVYICRTCDnAuW+EUz5+M5QnnFI1uKycmtt/Ra3iBomGz3U2lD1wB2u6Gasq75W6HrsjNwbdiYLD8c/z4CmbPyH/Y7FUI1+7UO9dFsQ6wiTTCZrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494253; c=relaxed/simple; bh=cQ5/ht1MhEKJnGUiCvumlLsoSzZ7WkaoBBdCe30201g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P4AmC4nl1X09ze40CcdP1dJM1ML9DEqXkwca72cwhvd364c9hEbfRf15Fhv40Ypg6nTQwfQOv39L/6bjXgYnKJf6bKijsT3c+32/QfihgJJ9DDy/vpFJJaGZB4V9s+ES0JZ9ptp+3FDJXUbZlhFrw0YTtK/6nSPKNw40rfTVTJ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XVSuY1ww; 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="XVSuY1ww" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D35CC4CED6; Fri, 10 Jan 2025 07:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736494252; bh=cQ5/ht1MhEKJnGUiCvumlLsoSzZ7WkaoBBdCe30201g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XVSuY1wwdNx8hh+oUVbyJBxOWd7lVPJvnkoBKpiVpNXFdVbnWjcxhfd72qYiOueNO mrhDo1zAM4Ic4wrpc5a+Ja5sRVKVsTtp156C3+jh/M2ChEyHT5mtXiP15xOoDb+VI8 QmNufjsDfYLKiv7okMFj1vREPfhoSGqCh7IxVgLvgfylMfOvdPMM/D///Wdim0G5om QviYbFTd/YKcTbamgGdvrehsshQ06srKSL04tpTU7nDlEJTHirvGQ0XY2245k7lX75 qfuxpBFP2SGSjUc3jkzoI1r+aKQfnqMTzrZUdG6kb+lBT++GSyrwTQa14JNSjpDBHe BD76RcZZL2Wfg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" Subject: [PATCH mptcp-next v9 2/8] mptcp: pm: userspace: flags: clearer msg if no remote addr Date: Fri, 10 Jan 2025 15:30:36 +0800 Message-ID: <3a900efc2b0b26c6d63d6e932672677f0336abf1.1736493803.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Matthieu Baerts (NGI0)" 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 == 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. Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 4de38bc03ab8..b6cf8ea1161d 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -580,11 +580,9 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) 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; - } + 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) { From patchwork Fri Jan 10 07:30:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13933879 X-Patchwork-Delegate: matthieu.baerts@tessares.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF7AD14A08E for ; Fri, 10 Jan 2025 07:30:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494254; cv=none; b=ndCMXnjodoCWfpw/3LuyIwdnReWMhOElhtn3zUKfJ8xWqZ63S13q0sfS2TygZTdOYszVSvDNLJ2GhBaFffjIPeL3olBekrwaOokPi6rXkjxA7ZpcnhcswgEJQqgac/lkLoF8bbeuiZ4AzX9c/MZid6F5ThH28dlCOGKxv+RCGa4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494254; c=relaxed/simple; bh=RD9pZ0XTea6TSP8rZSY/4A9M07ardPO+MyZfBNc5Bi4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HbVTuVd8FBHydmz/wHjBxc63tr6EPuxiw4tUDakO5B099PAAtzqPnHB63sjfpvzijuy4STVE0xfInWuoiBEw3PIsKuw4Oevp66eu3z9njz2SrBYCqNXuw7rLmY0XrEPh63RQySzMBD+MdOrmBWPJVAg0hcUqymYq5JFyZkhHiJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PTlBGECD; 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="PTlBGECD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26EE4C4CEDF; Fri, 10 Jan 2025 07:30:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736494254; bh=RD9pZ0XTea6TSP8rZSY/4A9M07ardPO+MyZfBNc5Bi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PTlBGECDlmXwVox9hdS/Qd+5I8hfXZvSZBAOeQDYyA6u/9PutbeF2yffpnnsP7o6d leypqZmVrP4ErYvjUVGqtA5ICAh2hZuklB+JAqt8jnqYGZubND3UaobIkFmOV1bxDy OiGszbZwhMBJFF7UT1ThpfdE0zue72XIj71knVkSgOBqDtYOThRu8bn+meXJijhWMM GO3kPZQ5Lm5gpy/RwMf1bOIlmKJcrPrUM5maf6c8C7gQ4X/0mrCVxJW6T8yY/joXQ0 Iw9h+H8WB4HhjfNtHzEoqnbsjwxE9vwv3V6Qj5PzVtPFgFN3Fs1fP3uUORtm541mpP lS20W0IXVFLtA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" Subject: [PATCH mptcp-next v9 3/8] mptcp: pm: more precise error messages Date: Fri, 10 Jan 2025 15:30:37 +0800 Message-ID: <006da446a1eadc361b68ad559e42a32f8a1c0873.1736493803.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Matthieu Baerts (NGI0)" 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. While at it, in mptcp_userspace_pm_set_flags() move the parsing after the check linked to the local attribute. Signed-off-by: Matthieu Baerts (NGI0) --- v2: - move the code using NL_SET_ERR_MSG_ATTR into patch 8. --- net/mptcp/pm_userspace.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index b6cf8ea1161d..cdc83fabb7c2 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -223,8 +223,14 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) goto announce_err; } - if (addr_val.addr.id == 0 || !(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { - GENL_SET_ERR_MSG(info, "invalid addr id or flags"); + if (addr_val.addr.id == 0) { + GENL_SET_ERR_MSG(info, "invalid addr id"); + err = -EINVAL; + goto announce_err; + } + + if (!(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { + GENL_SET_ERR_MSG(info, "invalid addr flags"); err = -EINVAL; goto announce_err; } @@ -531,8 +537,14 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info goto destroy_err; } - if (!addr_l.addr.port || !addr_r.port) { - GENL_SET_ERR_MSG(info, "missing local or remote port"); + if (!addr_l.addr.port) { + GENL_SET_ERR_MSG(info, "missing local port"); + err = -EINVAL; + goto destroy_err; + } + + if (!addr_r.port) { + GENL_SET_ERR_MSG(info, "missing remote port"); err = -EINVAL; goto destroy_err; } @@ -580,13 +592,18 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) if (ret < 0) goto set_flags_err; + if (loc.addr.family == AF_UNSPEC) { + GENL_SET_ERR_MSG(info, "invalid local address family"); + ret = -EINVAL; + goto set_flags_err; + } + 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) { - GENL_SET_ERR_MSG(info, "invalid address families"); + if (rem.addr.family == AF_UNSPEC) { + GENL_SET_ERR_MSG(info, "invalid remote address family"); ret = -EINVAL; goto set_flags_err; } From patchwork Fri Jan 10 07:30:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13933880 X-Patchwork-Delegate: matthieu.baerts@tessares.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5813814A08E for ; Fri, 10 Jan 2025 07:30:56 +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=1736494256; cv=none; b=BjVep9n81+qnSpGp9lGmaABCiic5SadaWsi4fQZwxxbYOFPwIEHaGtyhJ+mwyWR1ZVBusDDfHN+sYUuVxf8NkONcfLcoyEi3foOW1qS7bAxb7PfKg5NBBxfmsi0nKARYbnr8dY5d7xPOs/um5IlvXhNzqUhom1HcMwpCkAHvN8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494256; c=relaxed/simple; bh=Bs2qqRlQwp4MNUE9DrajrFyHEaBIDfBm4ktap5SzAYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EoBk6HzIo7DyOi+Aa7h0wsY5idOfERIadmVaD/B3VbwLuuVh81/t9H2+urZpl8c45OF42oJz6XL+OJ6/8qfAANReX1U9L8lXFUuCjpI/nAa1lx+iMBAEB2j+EPFmHPNHHBFsBuVWt/9hYH/eWhtj0BiOCKpCqVY9PAv//mZmPhI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jt0nFbbG; 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="jt0nFbbG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0053EC4CED6; Fri, 10 Jan 2025 07:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736494255; bh=Bs2qqRlQwp4MNUE9DrajrFyHEaBIDfBm4ktap5SzAYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jt0nFbbGGF6Kg//4J7tOu4Kyhdp+p/YldW9/Y0WSghFw85Mm9oUx+VDG6dTE3AP57 WPpEYL6YLJ3d9GeMwCQvenUP09yQ/KN0h7BIElTDpBLnjwNbDeRmgoR9zVT4tf4W2q tVvCObz2ivI191A1IbsJuHpdJVxuZ7IlivGVSnbxD6Y8HX+TBWLm3aJrJe6bNL1Hj1 ZCBARCTPwu85PjsvUpcsZEnhgPZK7Ren+Yvd1IxeW7ehraO+sUw5XOMbUrKcas4gsj FtL6eJdkQjj5ikMBs2vf5SabUPGVOeuyQB3sxpCGMi/r9GmZkAVcqQnp9mZRI4et86 nNBmwhYWDN+jg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" Subject: [PATCH mptcp-next v9 4/8] mptcp: pm: improve error messages Date: Fri, 10 Jan 2025 15:30:38 +0800 Message-ID: <43c16e82cdcf607e8dc8ebc19d033bbc364e06f3.1736493803.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Matthieu Baerts (NGI0)" 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) --- v2: add a comment in mptcp_userspace_pm_set_flags(). --- net/mptcp/pm_netlink.c | 6 ++++-- net/mptcp/pm_userspace.c | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 98ac73938bd8..a60217faf95d 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1875,7 +1875,9 @@ static int parse_limit(struct genl_info *info, int id, unsigned int *limit) *limit = nla_get_u32(attr); if (*limit > MPTCP_PM_ADDR_MAX) { - GENL_SET_ERR_MSG(info, "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; @@ -2003,7 +2005,7 @@ 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) { - GENL_SET_ERR_MSG(info, "missing required inputs"); + GENL_SET_ERR_MSG(info, "missing address ID"); return -EOPNOTSUPP; } } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index cdc83fabb7c2..e350d6cc23bf 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -190,7 +190,7 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in } if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); + GENL_SET_ERR_MSG(info, "userspace PM not selected"); sock_put((struct sock *)msk); return NULL; } @@ -428,6 +428,9 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) err = __mptcp_subflow_connect(sk, &local, &addr_r); release_sock(sk); + 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); @@ -552,6 +555,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info lock_sock(sk); ssk = mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r); if (!ssk) { + GENL_SET_ERR_MSG(info, "subflow not found"); err = -ESRCH; goto release_sock; } @@ -625,6 +629,10 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup); release_sock(sk); + /* mptcp_pm_nl_mp_prio_send_ack() only fails in one case */ + if (ret < 0) + GENL_SET_ERR_MSG(info, "subflow not found"); + set_flags_err: sock_put(sk); return ret; From patchwork Fri Jan 10 07:30:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13933881 X-Patchwork-Delegate: matthieu.baerts@tessares.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4DD314A08E for ; Fri, 10 Jan 2025 07:30:58 +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=1736494259; cv=none; b=q5nVrbuR/B2dWLZIDWzDbqYkSAtA6uXP6TsYfX8Fsd8nwNC2yWvtCDQj/VyeHInwEM/JtWHHlvOWm+7t2eDJ3+JGEEnke4l5TzlxMIfBrnrZiJM4IuVYI20yPbzs6Vr/WiUTza4Tij6xKVIiW25RtIdA+DPTm2FeoVJqNF7Pn+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494259; c=relaxed/simple; bh=/v343bsB/x4ZR18kN71yaHGjwhOk50DZDpL64LPrQMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NUaaA6xM/YNYlbXExretU3bBV+GNPsiWRuZIkGlDFgALf7NZnjFQ5sOyFv4ncx5YTajbHG8ApzsEti95Pt263SZfJWd9ZF/CzGuv6uEy+iD2AhmTpZ1BM/aKNAWbhQNNk5KZA+zELJztWDzZpzmDeDHQ2BGFAcR4/SmyGiVq8Jc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=unWsqDZ+; 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="unWsqDZ+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8B10C4CEDF; Fri, 10 Jan 2025 07:30:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736494258; bh=/v343bsB/x4ZR18kN71yaHGjwhOk50DZDpL64LPrQMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=unWsqDZ+tl7rqRcU9pjvKV2x3RQr9JfYLfLj5FoCsbl7LXf6k+JxzBDyhOKKQuP2N P7uSwJXJ1v0izIyjt9Ux+CaNHcswWWi6QwjSTIZnITG9FDhSb80TKjgSbgzA+Obezv HRy5cgg09U9qeDi80SsZbz2xO9W0eAK+2CotRWhV4+MlrfFJBOnyzu0qmTVJoWMTZ7 jXMUBzCr4MF3TTpyL3MEYr7sfeDMWe8oQs2JGiTwoxC7DZWi1YJtpByEKxNATrv4aG fjQiXolbATM6MpBcqK6+B2DrCGpO0EaqClm37Q+B//gO0sLE5/bLAwOQJXH4vvNc4x bfFg2/UWG2VwA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Matthieu Baerts Subject: [PATCH mptcp-next v9 5/8] mptcp: pm: userspace: use GENL_REQ_ATTR_CHECK Date: Fri, 10 Jan 2025 15:30:39 +0800 Message-ID: <1c97e5116246d09f8978d0355a84b434bf829231.1736493803.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang 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 e350d6cc23bf..4cbd234e2670 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, static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info) { - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct mptcp_sock *msk; + struct nlattr *token; - if (!token) { - GENL_SET_ERR_MSG(info, "missing required token"); + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_TOKEN)) return NULL; - } + token = info->attrs[MPTCP_PM_ATTR_TOKEN]; msk = mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token)); if (!msk) { NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); @@ -200,16 +199,14 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry addr_val; struct mptcp_sock *msk; + struct nlattr *addr; int err = -EINVAL; struct sock *sk; - if (!addr) { - GENL_SET_ERR_MSG(info, "missing required address"); + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR)) return err; - } msk = mptcp_userspace_pm_get_sock(info); if (!msk) @@ -217,6 +214,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) sk = (struct sock *)msk; + addr = info->attrs[MPTCP_PM_ATTR_ADDR]; err = mptcp_pm_parse_entry(addr, info, true, &addr_val); if (err < 0) { GENL_SET_ERR_MSG(info, "error parsing local address"); @@ -312,18 +310,17 @@ void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; struct mptcp_sock *msk; + struct nlattr *id; int err = -EINVAL; struct sock *sk; u8 id_val; - if (!id) { - GENL_SET_ERR_MSG(info, "missing required ID"); + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_LOC_ID)) return err; - } + id = info->attrs[MPTCP_PM_ATTR_LOC_ID]; id_val = nla_get_u8(id); msk = mptcp_userspace_pm_get_sock(info); @@ -369,19 +366,17 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry entry = { 0 }; struct mptcp_addr_info addr_r; + struct nlattr *raddr, *laddr; struct mptcp_pm_local local; struct mptcp_sock *msk; int err = -EINVAL; struct sock *sk; - 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; - } msk = mptcp_userspace_pm_get_sock(info); if (!msk) @@ -389,6 +384,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) sk = (struct sock *)msk; + laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; err = mptcp_pm_parse_entry(laddr, info, true, &entry); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -402,6 +398,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) } entry.flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW; + raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; err = mptcp_pm_parse_addr(raddr, info, &addr_r); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr"); @@ -493,18 +490,16 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk, int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *laddr = 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 = -EINVAL; - 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; - } msk = mptcp_userspace_pm_get_sock(info); if (!msk) @@ -512,12 +507,14 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info sk = (struct sock *)msk; + laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; err = 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; } + raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; err = mptcp_pm_parse_addr(raddr, info, &addr_r); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr"); From patchwork Fri Jan 10 07:30:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13933882 X-Patchwork-Delegate: matthieu.baerts@tessares.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8556614A08E for ; Fri, 10 Jan 2025 07:31:00 +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=1736494261; cv=none; b=r1EjVsCOzbf2onmdEjsAEZTQvUUKYHUZe2RitX/XC0yxshGqLrKEzvN3MLhvJ9CvuGwTnz43lQj+HsGm6xslBvSnjiwUCDlR6InWx/SEa1R5EAxY3EthGzXFzTh6AqgpDMt6wiiIg3is3bN7tLR2Ti3Enc2Tvs0kNPciJ8M90b8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494261; c=relaxed/simple; bh=ryqPfoq5MUEionftiSxy5wiw4TKIMxx5kI/KWhc7des=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RNm3NRiYRsqO5aA2UHYf/NeqX8PpaZPY/YabaUAnMivOkFi1W0M1XC0cGH4j5XOJHsWD0yUmUwRli4oJBFGCI87kt03vvN0CxL5zwcw6LvixnRSRyit5Y8zsmcp/s2gvWTqcwT/nbgs+hcI4lCy+fquMq+xwzYwVo8vCdDQVN9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mbMc3fvE; 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="mbMc3fvE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8647C4CEE1; Fri, 10 Jan 2025 07:30:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736494260; bh=ryqPfoq5MUEionftiSxy5wiw4TKIMxx5kI/KWhc7des=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mbMc3fvEQqChytPZKAOFTtSkFMf6R4/5clGtlcrYUoEP6o13TpUz9/Zzxk61b3T0Z tNxmgHHE05OiUdb6R58EXoG4OI6BYQ3yWZdf0dKqMLVy9BE32BieryJLLp1a43ntN+ QndwupXt4rSMHE7vjkDJwXcfPHBg74rkFfnCQu8tD4qqjD/FzfCRpx1RLkP7Nd/zXJ gfkb9ZueMMDiNJR3+G7tFJ13JOt9o4xysrgM0PxXBcWC/y/t4pVI7qxp8W8ilCSgqw LIQ9RPb24Nkj8n2bQC9oY8kOwVC6yLikYMMZIUYMrW32Z6hil6Q3L2RC1odhGsoGuG 5GpIZtjV331yQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" Subject: [PATCH mptcp-next v9 6/8] mptcp: pm: remove duplicated error messages Date: Fri, 10 Jan 2025 15:30:40 +0800 Message-ID: <68f944b4629c58878753458a445ee0281d8e2108.1736493803.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Matthieu Baerts (NGI0)" 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 4cbd234e2670..ab915716ed41 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -216,10 +216,8 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) addr = info->attrs[MPTCP_PM_ATTR_ADDR]; err = 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; - } if (addr_val.addr.id == 0) { GENL_SET_ERR_MSG(info, "invalid addr id"); @@ -386,10 +384,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; err = 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; - } if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) { GENL_SET_ERR_MSG(info, "invalid addr flags"); @@ -400,10 +396,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; err = 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; - } if (!mptcp_pm_addr_families_match(sk, &entry.addr, &addr_r)) { GENL_SET_ERR_MSG(info, "families mismatch"); @@ -509,17 +503,13 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; err = 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; - } raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; err = 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; - } #if IS_ENABLED(CONFIG_MPTCP_IPV6) if (addr_l.addr.family == AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) { From patchwork Fri Jan 10 07:30:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13933883 X-Patchwork-Delegate: matthieu.baerts@tessares.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C44A014A08E for ; Fri, 10 Jan 2025 07:31:01 +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=1736494261; cv=none; b=eHzEEnJCs020PoSJ2yLyxkPxi4lB5UuSHE+8C6oyH/8Lt0NCFxk0Dg3nEUYaCr5zVIL1J7itpR2wqKEAqeVIVaLQxiCyzAmTab0iEEQIIGakWbdaPk66rVJt9/fq4lBqWYKyvZkHYizLNRW8aamyEcBzDMt6L4YG0ZIbBYuIkNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494261; c=relaxed/simple; bh=uhxkRIWXQ7oz9UJ0VUzTpxyDa7ODYZRzDIu/F0VpZiQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tpX1IiCBTU2wHGzkuCtUhsweqc1/1lwQkKfNf6Qewk9LZolYKxCqQN373cuzoh7hz8O5iftnpsiytN4SUYxPMpap9veV+99O6JiOjeizE8OzzFEkYGDLnR8StEc7WtmzfElxo/KlTz7eYweVsIRTesfm0Qd1xXfZH7nn78oVTD8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TTWfXF3f; 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="TTWfXF3f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B44CFC4CED6; Fri, 10 Jan 2025 07:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736494261; bh=uhxkRIWXQ7oz9UJ0VUzTpxyDa7ODYZRzDIu/F0VpZiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TTWfXF3f3dbohsg5URChNXksIGgtAFkWPFBtwE4vYzhiRmlUEj6ytqQap9GeVMYR9 vo8S8Hse7Rk5xxZ4LgBunHBtYHM9iBH4gTPyhC0ZVhrHRYsC2LpWoBTWe7etPs2iGt ZVlAxsAmSW96rSKHHJATg4J+Wi9LYS5kWCZF60XM8FkoMGWDsIOX1QimSlmd7/SdDF F3G+iVwF68mFtdrx1Un6YfX0EJYM39ojQ9JtwVofvs94Ij8CC1o5w69Uiz4lrbd9An wqFKyit662WpOqw2bDReGF5BPFlrOxnp34u+k/84DmTtUJCf3AnSXHfulnwgmS3QNm XSgZFooWsnISQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" Subject: [PATCH mptcp-next v9 7/8] mptcp: pm: mark missing address attributes Date: Fri, 10 Jan 2025 15:30:41 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Matthieu Baerts (NGI0)" 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) --- v3: - adjust the location of "pernet = pm_nl_get_pernet(net);". v2: - keep "pernet = pm_nl_get_pernet(net);" at the beginning of mptcp_pm_nl_set_flags(). --- net/mptcp/pm_netlink.c | 24 ++++++++++++++++++++---- net/mptcp/pm_userspace.c | 15 ++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index a60217faf95d..ab56630b1d9c 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, int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet = genl_info_pm_nl(info); struct mptcp_pm_addr_entry addr, *entry; + struct nlattr *attr; int ret; + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR)) + return -EINVAL; + + attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; ret = mptcp_pm_parse_entry(attr, info, true, &addr); if (ret < 0) return ret; @@ -1587,12 +1591,16 @@ static int mptcp_nl_remove_id_zero_address(struct net *net, int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet = genl_info_pm_nl(info); struct mptcp_pm_addr_entry addr, *entry; unsigned int addr_max; + struct nlattr *attr; int ret; + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR)) + return -EINVAL; + + attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; ret = mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; @@ -1764,13 +1772,17 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet = genl_info_pm_nl(info); struct mptcp_pm_addr_entry addr, *entry; struct sk_buff *msg; + struct nlattr *attr; void *reply; int ret; + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR)) + return -EINVAL; + + attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; ret = mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; @@ -1986,18 +1998,22 @@ 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 = { .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 net *net = sock_net(skb->sk); struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; + struct nlattr *attr; u8 lookup_by_id = 0; u8 bkup = 0; int ret; + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR)) + return -EINVAL; + pernet = pm_nl_get_pernet(net); + attr = info->attrs[MPTCP_PM_ATTR_ADDR]; ret = mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index ab915716ed41..525dcb84353f 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -565,20 +565,24 @@ 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 *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry *entry; + struct nlattr *attr, *attr_rem; struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; u8 bkup = 0; + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR) || + GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE)) + return ret; + msk = mptcp_userspace_pm_get_sock(info); if (!msk) return ret; sk = (struct sock *)msk; + attr = info->attrs[MPTCP_PM_ATTR_ADDR]; ret = mptcp_pm_parse_entry(attr, info, false, &loc); if (ret < 0) goto set_flags_err; @@ -589,6 +593,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) goto set_flags_err; } + attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem); if (ret < 0) goto set_flags_err; @@ -677,20 +682,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 = 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 = -EINVAL; struct sock *sk; void *reply; + if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ENDPOINT_ADDR)) + return ret; + msk = mptcp_userspace_pm_get_sock(info); if (!msk) return ret; sk = (struct sock *)msk; + attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; ret = mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) goto out; From patchwork Fri Jan 10 07:30:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13933884 X-Patchwork-Delegate: matthieu.baerts@tessares.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB8C814A08E for ; Fri, 10 Jan 2025 07:31:03 +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=1736494263; cv=none; b=YI/3NKMV7dH4plOLtg3rQrSH2TFzA8WRH18bLMhBESoCSN6lGdjROI08VakOGuMm/UeP8eFziFgyb6g+tSFVqLlQhqVtmj2tr77ondmCCDQn9MhbB+cDpSnPirhTUDSxCwXLm8Iagq8TrQczv+3XjnrEQ8ebspRdbFVlRnXedf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736494263; c=relaxed/simple; bh=6tMv2AIrkrsTEWhm5p7v6KQKkWs+IUaSMu4lNIkR1qM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q2J3hB+vKgq6t+Z524djq/jR06liMuvmgeLA0GgUe750jKTCkYxXhZxtPaEFr4zsd7b2+NGBeHv+2vU1PE3hYkKSIJuNq5YPY0PCChxgsEH5elcxVIVb0Wne5T9yhLVV3qdkYe5qKCsaYU33tu6fIG/gkTjdBvSBYoIqPdyI6/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OdTuglr8; 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="OdTuglr8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D490C4CEDF; Fri, 10 Jan 2025 07:31:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736494263; bh=6tMv2AIrkrsTEWhm5p7v6KQKkWs+IUaSMu4lNIkR1qM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OdTuglr8eP6gDJCcDGXRsOqCS9/tZpUfxwr1X7PK519I98x9xCCDyfo518wpO+Sw7 KYk5FP0s8pszG5He7nrjFrvVpnRcXK58WODBBH31y7GDEzeR+RZLI1h8IzpqhzO3sB rcY3xVbrHZtF3j/3qrFsYOCXA3BopYk5AUMFnMNDDXbK7JyW2NFaS1OIaEkGUDxhFb /R9G8IID4YQyuFsRi+oE4e7Xw+NpYdcP0K8FXQB5qsbIGe+TgpnMXJmAoHM2TQQID7 OjXLQJ1mRBL7AQCOkB8weQOQdLTcifdSYZFYzTTjR8Ufc40Tq/aTnuqj9MVmYr7ex5 NMrP47mvuHaxQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" Subject: [PATCH mptcp-next v9 8/8] mptcp: pm: use NL_SET_ERR_MSG_ATTR when possible Date: Fri, 10 Jan 2025 15:30:42 +0800 Message-ID: <0416e719bbf265607b2c8c9065bcf8fbd0bbb685.1736493803.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Matthieu Baerts (NGI0)" 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. Signed-off-by: Matthieu Baerts (NGI0) --- v2: - update the code related mptcp_userspace_pm_remove_id_zero_address() since a new patch to drop "info" parameter of this patch is added. v3: - not use NL_SET_ERR_MSG_ATTR in mptcp_pm_nl_set_flags(), since 'attr' will be removed in the commit "mptcp: add local & remote parameters for set_flags". --- net/mptcp/pm_netlink.c | 13 ++++++++----- net/mptcp/pm_userspace.c | 24 ++++++++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index ab56630b1d9c..c6fd3b1727d7 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1407,18 +1407,21 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info) return ret; if (addr.addr.port && !address_use_port(&addr)) { - GENL_SET_ERR_MSG(info, "flags must have signal and not subflow when using port"); + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "flags must have signal and not subflow when using port"); return -EINVAL; } 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; } 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; } @@ -1616,7 +1619,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info) spin_lock_bh(&pernet->lock); entry = __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; } @@ -1802,7 +1805,7 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) rcu_read_lock(); entry = __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 = -EINVAL; goto unlock_fail; } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 525dcb84353f..4e5511ede7af 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -189,7 +189,8 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in } if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "userspace PM not selected"); + NL_SET_ERR_MSG_ATTR(info->extack, token, + "userspace PM not selected"); sock_put((struct sock *)msk); return NULL; } @@ -220,20 +221,21 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) goto announce_err; if (addr_val.addr.id == 0) { - GENL_SET_ERR_MSG(info, "invalid addr id"); + NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr id"); err = -EINVAL; goto announce_err; } if (!(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { - GENL_SET_ERR_MSG(info, "invalid addr flags"); + NL_SET_ERR_MSG_ATTR(info->extack, addr, "invalid addr flags"); err = -EINVAL; goto announce_err; } err = 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; } @@ -388,7 +390,7 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) goto create_err; 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 = -EINVAL; goto create_err; } @@ -407,7 +409,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) err = 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; } @@ -528,13 +531,13 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info } if (!addr_l.addr.port) { - GENL_SET_ERR_MSG(info, "missing local port"); + NL_SET_ERR_MSG_ATTR(info->extack, laddr, "missing local port"); err = -EINVAL; goto destroy_err; } if (!addr_r.port) { - GENL_SET_ERR_MSG(info, "missing remote port"); + NL_SET_ERR_MSG_ATTR(info->extack, raddr, "missing remote port"); err = -EINVAL; goto destroy_err; } @@ -599,7 +602,8 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) goto set_flags_err; if (rem.addr.family == AF_UNSPEC) { - GENL_SET_ERR_MSG(info, "invalid remote address family"); + NL_SET_ERR_MSG_ATTR(info->extack, attr_rem, + "invalid remote address family"); ret = -EINVAL; goto set_flags_err; } @@ -722,7 +726,7 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb, spin_lock_bh(&msk->pm.lock); entry = 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 = -EINVAL; goto unlock_fail; }