summaryrefslogtreecommitdiff
path: root/tools/net/ynl/lib/ynl.py
diff options
context:
space:
mode:
authorDonald Hunter <donald.hunter@gmail.com>2023-08-25 13:27:51 +0100
committerJakub Kicinski <kuba@kernel.org>2023-08-27 17:17:10 -0700
commit0493e56d021d371d3511159a38facbc92969c0f6 (patch)
tree352bcdd376f3c22609137e5058b9c030cbf65369 /tools/net/ynl/lib/ynl.py
parente46dd903efe367214802b8d1cac01bdc43708339 (diff)
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 <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>
Diffstat (limited to 'tools/net/ynl/lib/ynl.py')
-rw-r--r--tools/net/ynl/lib/ynl.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 43022dec1076..cab84c407ba2 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -497,6 +497,17 @@ class YnlFamily(SpecFamily):
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()
@@ -516,6 +527,8 @@ class YnlFamily(SpecFamily):
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"]}')