[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240326063728.2369353-3-liuhangbin@gmail.com>
Date: Tue, 26 Mar 2024 14:37:28 +0800
From: Hangbin Liu <liuhangbin@...il.com>
To: netdev@...r.kernel.org
Cc: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Donald Hunter <donald.hunter@...il.com>,
Jiri Pirko <jiri@...nulli.us>,
Jacob Keller <jacob.e.keller@...el.com>,
Stanislav Fomichev <sdf@...gle.com>,
Hangbin Liu <liuhangbin@...il.com>
Subject: [PATCH net-next 2/2] ynl: support un-nest sub-type for indexed-array
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@...il.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
Powered by blists - more mailing lists