devlink: add split ops generated according to spec
authorJiri Pirko <jiri@nvidia.com>
Thu, 3 Aug 2023 11:13:38 +0000 (13:13 +0200)
committerJakub Kicinski <kuba@kernel.org>
Fri, 4 Aug 2023 21:03:01 +0000 (14:03 -0700)
Improve the existing devlink spec in order to serve as a source for
generation of valid devlink split ops for the existing commands.
Add the generated sources.

Node that the policies are narrowed down only to the attributes that
are actually parsed. The dont-validate-strict parsing policy makes sure
that other possibly passed garbage attributes from userspace are
ignored during validation.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Link: https://lore.kernel.org/r/20230803111340.1074067-11-jiri@resnulli.us
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Documentation/netlink/specs/devlink.yaml
net/devlink/Makefile
net/devlink/netlink_gen.c [new file with mode: 0644]
net/devlink/netlink_gen.h [new file with mode: 0644]

index 12699b7..f6df0b3 100644 (file)
@@ -165,8 +165,13 @@ operations:
       name: get
       doc: Get devlink instances.
       attribute-set: devlink
+      dont-validate:
+        - strict
+        - dump
 
       do:
+        pre: devlink-nl-pre-doit
+        post: devlink-nl-post-doit
         request:
           value: 1
           attributes: &dev-id-attrs
@@ -189,8 +194,13 @@ operations:
       name: info-get
       doc: Get device information, like driver name, hardware and firmware versions etc.
       attribute-set: devlink
+      dont-validate:
+        - strict
+        - dump
 
       do:
+        pre: devlink-nl-pre-doit
+        post: devlink-nl-post-doit
         request:
           value: 51
           attributes: *dev-id-attrs
index ef91a76..a087af5 100644 (file)
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
 
-obj-y := leftover.o core.o netlink.o dev.o health.o
+obj-y := leftover.o core.o netlink.o netlink_gen.o dev.o health.o
diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c
new file mode 100644 (file)
index 0000000..32d8cbe
--- /dev/null
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+/* Do not edit directly, auto-generated from: */
+/*     Documentation/netlink/specs/devlink.yaml */
+/* YNL-GEN kernel source */
+
+#include <net/netlink.h>
+#include <net/genetlink.h>
+
+#include "netlink_gen.h"
+
+#include <uapi/linux/devlink.h>
+
+/* DEVLINK_CMD_GET - do */
+static const struct nla_policy devlink_get_nl_policy[DEVLINK_ATTR_DEV_NAME + 1] = {
+       [DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
+       [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
+};
+
+/* DEVLINK_CMD_INFO_GET - do */
+static const struct nla_policy devlink_info_get_nl_policy[DEVLINK_ATTR_DEV_NAME + 1] = {
+       [DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
+       [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
+};
+
+/* Ops table for devlink */
+const struct genl_split_ops devlink_nl_ops[4] = {
+       {
+               .cmd            = DEVLINK_CMD_GET,
+               .validate       = GENL_DONT_VALIDATE_STRICT,
+               .pre_doit       = devlink_nl_pre_doit,
+               .doit           = devlink_nl_get_doit,
+               .post_doit      = devlink_nl_post_doit,
+               .policy         = devlink_get_nl_policy,
+               .maxattr        = DEVLINK_ATTR_DEV_NAME,
+               .flags          = GENL_CMD_CAP_DO,
+       },
+       {
+               .cmd            = DEVLINK_CMD_GET,
+               .validate       = GENL_DONT_VALIDATE_DUMP,
+               .dumpit         = devlink_nl_get_dumpit,
+               .flags          = GENL_CMD_CAP_DUMP,
+       },
+       {
+               .cmd            = DEVLINK_CMD_INFO_GET,
+               .validate       = GENL_DONT_VALIDATE_STRICT,
+               .pre_doit       = devlink_nl_pre_doit,
+               .doit           = devlink_nl_info_get_doit,
+               .post_doit      = devlink_nl_post_doit,
+               .policy         = devlink_info_get_nl_policy,
+               .maxattr        = DEVLINK_ATTR_DEV_NAME,
+               .flags          = GENL_CMD_CAP_DO,
+       },
+       {
+               .cmd            = DEVLINK_CMD_INFO_GET,
+               .validate       = GENL_DONT_VALIDATE_DUMP,
+               .dumpit         = devlink_nl_info_get_dumpit,
+               .flags          = GENL_CMD_CAP_DUMP,
+       },
+};
diff --git a/net/devlink/netlink_gen.h b/net/devlink/netlink_gen.h
new file mode 100644 (file)
index 0000000..11980e0
--- /dev/null
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
+/* Do not edit directly, auto-generated from: */
+/*     Documentation/netlink/specs/devlink.yaml */
+/* YNL-GEN kernel header */
+
+#ifndef _LINUX_DEVLINK_GEN_H
+#define _LINUX_DEVLINK_GEN_H
+
+#include <net/netlink.h>
+#include <net/genetlink.h>
+
+#include <uapi/linux/devlink.h>
+
+/* Ops table for devlink */
+extern const struct genl_split_ops devlink_nl_ops[4];
+
+int devlink_nl_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,
+                       struct genl_info *info);
+void
+devlink_nl_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb,
+                    struct genl_info *info);
+
+int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info);
+int devlink_nl_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
+int devlink_nl_info_get_doit(struct sk_buff *skb, struct genl_info *info);
+int devlink_nl_info_get_dumpit(struct sk_buff *skb,
+                              struct netlink_callback *cb);
+
+#endif /* _LINUX_DEVLINK_GEN_H */