From: Hangbin Liu <liuhangbin@gmail.com>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Donald Hunter <donald.hunter@gmail.com>,
Jiri Pirko <jiri@resnulli.us>,
Jacob Keller <jacob.e.keller@intel.com>,
Stanislav Fomichev <sdf@google.com>,
Hangbin Liu <liuhangbin@gmail.com>
Subject: [PATCH net-next 2/2] ynl: support un-nest sub-type for indexed-array
Date: Tue, 26 Mar 2024 14:37:28 +0800 [thread overview]
Message-ID: <20240326063728.2369353-3-liuhangbin@gmail.com> (raw)
In-Reply-To: <20240326063728.2369353-1-liuhangbin@gmail.com>
Support un-nest sub-type for indexed-array. Since all the attr types are
same for un-nest sub-ype, the index number is used as attr name.
The result would look like:
# ip link add bond0 type bond mode 1 \
arp_ip_target 192.168.1.1,192.168.1.2 ns_ip6_target 2001::1,2001::2
# ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/rt_link.yaml \
--do getlink --json '{"ifname": "bond0"}' --output-json | jq '.linkinfo'
"arp-ip-target": [
{
"1": "192.168.1.1"
},
{
"2": "192.168.1.2"
}
],
[...]
"ns-ip6-target": [
{
"1": "2001::1"
},
{
"2": "2001::2"
}
],
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
tools/net/ynl/lib/ynl.py | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 7239e673a28a..58a602ff9544 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -595,6 +595,21 @@ class YnlFamily(SpecFamily):
decoded.append({ item.type: subattrs })
return decoded
+ def _decode_index_array(self, attr, attr_spec):
+ decoded = []
+ offset = 0
+ index = 0
+ while offset < len(attr.raw):
+ index = index + 1
+ item = NlAttr(attr.raw, offset)
+ offset += item.full_len
+
+ subattrs = item.as_bin()
+ if attr_spec.display_hint:
+ subattrs = self._formatted_string(subattrs, attr_spec.display_hint)
+ decoded.append({ index: subattrs })
+ return decoded
+
def _decode_nest_type_value(self, attr, attr_spec):
decoded = {}
value = attr
@@ -689,6 +704,8 @@ class YnlFamily(SpecFamily):
elif attr_spec["type"] == 'indexed-array' and 'sub-type' in attr_spec:
if attr_spec["sub-type"] == 'nest':
decoded = self._decode_array_nest(attr, attr_spec)
+ else:
+ decoded = self._decode_index_array(attr, attr_spec)
elif attr_spec["type"] == 'bitfield32':
value, selector = struct.unpack("II", attr.raw)
if 'enum' in attr_spec:
--
2.43.0
next prev parent reply other threads:[~2024-03-26 6:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-26 6:37 [PATCH net-next 0/2] ynl: rename array-nest to indexed-array Hangbin Liu
2024-03-26 6:37 ` [PATCH net-next 1/2] " Hangbin Liu
2024-03-27 3:46 ` Jakub Kicinski
2024-03-28 7:50 ` Hangbin Liu
2024-03-28 16:02 ` Jakub Kicinski
2024-03-26 6:37 ` Hangbin Liu [this message]
2024-03-28 7:41 ` [PATCH net-next 2/2] ynl: support un-nest sub-type for indexed-array Hangbin Liu
2024-03-28 16:04 ` 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=20240326063728.2369353-3-liuhangbin@gmail.com \
--to=liuhangbin@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=jacob.e.keller@intel.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.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;
as well as URLs for NNTP newsgroup(s).