Skip to contentSkip to conversation

tools: ynl-gen: support using pre-defined values in attr checks

PATCH Applied Hangbin Liu 2 participants 2 messages Mar 11, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 tools: ynl-gen: support using pre-defined values in attr checks

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, }

---
v3: iterating over self.family.consts as self.family['definitions'] is optional (Jakub Kicinski)
v2: Update the commit description. Drop other controversial patches.
v1 link: lore.kernel.org/netdev/[email protected]

---
 Documentation/netlink/genetlink-c.yaml      | 2 +-
 Documentation/netlink/genetlink-legacy.yaml | 2 +-
 Documentation/netlink/genetlink.yaml        | 2 +-
 Documentation/netlink/netlink-raw.yaml      | 2 +-
 tools/net/ynl/ynl-gen-c.py                  | 2 ++
 5 files changed, 6 insertions(+), 4 deletions(-)
Documentation/netlink/genetlink-c.yaml +1 -1
index 3ebd50d78820..24692a9343f0 100644
@@ -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.
Documentation/netlink/genetlink-legacy.yaml +1 -1
index 1d3fe3637707..b0b7e8bab8a9 100644
@@ -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.
Documentation/netlink/genetlink.yaml +1 -1
index 3283bf458ff1..d7edb8855563 100644
@@ -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.
Documentation/netlink/netlink-raw.yaml +1 -1
index 40fc8ab1ee44..57490e5c1ddf 100644
@@ -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
tools/net/ynl/ynl-gen-c.py +2 -0
index 67bfaff05154..5bb7ca01fe51 100755
@@ -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
Signature · 1 line
2.43.0
#1 lore raw
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 11 Mar 2024 22:07:27 +0800 you wrote:

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:

[...]

Here is the summary with links:
- [PATCHv3,net-next] tools: ynl-gen: support using pre-defined values in attr checks

    https://git.kernel.org/netdev/net-next/c/8d0c314c30c9

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html