From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
lorenzo@kernel.org, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net 2/2] tools: ynl: fix enum-as-flags in the generic CLI
Date: Tue, 7 Mar 2023 16:39:23 -0800 [thread overview]
Message-ID: <20230308003923.445268-3-kuba@kernel.org> (raw)
In-Reply-To: <20230308003923.445268-1-kuba@kernel.org>
Lorenzo points out that the generic CLI is broken for the netdev
family. When I added the support for documentation of enums
(and sparse enums) the client script was not updated.
It expects the values in enum to be a list of names,
now it can also be a dict (YAML object).
Reported-by: Lorenzo Bianconi <lorenzo@kernel.org>
Fixes: e4b48ed460d3 ("tools: ynl: add a completely generic client")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/net/ynl/lib/nlspec.py | 7 +++++--
tools/net/ynl/lib/ynl.py | 9 ++-------
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
index 7c1cf6c1499e..a34d088f6743 100644
--- a/tools/net/ynl/lib/nlspec.py
+++ b/tools/net/ynl/lib/nlspec.py
@@ -104,8 +104,9 @@ jsonschema = None
as declared in the "definitions" section of the spec.
Attributes:
- type enum or flags
- entries entries by name
+ type enum or flags
+ entries entries by name
+ entries_by_val entries by value
Methods:
get_mask for flags compute the mask of all defined values
"""
@@ -117,9 +118,11 @@ jsonschema = None
prev_entry = None
value_start = self.yaml.get('value-start', 0)
self.entries = dict()
+ self.entries_by_val = dict()
for entry in self.yaml['entries']:
e = self.new_entry(entry, prev_entry, value_start)
self.entries[e.name] = e
+ self.entries_by_val[e.raw_value()] = e
prev_entry = e
def new_entry(self, entry, prev_entry, value_start):
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index a842adc8e87e..90764a83c646 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -303,11 +303,6 @@ genl_family_name_to_id = None
self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_CAP_ACK, 1)
self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_EXT_ACK, 1)
- self._types = dict()
-
- for elem in self.yaml.get('definitions', []):
- self._types[elem['name']] = elem
-
self.async_msg_ids = set()
self.async_msg_queue = []
@@ -353,13 +348,13 @@ genl_family_name_to_id = None
def _decode_enum(self, rsp, attr_spec):
raw = rsp[attr_spec['name']]
- enum = self._types[attr_spec['enum']]
+ enum = self.consts[attr_spec['enum']]
i = attr_spec.get('value-start', 0)
if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
value = set()
while raw:
if raw & 1:
- value.add(enum['entries'][i])
+ value.add(enum.entries_by_val[i].name)
raw >>= 1
i += 1
else:
--
2.39.2
next prev parent reply other threads:[~2023-03-08 0:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-08 0:39 [PATCH net 0/2] tools: ynl: fix enum-as-flags in the generic CLI Jakub Kicinski
2023-03-08 0:39 ` [PATCH net 1/2] tools: ynl: move the enum classes to shared code Jakub Kicinski
2023-03-08 0:39 ` Jakub Kicinski [this message]
2023-03-09 7:30 ` [PATCH net 0/2] tools: ynl: fix enum-as-flags in the generic CLI patchwork-bot+netdevbpf
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=20230308003923.445268-3-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=lorenzo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.