From: Stephen Hemminger <stephen@networkplumber.org>
To: Julien Fortin <julien@cumulusnetworks.com>
Cc: netdev@vger.kernel.org, roopa@cumulusnetworks.com,
nikolay@cumulusnetworks.com, dsa@cumulusnetworks.com
Subject: Re: [PATCH 05/27] ip: ipaddress.c: add support for json output
Date: Mon, 7 Aug 2017 09:12:58 -0700 [thread overview]
Message-ID: <20170807091258.7c70ff87@xeon-e3> (raw)
In-Reply-To: <20170803155515.99226-6-julien@cumulusnetworks.com>
On Thu, 3 Aug 2017 17:54:53 +0200
Julien Fortin <julien@cumulusnetworks.com> wrote:
> From: Julien Fortin <julien@cumulusnetworks.com>
>
> This patch converts all output (mostly fprintfs) to the new ip_print api
> which handle both regular and json output.
> Initialize a json_writer and open an array object if -json was specified.
> Note that the JSON attribute naming follows the NETLINK_ATTRIBUTE naming.
>
> In many places throughout the code, IP, matches integer values with
> hardcoded strings tables, such as link mode, link operstate or link
> family.
> In JSON context, this will result in a named string field. In the
> very unlikely event that the requested index is out of bound, IP
> displays the raw integer value. For JSON context this result in
> having a different integer field example bellow:
>
> if (mode >= ARRAY_SIZE(link_modes))
> print_int(PRINT_ANY, "linkmode_index", "mode %d ", mode);
> else
> print_string(PRINT_ANY, "linkmode", "mode %s ",
> link_modes[mode]);
>
> The "_index" suffix is open to discussion and it is something that I came
> up with. The bottom line is that you can't have a string field that may
> become an int field in specific cases. Programs written in strongly type
> languages (like C) might break if they are expecting a string value and
> got an integer instead. We don't want to confuse anybody or make the code
> even more complicated handling these specifics cases.
> Hence the extra "_index" field that is easy to check for and deal with.
>
This patch does not apply to current master branch.
Please rebase.
next prev parent reply other threads:[~2017-08-07 16:13 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-03 15:54 [PATCH 00/27] ip: add -json support to 'ip link show' Julien Fortin
2017-08-03 15:54 ` [PATCH 01/27] color: add new COLOR_NONE and disable_color function Julien Fortin
2017-08-03 15:54 ` [PATCH 02/27] ip: add new command line argument -json (mutually exclusive with -color) Julien Fortin
2017-08-03 16:17 ` Stephen Hemminger
2017-08-03 15:54 ` [PATCH 03/27] json_writer: add new json handlers (null, float with format, lluint, hu) Julien Fortin
2017-08-03 15:54 ` [PATCH 04/27] ip: ip_print: add new API to print JSON or regular format output Julien Fortin
2017-08-03 15:54 ` [PATCH 05/27] ip: ipaddress.c: add support for json output Julien Fortin
2017-08-07 16:12 ` Stephen Hemminger [this message]
2017-08-03 15:54 ` [PATCH 06/27] ip: iplink.c: open/close json object for ip -brief -json link show dev DEV Julien Fortin
2017-08-03 15:54 ` [PATCH 07/27] ip: iplink_bond.c: add json output support Julien Fortin
2017-08-03 15:54 ` [PATCH 08/27] ip: iplink_bond_slave.c: add json output support (info_slave_data) Julien Fortin
2017-08-03 15:54 ` [PATCH 09/27] ip: iplink_hsr.c: add json output support Julien Fortin
2017-08-03 15:54 ` [PATCH 10/27] ip: iplink_bridge.c: " Julien Fortin
2017-08-03 15:54 ` [PATCH 11/27] ip: iplink_bridge_slave.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 12/27] ip: iplink_can.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 13/27] ip: iplink_geneve.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 14/27] ip: iplink_ipoib.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 15/27] ip: iplink_ipvlan.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 16/27] ip: iplink_vrf.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 17/27] ip: iplink_vxlan.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 18/27] ip: iplink_xdp.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 19/27] ip: ipmacsec.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 20/27] ip: link_gre.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 21/27] ip: link_gre6.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 22/27] ip: link_ip6tnl.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 23/27] ip: link_iptnl.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 24/27] ip: link_vti.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 25/27] ip: link_vti6.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 26/27] ip: link_macvlan.c: " Julien Fortin
2017-08-03 15:55 ` [PATCH 27/27] ip: iplink_vlan.c: " Julien Fortin
2017-08-03 17:08 ` [PATCH 00/27] ip: add -json support to 'ip link show' Oliver Hartkopp
2017-08-03 19:05 ` Julien Fortin
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=20170807091258.7c70ff87@xeon-e3 \
--to=stephen@networkplumber.org \
--cc=dsa@cumulusnetworks.com \
--cc=julien@cumulusnetworks.com \
--cc=netdev@vger.kernel.org \
--cc=nikolay@cumulusnetworks.com \
--cc=roopa@cumulusnetworks.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.