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

tools: ynl: add ipv4-or-v6 display hint

The attribute WGALLOWEDIP_A_IPADDR can contain either an IPv4
or an IPv6 address depending on WGALLOWEDIP_A_FAMILY, however
in practice it is enough to look at the attribute length.

This patch implements an ipv4-or-v6 display hint, that can
deal with this kind of attribute.

It only implements this display hint for genetlink-legacy, it
can be added to other protocol variants if needed, but we don't
want to encourage it's use.

Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://patch.msgid.link/20250915144301.725949-12-ast@fiberby.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Asbjørn Sloth Tønnesen and committed by
Jakub Kicinski
1b255e1b 52550d51

+3 -3
+2 -2
tools/net/ynl/pyynl/lib/ynl.py
··· 956 956 formatted = hex(raw) 957 957 else: 958 958 formatted = bytes.hex(raw, ' ') 959 - elif display_hint in [ 'ipv4', 'ipv6' ]: 959 + elif display_hint in [ 'ipv4', 'ipv6', 'ipv4-or-v6' ]: 960 960 formatted = format(ipaddress.ip_address(raw)) 961 961 elif display_hint == 'uuid': 962 962 formatted = str(uuid.UUID(bytes=raw)) ··· 965 965 return formatted 966 966 967 967 def _from_string(self, string, attr_spec): 968 - if attr_spec.display_hint in ['ipv4', 'ipv6']: 968 + if attr_spec.display_hint in ['ipv4', 'ipv6', 'ipv4-or-v6']: 969 969 ip = ipaddress.ip_address(string) 970 970 if attr_spec['type'] == 'binary': 971 971 raw = ip.packed