* [PATCH iproute2-next 0/7] Convert a number of use-cases to parse_on_off(), print_on_off()
@ 2020-11-14 22:53 Petr Machata
2020-11-14 22:53 ` [PATCH iproute2-next 1/7] bridge: link: Port over to parse_on_off() Petr Machata
` (8 more replies)
0 siblings, 9 replies; 11+ messages in thread
From: Petr Machata @ 2020-11-14 22:53 UTC (permalink / raw)
To: netdev, dsahern, stephen; +Cc: Petr Machata
Two helpers, parse_on_off() and print_on_off(), have been recently added to
lib/utils.c. Convert a number of instances of the same effective behavior
to calls to these helpers.
Petr Machata (7):
bridge: link: Port over to parse_on_off()
bridge: link: Convert to use print_on_off()
ip: iplink: Convert to use parse_on_off()
ip: iplink_bridge_slave: Port over to parse_on_off()
ip: iplink_bridge_slave: Convert to use print_on_off()
ip: ipnetconf: Convert to use print_on_off()
ip: iptuntap: Convert to use print_on_off()
bridge/link.c | 135 ++++++++++++++++++---------------------
ip/iplink.c | 47 +++++---------
ip/iplink_bridge_slave.c | 46 +++++--------
ip/ipnetconf.c | 28 ++++----
ip/iptuntap.c | 18 ++----
5 files changed, 112 insertions(+), 162 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH iproute2-next 1/7] bridge: link: Port over to parse_on_off()
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 ` Petr Machata
2020-11-14 22:53 ` [PATCH iproute2-next 2/7] bridge: link: Convert to use print_on_off() Petr Machata
` (7 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Petr Machata @ 2020-11-14 22:53 UTC (permalink / raw)
To: netdev, dsahern, stephen; +Cc: Petr Machata
Convert bridge/link.c from a custom on_off parser to the new global one.
Signed-off-by: Petr Machata <me@pmachata.org>
---
bridge/link.c | 79 ++++++++++++++++++++++++---------------------------
1 file changed, 37 insertions(+), 42 deletions(-)
diff --git a/bridge/link.c b/bridge/link.c
index 3bc7af209b8b..fa6eda849b32 100644
--- a/bridge/link.c
+++ b/bridge/link.c
@@ -275,22 +275,6 @@ static void usage(void)
exit(-1);
}
-static bool on_off(char *arg, __s8 *attr, char *val)
-{
- if (strcmp(val, "on") == 0)
- *attr = 1;
- else if (strcmp(val, "off") == 0)
- *attr = 0;
- else {
- fprintf(stderr,
- "Error: argument of \"%s\" must be \"on\" or \"off\"\n",
- arg);
- return false;
- }
-
- return true;
-}
-
static int brlink_modify(int argc, char **argv)
{
struct {
@@ -323,6 +307,7 @@ static int brlink_modify(int argc, char **argv)
__s16 mode = -1;
__u16 flags = 0;
struct rtattr *nest;
+ int ret;
while (argc > 0) {
if (strcmp(*argv, "dev") == 0) {
@@ -330,40 +315,49 @@ static int brlink_modify(int argc, char **argv)
d = *argv;
} else if (strcmp(*argv, "guard") == 0) {
NEXT_ARG();
- if (!on_off("guard", &bpdu_guard, *argv))
- return -1;
+ bpdu_guard = parse_on_off("guard", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "hairpin") == 0) {
NEXT_ARG();
- if (!on_off("hairpin", &hairpin, *argv))
- return -1;
+ hairpin = parse_on_off("hairpin", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "fastleave") == 0) {
NEXT_ARG();
- if (!on_off("fastleave", &fast_leave, *argv))
- return -1;
+ fast_leave = parse_on_off("fastleave", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "root_block") == 0) {
NEXT_ARG();
- if (!on_off("root_block", &root_block, *argv))
- return -1;
+ root_block = parse_on_off("root_block", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "learning") == 0) {
NEXT_ARG();
- if (!on_off("learning", &learning, *argv))
- return -1;
+ learning = parse_on_off("learning", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "learning_sync") == 0) {
NEXT_ARG();
- if (!on_off("learning_sync", &learning_sync, *argv))
- return -1;
+ learning_sync = parse_on_off("learning_sync", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "flood") == 0) {
NEXT_ARG();
- if (!on_off("flood", &flood, *argv))
- return -1;
+ flood = parse_on_off("flood", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "mcast_flood") == 0) {
NEXT_ARG();
- if (!on_off("mcast_flood", &mcast_flood, *argv))
- return -1;
+ mcast_flood = parse_on_off("mcast_flood", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "mcast_to_unicast") == 0) {
NEXT_ARG();
- if (!on_off("mcast_to_unicast", &mcast_to_unicast, *argv))
- return -1;
+ mcast_to_unicast = parse_on_off("mcast_to_unicast", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "cost") == 0) {
NEXT_ARG();
cost = atoi(*argv);
@@ -404,18 +398,19 @@ static int brlink_modify(int argc, char **argv)
flags |= BRIDGE_FLAGS_MASTER;
} else if (strcmp(*argv, "neigh_suppress") == 0) {
NEXT_ARG();
- if (!on_off("neigh_suppress", &neigh_suppress,
- *argv))
- return -1;
+ neigh_suppress = parse_on_off("neigh_suppress", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "vlan_tunnel") == 0) {
NEXT_ARG();
- if (!on_off("vlan_tunnel", &vlan_tunnel,
- *argv))
- return -1;
+ vlan_tunnel = parse_on_off("vlan_tunnel", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "isolated") == 0) {
NEXT_ARG();
- if (!on_off("isolated", &isolated, *argv))
- return -1;
+ isolated = parse_on_off("isolated", *argv, &ret);
+ if (ret)
+ return ret;
} else if (strcmp(*argv, "backup_port") == 0) {
NEXT_ARG();
backup_port_idx = ll_name_to_index(*argv);
--
2.25.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH iproute2-next 2/7] bridge: link: Convert to use print_on_off()
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 ` Petr Machata
2020-11-14 22:53 ` [PATCH iproute2-next 3/7] ip: iplink: Convert to use parse_on_off() Petr Machata
` (6 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Petr Machata @ 2020-11-14 22:53 UTC (permalink / raw)
To: netdev, dsahern, stephen; +Cc: Petr Machata
Instead of rolling a custom on-off printer, use the one added to utils.c.
Signed-off-by: Petr Machata <me@pmachata.org>
---
bridge/link.c | 56 ++++++++++++++++++++++-----------------------------
1 file changed, 24 insertions(+), 32 deletions(-)
diff --git a/bridge/link.c b/bridge/link.c
index fa6eda849b32..d88c469db78e 100644
--- a/bridge/link.c
+++ b/bridge/link.c
@@ -78,14 +78,6 @@ static void print_portstate(__u8 state)
"state (%d) ", state);
}
-static void print_onoff(FILE *fp, const char *flag, __u8 val)
-{
- if (is_json_context())
- print_bool(PRINT_JSON, flag, NULL, val);
- else
- fprintf(fp, "%s %s ", flag, val ? "on" : "off");
-}
-
static void print_hwmode(__u16 mode)
{
if (mode >= ARRAY_SIZE(hw_mode))
@@ -123,38 +115,38 @@ static void print_protinfo(FILE *fp, struct rtattr *attr)
fprintf(fp, "%s ", _SL_);
if (prtb[IFLA_BRPORT_MODE])
- print_onoff(fp, "hairpin",
- rta_getattr_u8(prtb[IFLA_BRPORT_MODE]));
+ print_on_off(PRINT_ANY, "hairpin", "hairpin %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_MODE]));
if (prtb[IFLA_BRPORT_GUARD])
- print_onoff(fp, "guard",
- rta_getattr_u8(prtb[IFLA_BRPORT_GUARD]));
+ print_on_off(PRINT_ANY, "guard", "guard %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_GUARD]));
if (prtb[IFLA_BRPORT_PROTECT])
- print_onoff(fp, "root_block",
- rta_getattr_u8(prtb[IFLA_BRPORT_PROTECT]));
+ print_on_off(PRINT_ANY, "root_block", "root_block %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_PROTECT]));
if (prtb[IFLA_BRPORT_FAST_LEAVE])
- print_onoff(fp, "fastleave",
- rta_getattr_u8(prtb[IFLA_BRPORT_FAST_LEAVE]));
+ print_on_off(PRINT_ANY, "fastleave", "fastleave %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_FAST_LEAVE]));
if (prtb[IFLA_BRPORT_LEARNING])
- print_onoff(fp, "learning",
- rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING]));
+ print_on_off(PRINT_ANY, "learning", "learning %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING]));
if (prtb[IFLA_BRPORT_LEARNING_SYNC])
- print_onoff(fp, "learning_sync",
- rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING_SYNC]));
+ print_on_off(PRINT_ANY, "learning_sync", "learning_sync %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING_SYNC]));
if (prtb[IFLA_BRPORT_UNICAST_FLOOD])
- print_onoff(fp, "flood",
- rta_getattr_u8(prtb[IFLA_BRPORT_UNICAST_FLOOD]));
+ print_on_off(PRINT_ANY, "flood", "flood %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_UNICAST_FLOOD]));
if (prtb[IFLA_BRPORT_MCAST_FLOOD])
- print_onoff(fp, "mcast_flood",
- rta_getattr_u8(prtb[IFLA_BRPORT_MCAST_FLOOD]));
+ print_on_off(PRINT_ANY, "mcast_flood", "mcast_flood %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_MCAST_FLOOD]));
if (prtb[IFLA_BRPORT_MCAST_TO_UCAST])
- print_onoff(fp, "mcast_to_unicast",
- rta_getattr_u8(prtb[IFLA_BRPORT_MCAST_TO_UCAST]));
+ print_on_off(PRINT_ANY, "mcast_to_unicast", "mcast_to_unicast %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_MCAST_TO_UCAST]));
if (prtb[IFLA_BRPORT_NEIGH_SUPPRESS])
- print_onoff(fp, "neigh_suppress",
- rta_getattr_u8(prtb[IFLA_BRPORT_NEIGH_SUPPRESS]));
+ print_on_off(PRINT_ANY, "neigh_suppress", "neigh_suppress %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_NEIGH_SUPPRESS]));
if (prtb[IFLA_BRPORT_VLAN_TUNNEL])
- print_onoff(fp, "vlan_tunnel",
- rta_getattr_u8(prtb[IFLA_BRPORT_VLAN_TUNNEL]));
+ print_on_off(PRINT_ANY, "vlan_tunnel", "vlan_tunnel %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_VLAN_TUNNEL]));
if (prtb[IFLA_BRPORT_BACKUP_PORT]) {
int ifidx;
@@ -166,8 +158,8 @@ static void print_protinfo(FILE *fp, struct rtattr *attr)
}
if (prtb[IFLA_BRPORT_ISOLATED])
- print_onoff(fp, "isolated",
- rta_getattr_u8(prtb[IFLA_BRPORT_ISOLATED]));
+ print_on_off(PRINT_ANY, "isolated", "isolated %s ",
+ rta_getattr_u8(prtb[IFLA_BRPORT_ISOLATED]));
} else
print_portstate(rta_getattr_u8(attr));
}
--
2.25.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH iproute2-next 3/7] ip: iplink: Convert to use parse_on_off()
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
2020-11-14 22:53 ` [PATCH iproute2-next 4/7] ip: iplink_bridge_slave: Port over to parse_on_off() Petr Machata
` (5 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Petr Machata @ 2020-11-14 22:53 UTC (permalink / raw)
To: netdev, dsahern, stephen; +Cc: Petr Machata
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
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH iproute2-next 4/7] ip: iplink_bridge_slave: Port over to parse_on_off()
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
` (2 preceding siblings ...)
2020-11-14 22:53 ` [PATCH iproute2-next 3/7] ip: iplink: Convert to use parse_on_off() Petr Machata
@ 2020-11-14 22:53 ` Petr Machata
2020-11-14 22:53 ` [PATCH iproute2-next 5/7] ip: iplink_bridge_slave: Convert to use print_on_off() Petr Machata
` (4 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Petr Machata @ 2020-11-14 22:53 UTC (permalink / raw)
To: netdev, dsahern, stephen; +Cc: Petr Machata
Invoke parse_on_off() from bridge_slave_parse_on_off() instead of
hand-rolling one. Exit on failure, because the invarg that was ivoked here
before would.
Signed-off-by: Petr Machata <me@pmachata.org>
---
ip/iplink_bridge_slave.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c
index 79a1d2f5f5b8..f7f6da0c79b7 100644
--- a/ip/iplink_bridge_slave.c
+++ b/ip/iplink_bridge_slave.c
@@ -297,15 +297,11 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
static void bridge_slave_parse_on_off(char *arg_name, char *arg_val,
struct nlmsghdr *n, int type)
{
- __u8 val;
-
- if (strcmp(arg_val, "on") == 0)
- val = 1;
- else if (strcmp(arg_val, "off") == 0)
- val = 0;
- else
- invarg("should be \"on\" or \"off\"", arg_name);
+ int ret;
+ __u8 val = parse_on_off(arg_name, arg_val, &ret);
+ if (ret)
+ exit(1);
addattr8(n, 1024, type, val);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH iproute2-next 5/7] ip: iplink_bridge_slave: Convert to use print_on_off()
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
` (3 preceding siblings ...)
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 ` Petr Machata
2020-11-14 22:54 ` [PATCH iproute2-next 6/7] ip: ipnetconf: " Petr Machata
` (3 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Petr Machata @ 2020-11-14 22:53 UTC (permalink / raw)
To: netdev, dsahern, stephen; +Cc: Petr Machata
Instead of rolling a custom on-off printer, use the one added to utils.c.
Note that _print_onoff() has an extra parameter for a JSON-specific flag
name. However that argument is not used, and never was. Therefore when
moving over to print_on_off(), drop this argument.
Signed-off-by: Petr Machata <me@pmachata.org>
---
ip/iplink_bridge_slave.c | 34 +++++++++++++---------------------
1 file changed, 13 insertions(+), 21 deletions(-)
diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c
index f7f6da0c79b7..717875864b18 100644
--- a/ip/iplink_bridge_slave.c
+++ b/ip/iplink_bridge_slave.c
@@ -76,14 +76,6 @@ static void print_portstate(FILE *f, __u8 state)
print_int(PRINT_ANY, "state_index", "state (%d) ", state);
}
-static void _print_onoff(FILE *f, char *json_flag, char *flag, __u8 val)
-{
- if (is_json_context())
- print_bool(PRINT_JSON, flag, NULL, val);
- else
- fprintf(f, "%s %s ", flag, val ? "on" : "off");
-}
-
static void _print_timer(FILE *f, const char *attr, struct rtattr *timer)
{
struct timeval tv;
@@ -145,27 +137,27 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
rta_getattr_u32(tb[IFLA_BRPORT_COST]));
if (tb[IFLA_BRPORT_MODE])
- _print_onoff(f, "mode", "hairpin",
+ print_on_off(PRINT_ANY, "hairpin", "hairpin %s ",
rta_getattr_u8(tb[IFLA_BRPORT_MODE]));
if (tb[IFLA_BRPORT_GUARD])
- _print_onoff(f, "guard", "guard",
+ print_on_off(PRINT_ANY, "guard", "guard %s ",
rta_getattr_u8(tb[IFLA_BRPORT_GUARD]));
if (tb[IFLA_BRPORT_PROTECT])
- _print_onoff(f, "protect", "root_block",
+ print_on_off(PRINT_ANY, "root_block", "root_block %s ",
rta_getattr_u8(tb[IFLA_BRPORT_PROTECT]));
if (tb[IFLA_BRPORT_FAST_LEAVE])
- _print_onoff(f, "fast_leave", "fastleave",
+ print_on_off(PRINT_ANY, "fastleave", "fastleave %s ",
rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]));
if (tb[IFLA_BRPORT_LEARNING])
- _print_onoff(f, "learning", "learning",
+ print_on_off(PRINT_ANY, "learning", "learning %s ",
rta_getattr_u8(tb[IFLA_BRPORT_LEARNING]));
if (tb[IFLA_BRPORT_UNICAST_FLOOD])
- _print_onoff(f, "unicast_flood", "flood",
+ print_on_off(PRINT_ANY, "flood", "flood %s ",
rta_getattr_u8(tb[IFLA_BRPORT_UNICAST_FLOOD]));
if (tb[IFLA_BRPORT_ID])
@@ -233,11 +225,11 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
rta_getattr_u8(tb[IFLA_BRPORT_CONFIG_PENDING]));
if (tb[IFLA_BRPORT_PROXYARP])
- _print_onoff(f, "proxyarp", "proxy_arp",
+ print_on_off(PRINT_ANY, "proxy_arp", "proxy_arp %s ",
rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP]));
if (tb[IFLA_BRPORT_PROXYARP_WIFI])
- _print_onoff(f, "proxyarp_wifi", "proxy_arp_wifi",
+ print_on_off(PRINT_ANY, "proxy_arp_wifi", "proxy_arp_wifi %s ",
rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP_WIFI]));
if (tb[IFLA_BRPORT_MULTICAST_ROUTER])
@@ -255,15 +247,15 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]) ? "on" : "off");
if (tb[IFLA_BRPORT_MCAST_FLOOD])
- _print_onoff(f, "mcast_flood", "mcast_flood",
+ print_on_off(PRINT_ANY, "mcast_flood", "mcast_flood %s ",
rta_getattr_u8(tb[IFLA_BRPORT_MCAST_FLOOD]));
if (tb[IFLA_BRPORT_MCAST_TO_UCAST])
- _print_onoff(f, "mcast_to_unicast", "mcast_to_unicast",
+ print_on_off(PRINT_ANY, "mcast_to_unicast", "mcast_to_unicast %s ",
rta_getattr_u8(tb[IFLA_BRPORT_MCAST_TO_UCAST]));
if (tb[IFLA_BRPORT_NEIGH_SUPPRESS])
- _print_onoff(f, "neigh_suppress", "neigh_suppress",
+ print_on_off(PRINT_ANY, "neigh_suppress", "neigh_suppress %s ",
rta_getattr_u8(tb[IFLA_BRPORT_NEIGH_SUPPRESS]));
if (tb[IFLA_BRPORT_GROUP_FWD_MASK]) {
@@ -279,11 +271,11 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
}
if (tb[IFLA_BRPORT_VLAN_TUNNEL])
- _print_onoff(f, "vlan_tunnel", "vlan_tunnel",
+ print_on_off(PRINT_ANY, "vlan_tunnel", "vlan_tunnel %s ",
rta_getattr_u8(tb[IFLA_BRPORT_VLAN_TUNNEL]));
if (tb[IFLA_BRPORT_ISOLATED])
- _print_onoff(f, "isolated", "isolated",
+ print_on_off(PRINT_ANY, "isolated", "isolated %s ",
rta_getattr_u8(tb[IFLA_BRPORT_ISOLATED]));
if (tb[IFLA_BRPORT_BACKUP_PORT]) {
--
2.25.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH iproute2-next 6/7] ip: ipnetconf: Convert to use print_on_off()
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
` (4 preceding siblings ...)
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 ` Petr Machata
2020-11-14 22:54 ` [PATCH iproute2-next 7/7] ip: iptuntap: " Petr Machata
` (2 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Petr Machata @ 2020-11-14 22:54 UTC (permalink / raw)
To: netdev, dsahern, stephen; +Cc: Petr Machata
Instead of rolling a custom on-off printer, use the one added to utils.c.
Signed-off-by: Petr Machata <me@pmachata.org>
---
ip/ipnetconf.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c
index 0e946ca34b4a..bb0ebe12da93 100644
--- a/ip/ipnetconf.c
+++ b/ip/ipnetconf.c
@@ -41,14 +41,6 @@ static void usage(void)
exit(-1);
}
-static void print_onoff(FILE *fp, const char *flag, __u32 val)
-{
- if (is_json_context())
- print_bool(PRINT_JSON, flag, NULL, val);
- else
- fprintf(fp, "%s %s ", flag, val ? "on" : "off");
-}
-
static struct rtattr *netconf_rta(struct netconfmsg *ncm)
{
return (struct rtattr *)((char *)ncm
@@ -117,8 +109,8 @@ int print_netconf(struct rtnl_ctrl_data *ctrl, struct nlmsghdr *n, void *arg)
}
if (tb[NETCONFA_FORWARDING])
- print_onoff(fp, "forwarding",
- rta_getattr_u32(tb[NETCONFA_FORWARDING]));
+ print_on_off(PRINT_ANY, "forwarding", "forwarding %s ",
+ rta_getattr_u32(tb[NETCONFA_FORWARDING]));
if (tb[NETCONFA_RP_FILTER]) {
__u32 rp_filter = rta_getattr_u32(tb[NETCONFA_RP_FILTER]);
@@ -133,19 +125,21 @@ int print_netconf(struct rtnl_ctrl_data *ctrl, struct nlmsghdr *n, void *arg)
}
if (tb[NETCONFA_MC_FORWARDING])
- print_onoff(fp, "mc_forwarding",
- rta_getattr_u32(tb[NETCONFA_MC_FORWARDING]));
+ print_on_off(PRINT_ANY, "mc_forwarding", "mc_forwarding %s ",
+ rta_getattr_u32(tb[NETCONFA_MC_FORWARDING]));
if (tb[NETCONFA_PROXY_NEIGH])
- print_onoff(fp, "proxy_neigh",
- rta_getattr_u32(tb[NETCONFA_PROXY_NEIGH]));
+ print_on_off(PRINT_ANY, "proxy_neigh", "proxy_neigh %s ",
+ rta_getattr_u32(tb[NETCONFA_PROXY_NEIGH]));
if (tb[NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN])
- print_onoff(fp, "ignore_routes_with_linkdown",
- rta_getattr_u32(tb[NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN]));
+ print_on_off(PRINT_ANY, "ignore_routes_with_linkdown",
+ "ignore_routes_with_linkdown %s ",
+ rta_getattr_u32(tb[NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN]));
if (tb[NETCONFA_INPUT])
- print_onoff(fp, "input", rta_getattr_u32(tb[NETCONFA_INPUT]));
+ print_on_off(PRINT_ANY, "input", "input %s ",
+ rta_getattr_u32(tb[NETCONFA_INPUT]));
close_json_object();
print_string(PRINT_FP, NULL, "\n", NULL);
--
2.25.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH iproute2-next 7/7] ip: iptuntap: Convert to use print_on_off()
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
` (5 preceding siblings ...)
2020-11-14 22:54 ` [PATCH iproute2-next 6/7] ip: ipnetconf: " Petr Machata
@ 2020-11-14 22:54 ` 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-25 4:44 ` David Ahern
8 siblings, 0 replies; 11+ messages in thread
From: Petr Machata @ 2020-11-14 22:54 UTC (permalink / raw)
To: netdev, dsahern, stephen; +Cc: Petr Machata
Instead of rolling a custom on-off printer, use the one added to utils.c.
Signed-off-by: Petr Machata <me@pmachata.org>
---
ip/iptuntap.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/ip/iptuntap.c b/ip/iptuntap.c
index 82e384998b1c..e9cc7c0f5f70 100644
--- a/ip/iptuntap.c
+++ b/ip/iptuntap.c
@@ -541,14 +541,6 @@ static void print_mq(FILE *f, struct rtattr *tb[])
}
}
-static void print_onoff(FILE *f, const char *flag, __u8 val)
-{
- if (is_json_context())
- print_bool(PRINT_JSON, flag, NULL, !!val);
- else
- fprintf(f, "%s %s ", flag, val ? "on" : "off");
-}
-
static void print_type(FILE *f, __u8 type)
{
SPRINT_BUF(buf);
@@ -573,17 +565,19 @@ static void tun_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
print_type(f, rta_getattr_u8(tb[IFLA_TUN_TYPE]));
if (tb[IFLA_TUN_PI])
- print_onoff(f, "pi", rta_getattr_u8(tb[IFLA_TUN_PI]));
+ print_on_off(PRINT_ANY, "pi", "pi %s ",
+ rta_getattr_u8(tb[IFLA_TUN_PI]));
if (tb[IFLA_TUN_VNET_HDR]) {
- print_onoff(f, "vnet_hdr",
- rta_getattr_u8(tb[IFLA_TUN_VNET_HDR]));
+ print_on_off(PRINT_ANY, "vnet_hdr", "vnet_hdr %s ",
+ rta_getattr_u8(tb[IFLA_TUN_VNET_HDR]));
}
print_mq(f, tb);
if (tb[IFLA_TUN_PERSIST])
- print_onoff(f, "persist", rta_getattr_u8(tb[IFLA_TUN_PERSIST]));
+ print_on_off(PRINT_ANY, "persist", "persist %s ",
+ rta_getattr_u8(tb[IFLA_TUN_PERSIST]));
if (tb[IFLA_TUN_OWNER])
print_owner(f, rta_getattr_u32(tb[IFLA_TUN_OWNER]));
--
2.25.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH iproute2-next 0/7] Convert a number of use-cases to parse_on_off(), print_on_off()
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
` (6 preceding siblings ...)
2020-11-14 22:54 ` [PATCH iproute2-next 7/7] ip: iptuntap: " Petr Machata
@ 2020-11-17 0:56 ` David Ahern
2020-11-23 21:21 ` Nikolay Aleksandrov
2020-11-25 4:44 ` David Ahern
8 siblings, 1 reply; 11+ messages in thread
From: David Ahern @ 2020-11-17 0:56 UTC (permalink / raw)
To: Petr Machata, netdev, stephen, Nikolay Aleksandrov
On 11/14/20 3:53 PM, Petr Machata wrote:
> Two helpers, parse_on_off() and print_on_off(), have been recently added to
> lib/utils.c. Convert a number of instances of the same effective behavior
> to calls to these helpers.
>
> Petr Machata (7):
> bridge: link: Port over to parse_on_off()
> bridge: link: Convert to use print_on_off()
> ip: iplink: Convert to use parse_on_off()
> ip: iplink_bridge_slave: Port over to parse_on_off()
> ip: iplink_bridge_slave: Convert to use print_on_off()
> ip: ipnetconf: Convert to use print_on_off()
> ip: iptuntap: Convert to use print_on_off()
>
> bridge/link.c | 135 ++++++++++++++++++---------------------
> ip/iplink.c | 47 +++++---------
> ip/iplink_bridge_slave.c | 46 +++++--------
> ip/ipnetconf.c | 28 ++++----
> ip/iptuntap.c | 18 ++----
> 5 files changed, 112 insertions(+), 162 deletions(-)
>
looks fine to me. Added Nik for a second set of eyes on the bridge changes.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH iproute2-next 0/7] Convert a number of use-cases to parse_on_off(), print_on_off()
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
0 siblings, 0 replies; 11+ messages in thread
From: Nikolay Aleksandrov @ 2020-11-23 21:21 UTC (permalink / raw)
To: David Ahern, Petr Machata, netdev, stephen
On 17/11/2020 02:56, David Ahern wrote:
> On 11/14/20 3:53 PM, Petr Machata wrote:
>> Two helpers, parse_on_off() and print_on_off(), have been recently added to
>> lib/utils.c. Convert a number of instances of the same effective behavior
>> to calls to these helpers.
>>
>> Petr Machata (7):
>> bridge: link: Port over to parse_on_off()
>> bridge: link: Convert to use print_on_off()
>> ip: iplink: Convert to use parse_on_off()
>> ip: iplink_bridge_slave: Port over to parse_on_off()
>> ip: iplink_bridge_slave: Convert to use print_on_off()
>> ip: ipnetconf: Convert to use print_on_off()
>> ip: iptuntap: Convert to use print_on_off()
>>
>> bridge/link.c | 135 ++++++++++++++++++---------------------
>> ip/iplink.c | 47 +++++---------
>> ip/iplink_bridge_slave.c | 46 +++++--------
>> ip/ipnetconf.c | 28 ++++----
>> ip/iptuntap.c | 18 ++----
>> 5 files changed, 112 insertions(+), 162 deletions(-)
>>
>
> looks fine to me. Added Nik for a second set of eyes on the bridge changes.
>
It's much later, but the changes look good to me. Thanks!
Cheers,
Nik
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH iproute2-next 0/7] Convert a number of use-cases to parse_on_off(), print_on_off()
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
` (7 preceding siblings ...)
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-25 4:44 ` David Ahern
8 siblings, 0 replies; 11+ messages in thread
From: David Ahern @ 2020-11-25 4:44 UTC (permalink / raw)
To: Petr Machata, netdev, stephen
On 11/14/20 3:53 PM, Petr Machata wrote:
> Two helpers, parse_on_off() and print_on_off(), have been recently added to
> lib/utils.c. Convert a number of instances of the same effective behavior
> to calls to these helpers.
>
applied to iproute2-next. Thanks, Petr.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2020-11-25 4:44 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH iproute2-next 3/7] ip: iplink: Convert to use parse_on_off() Petr Machata
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
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.