Commit 8b6811d9 authored by Donald Hunter's avatar Donald Hunter Committed by Jakub Kicinski

tools/net/ynl: Add binary and pad support to structs for tc

The tc netlink-raw family needs binary and pad types for several
qopt C structs. Add support for them to ynl.
Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDonald Hunter <donald.hunter@gmail.com>
Link: https://lore.kernel.org/r/20231215093720.18774-6-donald.hunter@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 1769e2be
......@@ -670,6 +670,9 @@ class YnlFamily(SpecFamily):
fixed_header_members = self.consts[name].members
size = 0
for m in fixed_header_members:
if m.type in ['pad', 'binary']:
size += m.len
else:
format = NlAttr.get_format(m.type, m.byte_order)
size += format.size
return size
......@@ -681,9 +684,17 @@ class YnlFamily(SpecFamily):
fixed_header_attrs = dict()
offset = 0
for m in fixed_header_members:
value = None
if m.type == 'pad':
offset += m.len
elif m.type == 'binary':
value = msg.raw[offset : offset + m.len]
offset += m.len
else:
format = NlAttr.get_format(m.type, m.byte_order)
[ value ] = format.unpack_from(msg.raw, offset)
offset += format.size
if value is not None:
if m.enum:
value = self._decode_enum(value, m)
fixed_header_attrs[m.name] = value
......@@ -753,6 +764,11 @@ class YnlFamily(SpecFamily):
fixed_header_members = self.consts[op.fixed_header].members
for m in fixed_header_members:
value = vals.pop(m.name) if m.name in vals else 0
if m.type == 'pad':
msg += bytearray(m.len)
elif m.type == 'binary':
msg += bytes.fromhex(value)
else:
format = NlAttr.get_format(m.type, m.byte_order)
msg += format.pack(value)
for name, value in vals.items():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment