From patchwork Fri Mar 1 17:14:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13578837 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E7076FC3 for ; Fri, 1 Mar 2024 17:14:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709313282; cv=none; b=m8TKXtwJEFv4zkN0mlggS1HJ/rYGWOCU/OZoQt6pd312ukEGJsGbhe73Vy/Ldjvfc8LdzOjjvHfyihx+DAn62kLp+UGppYJKSyMHsfJx8f0W/+cRjSG97e1SgrpETYxFwlVWTU+FdKN4Ehth/gkdTabtPF3DkKMe6w/ZLjL8pgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709313282; c=relaxed/simple; bh=F4RtRqtOfdgQkd+TLMRi9j4zqLakjNTuH0jkqMlfDtI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bzdzoh2yehC+66Hn+BPdv0tTDdpPylPIS6Y8VubcEPGHHVk2qWsFgtA+7VNGgLhUXY4RNZIZg6HXsdouPb7NSsPuPMkaLIh2nqtqxaFBEGw5ayXkNUAexp/Ms0DSA9wwBxdxGjuVozD61lVLAkNBv2t1bnWD7jr3psPenfoyoJ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Dou2G2BU; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dou2G2BU" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-412ca466e9eso4742545e9.0 for ; Fri, 01 Mar 2024 09:14:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709313279; x=1709918079; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4Bq87Z/SPPzCEo5Q0qhbmStS7HXGoeDTWiPK6HT4cN0=; b=Dou2G2BUpWBM298xUjDxN/STxP5ySF3r6+KoCsaA/IHn3WAHIQDqpZqfh7mVtcjCpN 7D103WsuCk8Fhjr8qX5bY2rknxgzICxM3KxXDAcNcXrK3XQbor91kSqcZdrG0HLEBHZz dKHobHaPWO1y9B1/TUrPXbTXSkjuee3TchsM43As9yzxUKCxRhMgIsgEq+ZschcQHuo1 3Sn0YQ+S5e2U4hLNec7asdcAQ5qloteL73RNyj6/0Nlq1tDZ3BclATzziY1RbLr0h8Tu 08IIz0Pc1W1IIq8C0Zhdff+TtXehuyqm9VW2/Aun8knpaapdXHXkdCunCibvgzcAdgv8 lKCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709313279; x=1709918079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Bq87Z/SPPzCEo5Q0qhbmStS7HXGoeDTWiPK6HT4cN0=; b=BNyhPozElhUWmD6lQZyB2gqqzdkV+Ovgx42jJk7d47ATA1Ayb0emwyVt9UAPVO/iRV N274tlhSDQj9j1iFcvnwLVZKi5mV9Ip2uHj7coHxd/lr5ojBykh+SUo5YMX+Y+/KXnjE 1aEER2vVylGhQcqkkyYT9MMcwe0lb04JArt5l7LQXyH4eTRTIjz5iQ1EJEm4W2Rqktph vRuvbQTR4/iFTnBAIShZIX2rTsiXh6rCHWLeofGFjo1zcJNXP7wBukFrDhDAGOOPY398 W3aKfO/2J/iPlf6pSQ+J3/MjerSZZrLTk5b9JjEXphq0LTOMQo8tIpX8BnV/5Gy+WkUG LT+A== X-Gm-Message-State: AOJu0YwlJEyniOyLKV6XpnnSQ1D7PDFAcQWWVoTgPP15b1gBWjRyEtgl /6/cEVWrQ0DhnfaFM5CgHN3xcDmsVj35zvTB93ecorGCT+UG9icbwVKumzy6AOg= X-Google-Smtp-Source: AGHT+IHVn7HiqdB2AFTmOso+sTjUZLXtOWIDL+HXSdcRC227fBjAeEyqsXjy+QyMW25NRqYJR2AcZw== X-Received: by 2002:a5d:438c:0:b0:33e:22f8:57 with SMTP id i12-20020a5d438c000000b0033e22f80057mr1211896wrq.49.1709313278941; Fri, 01 Mar 2024 09:14:38 -0800 (PST) Received: from imac.fritz.box ([2a02:8010:60a0:0:c06e:e547:41d1:e2b2]) by smtp.gmail.com with ESMTPSA id b8-20020a05600003c800b0033e17ff60e4sm3387556wrg.7.2024.03.01.09.14.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:14:38 -0800 (PST) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jacob Keller , Jiri Pirko , Stanislav Fomichev Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v1 1/4] tools/net/ynl: Fix extack decoding for netlink-raw Date: Fri, 1 Mar 2024 17:14:28 +0000 Message-ID: <20240301171431.65892-2-donald.hunter@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240301171431.65892-1-donald.hunter@gmail.com> References: <20240301171431.65892-1-donald.hunter@gmail.com> 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 Extack decoding was using a hard-coded msg header size of 20 but netlink-raw has a header size of 16. Use a protocol specific msghdr_size() when decoding the attr offssets. Signed-off-by: Donald Hunter --- tools/net/ynl/lib/ynl.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index ac55aa5a3083..29262505a3f2 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -348,6 +348,9 @@ class NetlinkProtocol: raise Exception(f'Multicast group "{mcast_name}" not present in the spec') return mcast_groups[mcast_name].value + def msghdr_size(self): + return 16 + class GenlProtocol(NetlinkProtocol): def __init__(self, family_name): @@ -373,6 +376,8 @@ class GenlProtocol(NetlinkProtocol): raise Exception(f'Multicast group "{mcast_name}" not present in the family') return self.genl_family['mcast'][mcast_name] + def msghdr_size(self): + return super().msghdr_size() + 4 class SpaceAttrs: @@ -693,7 +698,7 @@ class YnlFamily(SpecFamily): return msg = self.nlproto.decode(self, NlMsg(request, 0, op.attr_set)) - offset = 20 + self._struct_size(op.fixed_header) + 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']) if path: From patchwork Fri Mar 1 17:14:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13578838 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3B195663 for ; Fri, 1 Mar 2024 17:14:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709313284; cv=none; b=O2TJ+grvEYsqNOs9iY+ksS+yYnqI/BJjwJwNEs2RDbxY6iukuvwZaYnOqlGJUN1T6T9lswOtrJt/r3TQCMeh/Nviw4qr1tOpNsRdaj4inwnEREaJ65udJnobNlezVTK3SWMblWFHR7AtmjNJG0eW/HmbXpppvfl/If03gKTyerk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709313284; c=relaxed/simple; bh=bMK+HuEPPslYD2gVKITnQmNcq1JK/b+mMe9FIMAJg9E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=llhdWWDlxPOF3ARjF9FxrU2/Fdr8mJuFfxuEqPDWEQD84tWGDlJHL5BxDZtLG7z3HdtglKEdZJj7xjB1jwKkjXzy9LWFnKQ4GFzhERS8pPCxlZpImUDezfteliwY5IMJHC0QPPLWADuX9OMdnJkCfQH2ZN2cwzaddP3Athu0vv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C8nOQpb6; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C8nOQpb6" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d28464c554so29509191fa.3 for ; Fri, 01 Mar 2024 09:14:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709313280; x=1709918080; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oGy7I9gmi30fpuWsigLrpycA1+OS7TEwTIlqse2LMjo=; b=C8nOQpb6MjXI29PBOhYPcqwRkAv6ddBYD/M2zUg80hBEz3uh5CaR88P0dLAO0Q5p7q wSk918AIIgcSQf3IUOK8YKUuf0qEItdIwnJcjT3+D4KxdBDpBO2jro80vzqgPufHDKw+ 5rSZjo+xIFhP3/BaPsAMY3QJ/4q+tW3Ze6r/1yX6f0dF2ycWfoWKypCUnEJiREctz8qm nCTiU0cO9VA2nUt3zONYDkcxt2sHcO8hlN91PWpPDu/MM4Y9go681i3/Qak195bsvgEu gXj5SIB5qBRfaZ5UhYu9zrBZpXN5uqvqP13bznkxi6ztvfsoNtOldo7BxbnXJEek/mE+ ll7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709313280; x=1709918080; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oGy7I9gmi30fpuWsigLrpycA1+OS7TEwTIlqse2LMjo=; b=o88EhL2BsvK4G343OLuDvCiNXabshSbmvNFf82FWA2SL2x/uE4jP/28M1lTYOflQXO ziIJDmXy20HqjRKd6KHWNVNthuC9qRmeMbmZpQiyUgFoZDmd6Z+b2HLxHLUvVx/zZyVk DbVg7Gbsz9qf43dhb22d2NrHO+eVMXk1Q03MxNmUDzOUxbAEwqIDnNVTecSnuNKLmibX 4E9f+l0v0ejOAgiFgSQHmzaL/LW4ENW2CPR6lA3r8nUQoWa+o97/ULS5usJfylp7q7Jf 2OFhNpaR341UqCyu1l3WMsykQr9FeQTDdgswvErJwjj5b4DthyXKo+NawqDy22c20dHC 1pow== X-Gm-Message-State: AOJu0YwkXFHPR+tv8VPBmNUXMjlk/iIE/O5kRmst/xW0kxToel05Rj0Q 83b/w5a4tcwvtGMyrMGscAUSVU/4JB+BpUh5ata1aupT16rq5jLD8cF+H/UE7vs= X-Google-Smtp-Source: AGHT+IGHHRJLCV5hig7J/bNCn6D6U4DT15uN3Pn9+pvs/vLYBayJtfG/SUM11jQ21jVDQN3knB6tLw== X-Received: by 2002:a05:651c:10d4:b0:2d2:d0ba:2586 with SMTP id l20-20020a05651c10d400b002d2d0ba2586mr1676036ljn.24.1709313280222; Fri, 01 Mar 2024 09:14:40 -0800 (PST) Received: from imac.fritz.box ([2a02:8010:60a0:0:c06e:e547:41d1:e2b2]) by smtp.gmail.com with ESMTPSA id b8-20020a05600003c800b0033e17ff60e4sm3387556wrg.7.2024.03.01.09.14.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:14:39 -0800 (PST) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jacob Keller , Jiri Pirko , Stanislav Fomichev Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v1 2/4] tools/net/ynl: Report netlink errors without stacktrace Date: Fri, 1 Mar 2024 17:14:29 +0000 Message-ID: <20240301171431.65892-3-donald.hunter@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240301171431.65892-1-donald.hunter@gmail.com> References: <20240301171431.65892-1-donald.hunter@gmail.com> 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 ynl does not handle NlError exceptions so they get reported like program failures. Handle the NlError exceptions and report the netlink errors more cleanly. Example now: Netlink error: No such file or directory nl_len = 44 (28) nl_flags = 0x300 nl_type = 2 error: -2 extack: {'bad-attr': '.op'} Example before: Traceback (most recent call last): File "/home/donaldh/net-next/./tools/net/ynl/cli.py", line 81, in main() File "/home/donaldh/net-next/./tools/net/ynl/cli.py", line 69, in main reply = ynl.dump(args.dump, attrs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/donaldh/net-next/tools/net/ynl/lib/ynl.py", line 906, in dump return self._op(method, vals, [], dump=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/donaldh/net-next/tools/net/ynl/lib/ynl.py", line 872, in _op raise NlError(nl_msg) lib.ynl.NlError: Netlink error: No such file or directory nl_len = 44 (28) nl_flags = 0x300 nl_type = 2 error: -2 extack: {'bad-attr': '.op'} Signed-off-by: Donald Hunter --- tools/net/ynl/cli.py | 18 +++++++++++------- tools/net/ynl/lib/__init__.py | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/net/ynl/cli.py b/tools/net/ynl/cli.py index 0f8239979670..cccf4d801b76 100755 --- a/tools/net/ynl/cli.py +++ b/tools/net/ynl/cli.py @@ -6,7 +6,7 @@ import json import pprint import time -from lib import YnlFamily, Netlink +from lib import YnlFamily, Netlink, NlError class YnlEncoder(json.JSONEncoder): @@ -61,12 +61,16 @@ def main(): if args.sleep: time.sleep(args.sleep) - if args.do: - reply = ynl.do(args.do, attrs, args.flags) - output(reply) - if args.dump: - reply = ynl.dump(args.dump, attrs) - output(reply) + try: + if args.do: + reply = ynl.do(args.do, attrs, args.flags) + output(reply) + if args.dump: + reply = ynl.dump(args.dump, attrs) + output(reply) + except NlError as e: + print(e) + exit(1) if args.ntf: ynl.check_ntf() diff --git a/tools/net/ynl/lib/__init__.py b/tools/net/ynl/lib/__init__.py index f7eaa07783e7..9137b83e580a 100644 --- a/tools/net/ynl/lib/__init__.py +++ b/tools/net/ynl/lib/__init__.py @@ -2,7 +2,7 @@ from .nlspec import SpecAttr, SpecAttrSet, SpecEnumEntry, SpecEnumSet, \ SpecFamily, SpecOperation -from .ynl import YnlFamily, Netlink +from .ynl import YnlFamily, Netlink, NlError __all__ = ["SpecAttr", "SpecAttrSet", "SpecEnumEntry", "SpecEnumSet", - "SpecFamily", "SpecOperation", "YnlFamily", "Netlink"] + "SpecFamily", "SpecOperation", "YnlFamily", "Netlink", "NlError"] From patchwork Fri Mar 1 17:14:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13578839 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9418E883B for ; Fri, 1 Mar 2024 17:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709313285; cv=none; b=mAdvCrOVe7OWorkb90eKex/a3j47cC+pYooZJ0423pzVV8CS+dcEXjARNmBLeN3fTj9OhSvY/IPvQEDWqzhNO8ZREIRTFZeqIpX5fGlAxEuw9/1BTUnV54P3bO8SrD44eYYdQ17l541wyh4t7Eo3SnqbFPCjfxmE9xCd7wRiqaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709313285; c=relaxed/simple; bh=ITuzUrJ3LP04wRnLQqcNN+gf5uuq5gxvhzZLVz1+Jo8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gdFRPqTcb9m27YvVIehEDzcve1BBax4HL1Sj2gsqVnrHoiD01+7P5pdzW794T4RrW9RPjZsxS1nDxvzLb0VIzwWUbmLsji2AqwJQD2lEQ5J/DrHseCy6heO00T6XrguokNtQ0xx9W0VRQDGiZviZEkhLBfYvmBtbdj+R0WJ0GUs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QBWHhVZF; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QBWHhVZF" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-412a9e9c776so21170015e9.0 for ; Fri, 01 Mar 2024 09:14:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709313281; x=1709918081; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3dwjYerr/y8Vv41J2to9nLIRNF2G1qLwh4ctTCr/G/o=; b=QBWHhVZFKtp0j1w0QFxr9+3o+H5eIPd9+uddJ280BSa8VLuZPjxDt0yziV06qHGBRx 77PewdJZbXXxmzQCt7k585iEEwx57a/QtDEJB1GYFGFrHbjvsP5ZG6W9Bmf/e7LrE5s1 odUlzfaJZLSFd733z2z8v5Xs16ICL8cfspJrRx3szZXfDvT0cRuiP2ePfqjKdeY2fjtt tM1LY60KCkCEUMXoMiWoBptvEN9md9S04jPbhCK8vV7fDqOfPWb4dBLkYyOCsDlo8VEK 2mL9gwqybY/pOFQenQ+toh9XFJeO8IvWiGuI1YBLIikyq1FkEQITl3aRicuOXd1CpEQz bIoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709313281; x=1709918081; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3dwjYerr/y8Vv41J2to9nLIRNF2G1qLwh4ctTCr/G/o=; b=irqM1GBWnpaRI3T8n9xEdsHEppkow7KF6uF7PvXVVjv/Pas+inkF7BqO0Py1yuP5In GEFDxxEXbsMYwQIkaChlSJoJqNnrLDM6ASBa7VDtXaNDryTxAhOgsVVNQSWm8/dzI7Eu OP+6i3x5h19EqfudqiwF8uDmhYcOGc9HxobNJ3i5FUPp/B8IRuzcURwQOElremqa3WMD YsZwUD20pEYDXSfqdex9eBiFQJ0Jrvqof2rUsTOcx8wQayq+ChdCJcypjSx5SRXBp8Fn mKWVmHLphF2NAY+uRrWf2mdvOXrvJDZvdHbdB/D3nQBCIyREpHtUY9JeG0EbibAesnJL nxFA== X-Gm-Message-State: AOJu0YxmXJOagobi6o2aWZHDqD0T7hhOR2v1Scm3LeFmp2/VofOTRco1 ac0nrFZJMgYCDHZfoZr/9kUyM1EsOEFDeGAk8xr357Vbzgxn9I65GIaA/xfJJRE= X-Google-Smtp-Source: AGHT+IHbXytC+GSMu9Y0ikZKwWS7Wf+ypPJ4inCvhoA2hs+gCwLkTgKX+oheVUizuTeSvGOYOg0Dtw== X-Received: by 2002:a05:600c:4fc6:b0:412:b237:346e with SMTP id o6-20020a05600c4fc600b00412b237346emr2744383wmq.20.1709313281564; Fri, 01 Mar 2024 09:14:41 -0800 (PST) Received: from imac.fritz.box ([2a02:8010:60a0:0:c06e:e547:41d1:e2b2]) by smtp.gmail.com with ESMTPSA id b8-20020a05600003c800b0033e17ff60e4sm3387556wrg.7.2024.03.01.09.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:14:40 -0800 (PST) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jacob Keller , Jiri Pirko , Stanislav Fomichev Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v1 3/4] tools/net/ynl: Extend array-nest for multi level nesting Date: Fri, 1 Mar 2024 17:14:30 +0000 Message-ID: <20240301171431.65892-4-donald.hunter@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240301171431.65892-1-donald.hunter@gmail.com> References: <20240301171431.65892-1-donald.hunter@gmail.com> 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 The nlctrl family uses 2 levels of array nesting for policy attributes. Add a 'nest-depth' property to genetlink-legacy and extend ynl to use it. Signed-off-by: Donald Hunter --- Documentation/netlink/genetlink-legacy.yaml | 3 +++ tools/net/ynl/lib/nlspec.py | 2 ++ tools/net/ynl/lib/ynl.py | 9 ++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml index 938703088306..872c76065f1b 100644 --- a/Documentation/netlink/genetlink-legacy.yaml +++ b/Documentation/netlink/genetlink-legacy.yaml @@ -261,6 +261,9 @@ properties: struct: description: Name of the struct type used for the attribute. type: string + nest-depth: + description: Depth of nesting for an array-nest, defaults to 1. + type: integer # End genetlink-legacy # Make sure name-prefix does not appear in subsets (subsets inherit naming) diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py index fbce52395b3b..50e8447f089a 100644 --- a/tools/net/ynl/lib/nlspec.py +++ b/tools/net/ynl/lib/nlspec.py @@ -161,6 +161,7 @@ class SpecAttr(SpecElement): sub_message string, name of sub message type selector string, name of attribute used to select sub-message type + nest_depth integer, depth of array nesting is_auto_scalar bool, attr is a variable-size scalar """ @@ -178,6 +179,7 @@ class SpecAttr(SpecElement): self.display_hint = yaml.get('display-hint') self.sub_message = yaml.get('sub-message') self.selector = yaml.get('selector') + self.nest_depth = yaml.get('nest-depth', 1) self.is_auto_scalar = self.type == "sint" or self.type == "uint" diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 29262505a3f2..efceea9433f2 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -556,14 +556,17 @@ class YnlFamily(SpecFamily): decoded = self._formatted_string(decoded, attr_spec.display_hint) return decoded - def _decode_array_nest(self, attr, attr_spec): + def _decode_array_nest(self, attr, attr_spec, depth): decoded = [] offset = 0 while offset < len(attr.raw): item = NlAttr(attr.raw, offset) offset += item.full_len - subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes']) + if depth > 1: + subattrs = self._decode_array_nest(item, attr_spec, depth - 1) + else: + subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes']) decoded.append({ item.type: subattrs }) return decoded @@ -649,7 +652,7 @@ class YnlFamily(SpecFamily): if 'enum' in attr_spec: decoded = self._decode_enum(decoded, attr_spec) elif attr_spec["type"] == 'array-nest': - decoded = self._decode_array_nest(attr, attr_spec) + decoded = self._decode_array_nest(attr, attr_spec, attr_spec.nest_depth) elif attr_spec["type"] == 'bitfield32': value, selector = struct.unpack("II", attr.raw) if 'enum' in attr_spec: From patchwork Fri Mar 1 17:14:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donald Hunter X-Patchwork-Id: 13578840 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CF956FC3 for ; Fri, 1 Mar 2024 17:14:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709313286; cv=none; b=M6ZFy7HR98yBbORWn9ZDWvPlZrA9jnvi1bfbxq2rKW4p+o0Vt4zlL4XHb9j6h3+dPdF/9ndVTQX1SV8XvV8CVpsiwz/pKjQCIfkusyRa2QwEuzRTdzkVapHCwdxyHvzeUZhlnagUzUMDcnDYOB0pE5jt+PgAF9LT5YleMtO/ziQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709313286; c=relaxed/simple; bh=xkaHrcLkpSmNxGh5grebGCaGBvNuRiuDh19PT8gcvII=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gxgqfjJgSHt/3N6rKc0VD/HinJbUeBxMPjqyFwnICtt84hzLRbwj/jWK9nX5uEyXS/snq4ZpaObjANXEXsGz4jfWucZ+E56siOvkewGGWcpaKfCq0pchMNw2TCsgLjOkMLRZLPNC6/XVYOw7a1o5jPa1andvxzGDoAhLf/XwX58= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JE+AAosB; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JE+AAosB" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-412c23551e2so10548535e9.1 for ; Fri, 01 Mar 2024 09:14:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709313282; x=1709918082; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0DQDjaCr/OkAn7DTXR1QZoJd6CRz/IrrXKz+pjcqAdU=; b=JE+AAosB3UANmJyPO6mHGHtXve/0lgtc9sax93qas4QQgd2tAyUX3x91JPF2NnpLJ9 RpHRzdznWxuwPMw0geHqX1VSYQXU2k/HVzuxrcfxKK6IxxP7pGlJ63MG09aqJ9l2OrkP TlWJeaiMIiodIEcO1VBaZlFrBZ3YX+bxW5EmwwyYZ8RDf6dLw3MrcHgZMwXWsMEiqGp6 pQ+VbWPeApsD8AL3hxPL7ELvoB3GuvIgqDZDP/Mwzm3UfnCf7p4cTHDUrqsgEmqgG/8U FUCaX+bjYFCWVN4/2eFRzkxr+VJj4bHAJwBkSNzr7OPeylpGRJtbjem0wsWJYaHQd1H4 Wj+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709313282; x=1709918082; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0DQDjaCr/OkAn7DTXR1QZoJd6CRz/IrrXKz+pjcqAdU=; b=LjNGXi+nZQi6Hc5djmDPW/CIf8aGo5VSryjZ7fmhP/juHyNTTdAcG34vZQFK1H2IqI pAbezXguXs3WcysDE4P3P+21P8K0w2FQSqFeFTthGCBGkndeoJPNvGm2fVcRh5ZrBOMM USxwFaYn4Bo0iovU9QeCMXJC0/zEqaU5xW5anFfQgxOxcBP8Oldhvga7vLWWGvmplGIW 3uCHI28WGoA1vsRPEu7jjosjTimFRsImdzeBmTddq04aKMZdbOoGMqOdF9LKFrRL8Ehz 6DDOfwJGjTzFlwXKaLZ0UaOcVnoy6twXWIb9rVfkncgxe0K4JnhbxOeRaGMoD9sWMAwT lOSw== X-Gm-Message-State: AOJu0YyWcXtaVx72eC9ZC1FAzwgMAWa/HgE2fzyoX0spN4Sxss5/uQoe 64Sx2jwcBofobdnxJKrg4JXAFJ7EmVuK2EfqMhItYIxDzQTG33oqV/Ksa3tgjBU= X-Google-Smtp-Source: AGHT+IHl9bpJZBXE57H3kE82DYOhYbh1INMXrBvv8KoZzIGE9RIQiVRL3nKx5W2shqNBsOp6xzIA1A== X-Received: by 2002:a05:600c:474d:b0:412:c285:1091 with SMTP id w13-20020a05600c474d00b00412c2851091mr2864680wmo.7.1709313282507; Fri, 01 Mar 2024 09:14:42 -0800 (PST) Received: from imac.fritz.box ([2a02:8010:60a0:0:c06e:e547:41d1:e2b2]) by smtp.gmail.com with ESMTPSA id b8-20020a05600003c800b0033e17ff60e4sm3387556wrg.7.2024.03.01.09.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 09:14:42 -0800 (PST) From: Donald Hunter To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jacob Keller , Jiri Pirko , Stanislav Fomichev Cc: donald.hunter@redhat.com, Donald Hunter Subject: [PATCH net-next v1 4/4] doc/netlink/specs: Add spec for nlctrl netlink family Date: Fri, 1 Mar 2024 17:14:31 +0000 Message-ID: <20240301171431.65892-5-donald.hunter@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240301171431.65892-1-donald.hunter@gmail.com> References: <20240301171431.65892-1-donald.hunter@gmail.com> 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 Add a spec for the nlctrl family. Example usage: ./tools/net/ynl/cli.py \ --spec Documentation/netlink/specs/nlctrl.yaml \ --do getfamily --json '{"family-name": "nlctrl"}' ./tools/net/ynl/cli.py \ --spec Documentation/netlink/specs/nlctrl.yaml \ --dump getpolicy --json '{"family-name": "nlctrl"}' Signed-off-by: Donald Hunter --- Documentation/netlink/specs/nlctrl.yaml | 191 ++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 Documentation/netlink/specs/nlctrl.yaml diff --git a/Documentation/netlink/specs/nlctrl.yaml b/Documentation/netlink/specs/nlctrl.yaml new file mode 100644 index 000000000000..9b35a390ae96 --- /dev/null +++ b/Documentation/netlink/specs/nlctrl.yaml @@ -0,0 +1,191 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) + +name: nlctrl + +protocol: genetlink-legacy + +doc: | + Genetlink control. + +definitions: + - + name: op-flags + type: flags + entries: + - admin-perm + - cmd-cap-do + - cmd-cap-dump + - cmd-cap-haspol + - uns-admin-perm + - + name: attr-type + type: enum + entries: + - flag + - u8 + - u16 + - u32 + - u64 + - s8 + - s16 + - s32 + - s64 + - binary + - string + - nul-string + - nested + - nested-array + - bitfield32 + - sint + - uint + +attribute-sets: + - + name: ctrl-attrs + attributes: + - + name: family-id + type: u16 + - + name: family-name + type: string + - + name: version + type: u32 + - + name: hdrsize + type: u32 + - + name: maxattr + type: u32 + - + name: ops + type: array-nest + nested-attributes: op-attrs + - + name: mcast-groups + type: array-nest + nested-attributes: mcast-group-attrs + - + name: policy + type: array-nest + nest-depth: 2 + nested-attributes: policy-attrs + - + name: op-policy + type: array-nest + nested-attributes: op-policy-attrs + - + name: op + type: u32 + - + name: mcast-group-attrs + attributes: + - + name: name + type: string + - + name: id + type: u32 + - + name: op-attrs + attributes: + - + name: id + type: u32 + - + name: flags + type: u32 + enum: op-flags + enum-as-flags: true + - + name: policy-attrs + attributes: + - + name: type + type: u32 + enum: attr-type + - + name: min-value-s + type: s64 + - + name: max-value-s + type: s64 + - + name: min-value-u + type: u64 + - + name: max-value-u + type: u64 + - + name: min-length + type: u32 + - + name: max-length + type: u32 + - + name: policy-idx + type: u32 + - + name: policy-maxtype + type: u32 + - + name: bitfield32-mask + type: u32 + - + name: mask + type: u64 + - + name: pad + type: pad + - + name: op-policy-attrs + attributes: + - + name: do + type: u32 + - + name: dump + type: u32 + +operations: + enum-model: directional + list: + - + name: getfamily + doc: Get / dump genetlink families + attribute-set: ctrl-attrs + do: + request: + value: 3 + attributes: + - family-name + reply: &all_attrs + value: 1 + attributes: + - family-id + - family-name + - hdrsize + - maxattr + - mcast-groups + - ops + - version + dump: + reply: *all_attrs + - + name: getpolicy + doc: Get / dump genetlink policies + attribute-set: ctrl-attrs + dump: + request: + value: 10 + attributes: + - family-name + - family-id + - op + reply: + value: 10 + attributes: + - family-id + - op-policy + - policy