From patchwork Tue Mar 5 05:33:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13581631 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3BD846521 for ; Tue, 5 Mar 2024 05:33:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709616795; cv=none; b=iAPv3vXvL/SI6mVLKA+eHKhnjkMzhiMwhlklq51DK4iVxLewZkcC/a/8TLGeK4h9dE1VNFM19unmvEpn+Vj4T/bRmgL7fN4LBWp107aLJ5mVSag++Yn9WeCjJRtitAb+JpfEUYFSd2q87eCfYkMt3lx9NoTAaNrJErouaC+B9a4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709616795; c=relaxed/simple; bh=gfGhKDWqLmA1HX7FbHSjRQuNVO0z6tj8IdrIzMApVK8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ta4SWme6TiisB7KRPx2n1x5r2SbpWwDuzYPMsMyLwWtcFGMwlJVhjekBKXIUXCoLXNAG6ZdnbyR+TSu8KV3iZvYMmd+dDSQM5LlWETlGkkcETxl2auImvKTu1m6piocChk+kBj7cpMCQF2+ZpPpzr3rrya3cv2oioiQIEQgmAno= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F3AoJbF7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F3AoJbF7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBBB5C433C7; Tue, 5 Mar 2024 05:33:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709616795; bh=gfGhKDWqLmA1HX7FbHSjRQuNVO0z6tj8IdrIzMApVK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F3AoJbF77v+Rr8FzhhQcpfZmTONOsJc8YqKXZNbsPge/jAOXxT2pR5ksdLrByF+Xx Y0+KrkFZBsMIvBQebJ+z/qUT++vWDMSvxyaazg2Xzs6nIN6Z1+FKO7IVuqYJ6bYGIo BTW/RbLeVFvUZF37zdJoPtIqo57b3rWdsk3fvV2SD39h6m5ta72pJHJMrP1BEjEywN KW+Ibm/4ljuJGhY6BZQn2XIMA6gcPeRscl0AEarN3qq8NdLncO9nyx7OkdribH1Iaa yuhNswxGkf4H9i/off4hWscxAbxRdDzlU509ajcePBSo1pfHTjXcoOsNRd6gKiYIUQ T70bgZ1pK/xTQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, jiri@resnulli.us, donald.hunter@gmail.com, Jakub Kicinski Subject: [PATCH net-next v2 1/4] tools: ynl: move the new line in NlMsg __repr__ Date: Mon, 4 Mar 2024 21:33:07 -0800 Message-ID: <20240305053310.815877-2-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240305053310.815877-1-kuba@kernel.org> References: <20240305053310.815877-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org We add the new line even if message has no error or extack, which leads to print(nl_msg) ending with two new lines. Reviewed-by: Donald Hunter Signed-off-by: Jakub Kicinski --- tools/net/ynl/lib/ynl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index ac55aa5a3083..92ade9105f31 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -213,11 +213,11 @@ from .nlspec import SpecFamily return self.nl_type def __repr__(self): - msg = f"nl_len = {self.nl_len} ({len(self.raw)}) nl_flags = 0x{self.nl_flags:x} nl_type = {self.nl_type}\n" + msg = f"nl_len = {self.nl_len} ({len(self.raw)}) nl_flags = 0x{self.nl_flags:x} nl_type = {self.nl_type}" if self.error: - msg += '\terror: ' + str(self.error) + msg += '\n\terror: ' + str(self.error) if self.extack: - msg += '\textack: ' + repr(self.extack) + msg += '\n\textack: ' + repr(self.extack) return msg From patchwork Tue Mar 5 05:33:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13581632 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2A024C637 for ; Tue, 5 Mar 2024 05:33:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709616796; cv=none; b=cbaq5O40dSSfGYmG0uGxqRfNUqNw7arvO1oLGUNrXADwOvOYeMP5TrKNh5go+cFHKpXpS6rd7ljVpn727y1KTm0I83RNzpiPrCozr8zB3tYfvIu39dIEbRuEKlCdJz/GpbsHj18mulht1ayb4NlrTnB77gZ4WagQVKbsodOo5vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709616796; c=relaxed/simple; bh=vlXNscYVmI9A9o6+mBNrH59tYt31nVVZDVGvFZFv1v8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GM6mLw5tKVJFdcAc81YDaugNJr0necbZe/JnLtmZpGT39YEVITYGejRfKA4qXJ+zadd3f90U47duh/F4ZaXKSDHG9js5Eh4M3xqeRcOT/AQg9UZejTuRG7ffcBbsrZvC716FXf98nvEVQnH7FIv+jDoUMNk5t9VATW2AuwJcotc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mvr2UQ9G; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mvr2UQ9G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 770ADC43390; Tue, 5 Mar 2024 05:33:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709616795; bh=vlXNscYVmI9A9o6+mBNrH59tYt31nVVZDVGvFZFv1v8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mvr2UQ9G1LFU5nPesP5/Zbl2LqNWFD3+tqXGzVnn3yY1/GsN+9q52+2NMuA2CEqY9 EB2REYFcr62PmWWKQ+lAQfTfmBHrpb0x0u4y3a2JLeHtHj7IPlJijEAamfGffaGhEw FkuihKQxc2aDPyx0PFmrlyzkKiUMLiPo8OBybLhJTqhb4AxZrOieVB8bBJ/BPeGsaD 5SIKpzJVSiNdmTAWMX0MB6JiRHeMO8tDgazYs1tBUVVEiAAIDaO63QvQfLiQjCFzmY Q/PCmO9+bJR5zZNmP7yYO3yQPmuDV8eHsZDqLHa8hTNqWT6we9l3YXKWerxwgvzNar 20COouxczjm2Q== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, jiri@resnulli.us, donald.hunter@gmail.com, Jakub Kicinski Subject: [PATCH net-next v2 2/4] tools: ynl: allow setting recv() size Date: Mon, 4 Mar 2024 21:33:08 -0800 Message-ID: <20240305053310.815877-3-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240305053310.815877-1-kuba@kernel.org> References: <20240305053310.815877-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Make the size of the buffer we use for recv() configurable. The details of the buffer sizing in netlink are somewhat arcane, we could spend a lot of time polishing this API. Let's just leave some hopefully helpful comments for now. This is a for-developers-only feature, anyway. Signed-off-by: Jakub Kicinski Reviewed-by: Donald Hunter --- v2: - move the handling somewhere a bit more sensible - use 0 as default, and if to set it --- tools/net/ynl/lib/ynl.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 92ade9105f31..c3ff5be33e4e 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -84,6 +84,10 @@ from .nlspec import SpecFamily return f"Netlink error: {os.strerror(-self.nl_msg.error)}\n{self.nl_msg}" +class ConfigError(Exception): + pass + + class NlAttr: ScalarFormat = namedtuple('ScalarFormat', ['native', 'big', 'little']) type_formats = { @@ -400,7 +404,8 @@ genl_family_name_to_id = None class YnlFamily(SpecFamily): - def __init__(self, def_path, schema=None, process_unknown=False): + def __init__(self, def_path, schema=None, process_unknown=False, + recv_size=0): super().__init__(def_path, schema) self.include_raw = False @@ -415,6 +420,16 @@ genl_family_name_to_id = None except KeyError: raise Exception(f"Family '{self.yaml['name']}' not supported by the kernel") + # 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. + self._recv_size = recv_size if recv_size else 131072 + # Netlink will always allocate at least PAGE_SIZE - sizeof(skb_shinfo) + # for a message, so smaller receive sizes will lead to truncation. + # Note that the min size for other families may be larger than 4k! + if self._recv_size < 4000: + raise ConfigError() + self.sock = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, self.nlproto.proto_num) self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_CAP_ACK, 1) self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_EXT_ACK, 1) @@ -799,7 +814,7 @@ genl_family_name_to_id = None def check_ntf(self): while True: try: - reply = self.sock.recv(128 * 1024, socket.MSG_DONTWAIT) + reply = self.sock.recv(self._recv_size, socket.MSG_DONTWAIT) except BlockingIOError: return @@ -854,7 +869,7 @@ genl_family_name_to_id = None done = False rsp = [] while not done: - reply = self.sock.recv(128 * 1024) + reply = self.sock.recv(self._recv_size) nms = NlMsgs(reply, attr_space=op.attr_set) for nl_msg in nms: if nl_msg.extack: From patchwork Tue Mar 5 05:33:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13581633 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 794D879927 for ; Tue, 5 Mar 2024 05:33:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709616796; cv=none; b=j07TkSqua/I8NIkwRqkK115w6lxVUXSnpM//f/3XIpAYiFhOBXTa+TDY0oq6sDa5nIjbsdm/U4S780edxwc5zMODC6LxXw3jLQF5xoljnAgxAGaooxByxStRQeuFvYIdRMFSzAjrXvOa+HZoMcwGG3NkHD1hOacNdaYu9iNZnh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709616796; c=relaxed/simple; bh=Z5tGXdIJBb5HUThHoPBFEbgFQ2DtdDvWugcWnNPAJ9E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kbkKm6lbgUT/Nzgg2rcOOHVu5V05PCbJuBbvRoHL2KFFsxgoNDmL0ehAhygQFycrIM1sQLXJu8k3nXwfxIZqy5KkGsEmyLZqGwUq1+jjLB/jNzyoERRjaJUgdmYX8QdT3UkmqMhqobmU0fTJ2cBHCFKTItlCZ0Tkr0pJLtAI2ec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ahsoD4y8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ahsoD4y8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04293C433F1; Tue, 5 Mar 2024 05:33:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709616796; bh=Z5tGXdIJBb5HUThHoPBFEbgFQ2DtdDvWugcWnNPAJ9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ahsoD4y8HIk5uv7qO7v4IV2SyGAeZqZQEnGYSdaAXM3+zebWznku4L4/alTkEA1Vf w0gclSMyKgxPyda3qN1Ho91t9VuYHSZ9G6r5Y62EVW9pGAv/xNVfv4zNcTm6ayB/jz JGlQd1/ImwQlQq9hFLn29L2C3JPCtx0lzCcDMEK3e69clElRlvfE7lHKBsvBaVbJH7 MAZJvXVEBpMxZzYFOULMSANoYVMiR6abJqdy75AOpP5FiA5Owa0PoraUNKRdD8543V /6aJAqHr8sBUoWXR3ac0+PKlwmsVN5a/dTFyvrPQiwdEPF40Jc7Hy2wIsPdjn3u55y wsQ+3H+iBMrgA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, jiri@resnulli.us, donald.hunter@gmail.com, Jakub Kicinski Subject: [PATCH net-next v2 3/4] tools: ynl: support debug printing messages Date: Mon, 4 Mar 2024 21:33:09 -0800 Message-ID: <20240305053310.815877-4-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240305053310.815877-1-kuba@kernel.org> References: <20240305053310.815877-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org For manual debug, allow printing the netlink level messages to stderr. Reviewed-by: Donald Hunter Signed-off-by: Jakub Kicinski --- 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 c3ff5be33e4e..239e22b7a85f 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 @@ -420,6 +421,7 @@ genl_family_name_to_id = None except KeyError: raise Exception(f"Family '{self.yaml['name']}' not supported by the kernel") + 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) From patchwork Tue Mar 5 05:33:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13581634 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F1D27BAFF for ; Tue, 5 Mar 2024 05:33:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709616797; cv=none; b=o8vMmvGDcfjAoUxq81FX6nkkZtfuvnvc2Ly45xmQ6Wdh66X4XZrf9HytUtxr5RvNCmdhQx6lHtC8ezUuVHGg1G9Hh7SflT/C+b3FBVFzGYJV3olBBVAHus0Sb0nBGIzc2CBqyViPa1nyhlTkXmbKFIyW7g8tZ+rT0CZDvdw6IUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709616797; c=relaxed/simple; bh=LYJESzFtqcgL/UEJZGNrt8IF5+SGZcoBhszjj2nbHrk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZK0rQ8Q0NCP/VGWbnsrarNgbKgHxx4tDX6AICz2ivS5ZgTyzRtHNUB/CrdcD1230wZUHT0FAOUc9O1rSaCYGEI8RNDsj48/PTtL8VHmlkwZ8cyzvDnd8HjBnxGWRp/GPQtgVcD7qY3FnQPOfT3VsqHBGQe1H2uTLQlbI9vswmhk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S97vFh84; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S97vFh84" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85137C43390; Tue, 5 Mar 2024 05:33:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709616796; bh=LYJESzFtqcgL/UEJZGNrt8IF5+SGZcoBhszjj2nbHrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S97vFh84pqHCGblhNbepzGexY1Rw1B9MUdz7LqokLSlwPNEl5RP7mHGRmIm0CVBBD pfZWfTXx09RBDEjI+Rw+W9tH4E8+GBkynlPegP1YsbDLIuvb9tVG9nzKp2QaGUJ5iV MwvB2AvILI01OfCDv4vqQjE4EP5FbJGnFE0U4KhBLcl03eSKt3yDGl+XUi+Aw7x768 TtK5sgUkLF/KXWSl1P7DPn20n9xDV+DnyAHu8gO9O3/ajx1vFVaI7/1DiZ5cNKtQPD 9es6+Jrzw9g+SzCim1X74A/DaBnPj+NhnuNq3wS/pyV6BfTWeaJI7KfOUyLa2Vfi77 FO6HAMazrlJAQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, jiri@resnulli.us, donald.hunter@gmail.com, Jakub Kicinski Subject: [PATCH net-next v2 4/4] tools: ynl: add --dbg-small-recv for easier kernel testing Date: Mon, 4 Mar 2024 21:33:10 -0800 Message-ID: <20240305053310.815877-5-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240305053310.815877-1-kuba@kernel.org> References: <20240305053310.815877-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Most "production" netlink clients use large buffers to make dump efficient, which means that handling of dump continuation in the kernel is not very well tested. Add an option for debugging / testing handling of dumps. It enables printing of extra netlink-level debug and lowers the recv() buffer size in one go. When used without any argument (--dbg-small-recv) it picks a very small default (4000), explicit size can be set, too (--dbg-small-recv 5000). Example: $ ./cli.py [...] --dbg-small-recv Recv: read 3712 bytes, 29 messages nl_len = 128 (112) nl_flags = 0x0 nl_type = 19 [...] nl_len = 128 (112) nl_flags = 0x0 nl_type = 19 Recv: read 3968 bytes, 31 messages nl_len = 128 (112) nl_flags = 0x0 nl_type = 19 [...] nl_len = 128 (112) nl_flags = 0x0 nl_type = 19 Recv: read 532 bytes, 5 messages nl_len = 128 (112) nl_flags = 0x0 nl_type = 19 [...] nl_len = 128 (112) nl_flags = 0x0 nl_type = 19 nl_len = 20 (4) nl_flags = 0x2 nl_type = 3 (the [...] are edits to shorten the commit message). Note that the first message of the dump is sized conservatively by the kernel. Signed-off-by: Jakub Kicinski Reviewed-by: Donald Hunter --- tools/net/ynl/cli.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/net/ynl/cli.py b/tools/net/ynl/cli.py index 0f8239979670..e8a65fbc3698 100755 --- a/tools/net/ynl/cli.py +++ b/tools/net/ynl/cli.py @@ -38,6 +38,8 @@ from lib import YnlFamily, Netlink const=Netlink.NLM_F_APPEND) parser.add_argument('--process-unknown', action=argparse.BooleanOptionalAction) parser.add_argument('--output-json', action='store_true') + parser.add_argument('--dbg-small-recv', default=0, const=4000, + action='store', nargs='?', type=int) args = parser.parse_args() def output(msg): @@ -53,7 +55,10 @@ from lib import YnlFamily, Netlink if args.json_text: attrs = json.loads(args.json_text) - ynl = YnlFamily(args.spec, args.schema, args.process_unknown) + ynl = YnlFamily(args.spec, args.schema, args.process_unknown, + recv_size=args.dbg_small_recv) + if args.dbg_small_recv: + ynl.set_recv_dbg(True) if args.ntf: ynl.ntf_subscribe(args.ntf)