2 * MATE -- Meta Analysis and Tracing Engine
4 * Copyright 2004, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include "moduleinfo.h"
46 #include <epan/packet.h>
47 #include <epan/strutil.h>
48 #include <epan/prefs.h>
49 #include <epan/proto.h>
50 #include <epan/epan_dissect.h>
52 #include <epan/filesystem.h>
53 #include <epan/report_err.h>
55 #include "mate_util.h"
59 #define DEFAULT_GOG_EXPIRATION 2.0
67 #define DEFAULT_MATE_LIB_PATH "matelib"
69 #define MATE_ITEM_ID_SIZE 24
71 /* Config AVP Names */
72 #define KEYWORD_ACTION "Action"
73 #define KEYWORD_SETTINGS "Settings"
74 #define KEYWORD_INCLUDE "Include"
75 #define KEYWORD_TRANSFORM "Transform"
76 #define KEYWORD_PDU "PduDef"
77 #define KEYWORD_PDUCRITERIA "PduCriteria"
78 #define KEYWORD_PDUEXTRA "PduExtra"
79 #define KEYWORD_PDUTRANSFORM "PduTransform"
80 #define KEYWORD_GOP "GopDef"
81 #define KEYWORD_GOPSTART "GopStart"
82 #define KEYWORD_GOPSTOP "GopStop"
83 #define KEYWORD_GOPEXTRA "GopExtra"
84 #define KEYWORD_GOPTRANSFORM "GopTransform"
85 #define KEYWORD_GOGDEF "GogDef"
86 #define KEYWORD_GOGKEY "GogKey"
87 #define KEYWORD_GOGEXTRA "GogExtra"
88 #define KEYWORD_GOGTRANSFORM "GogTransform"
89 #define KEYWORD_NAME "Name"
90 #define KEYWORD_ON "On"
91 #define KEYWORD_FOR "For"
92 #define KEYWORD_FROM "From"
93 #define KEYWORD_TO "To"
94 #define KEYWORD_MATCH "Match"
95 #define KEYWORD_MODE "Mode"
96 #define KEYWORD_FILENAME "Filename"
97 #define KEYWORD_PROTO "Proto"
98 #define KEYWORD_METHOD "Method"
99 #define KEYWORD_TRANSPORT "Transport"
100 #define KEYWORD_PAYLOAD "Payload"
101 #define KEYWORD_STRICT "Strict"
102 #define KEYWORD_LOOSE "Loose"
103 #define KEYWORD_EVERY "Every"
104 #define KEYWORD_REPLACE "Replace"
105 #define KEYWORD_INSERT "Insert"
106 #define KEYWORD_MAP "Map"
107 #define KEYWORD_GOGEXPIRE "GogExpiration"
108 #define KEYWORD_GOPTREE "GopTree"
109 #define KEYWORD_DISCARDPDU "DiscardPduData"
110 #define KEYWORD_LIBPATH "ThingLibPath"
111 #define KEYWORD_SHOWPDUTREE "ShowPduTree"
112 #define KEYWORD_SHOWGOPTIMES "ShowGopTimes"
113 #define KEYWORD_STOP "Stop"
114 #define KEYWORD_DROPGOP "DiscardUnassignedGop"
115 #define KEYWORD_DROPPDU "DiscardUnassignedPdu"
116 #define KEYWORD_LIB "Lib"
117 #define KEYWORD_ACCEPT "Accept"
118 #define KEYWORD_REJECT "Reject"
119 #define KEYWORD_NOTREE "NoTree"
120 #define KEYWORD_BASICTREE "BasicTree"
121 #define KEYWORD_FULLTREE "FullTree"
122 #define KEYWORD_PDUTREE "PduTree"
123 #define KEYWORD_FRAMETREE "FrameTree"
124 #define KEYWORD_GOPEXPIRATION "GopExpiration"
125 #define KEYWORD_GOPIDLETIMEOUT "GopIdleTimeout"
126 #define KEYWORD_GOPLIFETIME "GopLifetime"
128 #define KEYWORD_DEBUGFILENAME "Debug_File"
129 #define KEYWORD_DBG_GENERAL "Debug_General"
130 #define KEYWORD_DBG_CFG "Debug_Cfg"
131 #define KEYWORD_DBG_PDU "Debug_Pdu"
132 #define KEYWORD_DBG_GOP "Debug_Gop"
133 #define KEYWORD_DBG_GOG "Debug_Gog"
134 #ifdef _AVP_DEBUGGING
135 #define KEYWORD_DBG_AVPLIB "Debug_AVP_Lib"
136 #define KEYWORD_DBG_AVP "Debug_AVP"
137 #define KEYWORD_DBG_AVP_OP "Debug_AVP_Op"
138 #define KEYWORD_DBG_AVPL "Debug_AVPL"
139 #define KEYWORD_DBG_AVPL_OP "Debug_AVPL_Op"
142 #define VALUE_TOO ((void*)1)
144 typedef enum _mate_item_type {
151 typedef struct _mate_cfg_item mate_cfg_pdu;
152 typedef struct _mate_cfg_item mate_cfg_gop;
153 typedef struct _mate_cfg_item mate_cfg_gog;
155 typedef struct _mate_item mate_item;
156 typedef struct _mate_item mate_pdu;
157 typedef struct _mate_item mate_gop;
158 typedef struct _mate_item mate_gog;
160 typedef struct _mate_cfg_item {
163 GPtrArray* transforms; /* transformations to be applied */
164 AVPL* extra; /* attributes to be added */
165 guint last_id; /* keeps the last id given to an item of this kind */
167 GHashTable* my_hfids; /* for creating register info */
168 GHashTable* items; /* all the items of this type */
175 gboolean discard_pdu_attributes;
176 gboolean last_to_be_created;
178 GPtrArray* transport_ranges; /* hfids of candidate transport ranges from which to extract attributes */
179 GPtrArray* payload_ranges; /* hfids of candidate payload ranges from which to extract attributes */
180 GHashTable* hfids_attr; /* k=hfid v=avp_name */
182 avpl_match_mode criterium_match_mode;
183 AVPL* criterium; /* must match to be created */
184 int hfid_pdu_rel_time;
185 int hfid_pdu_time_in_gop;
188 /* common to gop and gog */
195 AVPL* start; /* start candidate avpl */
196 AVPL* stop; /* stop candidate avpl */
197 AVPL* key; /* key candidate avpl */
198 guint8* show_pdu_tree;
204 int hfid_gop_num_pdus;
206 GHashTable* gop_index;
207 GHashTable* gog_index;
210 guint8* gop_as_subtree;
212 int hfid_gog_num_of_gops;
214 int hfid_gog_gopstart;
215 int hfid_gog_gopstop;
220 typedef struct _mate_config {
221 /* current defaults */
222 float gog_expiration; /* default expirations for gogs if undefined in gog */
223 gboolean discard_pdu_attributes; /* destroy the pdu's avpl once analyzed */
224 gboolean drop_pdu; /* destroy the pdu if not assign to a gop */
225 gboolean drop_gop; /* destroy the gop if not assign to a gog */
226 guint8* mate_lib_path; /* where to look for "Include" files first */
227 guint8* show_pdu_tree;
229 gboolean last_to_be_created;
230 avpl_match_mode match_mode;
231 avpl_replace_mode replace_mode;
232 guint8* gop_as_subtree;
235 float gop_expiration;
236 float gop_idle_timeout;
239 /* text "constants" */
248 /* what to dbgprint */
255 guint8* mate_config_file; /* name of the config file */
256 GString* mate_attrs_filter; /* "ip.addr || dns.id || ... " for the tap */
257 GString* mate_protos_filter; /* "dns || ftp || ..." for the tap */
258 FILE* dbg_facility; /* where to dump dbgprint output g_message if null */
261 GHashTable* pducfgs; /* k=pducfg->name v=pducfg */
262 GHashTable* gopcfgs; /* k=gopcfg->name v=gopcfg */
263 GHashTable* gogcfgs; /* k=gogcfg->name v=gogcfg */
264 GHashTable* transfs; /* k=transform->name v=transform */
266 GPtrArray* pducfglist; /* pducfgs in order of "execution" */
267 GHashTable* gops_by_pduname; /* k=pducfg->name v=gopcfg */
268 GHashTable* gogs_by_gopname; /* k=gopname v=loal where avpl->name == matchedgop->name */
275 typedef struct _mate_runtime_data {
276 guint current_items; /* a count of items */
277 GMemChunk* mate_items;
279 guint highest_analyzed_frame;
281 GHashTable* frames; /* k=frame.num v=pdus */
285 /* these are used to contain information regarding pdus, gops and gogs */
287 /* all three of them */
288 guint32 id; /* 1:1 -> saving a g_malloc */
289 mate_cfg_item* cfg; /* the type of this item */
291 AVPL* avpl; /* the attributes of the pdu/gop/gog */
293 mate_item* next; /* in pdu: next in gop; in gop: next in gog; in gog this doesn't make any sense yet */
295 float expiration; /* when will it expire after release (all gops releases if gog)? */
296 float idle_expiration; /* when will it expire if no new pdus are assigned to it */
298 /* on gop and gog: */
299 float start_time; /* time of start */
300 float release_time; /* when this gop/gog was released */
301 float last_time; /* the rel_time at which the last pdu has been added (to gop or gog's gop) */
303 /* union _payload { */
305 guint32 frame; /* wich frame I belog to? */
306 mate_gop* gop; /* the gop the pdu belongs to (if any) */
307 gboolean first; /* is this the first pdu in this frame? */
308 gboolean is_start; /* this is the start pdu for this gop */
309 gboolean is_stop; /* this is the stop pdu for this gop */
310 gboolean after_release; /* this pdu comes after the stop */
311 float rel_time; /* time since start of capture */
312 float time_in_gop; /* time since gop start */
313 mate_pdu* next_in_frame; /* points to the next pdu in this frame */
317 /* membership* gogs; */
318 mate_gog* gog; /* the gog of a gop */
319 mate_pdu* pdus; /* pdus that belong to a gop (NULL in gog) */
320 gboolean released; /* has this gop been released? */
321 int num_of_pdus; /* how many gops a gog has? */
322 int num_of_after_release_pdus; /* how many pdus have arrived since it's been released */
323 guint8* gop_key; /* used by gop */
324 mate_pdu* last_pdu; /* last pdu in pdu's list */
326 float time_to_timeout;
330 /* membership* gops; */
331 mate_gop* gops; /* gops that belong to a gog (NULL in gop) */
332 int num_of_gops; /* how many gops a gog has? */
333 int num_of_counting_gops; /* how many of them count for gog release */
334 int num_of_released_gops; /* how many of them have already been released */
335 guint last_n; /* the number of attributes the avpl had the last time we checked */
336 GPtrArray* gog_keys; /* the keys under which this gog is stored in the gogs hash */
337 mate_gop* last_gop; /* last gop in gop's list */
342 /* from mate_runtime.c */
343 extern void initialize_mate_runtime(void);
344 extern mate_pdu* mate_get_pdus(guint32 framenum);
345 extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree);
347 /* from mate_setup.c */
348 extern mate_config* mate_make_config(guint8* filename, int mate_hfid);
349 extern mate_config* mate_cfg(void);