xref: /linux/tools/testing/selftests/net/rtnetlink.py (revision 61f96e684edd28ca40555ec49ea1555df31ba619)
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0
3
4from lib.py import ksft_exit, ksft_run, ksft_ge, RtnlAddrFamily
5import socket
6
7IPV4_ALL_HOSTS_MULTICAST = b'\xe0\x00\x00\x01'
8
9def dump_mcaddr_check(rtnl: RtnlAddrFamily) -> None:
10    """
11    Verify that at least one interface has the IPv4 all-hosts multicast address.
12    At least the loopback interface should have this address.
13    """
14
15    addresses = rtnl.getmulticast({"ifa-family": socket.AF_INET}, dump=True)
16
17    all_host_multicasts = [
18        addr for addr in addresses if addr['multicast'] == IPV4_ALL_HOSTS_MULTICAST
19    ]
20
21    ksft_ge(len(all_host_multicasts), 1,
22            "No interface found with the IPv4 all-hosts multicast address")
23
24def main() -> None:
25    rtnl = RtnlAddrFamily()
26    ksft_run([dump_mcaddr_check], args=(rtnl, ))
27    ksft_exit()
28
29if __name__ == "__main__":
30    main()
31