[PATCH net-next 09/11] tools: ynl: encode indexed-array

Donald Hunter donald.hunter at gmail.com
Fri Sep 5 10:54:07 UTC 2025


Asbjørn Sloth Tønnesen <ast at fiberby.net> writes:

> This patch adds support for encoding indexed-array
> attributes with sub-type nest in pyynl.
>
> Signed-off-by: Asbjørn Sloth Tønnesen <ast at fiberby.net>
> ---
>  tools/net/ynl/pyynl/lib/ynl.py | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>
> diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py
> index 4928b41c636a..a37294a751da 100644
> --- a/tools/net/ynl/pyynl/lib/ynl.py
> +++ b/tools/net/ynl/pyynl/lib/ynl.py
> @@ -564,6 +564,11 @@ class YnlFamily(SpecFamily):
>              nl_type |= Netlink.NLA_F_NESTED
>              sub_space = attr['nested-attributes']
>              attr_payload = self._add_nest_attrs(value, sub_space, search_attrs)
> +        elif attr['type'] == 'indexed-array' and attr['sub-type'] == 'nest':
> +            nl_type |= Netlink.NLA_F_NESTED
> +            sub_space = attr['nested-attributes']
> +            attr_payload = self._encode_indexed_array(value, sub_space,
> +                                                      search_attrs)
>          elif attr["type"] == 'flag':
>              if not value:
>                  # If value is absent or false then skip attribute creation.
> @@ -617,6 +622,9 @@ class YnlFamily(SpecFamily):
>          else:
>              raise Exception(f'Unknown type at {space} {name} {value} {attr["type"]}')
>  
> +        return self._add_attr_raw(nl_type, attr_payload)
> +
> +    def _add_attr_raw(self, nl_type, attr_payload):
>          pad = b'\x00' * ((4 - len(attr_payload) % 4) % 4)
>          return struct.pack('HH', len(attr_payload) + 4, nl_type) + attr_payload + pad
>  
> @@ -628,6 +636,15 @@ class YnlFamily(SpecFamily):
>                                             sub_attrs)
>          return attr_payload
>  
> +    def _encode_indexed_array(self, vals, sub_space, search_attrs):
> +        attr_payload = b''
> +        nested_flag = Netlink.NLA_F_NESTED

This line is not doing anything, right?

> +        for i, val in enumerate(vals):
> +            idx = i | Netlink.NLA_F_NESTED
> +            val_payload = self._add_nest_attrs(val, sub_space, search_attrs)
> +            attr_payload += self._add_attr_raw(idx, val_payload)
> +        return attr_payload
> +
>      def _get_enum_or_unknown(self, enum, raw):
>          try:
>              name = enum.entries_by_val[raw].name


More information about the WireGuard mailing list