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

tools: ynl: decode hex input

This patch adds support for decoding hex input, so
that binary attributes can be read through --json.

Example (using future wireguard.yaml):
$ sudo ./tools/net/ynl/pyynl/cli.py --family wireguard \
--do set-device --json '{"ifindex":3,
"private-key":"2a ae 6c 35 c9 4f cf <... to 32 bytes>"}'

In order to somewhat mirror what is done in _formatted_string(),
then for non-binary attributes attempt to convert it to an int.

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-11-ast@fiberby.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Asbjørn Sloth Tønnesen and committed by
Jakub Kicinski
52550d51 5c51ae24

+5
+5
tools/net/ynl/pyynl/lib/ynl.py
··· 971 971 raw = ip.packed 972 972 else: 973 973 raw = int(ip) 974 + elif attr_spec.display_hint == 'hex': 975 + if attr_spec['type'] == 'binary': 976 + raw = bytes.fromhex(string) 977 + else: 978 + raw = int(string, 16) 974 979 else: 975 980 raise Exception(f"Display hint '{attr_spec.display_hint}' not implemented" 976 981 f" when parsing '{attr_spec['name']}'")