Skip to content

Commit e84a17d

Browse files
committed
tests/netlink: Assert the route scope of interface's addresses
While here, add one additional IPv4 link-local address to test_46_nofilter to cover the IPv4 RT_SCOPE_LINK case. Reviewed by: melifaro, #network MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D49226 (cherry picked from commit 5d8b484)
1 parent e7d1f20 commit e84a17d

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tests/sys/netlink/test_rtnl_ifaddr.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ class TestRtNlIfaddrList(NetlinkTestTemplate, SingleVnetTestTemplate):
3333
def setup_method(self, method):
3434
method_name = method.__name__
3535
if "4" in method_name:
36-
self.IPV4_PREFIXES = ["192.0.2.1/24"]
36+
if "nofilter" in method_name:
37+
self.IPV4_PREFIXES = ["192.0.2.1/24", "169.254.169.254/16"]
38+
else:
39+
self.IPV4_PREFIXES = ["192.0.2.1/24"]
3740
if "6" in method_name:
3841
self.IPV6_PREFIXES = ["2001:db8::1/64"]
3942
super().setup_method(method)
@@ -49,14 +52,21 @@ def test_46_nofilter(self):
4952
for rx_msg in self.read_msg_list(msg.nl_hdr.nlmsg_seq, NlRtMsgType.RTM_NEWADDR):
5053
ifname = socket.if_indextoname(rx_msg.base_hdr.ifa_index)
5154
family = rx_msg.base_hdr.ifa_family
52-
ret.append((ifname, family, rx_msg))
55+
scope = rx_msg.base_hdr.ifa_scope
56+
ret.append((ifname, family, scope))
5357

5458
ifname = "lo0"
55-
assert len([r for r in ret if r[0] == ifname]) > 0
59+
assert len([r for r in ret if r[0] == ifname and r[1] == socket.AF_INET and r[2] == RtScope.RT_SCOPE_HOST.value]) == 1
60+
assert len([r for r in ret if r[0] == ifname and r[1] == socket.AF_INET6 and r[2] == RtScope.RT_SCOPE_HOST.value]) == 1
61+
assert len([r for r in ret if r[0] == ifname and r[1] == socket.AF_INET6 and r[2] == RtScope.RT_SCOPE_LINK.value]) == 1
62+
assert len([r for r in ret if r[0] == ifname]) == 3
5663

5764
ifname = self.vnet.iface_alias_map["if1"].name
58-
assert len([r for r in ret if r[0] == ifname and r[1] == socket.AF_INET]) == 1
59-
assert len([r for r in ret if r[0] == ifname and r[1] == socket.AF_INET6]) == 2
65+
assert len([r for r in ret if r[0] == ifname and r[1] == socket.AF_INET and r[2] == RtScope.RT_SCOPE_LINK.value]) == 1
66+
assert len([r for r in ret if r[0] == ifname and r[1] == socket.AF_INET and r[2] == RtScope.RT_SCOPE_UNIVERSE.value]) == 1
67+
assert len([r for r in ret if r[0] == ifname and r[1] == socket.AF_INET6 and r[2] == RtScope.RT_SCOPE_LINK.value]) == 1
68+
assert len([r for r in ret if r[0] == ifname and r[1] == socket.AF_INET6 and r[2] == RtScope.RT_SCOPE_UNIVERSE.value]) == 1
69+
assert len([r for r in ret if r[0] == ifname]) == 4
6070

6171
def test_46_filter_iface(self):
6272
"""Tests that listing outputs both IPv4/IPv6 for the specific interface"""

0 commit comments

Comments
 (0)