diff options
| author | Jakub Kicinski <kuba@kernel.org> | 2025-11-28 19:53:22 -0800 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2025-11-28 19:53:22 -0800 |
| commit | 2ce992a1a400b28fd52f5ee77fb5ab836bb861a8 (patch) | |
| tree | 1bf3958406ac7964ec6038215a41545e30242dda | |
| parent | 2c80116b503296dd050c8b92bef34e300bc2b1d4 (diff) | |
| parent | 1adc241f3940c172c8c674a62004d3c34b360ab3 (diff) | |
Merge branch 'tools-ynl-add-schema-checking'
Donald Hunter says:
====================
tools: ynl: add schema checking
Add schema checking and yaml linting for the YNL specs.
Patch 1 adds a schema_check make target using a pyynl --validate option
Patch 2 adds a lint make target using yamllint
Patches 3,4 fix issues reported by make -C tools/net/ynl lint schema_check
====================
Link: https://patch.msgid.link/20251127123502.89142-1-donald.hunter@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
| -rw-r--r-- | Documentation/netlink/specs/conntrack.yaml | 2 | ||||
| -rw-r--r-- | Documentation/netlink/specs/ethtool.yaml | 2 | ||||
| -rw-r--r-- | Documentation/netlink/specs/nftables.yaml | 2 | ||||
| -rw-r--r-- | tools/net/ynl/Makefile | 22 | ||||
| -rwxr-xr-x | tools/net/ynl/pyynl/cli.py | 21 |
5 files changed, 40 insertions, 9 deletions
diff --git a/Documentation/netlink/specs/conntrack.yaml b/Documentation/netlink/specs/conntrack.yaml index bef528633b17..db7cddcda50a 100644 --- a/Documentation/netlink/specs/conntrack.yaml +++ b/Documentation/netlink/specs/conntrack.yaml @@ -457,7 +457,7 @@ attribute-sets: name: labels type: binary - - name: labels mask + name: labels-mask type: binary - name: synproxy diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 05d2b6508b59..0a2d2343f79a 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -1269,7 +1269,7 @@ attribute-sets: - name: hist type: nest - multi-attr: True + multi-attr: true nested-attributes: fec-hist - name: fec diff --git a/Documentation/netlink/specs/nftables.yaml b/Documentation/netlink/specs/nftables.yaml index cce88819ba71..17ad707fa0d5 100644 --- a/Documentation/netlink/specs/nftables.yaml +++ b/Documentation/netlink/specs/nftables.yaml @@ -915,7 +915,7 @@ attribute-sets: type: string doc: Name of set to use - - name: set id + name: set-id type: u32 byte-order: big-endian doc: ID of set to use diff --git a/tools/net/ynl/Makefile b/tools/net/ynl/Makefile index a40591e513b7..7736b492f559 100644 --- a/tools/net/ynl/Makefile +++ b/tools/net/ynl/Makefile @@ -12,6 +12,8 @@ endif libdir ?= $(prefix)/$(libdir_relative) includedir ?= $(prefix)/include +SPECDIR=../../../Documentation/netlink/specs + SUBDIRS = lib generated samples ynltool tests all: $(SUBDIRS) libynl.a @@ -54,4 +56,22 @@ install: libynl.a lib/*.h run_tests: @$(MAKE) -C tests run_tests -.PHONY: all clean distclean install run_tests $(SUBDIRS) +lint: + yamllint $(SPECDIR) + +schema_check: + @N=1; \ + for spec in $(SPECDIR)/*.yaml ; do \ + NAME=$$(basename $$spec) ; \ + OUTPUT=$$(./pyynl/cli.py --spec $$spec --validate) ; \ + if [ $$? -eq 0 ] ; then \ + echo "ok $$N $$NAME schema validation" ; \ + else \ + echo "not ok $$N $$NAME schema validation" ; \ + echo "$$OUTPUT" ; \ + echo ; \ + fi ; \ + N=$$((N+1)) ; \ + done + +.PHONY: all clean distclean install run_tests lint schema_check $(SUBDIRS) diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py index ff81ff083764..af02a5b7e5a2 100755 --- a/tools/net/ynl/pyynl/cli.py +++ b/tools/net/ynl/pyynl/cli.py @@ -10,7 +10,7 @@ import sys import textwrap sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix()) -from lib import YnlFamily, Netlink, NlError +from lib import YnlFamily, Netlink, NlError, SpecFamily sys_schema_dir='/usr/share/ynl' relative_schema_dir='../../../../Documentation/netlink' @@ -127,6 +127,7 @@ def main(): group.add_argument('--list-msgs', action='store_true') group.add_argument('--list-attrs', dest='list_attrs', metavar='OPERATION', type=str, help='List attributes for an operation') + group.add_argument('--validate', action='store_true') parser.add_argument('--duration', dest='duration', type=int, help='when subscribed, watch for DURATION seconds') @@ -168,15 +169,25 @@ def main(): if args.family: spec = f"{spec_dir()}/{args.family}.yaml" - if args.schema is None and spec.startswith(sys_schema_dir): - args.schema = '' # disable schema validation when installed - if args.process_unknown is None: - args.process_unknown = True else: spec = args.spec if not os.path.isfile(spec): raise Exception(f"Spec file {spec} does not exist") + if args.validate: + try: + SpecFamily(spec, args.schema) + except Exception as error: + print(error) + exit(1) + return + + if args.family: # set behaviour when using installed specs + if args.schema is None and spec.startswith(sys_schema_dir): + args.schema = '' # disable schema validation when installed + if args.process_unknown is None: + args.process_unknown = True + ynl = YnlFamily(spec, args.schema, args.process_unknown, recv_size=args.dbg_small_recv) if args.dbg_small_recv: |
