]> git.ipfire.org Git - thirdparty/iproute2.git/commit
lib: utils: Have parse_one_of() warn about prefix matches
authorPetr Machata <petrm@nvidia.com>
Wed, 22 Nov 2023 15:23:32 +0000 (16:23 +0100)
committerDavid Ahern <dsahern@kernel.org>
Wed, 22 Nov 2023 19:32:13 +0000 (19:32 +0000)
commitbd5226437a4c73404a0e50e419f1cd055b032a74
treed3e23ecaf64fd268f616345d80289956fe53c7bf
parent2b8766663d3cbca96d07b87d74e9000b80c2a988
lib: utils: Have parse_one_of() warn about prefix matches

The function parse_one_of() currently uses matches() for string comparison
under the hood. Extending matches()-based parsers is tricky, because newly
added matches might change the way strings are parsed, if the newly-added
string shares a prefix with a string that is matched later in the code.

Therefore in this patch, add a twist to parse_one_of() that partial prefix
matches yield a warning. This will not disturb standard output or the
overall behavior, but will make it obvious that the usage is discouraged
and prompt users to update their scripts and habits.

An example of output:

    # dcb ets set dev swp1 tc-tsa 0:s
    WARNING: 's' matches 'strict' by prefix.
    Matching by prefix is deprecated in this context, please use the full string.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
lib/utils.c