system: Determine if link is a bridge from sysfs
Determining whether link is a bridge via libnl seems to be tricky.
There are functions like rtnl_link_get_family(rtnl_link*)[1] or (even
better) rtnl_link_is_bridge(rtnl_link*)[2] but both of them seem to fail
in certain situations[3]. I have encountered this while adding/removing
interfaces to/from a bridge.
When the interface is added/removed to/from the bridge the kernel (see
/net/bridge/br_netlink.c) sends RTM_NEWLINK or RTM_DELLINK messages
for the interface being added/removed. This is kind of confusing for
libnl, because it can't differentiate whether the link was just updated
or really added/removed [3,4] (in reality only information about
changing the bridge vlan is sent) and it triggers NL_ACT_NEW/NL_ACT_DEL
event for the interface (if nl cache manager is used). The nl cache
manager considers the message to be an added/removed interface. And then
is then flagged by rtnl_link_is_bridge as a bridge and this is wrong.
That is why velia reports the interface as bridge even when it is not.
So, let's replace this method of determining if link is a bridge.
It seems that checking for the existence of
/sys/class/net/<name>/bridge directory works everytime.
A test is also added. Please note that receiving a libnl notification
about a change in the bridge state might take some time, hence the
longer waits.
[1] https://www.infradead.org/~tgr/libnl/doc/api/group__link.html
[2] https://www.infradead.org/~tgr/libnl/doc/api/group__bridge.html
[3] https://github.com/thom311/libnl/issues/209
[4] https://github.com/thom311/libnl/issues/74
Fixes: 019748fbfe1dfd5d05efbd7204be99122cf54e34
Bug: https://github.com/thom311/libnl/issues/209
Change-Id: I90e2dcb099c4df4daac7cea3b141a1a152a4de47
diff --git a/tests/sysrepo_system-ietfinterfaces-sudo.sh b/tests/sysrepo_system-ietfinterfaces-sudo.sh
index 1f17e14..5e29522 100755
--- a/tests/sysrepo_system-ietfinterfaces-sudo.sh
+++ b/tests/sysrepo_system-ietfinterfaces-sudo.sh
@@ -2,3 +2,4 @@
# $1 should be sudo executable
"$1" ip link del czechlight0 type dummy || true
+"$1" ip link del czechlight_br0 type dummy || true