Skip to content

Commit

Permalink
tools: ynl-gen: support limits using definitions
Browse files Browse the repository at this point in the history
Support using defines / constants in integer checks.
Carolina will need this for rate API extensions.

Reported-by: Carolina Jubran <cjubran@nvidia.com>
Link: https://lore.kernel.org/1e886aaf-e1eb-4f1a-b7ef-f63b350a3320@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Link: https://patch.msgid.link/20250203215510.1288728-2-kuba@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Jakub Kicinski authored and Paolo Abeni committed Feb 6, 2025
1 parent 7e8b24e commit fa79617
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Documentation/netlink/genetlink-c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ $defs:
pattern: ^[0-9A-Za-z_-]+( - 1)?$
minimum: 0
len-or-limit:
# literal int or limit based on fixed-width type e.g. u8-min, u16-max, etc.
# literal int, const name, or limit based on fixed-width type
# e.g. u8-min, u16-max, etc.
type: [ string, integer ]
pattern: ^[su](8|16|32|64)-(min|max)$
pattern: ^[0-9A-Za-z_-]+$
minimum: 0

# Schema for specs
Expand Down
5 changes: 3 additions & 2 deletions Documentation/netlink/genetlink-legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ $defs:
pattern: ^[0-9A-Za-z_-]+( - 1)?$
minimum: 0
len-or-limit:
# literal int or limit based on fixed-width type e.g. u8-min, u16-max, etc.
# literal int, const name, or limit based on fixed-width type
# e.g. u8-min, u16-max, etc.
type: [ string, integer ]
pattern: ^[su](8|16|32|64)-(min|max)$
pattern: ^[0-9A-Za-z_-]+$
minimum: 0

# Schema for specs
Expand Down
5 changes: 3 additions & 2 deletions Documentation/netlink/genetlink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ $defs:
pattern: ^[0-9A-Za-z_-]+( - 1)?$
minimum: 0
len-or-limit:
# literal int or limit based on fixed-width type e.g. u8-min, u16-max, etc.
# literal int, const name, or limit based on fixed-width type
# e.g. u8-min, u16-max, etc.
type: [ string, integer ]
pattern: ^[su](8|16|32|64)-(min|max)$
pattern: ^[0-9A-Za-z_-]+$
minimum: 0

# Schema for specs
Expand Down
5 changes: 4 additions & 1 deletion tools/net/ynl/pyynl/ynl_gen_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_limit(self, limit, default=None):
if isinstance(value, int):
return value
if value in self.family.consts:
raise Exception("Resolving family constants not implemented, yet")
return self.family.consts[value]["value"]
return limit_to_number(value)

def get_limit_str(self, limit, default=None, suffix=''):
Expand All @@ -110,6 +110,9 @@ def get_limit_str(self, limit, default=None, suffix=''):
if isinstance(value, int):
return str(value) + suffix
if value in self.family.consts:
const = self.family.consts[value]
if const.get('header'):
return c_upper(value)
return c_upper(f"{self.family['name']}-{value}")
return c_upper(value)

Expand Down

0 comments on commit fa79617

Please sign in to comment.