netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Andrea Claudi <aclaudi@redhat.com>
Cc: netdev@vger.kernel.org, dsahern@kernel.org
Subject: Re: [PATCH iproute2-next] ip tunnel: add json output
Date: Thu, 1 Aug 2019 08:16:20 -0700	[thread overview]
Message-ID: <20190801081620.6b25d23c@hermes.lan> (raw)
In-Reply-To: <7090709d3ddace589952a128fb62f6603e2da9e8.1564653511.git.aclaudi@redhat.com>

On Thu,  1 Aug 2019 12:12:58 +0200
Andrea Claudi <aclaudi@redhat.com> wrote:

> Add json support on iptunnel and ip6tunnel.
> The plain text output format should remain the same.
> 
> Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
> ---
>  ip/ip6tunnel.c | 82 +++++++++++++++++++++++++++++++--------------
>  ip/iptunnel.c  | 90 +++++++++++++++++++++++++++++++++-----------------
>  ip/tunnel.c    | 42 +++++++++++++++++------
>  3 files changed, 148 insertions(+), 66 deletions(-)
> 
> diff --git a/ip/ip6tunnel.c b/ip/ip6tunnel.c
> index d7684a673fdc4..f2b9710c1320f 100644
> --- a/ip/ip6tunnel.c
> +++ b/ip/ip6tunnel.c
> @@ -71,57 +71,90 @@ static void usage(void)
>  static void print_tunnel(const void *t)
>  {
>  	const struct ip6_tnl_parm2 *p = t;
> -	char s1[1024];
> -	char s2[1024];
> +	SPRINT_BUF(b1);
>  
>  	/* Do not use format_host() for local addr,
>  	 * symbolic name will not be useful.
>  	 */
> -	printf("%s: %s/ipv6 remote %s local %s",
> -	       p->name,
> -	       tnl_strproto(p->proto),
> -	       format_host_r(AF_INET6, 16, &p->raddr, s1, sizeof(s1)),
> -	       rt_addr_n2a_r(AF_INET6, 16, &p->laddr, s2, sizeof(s2)));
> +	open_json_object(NULL);
> +	print_string(PRINT_ANY, "ifname", "%s: ", p->name);

Print this using color for interface name?


> +	snprintf(b1, sizeof(b1), "%s/ipv6", tnl_strproto(p->proto));
> +	print_string(PRINT_ANY, "mode", "%s ", b1);
> +	print_string(PRINT_ANY,
> +		     "remote",
> +		     "remote %s ",
> +		     format_host_r(AF_INET6, 16, &p->raddr, b1, sizeof(b1)));
> +	print_string(PRINT_ANY,
> +		     "local",
> +		     "local %s",
> +		     rt_addr_n2a_r(AF_INET6, 16, &p->laddr, b1, sizeof(b1)));
> +
>  	if (p->link) {
>  		const char *n = ll_index_to_name(p->link);
>  
>  		if (n)
> -			printf(" dev %s", n);
> +			print_string(PRINT_ANY, "link", " dev %s", n);
>  	}
>  
>  	if (p->flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
> -		printf(" encaplimit none");
> +		print_bool(PRINT_ANY,
> +			   "ip6_tnl_f_ign_encap_limit",
> +			   " encaplimit none",
> +			   true);

For flags like this, print_null is more typical JSON than a boolean
value. Null is better for presence flag. Bool is better if both true and
false are printed.

  reply	other threads:[~2019-08-01 15:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-01 10:12 [PATCH iproute2-next] ip tunnel: add json output Andrea Claudi
2019-08-01 15:16 ` Stephen Hemminger [this message]
2019-08-02 11:14   ` Andrea Claudi
2019-08-02 15:49     ` Stephen Hemminger
2019-08-02 17:30       ` Andrea Claudi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190801081620.6b25d23c@hermes.lan \
    --to=stephen@networkplumber.org \
    --cc=aclaudi@redhat.com \
    --cc=dsahern@kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).