diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-04-16 18:18:11 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-04-17 01:18:43 +0000 |
commit | dae108837fc1d9c48eefbcc7feeff607c26e0a4e (patch) | |
tree | aa2901323887c6e2b6ffaa1700ea72447527a832 /plugins | |
parent | 3f912df8754972a6db06eda36564a300d5a5e350 (diff) | |
download | wireshark-dae108837fc1d9c48eefbcc7feeff607c26e0a4e.tar.gz |
Make the current MATE config pointer static only to packet-mate.c.
Pass it as an argument to everything else, so only packet-mate.c has the
notion of there being *a* configuration, and everything else takes the
configuration as an argument.
Change-Id: Ia92c1539586d3e71580fd822cf07bd3d79a6f093
Reviewed-on: https://code.wireshark.org/review/21151
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mate/mate.h | 13 | ||||
-rw-r--r-- | plugins/mate/mate_grammar.lemon | 8 | ||||
-rw-r--r-- | plugins/mate/mate_runtime.c | 21 | ||||
-rw-r--r-- | plugins/mate/mate_setup.c | 82 | ||||
-rw-r--r-- | plugins/mate/packet-mate.c | 12 |
5 files changed, 73 insertions, 63 deletions
diff --git a/plugins/mate/mate.h b/plugins/mate/mate.h index 01f5435f94..b1c15941ce 100644 --- a/plugins/mate/mate.h +++ b/plugins/mate/mate.h @@ -366,19 +366,18 @@ typedef union _mate_max_size { } mate_max_size; /* from mate_runtime.c */ -extern void initialize_mate_runtime(void); +extern void initialize_mate_runtime(mate_config* mc); extern mate_pdu* mate_get_pdus(guint32 framenum); -extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree); +extern void mate_analyze_frame(mate_config *mc, packet_info *pinfo, proto_tree* tree); /* from mate_setup.c */ extern mate_config* mate_make_config(const gchar* filename, int mate_hfid); -extern mate_config* mate_cfg(void); -extern mate_cfg_pdu* new_pducfg(gchar* name); -extern mate_cfg_gop* new_gopcfg(gchar* name); -extern mate_cfg_gog* new_gogcfg(gchar* name); +extern mate_cfg_pdu* new_pducfg(mate_config* matecfg, gchar* name); +extern mate_cfg_gop* new_gopcfg(mate_config* matecfg, gchar* name); +extern mate_cfg_gog* new_gogcfg(mate_config* matecfg, gchar* name); -extern gboolean add_hfid(header_field_info* hfi, gchar* as, GHashTable* where); +extern gboolean add_hfid(mate_config* matecfg, header_field_info* hfi, gchar* as, GHashTable* where); extern gchar* add_ranges(gchar* range, GPtrArray* range_ptr_arr); diff --git a/plugins/mate/mate_grammar.lemon b/plugins/mate/mate_grammar.lemon index 5b0b6ca34e..c7e084230d 100644 --- a/plugins/mate/mate_grammar.lemon +++ b/plugins/mate/mate_grammar.lemon @@ -422,7 +422,7 @@ pdu_decl ::= CLOSE_BRACE SEMICOLON. { - mate_cfg_pdu* cfg = new_pducfg(Name); + mate_cfg_pdu* cfg = new_pducfg(mc, Name); extraction_t *extraction, *next_extraction; GPtrArray* transport_stack = g_ptr_array_new(); int i; @@ -458,7 +458,7 @@ pdu_decl ::= for (extraction = Extraction; extraction; extraction = next_extraction) { next_extraction = extraction->next; - if ( ! add_hfid(extraction->hfi, extraction->as, cfg->hfids_attr) ) { + if ( ! add_hfid(mc, extraction->hfi, extraction->as, cfg->hfids_attr) ) { configuration_error(mc,"MATE: failed to create extraction rule '%s'",extraction->as); } @@ -545,7 +545,7 @@ gop_decl(A) ::= GOP_KW NAME(Name) ON_KW pdu_name(PduName) MATCH_KW avpl(Key) OPE if (g_hash_table_lookup(mc->gopcfgs,Name)) configuration_error(mc,"A Gop Named '%s' exists already.",Name); if (g_hash_table_lookup(mc->gops_by_pduname,PduName) ) configuration_error(mc,"Gop for Pdu '%s' exists already",PduName); - cfg = new_gopcfg(Name); + cfg = new_gopcfg(mc, Name); g_hash_table_insert(mc->gops_by_pduname,PduName,cfg); g_hash_table_insert(mc->gopcfgs,cfg->name,cfg); @@ -632,7 +632,7 @@ gog_decl ::= GOG_KW NAME(Name) OPEN_BRACE configuration_error(mc,"Gog '%s' exists already ",Name); } - cfg = new_gogcfg(Name); + cfg = new_gogcfg(mc, Name); cfg->expiration = Expiration; cfg->gop_tree_mode = Tree; diff --git a/plugins/mate/mate_runtime.c b/plugins/mate/mate_runtime.c index 1e4232c3c9..82c7af26ea 100644 --- a/plugins/mate/mate_runtime.c +++ b/plugins/mate/mate_runtime.c @@ -46,7 +46,6 @@ typedef struct _gogkey { static mate_runtime_data* rd = NULL; -static mate_config* mc = NULL; static int zero = 5; @@ -131,11 +130,11 @@ static void destroy_gogs_in_cfg(gpointer k _U_, gpointer v, gpointer p _U_) { c->last_id = 0; } -void initialize_mate_runtime(void) { +void initialize_mate_runtime(mate_config* mc) { dbg_print (dbg,5,dbg_facility,"initialize_mate: entering"); - if (( mc = mate_cfg() )) { + if (mc) { if (rd == NULL ) { rd = (mate_runtime_data *)g_malloc(sizeof(mate_runtime_data)); } else { @@ -301,7 +300,7 @@ static void gog_remove_keys (mate_gog* gog) { } -static void reanalyze_gop(mate_gop* gop) { +static void reanalyze_gop(mate_config* mc, mate_gop* gop) { LoAL* gog_keys = NULL; AVPL* curr_gogkey = NULL; mate_cfg_gop* gop_cfg = NULL; @@ -372,7 +371,7 @@ static void reanalyze_gop(mate_gop* gop) { } } -static void analyze_gop(mate_gop* gop) { +static void analyze_gop(mate_config* mc, mate_gop* gop) { mate_cfg_gog* cfg = NULL; LoAL* gog_keys = NULL; AVPL* curr_gogkey = NULL; @@ -453,13 +452,13 @@ static void analyze_gop(mate_gop* gop) { if (gogkey_match) delete_avpl(gogkey_match,TRUE); - reanalyze_gop(gop); + reanalyze_gop(mc, gop); } } -static void analyze_pdu(mate_pdu* pdu) { +static void analyze_pdu(mate_config* mc, mate_pdu* pdu) { /* TODO: return a g_boolean to tell we've destroyed the pdu when the pdu is unnassigned destroy the unassigned pdu @@ -643,9 +642,9 @@ static void analyze_pdu(mate_pdu* pdu) { gop->last_n = gop->avpl->len; if (gop->gog) { - reanalyze_gop(gop); + reanalyze_gop(mc, gop); } else { - analyze_gop(gop); + analyze_gop(mc, gop); } } else { @@ -833,7 +832,7 @@ static mate_pdu* new_pdu(mate_cfg_pdu* cfg, guint32 framenum, field_info* proto, } -extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree) { +extern void mate_analyze_frame(mate_config *mc, packet_info *pinfo, proto_tree* tree) { mate_cfg_pdu* cfg; GPtrArray* protos; field_info* proto; @@ -882,7 +881,7 @@ extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree) { } } - analyze_pdu(pdu); + analyze_pdu(mc, pdu); if ( ! pdu->gop && cfg->drop_unassigned) { delete_avpl(pdu->avpl,TRUE); diff --git a/plugins/mate/mate_setup.c b/plugins/mate/mate_setup.c index 0ced43af34..556663610e 100644 --- a/plugins/mate/mate_setup.c +++ b/plugins/mate/mate_setup.c @@ -24,11 +24,8 @@ #include "mate.h" -/* the current mate_config */ -static mate_config* matecfg = NULL; - /* appends the formatted string to the current error log */ -static void report_error(const gchar* fmt, ...) { +static void report_error(mate_config* matecfg, const gchar* fmt, ...) { static gchar error_buffer[DEBUG_BUFFER_SIZE]; va_list list; @@ -45,7 +42,7 @@ static void report_error(const gchar* fmt, ...) { /* creates a blank pdu config is going to be called only by the grammar which will set all those elements that aren't set here */ -extern mate_cfg_pdu* new_pducfg(gchar* name) { +extern mate_cfg_pdu* new_pducfg(mate_config* matecfg, gchar* name) { mate_cfg_pdu* cfg = (mate_cfg_pdu *)g_malloc(sizeof(mate_cfg_pdu)); cfg->name = g_strdup(name); @@ -76,7 +73,7 @@ extern mate_cfg_pdu* new_pducfg(gchar* name) { return cfg; } -extern mate_cfg_gop* new_gopcfg(gchar* name) { +extern mate_cfg_gop* new_gopcfg(mate_config* matecfg, gchar* name) { mate_cfg_gop* cfg = (mate_cfg_gop *)g_malloc(sizeof(mate_cfg_gop)); cfg->name = g_strdup(name); @@ -111,7 +108,7 @@ extern mate_cfg_gop* new_gopcfg(gchar* name) { return cfg; } -extern mate_cfg_gog* new_gogcfg(gchar* name) { +extern mate_cfg_gog* new_gogcfg(mate_config* matecfg, gchar* name) { mate_cfg_gog* cfg = (mate_cfg_gog *)g_malloc(sizeof(mate_cfg_gop)); cfg->name = g_strdup(name); @@ -145,7 +142,7 @@ extern mate_cfg_gog* new_gogcfg(gchar* name) { return cfg; } -extern gboolean add_hfid(header_field_info* hfi, gchar* how, GHashTable* where) { +extern gboolean add_hfid(mate_config* matecfg, header_field_info* hfi, gchar* how, GHashTable* where) { header_field_info* first_hfi = NULL; gboolean exists = FALSE; gchar* as; @@ -168,8 +165,9 @@ extern gboolean add_hfid(header_field_info* hfi, gchar* how, GHashTable* where) if (( as = (gchar *)g_hash_table_lookup(where,ip) )) { g_free(ip); if (! g_str_equal(as,how)) { - report_error("MATE Error: add field to Pdu: attempt to add %s(%i) as %s" - " failed: field already added as '%s'",hfi->abbrev,hfi->id,how,as); + report_error(matecfg, + "MATE Error: add field to Pdu: attempt to add %s(%i) as %s" + " failed: field already added as '%s'",hfi->abbrev,hfi->id,how,as); return FALSE; } } else { @@ -182,7 +180,7 @@ extern gboolean add_hfid(header_field_info* hfi, gchar* how, GHashTable* where) } if (! exists) { - report_error("MATE Error: cannot find field for attribute %s",how); + report_error(matecfg, "MATE Error: cannot find field for attribute %s",how); } return exists; } @@ -191,7 +189,7 @@ extern gboolean add_hfid(header_field_info* hfi, gchar* how, GHashTable* where) /* * XXX - where is this suposed to be used? */ -extern gchar* add_ranges(gchar* range,GPtrArray* range_ptr_arr) { +extern gchar* add_ranges(mate_config* matecfg, gchar* range,GPtrArray* range_ptr_arr) { gchar** ranges; guint i; header_field_info* hfi; @@ -220,7 +218,7 @@ extern gchar* add_ranges(gchar* range,GPtrArray* range_ptr_arr) { } #endif -static void new_attr_hfri(gchar* item_name, GHashTable* hfids, gchar* name) { +static void new_attr_hfri(mate_config* matecfg, gchar* item_name, GHashTable* hfids, gchar* name) { int* p_id = (int *)g_malloc(sizeof(int)); hf_register_info hfri; @@ -249,9 +247,16 @@ static const gchar* my_protoname(int proto_id) { } } +typedef struct { + mate_config* matecfg; + mate_cfg_pdu* cfg; +} analyze_pdu_hfids_arg; + static void analyze_pdu_hfids(gpointer k, gpointer v, gpointer p) { - mate_cfg_pdu* cfg = (mate_cfg_pdu *)p; - new_attr_hfri(cfg->name,cfg->my_hfids,(gchar*) v); + analyze_pdu_hfids_arg* argp = (analyze_pdu_hfids_arg*)p; + mate_config* matecfg = argp->matecfg; + mate_cfg_pdu* cfg = argp->cfg; + new_attr_hfri(matecfg, cfg->name,cfg->my_hfids,(gchar*) v); /* * Add this hfid to our table of hfids. @@ -261,7 +266,7 @@ static void analyze_pdu_hfids(gpointer k, gpointer v, gpointer p) { g_string_append_printf(matecfg->fields_filter,"||%s",my_protoname(*(int*)k)); } -static void analyze_transform_hfrs(gchar* name, GPtrArray* transforms, GHashTable* hfids) { +static void analyze_transform_hfrs(mate_config* matecfg, gchar* name, GPtrArray* transforms, GHashTable* hfids) { guint i; void* cookie = NULL; AVPL_Transf* t; @@ -272,16 +277,17 @@ static void analyze_transform_hfrs(gchar* name, GPtrArray* transforms, GHashTabl cookie = NULL; while(( avp = get_next_avp(t->replace,&cookie) )) { if (! g_hash_table_lookup(hfids,avp->n)) { - new_attr_hfri(name,hfids,avp->n); + new_attr_hfri(matecfg, name,hfids,avp->n); } } } } } -static void analyze_pdu_config(mate_cfg_pdu* cfg) { +static void analyze_pdu_config(mate_config* matecfg, mate_cfg_pdu* cfg) { hf_register_info hfri = { NULL, {NULL, NULL, FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL}}; gint* ett; + analyze_pdu_hfids_arg arg; hfri.p_id = &(cfg->hfid); hfri.hfinfo.name = g_strdup(cfg->name); @@ -310,7 +316,9 @@ static void analyze_pdu_config(mate_cfg_pdu* cfg) { g_array_append_val(matecfg->hfrs,hfri); - g_hash_table_foreach(cfg->hfids_attr,analyze_pdu_hfids,cfg); + arg.matecfg = matecfg; + arg.cfg = cfg; + g_hash_table_foreach(cfg->hfids_attr,analyze_pdu_hfids,&arg); ett = &cfg->ett; g_array_append_val(matecfg->ett,ett); @@ -318,10 +326,11 @@ static void analyze_pdu_config(mate_cfg_pdu* cfg) { ett = &cfg->ett_attr; g_array_append_val(matecfg->ett,ett); - analyze_transform_hfrs(cfg->name,cfg->transforms,cfg->my_hfids); + analyze_transform_hfrs(matecfg, cfg->name,cfg->transforms,cfg->my_hfids); } -static void analyze_gop_config(gpointer k _U_, gpointer v, gpointer p _U_) { +static void analyze_gop_config(gpointer k _U_, gpointer v, gpointer p) { + mate_config* matecfg = (mate_config*)p; mate_cfg_gop* cfg = (mate_cfg_gop *)v; void* cookie = NULL; AVP* avp; @@ -387,7 +396,7 @@ static void analyze_gop_config(gpointer k _U_, gpointer v, gpointer p _U_) { while(( avp = get_next_avp(cfg->key,&cookie) )) { if (! g_hash_table_lookup(cfg->my_hfids,avp->n)) { - new_attr_hfri(cfg->name,cfg->my_hfids,avp->n); + new_attr_hfri(matecfg, cfg->name,cfg->my_hfids,avp->n); } } @@ -395,7 +404,7 @@ static void analyze_gop_config(gpointer k _U_, gpointer v, gpointer p _U_) { cookie = NULL; while(( avp = get_next_avp(cfg->start,&cookie) )) { if (! g_hash_table_lookup(cfg->my_hfids,avp->n)) { - new_attr_hfri(cfg->name,cfg->my_hfids,avp->n); + new_attr_hfri(matecfg, cfg->name,cfg->my_hfids,avp->n); } } } @@ -404,7 +413,7 @@ static void analyze_gop_config(gpointer k _U_, gpointer v, gpointer p _U_) { cookie = NULL; while(( avp = get_next_avp(cfg->stop,&cookie) )) { if (! g_hash_table_lookup(cfg->my_hfids,avp->n)) { - new_attr_hfri(cfg->name,cfg->my_hfids,avp->n); + new_attr_hfri(matecfg, cfg->name,cfg->my_hfids,avp->n); } } } @@ -412,11 +421,11 @@ static void analyze_gop_config(gpointer k _U_, gpointer v, gpointer p _U_) { cookie = NULL; while(( avp = get_next_avp(cfg->extra,&cookie) )) { if (! g_hash_table_lookup(cfg->my_hfids,avp->n)) { - new_attr_hfri(cfg->name,cfg->my_hfids,avp->n); + new_attr_hfri(matecfg, cfg->name,cfg->my_hfids,avp->n); } } - analyze_transform_hfrs(cfg->name,cfg->transforms,cfg->my_hfids); + analyze_transform_hfrs(matecfg, cfg->name,cfg->transforms,cfg->my_hfids); ett = &cfg->ett; g_array_append_val(matecfg->ett,ett); @@ -433,7 +442,8 @@ static void analyze_gop_config(gpointer k _U_, gpointer v, gpointer p _U_) { g_hash_table_insert(matecfg->gops_by_pduname,cfg->name,cfg); } -static void analyze_gog_config(gpointer k _U_, gpointer v, gpointer p _U_) { +static void analyze_gog_config(gpointer k _U_, gpointer v, gpointer p) { + mate_config* matecfg = (mate_config*)p; mate_cfg_gog* cfg = (mate_cfg_gog *)v; void* avp_cookie; void* avpl_cookie; @@ -525,7 +535,7 @@ static void analyze_gog_config(gpointer k _U_, gpointer v, gpointer p _U_) { avp_cookie = NULL; while (( avp = get_next_avp(avpl,&avp_cookie) )) { if (! g_hash_table_lookup(cfg->my_hfids,avp->n)) { - new_attr_hfri(cfg->name,cfg->my_hfids,avp->n); + new_attr_hfri(matecfg, cfg->name,cfg->my_hfids,avp->n); insert_avp(key_avps,avp); } } @@ -535,7 +545,7 @@ static void analyze_gog_config(gpointer k _U_, gpointer v, gpointer p _U_) { avp_cookie = NULL; while (( avp = get_next_avp(cfg->extra,&avp_cookie) )) { if (! g_hash_table_lookup(cfg->my_hfids,avp->n)) { - new_attr_hfri(cfg->name,cfg->my_hfids,avp->n); + new_attr_hfri(matecfg, cfg->name,cfg->my_hfids,avp->n); } } @@ -544,7 +554,7 @@ static void analyze_gog_config(gpointer k _U_, gpointer v, gpointer p _U_) { merge_avpl(cfg->extra,key_avps,TRUE); - analyze_transform_hfrs(cfg->name,cfg->transforms,cfg->my_hfids); + analyze_transform_hfrs(matecfg, cfg->name,cfg->transforms,cfg->my_hfids); ett = &cfg->ett; g_array_append_val(matecfg->ett,ett); @@ -563,11 +573,11 @@ static void analyze_gog_config(gpointer k _U_, gpointer v, gpointer p _U_) { } -static void analyze_config(void) { +static void analyze_config(mate_config* matecfg) { guint i; for (i=0; i < matecfg->pducfglist->len; i++) { - analyze_pdu_config((mate_cfg_pdu*) g_ptr_array_index(matecfg->pducfglist,i)); + analyze_pdu_config(matecfg, (mate_cfg_pdu*) g_ptr_array_index(matecfg->pducfglist,i)); } g_hash_table_foreach(matecfg->gopcfgs,analyze_gop_config,matecfg); @@ -575,11 +585,8 @@ static void analyze_config(void) { } -extern mate_config* mate_cfg(void) { - return matecfg; -} - extern mate_config* mate_make_config(const gchar* filename, int mate_hfid) { + mate_config* matecfg; gint* ett; avp_init(); @@ -641,14 +648,13 @@ extern mate_config* mate_make_config(const gchar* filename, int mate_hfid) { g_array_append_val(matecfg->ett,ett); if ( mate_load_config(filename,matecfg) ) { - analyze_config(); + analyze_config(matecfg); } else { report_failure("MATE failed to configure!\n" "It is recommended that you fix your config and restart Wireshark.\n" "The reported error is:\n%s\n",matecfg->config_error->str); /* if (matecfg) destroy_mate_config(matecfg,FALSE); */ - matecfg = NULL; return NULL; } diff --git a/plugins/mate/packet-mate.c b/plugins/mate/packet-mate.c index 5dddc58580..d14dbdd45c 100644 --- a/plugins/mate/packet-mate.c +++ b/plugins/mate/packet-mate.c @@ -311,7 +311,7 @@ mate_tree(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) if ( tree == NULL) return tvb_captured_length(tvb); - mate_analyze_frame(pinfo,tree); + mate_analyze_frame(mc, pinfo,tree); if (( pdus = mate_get_pdus(pinfo->num) )) { for ( ; pdus; pdus = pdus->next_in_frame) { @@ -330,6 +330,12 @@ mate_packet(void *prs _U_, packet_info* tree _U_, epan_dissect_t *edt _U_, cons return 0; } +static void +initialize_mate(void) +{ + initialize_mate_runtime(mc); +} + extern void proto_reg_handoff_mate(void) @@ -351,7 +357,7 @@ proto_reg_handoff_mate(void) /* XXX: alignment warnings, what do they mean? */ proto_register_field_array(proto_mate, (hf_register_info*)(void *)mc->hfrs->data, mc->hfrs->len ); proto_register_subtree_array((gint**)(void*)mc->ett->data, mc->ett->len); - register_init_routine(initialize_mate_runtime); + register_init_routine(initialize_mate); /* * Set the list of fields we want. @@ -373,7 +379,7 @@ proto_reg_handoff_mate(void) return; } - initialize_mate_runtime(); + initialize_mate_runtime(mc); } current_mate_config_filename = pref_mate_config_filename; |