summaryrefslogtreecommitdiff
path: root/tools/net
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2023-08-23 17:30:52 -0700
committerJakub Kicinski <kuba@kernel.org>2023-08-24 19:04:20 -0700
commit649bde9004ac7e034383dcd810cb52f3f5d9e577 (patch)
treeff2b624a42ed4fd7539da63b79cfd700efe36181 /tools/net
parent10ea77e49c5761008d0e2bf6d30b434cbc62446d (diff)
tools: ynl: allow passing binary data
Recent changes made us assume that input for binary data is in hex. When using YNL as a Python library it's possible to pass in raw bytes. Bring the ability to do that back. Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Link: https://lore.kernel.org/r/20230824003056.1436637-2-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/net')
-rw-r--r--tools/net/ynl/lib/ynl.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 6951bcc7efdc..fa4f1c28efc5 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -410,7 +410,12 @@ class YnlFamily(SpecFamily):
elif attr["type"] == 'string':
attr_payload = str(value).encode('ascii') + b'\x00'
elif attr["type"] == 'binary':
- attr_payload = bytes.fromhex(value)
+ if isinstance(value, bytes):
+ attr_payload = value
+ elif isinstance(value, str):
+ attr_payload = bytes.fromhex(value)
+ else:
+ raise Exception(f'Unknown type for binary attribute, value: {value}')
elif attr['type'] in NlAttr.type_formats:
format = NlAttr.get_format(attr['type'], attr.byte_order)
attr_payload = format.pack(int(value))