From patchwork Wed Apr 4 12:24:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuval Mintz X-Patchwork-Id: 894955 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=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40GQJ52mpHz9s0b for ; Wed, 4 Apr 2018 22:29:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751231AbeDDM3W (ORCPT ); Wed, 4 Apr 2018 08:29:22 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:34489 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751097AbeDDM3V (ORCPT ); Wed, 4 Apr 2018 08:29:21 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yuvalm@mellanox.com) with ESMTPS (AES256-SHA encrypted); 4 Apr 2018 15:25:50 +0300 Received: from dev-r-vrt-155.mtr.labs.mlnx (dev-r-vrt-155.mtr.labs.mlnx [10.212.155.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w34COmLR031833; Wed, 4 Apr 2018 15:24:48 +0300 From: Yuval Mintz To: dsahern@gmail.com Cc: mlxsw@mellanox.com, netdev@vger.kernel.org, Yuval Mintz Subject: [PATCH iproute2-next] tc: Correct json output for actions Date: Wed, 4 Apr 2018 15:24:13 +0300 Message-Id: <1522844653-37136-1-git-send-email-yuvalm@mellanox.com> X-Mailer: git-send-email 2.4.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Commit 9fd3f0b255d9 ("tc: enable json output for actions") added JSON support for tc-actions at the expense of breaking other use cases that reach tc_print_action(), as the latter don't expect the 'actions' array to be a new object. Consider the following taken duringrun of tc_chain.sh selftest, and see the latter command output is broken: $ ./tc/tc -j -p actions list action gact | grep -C 3 actions [ { "total acts": 1 },{ "actions": [ { "order": 0, $ ./tc/tc -p -j -s filter show dev enp3s0np2 ingress | grep -C 3 actions }, "skip_hw": true, "not_in_hw": true,{ "actions": [ { "order": 1, "kind": "gact", "control_action": { Relocate the open/close of the JSON object to declare the object only for the case that needs it. Signed-off-by: Yuval Mintz Tested-by: Roman Mashak --- tc/m_action.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tc/m_action.c b/tc/m_action.c index 2f85d35..8993b93 100644 --- a/tc/m_action.c +++ b/tc/m_action.c @@ -366,7 +366,6 @@ tc_print_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts) if (tab_flush && NULL != tb[0] && NULL == tb[1]) return tc_print_action_flush(f, tb[0]); - open_json_object(NULL); open_json_array(PRINT_JSON, "actions"); for (i = 0; i <= tot_acts; i++) { if (tb[i]) { @@ -383,7 +382,6 @@ tc_print_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts) } close_json_array(PRINT_JSON, NULL); - close_json_object(); return 0; } @@ -439,8 +437,9 @@ int print_action(const struct sockaddr_nl *who, } } - + open_json_object(NULL); tc_print_action(fp, tb[TCA_ACT_TAB], tot_acts ? *tot_acts:0); + close_json_object(); return 0; }