2 * MATE -- Meta Analysis and Tracing Engine
4 * Copyright 2004, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
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 #define VALUE_TOO ((void*)1)
73 #define MateConfigError 65535
75 typedef enum _gop_tree_mode_t {
81 typedef enum _gop_pdu_tree {
88 typedef enum _accept_mode_t {
94 typedef struct _mate_cfg_pdu {
96 guint last_id; /* keeps the last id given to an item of this kind */
98 GHashTable* items; /* all the items of this type */
99 GPtrArray* transforms; /* transformations to be applied */
104 int hfid_pdu_rel_time;
105 int hfid_pdu_time_in_gop;
107 GHashTable* my_hfids; /* for creating register info */
112 GHashTable* hfids_attr; /* k=hfid v=avp_name */
115 gboolean last_extracted;
116 gboolean drop_unassigned;
118 GPtrArray* transport_ranges; /* hfids of candidate transport ranges from which to extract attributes */
119 GPtrArray* payload_ranges; /* hfids of candidate payload ranges from which to extract attributes */
121 avpl_match_mode criterium_match_mode;
122 accept_mode_t criterium_accept_mode;
127 typedef struct _mate_cfg_gop {
129 guint last_id; /* keeps the last id given to an item of this kind */
130 GHashTable* items; /* all the items of this type */
132 GPtrArray* transforms; /* transformations to be applied */
135 AVPL* key; /* key candidate avpl */
136 AVPL* start; /* start candidate avpl */
137 AVPL* stop; /* stop candidate avpl */
138 AVPL* extra; /* attributes to be added */
144 gboolean drop_unassigned;
145 gop_pdu_tree_t pdu_tree_mode;
148 GHashTable* my_hfids; /* for creating register info */
154 int hfid_gop_num_pdus;
161 GHashTable* gop_index;
162 GHashTable* gog_index;
166 typedef struct _mate_cfg_gog {
169 GHashTable* items; /* all the items of this type */
170 guint last_id; /* keeps the last id given to an item of this kind */
172 GPtrArray* transforms; /* transformations to be applied */
175 AVPL* extra; /* attributes to be added */
178 gop_tree_mode_t gop_tree_mode;
181 GHashTable* my_hfids; /* for creating register info */
183 int hfid_gog_num_of_gops;
185 int hfid_gog_gopstart;
186 int hfid_gog_gopstop;
197 typedef struct _mate_config {
198 gchar* mate_config_file; /* name of the config file */
202 GString* fields_filter; /* "ip.addr || dns.id || ... " for the tap */
203 GString* protos_filter; /* "dns || ftp || ..." for the tap */
206 FILE* dbg_facility; /* where to dump dbgprint output g_message if null */
208 gchar* mate_lib_path; /* where to look for "Include" files first */
210 GHashTable* pducfgs; /* k=pducfg->name v=pducfg */
211 GHashTable* gopcfgs; /* k=gopcfg->name v=gopcfg */
212 GHashTable* gogcfgs; /* k=gogcfg->name v=gogcfg */
213 GHashTable* transfs; /* k=transform->name v=transform */
215 GPtrArray* pducfglist; /* pducfgs in order of "execution" */
216 GHashTable* gops_by_pduname; /* k=pducfg->name v=gopcfg */
217 GHashTable* gogs_by_gopname; /* k=gopname v=loal where avpl->name == matchedgop->name */
224 struct _mate_cfg_defaults {
225 struct _pdu_defaults {
226 avpl_match_mode match_mode;
227 avpl_replace_mode replace_mode;
228 gboolean last_extracted;
230 gboolean drop_unassigned;
234 struct _gop_defaults {
239 gop_pdu_tree_t pdu_tree_mode;
241 gboolean drop_unassigned;
245 struct _gog_defaults {
248 gop_tree_mode_t gop_tree_mode;
252 /* what to dbgprint */
258 GPtrArray* config_stack;
259 GString* config_error;
264 typedef struct _mate_config_frame {
270 typedef struct _mate_runtime_data {
271 guint current_items; /* a count of items */
272 GMemChunk* mate_items;
274 guint highest_analyzed_frame;
276 GHashTable* frames; /* k=frame.num v=pdus */
280 typedef struct _mate_pdu mate_pdu;
281 typedef struct _mate_gop mate_gop;
282 typedef struct _mate_gog mate_gog;
284 /* these are used to contain information regarding pdus, gops and gogs */
286 guint32 id; /* 1:1 -> saving a g_malloc */
287 mate_cfg_pdu* cfg; /* the type of this item */
291 guint32 frame; /* wich frame I belog to? */
292 mate_pdu* next_in_frame; /* points to the next pdu in this frame */
293 float rel_time; /* time since start of capture */
295 mate_gop* gop; /* the gop the pdu belongs to (if any) */
296 mate_pdu* next; /* next in gop */
297 float time_in_gop; /* time since gop start */
299 gboolean first; /* is this the first pdu in this frame? */
300 gboolean is_start; /* this is the start pdu for this gop */
301 gboolean is_stop; /* this is the stop pdu for this gop */
302 gboolean after_release; /* this pdu comes after the stop */
312 AVPL* avpl; /* the attributes of the pdu/gop/gog */
315 mate_gog* gog; /* the gog of a gop */
316 mate_gop* next; /* next in gog; */
318 float expiration; /* when will it expire after release (all gops releases if gog)? */
319 float idle_expiration; /* when will it expire if no new pdus are assigned to it */
321 float time_to_timeout;
323 float start_time; /* time of start */
324 float release_time; /* when this gop/gog was released */
325 float last_time; /* the rel_time at which the last pdu has been added (to gop or gog's gop) */
328 int num_of_pdus; /* how many gops a gog has? */
329 int num_of_after_release_pdus; /* how many pdus have arrived since it's been released */
330 mate_pdu* pdus; /* pdus that belong to a gop (NULL in gog) */
331 mate_pdu* last_pdu; /* last pdu in pdu's list */
333 gboolean released; /* has this gop been released? */
341 AVPL* avpl; /* the attributes of the pdu/gop/gog */
342 guint last_n; /* the number of attributes the avpl had the last time we checked */
344 gboolean released; /* has this gop been released? */
346 float expiration; /* when will it expire after release (all gops releases if gog)? */
347 float idle_expiration; /* when will it expire if no new pdus are assigned to it */
349 /* on gop and gog: */
350 float start_time; /* time of start */
351 float release_time; /* when this gog was released */
352 float last_time; /* the rel_time at which the last pdu has been added */
354 mate_gop* gops; /* gops that belong to a gog (NULL in gop) */
355 mate_gop* last_gop; /* last gop in gop's list */
357 int num_of_gops; /* how many gops a gog has? */
358 int num_of_counting_gops; /* how many of them count for gog release */
359 int num_of_released_gops; /* how many of them have already been released */
360 GPtrArray* gog_keys; /* the keys under which this gog is stored in the gogs hash */
363 typedef union _mate_max_size {
369 /* from mate_runtime.c */
370 extern void initialize_mate_runtime(void);
371 extern mate_pdu* mate_get_pdus(guint32 framenum);
372 extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree);
374 /* from mate_setup.c */
375 extern mate_config* mate_make_config(const gchar* filename, int mate_hfid);
377 extern mate_config* mate_cfg(void);
378 extern mate_cfg_pdu* new_pducfg(gchar* name);
379 extern mate_cfg_gop* new_gopcfg(gchar* name);
380 extern mate_cfg_gog* new_gogcfg(gchar* name);
382 extern gboolean add_hfid(header_field_info* hfi, gchar* as, GHashTable* where);
383 extern gchar* add_ranges(gchar* range, GPtrArray* range_ptr_arr);
386 /* from mate_parser.l */
387 extern gboolean mate_load_config(const gchar* filename, mate_config* mc);