From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net,
edumazet@google.com, jacob.e.keller@intel.com,
johannes@sipsolutions.net
Subject: [patch net-next 02/10] tools: ynl-gen: introduce support for bitfield32 attribute type
Date: Tue, 10 Oct 2023 13:08:21 +0200 [thread overview]
Message-ID: <20231010110828.200709-3-jiri@resnulli.us> (raw)
In-Reply-To: <20231010110828.200709-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@nvidia.com>
Introduce support for forgotten attribute type bitfield32.
Note that since the generated code works with struct nla_bitfiel32,
the generator adds netlink.h to the list of includes for userspace
headers. Regenerate the headers.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
Documentation/netlink/genetlink-c.yaml | 2 +-
Documentation/netlink/genetlink-legacy.yaml | 4 +--
Documentation/netlink/genetlink.yaml | 2 +-
tools/net/ynl/generated/devlink-user.h | 1 +
tools/net/ynl/generated/ethtool-user.h | 1 +
tools/net/ynl/generated/fou-user.h | 1 +
tools/net/ynl/generated/handshake-user.h | 1 +
tools/net/ynl/generated/netdev-user.h | 1 +
tools/net/ynl/lib/ynl.c | 6 ++++
tools/net/ynl/lib/ynl.h | 1 +
tools/net/ynl/ynl-gen-c.py | 31 +++++++++++++++++++++
11 files changed, 47 insertions(+), 4 deletions(-)
diff --git a/Documentation/netlink/genetlink-c.yaml b/Documentation/netlink/genetlink-c.yaml
index f9366aaddd21..8192b87b3046 100644
--- a/Documentation/netlink/genetlink-c.yaml
+++ b/Documentation/netlink/genetlink-c.yaml
@@ -144,7 +144,7 @@ properties:
name:
type: string
type: &attr-type
- enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
+ enum: [ unused, pad, flag, binary, bitfield32, u8, u16, u32, u64, s32, s64,
string, nest, array-nest, nest-type-value ]
doc:
description: Documentation of the attribute.
diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml
index a6a490333a1a..8b867b5b9966 100644
--- a/Documentation/netlink/genetlink-legacy.yaml
+++ b/Documentation/netlink/genetlink-legacy.yaml
@@ -120,7 +120,7 @@ properties:
type: string
type:
description: The netlink attribute type
- enum: [ u8, u16, u32, u64, s8, s16, s32, s64, string, binary ]
+ enum: [ u8, u16, u32, u64, s8, s16, s32, s64, string, binary, bitfield32 ]
len:
$ref: '#/$defs/len-or-define'
byte-order:
@@ -187,7 +187,7 @@ properties:
type: string
type: &attr-type
description: The netlink attribute type
- enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
+ enum: [ unused, pad, flag, binary, bitfield32, u8, u16, u32, u64, s32, s64,
string, nest, array-nest, nest-type-value ]
doc:
description: Documentation of the attribute.
diff --git a/Documentation/netlink/genetlink.yaml b/Documentation/netlink/genetlink.yaml
index 2b788e607a14..5cde1b030e8e 100644
--- a/Documentation/netlink/genetlink.yaml
+++ b/Documentation/netlink/genetlink.yaml
@@ -117,7 +117,7 @@ properties:
name:
type: string
type: &attr-type
- enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
+ enum: [ unused, pad, flag, binary, bitfield32, u8, u16, u32, u64, s32, s64,
string, nest, array-nest, nest-type-value ]
doc:
description: Documentation of the attribute.
diff --git a/tools/net/ynl/generated/devlink-user.h b/tools/net/ynl/generated/devlink-user.h
index 4b686d147613..a490466fb98a 100644
--- a/tools/net/ynl/generated/devlink-user.h
+++ b/tools/net/ynl/generated/devlink-user.h
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <linux/types.h>
+#include <linux/netlink.h>
#include <linux/devlink.h>
struct ynl_sock;
diff --git a/tools/net/ynl/generated/ethtool-user.h b/tools/net/ynl/generated/ethtool-user.h
index ddc1a5209992..f7bce36f8485 100644
--- a/tools/net/ynl/generated/ethtool-user.h
+++ b/tools/net/ynl/generated/ethtool-user.h
@@ -10,6 +10,7 @@
#include <stdlib.h>
#include <string.h>
#include <linux/types.h>
+#include <linux/netlink.h>
#include <linux/ethtool.h>
struct ynl_sock;
diff --git a/tools/net/ynl/generated/fou-user.h b/tools/net/ynl/generated/fou-user.h
index a8f860892540..2ae6d1b66393 100644
--- a/tools/net/ynl/generated/fou-user.h
+++ b/tools/net/ynl/generated/fou-user.h
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <linux/types.h>
+#include <linux/netlink.h>
#include <linux/fou.h>
struct ynl_sock;
diff --git a/tools/net/ynl/generated/handshake-user.h b/tools/net/ynl/generated/handshake-user.h
index 2b34acc608de..1007f8db5c5e 100644
--- a/tools/net/ynl/generated/handshake-user.h
+++ b/tools/net/ynl/generated/handshake-user.h
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <linux/types.h>
+#include <linux/netlink.h>
#include <linux/handshake.h>
struct ynl_sock;
diff --git a/tools/net/ynl/generated/netdev-user.h b/tools/net/ynl/generated/netdev-user.h
index b4351ff34595..d6ffc0c8ccf4 100644
--- a/tools/net/ynl/generated/netdev-user.h
+++ b/tools/net/ynl/generated/netdev-user.h
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <linux/types.h>
+#include <linux/netlink.h>
#include <linux/netdev.h>
struct ynl_sock;
diff --git a/tools/net/ynl/lib/ynl.c b/tools/net/ynl/lib/ynl.c
index 514e0d69e731..4a94ef092b6e 100644
--- a/tools/net/ynl/lib/ynl.c
+++ b/tools/net/ynl/lib/ynl.c
@@ -373,6 +373,12 @@ int ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *attr)
yerr(yarg->ys, YNL_ERROR_ATTR_INVALID,
"Invalid attribute (string %s)", policy->name);
return -1;
+ case YNL_PT_BITFIELD32:
+ if (len == sizeof(struct nla_bitfield32))
+ break;
+ yerr(yarg->ys, YNL_ERROR_ATTR_INVALID,
+ "Invalid attribute (bitfield32 %s)", policy->name);
+ return -1;
default:
yerr(yarg->ys, YNL_ERROR_ATTR_INVALID,
"Invalid attribute (unknown %s)", policy->name);
diff --git a/tools/net/ynl/lib/ynl.h b/tools/net/ynl/lib/ynl.h
index 9eafa3552c16..813b26a08145 100644
--- a/tools/net/ynl/lib/ynl.h
+++ b/tools/net/ynl/lib/ynl.h
@@ -134,6 +134,7 @@ enum ynl_policy_type {
YNL_PT_U32,
YNL_PT_U64,
YNL_PT_NUL_STR,
+ YNL_PT_BITFIELD32,
};
struct ynl_policy_attr {
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index f125b5f704ba..27bbe376054d 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -433,6 +433,34 @@ class TypeBinary(Type):
f'memcpy({member}, {self.c_name}, {presence}_len);']
+class TypeBitfield32(Type):
+ def arg_member(self, ri):
+ return [f"const struct nla_bitfield32 *{self.c_name}"]
+
+ def struct_member(self, ri):
+ ri.cw.p(f"struct nla_bitfield32 {self.c_name};")
+
+ def _attr_typol(self):
+ return f'.type = YNL_PT_BITFIELD32, '
+
+ def _attr_policy(self, policy):
+ if not 'enum' in self.attr:
+ raise Exception('Enum required for bitfield32 attr')
+ enum = self.family.consts[self.attr['enum']]
+ mask = enum.get_mask(as_flags=True)
+ return f"NLA_POLICY_BITFIELD32({mask})"
+
+ def attr_put(self, ri, var):
+ line = f"mnl_attr_put(nlh, {self.enum_name}, sizeof(struct nla_bitfield32), &{var}->{self.c_name})"
+ self._attr_put_line(ri, var, line)
+
+ def _attr_get(self, ri, var):
+ return f"memcpy(&{var}->{self.c_name}, mnl_attr_get_payload(attr), sizeof(struct nla_bitfield32));", None, None
+
+ def _setter_lines(self, ri, member, presence):
+ return [f"memcpy(&{member}, {self.c_name}, sizeof(struct nla_bitfield32));"]
+
+
class TypeNest(Type):
def _complex_member_type(self, ri):
return self.nested_struct_type
@@ -735,6 +763,8 @@ class AttrSet(SpecAttrSet):
t = TypeString(self.family, self, elem, value)
elif elem['type'] == 'binary':
t = TypeBinary(self.family, self, elem, value)
+ elif elem['type'] == 'bitfield32':
+ t = TypeBitfield32(self.family, self, elem, value)
elif elem['type'] == 'nest':
t = TypeNest(self.family, self, elem, value)
elif elem['type'] == 'array-nest':
@@ -2406,6 +2436,7 @@ def main():
cw.p('#include <string.h>')
if args.header:
cw.p('#include <linux/types.h>')
+ cw.p('#include <linux/netlink.h>')
else:
cw.p(f'#include "{parsed.name}-user.h"')
cw.p('#include "ynl.h"')
--
2.41.0
next prev parent reply other threads:[~2023-10-10 11:08 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-10 11:08 [patch net-next 00/10] devlink: finish conversion to generated split_ops Jiri Pirko
2023-10-10 11:08 ` [patch net-next 01/10] genetlink: don't merge dumpit split op for different cmds into single iter Jiri Pirko
2023-10-10 11:24 ` Johannes Berg
2023-10-10 11:39 ` Jiri Pirko
2023-10-10 12:09 ` Johannes Berg
2023-10-10 12:12 ` Johannes Berg
2023-10-10 18:48 ` Jakub Kicinski
2023-10-11 6:08 ` Jiri Pirko
2023-10-11 11:27 ` Jiri Pirko
2023-10-11 16:47 ` Jakub Kicinski
2023-10-11 17:00 ` Jiri Pirko
2023-10-12 20:58 ` Jacob Keller
2023-10-10 11:08 ` Jiri Pirko [this message]
2023-10-10 11:11 ` [patch net-next 02/10] tools: ynl-gen: introduce support for bitfield32 attribute type Johannes Berg
2023-10-10 18:58 ` Jakub Kicinski
2023-10-11 6:07 ` Jiri Pirko
2023-10-11 16:52 ` Jakub Kicinski
2023-10-11 17:04 ` Jiri Pirko
2023-10-11 18:25 ` Jakub Kicinski
2023-10-12 9:28 ` Jiri Pirko
2023-10-12 21:06 ` Jacob Keller
2023-10-13 0:15 ` Jakub Kicinski
2023-10-13 18:49 ` Jacob Keller
2023-10-13 0:25 ` Jakub Kicinski
2023-10-10 19:01 ` Jakub Kicinski
2023-10-11 6:06 ` Jiri Pirko
2023-10-10 11:08 ` [patch net-next 03/10] netlink: specs: devlink: remove reload-action from devlink-get cmd reply Jiri Pirko
2023-10-10 11:08 ` [patch net-next 04/10] netlink: specs: devlink: make dont-validate single line Jiri Pirko
2023-10-10 11:08 ` [patch net-next 05/10] netlink: specs: devlink: fix reply command values Jiri Pirko
2023-10-10 18:59 ` Jakub Kicinski
2023-10-11 6:04 ` Jiri Pirko
2023-10-11 16:44 ` Jakub Kicinski
2023-10-11 17:00 ` Jiri Pirko
2023-10-10 11:08 ` [patch net-next 06/10] devlink: make devlink_flash_overwrite enum named one Jiri Pirko
2023-10-10 11:08 ` [patch net-next 07/10] devlink: rename netlink callback to be aligned with the generated ones Jiri Pirko
2023-10-10 11:08 ` [patch net-next 08/10] netlink: specs: devlink: add the remaining command to generate complete split_ops Jiri Pirko
2023-10-10 11:08 ` [patch net-next 09/10] devlink: remove duplicated netlink callback prototypes Jiri Pirko
2023-10-10 11:18 ` [patch net-next 10/10] devlink: remove netlink small_ops Jiri Pirko
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=20231010110828.200709-3-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jacob.e.keller@intel.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).