Convert a number of use-cases to parse_on_off(), print_on_off()
Subsystems (2)
cover Convert a number of use-cases to parse_on_off(), print_on_off()
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(-)
Signature · 1 line
2.25.1
PATCH 1/7 bridge: link: Port over to parse_on_off()
Convert bridge/link.c from a custom on_off parser to the new global one.
--- bridge/link.c | 79 ++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 42 deletions(-)
bridge/link.c +37 -42
@@ -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);
Signature · 1 line
2.25.1
PATCH 2/7 bridge: link: Convert to use print_on_off()
In reply to Petr MachataInstead of rolling a custom on-off printer, use the one added to utils.c.
--- bridge/link.c | 56 ++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 32 deletions(-)
bridge/link.c +24 -32
@@ -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)); }
Signature · 1 line
2.25.1
PATCH 3/7 ip: iplink: Convert to use parse_on_off()
In reply to Petr MachataInvoke parse_on_off() instead of rolling a custom function.
--- ip/iplink.c | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-)
ip/iplink.c +17 -30
@@ -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 ) {
Signature · 1 line
2.25.1
PATCH 4/7 ip: iplink_bridge_slave: Port over to parse_on_off()
In reply to Petr MachataInvoke 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.
--- ip/iplink_bridge_slave.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
ip/iplink_bridge_slave.c +4 -8
@@ -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); }
Signature · 1 line
2.25.1
PATCH 5/7 ip: iplink_bridge_slave: Convert to use print_on_off()
In reply to Petr MachataInstead 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.
--- ip/iplink_bridge_slave.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-)
ip/iplink_bridge_slave.c +13 -21
@@ -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 ]) {
Signature · 1 line
2.25.1
PATCH 6/7 ip: ipnetconf: Convert to use print_on_off()
In reply to Petr MachataInstead of rolling a custom on-off printer, use the one added to utils.c.
--- ip/ipnetconf.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
ip/ipnetconf.c +11 -17
@@ -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 );
Signature · 1 line
2.25.1
PATCH 7/7 ip: iptuntap: Convert to use print_on_off()
In reply to Petr MachataInstead of rolling a custom on-off printer, use the one added to utils.c.
--- ip/iptuntap.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
ip/iptuntap.c +6 -12
@@ -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 ]));
Signature · 1 line
2.25.1
Quoted 13 lines · Petr Machata
Two helpers,
parse_on_off()andprint_on_off(), have been recently added tolib/utils.c. Convert a number of instances of the same effective behavior to calls to these helpers.Petr Machata (7):
bridge: link: Port over toparse_on_off()
bridge: link: Convert to useprint_on_off()
ip: iplink: Convert to useparse_on_off()
ip:iplink_bridge_slave: Port over toparse_on_off()
ip:iplink_bridge_slave: Convert to useprint_on_off()
ip: ipnetconf: Convert to useprint_on_off()
ip: iptuntap: Convert to useprint_on_off()
Quoted 7 lines
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.
Quoted 22 lines · David Ahern
Quoted 13 lines · Petr Machata
Two helpers,
parse_on_off()andprint_on_off(), have been recently added tolib/utils.c. Convert a number of instances of the same effective behavior to calls to these helpers.Petr Machata (7):
bridge: link: Port over toparse_on_off()
bridge: link: Convert to useprint_on_off()
ip: iplink: Convert to useparse_on_off()
ip:iplink_bridge_slave: Port over toparse_on_off()
ip:iplink_bridge_slave: Convert to useprint_on_off()
ip: ipnetconf: Convert to useprint_on_off()
ip: iptuntap: Convert to useprint_on_off()Quoted 7 lines
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(-)
Quoted 2 lines
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
David Ahern
AppliedQuoted 4 lines · Petr Machata
Two helpers,
parse_on_off()andprint_on_off(), have been recently added tolib/utils.c. Convert a number of instances of the same effective behavior to calls to these helpers.
applied to iproute2-next. Thanks, Petr.