lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 31 Jan 2023 17:53:22 +0800
From:   Hangbin Liu <liuhangbin@...il.com>
To:     Jamal Hadi Salim <jhs@...atatu.com>
Cc:     Stephen Hemminger <stephen@...workplumber.org>,
        netdev@...r.kernel.org, David Ahern <dsahern@...nel.org>
Subject: Re: [PATCH iproute2-next 2/2] tc: add new attr TCA_EXT_WARN_MSG

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ