Skip to content

Commit 6fda63c

Browse files
kubalewskikuba-moo
authored andcommitted
tools/net/ynl: fix cli.py --subscribe feature
Execution of command: ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml / --subscribe "monitor" --sleep 10 fails with: File "/repo/./tools/net/ynl/cli.py", line 109, in main ynl.check_ntf() File "/repo/tools/net/ynl/lib/ynl.py", line 924, in check_ntf op = self.rsp_by_value[nl_msg.cmd()] KeyError: 19 Parsing Generic Netlink notification messages performs lookup for op in the message. The message was not yet decoded, and is not yet considered GenlMsg, thus msg.cmd() returns Generic Netlink family id (19) instead of proper notification command id (i.e.: DPLL_CMD_PIN_CHANGE_NTF=13). Allow the op to be obtained within NetlinkProtocol.decode(..) itself if the op was not passed to the decode function, thus allow parsing of Generic Netlink notifications without causing the failure. Suggested-by: Donald Hunter <[email protected]> Link: https://lore.kernel.org/netdev/[email protected]/ Fixes: 0a966d6 ("tools/net/ynl: Fix extack decoding for directional ops") Signed-off-by: Arkadiusz Kubalewski <[email protected]> Reviewed-by: Donald Hunter <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 20d664e commit 6fda63c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tools/net/ynl/lib/ynl.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ def _decode(self, nl_msg):
388388

389389
def decode(self, ynl, nl_msg, op):
390390
msg = self._decode(nl_msg)
391+
if op is None:
392+
op = ynl.rsp_by_value[msg.cmd()]
391393
fixed_header_size = ynl._struct_size(op.fixed_header)
392394
msg.raw_attrs = NlAttrs(msg.raw, fixed_header_size)
393395
return msg
@@ -921,8 +923,7 @@ def check_ntf(self):
921923
print("Netlink done while checking for ntf!?")
922924
continue
923925

924-
op = self.rsp_by_value[nl_msg.cmd()]
925-
decoded = self.nlproto.decode(self, nl_msg, op)
926+
decoded = self.nlproto.decode(self, nl_msg, None)
926927
if decoded.cmd() not in self.async_msg_ids:
927928
print("Unexpected msg id done while checking for ntf", decoded)
928929
continue
@@ -980,7 +981,7 @@ def _ops(self, ops):
980981
if nl_msg.extack:
981982
self._decode_extack(req_msg, op, nl_msg.extack)
982983
else:
983-
op = self.rsp_by_value[nl_msg.cmd()]
984+
op = None
984985
req_flags = []
985986

986987
if nl_msg.error:

0 commit comments

Comments
 (0)