[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220826030935.2165661-4-kuba@kernel.org>
Date: Thu, 25 Aug 2022 20:09:32 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: davem@...emloft.net
Cc: netdev@...r.kernel.org, edumazet@...gle.com, pabeni@...hat.com,
mkubecek@...e.cz, johannes@...solutions.net, idosch@...sch.org,
dsahern@...il.com, stephen@...workplumber.org,
Jakub Kicinski <kuba@...nel.org>, fw@...len.de
Subject: [PATCH net-next v3 3/6] netlink: add helpers for extack attr presence checking
Being able to check attribute presence and set extack
if not on one line is handy, add helpers.
Reviewed-by: Johannes Berg <johannes@...solutions.net>
Signed-off-by: Jakub Kicinski <kuba@...nel.org>
--
v2: squash old genetlink and netlink patches now that
we don't need special handling of fixed headers (Johannes)
---
CC: fw@...len.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 1619221c415c..d51e041d2242 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
Powered by blists - more mailing lists