Commit ec8c2574 authored by Antonio Quartulli's avatar Antonio Quartulli Committed by Jakub Kicinski
Browse files

ynl: ensure exact-len value is resolved



For type String and Binary we are currently usinig the exact-len
limit value as is without attempting any name resolution.
However, the spec may specify the name of a constant rather than an
actual value, which would result in using the constant name as is
and thus break the policy.

Ensure the limit value is passed to get_limit(), which will always
attempt resolving the name before printing the policy rule.

Signed-off-by: default avatarAntonio Quartulli <a@unstable.cc>
Link: https://lore.kernel.org/r/20240510232202.24051-1-a@unstable.cc


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent e5a28026
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -413,7 +413,7 @@ class TypeString(Type):

    def _attr_policy(self, policy):
        if 'exact-len' in self.checks:
            mem = 'NLA_POLICY_EXACT_LEN(' + str(self.checks['exact-len']) + ')'
            mem = 'NLA_POLICY_EXACT_LEN(' + str(self.get_limit('exact-len')) + ')'
        else:
            mem = '{ .type = ' + policy
            if 'max-len' in self.checks:
@@ -465,7 +465,7 @@ class TypeBinary(Type):

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