tools: ynl-gen: refactor check validation for TypeBinary
Subsystems (3)
Jakub Kicinski
maintainerPATCH 1/1 tools: ynl-gen: refactor check validation for TypeBinary
We only support a single check at a time for TypeBinary. Refactor the code to cover 'exact-len' and make adding new checks easier.
---
CC: [email protected]
CC: Antonio Quartulli <[email protected]>
--- tools/net/ynl/ynl-gen-c.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
tools/net/ynl/ynl-gen-c.py +15 -10
@@ -464,17 +464,22 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S return f'.type = YNL_PT_BINARY,' def _attr_policy(self, policy): - if 'exact-len' in self.checks: - mem = 'NLA_POLICY_EXACT_LEN(' + str(self.get_limit('exact-len')) + ')' + if len(self.checks) == 0: + pass + elif len(self.checks) == 1: + check_name = list(self.checks)[0] + if check_name not in {'exact-len', 'min-len'}: + raise Exception('Unsupported check for binary type: ' + check_name) else: - mem = '{ ' - if len(self.checks) == 1 and 'min-len' in self.checks: - mem += '.len = ' + str(self.get_limit('min-len')) - elif len(self.checks) == 0: - mem += '.type = NLA_BINARY' - else: - raise Exception('One or more of binary type checks not implemented, yet') - mem += ', }' + raise Exception('More than one check for binary type not implemented, yet') + + if len(self.checks) == 0: + mem = '{ .type = NLA_BINARY, }' + elif 'exact-len' in self.checks: + mem = 'NLA_POLICY_EXACT_LEN(' + str(self.get_limit('exact-len')) + ')' + elif 'min-len' in self.checks: + mem = '{ .len = ' + str(self.get_limit('min-len')) + ', }' + return mem def attr_put(self, ri, var):
Signature · 1 line
2.46.2
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, 7 Oct 2024 08:53:11 -0700 you wrote:
We only support a single check at a time for TypeBinary. Refactor the code to cover 'exact-len' and make adding new checks easier.
Signed-off-by Jakub Kicinski <[email protected]>[...]
Here is the summary with links:
- [net-next] tools: ynl-gen: refactor check validation for TypeBinary
https://git.kernel.org/netdev/net-next/c/42b233108117
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 6 lines · Jakub Kicinski
We only support a single check at a time for TypeBinary. Refactor the code to cover 'exact-len' and make adding new checks easier.