mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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>
			
			
This commit is contained in:
		
							parent
							
								
									eb4e17a1d9
								
							
						
					
					
						commit
						4f280376e5
					
				
					 5 changed files with 59 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -168,6 +168,29 @@ operations:
 | 
			
		|||
        reply:
 | 
			
		||||
          value: 20
 | 
			
		||||
          attributes: *ifaddr-all
 | 
			
		||||
    -
 | 
			
		||||
      name: getmaddrs
 | 
			
		||||
      doc: Get / dump IPv4/IPv6 multicast addresses.
 | 
			
		||||
      attribute-set: addr-attrs
 | 
			
		||||
      fixed-header: ifaddrmsg
 | 
			
		||||
      do:
 | 
			
		||||
        request:
 | 
			
		||||
          value: 58
 | 
			
		||||
          attributes:
 | 
			
		||||
            - ifa-family
 | 
			
		||||
            - ifa-index
 | 
			
		||||
        reply:
 | 
			
		||||
          value: 58
 | 
			
		||||
          attributes: &mcaddr-attrs
 | 
			
		||||
            - ifa-multicast
 | 
			
		||||
            - ifa-cacheinfo
 | 
			
		||||
      dump:
 | 
			
		||||
        request:
 | 
			
		||||
          value: 58
 | 
			
		||||
            - ifa-family
 | 
			
		||||
        reply:
 | 
			
		||||
          value: 58
 | 
			
		||||
          attributes: *mcaddr-attrs
 | 
			
		||||
 | 
			
		||||
mcast-groups:
 | 
			
		||||
  list:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,6 +36,7 @@ TEST_PROGS += cmsg_so_priority.sh
 | 
			
		|||
TEST_PROGS += cmsg_time.sh cmsg_ipv6.sh
 | 
			
		||||
TEST_PROGS += netns-name.sh
 | 
			
		||||
TEST_PROGS += nl_netdev.py
 | 
			
		||||
TEST_PROGS += rtnetlink.py
 | 
			
		||||
TEST_PROGS += srv6_end_dt46_l3vpn_test.sh
 | 
			
		||||
TEST_PROGS += srv6_end_dt4_l3vpn_test.sh
 | 
			
		||||
TEST_PROGS += srv6_end_dt6_l3vpn_test.sh
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,5 +5,5 @@ from .ksft import *
 | 
			
		|||
from .netns import NetNS
 | 
			
		||||
from .nsim import *
 | 
			
		||||
from .utils import *
 | 
			
		||||
from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily
 | 
			
		||||
from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily
 | 
			
		||||
from .ynl import NetshaperFamily
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,6 +42,10 @@ class RtnlFamily(YnlFamily):
 | 
			
		|||
        super().__init__((SPEC_PATH / Path('rt_link.yaml')).as_posix(),
 | 
			
		||||
                         schema='', recv_size=recv_size)
 | 
			
		||||
 | 
			
		||||
class RtnlAddrFamily(YnlFamily):
 | 
			
		||||
    def __init__(self, recv_size=0):
 | 
			
		||||
        super().__init__((SPEC_PATH / Path('rt_addr.yaml')).as_posix(),
 | 
			
		||||
                         schema='', recv_size=recv_size)
 | 
			
		||||
 | 
			
		||||
class NetdevFamily(YnlFamily):
 | 
			
		||||
    def __init__(self, recv_size=0):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										30
									
								
								tools/testing/selftests/net/rtnetlink.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										30
									
								
								tools/testing/selftests/net/rtnetlink.py
									
									
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,30 @@
 | 
			
		|||
#!/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()
 | 
			
		||||
		Loading…
	
		Reference in a new issue