Add YNL test framework and library improvements
Subsystems (5)
cover Add YNL test framework and library improvements
This series enhances YNL tools with some functionalities and adds YNL selftest framework.
Changes include:
- Add MAC address parsing support in YNL library
- Fix rt-rule spec consistency with other rt-* families
- Add selftests covering CLI and ethtool functionality
The tests provide usage examples and regression testing for YNL tools.
Hangbin Liu (3):
tools: ynl: Add MAC address parsing support
netlink: specs: update rt-rule src/dst attribute types to support IPv4
addresses
selftests: net: add YNL test framework
Documentation/netlink/specs/rt-rule.yaml | 6 +- tools/net/ynl/pyynl/lib/ynl.py | 9 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/net/ynl/Makefile | 18 ++ tools/testing/selftests/net/ynl/cli.sh | 234 +++++++++++++++++++++ tools/testing/selftests/net/ynl/config | 6 + tools/testing/selftests/net/ynl/ethtool.sh | 188 +++++++++++++++++ tools/testing/selftests/net/ynl/settings | 1 + 8 files changed, 461 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/net/ynl/Makefile create mode 100755 tools/testing/selftests/net/ynl/cli.sh create mode 100644 tools/testing/selftests/net/ynl/config create mode 100755 tools/testing/selftests/net/ynl/ethtool.sh create mode 100644 tools/testing/selftests/net/ynl/settings
Signature · 1 line
2.50.1
PATCH 1/3 tools: ynl: Add MAC address parsing support
Add missing support for parsing MAC addresses when display_hint is 'mac' in the YNL library. This enables YNL CLI to accept MAC address strings for attributes like lladdr in rt-neigh operations.
--- tools/net/ynl/pyynl/lib/ynl.py | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/net/ynl/pyynl/lib/ynl.py +9 -0
@@ -985,6 +985,15 @@ class YnlFamily(SpecFamily): raw = bytes.fromhex(string) else: raw = int(string, 16) + elif attr_spec.display_hint == 'mac': + # Parse MAC address in format "00:11:22:33:44:55" or "001122334455" + if ':' in string: + mac_bytes = [int(x, 16) for x in string.split(':')] + else: + if len(string) % 2 != 0: + raise Exception(f"Invalid MAC address format: {string}") + mac_bytes = [int(string[i:i+2], 16) for i in range(0, len(string), 2)] + raw = bytes(mac_bytes) else: raise Exception(f"Display hint '{attr_spec.display_hint}' not implemented" f" when parsing '{attr_spec['name']}'")
Signature · 1 line
2.50.1
PATCH 2/3 netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
In reply to Hangbin LiuSimilar with other rt-* family specs (rt-route, rt-addr, rt-neigh), change src and dst attributes in rt-rule.yaml from type u32 to type binary with display-hint ipv4 to properly support IPv4 address operations.
--- Documentation/netlink/specs/rt-rule.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/netlink/specs/rt-rule.yaml +4 -2
@@ -96,10 +96,12 @@ attribute-sets: attributes: - name: dst - type: u32 + type: binary + display-hint: ipv4 - name: src - type: u32 + type: binary + display-hint: ipv4 - name: iifname type: string
Signature · 1 line
2.50.1
Jakub Kicinski
maintainerRe: [PATCH net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
Documentation/netlink/specs/rt-rule.yaml attribute-sets: · line 104
Quoted 10 lines · On Wed, 29 Oct 2025 08:22:44 +0000 Hangbin Liu wrote:
- name: dstDocumentation/netlink/specs/rt-rule.yaml +4
-2- type: u32 + type: binary + display-hint: ipv4 - name: src - type: u32 + type: binary + display-hint: ipv4
This will be annoying For C / C++, and you didn't set the max len so I think we'll also have to malloc each time. Do we not support display-hint for scalars?
Re: [PATCH net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
Quoted 12 lines · Jakub Kicinski
Documentation/netlink/specs/rt-rule.yaml attribute-sets: · line 104
Quoted 10 lines · On Wed, 29 Oct 2025 08:22:44 +0000 Hangbin Liu wrote:
- name: dstDocumentation/netlink/specs/rt-rule.yaml +4
-2- type: u32 + type: binary + display-hint: ipv4 - name: src - type: u32 + type: binary + display-hint: ipv4
Quoted 3 lines
This will be annoying For C / C++, and you didn't set the max len so I think we'll also have to malloc each time. Do we not support display-hint for scalars?
Ah, I didn't notice this. Should we convert all the
type: binary
display-hint: ipv4
to
type: u32
byte-order: big-endian
display-hint: ipv4
Thanks
Hangbin
Jakub Kicinski
maintainerRe: [PATCH net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
Quoted 6 lines · On Thu, 30 Oct 2025 06:35:18 +0000 Hangbin Liu wrote:
Quoted 3 lines
This will be annoying For C / C++, and you didn't set the max len so I think we'll also have to malloc each time. Do we not support display-hint for scalars?
Ah, I didn't notice this. Should we convert all the
Quoted 8 lines
type: binary
display-hint: ipv4to
type: u32
byte-order: big-endian
display-hint: ipv4
I think we should try. Technically it may change some kernel policies, but without min/max-like checks the byte-order should be a nop for the policy.
Re: [PATCH net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
In reply to Jakub KicinskiQuoted 12 lines · Jakub Kicinski
Documentation/netlink/specs/rt-rule.yaml attribute-sets: · line 104
Quoted 10 lines · On Wed, 29 Oct 2025 08:22:44 +0000 Hangbin Liu wrote:
- name: dstDocumentation/netlink/specs/rt-rule.yaml +4
-2- type: u32 + type: binary + display-hint: ipv4 - name: src - type: u32 + type: binary + display-hint: ipv4
Quoted 3 lines
This will be annoying For C / C++, and you didn't set the max len so I think we'll also have to malloc each time. Do we not support display-hint for scalars?
Hi Jakub,
I just realize that most of the address/src/dst in rt-addr/route are dual stack. The same with FRA_DST. We can't simply change binary to u32. So can we keep this u32 -> binary change?
Thanks
Hangbin
Jakub Kicinski
maintainerRe: [PATCH net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
Quoted 17 lines · On Tue, 4 Nov 2025 09:27:12 +0000 Hangbin Liu wrote:
Quoted 12 lines · Jakub Kicinski
Documentation/netlink/specs/rt-rule.yaml attribute-sets: · line 104
Quoted 10 lines · On Wed, 29 Oct 2025 08:22:44 +0000 Hangbin Liu wrote:
- name: dstDocumentation/netlink/specs/rt-rule.yaml +4
-2- type: u32 + type: binary + display-hint: ipv4 - name: src - type: u32 + type: binary + display-hint: ipv4Quoted 3 lines
This will be annoying For C / C++, and you didn't set the max len so I think we'll also have to malloc each time. Do we not support display-hint for scalars?
Quoted 5 lines
Hi Jakub,
I just realize that most of the address/src/dst in rt-addr/route are dual stack. The same with
FRA_DST. We can't simply change binary to u32. So can we keep this u32 -> binary change?
Ah, should have looked at more context..
Yes, and in that case without the display-hint?
Re: [PATCH net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
Quoted 8 lines · Jakub Kicinski
Quoted 5 lines
Hi Jakub,
I just realize that most of the address/src/dst in rt-addr/route are dual stack. The same with
FRA_DST. We can't simply change binary to u32. So can we keep this u32 -> binary change?Ah, should have looked at more context..
Yes, and in that case without the display-hint?
The display-hint is required; otherwise, the displayed src and dst fields appear as binary data, and setting the rule’s src/dst values also fails. I haven’t checked the code yet, but with
- display-hint: ipv4
the IPv6 addresses are also displayed correctly :)
Thanks
Hangbin
Jakub Kicinski
maintainerRe: [PATCH net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
Quoted 4 lines · On Wed, 5 Nov 2025 07:55:47 +0000 Hangbin Liu wrote:
Quoted 4 lines
Quoted 3 lines
I just realize that most of the address/src/dst in rt-addr/route are dual stack. The same with
FRA_DST. We can't simply change binary to u32. So can we keep this u32 -> binary change?
Quoted 8 lines
Quoted 2 lines
Ah, should have looked at more context..
Yes, and in that case without the display-hint?The display-hint is required; otherwise, the displayed src and dst fields appear as binary data, and setting the rule’s src/dst values also fails. I haven’t checked the code yet, but with
- display-hint: ipv4
the IPv6 addresses are also displayed correctly :)
Heh, we should have called the hint "ip" in that case :)
Re: [PATCH net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · On Wed, 5 Nov 2025 07:55:47 +0000 Hangbin Liu wrote:
Quoted 6 lines
Quoted 3 lines
I just realize that most of the address/src/dst in rt-addr/route are dual stack. The same with
FRA_DST. We can't simply change binary to u32. So can we keep this u32 -> binary change?Ah, should have looked at more context..
Yes, and in that case without the display-hint?
Quoted 7 lines
Quoted 5 lines
The display-hint is required; otherwise, the displayed src and dst fields appear as binary data, and setting the rule’s src/dst values also fails. I haven’t checked the code yet, but with
- display-hint: ipv4
the IPv6 addresses are also displayed correctly :)Heh, we should have called the hint "ip" in that case :)
I saw the display hit supports "ipv4-or-v6", but genetlink-c.yaml doesn't have "ipv4-or-v6". Do you know why?
# grep -rn fddi Documentation/netlink Documentation/netlink/genetlink.yaml:188: enum: [ hex, mac, fddi, ipv4, ipv6, uuid ] Documentation/netlink/genetlink-legacy.yaml:157: enum: [ hex, mac, fddi, ipv4, ipv6, ipv4-or-v6, uuid ] Documentation/netlink/netlink-raw.yaml:160: enum: [ hex, mac, fddi, ipv4, ipv6, uuid ] Documentation/netlink/genetlink-c.yaml:230: enum: [ hex, mac, fddi, ipv4, ipv6, uuid ]
Thanks
Hangbin
Jakub Kicinski
maintainerRe: [PATCH net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
Quoted 9 lines · On Thu, 6 Nov 2025 02:34:20 +0000 Hangbin Liu wrote:
Quoted 7 lines
Quoted 5 lines
The display-hint is required; otherwise, the displayed src and dst fields appear as binary data, and setting the rule’s src/dst values also fails. I haven’t checked the code yet, but with
- display-hint: ipv4
the IPv6 addresses are also displayed correctly :)Heh, we should have called the hint "ip" in that case :)
I saw the display hit supports "ipv4-or-v6",
Ah!
Quoted 1 line
but
genetlink-c.yamldoesn't have "ipv4-or-v6". Do you know why?
Probably just wasn't used until now. It should be in all the schemas.
Re: [PATCH net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
Quoted 4 lines · Jakub Kicinski
Quoted 1 line · On Thu, 6 Nov 2025 02:34:20 +0000 Hangbin Liu wrote:
but
genetlink-c.yamldoesn't have "ipv4-or-v6". Do you know why?Probably just wasn't used until now. It should be in all the schemas.
I couldn't find any other users, besides wireguard, as other families uses the ATTRv4 / ATTRv6 style attributes.
Quoted 3 lines · In commit 1b255e1beabf I wrote:
It only implements this display hint for genetlink-legacy, it can be added to other protocol variants if needed, but we don't want to encourage it's use.
Re: [PATCH net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses
Quoted 12 lines · Asbjørn Sloth Tønnesen
Quoted 4 lines · Jakub Kicinski
Quoted 1 line · On Thu, 6 Nov 2025 02:34:20 +0000 Hangbin Liu wrote:
but
genetlink-c.yamldoesn't have "ipv4-or-v6". Do you know why?Probably just wasn't used until now. It should be in all the schemas.
I couldn't find any other users, besides wireguard, as other families uses the ATTRv4 / ATTRv6 style attributes.
Quoted 3 lines · In commit 1b255e1beabf I wrote:
It only implements this display hint for genetlink-legacy, it can be added to other protocol variants if needed, but we don't want to encourage it's use.
Thanks for the comment. I will examine if other parts also need an update.
Regards
Hangbin
PATCH 3/3 selftests: net: add YNL test framework
In reply to Hangbin LiuAdd a test framework for YAML Netlink (YNL) tools, covering both CLI and ethtool functionality. The framework includes:
1) cli: family listing, netdev, ethtool, rt-* families, and nlctrl operations
2) ethtool: device info, statistics, ring/coalesce/pause parameters, and feature gettings
The current YNL syntax is a bit obscure, and end users may not always know how to use it. This test framework provides usage examples and also serves as a regression test to catch potential breakages caused by future changes.
--- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/net/ynl/Makefile | 18 ++ tools/testing/selftests/net/ynl/cli.sh | 234 +++++++++++++++++++++ tools/testing/selftests/net/ynl/config | 6 + tools/testing/selftests/net/ynl/ethtool.sh | 188 +++++++++++++++++ tools/testing/selftests/net/ynl/settings | 1 + 6 files changed, 448 insertions(+) create mode 100644 tools/testing/selftests/net/ynl/Makefile create mode 100755 tools/testing/selftests/net/ynl/cli.sh create mode 100644 tools/testing/selftests/net/ynl/config create mode 100755 tools/testing/selftests/net/ynl/ethtool.sh create mode 100644 tools/testing/selftests/net/ynl/settings
tools/testing/selftests/Makefile +1 -0
@@ -78,6 +78,7 @@ TARGETS += net/ovpn TARGETS += net/packetdrill TARGETS += net/rds TARGETS += net/tcp_ao +TARGETS += net/ynl TARGETS += nolibc TARGETS += nsfs TARGETS += pci_endpoint
tools/testing/selftests/net/ynl/Makefile new file +18 -0
@@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0 +# Makefile for YNL tests + +TEST_PROGS := \ + cli.sh \ + ethtool.sh \ +# end of TEST_PROGS + +TEST_FILES := \ + settings \ +# end of TEST_FILES + +TEST_INCLUDES := \ + $(wildcard ../lib/sh/*.sh) \ + ../lib.sh \ +# end of TEST_INCLUDES + +include ../../lib.mk
tools/testing/selftests/net/ynl/cli.sh new file +234 -0
234 lines not on this page · raw message
tools/testing/selftests/net/ynl/config new file +6 -0
@@ -0,0 +1,6 @@ +CONFIG_DUMMY=m +CONFIG_INET_DIAG=y +CONFIG_IPV6=y +CONFIG_NET_NS=y +CONFIG_NETDEVSIM=m +CONFIG_VETH=m
tools/testing/selftests/net/ynl/ethtool.sh new file +188 -0
188 lines not on this page · raw message
tools/testing/selftests/net/ynl/settings new file +1 -0
@@ -0,0 +1 @@ +timeout=120
Signature · 1 line
2.50.1
Jakub Kicinski
maintainerRe: [PATCH net-next 3/3] selftests: net: add YNL test framework
Quoted 11 lines · On Wed, 29 Oct 2025 08:22:45 +0000 Hangbin Liu wrote:
Add a test framework for YAML Netlink (YNL) tools, covering both CLI and ethtool functionality. The framework includes:
1) cli: family listing, netdev, ethtool, rt-* families, and nlctrl operations
2) ethtool: device info, statistics, ring/coalesce/pause parameters, and feature gettingsThe current YNL syntax is a bit obscure, and end users may not always know how to use it. This test framework provides usage examples and also serves as a regression test to catch potential breakages caused by future changes.
Hm, my knee-jerk reaction was that we should avoid adding too much ynl stuff to the kernel at this point. But looking closer it's not that long.
Do I understand correctly, tho, that you're testing _system_ YNL? Not what's in tree?
Re: [PATCH net-next 3/3] selftests: net: add YNL test framework
Quoted 13 lines · Jakub Kicinski
Quoted 11 lines · On Wed, 29 Oct 2025 08:22:45 +0000 Hangbin Liu wrote:
Add a test framework for YAML Netlink (YNL) tools, covering both CLI and ethtool functionality. The framework includes:
1) cli: family listing, netdev, ethtool, rt-* families, and nlctrl operations
2) ethtool: device info, statistics, ring/coalesce/pause parameters, and feature gettingsThe current YNL syntax is a bit obscure, and end users may not always know how to use it. This test framework provides usage examples and also serves as a regression test to catch potential breakages caused by future changes.
Quoted 6 lines
Hm, my knee-jerk reaction was that we should avoid adding too much ynl stuff to the kernel at this point. But looking closer it's not that long.
Do I understand correctly, tho, that you're testing _system_ YNL? Not what's in tree?
Kind of. With this we can test both the system's YNL and also make sure the YNL interface has no regression.
Thanks
Hangbin
Jakub Kicinski
maintainerRe: [PATCH net-next 3/3] selftests: net: add YNL test framework
Quoted 9 lines · On Thu, 30 Oct 2025 06:00:24 +0000 Hangbin Liu wrote:
Quoted 6 lines
Hm, my knee-jerk reaction was that we should avoid adding too much ynl stuff to the kernel at this point. But looking closer it's not that long.
Do I understand correctly, tho, that you're testing _system_ YNL? Not what's in tree?
Kind of. With this we can test both the system's YNL and also make sure the YNL interface has no regression.
Meaning we still test the spec, right?
To state the obvious ideally we'd test both the specs and the Python tools. Strictly better, and without it adding tests for new Python features will be a little annoying for people running the selftest.
Maybe the solution is as simple as finding and alias'ing ynl to the cli.py ?
Re: [PATCH net-next 3/3] selftests: net: add YNL test framework
Quoted 5 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 30 Oct 2025 06:00:24 +0000 Hangbin Liu wrote:
Quoted 4 lines
Hm, my knee-jerk reaction was that we should avoid adding too much ynl stuff to the kernel at this point. But looking closer it's not that long.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Do I understand correctly, tho, that you're testing _system_ YNL? Not what's in tree?
Kind of. With this we can test both the system's YNL and also make sure the YNL interface has no regression.
Meaning we still test the spec, right?
I just do make install in tools/net/ynl. Both the ynl scripts and specs are installed. So I think the specs are also tested.
Quoted 4 lines
To state the obvious ideally we'd test both the specs and the Python tools. Strictly better, and without it adding tests for new Python features will be a little annoying for people running the selftest.
Yes
Quoted 2 lines
Maybe the solution is as simple as finding and alias'ing ynl to the
cli.py?
I didn't get here. The ynl calls pyynl.cli:main, that should be enough. Do you mean we should find the cli.py path and call it like $source_code/tools/net/ynl/pyynl/cli.py --spec $source_code/Documentation/netlink/specs/xxx.yaml ...?
Thanks
Hangbin
Jakub Kicinski
maintainerRe: [PATCH net-next 3/3] selftests: net: add YNL test framework
Quoted 14 lines · On Fri, 31 Oct 2025 01:48:17 +0000 Hangbin Liu wrote:
Quoted 4 lines
Quoted 2 lines
Kind of. With this we can test both the system's YNL and also make sure the YNL interface has no regression.
Meaning we still test the spec, right?
I just do
make installintools/net/ynl. Both the ynl scripts and specs are installed. So I think the specs are also tested.Quoted 3 lines
To state the obvious ideally we'd test both the specs and the Python tools. Strictly better, and without it adding tests for new Python features will be a little annoying for people running the selftest.
Yes
Quoted 7 lines
Quoted 2 lines
Maybe the solution is as simple as finding and alias'ing ynl to the
cli.py?I didn't get here. The
ynlcalls pyynl.cli:main, that should be enough. Do you mean we should find thecli.pypath and call it like$source_code/tools/net/ynl/pyynl/cli.py --spec $source_code/Documentation/netlink/specs/xxx.yaml ...?
More or less. But it needs to know how to install itself when kernel selftests are installed. Maybe it's not worth the complexity and we should add the script under tools/net/ynl. Easier to refer from there.
Re: [PATCH net-next 3/3] selftests: net: add YNL test framework
Quoted 11 lines · Jakub Kicinski
Quoted 7 lines
I just do
make installintools/net/ynl. Both the ynl scripts and specs are installed. So I think the specs are also tested.I didn't get here. The
ynlcalls pyynl.cli:main, that should be enough. Do you mean we should find thecli.pypath and call it like$source_code/tools/net/ynl/pyynl/cli.py --spec $source_code/Documentation/netlink/specs/xxx.yaml ...?More or less. But it needs to know how to install itself when kernel selftests are installed. Maybe it's not worth the complexity and we should add the script under
tools/net/ynl. Easier to refer from there.
Hmm, how should we execute the script under tools/net/ynl? Use the cli.py like:
./cli.py --spec ../../../Documentation/netlink/specs/xxx.yaml
Or use the installed name ynl
ynl --family xxx ...
Thanks
Hangbin
Jakub Kicinski
maintainerRe: [PATCH net-next 3/3] selftests: net: add YNL test framework
Quoted 13 lines · On Mon, 3 Nov 2025 05:12:43 +0000 Hangbin Liu wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 7 lines
I just do
make installintools/net/ynl. Both the ynl scripts and specs are installed. So I think the specs are also tested.I didn't get here. The
ynlcalls pyynl.cli:main, that should be enough. Do you mean we should find thecli.pypath and call it like$source_code/tools/net/ynl/pyynl/cli.py --spec $source_code/Documentation/netlink/specs/xxx.yaml ...?More or less. But it needs to know how to install itself when kernel selftests are installed. Maybe it's not worth the complexity and we should add the script under
tools/net/ynl. Easier to refer from there.
Quoted 8 lines
Hmm, how should we execute the script under
tools/net/ynl? Use thecli.pylike:./cli.py --spec
../../../Documentation/netlink/specs/xxx.yamlOr use the installed name
ynlynl --family xxx ...
I think under tools/net we don't have the kernel selftest infra. This is not great because we lose the integration benefits, but it gives us the ability to.. do whatever want..
I think relative paths would be fine? I believe that if you run cli from its directory you can use --family and it will refer to the in-tree specs automagically ?
Re: [PATCH net-next 3/3] selftests: net: add YNL test framework
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 3 Nov 2025 05:12:43 +0000 Hangbin Liu wrote:
Hmm, how should we execute the script under
tools/net/ynl? Use thecli.pylike:./cli.py --spec
../../../Documentation/netlink/specs/xxx.yaml
Quoted 7 lines
Quoted 3 lines
Or use the installed name
ynlynl --family xxx ...
I think under
tools/netwe don't have the kernel selftest infra. This is not great because we lose the integration benefits, but it gives us the ability to.. do whatever want..
Yep.
Quoted 4 lines
I think relative paths would be fine? I believe that if you run cli from its directory you can use --family and it will refer to the in-tree specs automagically ?
OK, let me try it.
Thanks
Hangbin