aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2009-06-05 22:42:47 +0000
committerGuy Harris <guy@alum.mit.edu>2009-06-05 22:42:47 +0000
commitcf91fdf16b2d961024ea062503ce5fb91af28186 (patch)
tree2654abe47f378933a5d325856a7b3f877338dd19 /file.c
parentf84499059642f102c7272e72f74d7a986f51b520 (diff)
Have tap listeners specify whether the "packet" routine requires
a protocol tree; the column values. This includes stats-tree listeners. Have the routines to build the packet list, and to retap packets, honor those requirements. This means that cf_retap_packets() no longer needs an argument to specify whether to construct the column values or not, so get rid of that argument. This also means that there's no need for a tap to have a fake filter to ensure that the protocol tree will be built, so don't set up a fake "frame" filter. While we're at it, clean up some cases where "no filter" was represented as a null string rather than a null pointer. Have a routine to return an indication of the number of tap listeners with filters; use that rather than the global num_tap_filters. Clean up some indentation and some gboolean vs. gint items. svn path=/trunk/; revision=28645
Diffstat (limited to 'file.c')
-rw-r--r--file.c102
1 files changed, 81 insertions, 21 deletions
diff --git a/file.c b/file.c
index 0b7bdab336..a02c53d49c 100644
--- a/file.c
+++ b/file.c
@@ -83,7 +83,8 @@ static guint32 cum_bytes = 0;
static void cf_reset_state(capture_file *cf);
-static int read_packet(capture_file *cf, dfilter_t *dfcode, gint64 offset);
+static int read_packet(capture_file *cf, dfilter_t *dfcode,
+ gboolean filtering_tap_listeners, guint tap_flags, gint64 offset);
static void rescan_packets(capture_file *cf, const char *action, const char *action_item,
gboolean refilter, gboolean redissect);
@@ -415,6 +416,8 @@ cf_read(capture_file *cf)
volatile gint64 progbar_nextstep;
volatile gint64 progbar_quantum;
dfilter_t *dfcode;
+ gboolean filtering_tap_listeners;
+ guint tap_flags;
#ifdef HAVE_LIBPCAP
volatile int displayed_once = 0;
#endif
@@ -428,6 +431,12 @@ cf_read(capture_file *cf)
dfilter_compile(cf->dfilter, &dfcode);
}
+ /* Do we have any tap listeners with filters? */
+ filtering_tap_listeners = have_filtering_tap_listeners();
+
+ /* Get the union of the flags for all tap listeners. */
+ tap_flags = union_of_tap_listener_flags();
+
cum_bytes=0;
reset_tap_listeners();
@@ -522,7 +531,7 @@ cf_read(capture_file *cf)
break;
}
TRY {
- read_packet(cf, dfcode, data_offset);
+ read_packet(cf, dfcode, filtering_tap_listeners, tap_flags, data_offset);
}
CATCH(OutOfMemoryError) {
gpointer dialog;
@@ -658,6 +667,8 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
gchar *err_info;
volatile int newly_displayed_packets = 0;
dfilter_t *dfcode;
+ gboolean filtering_tap_listeners;
+ guint tap_flags;
/* Compile the current display filter.
* We assume this will not fail since cf->dfilter is only set in
@@ -668,6 +679,12 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
dfilter_compile(cf->dfilter, &dfcode);
}
+ /* Do we have any tap listeners with filters? */
+ filtering_tap_listeners = have_filtering_tap_listeners();
+
+ /* Get the union of the flags for all tap listeners. */
+ tap_flags = union_of_tap_listener_flags();
+
*err = 0;
packet_list_check_end();
@@ -683,7 +700,8 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
break;
}
TRY{
- if (read_packet(cf, dfcode, data_offset) != -1) {
+ if (read_packet(cf, dfcode, filtering_tap_listeners, tap_flags,
+ data_offset) != -1) {
newly_displayed_packets++;
}
}
@@ -759,6 +777,8 @@ cf_finish_tail(capture_file *cf, int *err)
gchar *err_info;
gint64 data_offset;
dfilter_t *dfcode;
+ gboolean filtering_tap_listeners;
+ guint tap_flags;
/* Compile the current display filter.
* We assume this will not fail since cf->dfilter is only set in
@@ -769,6 +789,12 @@ cf_finish_tail(capture_file *cf, int *err)
dfilter_compile(cf->dfilter, &dfcode);
}
+ /* Do we have any tap listeners with filters? */
+ filtering_tap_listeners = have_filtering_tap_listeners();
+
+ /* Get the union of the flags for all tap listeners. */
+ tap_flags = union_of_tap_listener_flags();
+
if(cf->wth == NULL) {
cf_close(cf);
return CF_READ_ERROR;
@@ -784,7 +810,7 @@ cf_finish_tail(capture_file *cf, int *err)
aren't any packets left to read) exit. */
break;
}
- read_packet(cf, dfcode, data_offset);
+ read_packet(cf, dfcode, filtering_tap_listeners, tap_flags, data_offset);
}
/* Cleanup and release all dfilter resources */
@@ -915,7 +941,8 @@ void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode)
static int
add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
- dfilter_t *dfcode,
+ dfilter_t *dfcode, gboolean filtering_tap_listeners,
+ guint tap_flags,
union wtap_pseudo_header *pseudo_header, const guchar *buf,
gboolean refilter)
{
@@ -967,15 +994,18 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
we have a list of color filters;
- we have tap listeners;
+ we have tap listeners with filters;
+
+ we have tap listeners that require a protocol tree;
we have custom columns;
allocate a protocol tree root node, so that we'll construct
a protocol tree against which a filter expression can be
evaluated. */
- if ((dfcode != NULL && refilter) || color_filters_used()
- || num_tap_filters != 0 || have_custom_cols(&cf->cinfo))
+ if ((dfcode != NULL && refilter) || color_filters_used() ||
+ filtering_tap_listeners || (tap_flags & TL_REQUIRES_PROTO_TREE) ||
+ have_custom_cols(&cf->cinfo))
create_proto_tree = TRUE;
/* Dissect the frame. */
@@ -1088,7 +1118,8 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
/* read in a new packet */
/* returns the row of the new packet in the packet list or -1 if not displayed */
static int
-read_packet(capture_file *cf, dfilter_t *dfcode, gint64 offset)
+read_packet(capture_file *cf, dfilter_t *dfcode,
+ gboolean filtering_tap_listeners, guint tap_flags, gint64 offset)
{
const struct wtap_pkthdr *phdr = wtap_phdr(cf->wth);
union wtap_pseudo_header *pseudo_header = wtap_pseudoheader(cf->wth);
@@ -1147,7 +1178,9 @@ read_packet(capture_file *cf, dfilter_t *dfcode, gint64 offset)
cf->f_datalen = offset + phdr->caplen;
fdata->num = cf->count;
if (!cf->redissecting) {
- row = add_packet_to_packet_list(fdata, cf, dfcode, pseudo_header, buf, TRUE);
+ row = add_packet_to_packet_list(fdata, cf, dfcode,
+ filtering_tap_listeners, tap_flags,
+ pseudo_header, buf, TRUE);
}
} else {
/* XXX - if we didn't have read filters, or if we could avoid
@@ -1512,6 +1545,8 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
int progbar_nextstep;
int progbar_quantum;
dfilter_t *dfcode;
+ gboolean filtering_tap_listeners;
+ guint tap_flags;
/* Compile the current display filter.
* We assume this will not fail since cf->dfilter is only set in
@@ -1522,6 +1557,12 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
dfilter_compile(cf->dfilter, &dfcode);
}
+ /* Do we have any tap listeners with filters? */
+ filtering_tap_listeners = have_filtering_tap_listeners();
+
+ /* Get the union of the flags for all tap listeners. */
+ tap_flags = union_of_tap_listener_flags();
+
cum_bytes=0;
reset_tap_listeners();
/* Which frame, if any, is the currently selected frame?
@@ -1668,8 +1709,9 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
preceding_row = prev_row;
preceding_frame = prev_frame;
}
- row = add_packet_to_packet_list(fdata, cf, dfcode, &cf->pseudo_header, cf->pd,
- refilter);
+ row = add_packet_to_packet_list(fdata, cf, dfcode, filtering_tap_listeners,
+ tap_flags, &cf->pseudo_header, cf->pd,
+ refilter);
/* If this frame is displayed, and this is the first frame we've
seen displayed after the selected frame, remember this frame -
@@ -1902,20 +1944,22 @@ process_specified_packets(capture_file *cf, packet_range_t *range,
return ret;
}
+typedef struct {
+ gboolean construct_protocol_tree;
+ column_info *cinfo;
+} retap_callback_args_t;
+
static gboolean
retap_packet(capture_file *cf _U_, frame_data *fdata,
union wtap_pseudo_header *pseudo_header, const guint8 *pd,
void *argsp)
{
- column_info *cinfo = argsp;
+ retap_callback_args_t *args = argsp;
epan_dissect_t *edt;
- /* If 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. */
- edt = epan_dissect_new(num_tap_filters != 0, FALSE);
+ edt = epan_dissect_new(args->construct_protocol_tree, FALSE);
tap_queue_init(edt);
- epan_dissect_run(edt, pseudo_header, pd, fdata, cinfo);
+ epan_dissect_run(edt, pseudo_header, pd, fdata, args->cinfo);
tap_push_tapped_queue(edt);
epan_dissect_free(edt);
@@ -1923,9 +1967,25 @@ retap_packet(capture_file *cf _U_, frame_data *fdata,
}
cf_read_status_t
-cf_retap_packets(capture_file *cf, gboolean do_columns)
+cf_retap_packets(capture_file *cf)
{
packet_range_t range;
+ retap_callback_args_t callback_args;
+ gboolean filtering_tap_listeners;
+ guint tap_flags;
+
+ /* Do we have any tap listeners with filters? */
+ filtering_tap_listeners = have_filtering_tap_listeners();
+
+ tap_flags = union_of_tap_listener_flags();
+
+ /* If any tap listeners have filters, or require the protocol tree,
+ construct the protocol tree. */
+ callback_args.construct_protocol_tree = filtering_tap_listeners ||
+ (tap_flags & TL_REQUIRES_PROTO_TREE);
+
+ /* If any tap listeners require the columns, construct them. */
+ callback_args.cinfo = (tap_flags & TL_REQUIRES_COLUMNS) ? &cf->cinfo : NULL;
/* Reset the tap listeners. */
reset_tap_listeners();
@@ -1934,9 +1994,9 @@ cf_retap_packets(capture_file *cf, gboolean do_columns)
re-running the taps. */
packet_range_init(&range);
packet_range_process_init(&range);
- switch (process_specified_packets(cf, &range, "Refiltering statistics on",
+ switch (process_specified_packets(cf, &range, "Recalculating statistics on",
"all packets", TRUE, retap_packet,
- do_columns ? &cf->cinfo : NULL)) {
+ &callback_args)) {
case PSP_FINISHED:
/* Completed successfully. */
return CF_READ_OK;