Subject: Re: [PATCH net-next v2 4/6] tools: ynl: Add struct attr decoding to ynl

From: Jakub Kicinski <[email-masked]>
Date: Wed, 22 Mar 2023 11:37:59 -0700

On Wed, 22 Mar 2023 11:48:12 +0000 Donald Hunter wrote:
> > On Sun, 19 Mar 2023 19:38:01 +0000 Donald Hunter wrote:  
> >>                  enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
> >> -                        string, nest, array-nest, nest-type-value ]
> >> +                        string, nest, array-nest, nest-type-value, struct ]  
> >
> > I wonder if we should also only allow struct as a subtype of binary?
> >
> > Structs can technically grow with newer kernels (i.e. new members can
> > be added at the end). So I think for languages like C we will still
> > need to expose to the user the original length of the attribute.
> > And binary comes with a length so codgen reuse fits nicely.
> >
> > Either way - docs need to be updated.  
> 
> Yep, as I was replying to your previous comment, I started to think
> about making struct a subtype of binary. That would make a struct attr
> something like:
> 
>  -
>    name: stats
>    type: binary
>    sub-type: struct
>    struct: vport-stats

LGTM!

> I originally chose 'struct' as the attr name, following the pattern that
> 'enum' is used for enum names but I'm not sure it's clear enough. Maybe
> 'sub-type-name' would be better?

Agreed, using the sub-type's value as name of another attr 
is mixing keys and values.

But sub-type-name would then also be used for enums (I mean in 
normal type: u32 enums, not binary arrays)?
enums don't have a sub-type so there we'd have sub-type-name
and no sub-type.
Plus for binary arrays of enums we'd have:

  -
    name: stats
    type: binary
    sub-type: u32
    sub-type-name: vport-stats

Doesn't say enum anywhere :S  We'd need to assume if sub-type is
a scalar the sub-type-name is an enum?

Maybe to avoid saying struct twice we should go the enum way and
actually ditch the sub-type for structs? Presence of struct: abc
implies it's a struct, only use sub-type for scalar types?

  -
    name: stats
    type: binary
    struct: vport-stats

  -
    name: another
    type: binary
    sub-type: u32
    enum: enums-name