Skip to content

Commit

Permalink
tools/net/ynl: Implement nlattr array-nest decoding in ynl
Browse files Browse the repository at this point in the history
Add support for the 'array-nest' attribute type that is used by several
netlink-raw families.

Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20230825122756.7603-9-donald.hunter@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Donald Hunter authored and Jakub Kicinski committed Aug 28, 2023
1 parent e46dd90 commit 0493e56
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tools/net/ynl/lib/ynl.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,17 @@ def _decode_binary(self, attr, attr_spec):
decoded = NlAttr.formatted_string(decoded, attr_spec.display_hint)
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):
attr_space = self.attr_sets[space]
rsp = dict()
Expand All @@ -516,6 +527,8 @@ def _decode(self, attrs, space):
decoded = True
elif attr_spec["type"] in NlAttr.type_formats:
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:
raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}')

Expand Down

0 comments on commit 0493e56

Please sign in to comment.