From: Hangbin Liu <liuhangbin@gmail.com>
To: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>,
netdev@vger.kernel.org, David Ahern <dsahern@kernel.org>
Subject: Re: [PATCH iproute2-next 2/2] tc: add new attr TCA_EXT_WARN_MSG
Date: Tue, 31 Jan 2023 17:53:22 +0800 [thread overview]
Message-ID: <Y9jlElu4Hb1ktoZi@Laptop-X1> (raw)
In-Reply-To: <CAM0EoMkOquxiQH23gKwehf_MGL4j2GbGDdZxW-cc8bpC6Jrpqw@mail.gmail.com>
On Tue, Jan 17, 2023 at 10:09:41AM -0500, Jamal Hadi Salim wrote:
> > Ok, but use lower case for JSON tag following existing conventions.
> >
> > Note: json support in monitor mode is incomplete for many of the
> > commands bridge, ip, tc, devlink. It doesn't always generate valid JSON
> > yet.
>
> We can work for starters with the tc one and maybe cover ip as well...
I tried adding the JSON obj for ip monitor. There are 2 choices and some
issues.
If we open JSON before/after accept_msg:
diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
index 9b055264..a6944636 100644
--- a/ip/ipmonitor.c
+++ b/ip/ipmonitor.c
@@ -338,8 +338,13 @@ int do_ipmonitor(int argc, char **argv)
netns_nsid_socket_init();
netns_map_init();
- if (rtnl_listen(&rth, accept_msg, stdout) < 0)
+ new_json_obj(json);
+ if (rtnl_listen(&rth, accept_msg, stdout) < 0) {
+ delete_json_obj();
exit(2);
+ }
+
+ delete_json_obj();
return 0;
}
The JSON output looks like the following result, the ifindex is not quoted in
the braces. And the JSON format is not complete at the end.
# ip/ip -j -p monitor
[ {
"family": "inet",
"interface": "veth0",
"forwarding": false,
"rp_filter": "strict",
"mc_forwarding": false,
"proxy_neigh": false,
"ignore_routes_with_linkdown": false
},{
"family": "inet6",
"interface": "veth0",
"forwarding": false,
"mc_forwarding": false,
"proxy_neigh": false,
"ignore_routes_with_linkdown": false
},
"ifindex": 17,
"link": null,
"ifname": "veth0",
"flags": [ "BROADCAST","MULTICAST" ],
"mtu": 1500,
"qdisc": "noop",
"operstate": "DOWN",
"group": "default",
"link_type": "ether",
"address": "72:4f:8c:32:13:63",
"broadcast": "ff:ff:ff:ff:ff:ff",{
"family": "inet",
"interface": "veth1",
"forwarding": false,
"rp_filter": "strict",
"mc_forwarding": false,
"proxy_neigh": false,
"ignore_routes_with_linkdown": false
},{
"family": "inet6",
"interface": "veth1",
"forwarding": false,
"mc_forwarding": false,
"proxy_neigh": false,
"ignore_routes_with_linkdown": false
},
"ifindex": 18,
"link": "veth0",
"ifname": "veth1",
"flags": [ "BROADCAST","MULTICAST","M-DOWN" ],
"mtu": 1500,
"qdisc": "noop",
"operstate": "DOWN",
"group": "default",
"link_type": "ether",
"address": "42:75:b7:38:9c:ad",
"broadcast": "ff:ff:ff:ff:ff:ff",{
"dst": "fe80::ee3e:f701:b990:8a61",
"dev": "eth0",
"lladdr": "ec:3e:f7:90:8a:61",
"router": null,
"state": [ "STALE" ]
}^C
If we open JSON in the accept_msg(). Like:
diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
index 9b055264..4af18a6c 100644
--- a/ip/ipmonitor.c
+++ b/ip/ipmonitor.c
@@ -55,6 +55,7 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
{
FILE *fp = (FILE *)arg;
+ new_json_obj(json);
switch (n->nlmsg_type) {
case RTM_NEWROUTE:
case RTM_DELROUTE: {
@@ -63,21 +64,21 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
if (len < 0) {
fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
- return -1;
+ goto err_out;
}
if (r->rtm_flags & RTM_F_CLONED)
- return 0;
+ goto out;
[...]
@@ -170,7 +171,14 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
n->nlmsg_flags, n->nlmsg_flags, n->nlmsg_len,
n->nlmsg_len);
}
+
+out:
+ delete_json_obj();
return 0;
+
+err_out:
+ delete_json_obj();
+ return -1;
}
The result would like:
# ./ip/ip -j monitor
[{"deleted":true,"family":"inet","interface":"veth0"}]
[{"deleted":true,"family":"inet6","interface":"veth0"}]
[{"deleted":true,"family":"inet","interface":"veth1"}]
[{"deleted":true,"family":"inet6","interface":"veth1"}]
This format looks good, but I'm not sure if the JSON output is valid with
list for each line.
Any comments?
Thanks
Hangbin
next prev parent reply other threads:[~2023-01-31 9:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 3:43 [PATCHv4 net-next] sched: add new attr TCA_EXT_WARN_MSG to report tc extact message Hangbin Liu
2023-01-13 3:46 ` [PATCH iproute2-next 1/2] Revert "tc/tc_monitor: print netlink extack message" Hangbin Liu
2023-01-13 3:46 ` [PATCH iproute2-next 2/2] tc: add new attr TCA_EXT_WARN_MSG Hangbin Liu
2023-01-13 4:00 ` Hangbin Liu
2023-01-13 4:30 ` Stephen Hemminger
2023-01-13 6:20 ` Hangbin Liu
2023-01-14 12:59 ` Jamal Hadi Salim
2023-01-14 17:03 ` Stephen Hemminger
2023-01-17 15:09 ` Jamal Hadi Salim
2023-01-31 9:53 ` Hangbin Liu [this message]
2023-01-14 2:15 ` David Ahern
2023-01-14 6:15 ` [PATCHv4 net-next] sched: add new attr TCA_EXT_WARN_MSG to report tc extact message Jakub Kicinski
2023-01-14 12:19 ` Jamal Hadi Salim
2023-01-17 7:19 ` [PATCHv2 iproute2-next 0/2] tc: add new attr TCA_EXT_WARN_MSG Hangbin Liu
2023-01-17 7:19 ` [PATCHv2 iproute2-next 1/2] Revert "tc/tc_monitor: print netlink extack message" Hangbin Liu
2023-01-17 7:19 ` [PATCHv2 iproute2-next 2/2] tc: add new attr TCA_EXT_WARN_MSG Hangbin Liu
2023-01-22 18:10 ` [PATCHv2 iproute2-next 0/2] " patchwork-bot+netdevbpf
2023-01-17 8:50 ` [PATCHv4 net-next] sched: add new attr TCA_EXT_WARN_MSG to report tc extact message patchwork-bot+netdevbpf
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=Y9jlElu4Hb1ktoZi@Laptop-X1 \
--to=liuhangbin@gmail.com \
--cc=dsahern@kernel.org \
--cc=jhs@mojatatu.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.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