Commit 52550d51 authored by Asbjørn Sloth Tønnesen's avatar Asbjørn Sloth Tønnesen Committed by Jakub Kicinski
Browse files

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: default avatarAsbjørn Sloth Tønnesen <ast@fiberby.net>
Reviewed-by: default avatarDonald Hunter <donald.hunter@gmail.com>
Link: https://patch.msgid.link/20250915144301.725949-11-ast@fiberby.net


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 5c51ae24
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -971,6 +971,11 @@ class YnlFamily(SpecFamily):
                raw = ip.packed
            else:
                raw = int(ip)
        elif attr_spec.display_hint == 'hex':
            if attr_spec['type'] == 'binary':
                raw = bytes.fromhex(string)
            else:
                raw = int(string, 16)
        else:
            raise Exception(f"Display hint '{attr_spec.display_hint}' not implemented"
                            f" when parsing '{attr_spec['name']}'")