Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Donald Hunter and committed by
Jakub Kicinski
0493e56d e46dd903

+13
+13
tools/net/ynl/lib/ynl.py
··· 497 497 decoded = NlAttr.formatted_string(decoded, attr_spec.display_hint) 498 498 return decoded 499 499 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 + 500 511 def _decode(self, attrs, space): 501 512 attr_space = self.attr_sets[space] 502 513 rsp = dict() ··· 527 516 decoded = True 528 517 elif attr_spec["type"] in NlAttr.type_formats: 529 518 decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order) 519 + elif attr_spec["type"] == 'array-nest': 520 + decoded = self._decode_array_nest(attr, attr_spec) 530 521 else: 531 522 raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}') 532 523