From patchwork Thu Aug 17 17:36:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Fortin X-Patchwork-Id: 802801 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 (1024-bit key; unprotected) header.d=cumulusnetworks.com header.i=@cumulusnetworks.com header.b="M4Rf9esT"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xYD6L2LZmz9t4X for ; Fri, 18 Aug 2017 03:41:30 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753497AbdHQRl2 (ORCPT ); Thu, 17 Aug 2017 13:41:28 -0400 Received: from mail-wr0-f173.google.com ([209.85.128.173]:37904 "EHLO mail-wr0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753554AbdHQRlZ (ORCPT ); Thu, 17 Aug 2017 13:41:25 -0400 Received: by mail-wr0-f173.google.com with SMTP id 5so25425237wrz.5 for ; Thu, 17 Aug 2017 10:41:24 -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; bh=aQf7foBHYjGy/HP08I4aWtMzCS2nBUuSEQ73PPLvmv0=; b=M4Rf9esTCNxs2X2T81R895EAkt3g7jJFqeRry6BZvtiNcVvyWnVLqdDm6TdhFiDFWu tXPbxIRcKOzDhTewv99LIDkCqZWZ5JMYBKdx/Nsgp95jQnm2wIF7Jj5H8ckKSEt8V72R p68FK+v5zXbfRlC852oD7mhwZC2i8TYcF0IXY= 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; bh=aQf7foBHYjGy/HP08I4aWtMzCS2nBUuSEQ73PPLvmv0=; b=jIEs1cuaxMC6M+h5yoSBi/RmezEJSi8BY9zz3OPXStO3mCCieOdcwBYmjIEYX4AWwq UYOHXZjtGRpNVrxj498DQkiPvtlSSkNJcGxwPMEdXMfyIXNRk6kLNvrJhEo3SLfQAk8A BoillsK9YxRnog9D44OBZUCUJvt0rpxrOsI2w3F/foQUI7e49M0FU7unZVO5M+5x/tCk 1lcgP7/lK7jghPRS4X5crWSZHENZVWErRBSf5w8bkvqFmKkPxgPPTNJHpoIo9Ss8+EIg WadnqSA35kEIHP4yH+WpD+CuLkHJNO3q6rGHYerapPuYRhc7ObyTHk3Tbg6+PyhYub7a Mzmw== X-Gm-Message-State: AHYfb5gA/I9gR9zd+Mta94EQANLJqL1dYYNPE/mP+xqfqdWNY5u42bH+ fq1s438zSjfdFKpSTGHHbHuk X-Received: by 10.28.69.91 with SMTP id s88mr1914092wma.127.1502991683721; Thu, 17 Aug 2017 10:41:23 -0700 (PDT) Received: from localhost.localdomain ([37.169.21.172]) by smtp.googlemail.com with ESMTPSA id k13sm3902040wrd.4.2017.08.17.10.41.18 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 17 Aug 2017 10:41:23 -0700 (PDT) From: Julien Fortin X-Google-Original-From: Julien Fortin To: netdev@vger.kernel.org Cc: roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com, dsa@cumulusnetworks.com, Julien Fortin Subject: [PATCH iproute2 json v2 14/27] ip: iplink_ipoib.c: add json output support Date: Thu, 17 Aug 2017 10:36:01 -0700 Message-Id: <20170817173614.54987-15-julien@cumulusnetworks.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170817173614.54987-1-julien@cumulusnetworks.com> References: <20170817173614.54987-1-julien@cumulusnetworks.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Julien Fortin Schema: { "key": { "type": "string", "attr": "IFLA_IPOIB_PKEY" }, "mode": { "type": "string", "attr": "IFLA_IPOIB_PKEY" }, "umcast": { "type": "string", "attr": "IFLA_IPOIB_UMCAST" } } Signed-off-by: Julien Fortin --- ip/iplink_ipoib.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/ip/iplink_ipoib.c b/ip/iplink_ipoib.c index 86dc65ca..e69bda0e 100644 --- a/ip/iplink_ipoib.c +++ b/ip/iplink_ipoib.c @@ -91,23 +91,43 @@ static void ipoib_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) RTA_PAYLOAD(tb[IFLA_IPOIB_PKEY]) < sizeof(__u16)) return; - fprintf(f, "pkey %#.4x ", rta_getattr_u16(tb[IFLA_IPOIB_PKEY])); + __u16 pkey = rta_getattr_u16(tb[IFLA_IPOIB_PKEY]); + + if (is_json_context()) { + SPRINT_BUF(b1); + + snprintf(b1, sizeof(b1), "%#.4x", pkey); + print_string(PRINT_JSON, "key", NULL, b1); + } else { + fprintf(f, "pkey %#.4x ", pkey); + } if (!tb[IFLA_IPOIB_MODE] || RTA_PAYLOAD(tb[IFLA_IPOIB_MODE]) < sizeof(__u16)) return; mode = rta_getattr_u16(tb[IFLA_IPOIB_MODE]); - fprintf(f, "mode %s ", + + const char *mode_str = mode == IPOIB_MODE_DATAGRAM ? "datagram" : - mode == IPOIB_MODE_CONNECTED ? "connected" : - "unknown"); + mode == IPOIB_MODE_CONNECTED ? "connected" : "unknown"; + + print_string(PRINT_ANY, "mode", "mode %s ", mode_str); if (!tb[IFLA_IPOIB_UMCAST] || RTA_PAYLOAD(tb[IFLA_IPOIB_UMCAST]) < sizeof(__u16)) return; - fprintf(f, "umcast %.4x ", rta_getattr_u16(tb[IFLA_IPOIB_UMCAST])); + __u16 umcast = rta_getattr_u16(tb[IFLA_IPOIB_UMCAST]); + + if (is_json_context()) { + SPRINT_BUF(b1); + + snprintf(b1, sizeof(b1), "%.4x", umcast); + print_string(PRINT_JSON, "umcast", NULL, b1); + } else { + fprintf(f, "umcast %.4x ", umcast); + } } static void ipoib_print_help(struct link_util *lu, int argc, char **argv,