Skip to contentSkip to conversation

tools: ynl: process unknown for enum values

PATCH Applied Donald Hunter 3 participants 3 messages Jul 11, 2025 – Jul 13, 2025

Subsystems (3)
lore
Share & tools
lore

Donald Hunter

author maintainer
#0 lore raw

PATCH 1/1 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"

---
 tools/net/ynl/pyynl/lib/ynl.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
tools/net/ynl/pyynl/lib/ynl.py +12 -2
index 7529bce174ff..006b359294a4 100644
@@ -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):
Signature · 1 line
2.50.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · On Fri, 11 Jul 2025 18:04:56 +0100 Donald Hunter wrote:

Extend the process_unknown handing to enum values and flags.

Tested by removing entries from rt-link.yaml and rt-neigh.yaml:

#2 lore raw
In reply to Donald Hunter
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 6 lines · On Fri, 11 Jul 2025 18:04:56 +0100 you wrote:

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"'
Quoted 8 lines

[
"up",
"Unknown(6)",
"loopback",
"Unknown(16)"
]

[...]

Here is the summary with links:
- [net-next,v1] tools: ynl: process unknown for enum values

    https://git.kernel.org/netdev/net-next/c/8c2e602225f0

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html