diff options
-rw-r--r-- | conversation.c | 92 | ||||
-rw-r--r-- | conversation.h | 15 | ||||
-rw-r--r-- | packet-afs.c | 17 | ||||
-rw-r--r-- | packet-smb.c | 18 |
4 files changed, 81 insertions, 61 deletions
diff --git a/conversation.c b/conversation.c index 0cef652d2e..3f60a2d906 100644 --- a/conversation.c +++ b/conversation.c @@ -1,7 +1,7 @@ /* conversation.c * Routines for building lists of packets that are part of a "conversation" * - * $Id: conversation.c,v 1.1 1999/10/22 07:17:28 guy Exp $ + * $Id: conversation.c,v 1.2 1999/10/24 07:27:17 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -40,10 +40,11 @@ #include <string.h> #include <glib.h> #include "packet.h" +#include "conversation.h" static GHashTable *conversation_hashtable = NULL; static GMemChunk *conversation_key_chunk = NULL; -static GMemChunk *conversation_val_chunk = NULL; +static GMemChunk *conversation_chunk = NULL; typedef struct conversation_key { struct conversation_key *next; @@ -60,11 +61,6 @@ typedef struct conversation_key { */ static conversation_key *conversation_keys; -typedef struct conversation_val { - struct conversation_val *next; - guint32 index; -} conversation_val; - static guint32 new_index; static int conversation_init_count = 200; @@ -207,8 +203,8 @@ conversation_init(void) g_hash_table_destroy(conversation_hashtable); if (conversation_key_chunk != NULL) g_mem_chunk_destroy(conversation_key_chunk); - if (conversation_val_chunk != NULL) - g_mem_chunk_destroy(conversation_val_chunk); + if (conversation_chunk != NULL) + g_mem_chunk_destroy(conversation_chunk); conversation_hashtable = g_hash_table_new(conversation_hash, conversation_equal); @@ -216,9 +212,9 @@ conversation_init(void) sizeof(conversation_key), conversation_init_count * sizeof(struct conversation_key), G_ALLOC_AND_FREE); - conversation_val_chunk = g_mem_chunk_new("conversation_val_chunk", - sizeof(conversation_val), - conversation_init_count * sizeof(struct conversation_val), + conversation_chunk = g_mem_chunk_new("conversation_chunk", + sizeof(conversation_t), + conversation_init_count * sizeof(conversation_t), G_ALLOC_AND_FREE); /* @@ -243,18 +239,45 @@ copy_address(address *to, address *from) } /* - * Given source and destination addresses and ports for a packet, add - * it to the conversation containing packets between those address/port - * pairs, creating a new conversation if none exists between them. - * - * Returns an index to use to refer to the conversation. + * Given source and destination addresses and ports for a packet, + * create a new conversation to contain packets between those address/port + * pairs. */ -guint32 -add_to_conversation(address *src, address *dst, port_type ptype, +conversation_t * +conversation_new(address *src, address *dst, port_type ptype, + guint16 src_port, guint16 dst_port, void *data) +{ + conversation_t *conversation; + conversation_key *new_key; + + new_key = g_mem_chunk_alloc(conversation_key_chunk); + new_key->next = conversation_keys; + conversation_keys = new_key; + copy_address(&new_key->src, src); + copy_address(&new_key->dst, dst); + new_key->ptype = ptype; + new_key->port_src = src_port; + new_key->port_dst = dst_port; + + conversation = g_mem_chunk_alloc(conversation_chunk); + conversation->index = new_index; + conversation->data = data; + new_index++; + + g_hash_table_insert(conversation_hashtable, new_key, conversation); + return conversation; +} + +/* + * Given source and destination addresses and ports for a packet, + * search for a conversation containing packets between those address/port + * pairs. Returns NULL if not found. + */ +conversation_t * +find_conversation(address *src, address *dst, port_type ptype, guint16 src_port, guint16 dst_port) { - conversation_val *conversation; - conversation_key key, *new_key; + conversation_key key; /* * We don't make a copy of the address data, we just copy the @@ -265,30 +288,5 @@ add_to_conversation(address *src, address *dst, port_type ptype, key.ptype = ptype; key.port_src = src_port; key.port_dst = dst_port; - conversation = - (conversation_val *)g_hash_table_lookup(conversation_hashtable, - &key); - if (conversation == NULL) { - /* - * No such conversation yet. - * Allocate a new one. - * Here, we *do* have to copy the address data. - */ - new_key = g_mem_chunk_alloc(conversation_key_chunk); - new_key->next = conversation_keys; - conversation_keys = new_key; - copy_address(&new_key->src, src); - copy_address(&new_key->dst, dst); - new_key->ptype = ptype; - new_key->port_src = src_port; - new_key->port_dst = dst_port; - - conversation = g_mem_chunk_alloc(conversation_val_chunk); - conversation->index = new_index; - new_index++; - - g_hash_table_insert(conversation_hashtable, new_key, - conversation); - } - return conversation->index; + return g_hash_table_lookup(conversation_hashtable, &key); } diff --git a/conversation.h b/conversation.h index 5b722051aa..5f638eca73 100644 --- a/conversation.h +++ b/conversation.h @@ -1,7 +1,7 @@ /* conversation.h * Routines for building lists of packets that are part of a "conversation" * - * $Id: conversation.h,v 1.1 1999/10/22 07:17:28 guy Exp $ + * $Id: conversation.h,v 1.2 1999/10/24 07:27:18 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -23,6 +23,17 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* + * Data structure representing a conversation. + */ +typedef struct conversation { + struct conversation *next; /* pointer to next conversation on hash chain */ + guint32 index; /* unique ID for conversation */ + void *data; /* data our client can associate with a conversation */ +} conversation_t; + extern void conversation_init(void); -extern guint32 add_to_conversation(address *src, address *dst, port_type ptype, +conversation_t *conversation_new(address *src, address *dst, port_type ptype, + guint16 src_port, guint16 dst_port, void *data); +conversation_t *find_conversation(address *src, address *dst, port_type ptype, guint16 src_port, guint16 dst_port); diff --git a/packet-afs.c b/packet-afs.c index 3d0301dc3f..f15b941878 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.2 1999/10/22 07:17:30 guy Exp $ + * $Id: packet-afs.c,v 1.3 1999/10/24 07:27:18 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@unicom.net> @@ -636,6 +636,7 @@ dissect_afs(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) value_string const *vals; int reply = 0; int doffset = 0; + conversation_t *conversation; struct afs_request_key request_key, *new_request_key; struct afs_request_val *request_val; void (*dissector)(const u_char *pd, int offset, @@ -656,8 +657,7 @@ dissect_afs(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) port = ((reply == 0) ? pi.destport : pi.srcport ); /* - * Find out what conversation this packet is part of, or add it to a - * new conversation if it's not already part of one. + * Find out what conversation this packet is part of. * XXX - this should really be done by the transport-layer protocol, * although for connectionless transports, we may not want to do that * unless we know some higher-level protocol will want it - or we @@ -669,8 +669,15 @@ dissect_afs(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) * packets from A:X to B:Y as being part of the same conversation as * packets from B:Y to A:X. */ - request_key.conversation = add_to_conversation(&pi.src, &pi.dst, - pi.ptype, pi.srcport, pi.destport); + conversation = find_conversation(&pi.src, &pi.dst, pi.ptype, + pi.srcport, pi.destport); + if (conversation == NULL) { + /* It's not part of any conversation - create a new one. */ + conversation = conversation_new(&pi.src, &pi.dst, pi.ptype, + pi.srcport, pi.destport, NULL); + } + + request_key.conversation = conversation->index; request_key.service = ntohs(rxh->serviceId); request_key.callnumber = ntohl(rxh->callNumber); diff --git a/packet-smb.c b/packet-smb.c index 1cf0188c58..bf8e31307d 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.31 1999/10/22 07:17:37 guy Exp $ + * $Id: packet-smb.c,v 1.32 1999/10/24 07:27:20 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@unicom.net> @@ -8208,13 +8208,12 @@ dissect_transact2_smb(const u_char *pd, int offset, frame_data *fd, proto_tree * guint16 DataCount; guint16 ByteCount; const char *TransactName; - guint32 conversation; + conversation_t *conversation; struct smb_request_key request_key, *new_request_key; struct smb_request_val *request_val; /* - * Find out what conversation this packet is part of, or add it to a - * new conversation if it's not already part of one. + * Find out what conversation this packet is part of. * XXX - this should really be done by the transport-layer protocol, * although for connectionless transports, we may not want to do that * unless we know some higher-level protocol will want it - or we @@ -8226,13 +8225,18 @@ dissect_transact2_smb(const u_char *pd, int offset, frame_data *fd, proto_tree * * packets from A:X to B:Y as being part of the same conversation as * packets from B:Y to A:X. */ - conversation = add_to_conversation(&pi.src, &pi.dst, pi.ptype, + conversation = find_conversation(&pi.src, &pi.dst, pi.ptype, pi.srcport, pi.destport); + if (conversation == NULL) { + /* It's not part of any conversation - create a new one. */ + conversation = conversation_new(&pi.src, &pi.dst, pi.ptype, + pi.srcport, pi.destport, NULL); + } /* * Check for and insert entry in request hash table if does not exist */ - request_key.conversation = conversation; + request_key.conversation = conversation->index; request_key.mid = si.mid; request_val = (struct smb_request_val *) g_hash_table_lookup(smb_request_hash, &request_key); @@ -8240,7 +8244,7 @@ dissect_transact2_smb(const u_char *pd, int offset, frame_data *fd, proto_tree * if (!request_val) { /* Create one */ new_request_key = g_mem_chunk_alloc(smb_request_keys); - new_request_key -> conversation = conversation; + new_request_key -> conversation = conversation->index; new_request_key -> mid = si.mid; request_val = g_mem_chunk_alloc(smb_request_vals); |