]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
lib: parse_mapping: Recognize a keyword "all"
authorPetr Machata <me@pmachata.org>
Thu, 12 Nov 2020 22:24:46 +0000 (23:24 +0100)
committerDavid Ahern <dsahern@gmail.com>
Sat, 14 Nov 2020 02:43:15 +0000 (19:43 -0700)
The DCB tool will have to provide an interface to a number of fixed-size
arrays. Unlike the egress- and ingress-qos-map, it makes good sense to have
an interface to set all members to the same value. For example to set
strict priority on all TCs besides select few, or to reset allocated
bandwidth to all zeroes, again besides several explicitly-given ones.

To support this usage, extend the parse_mapping() with a boolean that
determines whether this special use is supported. If "all" is given and
recognized, mapping_cb is called with the key of -1.

Have iplink_vlan pass false for allow_all.

Signed-off-by: Petr Machata <me@pmachata.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
include/utils.h
ip/iplink_vlan.c
lib/utils.c

index 2d1a587cb1ef970e19f5ea68e99d98aa9659d434..588fceb724421a93e71bf900e06d85a89c8bba85 100644 (file)
@@ -329,7 +329,7 @@ int parse_one_of(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(int *argcp, char ***argvp,
+int parse_mapping(int *argcp, char ***argvp, bool allow_all,
                  int (*mapping_cb)(__u32 key, char *value, void *data),
                  void *mapping_cb_data);
 
index dadc349db16c10d4136cfd533b3d9038a3bc474a..1426f2afca23ffe7ae14da9a589f82dd1eb3d770 100644 (file)
@@ -69,7 +69,7 @@ static int vlan_parse_qos_map(int *argcp, char ***argvp, struct nlmsghdr *n,
 
        tail = addattr_nest(n, 1024, attrtype);
 
-       if (parse_mapping(argcp, argvp, &parse_qos_mapping, n))
+       if (parse_mapping(argcp, argvp, false, &parse_qos_mapping, n))
                return 1;
 
        addattr_nest_end(n, tail);
index 67d64df7e3e6849d6da6d4e7e26e6e5846fc320d..a0ba5181160ef4c00440368b9ae3591d3a353b63 100644 (file)
@@ -1764,7 +1764,7 @@ bool parse_on_off(const char *msg, const char *realval, int *p_err)
        return parse_one_of(msg, realval, values_on_off, ARRAY_SIZE(values_on_off), p_err);
 }
 
-int parse_mapping(int *argcp, char ***argvp,
+int parse_mapping(int *argcp, char ***argvp, bool allow_all,
                  int (*mapping_cb)(__u32 key, char *value, void *data),
                  void *mapping_cb_data)
 {
@@ -1780,7 +1780,9 @@ int parse_mapping(int *argcp, char ***argvp,
                        break;
                *colon = '\0';
 
-               if (get_u32(&key, *argv, 0)) {
+               if (allow_all && matches(*argv, "all") == 0) {
+                       key = (__u32) -1;
+               } else if (get_u32(&key, *argv, 0)) {
                        ret = 1;
                        break;
                }