Skip to content

Commit

Permalink
Provide for per-protocol-tree data in the proto_tree code.
Browse files Browse the repository at this point in the history
Put a hash-table of "interesting" fields in the per-proto-tree data.
The dfilter code records which fields/protocols are "interesting" (by which
I mean, their value or existence is checked). Thus, the proto_tree routines
can create special arrays of field_info*'s that are ready for the dfilter
engine to use during a filter operation.

Also store the "proto_tree_is_visible" boolean, renamed "visible", in
the per-proto-tree data.

Move epan_dissect_t to its own header file to make #include dependencies
easier to handle.

Provide epan_dissect_fill_in_columns(), which accepts just the epan_dissect_t*
as an argument.

epan_dissect_new() needs to be followed by epan_dissect_run() for the
dissection to actually take place. Between those two calls,
epan_dissect_prime_dfilter() can be run 0, 1, or multiple times in order to
prime the empty proto_tree with the "intersesting" fields from the dfilter_t.

svn path=/trunk/; revision=4422
  • Loading branch information
gilramir committed Dec 18, 2001
1 parent 4e013a4 commit 791f577
Show file tree
Hide file tree
Showing 27 changed files with 536 additions and 261 deletions.
3 changes: 2 additions & 1 deletion epan/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Automake file for the EPAN library
# (Ethereal Protocol ANalyzer Library)
#
# $Id: Makefile.am,v 1.29 2001/11/22 03:07:06 hagbard Exp $
# $Id: Makefile.am,v 1.30 2001/12/18 19:09:03 gram Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@zing.org>
Expand Down Expand Up @@ -46,6 +46,7 @@ libethereal_a_SOURCES = \
column-utils.h \
epan.c \
epan.h \
epan_dissect.h \
except.c \
except.h \
exceptions.h \
Expand Down
5 changes: 4 additions & 1 deletion epan/dfilter/dfilter-int.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: dfilter-int.h,v 1.3 2001/02/15 06:22:45 guy Exp $
* $Id: dfilter-int.h,v 1.4 2001/12/18 19:09:06 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
Expand Down Expand Up @@ -35,6 +35,8 @@ struct _dfilter_t {
int num_registers;
GList **registers;
gboolean *attempted_load;
int *interesting_fields;
int num_interesting_fields;
};

typedef struct {
Expand All @@ -43,6 +45,7 @@ typedef struct {
gboolean syntax_error;
GPtrArray *insns;
GHashTable *loaded_fields;
GHashTable *interesting_fields;
int next_insn_id;
int next_register;
} dfwork_t;
Expand Down
27 changes: 26 additions & 1 deletion epan/dfilter/dfilter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: dfilter.c,v 1.5 2001/07/13 00:55:54 guy Exp $
* $Id: dfilter.c,v 1.6 2001/12/18 19:09:06 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
Expand Down Expand Up @@ -37,6 +37,7 @@
#include "gencode.h"
#include "semcheck.h"
#include "dfvm.h"
#include "epan_dissect.h"


/* Balanced tree of abbreviations and IDs */
Expand Down Expand Up @@ -228,6 +229,10 @@ dfilter_free(dfilter_t *df)
free_insns(df->insns);
}

if (df->interesting_fields) {
g_free(df->interesting_fields);
}

g_free(df->registers);
g_free(df->attempted_load);
g_free(df);
Expand All @@ -245,6 +250,7 @@ dfwork_new(void)
dfw->syntax_error = FALSE;
dfw->insns = NULL;
dfw->loaded_fields = NULL;
dfw->interesting_fields = NULL;
dfw->next_insn_id = 0;
dfw->next_register = 0;

Expand All @@ -262,10 +268,15 @@ dfwork_free(dfwork_t *dfw)
g_hash_table_destroy(dfw->loaded_fields);
}

if (dfw->interesting_fields) {
g_hash_table_destroy(dfw->interesting_fields);
}

if (dfw->insns) {
free_insns(dfw->insns);
}


g_free(dfw);
}

Expand Down Expand Up @@ -333,6 +344,8 @@ dfilter_compile(gchar *text, dfilter_t **dfp)
dfilter = dfilter_new();
dfilter->insns = dfw->insns;
dfw->insns = NULL;
dfilter->interesting_fields = dfw_interesting_fields(dfw,
&dfilter->num_interesting_fields);

/* Initialize run-time space */
dfilter->num_registers = dfw->next_register;
Expand Down Expand Up @@ -377,6 +390,18 @@ dfilter_apply_edt(dfilter_t *df, epan_dissect_t* edt)
}


void
dfilter_foreach_interesting_field(dfilter_t *df, GFunc func,
gpointer user_data)
{
int i;

for (i = 0; i < df->num_interesting_fields; i++) {
func(GINT_TO_POINTER(df->interesting_fields[i]), user_data);
}
}


void
dfilter_dump(dfilter_t *df)
{
Expand Down
12 changes: 9 additions & 3 deletions epan/dfilter/dfilter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: dfilter.h,v 1.2 2001/02/01 20:31:18 gram Exp $
* $Id: dfilter.h,v 1.3 2001/12/18 19:09:06 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
Expand All @@ -25,12 +25,14 @@
#define DFILTER_H

#include <glib.h>
#include "epan.h"
#include "proto.h"

/* Passed back to user */
typedef struct _dfilter_t dfilter_t;

#include "epan.h"
#include "proto.h"


/* Module-level initialization */
void
dfilter_init(void);
Expand Down Expand Up @@ -75,6 +77,10 @@ dfilter_apply_edt(dfilter_t *df, epan_dissect_t* edt);
gboolean
dfilter_apply(dfilter_t *df, tvbuff_t *tvb, proto_tree *tree);

/* Run a callback for each interesting field in the dfilter. */
void
dfilter_foreach_interesting_field(dfilter_t *df, GFunc func,
gpointer user_data);

/* Print bytecode of dfilter to stdout */
void
Expand Down
6 changes: 4 additions & 2 deletions epan/dfilter/dfvm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: dfvm.c,v 1.4 2001/12/13 05:55:23 gram Exp $
* $Id: dfvm.c,v 1.5 2001/12/18 19:09:06 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
Expand Down Expand Up @@ -211,14 +211,16 @@ read_tree(dfilter_t *df, proto_tree *tree, int field_id, int reg)
if (!finfos) {
return FALSE;
}
else if (g_ptr_array_len(finfos) == 0) {
return FALSE;
}

len = finfos->len;
for (i = 0; i < len; i++) {
finfo = g_ptr_array_index(finfos, i);
fvalues = g_list_prepend(fvalues, finfo->value);
}
fvalues = g_list_reverse(fvalues);
g_ptr_array_free(finfos, TRUE);

df->registers[reg] = fvalues;
return TRUE;
Expand Down
50 changes: 48 additions & 2 deletions epan/dfilter/gencode.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: gencode.c,v 1.3 2001/02/27 19:23:28 gram Exp $
* $Id: gencode.c,v 1.4 2001/12/18 19:09:06 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
Expand Down Expand Up @@ -57,7 +57,7 @@ dfw_append_read_tree(dfwork_t *dfw, int field_id)
* can re-use registers. */
reg = GPOINTER_TO_UINT(
g_hash_table_lookup(dfw->loaded_fields,
GUINT_TO_POINTER(field_id)));
GINT_TO_POINTER(field_id)));
if (reg) {
/* Reg's are stored in has as reg+1, so
* that the non-existence of a field_id in
Expand All @@ -70,6 +70,10 @@ dfw_append_read_tree(dfwork_t *dfw, int field_id)
g_hash_table_insert(dfw->loaded_fields,
GUINT_TO_POINTER(field_id),
GUINT_TO_POINTER(reg + 1));

/* Record the FIELD_ID in hash of interesting fields. */
g_hash_table_insert(dfw->interesting_fields,
GINT_TO_POINTER(field_id), GUINT_TO_POINTER(TRUE));
}

insn = dfvm_insn_new(READ_TREE);
Expand Down Expand Up @@ -232,6 +236,11 @@ gen_test(dfwork_t *dfw, stnode_t *st_node)
insn = dfvm_insn_new(CHECK_EXISTS);
insn->arg1 = val1;
dfw_append_insn(dfw, insn);

/* Record the FIELD_ID in hash of interesting fields. */
g_hash_table_insert(dfw->interesting_fields,
GINT_TO_POINTER(hfinfo->id), GUINT_TO_POINTER(TRUE));

break;

case TEST_OP_NOT:
Expand Down Expand Up @@ -312,7 +321,44 @@ dfw_gencode(dfwork_t *dfw)
{
dfw->insns = g_ptr_array_new();
dfw->loaded_fields = g_hash_table_new(g_direct_hash, g_direct_equal);
dfw->interesting_fields = g_hash_table_new(g_direct_hash, g_direct_equal);
gencode(dfw, dfw->st_root);
dfw_append_insn(dfw, dfvm_insn_new(RETURN));
}



typedef struct {
int i;
int *fields;
} hash_key_iterator;

static void
get_hash_key(gpointer key, gpointer value, gpointer user_data)
{
int field_id = GPOINTER_TO_INT(key);
hash_key_iterator *hki = user_data;

hki->fields[hki->i] = field_id;
hki->i++;
}

int*
dfw_interesting_fields(dfwork_t *dfw, int *caller_num_fields)
{
int num_fields = g_hash_table_size(dfw->interesting_fields);

hash_key_iterator hki;

if (num_fields == 0) {
*caller_num_fields = 0;
return NULL;
}

hki.fields = g_new(int, num_fields);
hki.i = 0;

g_hash_table_foreach(dfw->interesting_fields, get_hash_key, &hki);
*caller_num_fields = num_fields;
return hki.fields;
}
3 changes: 3 additions & 0 deletions epan/dfilter/gencode.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
void
dfw_gencode(dfwork_t *dfw);

int*
dfw_interesting_fields(dfwork_t *dfw, int *caller_num_fields);

#endif
3 changes: 2 additions & 1 deletion epan/dfilter/semcheck.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: semcheck.c,v 1.6 2001/11/02 10:09:49 guy Exp $
* $Id: semcheck.c,v 1.7 2001/12/18 19:09:06 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
Expand Down Expand Up @@ -32,6 +32,7 @@
#include "sttype-test.h"

#include "exceptions.h"
#include "packet.h"

static void
semcheck(dfwork_t *dfw, stnode_t *st_node);
Expand Down
61 changes: 39 additions & 22 deletions epan/epan.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* epan.h
*
* $Id: epan.c,v 1.14 2001/12/16 22:16:13 guy Exp $
* $Id: epan.c,v 1.15 2001/12/18 19:09:03 gram Exp $
*
* Ethereal Protocol Analyzer Library
*
Expand All @@ -11,14 +11,13 @@
#endif

#include <glib.h>
#include <epan.h>
#include "epan.h"
#include "epan_dissect.h"

#include "conversation.h"
#include "dfilter/dfilter.h"
#include "except.h"
#include "packet.h"
#include "proto.h"
#include "tvbuff.h"
#include "column-utils.h"

/*
* XXX - this takes the plugin directory as an argument, because
Expand Down Expand Up @@ -74,37 +73,34 @@ epan_conversation_init(void)


epan_dissect_t*
epan_dissect_new(void* pseudo_header, const guint8* data, frame_data *fd,
gboolean create_proto_tree, gboolean proto_tree_visible,
column_info *cinfo)
epan_dissect_new(gboolean create_proto_tree, gboolean proto_tree_visible)
{
epan_dissect_t *edt;

edt = g_new(epan_dissect_t, 1);

/* start with empty data source list */
if ( fd->data_src)
g_slist_free( fd->data_src);
fd->data_src = 0;

/*
* Set the global "proto_tree_is_visible" to control whether
* to fill in the text representation field in the protocol
* tree fields.
*/
proto_tree_is_visible = proto_tree_visible;
if (create_proto_tree) {
edt->tree = proto_tree_create_root();
proto_tree_set_visible(edt->tree, proto_tree_visible);
}
else {
edt->tree = NULL;
}

dissect_packet(edt, pseudo_header, data, fd, cinfo);
return edt;
}

proto_tree_is_visible = FALSE;
void
epan_dissect_run(epan_dissect_t *edt, void* pseudo_header,
const guint8* data, frame_data *fd, column_info *cinfo)
{
/* start with empty data source list */
if (fd->data_src) {
g_slist_free(fd->data_src);
}
fd->data_src = NULL;

return edt;
dissect_packet(edt, pseudo_header, data, fd, cinfo);
}


Expand All @@ -122,3 +118,24 @@ epan_dissect_free(epan_dissect_t* edt)

g_free(edt);
}

static void
prime_dfilter(gpointer data, gpointer user_data)
{
int hfid = GPOINTER_TO_INT(data);
proto_tree *tree = user_data;

proto_tree_prime_hfid(tree, hfid);
}

void
epan_dissect_prime_dfilter(epan_dissect_t *edt, dfilter_t* dfcode)
{
dfilter_foreach_interesting_field(dfcode, prime_dfilter, edt->tree);
}

void
epan_dissect_fill_in_columns(epan_dissect_t *edt)
{
fill_in_columns(&edt->pi);
}
Loading

0 comments on commit 791f577

Please sign in to comment.