Files
linux/tools/testing/selftests/net/rtnetlink.py
Yuyang Huang 4f280376e5 selftests/net: Add selftest for IPv4 RTM_GETMULTICAST support
This change introduces a new selftest case to verify the functionality
of dumping IPv4 multicast addresses using the RTM_GETMULTICAST netlink
message. The test utilizes the ynl library to interact with the
netlink interface and validate that the kernel correctly reports the
joined IPv4 multicast addresses.

To run the test, execute the following command:

$ vng -v --user root --cpus 16 -- \
    make -C tools/testing/selftests TARGETS=net \
    TEST_PROGS=rtnetlink.py TEST_GEN_PROGS="" run_tests

Cc: Maciej Żenczykowski <maze@google.com>
Cc: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
Link: https://patch.msgid.link/20250207110836.2407224-2-yuyanghuang@google.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2025-02-11 11:26:53 +01:00

31 lines
867 B
Python
Executable File

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
from lib.py import ksft_exit, ksft_run, ksft_ge, RtnlAddrFamily
import socket
IPV4_ALL_HOSTS_MULTICAST = b'\xe0\x00\x00\x01'
def dump_mcaddr_check(rtnl: RtnlAddrFamily) -> None:
"""
Verify that at least one interface has the IPv4 all-hosts multicast address.
At least the loopback interface should have this address.
"""
addresses = rtnl.getmaddrs({"ifa-family": socket.AF_INET}, dump=True)
all_host_multicasts = [
addr for addr in addresses if addr['ifa-multicast'] == IPV4_ALL_HOSTS_MULTICAST
]
ksft_ge(len(all_host_multicasts), 1,
"No interface found with the IPv4 all-hosts multicast address")
def main() -> None:
rtnl = RtnlAddrFamily()
ksft_run([dump_mcaddr_check], args=(rtnl, ))
ksft_exit()
if __name__ == "__main__":
main()