mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 04:02:20 +00:00
tools: ynl: Handle byte-order in struct members
Add support for byte-order in struct members in the genetlink-legacy spec. Signed-off-by: Donald Hunter <donald.hunter@gmail.com> Acked-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
7c2435ef76
commit
bddd2e561b
@ -122,6 +122,8 @@ properties:
|
||||
enum: [ u8, u16, u32, u64, s8, s16, s32, s64, string ]
|
||||
len:
|
||||
$ref: '#/$defs/len-or-define'
|
||||
byte-order:
|
||||
enum: [ little-endian, big-endian ]
|
||||
# End genetlink-legacy
|
||||
|
||||
attribute-sets:
|
||||
|
@ -226,11 +226,13 @@ class SpecStructMember(SpecElement):
|
||||
Represents a single struct member attribute.
|
||||
|
||||
Attributes:
|
||||
type string, type of the member attribute
|
||||
type string, type of the member attribute
|
||||
byte_order string or None for native byte order
|
||||
"""
|
||||
def __init__(self, family, yaml):
|
||||
super().__init__(family, yaml)
|
||||
self.type = yaml['type']
|
||||
self.byte_order = yaml.get('byte-order')
|
||||
|
||||
|
||||
class SpecStruct(SpecElement):
|
||||
|
@ -124,7 +124,7 @@ class NlAttr:
|
||||
offset = 0
|
||||
for m in members:
|
||||
# TODO: handle non-scalar members
|
||||
format = self.get_format(m.type)
|
||||
format = self.get_format(m.type, m.byte_order)
|
||||
decoded = format.unpack_from(self.raw, offset)
|
||||
offset += format.size
|
||||
value[m.name] = decoded[0]
|
||||
@ -305,7 +305,7 @@ class GenlMsg:
|
||||
|
||||
self.fixed_header_attrs = dict()
|
||||
for m in fixed_header_members:
|
||||
format = NlAttr.get_format(m.type)
|
||||
format = NlAttr.get_format(m.type, m.byte_order)
|
||||
decoded = format.unpack_from(nl_msg.raw, offset)
|
||||
offset += format.size
|
||||
self.fixed_header_attrs[m.name] = decoded[0]
|
||||
@ -542,7 +542,7 @@ class YnlFamily(SpecFamily):
|
||||
fixed_header_members = self.consts[op.fixed_header].members
|
||||
for m in fixed_header_members:
|
||||
value = vals.pop(m.name)
|
||||
format = NlAttr.get_format(m.type)
|
||||
format = NlAttr.get_format(m.type, m.byte_order)
|
||||
msg += format.pack(value)
|
||||
for name, value in vals.items():
|
||||
msg += self._add_attr(op.attr_set.name, name, value)
|
||||
|
Loading…
Reference in New Issue
Block a user