From patchwork Mon Jan 6 08:16:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13927047 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 1AF231D89FE for ; Mon, 6 Jan 2025 08:16:44 +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=1736151405; cv=none; b=BTKOawSg/PDKU+kTcinr73q4/VdG8HDy7cfAjv0Hrr9q8FX01NsTWhRj2PcTYh4Zu1R2AaKwXtcjPiAEgTRrez2gD8Foo35xSILuJ/z5yYqiklgWpJXOF03t8MaOkyLHpa6CSNc7R0bY/KFNn0qVJZT+Vbzqw2k4nLYH9KEPsjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736151405; c=relaxed/simple; bh=XXsvtGwi1HTSCnqPYKBlOfWs13dziJtl9pbzNFDFRK8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XtPiirY2QH8YKj7ylI5lDOlPn1t+I5l2CDPSLi1P6Dd/OBvvqP2ZvnBRoyz87i4YOAWPpJIHzAW1Sa0I3R2jVHXpZ46PfXqXr0FFOkZlcCRx516HIvTqHvoUK9EtqWmZZM3hqECWCkwxKW0XUswdHh77dvrgeL9jWsquO7DHJl8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=by3J4utT; 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="by3J4utT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EEA0C4CEDF; Mon, 6 Jan 2025 08:16:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736151404; bh=XXsvtGwi1HTSCnqPYKBlOfWs13dziJtl9pbzNFDFRK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=by3J4utTMQf2zt7fAsbeLYhc3ELcc6xRxy/BCirR0LbIcXBz92kBfioTHbJQiPE06 3Sadn7JkYkXaLTnBhV3P8S+vWqGPvMZEw+/ErI4nWZinaq5R8IaqAdCxyhPiDKY0TI 8Dav0RJ07kFNJr5dC7+rcLvRCmnMpVofJ9sGIyXByXiJikVf8q3OcozptnhwfJ3wua cWWthfNZo7s73BdkZ36xv6ijvZDi8y7bG3g1FmhnQeeEOrIoIq+59ZUFcxWpS4KwNq rIGaUAORaLt6W9A7aajSHPAI0TMa8UPPmorkP8DMKz0+Gu2c0ysWO7h5Y1T4IzD4we psK9kXY9zMgmw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: "Matthieu Baerts (NGI0)" Subject: [PATCH mptcp-next v7 11/11] mptcp: pm: mark missing address attributes Date: Mon, 6 Jan 2025 16:16:16 +0800 Message-ID: <6db9c829384bf1d23b9fa571807910edfdddca7f.1736150983.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() 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 | 18 +++++++++++++++--- net/mptcp/pm_userspace.c | 6 +++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 528718cb70ec..46852c479b43 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; @@ -1590,12 +1594,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; @@ -1767,13 +1775,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; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index dc9ebfb06d96..801b1280a1aa 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -663,20 +663,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;