Skip to content

Commit a7408b5

Browse files
liuhangbinkuba-moo
authored andcommitted
ynl: support binary and integer sub-type for indexed-array
Add binary and integer sub-type support for indexed-array to display bond arp and ns targets. Here is what the result looks like: # ip link add bond0 type bond mode 1 \ arp_ip_target 192.168.1.1,192.168.1.2 ns_ip6_target 2001::1,2001::2 # ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/rt_link.yaml \ --do getlink --json '{"ifname": "bond0"}' --output-json | jq '.linkinfo' "arp-ip-target": [ "192.168.1.1", "192.168.1.2" ], [...] "ns-ip6-target": [ "2001::1", "2001::2" ], Signed-off-by: Hangbin Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent aa6485d commit a7408b5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Documentation/userspace-api/netlink/genetlink-legacy.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@ looks like::
6666
[MEMBER1]
6767
[MEMBER2]
6868

69-
It wraps the entire array in an extra attribute (hence limiting its size
70-
to 64kB). The ``ENTRY`` nests are special and have the index of the entry
71-
as their type instead of normal attribute type.
69+
Other ``sub-type`` like ``u32`` means there is only one member as described
70+
in ``sub-type`` in the ``ENTRY``. The structure looks like::
71+
72+
[SOME-OTHER-ATTR]
73+
[ARRAY-ATTR]
74+
[ENTRY u32]
75+
[ENTRY u32]
7276

7377
type-value
7478
~~~~~~~~~~

tools/net/ynl/lib/ynl.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,16 @@ def _decode_array_attr(self, attr, attr_spec):
641641
if attr_spec["sub-type"] == 'nest':
642642
subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
643643
decoded.append({ item.type: subattrs })
644+
elif attr_spec["sub-type"] == 'binary':
645+
subattrs = item.as_bin()
646+
if attr_spec.display_hint:
647+
subattrs = self._formatted_string(subattrs, attr_spec.display_hint)
648+
decoded.append(subattrs)
649+
elif attr_spec["sub-type"] in NlAttr.type_formats:
650+
subattrs = item.as_scalar(attr_spec['sub-type'], attr_spec.byte_order)
651+
if attr_spec.display_hint:
652+
subattrs = self._formatted_string(subattrs, attr_spec.display_hint)
653+
decoded.append(subattrs)
644654
else:
645655
raise Exception(f'Unknown {attr_spec["sub-type"]} with name {attr_spec["name"]}')
646656
return decoded

0 commit comments

Comments
 (0)