[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1518105845-4951-1-git-send-email-serhe.popovych@gmail.com>
Date: Thu, 8 Feb 2018 18:04:05 +0200
From: Serhey Popovych <serhe.popovych@...il.com>
To: netdev@...r.kernel.org
Subject: [PATCH iproute2-next] 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 <serhe.popovych@...il.com>
---
ip/iplink_bridge_slave.c | 24 +++++-------------------
ip/link_gre.c | 6 ++++--
ip/link_gre6.c | 6 ++++--
3 files changed, 13 insertions(+), 23 deletions(-)
diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c
index be0fb4f..3fbfb87 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 b2573a1..e6a3174 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 880b75d..86dcc96 100644
--- a/ip/link_gre6.c
+++ b/ip/link_gre6.c
@@ -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,
--
1.7.10.4
Powered by blists - more mailing lists