diff mbox series

[iproute2-next,13/15] lib: parse_mapping: Recognize a keyword "all"

Message ID f3f263759f21a99c63309eddb20bd7cf05fce0d7.1603154867.git.me@pmachata.org
State New
Headers show
Series Add a tool for configuration of DCB | expand

Commit Message

Petr Machata Oct. 20, 2020, 12:58 a.m. UTC
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>
---
 include/utils.h  | 2 +-
 ip/iplink_vlan.c | 2 +-
 lib/utils.c      | 6 ++++--
 3 files changed, 6 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/include/utils.h b/include/utils.h
index 8323e3cf1103..cad87d39695a 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -339,7 +339,7 @@  int parse_on_off(const char *msg, const char *realval, int *p_err);
 void parse_flag_on_off(const char *msg, const char *realval,
 		       unsigned int *p_flags, unsigned int flag, int *p_ret);
 
-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);
 
diff --git a/ip/iplink_vlan.c b/ip/iplink_vlan.c
index 73aa94acde3c..8ab2250cf110 100644
--- a/ip/iplink_vlan.c
+++ b/ip/iplink_vlan.c
@@ -64,7 +64,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);
diff --git a/lib/utils.c b/lib/utils.c
index 87cc6ae0cfba..51471ba73b8d 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1775,7 +1775,7 @@  void parse_flag_on_off(const char *msg, const char *realval,
 	set_flag(p_flags, flag, on_off);
 }
 
-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)
 {
@@ -1791,7 +1791,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;
 		}