@@ -158,6 +158,9 @@ class SpecAttr(SpecElement):
158
158
len integer, optional byte length of binary types
159
159
display_hint string, hint to help choose format specifier
160
160
when displaying the value
161
+ sub_message string, name of sub message type
162
+ selector string, name of attribute used to select
163
+ sub-message type
161
164
162
165
is_auto_scalar bool, attr is a variable-size scalar
163
166
"""
@@ -173,6 +176,8 @@ def __init__(self, family, attr_set, yaml, value):
173
176
self .byte_order = yaml .get ('byte-order' )
174
177
self .len = yaml .get ('len' )
175
178
self .display_hint = yaml .get ('display-hint' )
179
+ self .sub_message = yaml .get ('sub-message' )
180
+ self .selector = yaml .get ('selector' )
176
181
177
182
self .is_auto_scalar = self .type == "sint" or self .type == "uint"
178
183
@@ -278,6 +283,47 @@ def items(self):
278
283
return self .members .items ()
279
284
280
285
286
+ class SpecSubMessage (SpecElement ):
287
+ """ Netlink sub-message definition
288
+
289
+ Represents a set of sub-message formats for polymorphic nlattrs
290
+ that contain type-specific sub messages.
291
+
292
+ Attributes:
293
+ name string, name of sub-message definition
294
+ formats dict of sub-message formats indexed by match value
295
+ """
296
+ def __init__ (self , family , yaml ):
297
+ super ().__init__ (family , yaml )
298
+
299
+ self .formats = collections .OrderedDict ()
300
+ for elem in self .yaml ['formats' ]:
301
+ format = self .new_format (family , elem )
302
+ self .formats [format .value ] = format
303
+
304
+ def new_format (self , family , format ):
305
+ return SpecSubMessageFormat (family , format )
306
+
307
+
308
+ class SpecSubMessageFormat (SpecElement ):
309
+ """ Netlink sub-message definition
310
+
311
+ Represents a set of sub-message formats for polymorphic nlattrs
312
+ that contain type-specific sub messages.
313
+
314
+ Attributes:
315
+ value attribute value to match against type selector
316
+ fixed_header string, name of fixed header, or None
317
+ attr_set string, name of attribute set, or None
318
+ """
319
+ def __init__ (self , family , yaml ):
320
+ super ().__init__ (family , yaml )
321
+
322
+ self .value = yaml .get ('value' )
323
+ self .fixed_header = yaml .get ('fixed-header' )
324
+ self .attr_set = yaml .get ('attribute-set' )
325
+
326
+
281
327
class SpecOperation (SpecElement ):
282
328
"""Netlink Operation
283
329
@@ -365,6 +411,7 @@ class SpecFamily(SpecElement):
365
411
366
412
attr_sets dict of attribute sets
367
413
msgs dict of all messages (index by name)
414
+ sub_msgs dict of all sub messages (index by name)
368
415
ops dict of all valid requests / responses
369
416
ntfs dict of all async events
370
417
consts dict of all constants/enums
@@ -405,6 +452,7 @@ def __init__(self, spec_path, schema_path=None, exclude_ops=None):
405
452
jsonschema .validate (self .yaml , schema )
406
453
407
454
self .attr_sets = collections .OrderedDict ()
455
+ self .sub_msgs = collections .OrderedDict ()
408
456
self .msgs = collections .OrderedDict ()
409
457
self .req_by_value = collections .OrderedDict ()
410
458
self .rsp_by_value = collections .OrderedDict ()
@@ -441,6 +489,9 @@ def new_attr_set(self, elem):
441
489
def new_struct (self , elem ):
442
490
return SpecStruct (self , elem )
443
491
492
+ def new_sub_message (self , elem ):
493
+ return SpecSubMessage (self , elem );
494
+
444
495
def new_operation (self , elem , req_val , rsp_val ):
445
496
return SpecOperation (self , elem , req_val , rsp_val )
446
497
@@ -529,6 +580,10 @@ def resolve(self):
529
580
attr_set = self .new_attr_set (elem )
530
581
self .attr_sets [elem ['name' ]] = attr_set
531
582
583
+ for elem in self .yaml .get ('sub-messages' , []):
584
+ sub_message = self .new_sub_message (elem )
585
+ self .sub_msgs [sub_message .name ] = sub_message
586
+
532
587
if self .msg_id_model == 'unified' :
533
588
self ._dictify_ops_unified ()
534
589
elif self .msg_id_model == 'directional' :
0 commit comments