aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>1999-11-17 21:58:33 +0000
committerGuy Harris <guy@alum.mit.edu>1999-11-17 21:58:33 +0000
commit4fddc1f3284d735e439f1b30b5c351994a8b0e6d (patch)
treebf2778e6e4a39d17911244ab0e2e5a1e10db2c1c
parentcd478752a11caccf21882feb1bf5b00e96095922 (diff)
Provide a general mechanism by which dissectors can register "init"
routines, which are called before a dissection pass is made over all the packets in a capture - the "init" routine would clear out any state information that needs to be initialized before such a dissection pass. Make the NCP, SMB, AFS, and ONC RPC dissectors register their "init" routines with that mechanism, have the code that reads in a capture file call the routine that calls all registered "init" routines rather than calling a wired-in set of "init" routines, and also have the code that runs a filtering or colorizing pass over all the packets call that routine, as a filtering or colorizing pass is a dissection pass. Have the ONC RPC "init" routine zero out the table of RPC calls, so that it completely erases any state from the previous dissection pass (so that, for example, if you run a filtering pass, it doesn't mark any non-duplicate packets as duplicates because it remembers them from the previous pass). svn path=/trunk/; revision=1050
-rw-r--r--file.c21
-rw-r--r--packet-afs.c5
-rw-r--r--packet-ncp.c5
-rw-r--r--packet-ncp.h5
-rw-r--r--packet-rpc.c8
-rw-r--r--packet-smb.c9
-rw-r--r--packet.c29
-rw-r--r--packet.h13
8 files changed, 66 insertions, 29 deletions
diff --git a/file.c b/file.c
index d9e96dd8c9..08ddbcb32c 100644
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
- * $Id: file.c,v 1.119 1999/11/08 01:03:31 guy Exp $
+ * $Id: file.c,v 1.120 1999/11/17 21:58:33 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -93,8 +93,6 @@
#include "packet-ipv6.h"
-#include "packet-ncp.h"
-
#include "packet-sna.h"
#include "packet-vines.h"
@@ -147,10 +145,7 @@ open_cap_file(char *fname, capture_file *cf) {
conversation_init();
/* Initialize protocol-specific variables */
- afs_init_protocol();
- ncp_init_protocol();
- rpc_init_protocol();
- smb_init_protocol();
+ init_all_protocols();
cf->wth = wth;
cf->fh = fh;
@@ -861,8 +856,7 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf
}
/* Apply the filters */
- if (cf->dfcode != NULL ||
- CFILTERS_CONTAINS_FILTER(cf)) {
+ if (cf->dfcode != NULL || CFILTERS_CONTAINS_FILTER(cf)) {
protocol_tree = proto_tree_create_root();
dissect_packet(buf, fdata, protocol_tree);
if (cf->dfcode != NULL)
@@ -1064,6 +1058,15 @@ colorize_packets(capture_file *cf)
guint32 progbar_quantum;
guint32 progbar_nextstep;
+ /* We need to re-initialize all the state information that protocols
+ keep, because we're making a fresh pass through all the packets. */
+
+ /* Initialize the table of conversations. */
+ conversation_init();
+
+ /* Initialize protocol-specific variables */
+ init_all_protocols();
+
gtk_progress_set_activity_mode(GTK_PROGRESS(prog_bar), FALSE);
/* Freeze the packet list while we redo it, so we don't get any
diff --git a/packet-afs.c b/packet-afs.c
index 3b45e2e402..e1447c45eb 100644
--- a/packet-afs.c
+++ b/packet-afs.c
@@ -6,7 +6,7 @@
* Portions based on information retrieved from the RX definitions
* in Arla, the free AFS client at http://www.stacken.kth.se/project/arla/
*
- * $Id: packet-afs.c,v 1.6 1999/11/16 11:42:23 guy Exp $
+ * $Id: packet-afs.c,v 1.7 1999/11/17 21:58:31 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@unicom.net>
@@ -685,7 +685,7 @@ afs_hash (gconstpointer v)
/*
* Protocol initialization
*/
-void
+static void
afs_init_protocol(void)
{
if (afs_request_hash)
@@ -2607,4 +2607,5 @@ proto_register_afs(void)
proto_afs = proto_register_protocol("Andrew File System (AFS)", "afs");
proto_register_field_array(proto_afs, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
+ register_init_routine(&afs_init_protocol);
}
diff --git a/packet-ncp.c b/packet-ncp.c
index 6d6b62591f..d45bc70d31 100644
--- a/packet-ncp.c
+++ b/packet-ncp.c
@@ -2,7 +2,7 @@
* Routines for NetWare Core Protocol
* Gilbert Ramirez <gram@verdict.uthscsa.edu>
*
- * $Id: packet-ncp.c,v 1.21 1999/11/16 11:42:40 guy Exp $
+ * $Id: packet-ncp.c,v 1.22 1999/11/17 21:58:28 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@unicom.net>
@@ -388,7 +388,7 @@ guint ncp_hash (gconstpointer v)
/* Initializes the hash table and the mem_chunk area each time a new
* file is loaded or re-loaded in ethereal */
-void
+static void
ncp_init_protocol(void)
{
#if defined(DEBUG_NCP_HASH)
@@ -891,4 +891,5 @@ proto_register_ncp(void)
proto_ncp = proto_register_protocol("NetWare Core Protocol", "ncp");
proto_register_field_array(proto_ncp, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
+ register_init_routine(&ncp_init_protocol);
}
diff --git a/packet-ncp.h b/packet-ncp.h
index 837f7bf6a0..ba19899a40 100644
--- a/packet-ncp.h
+++ b/packet-ncp.h
@@ -2,7 +2,7 @@
* Routines for NetWare Core Protocol
* Gilbert Ramirez <gram@verdict.uthscsa.edu>
*
- * $Id: packet-ncp.h,v 1.5 1999/03/20 04:38:57 gram Exp $
+ * $Id: packet-ncp.h,v 1.6 1999/11/17 21:58:33 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@unicom.net>
@@ -26,6 +26,3 @@
extern guint32 nw_server_address;
-
-void ncp_init_protocol(void);
-
diff --git a/packet-rpc.c b/packet-rpc.c
index a84e7479d0..68f836c7d4 100644
--- a/packet-rpc.c
+++ b/packet-rpc.c
@@ -2,7 +2,7 @@
* Routines for rpc dissection
* Copyright 1999, Uwe Girlich <Uwe.Girlich@philosys.de>
*
- * $Id: packet-rpc.c,v 1.16 1999/11/16 11:42:51 guy Exp $
+ * $Id: packet-rpc.c,v 1.17 1999/11/17 21:58:32 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@unicom.net>
@@ -1015,10 +1015,11 @@ dissect_rpc_prog:
return TRUE;
}
-/* will be called from file.c on every new file open */
-void
+/* Discard any state we've saved. */
+static void
rpc_init_protocol(void)
{
+ memset(rpc_call_table, '\0', sizeof rpc_call_table);
rpc_call_index = 0;
rpc_call_firstfree = 0;
}
@@ -1101,4 +1102,5 @@ proto_register_rpc(void)
proto_rpc = proto_register_protocol("Remote Procedure Call", "rpc");
proto_register_field_array(proto_rpc, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
+ register_init_routine(&rpc_init_protocol);
}
diff --git a/packet-smb.c b/packet-smb.c
index 8b21996905..67cf394c96 100644
--- a/packet-smb.c
+++ b/packet-smb.c
@@ -2,7 +2,7 @@
* Routines for smb packet dissection
* Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
*
- * $Id: packet-smb.c,v 1.40 1999/11/16 17:03:36 gram Exp $
+ * $Id: packet-smb.c,v 1.41 1999/11/17 21:58:28 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@unicom.net>
@@ -139,10 +139,10 @@ smb_hash (gconstpointer v)
}
/*
- * Initialize some variables every time a file is loaded or re-loaded
+ * Free up any state information we've saved, and re-initialize the
+ * tables of state information.
*/
-
-void
+static void
smb_init_protocol(void)
{
#if defined(DEBUG_SMB_HASH)
@@ -10624,4 +10624,5 @@ proto_register_smb(void)
proto_browse = proto_register_protocol("Microsoft Windows Browser Protocol", "browser");
/* proto_register_field_array(proto_smb, hf, array_length(hf));*/
proto_register_subtree_array(ett, array_length(ett));
+ register_init_routine(&smb_init_protocol);
}
diff --git a/packet.c b/packet.c
index b6899d930a..48f158cd73 100644
--- a/packet.c
+++ b/packet.c
@@ -1,7 +1,7 @@
/* packet.c
* Routines for packet disassembly
*
- * $Id: packet.c,v 1.54 1999/11/16 11:43:04 guy Exp $
+ * $Id: packet.c,v 1.55 1999/11/17 21:58:32 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -722,6 +722,33 @@ void blank_packetinfo(void)
pi.destport = 0;
}
+/* Allow protocols to register "init" routines, which are called before
+ we make a pass through a capture file and dissect all its packets
+ (e.g., when we read in a new capture file, or run a "filter packets"
+ or "colorize packets" pass over the current capture file). */
+static GSList *init_routines;
+
+void
+register_init_routine(void (*func)(void))
+{
+ init_routines = g_slist_append(init_routines, func);
+}
+
+/* Call all the registered "init" routines. */
+static void
+call_init_routine(gpointer routine, gpointer dummy)
+{
+ void (*func)(void) = routine;
+
+ (*func)();
+}
+
+void
+init_all_protocols(void)
+{
+ g_slist_foreach(init_routines, &call_init_routine, NULL);
+}
+
/* this routine checks the frame type from the cf structure */
void
dissect_packet(const u_char *pd, frame_data *fd, proto_tree *tree)
diff --git a/packet.h b/packet.h
index 802b1c66a3..1fb7d46312 100644
--- a/packet.h
+++ b/packet.h
@@ -1,7 +1,7 @@
/* packet.h
* Definitions for packet disassembly structures and routines
*
- * $Id: packet.h,v 1.143 1999/11/17 02:17:07 guy Exp $
+ * $Id: packet.h,v 1.144 1999/11/17 21:58:32 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -245,9 +245,14 @@ void col_append_str(frame_data *, gint, gchar *);
void blank_packetinfo(void);
-void afs_init_protocol(void);
-void rpc_init_protocol(void);
-void smb_init_protocol(void);
+/* Allow protocols to register "init" routines, which are called before
+ we make a pass through a capture file and dissect all its packets
+ (e.g., when we read in a new capture file, or run a "filter packets"
+ or "colorize packets" pass over the current capture file). */
+void register_init_routine(void (*func)(void));
+
+/* Call all the registered "init" routines. */
+void init_all_protocols(void);
void dissect_packet(const u_char *, frame_data *, proto_tree *);