All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	jiri@resnulli.us, donald.hunter@gmail.com,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 3/4] tools: ynl: support debug printing messages
Date: Fri,  1 Mar 2024 15:05:41 -0800	[thread overview]
Message-ID: <20240301230542.116823-4-kuba@kernel.org> (raw)
In-Reply-To: <20240301230542.116823-1-kuba@kernel.org>

For manual debug, allow printing the netlink level messages
to stderr.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/net/ynl/lib/ynl.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index bc5a526dbb99..2462228dacc1 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -7,6 +7,7 @@ import random
 import socket
 import struct
 from struct import Struct
+import sys
 import yaml
 import ipaddress
 import uuid
@@ -428,6 +429,7 @@ genl_family_name_to_id = None
         self.async_msg_ids = set()
         self.async_msg_queue = []
 
+        self._recv_dbg = False
         # Note that netlink will use conservative (min) message size for
         # the first dump recv() on the socket, our setting will only matter
         # from the second recv() on.
@@ -453,6 +455,17 @@ genl_family_name_to_id = None
         self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_ADD_MEMBERSHIP,
                              mcast_id)
 
+    def set_recv_dbg(self, enabled):
+        self._recv_dbg = enabled
+
+    def _recv_dbg_print(self, reply, nl_msgs):
+        if not self._recv_dbg:
+            return
+        print("Recv: read", len(reply), "bytes,",
+              len(nl_msgs.msgs), "messages", file=sys.stderr)
+        for nl_msg in nl_msgs:
+            print("  ", nl_msg, file=sys.stderr)
+
     def _encode_enum(self, attr_spec, value):
         enum = self.consts[attr_spec['enum']]
         if enum.type == 'flags' or attr_spec.get('enum-as-flags', False):
@@ -819,6 +832,7 @@ genl_family_name_to_id = None
                 return
 
             nms = NlMsgs(reply)
+            self._recv_dbg_print(reply, nms)
             for nl_msg in nms:
                 if nl_msg.error:
                     print("Netlink error in ntf!?", os.strerror(-nl_msg.error))
@@ -871,6 +885,7 @@ genl_family_name_to_id = None
         while not done:
             reply = self.sock.recv(self._recv_size)
             nms = NlMsgs(reply, attr_space=op.attr_set)
+            self._recv_dbg_print(reply, nms)
             for nl_msg in nms:
                 if nl_msg.extack:
                     self._decode_extack(msg, op, nl_msg.extack)
-- 
2.44.0


  parent reply	other threads:[~2024-03-01 23:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 23:05 [PATCH net-next 0/4] tools: ynl: add --dbg-small-recv for easier kernel testing Jakub Kicinski
2024-03-01 23:05 ` [PATCH net-next 1/4] tools: ynl: move the new line in NlMsg __repr__ Jakub Kicinski
2024-03-04 11:08   ` Donald Hunter
2024-03-01 23:05 ` [PATCH net-next 2/4] tools: ynl: allow setting recv() size Jakub Kicinski
2024-03-04 11:38   ` Donald Hunter
2024-03-04 13:38   ` Donald Hunter
2024-03-04 14:58     ` Jakub Kicinski
2024-03-04 15:57       ` Donald Hunter
2024-03-04 16:20         ` Jakub Kicinski
2024-03-01 23:05 ` Jakub Kicinski [this message]
2024-03-04 11:34   ` [PATCH net-next 3/4] tools: ynl: support debug printing messages Donald Hunter
2024-03-01 23:05 ` [PATCH net-next 4/4] tools: ynl: add --dbg-small-recv for easier kernel testing Jakub Kicinski
2024-03-04 11:26   ` Donald Hunter
2024-03-04 14:59     ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240301230542.116823-4-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.