Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <donald.hunter@gmail.com>
Link: https://lore.kernel.org/netdev/m2le0n5xpn.fsf@gmail.com/
Fixes: 0a966d606c68 ("tools/net/ynl: Fix extack decoding for directional ops")
Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://patch.msgid.link/20240904135034.316033-1-arkadiusz.kubalewski@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Arkadiusz Kubalewski and committed by
Jakub Kicinski
6fda63c4 20d664eb

+4 -3
+4 -3
tools/net/ynl/lib/ynl.py
··· 388 388 389 389 def decode(self, ynl, nl_msg, op): 390 390 msg = self._decode(nl_msg) 391 + if op is None: 392 + op = ynl.rsp_by_value[msg.cmd()] 391 393 fixed_header_size = ynl._struct_size(op.fixed_header) 392 394 msg.raw_attrs = NlAttrs(msg.raw, fixed_header_size) 393 395 return msg ··· 923 921 print("Netlink done while checking for ntf!?") 924 922 continue 925 923 926 - op = self.rsp_by_value[nl_msg.cmd()] 927 - decoded = self.nlproto.decode(self, nl_msg, op) 924 + decoded = self.nlproto.decode(self, nl_msg, None) 928 925 if decoded.cmd() not in self.async_msg_ids: 929 926 print("Unexpected msg id done while checking for ntf", decoded) 930 927 continue ··· 981 980 if nl_msg.extack: 982 981 self._decode_extack(req_msg, op, nl_msg.extack) 983 982 else: 984 - op = self.rsp_by_value[nl_msg.cmd()] 983 + op = None 985 984 req_flags = [] 986 985 987 986 if nl_msg.error: