From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net,
edumazet@google.com, jacob.e.keller@intel.com,
swarupkotikalapudi@gmail.com, donald.hunter@gmail.com,
sdf@google.com, lorenzo@kernel.org,
alessandromarcolini99@gmail.com
Subject: [patch net-next 07/13] tools: ynl: add support for list in nested attribute
Date: Mon, 19 Feb 2024 18:25:23 +0100 [thread overview]
Message-ID: <20240219172525.71406-8-jiri@resnulli.us> (raw)
In-Reply-To: <20240219172525.71406-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@nvidia.com>
Some nested attributes, like devlink-fmg, contain plain list of
attributes that may repeat. Current decode rsp implementation is
dictionary which causes duplicate attributes to be re-written.
To solve this, introduce "nested-list" flag for "nest" type which
indicates the _decode() function to use list instead of dictionary and
store each decoded attribute into this list as a separate dictionary.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
Documentation/netlink/genetlink-legacy.yaml | 3 +++
tools/net/ynl/lib/ynl.py | 18 ++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml
index 77d89f81c71f..0e0ee3b4ff5f 100644
--- a/Documentation/netlink/genetlink-legacy.yaml
+++ b/Documentation/netlink/genetlink-legacy.yaml
@@ -220,6 +220,9 @@ properties:
nested-attributes:
description: Name of the space (sub-space) used inside the attribute.
type: string
+ nested-list:
+ description: The nested attribute contains a list of attributes.
+ type: boolean
enum:
description: Name of the enum type used for the attribute.
type: string
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 8591e6bfe40b..08fe27c8dec7 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -386,8 +386,12 @@ class SpaceAttrs:
def lookup(self, name):
for scope in self.scopes:
if name in scope.spec:
- if name in scope.values:
+ if isinstance(scope.values, dict) and name in scope.values:
return scope.values[name]
+ if isinstance(scope.values, list):
+ for item in reversed(scope.values):
+ if name in item:
+ return item[name]
spec_name = scope.spec.yaml['name']
raise Exception(
f"No value for '{name}' in attribute space '{spec_name}'")
@@ -568,6 +572,10 @@ class YnlFamily(SpecFamily):
return attr.as_bin()
def _rsp_add(self, rsp, name, is_multi, decoded):
+ if isinstance(rsp, list):
+ rsp.append({name: decoded})
+ return
+
if is_multi == None:
if name in rsp and type(rsp[name]) is not list:
rsp[name] = [rsp[name]]
@@ -620,8 +628,8 @@ class YnlFamily(SpecFamily):
raise Exception(f"Unknown attribute-set '{attr_space}' when decoding '{attr_spec.name}'")
return decoded
- def _decode(self, attrs, space, outer_attrs = None):
- rsp = dict()
+ def _decode(self, attrs, space, outer_attrs = None, to_list = False):
+ rsp = list() if to_list else dict()
if space:
attr_space = self.attr_sets[space]
search_attrs = SpaceAttrs(attr_space, rsp, outer_attrs)
@@ -637,7 +645,9 @@ class YnlFamily(SpecFamily):
continue
if attr_spec["type"] == 'nest':
- subdict = self._decode(NlAttrs(attr.raw), attr_spec['nested-attributes'], search_attrs)
+ nested_list = attr_spec['nested-list'] if 'nested-list' in attr_spec else False
+ subdict = self._decode(NlAttrs(attr.raw), attr_spec['nested-attributes'],
+ search_attrs, to_list = nested_list)
decoded = subdict
elif attr_spec["type"] == 'string':
decoded = attr.as_strz()
--
2.43.2
next prev parent reply other threads:[~2024-02-19 17:25 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-19 17:25 [patch net-next 00/13] netlink: specs: devlink: add the rest of missing attribute definitions Jiri Pirko
2024-02-19 17:25 ` [patch net-next 01/13] tools: ynl: allow user to specify flag attr with bool values Jiri Pirko
2024-02-19 20:42 ` Jakub Kicinski
2024-02-20 7:24 ` Jiri Pirko
2024-02-19 17:25 ` [patch net-next 02/13] tools: ynl: process all scalar types encoding in single elif statement Jiri Pirko
2024-02-19 17:25 ` [patch net-next 03/13] tools: ynl: allow user to pass enum string instead of scalar value Jiri Pirko
2024-02-19 20:49 ` Jakub Kicinski
2024-02-20 7:25 ` Jiri Pirko
2024-02-21 1:55 ` Jakub Kicinski
2024-02-21 14:31 ` Jiri Pirko
2024-02-19 20:51 ` Jakub Kicinski
2024-02-20 7:27 ` Jiri Pirko
2024-02-21 1:59 ` Jakub Kicinski
2024-02-21 11:40 ` Donald Hunter
2024-02-19 17:25 ` [patch net-next 04/13] netlink: specs: allow sub-messages in genetlink-legacy Jiri Pirko
2024-02-19 20:51 ` Jakub Kicinski
2024-02-20 7:28 ` Jiri Pirko
2024-02-19 17:25 ` [patch net-next 05/13] tools: ynl: allow attr in a subset to be of a different type Jiri Pirko
2024-02-19 17:25 ` [patch net-next 06/13] tools: ynl: introduce attribute-replace for sub-message Jiri Pirko
2024-02-19 22:52 ` Jakub Kicinski
2024-02-20 7:31 ` Jiri Pirko
2024-02-21 2:10 ` Jakub Kicinski
2024-02-21 12:48 ` Jiri Pirko
2024-02-21 18:45 ` Jakub Kicinski
2024-02-22 13:20 ` Jiri Pirko
2024-02-19 17:25 ` Jiri Pirko [this message]
2024-02-19 17:25 ` [patch net-next 08/13] netlink: specs: devlink: add enum for param-type attribute values Jiri Pirko
2024-02-19 17:25 ` [patch net-next 09/13] netlink: specs: devlink: add missing param attribute definitions Jiri Pirko
2024-02-19 17:26 ` [patch net-next 10/13] netlink: specs: devlink: treat dl-fmsg attribute as list Jiri Pirko
2024-02-19 17:26 ` [patch net-next 11/13] netlink: specs: devlink: add enum for fmsg-obj-value-type attribute values Jiri Pirko
2024-02-19 17:26 ` [patch net-next 12/13] netlink: specs: devlink: add missing fmsg-obj-value-data attribute definitions Jiri Pirko
2024-02-19 17:26 ` [patch net-next 13/13] netlink: specs: devlink: add missing nested devlink definitions Jiri Pirko
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=20240219172525.71406-8-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=alessandromarcolini99@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=jacob.e.keller@intel.com \
--cc=kuba@kernel.org \
--cc=lorenzo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.com \
--cc=swarupkotikalapudi@gmail.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).