Skip to content

Commit 0493e56

Browse files
donaldhkuba-moo
authored andcommitted
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: Donald Hunter <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e46dd90 commit 0493e56

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/net/ynl/lib/ynl.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,17 @@ def _decode_binary(self, attr, attr_spec):
497497
decoded = NlAttr.formatted_string(decoded, attr_spec.display_hint)
498498
return decoded
499499

500+
def _decode_array_nest(self, attr, attr_spec):
501+
decoded = []
502+
offset = 0
503+
while offset < len(attr.raw):
504+
item = NlAttr(attr.raw, offset)
505+
offset += item.full_len
506+
507+
subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
508+
decoded.append({ item.type: subattrs })
509+
return decoded
510+
500511
def _decode(self, attrs, space):
501512
attr_space = self.attr_sets[space]
502513
rsp = dict()
@@ -516,6 +527,8 @@ def _decode(self, attrs, space):
516527
decoded = True
517528
elif attr_spec["type"] in NlAttr.type_formats:
518529
decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order)
530+
elif attr_spec["type"] == 'array-nest':
531+
decoded = self._decode_array_nest(attr, attr_spec)
519532
else:
520533
raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}')
521534

0 commit comments

Comments
 (0)