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,
nicolas.dichtel@6wind.com, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v3 11/12] tools: ynl-gen: don't init enum checks for classic netlink
Date: Tue, 29 Apr 2025 08:47:03 -0700 [thread overview]
Message-ID: <20250429154704.2613851-12-kuba@kernel.org> (raw)
In-Reply-To: <20250429154704.2613851-1-kuba@kernel.org>
rt-link has a vlan-protocols enum with:
name: 8021q value: 33024
name: 8021ad value: 34984
It's nice to have, since it converts the values to strings in Python.
For C, however, the codegen is trying to use enums to generate strict
policy checks. Parsing such sparse enums is not possible via policies.
Since for classic netlink we don't support kernel codegen and policy
generation - skip the auto-generation of checks from enums.
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v3:
- improve grammar
v2: https://lore.kernel.org/20250425024311.1589323-12-kuba@kernel.org
- move the comment about the skip before the if
v1: https://lore.kernel.org/4b8339b7-9dc6-4231-a60f-0c9f6296358a@intel.com
---
tools/net/ynl/pyynl/ynl_gen_c.py | 46 ++++++++++++++++++--------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index 2d185c7ea16c..1dd9580086cd 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -357,26 +357,10 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
if 'byte-order' in attr:
self.byte_order_comment = f" /* {attr['byte-order']} */"
- if 'enum' in self.attr:
- enum = self.family.consts[self.attr['enum']]
- low, high = enum.value_range()
- if 'min' not in self.checks:
- if low != 0 or self.type[0] == 's':
- self.checks['min'] = low
- if 'max' not in self.checks:
- self.checks['max'] = high
-
- if 'min' in self.checks and 'max' in self.checks:
- if self.get_limit('min') > self.get_limit('max'):
- raise Exception(f'Invalid limit for "{self.name}" min: {self.get_limit("min")} max: {self.get_limit("max")}')
- self.checks['range'] = True
-
- low = min(self.get_limit('min', 0), self.get_limit('max', 0))
- high = max(self.get_limit('min', 0), self.get_limit('max', 0))
- if low < 0 and self.type[0] == 'u':
- raise Exception(f'Invalid limit for "{self.name}" negative limit for unsigned type')
- if low < -32768 or high > 32767:
- self.checks['full-range'] = True
+ # Classic families have some funny enums, don't bother
+ # computing checks, since we only need them for kernel policies
+ if not family.is_classic():
+ self._init_checks()
# Added by resolve():
self.is_bitfield = None
@@ -401,6 +385,28 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
else:
self.type_name = '__' + self.type
+ def _init_checks(self):
+ if 'enum' in self.attr:
+ enum = self.family.consts[self.attr['enum']]
+ low, high = enum.value_range()
+ if 'min' not in self.checks:
+ if low != 0 or self.type[0] == 's':
+ self.checks['min'] = low
+ if 'max' not in self.checks:
+ self.checks['max'] = high
+
+ if 'min' in self.checks and 'max' in self.checks:
+ if self.get_limit('min') > self.get_limit('max'):
+ raise Exception(f'Invalid limit for "{self.name}" min: {self.get_limit("min")} max: {self.get_limit("max")}')
+ self.checks['range'] = True
+
+ low = min(self.get_limit('min', 0), self.get_limit('max', 0))
+ high = max(self.get_limit('min', 0), self.get_limit('max', 0))
+ if low < 0 and self.type[0] == 'u':
+ raise Exception(f'Invalid limit for "{self.name}" negative limit for unsigned type')
+ if low < -32768 or high > 32767:
+ self.checks['full-range'] = True
+
def _attr_policy(self, policy):
if 'flags-mask' in self.checks or self.is_bitfield:
if self.is_bitfield:
--
2.49.0
next prev parent reply other threads:[~2025-04-29 15:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-29 15:46 [PATCH net-next v3 00/12] tools: ynl-gen: additional C types and classic netlink handling Jakub Kicinski
2025-04-29 15:46 ` [PATCH net-next v3 01/12] tools: ynl-gen: fix comment about nested struct dict Jakub Kicinski
2025-04-29 15:46 ` [PATCH net-next v3 02/12] tools: ynl-gen: factor out free_needs_iter for a struct Jakub Kicinski
2025-04-29 15:46 ` [PATCH net-next v3 03/12] tools: ynl-gen: fill in missing empty attr lists Jakub Kicinski
2025-04-29 15:46 ` [PATCH net-next v3 04/12] tools: ynl: let classic netlink requests specify extra nlflags Jakub Kicinski
2025-04-29 15:46 ` [PATCH net-next v3 05/12] tools: ynl-gen: support using dump types for ntf Jakub Kicinski
2025-04-29 15:46 ` [PATCH net-next v3 06/12] tools: ynl-gen: support CRUD-like notifications for classic Netlink Jakub Kicinski
2025-04-29 15:46 ` [PATCH net-next v3 07/12] tools: ynl-gen: multi-attr: type gen for string Jakub Kicinski
2025-04-29 15:47 ` [PATCH net-next v3 08/12] tools: ynl-gen: mutli-attr: support binary types with struct Jakub Kicinski
2025-04-29 15:47 ` [PATCH net-next v3 09/12] tools: ynl-gen: array-nest: support put for scalar Jakub Kicinski
2025-04-29 15:47 ` [PATCH net-next v3 10/12] tools: ynl-gen: array-nest: support binary array with exact-len Jakub Kicinski
2025-04-29 15:47 ` Jakub Kicinski [this message]
2025-04-29 15:47 ` [PATCH net-next v3 12/12] tools: ynl: allow fixed-header to be specified per op Jakub Kicinski
2025-05-02 10:50 ` [PATCH net-next v3 00/12] tools: ynl-gen: additional C types and classic netlink handling patchwork-bot+netdevbpf
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=20250429154704.2613851-12-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=nicolas.dichtel@6wind.com \
--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).