From patchwork Thu Jul 13 09:05:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arkadiusz Kubalewski X-Patchwork-Id: 13311633 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 79406FBE1 for ; Thu, 13 Jul 2023 09:07:58 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52F0912E; Thu, 13 Jul 2023 02:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689239277; x=1720775277; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bPZzjqz7eqP99LYiwaj8IjdY7wvVMBfdnWJXbpDiBtk=; b=KYyiECIjtSO11ykoxV4pg2fPug+Pu0rnqK4hOzrPqclGYjzN3vQ27emh ioiSH0Jt+fizP7i+oRmPiAFI6sVy6B9IFgN018oaAAcZmt5o47Au8SOvr 2pBf2ha3jTic9FZN8EbhyNcZrPVUxsTJ6PxdLC7zbE5+lpQ+lytW1EhKL oRZU2ZUQrB3c7i7J5orn7R5TR2bzvNDUMSD9Yd1W5h6unGEUc6YXUQYGs XoOY9JD98m+hhTF+2f47M+YrKI3TY+ot1gqQtOUw1lyZFxuz21Ypr6z5J vW5ArCZN8D/TpNpti4X5MLNz5q79ylCiVd4oZl3ddhlma7Z5Hcd2eq3az g==; X-IronPort-AV: E=McAfee;i="6600,9927,10769"; a="367760138" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="367760138" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 02:07:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10769"; a="866481086" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="866481086" Received: from amlin-018-114.igk.intel.com ([10.102.18.114]) by fmsmga001.fm.intel.com with ESMTP; 13 Jul 2023 02:07:54 -0700 From: Arkadiusz Kubalewski To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com, chuck.lever@oracle.com Cc: Arkadiusz Kubalewski Subject: [PATCH net-next 1/2 v2] tools: ynl-gen: fix enum index in _decode_enum(..) Date: Thu, 13 Jul 2023 11:05:49 +0200 Message-Id: <20230713090550.132858-2-arkadiusz.kubalewski@intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230713090550.132858-1-arkadiusz.kubalewski@intel.com> References: <20230713090550.132858-1-arkadiusz.kubalewski@intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Remove wrong index adjustment, which is a leftover from adding support for sparse enums. enum.entries_by_val() function shall not subtract the start-value, as it is indexed with real enum value. Fixes: c311aaa74ca1 ("tools: ynl: fix enum-as-flags in the generic CLI") Signed-off-by: Arkadiusz Kubalewski --- tools/net/ynl/lib/ynl.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 1b3a36fbb1c3..3908438d3716 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -420,16 +420,14 @@ class YnlFamily(SpecFamily): def _decode_enum(self, rsp, attr_spec): raw = rsp[attr_spec['name']] enum = self.consts[attr_spec['enum']] - i = attr_spec.get('value-start', 0) if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']: value = set() while raw: if raw & 1: - value.add(enum.entries_by_val[i].name) + value.add(enum.entries_by_val[raw & 1].name) raw >>= 1 - i += 1 else: - value = enum.entries_by_val[raw - i].name + value = enum.entries_by_val[raw].name rsp[attr_spec['name']] = value def _decode_binary(self, attr, attr_spec): From patchwork Thu Jul 13 09:05:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arkadiusz Kubalewski X-Patchwork-Id: 13311634 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 B3AA4100A7 for ; Thu, 13 Jul 2023 09:08:01 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C4B01980; Thu, 13 Jul 2023 02:08:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689239280; x=1720775280; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E0G5VImXv6hkeSTU8kcKA4+bnPv7R82T0wFQmCmbE0I=; b=S7kjHHsgneOKNqBFt871vTOCBTXdiZMGqYdjcj4igUR9PewXC1yfyklI /Jw/tVUvfhU2ilRKHamDaMxP0C9Kw1GAIdB3xyV+fmCCaupZ2wXnJOl5L pSuQpoqx7sotFvS+sZHceMOkrv6e3FG7apNbh5xOo9HKEOoflm+y1T8h9 v+6K13b2Y5vGBuFvpWVqnQ2YkCFl4cyUq6bQvDbGyQEDKv6x2xI7youfy yeW1D/SqMTJwEDAfsuDa4+ICG+uonpEh98XqVLjIX6riuXgGUFE7Ui0YK cFCMFfaTIfPk92VyRg7AVlqYPsur5hqUoqZKwoO39F8KrDPdufDy4CglO Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10769"; a="367760145" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="367760145" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 02:08:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10769"; a="866481095" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="866481095" Received: from amlin-018-114.igk.intel.com ([10.102.18.114]) by fmsmga001.fm.intel.com with ESMTP; 13 Jul 2023 02:07:57 -0700 From: Arkadiusz Kubalewski To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com, chuck.lever@oracle.com Cc: Arkadiusz Kubalewski Subject: [PATCH net-next 2/2 v2] tools: ynl-gen: fix parse multi-attr enum attribute Date: Thu, 13 Jul 2023 11:05:50 +0200 Message-Id: <20230713090550.132858-3-arkadiusz.kubalewski@intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230713090550.132858-1-arkadiusz.kubalewski@intel.com> References: <20230713090550.132858-1-arkadiusz.kubalewski@intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org When attribute is enum type and marked as multi-attr, the netlink respond is not parsed, fails with stack trace: Traceback (most recent call last): File "/net-next/tools/net/ynl/./test.py", line 520, in main() File "/net-next/tools/net/ynl/./test.py", line 488, in main dplls=dplls_get(282574471561216) File "/net-next/tools/net/ynl/./test.py", line 48, in dplls_get reply=act(args) File "/net-next/tools/net/ynl/./test.py", line 41, in act reply = ynl.dump(args.dump, attrs) File "/net-next/tools/net/ynl/lib/ynl.py", line 598, in dump return self._op(method, vals, dump=True) File "/net-next/tools/net/ynl/lib/ynl.py", line 584, in _op rsp_msg = self._decode(gm.raw_attrs, op.attr_set.name) File "/net-next/tools/net/ynl/lib/ynl.py", line 451, in _decode self._decode_enum(rsp, attr_spec) File "/net-next/tools/net/ynl/lib/ynl.py", line 408, in _decode_enum value = enum.entries_by_val[raw].name TypeError: unhashable type: 'list' error: 1 Redesign _decode_enum(..) to take a enum int value and translate it to either a bitmask or enum name as expected. Signed-off-by: Arkadiusz Kubalewski --- tools/net/ynl/lib/ynl.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 3908438d3716..06d88f083f95 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -417,8 +417,7 @@ class YnlFamily(SpecFamily): pad = b'\x00' * ((4 - len(attr_payload) % 4) % 4) return struct.pack('HH', len(attr_payload) + 4, nl_type) + attr_payload + pad - def _decode_enum(self, rsp, attr_spec): - raw = rsp[attr_spec['name']] + def _decode_enum(self, raw, attr_spec): enum = self.consts[attr_spec['enum']] if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']: value = set() @@ -428,7 +427,7 @@ class YnlFamily(SpecFamily): raw >>= 1 else: value = enum.entries_by_val[raw].name - rsp[attr_spec['name']] = value + return value def _decode_binary(self, attr, attr_spec): if attr_spec.struct_name: @@ -436,7 +435,7 @@ class YnlFamily(SpecFamily): decoded = attr.as_struct(members) for m in members: if m.enum: - self._decode_enum(decoded, m) + decoded[m] = self._decode_enum(decoded[m], m) elif attr_spec.sub_type: decoded = attr.as_c_array(attr_spec.sub_type) else: @@ -464,6 +463,9 @@ class YnlFamily(SpecFamily): else: raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}') + if 'enum' in attr_spec: + decoded = self._decode_enum(int.from_bytes(attr.raw, "big"), attr_spec) + if not attr_spec.is_multi: rsp[attr_spec['name']] = decoded elif attr_spec.name in rsp: @@ -471,8 +473,6 @@ class YnlFamily(SpecFamily): else: rsp[attr_spec.name] = [decoded] - if 'enum' in attr_spec: - self._decode_enum(rsp, attr_spec) return rsp def _decode_extack_path(self, attrs, attr_set, offset, target):