diff mbox series

[net-next,v8,2/2] selftests/net: Add selftest for IPv4 RTM_GETMULTICAST support

Message ID 20250207110836.2407224-2-yuyanghuang@google.com (mailing list archive)
State New
Headers show
Series [net-next,v8,1/2] netlink: support dumping IPv4 multicast addresses | expand

Commit Message

Yuyang Huang Feb. 7, 2025, 11:08 a.m. UTC
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>
---

Changelog since v7:
- Create a new RtnlAddrFamily to load rt_addr.yaml.

Changelog since v6:
- Move `getmaddrs` definition to rt_addr.yaml.

 Documentation/netlink/specs/rt_addr.yaml      | 23 ++++++++++++++
 tools/testing/selftests/net/Makefile          |  1 +
 .../testing/selftests/net/lib/py/__init__.py  |  2 +-
 tools/testing/selftests/net/lib/py/ynl.py     |  4 +++
 tools/testing/selftests/net/rtnetlink.py      | 30 +++++++++++++++++++
 5 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/rtnetlink.py

Comments

Simon Horman Feb. 10, 2025, 4:13 p.m. UTC | #1
On Fri, Feb 07, 2025 at 08:08:36PM +0900, Yuyang Huang wrote:
> 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>
> ---
> 
> Changelog since v7:
> - Create a new RtnlAddrFamily to load rt_addr.yaml.
> 
> Changelog since v6:
> - Move `getmaddrs` definition to rt_addr.yaml.
> 
>  Documentation/netlink/specs/rt_addr.yaml      | 23 ++++++++++++++

Hi Yuyang Huang,

FWIIW I think that the YAML spec entry is distinct from, although a
dependency of, adding the test. I would put it in a separate patch.

>  tools/testing/selftests/net/Makefile          |  1 +
>  .../testing/selftests/net/lib/py/__init__.py  |  2 +-
>  tools/testing/selftests/net/lib/py/ynl.py     |  4 +++
>  tools/testing/selftests/net/rtnetlink.py      | 30 +++++++++++++++++++
>  5 files changed, 59 insertions(+), 1 deletion(-)
>  create mode 100755 tools/testing/selftests/net/rtnetlink.py

...
Yuyang Huang Feb. 11, 2025, 5:43 a.m. UTC | #2
>FWIIW I think that the YAML spec entry is distinct from, although a
>dependency of, adding the test. I would put it in a separate patch.

Thanks for the feedback! I will split the change into two patches in
the next submission.

Thanks,

Yuyang


On Mon, Feb 10, 2025 at 8:13 AM Simon Horman <horms@kernel.org> wrote:
>
> On Fri, Feb 07, 2025 at 08:08:36PM +0900, Yuyang Huang wrote:
> > 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>
> > ---
> >
> > Changelog since v7:
> > - Create a new RtnlAddrFamily to load rt_addr.yaml.
> >
> > Changelog since v6:
> > - Move `getmaddrs` definition to rt_addr.yaml.
> >
> >  Documentation/netlink/specs/rt_addr.yaml      | 23 ++++++++++++++
>
> Hi Yuyang Huang,
>
> FWIIW I think that the YAML spec entry is distinct from, although a
> dependency of, adding the test. I would put it in a separate patch.
>
> >  tools/testing/selftests/net/Makefile          |  1 +
> >  .../testing/selftests/net/lib/py/__init__.py  |  2 +-
> >  tools/testing/selftests/net/lib/py/ynl.py     |  4 +++
> >  tools/testing/selftests/net/rtnetlink.py      | 30 +++++++++++++++++++
> >  5 files changed, 59 insertions(+), 1 deletion(-)
> >  create mode 100755 tools/testing/selftests/net/rtnetlink.py
>
> ...
Simon Horman Feb. 11, 2025, 10:05 a.m. UTC | #3
On Mon, Feb 10, 2025 at 09:43:03PM -0800, Yuyang Huang wrote:
> >FWIIW I think that the YAML spec entry is distinct from, although a
> >dependency of, adding the test. I would put it in a separate patch.
> 
> Thanks for the feedback! I will split the change into two patches in
> the next submission.

Thanks,

After sleeping on this I realise that this is really only a very
minor process issue. And as we are already on v8, after mostly
minor revisions to get there, I think this patchset can be accepted
as-is after all.

So no action required by you at this time.
diff mbox series

Patch

diff --git a/Documentation/netlink/specs/rt_addr.yaml b/Documentation/netlink/specs/rt_addr.yaml
index cbee1cedb177..5dd5469044c7 100644
--- a/Documentation/netlink/specs/rt_addr.yaml
+++ b/Documentation/netlink/specs/rt_addr.yaml
@@ -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:
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 73ee88d6b043..e2f03211f9b3 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -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
diff --git a/tools/testing/selftests/net/lib/py/__init__.py b/tools/testing/selftests/net/lib/py/__init__.py
index 54d8f5eba810..729457859316 100644
--- a/tools/testing/selftests/net/lib/py/__init__.py
+++ b/tools/testing/selftests/net/lib/py/__init__.py
@@ -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
diff --git a/tools/testing/selftests/net/lib/py/ynl.py b/tools/testing/selftests/net/lib/py/ynl.py
index ad1e36baee2a..8986c584cb37 100644
--- a/tools/testing/selftests/net/lib/py/ynl.py
+++ b/tools/testing/selftests/net/lib/py/ynl.py
@@ -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):
diff --git a/tools/testing/selftests/net/rtnetlink.py b/tools/testing/selftests/net/rtnetlink.py
new file mode 100755
index 000000000000..80950888800b
--- /dev/null
+++ b/tools/testing/selftests/net/rtnetlink.py
@@ -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()