2 * MATE -- Meta Analysis and Tracing Engine
4 * Copyright 2004, Luis E. Garcia Ontanon <luis@ontanon.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 #include "moduleinfo.h"
44 #include <wsutil/report_err.h>
46 #include <epan/packet.h>
47 #include <epan/exceptions.h>
48 #include <epan/strutil.h>
49 #include <epan/prefs.h>
50 #include <epan/proto.h>
51 #include <epan/epan_dissect.h>
53 #include <epan/filesystem.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 */
273 guint highest_analyzed_frame
;
275 GHashTable
* frames
; /* k=frame.num v=pdus */
279 typedef struct _mate_pdu mate_pdu
;
280 typedef struct _mate_gop mate_gop
;
281 typedef struct _mate_gog mate_gog
;
283 /* these are used to contain information regarding pdus, gops and gogs */
285 guint32 id
; /* 1:1 -> saving a g_malloc */
286 mate_cfg_pdu
* cfg
; /* the type of this item */
290 guint32 frame
; /* wich frame I belog to? */
291 mate_pdu
* next_in_frame
; /* points to the next pdu in this frame */
292 float rel_time
; /* time since start of capture */
294 mate_gop
* gop
; /* the gop the pdu belongs to (if any) */
295 mate_pdu
* next
; /* next in gop */
296 float time_in_gop
; /* time since gop start */
298 gboolean first
; /* is this the first pdu in this frame? */
299 gboolean is_start
; /* this is the start pdu for this gop */
300 gboolean is_stop
; /* this is the stop pdu for this gop */
301 gboolean after_release
; /* this pdu comes after the stop */
311 AVPL
* avpl
; /* the attributes of the pdu/gop/gog */
314 mate_gog
* gog
; /* the gog of a gop */
315 mate_gop
* next
; /* next in gog; */
317 float expiration
; /* when will it expire after release (all gops releases if gog)? */
318 float idle_expiration
; /* when will it expire if no new pdus are assigned to it */
320 float time_to_timeout
;
322 float start_time
; /* time of start */
323 float release_time
; /* when this gop/gog was released */
324 float last_time
; /* the rel_time at which the last pdu has been added (to gop or gog's gop) */
327 int num_of_pdus
; /* how many gops a gog has? */
328 int num_of_after_release_pdus
; /* how many pdus have arrived since it's been released */
329 mate_pdu
* pdus
; /* pdus that belong to a gop (NULL in gog) */
330 mate_pdu
* last_pdu
; /* last pdu in pdu's list */
332 gboolean released
; /* has this gop been released? */
340 AVPL
* avpl
; /* the attributes of the pdu/gop/gog */
341 guint last_n
; /* the number of attributes the avpl had the last time we checked */
343 gboolean released
; /* has this gop been released? */
345 float expiration
; /* when will it expire after release (all gops releases if gog)? */
346 float idle_expiration
; /* when will it expire if no new pdus are assigned to it */
348 /* on gop and gog: */
349 float start_time
; /* time of start */
350 float release_time
; /* when this gog was released */
351 float last_time
; /* the rel_time at which the last pdu has been added */
353 mate_gop
* gops
; /* gops that belong to a gog (NULL in gop) */
354 mate_gop
* last_gop
; /* last gop in gop's list */
356 int num_of_gops
; /* how many gops a gog has? */
357 int num_of_counting_gops
; /* how many of them count for gog release */
358 int num_of_released_gops
; /* how many of them have already been released */
359 GPtrArray
* gog_keys
; /* the keys under which this gog is stored in the gogs hash */
362 typedef union _mate_max_size
{
368 /* from mate_runtime.c */
369 extern void initialize_mate_runtime(void);
370 extern mate_pdu
* mate_get_pdus(guint32 framenum
);
371 extern void mate_analyze_frame(packet_info
*pinfo
, proto_tree
* tree
);
373 /* from mate_setup.c */
374 extern mate_config
* mate_make_config(const gchar
* filename
, int mate_hfid
);
376 extern mate_config
* mate_cfg(void);
377 extern mate_cfg_pdu
* new_pducfg(gchar
* name
);
378 extern mate_cfg_gop
* new_gopcfg(gchar
* name
);
379 extern mate_cfg_gog
* new_gogcfg(gchar
* name
);
381 extern gboolean
add_hfid(header_field_info
* hfi
, gchar
* as
, GHashTable
* where
);
382 extern gchar
* add_ranges(gchar
* range
, GPtrArray
* range_ptr_arr
);
385 /* from mate_parser.l */
386 extern gboolean
mate_load_config(const gchar
* filename
, mate_config
* mc
);