public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
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>, Jonathan Corbet <corbet@lwn•net>,
	linux-doc@vger•kernel.org,
	Jacob Keller <jacob.e.keller@intel•com>,
	Breno Leitao <leitao@debian•org>, Jiri Pirko <jiri@resnulli•us>,
	Alessandro Marcolini <alessandromarcolini99@gmail•com>
Cc: donald.hunter@redhat•com, Donald Hunter <donald.hunter@gmail•com>
Subject: [PATCH net-next v1 02/12] tools/net/ynl: Support sub-messages in nested attribute spaces
Date: Tue, 23 Jan 2024 16:05:28 +0000	[thread overview]
Message-ID: <20240123160538.172-3-donald.hunter@gmail.com> (raw)
In-Reply-To: <20240123160538.172-1-donald.hunter@gmail.com>

Sub-message selectors could only be resolved using values from the
current nest level. Enable value lookup in outer scopes by using
collections.ChainMap to implement an ordered lookup from nested to
outer scopes.

Signed-off-by: Donald Hunter <donald.hunter@gmail•com>
---
 tools/net/ynl/lib/ynl.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 1e10512b2117..b00cde5d29e5 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
 
-from collections import namedtuple
+from collections import namedtuple, ChainMap
 import functools
 import os
 import random
@@ -564,8 +564,8 @@ class YnlFamily(SpecFamily):
         spec = sub_msg_spec.formats[value]
         return spec
 
-    def _decode_sub_msg(self, attr, attr_spec, rsp):
-        msg_format = self._resolve_selector(attr_spec, rsp)
+    def _decode_sub_msg(self, attr, attr_spec, vals):
+        msg_format = self._resolve_selector(attr_spec, vals)
         decoded = {}
         offset = 0
         if msg_format.fixed_header:
@@ -579,10 +579,11 @@ class YnlFamily(SpecFamily):
                 raise Exception(f"Unknown attribute-set '{attr_space}' when decoding '{attr_spec.name}'")
         return decoded
 
-    def _decode(self, attrs, space):
+    def _decode(self, attrs, space, outer_vals = ChainMap()):
         if space:
             attr_space = self.attr_sets[space]
         rsp = dict()
+        vals = ChainMap(rsp, outer_vals)
         for attr in attrs:
             try:
                 attr_spec = attr_space.attrs_by_val[attr.type]
@@ -594,7 +595,7 @@ class YnlFamily(SpecFamily):
                 continue
 
             if attr_spec["type"] == 'nest':
-                subdict = self._decode(NlAttrs(attr.raw), attr_spec['nested-attributes'])
+                subdict = self._decode(NlAttrs(attr.raw), attr_spec['nested-attributes'], vals)
                 decoded = subdict
             elif attr_spec["type"] == 'string':
                 decoded = attr.as_strz()
@@ -617,7 +618,7 @@ class YnlFamily(SpecFamily):
                     selector = self._decode_enum(selector, attr_spec)
                 decoded = {"value": value, "selector": selector}
             elif attr_spec["type"] == 'sub-message':
-                decoded = self._decode_sub_msg(attr, attr_spec, rsp)
+                decoded = self._decode_sub_msg(attr, attr_spec, vals)
             else:
                 if not self.process_unknown:
                     raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}')
-- 
2.42.0


  parent reply	other threads:[~2024-01-23 16:05 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-23 16:05 [PATCH net-next v1 00/12] tools/net/ynl: Add features for tc family Donald Hunter
2024-01-23 16:05 ` [PATCH net-next v1 01/12] tools/net/ynl: Add --output-json arg to ynl cli Donald Hunter
2024-01-25 13:50   ` Breno Leitao
2024-01-23 16:05 ` Donald Hunter [this message]
2024-01-24  0:18   ` [PATCH net-next v1 02/12] tools/net/ynl: Support sub-messages in nested attribute spaces Jakub Kicinski
2024-01-24  9:37     ` Donald Hunter
2024-01-24 15:32       ` Jakub Kicinski
2024-01-26 12:44         ` Donald Hunter
2024-01-26 18:50           ` Jakub Kicinski
2024-01-27 17:18             ` Donald Hunter
2024-01-27 18:52               ` Alessandro Marcolini
2024-01-28 19:36                 ` Donald Hunter
2024-01-29 20:35                   ` Alessandro Marcolini
2024-01-30  1:32                   ` Jakub Kicinski
2024-01-30  1:42               ` Jakub Kicinski
2024-01-30  9:12                 ` Donald Hunter
2024-02-01 20:53                 ` Jacob Keller
2024-02-02  0:04                   ` Jakub Kicinski
2024-02-02 17:12                     ` Jacob Keller
2024-01-23 16:05 ` [PATCH net-next v1 03/12] tools/net/ynl: Refactor fixed header encoding into separate method Donald Hunter
2024-01-23 16:05 ` [PATCH net-next v1 04/12] tools/net/ynl: Add support for encoding sub-messages Donald Hunter
2024-01-23 16:05 ` [PATCH net-next v1 05/12] tools/net/ynl: Encode default values for binary blobs Donald Hunter
2024-01-23 16:05 ` [PATCH net-next v1 06/12] tools/net/ynl: Combine struct decoding logic in ynl Donald Hunter
2024-01-23 16:05 ` [PATCH net-next v1 07/12] tools/net/ynl: Rename _fixed_header_size() to _struct_size() Donald Hunter
2024-01-23 16:05 ` [PATCH net-next v1 08/12] tools/net/ynl: Move formatted_string method out of NlAttr Donald Hunter
2024-01-25 14:24   ` Breno Leitao
2024-01-23 16:05 ` [PATCH net-next v1 09/12] tools/net/ynl: Add support for nested structs Donald Hunter
2024-01-23 16:05 ` [PATCH net-next v1 10/12] doc/netlink: Describe nested structs in netlink raw docs Donald Hunter
2024-01-23 16:05 ` [PATCH net-next v1 11/12] tools/net/ynl: Add type info to struct members in generated docs Donald Hunter
2024-01-25 13:59   ` Breno Leitao
2024-01-23 16:05 ` [PATCH net-next v1 12/12] doc/netlink/specs: Update the tc spec 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=20240123160538.172-3-donald.hunter@gmail.com \
    --to=donald.hunter@gmail$(echo .)com \
    --cc=alessandromarcolini99@gmail$(echo .)com \
    --cc=corbet@lwn$(echo .)net \
    --cc=davem@davemloft$(echo .)net \
    --cc=donald.hunter@redhat$(echo .)com \
    --cc=edumazet@google$(echo .)com \
    --cc=jacob.e.keller@intel$(echo .)com \
    --cc=jiri@resnulli$(echo .)us \
    --cc=kuba@kernel$(echo .)org \
    --cc=leitao@debian$(echo .)org \
    --cc=linux-doc@vger$(echo .)kernel.org \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=pabeni@redhat$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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