[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <24ac69937eff13dce8d6360599b39ab4e9ddcc86.1603154867.git.me@pmachata.org>
Date: Tue, 20 Oct 2020 02:58:14 +0200
From: Petr Machata <me@...chata.org>
To: netdev@...r.kernel.org, dsahern@...il.com,
stephen@...workplumber.org
Cc: john.fastabend@...il.com, jiri@...dia.com, idosch@...dia.com,
Petr Machata <me@...chata.org>
Subject: [PATCH iproute2-next 06/15] ip: iplink_vlan: Port over to parse_flag_on_off()
Convert bridge/link.c from a hand-rolled on_off parsing to the new global
one.
Signed-off-by: Petr Machata <me@...chata.org>
---
ip/iplink_vlan.c | 55 +++++++++++++++++-------------------------------
1 file changed, 19 insertions(+), 36 deletions(-)
diff --git a/ip/iplink_vlan.c b/ip/iplink_vlan.c
index 1e6817f5de3d..66c4c0fb57f1 100644
--- a/ip/iplink_vlan.c
+++ b/ip/iplink_vlan.c
@@ -43,12 +43,6 @@ static void explain(void)
print_explain(stderr);
}
-static int on_off(const char *msg, const char *arg)
-{
- fprintf(stderr, "Error: argument of \"%s\" must be \"on\" or \"off\", not \"%s\"\n", msg, arg);
- return -1;
-}
-
static int vlan_parse_qos_map(int *argcp, char ***argvp, struct nlmsghdr *n,
int attrtype)
{
@@ -87,6 +81,7 @@ static int vlan_parse_opt(struct link_util *lu, int argc, char **argv,
{
struct ifla_vlan_flags flags = { 0 };
__u16 id, proto;
+ int ret;
while (argc > 0) {
if (matches(*argv, "protocol") == 0) {
@@ -102,48 +97,36 @@ static int vlan_parse_opt(struct link_util *lu, int argc, char **argv,
} else if (matches(*argv, "reorder_hdr") == 0) {
NEXT_ARG();
flags.mask |= VLAN_FLAG_REORDER_HDR;
- if (strcmp(*argv, "on") == 0)
- flags.flags |= VLAN_FLAG_REORDER_HDR;
- else if (strcmp(*argv, "off") == 0)
- flags.flags &= ~VLAN_FLAG_REORDER_HDR;
- else
- return on_off("reorder_hdr", *argv);
+ parse_flag_on_off("reorder_hdr", *argv, &flags.flags, VLAN_FLAG_REORDER_HDR,
+ &ret);
+ if (ret)
+ return ret;
} else if (matches(*argv, "gvrp") == 0) {
NEXT_ARG();
flags.mask |= VLAN_FLAG_GVRP;
- if (strcmp(*argv, "on") == 0)
- flags.flags |= VLAN_FLAG_GVRP;
- else if (strcmp(*argv, "off") == 0)
- flags.flags &= ~VLAN_FLAG_GVRP;
- else
- return on_off("gvrp", *argv);
+ parse_flag_on_off("gvrp", *argv, &flags.flags, VLAN_FLAG_GVRP, &ret);
+ if (ret)
+ return ret;
} else if (matches(*argv, "mvrp") == 0) {
NEXT_ARG();
flags.mask |= VLAN_FLAG_MVRP;
- if (strcmp(*argv, "on") == 0)
- flags.flags |= VLAN_FLAG_MVRP;
- else if (strcmp(*argv, "off") == 0)
- flags.flags &= ~VLAN_FLAG_MVRP;
- else
- return on_off("mvrp", *argv);
+ parse_flag_on_off("mvrp", *argv, &flags.flags, VLAN_FLAG_MVRP, &ret);
+ if (ret)
+ return ret;
} else if (matches(*argv, "loose_binding") == 0) {
NEXT_ARG();
flags.mask |= VLAN_FLAG_LOOSE_BINDING;
- if (strcmp(*argv, "on") == 0)
- flags.flags |= VLAN_FLAG_LOOSE_BINDING;
- else if (strcmp(*argv, "off") == 0)
- flags.flags &= ~VLAN_FLAG_LOOSE_BINDING;
- else
- return on_off("loose_binding", *argv);
+ parse_flag_on_off("loose_binding", *argv, &flags.flags,
+ VLAN_FLAG_LOOSE_BINDING, &ret);
+ if (ret)
+ return ret;
} else if (matches(*argv, "bridge_binding") == 0) {
NEXT_ARG();
flags.mask |= VLAN_FLAG_BRIDGE_BINDING;
- if (strcmp(*argv, "on") == 0)
- flags.flags |= VLAN_FLAG_BRIDGE_BINDING;
- else if (strcmp(*argv, "off") == 0)
- flags.flags &= ~VLAN_FLAG_BRIDGE_BINDING;
- else
- return on_off("bridge_binding", *argv);
+ parse_flag_on_off("bridge_binding", *argv, &flags.flags,
+ VLAN_FLAG_BRIDGE_BINDING, &ret);
+ if (ret)
+ return ret;
} else if (matches(*argv, "ingress-qos-map") == 0) {
NEXT_ARG();
if (vlan_parse_qos_map(&argc, &argv, n,
--
2.25.1
Powered by blists - more mailing lists