Thread (55 messages) 55 messages, 6 authors, 2025-09-11

Re: [PATCH net-next 10/11] tools: ynl: decode hex input

From: Asbjørn Sloth Tønnesen <hidden>
Date: 2025-09-09 20:19:06
Also in: lkml

On 9/9/25 6:10 PM, Sabrina Dubroca wrote:
2025-09-04, 22:01:33 +0000, Asbjørn Sloth Tønnesen wrote:
quoted
This patch add 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>"}'

Signed-off-by: Asbjørn Sloth Tønnesen <redacted>
---
  tools/net/ynl/pyynl/lib/ynl.py | 2 ++
  1 file changed, 2 insertions(+)
diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py
index a37294a751da..78c0245ca587 100644
--- a/tools/net/ynl/pyynl/lib/ynl.py
+++ b/tools/net/ynl/pyynl/lib/ynl.py
@@ -973,6 +973,8 @@ class YnlFamily(SpecFamily):
                  raw = ip.packed
              else:
                  raw = int(ip)
+        elif attr_spec.display_hint == 'hex':
+            raw = bytes.fromhex(string)
I'm working on a spec for macsec and ended up with a similar change,
but doing instead:

+        elif attr_spec.display_hint == 'hex':
+            raw = int(string, 16)

since the destination attribute is u32/u64 and not binary for macsec.

So maybe this should be:

+            if attr_spec['type'] == 'binary':
+                raw = bytes.fromhex(string)
+            else:
+                raw = int(string, 16)

to cover both cases?

I think it matches better what's already in _formatted_string.

(I don't mind having the current patch go in and making this change
together with the macsec spec when it's ready)
Cool, I will include it in v2, which I hope to get out tomorrow.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help