15
15
import ipaddress
16
16
import struct
17
17
18
- __all__ = ["V9DataFlowSet" , "V9DataRecord" , "V9ExportPacket" , "V9Header" , "V9TemplateField" ,
18
+ __all__ = ["V9DataFlowSet" , "V9DataRecord" , "V9ExportPacket" , "V9Header" , "V9TemplateField" , "V9OptionsTemplateFlowSet"
19
19
"V9TemplateFlowSet" , "V9TemplateNotRecognized" , "V9TemplateRecord" ]
20
20
21
21
V9_FIELD_TYPES = {
@@ -263,6 +263,17 @@ def __repr__(self):
263
263
' ' .join ([V9_FIELD_TYPES [field .field_type ] for field in self .fields ]))
264
264
265
265
266
+ class V9OptionsTemplateFlowSet :
267
+ """An options template flowset. Always uses flowset ID 1.
268
+ TODO: not handled at the moment, only stub implementation
269
+ """
270
+ def __init__ (self , data ):
271
+ pack = struct .unpack ('!HHH' , data [:6 ])
272
+ self .flowset_id = pack [0 ]
273
+ self .length = pack [1 ]
274
+ self .template_id = pack [2 ]
275
+
276
+
266
277
class V9TemplateFlowSet :
267
278
"""A template flowset, which holds an id that is used by data flowsets to
268
279
reference back to the template. The template then has fields which hold
@@ -340,6 +351,7 @@ def __init__(self, data, templates):
340
351
skipped_flowsets_offsets = []
341
352
while offset != len (data ):
342
353
flowset_id = struct .unpack ('!H' , data [offset :offset + 2 ])[0 ]
354
+
343
355
if flowset_id == 0 : # TemplateFlowSet always have id 0
344
356
tfs = V9TemplateFlowSet (data [offset :])
345
357
@@ -353,6 +365,13 @@ def __init__(self, data, templates):
353
365
# Update the templates with the provided templates, even if they are the same
354
366
self ._templates .update (tfs .templates )
355
367
offset += tfs .length
368
+
369
+ elif flowset_id == 1 : # Option templates always use ID 1
370
+ # TODO: Options templates are ignored, to prevent template ID collision
371
+ # (if a collision can occur is not yet tested)
372
+ otfs = V9OptionsTemplateFlowSet (data [offset :])
373
+ offset += otfs .length
374
+
356
375
else :
357
376
try :
358
377
dfs = V9DataFlowSet (data [offset :], self ._templates )
0 commit comments