From: Donald Hunter <donald.hunter@gmail.com>
To: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Johannes Berg <johannes@sipsolutions.net>,
linux-wireless@vger.kernel.org
Cc: donald.hunter@redhat.com, Donald Hunter <donald.hunter@gmail.com>
Subject: [PATCH net-next v3 07/10] tools/net/ynl: add indexed-array scalar support to ynl-gen-c
Date: Thu, 6 Feb 2025 09:26:55 +0000 [thread overview]
Message-ID: <20250206092658.1383-8-donald.hunter@gmail.com> (raw)
In-Reply-To: <20250206092658.1383-1-donald.hunter@gmail.com>
Extend ynl-gen-c.py with support for indexed-array that has a scalar
sub-type.
Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
tools/net/ynl/pyynl/ynl_gen_c.py | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index 1316a4fe798a..7e6454185310 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -687,7 +687,10 @@ class TypeArrayNest(Type):
raise Exception(f"Sub-type {self.attr['sub-type']} not supported yet")
def _attr_typol(self):
- return f'.type = YNL_PT_NEST, .nest = &{self.nested_render_name}_nest, '
+ if self.attr['sub-type'] in scalars:
+ return f'.type = YNL_PT_U{c_upper(self.sub_type[1:])}, '
+ else:
+ return f'.type = YNL_PT_NEST, .nest = &{self.nested_render_name}_nest, '
def _attr_get(self, ri, var):
local_vars = ['const struct nlattr *attr2;']
@@ -889,7 +892,7 @@ class AttrSet(SpecAttrSet):
elif elem['type'] == 'nest':
t = TypeNest(self.family, self, elem, value)
elif elem['type'] == 'indexed-array' and 'sub-type' in elem:
- if elem["sub-type"] == 'nest':
+ if elem["sub-type"] in ['nest', 'u32']:
t = TypeArrayNest(self.family, self, elem, value)
else:
raise Exception(f'new_attr: unsupported sub-type {elem["sub-type"]}')
@@ -1673,6 +1676,9 @@ def _multi_parse(ri, struct, init_lines, local_vars):
if aspec["sub-type"] == 'nest':
local_vars.append(f'const struct nlattr *attr_{aspec.c_name};')
array_nests.add(arg)
+ elif aspec['sub-type'] in scalars:
+ local_vars.append(f'const struct nlattr *attr_{aspec.c_name};')
+ array_nests.add(arg)
else:
raise Exception(f'Not supported sub-type {aspec["sub-type"]}')
if 'multi-attr' in aspec:
@@ -1728,11 +1734,17 @@ def _multi_parse(ri, struct, init_lines, local_vars):
ri.cw.p(f"dst->{aspec.c_name} = calloc(n_{aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
ri.cw.p(f"dst->n_{aspec.c_name} = n_{aspec.c_name};")
ri.cw.p('i = 0;')
- ri.cw.p(f"parg.rsp_policy = &{aspec.nested_render_name}_nest;")
+ if 'nested-attributes' in aspec:
+ ri.cw.p(f"parg.rsp_policy = &{aspec.nested_render_name}_nest;")
ri.cw.block_start(line=f"ynl_attr_for_each_nested(attr, attr_{aspec.c_name})")
- ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
- ri.cw.p(f"if ({aspec.nested_render_name}_parse(&parg, attr, ynl_attr_type(attr)))")
- ri.cw.p('return YNL_PARSE_CB_ERROR;')
+ if 'nested-attributes' in aspec:
+ ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
+ ri.cw.p(f"if ({aspec.nested_render_name}_parse(&parg, attr, ynl_attr_type(attr)))")
+ ri.cw.p('return YNL_PARSE_CB_ERROR;')
+ elif aspec.sub_type in scalars:
+ ri.cw.p(f"dst->{aspec.c_name}[i] = ynl_attr_get_{aspec.sub_type}(attr);")
+ else:
+ raise Exception(f"Nest parsing type not supported in {aspec['name']}")
ri.cw.p('i++;')
ri.cw.block_end()
ri.cw.block_end()
--
2.48.1
next prev parent reply other threads:[~2025-02-06 9:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 9:26 [PATCH net-next v3 00/10] netlink: specs: add a spec for nl80211 wiphy Donald Hunter
2025-02-06 9:26 ` [PATCH net-next v3 01/10] tools/net/ynl: remove extraneous plural from variable names Donald Hunter
2025-02-06 9:26 ` [PATCH net-next v3 02/10] tools/net/ynl: support decoding indexed arrays as enums Donald Hunter
2025-02-06 9:26 ` [PATCH net-next v3 03/10] tools/net/ynl: support rendering C array members to strings Donald Hunter
2025-02-06 9:26 ` [PATCH net-next v3 04/10] tools/net/ynl: accept IP string inputs Donald Hunter
2025-02-06 16:07 ` Jakub Kicinski
2025-02-06 9:26 ` [PATCH net-next v3 05/10] tools/net/ynl: add s8, s16 to valid scalars in ynl-gen-c Donald Hunter
2025-02-06 16:07 ` Jakub Kicinski
2025-02-06 9:26 ` [PATCH net-next v3 06/10] tools/net/ynl: sanitise enums with leading digits " Donald Hunter
2025-02-06 16:10 ` Jakub Kicinski
2025-02-07 9:24 ` Donald Hunter
2025-02-06 9:26 ` Donald Hunter [this message]
2025-02-06 16:12 ` [PATCH net-next v3 07/10] tools/net/ynl: add indexed-array scalar support to ynl-gen-c Jakub Kicinski
2025-02-06 9:26 ` [PATCH net-next v3 08/10] netlink: specs: support nested structs in genetlink legacy Donald Hunter
2025-02-06 9:26 ` [PATCH net-next v3 09/10] netlink: specs: add s8, s16 to genetlink schemas Donald Hunter
2025-02-06 9:26 ` [PATCH net-next v3 10/10] netlink: specs: wireless: add a spec for nl80211 Donald Hunter
2025-02-06 9:43 ` Johannes Berg
2025-02-06 12:12 ` Donald Hunter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250206092658.1383-8-donald.hunter@gmail.com \
--to=donald.hunter@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@redhat.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.