summaryrefslogtreecommitdiff
path: root/tools/net/ynl/lib
diff options
context:
space:
mode:
authorDonald Hunter <donald.hunter@gmail.com>2024-01-29 22:34:51 +0000
committerJakub Kicinski <kuba@kernel.org>2024-01-31 21:19:18 -0800
commita387a921139e07587b0fb93c9c0fec8b6800776d (patch)
tree5be8288fc4842479dbe00931a6f155fcf44af2ce /tools/net/ynl/lib
parentab463c4342d1d14f25357c0f9f1a9744d7417edd (diff)
tools/net/ynl: Encode default values for binary blobs
Add support for defaulting binary byte arrays to all zeros as well as defaulting scalar values to 0 when encoding input parameters. Signed-off-by: Donald Hunter <donald.hunter@gmail.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Link: https://lore.kernel.org/r/20240129223458.52046-7-donald.hunter@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/net/ynl/lib')
-rw-r--r--tools/net/ynl/lib/ynl.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index b063094e8a4b..d04435f26f89 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -742,12 +742,17 @@ class YnlFamily(SpecFamily):
members = self.consts[name].members
attr_payload = b''
for m in members:
- value = vals.pop(m.name) if m.name in vals else 0
+ value = vals.pop(m.name) if m.name in vals else None
if m.type == 'pad':
attr_payload += bytearray(m.len)
elif m.type == 'binary':
- attr_payload += bytes.fromhex(value)
+ if value is None:
+ attr_payload += bytearray(m.len)
+ else:
+ attr_payload += bytes.fromhex(value)
else:
+ if value is None:
+ value = 0
format = NlAttr.get_format(m.type, m.byte_order)
attr_payload += format.pack(value)
return attr_payload