summaryrefslogtreecommitdiff
path: root/epan/conversation.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-10-21 05:52:28 +0000
committerGuy Harris <guy@alum.mit.edu>2000-10-21 05:52:28 +0000
commit563f86ee5eab280006171dbd7fdb411715594355 (patch)
tree616003167e713e2f88482dfdd46c1869d68eb308 /epan/conversation.c
parent183e9cbf25933dcd9abc8db485f5308459f192b2 (diff)
downloadwireshark-563f86ee5eab280006171dbd7fdb411715594355.tar.gz
Support for conversations with "wildcard" destination addresses, from
Jeff Foster. svn path=/trunk/; revision=2523
Diffstat (limited to 'epan/conversation.c')
-rw-r--r--epan/conversation.c147
1 files changed, 118 insertions, 29 deletions
diff --git a/epan/conversation.c b/epan/conversation.c
index 144f27b993..4ae117c9d2 100644
--- a/epan/conversation.c
+++ b/epan/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 2000/09/27 04:54:47 gram Exp $
+ * $Id: conversation.c,v 1.2 2000/10/21 05:52:28 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -46,6 +46,7 @@ static GHashTable *conversation_hashtable = NULL;
static GMemChunk *conversation_key_chunk = NULL;
static GMemChunk *conversation_chunk = NULL;
+#ifdef __NOT_USED__
typedef struct conversation_key {
struct conversation_key *next;
address src;
@@ -53,8 +54,9 @@ typedef struct conversation_key {
port_type ptype;
guint32 port_src;
guint32 port_dst;
+ guint options;
} conversation_key;
-
+#endif
/*
* Linked list of conversation keys, so we can, before freeing them all,
* free the address data allocations associated with them.
@@ -79,18 +81,21 @@ conversation_equal(gconstpointer v, gconstpointer w)
/*
* Are the first and second source ports the same, the first and
- * second destination ports the same, the first and second source
- * addresses the same, and the first and second destination
- * addresses the same?
+ * second destination ports the same or not used (NO_DST_PORT),
+ * the first and second source addresses the same, and the first
+ * and second destination addresses the same or not used (NO_DST_ADDR)?
*/
if (v1->port_src == v2->port_src &&
- v1->port_dst == v2->port_dst &&
+ (((v1->options & NO_DST_PORT) && (v2->options & NO_DST_PORT)) ||
+ v1->port_dst == v2->port_dst) &&
v1->src.type == v2->src.type &&
v1->src.len == v2->src.len &&
memcmp(v1->src.data, v2->src.data, v1->src.len) == 0 &&
- v1->dst.type == v2->dst.type &&
- v1->dst.len == v2->dst.len &&
- memcmp(v1->dst.data, v2->dst.data, v1->dst.len) == 0) {
+ (((v1->ptype & NO_DST_ADDR) && (v2->ptype & NO_DST_ADDR)) ||
+ (v1->dst.type == v2->dst.type &&
+ v1->dst.type == v2->dst.type &&
+ v1->dst.len == v2->dst.len &&
+ memcmp(v1->dst.data, v2->dst.data, v1->dst.len) == 0))) {
/*
* Yes. It's the same conversation, and the two
* address/port pairs are going in the same direction.
@@ -99,20 +104,23 @@ conversation_equal(gconstpointer v, gconstpointer w)
}
/*
- * Is the first source port the same as the second destination
- * port, the first destination port the same as the first
- * source port, the first source address the same as the second
- * destination address, and the first destination address the
- * same as the second source address?
+ * Is the first destination port the same as the second source
+ * port, the first source port the same as the second destination
+ * port or not used (NO_DEST_PORT), the first destination address
+ * the same as the second source address, and the first source
+ * address the same as the second destination address or not used
+ * (NO_DEST_ADDR).
*/
- if (v1->port_src == v2->port_dst &&
- v1->port_dst == v2->port_src &&
- v1->src.type == v2->dst.type &&
- v1->src.len == v2->dst.len &&
- memcmp(v1->src.data, v2->dst.data, v1->src.len) == 0 &&
+ if (v1->port_dst == v2->port_src &&
+ (((v1->options & NO_DST_PORT) &&(v2->options & NO_DST_PORT)) ||
+ v1->port_src == v2->port_dst) &&
v1->dst.type == v2->src.type &&
v1->dst.len == v2->src.len &&
- memcmp(v1->dst.data, v2->src.data, v1->dst.len) == 0) {
+ memcmp(v1->dst.data, v2->src.data, v1->dst.len) == 0 &&
+ (((v1->options & NO_DST_ADDR) && (v2->options & NO_DST_ADDR)) ||
+ (v1->src.type == v2->dst.type &&
+ v1->src.len == v2->dst.len &&
+ memcmp(v1->src.data, v2->dst.data, v1->src.len) == 0))) {
/*
* Yes. It's the same conversation, and the two
* address/port pairs are going in opposite directions.
@@ -133,6 +141,7 @@ conversation_equal(gconstpointer v, gconstpointer w)
static guint
conversation_hash(gconstpointer v)
{
+
conversation_key *key = (conversation_key *)v;
guint hash_val;
int i;
@@ -140,9 +149,16 @@ conversation_hash(gconstpointer v)
hash_val = 0;
for (i = 0; i < key->src.len; i++)
hash_val += key->src.data[i];
- for (i = 0; i < key->dst.len; i++)
- hash_val += key->dst.data[i];
- hash_val += key->port_src + key->port_dst;
+
+ hash_val += key->port_src;
+
+/* Only hash the destination information if the value is needed. */
+ if ( ! ( key->options & NO_DST_ADDR))
+ for (i = 0; i < key->dst.len; i++)
+ hash_val += key->dst.data[i];
+
+ if ( ! (key->options & NO_DST_PORT))
+ hash_val += key->port_dst;
return hash_val;
}
@@ -222,11 +238,13 @@ copy_address(address *to, address *from)
/*
* Given source and destination addresses and ports for a packet,
* create a new conversation to contain packets between those address/port
- * pairs.
+ * pairs. The options field is used to flag the destination address/port
+ * are not given and any value is acceptable.
+
*/
conversation_t *
conversation_new(address *src, address *dst, port_type ptype,
- guint32 src_port, guint32 dst_port, void *data)
+ guint32 src_port, guint32 dst_port, void *data, guint options)
{
conversation_t *conversation;
conversation_key *new_key;
@@ -239,6 +257,7 @@ conversation_new(address *src, address *dst, port_type ptype,
new_key->ptype = ptype;
new_key->port_src = src_port;
new_key->port_dst = dst_port;
+ new_key->options = options;
conversation = g_mem_chunk_alloc(conversation_chunk);
conversation->index = new_index;
@@ -247,20 +266,49 @@ conversation_new(address *src, address *dst, port_type ptype,
/* clear dissector pointer */
conversation->dissector.new_d = NULL;
+/* set the key pointer */
+ conversation->key_ptr = new_key;
+
new_index++;
g_hash_table_insert(conversation_hashtable, new_key, conversation);
return conversation;
}
+/* Set the destination port in a key. Remove the original from table,
+ update the options and port values, insert the updated key.
+*/
+void conversation_set_port( conversation_t *conv, guint32 port){
+
+ g_hash_table_remove(conversation_hashtable, conv->key_ptr);
+ conv->key_ptr->options &= ~NO_DST_PORT;
+ conv->key_ptr->port_dst = port;
+ g_hash_table_insert(conversation_hashtable, conv->key_ptr, conv);
+
+}
+
+/* Set the destination address in a key. Remove the original from
+ table, update the options and port values, insert the updated key.
+*/
+void conversation_set_addr( conversation_t *conv, address *addr){
+
+
+ g_hash_table_remove(conversation_hashtable, conv->key_ptr);
+ conv->key_ptr->options &= ~NO_DST_ADDR;
+ copy_address(&conv->key_ptr->dst, addr);
+ g_hash_table_insert(conversation_hashtable, conv->key_ptr, conv);
+}
+
/*
* 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.
+ * pairs. Returns NULL if not found. If the NO_DEST_ADDR and/or NO_DEST_PORT
+ * flags are set in the conversation options field, that value will not
+ * be used.
*/
conversation_t *
find_conversation(address *src, address *dst, port_type ptype,
- guint32 src_port, guint32 dst_port)
+ guint32 src_port, guint32 dst_port, uint options)
{
conversation_key key;
@@ -271,6 +319,7 @@ find_conversation(address *src, address *dst, port_type ptype,
key.src = *src;
key.dst = *dst;
key.ptype = ptype;
+ key.options = options;
key.port_src = src_port;
key.port_dst = dst_port;
return g_hash_table_lookup(conversation_hashtable, &key);
@@ -299,7 +348,14 @@ conversation_set_dissector(conversation_t *conversation,
* Given source and destination addresses and ports for a packet,
* search for a conversational dissector.
* If found, call it and return TRUE, otherwise return FALSE.
+ *
+ * Will search for a exact match (src & dst), then search for wild
+ * card matches: try to match any port on the destination address first,
+ * then try to match any address on the port, then try to match any
+ * address and any port.
+ *
*/
+
gboolean
old_try_conversation_dissector(address *src, address *dst, port_type ptype,
guint32 src_port, guint32 dst_port, const u_char *pd, int offset,
@@ -308,7 +364,18 @@ old_try_conversation_dissector(address *src, address *dst, port_type ptype,
conversation_t *conversation;
tvbuff_t *tvb;
- conversation = find_conversation(src, dst, ptype, src_port, dst_port);
+ conversation = find_conversation(src, dst, ptype, src_port, dst_port, 0);
+
+ if (conversation == NULL)
+ conversation = find_conversation(src, dst, ptype, src_port, dst_port, NO_DST_ADDR);
+
+ if (conversation == NULL)
+ conversation = find_conversation(src, dst, ptype, src_port, dst_port, NO_DST_PORT);
+
+ if (conversation == NULL)
+ conversation = find_conversation(src, dst, ptype, src_port, dst_port,
+ NO_DST_PORT | NO_DST_ADDR);
+
if (conversation != NULL) {
if (conversation->is_old_dissector) {
if (conversation->dissector.old_d == NULL)
@@ -335,6 +402,17 @@ old_try_conversation_dissector(address *src, address *dst, port_type ptype,
return FALSE;
}
+/*
+ * Given source and destination addresses and ports for a packet,
+ * search for a conversational dissector.
+ * If found, call it and return TRUE, otherwise return FALSE.
+ *
+ * Will search for a exact match (src & dst), then search for wild
+ * card matches: try to match any port on the destination address first,
+ * then try to match any address on the port, then try to match any
+ * address and any port.
+*/
+
gboolean
try_conversation_dissector(address *src, address *dst, port_type ptype,
guint32 src_port, guint32 dst_port, tvbuff_t *tvb, packet_info *pinfo,
@@ -344,7 +422,18 @@ try_conversation_dissector(address *src, address *dst, port_type ptype,
const guint8 *pd;
int offset;
- conversation = find_conversation(src, dst, ptype, src_port, dst_port);
+ conversation = find_conversation(src, dst, ptype, src_port, dst_port, 0);
+
+ if (conversation == NULL)
+ conversation = find_conversation(src, dst, ptype, src_port, dst_port, NO_DST_ADDR);
+
+ if (conversation == NULL)
+ conversation = find_conversation(src, dst, ptype, src_port, dst_port, NO_DST_PORT);
+
+ if (conversation == NULL)
+ conversation = find_conversation(src, dst, ptype, src_port, dst_port,
+ NO_DST_PORT | NO_DST_ADDR);
+
if (conversation != NULL) {
if (conversation->is_old_dissector) {
/*