mirror of
https://github.com/torvalds/linux.git
synced 2026-05-23 14:42:08 +02:00
tools: ynl: move nest packing to a helper function
This patch moves nest packing into a helper function, that can also be used for packing indexed arrays. No behavioural changes intended. 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-9-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
a44a93ea6f
commit
328c134262
|
|
@ -561,11 +561,8 @@ class YnlFamily(SpecFamily):
|
|||
|
||||
if attr["type"] == 'nest':
|
||||
nl_type |= Netlink.NLA_F_NESTED
|
||||
attr_payload = b''
|
||||
sub_space = attr['nested-attributes']
|
||||
sub_attrs = SpaceAttrs(self.attr_sets[sub_space], value, search_attrs)
|
||||
for subname, subvalue in value.items():
|
||||
attr_payload += self._add_attr(sub_space, subname, subvalue, sub_attrs)
|
||||
attr_payload = self._add_nest_attrs(value, sub_space, search_attrs)
|
||||
elif attr["type"] == 'flag':
|
||||
if not value:
|
||||
# If value is absent or false then skip attribute creation.
|
||||
|
|
@ -622,6 +619,14 @@ class YnlFamily(SpecFamily):
|
|||
pad = b'\x00' * ((4 - len(attr_payload) % 4) % 4)
|
||||
return struct.pack('HH', len(attr_payload) + 4, nl_type) + attr_payload + pad
|
||||
|
||||
def _add_nest_attrs(self, value, sub_space, search_attrs):
|
||||
sub_attrs = SpaceAttrs(self.attr_sets[sub_space], value, search_attrs)
|
||||
attr_payload = b''
|
||||
for subname, subvalue in value.items():
|
||||
attr_payload += self._add_attr(sub_space, subname, subvalue,
|
||||
sub_attrs)
|
||||
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