From: Stephen Hemminger <stephen@networkplumber.org>
To: Lars Ekman <uablrek@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: iproute2 bug in json output for encap
Date: Fri, 14 Apr 2023 10:01:01 -0700 [thread overview]
Message-ID: <20230414100101.16813970@hermes.local> (raw)
In-Reply-To: <65b59170-28c2-2e3b-f435-2bdcc6d7b10c@gmail.com>
On Fri, 14 Apr 2023 18:26:03 +0200
Lars Ekman <uablrek@gmail.com> wrote:
> Hi again,
>
> Digging a little deeper I see that the double "dst" items will cause
> problems with most (all?) json parsers. I intend to use "go" and json
> parsing will be parsed to a "map" (hash-table) so duplicate keys will
> not work.
>
> https://stackoverflow.com/questions/21832701/does-json-syntax-allow-duplicate-keys-in-an-object
>
> IMHO it would be better to use a structured "encap" item. Something like;
>
> [ {
> "dst": "192.168.11.0/24",
> "encap": {
> "protocol": "ip6",
> "id": 0,
> "src": "::",
> "dst": "fd00::c0a8:2dd",
> "hoplimit": 0,
> "tc": 0
> },
> "scope": "link",
> "flags": [ ]
> } ]
Something like this?
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index 52221c6976b3..37730024caaf 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -834,14 +834,15 @@ static void print_encap_xfrm(FILE *fp, struct rtattr *encap)
void lwt_print_encap(FILE *fp, struct rtattr *encap_type,
struct rtattr *encap)
{
- int et;
+ uint16_t et;
if (!encap_type)
return;
et = rta_getattr_u16(encap_type);
-
- print_string(PRINT_ANY, "encap", " encap %s ", format_encap_type(et));
+ open_json_object("encap");
+ print_string(PRINT_ANY, "encap_type", " encap %s ",
+ format_encap_type(et));
switch (et) {
case LWTUNNEL_ENCAP_MPLS:
@@ -875,6 +876,7 @@ void lwt_print_encap(FILE *fp, struct rtattr *encap_type,
print_encap_xfrm(fp, encap);
break;
}
+ close_json_object();
}
static struct ipv6_sr_hdr *parse_srh(char *segbuf, int hmac, bool encap)
prev parent reply other threads:[~2023-04-14 17:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-14 8:29 iproute2 bug in json output for encap Lars Ekman
2023-04-14 15:21 ` Stephen Hemminger
2023-04-14 16:12 ` Lars Ekman
2023-04-14 16:26 ` Lars Ekman
2023-04-14 16:44 ` Stephen Hemminger
2023-04-14 17:01 ` Stephen Hemminger [this message]
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=20230414100101.16813970@hermes.local \
--to=stephen@networkplumber.org \
--cc=netdev@vger.kernel.org \
--cc=uablrek@gmail.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.