From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, horms@kernel.org, donald.hunter@gmail.com,
jacob.e.keller@intel.com, sdf@fomichev.me, jdamato@fastly.com,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 10/12] tools: ynl-gen: array-nest: support binary array with exact-len
Date: Thu, 24 Apr 2025 19:43:09 -0700 [thread overview]
Message-ID: <20250425024311.1589323-11-kuba@kernel.org> (raw)
In-Reply-To: <20250425024311.1589323-1-kuba@kernel.org>
IPv6 addresses are expressed as binary arrays since we don't have u128.
Since they are not variable length, however, they are relatively
easy to represent as an array of known size.
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/net/ynl/pyynl/ynl_gen_c.py | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index a4e65da19696..2d185c7ea16c 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -183,10 +183,10 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
raise Exception(f"Struct member not implemented for class type {self.type}")
def struct_member(self, ri):
- if self.is_multi_val():
- ri.cw.p(f"unsigned int n_{self.c_name};")
member = self._complex_member_type(ri)
if member:
+ if self.is_multi_val():
+ ri.cw.p(f"unsigned int n_{self.c_name};")
ptr = '*' if self.is_multi_val() else ''
if self.is_recursive_for_op(ri):
ptr = '*'
@@ -728,12 +728,22 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
elif self.attr['sub-type'] in scalars:
scalar_pfx = '__' if ri.ku_space == 'user' else ''
return scalar_pfx + self.attr['sub-type']
+ elif self.attr['sub-type'] == 'binary' and 'exact-len' in self.checks:
+ return None # use arg_member()
else:
raise Exception(f"Sub-type {self.attr['sub-type']} not supported yet")
+ def arg_member(self, ri):
+ if self.sub_type == 'binary' and 'exact-len' in self.checks:
+ return [f'unsigned char (*{self.c_name})[{self.checks["exact-len"]}]',
+ f'unsigned int n_{self.c_name}']
+ return super().arg_member(ri)
+
def _attr_typol(self):
if self.attr['sub-type'] in scalars:
return f'.type = YNL_PT_U{c_upper(self.sub_type[1:])}, '
+ elif self.attr['sub-type'] == 'binary' and 'exact-len' in self.checks:
+ return f'.type = YNL_PT_BINARY, .len = {self.checks["exact-len"]}, '
else:
return f'.type = YNL_PT_NEST, .nest = &{self.nested_render_name}_nest, '
@@ -754,6 +764,9 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
ri.cw.block_start(line=f'for (i = 0; i < {var}->n_{self.c_name}; i++)')
ri.cw.p(f"ynl_attr_put_{put_type}(nlh, i, {var}->{self.c_name}[i]);")
ri.cw.block_end()
+ elif self.sub_type == 'binary' and 'exact-len' in self.checks:
+ ri.cw.p(f'for (i = 0; i < {var}->n_{self.c_name}; i++)')
+ ri.cw.p(f"ynl_attr_put(nlh, i, {var}->{self.c_name}[i], {self.checks['exact-len']});")
else:
raise Exception(f"Put for ArrayNest sub-type {self.attr['sub-type']} not supported, yet")
ri.cw.p('ynl_attr_nest_end(nlh, array);')
@@ -964,7 +977,7 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
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"] in ['nest', 'u32']:
+ if elem["sub-type"] in ['binary', 'nest', 'u32']:
t = TypeArrayNest(self.family, self, elem, value)
else:
raise Exception(f'new_attr: unsupported sub-type {elem["sub-type"]}')
@@ -1786,7 +1799,7 @@ _C_KW = {
needs_parg = False
for arg, aspec in struct.member_list():
if aspec['type'] == 'indexed-array' and 'sub-type' in aspec:
- if aspec["sub-type"] == 'nest':
+ if aspec["sub-type"] in {'binary', 'nest'}:
local_vars.append(f'const struct nlattr *attr_{aspec.c_name};')
array_nests.add(arg)
elif aspec['sub-type'] in scalars:
@@ -1859,6 +1872,9 @@ _C_KW = {
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);")
+ elif aspec.sub_type == 'binary' and 'exact-len' in aspec.checks:
+ # Length is validated by typol
+ ri.cw.p(f'memcpy(dst->{aspec.c_name}[i], ynl_attr_data(attr), {aspec.checks["exact-len"]});')
else:
raise Exception(f"Nest parsing type not supported in {aspec['name']}")
ri.cw.p('i++;')
--
2.49.0
next prev parent reply other threads:[~2025-04-25 2:43 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-25 2:42 [PATCH net-next v2 00/12] tools: ynl-gen: additional C types and classic netlink handling Jakub Kicinski
2025-04-25 2:43 ` [PATCH net-next v2 01/12] tools: ynl-gen: fix comment about nested struct dict Jakub Kicinski
2025-04-25 9:08 ` Donald Hunter
2025-04-25 2:43 ` [PATCH net-next v2 02/12] tools: ynl-gen: factor out free_needs_iter for a struct Jakub Kicinski
2025-04-25 9:09 ` Donald Hunter
2025-04-25 2:43 ` [PATCH net-next v2 03/12] tools: ynl-gen: fill in missing empty attr lists Jakub Kicinski
2025-04-25 9:12 ` Donald Hunter
2025-04-25 2:43 ` [PATCH net-next v2 04/12] tools: ynl: let classic netlink requests specify extra nlflags Jakub Kicinski
2025-04-25 9:15 ` Donald Hunter
2025-04-25 2:43 ` [PATCH net-next v2 05/12] tools: ynl-gen: support using dump types for ntf Jakub Kicinski
2025-04-25 9:16 ` Donald Hunter
2025-04-25 2:43 ` [PATCH net-next v2 06/12] tools: ynl-gen: support CRUD-like notifications for classic Netlink Jakub Kicinski
2025-04-25 9:21 ` Donald Hunter
2025-04-25 2:43 ` [PATCH net-next v2 07/12] tools: ynl-gen: multi-attr: type gen for string Jakub Kicinski
2025-04-25 9:26 ` Donald Hunter
2025-04-25 17:21 ` Simon Horman
2025-04-25 2:43 ` [PATCH net-next v2 08/12] tools: ynl-gen: mutli-attr: support binary types with struct Jakub Kicinski
2025-04-25 9:27 ` Donald Hunter
2025-04-25 2:43 ` [PATCH net-next v2 09/12] tools: ynl-gen: array-nest: support put for scalar Jakub Kicinski
2025-04-25 9:48 ` Donald Hunter
2025-04-25 2:43 ` Jakub Kicinski [this message]
2025-04-25 9:56 ` [PATCH net-next v2 10/12] tools: ynl-gen: array-nest: support binary array with exact-len Donald Hunter
2025-04-25 2:43 ` [PATCH net-next v2 11/12] tools: ynl-gen: don't init enum checks for classic netlink Jakub Kicinski
2025-04-25 10:04 ` Donald Hunter
2025-04-25 2:43 ` [PATCH net-next v2 12/12] tools: ynl: allow fixed-header to be specified per op Jakub Kicinski
2025-04-25 10:08 ` 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=20250425024311.1589323-11-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=jdamato@fastly.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).