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, const address *addr2, const 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;
192 ADD_ADDRESS_TO_HASH(hash_val, &key->addr1);
193 hash_val += key->port1;
194 ADD_ADDRESS_TO_HASH(hash_val, &key->addr2);
195 hash_val += key->port2;
201 * Compare two conversation keys for an exact match.
204 conversation_match_exact(gconstpointer v, gconstpointer w)
206 const conversation_key *v1 = (const conversation_key *)v;
207 const conversation_key *v2 = (const conversation_key *)w;
209 if (v1->ptype != v2->ptype)
210 return 0; /* different types of port */
213 * Are the first and second port 1 values the same, the first and
214 * second port 2 values the same, the first and second address
215 * 1 values the same, and the first and second address 2 values
218 if (v1->port1 == v2->port1 &&
219 v1->port2 == v2->port2 &&
220 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1) &&
221 ADDRESSES_EQUAL(&v1->addr2, &v2->addr2)) {
223 * Yes. It's the same conversation, and the two
224 * address/port pairs are going in the same direction.
230 * Is the first port 2 the same as the second port 1, the first
231 * port 1 the same as the second port 2, the first address 2
232 * the same as the second address 1, and the first address 1
233 * the same as the second address 2?
235 if (v1->port2 == v2->port1 &&
236 v1->port1 == v2->port2 &&
237 ADDRESSES_EQUAL(&v1->addr2, &v2->addr1) &&
238 ADDRESSES_EQUAL(&v1->addr1, &v2->addr2)) {
240 * Yes. It's the same conversation, and the two
241 * address/port pairs are going in opposite directions.
247 * The addresses or the ports don't match.
253 * Compute the hash value for two given address/port pairs if the match
254 * has a wildcard address 2.
257 conversation_hash_no_addr2(gconstpointer v)
259 const conversation_key *key = (const conversation_key *)v;
263 ADD_ADDRESS_TO_HASH(hash_val, &key->addr1);
264 hash_val += key->port1;
265 hash_val += key->port2;
271 * Compare two conversation keys, except for the address 2 value.
272 * We don't check both directions of the conversation - the routine
273 * doing the hash lookup has to do two searches, as the hash key
274 * will be different for the two directions.
277 conversation_match_no_addr2(gconstpointer v, gconstpointer w)
279 const conversation_key *v1 = (const conversation_key *)v;
280 const conversation_key *v2 = (const conversation_key *)w;
282 if (v1->ptype != v2->ptype)
283 return 0; /* different types of port */
286 * Are the first and second port 1 values the same, the first and
287 * second port 2 valuess the same, and the first and second
288 * address 1 values the same?
290 if (v1->port1 == v2->port1 &&
291 v1->port2 == v2->port2 &&
292 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1)) {
294 * Yes. It's the same conversation, and the two
295 * address/port pairs are going in the same direction.
301 * The addresses or the ports don't match.
307 * Compute the hash value for two given address/port pairs if the match
308 * has a wildcard port 2.
311 conversation_hash_no_port2(gconstpointer v)
313 const conversation_key *key = (const conversation_key *)v;
317 ADD_ADDRESS_TO_HASH(hash_val, &key->addr1);
318 hash_val += key->port1;
319 ADD_ADDRESS_TO_HASH(hash_val, &key->addr2);
325 * Compare two conversation keys, except for the port 2 value.
326 * We don't check both directions of the conversation - the routine
327 * doing the hash lookup has to do two searches, as the hash key
328 * will be different for the two directions.
331 conversation_match_no_port2(gconstpointer v, gconstpointer w)
333 const conversation_key *v1 = (const conversation_key *)v;
334 const conversation_key *v2 = (const conversation_key *)w;
336 if (v1->ptype != v2->ptype)
337 return 0; /* different types of port */
340 * Are the first and second port 1 values the same, the first and
341 * second address 1 values the same, and the first and second
342 * address 2 values the same?
344 if (v1->port1 == v2->port1 &&
345 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1) &&
346 ADDRESSES_EQUAL(&v1->addr2, &v2->addr2)) {
348 * Yes. It's the same conversation, and the two
349 * address/port pairs are going in the same direction.
355 * The addresses or the ports don't match.
361 * Compute the hash value for two given address/port pairs if the match
362 * has a wildcard address 2 and port 2.
365 conversation_hash_no_addr2_or_port2(gconstpointer v)
367 const conversation_key *key = (const conversation_key *)v;
371 ADD_ADDRESS_TO_HASH(hash_val, &key->addr1);
372 hash_val += key->port1;
378 * Compare the address 1 and port 1 in the two conversation keys.
379 * We don't check both directions of the conversation - the routine
380 * doing the hash lookup has to do two searches, as the hash key
381 * will be different for the two directions.
384 conversation_match_no_addr2_or_port2(gconstpointer v, gconstpointer w)
386 const conversation_key *v1 = (const conversation_key *)v;
387 const conversation_key *v2 = (const conversation_key *)w;
389 if (v1->ptype != v2->ptype)
390 return 0; /* different types of port */
393 * Are the first and second port 1 values the same and the first
394 * and second address 1 values the same?
396 if (v1->port1 == v2->port1 &&
397 ADDRESSES_EQUAL(&v1->addr1, &v2->addr1)) {
399 * Yes. It's the same conversation, and the two
400 * address/port pairs are going in the same direction.
406 * The addresses or the ports don't match.
412 * Destroy all existing conversations
415 conversation_cleanup(void)
417 /* The conversation keys are se_ allocated so they are already gone */
418 conversation_keys = NULL;
419 if (conversation_hashtable_exact != NULL)
420 g_hash_table_destroy(conversation_hashtable_exact);
421 if (conversation_hashtable_no_addr2 != NULL)
422 g_hash_table_destroy(conversation_hashtable_no_addr2);
423 if (conversation_hashtable_no_port2 != NULL)
424 g_hash_table_destroy(conversation_hashtable_no_port2);
425 if (conversation_hashtable_no_addr2_or_port2 != NULL)
426 g_hash_table_destroy(conversation_hashtable_no_addr2_or_port2);
428 conversation_hashtable_exact = NULL;
429 conversation_hashtable_no_addr2 = NULL;
430 conversation_hashtable_no_port2 = NULL;
431 conversation_hashtable_no_addr2_or_port2 = NULL;
435 * Initialize some variables every time a file is loaded or re-loaded.
436 * Create a new hash table for the conversations in the new file.
439 conversation_init(void)
442 * Free up any space allocated for conversation protocol data
445 * We can free the space, as the structures it contains are
446 * pointed to by conversation data structures that were freed
449 conversation_hashtable_exact =
450 g_hash_table_new(conversation_hash_exact,
451 conversation_match_exact);
452 conversation_hashtable_no_addr2 =
453 g_hash_table_new(conversation_hash_no_addr2,
454 conversation_match_no_addr2);
455 conversation_hashtable_no_port2 =
456 g_hash_table_new(conversation_hash_no_port2,
457 conversation_match_no_port2);
458 conversation_hashtable_no_addr2_or_port2 =
459 g_hash_table_new(conversation_hash_no_addr2_or_port2,
460 conversation_match_no_addr2_or_port2);
463 * Start the conversation indices over at 0.
469 * Given two address/port pairs for a packet, create a new conversation
470 * to contain packets between those address/port pairs.
472 * The options field is used to specify whether the address 2 value
473 * and/or port 2 value are not given and any value is acceptable
474 * when searching for this conversation.
477 conversation_new(const guint32 setup_frame, const address *addr1, const address *addr2, const port_type ptype,
478 const guint32 port1, const guint32 port2, const guint options)
481 DISSECTOR_ASSERT(!(options | CONVERSATION_TEMPLATE) || ((options | (NO_ADDR2 | NO_PORT2 | NO_PORT2_FORCE))) &&
482 "A conversation template may not be constructed without wildcard options");
484 GHashTable* hashtable;
485 conversation_t *conversation;
487 conversation_key existing_key;
488 conversation_key *new_key;
490 if (options & NO_ADDR2) {
491 if (options & (NO_PORT2|NO_PORT2_FORCE)) {
492 hashtable = conversation_hashtable_no_addr2_or_port2;
494 hashtable = conversation_hashtable_no_addr2;
497 if (options & (NO_PORT2|NO_PORT2_FORCE)) {
498 hashtable = conversation_hashtable_no_port2;
500 hashtable = conversation_hashtable_exact;
504 existing_key.addr1 = *addr1;
505 existing_key.addr2 = *addr2;
506 existing_key.ptype = ptype;
507 existing_key.port1 = port1;
508 existing_key.port2 = port2;
510 conversation = g_hash_table_lookup(hashtable, &existing_key);
511 tc = conversation; /* Remember if lookup was successful */
513 new_key = se_alloc(sizeof(struct conversation_key));
514 new_key->next = conversation_keys;
515 conversation_keys = new_key;
516 SE_COPY_ADDRESS(&new_key->addr1, addr1);
517 SE_COPY_ADDRESS(&new_key->addr2, addr2);
518 new_key->ptype = ptype;
519 new_key->port1 = port1;
520 new_key->port2 = port2;
523 for (; conversation->next; conversation = conversation->next)
525 conversation->next = se_alloc(sizeof(conversation_t));
526 conversation = conversation->next;
528 conversation = se_alloc(sizeof(conversation_t));
531 conversation->next = NULL;
532 conversation->index = new_index;
533 conversation->setup_frame = setup_frame;
534 conversation->data_list = NULL;
536 /* clear dissector handle */
537 conversation->dissector_handle = NULL;
539 /* set the options and key pointer */
540 conversation->options = options;
541 conversation->key_ptr = new_key;
545 /* only insert a hash table entry if this
546 * is the first conversation with this key */
548 g_hash_table_insert(hashtable, new_key, conversation);
554 * Set the port 2 value in a key. Remove the original from table,
555 * update the options and port values, insert the updated key.
558 conversation_set_port2(conversation_t *conv, const guint32 port)
560 DISSECTOR_ASSERT(!(conv->options & CONVERSATION_TEMPLATE) &&
561 "Use the conversation_create_from_template function when the CONVERSATION_TEMPLATE bit is set in the options mask");
564 * If the port 2 value is not wildcarded, don't set it.
566 if ((!(conv->options & NO_PORT2)) || (conv->options & NO_PORT2_FORCE))
569 if (conv->options & NO_ADDR2) {
570 g_hash_table_remove(conversation_hashtable_no_addr2_or_port2,
573 g_hash_table_remove(conversation_hashtable_no_port2,
576 conv->options &= ~NO_PORT2;
577 conv->key_ptr->port2 = port;
578 if (conv->options & NO_ADDR2) {
579 g_hash_table_insert(conversation_hashtable_no_addr2,
580 conv->key_ptr, conv);
582 g_hash_table_insert(conversation_hashtable_exact,
583 conv->key_ptr, conv);
588 * Set the address 2 value in a key. Remove the original from
589 * table, update the options and port values, insert the updated key.
592 conversation_set_addr2(conversation_t *conv, const address *addr)
594 DISSECTOR_ASSERT(!(conv->options & CONVERSATION_TEMPLATE) &&
595 "Use the conversation_create_from_template function when the CONVERSATION_TEMPLATE bit is set in the options mask");
598 * If the address 2 value is not wildcarded, don't set it.
600 if (!(conv->options & NO_ADDR2))
603 if (conv->options & NO_PORT2) {
604 g_hash_table_remove(conversation_hashtable_no_addr2_or_port2,
607 g_hash_table_remove(conversation_hashtable_no_addr2,
610 conv->options &= ~NO_ADDR2;
611 SE_COPY_ADDRESS(&conv->key_ptr->addr2, addr);
612 if (conv->options & NO_PORT2) {
613 g_hash_table_insert(conversation_hashtable_no_port2,
614 conv->key_ptr, conv);
616 g_hash_table_insert(conversation_hashtable_exact,
617 conv->key_ptr, conv);
622 * Search a particular hash table for a conversation with the specified
623 * {addr1, port1, addr2, port2} and set up before frame_num.
625 static conversation_t *
626 conversation_lookup_hashtable(GHashTable *hashtable, const guint32 frame_num, const address *addr1, const address *addr2,
627 const port_type ptype, const guint32 port1, const guint32 port2)
629 conversation_t* conversation;
630 conversation_t* match;
631 conversation_key key;
634 * We don't make a copy of the address data, we just copy the
635 * pointer to it, as "key" disappears when we return.
643 match = g_hash_table_lookup(hashtable, &key);
646 for (conversation = match->next; conversation; conversation = conversation->next) {
647 if ((conversation->setup_frame <= frame_num)
648 && (conversation->setup_frame > match->setup_frame))
649 match = conversation;
651 if (match->setup_frame > frame_num)
660 * Given two address/port pairs for a packet, search for a conversation
661 * containing packets between those address/port pairs. Returns NULL if
664 * We try to find the most exact match that we can, and then proceed to
665 * try wildcard matches on the "addr_b" and/or "port_b" argument if a more
666 * exact match failed.
668 * Either or both of the "addr_b" and "port_b" arguments may be specified as
669 * a wildcard by setting the NO_ADDR_B or NO_PORT_B flags in the "options"
670 * argument. We do only wildcard matches on addresses and ports specified
675 * if neither "addr_b" nor "port_b" were specified as wildcards, we
676 * do an exact match (addr_a/port_a and addr_b/port_b) and, if that
677 * succeeds, we return a pointer to the matched conversation;
679 * otherwise, if "port_b" wasn't specified as a wildcard, we try to
680 * match any address 2 with the specified port 2 (addr_a/port_a and
681 * {any}/addr_b) and, if that succeeds, we return a pointer to the
682 * matched conversation;
684 * otherwise, if "addr_b" wasn't specified as a wildcard, we try to
685 * match any port 2 with the specified address 2 (addr_a/port_a and
686 * addr_b/{any}) and, if that succeeds, we return a pointer to the
687 * matched conversation;
689 * otherwise, we try to match any address 2 and any port 2
690 * (addr_a/port_a and {any}/{any}) and, if that succeeds, we return
691 * a pointer to the matched conversation;
693 * otherwise, we found no matching conversation, and return NULL.
696 find_conversation(const guint32 frame_num, const address *addr_a, const address *addr_b, const port_type ptype,
697 const guint32 port_a, const guint32 port_b, const guint options)
699 conversation_t *conversation;
702 * First try an exact match, if we have two addresses and ports.
704 if (!(options & (NO_ADDR_B|NO_PORT_B))) {
706 * Neither search address B nor search port B are wildcarded,
707 * start out with an exact match.
708 * Exact matches check both directions.
711 conversation_lookup_hashtable(conversation_hashtable_exact,
712 frame_num, addr_a, addr_b, ptype,
714 if ((conversation == NULL) && (addr_a->type == AT_FC)) {
715 /* In Fibre channel, OXID & RXID are never swapped as
716 * TCP/UDP ports are in TCP/IP.
719 conversation_lookup_hashtable(conversation_hashtable_exact,
720 frame_num, addr_b, addr_a, ptype,
723 if (conversation != NULL)
728 * Well, that didn't find anything. Try matches that wildcard
729 * one of the addresses, if we have two ports.
731 if (!(options & NO_PORT_B)) {
733 * Search port B isn't wildcarded.
735 * First try looking for a conversation with the specified
736 * address A and port A as the first address and port, and
737 * with any address and the specified port B as the second
739 * ("addr_b" doesn't take part in this lookup.)
742 conversation_lookup_hashtable(conversation_hashtable_no_addr2,
743 frame_num, addr_a, addr_b, ptype, port_a, port_b);
744 if ((conversation == NULL) && (addr_a->type == AT_FC)) {
745 /* In Fibre channel, OXID & RXID are never swapped as
746 * TCP/UDP ports are in TCP/IP.
749 conversation_lookup_hashtable(conversation_hashtable_no_addr2,
750 frame_num, addr_b, addr_a, ptype,
753 if (conversation != NULL) {
755 * If search address B isn't wildcarded, and this is for a
756 * connection-oriented protocol, set the second address for this
757 * conversation to address B, as that's the address that matched the
758 * wildcarded second address for this conversation.
760 * (This assumes that, for all connection oriented protocols, the
761 * endpoints of a connection have only one address each, i.e. you
762 * don't get packets in a given direction coming from more than one
763 * address, unless the CONVERSATION_TEMPLATE option is set.)
765 if (!(conversation->options & NO_ADDR_B) && ptype != PT_UDP)
767 if(!(conversation->options & CONVERSATION_TEMPLATE))
769 conversation_set_addr2(conversation, addr_b);
774 conversation_create_from_template(conversation, addr_b, 0);
781 * Well, that didn't find anything.
782 * If search address B was specified, try looking for a
783 * conversation with the specified address B and port B as
784 * the first address and port, and with any address and the
785 * specified port A as the second address and port (this
786 * packet may be going in the opposite direction from the
787 * first packet in the conversation).
788 * ("addr_a" doesn't take part in this lookup.)
790 if (!(options & NO_ADDR_B)) {
792 conversation_lookup_hashtable(conversation_hashtable_no_addr2,
793 frame_num, addr_b, addr_a, ptype, port_b, port_a);
794 if (conversation != NULL) {
796 * If this is for a connection-oriented
797 * protocol, set the second address for
798 * this conversation to address A, as
799 * that's the address that matched the
800 * wildcarded second address for this
803 if (ptype != PT_UDP) {
804 if(!(conversation->options & CONVERSATION_TEMPLATE))
806 conversation_set_addr2(conversation, addr_a);
811 conversation_create_from_template(conversation, addr_a, 0);
820 * Well, that didn't find anything. Try matches that wildcard
821 * one of the ports, if we have two addresses.
823 if (!(options & NO_ADDR_B)) {
825 * Search address B isn't wildcarded.
827 * First try looking for a conversation with the specified
828 * address A and port A as the first address and port, and
829 * with the specified address B and any port as the second
831 * ("port_b" doesn't take part in this lookup.)
834 conversation_lookup_hashtable(conversation_hashtable_no_port2,
835 frame_num, addr_a, addr_b, ptype, port_a, port_b);
836 if ((conversation == NULL) && (addr_a->type == AT_FC)) {
837 /* In Fibre channel, OXID & RXID are never swapped as
838 * TCP/UDP ports are in TCP/IP
841 conversation_lookup_hashtable(conversation_hashtable_no_port2,
842 frame_num, addr_b, addr_a, ptype, port_a, port_b);
844 if (conversation != NULL) {
846 * If search port B isn't wildcarded, and this is for a connection-
847 * oriented protocol, set the second port for this conversation to
848 * port B, as that's the port that matched the wildcarded second port
849 * for this conversation.
851 * (This assumes that, for all connection oriented protocols, the
852 * endpoints of a connection have only one port each, i.e. you don't
853 * get packets in a given direction coming from more than one port,
854 * unless the CONVERSATION_TEMPLATE option is set.)
856 if (!(conversation->options & NO_PORT_B) && ptype != PT_UDP)
858 if(!(conversation->options & CONVERSATION_TEMPLATE))
860 conversation_set_port2(conversation, port_b);
865 conversation_create_from_template(conversation, 0, port_b);
872 * Well, that didn't find anything.
873 * If search port B was specified, try looking for a
874 * conversation with the specified address B and port B
875 * as the first address and port, and with the specified
876 * address A and any port as the second address and port
877 * (this packet may be going in the opposite direction
878 * from the first packet in the conversation).
879 * ("port_a" doesn't take part in this lookup.)
881 if (!(options & NO_PORT_B)) {
883 conversation_lookup_hashtable(conversation_hashtable_no_port2,
884 frame_num, addr_b, addr_a, ptype, port_b, port_a);
885 if (conversation != NULL) {
887 * If this is for a connection-oriented
888 * protocol, set the second port for
889 * this conversation to port A, as
890 * that's the address that matched the
891 * wildcarded second address for this
896 if(!(conversation->options & CONVERSATION_TEMPLATE))
898 conversation_set_port2(conversation, port_a);
903 conversation_create_from_template(conversation, 0, port_a);
912 * Well, that didn't find anything. Try matches that wildcard
913 * one address/port pair.
915 * First try looking for a conversation with the specified address A
916 * and port A as the first address and port.
917 * (Neither "addr_b" nor "port_b" take part in this lookup.)
920 conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
921 frame_num, addr_a, addr_b, ptype, port_a, port_b);
922 if (conversation != NULL) {
924 * If this is for a connection-oriented protocol:
926 * if search address B isn't wildcarded, set the
927 * second address for this conversation to address
928 * B, as that's the address that matched the
929 * wildcarded second address for this conversation;
931 * if search port B isn't wildcarded, set the
932 * second port for this conversation to port B,
933 * as that's the port that matched the wildcarded
934 * second port for this conversation.
938 if(!(conversation->options & CONVERSATION_TEMPLATE))
940 if (!(conversation->options & NO_ADDR_B))
941 conversation_set_addr2(conversation, addr_b);
942 if (!(conversation->options & NO_PORT_B))
943 conversation_set_port2(conversation, port_b);
948 conversation_create_from_template(conversation, addr_b, port_b);
955 * Well, that didn't find anything.
956 * If search address and port B were specified, try looking for a
957 * conversation with the specified address B and port B as the
958 * first address and port, and with any second address and port
959 * (this packet may be going in the opposite direction from the
960 * first packet in the conversation).
961 * (Neither "addr_a" nor "port_a" take part in this lookup.)
963 if (addr_a->type == AT_FC)
965 conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
966 frame_num, addr_b, addr_a, ptype, port_a, port_b);
969 conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
970 frame_num, addr_b, addr_a, ptype, port_b, port_a);
971 if (conversation != NULL) {
973 * If this is for a connection-oriented protocol, set the
974 * second address for this conversation to address A, as
975 * that's the address that matched the wildcarded second
976 * address for this conversation, and set the second port
977 * for this conversation to port A, as that's the port
978 * that matched the wildcarded second port for this
983 if(!(conversation->options & CONVERSATION_TEMPLATE))
985 conversation_set_addr2(conversation, addr_a);
986 conversation_set_port2(conversation, port_a);
990 conversation = conversation_create_from_template(conversation, addr_a, port_a);
997 * We found no conversation.
1003 p_compare(gconstpointer a, gconstpointer b)
1005 const conv_proto_data *ap = (const conv_proto_data *)a;
1006 const conv_proto_data *bp = (const conv_proto_data *)b;
1008 if (ap->proto > bp->proto)
1010 else if (ap->proto == bp->proto)
1017 conversation_add_proto_data(conversation_t *conv, const int proto, void *proto_data)
1019 conv_proto_data *p1 = se_alloc(sizeof(conv_proto_data));
1022 p1->proto_data = proto_data;
1024 /* Add it to the list of items for this conversation. */
1026 conv->data_list = g_slist_insert_sorted(conv->data_list, (gpointer *)p1,
1031 conversation_get_proto_data(const conversation_t *conv, const int proto)
1033 conv_proto_data temp, *p1;
1037 temp.proto_data = NULL;
1039 item = g_slist_find_custom(conv->data_list, (gpointer *)&temp,
1043 p1 = (conv_proto_data *)item->data;
1044 return p1->proto_data;
1051 conversation_delete_proto_data(conversation_t *conv, const int proto)
1053 conv_proto_data temp;
1057 temp.proto_data = NULL;
1059 item = g_slist_find_custom(conv->data_list, (gpointer *)&temp,
1063 conv->data_list = g_slist_remove(conv->data_list, item->data);
1069 conversation_set_dissector(conversation_t *conversation, const dissector_handle_t handle)
1071 conversation->dissector_handle = handle;
1075 * Given two address/port pairs for a packet, search for a matching
1076 * conversation and, if found and it has a conversation dissector,
1077 * call that dissector and return TRUE, otherwise return FALSE.
1079 * This helper uses call_dissector_only which will NOT call the default
1080 * "data" dissector if the packet was rejected.
1081 * Our caller is responsible to call the data dissector explicitely in case
1082 * this function returns FALSE.
1085 try_conversation_dissector(const address *addr_a, const address *addr_b, const port_type ptype,
1086 const guint32 port_a, const guint32 port_b, tvbuff_t *tvb, packet_info *pinfo,
1089 conversation_t *conversation;
1091 conversation = find_conversation(pinfo->fd->num, addr_a, addr_b, ptype, port_a,
1094 if (conversation != NULL) {
1096 if (conversation->dissector_handle == NULL)
1098 ret=call_dissector_only(conversation->dissector_handle, tvb, pinfo,
1101 /* this packet was rejected by the dissector
1102 * so return FALSE in case our caller wants
1103 * to do some cleaning up.
1112 /* A helper function that calls find_conversation() and, if a conversation is
1113 * not found, calls conversation_new().
1114 * The frame number and addresses are taken from pinfo.
1115 * No options are used, though we could extend this API to include an options
1119 find_or_create_conversation(packet_info *pinfo)
1121 conversation_t *conv=NULL;
1123 /* Have we seen this conversation before? */
1124 if((conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
1125 pinfo->ptype, pinfo->srcport,
1126 pinfo->destport, 0)) == NULL) {
1127 /* No, this is a new conversation. */
1128 conv = conversation_new(pinfo->fd->num, &pinfo->src,
1129 &pinfo->dst, pinfo->ptype,
1130 pinfo->srcport, pinfo->destport, 0);