From patchwork Thu Aug 17 17:36:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Fortin X-Patchwork-Id: 802805 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="Cj1TVQPc"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xYD6d0PH1z9t4X for ; Fri, 18 Aug 2017 03:41:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753611AbdHQRln (ORCPT ); Thu, 17 Aug 2017 13:41:43 -0400 Received: from mail-wr0-f179.google.com ([209.85.128.179]:34085 "EHLO mail-wr0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753595AbdHQRlj (ORCPT ); Thu, 17 Aug 2017 13:41:39 -0400 Received: by mail-wr0-f179.google.com with SMTP id y96so47244372wrc.1 for ; Thu, 17 Aug 2017 10:41:38 -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=W4nAWPeLK+3rsDWzNBpmKUoUHJ1QUgvxEf7ifeIHNhg=; b=Cj1TVQPcV9wGKh+whUlhZ+GM3mFkPdLa/mD7qusoP+9hjxiInil9x19zMa5IC3740y j6kooJTC3VNfkm1rJRNOgL6JxvXOI9D4wcAYoFRo6b8ZSIO8coxr1ThIDi0fxCjXINcY FXtX5uBJ5nyaHvU0hsFOk1Bo9jDxHonUdfrT8= 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=W4nAWPeLK+3rsDWzNBpmKUoUHJ1QUgvxEf7ifeIHNhg=; b=d8vdTFNKwZHZBe3EHgeVwiEapvWBTqYLkNu5VNbl8E/WMx62xRvXLByL8kZ4NCAlkY etuTqLivA4tVxN0fTGdUrSuS1wdgd2MKZ3xtKyKDit8rhRabkYsU5aVsuLebldIQgyCX OPIxiG8h/r5C3RsOcGpwQdZz+M3K5uSik37Zle7Fp860FTQKkO+qRKMhVvrlwrUJ/Pxk hTuv/cU4utGodyPXOZgPWQiuiQ1rZRjLeBeH0PEK3xxwqz80ydGvhE/xy+t+gcq5+1Pc Xrva3HG9NB0kNyjgV2QNoFq3YPobZoNxumwnkRvCyEFLkBnpuL0yyLzOUzJE9vCtoX9l LXHw== X-Gm-Message-State: AHYfb5gIDqoLdheylG/dhC2ufmFWxoDuOSgeTIArxpRJVhGphaLh/2V4 4kjXVTLkd0aM1/jdX3ByqKmg X-Received: by 10.28.57.197 with SMTP id g188mr1958787wma.33.1502991697676; Thu, 17 Aug 2017 10:41:37 -0700 (PDT) Received: from localhost.localdomain ([37.169.21.172]) by smtp.googlemail.com with ESMTPSA id k13sm3902040wrd.4.2017.08.17.10.41.34 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 17 Aug 2017 10:41:37 -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 18/27] ip: iplink_xdp.c: add json output support Date: Thu, 17 Aug 2017 10:36:05 -0700 Message-Id: <20170817173614.54987-19-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 { "attached": { "type": "uint", "attr": "IFLA_XDP_ATTACHED" }, "prog_id": { "type": "uint", "attr": "IFLA_XDP_PROG_ID" } } Signed-off-by: Julien Fortin --- ip/iplink_xdp.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/ip/iplink_xdp.c b/ip/iplink_xdp.c index 9ae9ee5d..3a61076e 100644 --- a/ip/iplink_xdp.c +++ b/ip/iplink_xdp.c @@ -16,6 +16,7 @@ #include "xdp.h" #include "bpf_util.h" +#include "ip_common.h" extern int force; @@ -92,20 +93,24 @@ void xdp_dump(FILE *fp, struct rtattr *xdp) return; mode = rta_getattr_u8(tb[IFLA_XDP_ATTACHED]); - if (mode == XDP_ATTACHED_NONE) - return; - else if (mode == XDP_ATTACHED_DRV) - fprintf(fp, "xdp"); - else if (mode == XDP_ATTACHED_SKB) - fprintf(fp, "xdpgeneric"); - else if (mode == XDP_ATTACHED_HW) - fprintf(fp, "xdpoffload"); - else - fprintf(fp, "xdp[%u]", mode); + if (is_json_context()) { + print_uint(PRINT_JSON, "attached", NULL, mode); + } else { + if (mode == XDP_ATTACHED_NONE) + return; + else if (mode == XDP_ATTACHED_DRV) + fprintf(fp, "xdp"); + else if (mode == XDP_ATTACHED_SKB) + fprintf(fp, "xdpgeneric"); + else if (mode == XDP_ATTACHED_HW) + fprintf(fp, "xdpoffload"); + else + fprintf(fp, "xdp[%u]", mode); + } if (tb[IFLA_XDP_PROG_ID]) - fprintf(fp, "/id:%u", - rta_getattr_u32(tb[IFLA_XDP_PROG_ID])); + print_uint(PRINT_ANY, "prog_id", "/id:%u", + rta_getattr_u32(tb[IFLA_XDP_PROG_ID])); - fprintf(fp, " "); + print_string(PRINT_FP, NULL, "%c", " "); }