From 707e7d1a297977382e7e1d77dd66272e179a3bf5 Mon Sep 17 00:00:00 2001 From: Richard Alpe Date: Tue, 1 Oct 2024 14:17:32 +0200 Subject: [PATCH] yanger: skip internal interfaces In "14128047e18d statd: remove nl code and improve speed" the handling of all interfaces where moved from statd to Yanger. This means statd no longer tracks interfaces using Netlink, but instead relies on Yanger to recognise and list all interfaces in the system. In the midst of this change the ignoring of "internal" interfaces where lost. In this commit we reintroduce this logic in Yanger and add a test case that ensures internal interfaces isn't listed. Fixes: 14128047e18d statd: remove nl code and improve speed Signed-off-by: Richard Alpe --- src/statd/python/yanger/yanger.py | 4 ++ test/case/cli/system-output/ethtool-dsa0.txt | 32 +++++++++++ .../system-output/ethtool-groups-dsa0.json | 7 +++ test/case/cli/system-output/ip-addr-show.json | 52 ++++++++++++++++++ test/case/cli/system-output/ip-link-show.json | 53 +++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 test/case/cli/system-output/ethtool-dsa0.txt create mode 100644 test/case/cli/system-output/ethtool-groups-dsa0.json diff --git a/src/statd/python/yanger/yanger.py b/src/statd/python/yanger/yanger.py index cc7d1217..5b67d1cf 100755 --- a/src/statd/python/yanger/yanger.py +++ b/src/statd/python/yanger/yanger.py @@ -899,6 +899,10 @@ def _add_interface(ifname, ip_link_data, ip_addr_data, yang_ifaces): if not ip_link_data or not ip_addr_data: return + # Skip internal interfaces. + if 'group' in ip_link_data and ip_link_data['group'] == "internal": + return + yang_ifaces.append(get_iface_data(ifname, ip_link_data, ip_addr_data)) def add_interface(ifname, yang_ifaces): diff --git a/test/case/cli/system-output/ethtool-dsa0.txt b/test/case/cli/system-output/ethtool-dsa0.txt new file mode 100644 index 00000000..6fb392ba --- /dev/null +++ b/test/case/cli/system-output/ethtool-dsa0.txt @@ -0,0 +1,32 @@ +Settings for dsa0: + Supported ports: [ MII ] + Supported link modes: 10000baseT/Full + 10000baseKX4/Full + 10000baseKR/Full + 10000baseCR/Full + 10000baseSR/Full + 10000baseLR/Full + 10000baseLRM/Full + 10000baseER/Full + Supported pause frame use: Symmetric Receive-only + Supports auto-negotiation: Yes + Supported FEC modes: Not reported + Advertised link modes: 10000baseT/Full + 10000baseKX4/Full + 10000baseKR/Full + 10000baseCR/Full + 10000baseSR/Full + 10000baseLR/Full + 10000baseLRM/Full + 10000baseER/Full + Advertised pause frame use: Symmetric Receive-only + Advertised auto-negotiation: Yes + Advertised FEC modes: Not reported + Speed: 10000Mb/s + Duplex: Full + Auto-negotiation: on + Port: MII + PHYAD: 0 + Transceiver: internal +netlink error: Operation not permitted + Link detected: yes diff --git a/test/case/cli/system-output/ethtool-groups-dsa0.json b/test/case/cli/system-output/ethtool-groups-dsa0.json new file mode 100644 index 00000000..55cd2636 --- /dev/null +++ b/test/case/cli/system-output/ethtool-groups-dsa0.json @@ -0,0 +1,7 @@ +[ { + "ifname": "dsa0", + "eth-phy": {}, + "eth-mac": {}, + "eth-ctrl": {}, + "rmon": {} +} ] diff --git a/test/case/cli/system-output/ip-addr-show.json b/test/case/cli/system-output/ip-addr-show.json index 5ff305f0..04ad3de7 100644 --- a/test/case/cli/system-output/ip-addr-show.json +++ b/test/case/cli/system-output/ip-addr-show.json @@ -1,4 +1,56 @@ [ + { + "ifindex": 2, + "ifname": "dsa0", + "flags": [ + "BROADCAST", + "MULTICAST", + "UP", + "LOWER_UP" + ], + "mtu": 1504, + "qdisc": "mq", + "operstate": "UP", + "group": "internal", + "txqlen": 2048, + "link_type": "ether", + "address": "02:00:de:ad:02:20", + "broadcast": "ff:ff:ff:ff:ff:ff", + "promiscuity": 0, + "allmulti": 0, + "min_mtu": 68, + "max_mtu": 9888, + "num_tx_queues": 8, + "num_rx_queues": 4, + "gso_max_size": 65536, + "gso_max_segs": 300, + "tso_max_size": 65536, + "tso_max_segs": 300, + "gro_max_size": 65536, + "gso_ipv4_max_size": 65536, + "gro_ipv4_max_size": 65536, + "parentbus": "platform", + "parentdev": "f2000000.ethernet", + "addr_info": [], + "stats64": { + "rx": { + "bytes": 1756811, + "packets": 6777, + "errors": 0, + "dropped": 0, + "over_errors": 0, + "multicast": 0 + }, + "tx": { + "bytes": 1849127, + "packets": 7157, + "errors": 0, + "dropped": 0, + "carrier_errors": 0, + "collisions": 0 + } + } + }, { "ifindex": 7, "ifname": "br0", diff --git a/test/case/cli/system-output/ip-link-show.json b/test/case/cli/system-output/ip-link-show.json index 7222f724..3d7b2dee 100644 --- a/test/case/cli/system-output/ip-link-show.json +++ b/test/case/cli/system-output/ip-link-show.json @@ -1,4 +1,57 @@ [ + { + "ifindex": 2, + "ifname": "dsa0", + "flags": [ + "BROADCAST", + "MULTICAST", + "UP", + "LOWER_UP" + ], + "mtu": 1504, + "qdisc": "mq", + "operstate": "UP", + "linkmode": "DEFAULT", + "group": "internal", + "txqlen": 2048, + "link_type": "ether", + "address": "02:00:de:ad:02:20", + "broadcast": "ff:ff:ff:ff:ff:ff", + "promiscuity": 0, + "allmulti": 0, + "min_mtu": 68, + "max_mtu": 9888, + "inet6_addr_gen_mode": "eui64", + "num_tx_queues": 8, + "num_rx_queues": 4, + "gso_max_size": 65536, + "gso_max_segs": 300, + "tso_max_size": 65536, + "tso_max_segs": 300, + "gro_max_size": 65536, + "gso_ipv4_max_size": 65536, + "gro_ipv4_max_size": 65536, + "parentbus": "platform", + "parentdev": "f2000000.ethernet", + "stats64": { + "rx": { + "bytes": 1751876, + "packets": 6757, + "errors": 0, + "dropped": 0, + "over_errors": 0, + "multicast": 0 + }, + "tx": { + "bytes": 1843945, + "packets": 7136, + "errors": 0, + "dropped": 0, + "carrier_errors": 0, + "collisions": 0 + } + } + }, { "ifindex": 7, "ifname": "br0",