Advertisement
Guest User

ProtocolProfilerProcs.tcl

a guest
Nov 12th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 23.21 KB | None | 0 0
  1. #####
  2. # ProtocolProfileProcs.tcl
  3. # Author: Thomas Schockaert
  4. # Last Changed: 20141104
  5. # Contents: The procedures that perform the protocol mapping magic that translates bytes to meaningful logs.
  6. # Howto:
  7. # - You only need to call mapProtocol in your iRule in the CLIENT_DATA and SERVER_DATA event.
  8. # - It is possible that you need to pre-treat the payload, as is the case with SSL, where one payload can contain multiple instances of the protocol map.
  9. #   You would need to run mapProtocol on each 'record', instead of on the entire payload, as the payload contains multiple records.
  10. # - Example:
  11. #   when CLIENT_ACCEPTED {
  12. #       array set pmap [call ProtocolProfilerInit::init_dns]
  13. #   }
  14. #   when CLIENT_DATA {
  15. #       binary scan [UDP::payload] H* client_payload_in_hex
  16. #       call ProtocolProfilerProcs::mapProtocol 0 $client_payload_in_hex 0 {} "" [array get pmap] $static::DEBUG
  17. #   }
  18. #   when SERVER_DATA {
  19. #       binary scan [UDP::payload] H* server_payload_in_hex
  20. #       call ProtocolProfilerProcs::mapProtocol 0 $server_payload_in_hex 0 {} "" [array get pmap] $static::DEBUG
  21. #   }
  22. #####
  23.  
  24. ### isIndex { index lst_pmap debug }
  25. # Description:
  26. # - This procedure checks if a given index exists in the 'pmap' array
  27. # Arguments:
  28. # - index => an index to verify for existence
  29. # - lst_pmap => the protocol map
  30. # - debug => 0 = no debug logging, 1 = debug logging
  31. # Returns:
  32. # - 1 if found
  33. # - 0 if not found
  34. proc isIndex { index lst_pmap debug } {
  35.     # create the protocol map array from the protocol map list
  36.     array set pmap $lst_pmap
  37.     # search the array for the existence of the index
  38.     if { [info exists pmap($index)] } {
  39.         return 1
  40.     } else { if { $debug == 2 } { log local0. "DEBUG isIndex: pmap($index) could not be found" } }
  41.     return 0
  42. }
  43.  
  44. ### isParent { index lst_pmap debug }
  45. # Description:
  46. # - This procedure appends '_0' to a given text (index) and checks if it exists in the 'pmap' array
  47. # Arguments:
  48. # - index => a string that can be found in the pmap names list (a name is an array key)
  49. # - lst_pmap => the protocol map
  50. # - debug => 0 = no debug logging, 1 = debug logging
  51. # Returns:
  52. # - 1 if found
  53. # - 0 if not found
  54. proc isParentIndex { index lst_pmap debug } {
  55.     # verify that the given index exists
  56.     if { [call ProtocolProfilerProcs::isIndex $index $lst_pmap $debug] } {
  57.         # establish what its first child should look like
  58.         set first_child_index "${index}_0"
  59.         # verify if that first child exists
  60.         if { [call ProtocolProfilerProcs::isIndex $first_child_index $lst_pmap $debug] } {
  61.             return 1
  62.         } else { if { $debug == 2 } { log local0. "DEBUG isParentIndex: isIndex said '$first_child_index' is not a valid index" } }
  63.     } else { if { $debug == 2 } { log local0. "DEBUG isParentIndex: isIndex said '$index' is not a valid index" } }
  64.     return 0
  65. }
  66.  
  67. ### getParentIndex { index lst_pmap debug }
  68. # Description:
  69. # - This procedure splits an index string by the '_' character and returns all but the last part
  70. # Arguments:
  71. # - index => a string splittable by '_' characters (ex.: 0_1_2_3)
  72. # - lst_pmap => the protocol map
  73. # - debug => 0 = no debug logging, 1 = debug logging
  74. # Returns:
  75. # - the parent index string if found
  76. # - -1 if there is no parent index to generate (i.e.: if the index passed to the proc does not contain '_' characters)
  77. proc getParentIndex { index lst_pmap debug } {
  78.     # split the index string by the '_' character
  79.     set lst_index [split $index "_"]
  80.     # if one or more '_' characters are found, concatenate all but the last field and return it
  81.     if { [llength $lst_index] > 1 } {
  82.         set first_parent_index ""
  83.         for { set x 0 } { $x < [expr [llength $lst_index]-1] } { incr x } {
  84.             append first_parent_index "[lindex $lst_index $x]_"
  85.         }
  86.         set first_parent_index [substr $first_parent_index 0 [expr [string length $first_parent_index] -1]]
  87.         return $first_parent_index
  88.     } else { if { $debug == 2 } { log local0. "DEBUG getParentIndex: $index is a root parent (no '_' found)" } }
  89.     return -1
  90. }
  91.  
  92. ### getSiblingIndex { index lst_pmap debug }
  93. # Description:
  94. # - This procedure returns a list containing the siblings of an index. It finds them by finding the parent index and looping through possible child indexes.
  95. # - The returned list does not include the index itself, just its siblings.
  96. # Arguments:
  97. # - index => an index string
  98. # - lst_pmap => the protocol map
  99. # - debug => 0 = no debug logging, 1 = debug logging
  100. # Returns:
  101. # - a list of sibling indexes (possibly empty)
  102. proc getSiblingIndexes { index lst_pmap debug } {
  103.     set lst_sibling_indexes {}
  104.     if { [call ProtocolProfilerProcs::isIndex $index $lst_pmap $debug] } {
  105.         set parent_index [call ProtocolProfilerProcs::getParentIndex $index $lst_pmap $debug]
  106.         if { [call ProtocolProfilerProcs::isParentIndex $parent_index $lst_pmap $debug] } {
  107.             for { set x 0 } { $x < 255 } { incr x } {
  108.                 set new_index "${parent_index}_$x"
  109.                 if { [call ProtocolProfilerProcs::isIndex $new_index $lst_pmap $debug] } {
  110.                     #if { !($index == $new_index) } {
  111.                         lappend lst_sibling_indexes $new_index
  112.                     #}
  113.                 } else { break }
  114.             }
  115.         } else { if { $debug == 2 } { log local0. "DEBUG getSiblingIndexes: isParentIndex said '$parent_index' is not a valid parent index" } }
  116.     } else { if { $debug == 2 } { log local0. "DEBUG getSiblingIndexes: isIndex said '$index' is not a valid index" } }
  117.     return $lst_sibling_indexes
  118. }
  119.  
  120. ### getChildrenIndexes { index lst_pmap debug }
  121. # Description:
  122. # - This procedure returns a list containing the children of an index. It finds them by checking if the index is a parent index and looping through possible child indexes.
  123. # Arguments:
  124. # - index => an index string
  125. # - lst_pmap => the protocol map
  126. # - debug => 0 = no debug logging, 1 = debug logging
  127. # Returns:
  128. # - a list of child indexes (possibly empty)
  129. proc getChildrenIndexes { index lst_pmap debug } {
  130.     set lst_child_indexes {}
  131.     if { [call ProtocolProfilerProcs::isParentIndex $index $lst_pmap $debug] } {
  132.         for { set x 0 } { $x < 255 } { incr x } {
  133.             set new_child_index "${index}_$x"
  134.             if { !([call ProtocolProfilerProcs::isIndex $new_child_index $lst_pmap 0]) } {
  135.                 break
  136.             }
  137.             else {
  138.                 lappend lst_child_indexes $new_child_index
  139.             }
  140.         }
  141.     } else { if { $debug == 2 } { log local0. "DEBUG getChildrenIndexes: isParentIndex said '$parent_index' is not a valid parent index" } }
  142.     return $lst_child_indexes
  143. }
  144.  
  145. ### getMarkedIndexes { index lst_pmap debug }
  146. # Description:
  147. # - This procedure returns a list containing the protocol map levels that have a marker below the current index.
  148. # - A marker consist of a field definition of 2 fields: the 'fieldnamename' and 'markerfield=markervalue'
  149. # Arguments:
  150. # - index => an index string
  151. # - lst_pmap => the protocol map
  152. # - debug => 0 = no debug logging, 1 = debug logging
  153. # Returns:
  154. # - a list of marker indexes (possibly empty)
  155. proc getMarkedIndexes { index lst_pmap debug } {
  156.     # create the protocol map array from the protocol map list
  157.     array set pmap $lst_pmap
  158.     set lst_marker_indexes {}
  159.     if { [call ProtocolProfilerProcs::isParentIndex $index $lst_pmap $debug] } {
  160.         for { set x 0 } { $x < 255 } { incr x } {
  161.             set new_marker_index "${index}_$x"
  162.             if { [call ProtocolProfilerProcs::isIndex $new_marker_index $lst_pmap 0] } {
  163.                 if { [llength $pmap($new_marker_index)] == 2 } {
  164.                     lappend lst_marker_indexes $new_marker_index
  165.                 }
  166.             }
  167.         }
  168.     } else { if { $debug == 2 } { log local0. "DEBUG getMarkerIndexes: isParentIndex said '$index' is not a valid parent index" } }
  169.     return $lst_marker_indexes
  170. }
  171.  
  172. ### getIndexByFieldname { index fieldname lst_pmap debug }
  173. # Description:
  174. # - This procedure returns the index string for a fieldname that is present in the protocol map.
  175. # Arguments:
  176. # - index => an index string
  177. # - fieldname => a fieldname to search for in the protocol map
  178. # - lst_pmap => the protocol map
  179. # - debug => 0 = no debug logging, 1 = debug logging
  180. # Returns:
  181. # - the index string for the fieldname if found
  182. # - an empty string if not found
  183. proc getIndexByFieldname { index fieldname lst_pmap debug } {
  184.     # create the protocol map array from the protocol map list
  185.     array set pmap $lst_pmap
  186.     set lst_children [call ProtocolProfilerProcs::getChildrenIndexes $index $lst_pmap $debug]
  187.     set search_index 0
  188.     if { [llength $lst_children] > 0 } {
  189.         foreach { child_index } $lst_children {
  190.             if { [lindex $pmap($child_index) 0] == "$fieldname" } {
  191.                 set search_index $child_index
  192.                 break
  193.             }
  194.             else {
  195.                 set search_index [call ProtocolProfilerProcs::getIndexByFieldname $child_index $fieldname $lst_pmap $debug]
  196.             }
  197.         }
  198.     } else { if { $debug == 2 } { log -noname local0. "DEBUG getIndexByFieldname: getChildrenIndexes said '$index' has no children." } }
  199.     return $search_index
  200. }
  201.  
  202. ### getFieldDefinitionByIndex { index lst_pmap debug }
  203. # Description:
  204. # - This procedure returns the field definition string for an index that is present in the protocol map.
  205. # Arguments:
  206. # - index => an index string
  207. # - lst_pmap => the protocol map
  208. # - debug => 0 = no debug logging, 1 = debug logging
  209. # Returns:
  210. # - the field definition for the index if found
  211. # - an empty string if not found
  212. proc getFieldDefinitionByIndex { index lst_pmap debug } {
  213.     # create the protocol map array from the protocol map list
  214.     array set pmap $lst_pmap
  215.     set returnvalue ""
  216.     if { [call ProtocolProfilerProcs::isIndex $index $lst_pmap $debug] } {
  217.         if { [llength $pmap($index)] >= 3 } {
  218.             set returnvalue $pmap($index)
  219.         } else { if { $debug == 2 } { log -noname local0. "DEBUG getFieldDefinitionByIndex: '$index' doet not contain a valid field definition" } }    
  220.     } else { if { $debug == 2 } { log -noname local0. "DEBUG getFieldDefinitionByIndex: isIndex said '$index' is not a valid index" } }
  221.     return $returnvalue
  222. }
  223.  
  224. ### getFieldDefinitionByFieldname { fieldname index lst_pmap debug }
  225. # Description:
  226. # - This procedure returns the field definition string for an fieldname that is present in the protocol map.
  227. # Arguments:
  228. # - fieldname => a fieldname string
  229. # - index => an index string
  230. # - lst_pmap => the protocol map
  231. # - debug => 0 = no debug logging, 1 = debug logging
  232. # Returns:
  233. # - the field definition for the fieldname if found
  234. # - an empty string if not found
  235. proc getFieldDefinitionByFieldname { fieldname index lst_pmap debug } {
  236.     # create the protocol map array from the protocol map list
  237.     array set pmap $lst_pmap
  238.     set fielddefinition ""
  239.     set potential_fielddefinition [call ProtocolProfilerProcs::getFieldDefinitionByIndex $index $lst_pmap $debug]
  240.     if { [lindex $potential_fielddefinition 0] == $fieldname } {
  241.         set fielddefinition $potential_fielddefinition
  242.     }
  243.     else {
  244.         set lst_children [call ProtocolProfilerProcs::getChildrenIndexes $index $lst_pmap 0]
  245.         if { [llength $lst_children] > 0 } {
  246.             foreach { child_index } $lst_children {
  247.                 set fielddefinition [call ProtocolProfilerProcs::getFieldDefinitionByFieldname $fieldname $child_index $lst_pmap $debug]
  248.                 if { !($fielddefinition == "") } {
  249.                     break
  250.                 }
  251.             }
  252.         } else { if { $debug == 2 } { log -noname local0. "DEBUG getFieldDefinitionByFieldname: getChildrenIndexes said '$index' has no children." } }
  253.     }
  254.     return $fielddefinition
  255. }
  256.  
  257. proc resolveMarker { index data offset lst_pmap logspacing debug } {
  258.     array set pmap $lst_pmap
  259.     set returnvalue {}
  260.     set marker_fielddefinition [call ProtocolProfilerProcs::getFieldDefinitionByIndex $index $lst_pmap $debug]
  261.     if { !($marker_fielddefinition == "") } {
  262.         if { $debug == 1 } { log -noname local0. "${logspacing} resolveMarker: found a potential marker field definition at index '$index' ($marker_fielddefinition)" }
  263.         set marker_fieldname [lindex $marker_fielddefinition 0]
  264.         set marker_bytelength [lindex $marker_fielddefinition 1]
  265.         if { [string is integer $marker_bytelength] } {
  266.             if { $debug == 1 } { log -noname local0. "${logspacing} resolveMarker: confirmed field definition at index '$index' as a valid marker" }
  267.             set marker_datalength [expr $marker_bytelength*2]
  268.             set marker_format [lindex $marker_fielddefinition 0]
  269.             set lst_markedindexes [call ProtocolProfilerProcs::getMarkedIndexes $index $lst_pmap $debug]
  270.             set lst_markedindexes_length [llength $lst_markedindexes]
  271.             if { $lst_markedindexes_length > 0 } {
  272.                 if { $debug == 1 } { log -noname local0. "${logspacing} resolveMarker: found $lst_markedindexes_length indexes that reference '$marker_fieldname' as their marker ([join $lst_markedindexes ", "])" }
  273.                 foreach { marked_index } $lst_markedindexes {
  274.                     set marked_index_name [lindex $pmap($marked_index) 0]
  275.                     set marked_index_markerdescription [lindex $pmap($marked_index) 1]
  276.                     set marked_index_marker_name [lindex [split $marked_index_markerdescription "="] 0]
  277.                     set marked_index_marker_value [lindex [split $marked_index_markerdescription "="] 1]
  278.                     set marker_data 0x[substr $data $offset $marker_datalength]
  279.                     if { $marked_index_marker_value == $marker_data } {
  280.                         if { $debug == 1 } { log -noname local0. "${logspacing}- resolveMarker: index '$marked_index' matches the value of the marker '$marker_fieldname'" }
  281.                         set offset [expr $offset+$marker_datalength]
  282.                         lappend returnvalue $offset
  283.                         lappend returnvalue $marked_index
  284.                         break
  285.                     }
  286.                     elseif { $marked_index_marker_value == "*" } {
  287.                         if { $debug == 1 } { log -noname local0. "${logspacing}- resolveMarker: index '$marked_index' matches the wildcard value of the marker '$marker_fieldname'" }
  288.                         set offset [expr $offset+$marker_datalength]
  289.                         lappend returnvalue $offset
  290.                         lappend returnvalue $marked_index
  291.                         break                      
  292.                     }
  293.                     else {
  294.                         if { $debug == 1 } { log -noname local0. "${logspacing}- resolveMarker: index '$marked_index' does not match the value of the marker '$marker_fieldname'" }
  295.                     }
  296.                 }
  297.             }
  298.             else {
  299.                 if { $debug == 1 } { log -noname local0. "${logspacing} resolveMarker: could not find indexes that reference '$marker_fieldname' as their marker" }
  300.             }
  301.         }
  302.         else {
  303.             if { $debug == 1 } { log -noname local0. "${logspacing} resolveMarker: could not find a valid marker field definition at index '$index' ($pmap($index)) (bytelength not an integer)" }
  304.         }
  305.     }
  306.     else {
  307.         if { $debug == 1 } { log -noname local0. "${logspacing} resolveMarker: could not find a valid marker field definition at index '$index' ($pmap($index))" }
  308.     }
  309.     return $returnvalue
  310. }
  311.  
  312. proc resolveFields { index data offset lst_lengthfields lst_pmap logspacing debug } {
  313.     array set pmap $lst_pmap
  314.     set returnvalue {}
  315.     set lst_indexestoresolve [call ProtocolProfilerProcs::getSiblingIndexes $index $lst_pmap $debug]
  316.     set lst_indexestoresolve_length [llength $lst_indexestoresolve]
  317.     if { $lst_indexestoresolve_length > 0 } {
  318.         if { $debug == 1 } { log -noname local0. "${logspacing} resolveFields: found $lst_indexestoresolve_length potential index(es) on the level of index '$index'" }
  319.         foreach { resolve_index } $lst_indexestoresolve {
  320.             set resolve_index_fielddefinition [call ProtocolProfilerProcs::getFieldDefinitionByIndex $resolve_index $lst_pmap $debug]
  321.             if { !($resolve_index_fielddefinition == "") } {
  322.                 if { $debug == 1 } { log -noname local0. "${logspacing}- resolveFields: index '$resolve_index' has a resolvable field definition" }
  323.                 set resolve_index_fieldname [lindex $resolve_index_fielddefinition 0]
  324.                 set resolve_index_bytelength [lindex $resolve_index_fielddefinition 1]
  325.                 set resolve_index_format [lindex $resolve_index_fielddefinition 2]
  326.                 if { [string is integer $resolve_index_bytelength] } {
  327.                     if { $debug == 1 } { log -noname local0. "${logspacing}-- resolveFields: index '$resolve_index' has a decimal bytelength field" }
  328.                     set resolve_index_datalength [expr $resolve_index_bytelength*2]
  329.                 }
  330.                 else {
  331.                     if { "$resolve_index_bytelength" contains "\[" } {
  332.                         if { $debug == 9 } { log -noname local0. "${logspacing}-- resolveFields: index '$resolve_index' has a calculated (formula) bytelength field" }
  333.                         eval "set tmp_resolve_index_bytelength $resolve_index_bytelength"
  334.                         set resolve_index_datalength [expr ($tmp_resolve_index_bytelength-($offset/2))*2]
  335.                     }
  336.                     else {
  337.                         if { $debug == 9 } { log -noname local0. "${logspacing}-- resolveFields: index '$resolve_index' references another field's value as its length" }
  338.                         set resolve_findlengthfield [lsearch $lst_lengthfields "${resolve_index_bytelength}_*"]
  339.                         if { !($resolve_findlengthfield == "") } {
  340.                             if { $debug == 9 } { log -noname local0. "${logspacing}-- resolveFields: the referenced length field '${resolve_index_bytelength}' for index '$resolve_index' was found" }
  341.                             set resolve_index_datalength [expr [lindex [split [lindex $lst_lengthfields [lsearch $lst_lengthfields "${resolve_index_bytelength}_*"]] "_"] 1]*2]
  342.                         }
  343.                         else {
  344.                             if { $debug == 9 } { log -noname local0. "${logspacing}-- resolveFields: the referenced length field '${resolve_index_bytelength}' for index '$resolve_index' could not be found" }
  345.                         }
  346.                     }
  347.                 }
  348.                 set resolve_index_data_rawvalue [substr $data $offset $resolve_index_datalength]
  349.                 set resolve_index_data_readablevalue "n/a"
  350.                 set nodecoder 0
  351.                 eval "if \{ \[catch \{ set resolve_index_data_readablevalue \[call ProtocolProfilerDecoders::decode_$resolve_index_format {$resolve_index_fielddefinition} \"$resolve_index_data_rawvalue\"\] \} errmsg\] \} \{ set nodecoder 1 \}"
  352.                 if { $nodecoder == 1 || $resolve_index_data_readablevalue == "Unknown" } {
  353.                     set resolve_index_data_readablevalue "(0x$resolve_index_data_rawvalue) Unknown"
  354.                 }
  355.                 set offset [expr $offset+$resolve_index_datalength]
  356.                 if { $debug == 1 } { log -noname local0. "$logspacing-- resolveFields: $resolve_index_fieldname = $resolve_index_data_readablevalue" }
  357.                 if { $resolve_index_fieldname ends_with "length" } {
  358.                     lappend lst_lengthfields "${resolve_index_fieldname}_$resolve_index_data_readablevalue"
  359.                 }
  360.                 lappend returnvalue "$resolve_index_fieldname = $resolve_index_data_readablevalue"
  361.             }
  362.             else {
  363.                 if { $debug == 1 } { log -noname local0. "${logspacing}- resolveFields: index '$resolve_index' doet not have a resolvable field definition" }
  364.             }
  365.         }
  366.     }
  367.     else {
  368.         if { $debug == 1 } { log -noname local0. "${logspacing} resolveFields: could not find any potential indexes that are siblings to index '$index'" }
  369.     }
  370.     return "$offset {$lst_lengthfields} $returnvalue"
  371. }
  372.  
  373. ### getFieldDefinitionByFieldname { index data offset logspacing lst_pmap debug }
  374. # Description (very short):
  375. # - mapProtocol is called for a specific index; this is its starting point
  376. # - 1) It verifies if this index has a valid field definition (minimum of 3 fields in the definition, checked by proc getFieldDefinitionByIndex).
  377. # -    If the index has no valid field definition, it gets a list of its siblings and tries to resolve the fields that have a valid field definition.
  378. # -    However, if the index does have a valid field definition, it checks if it's being used as a marker by children of this index.
  379. # - 2) If it's being used as a marker by one or more of its children, it will resolve the index to its value and advance the offset with its length
  380. # -    If it's being used as a marker, after having resolved the field, it will it will try to resolve the siblings of the marker level further advancing the offset as required.
  381. # -    Once finished, it will change the starting point to within the marker level by calling itself (mapProtocol) on the matching marker index.
  382. # Arguments:
  383. # - index => an index string
  384. # - data => the actual protocol data as seen on the wire
  385. # - offset => the offset at which to start reading the protocol data
  386. # - logspacing => usually just a space, used to trace the recursion of the function visually by enabling debug = 2
  387. # - lst_pmap => the protocol map
  388. # - debug => 0 = no debug logging, 1 = debug logging
  389. # Returns:
  390. # - nothing
  391. proc mapProtocol { index data offset lst_lengthfields logspacing lst_pmap debug } {
  392.     # create the protocol map array from the protocol map list
  393.     array set pmap $lst_pmap
  394.     if { $debug == 1 } { log -noname local0. "${logspacing}- mapProtocol on index '$index' with offset '$offset'" }
  395.     set lst_indexestoresolve {}
  396.     set marker_found 0
  397.     set marker_found_index ""
  398.     set newoffset $offset
  399.    
  400.     # resolveMarkers
  401.     if { $debug == 1 } { log -noname local0. "${logspacing}-- mapProtocol: detecting markers" }
  402.     set lst_markerindexestoresolve [call ProtocolProfilerProcs::getSiblingIndexes $index $lst_pmap $debug]
  403.     set lst_markerindexestoresolve_length [llength $lst_markerindexestoresolve]
  404.     set fields_resolved 0
  405.     if { $lst_markerindexestoresolve_length > 0 } {
  406.         foreach { resolve_markerindex } $lst_markerindexestoresolve {
  407.             set lst_markerresults [call ProtocolProfilerProcs::resolveMarker $resolve_markerindex $data $newoffset $lst_pmap "${logspacing}---" $debug]
  408.             if { [llength $lst_markerresults] == 2 } {
  409.                 #set offset [lindex $lst_markerresults 0]
  410.                 set marker_found_index [lindex $lst_markerresults 1]
  411.                 # resolveFields (only once for the current index level; this is to avoid an n+1'th marker from resolving the same fields when it has already been done by the first marker)
  412.                 if { $fields_resolved == 0 } {
  413.                     set fields_resolved 1
  414.                     if { $debug == 1 } { log -noname local0. "${logspacing}--- mapProtocol: resolving fields on the same level as the marker '$index'" }
  415.                     set lst_fields {}
  416.                     set lst_fields [call ProtocolProfilerProcs::resolveFields $index $data $newoffset $lst_lengthfields $lst_pmap "${logspacing}---" $debug]
  417.                     if { [llength $lst_fields] > 0 } {
  418.                         set lst_fields_cnt 0
  419.                         foreach { field } $lst_fields {
  420.                             if { $lst_fields_cnt > 1 } {
  421.                                 log -noname local0. "$field"
  422.                             }
  423.                             incr lst_fields_cnt
  424.                         }
  425.                     }
  426.                     set newoffset [lindex $lst_fields 0]
  427.                     set lst_lengthfields [lindex $lst_fields 1]
  428.                 }
  429.                 # mapProtocol on the found marker
  430.                 if { $debug == 1 } { log -noname local0. "${logspacing}-- mapProtocol: mapping detected marker '$marker_found_index'" }
  431.                 call ProtocolProfilerProcs::mapProtocol $marker_found_index $data $newoffset $lst_lengthfields "$logspacing " $lst_pmap $debug
  432.             }
  433.         }
  434.     }
  435.    
  436.     # resolveFields when it hasn't been done yet through marker resolving (only happens when no markers were found on this level)
  437.     if { $offset == $newoffset } {
  438.         if { $debug == 1 } { log -noname local0. "${logspacing}-- mapProtocol: no markers on this level so resolving fields on the same level as '$index'" }
  439.         set lst_fields {}
  440.         set lst_fields [call ProtocolProfilerProcs::resolveFields $index $data $offset $lst_lengthfields $lst_pmap "${logspacing}---" $debug]
  441.         if { [llength $lst_fields] > 0 } {
  442.             set lst_fields_cnt 0
  443.             foreach { field } $lst_fields {
  444.                 if { $lst_fields_cnt > 1 } {
  445.                     log -noname local0. "$field"
  446.                 }
  447.                 incr lst_fields_cnt
  448.             }
  449.         }
  450.         set offset [lindex $lst_fields 0]
  451.        
  452.         # mapProtocol on the next sublevel
  453.         if { [call ProtocolProfilerProcs::isParentIndex $index $lst_pmap $debug] } {
  454.             if { $debug == 1 } { log -noname local0. "${logspacing}-- mapProtocol: nothing left on level '$index'; mapping one level down: '${index}_0'" }
  455.             call ProtocolProfilerProcs::mapProtocol ${index}_0 $data $offset $lst_lengthfields "$logspacing " $lst_pmap $debug
  456.         }
  457.         else {
  458.             if { $debug == 1 } { log -noname local0. "${logspacing}-- mapProtocol: nothing left on level '$index'; nothing on level '${index}_0' => END" }
  459.         }
  460.     }
  461.     else {
  462.         if { $debug == 1 } { log -noname local0. "${logspacing}-- mapProtocol: markers were found on this level, they have all been handled => END" }
  463.     }
  464. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement