From: Donald Hunter <donald.hunter@gmail.com>
To: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Jacob Keller <jacob.e.keller@intel.com>,
Jiri Pirko <jiri@resnulli.us>,
Stanislav Fomichev <sdf@google.com>
Cc: donald.hunter@redhat.com, Donald Hunter <donald.hunter@gmail.com>
Subject: [PATCH net-next v1 3/4] tools/net/ynl: Extend array-nest for multi level nesting
Date: Fri, 1 Mar 2024 17:14:30 +0000 [thread overview]
Message-ID: <20240301171431.65892-4-donald.hunter@gmail.com> (raw)
In-Reply-To: <20240301171431.65892-1-donald.hunter@gmail.com>
The nlctrl family uses 2 levels of array nesting for policy attributes.
Add a 'nest-depth' property to genetlink-legacy and extend ynl to use
it.
Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
Documentation/netlink/genetlink-legacy.yaml | 3 +++
tools/net/ynl/lib/nlspec.py | 2 ++
tools/net/ynl/lib/ynl.py | 9 ++++++---
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml
index 938703088306..872c76065f1b 100644
--- a/Documentation/netlink/genetlink-legacy.yaml
+++ b/Documentation/netlink/genetlink-legacy.yaml
@@ -261,6 +261,9 @@ properties:
struct:
description: Name of the struct type used for the attribute.
type: string
+ nest-depth:
+ description: Depth of nesting for an array-nest, defaults to 1.
+ type: integer
# End genetlink-legacy
# Make sure name-prefix does not appear in subsets (subsets inherit naming)
diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
index fbce52395b3b..50e8447f089a 100644
--- a/tools/net/ynl/lib/nlspec.py
+++ b/tools/net/ynl/lib/nlspec.py
@@ -161,6 +161,7 @@ class SpecAttr(SpecElement):
sub_message string, name of sub message type
selector string, name of attribute used to select
sub-message type
+ nest_depth integer, depth of array nesting
is_auto_scalar bool, attr is a variable-size scalar
"""
@@ -178,6 +179,7 @@ class SpecAttr(SpecElement):
self.display_hint = yaml.get('display-hint')
self.sub_message = yaml.get('sub-message')
self.selector = yaml.get('selector')
+ self.nest_depth = yaml.get('nest-depth', 1)
self.is_auto_scalar = self.type == "sint" or self.type == "uint"
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 29262505a3f2..efceea9433f2 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -556,14 +556,17 @@ class YnlFamily(SpecFamily):
decoded = self._formatted_string(decoded, attr_spec.display_hint)
return decoded
- def _decode_array_nest(self, attr, attr_spec):
+ def _decode_array_nest(self, attr, attr_spec, depth):
decoded = []
offset = 0
while offset < len(attr.raw):
item = NlAttr(attr.raw, offset)
offset += item.full_len
- subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
+ if depth > 1:
+ subattrs = self._decode_array_nest(item, attr_spec, depth - 1)
+ else:
+ subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
decoded.append({ item.type: subattrs })
return decoded
@@ -649,7 +652,7 @@ class YnlFamily(SpecFamily):
if 'enum' in attr_spec:
decoded = self._decode_enum(decoded, attr_spec)
elif attr_spec["type"] == 'array-nest':
- decoded = self._decode_array_nest(attr, attr_spec)
+ decoded = self._decode_array_nest(attr, attr_spec, attr_spec.nest_depth)
elif attr_spec["type"] == 'bitfield32':
value, selector = struct.unpack("II", attr.raw)
if 'enum' in attr_spec:
--
2.42.0
next prev parent reply other threads:[~2024-03-01 17:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 17:14 [PATCH net-next v1 0/4] tools/net/ynl: Add support for nlctrl netlink family Donald Hunter
2024-03-01 17:14 ` [PATCH net-next v1 1/4] tools/net/ynl: Fix extack decoding for netlink-raw Donald Hunter
2024-03-01 17:14 ` [PATCH net-next v1 2/4] tools/net/ynl: Report netlink errors without stacktrace Donald Hunter
2024-03-01 17:14 ` Donald Hunter [this message]
2024-03-03 4:05 ` [PATCH net-next v1 3/4] tools/net/ynl: Extend array-nest for multi level nesting Jakub Kicinski
2024-03-03 10:50 ` Donald Hunter
2024-03-04 15:22 ` Jakub Kicinski
2024-03-04 16:21 ` Donald Hunter
2024-03-04 16:32 ` Jakub Kicinski
2024-03-01 17:14 ` [PATCH net-next v1 4/4] doc/netlink/specs: Add spec for nlctrl netlink family Donald Hunter
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=20240301171431.65892-4-donald.hunter@gmail.com \
--to=donald.hunter@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@redhat.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).