From: Serhey Popovych <serhe.popovych@gmail.com>
To: netdev@vger.kernel.org
Subject: [PATCH iproute2 v2 4/9] ip/tunnel: Use print_0xhex() instead of print_string()
Date: Thu, 18 Jan 2018 16:04:31 +0200 [thread overview]
Message-ID: <1516284276-10942-5-git-send-email-serhe.popovych@gmail.com> (raw)
In-Reply-To: <1516284276-10942-1-git-send-email-serhe.popovych@gmail.com>
No need for custom SPRINT_BUF() and snprintf() 0x%x
value to this buffer: we can use print_0xhex() instead
of print_string().
In link_iptnl.c use s2 instead of s1 buffer and remove
s1.
While there adjust fwmark option print order in iptnl
and ip6tnl to get it match each other.
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
ip/link_gre.c | 5 ++---
ip/link_gre6.c | 9 ++++-----
ip/link_ip6tnl.c | 18 ++++++++----------
ip/link_iptnl.c | 22 ++++++++++------------
ip/link_vti.c | 6 ++----
ip/link_vti6.c | 5 ++---
6 files changed, 28 insertions(+), 37 deletions(-)
diff --git a/ip/link_gre.c b/ip/link_gre.c
index 490d7db..2462828 100644
--- a/ip/link_gre.c
+++ b/ip/link_gre.c
@@ -443,9 +443,8 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[])
__u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]);
if (fwmark) {
- snprintf(s2, sizeof(s2), "0x%x", fwmark);
-
- print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+ print_0xhex(PRINT_ANY,
+ "fwmark", "fwmark 0x%x ", fwmark);
}
}
}
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
index 37bc544..7dcd70d 100644
--- a/ip/link_gre6.c
+++ b/ip/link_gre6.c
@@ -497,18 +497,17 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (oflags & GRE_CSUM)
print_bool(PRINT_ANY, "ocsum", "ocsum ", true);
- if (flags & IP6_TNL_F_USE_ORIG_FWMARK)
+ if (flags & IP6_TNL_F_USE_ORIG_FWMARK) {
print_bool(PRINT_ANY,
"ip6_tnl_f_use_orig_fwmark",
"fwmark inherit ",
true);
- else if (tb[IFLA_GRE_FWMARK]) {
+ } else if (tb[IFLA_GRE_FWMARK]) {
__u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]);
if (fwmark) {
- snprintf(s2, sizeof(s2), "0x%x", fwmark);
-
- print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+ print_0xhex(PRINT_ANY,
+ "fwmark", "fwmark 0x%x ", fwmark);
}
}
diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c
index 605bc61..00bf00a 100644
--- a/ip/link_ip6tnl.c
+++ b/ip/link_ip6tnl.c
@@ -438,6 +438,12 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
if (flags & IP6_TNL_F_MIP6_DEV)
print_bool(PRINT_ANY, "ip6_tnl_f_mip6_dev", "mip6 ", true);
+ if (flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE)
+ print_bool(PRINT_ANY,
+ "ip6_tnl_f_allow_local_remote",
+ "allow-localremote ",
+ true);
+
if (flags & IP6_TNL_F_USE_ORIG_FWMARK) {
print_bool(PRINT_ANY,
"ip6_tnl_f_use_orig_fwmark",
@@ -447,19 +453,11 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
__u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
if (fwmark) {
- SPRINT_BUF(b1);
-
- snprintf(b1, sizeof(b1), "0x%x", fwmark);
- print_string(PRINT_ANY, "fwmark", "fwmark %s ", b1);
+ print_0xhex(PRINT_ANY,
+ "fwmark", "fwmark 0x%x ", fwmark);
}
}
- if (flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE)
- print_bool(PRINT_ANY,
- "ip6_tnl_f_allow_local_remote",
- "allow-localremote ",
- true);
-
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]);
diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index 7fda580..00a8366 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -360,7 +360,6 @@ get_failed:
static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
- char s1[1024];
char s2[64];
const char *local = "any";
const char *remote = "any";
@@ -455,7 +454,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
const char *prefix = inet_ntop(AF_INET6,
RTA_DATA(tb[IFLA_IPTUN_6RD_PREFIX]),
- s1, sizeof(s1));
+ s2, sizeof(s2));
if (is_json_context()) {
print_string(PRINT_JSON, "prefix", NULL, prefix);
@@ -482,6 +481,15 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
}
}
+ if (tb[IFLA_IPTUN_FWMARK]) {
+ __u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
+
+ if (fwmark) {
+ print_0xhex(PRINT_ANY,
+ "fwmark", "fwmark 0x%x ", fwmark);
+ }
+ }
+
if (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]);
@@ -545,16 +553,6 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
fputs("noencap-remcsum ", f);
}
}
-
- if (tb[IFLA_IPTUN_FWMARK]) {
- __u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
-
- if (fwmark) {
- snprintf(s2, sizeof(s2), "0x%x", fwmark);
-
- print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
- }
- }
}
static void iptunnel_print_help(struct link_util *lu, int argc, char **argv,
diff --git a/ip/link_vti.c b/ip/link_vti.c
index 554cfcc..baaaf2f 100644
--- a/ip/link_vti.c
+++ b/ip/link_vti.c
@@ -213,10 +213,8 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
__u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]);
if (fwmark) {
- SPRINT_BUF(b1);
-
- snprintf(b1, sizeof(b1), "0x%x", fwmark);
- print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+ print_0xhex(PRINT_ANY,
+ "fwmark", "fwmark 0x%x ", fwmark);
}
}
}
diff --git a/ip/link_vti6.c b/ip/link_vti6.c
index a63f49f..952dbb0 100644
--- a/ip/link_vti6.c
+++ b/ip/link_vti6.c
@@ -212,9 +212,8 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
__u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]);
if (fwmark) {
- snprintf(s2, sizeof(s2), "0x%x", fwmark);
-
- print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+ print_0xhex(PRINT_ANY,
+ "fwmark", "fwmark 0x%x ", fwmark);
}
}
}
--
1.7.10.4
next prev parent reply other threads:[~2018-01-18 14:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-18 14:04 [PATCH iproute2 v2 0/9] ip/tunnel: Improve tunnel parameters printing Serhey Popovych
2018-01-18 14:04 ` [PATCH iproute2 v2 1/9] iplink: Use ll_index_to_name() instead of if_indextoname() Serhey Popovych
2018-01-18 14:04 ` [PATCH iproute2 v2 2/9] ip/tunnel: Correct and unify ttl/hoplimit printing Serhey Popovych
2018-01-18 14:04 ` [PATCH iproute2 v2 3/9] ip/tunnel: Simplify and unify tos printing Serhey Popovych
2018-01-18 14:04 ` Serhey Popovych [this message]
2018-01-18 14:04 ` [PATCH iproute2 v2 5/9] ip/tunnel: Abstract tunnel encapsulation options printing Serhey Popovych
2018-01-18 14:04 ` [PATCH iproute2 v2 6/9] gre/tunnel: Print erspan_index using print_uint() Serhey Popovych
2018-01-18 14:04 ` [PATCH iproute2 v2 7/9] vti/tunnel: Unify ikey/okey printing Serhey Popovych
2018-01-18 14:04 ` [PATCH iproute2 v2 8/9] vti6/tunnel: Unify and simplify link type help functions Serhey Popovych
2018-01-18 14:04 ` [PATCH iproute2 v2 9/9] tunnel: Return constant string without copying it Serhey Popovych
2018-01-19 0:35 ` [PATCH iproute2 v2 0/9] ip/tunnel: Improve tunnel parameters printing Stephen Hemminger
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=1516284276-10942-5-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).