From patchwork Thu Aug 17 17:36:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Julien Fortin X-Patchwork-Id: 802812 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="O/GTPZXi"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xYD7Y10zcz9t4Z for ; Fri, 18 Aug 2017 03:42:33 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753756AbdHQRma (ORCPT ); Thu, 17 Aug 2017 13:42:30 -0400 Received: from mail-wr0-f172.google.com ([209.85.128.172]:34455 "EHLO mail-wr0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753748AbdHQRm1 (ORCPT ); Thu, 17 Aug 2017 13:42:27 -0400 Received: by mail-wr0-f172.google.com with SMTP id y96so47261842wrc.1 for ; Thu, 17 Aug 2017 10:42:26 -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 :mime-version:content-transfer-encoding; bh=WUtoBTxtZdwb7dG2PLFeyfOzBZxnEXq8AcS1ekewUfs=; b=O/GTPZXi7ZEfh6Ar2BROe8+8EIg5DrZJIe5jsVKEJkNGSl5Gru4OpVopsaK0DKQd7g pkzrgwpbO+KIHVhARFAEczkNHgm2EMVMPzB6u00ajdQH3zlWpfgIBbyFYjA+/gk7zGBK o6ifvo7N0aIyMMuURXDRGepamOsOiwR3I4Dbg= 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:mime-version:content-transfer-encoding; bh=WUtoBTxtZdwb7dG2PLFeyfOzBZxnEXq8AcS1ekewUfs=; b=Gxo6vTCukyCW18wyF+T0nryfL5PmIG8DPTzn8YopXMibbKebPKRvurY3693wS5G722 XFgbvBnc4ff+BoKdpjkgAX6K+OUQl9aMEDiYuz3JnQ5eiBTmg4ha4kFF2QMt9mosrdZ3 TbE+bFSvmLY7kl+As6+MooqQUjC7WNNFMLYcuPwISlzuZ1LYHnvNBo/dzR+P/sXKTstS iG2llXnCbHhN55/YdqRjlfaeUUAu1DT9LvZzduD73Kh7+2kB7mtUS7XFtZydkXJ0omnP IjCcI76/mlPT4uso6Ilnmous2bhFnIhk7qqySoUMcAQiy6hHdqyIgAnioDRKMVgS6Kt/ maxA== X-Gm-Message-State: AHYfb5jdGhJxg1Y+loom4DyZkgDVuRRgjc93S3Qrm6a3D7lZr6hlC8h0 090ombcTBy6sKRlI+RO1oXg5 X-Received: by 10.223.144.162 with SMTP id i31mr4111121wri.3.1502991745599; Thu, 17 Aug 2017 10:42:25 -0700 (PDT) Received: from localhost.localdomain ([37.169.21.172]) by smtp.googlemail.com with ESMTPSA id k13sm3902040wrd.4.2017.08.17.10.42.21 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 17 Aug 2017 10:42:25 -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 25/27] ip: link_vti6.c: add json output support Date: Thu, 17 Aug 2017 10:36:12 -0700 Message-Id: <20170817173614.54987-26-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> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Julien Fortin Schema: { "remote": { "type": "string", "attr": "IFLA_VTI_REMOTE" }, "local": { "type": "string", "attr": "IFLA_VTI_LOCAL" }, "link": { "type": "string", "attr": "IFLA_VTI_LINK", "mutually_exclusive": { "link_index": { "type": "uint", } } }, "ikey": { "type": "string", "attr": "IFLA_VTI_IKEY" }, "okey": { "type": "string", "attr": "IFLA_VTI_OKEY" } } ➜ ~ ip -6 tunnel add name vti6 mode vti6 local 2001:db8:1::1/64 remote 2001:0db8:85a3:0000:0000:8a2e:0370:7334 ➜ ~ ip link show 10: ip6tnl0@NONE: mtu 1452 qdisc noop state DOWN mode DEFAULT group default link/tunnel6 :: brd :: 11: ip6_vti0@NONE: mtu 1500 qdisc noop state DOWN mode DEFAULT group default link/tunnel6 :: brd :: 12: vti6@NONE: mtu 1500 qdisc noop state DOWN mode DEFAULT group default link/tunnel6 2001:db8:1::1 peer 2001:db8:85a3::8a2e:370:7334 ➜ ~ ./ip -details -json link show [{ "ifindex": 10, "ifname": "ip6tnl0", "link": null, "flags": ["NOARP"], "mtu": 1452, "qdisc": "noop", "operstate": "DOWN", "linkmode": "DEFAULT", "group": "default", "link_type": "tunnel6", "address": "::", "broadcast": "::", "promiscuity": 0, "linkinfo": { "info_kind": "ip6tnl", "info_data": { "proto": "ip6ip6", "remote": "::", "local": "::", "encap_limit": 0, "ttl": 0, "flowinfo_tclass": "0x00", "flowlabel": "0x00000", "flowinfo": "0x00000000" } }, "inet6_addr_gen_mode": "eui64", "num_tx_queues": 1, "num_rx_queues": 1, "gso_max_size": 65536, "gso_max_segs": 65535 },{ "ifindex": 11, "ifname": "ip6_vti0", "link": null, "flags": ["NOARP"], "mtu": 1500, "qdisc": "noop", "operstate": "DOWN", "linkmode": "DEFAULT", "group": "default", "link_type": "tunnel6", "address": "::", "broadcast": "::", "promiscuity": 0, "linkinfo": { "info_kind": "vti6", "info_data": { "remote": "::", "local": "::", "ikey": "0.0.0.0", "okey": "0.0.0.0" } }, "inet6_addr_gen_mode": "eui64", "num_tx_queues": 1, "num_rx_queues": 1, "gso_max_size": 65536, "gso_max_segs": 65535 },{ "ifindex": 12, "ifname": "vti6", "link": null, "flags": ["POINTOPOINT","NOARP"], "mtu": 1500, "qdisc": "noop", "operstate": "DOWN", "linkmode": "DEFAULT", "group": "default", "link_type": "tunnel6", "address": "2001:db8:1::1", "link_pointtopoint": true, "broadcast": "2001:db8:85a3::8a2e:370:7334", "promiscuity": 0, "linkinfo": { "info_kind": "vti6", "info_data": { "remote": "2001:db8:85a3::8a2e:370:7334", "local": "2001:db8:1::1", "ikey": "0.0.0.0", "okey": "0.0.0.0" } }, "inet6_addr_gen_mode": "eui64", "num_tx_queues": 1, "num_rx_queues": 1, "gso_max_size": 65536, "gso_max_segs": 65535 } ] Signed-off-by: Julien Fortin --- ip/link_vti6.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ip/link_vti6.c b/ip/link_vti6.c index 6ea1fc23..8198d468 100644 --- a/ip/link_vti6.c +++ b/ip/link_vti6.c @@ -225,7 +225,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) remote = format_host(AF_INET6, 16, &daddr); } - fprintf(f, "remote %s ", remote); + print_string(PRINT_ANY, "remote", "remote %s ", remote); if (tb[IFLA_VTI_LOCAL]) { memcpy(&saddr, RTA_DATA(tb[IFLA_VTI_LOCAL]), sizeof(saddr)); @@ -233,29 +233,35 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) local = format_host(AF_INET6, 16, &saddr); } - fprintf(f, "local %s ", local); + print_string(PRINT_ANY, "local", "local %s ", local); if (tb[IFLA_VTI_LINK] && (link = rta_getattr_u32(tb[IFLA_VTI_LINK]))) { const char *n = if_indextoname(link, s2); if (n) - fprintf(f, "dev %s ", n); + print_string(PRINT_ANY, "link", "dev %s ", n); else - fprintf(f, "dev %u ", link); + print_uint(PRINT_ANY, "link_index", "dev %u ", link); } if (tb[IFLA_VTI_IKEY]) { inet_ntop(AF_INET, RTA_DATA(tb[IFLA_VTI_IKEY]), s2, sizeof(s2)); - fprintf(f, "ikey %s ", s2); + print_string(PRINT_ANY, "ikey", "ikey %s ", s2); } if (tb[IFLA_VTI_OKEY]) { inet_ntop(AF_INET, RTA_DATA(tb[IFLA_VTI_OKEY]), s2, sizeof(s2)); - fprintf(f, "okey %s ", s2); + print_string(PRINT_ANY, "okey", "okey %s ", s2); } - if (tb[IFLA_VTI_FWMARK] && rta_getattr_u32(tb[IFLA_VTI_FWMARK])) { - fprintf(f, "fwmark 0x%x ", rta_getattr_u32(tb[IFLA_VTI_FWMARK])); + if (tb[IFLA_VTI_FWMARK]) { + __u32 fwmark = rta_getattr_u32(tb[IFLA_VTI_FWMARK]); + + if (fwmark) { + snprintf(s2, sizeof(s2), "0x%x", fwmark); + + print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2); + } } }