From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
jiri@resnulli.us, johannes@sipsolutions.net,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 07/10] genetlink: add genlmsg_iput() API
Date: Thu, 10 Aug 2023 16:38:42 -0700 [thread overview]
Message-ID: <20230810233845.2318049-8-kuba@kernel.org> (raw)
In-Reply-To: <20230810233845.2318049-1-kuba@kernel.org>
Add some APIs and helpers required for convenient construction
of replies and notifications based on struct genl_info.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
include/net/genetlink.h | 54 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 53 insertions(+), 1 deletion(-)
diff --git a/include/net/genetlink.h b/include/net/genetlink.h
index 6b858c4cba5b..e18a4c0d69ee 100644
--- a/include/net/genetlink.h
+++ b/include/net/genetlink.h
@@ -113,7 +113,7 @@ struct genl_info {
struct netlink_ext_ack *extack;
};
-static inline struct net *genl_info_net(struct genl_info *info)
+static inline struct net *genl_info_net(const struct genl_info *info)
{
return read_pnet(&info->_net);
}
@@ -270,6 +270,32 @@ genl_info_dump(struct netlink_callback *cb)
return &genl_dumpit_info(cb)->info;
}
+/**
+ * genl_info_init_ntf() - initialize genl_info for notifications
+ * @info: genl_info struct to set up
+ * @family: pointer to the genetlink family
+ * @cmd: command to be used in the notification
+ *
+ * Initialize a locally declared struct genl_info to pass to various APIs.
+ * Intended to be used when creating notifications.
+ */
+static inline void
+genl_info_init_ntf(struct genl_info *info, const struct genl_family *family,
+ u8 cmd)
+{
+ struct genlmsghdr *hdr = (void *) &info->user_ptr[0];
+
+ memset(info, 0, sizeof(*info));
+ info->family = family;
+ info->genlhdr = hdr;
+ hdr->cmd = cmd;
+}
+
+static inline bool genl_info_is_ntf(const struct genl_info *info)
+{
+ return !info->nlhdr;
+}
+
int genl_register_family(struct genl_family *family);
int genl_unregister_family(const struct genl_family *family);
void genl_notify(const struct genl_family *family, struct sk_buff *skb,
@@ -278,6 +304,32 @@ void genl_notify(const struct genl_family *family, struct sk_buff *skb,
void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
const struct genl_family *family, int flags, u8 cmd);
+static inline void *
+__genlmsg_iput(struct sk_buff *skb, const struct genl_info *info, int flags)
+{
+ return genlmsg_put(skb, info->snd_portid, info->snd_seq, info->family,
+ flags, info->genlhdr->cmd);
+}
+
+/**
+ * genlmsg_iput - start genetlink message based on genl_info
+ * @skb: skb in which message header will be placed
+ * @info: genl_info as provided to do/dump handlers
+ *
+ * Convenience wrapper which starts a genetlink message based on
+ * information in user request. @info should be either the struct passed
+ * by genetlink core to do/dump handlers (when constructing replies to
+ * such requests) or a struct initialized by genl_info_init_ntf()
+ * when constructing notifications.
+ *
+ * Returns pointer to new genetlink header.
+ */
+static inline void *
+genlmsg_iput(struct sk_buff *skb, const struct genl_info *info)
+{
+ return __genlmsg_iput(skb, info, 0);
+}
+
/**
* genlmsg_nlhdr - Obtain netlink header from user specified header
* @user_hdr: user header as returned from genlmsg_put()
--
2.41.0
next prev parent reply other threads:[~2023-08-10 23:38 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-10 23:38 [PATCH net-next v2 00/10] genetlink: provide struct genl_info to dumps Jakub Kicinski
2023-08-10 23:38 ` [PATCH net-next v2 01/10] genetlink: push conditional locking into dumpit/done Jakub Kicinski
2023-08-10 23:38 ` [PATCH net-next v2 02/10] genetlink: make genl_info->nlhdr const Jakub Kicinski
2023-08-10 23:38 ` [PATCH net-next v2 03/10] genetlink: remove userhdr from struct genl_info Jakub Kicinski
2023-08-10 23:38 ` [Drbd-dev] " Jakub Kicinski
2023-08-10 23:38 ` [PATCH net-next v2 04/10] genetlink: add struct genl_info to struct genl_dumpit_info Jakub Kicinski
2023-08-10 23:38 ` [PATCH net-next v2 05/10] genetlink: use attrs from struct genl_info Jakub Kicinski
2023-08-10 23:38 ` [PATCH net-next v2 06/10] genetlink: add a family pointer to " Jakub Kicinski
2023-08-11 6:28 ` Jiri Pirko
2023-08-10 23:38 ` Jakub Kicinski [this message]
2023-08-11 6:44 ` [PATCH net-next v2 07/10] genetlink: add genlmsg_iput() API Jiri Pirko
2023-08-10 23:38 ` [PATCH net-next v2 08/10] netdev-genl: use struct genl_info for reply construction Jakub Kicinski
2023-08-11 6:44 ` Jiri Pirko
2023-08-10 23:38 ` [PATCH net-next v2 09/10] ethtool: netlink: simplify arguments to ethnl_default_parse() Jakub Kicinski
2023-08-10 23:38 ` [PATCH net-next v2 10/10] ethtool: netlink: always pass genl_info to .prepare_data Jakub Kicinski
2023-08-11 6:42 ` Jiri Pirko
2023-08-11 7:13 ` Michal Kubecek
2023-08-11 7:29 ` Jiri Pirko
2023-08-11 22:24 ` Jakub Kicinski
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=20230810233845.2318049-8-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--cc=johannes@sipsolutions.net \
--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.