From: Petr Machata <me@pmachata.org>
To: netdev@vger.kernel.org, dsahern@gmail.com, stephen@networkplumber.org
Cc: Petr Machata <me@pmachata.org>
Subject: [PATCH iproute2-next 3/7] ip: iplink: Convert to use parse_on_off()
Date: Sat, 14 Nov 2020 23:53:57 +0100 [thread overview]
Message-ID: <972a28d826eb677c3884aed70f893e7d257b1328.1605393324.git.me@pmachata.org> (raw)
In-Reply-To: <cover.1605393324.git.me@pmachata.org>
Invoke parse_on_off() instead of rolling a custom function.
Signed-off-by: Petr Machata <me@pmachata.org>
---
ip/iplink.c | 47 +++++++++++++++++------------------------------
1 file changed, 17 insertions(+), 30 deletions(-)
diff --git a/ip/iplink.c b/ip/iplink.c
index d6b766de1fcf..f5766c39507b 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -352,6 +352,7 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp,
int len, argc = *argcp;
char **argv = *argvp;
struct rtattr *vfinfo;
+ int ret;
tivt.min_tx_rate = -1;
tivt.max_tx_rate = -1;
@@ -464,12 +465,9 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp,
struct ifla_vf_spoofchk ivs;
NEXT_ARG();
- if (matches(*argv, "on") == 0)
- ivs.setting = 1;
- else if (matches(*argv, "off") == 0)
- ivs.setting = 0;
- else
- return on_off("spoofchk", *argv);
+ ivs.setting = parse_on_off("spoofchk", *argv, &ret);
+ if (ret)
+ return ret;
ivs.vf = vf;
addattr_l(&req->n, sizeof(*req), IFLA_VF_SPOOFCHK,
&ivs, sizeof(ivs));
@@ -478,12 +476,9 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp,
struct ifla_vf_rss_query_en ivs;
NEXT_ARG();
- if (matches(*argv, "on") == 0)
- ivs.setting = 1;
- else if (matches(*argv, "off") == 0)
- ivs.setting = 0;
- else
- return on_off("query_rss", *argv);
+ ivs.setting = parse_on_off("query_rss", *argv, &ret);
+ if (ret)
+ return ret;
ivs.vf = vf;
addattr_l(&req->n, sizeof(*req), IFLA_VF_RSS_QUERY_EN,
&ivs, sizeof(ivs));
@@ -492,12 +487,9 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp,
struct ifla_vf_trust ivt;
NEXT_ARG();
- if (matches(*argv, "on") == 0)
- ivt.setting = 1;
- else if (matches(*argv, "off") == 0)
- ivt.setting = 0;
- else
- invarg("Invalid \"trust\" value\n", *argv);
+ ivt.setting = parse_on_off("trust", *argv, &ret);
+ if (ret)
+ return ret;
ivt.vf = vf;
addattr_l(&req->n, sizeof(*req), IFLA_VF_TRUST,
&ivt, sizeof(ivt));
@@ -595,6 +587,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
int index = 0;
int group = -1;
int addr_len = 0;
+ int err;
ret = argc;
@@ -738,12 +731,9 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
int carrier;
NEXT_ARG();
- if (strcmp(*argv, "on") == 0)
- carrier = 1;
- else if (strcmp(*argv, "off") == 0)
- carrier = 0;
- else
- return on_off("carrier", *argv);
+ carrier = parse_on_off("carrier", *argv, &err);
+ if (err)
+ return err;
addattr8(&req->n, sizeof(*req), IFLA_CARRIER, carrier);
} else if (strcmp(*argv, "vf") == 0) {
@@ -896,12 +886,9 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
unsigned int proto_down;
NEXT_ARG();
- if (strcmp(*argv, "on") == 0)
- proto_down = 1;
- else if (strcmp(*argv, "off") == 0)
- proto_down = 0;
- else
- return on_off("protodown", *argv);
+ proto_down = parse_on_off("protodown", *argv, &err);
+ if (err)
+ return err;
addattr8(&req->n, sizeof(*req), IFLA_PROTO_DOWN,
proto_down);
} else if (strcmp(*argv, "protodown_reason") == 0) {
--
2.25.1
next prev parent reply other threads:[~2020-11-14 22:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-14 22:53 [PATCH iproute2-next 0/7] Convert a number of use-cases to parse_on_off(), print_on_off() Petr Machata
2020-11-14 22:53 ` [PATCH iproute2-next 1/7] bridge: link: Port over to parse_on_off() Petr Machata
2020-11-14 22:53 ` [PATCH iproute2-next 2/7] bridge: link: Convert to use print_on_off() Petr Machata
2020-11-14 22:53 ` Petr Machata [this message]
2020-11-14 22:53 ` [PATCH iproute2-next 4/7] ip: iplink_bridge_slave: Port over to parse_on_off() Petr Machata
2020-11-14 22:53 ` [PATCH iproute2-next 5/7] ip: iplink_bridge_slave: Convert to use print_on_off() Petr Machata
2020-11-14 22:54 ` [PATCH iproute2-next 6/7] ip: ipnetconf: " Petr Machata
2020-11-14 22:54 ` [PATCH iproute2-next 7/7] ip: iptuntap: " Petr Machata
2020-11-17 0:56 ` [PATCH iproute2-next 0/7] Convert a number of use-cases to parse_on_off(), print_on_off() David Ahern
2020-11-23 21:21 ` Nikolay Aleksandrov
2020-11-25 4:44 ` David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=972a28d826eb677c3884aed70f893e7d257b1328.1605393324.git.me@pmachata.org \
--to=me@pmachata.org \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.