Commit 0493e56d authored by Donald Hunter's avatar Donald Hunter Committed by Jakub Kicinski

tools/net/ynl: Implement nlattr array-nest decoding in ynl

Add support for the 'array-nest' attribute type that is used by several
netlink-raw families.
Signed-off-by: default avatarDonald Hunter <donald.hunter@gmail.com>
Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20230825122756.7603-9-donald.hunter@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent e46dd903
...@@ -497,6 +497,17 @@ class YnlFamily(SpecFamily): ...@@ -497,6 +497,17 @@ class YnlFamily(SpecFamily):
decoded = NlAttr.formatted_string(decoded, attr_spec.display_hint) decoded = NlAttr.formatted_string(decoded, attr_spec.display_hint)
return decoded return decoded
def _decode_array_nest(self, attr, attr_spec):
decoded = []
offset = 0
while offset < len(attr.raw):
item = NlAttr(attr.raw, offset)
offset += item.full_len
subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
decoded.append({ item.type: subattrs })
return decoded
def _decode(self, attrs, space): def _decode(self, attrs, space):
attr_space = self.attr_sets[space] attr_space = self.attr_sets[space]
rsp = dict() rsp = dict()
...@@ -516,6 +527,8 @@ class YnlFamily(SpecFamily): ...@@ -516,6 +527,8 @@ class YnlFamily(SpecFamily):
decoded = True decoded = True
elif attr_spec["type"] in NlAttr.type_formats: elif attr_spec["type"] in NlAttr.type_formats:
decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order) decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order)
elif attr_spec["type"] == 'array-nest':
decoded = self._decode_array_nest(attr, attr_spec)
else: else:
raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}') raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment