diff options
author | Lars Roland <Lars.Roland@gmx.net> | 2004-12-12 23:40:44 +0000 |
---|---|---|
committer | Lars Roland <Lars.Roland@gmx.net> | 2004-12-12 23:40:44 +0000 |
commit | 04a6f55e4c7945ad943e3b3532a07114ea1665b2 (patch) | |
tree | d7cf3c9d0cbc38448b64fc9f57d887e08ebfadde /plugins/mate | |
parent | 593131d1323c8ab63ccd639a25c5026ea1dc291a (diff) | |
download | wireshark-04a6f55e4c7945ad943e3b3532a07114ea1665b2.tar.gz wireshark-04a6f55e4c7945ad943e3b3532a07114ea1665b2.tar.bz2 wireshark-04a6f55e4c7945ad943e3b3532a07114ea1665b2.zip |
Update for Mate from Luis Ontanon:
- make rd static (no purpose for it to be global)
- remove outdated comments
- add "PduCriteria" feature (as already stated in the wiki)
- add "DiscardUnassignedPdu" feature (as already stated in the wiki)
- removed ".Id" from abbrev for "mate.item_name"
- in radius.mate: Don't use the port to determine the Gop key.
svn path=/trunk/; revision=12735
Diffstat (limited to 'plugins/mate')
-rw-r--r-- | plugins/mate/mate.h | 6 | ||||
-rw-r--r-- | plugins/mate/mate_runtime.c | 47 | ||||
-rw-r--r-- | plugins/mate/mate_setup.c | 121 | ||||
-rw-r--r-- | plugins/mate/mate_util.c | 37 | ||||
-rw-r--r-- | plugins/mate/mate_util.h | 8 | ||||
-rw-r--r-- | plugins/mate/matelib/radius.mate | 4 |
6 files changed, 171 insertions, 52 deletions
diff --git a/plugins/mate/mate.h b/plugins/mate/mate.h index f56d7590a8..f8d09968a8 100644 --- a/plugins/mate/mate.h +++ b/plugins/mate/mate.h @@ -109,6 +109,8 @@ #define KEYWORD_DROPGOP "DiscardUnassignedGop" #define KEYWORD_DROPPDU "DiscardUnassignedPdu" #define KEYWORD_LIB "Lib" +#define KEYWORD_ACCEPT "Accept" +#define KEYWORD_REJECT "Reject" #define KEYWORD_DEBUGFILENAME "Debug_File" #define KEYWORD_DBG_GENERAL "Debug_General" @@ -196,7 +198,9 @@ typedef struct _mate_config { gboolean last_to_be_created; avpl_match_mode match_mode; avpl_replace_mode replace_mode; - + guint8* accept; + guint8* reject; + /* what to dbgprint */ int dbg_lvl; int dbg_cfg_lvl; diff --git a/plugins/mate/mate_runtime.c b/plugins/mate/mate_runtime.c index 2de8eb3952..cb4bb28935 100644 --- a/plugins/mate/mate_runtime.c +++ b/plugins/mate/mate_runtime.c @@ -50,7 +50,7 @@ typedef struct _tmp_pdu_data { } tmp_pdu_data; -mate_runtime_data* rd = NULL; +static mate_runtime_data* rd = NULL; static mate_config* mc = NULL; static int zero = 0; @@ -109,7 +109,6 @@ extern void init_mate_runtime_data(void) { rd->mate_items = g_mem_chunk_new("mate_items",sizeof(mate_item),1024,G_ALLOC_AND_FREE); } -/* creates a mate_item*/ static mate_item* new_mate_item(mate_cfg_item* cfg) { mate_item* it = g_mem_chunk_alloc(rd->mate_items); @@ -132,7 +131,6 @@ static mate_item* new_mate_item(mate_cfg_item* cfg) { return it; } -/* a new gop */ static mate_gop* new_gop(mate_cfg_gop* cfg, mate_pdu* pdu, guint8* key) { mate_gop* gop = new_mate_item(cfg); @@ -178,7 +176,6 @@ static void adopt_gop(mate_gog* gog, mate_gop* gop) { } -/* a new gog */ static mate_gog* new_gog(mate_cfg_gog* cfg, mate_gop* gop) { mate_gog* gog = new_mate_item(cfg); @@ -662,7 +659,8 @@ extern int mate_packet(void *prs _U_, packet_info *pinfo, epan_dissect_t *edt, v GPtrArray* protos; field_info* proto; guint i,j; - + AVPL* criterium_match; + rd->now = (((float)pinfo->fd->rel_secs) + (((float)pinfo->fd->rel_usecs) / 1000000) ); dbg_print (dbg,3,dbg_facility,"mate_packet: got frame number: %i at %d\n",pinfo->fd->num,rd->now); @@ -684,22 +682,43 @@ extern int mate_packet(void *prs _U_, packet_info *pinfo, epan_dissect_t *edt, v proto = (field_info*) g_ptr_array_index(protos,j); pdu = new_pdu(cfg, pinfo->fd->num, proto, tree->tree_data->interesting_hfids); - - if (!last) { - g_hash_table_insert(rd->frames,(gpointer) pinfo->fd->num,pdu); - last = pdu; - } else { - last->next_in_frame = pdu; - last = pdu; - } + if (cfg->criterium) { + criterium_match = new_avpl_from_match(cfg->criterium_match_mode,"",pdu->avpl,cfg->criterium,FALSE); + if (criterium_match) { + delete_avpl(criterium_match,FALSE); + } + + if ( (criterium_match && cfg->criterium->name == mc->reject ) || ( ! criterium_match && cfg->criterium->name == mc->accept )) { + delete_avpl(pdu->avpl,TRUE); + g_mem_chunk_free(rd->mate_items,pdu); + pdu = NULL; + continue; + } + } + analize_pdu(pdu); + if ( ! pdu->gop && cfg->drop_pdu) { + delete_avpl(pdu->avpl,TRUE); + g_mem_chunk_free(rd->mate_items,pdu); + pdu = NULL; + continue; + } + if ( cfg->discard_pdu_attributes ) { delete_avpl(pdu->avpl,TRUE); pdu->avpl = NULL; } + if (!last) { + g_hash_table_insert(rd->frames,GINT_TO_POINTER(pinfo->fd->num),pdu); + last = pdu; + } else { + last->next_in_frame = pdu; + last = pdu; + } + } if ( pdu && cfg->last_to_be_created ) break; @@ -729,7 +748,7 @@ extern mate_pdu* mate_get_pdus(guint32 framenum) { /* this will be called when the mate's dissector is initialized */ extern void initialize_mate_runtime(void) { dbg_print (dbg,5,dbg_facility,"initialize_mate: entering"); - + if (( mc = mate_cfg() )) { dbg_pdu = &(mc->dbg_pdu_lvl); diff --git a/plugins/mate/mate_setup.c b/plugins/mate/mate_setup.c index d1c3832058..b81c9f033a 100644 --- a/plugins/mate/mate_setup.c +++ b/plugins/mate/mate_setup.c @@ -26,8 +26,6 @@ #include "mate.h" -/* FIXME: config names should be at most 8 chars! */ - static int* dbg; static int dbg_cfg_lvl = 1; @@ -130,7 +128,7 @@ static mate_cfg_item* new_mate_cfg_item(guint8* name) { new->hfid_pdu_rel_time = -1; new->my_hfids = g_hash_table_new(g_str_hash,g_str_equal); new->items = g_hash_table_new(g_direct_hash,g_direct_equal); - + new->hfid_gop_pdu = -1; new->hfid_gop_start_time = -1; new->hfid_gop_stop_time = -1; @@ -455,11 +453,69 @@ static gboolean config_pduextra(AVPL* avpl) { } +static gboolean config_pducriteria(AVPL* avpl) { + guint8* name; + mate_cfg_gop* cfg = lookup_using_index_avp(avpl, KEYWORD_FOR,matecfg->pducfgs,&name); + guint8* match = extract_named_str(avpl, KEYWORD_MATCH, NULL); + avpl_match_mode match_mode = AVPL_STRICT; + guint8* mode = extract_named_str(avpl, KEYWORD_MODE, NULL); + + if (!cfg) { + g_warning("mate: PduCriteria Config error: Pdu %s does not exist",name); + delete_avpl(avpl,TRUE); + return FALSE; + } + + if ( mode ) { + if ( g_strcasecmp(mode,KEYWORD_ACCEPT) == 0 ) { + mode = matecfg->accept; + } else if ( g_strcasecmp(mode,KEYWORD_REJECT) == 0 ) { + mode = matecfg->reject; + } else { + g_warning("mate: PduCriteria Config error: no such criteria mode: %s",mode); + delete_avpl(avpl,TRUE); + return FALSE; + } + } else { + mode = matecfg->accept; + } + + rename_avpl(avpl,mode); + + if ( match ) { + if ( g_strcasecmp(match,KEYWORD_LOOSE) == 0 ) { + match_mode = AVPL_LOOSE; + } else if ( g_strcasecmp(match,KEYWORD_EVERY) == 0 ) { + match_mode = AVPL_EVERY; + } else if ( g_strcasecmp(match,KEYWORD_STRICT) == 0 ) { + match_mode = AVPL_STRICT; + } else { + g_warning("mate: PduCriteria Config error: no such match mode: %s",match); + delete_avpl(avpl,TRUE); + return FALSE; + } + } + + cfg->criterium_match_mode = match_mode; + + if (cfg->criterium) { + /* FEATURE: more criteria */ + g_warning("mate: PduCriteria Config error: PduCriteria alredy exists for %s",name); + delete_avpl(avpl,TRUE); + return FALSE; + } + + + cfg->criterium = avpl; + + return TRUE; +} + static gboolean config_include(AVPL* avpl) { guint8* filename = extract_named_str(avpl,KEYWORD_FILENAME,NULL); guint8* lib = extract_named_str(avpl,KEYWORD_LIB,NULL); - + if ( ! filename && ! lib ) { mate_config_error(NULL,NULL,"mate: Include file error: no Filename or Lib given"); return FALSE; @@ -469,20 +525,20 @@ static gboolean config_include(AVPL* avpl) { mate_config_error(NULL,NULL,"mate: Include file error: use either Filename or Lib, not both."); return FALSE; } - + if (lib) { filename = g_strdup_printf("%s%s.mate",matecfg->mate_lib_path,lib); } - + /* FIXME: stop recursion */ if ( ! mate_load_config(filename) ) { mate_config_error(NULL,NULL,"mate: Error Loading '%s'",filename); if (lib) g_free(filename); return FALSE; } - + if (lib) g_free(filename); - + return TRUE; } @@ -974,6 +1030,8 @@ static void print_pdu_config(mate_cfg_pdu* cfg) { int hfid; guint8* discard; guint8* stop; + guint8* criterium_match = NULL; + guint8* criterium; GString* s = g_string_new("Action=PduDef; "); discard = cfg->discard_pdu_attributes ? "TRUE": "FALSE"; @@ -993,6 +1051,31 @@ static void print_pdu_config(mate_cfg_pdu* cfg) { dbg_print(dbg_cfg,0,dbg_facility,"%s",s->str); + if (cfg->criterium) { + switch(cfg->criterium_match_mode) { + case AVPL_NO_MATCH: + criterium_match = "None"; + break; + case AVPL_STRICT: + criterium_match = "Strict"; + break; + case AVPL_LOOSE: + criterium_match = "Loose"; + break; + case AVPL_EVERY: + criterium_match = "Every"; + break; + } + + criterium = avpl_to_str(cfg->criterium); + + dbg_print(dbg_cfg,0,dbg_facility, + "Action=PduCriteria; For=%s; Match=%s; Mode=%s; %s", + cfg->name,criterium_match,cfg->criterium->name,criterium); + + g_free(criterium); + } + print_xxx_transforms(cfg); g_string_free(s,TRUE); @@ -1093,7 +1176,7 @@ static void analyze_pdu_config(mate_cfg_pdu* cfg) { hfri.p_id = &(cfg->hfid); hfri.hfinfo.name = g_strdup_printf("%s",cfg->name); - hfri.hfinfo.abbrev = g_strdup_printf("mate.%s.Id",cfg->name); + hfri.hfinfo.abbrev = g_strdup_printf("mate.%s",cfg->name); hfri.hfinfo.blurb = g_strdup_printf("%s id",cfg->name); hfri.hfinfo.type = FT_UINT32; hfri.hfinfo.display = BASE_DEC; @@ -1122,7 +1205,7 @@ static void analyze_gop_config(gpointer k _U_, gpointer v, gpointer p _U_) { hfri.p_id = &(cfg->hfid); hfri.hfinfo.name = g_strdup_printf("%s",cfg->name); - hfri.hfinfo.abbrev = g_strdup_printf("mate.%s.Id",cfg->name); + hfri.hfinfo.abbrev = g_strdup_printf("mate.%s",cfg->name); hfri.hfinfo.blurb = g_strdup_printf("%s id",cfg->name); hfri.hfinfo.type = FT_UINT32; hfri.hfinfo.display = BASE_DEC; @@ -1209,7 +1292,7 @@ static void analyze_gog_config(gpointer k _U_, gpointer v, gpointer p _U_) { hfri.p_id = &(cfg->hfid); hfri.hfinfo.name = g_strdup_printf("%s",cfg->name); - hfri.hfinfo.abbrev = g_strdup_printf("mate.%s.Id",cfg->name); + hfri.hfinfo.abbrev = g_strdup_printf("mate.%s",cfg->name); hfri.hfinfo.blurb = g_strdup_printf("%s Id",cfg->name); hfri.hfinfo.type = FT_UINT32; hfri.hfinfo.display = BASE_DEC; @@ -1272,8 +1355,10 @@ static void new_action(guint8* name, config_action* action) { } static void init_actions() { + AVP* avp; all_keywords = new_avpl("all_keywords"); + insert_avp(all_keywords,new_avp(KEYWORD_ACTION,"",'=')); insert_avp(all_keywords,new_avp(KEYWORD_SETTINGS,"",'=')); insert_avp(all_keywords,new_avp(KEYWORD_INCLUDE,"",'=')); @@ -1333,6 +1418,15 @@ static void init_actions() { insert_avp(all_keywords,new_avp(KEYWORD_DBG_AVPL_OP,"",'=')); #endif + avp = new_avp(KEYWORD_ACCEPT,"",'='); + matecfg->accept = avp->n; + insert_avp(all_keywords,avp); + + avp = new_avp(KEYWORD_REJECT,"",'='); + matecfg->reject = avp->n; + insert_avp(all_keywords,avp); + + if (actions) { g_hash_table_destroy(actions); } @@ -1342,7 +1436,7 @@ static void init_actions() { new_action(KEYWORD_SETTINGS,config_settings); new_action(KEYWORD_PDU,config_pdu); new_action(KEYWORD_PDUEXTRA,config_pduextra); - /* new_action(KEYWORD_PDUCRITERIA,config_pdu); */ + new_action(KEYWORD_PDUCRITERIA,config_pducriteria); new_action(KEYWORD_GOP,config_gop); new_action(KEYWORD_GOGDEF,config_gog); new_action(KEYWORD_GOGKEY,config_gogkey); @@ -1375,7 +1469,6 @@ extern mate_config* mate_cfg() { extern mate_config* mate_make_config(guint8* filename) { avp_init(); - init_actions(); matecfg = g_malloc(sizeof(mate_config)); @@ -1410,6 +1503,8 @@ extern mate_config* mate_make_config(guint8* filename) { dbg = &matecfg->dbg_lvl; + init_actions(); + if ( mate_load_config(filename) ) { analyze_config(); dbg_print (dbg_cfg,3,dbg_facility,"mate_make_config: OK"); diff --git a/plugins/mate/mate_util.c b/plugins/mate/mate_util.c index 11fdb8e4a6..a508b593e6 100644 --- a/plugins/mate/mate_util.c +++ b/plugins/mate/mate_util.c @@ -1314,6 +1314,27 @@ extern AVPL* new_avpl_exact_match(guint8* name,AVPL* src, AVPL* op, gboolean cop return NULL; } +extern AVPL* new_avpl_from_match(avpl_match_mode mode, guint8* name,AVPL* src, AVPL* op, gboolean copy_avps) { + AVPL* avpl = NULL; + + switch (mode) { + case AVPL_STRICT: + avpl = new_avpl_exact_match(name,src,op,copy_avps); + break; + case AVPL_LOOSE: + avpl = new_avpl_loose_match(name,src,op,copy_avps); + break; + case AVPL_EVERY: + avpl = new_avpl_every_match(name,src,op,copy_avps); + break; + case AVPL_NO_MATCH: + avpl = new_avpl_from_avpl(name,src,copy_avps); + merge_avpl(avpl, op, copy_avps); + break; + } + + return avpl; +} /** * new_avpl_transform: @@ -1399,20 +1420,8 @@ extern void avpl_transform(AVPL* src, AVPL_Transf* op) { #endif for ( ; op ; op = op->next) { - switch (op->match_mode) { - case AVPL_STRICT: - avpl = new_avpl_exact_match(src->name,src,op->match,TRUE); - break; - case AVPL_LOOSE: - avpl = new_avpl_loose_match(src->name,src,op->match,TRUE); - break; - case AVPL_EVERY: - avpl = new_avpl_every_match(src->name,src,op->match,TRUE); - break; - case AVPL_NO_MATCH: - avpl = new_avpl(src->name); - break; - } + + avpl = new_avpl_from_match(op->match_mode, src->name,src, op->match, TRUE); if (avpl) { switch (op->replace_mode) { diff --git a/plugins/mate/mate_util.h b/plugins/mate/mate_util.h index d029cd1adf..454b6620eb 100644 --- a/plugins/mate/mate_util.h +++ b/plugins/mate/mate_util.h @@ -24,14 +24,6 @@ */ -/* Note: - * Although for now it is used only by tracing.c - * I decided to make it into a separate module - * since one day in the near future I will be using it - * to reimplement packet-radius.c - */ - - #ifndef __AVP_H_ #define __AVP_H_ #include "epan/proto.h" diff --git a/plugins/mate/matelib/radius.mate b/plugins/mate/matelib/radius.mate index 1f13885f4e..851717557d 100644 --- a/plugins/mate/matelib/radius.mate +++ b/plugins/mate/matelib/radius.mate @@ -1,7 +1,7 @@ # radius.mate # $Id$ -Action=PduDef; Name=radius_pdu; Proto=radius; Transport=udp/ip; addr=ip.addr; port=udp.port; radius_id=radius.id; radius_code=radius.code; -Action=GopDef; Name=radius_req; On=radius_pdu; radius_id; addr; addr; port; port; +Action=PduDef; Name=radius_pdu; Proto=radius; Transport=udp/ip; radius_addr=ip.addr; radius_port=udp.port; radius_id=radius.id; radius_code=radius.code; +Action=GopDef; Name=radius_req; On=radius_pdu; radius_id; radius_addr; radius_addr; Action=GopStart; For=radius_req; radius_code|1|4|7; Action=GopStop; For=radius_req; radius_code|2|3|5|8|9; |