]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lib: utils: Introduce parse_one_of_deprecated()
authorPetr Machata <petrm@nvidia.com>
Wed, 22 Nov 2023 15:23:31 +0000 (16:23 +0100)
committerDavid Ahern <dsahern@kernel.org>
Wed, 22 Nov 2023 19:32:09 +0000 (19:32 +0000)
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.

In this patch, introduce a new function, parse_one_of_deprecated(). This
will be currently synonymous with parse_one_of(), however the latter will
change behavior in the next patch.

Use the new function for parsing of the macsec "validate" option. The
reason is that the valid strings for that option are "disabled", "check"
and "strict". It is not hard to see how "disabled" could be misspelled as
"disable", and be baked in some script in this form.

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

index add55bfa3a33639224ff64c67fc03a9b5a878721..9ba129b8f2fe748e8f7c1c6189a2bc128f2b06c7 100644 (file)
@@ -342,6 +342,9 @@ int do_batch(const char *name, bool force,
 
 int parse_one_of(const char *msg, const char *realval, const char * const *list,
                 size_t len, int *p_err);
+int parse_one_of_deprecated(const char *msg, const char *realval,
+                           const char * const *list,
+                           size_t len, int *p_err);
 bool parse_on_off(const char *msg, const char *realval, int *p_err);
 
 int parse_mapping_num_all(__u32 *keyp, const char *key);
index 476a6d1d2eb5296a40ee62a8648633dc2daa2d5b..fc4c86314fabdd06eaabda02e66189e7aa2565df 100644 (file)
@@ -1457,8 +1457,10 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv,
                                invarg("expected replay window size", *argv);
                } else if (strcmp(*argv, "validate") == 0) {
                        NEXT_ARG();
-                       validate = parse_one_of("validate", *argv, validate_str,
-                                               ARRAY_SIZE(validate_str), &ret);
+                       validate = parse_one_of_deprecated("validate", *argv,
+                                                          validate_str,
+                                                          ARRAY_SIZE(validate_str),
+                                                          &ret);
                        if (ret != 0)
                                return ret;
                        addattr8(n, MACSEC_BUFLEN,
index f1ca3852958f69b68f146904ce28c4b39d6134a8..9142dc1d266a425b987f7a3f87ded4498861fe7e 100644 (file)
@@ -1758,6 +1758,13 @@ int parse_one_of(const char *msg, const char *realval, const char * const *list,
        return __parse_one_of(msg, realval, list, len, p_err, matches);
 }
 
+int parse_one_of_deprecated(const char *msg, const char *realval,
+                           const char * const *list,
+                           size_t len, int *p_err)
+{
+       return __parse_one_of(msg, realval, list, len, p_err, matches);
+}
+
 bool parse_on_off(const char *msg, const char *realval, int *p_err)
 {
        static const char * const values_on_off[] = { "off", "on" };