Skip to content

Commit 313a7a8

Browse files
donaldhkuba-moo
authored andcommitted
tools: ynl: Support enums in struct members in genetlink-legacy
Support decoding scalars as enums in struct members for genetlink-legacy specs. Signed-off-by: Donald Hunter <donald.hunter@gmail.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 5ac1888 commit 313a7a8

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

Documentation/netlink/genetlink-legacy.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ properties:
127127
doc:
128128
description: Documentation for the struct member attribute.
129129
type: string
130+
enum:
131+
description: Name of the enum type used for the attribute.
132+
type: string
130133
# End genetlink-legacy
131134

132135
attribute-sets:

tools/net/ynl/lib/nlspec.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,13 @@ class SpecStructMember(SpecElement):
228228
Attributes:
229229
type string, type of the member attribute
230230
byte_order string or None for native byte order
231+
enum string, name of the enum definition
231232
"""
232233
def __init__(self, family, yaml):
233234
super().__init__(family, yaml)
234235
self.type = yaml['type']
235236
self.byte_order = yaml.get('byte-order')
237+
self.enum = yaml.get('enum')
236238

237239

238240
class SpecStruct(SpecElement):

tools/net/ynl/lib/ynl.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,11 @@ def _decode_enum(self, rsp, attr_spec):
412412

413413
def _decode_binary(self, attr, attr_spec):
414414
if attr_spec.struct_name:
415-
decoded = attr.as_struct(self.consts[attr_spec.struct_name])
415+
members = self.consts[attr_spec.struct_name]
416+
decoded = attr.as_struct(members)
417+
for m in members:
418+
if m.enum:
419+
self._decode_enum(decoded, m)
416420
elif attr_spec.sub_type:
417421
decoded = attr.as_c_array(attr_spec.sub_type)
418422
else:

0 commit comments

Comments
 (0)