netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Serhey Popovych <serhe.popovych@gmail.com>
To: netdev@vger.kernel.org
Subject: [PATCH iproute2 7/9] ip/tunnel: Minor cleanups in print routines
Date: Fri, 12 Jan 2018 19:39:32 +0200	[thread overview]
Message-ID: <1515778774-24173-8-git-send-email-serhe.popovych@gmail.com> (raw)
In-Reply-To: <1515778774-24173-1-git-send-email-serhe.popovych@gmail.com>

Print "unknown" parameter for "encap" type in PRINT_FP
context using "%s " format specifier and benefit from
complite time string merge.

Unify encapsulation type check.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
 ip/link_gre.c    |    5 +++--
 ip/link_gre6.c   |    8 ++++----
 ip/link_ip6tnl.c |    6 +++---
 ip/link_iptnl.c  |    2 +-
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/ip/link_gre.c b/ip/link_gre.c
index a7d1cd1..b4cde62 100644
--- a/ip/link_gre.c
+++ b/ip/link_gre.c
@@ -450,6 +450,8 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[])
 
 static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
+	__u16 type;
+
 	if (!tb)
 		return;
 
@@ -469,8 +471,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 	}
 
 	if (tb[IFLA_GRE_ENCAP_TYPE] &&
-	    rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
-		__u16 type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]);
+	    (type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE])) != TUNNEL_ENCAP_NONE) {
 		__u16 flags = rta_getattr_u16(tb[IFLA_GRE_ENCAP_FLAGS]);
 		__u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
 		__u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
index 200846e..557151f 100644
--- a/ip/link_gre6.c
+++ b/ip/link_gre6.c
@@ -381,6 +381,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 	unsigned int iflags = 0;
 	unsigned int oflags = 0;
 	unsigned int flags = 0;
+	__u16 type;
 	__u32 flowinfo = 0;
 	struct in6_addr in6_addr_any = IN6ADDR_ANY_INIT;
 	__u8 ttl = 0;
@@ -518,15 +519,14 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 	}
 
 	if (tb[IFLA_GRE_ENCAP_TYPE] &&
-	    rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
-		__u16 type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]);
+	    (type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE])) != TUNNEL_ENCAP_NONE) {
 		__u16 flags = rta_getattr_u16(tb[IFLA_GRE_ENCAP_FLAGS]);
 		__u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
 		__u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);
 
 		open_json_object("encap");
-
 		print_string(PRINT_FP, NULL, "encap ", NULL);
+
 		switch (type) {
 		case TUNNEL_ENCAP_FOU:
 			print_string(PRINT_ANY, "type", "%s ", "fou");
@@ -535,7 +535,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 			print_string(PRINT_ANY, "type", "%s ", "gue");
 			break;
 		default:
-			print_null(PRINT_ANY, "type", "unknown ", NULL);
+			print_null(PRINT_ANY, "type", "%s ", "unknown");
 			break;
 		}
 
diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c
index aa6f6fa..51c73dc 100644
--- a/ip/link_ip6tnl.c
+++ b/ip/link_ip6tnl.c
@@ -336,6 +336,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
 	char s2[64];
 	unsigned int link;
 	int flags = 0;
+	__u16 type;
 	__u32 flowinfo = 0;
 	__u8 ttl = 0;
 
@@ -458,8 +459,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
 	}
 
 	if (tb[IFLA_IPTUN_ENCAP_TYPE] &&
-	    rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
-		__u16 type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]);
+	    (type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE])) != TUNNEL_ENCAP_NONE) {
 		__u16 flags = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_FLAGS]);
 		__u16 sport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_SPORT]);
 		__u16 dport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_DPORT]);
@@ -474,7 +474,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
 			print_string(PRINT_ANY, "type", "%s ", "gue");
 			break;
 		default:
-			print_null(PRINT_ANY, "type", "unknown ", NULL);
+			print_null(PRINT_ANY, "type", "%s ", "unknown");
 			break;
 		}
 
diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index 83a524f..17d28ec 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -505,7 +505,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
 			print_string(PRINT_ANY, "type", "%s ", "gue");
 			break;
 		default:
-			print_null(PRINT_ANY, "type", "unknown ", NULL);
+			print_null(PRINT_ANY, "type", "%s ", "unknown");
 			break;
 		}
 
-- 
1.7.10.4

  parent reply	other threads:[~2018-01-12 17:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-12 17:39 [PATCH iproute2 0/9] ip/tunnel: Improve tunnel parameters printing Serhey Popovych
2018-01-12 17:39 ` [PATCH iproute2 1/9] iplink: Use ll_index_to_name() instead of if_indextoname() Serhey Popovych
2018-01-17 18:53   ` Stephen Hemminger
2018-01-12 17:39 ` [PATCH iproute2 2/9] ip/tunnel: Correct and unify ttl/hoplimit printing Serhey Popovych
2018-01-12 17:39 ` [PATCH iproute2 3/9] ip/tunnel: Simplify and unify tos printing Serhey Popovych
2018-01-12 17:39 ` [PATCH iproute2 4/9] ip/tunnel: Use print_0xhex() instead of print_string() Serhey Popovych
2018-01-12 17:39 ` [PATCH iproute2 5/9] ip/tunnel: Use print_string() and simplify encap option printing Serhey Popovych
2018-01-12 17:39 ` [PATCH iproute2 6/9] gre/tunnel: Print erspan_index using print_uint() Serhey Popovych
2018-01-12 17:39 ` Serhey Popovych [this message]
2018-01-12 17:39 ` [PATCH iproute2 8/9] vti/tunnel: Unify ikey/okey printing Serhey Popovych
2018-01-12 17:39 ` [PATCH iproute2 9/9] vti6/tunnel: Unify and simplify link type help functions Serhey Popovych

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1515778774-24173-8-git-send-email-serhe.popovych@gmail.com \
    --to=serhe.popovych@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).