netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2-next] ip: Use print_0xhex() where appropriate
@ 2018-02-08 16:04 Serhey Popovych
  2018-02-09 16:12 ` David Ahern
  0 siblings, 1 reply; 2+ messages in thread
From: Serhey Popovych @ 2018-02-08 16:04 UTC (permalink / raw)
  To: netdev

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@gmail.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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute2-next] ip: Use print_0xhex() where appropriate
  2018-02-08 16:04 [PATCH iproute2-next] ip: Use print_0xhex() where appropriate Serhey Popovych
@ 2018-02-09 16:12 ` David Ahern
  0 siblings, 0 replies; 2+ messages in thread
From: David Ahern @ 2018-02-09 16:12 UTC (permalink / raw)
  To: Serhey Popovych, netdev

On 2/8/18 9:04 AM, Serhey Popovych wrote:
> 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@gmail.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-09 16:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-08 16:04 [PATCH iproute2-next] ip: Use print_0xhex() where appropriate Serhey Popovych
2018-02-09 16:12 ` David Ahern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).