]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: fdb get: add missing json init (new_json_obj)
authorJulien Fortin <julien@cumulusnetworks.com>
Fri, 10 Jul 2020 00:53:02 +0000 (02:53 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 13 Jul 2020 15:41:42 +0000 (08:41 -0700)
'bridge fdb get' has json support but the json object is never initialized

before patch:

$ bridge -j fdb get 56:23:28:4f:4f:e5 dev vx0
56:23:28:4f:4f:e5 dev vx0 master br0 permanent
$

after patch:

$ bridge -j fdb get 56:23:28:4f:4f:e5 dev vx0 | \
python -c \
'import sys,json;print(json.dumps(json.loads(sys.stdin.read()),indent=4))'
[
    {
        "master": "br0",
        "mac": "56:23:28:4f:4f:e5",
        "flags": [],
        "ifname": "vx0",
        "state": "permanent"
    }
]
$

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
bridge/fdb.c

index 710dfc99ee1d713e11bc33d42063a3db6631f1fd..a12b5474e86b2f0c1cfdc3ff57a749ca69723070 100644 (file)
@@ -619,10 +619,16 @@ static int fdb_get(int argc, char **argv)
        if (rtnl_talk(&rth, &req.n, &answer) < 0)
                return -2;
 
+       /*
+        * Initialize a json_writer and open an array object
+        * if -json was specified.
+        */
+       new_json_obj(json);
        if (print_fdb(answer, stdout) < 0) {
                fprintf(stderr, "An error :-)\n");
                return -1;
        }
+       delete_json_obj();
 
        return 0;
 }