2 * Routines for building lists of packets that are part of a "conversation"
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include "conversation.h"
37 * Hash table for conversations with no wildcards.
39 static GHashTable *conversation_hashtable_exact = NULL;
42 * Hash table for conversations with one wildcard address.
44 static GHashTable *conversation_hashtable_no_addr2 = NULL;
47 * Hash table for conversations with one wildcard port.
49 static GHashTable *conversation_hashtable_no_port2 = NULL;
52 * Hash table for conversations with one wildcard address and port.
54 static GHashTable *conversation_hashtable_no_addr2_or_port2 = NULL;
56 static GMemChunk *conversation_key_chunk = NULL;
57 static GMemChunk *conversation_chunk = NULL;
60 typedef struct conversation_key {
61 struct conversation_key *next;
70 * Linked list of conversation keys, so we can, before freeing them all,
71 * free the address data allocations associated with them.
73 static conversation_key *conversation_keys;
75 static guint32 new_index;
77 static int conversation_init_count = 200;
80 * Protocol-specific data attached to a conversation_t structure - protocol
81 * index and opaque pointer.
83 typedef struct _conv_proto_data {
88 static GMemChunk *conv_proto_data_area = NULL;
91 * Creates a new conversation with known endpoints based on a conversation
92 * created with the CONVERSATION_TEMPLATE option while keeping the
93 * conversation created with the CONVERSATION_TEMPLATE option so it can still
94 * match future connections.
96 * Passing a pointer to a conversation whose options mask does not include
97 * CONVERSATION_TEMPLATE or where the conversation's protocol type (ptype)
98 * indicates a non-connnection oriented protocol will return the conversation
101 * addr2 and port2 are used in the function if their respective conversation
102 * options bits are set (NO_ADDR2 and NO_PORT2).
105 conversation_create_from_template(conversation_t *conversation, address *addr2, guint32 port2)
108 * Add a new conversation and keep the conversation template only if the
109 * CONVERSATION_TEMPLATE bit is set for a connection oriented protocol.
111 if(conversation->options & CONVERSATION_TEMPLATE &&
112 conversation->key_ptr->ptype != PT_UDP)
115 * Set up a new options mask where the conversation template bit and the
116 * bits for absence of a second address and port pair have been removed.
118 conversation_t *new_conversation_from_template;
119 guint options = conversation->options & ~(CONVERSATION_TEMPLATE | NO_ADDR2 | NO_PORT2);
122 * Are both the NO_ADDR2 and NO_PORT2 wildcards set in the options mask?
124 if(conversation->options & NO_ADDR2 &&
125 conversation->options & NO_PORT2)
128 * The conversation template was created without knowledge of both
129 * the second address as well as the second port. Create a new
130 * conversation with new 2nd address and 2nd port.
132 new_conversation_from_template =
133 conversation_new(conversation->setup_frame,
134 &conversation->key_ptr->addr1, addr2,
135 conversation->key_ptr->ptype, conversation->key_ptr->port1,
138 else if(conversation->options & NO_PORT2)
141 * The conversation template was created without knowledge of port 2
142 * only. Create a new conversation with new 2nd port.
144 new_conversation_from_template =
145 conversation_new(conversation->setup_frame,
146 &conversation->key_ptr->addr1, &conversation->key_ptr->addr2,
147 conversation->key_ptr->ptype, conversation->key_ptr->port1,
150 else if(conversation->options & NO_ADDR2)
153 * The conversation template was created without knowledge of address
154 * 2. Create a new conversation with new 2nd address.
156 new_conversation_from_template =
157 conversation_new(conversation->setup_frame,
158 &conversation->key_ptr->addr1, addr2,
159 conversation->key_ptr->ptype, conversation->key_ptr->port1,
160 conversation->key_ptr->port2, options);
165 * The CONVERSATION_TEMPLATE bit was set, but no other bit that the
166 * CONVERSATION_TEMPLATE bit controls is active. Just return the old
173 * Set the protocol dissector used for the template conversation as
174 * the handler of the new conversation as well.
176 new_conversation_from_template->dissector_handle = conversation->dissector_handle;
178 return new_conversation_from_template;
187 * Compute the hash value for two given address/port pairs if the match
191 conversation_hash_exact(gconstpointer v)
193 const conversation_key *key = (const conversation_key *)v;
198 for (i = 0; i < key->addr1.len; i++)
199 hash_val += key->addr1.data[i];
201 hash_val += key->port1;
203 for (i = 0; i < key->addr2.len; i++)
204 hash_val += key->addr2.data[i];
206 hash_val += key->port2;
212 * Compare two conversation keys for an exact match.
215 conversation_match_exact(gconstpointer v, gconstpointer w)
217 const conversation_key *v1 = (const conversation_key *)v;
218 const conversation_key *v2 = (const conversation_key *)w;
220 if (v1->ptype != v2->ptype)
221 return 0; /* different types of port */
224 * Are the first and second port 1 values the same, the first and
225 * second port 2 values the same, the first and second address
226 * 1 values the same, and the first and second address 2 values
229 if (v1->port1 == v2->port1 &&
230 v1->port2 == v2->port2 &&
231 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1) &&
232 ADDRESSES_EQUAL(&v1->addr2, &v2->addr2)) {
234 * Yes. It's the same conversation, and the two
235 * address/port pairs are going in the same direction.
241 * Is the first port 2 the same as the second port 1, the first
242 * port 1 the same as the second port 2, the first address 2
243 * the same as the second address 1, and the first address 1
244 * the same as the second address 2?
246 if (v1->port2 == v2->port1 &&
247 v1->port1 == v2->port2 &&
248 ADDRESSES_EQUAL(&v1->addr2, &v2->addr1) &&
249 ADDRESSES_EQUAL(&v1->addr1, &v2->addr2)) {
251 * Yes. It's the same conversation, and the two
252 * address/port pairs are going in opposite directions.
258 * The addresses or the ports don't match.
264 * Compute the hash value for two given address/port pairs if the match
265 * has a wildcard address 2.
268 conversation_hash_no_addr2(gconstpointer v)
270 const conversation_key *key = (const conversation_key *)v;
275 for (i = 0; i < key->addr1.len; i++)
276 hash_val += key->addr1.data[i];
278 hash_val += key->port1;
280 hash_val += key->port2;
286 * Compare two conversation keys, except for the address 2 value.
287 * We don't check both directions of the conversation - the routine
288 * doing the hash lookup has to do two searches, as the hash key
289 * will be different for the two directions.
292 conversation_match_no_addr2(gconstpointer v, gconstpointer w)
294 const conversation_key *v1 = (const conversation_key *)v;
295 const conversation_key *v2 = (const conversation_key *)w;
297 if (v1->ptype != v2->ptype)
298 return 0; /* different types of port */
301 * Are the first and second port 1 values the same, the first and
302 * second port 2 valuess the same, and the first and second
303 * address 1 values the same?
305 if (v1->port1 == v2->port1 &&
306 v1->port2 == v2->port2 &&
307 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1)) {
309 * Yes. It's the same conversation, and the two
310 * address/port pairs are going in the same direction.
316 * The addresses or the ports don't match.
322 * Compute the hash value for two given address/port pairs if the match
323 * has a wildcard port 2.
326 conversation_hash_no_port2(gconstpointer v)
328 const conversation_key *key = (const conversation_key *)v;
333 for (i = 0; i < key->addr1.len; i++)
334 hash_val += key->addr1.data[i];
336 hash_val += key->port1;
338 for (i = 0; i < key->addr2.len; i++)
339 hash_val += key->addr2.data[i];
345 * Compare two conversation keys, except for the port 2 value.
346 * We don't check both directions of the conversation - the routine
347 * doing the hash lookup has to do two searches, as the hash key
348 * will be different for the two directions.
351 conversation_match_no_port2(gconstpointer v, gconstpointer w)
353 const conversation_key *v1 = (const conversation_key *)v;
354 const conversation_key *v2 = (const conversation_key *)w;
356 if (v1->ptype != v2->ptype)
357 return 0; /* different types of port */
360 * Are the first and second port 1 values the same, the first and
361 * second address 1 values the same, and the first and second
362 * address 2 values the same?
364 if (v1->port1 == v2->port1 &&
365 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1) &&
366 ADDRESSES_EQUAL(&v1->addr2, &v2->addr2)) {
368 * Yes. It's the same conversation, and the two
369 * address/port pairs are going in the same direction.
375 * The addresses or the ports don't match.
381 * Compute the hash value for two given address/port pairs if the match
382 * has a wildcard address 2 and port 2.
385 conversation_hash_no_addr2_or_port2(gconstpointer v)
387 const conversation_key *key = (const conversation_key *)v;
392 for (i = 0; i < key->addr1.len; i++)
393 hash_val += key->addr1.data[i];
395 hash_val += key->port1;
401 * Compare the address 1 and port 1 in the two conversation keys.
402 * We don't check both directions of the conversation - the routine
403 * doing the hash lookup has to do two searches, as the hash key
404 * will be different for the two directions.
407 conversation_match_no_addr2_or_port2(gconstpointer v, gconstpointer w)
409 const conversation_key *v1 = (const conversation_key *)v;
410 const conversation_key *v2 = (const conversation_key *)w;
412 if (v1->ptype != v2->ptype)
413 return 0; /* different types of port */
416 * Are the first and second port 1 values the same and the first
417 * and second address 1 values the same?
419 if (v1->port1 == v2->port1 &&
420 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1)) {
422 * Yes. It's the same conversation, and the two
423 * address/port pairs are going in the same direction.
429 * The addresses or the ports don't match.
435 * Initialize some variables every time a file is loaded or re-loaded.
436 * Destroy all existing conversations, and create a new hash table
437 * for the conversations in the new file.
440 conversation_init(void)
442 conversation_key *key;
445 * Free the addresses associated with the conversation keys.
447 for (key = conversation_keys; key != NULL; key = key->next) {
449 * Grr. I guess the theory here is that freeing
450 * something sure as heck modifies it, so you
451 * want to ban attempts to free it, but, alas,
452 * if we make the "data" field of an "address"
453 * structure not a "const", the compiler whines if
454 * we try to make it point into the data for a packet,
455 * as that's a "const" array (and should be, as dissectors
456 * shouldn't trash it).
458 * So we cast the complaint into oblivion, and rely on
459 * the fact that these addresses are known to have had
460 * their data mallocated, i.e. they don't point into,
461 * say, the middle of the data for a packet.
463 g_free((gpointer)key->addr1.data);
464 g_free((gpointer)key->addr2.data);
466 conversation_keys = NULL;
467 if (conversation_hashtable_exact != NULL)
468 g_hash_table_destroy(conversation_hashtable_exact);
469 if (conversation_hashtable_no_addr2 != NULL)
470 g_hash_table_destroy(conversation_hashtable_no_addr2);
471 if (conversation_hashtable_no_port2 != NULL)
472 g_hash_table_destroy(conversation_hashtable_no_port2);
473 if (conversation_hashtable_no_addr2_or_port2 != NULL)
474 g_hash_table_destroy(conversation_hashtable_no_addr2_or_port2);
475 if (conversation_key_chunk != NULL)
476 g_mem_chunk_destroy(conversation_key_chunk);
477 if (conversation_chunk != NULL)
478 g_mem_chunk_destroy(conversation_chunk);
481 * Free up any space allocated for conversation protocol data
484 * We can free the space, as the structures it contains are
485 * pointed to by conversation data structures that were freed
488 if (conv_proto_data_area != NULL)
489 g_mem_chunk_destroy(conv_proto_data_area);
491 conversation_hashtable_exact =
492 g_hash_table_new(conversation_hash_exact,
493 conversation_match_exact);
494 conversation_hashtable_no_addr2 =
495 g_hash_table_new(conversation_hash_no_addr2,
496 conversation_match_no_addr2);
497 conversation_hashtable_no_port2 =
498 g_hash_table_new(conversation_hash_no_port2,
499 conversation_match_no_port2);
500 conversation_hashtable_no_addr2_or_port2 =
501 g_hash_table_new(conversation_hash_no_addr2_or_port2,
502 conversation_match_no_addr2_or_port2);
503 conversation_key_chunk = g_mem_chunk_new("conversation_key_chunk",
504 sizeof(conversation_key),
505 conversation_init_count * sizeof(struct conversation_key),
507 conversation_chunk = g_mem_chunk_new("conversation_chunk",
508 sizeof(conversation_t),
509 conversation_init_count * sizeof(conversation_t),
513 * Allocate a new area for conversation protocol data items.
515 conv_proto_data_area = g_mem_chunk_new("conv_proto_data_area",
516 sizeof(conv_proto_data), 20 * sizeof(conv_proto_data), /* FIXME*/
520 * Start the conversation indices over at 0.
526 * Given two address/port pairs for a packet, create a new conversation
527 * to contain packets between those address/port pairs.
529 * The options field is used to specify whether the address 2 value
530 * and/or port 2 value are not given and any value is acceptable
531 * when searching for this conversation.
534 conversation_new(guint32 setup_frame, address *addr1, address *addr2, port_type ptype,
535 guint32 port1, guint32 port2, guint options)
538 DISSECTOR_ASSERT(!(options | CONVERSATION_TEMPLATE) || ((options | (NO_ADDR2 | NO_PORT2 | NO_PORT2_FORCE))) &&
539 "A conversation template may not be constructed without wildcard options");
541 GHashTable* hashtable;
542 conversation_t *conversation;
544 conversation_key existing_key;
545 conversation_key *new_key;
547 if (options & NO_ADDR2) {
548 if (options & (NO_PORT2|NO_PORT2_FORCE)) {
549 hashtable = conversation_hashtable_no_addr2_or_port2;
551 hashtable = conversation_hashtable_no_addr2;
554 if (options & (NO_PORT2|NO_PORT2_FORCE)) {
555 hashtable = conversation_hashtable_no_port2;
557 hashtable = conversation_hashtable_exact;
561 existing_key.addr1 = *addr1;
562 existing_key.addr2 = *addr2;
563 existing_key.ptype = ptype;
564 existing_key.port1 = port1;
565 existing_key.port2 = port2;
567 conversation = g_hash_table_lookup(hashtable, &existing_key);
568 tc = conversation; /* Remember if lookup was successful */
570 new_key = g_mem_chunk_alloc(conversation_key_chunk);
571 new_key->next = conversation_keys;
572 conversation_keys = new_key;
573 COPY_ADDRESS(&new_key->addr1, addr1);
574 COPY_ADDRESS(&new_key->addr2, addr2);
575 new_key->ptype = ptype;
576 new_key->port1 = port1;
577 new_key->port2 = port2;
580 for (; conversation->next; conversation = conversation->next)
582 conversation->next = g_mem_chunk_alloc(conversation_chunk);
583 conversation = conversation->next;
585 conversation = g_mem_chunk_alloc(conversation_chunk);
588 conversation->next = NULL;
589 conversation->index = new_index;
590 conversation->setup_frame = setup_frame;
591 conversation->data_list = NULL;
593 /* clear dissector handle */
594 conversation->dissector_handle = NULL;
596 /* set the options and key pointer */
597 conversation->options = options;
598 conversation->key_ptr = new_key;
602 /* only insert a hash table entry if this
603 * is the first conversation with this key */
605 g_hash_table_insert(hashtable, new_key, conversation);
611 * Set the port 2 value in a key. Remove the original from table,
612 * update the options and port values, insert the updated key.
615 conversation_set_port2(conversation_t *conv, guint32 port)
617 DISSECTOR_ASSERT(!(conv->options & CONVERSATION_TEMPLATE) &&
618 "Use the conversation_create_from_template function when the CONVERSATION_TEMPLATE bit is set in the options mask");
621 * If the port 2 value is not wildcarded, don't set it.
623 if ((!(conv->options & NO_PORT2)) || (conv->options & NO_PORT2_FORCE))
626 if (conv->options & NO_ADDR2) {
627 g_hash_table_remove(conversation_hashtable_no_addr2_or_port2,
630 g_hash_table_remove(conversation_hashtable_no_port2,
633 conv->options &= ~NO_PORT2;
634 conv->key_ptr->port2 = port;
635 if (conv->options & NO_ADDR2) {
636 g_hash_table_insert(conversation_hashtable_no_addr2,
637 conv->key_ptr, conv);
639 g_hash_table_insert(conversation_hashtable_exact,
640 conv->key_ptr, conv);
645 * Set the address 2 value in a key. Remove the original from
646 * table, update the options and port values, insert the updated key.
649 conversation_set_addr2(conversation_t *conv, address *addr)
651 DISSECTOR_ASSERT(!(conv->options & CONVERSATION_TEMPLATE) &&
652 "Use the conversation_create_from_template function when the CONVERSATION_TEMPLATE bit is set in the options mask");
655 * If the address 2 value is not wildcarded, don't set it.
657 if (!(conv->options & NO_ADDR2))
660 if (conv->options & NO_PORT2) {
661 g_hash_table_remove(conversation_hashtable_no_addr2_or_port2,
664 g_hash_table_remove(conversation_hashtable_no_addr2,
667 conv->options &= ~NO_ADDR2;
668 COPY_ADDRESS(&conv->key_ptr->addr2, addr);
669 if (conv->options & NO_PORT2) {
670 g_hash_table_insert(conversation_hashtable_no_port2,
671 conv->key_ptr, conv);
673 g_hash_table_insert(conversation_hashtable_exact,
674 conv->key_ptr, conv);
679 * Search a particular hash table for a conversaton with the specified
680 * addr1, port1, addr2, and port2.
682 static conversation_t *
683 conversation_lookup_hashtable(GHashTable *hashtable, guint32 frame_num, address *addr1, address *addr2,
684 port_type ptype, guint32 port1, guint32 port2)
686 conversation_t* conversation;
687 conversation_t* match;
688 conversation_key key;
691 * We don't make a copy of the address data, we just copy the
692 * pointer to it, as "key" disappears when we return.
700 match = g_hash_table_lookup(hashtable, &key);
703 for (conversation = match->next; conversation; conversation = conversation->next) {
704 if ((conversation->setup_frame < frame_num)
705 && (conversation->setup_frame > match->setup_frame))
706 match = conversation;
715 * Given two address/port pairs for a packet, search for a conversation
716 * containing packets between those address/port pairs. Returns NULL if
719 * We try to find the most exact match that we can, and then proceed to
720 * try wildcard matches on the "addr_b" and/or "port_b" argument if a more
721 * exact match failed.
723 * Either or both of the "addr_b" and "port_b" arguments may be specified as
724 * a wildcard by setting the NO_ADDR_B or NO_PORT_B flags in the "options"
725 * argument. We do only wildcard matches on addresses and ports specified
730 * if neither "addr_b" nor "port_b" were specified as wildcards, we
731 * do an exact match (addr_a/port_a and addr_b/port_b) and, if that
732 * succeeds, we return a pointer to the matched conversation;
734 * otherwise, if "port_b" wasn't specified as a wildcard, we try to
735 * match any address 2 with the specified port 2 (addr_a/port_a and
736 * {any}/addr_b) and, if that succeeds, we return a pointer to the
737 * matched conversation;
739 * otherwise, if "addr_b" wasn't specified as a wildcard, we try to
740 * match any port 2 with the specified address 2 (addr_a/port_a and
741 * addr_b/{any}) and, if that succeeds, we return a pointer to the
742 * matched conversation;
744 * otherwise, we try to match any address 2 and any port 2
745 * (addr_a/port_a and {any}/{any}) and, if that succeeds, we return
746 * a pointer to the matched conversation;
748 * otherwise, we found no matching conversation, and return NULL.
751 find_conversation(guint32 frame_num, address *addr_a, address *addr_b, port_type ptype,
752 guint32 port_a, guint32 port_b, guint options)
754 conversation_t *conversation;
757 * First try an exact match, if we have two addresses and ports.
759 if (!(options & (NO_ADDR_B|NO_PORT_B))) {
761 * Neither search address B nor search port B are wildcarded,
762 * start out with an exact match.
763 * Exact matches check both directions.
766 conversation_lookup_hashtable(conversation_hashtable_exact,
767 frame_num, addr_a, addr_b, ptype,
769 if ((conversation == NULL) && (addr_a->type == AT_FC)) {
770 /* In Fibre channel, OXID & RXID are never swapped as
771 * TCP/UDP ports are in TCP/IP.
774 conversation_lookup_hashtable(conversation_hashtable_exact,
775 frame_num, addr_b, addr_a, ptype,
778 if (conversation != NULL)
783 * Well, that didn't find anything. Try matches that wildcard
784 * one of the addresses, if we have two ports.
786 if (!(options & NO_PORT_B)) {
788 * Search port B isn't wildcarded.
790 * First try looking for a conversation with the specified
791 * address A and port A as the first address and port, and
792 * with any address and the specified port B as the second
794 * ("addr_b" doesn't take part in this lookup.)
797 conversation_lookup_hashtable(conversation_hashtable_no_addr2,
798 frame_num, addr_a, addr_b, ptype, port_a, port_b);
799 if ((conversation == NULL) && (addr_a->type == AT_FC)) {
800 /* In Fibre channel, OXID & RXID are never swapped as
801 * TCP/UDP ports are in TCP/IP.
804 conversation_lookup_hashtable(conversation_hashtable_no_addr2,
805 frame_num, addr_b, addr_a, ptype,
808 if (conversation != NULL) {
810 * If search address B isn't wildcarded, and this is for a
811 * connection-oriented protocol, set the second address for this
812 * conversation to address B, as that's the address that matched the
813 * wildcarded second address for this conversation.
815 * (This assumes that, for all connection oriented protocols, the
816 * endpoints of a connection have only one address each, i.e. you
817 * don't get packets in a given direction coming from more than one
818 * address, unless the CONVERSATION_TEMPLATE option is set.)
820 if (!(options & NO_ADDR_B) && ptype != PT_UDP)
822 if(!(options & CONVERSATION_TEMPLATE))
824 conversation_set_addr2(conversation, addr_b);
829 conversation_create_from_template(conversation, addr_b, 0);
836 * Well, that didn't find anything.
837 * If search address B was specified, try looking for a
838 * conversation with the specified address B and port B as
839 * the first address and port, and with any address and the
840 * specified port A as the second address and port (this
841 * packet may be going in the opposite direction from the
842 * first packet in the conversation).
843 * ("addr_a" doesn't take part in this lookup.)
845 if (!(options & NO_ADDR_B)) {
847 conversation_lookup_hashtable(conversation_hashtable_no_addr2,
848 frame_num, addr_b, addr_a, ptype, port_b, port_a);
849 if (conversation != NULL) {
851 * If this is for a connection-oriented
852 * protocol, set the second address for
853 * this conversation to address A, as
854 * that's the address that matched the
855 * wildcarded second address for this
858 if (ptype != PT_UDP) {
859 if(!(options & CONVERSATION_TEMPLATE))
861 conversation_set_addr2(conversation, addr_a);
866 conversation_create_from_template(conversation, addr_a, 0);
875 * Well, that didn't find anything. Try matches that wildcard
876 * one of the ports, if we have two addresses.
878 if (!(options & NO_ADDR_B)) {
880 * Search address B isn't wildcarded.
882 * First try looking for a conversation with the specified
883 * address A and port A as the first address and port, and
884 * with the specified address B and any port as the second
886 * ("port_b" doesn't take part in this lookup.)
889 conversation_lookup_hashtable(conversation_hashtable_no_port2,
890 frame_num, addr_a, addr_b, ptype, port_a, port_b);
891 if ((conversation == NULL) && (addr_a->type == AT_FC)) {
892 /* In Fibre channel, OXID & RXID are never swapped as
893 * TCP/UDP ports are in TCP/IP
896 conversation_lookup_hashtable(conversation_hashtable_no_port2,
897 frame_num, addr_b, addr_a, ptype, port_a, port_b);
899 if (conversation != NULL) {
901 * If search port B isn't wildcarded, and this is for a connection-
902 * oriented protocol, set the second port for this conversation to
903 * port B, as that's the port that matched the wildcarded second port
904 * for this conversation.
906 * (This assumes that, for all connection oriented protocols, the
907 * endpoints of a connection have only one port each, i.e. you don't
908 * get packets in a given direction coming from more than one port,
909 * unless the CONVERSATION_TEMPLATE option is set.)
911 if (!(options & NO_PORT_B) && ptype != PT_UDP)
913 if(!(options & CONVERSATION_TEMPLATE))
915 conversation_set_port2(conversation, port_b);
920 conversation_create_from_template(conversation, 0, port_b);
927 * Well, that didn't find anything.
928 * If search port B was specified, try looking for a
929 * conversation with the specified address B and port B
930 * as the first address and port, and with the specified
931 * address A and any port as the second address and port
932 * (this packet may be going in the opposite direction
933 * from the first packet in the conversation).
934 * ("port_a" doesn't take part in this lookup.)
936 if (!(options & NO_PORT_B)) {
938 conversation_lookup_hashtable(conversation_hashtable_no_port2,
939 frame_num, addr_b, addr_a, ptype, port_b, port_a);
940 if (conversation != NULL) {
942 * If this is for a connection-oriented
943 * protocol, set the second port for
944 * this conversation to port A, as
945 * that's the address that matched the
946 * wildcarded second address for this
951 if(!(options & CONVERSATION_TEMPLATE))
953 conversation_set_port2(conversation, port_a);
958 conversation_create_from_template(conversation, 0, port_a);
967 * Well, that didn't find anything. Try matches that wildcard
968 * one address/port pair.
970 * First try looking for a conversation with the specified address A
971 * and port A as the first address and port.
972 * (Neither "addr_b" nor "port_b" take part in this lookup.)
975 conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
976 frame_num, addr_a, addr_b, ptype, port_a, port_b);
977 if (conversation != NULL) {
979 * If this is for a connection-oriented protocol:
981 * if search address B isn't wildcarded, set the
982 * second address for this conversation to address
983 * B, as that's the address that matched the
984 * wildcarded second address for this conversation;
986 * if search port B isn't wildcarded, set the
987 * second port for this conversation to port B,
988 * as that's the port that matched the wildcarded
989 * second port for this conversation.
993 if(!(options & CONVERSATION_TEMPLATE))
995 if (!(options & NO_ADDR_B))
996 conversation_set_addr2(conversation, addr_b);
997 if (!(options & NO_PORT_B))
998 conversation_set_port2(conversation, port_b);
1003 conversation_create_from_template(conversation, addr_b, port_b);
1006 return conversation;
1010 * Well, that didn't find anything.
1011 * If search address and port B were specified, try looking for a
1012 * conversation with the specified address B and port B as the
1013 * first address and port, and with any second address and port
1014 * (this packet may be going in the opposite direction from the
1015 * first packet in the conversation).
1016 * (Neither "addr_a" nor "port_a" take part in this lookup.)
1018 if (addr_a->type == AT_FC)
1020 conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
1021 frame_num, addr_b, addr_a, ptype, port_a, port_b);
1024 conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
1025 frame_num, addr_b, addr_a, ptype, port_b, port_a);
1026 if (conversation != NULL) {
1028 * If this is for a connection-oriented protocol, set the
1029 * second address for this conversation to address A, as
1030 * that's the address that matched the wildcarded second
1031 * address for this conversation, and set the second port
1032 * for this conversation to port A, as that's the port
1033 * that matched the wildcarded second port for this
1036 if (ptype != PT_UDP)
1038 if(!(conversation->options & CONVERSATION_TEMPLATE))
1040 conversation_set_addr2(conversation, addr_a);
1041 conversation_set_port2(conversation, port_a);
1045 conversation = conversation_create_from_template(conversation, addr_a, port_a);
1048 return conversation;
1052 * We found no conversation.
1058 p_compare(gconstpointer a, gconstpointer b)
1060 const conv_proto_data *ap = (const conv_proto_data *)a;
1061 const conv_proto_data *bp = (const conv_proto_data *)b;
1063 if (ap->proto > bp->proto)
1065 else if (ap->proto == bp->proto)
1072 conversation_add_proto_data(conversation_t *conv, int proto, void *proto_data)
1074 conv_proto_data *p1 = g_mem_chunk_alloc(conv_proto_data_area);
1077 p1->proto_data = proto_data;
1079 /* Add it to the list of items for this conversation. */
1081 conv->data_list = g_slist_insert_sorted(conv->data_list, (gpointer *)p1,
1086 conversation_get_proto_data(conversation_t *conv, int proto)
1088 conv_proto_data temp, *p1;
1092 temp.proto_data = NULL;
1094 item = g_slist_find_custom(conv->data_list, (gpointer *)&temp,
1098 p1 = (conv_proto_data *)item->data;
1099 return p1->proto_data;
1106 conversation_delete_proto_data(conversation_t *conv, int proto)
1108 conv_proto_data temp;
1112 temp.proto_data = NULL;
1114 item = g_slist_find_custom(conv->data_list, (gpointer *)&temp,
1118 conv->data_list = g_slist_remove(conv->data_list, item);
1122 conversation_set_dissector(conversation_t *conversation,
1123 dissector_handle_t handle)
1125 conversation->dissector_handle = handle;
1129 * Given two address/port pairs for a packet, search for a matching
1130 * conversation and, if found and it has a conversation dissector,
1131 * call that dissector and return TRUE, otherwise return FALSE.
1134 try_conversation_dissector(address *addr_a, address *addr_b, port_type ptype,
1135 guint32 port_a, guint32 port_b, tvbuff_t *tvb, packet_info *pinfo,
1138 conversation_t *conversation;
1140 conversation = find_conversation(pinfo->fd->num, addr_a, addr_b, ptype, port_a,
1143 if (conversation != NULL) {
1144 if (conversation->dissector_handle == NULL)
1146 call_dissector(conversation->dissector_handle, tvb, pinfo,