lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251022182701.250897-3-ast@fiberby.net>
Date: Wed, 22 Oct 2025 18:26:55 +0000
From: Asbjørn Sloth Tønnesen <ast@...erby.net>
To: "David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>
Cc: Asbjørn Sloth Tønnesen <ast@...erby.net>,
	Chia-Yu Chang <chia-yu.chang@...ia-bell-labs.com>,
	Chuck Lever <chuck.lever@...cle.com>,
	Donald Hunter <donald.hunter@...il.com>,
	Jonathan Corbet <corbet@....net>,
	"Matthieu Baerts (NGI0)" <matttbe@...nel.org>,
	Simon Horman <horms@...nel.org>,
	linux-doc@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	netdev@...r.kernel.org
Subject: [PATCH net-next 2/7] tools: ynl: support ignore-index in indexed-array decoding

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@...erby.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ