Ethereal-dev: Re: [Ethereal-dev] Changing tap code not to call "epan_dissect_run()" one more t
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: "Pia Sahlberg" <piabar@xxxxxxxxxxx>
Date: Wed, 16 Oct 2002 23:30:49 +0000
Hi, attached are two patches:tap.diff that cleans up the tap interface and makes the packet only be dissected ONCE. Not as previously once in file.c and once in tap.c.
tcp.diff that fixes the bug with TCP-Desegmentation interaction with RelativeSequence numbers.
Please check in these in. best regards ronnie sahlberg _________________________________________________________________Get faster connections�-- switch to�MSN Internet Access! http://resourcecenter.msn.com/access/plans/default.asp
diff -u -r -x *.[^ch]|nmake|am ethereal-orig/file.c ethereal/file.c --- ethereal-orig/file.c Wed Oct 16 20:26:58 2002 +++ ethereal/file.c Wed Oct 16 19:49:17 2002 @@ -657,18 +657,21 @@ firstusec = fdata->abs_usecs; } - tap_queue_init(pseudo_header, buf, fdata); /* If either we have a display filter and are re-applying it; we have a list of color filters; + we have tap listeners; + allocate a protocol tree root node, so that we'll construct a protocol tree against which a filter expression can be evaluated. */ if ((cf->dfcode != NULL && refilter) || filter_list != NULL) create_proto_tree = TRUE; + if ( num_tap_filters ) + create_proto_tree = TRUE; /* Dissect the frame. */ edt = epan_dissect_new(create_proto_tree, FALSE); @@ -679,8 +682,9 @@ if (filter_list) { filter_list_prime_edt(edt); } + tap_queue_init(edt); epan_dissect_run(edt, pseudo_header, buf, fdata, &cf->cinfo); - tap_push_tapped_queue(); + tap_push_tapped_queue(edt); /* If we have a display filter, apply it if we're refiltering, otherwise leave the "passed_dfilter" flag alone. diff -u -r -x *.[^ch]|nmake|am ethereal-orig/tap.c ethereal/tap.c --- ethereal-orig/tap.c Wed Oct 16 20:26:58 2002 +++ ethereal/tap.c Wed Oct 16 20:28:11 2002 @@ -41,7 +41,8 @@ #include "epan/dfilter/dfilter.h" #include "tap.h" -int tapping_is_active=0; +static int tapping_is_active=0; +int num_tap_filters=0; typedef struct _tap_dissector_t { struct _tap_dissector_t *next; @@ -79,10 +80,6 @@ } tap_listener_t; static volatile tap_listener_t *tap_listener_queue=NULL; -static union wtap_pseudo_header *l_pseudo_header=NULL; -static const u_char *l_buf=NULL; -static frame_data *l_fdata; - /* ********************************************************************** * Init routine only called from epan at application startup* ********************************************************************** */
@@ -201,52 +198,56 @@This is very cheap since we just prepend the used queue to the free queue.
*/ void-tap_queue_init(union wtap_pseudo_header *pseudo_header, const u_char *buf, frame_data *fdata)
+tap_queue_init(epan_dissect_t *edt) { tap_packet_t *tpt; + tap_listener_t *tl; - l_pseudo_header=pseudo_header; - l_buf=buf; - l_fdata=fdata; + /* nothing to do, just return */ + if(!tap_listener_queue){ + return; + } tapping_is_active=1; - tpt=tap_packet_list_queue; - if(!tpt){ - return; - } - - for(;tpt->next;tpt=tpt->next) + if(tpt){ + for(;tpt->next;tpt=tpt->next) ; - tpt->next=tap_packet_list_free; - tap_packet_list_free=tap_packet_list_queue; - tap_packet_list_queue=NULL; + tpt->next=tap_packet_list_free; + tap_packet_list_free=tap_packet_list_queue; + tap_packet_list_queue=NULL; + } + /* loop over all tap listeners and build the list of all + interesting hf_fields */ + for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){ + if(tl->code){ + epan_dissect_prime_dfilter(edt, tl->code); + } + } }/* this function is called after a packet has been fully dissected to push the tapped
data to all extensions that has callbacks registered. */ void -tap_push_tapped_queue(void) +tap_push_tapped_queue(epan_dissect_t *edt) { tap_packet_t *tp; tap_listener_t *tl; - epan_dissect_t *edt; - - tapping_is_active=0; - edt=epan_dissect_new(TRUE, FALSE); - /* loop over all tap listeners and build the list of all - interesting hf_fields */ - for(tl=(tap_listener_t *)tap_listener_queue;tl;tl=tl->next){ - if(tl->code){ - epan_dissect_prime_dfilter(edt, tl->code); - } + /* nothing to do, just return */ + if(!tapping_is_active){ + return; } - epan_dissect_run(edt, l_pseudo_header, l_buf, l_fdata, NULL); + tapping_is_active=0; + + /* nothing to do, just return */ + if(!tap_packet_list_queue){ + return; + } /* loop over all tap listeners and call the listener callback for all packets that match the filter. */ @@ -263,8 +264,6 @@ } } } - - epan_dissect_free(edt); }/* This function is called when we need to reset all tap listeners, for example
@@ -310,7 +309,7 @@ /* ********************************************************************** - * Functions used by the RS (Really Simple api) extension to + * Functions used by tap to * 1, register that a really simple extension is available for use by * ethereal. * 2, start tapping from a subdissector @@ -358,6 +357,8 @@ g_free(tl); fprintf(stderr,"register_tap_listener(): %s\n", dfilter_error_msg); return 1; + } else { + num_tap_filters++; } } @@ -401,6 +402,7 @@ if(tl){ if(tl->code){ dfilter_free(tl->code); + num_tap_filters--; } g_free(tl); } diff -u -r -x *.[^ch]|nmake|am ethereal-orig/tap.h ethereal/tap.h --- ethereal-orig/tap.h Wed Oct 16 20:26:59 2002 +++ ethereal/tap.h Wed Oct 16 19:55:15 2002 @@ -22,14 +22,16 @@* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ -#include "wiretap/wtap.h" +#include "epan/epan.h" + +extern int num_tap_filters; void tap_init(void); int register_tap(char *name); int find_tap_id(char *name);void tap_queue_packet(int tap_id, packet_info *pinfo, void *tap_specific_data); -void tap_queue_init(union wtap_pseudo_header *pseudo_header, const u_char *buf, frame_data *fdata);
-void tap_push_tapped_queue(void); +void tap_queue_init(epan_dissect_t *edt); +void tap_push_tapped_queue(epan_dissect_t *edt); extern int tapping_is_active; void reset_tap_listeners(void); void draw_tap_listeners(gboolean draw_all);diff -u -r -x *.[^ch]|nmake|am ethereal-orig/tethereal.c ethereal/tethereal.c
--- ethereal-orig/tethereal.c Wed Oct 16 20:27:00 2002 +++ ethereal/tethereal.c Wed Oct 16 19:55:45 2002 @@ -1675,9 +1675,9 @@ epan_dissect_prime_dfilter(edt, cf->rfcode); } - tap_queue_init(pseudo_header, buf, &fdata); + tap_queue_init(edt);epan_dissect_run(edt, pseudo_header, buf, &fdata, verbose ? NULL : &cf->cinfo);
- tap_push_tapped_queue(); + tap_push_tapped_queue(edt); if (cf->rfcode) { passed = dfilter_apply_edt(cf->rfcode, edt);diff -u -r -x *.[^ch]|nmake|am ethereal-orig/packet-tcp.c ethereal/packet-tcp.c
--- ethereal-orig/packet-tcp.c Thu Oct 17 06:49:00 2002 +++ ethereal/packet-tcp.c Thu Oct 17 06:51:09 2002 @@ -743,6 +743,8 @@ address *dst; guint32 seq; /* xxx */ + guint16 sport; + guint16 dport; guint32 start_seq; guint32 tot_len; guint32 first_frame; @@ -771,7 +773,7 @@ { tcp_segment_key *key = (tcp_segment_key *)k; - return key->seq; + return key->seq+key->sport; } static gint @@ -783,6 +785,8 @@ return ( ( (key1->seq==key2->seq) &&(ADDRESSES_EQUAL(key1->src, key2->src)) &&(ADDRESSES_EQUAL(key1->dst, key2->dst)) + &&(key1->sport==key2->sport) + &&(key1->dport==key2->dport) ) ? TRUE:FALSE); } @@ -837,7 +841,7 @@ proto_tree *tree, proto_tree *tcp_tree) { struct tcpinfo *tcpinfo = pinfo->private_data; - fragment_data *ipfd_head; + fragment_data *ipfd_head=NULL; tcp_segment_key old_tsk, *tsk; gboolean must_desegment = FALSE; gboolean called_dissector = FALSE; @@ -868,6 +872,8 @@ */ old_tsk.src = &pinfo->src; old_tsk.dst = &pinfo->dst; + old_tsk.sport = sport; + old_tsk.dport = dport; old_tsk.seq = seq; tsk = g_hash_table_lookup(tcp_segment_table, &old_tsk); @@ -876,7 +882,7 @@ a higher-level PDU. This means we must desegment it. Add it to the defragmentation lists. */ - ipfd_head = fragment_add(tvb, offset, pinfo, tsk->start_seq, + ipfd_head = fragment_add(tvb, offset, pinfo, tsk->first_frame, tcp_fragment_table, seq - tsk->start_seq, nxtseq - seq, @@ -1001,7 +1007,7 @@ * being a new higher-level PDU that also * needs desegmentation). */ - fragment_set_partial_reassembly(pinfo,tsk->start_seq,tcp_fragment_table); + fragment_set_partial_reassembly(pinfo,tsk->first_frame,tcp_fragment_table); tsk->tot_len = tvb_reported_length(next_tvb) + pinfo->desegment_len; /* @@ -1148,11 +1154,13 @@ tsk->start_seq = tsk->seq; tsk->tot_len = nxtseq - tsk->start_seq + pinfo->desegment_len; tsk->first_frame = pinfo->fd->num; + tsk->sport=sport; + tsk->dport=dport; g_hash_table_insert(tcp_segment_table, tsk, tsk); /* Add portion of segment unprocessed by the subdissector to defragmentation lists */ - fragment_add(tvb, deseg_offset, pinfo, tsk->start_seq, + fragment_add(tvb, deseg_offset, pinfo, tsk->first_frame, tcp_fragment_table, tsk->seq - tsk->start_seq, nxtseq - tsk->start_seq,
- Follow-Ups:
- Prev by Date: Re: [Ethereal-dev] tapping commentary
- Next by Date: Re: [Ethereal-dev] Patch: adding "running time" to the capture window
- Previous by thread: Re: [Ethereal-dev] Changing tap code not to call "epan_dissect_run()" one more time?
- Next by thread: Re: [Ethereal-dev] Changing tap code not to call "epan_dissect_run()" one more time?
- Index(es):