Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Donald Hunter and committed by
David S. Miller
8c2e6022 a52f9f0d

+12 -2
+12 -2
tools/net/ynl/pyynl/lib/ynl.py
··· 618 618 pad = b'\x00' * ((4 - len(attr_payload) % 4) % 4) 619 619 return struct.pack('HH', len(attr_payload) + 4, nl_type) + attr_payload + pad 620 620 621 + def _get_enum_or_unknown(self, enum, raw): 622 + try: 623 + name = enum.entries_by_val[raw].name 624 + except KeyError as error: 625 + if self.process_unknown: 626 + name = f"Unknown({raw})" 627 + else: 628 + raise error 629 + return name 630 + 621 631 def _decode_enum(self, raw, attr_spec): 622 632 enum = self.consts[attr_spec['enum']] 623 633 if enum.type == 'flags' or attr_spec.get('enum-as-flags', False): ··· 635 625 value = set() 636 626 while raw: 637 627 if raw & 1: 638 - value.add(enum.entries_by_val[i].name) 628 + value.add(self._get_enum_or_unknown(enum, i)) 639 629 raw >>= 1 640 630 i += 1 641 631 else: 642 - value = enum.entries_by_val[raw].name 632 + value = self._get_enum_or_unknown(enum, raw) 643 633 return value 644 634 645 635 def _decode_binary(self, attr, attr_spec):