|
7 | 7 | import socket |
8 | 8 | import struct |
9 | 9 | from struct import Struct |
| 10 | +import sys |
10 | 11 | import yaml |
11 | 12 | import ipaddress |
12 | 13 | import uuid |
@@ -420,6 +421,7 @@ def __init__(self, def_path, schema=None, process_unknown=False, |
420 | 421 | except KeyError: |
421 | 422 | raise Exception(f"Family '{self.yaml['name']}' not supported by the kernel") |
422 | 423 |
|
| 424 | + self._recv_dbg = False |
423 | 425 | # Note that netlink will use conservative (min) message size for |
424 | 426 | # the first dump recv() on the socket, our setting will only matter |
425 | 427 | # from the second recv() on. |
@@ -453,6 +455,17 @@ def ntf_subscribe(self, mcast_name): |
453 | 455 | self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_ADD_MEMBERSHIP, |
454 | 456 | mcast_id) |
455 | 457 |
|
| 458 | + def set_recv_dbg(self, enabled): |
| 459 | + self._recv_dbg = enabled |
| 460 | + |
| 461 | + def _recv_dbg_print(self, reply, nl_msgs): |
| 462 | + if not self._recv_dbg: |
| 463 | + return |
| 464 | + print("Recv: read", len(reply), "bytes,", |
| 465 | + len(nl_msgs.msgs), "messages", file=sys.stderr) |
| 466 | + for nl_msg in nl_msgs: |
| 467 | + print(" ", nl_msg, file=sys.stderr) |
| 468 | + |
456 | 469 | def _encode_enum(self, attr_spec, value): |
457 | 470 | enum = self.consts[attr_spec['enum']] |
458 | 471 | if enum.type == 'flags' or attr_spec.get('enum-as-flags', False): |
@@ -819,6 +832,7 @@ def check_ntf(self): |
819 | 832 | return |
820 | 833 |
|
821 | 834 | nms = NlMsgs(reply) |
| 835 | + self._recv_dbg_print(reply, nms) |
822 | 836 | for nl_msg in nms: |
823 | 837 | if nl_msg.error: |
824 | 838 | print("Netlink error in ntf!?", os.strerror(-nl_msg.error)) |
@@ -871,6 +885,7 @@ def _op(self, method, vals, flags=None, dump=False): |
871 | 885 | while not done: |
872 | 886 | reply = self.sock.recv(self._recv_size) |
873 | 887 | nms = NlMsgs(reply, attr_space=op.attr_set) |
| 888 | + self._recv_dbg_print(reply, nms) |
874 | 889 | for nl_msg in nms: |
875 | 890 | if nl_msg.extack: |
876 | 891 | self._decode_extack(msg, op, nl_msg.extack) |
|
0 commit comments