From patchwork Tue Apr 16 15:30:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 1086382 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@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; dmarc=pass (p=none dis=none) header.from=cumulusnetworks.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=cumulusnetworks.com header.i=@cumulusnetworks.com header.b="V/TNJ7uJ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44k8Sr1t8Mz9s4Y for ; Wed, 17 Apr 2019 01:30:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728316AbfDPPaS (ORCPT ); Tue, 16 Apr 2019 11:30:18 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:42765 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbfDPPaS (ORCPT ); Tue, 16 Apr 2019 11:30:18 -0400 Received: by mail-wr1-f67.google.com with SMTP id g3so27662634wrx.9 for ; Tue, 16 Apr 2019 08:30:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cumulusnetworks.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vLNIg7ckJoKYHhVeqFHJ0MzkRrNOt4PAbY0iJufcJLg=; b=V/TNJ7uJbMKIMdxBmiEWMb71hiEJxF2Bbhweir1sctQ68qyVgmdAYtufK5LSo7GjvF Q3wlIRm+bb/wyPOELR7z70v6m1tf9Xs4hUsCLUz4WM/I+KTQ750vbPICkmeySokabIar Kl6yjwOnioDzRTHJRk4jV4tO1z7AKSUh1sGMQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vLNIg7ckJoKYHhVeqFHJ0MzkRrNOt4PAbY0iJufcJLg=; b=DxjhAtySkvs4t4xHcSSmE4M0u/QE5IwBYQ5CH4q4EEjnBf5Q2emK1ZUxhlthhqN8bx 4gZF3mM/IXNrYbB5KPiKuTRY9N9w7sZSHyHSIN5Jm2pRmp45smAP4spYlBpy5K79ZcuP e9nnvHuKx0bbwSfcVkn8LGwqXT3hs5srIYQ35ubbRCDINXXaNfrl4VYZ+QU7e6AbQ6pJ 7hj6Drr9IiL/CSnEfFhTr3UVUuT+eOISPizzenqYDYIRXDfYQ/A0zwT9LY9S1cmrordR +/gU5kcla5hGuPQMpLAYZBKnDEy7pRsf0Fhp/pXpNzU9DTFadpJrFs/v9NWbichfUQzH XpBw== X-Gm-Message-State: APjAAAXqlodgKYBLIzTmiPruYu8RzXtR7gOA9ObDhTG82BJulVyWmJKv 6SlQOHLfYoIaye94lrCVn3EpBtGz70g= X-Google-Smtp-Source: APXvYqwGYLBPFc1+iJ9WucPl/Zl5+RQvNyK3/AfetQO57dzr/OXu/cPK/bmV9K9d3aSDbzMFB51kjA== X-Received: by 2002:a5d:52cc:: with SMTP id r12mr32690923wrv.163.1555428615407; Tue, 16 Apr 2019 08:30:15 -0700 (PDT) Received: from localhost.localdomain ([93.152.141.58]) by smtp.gmail.com with ESMTPSA id h18sm64794061wrt.97.2019.04.16.08.30.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Apr 2019 08:30:14 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@cumulusnetworks.com, Stephen Hemminger , Nikolay Aleksandrov Subject: [PATCH iproute2 v2] bridge: vlan: fix standard stats output Date: Tue, 16 Apr 2019 18:30:12 +0300 Message-Id: <20190416153012.32490-1-nikolay@cumulusnetworks.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416151420.31785-1-nikolay@cumulusnetworks.com> References: <20190416151420.31785-1-nikolay@cumulusnetworks.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Each of the commits below broke the vlan stats output in a different way: - 45fca4ed9412 ("bridge: fix vlan show stats formatting") Added a second print of an interface name (e.g. eth4eth4) - c7c1a1ef51ae ("bridge: colorize output and use JSON print library") Broke normal vlan stats output by not printing a new line after them Also printed interfaces without any vlans when printing stats This fix is not pretty but it brings back the previous behaviour. Before this fix: $ bridge -s vlan show port vlan id br0br0 1 PVID Egress Untagged RX: 0 bytes 0 packets TX: 0 bytes 0 packets 4 RX: 0 bytes 0 packets TX: 0 bytes 0 packetseth4eth4 4 RX: 0 bytes 0 packets TX: 0 bytes 0 packetsroot@debian:~/ After this fix: $ bridge -s vlan show port vlan id br0 1 PVID Egress Untagged RX: 0 bytes 0 packets TX: 0 bytes 0 packets 4 RX: 0 bytes 0 packets TX: 0 bytes 0 packets eth4 4 RX: 0 bytes 0 packets TX: 0 bytes 0 packets Fixes: 45fca4ed9412 ("bridge: fix vlan show stats formatting") Fixes: c7c1a1ef51ae ("bridge: colorize output and use JSON print library") Signed-off-by: Nikolay Aleksandrov --- v2: simplify print_vlan_stats_attr bridge/vlan.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index d075a42d139b..6d33b0a990a5 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -252,11 +252,11 @@ static int filter_vlan_check(__u16 vid, __u16 flags) return 1; } -static void open_vlan_port(int ifi_index) +static void open_vlan_port(int ifi_index, const char *fmt) { open_json_object(NULL); - print_string(PRINT_ANY, "ifname", "%s", - ll_index_to_name(ifi_index)); + print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname", fmt, + ll_index_to_name(ifi_index)); open_json_array(PRINT_JSON, "vlans"); } @@ -286,7 +286,7 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex) __u32 last_tunid_start = 0; if (!filter_vlan) - open_vlan_port(ifindex); + open_vlan_port(ifindex, "%s"); open_json_array(PRINT_JSON, "tunnel"); for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { @@ -331,7 +331,7 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex) continue; if (filter_vlan) - open_vlan_port(ifindex); + open_vlan_port(ifindex, "%s"); open_json_object(NULL); print_range("vlan", last_vid_start, tunnel_vid); @@ -463,7 +463,7 @@ static void print_one_vlan_stats(const struct bridge_vlan_xstats *vstats) print_lluint(PRINT_ANY, "tx_bytes", " TX: %llu bytes", vstats->tx_bytes); - print_lluint(PRINT_ANY, "tx_packets", " %llu packets", + print_lluint(PRINT_ANY, "tx_packets", " %llu packets\n", vstats->tx_packets); close_json_object(); } @@ -472,7 +472,7 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) { struct rtattr *brtb[LINK_XSTATS_TYPE_MAX+1]; struct rtattr *i, *list; - const char *ifname; + bool found_vlan = false; int rem; parse_rtattr(brtb, LINK_XSTATS_TYPE_MAX, RTA_DATA(attr), @@ -483,12 +483,6 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) list = brtb[LINK_XSTATS_TYPE_BRIDGE]; rem = RTA_PAYLOAD(list); - ifname = ll_index_to_name(ifindex); - open_vlan_port(ifindex); - - print_color_string(PRINT_FP, COLOR_IFNAME, - NULL, "%-16s", ifname); - for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { const struct bridge_vlan_xstats *vstats = RTA_DATA(i); @@ -503,9 +497,19 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) !(vstats->flags & BRIDGE_VLAN_INFO_BRENTRY)) continue; + /* found vlan stats, first time print the interface name */ + if (!found_vlan) { + open_vlan_port(ifindex, "%-16s"); + found_vlan = true; + } else { + print_string(PRINT_FP, NULL, "%-16s", ""); + } print_one_vlan_stats(vstats); } - close_vlan_port(); + + /* vlan_port is opened only if there are any vlan stats */ + if (found_vlan) + close_vlan_port(); } static int print_vlan_stats(struct nlmsghdr *n, void *arg) @@ -632,7 +636,7 @@ void print_vlan_info(struct rtattr *tb, int ifindex) int rem = RTA_PAYLOAD(list); __u16 last_vid_start = 0; - open_vlan_port(ifindex); + open_vlan_port(ifindex, "%s"); for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { struct bridge_vlan_info *vinfo;