Skip to content

Commit df15c15

Browse files
kubalewskikuba-moo
authored andcommitted
tools: ynl-gen: fix parse multi-attr enum attribute
When attribute is enum type and marked as multi-attr, the netlink respond is not parsed, fails with stack trace: Traceback (most recent call last): File "/net-next/tools/net/ynl/./test.py", line 520, in <module> main() File "/net-next/tools/net/ynl/./test.py", line 488, in main dplls=dplls_get(282574471561216) File "/net-next/tools/net/ynl/./test.py", line 48, in dplls_get reply=act(args) File "/net-next/tools/net/ynl/./test.py", line 41, in act reply = ynl.dump(args.dump, attrs) File "/net-next/tools/net/ynl/lib/ynl.py", line 598, in dump return self._op(method, vals, dump=True) File "/net-next/tools/net/ynl/lib/ynl.py", line 584, in _op rsp_msg = self._decode(gm.raw_attrs, op.attr_set.name) File "/net-next/tools/net/ynl/lib/ynl.py", line 451, in _decode self._decode_enum(rsp, attr_spec) File "/net-next/tools/net/ynl/lib/ynl.py", line 408, in _decode_enum value = enum.entries_by_val[raw].name TypeError: unhashable type: 'list' error: 1 Redesign _decode_enum(..) to take a enum int value and translate it to either a bitmask or enum name as expected. Signed-off-by: Arkadiusz Kubalewski <[email protected]> Reviewed-by: Donald Hunter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d7ddf5f commit df15c15

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tools/net/ynl/lib/ynl.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,7 @@ def _add_attr(self, space, name, value):
417417
pad = b'\x00' * ((4 - len(attr_payload) % 4) % 4)
418418
return struct.pack('HH', len(attr_payload) + 4, nl_type) + attr_payload + pad
419419

420-
def _decode_enum(self, rsp, attr_spec):
421-
raw = rsp[attr_spec['name']]
420+
def _decode_enum(self, raw, attr_spec):
422421
enum = self.consts[attr_spec['enum']]
423422
if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
424423
i = 0
@@ -430,15 +429,15 @@ def _decode_enum(self, rsp, attr_spec):
430429
i += 1
431430
else:
432431
value = enum.entries_by_val[raw].name
433-
rsp[attr_spec['name']] = value
432+
return value
434433

435434
def _decode_binary(self, attr, attr_spec):
436435
if attr_spec.struct_name:
437436
members = self.consts[attr_spec.struct_name]
438437
decoded = attr.as_struct(members)
439438
for m in members:
440439
if m.enum:
441-
self._decode_enum(decoded, m)
440+
decoded[m.name] = self._decode_enum(decoded[m.name], m)
442441
elif attr_spec.sub_type:
443442
decoded = attr.as_c_array(attr_spec.sub_type)
444443
else:
@@ -466,15 +465,16 @@ def _decode(self, attrs, space):
466465
else:
467466
raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}')
468467

468+
if 'enum' in attr_spec:
469+
decoded = self._decode_enum(decoded, attr_spec)
470+
469471
if not attr_spec.is_multi:
470472
rsp[attr_spec['name']] = decoded
471473
elif attr_spec.name in rsp:
472474
rsp[attr_spec.name].append(decoded)
473475
else:
474476
rsp[attr_spec.name] = [decoded]
475477

476-
if 'enum' in attr_spec:
477-
self._decode_enum(rsp, attr_spec)
478478
return rsp
479479

480480
def _decode_extack_path(self, attrs, attr_set, offset, target):

0 commit comments

Comments
 (0)