Skip to content

Commit 9738280

Browse files
committed
tools: ynl: fix mixing ops and notifications on one socket
The multi message support loosened the connection between the request and response handling, as we can now submit multiple requests before we start processing responses. Passing the attr set to NlMsgs decoding no longer makes sense (if it ever did), attr set may differ message by messsage. Isolate the part of decoding responsible for attr-set specific interpretation and call it once we identified the correct op. Without this fix performing SET operation on an ethtool socket, while being subscribed to notifications causes: # File "tools/net/ynl/pyynl/lib/ynl.py", line 1096, in _op # Exception| return self._ops(ops)[0] # Exception| ~~~~~~~~~^^^^^ # File "tools/net/ynl/pyynl/lib/ynl.py", line 1040, in _ops # Exception| nms = NlMsgs(reply, attr_space=op.attr_set) # Exception| ^^^^^^^^^^^ The value of op we use on line 1040 is stale, it comes form the previous loop. If a notification comes before a response we will update op to None and the next iteration thru the loop will break with the trace above. Fixes: 6fda63c ("tools/net/ynl: fix cli.py --subscribe feature") Fixes: ba8be00 ("tools/net/ynl: Add multi message support to ynl") Reviewed-by: Donald Hunter <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 664f1b8 commit 9738280

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

tools/net/ynl/pyynl/lib/ynl.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,7 @@ def __init__(self, msg, offset, attr_space=None):
231231
self.extack['unknown'].append(extack)
232232

233233
if attr_space:
234-
# We don't have the ability to parse nests yet, so only do global
235-
if 'miss-type' in self.extack and 'miss-nest' not in self.extack:
236-
miss_type = self.extack['miss-type']
237-
if miss_type in attr_space.attrs_by_val:
238-
spec = attr_space.attrs_by_val[miss_type]
239-
self.extack['miss-type'] = spec['name']
240-
if 'doc' in spec:
241-
self.extack['miss-type-doc'] = spec['doc']
234+
self.annotate_extack(attr_space)
242235

243236
def _decode_policy(self, raw):
244237
policy = {}
@@ -264,6 +257,18 @@ def _decode_policy(self, raw):
264257
policy['mask'] = attr.as_scalar('u64')
265258
return policy
266259

260+
def annotate_extack(self, attr_space):
261+
""" Make extack more human friendly with attribute information """
262+
263+
# We don't have the ability to parse nests yet, so only do global
264+
if 'miss-type' in self.extack and 'miss-nest' not in self.extack:
265+
miss_type = self.extack['miss-type']
266+
if miss_type in attr_space.attrs_by_val:
267+
spec = attr_space.attrs_by_val[miss_type]
268+
self.extack['miss-type'] = spec['name']
269+
if 'doc' in spec:
270+
self.extack['miss-type-doc'] = spec['doc']
271+
267272
def cmd(self):
268273
return self.nl_type
269274

@@ -277,12 +282,12 @@ def __repr__(self):
277282

278283

279284
class NlMsgs:
280-
def __init__(self, data, attr_space=None):
285+
def __init__(self, data):
281286
self.msgs = []
282287

283288
offset = 0
284289
while offset < len(data):
285-
msg = NlMsg(data, offset, attr_space=attr_space)
290+
msg = NlMsg(data, offset)
286291
offset += msg.nl_len
287292
self.msgs.append(msg)
288293

@@ -1034,12 +1039,13 @@ def _ops(self, ops):
10341039
op_rsp = []
10351040
while not done:
10361041
reply = self.sock.recv(self._recv_size)
1037-
nms = NlMsgs(reply, attr_space=op.attr_set)
1042+
nms = NlMsgs(reply)
10381043
self._recv_dbg_print(reply, nms)
10391044
for nl_msg in nms:
10401045
if nl_msg.nl_seq in reqs_by_seq:
10411046
(op, vals, req_msg, req_flags) = reqs_by_seq[nl_msg.nl_seq]
10421047
if nl_msg.extack:
1048+
nl_msg.annotate_extack(op.attr_set)
10431049
self._decode_extack(req_msg, op, nl_msg.extack, vals)
10441050
else:
10451051
op = None

0 commit comments

Comments
 (0)