Skip to content

Commit c311aaa

Browse files
committed
tools: ynl: fix enum-as-flags in the generic CLI
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 <[email protected]> Fixes: e4b48ed ("tools: ynl: add a completely generic client") Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 6517a60 commit c311aaa

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

tools/net/ynl/lib/nlspec.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ class SpecEnumSet(SpecElement):
104104
as declared in the "definitions" section of the spec.
105105
106106
Attributes:
107-
type enum or flags
108-
entries entries by name
107+
type enum or flags
108+
entries entries by name
109+
entries_by_val entries by value
109110
Methods:
110111
get_mask for flags compute the mask of all defined values
111112
"""
@@ -117,9 +118,11 @@ def __init__(self, family, yaml):
117118
prev_entry = None
118119
value_start = self.yaml.get('value-start', 0)
119120
self.entries = dict()
121+
self.entries_by_val = dict()
120122
for entry in self.yaml['entries']:
121123
e = self.new_entry(entry, prev_entry, value_start)
122124
self.entries[e.name] = e
125+
self.entries_by_val[e.raw_value()] = e
123126
prev_entry = e
124127

125128
def new_entry(self, entry, prev_entry, value_start):

tools/net/ynl/lib/ynl.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,6 @@ def __init__(self, def_path, schema=None):
303303
self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_CAP_ACK, 1)
304304
self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_EXT_ACK, 1)
305305

306-
self._types = dict()
307-
308-
for elem in self.yaml.get('definitions', []):
309-
self._types[elem['name']] = elem
310-
311306
self.async_msg_ids = set()
312307
self.async_msg_queue = []
313308

@@ -353,13 +348,13 @@ def _add_attr(self, space, name, value):
353348

354349
def _decode_enum(self, rsp, attr_spec):
355350
raw = rsp[attr_spec['name']]
356-
enum = self._types[attr_spec['enum']]
351+
enum = self.consts[attr_spec['enum']]
357352
i = attr_spec.get('value-start', 0)
358353
if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
359354
value = set()
360355
while raw:
361356
if raw & 1:
362-
value.add(enum['entries'][i])
357+
value.add(enum.entries_by_val[i].name)
363358
raw >>= 1
364359
i += 1
365360
else:

0 commit comments

Comments
 (0)