Handling unknown enumerator value in Netlink DPLL

Fix the parser error for enumerator values not described in the
specification files, treating them as unknown value.

The new version of Microchip driver introduced an error when getting
information from DPLL device. The driver is returning an unsupported
value by the enumerator, causing the error.

The patch "0001-tools-ynl-process-unknown-for-enum-values" fixes the
issue.

TEST PLAN:
PASS: Build package and image.
PASS: Read DPLL data successfully.

Story: 2011345
Task: 52581

Change-Id: I44fac73751b8860b1104c15d713d8d2b22080fdd
Signed-off-by: Reynaldo P Gomes <reynaldo.patronegomes@windriver.com>
This commit is contained in:
Reynaldo P Gomes
2025-07-24 16:09:56 -03:00
parent 69f8cdcf4a
commit bb58dcf9bc
5 changed files with 83 additions and 2 deletions

View File

@@ -1,3 +1,9 @@
pynetlink (1.0.1-0) unstable; urgency=medium
* Handling unknown enumerator value in Netlink DPLL.
-- Reynaldo P Gomes <reynaldo.patronegomes@windriver.com> Thu, 24 Jul 2025 15:40:00 -0300
pynetlink (1.0.0-0) unstable; urgency=medium
* New upstream release.

View File

@@ -1,6 +1,6 @@
---
debname: pynetlink
debver: 1.0.0
debver: 1.0.1
src_path: src
revision:
dist: $STX_DIST

View File

@@ -0,0 +1,73 @@
From 8c2e602225f0a96f2c5c65de8ab06e304081e542 Mon Sep 17 00:00:00 2001
From: Donald Hunter <donald.hunter@gmail.com>
Date: Fri, 11 Jul 2025 18:04:56 +0100
Subject: [PATCH] tools: ynl: process unknown for enum values
Extend the process_unknown handing to enum values and flags.
Tested by removing entries from rt-link.yaml and rt-neigh.yaml:
./tools/net/ynl/pyynl/cli.py --family rt-link --dump getlink \
--process-unknown --output-json | jq '.[0] | ."ifi-flags"'
[
"up",
"Unknown(6)",
"loopback",
"Unknown(16)"
]
./tools/net/ynl/pyynl/cli.py --family rt-neigh --dump getneigh \
--process-unknown --output-json | jq '.[] | ."ndm-type"'
"unicast"
"Unknown(5)"
"Unknown(5)"
"unicast"
"Unknown(5)"
"unicast"
"broadcast"
Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
pynetlink/base/ynl.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/pynetlink/base/ynl.py b/pynetlink/base/ynl.py
index 7529bce174ff..006b359294a4 100644
--- a/pynetlink/base/ynl.py
+++ b/pynetlink/base/ynl.py
@@ -618,6 +618,16 @@ 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 _get_enum_or_unknown(self, enum, raw):
+ try:
+ name = enum.entries_by_val[raw].name
+ except KeyError as error:
+ if self.process_unknown:
+ name = f"Unknown({raw})"
+ else:
+ raise error
+ return name
+
def _decode_enum(self, raw, attr_spec):
enum = self.consts[attr_spec['enum']]
if enum.type == 'flags' or attr_spec.get('enum-as-flags', False):
@@ -625,11 +635,11 @@ class YnlFamily(SpecFamily):
value = set()
while raw:
if raw & 1:
- value.add(enum.entries_by_val[i].name)
+ value.add(self._get_enum_or_unknown(enum, i))
raw >>= 1
i += 1
else:
- value = enum.entries_by_val[raw].name
+ value = self._get_enum_or_unknown(enum, raw)
return value
def _decode_binary(self, attr, attr_spec):
--
2.34.1

View File

@@ -0,0 +1 @@
0001-tools-ynl-process-unknown-for-enum-values.patch

View File

@@ -43,7 +43,8 @@ class NetlinkFactory:
return YnlFamily(
files('pynetlink').joinpath('specs', yaml_spec_file),
files('pynetlink').joinpath('schemas', yaml_schema_file))
files('pynetlink').joinpath('schemas', yaml_schema_file),
process_unknown=True)
@staticmethod
def get_dpll_instance() -> YnlFamily: