rtnetlink.py 866 B

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