All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	mkubecek@suse.cz, johannes@sipsolutions.net,
	Jakub Kicinski <kuba@kernel.org>,
	fw@strlen.de
Subject: [PATCH net-next v2 3/6] netlink: add helpers for extack attr presence checking
Date: Wed, 24 Aug 2022 19:41:19 -0700	[thread overview]
Message-ID: <20220825024122.1998968-4-kuba@kernel.org> (raw)
In-Reply-To: <20220825024122.1998968-1-kuba@kernel.org>

Being able to check attribute presence and set extack
if not on one line is handy, add helpers.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
--
v2: squash old genetlink and netlink patches now that
    we don't need special handling of fixed headers (Johannes)
---
CC: fw@strlen.de
---
 include/linux/netlink.h | 11 +++++++++++
 include/net/genetlink.h |  7 +++++++
 2 files changed, 18 insertions(+)

diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 2e647157f383..f30b66996058 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -139,6 +139,17 @@ struct netlink_ext_ack {
 	}						\
 } while (0)
 
+#define NL_REQ_ATTR_CHECK(extack, nest, tb, type) ({		\
+	struct nlattr **__tb = (tb);				\
+	u32 __attr = (type);					\
+	int __retval;						\
+								\
+	__retval = !__tb[__attr];				\
+	if (__retval)						\
+		NL_SET_ERR_ATTR_MISS((extack), (nest), __attr);	\
+	__retval;						\
+})
+
 static inline void nl_set_extack_cookie_u64(struct netlink_ext_ack *extack,
 					    u64 cookie)
 {
diff --git a/include/net/genetlink.h b/include/net/genetlink.h
index 56a50e1c51b9..c41b20783ad0 100644
--- a/include/net/genetlink.h
+++ b/include/net/genetlink.h
@@ -107,6 +107,13 @@ static inline void genl_info_net_set(struct genl_info *info, struct net *net)
 
 #define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG((info)->extack, msg)
 
+/* Report that a root attribute is missing */
+#define GENL_REQ_ATTR_CHECK(info, attr) ({				\
+	struct genl_info *__info = (info);				\
+									\
+	NL_REQ_ATTR_CHECK(__info->extack, NULL, __info->attrs, (attr)); \
+})
+
 enum genl_validate_flags {
 	GENL_DONT_VALIDATE_STRICT		= BIT(0),
 	GENL_DONT_VALIDATE_DUMP			= BIT(1),
-- 
2.37.2


  parent reply	other threads:[~2022-08-25  2:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-25  2:41 [PATCH net-next v2 0/6] netlink: support reporting missing attributes Jakub Kicinski
2022-08-25  2:41 ` [PATCH net-next v2 1/6] netlink: factor out extack composition Jakub Kicinski
2022-08-25  6:47   ` Johannes Berg
2022-08-25  2:41 ` [PATCH net-next v2 2/6] netlink: add support for ext_ack missing attributes Jakub Kicinski
2022-08-25  6:49   ` Johannes Berg
2022-08-25  2:41 ` Jakub Kicinski [this message]
2022-08-25  2:41 ` [PATCH net-next v2 4/6] devlink: use missing attribute ext_ack Jakub Kicinski
2022-08-25  2:41 ` [PATCH net-next v2 5/6] ethtool: strset: report missing ETHTOOL_A_STRINGSET_ID via ext_ack Jakub Kicinski
2022-08-25  2:41 ` [PATCH net-next v2 6/6] ethtool: report missing header via ext_ack in the default handler Jakub Kicinski
2022-08-25 12:19   ` Ido Schimmel
2022-08-25 15:34     ` Jakub Kicinski
2022-08-25  6:51 ` [PATCH net-next v2 0/6] netlink: support reporting missing attributes Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220825024122.1998968-4-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=johannes@sipsolutions.net \
    --cc=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.