Re: [PATCH net-next 06/11] tools: ynl-gen: don't validate nested array attribute types

Jacob Keller <[email protected]>
Newsgroups com.zx2c4.lists.wireguard,org.kernel.vger.linux-kernel,org.kernel.vger.netdev
Message-ID <[email protected]>

On 9/4/2025 3:01 PM, Asbjørn Sloth Tønnesen wrote:
> In nested arrays don't require that the intermediate
> attribute type should be a valid attribute type, it
> might just be an index or simple 0, it is often not
> even used.
> 
> See include/net/netlink.h about NLA_NESTED_ARRAY:
>> The difference to NLA_NESTED is the structure:
>> NLA_NESTED has the nested attributes directly inside
>> while an array has the nested attributes at another
>> level down and the attribute types directly in the
>> nesting don't matter.
> 

To me, it would seem like it makes more sense to define these (even if
thats defined per family?) than to just say they aren't defined at all?

Hm.

> Signed-off-by: Asbjørn Sloth Tønnesen <[email protected]>
> ---
>  tools/net/ynl/pyynl/ynl_gen_c.py | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
> index e6a84e13ec0a..3c0b158c4da8 100755
> --- a/tools/net/ynl/pyynl/ynl_gen_c.py
> +++ b/tools/net/ynl/pyynl/ynl_gen_c.py
> @@ -834,11 +834,12 @@ class TypeArrayNest(Type):
>      def _attr_get(self, ri, var):
>          local_vars = ['const struct nlattr *attr2;']
>          get_lines = [f'attr_{self.c_name} = attr;',
> -                     'ynl_attr_for_each_nested(attr2, attr) {',
> -                     '\tif (ynl_attr_validate(yarg, attr2))',
> -                     '\t\treturn YNL_PARSE_CB_ERROR;',
> -                     f'\tn_{self.c_name}++;',
> -                     '}']
> +                     'ynl_attr_for_each_nested(attr2, attr) {']
> +        if self.attr['sub-type'] != 'nest':
> +            get_lines.append('\tif (ynl_attr_validate(yarg, attr2))')
> +            get_lines.append('\t\treturn YNL_PARSE_CB_ERROR;')
> +        get_lines.append(f'\tn_{self.c_name}++;')
> +        get_lines.append('}')
>          return get_lines, None, local_vars
>  
>      def attr_put(self, ri, var):
OpenPGP_signature.asc (application/pgp-signature, 236 B)
-----BEGIN PGP SIGNATURE-----

wnsEABYIACMWIQQgQFSp1zOQVirsQx5qll0+bw8o6AUCaLt/IgUDAAAAAAAKCRBqll0+bw8o6B07
AQCOTQb8Z7IBEcmbiXR0yfQlwMWcgApwy+UDcXwmhoeoGwD/bCsi+hE+fB6/hVL1uX5BekT4c8GP
KnEnu+018Hz+eQk=
=fQkn
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.