Skip to content

Commit 8da3a55

Browse files
Jiri Pirkokuba-moo
authored andcommitted
ynl: allow to encode u8 attr
Playing with dpll netlink, I came across following issue: $ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do pin-set --json '{"id": 0, "pin-idx": 1, "pin-state": 1}' Traceback (most recent call last): File "tools/net/ynl/cli.py", line 52, in <module> main() File "tools/net/ynl/cli.py", line 40, in main reply = ynl.do(args.do, attrs) File "tools/net/ynl/lib/ynl.py", line 520, in do return self._op(method, vals) File "tools/net/ynl/lib/ynl.py", line 476, in _op msg += self._add_attr(op.attr_set.name, name, value) File "tools/net/ynl/lib/ynl.py", line 344, in _add_attr raise Exception(f'Unknown type at {space} {name} {value} {attr["type"]}') Exception: Unknown type at dpll pin-state 1 u8 I'm not that familiar with ynl code, but from a quick peek, I suspect that couple other types are missing for both encoding and decoding. Ignoring those here as I'm scratching my local itch only. Fix the issue by adding u8 attr packing. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Link: https://lore.kernel.org/r/20230322154242.1739136-1-jiri@resnulli.us Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3eb8eea commit 8da3a55

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

tools/net/ynl/lib/ynl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ def _add_attr(self, space, name, value):
334334
attr_payload += self._add_attr(attr['nested-attributes'], subname, subvalue)
335335
elif attr["type"] == 'flag':
336336
attr_payload = b''
337+
elif attr["type"] == 'u8':
338+
attr_payload = struct.pack("B", int(value))
337339
elif attr["type"] == 'u32':
338340
attr_payload = struct.pack("I", int(value))
339341
elif attr["type"] == 'string':

0 commit comments

Comments
 (0)