mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Asbjørn Sloth Tønnesen" <ast@fiberby.net>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: "Asbjørn Sloth Tønnesen" <ast@fiberby.net>,
	"Chia-Yu Chang" <chia-yu.chang@nokia-bell-labs.com>,
	"Chuck Lever" <chuck.lever@oracle.com>,
	"Donald Hunter" <donald.hunter@gmail.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Matthieu Baerts (NGI0)" <matttbe@kernel.org>,
	"Simon Horman" <horms@kernel.org>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org
Subject: [PATCH net-next 2/7] tools: ynl: support ignore-index in indexed-array decoding
Date: Wed, 22 Oct 2025 18:26:55 +0000	[thread overview]
Message-ID: <20251022182701.250897-3-ast@fiberby.net> (raw)
In-Reply-To: <20251022182701.250897-1-ast@fiberby.net>

When decoding indexed-arrays with `ignore-index` set, then
elide the index, aka. the nested attribute-type.

Previously the index was always preserved for sub-type nest,
but was elided for all other sub-types.

I have opted to reuse the existing `subattr` variable, as renaming
it will render the diff unreadable at least for this version.

Output if `rates` does NOT have `ignore-index` set:
  $ ./tools/net/ynl/pyynl/cli.py --family nl80211 --dump get-wiphy
  [...]
  'rates': [{0: {'rate': 60}},
            {1: {'rate': 90}},
            {2: {'rate': 120}},
            {3: {'rate': 180}},
            {4: {'rate': 240}},
            [...]

Output if `rates` has `ignore-index` set to true:
  $ ./tools/net/ynl/pyynl/cli.py --family nl80211 --dump get-wiphy
  [...]
  'rates': [{'rate': 60},
            {'rate': 90},
            {'rate': 120},
            {'rate': 180},
            {'rate': 240},
            [...]

If the above example had to be passed back though --json, then it
now aligns with the new output format, and would look like this:
  --json '{"rates":[ {"rate":60}, {"rate":90}, ... ]}'

Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
---
 tools/net/ynl/pyynl/lib/ynl.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py
index 62383c70ebb95..14c7e51db6f5c 100644
--- a/tools/net/ynl/pyynl/lib/ynl.py
+++ b/tools/net/ynl/pyynl/lib/ynl.py
@@ -690,23 +690,26 @@ class YnlFamily(SpecFamily):
             item = NlAttr(attr.raw, offset)
             offset += item.full_len
 
+            subattr = None
             if attr_spec["sub-type"] == 'nest':
-                subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
-                decoded.append({ item.type: subattrs })
+                subattr = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
             elif attr_spec["sub-type"] == 'binary':
                 subattr = item.as_bin()
                 if attr_spec.display_hint:
                     subattr = self._formatted_string(subattr, attr_spec.display_hint)
-                decoded.append(subattr)
             elif attr_spec["sub-type"] in NlAttr.type_formats:
                 subattr = item.as_scalar(attr_spec['sub-type'], attr_spec.byte_order)
                 if 'enum' in attr_spec:
                     subattr = self._decode_enum(subattr, attr_spec)
                 elif attr_spec.display_hint:
                     subattr = self._formatted_string(subattr, attr_spec.display_hint)
-                decoded.append(subattr)
             else:
                 raise Exception(f'Unknown {attr_spec["sub-type"]} with name {attr_spec["name"]}')
+
+            if attr_spec.get('ignore-index', False):
+                decoded.append(subattr)
+            else:
+                decoded.append({ item.type: subattr })
         return decoded
 
     def _decode_nest_type_value(self, attr, attr_spec):
-- 
2.51.0


  parent reply	other threads:[~2025-10-22 18:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-22 18:26 [PATCH net-next 0/7] ynl: add ignore-index flag for indexed-array Asbjørn Sloth Tønnesen
2025-10-22 18:26 ` [PATCH net-next 1/7] netlink: specs: " Asbjørn Sloth Tønnesen
2025-10-22 18:26 ` Asbjørn Sloth Tønnesen [this message]
2025-10-22 18:26 ` [PATCH net-next 3/7] tools: ynl: support ignore-index in indexed-array encoding Asbjørn Sloth Tønnesen
2025-10-22 18:26 ` [PATCH net-next 4/7] netlink: specs: nl80211: set ignore-index on indexed-arrays Asbjørn Sloth Tønnesen
2025-10-22 18:26 ` [PATCH net-next 5/7] netlink: specs: nlctrl: " Asbjørn Sloth Tønnesen
2025-10-22 18:26 ` [PATCH net-next 6/7] netlink: specs: rt-link: " Asbjørn Sloth Tønnesen
2025-10-22 18:27 ` [PATCH net-next 7/7] netlink: specs: tc: " Asbjørn Sloth Tønnesen
2025-10-23  1:45 ` [PATCH net-next 0/7] ynl: add ignore-index flag for indexed-array Jakub Kicinski
2025-10-23 18:37   ` Asbjørn Sloth Tønnesen
2025-10-24  0:03     ` Jakub Kicinski
2025-10-24 19:19       ` Asbjørn Sloth Tønnesen
2025-10-24 23:52         ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251022182701.250897-3-ast@fiberby.net \
    --to=ast@fiberby.net \
    --cc=chia-yu.chang@nokia-bell-labs.com \
    --cc=chuck.lever@oracle.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matttbe@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®