From patchwork Thu Aug 3 15:55:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Fortin X-Patchwork-Id: 797285 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="F3SGsW2m"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xNZSZ5J6Sz9s7C for ; Fri, 4 Aug 2017 01:57:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751904AbdHCP5Q (ORCPT ); Thu, 3 Aug 2017 11:57:16 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:35554 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751925AbdHCPz4 (ORCPT ); Thu, 3 Aug 2017 11:55:56 -0400 Received: by mail-wm0-f47.google.com with SMTP id m85so19152311wma.0 for ; Thu, 03 Aug 2017 08:55:56 -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=Leh11Rl/gNzH8q97EW1rrPf9qjR920LnvSJiwsEI9Xc=; b=F3SGsW2mg6zzrIb1f2qd5LMQjBHVj9M8ttwVhEqDK4+JeVGGaVdJiRs00xO2tkeJDu JWpsvM9ZDQLsdmEZo1kYi/iYMgm4ArN+wcsriW1TZOnCTBYRKCKZSB10DMOYttsCDdGK +R9LzewLt3uTfkNYZKNKrD/cbKmyxSWG4svdY= 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=Leh11Rl/gNzH8q97EW1rrPf9qjR920LnvSJiwsEI9Xc=; b=qFJ2VBr4OpLwTLnzERDQN4pa8fmRtiNmxYdUQiJd9Hlzr9ZDxbgX9H8LkZi70fwZ46 NwGecXmqGUAyxYJAwmPFted+jScPVmbl/sOiM3MXsaUwpF+l0bqFbtSIhstDDunZ3SLN clSbEJZQ4fE2e0UobjAr8lIlqphh31HQ4ujdlzVEQRD2YYEUA+aELyLBo3Gf74gJ4vOC QdZiMqfN27Y88o0k5Oh34Ao1rKIv+omTe1cHOvpWMi64RWyQQuVZcDdworI9+ebzdKHm qKRNU1n5M7nafqczby7DpUY5D3+beHyMMlXNYBZwRCAc4oA4srheU38R06o/Clel4vjo S0eQ== X-Gm-Message-State: AIVw110QV6TMD7k27UUI8YlAJ1RdZNgFqKyaiXlRpqMOSA8xlSaEofeF C0D5fYOtHCdHNmSPZX4= X-Received: by 10.28.139.144 with SMTP id n138mr1505095wmd.14.1501775755321; Thu, 03 Aug 2017 08:55:55 -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.53 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 03 Aug 2017 08:55:54 -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 18/27] ip: iplink_xdp.c: add json output support Date: Thu, 3 Aug 2017 17:55:06 +0200 Message-Id: <20170803155515.99226-19-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 { "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", " "); }