summaryrefslogtreecommitdiff
path: root/rust/helpers
diff options
context:
space:
mode:
authorAlice Ryhl <aliceryhl@google.com>2026-07-07 10:06:50 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-07-17 15:18:39 +0200
commit5eaa5fbb6e6ce6d779fddf7aee42884d60990d40 (patch)
tree39d9b0621b7dd9c7e1c054f3af33af1544b11a5a /rust/helpers
parent2e70c06873c6e23441485d50b8ecac693e7f71c6 (diff)
rust: netlink: add raw netlink abstraction
This implements a safe and relatively simple API over the netlink API, that allows you to add different attributes to a netlink message and broadcast it. As the first user of this API only makes use of broadcast, only broadcast messages are supported here. This API is intended to be safe and to be easy to use in *generated* code. This is because netlink is generally used with yaml files that describe the underlying API, and the python generator outputs C code (or, soon, Rust code) that lets you use the API more easily. So for example, if there is a string field, the code generator will output a method that internall calls `put_string()` with the right attr type. Reviewed-by: Matthew Maurer <mmaurer@google.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Carlos Llamas <cmllamas@google.com> Acked-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Link: https://patch.msgid.link/20260707-binder-netlink-v7-2-42b40e4b1ac8@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'rust/helpers')
-rw-r--r--rust/helpers/helpers.c1
-rw-r--r--rust/helpers/net/genetlink.c46
2 files changed, 47 insertions, 0 deletions
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 998e31052e66..1d4ee51f576b 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -72,6 +72,7 @@
#include "maple_tree.c"
#include "mm.c"
#include "mutex.c"
+#include "net/genetlink.c"
#include "of.c"
#include "page.c"
#include "pci.c"
diff --git a/rust/helpers/net/genetlink.c b/rust/helpers/net/genetlink.c
new file mode 100644
index 000000000000..3530b69f6cf7
--- /dev/null
+++ b/rust/helpers/net/genetlink.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Copyright (C) 2026 Google LLC.
+ */
+
+#include <net/genetlink.h>
+
+#ifdef CONFIG_NET
+
+__rust_helper struct sk_buff *rust_helper_genlmsg_new(size_t payload, gfp_t flags)
+{
+ return genlmsg_new(payload, flags);
+}
+
+__rust_helper
+int rust_helper_genlmsg_multicast(const struct genl_family *family,
+ struct sk_buff *skb, u32 portid,
+ unsigned int group, gfp_t flags)
+{
+ return genlmsg_multicast(family, skb, portid, group, flags);
+}
+
+__rust_helper void rust_helper_genlmsg_cancel(struct sk_buff *skb, void *hdr)
+{
+ genlmsg_cancel(skb, hdr);
+}
+
+__rust_helper void rust_helper_genlmsg_end(struct sk_buff *skb, void *hdr)
+{
+ genlmsg_end(skb, hdr);
+}
+
+__rust_helper void rust_helper_nlmsg_free(struct sk_buff *skb)
+{
+ nlmsg_free(skb);
+}
+
+__rust_helper
+int rust_helper_genl_has_listeners(const struct genl_family *family,
+ struct net *net, unsigned int group)
+{
+ return genl_has_listeners(family, net, group);
+}
+
+#endif