From 223b23e2c428aff6c1e61f49d8e2edde77801a12 Mon Sep 17 00:00:00 2001 From: James Falcon Date: Wed, 26 Jan 2022 19:40:06 -0600 Subject: Add json parsing of ip addr show (SC-723) (#1210) When obtaining information from "ip addr", default to using "ip --json addr" rather than using regex to parse "ip addr show" as json is machine readable as less prone to error. Deprecate but leave fallback to use "ip addr" for older iproute2 tooling which does not support --json param. Fix regex parsing of "ip addr" to support peer addresses and metrics. --- tests/data/netinfo/sample-ipaddrshow-json-down | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/data/netinfo/sample-ipaddrshow-json-down (limited to 'tests/data/netinfo/sample-ipaddrshow-json-down') diff --git a/tests/data/netinfo/sample-ipaddrshow-json-down b/tests/data/netinfo/sample-ipaddrshow-json-down new file mode 100644 index 00000000..7ad5dde0 --- /dev/null +++ b/tests/data/netinfo/sample-ipaddrshow-json-down @@ -0,0 +1,57 @@ +[ + { + "ifindex": 1, + "ifname": "lo", + "flags": [ + "LOOPBACK", + "UP", + "LOWER_UP" + ], + "mtu": 65536, + "qdisc": "noqueue", + "operstate": "UNKNOWN", + "group": "default", + "txqlen": 1000, + "link_type": "loopback", + "address": "00:00:00:00:00:00", + "broadcast": "00:00:00:00:00:00", + "addr_info": [ + { + "family": "inet", + "local": "127.0.0.1", + "prefixlen": 8, + "scope": "host", + "label": "lo", + "valid_life_time": 4294967295, + "preferred_life_time": 4294967295 + }, + { + "family": "inet6", + "local": "::1", + "prefixlen": 128, + "scope": "host", + "valid_life_time": 4294967295, + "preferred_life_time": 4294967295 + } + ] + }, + { + "ifindex": 23, + "link_index": 24, + "ifname": "eth0", + "flags": [ + "BROADCAST", + "MULTICAST" + ], + "mtu": 1500, + "qdisc": "noqueue", + "operstate": "DOWN", + "group": "default", + "txqlen": 1000, + "link_type": "ether", + "address": "00:16:3e:de:51:a6", + "broadcast": "ff:ff:ff:ff:ff:ff", + "link_netnsid": 0, + "addr_info": [] + } +] -- cgit v1.2.3