Commit 345c6cc0 authored by Davide Caratti's avatar Davide Caratti Committed by Geliang Tang
Browse files

tools: ynl-gen: add support for exact-len validation

mainline inclusion
from mainline-v6.7-rc1
commit 0c63ad3795269849782ca24a084952206986d3bf
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9VYQ9
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=0c63ad3795269849782ca24a084952206986d3bf

--------------------------------

add support for 'exact-len' validation on netlink attributes.

Link: https://github.com/multipath-tcp/mptcp_net-next/issues/340


Acked-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.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarJackie Liu <liuyun01@kylinos.cn>
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
parent 8c92cd45
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -202,6 +202,9 @@ properties:
                  max-len:
                    description: Max length for a string or a binary attribute.
                    $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
              display-hint: &display-hint
                description: |
+3 −0
Original line number Diff line number Diff line
@@ -241,6 +241,9 @@ properties:
                  max-len:
                    description: Max length for a string or a binary attribute.
                    $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
              display-hint: *display-hint
              # Start genetlink-c
+3 −0
Original line number Diff line number Diff line
@@ -175,6 +175,9 @@ properties:
                  max-len:
                    description: Max length for a string or a binary attribute.
                    $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
              display-hint: &display-hint
                description: |
+3 −0
Original line number Diff line number Diff line
@@ -240,6 +240,9 @@ properties:
                  max-len:
                    description: Max length for a string or a binary attribute.
                    $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
              display-hint: *display-hint
              # Start genetlink-c
+17 −11
Original line number Diff line number Diff line
@@ -406,6 +406,9 @@ class TypeString(Type):
        return f'.type = YNL_PT_NUL_STR, '

    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
            if 'max-len' in self.checks:
                mem += ', .len = ' + str(self.get_limit('max-len'))
@@ -455,6 +458,9 @@ class TypeBinary(Type):
        return f'.type = YNL_PT_BINARY,'

    def _attr_policy(self, policy):
        if 'exact-len' in self.checks:
            mem = 'NLA_POLICY_EXACT_LEN(' + str(self.checks['exact-len']) + ')'
        else:
            mem = '{ '
            if len(self.checks) == 1 and 'min-len' in self.checks:
                mem += '.len = ' + str(self.get_limit('min-len'))