netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] YNL CLI --list-attrs argument
@ 2025-11-16 19:28 Gal Pressman
  2025-11-16 19:28 ` [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes Gal Pressman
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Gal Pressman @ 2025-11-16 19:28 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, netdev
  Cc: Donald Hunter, Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, bpf,
	Gal Pressman

When experimenting with the YNL CLI, I found the process of going back
and forth to examine the YAML spec files in order to figure out how to
use each command quite tiring.

The addition of --list-attrs helps by providing all information needed
directly in the tool. I figured others would likely find it useful as
well.

Gal Pressman (3):
  tools: ynl: cli: Add --list-attrs option to show operation attributes
  tools: ynl: cli: Parse nested attributes in --list-attrs output
  tools: ynl: cli: Display enum values in --list-attrs output

 tools/net/ynl/pyynl/cli.py | 77 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

-- 
2.40.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
  2025-11-16 19:28 [PATCH net-next 0/3] YNL CLI --list-attrs argument Gal Pressman
@ 2025-11-16 19:28 ` Gal Pressman
  2025-11-17 15:56   ` Donald Hunter
                     ` (2 more replies)
  2025-11-16 19:28 ` [PATCH net-next 2/3] tools: ynl: cli: Parse nested attributes in --list-attrs output Gal Pressman
  2025-11-16 19:28 ` [PATCH net-next 3/3] tools: ynl: cli: Display enum values " Gal Pressman
  2 siblings, 3 replies; 17+ messages in thread
From: Gal Pressman @ 2025-11-16 19:28 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, netdev
  Cc: Donald Hunter, Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, bpf,
	Gal Pressman, Nimrod Oren

Add a --list-attrs option to the YNL CLI that displays information about
netlink operations, including request and reply attributes.
This eliminates the need to manually inspect YAML spec files to
determine the JSON structure required for operations, or understand the
structure of the reply.

Example usage:
  # ./cli.py --family netdev --list-attrs dev-get
  Operation: dev-get

  Do request attributes:
    - ifindex: u32
      netdev ifindex

  Do reply attributes:
    - ifindex: u32
      netdev ifindex
    - xdp-features: u64 (enum: xdp-act)
      Bitmask of enabled xdp-features.
    - xdp-zc-max-segs: u32
      max fragment count supported by ZC driver
    - xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
      Bitmask of supported XDP receive metadata features. See Documentation/networking/xdp-rx-metadata.rst for more details.
    - xsk-features: u64 (enum: xsk-flags)
      Bitmask of enabled AF_XDP features.

  Dump reply attributes:
    - ifindex: u32
      netdev ifindex
    - xdp-features: u64 (enum: xdp-act)
      Bitmask of enabled xdp-features.
    - xdp-zc-max-segs: u32
      max fragment count supported by ZC driver
    - xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
      Bitmask of supported XDP receive metadata features. See Documentation/networking/xdp-rx-metadata.rst for more details.
    - xsk-features: u64 (enum: xsk-flags)
      Bitmask of enabled AF_XDP features.

Reviewed-by: Nimrod Oren <noren@nvidia.com>
Signed-off-by: Gal Pressman <gal@nvidia.com>
---
 tools/net/ynl/pyynl/cli.py | 55 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py
index 8c192e900bd3..7ac3b4627f1b 100755
--- a/tools/net/ynl/pyynl/cli.py
+++ b/tools/net/ynl/pyynl/cli.py
@@ -7,6 +7,7 @@ import os
 import pathlib
 import pprint
 import sys
+import textwrap
 
 sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix())
 from lib import YnlFamily, Netlink, NlError
@@ -70,6 +71,8 @@ def main():
     group.add_argument('--dump', dest='dump', metavar='DUMP-OPERATION', type=str)
     group.add_argument('--list-ops', action='store_true')
     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')
 
     parser.add_argument('--duration', dest='duration', type=int,
                         help='when subscribed, watch for DURATION seconds')
@@ -128,6 +131,40 @@ def main():
     if args.ntf:
         ynl.ntf_subscribe(args.ntf)
 
+    def print_attr_list(attr_names, attr_set):
+        """Print a list of attributes with their types and documentation."""
+        for attr_name in attr_names:
+            if attr_name in attr_set.attrs:
+                attr = attr_set.attrs[attr_name]
+                attr_info = f'  - {attr_name}: {attr.type}'
+                if 'enum' in attr.yaml:
+                    attr_info += f" (enum: {attr.yaml['enum']})"
+                if attr.yaml.get('doc'):
+                    doc_text = textwrap.indent(attr.yaml['doc'], '    ')
+                    attr_info += f"\n{doc_text}"
+                print(attr_info)
+            else:
+                print(f'  - {attr_name}')
+
+    def print_mode_attrs(mode, mode_spec, attr_set, print_request=True):
+        """Print a given mode (do/dump/event/notify)."""
+        mode_title = mode.capitalize()
+
+        if print_request and 'request' in mode_spec and 'attributes' in mode_spec['request']:
+            print(f'\n{mode_title} request attributes:')
+            print_attr_list(mode_spec['request']['attributes'], attr_set)
+
+        if 'reply' in mode_spec and 'attributes' in mode_spec['reply']:
+            print(f'\n{mode_title} reply attributes:')
+            print_attr_list(mode_spec['reply']['attributes'], attr_set)
+
+        if 'attributes' in mode_spec:
+            print(f'\n{mode_title} attributes:')
+            print_attr_list(mode_spec['attributes'], attr_set)
+
+        if 'mcgrp' in mode_spec:
+                print(f"Multicast group: {op.yaml['mcgrp']}")
+
     if args.list_ops:
         for op_name, op in ynl.ops.items():
             print(op_name, " [", ", ".join(op.modes), "]")
@@ -135,6 +172,24 @@ def main():
         for op_name, op in ynl.msgs.items():
             print(op_name, " [", ", ".join(op.modes), "]")
 
+    if args.list_attrs:
+        op = ynl.msgs.get(args.list_attrs)
+        if not op:
+            print(f'Operation {args.list_attrs} not found')
+            exit(1)
+
+        print(f'Operation: {op.name}')
+
+        for mode in ['do', 'dump', 'event']:
+            if mode in op.yaml:
+                print_mode_attrs(mode, op.yaml[mode], op.attr_set, True)
+
+        if 'notify' in op.yaml:
+            mode_spec = op.yaml['notify']
+            ref_spec = ynl.msgs.get(mode_spec).yaml.get('do')
+            if ref_spec:
+                print_mode_attrs(mode, ref_spec, op.attr_set, False)
+
     try:
         if args.do:
             reply = ynl.do(args.do, attrs, args.flags)
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next 2/3] tools: ynl: cli: Parse nested attributes in --list-attrs output
  2025-11-16 19:28 [PATCH net-next 0/3] YNL CLI --list-attrs argument Gal Pressman
  2025-11-16 19:28 ` [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes Gal Pressman
@ 2025-11-16 19:28 ` Gal Pressman
  2025-11-17 15:57   ` Donald Hunter
  2025-11-16 19:28 ` [PATCH net-next 3/3] tools: ynl: cli: Display enum values " Gal Pressman
  2 siblings, 1 reply; 17+ messages in thread
From: Gal Pressman @ 2025-11-16 19:28 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, netdev
  Cc: Donald Hunter, Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, bpf,
	Gal Pressman, Nimrod Oren

Enhance the --list-attrs option to recursively display nested attributes
instead of just showing "nest" as the type.
Nested attributes now show their attribute set name and expand to
display their contents.

  # ./cli.py --family ethtool --list-attrs rss-get
  [..]
  Do request attributes:
    - header: nest -> header
        - dev-index: u32
        - dev-name: string
        - flags: u32 (enum: header-flags)
        - phy-index: u32
    - context: u32
  [..]

Reviewed-by: Nimrod Oren <noren@nvidia.com>
Signed-off-by: Gal Pressman <gal@nvidia.com>
---
 tools/net/ynl/pyynl/cli.py | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py
index 7ac3b4627f1b..3389e552ec4e 100755
--- a/tools/net/ynl/pyynl/cli.py
+++ b/tools/net/ynl/pyynl/cli.py
@@ -131,20 +131,37 @@ def main():
     if args.ntf:
         ynl.ntf_subscribe(args.ntf)
 
-    def print_attr_list(attr_names, attr_set):
+    def print_attr_list(attr_names, attr_set, indent=2):
         """Print a list of attributes with their types and documentation."""
+        prefix = ' ' * indent
         for attr_name in attr_names:
             if attr_name in attr_set.attrs:
                 attr = attr_set.attrs[attr_name]
-                attr_info = f'  - {attr_name}: {attr.type}'
+                attr_info = f'{prefix}- {attr_name}: {attr.type}'
                 if 'enum' in attr.yaml:
                     attr_info += f" (enum: {attr.yaml['enum']})"
+
+                # Show nested attributes reference and recursively display them
+                nested_set_name = None
+                if attr.type == 'nest' and 'nested-attributes' in attr.yaml:
+                    nested_set_name = attr.yaml['nested-attributes']
+                    attr_info += f" -> {nested_set_name}"
+
                 if attr.yaml.get('doc'):
-                    doc_text = textwrap.indent(attr.yaml['doc'], '    ')
+                    doc_text = textwrap.indent(attr.yaml['doc'], prefix + '  ')
                     attr_info += f"\n{doc_text}"
                 print(attr_info)
+
+                # Recursively show nested attributes
+                if nested_set_name in ynl.attr_sets:
+                    nested_set = ynl.attr_sets[nested_set_name]
+                    # Filter out 'unspec' and other unused attrs
+                    nested_names = [n for n in nested_set.attrs.keys()
+                                    if nested_set.attrs[n].type != 'unused']
+                    if nested_names:
+                        print_attr_list(nested_names, nested_set, indent + 4)
             else:
-                print(f'  - {attr_name}')
+                print(f'{prefix}- {attr_name}')
 
     def print_mode_attrs(mode, mode_spec, attr_set, print_request=True):
         """Print a given mode (do/dump/event/notify)."""
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next 3/3] tools: ynl: cli: Display enum values in --list-attrs output
  2025-11-16 19:28 [PATCH net-next 0/3] YNL CLI --list-attrs argument Gal Pressman
  2025-11-16 19:28 ` [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes Gal Pressman
  2025-11-16 19:28 ` [PATCH net-next 2/3] tools: ynl: cli: Parse nested attributes in --list-attrs output Gal Pressman
@ 2025-11-16 19:28 ` Gal Pressman
  2025-11-17 16:05   ` Donald Hunter
  2 siblings, 1 reply; 17+ messages in thread
From: Gal Pressman @ 2025-11-16 19:28 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, netdev
  Cc: Donald Hunter, Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, bpf,
	Gal Pressman, Nimrod Oren

When listing attributes with --list-attrs, display the actual enum
values for attributes that reference an enum type.

  # ./cli.py --family netdev --list-attrs dev-get
  [..]
    - xdp-features: u64 (enum: xdp-act)
      Values: basic, redirect, ndo-xmit, xsk-zerocopy, hw-offload, rx-sg, ndo-xmit-sg
      Bitmask of enabled xdp-features.
  [..]

Reviewed-by: Nimrod Oren <noren@nvidia.com>
Signed-off-by: Gal Pressman <gal@nvidia.com>
---
 tools/net/ynl/pyynl/cli.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py
index 3389e552ec4e..d305add514cd 100755
--- a/tools/net/ynl/pyynl/cli.py
+++ b/tools/net/ynl/pyynl/cli.py
@@ -139,7 +139,12 @@ def main():
                 attr = attr_set.attrs[attr_name]
                 attr_info = f'{prefix}- {attr_name}: {attr.type}'
                 if 'enum' in attr.yaml:
-                    attr_info += f" (enum: {attr.yaml['enum']})"
+                    enum_name = attr.yaml['enum']
+                    attr_info += f" (enum: {enum_name})"
+                    # Print enum values if available
+                    if enum_name in ynl.consts:
+                        enum_values = list(ynl.consts[enum_name].entries.keys())
+                        attr_info += f"\n{prefix}  Values: {', '.join(enum_values)}"
 
                 # Show nested attributes reference and recursively display them
                 nested_set_name = None
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
  2025-11-16 19:28 ` [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes Gal Pressman
@ 2025-11-17 15:56   ` Donald Hunter
  2025-11-18  9:38     ` Gal Pressman
  2025-11-18  1:35   ` Jakub Kicinski
  2025-11-18  1:38   ` Jakub Kicinski
  2 siblings, 1 reply; 17+ messages in thread
From: Donald Hunter @ 2025-11-17 15:56 UTC (permalink / raw)
  To: Gal Pressman
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, netdev, Simon Horman, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Stanislav Fomichev, bpf, Nimrod Oren

Gal Pressman <gal@nvidia.com> writes:

> Add a --list-attrs option to the YNL CLI that displays information about
> netlink operations, including request and reply attributes.
> This eliminates the need to manually inspect YAML spec files to
> determine the JSON structure required for operations, or understand the
> structure of the reply.

Thanks for the contribution, it's been on my wishlist for a while.

[...]

> +    def print_attr_list(attr_names, attr_set):
> +        """Print a list of attributes with their types and documentation."""
> +        for attr_name in attr_names:
> +            if attr_name in attr_set.attrs:
> +                attr = attr_set.attrs[attr_name]
> +                attr_info = f'  - {attr_name}: {attr.type}'
> +                if 'enum' in attr.yaml:
> +                    attr_info += f" (enum: {attr.yaml['enum']})"
> +                if attr.yaml.get('doc'):
> +                    doc_text = textwrap.indent(attr.yaml['doc'], '    ')
> +                    attr_info += f"\n{doc_text}"
> +                print(attr_info)
> +            else:
> +                print(f'  - {attr_name}')

Does this line execute? I think this scenario indicates a malformed
spec that would fail codegen.

> +    def print_mode_attrs(mode, mode_spec, attr_set, print_request=True):
> +        """Print a given mode (do/dump/event/notify)."""
> +        mode_title = mode.capitalize()
> +
> +        if print_request and 'request' in mode_spec and 'attributes' in mode_spec['request']:
> +            print(f'\n{mode_title} request attributes:')
> +            print_attr_list(mode_spec['request']['attributes'], attr_set)
> +
> +        if 'reply' in mode_spec and 'attributes' in mode_spec['reply']:
> +            print(f'\n{mode_title} reply attributes:')
> +            print_attr_list(mode_spec['reply']['attributes'], attr_set)
> +
> +        if 'attributes' in mode_spec:
> +            print(f'\n{mode_title} attributes:')
> +            print_attr_list(mode_spec['attributes'], attr_set)
> +
> +        if 'mcgrp' in mode_spec:
> +                print(f"Multicast group: {op.yaml['mcgrp']}")
> +
>      if args.list_ops:
>          for op_name, op in ynl.ops.items():
>              print(op_name, " [", ", ".join(op.modes), "]")
> @@ -135,6 +172,24 @@ def main():
>          for op_name, op in ynl.msgs.items():
>              print(op_name, " [", ", ".join(op.modes), "]")
>  
> +    if args.list_attrs:
> +        op = ynl.msgs.get(args.list_attrs)
> +        if not op:
> +            print(f'Operation {args.list_attrs} not found')
> +            exit(1)
> +
> +        print(f'Operation: {op.name}')
> +
> +        for mode in ['do', 'dump', 'event']:
> +            if mode in op.yaml:
> +                print_mode_attrs(mode, op.yaml[mode], op.attr_set, True)
> +
> +        if 'notify' in op.yaml:
> +            mode_spec = op.yaml['notify']
> +            ref_spec = ynl.msgs.get(mode_spec).yaml.get('do')
> +            if ref_spec:
> +                print_mode_attrs(mode, ref_spec, op.attr_set, False)

I guess mode is set to 'event' after the for loop. I'd prefer to not
see it used outside the loop, and just use literal 'event' here.

> +
>      try:
>          if args.do:
>              reply = ynl.do(args.do, attrs, args.flags)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 2/3] tools: ynl: cli: Parse nested attributes in --list-attrs output
  2025-11-16 19:28 ` [PATCH net-next 2/3] tools: ynl: cli: Parse nested attributes in --list-attrs output Gal Pressman
@ 2025-11-17 15:57   ` Donald Hunter
  0 siblings, 0 replies; 17+ messages in thread
From: Donald Hunter @ 2025-11-17 15:57 UTC (permalink / raw)
  To: Gal Pressman
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, netdev, Simon Horman, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Stanislav Fomichev, bpf, Nimrod Oren

Gal Pressman <gal@nvidia.com> writes:

> Enhance the --list-attrs option to recursively display nested attributes
> instead of just showing "nest" as the type.
> Nested attributes now show their attribute set name and expand to
> display their contents.
>
>   # ./cli.py --family ethtool --list-attrs rss-get
>   [..]
>   Do request attributes:
>     - header: nest -> header
>         - dev-index: u32
>         - dev-name: string
>         - flags: u32 (enum: header-flags)
>         - phy-index: u32
>     - context: u32
>   [..]
>
> Reviewed-by: Nimrod Oren <noren@nvidia.com>
> Signed-off-by: Gal Pressman <gal@nvidia.com>

Reviewed-by: Donald Hunter <donald.hunter@gmail.com>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 3/3] tools: ynl: cli: Display enum values in --list-attrs output
  2025-11-16 19:28 ` [PATCH net-next 3/3] tools: ynl: cli: Display enum values " Gal Pressman
@ 2025-11-17 16:05   ` Donald Hunter
  2025-11-18  9:35     ` Gal Pressman
  0 siblings, 1 reply; 17+ messages in thread
From: Donald Hunter @ 2025-11-17 16:05 UTC (permalink / raw)
  To: Gal Pressman
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, netdev, Simon Horman, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Stanislav Fomichev, bpf, Nimrod Oren

Gal Pressman <gal@nvidia.com> writes:

> When listing attributes with --list-attrs, display the actual enum
> values for attributes that reference an enum type.
>
>   # ./cli.py --family netdev --list-attrs dev-get
>   [..]
>     - xdp-features: u64 (enum: xdp-act)
>       Values: basic, redirect, ndo-xmit, xsk-zerocopy, hw-offload, rx-sg, ndo-xmit-sg
>       Bitmask of enabled xdp-features.
>   [..]
>
> Reviewed-by: Nimrod Oren <noren@nvidia.com>
> Signed-off-by: Gal Pressman <gal@nvidia.com>
> ---
>  tools/net/ynl/pyynl/cli.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py
> index 3389e552ec4e..d305add514cd 100755
> --- a/tools/net/ynl/pyynl/cli.py
> +++ b/tools/net/ynl/pyynl/cli.py
> @@ -139,7 +139,12 @@ def main():
>                  attr = attr_set.attrs[attr_name]
>                  attr_info = f'{prefix}- {attr_name}: {attr.type}'
>                  if 'enum' in attr.yaml:
> -                    attr_info += f" (enum: {attr.yaml['enum']})"
> +                    enum_name = attr.yaml['enum']
> +                    attr_info += f" (enum: {enum_name})"

Would be good to say enum | flags so that people know what semantics are valid.

> +                    # Print enum values if available
> +                    if enum_name in ynl.consts:
> +                        enum_values = list(ynl.consts[enum_name].entries.keys())
> +                        attr_info += f"\n{prefix}  Values: {', '.join(enum_values)}"

This produces quite noisy output for e.g.

./tools/net/ynl/pyynl/cli.py --family ethtool --list-attrs rss-get

Not sure what to suggest to improve readability but maybe it doesn't
need 'Values:' or commas, or perhaps only output each enum once?

>  
>                  # Show nested attributes reference and recursively display them
>                  nested_set_name = None

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
  2025-11-16 19:28 ` [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes Gal Pressman
  2025-11-17 15:56   ` Donald Hunter
@ 2025-11-18  1:35   ` Jakub Kicinski
  2025-11-18  9:20     ` Donald Hunter
  2025-11-18  9:38     ` Gal Pressman
  2025-11-18  1:38   ` Jakub Kicinski
  2 siblings, 2 replies; 17+ messages in thread
From: Jakub Kicinski @ 2025-11-18  1:35 UTC (permalink / raw)
  To: Gal Pressman
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Andrew Lunn, netdev,
	Donald Hunter, Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, bpf,
	Nimrod Oren

On Sun, 16 Nov 2025 21:28:43 +0200 Gal Pressman wrote:
> Add a --list-attrs option to the YNL CLI that displays information about
> netlink operations, including request and reply attributes.
> This eliminates the need to manually inspect YAML spec files to
> determine the JSON structure required for operations, or understand the
> structure of the reply.
> 
> Example usage:
>   # ./cli.py --family netdev --list-attrs dev-get
>   Operation: dev-get
> 
>   Do request attributes:
>     - ifindex: u32
>       netdev ifindex
> 
>   Do reply attributes:
>     - ifindex: u32
>       netdev ifindex
>     - xdp-features: u64 (enum: xdp-act)
>       Bitmask of enabled xdp-features.
>     - xdp-zc-max-segs: u32
>       max fragment count supported by ZC driver
>     - xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
>       Bitmask of supported XDP receive metadata features. See Documentation/networking/xdp-rx-metadata.rst for more details.
>     - xsk-features: u64 (enum: xsk-flags)
>       Bitmask of enabled AF_XDP features.
> 
>   Dump reply attributes:
>     - ifindex: u32
>       netdev ifindex
>     - xdp-features: u64 (enum: xdp-act)
>       Bitmask of enabled xdp-features.
>     - xdp-zc-max-segs: u32
>       max fragment count supported by ZC driver
>     - xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
>       Bitmask of supported XDP receive metadata features. See Documentation/networking/xdp-rx-metadata.rst for more details.
>     - xsk-features: u64 (enum: xsk-flags)
>       Bitmask of enabled AF_XDP features.

Could you try to detect that do and dump replies are identical 
and combine them? They are the same more often than not so 
I think it'd be nice to avoid printing the same info twice.

> Reviewed-by: Nimrod Oren <noren@nvidia.com>
> Signed-off-by: Gal Pressman <gal@nvidia.com>
> ---
>  tools/net/ynl/pyynl/cli.py | 55 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 55 insertions(+)
> 
> diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py
> index 8c192e900bd3..7ac3b4627f1b 100755
> --- a/tools/net/ynl/pyynl/cli.py
> +++ b/tools/net/ynl/pyynl/cli.py
> @@ -7,6 +7,7 @@ import os
>  import pathlib
>  import pprint
>  import sys
> +import textwrap
>  
>  sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix())
>  from lib import YnlFamily, Netlink, NlError
> @@ -70,6 +71,8 @@ def main():
>      group.add_argument('--dump', dest='dump', metavar='DUMP-OPERATION', type=str)
>      group.add_argument('--list-ops', action='store_true')
>      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')
>  
>      parser.add_argument('--duration', dest='duration', type=int,
>                          help='when subscribed, watch for DURATION seconds')
> @@ -128,6 +131,40 @@ def main():
>      if args.ntf:
>          ynl.ntf_subscribe(args.ntf)
>  
> +    def print_attr_list(attr_names, attr_set):

It nesting functions inside main() a common pattern for Python?
Having a function declared in the middle of another function,
does not seem optimal to me, but for some reason Claude loves
to do that.

> +        """Print a list of attributes with their types and documentation."""
> +        for attr_name in attr_names:
> +            if attr_name in attr_set.attrs:
> +                attr = attr_set.attrs[attr_name]
> +                attr_info = f'  - {attr_name}: {attr.type}'
> +                if 'enum' in attr.yaml:
> +                    attr_info += f" (enum: {attr.yaml['enum']})"
> +                if attr.yaml.get('doc'):
> +                    doc_text = textwrap.indent(attr.yaml['doc'], '    ')
> +                    attr_info += f"\n{doc_text}"
> +                print(attr_info)
> +            else:
> +                print(f'  - {attr_name}')
> +

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
  2025-11-16 19:28 ` [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes Gal Pressman
  2025-11-17 15:56   ` Donald Hunter
  2025-11-18  1:35   ` Jakub Kicinski
@ 2025-11-18  1:38   ` Jakub Kicinski
  2025-11-18  9:36     ` Gal Pressman
  2 siblings, 1 reply; 17+ messages in thread
From: Jakub Kicinski @ 2025-11-18  1:38 UTC (permalink / raw)
  To: Gal Pressman
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Andrew Lunn, netdev,
	Donald Hunter, Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, bpf,
	Nimrod Oren

On Sun, 16 Nov 2025 21:28:43 +0200 Gal Pressman wrote:
> Add a --list-attrs option to the YNL CLI that displays information about
> netlink operations, including request and reply attributes.
> This eliminates the need to manually inspect YAML spec files to
> determine the JSON structure required for operations, or understand the
> structure of the reply.

I _think_ these two pylint issues are new / should be fixed:

tools/net/ynl/pyynl/cli.py:166:0: W0311: Bad indentation. Found 16 spaces, expected 12 (bad-indentation)

tools/net/ynl/pyynl/cli.py:166:42: E0606: Possibly using variable 'op' before assignment (possibly-used-before-assignment)
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
  2025-11-18  1:35   ` Jakub Kicinski
@ 2025-11-18  9:20     ` Donald Hunter
  2025-11-18  9:38     ` Gal Pressman
  1 sibling, 0 replies; 17+ messages in thread
From: Donald Hunter @ 2025-11-18  9:20 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Gal Pressman, David S. Miller, Eric Dumazet, Paolo Abeni,
	Andrew Lunn, netdev, Simon Horman, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Stanislav Fomichev, bpf, Nimrod Oren

Jakub Kicinski <kuba@kernel.org> writes:

> On Sun, 16 Nov 2025 21:28:43 +0200 Gal Pressman wrote:
>>
>> +    def print_attr_list(attr_names, attr_set):
>
> It nesting functions inside main() a common pattern for Python?
> Having a function declared in the middle of another function,
> does not seem optimal to me, but for some reason Claude loves
> to do that.

It's common for closure-like things and for scoping. Reviewing this
again, these add a lot of noise to main() and would be better separated
out.

To be fair, I started it with `def output(msg)` but I'd argue it is a
closure-like scoped helper thing :-)

>> +        """Print a list of attributes with their types and documentation."""
>> +        for attr_name in attr_names:
>> +            if attr_name in attr_set.attrs:
>> +                attr = attr_set.attrs[attr_name]
>> +                attr_info = f'  - {attr_name}: {attr.type}'
>> +                if 'enum' in attr.yaml:
>> +                    attr_info += f" (enum: {attr.yaml['enum']})"
>> +                if attr.yaml.get('doc'):
>> +                    doc_text = textwrap.indent(attr.yaml['doc'], '    ')
>> +                    attr_info += f"\n{doc_text}"
>> +                print(attr_info)
>> +            else:
>> +                print(f'  - {attr_name}')
>> +

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 3/3] tools: ynl: cli: Display enum values in --list-attrs output
  2025-11-17 16:05   ` Donald Hunter
@ 2025-11-18  9:35     ` Gal Pressman
  0 siblings, 0 replies; 17+ messages in thread
From: Gal Pressman @ 2025-11-18  9:35 UTC (permalink / raw)
  To: Donald Hunter
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, netdev, Simon Horman, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Stanislav Fomichev, bpf, Nimrod Oren

On 17/11/2025 18:05, Donald Hunter wrote:
>> diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py
>> index 3389e552ec4e..d305add514cd 100755
>> --- a/tools/net/ynl/pyynl/cli.py
>> +++ b/tools/net/ynl/pyynl/cli.py
>> @@ -139,7 +139,12 @@ def main():
>>                  attr = attr_set.attrs[attr_name]
>>                  attr_info = f'{prefix}- {attr_name}: {attr.type}'
>>                  if 'enum' in attr.yaml:
>> -                    attr_info += f" (enum: {attr.yaml['enum']})"
>> +                    enum_name = attr.yaml['enum']
>> +                    attr_info += f" (enum: {enum_name})"
> 
> Would be good to say enum | flags so that people know what semantics are valid.

I changed "Values: " to "enum:"/"flags:".

> 
>> +                    # Print enum values if available
>> +                    if enum_name in ynl.consts:
>> +                        enum_values = list(ynl.consts[enum_name].entries.keys())
>> +                        attr_info += f"\n{prefix}  Values: {', '.join(enum_values)}"
> 
> This produces quite noisy output for e.g.
> 
> ./tools/net/ynl/pyynl/cli.py --family ethtool --list-attrs rss-get
> 
> Not sure what to suggest to improve readability but maybe it doesn't
> need 'Values:' or commas, or perhaps only output each enum once?

Values was replaced, I don't see how removing the commas improves the
situation.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
  2025-11-18  1:38   ` Jakub Kicinski
@ 2025-11-18  9:36     ` Gal Pressman
  0 siblings, 0 replies; 17+ messages in thread
From: Gal Pressman @ 2025-11-18  9:36 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Andrew Lunn, netdev,
	Donald Hunter, Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, bpf,
	Nimrod Oren

On 18/11/2025 3:38, Jakub Kicinski wrote:
> On Sun, 16 Nov 2025 21:28:43 +0200 Gal Pressman wrote:
>> Add a --list-attrs option to the YNL CLI that displays information about
>> netlink operations, including request and reply attributes.
>> This eliminates the need to manually inspect YAML spec files to
>> determine the JSON structure required for operations, or understand the
>> structure of the reply.
> 
> I _think_ these two pylint issues are new / should be fixed:
> 
> tools/net/ynl/pyynl/cli.py:166:0: W0311: Bad indentation. Found 16 spaces, expected 12 (bad-indentation)
> 
> tools/net/ynl/pyynl/cli.py:166:42: E0606: Possibly using variable 'op' before assignment (possibly-used-before-assignment)

Will do.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
  2025-11-18  1:35   ` Jakub Kicinski
  2025-11-18  9:20     ` Donald Hunter
@ 2025-11-18  9:38     ` Gal Pressman
  2025-11-18 17:13       ` Jakub Kicinski
  1 sibling, 1 reply; 17+ messages in thread
From: Gal Pressman @ 2025-11-18  9:38 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Andrew Lunn, netdev,
	Donald Hunter, Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, bpf,
	Nimrod Oren

On 18/11/2025 3:35, Jakub Kicinski wrote:
>>   Do reply attributes:
>>     - ifindex: u32
>>       netdev ifindex
>>     - xdp-features: u64 (enum: xdp-act)
>>       Bitmask of enabled xdp-features.
>>     - xdp-zc-max-segs: u32
>>       max fragment count supported by ZC driver
>>     - xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
>>       Bitmask of supported XDP receive metadata features. See Documentation/networking/xdp-rx-metadata.rst for more details.
>>     - xsk-features: u64 (enum: xsk-flags)
>>       Bitmask of enabled AF_XDP features.
>>
>>   Dump reply attributes:
>>     - ifindex: u32
>>       netdev ifindex
>>     - xdp-features: u64 (enum: xdp-act)
>>       Bitmask of enabled xdp-features.
>>     - xdp-zc-max-segs: u32
>>       max fragment count supported by ZC driver
>>     - xdp-rx-metadata-features: u64 (enum: xdp-rx-metadata)
>>       Bitmask of supported XDP receive metadata features. See Documentation/networking/xdp-rx-metadata.rst for more details.
>>     - xsk-features: u64 (enum: xsk-flags)
>>       Bitmask of enabled AF_XDP features.
> 
> Could you try to detect that do and dump replies are identical 
> and combine them? They are the same more often than not so 
> I think it'd be nice to avoid printing the same info twice.

We need to take care of both cases where the whole operation is
identical (e.g., ethtool debug-get), and cases where only the replies
are identical (e.g., netdev dev-get). This kind of complicates the code.

I'll give it a few more attempts, but maybe this should come as a
followup to this series.

>> @@ -128,6 +131,40 @@ def main():
>>      if args.ntf:
>>          ynl.ntf_subscribe(args.ntf)
>>  
>> +    def print_attr_list(attr_names, attr_set):
> 
> It nesting functions inside main() a common pattern for Python?
> Having a function declared in the middle of another function,
> does not seem optimal to me, but for some reason Claude loves
> to do that.

I used output() as a reference, but I'll move it outside.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
  2025-11-17 15:56   ` Donald Hunter
@ 2025-11-18  9:38     ` Gal Pressman
  0 siblings, 0 replies; 17+ messages in thread
From: Gal Pressman @ 2025-11-18  9:38 UTC (permalink / raw)
  To: Donald Hunter
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, netdev, Simon Horman, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Stanislav Fomichev, bpf, Nimrod Oren

On 17/11/2025 17:56, Donald Hunter wrote:
>> +    def print_attr_list(attr_names, attr_set):
>> +        """Print a list of attributes with their types and documentation."""
>> +        for attr_name in attr_names:
>> +            if attr_name in attr_set.attrs:
>> +                attr = attr_set.attrs[attr_name]
>> +                attr_info = f'  - {attr_name}: {attr.type}'
>> +                if 'enum' in attr.yaml:
>> +                    attr_info += f" (enum: {attr.yaml['enum']})"
>> +                if attr.yaml.get('doc'):
>> +                    doc_text = textwrap.indent(attr.yaml['doc'], '    ')
>> +                    attr_info += f"\n{doc_text}"
>> +                print(attr_info)
>> +            else:
>> +                print(f'  - {attr_name}')
> 
> Does this line execute? I think this scenario indicates a malformed
> spec that would fail codegen.

You're right, removed.

>> +    if args.list_attrs:
>> +        op = ynl.msgs.get(args.list_attrs)
>> +        if not op:
>> +            print(f'Operation {args.list_attrs} not found')
>> +            exit(1)
>> +
>> +        print(f'Operation: {op.name}')
>> +
>> +        for mode in ['do', 'dump', 'event']:
>> +            if mode in op.yaml:
>> +                print_mode_attrs(mode, op.yaml[mode], op.attr_set, True)
>> +
>> +        if 'notify' in op.yaml:
>> +            mode_spec = op.yaml['notify']
>> +            ref_spec = ynl.msgs.get(mode_spec).yaml.get('do')
>> +            if ref_spec:
>> +                print_mode_attrs(mode, ref_spec, op.attr_set, False)
> 
> I guess mode is set to 'event' after the for loop. I'd prefer to not
> see it used outside the loop, and just use literal 'event' here.

This is actually a bug, mode needs to be 'notify'.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
  2025-11-18  9:38     ` Gal Pressman
@ 2025-11-18 17:13       ` Jakub Kicinski
  2025-11-19 11:36         ` Gal Pressman
  0 siblings, 1 reply; 17+ messages in thread
From: Jakub Kicinski @ 2025-11-18 17:13 UTC (permalink / raw)
  To: Gal Pressman
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Andrew Lunn, netdev,
	Donald Hunter, Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, bpf,
	Nimrod Oren

On Tue, 18 Nov 2025 11:38:04 +0200 Gal Pressman wrote:
> > Could you try to detect that do and dump replies are identical 
> > and combine them? They are the same more often than not so 
> > I think it'd be nice to avoid printing the same info twice.  
> 
> We need to take care of both cases where the whole operation is
> identical (e.g., ethtool debug-get), and cases where only the replies
> are identical (e.g., netdev dev-get). This kind of complicates the code.

I was thinking just the reply. This is mostly for GET type operations.
Request doesn't exist for DUMP, but for DO it carries ID.

> I'll give it a few more attempts, but maybe this should come as a
> followup to this series.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
  2025-11-18 17:13       ` Jakub Kicinski
@ 2025-11-19 11:36         ` Gal Pressman
  2025-11-19 14:20           ` Jakub Kicinski
  0 siblings, 1 reply; 17+ messages in thread
From: Gal Pressman @ 2025-11-19 11:36 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Andrew Lunn, netdev,
	Donald Hunter, Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, bpf,
	Nimrod Oren

On 18/11/2025 19:13, Jakub Kicinski wrote:
> On Tue, 18 Nov 2025 11:38:04 +0200 Gal Pressman wrote:
>>> Could you try to detect that do and dump replies are identical 
>>> and combine them? They are the same more often than not so 
>>> I think it'd be nice to avoid printing the same info twice.  
>>
>> We need to take care of both cases where the whole operation is
>> identical (e.g., ethtool debug-get), and cases where only the replies
>> are identical (e.g., netdev dev-get). This kind of complicates the code.
> 
> I was thinking just the reply. This is mostly for GET type operations.
> Request doesn't exist for DUMP, but for DO it carries ID.

Some dumps have requests, like ethtool's debug-get or strset-get.
I have a patch that detects identical replies, but it's quite ugly TBH.
I'd prefer to keep the code as is, but up to you.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes
  2025-11-19 11:36         ` Gal Pressman
@ 2025-11-19 14:20           ` Jakub Kicinski
  0 siblings, 0 replies; 17+ messages in thread
From: Jakub Kicinski @ 2025-11-19 14:20 UTC (permalink / raw)
  To: Gal Pressman
  Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Andrew Lunn, netdev,
	Donald Hunter, Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev, bpf,
	Nimrod Oren

On Wed, 19 Nov 2025 13:36:09 +0200 Gal Pressman wrote:
> On 18/11/2025 19:13, Jakub Kicinski wrote:
> > On Tue, 18 Nov 2025 11:38:04 +0200 Gal Pressman wrote:  
> >> We need to take care of both cases where the whole operation is
> >> identical (e.g., ethtool debug-get), and cases where only the replies
> >> are identical (e.g., netdev dev-get). This kind of complicates the code.  
> > 
> > I was thinking just the reply. This is mostly for GET type operations.
> > Request doesn't exist for DUMP, but for DO it carries ID.  
> 
> Some dumps have requests, like ethtool's debug-get or strset-get.
> I have a patch that detects identical replies, but it's quite ugly TBH.
> I'd prefer to keep the code as is, but up to you.

It's alright. I'll poke at it after merging, but if we can't find 
a clean way it's fine.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-11-19 14:20 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-16 19:28 [PATCH net-next 0/3] YNL CLI --list-attrs argument Gal Pressman
2025-11-16 19:28 ` [PATCH net-next 1/3] tools: ynl: cli: Add --list-attrs option to show operation attributes Gal Pressman
2025-11-17 15:56   ` Donald Hunter
2025-11-18  9:38     ` Gal Pressman
2025-11-18  1:35   ` Jakub Kicinski
2025-11-18  9:20     ` Donald Hunter
2025-11-18  9:38     ` Gal Pressman
2025-11-18 17:13       ` Jakub Kicinski
2025-11-19 11:36         ` Gal Pressman
2025-11-19 14:20           ` Jakub Kicinski
2025-11-18  1:38   ` Jakub Kicinski
2025-11-18  9:36     ` Gal Pressman
2025-11-16 19:28 ` [PATCH net-next 2/3] tools: ynl: cli: Parse nested attributes in --list-attrs output Gal Pressman
2025-11-17 15:57   ` Donald Hunter
2025-11-16 19:28 ` [PATCH net-next 3/3] tools: ynl: cli: Display enum values " Gal Pressman
2025-11-17 16:05   ` Donald Hunter
2025-11-18  9:35     ` Gal Pressman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).