@@ -92,6 +92,41 @@ definitions:
-
name: ifi-change
type: u32
+ -
+ name: ifaddrmsg
+ type: struct
+ members:
+ -
+ name: ifa-family
+ type: u8
+ -
+ name: ifa-prefixlen
+ type: u8
+ -
+ name: ifa-flags
+ type: u8
+ -
+ name: ifa-scope
+ type: u8
+ -
+ name: ifa-index
+ type: u32
+ -
+ name: ifacacheinfo
+ type: struct
+ members:
+ -
+ name: ifa-prefered
+ type: u32
+ -
+ name: ifa-valid
+ type: u32
+ -
+ name: cstamp
+ type: u32
+ -
+ name: tstamp
+ type: u32
-
name: ifla-bridge-id
type: struct
@@ -2253,6 +2288,18 @@ attribute-sets:
-
name: tailroom
type: u16
+ -
+ name: ifmcaddr-attrs
+ attributes:
+ -
+ name: addr
+ type: binary
+ value: 7
+ -
+ name: cacheinfo
+ type: binary
+ struct: ifacacheinfo
+ value: 6
sub-messages:
-
@@ -2493,6 +2540,29 @@ operations:
reply:
value: 92
attributes: *link-stats-attrs
+ -
+ name: getmaddrs
+ doc: Get / dump IPv4/IPv6 multicast addresses.
+ attribute-set: ifmcaddr-attrs
+ fixed-header: ifaddrmsg
+ do:
+ request:
+ value: 58
+ attributes:
+ - ifa-family
+ - ifa-index
+ reply:
+ value: 58
+ attributes: &mcaddr-attrs
+ - addr
+ - 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
new file mode 100755
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+from lib.py import ksft_exit, ksft_run, ksft_ge, RtnlFamily
+import socket
+
+IPV4_ALL_HOSTS_MULTICAST = b'\xe0\x00\x00\x01'
+
+def dump_mcaddr_check(rtnl: RtnlFamily) -> 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['addr'] == 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 = RtnlFamily()
+ ksft_run([dump_mcaddr_check], args=(rtnl, ))
+ ksft_exit()
+
+if __name__ == "__main__":
+ main()
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> --- Documentation/netlink/specs/rt_link.yaml | 70 ++++++++++++++++++++++++ tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/rtnetlink.py | 30 ++++++++++ 3 files changed, 101 insertions(+) create mode 100755 tools/testing/selftests/net/rtnetlink.py