From patchwork Fri Jan 12 17:39:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serhey Popovych X-Patchwork-Id: 860088 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="b8y0c5g5"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zJ94Q3yGxz9s4s for ; Sat, 13 Jan 2018 04:40:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964913AbeALRkD (ORCPT ); Fri, 12 Jan 2018 12:40:03 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:46198 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934126AbeALRj7 (ORCPT ); Fri, 12 Jan 2018 12:39:59 -0500 Received: by mail-lf0-f67.google.com with SMTP id a12so6738351lfe.13 for ; Fri, 12 Jan 2018 09:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=+5MZiePmXul7LDWHDfNxK+9HRjBZ3H/tfp1rU+lglTw=; b=b8y0c5g5hescNA6KGtAAl/w+QFcRd6iKsJzpbSf5qMM2jwR9LcLbF6D/l9FSLT/un4 Y+bNM6tD8rPG6q0h5fmRNJTPgf+JsrK7PgcyrqIkXjTng/TBK+pe/5SGUMQInscvvKR+ Jx1+BkSK3n+vr9VI4mOMNYu39AXOGpQH1QWmHxYZBuVfa8bgHL9fGyg8CDtyYpjILyIz 0O6wc4Gzwfu8eJwhjxs+AulM8grl48kJVlhIWfzebfcNn/t356vxWyuKY++XyFWKG0H1 FwuCvXifIeyZZYG8WmeCjE3GsssthJ73JX4wVa8YtlaBnY7tfFXqp5fSFhfRkkfItA17 J1tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=+5MZiePmXul7LDWHDfNxK+9HRjBZ3H/tfp1rU+lglTw=; b=EOqJO6wuSoQ92Fc7NmC5j6K2S4IXWQNGuXCH2PvXy2EBKk1lIyr/k1PsnM+0/ERrgc pojGlknKJmj3OQw+n+sRC8C73+urlKQqQwMovZDGOOS67gGdxXXjJbIPtlgmWB5dLW6I giIGcKMzC2itOp1yv3UEWuICgorFD40kCwWaC4C8MIj+IJhVgmB4A86l4bYtXdmeX/1y dBB94FrRs7u/TQhKuPrHCzeWtpLZZkOxo58uOWgKD0QRrGIZ2pzmI4FzW/IxcJj1366p W1Tzx7OoD6ymQFD8Lex6ki4YcoQ62q2MtyrXtiaMMDlMbIX1PQrM9pfmWVgE6Ewqi1z9 P4zw== X-Gm-Message-State: AKwxytcUFsi/dYSEZe+nRV20Xo1fc6kBz/9GgrkpfJqsYfAQDf7VGwer OZZ337d4iprL4eJc92jfXyK9bQ== X-Google-Smtp-Source: ACJfBota/cNC2arhu6GN6SqeSSuFDHeNbSlyjZCNWEI6ffu04WvTF7ZRNUYdw19pRH8bFd5lTX71Ng== X-Received: by 10.25.147.11 with SMTP id v11mr8801660lfd.93.1515778797604; Fri, 12 Jan 2018 09:39:57 -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.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 09:39:56 -0800 (PST) From: Serhey Popovych To: netdev@vger.kernel.org Subject: [PATCH iproute2 3/9] ip/tunnel: Simplify and unify tos printing Date: Fri, 12 Jan 2018 19:39:28 +0200 Message-Id: <1515778774-24173-4-git-send-email-serhe.popovych@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1515778774-24173-1-git-send-email-serhe.popovych@gmail.com> References: <1515778774-24173-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org For ip tunnels tos can be 0 when not configured, 1 when inherited from encapsulated packet and rest specifying diffserv (rfc2474) or tos (rfc1349) bits. It is stored in packet tos/diffserv field and returned in tos netlink attribute to userspace. Simplify and unify tos printing by using print_0xhex() and print_string() instead of fprintf() to output values. Signed-off-by: Serhey Popovych --- ip/iplink_geneve.c | 23 ++++++++--------------- ip/iplink_vxlan.c | 19 ++++++++----------- ip/link_gre.c | 23 ++++++++--------------- ip/link_iptnl.c | 22 ++++++++-------------- 4 files changed, 32 insertions(+), 55 deletions(-) diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c index 5a0afd4..2d0a041 100644 --- a/ip/iplink_geneve.c +++ b/ip/iplink_geneve.c @@ -228,7 +228,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) { __u32 vni; __u8 ttl = 0; - __u8 tos; + __u8 tos = 0; if (!tb) return; @@ -270,20 +270,13 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) else print_string(PRINT_FP, NULL, "ttl %s ", "inherit"); - if (tb[IFLA_GENEVE_TOS] && - (tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]))) { - if (is_json_context()) { - print_0xhex(PRINT_JSON, "tos", "%#x", tos); - } else { - if (tos == 1) { - print_string(PRINT_FP, - "tos", - "tos %s ", - "inherit"); - } else { - fprintf(f, "tos %#x ", tos); - } - } + if (tb[IFLA_GENEVE_TOS]) + tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]); + if (tos) { + if (is_json_context() || tos != 1) + print_0xhex(PRINT_ANY, "tos", "tos 0x%x ", tos); + else + print_string(PRINT_FP, NULL, "tos %s ", "inherit"); } if (tb[IFLA_GENEVE_LABEL]) { diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index bac326d..e292369 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -396,7 +396,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) __u32 vni; unsigned int link; __u8 ttl = 0; - __u8 tos; + __u8 tos = 0; __u32 maxaddr; if (!tb) @@ -514,16 +514,13 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (tb[IFLA_VXLAN_L3MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L3MISS])) print_bool(PRINT_ANY, "l3miss", "l3miss ", true); - if (tb[IFLA_VXLAN_TOS] && - (tos = rta_getattr_u8(tb[IFLA_VXLAN_TOS]))) { - if (is_json_context()) { - print_0xhex(PRINT_JSON, "tos", "%#x", tos); - } else { - if (tos == 1) - fprintf(f, "tos %s ", "inherit"); - else - fprintf(f, "tos %#x ", tos); - } + if (tb[IFLA_VXLAN_TOS]) + tos = rta_getattr_u8(tb[IFLA_VXLAN_TOS]); + if (tos) { + if (is_json_context() || tos != 1) + print_0xhex(PRINT_ANY, "tos", "tos 0x%x ", tos); + else + print_string(PRINT_FP, NULL, "tos %s ", "inherit"); } if (tb[IFLA_VXLAN_TTL]) diff --git a/ip/link_gre.c b/ip/link_gre.c index 2f6be20..11a131f 100644 --- a/ip/link_gre.c +++ b/ip/link_gre.c @@ -363,6 +363,7 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[]) unsigned int iflags = 0; unsigned int oflags = 0; __u8 ttl = 0; + __u8 tos = 0; if (tb[IFLA_GRE_REMOTE]) { unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]); @@ -396,21 +397,13 @@ static void gre_print_direct_opt(FILE *f, struct rtattr *tb[]) else print_string(PRINT_FP, NULL, "ttl %s ", "inherit"); - if (tb[IFLA_GRE_TOS] && rta_getattr_u8(tb[IFLA_GRE_TOS])) { - int tos = rta_getattr_u8(tb[IFLA_GRE_TOS]); - - if (is_json_context()) { - SPRINT_BUF(b1); - - snprintf(b1, sizeof(b1), "0x%x", tos); - print_string(PRINT_JSON, "tos", NULL, b1); - } else { - fputs("tos ", f); - if (tos == 1) - fputs("inherit ", f); - else - fprintf(f, "0x%x ", tos); - } + if (tb[IFLA_GRE_TOS]) + tos = rta_getattr_u8(tb[IFLA_GRE_TOS]); + if (tos) { + if (is_json_context() || tos != 1) + print_0xhex(PRINT_ANY, "tos", "tos 0x%x ", tos); + else + print_string(PRINT_FP, NULL, "tos %s ", "inherit"); } if (tb[IFLA_GRE_PMTUDISC]) { diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c index e19cb21..fd08bd9 100644 --- a/ip/link_iptnl.c +++ b/ip/link_iptnl.c @@ -367,6 +367,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[ unsigned int link; __u16 prefixlen, type; __u8 ttl = 0; + __u8 tos = 0; if (!tb) return; @@ -423,20 +424,13 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[ else print_string(PRINT_FP, NULL, "ttl %s ", "inherit"); - if (tb[IFLA_IPTUN_TOS]) { - int tos = rta_getattr_u8(tb[IFLA_IPTUN_TOS]); - - if (tos) { - if (is_json_context()) { - print_0xhex(PRINT_JSON, "tos", "%#x", tos); - } else { - fputs("tos ", f); - if (tos == 1) - fputs("inherit ", f); - else - fprintf(f, "0x%x ", tos); - } - } + if (tb[IFLA_IPTUN_TOS]) + tos = rta_getattr_u8(tb[IFLA_IPTUN_TOS]); + if (tos) { + if (is_json_context() || tos != 1) + print_0xhex(PRINT_ANY, "tos", "tos 0x%x ", tos); + else + print_string(PRINT_FP, NULL, "tos %s ", "inherit"); } if (tb[IFLA_IPTUN_PMTUDISC] && rta_getattr_u8(tb[IFLA_IPTUN_PMTUDISC]))