]> git.proxmox.com Git - mirror_iproute2.git/commit
ip route: get: print JSON output when -j is given
authorMatteo Croce <mcroce@redhat.com>
Mon, 18 Mar 2019 17:19:30 +0000 (18:19 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 19 Mar 2019 16:50:01 +0000 (09:50 -0700)
commita0a639d9c002d957ce9d5547c806919cbffa3834
treed5666186211e3b7aa968eed6728df2331e229a9a
parent073661773872709518d35d4d093f3a715281f21d
ip route: get: print JSON output when -j is given

The ip -j option to print output as JSON is ignored when using 'route get':

    $ ip -j route get 127.0.0.1
    local 127.0.0.1 dev lo src 127.0.0.1 uid 1000
        cache <local>

Enable JSON output in iproute_get(), and don't let print_cache_flags() close
the JSON output, as it's not always the last called JSON function.

Tested on different route types:

    $ ip -j -p route get 127.0.0.1
    [ {
            "type": "local",
            "dst": "127.0.0.1",
            "dev": "lo",
            "prefsrc": "127.0.0.1",
            "flags": [ ],
            "uid": 1000,
            "cache": [ "local" ]
        } ]

    $ ip -d -j -p route get 192.0.2.1
    [ {
            "type": "unicast",
            "dst": "192.0.2.1",
            "gateway": "192.168.85.1",
            "dev": "wlp3s0",
            "table": "main",
            "prefsrc": "192.168.85.2",
            "flags": [ ],
            "uid": 1000,
            "cache": [ ]
        } ]

Fixes: 663c3cb23103 ("iproute: implement JSON and color output")
Acked-by: Phil Sutter <phil@nwl.cc>
Reviewed-and-tested-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Matteo Croce <mcroce@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/iproute.c