From: Serhey Popovych Date: Thu, 8 Feb 2018 16:04:05 +0000 (+0200) Subject: ip: Use print_0xhex() where appropriate X-Git-Tag: v4.17.0~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db2b8b6ef0a27480deb7329f888fa5218fe67907;p=thirdparty%2Fiproute2.git 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 Signed-off-by: David Ahern --- diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c index be0fb4fa3..3fbfb878c 100644 --- a/ip/iplink_bridge_slave.c +++ b/ip/iplink_bridge_slave.c @@ -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); diff --git a/ip/link_gre.c b/ip/link_gre.c index e6b564552..e3e532393 100644 --- a/ip/link_gre.c +++ b/ip/link_gre.c @@ -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, diff --git a/ip/link_gre6.c b/ip/link_gre6.c index ff11cd186..251ae0e32 100644 --- a/ip/link_gre6.c +++ b/ip/link_gre6.c @@ -556,7 +556,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]) { @@ -573,7 +574,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,