From mboxrd@z Thu Jan 1 00:00:00 1970 From: Serhey Popovych Subject: [PATCH iproute2 4/9] ip/tunnel: Use print_0xhex() instead of print_string() Date: Fri, 12 Jan 2018 19:39:29 +0200 Message-ID: <1515778774-24173-5-git-send-email-serhe.popovych@gmail.com> References: <1515778774-24173-1-git-send-email-serhe.popovych@gmail.com> To: netdev@vger.kernel.org Return-path: Received: from mail-lf0-f65.google.com ([209.85.215.65]:41074 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933729AbeALRkA (ORCPT ); Fri, 12 Jan 2018 12:40:00 -0500 Received: by mail-lf0-f65.google.com with SMTP id h137so6763219lfe.8 for ; Fri, 12 Jan 2018 09:40:00 -0800 (PST) Received: from tuxracer.localdomain ([2a01:6d80::195:20:96:53]) by smtp.gmail.com with ESMTPSA id c190sm3781968lfc.81.2018.01.12.09.39.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 09:39:58 -0800 (PST) In-Reply-To: <1515778774-24173-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: 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 --- ip/link_gre.c | 5 ++--- ip/link_gre6.c | 9 ++++----- ip/link_ip6tnl.c | 18 ++++++++---------- ip/link_iptnl.c | 22 ++++++++++------------ ip/link_vti.c | 14 ++++---------- ip/link_vti6.c | 13 ++++--------- 6 files changed, 32 insertions(+), 49 deletions(-) diff --git a/ip/link_gre.c b/ip/link_gre.c index 11a131f..2ae2194 100644 --- a/ip/link_gre.c +++ b/ip/link_gre.c @@ -442,9 +442,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 9b08656..9576354 100644 --- a/ip/link_gre6.c +++ b/ip/link_gre6.c @@ -496,18 +496,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 bd06e46..9594c3e 100644 --- a/ip/link_ip6tnl.c +++ b/ip/link_ip6tnl.c @@ -437,6 +437,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", @@ -446,19 +452,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 fd08bd9..fcb0795 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"; @@ -454,7 +453,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); @@ -481,6 +480,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]); @@ -544,16 +552,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 7ae2e3c..eebf542 100644 --- a/ip/link_vti.c +++ b/ip/link_vti.c @@ -168,6 +168,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) const char *local = "any"; const char *remote = "any"; __u32 key; + __u32 fwmark; unsigned int link; char s2[IFNAMSIZ]; @@ -208,16 +209,9 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) (key = rta_getattr_u32(tb[IFLA_VTI_OKEY]))) print_0xhex(PRINT_ANY, "okey", "okey %#x ", ntohl(key)); - if (tb[IFLA_VTI_FWMARK]) { - __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); - } - } + if (tb[IFLA_VTI_FWMARK] && + (fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]))) + print_0xhex(PRINT_ANY, "fwmark", "fwmark 0x%x ", fwmark); } static void vti_print_help(struct link_util *lu, int argc, char **argv, diff --git a/ip/link_vti6.c b/ip/link_vti6.c index f7c40d3..29a7062 100644 --- a/ip/link_vti6.c +++ b/ip/link_vti6.c @@ -168,6 +168,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) const char *remote = "any"; struct in6_addr saddr; struct in6_addr daddr; + __u32 fwmark; unsigned int link; char s2[64]; @@ -207,15 +208,9 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) print_string(PRINT_ANY, "okey", "okey %s ", s2); } - if (tb[IFLA_VTI_FWMARK]) { - __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); - } - } + if (tb[IFLA_VTI_FWMARK] && + (fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]))) + print_0xhex(PRINT_ANY, "fwmark", "fwmark 0x%x ", fwmark); } struct link_util vti6_link_util = { -- 1.7.10.4