* [PATCH net-next] tools: ynl-gen: refactor check validation for TypeBinary
@ 2024-10-07 15:53 Jakub Kicinski
2024-10-08 8:51 ` Donald Hunter
2024-10-08 17:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Jakub Kicinski @ 2024-10-07 15:53 UTC (permalink / raw)
To: davem
Cc: netdev, edumazet, pabeni, Jakub Kicinski, donald.hunter,
Antonio Quartulli
We only support a single check at a time for TypeBinary.
Refactor the code to cover 'exact-len' and make adding
new checks easier.
Link: https://lore.kernel.org/20241004063855.1a693dd1@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: donald.hunter@gmail.com
CC: Antonio Quartulli <antonio@openvpn.net>
---
tools/net/ynl/ynl-gen-c.py | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 717530bc9c52..9e8254aad578 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -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):
--
2.46.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next] tools: ynl-gen: refactor check validation for TypeBinary
2024-10-07 15:53 [PATCH net-next] tools: ynl-gen: refactor check validation for TypeBinary Jakub Kicinski
@ 2024-10-08 8:51 ` Donald Hunter
2024-10-08 17:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Donald Hunter @ 2024-10-08 8:51 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, Antonio Quartulli
Jakub Kicinski <kuba@kernel.org> writes:
> We only support a single check at a time for TypeBinary.
> Refactor the code to cover 'exact-len' and make adding
> new checks easier.
>
> Link: https://lore.kernel.org/20241004063855.1a693dd1@kernel.org
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] tools: ynl-gen: refactor check validation for TypeBinary
2024-10-07 15:53 [PATCH net-next] tools: ynl-gen: refactor check validation for TypeBinary Jakub Kicinski
2024-10-08 8:51 ` Donald Hunter
@ 2024-10-08 17:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-10-08 17:10 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, donald.hunter, antonio
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
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.
>
> Link: https://lore.kernel.org/20241004063855.1a693dd1@kernel.org
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
>
> [...]
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-11 10:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-07 15:53 [PATCH net-next] tools: ynl-gen: refactor check validation for TypeBinary Jakub Kicinski
2024-10-08 8:51 ` Donald Hunter
2024-10-08 17:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).