Commit 0c63ad37 authored by Davide Caratti's avatar Davide Caratti Committed by Jakub Kicinski

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/340Acked-by: default avatarMatthieu Baerts <matttbe@kernel.org>
Signed-off-by: default avatarDavide Caratti <dcaratti@redhat.com>
Signed-off-by: default avatarMat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20231023-send-net-next-20231023-1-v2-2-16b1f701f900@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 52c121f4
...@@ -199,6 +199,9 @@ properties: ...@@ -199,6 +199,9 @@ properties:
max-len: max-len:
description: Max length for a string or a binary attribute. description: Max length for a string or a binary attribute.
$ref: '#/$defs/len-or-define' $ref: '#/$defs/len-or-define'
exact-len:
description: Exact length for a string or a binary attribute.
$ref: '#/$defs/len-or-define'
sub-type: *attr-type sub-type: *attr-type
display-hint: &display-hint display-hint: &display-hint
description: | description: |
......
...@@ -242,6 +242,9 @@ properties: ...@@ -242,6 +242,9 @@ properties:
max-len: max-len:
description: Max length for a string or a binary attribute. description: Max length for a string or a binary attribute.
$ref: '#/$defs/len-or-define' $ref: '#/$defs/len-or-define'
exact-len:
description: Exact length for a string or a binary attribute.
$ref: '#/$defs/len-or-define'
sub-type: *attr-type sub-type: *attr-type
display-hint: *display-hint display-hint: *display-hint
# Start genetlink-c # Start genetlink-c
......
...@@ -172,6 +172,9 @@ properties: ...@@ -172,6 +172,9 @@ properties:
max-len: max-len:
description: Max length for a string or a binary attribute. description: Max length for a string or a binary attribute.
$ref: '#/$defs/len-or-define' $ref: '#/$defs/len-or-define'
exact-len:
description: Exact length for a string or a binary attribute.
$ref: '#/$defs/len-or-define'
sub-type: *attr-type sub-type: *attr-type
display-hint: &display-hint display-hint: &display-hint
description: | description: |
......
...@@ -240,6 +240,9 @@ properties: ...@@ -240,6 +240,9 @@ properties:
max-len: max-len:
description: Max length for a string or a binary attribute. description: Max length for a string or a binary attribute.
$ref: '#/$defs/len-or-define' $ref: '#/$defs/len-or-define'
exact-len:
description: Exact length for a string or a binary attribute.
$ref: '#/$defs/len-or-define'
sub-type: *attr-type sub-type: *attr-type
display-hint: *display-hint display-hint: *display-hint
# Start genetlink-c # Start genetlink-c
......
...@@ -410,6 +410,9 @@ class TypeString(Type): ...@@ -410,6 +410,9 @@ class TypeString(Type):
return f'.type = YNL_PT_NUL_STR, ' return f'.type = YNL_PT_NUL_STR, '
def _attr_policy(self, policy): def _attr_policy(self, policy):
if 'exact-len' in self.checks:
mem = 'NLA_POLICY_EXACT_LEN(' + str(self.checks['exact-len']) + ')'
else:
mem = '{ .type = ' + policy mem = '{ .type = ' + policy
if 'max-len' in self.checks: if 'max-len' in self.checks:
mem += ', .len = ' + str(self.get_limit('max-len')) mem += ', .len = ' + str(self.get_limit('max-len'))
...@@ -459,6 +462,9 @@ class TypeBinary(Type): ...@@ -459,6 +462,9 @@ class TypeBinary(Type):
return f'.type = YNL_PT_BINARY,' return f'.type = YNL_PT_BINARY,'
def _attr_policy(self, policy): def _attr_policy(self, policy):
if 'exact-len' in self.checks:
mem = 'NLA_POLICY_EXACT_LEN(' + str(self.checks['exact-len']) + ')'
else:
mem = '{ ' mem = '{ '
if len(self.checks) == 1 and 'min-len' in self.checks: if len(self.checks) == 1 and 'min-len' in self.checks:
mem += '.len = ' + str(self.get_limit('min-len')) mem += '.len = ' + str(self.get_limit('min-len'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment