]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools: ynl-gen: support using pre-defined values in attr checks
authorHangbin Liu <liuhangbin@gmail.com>
Mon, 11 Mar 2024 14:07:27 +0000 (22:07 +0800)
committerJakub Kicinski <kuba@kernel.org>
Mon, 11 Mar 2024 20:07:48 +0000 (13:07 -0700)
Support using pre-defined values in checks so we don't need to use hard
code number for the string, binary length. e.g. we have a definition like

 #define TEAM_STRING_MAX_LEN 32

Which defined in yaml like:

 definitions:
   -
     name: string-max-len
     type: const
     value: 32

It can be used in the attribute-sets like

attribute-sets:
  -
    name: attr-option
    name-prefix: team-attr-option-
    attributes:
      -
        name: name
        type: string
        checks:
          len: string-max-len

With this patch it will be converted to

[TEAM_ATTR_OPTION_NAME] = { .type = NLA_STRING, .len = TEAM_STRING_MAX_LEN, }

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Link: https://lore.kernel.org/r/20240311140727.109562-1-liuhangbin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Documentation/netlink/genetlink-c.yaml
Documentation/netlink/genetlink-legacy.yaml
Documentation/netlink/genetlink.yaml
Documentation/netlink/netlink-raw.yaml
tools/net/ynl/ynl-gen-c.py

index 3ebd50d788200cf282b385424f4edac2a030add8..24692a9343f087de01c445ba0b90f99fe08c9bbc 100644 (file)
@@ -11,7 +11,7 @@ $defs:
     minimum: 0
   len-or-define:
     type: [ string, integer ]
-    pattern: ^[0-9A-Za-z_]+( - 1)?$
+    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.
index 1d3fe36377079786fa36c1e504559d0287e3afa9..b0b7e8bab8a983d5ef330813991798a5356d4cc0 100644 (file)
@@ -11,7 +11,7 @@ $defs:
     minimum: 0
   len-or-define:
     type: [ string, integer ]
-    pattern: ^[0-9A-Za-z_]+( - 1)?$
+    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.
index 3283bf458ff13dc829232e4197fbd257c6e637d7..d7edb88555630e153934e4fe5f0dd4fc1ed8c659 100644 (file)
@@ -11,7 +11,7 @@ $defs:
     minimum: 0
   len-or-define:
     type: [ string, integer ]
-    pattern: ^[0-9A-Za-z_]+( - 1)?$
+    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.
index 40fc8ab1ee4428b8102317eac15991d435ee2ff2..57490e5c1ddf81105e9d14f1915153cb5e87a2c7 100644 (file)
@@ -11,7 +11,7 @@ $defs:
     minimum: 0
   len-or-define:
     type: [ string, integer ]
-    pattern: ^[0-9A-Za-z_]+( - 1)?$
+    pattern: ^[0-9A-Za-z_-]+( - 1)?$
     minimum: 0
 
 # Schema for specs
index 67bfaff0515458ec43dca4a51708cf06c51a0093..5bb7ca01fe510d0af6930cd8ac7846186bf7728a 100755 (executable)
@@ -80,6 +80,8 @@ class Type(SpecAttr):
         value = self.checks.get(limit, default)
         if value is None:
             return value
+        elif value in self.family.consts:
+            return c_upper(f"{self.family['name']}-{value}")
         if not isinstance(value, int):
             value = limit_to_number(value)
         return value