Skip to content

Commit

Permalink
tools/net/ynl: Fix extack decoding for directional ops
Browse files Browse the repository at this point in the history
NetlinkProtocol.decode() was looking up ops by response value which breaks
when it is used for extack decoding of directional ops. Instead, pass
the op to decode().

Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://lore.kernel.org/r/20240418104737.77914-3-donald.hunter@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Donald Hunter authored and Jakub Kicinski committed Apr 23, 2024
1 parent 1ee7316 commit 0a966d6
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions tools/net/ynl/lib/ynl.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,9 @@ def message(self, flags, command, version, seq=None):
def _decode(self, nl_msg):
return nl_msg

def decode(self, ynl, nl_msg):
def decode(self, ynl, nl_msg, op):
msg = self._decode(nl_msg)
fixed_header_size = 0
if ynl:
op = ynl.rsp_by_value[msg.cmd()]
fixed_header_size = ynl._struct_size(op.fixed_header)
fixed_header_size = ynl._struct_size(op.fixed_header)
msg.raw_attrs = NlAttrs(msg.raw, fixed_header_size)
return msg

Expand Down Expand Up @@ -797,7 +794,7 @@ def _decode_extack(self, request, op, extack):
if 'bad-attr-offs' not in extack:
return

msg = self.nlproto.decode(self, NlMsg(request, 0, op.attr_set))
msg = self.nlproto.decode(self, NlMsg(request, 0, op.attr_set), op)
offset = self.nlproto.msghdr_size() + self._struct_size(op.fixed_header)
path = self._decode_extack_path(msg.raw_attrs, op.attr_set, offset,
extack['bad-attr-offs'])
Expand Down Expand Up @@ -922,7 +919,8 @@ def check_ntf(self):
print("Netlink done while checking for ntf!?")
continue

decoded = self.nlproto.decode(self, nl_msg)
op = self.rsp_by_value[nl_msg.cmd()]
decoded = self.nlproto.decode(self, nl_msg, op)
if decoded.cmd() not in self.async_msg_ids:
print("Unexpected msg id done while checking for ntf", decoded)
continue
Expand Down Expand Up @@ -979,7 +977,7 @@ def _op(self, method, vals, flags=None, dump=False):
done = True
break

decoded = self.nlproto.decode(self, nl_msg)
decoded = self.nlproto.decode(self, nl_msg, op)

# Check if this is a reply to our request
if nl_msg.nl_seq != req_seq or decoded.cmd() != op.rsp_value:
Expand Down

0 comments on commit 0a966d6

Please sign in to comment.