From patchwork Thu Aug 3 15:55: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: 797288 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="ZHrRwv6I"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xNZSy53J1z9s7C for ; Fri, 4 Aug 2017 01:57:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751968AbdHCP5c (ORCPT ); Thu, 3 Aug 2017 11:57:32 -0400 Received: from mail-wr0-f181.google.com ([209.85.128.181]:37252 "EHLO mail-wr0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751923AbdHCPzt (ORCPT ); Thu, 3 Aug 2017 11:55:49 -0400 Received: by mail-wr0-f181.google.com with SMTP id 33so7385729wrz.4 for ; Thu, 03 Aug 2017 08:55:49 -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=4BETkJfp+mixr6N3Va08+8TDf5wAwp9V8PnSRfAoKS0=; b=ZHrRwv6IzMiXcWN881AMbFkakm6IarCZjdilDYqEXHHVTDyz8axeyzkXSJcQO0ajtX dVrIy3UtXD1EwU37ddlbvjZnOdWwFhkfhLQQqOX/7KIsaIjUDrT/PYQFoYXALJkPfu0H sbrRoyfuXZLLFGRTqHrLXHiA/EjwuOkEZI42Y= 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=4BETkJfp+mixr6N3Va08+8TDf5wAwp9V8PnSRfAoKS0=; b=ooTZzLAzrlhGmZ9Z8FrpMzAtLfCi69vj+Z4NW+BegB4/TG6MpF0FAgA33aJVBSYCCW uaWOfWz1porKZlqRMFMync3UznbR3zHAfAjV/11mp6Sy+8aIiFqMwjvMDvtsoixIilRj kTpGbAoHGrkiTyrwL1HD3Ia0ZR6UEY6R+Eqb2NVs9H0btIPkzNnocEYgQJcVzFp99H8C fSA0T8hj/AF6GwbzoIGiKY4nClfVM88/FfRf3Y11Mx2w5FLQTaprT2cOQb3FZFwfQMOG QeVdX+PJJzOrka2YQyOpKAl27kc+Jbpg73Kqiw9RGyuY/USj7oLo/s4lZMTxt4r9Ztjo Qqag== X-Gm-Message-State: AIVw113lCO0VovHxwejLiw0dmFnUO/shHrlP6mL4OFMpb1hJZa0eLuNJ 3ir2Ij2DMExM8HIx4sA= X-Received: by 10.223.166.68 with SMTP id k62mr1615162wrc.283.1501775748208; Thu, 03 Aug 2017 08:55:48 -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.47 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 03 Aug 2017 08:55:47 -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 13/27] ip: iplink_geneve.c: add json output support Date: Thu, 3 Aug 2017 17:55:01 +0200 Message-Id: <20170803155515.99226-14-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: { "id": { "type": "uint", "attr": "IFLA_GENEVE_ID" }, "remote": { "type": "string", "attr": "IFLA_GENEVE_REMOTE" }, "remote6": { "type": "string", "attr": "IFLA_GENEVE_REMOTE6" }, "ttl": { "type": "int", "attr": "IFLA_GENEVE_TTL" }, "tos": { "type": "string", "attr": "IFLA_GENEVE_TOS" }, "label": { "type": "string", "attr": "IFLA_GENEVE_LABEL" }, "port": { "type": "uint", "attr": "IFLA_GENEVE_PORT" }, "collect_metadata": { "type": "bool", "attr": "IFLA_GENEVE_COLLECT_METADATA" }, "udp_csum": { "type": "bool", "attr": "IFLA_GENEVE_UDP_CSUM" }, "udp_zero_csum6_tx": { "type": "bool", "attr": "IFLA_GENEVE_UDP_ZERO_CSUM6_TX" }, "udp_zero_csum6_rx": { "type": "bool", "attr": "IFLA_GENEVE_UDP_ZERO_CSUM6_RX" } } Signed-off-by: Julien Fortin --- ip/iplink_geneve.c | 86 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 23 deletions(-) diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c index 594a3e59..f0f1d1c7 100644 --- a/ip/iplink_geneve.c +++ b/ip/iplink_geneve.c @@ -237,22 +237,28 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) return; vni = rta_getattr_u32(tb[IFLA_GENEVE_ID]); - fprintf(f, "id %u ", vni); + print_uint(PRINT_ANY, "id", "id %u ", vni); if (tb[IFLA_GENEVE_REMOTE]) { __be32 addr = rta_getattr_u32(tb[IFLA_GENEVE_REMOTE]); if (addr) - fprintf(f, "remote %s ", - format_host(AF_INET, 4, &addr)); + print_string(PRINT_ANY, + "remote", + "remote %s ", + format_host(AF_INET, 4, &addr)); } else if (tb[IFLA_GENEVE_REMOTE6]) { struct in6_addr addr; memcpy(&addr, RTA_DATA(tb[IFLA_GENEVE_REMOTE6]), sizeof(struct in6_addr)); if (!IN6_IS_ADDR_UNSPECIFIED(&addr)) { if (!IN6_IS_ADDR_MULTICAST(&addr)) - fprintf(f, "remote %s ", - format_host(AF_INET6, sizeof(struct in6_addr), &addr)); + print_string(PRINT_ANY, + "remote6", + "remote %s ", + format_host(AF_INET6, + sizeof(struct in6_addr), + &addr)); } } @@ -260,47 +266,81 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) __u8 ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]); if (ttl) - fprintf(f, "ttl %d ", ttl); + print_int(PRINT_ANY, "ttl", "ttl %d ", ttl); } if (tb[IFLA_GENEVE_TOS] && (tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]))) { - if (tos == 1) - fprintf(f, "tos inherit "); - else - fprintf(f, "tos %#x ", tos); + if (is_json_context()) { + print_0xhex(PRINT_JSON, "tos", "%#x", tos); + } else { + if (tos == 1) { + print_string(PRINT_FP, + "tos", + "tos %s ", + "inherit"); + } else { + fprintf(f, "tos %#x ", tos); + } + } } if (tb[IFLA_GENEVE_LABEL]) { __u32 label = rta_getattr_u32(tb[IFLA_GENEVE_LABEL]); if (label) - fprintf(f, "flowlabel %#x ", ntohl(label)); + print_0xhex(PRINT_ANY, + "label", + "flowlabel %#x ", + ntohl(label)); } if (tb[IFLA_GENEVE_PORT]) - fprintf(f, "dstport %u ", - rta_getattr_be16(tb[IFLA_GENEVE_PORT])); + print_uint(PRINT_ANY, + "port", + "dstport %u ", + rta_getattr_be16(tb[IFLA_GENEVE_PORT])); if (tb[IFLA_GENEVE_COLLECT_METADATA]) - fputs("external ", f); + print_bool(PRINT_ANY, "collect_metadata", "external ", true); if (tb[IFLA_GENEVE_UDP_CSUM]) { - if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_CSUM])) - fputs("no", f); - fputs("udpcsum ", f); + if (is_json_context()) { + print_bool(PRINT_JSON, + "udp_csum", + NULL, + rta_getattr_u8(tb[IFLA_GENEVE_UDP_CSUM])); + } else { + if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_CSUM])) + fputs("no", f); + fputs("udpcsum ", f); + } } if (tb[IFLA_GENEVE_UDP_ZERO_CSUM6_TX]) { - if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_TX])) - fputs("no", f); - fputs("udp6zerocsumtx ", f); + if (is_json_context()) { + print_bool(PRINT_JSON, + "udp_zero_csum6_tx", + NULL, + rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_TX])); + } else { + if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_TX])) + fputs("no", f); + fputs("udp6zerocsumtx ", f); + } } if (tb[IFLA_GENEVE_UDP_ZERO_CSUM6_RX]) { - if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_RX])) - fputs("no", f); - fputs("udp6zerocsumrx ", f); + if (is_json_context()) { + print_bool(PRINT_JSON, + "udp_zero_csum6_rx", + NULL, + rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_RX])); + } else { + if (!rta_getattr_u8(tb[IFLA_GENEVE_UDP_ZERO_CSUM6_RX])) + fputs("no", f); + fputs("udp6zerocsumrx ", f); + } } }