From mboxrd@z Thu Jan 1 00:00:00 1970 From: Serhey Popovych Subject: [PATCH iproute2 3/7] ip6/tunnel: Unify tclass printing Date: Mon, 8 Jan 2018 19:06:34 +0200 Message-ID: <1515431198-29362-4-git-send-email-serhe.popovych@gmail.com> References: <1515431198-29362-1-git-send-email-serhe.popovych@gmail.com> To: netdev@vger.kernel.org Return-path: Received: from mail-lf0-f66.google.com ([209.85.215.66]:43506 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935525AbeAHRGq (ORCPT ); Mon, 8 Jan 2018 12:06:46 -0500 Received: by mail-lf0-f66.google.com with SMTP id z124so2432377lfd.10 for ; Mon, 08 Jan 2018 09:06:46 -0800 (PST) Received: from tuxracer.localdomain ([2a01:6d80::195:20:96:53]) by smtp.gmail.com with ESMTPSA id y138sm2221484lfd.62.2018.01.08.09.06.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 09:06:44 -0800 (PST) In-Reply-To: <1515431198-29362-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: Use @s2 buffer to store string representation of tclass and get rid of extra SPRINT_BUF(): no need to preserve @s2 contents for later. Use print_string(PRINT_ANY, ...) with prepared by snprintf() string for both PRINT_JSON and PRINT_FP cases. While there use __u32 for flowinfo in link_gre6.c and check for IFLA_GRE_FLOWINFO attribute presense. Signed-off-by: Serhey Popovych --- ip/link_gre6.c | 16 +++++----------- ip/link_ip6tnl.c | 16 +++++----------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/ip/link_gre6.c b/ip/link_gre6.c index 87c313c..a02dd4a 100644 --- a/ip/link_gre6.c +++ b/ip/link_gre6.c @@ -380,7 +380,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; - unsigned int flowinfo = 0; + __u32 flowinfo = 0; struct in6_addr in6_addr_any = IN6ADDR_ANY_INIT; if (!tb) @@ -471,17 +471,11 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) "ip6_tnl_f_use_orig_tclass", "tclass inherit ", true); - } else { - if (is_json_context()) { - SPRINT_BUF(b1); + } else if (tb[IFLA_GRE_FLOWINFO]) { + __u32 val = ntohl(flowinfo & IP6_FLOWINFO_TCLASS) >> 20; - snprintf(b1, sizeof(b1), "0x%02x", - ntohl(flowinfo & IP6_FLOWINFO_TCLASS) >> 20); - print_string(PRINT_JSON, "tclass", NULL, b1); - } else { - fprintf(f, "tclass 0x%02x ", - ntohl(flowinfo & IP6_FLOWINFO_TCLASS) >> 20); - } + snprintf(s2, sizeof(s2), "0x%02x", val); + print_string(PRINT_ANY, "tclass", "tclass %s ", s2); } if (flags & IP6_TNL_F_RCV_DSCP_COPY) diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c index e084975..05322fd 100644 --- a/ip/link_ip6tnl.c +++ b/ip/link_ip6tnl.c @@ -404,22 +404,16 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb "hoplimit %u ", rta_getattr_u8(tb[IFLA_IPTUN_TTL])); - if (flags & IP6_TNL_F_USE_ORIG_TCLASS) + if (flags & IP6_TNL_F_USE_ORIG_TCLASS) { print_bool(PRINT_ANY, "ip6_tnl_f_use_orig_tclass", "tclass inherit ", true); - else if (tb[IFLA_IPTUN_FLOWINFO]) { - __u32 val = ntohl(flowinfo & IP6_FLOWINFO_TCLASS); + } else if (tb[IFLA_IPTUN_FLOWINFO]) { + __u32 val = ntohl(flowinfo & IP6_FLOWINFO_TCLASS) >> 20; - if (is_json_context()) { - SPRINT_BUF(b1); - - snprintf(b1, sizeof(b1), "0x%02x", (__u8)(val >> 20)); - print_string(PRINT_JSON, "tclass", NULL, b1); - } else { - printf("tclass 0x%02x ", (__u8)(val >> 20)); - } + snprintf(s2, sizeof(s2), "0x%02x", val); + print_string(PRINT_ANY, "tclass", "tclass %s ", s2); } if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) { -- 1.7.10.4