From patchwork Thu Aug 3 15:55:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Fortin X-Patchwork-Id: 797289 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="E6YOcOeg"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xNZT24VyGz9s7C for ; Fri, 4 Aug 2017 01:57:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751947AbdHCP5b (ORCPT ); Thu, 3 Aug 2017 11:57:31 -0400 Received: from mail-wr0-f179.google.com ([209.85.128.179]:33427 "EHLO mail-wr0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751924AbdHCPzu (ORCPT ); Thu, 3 Aug 2017 11:55:50 -0400 Received: by mail-wr0-f179.google.com with SMTP id v105so7426230wrb.0 for ; Thu, 03 Aug 2017 08:55:50 -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=N0mAlXsQfohu4mful1WKu6NCBf0wajDtfdJlq0eDcvg=; b=E6YOcOegAo5fQj+2zSSnvX3DRnzJGSj/57i3xgiY8zdbOgF9grGhqPzJF68UmZwgGU +eU0DlWsGAj0buARwkOhCKWvp5NdOZoYa9cFrOwda4OAv75dwP8jBDUY3ZupTaglSNP3 WhIoZG2TTLYzfOfWrneAvHOVu5Jnob59wCs3A= 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=N0mAlXsQfohu4mful1WKu6NCBf0wajDtfdJlq0eDcvg=; b=iIMvto2wQDeGUWvu4+OjvUgUg2K+rR63tAzAyU7Y1p5amaWjAKkp2FaKHa8ngkkovn MTombxs1xfiZNEZFyq2nEu20IIX9TJkLF0A3A3SaPx0VM6UWZrSxpyIk5qqwrCAgZ3Hp WI+FP4XsXdS5FSTkA1GO5ysuaCsZACZiZd7UQDI1dSCXkOue784lNGgmKHiDrqQDzmhA UaLkR9CvaMAPlMVFoN2lhJ2TkDJKSQNcLC4FEK71dMFYlU/WBkVz7yVOCYidxqNoOFmO 57gQc59FaqNGUGpX9dXjfL66OLHvizr49vHGjAjRhft3HcqHZ2HXEPeE4vpS9BOd583l CJdQ== X-Gm-Message-State: AIVw113nmqD2kuA1SWKQcMcdiU0Fa1p8dlgTuzJ0EyXcRpL2Q6/Icd3d FXh9EeXUwLTODG0R1HY= X-Received: by 10.223.179.27 with SMTP id j27mr1578235wrd.190.1501775749367; Thu, 03 Aug 2017 08:55:49 -0700 (PDT) Received: from localhost.localdomain (91-160-18-219.subs.proxad.net. [91.160.18.219]) by smtp.googlemail.com with ESMTPSA id d91sm2213309wma.23.2017.08.03.08.55.48 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 03 Aug 2017 08:55:48 -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 14/27] ip: iplink_ipoib.c: add json output support Date: Thu, 3 Aug 2017 17:55:02 +0200 Message-Id: <20170803155515.99226-15-julien@cumulusnetworks.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170803155515.99226-1-julien@cumulusnetworks.com> References: <20170803155515.99226-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,