Skip to content

Commit 4f28037

Browse files
Yuyang HuangPaolo Abeni
authored andcommitted
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>
1 parent eb4e17a commit 4f28037

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

Documentation/netlink/specs/rt_addr.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,29 @@ operations:
168168
reply:
169169
value: 20
170170
attributes: *ifaddr-all
171+
-
172+
name: getmaddrs
173+
doc: Get / dump IPv4/IPv6 multicast addresses.
174+
attribute-set: addr-attrs
175+
fixed-header: ifaddrmsg
176+
do:
177+
request:
178+
value: 58
179+
attributes:
180+
- ifa-family
181+
- ifa-index
182+
reply:
183+
value: 58
184+
attributes: &mcaddr-attrs
185+
- ifa-multicast
186+
- ifa-cacheinfo
187+
dump:
188+
request:
189+
value: 58
190+
- ifa-family
191+
reply:
192+
value: 58
193+
attributes: *mcaddr-attrs
171194

172195
mcast-groups:
173196
list:

tools/testing/selftests/net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ TEST_PROGS += cmsg_so_priority.sh
3636
TEST_PROGS += cmsg_time.sh cmsg_ipv6.sh
3737
TEST_PROGS += netns-name.sh
3838
TEST_PROGS += nl_netdev.py
39+
TEST_PROGS += rtnetlink.py
3940
TEST_PROGS += srv6_end_dt46_l3vpn_test.sh
4041
TEST_PROGS += srv6_end_dt4_l3vpn_test.sh
4142
TEST_PROGS += srv6_end_dt6_l3vpn_test.sh

tools/testing/selftests/net/lib/py/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
from .netns import NetNS
66
from .nsim import *
77
from .utils import *
8-
from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily
8+
from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily
99
from .ynl import NetshaperFamily

tools/testing/selftests/net/lib/py/ynl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def __init__(self, recv_size=0):
4242
super().__init__((SPEC_PATH / Path('rt_link.yaml')).as_posix(),
4343
schema='', recv_size=recv_size)
4444

45+
class RtnlAddrFamily(YnlFamily):
46+
def __init__(self, recv_size=0):
47+
super().__init__((SPEC_PATH / Path('rt_addr.yaml')).as_posix(),
48+
schema='', recv_size=recv_size)
4549

4650
class NetdevFamily(YnlFamily):
4751
def __init__(self, recv_size=0):
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
from lib.py import ksft_exit, ksft_run, ksft_ge, RtnlAddrFamily
5+
import socket
6+
7+
IPV4_ALL_HOSTS_MULTICAST = b'\xe0\x00\x00\x01'
8+
9+
def 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.getmaddrs({"ifa-family": socket.AF_INET}, dump=True)
16+
17+
all_host_multicasts = [
18+
addr for addr in addresses if addr['ifa-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+
24+
def main() -> None:
25+
rtnl = RtnlAddrFamily()
26+
ksft_run([dump_mcaddr_check], args=(rtnl, ))
27+
ksft_exit()
28+
29+
if __name__ == "__main__":
30+
main()

0 commit comments

Comments
 (0)