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 3/7] tools: ynl: support ignore-index in indexed-array encoding
Date: Wed, 22 Oct 2025 18:26:56 +0000	[thread overview]
Message-ID: <20251022182701.250897-4-ast@fiberby.net> (raw)
In-Reply-To: <20251022182701.250897-1-ast@fiberby.net>

When parsing indexed-array attributes to cli.py's --json, then
previously the index would always be set incrementally.

This patch adds support for setting arbitrary indexes, when
`ignore-index` is set to false or is unspecified.

When `ignore-index` is set to true, then it retains the current
input format, and it's alignment with the output from cli.py.

The below examples are fictive as `rates` is not used in requests.
The implementation have been tested with a newer version of the
previously posted wireguard spec[1].

When `rates` have `ignore-index` set to false (or unspecified):
  --json '{"rates":[ [0,{"rate":60}], [42,{"rate":90}] ]}'

When `rates` have `ignore-index` set to true:
  --json '{"rates":[ {"rate":60}, {"rate":90} ]}'

[1] https://lore.kernel.org/netdev/20250904-wg-ynl-rfc@fiberby.net/

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

diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py
index 14c7e51db6f5c..a284bc2ad3440 100644
--- a/tools/net/ynl/pyynl/lib/ynl.py
+++ b/tools/net/ynl/pyynl/lib/ynl.py
@@ -566,8 +566,9 @@ class YnlFamily(SpecFamily):
         elif attr['type'] == 'indexed-array' and attr['sub-type'] == 'nest':
             nl_type |= Netlink.NLA_F_NESTED
             sub_space = attr['nested-attributes']
+            ignore_idx = attr.get('ignore-index', False)
             attr_payload = self._encode_indexed_array(value, sub_space,
-                                                      search_attrs)
+                                                      search_attrs, ignore_idx)
         elif attr["type"] == 'flag':
             if not value:
                 # If value is absent or false then skip attribute creation.
@@ -635,9 +636,11 @@ class YnlFamily(SpecFamily):
                                            sub_attrs)
         return attr_payload
 
-    def _encode_indexed_array(self, vals, sub_space, search_attrs):
+    def _encode_indexed_array(self, vals, sub_space, search_attrs, ignore_idx):
         attr_payload = b''
         for i, val in enumerate(vals):
+            if not ignore_idx:
+                i, val = val[0], val[1]
             idx = i | Netlink.NLA_F_NESTED
             val_payload = self._add_nest_attrs(val, sub_space, search_attrs)
             attr_payload += self._add_attr_raw(idx, val_payload)
-- 
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 ` [PATCH net-next 2/7] tools: ynl: support ignore-index in indexed-array decoding 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 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-4-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®