diff options
author | Davide Caratti <dcaratti@redhat.com> | 2023-10-23 21:17:06 +0300 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2023-10-24 23:00:31 +0300 |
commit | 0c63ad3795269849782ca24a084952206986d3bf (patch) | |
tree | 4585356be03103804c46a0c2da49302580e829ae /tools/net/ynl/ynl-gen-c.py | |
parent | 52c121f4bf27592530f3fedf123b89ed79397af8 (diff) | |
download | linux-0c63ad3795269849782ca24a084952206986d3bf.tar.xz |
tools: ynl-gen: add support for exact-len validation
add support for 'exact-len' validation on netlink attributes.
Link: https://github.com/multipath-tcp/mptcp_net-next/issues/340
Acked-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: Mat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20231023-send-net-next-20231023-1-v2-2-16b1f701f900@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/net/ynl/ynl-gen-c.py')
-rwxr-xr-x | tools/net/ynl/ynl-gen-c.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py index 8ae283b1a9bc..0fee68863db4 100755 --- a/tools/net/ynl/ynl-gen-c.py +++ b/tools/net/ynl/ynl-gen-c.py @@ -410,10 +410,13 @@ class TypeString(Type): return f'.type = YNL_PT_NUL_STR, ' def _attr_policy(self, policy): - mem = '{ .type = ' + policy - if 'max-len' in self.checks: - mem += ', .len = ' + str(self.get_limit('max-len')) - mem += ', }' + if 'exact-len' in self.checks: + mem = 'NLA_POLICY_EXACT_LEN(' + str(self.checks['exact-len']) + ')' + else: + mem = '{ .type = ' + policy + if 'max-len' in self.checks: + mem += ', .len = ' + str(self.get_limit('max-len')) + mem += ', }' return mem def attr_policy(self, cw): @@ -459,14 +462,17 @@ class TypeBinary(Type): return f'.type = YNL_PT_BINARY,' def _attr_policy(self, policy): - 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' + if 'exact-len' in self.checks: + mem = 'NLA_POLICY_EXACT_LEN(' + str(self.checks['exact-len']) + ')' else: - raise Exception('One or more of binary type checks not implemented, yet') - mem += ', }' + 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 += ', }' return mem def attr_put(self, ri, var): |