]> git.ipfire.org Git - thirdparty/iproute2.git/commit
ip-route: fix json formatting for metrics
authorAndrea Claudi <aclaudi@redhat.com>
Mon, 8 Jul 2019 09:36:42 +0000 (11:36 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 10 Jul 2019 00:30:06 +0000 (17:30 -0700)
commit89ce8012d71f5689074dc4cbe3db102cbdf76460
treefb5cf748b9536d831127a24d3000410eeffb3f99
parentaf2583437ea03f7d74815bee7c1c7b03baaf4894
ip-route: fix json formatting for metrics

Setting metrics for routes currently lead to non-parsable
json output. For example:

$ ip link add type dummy
$ ip route add 192.168.2.0 dev dummy0 metric 100 mtu 1000 rto_min 3
$ ip -j route | jq
parse error: ':' not as part of an object at line 1, column 319

Fixing this opening a json object in the metrics array and using
print_string() instead of fprintf().

This is the output for the above commands applying this patch:

$ ip -j route | jq
[
  {
    "dst": "192.168.2.0",
    "dev": "dummy0",
    "scope": "link",
    "metric": 100,
    "flags": [],
    "metrics": [
      {
        "mtu": 1000,
        "rto_min": 3
      }
    ]
  }
]

Fixes: 663c3cb23103f ("iproute: implement JSON and color output")
Fixes: 968272e791710 ("iproute: refactor metrics print")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Reported-by: Frank Hofmann <fhofmann@cloudflare.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/iproute.c