ip: Use print_0xhex() where appropriate
Subsystems (2)
PATCH 1/1 ip: Use print_0xhex() where appropriate
In gre/gre6 for non-JSON output 0x%x format is used: use print_0xhex() to get the same value for JSON.
Get rid of custom _print_hex() in bridge slave code: print_0xhex() can be used perfectly.
Break long print_uint() with long argument list to fit into 80 columns.
Signed-off-by Serhey Popovych <[email protected]>
--- ip/iplink_bridge_slave.c | 24 +++++------------------- ip/link_gre.c | 6 ++++-- ip/link_gre6.c | 6 ++++-- 3 files changed, 13 insertions(+), 23 deletions(-)
ip/iplink_bridge_slave.c +5 -19
@@ -81,21 +81,6 @@ static void _print_onoff(FILE *f, char *json_flag, char *flag, __u8 val)fprintf (f,"%s %s " , flag, val ?"on" :"off" ); } -static void _print_hex (FILE *f, -const char *json_attr, -const char *attr, -__u16 val) -{ -if (is_json_context ()) { -SPRINT_BUF (b1); - -snprintf (b1,sizeof (b1),"0x%x" , val); -print_string (PRINT_JSON , json_attr,NULL , b1); - }else { -fprintf (f,"%s 0x%x " , attr, val); - } -} -static void _print_timer (FILE *f,const char *attr,struct rtattr *timer) {struct timeval tv;
@@ -181,11 +166,11 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f, rta_getattr_u8(tb[IFLA_BRPORT_UNICAST_FLOOD]));if (tb[IFLA_BRPORT_ID ]) -_print_hex (f,"id" ,"port_id" , -rta_getattr_u16 (tb[IFLA_BRPORT_ID ])); +print_0xhex (PRINT_ANY ,"id" ,"port_id 0x%x " , +rta_getattr_u16 (tb[IFLA_BRPORT_ID ]));if (tb[IFLA_BRPORT_NO ]) -_print_hex (f,"no" ,"port_no" , +print_0xhex (PRINT_ANY ,"no" ,"port_no 0x%x " ,rta_getattr_u16 (tb[IFLA_BRPORT_NO ]));if (tb[IFLA_BRPORT_DESIGNATED_PORT ])
@@ -279,7 +264,8 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,__u16 fwd_mask; fwd_mask =rta_getattr_u16 (tb[IFLA_BRPORT_GROUP_FWD_MASK ]); -_print_hex (f,"group_fwd_mask" ,"group_fwd_mask" , fwd_mask); +print_0xhex (PRINT_ANY ,"group_fwd_mask" , +"group_fwd_mask 0x%x " , fwd_mask);_bitmask2str (fwd_mask, convbuf,sizeof (convbuf), fwd_mask_tbl);print_string (PRINT_ANY ,"group_fwd_mask_str" ,"group_fwd_mask_str %s " , convbuf);
ip/link_gre.c +4 -2
@@ -490,7 +490,8 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])if (tb[IFLA_GRE_ERSPAN_VER ]) {__u8 erspan_ver =rta_getattr_u8 (tb[IFLA_GRE_ERSPAN_VER ]); -print_uint (PRINT_ANY ,"erspan_ver" ,"erspan_ver %u " , erspan_ver); +print_uint (PRINT_ANY , +"erspan_ver" ,"erspan_ver %u " , erspan_ver); }if (tb[IFLA_GRE_ERSPAN_DIR ]) {
@@ -507,7 +508,8 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])if (tb[IFLA_GRE_ERSPAN_HWID ]) {__u16 erspan_hwid =rta_getattr_u16 (tb[IFLA_GRE_ERSPAN_HWID ]); -print_hex (PRINT_ANY ,"erspan_hwid" ,"erspan_hwid 0x%x " , erspan_hwid); +print_0xhex (PRINT_ANY , +"erspan_hwid" ,"erspan_hwid 0x%x " , erspan_hwid); } tnl_print_encap(tb,
ip/link_gre6.c +4 -2
@@ -557,7 +557,8 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])if (tb[IFLA_GRE_ERSPAN_VER ]) {__u8 erspan_ver =rta_getattr_u8 (tb[IFLA_GRE_ERSPAN_VER ]); -print_uint (PRINT_ANY ,"erspan_ver" ,"erspan_ver %u " , erspan_ver); +print_uint (PRINT_ANY , +"erspan_ver" ,"erspan_ver %u " , erspan_ver); }if (tb[IFLA_GRE_ERSPAN_DIR ]) {
@@ -574,7 +575,8 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])if (tb[IFLA_GRE_ERSPAN_HWID ]) {__u16 erspan_hwid =rta_getattr_u16 (tb[IFLA_GRE_ERSPAN_HWID ]); -print_hex (PRINT_ANY ,"erspan_hwid" ,"erspan_hwid 0x%x " , erspan_hwid); +print_0xhex (PRINT_ANY , +"erspan_hwid" ,"erspan_hwid 0x%x " , erspan_hwid); } tnl_print_encap(tb,
Signature · 1 line
1.7.10.4
David Ahern
AppliedQuoted 6 lines · Serhey Popovych
In gre/gre6 for non-JSON output 0x%x format is used: use
print_0xhex()to get the same value for JSON.Get rid of custom
_print_hex()in bridge slave code:print_0xhex()can be used perfectly.
Quoted 9 lines
Break long
print_uint()with long argument list to fit into 80 columns.Signed-off-by Serhey Popovych <[email protected]>--- ip/iplink_bridge_slave.c | 24 +++++------------------- ip/link_gre.c | 6 ++++-- ip/link_gre6.c | 6 ++++-- 3 files changed, 13 insertions(+), 23 deletions(-)
applied to iproute2-next