Adds Payload AVP to PduDef AVPLs simmetric to the Transport AVP
authorlego <lego@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 18 Feb 2005 22:33:16 +0000 (22:33 +0000)
committerlego <lego@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 18 Feb 2005 22:33:16 +0000 (22:33 +0000)
allows to fetch fields also from ranges that are the payload of the Proto

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@13427 f5534014-38df-0310-8fa8-9805f1628bb7

plugins/mate/mate.h
plugins/mate/mate_runtime.c
plugins/mate/mate_setup.c

index 8540e15145d1702c50aaae167a38ee72e72c736b..3da59f059488478157cebe96f562f80591c3589d 100644 (file)
 #define KEYWORD_PROTO "Proto"
 #define KEYWORD_METHOD "Method"
 #define KEYWORD_TRANSPORT "Transport"
+#define KEYWORD_PAYLOAD "Payload"
 #define KEYWORD_STRICT "Strict"
 #define KEYWORD_LOOSE "Loose"
 #define KEYWORD_EVERY "Every"
 #define KEYWORD_DEBUGFILENAME "Debug_File"
 #define KEYWORD_DBG_GENERAL "Debug_General"
 #define KEYWORD_DBG_CFG "Debug_Cfg"
-#define KEYWORD_DBG_PDU "Debug_PDU"
+#define KEYWORD_DBG_PDU "Debug_Pdu"
 #define KEYWORD_DBG_GOP "Debug_Gop"
 #define KEYWORD_DBG_GOG "Debug_Gog"
 #ifdef _AVP_DEBUGGING
@@ -175,7 +176,8 @@ typedef struct _mate_cfg_item {
        gboolean discard_pdu_attributes;
        gboolean last_to_be_created;
        int hfid_proto;
-       GPtrArray* hfid_ranges; /* hfids of candidate ranges from which to extract attributes */
+       GPtrArray* transport_ranges; /* hfids of candidate transport ranges from which to extract attributes */
+       GPtrArray* payload_ranges; /* hfids of candidate payload ranges from which to extract attributes */
        GHashTable* hfids_attr; /* k=hfid v=avp_name */
        gboolean drop_pdu;
        avpl_match_mode criterium_match_mode;
index dc44a9f2905ba90853aa49a05bc047149de1bd2c..1f8284671bd918cbba4f8b64212fe27781f54e08 100644 (file)
@@ -730,6 +730,8 @@ static mate_pdu* new_pdu(mate_cfg_pdu* cfg, guint32 framenum, field_info* proto,
        gint min_dist;
        field_info* range_fi;
        gint32 last_start;
+       gint32 first_end;
+       gint32 curr_end;
        int hfid;
 
        dbg_print (dbg_pdu,2,dbg_facility,"new_pdu: type=%s framenum=%i",cfg->name,framenum);
@@ -760,8 +762,9 @@ static mate_pdu* new_pdu(mate_cfg_pdu* cfg, guint32 framenum, field_info* proto,
        
        last_start = proto_range->start;
        
-       for (i = 0; i < cfg->hfid_ranges->len; i++) {
-               hfid = *((int*)g_ptr_array_index(cfg->hfid_ranges,i));
+       /* first we move forward in the tranport */
+       for (i = 0; i < cfg->transport_ranges->len; i++) {
+               hfid = *((int*)g_ptr_array_index(cfg->transport_ranges,i));
                ptrs = (GPtrArray*) g_hash_table_lookup(interesting,GINT_TO_POINTER(hfid));
                min_dist = 99999;
                range_fi = NULL;
@@ -792,6 +795,44 @@ static mate_pdu* new_pdu(mate_cfg_pdu* cfg, guint32 framenum, field_info* proto,
                }
        }
        
+       if (cfg->payload_ranges) {
+
+               first_end = proto_range->end;
+               
+               for (i = cfg->payload_ranges->len - 1 ; i+1; i--) {
+                       hfid = *((int*)g_ptr_array_index(cfg->payload_ranges,i));
+                       ptrs = (GPtrArray*) g_hash_table_lookup(interesting,GINT_TO_POINTER(hfid));
+                       min_dist = 99999;
+                       range_fi = NULL;
+                       
+                       if (ptrs) {
+                               for (j=0; j < ptrs->len; j++) {
+                                       cfi = (field_info*) g_ptr_array_index(ptrs,j);
+                                       curr_end = cfi->start + cfi->length;
+                                       if (curr_end > first_end && min_dist >= (curr_end - first_end) ) {
+                                               range_fi = cfi;
+                                               min_dist = curr_end - first_end;
+                                       }
+                               }
+                               
+                               if ( range_fi ) {
+                                       range = g_malloc(sizeof(range));
+                                       range->start = range_fi->start;
+                                       range->end = range_fi->start + range_fi->length;
+                                       g_ptr_array_add(data.ranges,range);
+                                       
+                                       last_start = range_fi->start;
+                                       
+                                       dbg_print(dbg_pdu,3,dbg_facility,"new_pdu: payload(%i) range %i-%i",hfid,range->start,range->end);
+                               } else {
+                                       /* we missed a range  */
+                                       dbg_print(dbg_pdu,6,dbg_facility,"new_pdu: payload(%i) missed",hfid);
+                               }
+                               
+                       }
+               }
+       }
+
        g_hash_table_foreach(cfg->hfids_attr,get_pdu_fields,&data);
        
        g_ptr_array_free(data.ranges,TRUE);
index 08e34e14069106e499b9aa0a5f86482682bd90a3..638745a783e8628c73946fa94cab23e018d04d5b 100644 (file)
@@ -136,7 +136,8 @@ static mate_cfg_item* new_mate_cfg_item(guint8* name) {
        new->discard_pdu_attributes = matecfg->discard_pdu_attributes;
        new->last_to_be_created = matecfg->last_to_be_created;
        new->hfid_proto = -1;
-       new->hfid_ranges = NULL;
+       new->transport_ranges = NULL;
+       new->payload_ranges = NULL;
        new->hfids_attr = NULL;
        new->drop_pdu = matecfg->drop_pdu;
        new->criterium_match_mode = AVPL_NO_MATCH;
@@ -195,8 +196,11 @@ static void delete_mate_cfg_item(mate_cfg_item* cfg, gboolean avp_items_too) {
 
        if (cfg->transforms) g_ptr_array_free(cfg->transforms,TRUE);
 
-       if (cfg->hfid_ranges)
-               g_ptr_array_free(cfg->hfid_ranges,TRUE);
+       if (cfg->transport_ranges)
+               g_ptr_array_free(cfg->transport_ranges,TRUE);
+       
+       if (cfg->payload_ranges)
+               g_ptr_array_free(cfg->payload_ranges,TRUE);
 
        if (cfg->hfids_attr)
                g_hash_table_foreach_remove(cfg->hfids_attr,free_both, VALUE_TOO );
@@ -207,7 +211,8 @@ static mate_cfg_pdu* new_pducfg(guint8* name) {
        mate_cfg_pdu* new = new_mate_cfg_item(name);
 
        new->type = MATE_PDU_TYPE;
-       new->hfid_ranges = g_ptr_array_new();
+       new->transport_ranges = g_ptr_array_new();
+       
        new->hfids_attr = g_hash_table_new(g_int_hash,g_int_equal);
 
        g_ptr_array_add(matecfg->pducfglist,(gpointer) new);
@@ -368,15 +373,43 @@ static gboolean add_hfid(guint8* what, guint8* how, GHashTable* where) {
        return exists;
 }
 
+static guint8* add_ranges(guint8* range,GPtrArray* range_ptr_arr) {
+       gchar**  ranges;
+       guint i;
+       header_field_info* hfi;
+       int* hfidp;
+
+       ranges = g_strsplit(range,"/",0);
+       
+       if (ranges) {
+               for (i=0; ranges[i]; i++) {
+                       hfi = proto_registrar_get_byname(ranges[i]);
+                       if (hfi) {
+                               hfidp = g_malloc(sizeof(int));
+                               *hfidp = hfi->id;
+                               g_ptr_array_add(range_ptr_arr,(gpointer)hfidp);
+                               g_string_sprintfa(matecfg->mate_attrs_filter, "||%s",ranges[i]);
+                       } else {
+                               g_strfreev(ranges);
+                               return g_strdup_printf("no such proto: '%s'",ranges[i]);;
+                       }
+               }
+               
+               g_strfreev(ranges);
+       }
+       
+       return NULL;
+}
+
+
 static gboolean config_pdu(AVPL* avpl) {
        guint8* name = NULL;
        guint8* transport = extract_named_str(avpl,KEYWORD_TRANSPORT,NULL);
+       guint8* payload = extract_named_str(avpl,KEYWORD_PAYLOAD,NULL);
        guint8* proto = extract_named_str(avpl,KEYWORD_PROTO,"no_protocol");
        mate_cfg_pdu* cfg = lookup_using_index_avp(avpl,KEYWORD_NAME,matecfg->pducfgs,&name);
        header_field_info* hfi;
-       int* hfidp;
-       gchar**  transports;
-       guint i;
+       guint8* range_err;
        AVP* attr_avp;
 
        if (! name ) {
@@ -407,31 +440,25 @@ static gboolean config_pdu(AVPL* avpl) {
        g_string_sprintfa(matecfg->mate_protos_filter,"||%s",proto);
 
        if ( transport ) {
-
-               transports = g_strsplit(transport,"/",0);
-
-               if (transports) {
-                       for (i=0; transports[i]; i++) {
-                               hfi = proto_registrar_get_byname(transports[i]);
-                               if (hfi) {
-                                       hfidp = g_malloc(sizeof(int));
-                                       *hfidp = hfi->id;
-                                       g_ptr_array_add(cfg->hfid_ranges,(gpointer)hfidp);
-                                       g_string_sprintfa(matecfg->mate_attrs_filter, "||%s",transports[i]);
-                               } else {
-                                       report_error("MATE: PduDef: no such proto: '%s' for Transport in: %s",proto,avpl->name);
-                                       g_strfreev(transports);
-                                       return FALSE;
-                               }
-                       }
-
-                       g_strfreev(transports);
+               if (( range_err = add_ranges(transport,cfg->transport_ranges) )) {
+                       report_error("MATE: PduDef: %s in Transport for '%s' in: %s",range_err, cfg->name,avpl->name);
+                       g_free(range_err);
+                       return FALSE;                   
                }
        } else {
                report_error("MATE: PduDef: no Transport for '%s' in: %s",cfg->name,avpl->name);
                return FALSE;
        }
 
+       if ( payload ) {
+               cfg->payload_ranges = g_ptr_array_new();
+               if (( range_err = add_ranges(payload,cfg->payload_ranges) )) {
+                       report_error("MATE: PduDef: %s in Payload for '%s' in: %s",range_err, cfg->name,avpl->name);
+                       g_free(range_err);
+                       return FALSE;                   
+               }
+       }
+       
        while (( attr_avp = extract_first_avp(avpl) )) {
                if ( ! add_hfid(attr_avp->v,attr_avp->n,cfg->hfids_attr) ) {
                        report_error("MATE: PduDef: failed to set PDU attribute '%s' in: %s",attr_avp->n,avpl->name);
@@ -598,7 +625,7 @@ static gboolean config_settings(AVPL*avpl) {
 
        matecfg->dbg_lvl = extract_named_int(avpl, KEYWORD_DBG_GENERAL,0);
        matecfg->dbg_cfg_lvl = extract_named_int(avpl, KEYWORD_DBG_CFG,0);
-       matecfg->dbg_gop_lvl = extract_named_int(avpl, KEYWORD_DBG_PDU,0);
+       matecfg->dbg_pdu_lvl = extract_named_int(avpl, KEYWORD_DBG_PDU,0);
        matecfg->dbg_gop_lvl = extract_named_int(avpl, KEYWORD_DBG_GOP,0);
        matecfg->dbg_gog_lvl = extract_named_int(avpl, KEYWORD_DBG_GOG,0);
 
@@ -1094,13 +1121,25 @@ static void print_pdu_config(mate_cfg_pdu* cfg) {
        g_string_sprintfa(s, "Name=%s; Proto=%s; DiscartAttribs=%s; Stop=%s;  Transport=",
                                          cfg->name,my_protoname(cfg->hfid_proto),discard,stop);
 
-       for (i = 0; i < cfg->hfid_ranges->len; i++) {
-               hfid = *((int*) g_ptr_array_index(cfg->hfid_ranges,i));
+       for (i = 0; i < cfg->transport_ranges->len; i++) {
+               hfid = *((int*) g_ptr_array_index(cfg->transport_ranges,i));
                g_string_sprintfa(s,"%s/",my_protoname(hfid));
        }
 
        *(s->str + s->len - 1) = ';';
 
+       if (cfg->payload_ranges->len) {
+               g_string_sprintfa(s, " Payload=");
+               
+               for (i = 0; i < cfg->payload_ranges->len; i++) {
+                       hfid = *((int*) g_ptr_array_index(cfg->payload_ranges,i));
+                       g_string_sprintfa(s,"%s/",my_protoname(hfid));
+               }
+               
+               *(s->str + s->len - 1) = ';';
+
+       }
+       
        g_hash_table_foreach(cfg->hfids_attr,print_hfid_hash,s);
 
        dbg_print(dbg_cfg,0,dbg_facility,"%s",s->str);