mirror of
https://github.com/torvalds/linux.git
synced 2026-05-23 22:52:19 +02:00
tools: ynl: encode indexed-arrays
This patch adds support for encoding indexed-array attributes with sub-type nest in pyynl. Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Link: https://patch.msgid.link/20250915144301.725949-10-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
328c134262
commit
5c51ae2446
|
|
@ -563,6 +563,11 @@ class YnlFamily(SpecFamily):
|
|||
nl_type |= Netlink.NLA_F_NESTED
|
||||
sub_space = attr['nested-attributes']
|
||||
attr_payload = self._add_nest_attrs(value, sub_space, search_attrs)
|
||||
elif attr['type'] == 'indexed-array' and attr['sub-type'] == 'nest':
|
||||
nl_type |= Netlink.NLA_F_NESTED
|
||||
sub_space = attr['nested-attributes']
|
||||
attr_payload = self._encode_indexed_array(value, sub_space,
|
||||
search_attrs)
|
||||
elif attr["type"] == 'flag':
|
||||
if not value:
|
||||
# If value is absent or false then skip attribute creation.
|
||||
|
|
@ -616,6 +621,9 @@ class YnlFamily(SpecFamily):
|
|||
else:
|
||||
raise Exception(f'Unknown type at {space} {name} {value} {attr["type"]}')
|
||||
|
||||
return self._add_attr_raw(nl_type, attr_payload)
|
||||
|
||||
def _add_attr_raw(self, nl_type, attr_payload):
|
||||
pad = b'\x00' * ((4 - len(attr_payload) % 4) % 4)
|
||||
return struct.pack('HH', len(attr_payload) + 4, nl_type) + attr_payload + pad
|
||||
|
||||
|
|
@ -627,6 +635,14 @@ class YnlFamily(SpecFamily):
|
|||
sub_attrs)
|
||||
return attr_payload
|
||||
|
||||
def _encode_indexed_array(self, vals, sub_space, search_attrs):
|
||||
attr_payload = b''
|
||||
for i, val in enumerate(vals):
|
||||
idx = i | Netlink.NLA_F_NESTED
|
||||
val_payload = self._add_nest_attrs(val, sub_space, search_attrs)
|
||||
attr_payload += self._add_attr_raw(idx, val_payload)
|
||||
return attr_payload
|
||||
|
||||
def _get_enum_or_unknown(self, enum, raw):
|
||||
try:
|
||||
name = enum.entries_by_val[raw].name
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user