Skip to content

Commit fa79617

Browse files
kuba-mooPaolo Abeni
authored andcommitted
tools: ynl-gen: support limits using definitions
Support using defines / constants in integer checks. Carolina will need this for rate API extensions. Reported-by: Carolina Jubran <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 7e8b24e commit fa79617

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

Documentation/netlink/genetlink-c.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ $defs:
1414
pattern: ^[0-9A-Za-z_-]+( - 1)?$
1515
minimum: 0
1616
len-or-limit:
17-
# literal int or limit based on fixed-width type e.g. u8-min, u16-max, etc.
17+
# literal int, const name, or limit based on fixed-width type
18+
# e.g. u8-min, u16-max, etc.
1819
type: [ string, integer ]
19-
pattern: ^[su](8|16|32|64)-(min|max)$
20+
pattern: ^[0-9A-Za-z_-]+$
2021
minimum: 0
2122

2223
# Schema for specs

Documentation/netlink/genetlink-legacy.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ $defs:
1414
pattern: ^[0-9A-Za-z_-]+( - 1)?$
1515
minimum: 0
1616
len-or-limit:
17-
# literal int or limit based on fixed-width type e.g. u8-min, u16-max, etc.
17+
# literal int, const name, or limit based on fixed-width type
18+
# e.g. u8-min, u16-max, etc.
1819
type: [ string, integer ]
19-
pattern: ^[su](8|16|32|64)-(min|max)$
20+
pattern: ^[0-9A-Za-z_-]+$
2021
minimum: 0
2122

2223
# Schema for specs

Documentation/netlink/genetlink.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ $defs:
1414
pattern: ^[0-9A-Za-z_-]+( - 1)?$
1515
minimum: 0
1616
len-or-limit:
17-
# literal int or limit based on fixed-width type e.g. u8-min, u16-max, etc.
17+
# literal int, const name, or limit based on fixed-width type
18+
# e.g. u8-min, u16-max, etc.
1819
type: [ string, integer ]
19-
pattern: ^[su](8|16|32|64)-(min|max)$
20+
pattern: ^[0-9A-Za-z_-]+$
2021
minimum: 0
2122

2223
# Schema for specs

tools/net/ynl/pyynl/ynl_gen_c.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def get_limit(self, limit, default=None):
100100
if isinstance(value, int):
101101
return value
102102
if value in self.family.consts:
103-
raise Exception("Resolving family constants not implemented, yet")
103+
return self.family.consts[value]["value"]
104104
return limit_to_number(value)
105105

106106
def get_limit_str(self, limit, default=None, suffix=''):
@@ -110,6 +110,9 @@ def get_limit_str(self, limit, default=None, suffix=''):
110110
if isinstance(value, int):
111111
return str(value) + suffix
112112
if value in self.family.consts:
113+
const = self.family.consts[value]
114+
if const.get('header'):
115+
return c_upper(value)
113116
return c_upper(f"{self.family['name']}-{value}")
114117
return c_upper(value)
115118

0 commit comments

Comments
 (0)