diff options
author | Jiri Pirko <jiri@nvidia.com> | 2023-10-21 13:27:03 +0200 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2023-10-23 16:12:46 -0700 |
commit | 4e2846fd6684227c8f8129ec184fbf090279216d (patch) | |
tree | aa708e34b4209be534c0aa885a5b93480f7a22aa /tools/net/ynl/lib/ynl.py | |
parent | f862ed2d0bf0cf51c28c1a69e3c2a1558d5a2978 (diff) |
tools: ynl-gen: introduce support for bitfield32 attribute type
Introduce support for attribute type bitfield32.
Note that since the generated code works with struct nla_bitfield32,
the generator adds netlink.h to the list of includes for userspace
headers in case any bitfield32 is present.
Note that this is added only to genetlink-legacy scheme as requested
by Jakub Kicinski.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20231021112711.660606-3-jiri@resnulli.us
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/net/ynl/lib/ynl.py')
-rw-r--r-- | tools/net/ynl/lib/ynl.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 3b36553a66cc..b1da4aea9336 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -478,6 +478,8 @@ class YnlFamily(SpecFamily): elif attr['type'] in NlAttr.type_formats: format = NlAttr.get_format(attr['type'], attr.byte_order) attr_payload = format.pack(int(value)) + elif attr['type'] in "bitfield32": + attr_payload = struct.pack("II", int(value["value"]), int(value["selector"])) else: raise Exception(f'Unknown type at {space} {name} {value} {attr["type"]}') @@ -545,14 +547,19 @@ class YnlFamily(SpecFamily): decoded = attr.as_auto_scalar(attr_spec['type'], attr_spec.byte_order) elif attr_spec["type"] in NlAttr.type_formats: decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order) + if 'enum' in attr_spec: + decoded = self._decode_enum(decoded, attr_spec) elif attr_spec["type"] == 'array-nest': decoded = self._decode_array_nest(attr, attr_spec) + elif attr_spec["type"] == 'bitfield32': + value, selector = struct.unpack("II", attr.raw) + if 'enum' in attr_spec: + value = self._decode_enum(value, attr_spec) + selector = self._decode_enum(selector, attr_spec) + decoded = {"value": value, "selector": selector} else: raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}') - if 'enum' in attr_spec: - decoded = self._decode_enum(decoded, attr_spec) - if not attr_spec.is_multi: rsp[attr_spec['name']] = decoded elif attr_spec.name in rsp: |