2 * Routines for building lists of packets that are part of a "conversation"
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
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.
35 #include "conversation.h"
38 * Hash table for conversations with no wildcards.
40 static GHashTable *conversation_hashtable_exact = NULL;
43 * Hash table for conversations with one wildcard address.
45 static GHashTable *conversation_hashtable_no_addr2 = NULL;
48 * Hash table for conversations with one wildcard port.
50 static GHashTable *conversation_hashtable_no_port2 = NULL;
53 * Hash table for conversations with one wildcard address and port.
55 static GHashTable *conversation_hashtable_no_addr2_or_port2 = NULL;
59 typedef struct conversation_key {
60 struct conversation_key *next;
69 * Linked list of conversation keys, so we can, before freeing them all,
70 * free the address data allocations associated with them.
72 static conversation_key *conversation_keys;
74 static guint32 new_index;
77 * Protocol-specific data attached to a conversation_t structure - protocol
78 * index and opaque pointer.
80 typedef struct _conv_proto_data {
86 * Creates a new conversation with known endpoints based on a conversation
87 * created with the CONVERSATION_TEMPLATE option while keeping the
88 * conversation created with the CONVERSATION_TEMPLATE option so it can still
89 * match future connections.
91 * Passing a pointer to a conversation whose options mask does not include
92 * CONVERSATION_TEMPLATE or where the conversation's protocol type (ptype)
93 * indicates a non-connnection oriented protocol will return the conversation
96 * addr2 and port2 are used in the function if their respective conversation
97 * options bits are set (NO_ADDR2 and NO_PORT2).
99 static conversation_t *
100 conversation_create_from_template(conversation_t *conversation, address *addr2, guint32 port2)
103 * Add a new conversation and keep the conversation template only if the
104 * CONVERSATION_TEMPLATE bit is set for a connection oriented protocol.
106 if(conversation->options & CONVERSATION_TEMPLATE &&
107 conversation->key_ptr->ptype != PT_UDP)
110 * Set up a new options mask where the conversation template bit and the
111 * bits for absence of a second address and port pair have been removed.
113 conversation_t *new_conversation_from_template;
114 guint options = conversation->options & ~(CONVERSATION_TEMPLATE | NO_ADDR2 | NO_PORT2);
117 * Are both the NO_ADDR2 and NO_PORT2 wildcards set in the options mask?
119 if(conversation->options & NO_ADDR2 &&
120 conversation->options & NO_PORT2)
123 * The conversation template was created without knowledge of both
124 * the second address as well as the second port. Create a new
125 * conversation with new 2nd address and 2nd port.
127 new_conversation_from_template =
128 conversation_new(conversation->setup_frame,
129 &conversation->key_ptr->addr1, addr2,
130 conversation->key_ptr->ptype, conversation->key_ptr->port1,
133 else if(conversation->options & NO_PORT2)
136 * The conversation template was created without knowledge of port 2
137 * only. Create a new conversation with new 2nd port.
139 new_conversation_from_template =
140 conversation_new(conversation->setup_frame,
141 &conversation->key_ptr->addr1, &conversation->key_ptr->addr2,
142 conversation->key_ptr->ptype, conversation->key_ptr->port1,
145 else if(conversation->options & NO_ADDR2)
148 * The conversation template was created without knowledge of address
149 * 2. Create a new conversation with new 2nd address.
151 new_conversation_from_template =
152 conversation_new(conversation->setup_frame,
153 &conversation->key_ptr->addr1, addr2,
154 conversation->key_ptr->ptype, conversation->key_ptr->port1,
155 conversation->key_ptr->port2, options);
160 * The CONVERSATION_TEMPLATE bit was set, but no other bit that the
161 * CONVERSATION_TEMPLATE bit controls is active. Just return the old
168 * Set the protocol dissector used for the template conversation as
169 * the handler of the new conversation as well.
171 new_conversation_from_template->dissector_handle = conversation->dissector_handle;
173 return new_conversation_from_template;
182 * Compute the hash value for two given address/port pairs if the match
186 conversation_hash_exact(gconstpointer v)
188 const conversation_key *key = (const conversation_key *)v;
193 for (i = 0; i < key->addr1.len; i++)
194 hash_val += key->addr1.data[i];
196 hash_val += key->port1;
198 for (i = 0; i < key->addr2.len; i++)
199 hash_val += key->addr2.data[i];
201 hash_val += key->port2;
207 * Compare two conversation keys for an exact match.
210 conversation_match_exact(gconstpointer v, gconstpointer w)
212 const conversation_key *v1 = (const conversation_key *)v;
213 const conversation_key *v2 = (const conversation_key *)w;
215 if (v1->ptype != v2->ptype)
216 return 0; /* different types of port */
219 * Are the first and second port 1 values the same, the first and
220 * second port 2 values the same, the first and second address
221 * 1 values the same, and the first and second address 2 values
224 if (v1->port1 == v2->port1 &&
225 v1->port2 == v2->port2 &&
226 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1) &&
227 ADDRESSES_EQUAL(&v1->addr2, &v2->addr2)) {
229 * Yes. It's the same conversation, and the two
230 * address/port pairs are going in the same direction.
236 * Is the first port 2 the same as the second port 1, the first
237 * port 1 the same as the second port 2, the first address 2
238 * the same as the second address 1, and the first address 1
239 * the same as the second address 2?
241 if (v1->port2 == v2->port1 &&
242 v1->port1 == v2->port2 &&
243 ADDRESSES_EQUAL(&v1->addr2, &v2->addr1) &&
244 ADDRESSES_EQUAL(&v1->addr1, &v2->addr2)) {
246 * Yes. It's the same conversation, and the two
247 * address/port pairs are going in opposite directions.
253 * The addresses or the ports don't match.
259 * Compute the hash value for two given address/port pairs if the match
260 * has a wildcard address 2.
263 conversation_hash_no_addr2(gconstpointer v)
265 const conversation_key *key = (const conversation_key *)v;
270 for (i = 0; i < key->addr1.len; i++)
271 hash_val += key->addr1.data[i];
273 hash_val += key->port1;
275 hash_val += key->port2;
281 * Compare two conversation keys, except for the address 2 value.
282 * We don't check both directions of the conversation - the routine
283 * doing the hash lookup has to do two searches, as the hash key
284 * will be different for the two directions.
287 conversation_match_no_addr2(gconstpointer v, gconstpointer w)
289 const conversation_key *v1 = (const conversation_key *)v;
290 const conversation_key *v2 = (const conversation_key *)w;
292 if (v1->ptype != v2->ptype)
293 return 0; /* different types of port */
296 * Are the first and second port 1 values the same, the first and
297 * second port 2 valuess the same, and the first and second
298 * address 1 values the same?
300 if (v1->port1 == v2->port1 &&
301 v1->port2 == v2->port2 &&
302 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1)) {
304 * Yes. It's the same conversation, and the two
305 * address/port pairs are going in the same direction.
311 * The addresses or the ports don't match.
317 * Compute the hash value for two given address/port pairs if the match
318 * has a wildcard port 2.
321 conversation_hash_no_port2(gconstpointer v)
323 const conversation_key *key = (const conversation_key *)v;
328 for (i = 0; i < key->addr1.len; i++)
329 hash_val += key->addr1.data[i];
331 hash_val += key->port1;
333 for (i = 0; i < key->addr2.len; i++)
334 hash_val += key->addr2.data[i];
340 * Compare two conversation keys, except for the port 2 value.
341 * We don't check both directions of the conversation - the routine
342 * doing the hash lookup has to do two searches, as the hash key
343 * will be different for the two directions.
346 conversation_match_no_port2(gconstpointer v, gconstpointer w)
348 const conversation_key *v1 = (const conversation_key *)v;
349 const conversation_key *v2 = (const conversation_key *)w;
351 if (v1->ptype != v2->ptype)
352 return 0; /* different types of port */
355 * Are the first and second port 1 values the same, the first and
356 * second address 1 values the same, and the first and second
357 * address 2 values the same?
359 if (v1->port1 == v2->port1 &&
360 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1) &&
361 ADDRESSES_EQUAL(&v1->addr2, &v2->addr2)) {
363 * Yes. It's the same conversation, and the two
364 * address/port pairs are going in the same direction.
370 * The addresses or the ports don't match.
376 * Compute the hash value for two given address/port pairs if the match
377 * has a wildcard address 2 and port 2.
380 conversation_hash_no_addr2_or_port2(gconstpointer v)
382 const conversation_key *key = (const conversation_key *)v;
387 for (i = 0; i < key->addr1.len; i++)
388 hash_val += key->addr1.data[i];
390 hash_val += key->port1;
396 * Compare the address 1 and port 1 in the two conversation keys.
397 * We don't check both directions of the conversation - the routine
398 * doing the hash lookup has to do two searches, as the hash key
399 * will be different for the two directions.
402 conversation_match_no_addr2_or_port2(gconstpointer v, gconstpointer w)
404 const conversation_key *v1 = (const conversation_key *)v;
405 const conversation_key *v2 = (const conversation_key *)w;
407 if (v1->ptype != v2->ptype)
408 return 0; /* different types of port */
411 * Are the first and second port 1 values the same and the first
412 * and second address 1 values the same?
414 if (v1->port1 == v2->port1 &&
415 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1)) {
417 * Yes. It's the same conversation, and the two
418 * address/port pairs are going in the same direction.
424 * The addresses or the ports don't match.
430 * Initialize some variables every time a file is loaded or re-loaded.
431 * Destroy all existing conversations, and create a new hash table
432 * for the conversations in the new file.
435 conversation_init(void)
437 conversation_key *key;
440 * Free the addresses associated with the conversation keys.
442 for (key = conversation_keys; key != NULL; key = key->next) {
444 * Grr. I guess the theory here is that freeing
445 * something sure as heck modifies it, so you
446 * want to ban attempts to free it, but, alas,
447 * if we make the "data" field of an "address"
448 * structure not a "const", the compiler whines if
449 * we try to make it point into the data for a packet,
450 * as that's a "const" array (and should be, as dissectors
451 * shouldn't trash it).
453 * So we cast the complaint into oblivion, and rely on
454 * the fact that these addresses are known to have had
455 * their data mallocated, i.e. they don't point into,
456 * say, the middle of the data for a packet.
458 g_free((gpointer)key->addr1.data);
459 g_free((gpointer)key->addr2.data);
461 conversation_keys = NULL;
462 if (conversation_hashtable_exact != NULL)
463 g_hash_table_destroy(conversation_hashtable_exact);
464 if (conversation_hashtable_no_addr2 != NULL)
465 g_hash_table_destroy(conversation_hashtable_no_addr2);
466 if (conversation_hashtable_no_port2 != NULL)
467 g_hash_table_destroy(conversation_hashtable_no_port2);
468 if (conversation_hashtable_no_addr2_or_port2 != NULL)
469 g_hash_table_destroy(conversation_hashtable_no_addr2_or_port2);
472 * Free up any space allocated for conversation protocol data
475 * We can free the space, as the structures it contains are
476 * pointed to by conversation data structures that were freed
479 conversation_hashtable_exact =
480 g_hash_table_new(conversation_hash_exact,
481 conversation_match_exact);
482 conversation_hashtable_no_addr2 =
483 g_hash_table_new(conversation_hash_no_addr2,
484 conversation_match_no_addr2);
485 conversation_hashtable_no_port2 =
486 g_hash_table_new(conversation_hash_no_port2,
487 conversation_match_no_port2);
488 conversation_hashtable_no_addr2_or_port2 =
489 g_hash_table_new(conversation_hash_no_addr2_or_port2,
490 conversation_match_no_addr2_or_port2);
493 * Start the conversation indices over at 0.
499 * Given two address/port pairs for a packet, create a new conversation
500 * to contain packets between those address/port pairs.
502 * The options field is used to specify whether the address 2 value
503 * and/or port 2 value are not given and any value is acceptable
504 * when searching for this conversation.
507 conversation_new(guint32 setup_frame, address *addr1, address *addr2, port_type ptype,
508 guint32 port1, guint32 port2, guint options)
511 DISSECTOR_ASSERT(!(options | CONVERSATION_TEMPLATE) || ((options | (NO_ADDR2 | NO_PORT2 | NO_PORT2_FORCE))) &&
512 "A conversation template may not be constructed without wildcard options");
514 GHashTable* hashtable;
515 conversation_t *conversation;
517 conversation_key existing_key;
518 conversation_key *new_key;
520 if (options & NO_ADDR2) {
521 if (options & (NO_PORT2|NO_PORT2_FORCE)) {
522 hashtable = conversation_hashtable_no_addr2_or_port2;
524 hashtable = conversation_hashtable_no_addr2;
527 if (options & (NO_PORT2|NO_PORT2_FORCE)) {
528 hashtable = conversation_hashtable_no_port2;
530 hashtable = conversation_hashtable_exact;
534 existing_key.addr1 = *addr1;
535 existing_key.addr2 = *addr2;
536 existing_key.ptype = ptype;
537 existing_key.port1 = port1;
538 existing_key.port2 = port2;
540 conversation = g_hash_table_lookup(hashtable, &existing_key);
541 tc = conversation; /* Remember if lookup was successful */
543 new_key = se_alloc(sizeof(struct conversation_key));
544 new_key->next = conversation_keys;
545 conversation_keys = new_key;
546 COPY_ADDRESS(&new_key->addr1, addr1);
547 COPY_ADDRESS(&new_key->addr2, addr2);
548 new_key->ptype = ptype;
549 new_key->port1 = port1;
550 new_key->port2 = port2;
553 for (; conversation->next; conversation = conversation->next)
555 conversation->next = se_alloc(sizeof(conversation_t));
556 conversation = conversation->next;
558 conversation = se_alloc(sizeof(conversation_t));
561 conversation->next = NULL;
562 conversation->index = new_index;
563 conversation->setup_frame = setup_frame;
564 conversation->data_list = NULL;
566 /* clear dissector handle */
567 conversation->dissector_handle = NULL;
569 /* set the options and key pointer */
570 conversation->options = options;
571 conversation->key_ptr = new_key;
575 /* only insert a hash table entry if this
576 * is the first conversation with this key */
578 g_hash_table_insert(hashtable, new_key, conversation);
584 * Set the port 2 value in a key. Remove the original from table,
585 * update the options and port values, insert the updated key.
588 conversation_set_port2(conversation_t *conv, guint32 port)
590 DISSECTOR_ASSERT(!(conv->options & CONVERSATION_TEMPLATE) &&
591 "Use the conversation_create_from_template function when the CONVERSATION_TEMPLATE bit is set in the options mask");
594 * If the port 2 value is not wildcarded, don't set it.
596 if ((!(conv->options & NO_PORT2)) || (conv->options & NO_PORT2_FORCE))
599 if (conv->options & NO_ADDR2) {
600 g_hash_table_remove(conversation_hashtable_no_addr2_or_port2,
603 g_hash_table_remove(conversation_hashtable_no_port2,
606 conv->options &= ~NO_PORT2;
607 conv->key_ptr->port2 = port;
608 if (conv->options & NO_ADDR2) {
609 g_hash_table_insert(conversation_hashtable_no_addr2,
610 conv->key_ptr, conv);
612 g_hash_table_insert(conversation_hashtable_exact,
613 conv->key_ptr, conv);
618 * Set the address 2 value in a key. Remove the original from
619 * table, update the options and port values, insert the updated key.
622 conversation_set_addr2(conversation_t *conv, address *addr)
624 DISSECTOR_ASSERT(!(conv->options & CONVERSATION_TEMPLATE) &&
625 "Use the conversation_create_from_template function when the CONVERSATION_TEMPLATE bit is set in the options mask");
628 * If the address 2 value is not wildcarded, don't set it.
630 if (!(conv->options & NO_ADDR2))
633 if (conv->options & NO_PORT2) {
634 g_hash_table_remove(conversation_hashtable_no_addr2_or_port2,
637 g_hash_table_remove(conversation_hashtable_no_addr2,
640 conv->options &= ~NO_ADDR2;
641 COPY_ADDRESS(&conv->key_ptr->addr2, addr);
642 if (conv->options & NO_PORT2) {
643 g_hash_table_insert(conversation_hashtable_no_port2,
644 conv->key_ptr, conv);
646 g_hash_table_insert(conversation_hashtable_exact,
647 conv->key_ptr, conv);
652 * Search a particular hash table for a conversaton with the specified
653 * addr1, port1, addr2, and port2.
655 static conversation_t *
656 conversation_lookup_hashtable(GHashTable *hashtable, guint32 frame_num, address *addr1, address *addr2,
657 port_type ptype, guint32 port1, guint32 port2)
659 conversation_t* conversation;
660 conversation_t* match;
661 conversation_key key;
664 * We don't make a copy of the address data, we just copy the
665 * pointer to it, as "key" disappears when we return.
673 match = g_hash_table_lookup(hashtable, &key);
676 for (conversation = match->next; conversation; conversation = conversation->next) {
677 if ((conversation->setup_frame < frame_num)
678 && (conversation->setup_frame > match->setup_frame))
679 match = conversation;
688 * Given two address/port pairs for a packet, search for a conversation
689 * containing packets between those address/port pairs. Returns NULL if
692 * We try to find the most exact match that we can, and then proceed to
693 * try wildcard matches on the "addr_b" and/or "port_b" argument if a more
694 * exact match failed.
696 * Either or both of the "addr_b" and "port_b" arguments may be specified as
697 * a wildcard by setting the NO_ADDR_B or NO_PORT_B flags in the "options"
698 * argument. We do only wildcard matches on addresses and ports specified
703 * if neither "addr_b" nor "port_b" were specified as wildcards, we
704 * do an exact match (addr_a/port_a and addr_b/port_b) and, if that
705 * succeeds, we return a pointer to the matched conversation;
707 * otherwise, if "port_b" wasn't specified as a wildcard, we try to
708 * match any address 2 with the specified port 2 (addr_a/port_a and
709 * {any}/addr_b) and, if that succeeds, we return a pointer to the
710 * matched conversation;
712 * otherwise, if "addr_b" wasn't specified as a wildcard, we try to
713 * match any port 2 with the specified address 2 (addr_a/port_a and
714 * addr_b/{any}) and, if that succeeds, we return a pointer to the
715 * matched conversation;
717 * otherwise, we try to match any address 2 and any port 2
718 * (addr_a/port_a and {any}/{any}) and, if that succeeds, we return
719 * a pointer to the matched conversation;
721 * otherwise, we found no matching conversation, and return NULL.
724 find_conversation(guint32 frame_num, address *addr_a, address *addr_b, port_type ptype,
725 guint32 port_a, guint32 port_b, guint options)
727 conversation_t *conversation;
730 * First try an exact match, if we have two addresses and ports.
732 if (!(options & (NO_ADDR_B|NO_PORT_B))) {
734 * Neither search address B nor search port B are wildcarded,
735 * start out with an exact match.
736 * Exact matches check both directions.
739 conversation_lookup_hashtable(conversation_hashtable_exact,
740 frame_num, addr_a, addr_b, ptype,
742 if ((conversation == NULL) && (addr_a->type == AT_FC)) {
743 /* In Fibre channel, OXID & RXID are never swapped as
744 * TCP/UDP ports are in TCP/IP.
747 conversation_lookup_hashtable(conversation_hashtable_exact,
748 frame_num, addr_b, addr_a, ptype,
751 if (conversation != NULL)
756 * Well, that didn't find anything. Try matches that wildcard
757 * one of the addresses, if we have two ports.
759 if (!(options & NO_PORT_B)) {
761 * Search port B isn't wildcarded.
763 * First try looking for a conversation with the specified
764 * address A and port A as the first address and port, and
765 * with any address and the specified port B as the second
767 * ("addr_b" doesn't take part in this lookup.)
770 conversation_lookup_hashtable(conversation_hashtable_no_addr2,
771 frame_num, addr_a, addr_b, ptype, port_a, port_b);
772 if ((conversation == NULL) && (addr_a->type == AT_FC)) {
773 /* In Fibre channel, OXID & RXID are never swapped as
774 * TCP/UDP ports are in TCP/IP.
777 conversation_lookup_hashtable(conversation_hashtable_no_addr2,
778 frame_num, addr_b, addr_a, ptype,
781 if (conversation != NULL) {
783 * If search address B isn't wildcarded, and this is for a
784 * connection-oriented protocol, set the second address for this
785 * conversation to address B, as that's the address that matched the
786 * wildcarded second address for this conversation.
788 * (This assumes that, for all connection oriented protocols, the
789 * endpoints of a connection have only one address each, i.e. you
790 * don't get packets in a given direction coming from more than one
791 * address, unless the CONVERSATION_TEMPLATE option is set.)
793 if (!(conversation->options & NO_ADDR_B) && ptype != PT_UDP)
795 if(!(conversation->options & CONVERSATION_TEMPLATE))
797 conversation_set_addr2(conversation, addr_b);
802 conversation_create_from_template(conversation, addr_b, 0);
809 * Well, that didn't find anything.
810 * If search address B was specified, try looking for a
811 * conversation with the specified address B and port B as
812 * the first address and port, and with any address and the
813 * specified port A as the second address and port (this
814 * packet may be going in the opposite direction from the
815 * first packet in the conversation).
816 * ("addr_a" doesn't take part in this lookup.)
818 if (!(options & NO_ADDR_B)) {
820 conversation_lookup_hashtable(conversation_hashtable_no_addr2,
821 frame_num, addr_b, addr_a, ptype, port_b, port_a);
822 if (conversation != NULL) {
824 * If this is for a connection-oriented
825 * protocol, set the second address for
826 * this conversation to address A, as
827 * that's the address that matched the
828 * wildcarded second address for this
831 if (ptype != PT_UDP) {
832 if(!(conversation->options & CONVERSATION_TEMPLATE))
834 conversation_set_addr2(conversation, addr_a);
839 conversation_create_from_template(conversation, addr_a, 0);
848 * Well, that didn't find anything. Try matches that wildcard
849 * one of the ports, if we have two addresses.
851 if (!(options & NO_ADDR_B)) {
853 * Search address B isn't wildcarded.
855 * First try looking for a conversation with the specified
856 * address A and port A as the first address and port, and
857 * with the specified address B and any port as the second
859 * ("port_b" doesn't take part in this lookup.)
862 conversation_lookup_hashtable(conversation_hashtable_no_port2,
863 frame_num, addr_a, addr_b, ptype, port_a, port_b);
864 if ((conversation == NULL) && (addr_a->type == AT_FC)) {
865 /* In Fibre channel, OXID & RXID are never swapped as
866 * TCP/UDP ports are in TCP/IP
869 conversation_lookup_hashtable(conversation_hashtable_no_port2,
870 frame_num, addr_b, addr_a, ptype, port_a, port_b);
872 if (conversation != NULL) {
874 * If search port B isn't wildcarded, and this is for a connection-
875 * oriented protocol, set the second port for this conversation to
876 * port B, as that's the port that matched the wildcarded second port
877 * for this conversation.
879 * (This assumes that, for all connection oriented protocols, the
880 * endpoints of a connection have only one port each, i.e. you don't
881 * get packets in a given direction coming from more than one port,
882 * unless the CONVERSATION_TEMPLATE option is set.)
884 if (!(conversation->options & NO_PORT_B) && ptype != PT_UDP)
886 if(!(conversation->options & CONVERSATION_TEMPLATE))
888 conversation_set_port2(conversation, port_b);
893 conversation_create_from_template(conversation, 0, port_b);
900 * Well, that didn't find anything.
901 * If search port B was specified, try looking for a
902 * conversation with the specified address B and port B
903 * as the first address and port, and with the specified
904 * address A and any port as the second address and port
905 * (this packet may be going in the opposite direction
906 * from the first packet in the conversation).
907 * ("port_a" doesn't take part in this lookup.)
909 if (!(options & NO_PORT_B)) {
911 conversation_lookup_hashtable(conversation_hashtable_no_port2,
912 frame_num, addr_b, addr_a, ptype, port_b, port_a);
913 if (conversation != NULL) {
915 * If this is for a connection-oriented
916 * protocol, set the second port for
917 * this conversation to port A, as
918 * that's the address that matched the
919 * wildcarded second address for this
924 if(!(conversation->options & CONVERSATION_TEMPLATE))
926 conversation_set_port2(conversation, port_a);
931 conversation_create_from_template(conversation, 0, port_a);
940 * Well, that didn't find anything. Try matches that wildcard
941 * one address/port pair.
943 * First try looking for a conversation with the specified address A
944 * and port A as the first address and port.
945 * (Neither "addr_b" nor "port_b" take part in this lookup.)
948 conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
949 frame_num, addr_a, addr_b, ptype, port_a, port_b);
950 if (conversation != NULL) {
952 * If this is for a connection-oriented protocol:
954 * if search address B isn't wildcarded, set the
955 * second address for this conversation to address
956 * B, as that's the address that matched the
957 * wildcarded second address for this conversation;
959 * if search port B isn't wildcarded, set the
960 * second port for this conversation to port B,
961 * as that's the port that matched the wildcarded
962 * second port for this conversation.
966 if(!(conversation->options & CONVERSATION_TEMPLATE))
968 if (!(conversation->options & NO_ADDR_B))
969 conversation_set_addr2(conversation, addr_b);
970 if (!(conversation->options & NO_PORT_B))
971 conversation_set_port2(conversation, port_b);
976 conversation_create_from_template(conversation, addr_b, port_b);
983 * Well, that didn't find anything.
984 * If search address and port B were specified, try looking for a
985 * conversation with the specified address B and port B as the
986 * first address and port, and with any second address and port
987 * (this packet may be going in the opposite direction from the
988 * first packet in the conversation).
989 * (Neither "addr_a" nor "port_a" take part in this lookup.)
991 if (addr_a->type == AT_FC)
993 conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
994 frame_num, addr_b, addr_a, ptype, port_a, port_b);
997 conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
998 frame_num, addr_b, addr_a, ptype, port_b, port_a);
999 if (conversation != NULL) {
1001 * If this is for a connection-oriented protocol, set the
1002 * second address for this conversation to address A, as
1003 * that's the address that matched the wildcarded second
1004 * address for this conversation, and set the second port
1005 * for this conversation to port A, as that's the port
1006 * that matched the wildcarded second port for this
1009 if (ptype != PT_UDP)
1011 if(!(conversation->options & CONVERSATION_TEMPLATE))
1013 conversation_set_addr2(conversation, addr_a);
1014 conversation_set_port2(conversation, port_a);
1018 conversation = conversation_create_from_template(conversation, addr_a, port_a);
1021 return conversation;
1025 * We found no conversation.
1031 p_compare(gconstpointer a, gconstpointer b)
1033 const conv_proto_data *ap = (const conv_proto_data *)a;
1034 const conv_proto_data *bp = (const conv_proto_data *)b;
1036 if (ap->proto > bp->proto)
1038 else if (ap->proto == bp->proto)
1045 conversation_add_proto_data(conversation_t *conv, int proto, void *proto_data)
1047 conv_proto_data *p1 = se_alloc(sizeof(conv_proto_data));
1050 p1->proto_data = proto_data;
1052 /* Add it to the list of items for this conversation. */
1054 conv->data_list = g_slist_insert_sorted(conv->data_list, (gpointer *)p1,
1059 conversation_get_proto_data(conversation_t *conv, int proto)
1061 conv_proto_data temp, *p1;
1065 temp.proto_data = NULL;
1067 item = g_slist_find_custom(conv->data_list, (gpointer *)&temp,
1071 p1 = (conv_proto_data *)item->data;
1072 return p1->proto_data;
1079 conversation_delete_proto_data(conversation_t *conv, int proto)
1081 conv_proto_data temp;
1085 temp.proto_data = NULL;
1087 item = g_slist_find_custom(conv->data_list, (gpointer *)&temp,
1091 conv->data_list = g_slist_remove(conv->data_list, item->data);
1097 conversation_set_dissector(conversation_t *conversation, dissector_handle_t handle)
1099 conversation->dissector_handle = handle;
1103 * Given two address/port pairs for a packet, search for a matching
1104 * conversation and, if found and it has a conversation dissector,
1105 * call that dissector and return TRUE, otherwise return FALSE.
1107 * This helper uses call_dissector_only which will NOT call the default
1108 * "data" dissector if the packet was rejected.
1109 * Our caller is responsible to call the data dissector explicitely in case
1110 * this function returns FALSE.
1113 try_conversation_dissector(address *addr_a, address *addr_b, port_type ptype,
1114 guint32 port_a, guint32 port_b, tvbuff_t *tvb, packet_info *pinfo,
1117 conversation_t *conversation;
1119 conversation = find_conversation(pinfo->fd->num, addr_a, addr_b, ptype, port_a,
1122 if (conversation != NULL) {
1124 if (conversation->dissector_handle == NULL)
1126 ret=call_dissector_only(conversation->dissector_handle, tvb, pinfo,
1129 /* this packet was rejected by the dissector
1130 * so return FALSE in case our caller wants
1131 * to do some cleaning up.