Qt: Add copy from another profile in UAT dialogs
[metze/wireshark/wip.git] / epan / conversation.c
index b473511ed440ba0267d968988ecd082d3a0ea03b..fc94e3d65beaa44b99a3c34abbf3de9d1e2b071c 100644 (file)
@@ -5,19 +5,7 @@
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include "config.h"
 int _debug_conversation_indent = 0;
 #endif
 
+struct endpoint {
+       address addr1;
+       address addr2;
+       endpoint_type etype;
+       guint32 port1;
+       guint32 port2;
+       guint options;
+};
+
 struct conversation_key {
        struct conversation_key *next;
        address addr1;
@@ -68,6 +65,12 @@ static wmem_map_t *conversation_hashtable_no_addr2_or_port2 = NULL;
 
 static guint32 new_index;
 
+/*
+ * Placeholder for address-less conversations.
+ */
+static address null_address_ = ADDRESS_INIT_NONE;
+
+
 /*
  * Creates a new conversation with known endpoints based on a conversation
  * created with the CONVERSATION_TEMPLATE option while keeping the
@@ -89,8 +92,8 @@ conversation_create_from_template(conversation_t *conversation, const address *a
         * Add a new conversation and keep the conversation template only if the
         * CONVERSATION_TEMPLATE bit is set for a connection oriented protocol.
         */
-       if(conversation->options & CONVERSATION_TEMPLATE &&
-               conversation->key_ptr->etype != ENDPOINT_UDP)
+       if (conversation->options & CONVERSATION_TEMPLATE &&
+           conversation->key_ptr->etype != ENDPOINT_UDP)
        {
                /*
                 * Set up a new options mask where the conversation template bit and the
@@ -102,8 +105,8 @@ conversation_create_from_template(conversation_t *conversation, const address *a
                /*
                 * Are both the NO_ADDR2 and NO_PORT2 wildcards set in the options mask?
                 */
-               if(conversation->options & NO_ADDR2 &&
-                       conversation->options & NO_PORT2)
+               if (conversation->options & NO_ADDR2 &&
+                   conversation->options & NO_PORT2)
                {
                        /*
                         * The conversation template was created without knowledge of both
@@ -116,7 +119,7 @@ conversation_create_from_template(conversation_t *conversation, const address *a
                                                 conversation->key_ptr->etype, conversation->key_ptr->port1,
                                                 port2, options);
                }
-               else if(conversation->options & NO_PORT2)
+               else if (conversation->options & NO_PORT2)
                {
                        /*
                         * The conversation template was created without knowledge of port 2
@@ -128,7 +131,7 @@ conversation_create_from_template(conversation_t *conversation, const address *a
                                                 conversation->key_ptr->etype, conversation->key_ptr->port1,
                                                 port2, options);
                }
-               else if(conversation->options & NO_ADDR2)
+               else if (conversation->options & NO_ADDR2)
                {
                        /*
                         * The conversation template was created without knowledge of address
@@ -505,7 +508,7 @@ conversation_insert_into_hashtable(wmem_map_t *hashtable, conversation_t *conv)
 
                chain_tail = chain_head->last;
 
-               if(conv->setup_frame >= chain_tail->setup_frame) {
+               if (conv->setup_frame >= chain_tail->setup_frame) {
                        /* This convo belongs at the end of the chain */
                        conv->next = NULL;
                        conv->last = NULL;
@@ -617,9 +620,93 @@ conversation_new(const guint32 setup_frame, const address *addr1, const address
        conversation_t *conversation=NULL;
        conversation_key_t new_key;
 
-       DPRINT(("creating conversation for frame #%d: %s:%d -> %s:%d (ptype=%d)",
-                   setup_frame, address_to_str(wmem_packet_scope(), addr1), port1,
-                   address_to_str(wmem_packet_scope(), addr2), port2, ptype));
+#ifdef DEBUG_CONVERSATION
+       if (addr1 == NULL) {
+               /*
+                * No address 1.
+                */
+               if (options & NO_ADDR2) {
+                       /*
+                        * Neither address 1 nor address 2.
+                        */
+                       if (options & NO_PORT2) {
+                               /*
+                                * Port 1 but not port 2.
+                                */
+                               DPRINT(("creating conversation for frame #%u: ID %u (etype=%d)",
+                                           setup_frame, port1, etype));
+                       } else {
+                               /*
+                                * Ports 1 and 2.
+                                */
+                               DPRINT(("creating conversation for frame #%u: %u -> %u (etype=%d)",
+                                           setup_frame, port1, port2, etype));
+                       }
+               } else {
+                       /*
+                        * Address 2 but not address 1.
+                        */
+                       if (options & NO_PORT2) {
+                               /*
+                                * Port 1 but not port 2.
+                                */
+                               DPRINT(("creating conversation for frame #%u: ID %u, address %s (etype=%d)",
+                                           setup_frame, port1,
+                                           address_to_str(wmem_packet_scope(), addr2), etype));
+                       } else {
+                               /*
+                                * Ports 1 and 2.
+                                */
+                               DPRINT(("creating conversation for frame #%u: %u -> %s:%u (etype=%d)",
+                                           setup_frame, port1,
+                                           address_to_str(wmem_packet_scope(), addr2), port2, etype));
+                       }
+               }
+       } else {
+               /*
+                * Address 1.
+                */
+               if (options & NO_ADDR2) {
+                       /*
+                        * Address 1 but no address 2.
+                        */
+                       if (options & NO_PORT2) {
+                               /*
+                                * Port 1 but not port 2.
+                                */
+                               DPRINT(("creating conversation for frame #%u: %s:%u (etype=%d)",
+                                           setup_frame, address_to_str(wmem_packet_scope(), addr1), port1,
+                                           etype));
+                       } else {
+                               /*
+                                * Ports 1 and 2.
+                                */
+                               DPRINT(("creating conversation for frame #%u: %s:%u -> %u (etype=%d)",
+                                           setup_frame, address_to_str(wmem_packet_scope(), addr1), port1,
+                                           port2, etype));
+                       }
+               } else {
+                       /*
+                        * Addresses 1 and 2.
+                        */
+                       if (options & NO_PORT2) {
+                               /*
+                                * Port 1 but not port 2.
+                                */
+                               DPRINT(("creating conversation for frame #%u: %s:%u -> %s (etype=%d)",
+                                           setup_frame, address_to_str(wmem_packet_scope(), addr1), port1,
+                                           address_to_str(wmem_packet_scope(), addr2), etype));
+                       } else {
+                               /*
+                                * Ports 1 and 2.
+                                */
+                               DPRINT(("creating conversation for frame #%u: %s:%u -> %s:%u (etype=%d)",
+                                           setup_frame, address_to_str(wmem_packet_scope(), addr1), port1,
+                                           address_to_str(wmem_packet_scope(), addr2), port2, etype));
+                       }
+               }
+       }
+#endif
 
        if (options & NO_ADDR2) {
                if (options & (NO_PORT2|NO_PORT2_FORCE)) {
@@ -636,8 +723,16 @@ conversation_new(const guint32 setup_frame, const address *addr1, const address
        }
 
        new_key = wmem_new(wmem_file_scope(), struct conversation_key);
-       copy_address_wmem(wmem_file_scope(), &new_key->addr1, addr1);
-       copy_address_wmem(wmem_file_scope(), &new_key->addr2, addr2);
+       if (addr1 != NULL) {
+               copy_address_wmem(wmem_file_scope(), &new_key->addr1, addr1);
+       } else {
+               clear_address(&new_key->addr1);
+       }
+       if (addr2 != NULL) {
+               copy_address_wmem(wmem_file_scope(), &new_key->addr2, addr2);
+       } else {
+               clear_address(&new_key->addr2);
+       }
        new_key->etype = etype;
        new_key->port1 = port1;
        new_key->port2 = port2;
@@ -664,6 +759,12 @@ conversation_new(const guint32 setup_frame, const address *addr1, const address
        return conversation;
 }
 
+conversation_t *conversation_new_by_id(const guint32 setup_frame, const endpoint_type etype, const guint32 id, const guint options)
+{
+       /* Force the lack of an address or port 2 */
+       return conversation_new(setup_frame, NULL, NULL, etype, id, 0, options | NO_ADDR2 | NO_PORT2);
+}
+
 /*
  * Set the port 2 value in a key.  Remove the original from table,
  * update the options and port values, insert the updated key.
@@ -671,8 +772,8 @@ conversation_new(const guint32 setup_frame, const address *addr1, const address
 void
 conversation_set_port2(conversation_t *conv, const guint32 port)
 {
-   DISSECTOR_ASSERT_HINT(!(conv->options & CONVERSATION_TEMPLATE),
-            "Use the conversation_create_from_template function when the CONVERSATION_TEMPLATE bit is set in the options mask");
+       DISSECTOR_ASSERT_HINT(!(conv->options & CONVERSATION_TEMPLATE),
+           "Use the conversation_create_from_template function when the CONVERSATION_TEMPLATE bit is set in the options mask");
 
        DPRINT(("called for port=%d", port));
 
@@ -752,8 +853,16 @@ conversation_lookup_hashtable(wmem_map_t *hashtable, const guint32 frame_num, co
         * We don't make a copy of the address data, we just copy the
         * pointer to it, as "key" disappears when we return.
         */
-       key.addr1 = *addr1;
-       key.addr2 = *addr2;
+       if (addr1 != NULL) {
+               key.addr1 = *addr1;
+       } else {
+               clear_address(&key.addr1);
+       }
+       if (addr2 != NULL) {
+               key.addr2 = *addr2;
+       } else {
+               clear_address(&key.addr2);
+       }
        key.etype = etype;
        key.port1 = port1;
        key.port2 = port2;
@@ -763,10 +872,10 @@ conversation_lookup_hashtable(wmem_map_t *hashtable, const guint32 frame_num, co
        if (chain_head && (chain_head->setup_frame <= frame_num)) {
                match = chain_head;
 
-               if((chain_head->last)&&(chain_head->last->setup_frame<=frame_num))
+               if ((chain_head->last)&&(chain_head->last->setup_frame<=frame_num))
                        return chain_head->last;
 
-               if((chain_head->latest_found)&&(chain_head->latest_found->setup_frame<=frame_num))
+               if ((chain_head->latest_found)&&(chain_head->latest_found->setup_frame<=frame_num))
                        match = chain_head->latest_found;
 
                for (convo = match; convo && convo->setup_frame <= frame_num; convo = convo->next) {
@@ -833,16 +942,20 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                 * Neither search address B nor search port B are wildcarded,
                 * start out with an exact match.
                 */
-               DPRINT(("trying exact match"));
+               DPRINT(("trying exact match: %s:%d -> %s:%d",
+                   address_to_str(wmem_packet_scope(), addr_a), port_a,
+                   address_to_str(wmem_packet_scope(), addr_b), port_b));
                conversation =
-                       conversation_lookup_hashtable(conversation_hashtable_exact,
+                   conversation_lookup_hashtable(conversation_hashtable_exact,
                        frame_num, addr_a, addr_b, etype,
                        port_a, port_b);
                /* Didn't work, try the other direction */
                if (conversation == NULL) {
-                       DPRINT(("trying opposite direction"));
+                       DPRINT(("trying exact match: %s:%d -> %s:%d",
+                           address_to_str(wmem_packet_scope(), addr_b), port_b,
+                           address_to_str(wmem_packet_scope(), addr_a), port_a));
                        conversation =
-                               conversation_lookup_hashtable(conversation_hashtable_exact,
+                           conversation_lookup_hashtable(conversation_hashtable_exact,
                                frame_num, addr_b, addr_a, etype,
                                port_b, port_a);
                }
@@ -850,8 +963,11 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                        /* In Fibre channel, OXID & RXID are never swapped as
                         * TCP/UDP ports are in TCP/IP.
                         */
+                       DPRINT(("trying exact match: %s:%d -> %s:%d",
+                           address_to_str(wmem_packet_scope(), addr_b), port_a,
+                           address_to_str(wmem_packet_scope(), addr_a), port_b));
                        conversation =
-                               conversation_lookup_hashtable(conversation_hashtable_exact,
+                           conversation_lookup_hashtable(conversation_hashtable_exact,
                                frame_num, addr_b, addr_a, etype,
                                port_a, port_b);
                }
@@ -874,16 +990,21 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                 * address and port.
                 * ("addr_b" doesn't take part in this lookup.)
                 */
-               DPRINT(("trying wildcarded dest address"));
+               DPRINT(("trying wildcarded match: %s:%d -> *:%d",
+                   address_to_str(wmem_packet_scope(), addr_a), port_a,
+                   port_b));
                conversation =
-                       conversation_lookup_hashtable(conversation_hashtable_no_addr2,
+                   conversation_lookup_hashtable(conversation_hashtable_no_addr2,
                        frame_num, addr_a, addr_b, etype, port_a, port_b);
                if ((conversation == NULL) && (addr_a->type == AT_FC)) {
                        /* In Fibre channel, OXID & RXID are never swapped as
                         * TCP/UDP ports are in TCP/IP.
                         */
+                       DPRINT(("trying wildcarded match: %s:%d -> *:%d",
+                           address_to_str(wmem_packet_scope(), addr_b), port_a,
+                           port_b));
                        conversation =
-                               conversation_lookup_hashtable(conversation_hashtable_no_addr2,
+                           conversation_lookup_hashtable(conversation_hashtable_no_addr2,
                                frame_num, addr_b, addr_a, etype,
                                port_a, port_b);
                }
@@ -902,7 +1023,7 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                        DPRINT(("wildcarded dest address match found"));
                        if (!(conversation->options & NO_ADDR_B) && etype != ENDPOINT_UDP)
                        {
-                               if(!(conversation->options & CONVERSATION_TEMPLATE))
+                               if (!(conversation->options & CONVERSATION_TEMPLATE))
                                {
                                        conversation_set_addr2(conversation, addr_b);
                                }
@@ -926,9 +1047,11 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                 * ("addr_a" doesn't take part in this lookup.)
                 */
                if (!(options & NO_ADDR_B)) {
-                       DPRINT(("trying dest addr:port as source addr:port with wildcarded dest addr"));
+                       DPRINT(("trying wildcarded match: %s:%d -> *:%d",
+                           address_to_str(wmem_packet_scope(), addr_b), port_b,
+                           port_a));
                        conversation =
-                               conversation_lookup_hashtable(conversation_hashtable_no_addr2,
+                           conversation_lookup_hashtable(conversation_hashtable_no_addr2,
                                frame_num, addr_b, addr_a, etype, port_b, port_a);
                        if (conversation != NULL) {
                                /*
@@ -941,14 +1064,14 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                                 */
                                DPRINT(("match found"));
                                if (etype != ENDPOINT_UDP) {
-                                       if(!(conversation->options & CONVERSATION_TEMPLATE))
+                                       if (!(conversation->options & CONVERSATION_TEMPLATE))
                                        {
                                                conversation_set_addr2(conversation, addr_a);
                                        }
                                        else
                                        {
                                                conversation =
-                                                       conversation_create_from_template(conversation, addr_a, 0);
+                                                   conversation_create_from_template(conversation, addr_a, 0);
                                        }
                                }
                                return conversation;
@@ -970,16 +1093,21 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                 * address and port.
                 * ("port_b" doesn't take part in this lookup.)
                 */
-               DPRINT(("trying wildcarded dest port"));
+               DPRINT(("trying wildcarded match: %s:%d -> %s:*",
+                   address_to_str(wmem_packet_scope(), addr_a), port_a,
+                   address_to_str(wmem_packet_scope(), addr_b)));
                conversation =
-                       conversation_lookup_hashtable(conversation_hashtable_no_port2,
+                   conversation_lookup_hashtable(conversation_hashtable_no_port2,
                        frame_num, addr_a, addr_b, etype, port_a, port_b);
                if ((conversation == NULL) && (addr_a->type == AT_FC)) {
                        /* In Fibre channel, OXID & RXID are never swapped as
                         * TCP/UDP ports are in TCP/IP
                         */
+                       DPRINT(("trying wildcarded match: %s:%d -> %s:*",
+                           address_to_str(wmem_packet_scope(), addr_b), port_a,
+                           address_to_str(wmem_packet_scope(), addr_a)));
                        conversation =
-                               conversation_lookup_hashtable(conversation_hashtable_no_port2,
+                           conversation_lookup_hashtable(conversation_hashtable_no_port2,
                                frame_num, addr_b, addr_a, etype, port_a, port_b);
                }
                if (conversation != NULL) {
@@ -997,14 +1125,14 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                        DPRINT(("match found"));
                        if (!(conversation->options & NO_PORT_B) && etype != ENDPOINT_UDP)
                        {
-                               if(!(conversation->options & CONVERSATION_TEMPLATE))
+                               if (!(conversation->options & CONVERSATION_TEMPLATE))
                                {
                                        conversation_set_port2(conversation, port_b);
                                }
                                else
                                {
                                        conversation =
-                                               conversation_create_from_template(conversation, 0, port_b);
+                                           conversation_create_from_template(conversation, 0, port_b);
                                }
                        }
                        return conversation;
@@ -1021,9 +1149,11 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                 * ("port_a" doesn't take part in this lookup.)
                 */
                if (!(options & NO_PORT_B)) {
-                       DPRINT(("trying dest addr:port as source addr:port and wildcarded dest port"));
+                       DPRINT(("trying wildcarded match: %s:%d -> %s:*",
+                           address_to_str(wmem_packet_scope(), addr_b), port_b,
+                           address_to_str(wmem_packet_scope(), addr_a)));
                        conversation =
-                               conversation_lookup_hashtable(conversation_hashtable_no_port2,
+                           conversation_lookup_hashtable(conversation_hashtable_no_port2,
                                frame_num, addr_b, addr_a, etype, port_b, port_a);
                        if (conversation != NULL) {
                                /*
@@ -1037,14 +1167,14 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                                DPRINT(("match found"));
                                if (etype != ENDPOINT_UDP)
                                {
-                                       if(!(conversation->options & CONVERSATION_TEMPLATE))
+                                       if (!(conversation->options & CONVERSATION_TEMPLATE))
                                        {
                                                conversation_set_port2(conversation, port_a);
                                        }
                                        else
                                        {
                                                conversation =
-                                                       conversation_create_from_template(conversation, 0, port_a);
+                                                   conversation_create_from_template(conversation, 0, port_a);
                                        }
                                }
                                return conversation;
@@ -1060,9 +1190,10 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
         * and port A as the first address and port.
         * (Neither "addr_b" nor "port_b" take part in this lookup.)
         */
-       DPRINT(("trying wildcarding dest addr:port"));
+       DPRINT(("trying wildcarded match: %s:%d -> *:*",
+           address_to_str(wmem_packet_scope(), addr_a), port_a));
        conversation =
-               conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
+           conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
                frame_num, addr_a, addr_b, etype, port_a, port_b);
        if (conversation != NULL) {
                /*
@@ -1081,7 +1212,7 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                DPRINT(("match found"));
                if (etype != ENDPOINT_UDP)
                {
-                       if(!(conversation->options & CONVERSATION_TEMPLATE))
+                       if (!(conversation->options & CONVERSATION_TEMPLATE))
                        {
                                if (!(conversation->options & NO_ADDR_B))
                                        conversation_set_addr2(conversation, addr_b);
@@ -1091,7 +1222,7 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                        else
                        {
                                conversation =
-                                       conversation_create_from_template(conversation, addr_b, port_b);
+                                   conversation_create_from_template(conversation, addr_b, port_b);
                        }
                }
                return conversation;
@@ -1113,15 +1244,19 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                 * first packet in the conversation).
                 * (Neither "addr_a" nor "port_a" take part in this lookup.)
                 */
-               DPRINT(("trying dest addr:port as source addr:port and wildcarding dest addr:port"));
-               if (addr_a->type == AT_FC)
+               if ((addr_a != NULL) && (addr_a->type == AT_FC)) {
+                       DPRINT(("trying wildcarded match: %s:%d -> *:*",
+                           address_to_str(wmem_packet_scope(), addr_b), port_a));
                        conversation =
-                               conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
+                           conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
                                frame_num, addr_b, addr_a, etype, port_a, port_b);
-               else
+               } else {
+                       DPRINT(("trying wildcarded match: %s:%d -> *:*",
+                           address_to_str(wmem_packet_scope(), addr_b), port_b));
                        conversation =
-                               conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
+                           conversation_lookup_hashtable(conversation_hashtable_no_addr2_or_port2,
                                frame_num, addr_b, addr_a, etype, port_b, port_a);
+               }
                if (conversation != NULL) {
                        /*
                         * If this is for a connection-oriented protocol, set the
@@ -1135,7 +1270,7 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
                        DPRINT(("match found"));
                        if (etype != ENDPOINT_UDP)
                        {
-                               if(!(conversation->options & CONVERSATION_TEMPLATE))
+                               if (!(conversation->options & CONVERSATION_TEMPLATE))
                                {
                                        conversation_set_addr2(conversation, addr_a);
                                        conversation_set_port2(conversation, port_a);
@@ -1156,6 +1291,12 @@ find_conversation(const guint32 frame_num, const address *addr_a, const address
        return NULL;
 }
 
+conversation_t *find_conversation_by_id(const guint32 frame, const endpoint_type etype, const guint32 id, const guint options)
+{
+       /* Force the lack of a address or port B */
+       return find_conversation(frame, &null_address_, &null_address_, etype, id, 0, options|NO_ADDR_B|NO_PORT_B);
+}
+
 void
 conversation_add_proto_data(conversation_t *conv, const int proto, void *proto_data)
 {
@@ -1202,6 +1343,23 @@ conversation_get_dissector(conversation_t *conversation, const guint32 frame_num
        return (dissector_handle_t)wmem_tree_lookup32_le(conversation->dissector_tree, frame_num);
 }
 
+static gboolean try_conversation_call_dissector_helper(conversation_t *conversation, gboolean* dissector_success,
+                                       tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
+{
+       int ret;
+       dissector_handle_t handle = (dissector_handle_t)wmem_tree_lookup32_le(
+                                       conversation->dissector_tree, pinfo->num);
+       if (handle == NULL)
+               return FALSE;
+
+       ret = call_dissector_only(handle, tvb, pinfo, tree, data);
+
+       /* Let the caller decide what to do with success or rejection */
+       (*dissector_success) = (ret != 0);
+
+       return TRUE;
+}
+
 /*
  * Given two address/port pairs for a packet, search for a matching
  * conversation and, if found and it has a conversation dissector,
@@ -1215,20 +1373,62 @@ conversation_get_dissector(conversation_t *conversation, const guint32 frame_num
 gboolean
 try_conversation_dissector(const address *addr_a, const address *addr_b, const endpoint_type etype,
     const guint32 port_a, const guint32 port_b, tvbuff_t *tvb, packet_info *pinfo,
-    proto_tree *tree, void* data)
+    proto_tree *tree, void* data, const guint options)
 {
        conversation_t *conversation;
+       gboolean dissector_success;
 
-       conversation = find_conversation(pinfo->num, addr_a, addr_b, etype, port_a,
-           port_b, 0);
+       /* Try each mode based on option flags */
+
+       conversation = find_conversation(pinfo->num, addr_a, addr_b, etype, port_a, port_b, 0);
+       if (conversation != NULL) {
+               if (try_conversation_call_dissector_helper(conversation, &dissector_success, tvb, pinfo, tree, data))
+                       return dissector_success;
+       }
+
+       if (options & NO_ADDR_B) {
+               conversation = find_conversation(pinfo->num, addr_a, addr_b, etype, port_a, port_b, NO_ADDR_B);
+               if (conversation != NULL) {
+                       if (try_conversation_call_dissector_helper(conversation, &dissector_success, tvb, pinfo, tree, data))
+                               return dissector_success;
+               }
+       }
+
+       if (options & NO_PORT_B) {
+               conversation = find_conversation(pinfo->num, addr_a, addr_b, etype, port_a, port_b, NO_PORT_B);
+               if (conversation != NULL) {
+                       if (try_conversation_call_dissector_helper(conversation, &dissector_success, tvb, pinfo, tree, data))
+                               return dissector_success;
+               }
+       }
+
+       if (options & (NO_ADDR_B|NO_PORT_B)) {
+               conversation = find_conversation(pinfo->num, addr_a, addr_b, etype, port_a, port_b, NO_ADDR_B|NO_PORT_B);
+               if (conversation != NULL) {
+                       if (try_conversation_call_dissector_helper(conversation, &dissector_success, tvb, pinfo, tree, data))
+                               return dissector_success;
+               }
+       }
+
+       return FALSE;
+}
+
+gboolean
+try_conversation_dissector_by_id(const endpoint_type etype, const guint32 id, tvbuff_t *tvb,
+    packet_info *pinfo, proto_tree *tree, void* data)
+{
+       conversation_t *conversation;
+
+       conversation = find_conversation_by_id(pinfo->num, etype, id, 0);
 
        if (conversation != NULL) {
                int ret;
+
                dissector_handle_t handle = (dissector_handle_t)wmem_tree_lookup32_le(conversation->dissector_tree, pinfo->num);
                if (handle == NULL)
                        return FALSE;
-               ret=call_dissector_only(handle, tvb, pinfo, tree, data);
-               if(!ret) {
+               ret = call_dissector_only(handle, tvb, pinfo, tree, data);
+               if (!ret) {
                        /* this packet was rejected by the dissector
                         * so return FALSE in case our caller wants
                         * to do some cleaning up.
@@ -1248,19 +1448,32 @@ find_conversation_pinfo(packet_info *pinfo, const guint options)
 {
        conversation_t *conv=NULL;
 
-       DPRINT(("called for frame #%d: %s:%d -> %s:%d (ptype=%d)",
+       DPRINT(("called for frame #%u: %s:%d -> %s:%d (ptype=%d)",
                pinfo->num, address_to_str(wmem_packet_scope(), &pinfo->src), pinfo->srcport,
                address_to_str(wmem_packet_scope(), &pinfo->dst), pinfo->destport, pinfo->ptype));
        DINDENT();
 
        /* Have we seen this conversation before? */
-       if((conv = find_conversation(pinfo->num, &pinfo->src, &pinfo->dst,
-                                    conversation_pt_to_endpoint_type(pinfo->ptype), pinfo->srcport,
-                                    pinfo->destport, options)) != NULL) {
-               DPRINT(("found previous conversation for frame #%d (last_frame=%d)",
-                               pinfo->num, conv->last_frame));
-               if (pinfo->num > conv->last_frame) {
-                       conv->last_frame = pinfo->num;
+       if (pinfo->use_endpoint) {
+               DISSECTOR_ASSERT(pinfo->conv_endpoint);
+               if ((conv = find_conversation(pinfo->num, &pinfo->conv_endpoint->addr1, &pinfo->conv_endpoint->addr2,
+                                             pinfo->conv_endpoint->etype, pinfo->conv_endpoint->port1,
+                                             pinfo->conv_endpoint->port2, pinfo->conv_endpoint->options)) != NULL) {
+                       DPRINT(("found previous conversation for frame #%u (last_frame=%d)",
+                                       pinfo->num, conv->last_frame));
+                       if (pinfo->num > conv->last_frame) {
+                               conv->last_frame = pinfo->num;
+                       }
+               }
+       } else {
+               if ((conv = find_conversation(pinfo->num, &pinfo->src, &pinfo->dst,
+                                             conversation_pt_to_endpoint_type(pinfo->ptype), pinfo->srcport,
+                                             pinfo->destport, options)) != NULL) {
+                       DPRINT(("found previous conversation for frame #%u (last_frame=%d)",
+                                       pinfo->num, conv->last_frame));
+                       if (pinfo->num > conv->last_frame) {
+                               conv->last_frame = pinfo->num;
+                       }
                }
        }
 
@@ -1279,9 +1492,9 @@ find_or_create_conversation(packet_info *pinfo)
        conversation_t *conv=NULL;
 
        /* Have we seen this conversation before? */
-       if((conv = find_conversation_pinfo(pinfo, 0)) == NULL) {
+       if ((conv = find_conversation_pinfo(pinfo, 0)) == NULL) {
                /* No, this is a new conversation. */
-               DPRINT(("did not find previous conversation for frame #%d",
+               DPRINT(("did not find previous conversation for frame #%u",
                                pinfo->num));
                DINDENT();
                conv = conversation_new(pinfo->num, &pinfo->src,
@@ -1295,6 +1508,63 @@ find_or_create_conversation(packet_info *pinfo)
        return conv;
 }
 
+conversation_t *
+find_or_create_conversation_by_id(packet_info *pinfo, const endpoint_type etype, const guint32 id)
+{
+       conversation_t *conv=NULL;
+
+       /* Have we seen this conversation before? */
+       if ((conv = find_conversation_by_id(pinfo->num, etype, id, 0)) == NULL) {
+               /* No, this is a new conversation. */
+               DPRINT(("did not find previous conversation for frame #%u",
+                               pinfo->num));
+               DINDENT();
+               conv = conversation_new_by_id(pinfo->num, etype, id, 0);
+               DENDENT();
+       }
+
+       DENDENT();
+
+       return conv;
+}
+
+void conversation_create_endpoint(struct _packet_info *pinfo, address* addr1, address* addr2,
+    endpoint_type etype, guint32 port1, guint32        port2, const guint options)
+{
+       pinfo->conv_endpoint = wmem_new0(pinfo->pool, struct endpoint);
+       pinfo->use_endpoint = TRUE;
+
+       if (addr1 != NULL)
+               copy_address_wmem(pinfo->pool, &pinfo->conv_endpoint->addr1, addr1);
+
+       if (addr2 != NULL)
+               copy_address_wmem(pinfo->pool, &pinfo->conv_endpoint->addr2, addr2);
+
+       pinfo->conv_endpoint->etype = etype;
+       pinfo->conv_endpoint->port1 = port1;
+       pinfo->conv_endpoint->port2 = port2;
+       pinfo->conv_endpoint->options = options;
+}
+
+void conversation_create_endpoint_by_id(struct _packet_info *pinfo,
+    endpoint_type etype, guint32 id, const guint options)
+{
+       /* Force the lack of a address or port B */
+       conversation_create_endpoint(pinfo, &null_address_, &null_address_, etype, id, 0, options|NO_ADDR_B|NO_PORT_B);
+}
+
+guint32 conversation_get_endpoint_by_id(struct _packet_info *pinfo, endpoint_type etype, const guint options)
+{
+       if (pinfo->conv_endpoint == NULL)
+               return 0;
+
+       if ((pinfo->conv_endpoint->etype != etype) &&
+           ((options & USE_LAST_ENDPOINT) != USE_LAST_ENDPOINT))
+               return 0;
+
+       return pinfo->conv_endpoint->port1;
+}
+
 wmem_map_t *
 get_conversation_hashtable_exact(void)
 {
@@ -1360,14 +1630,10 @@ endpoint_type conversation_pt_to_endpoint_type(port_type pt)
                return ENDPOINT_DCCP;
        case PT_IPX:
                return ENDPOINT_IPX;
-       case PT_EXCHG:
-               return ENDPOINT_EXCHG;
        case PT_DDP:
                return ENDPOINT_DDP;
        case PT_IDP:
                return ENDPOINT_IDP;
-       case PT_TIPC:
-               return ENDPOINT_TIPC;
        case PT_USB:
                return ENDPOINT_USB;
        case PT_I2C:
@@ -1376,8 +1642,6 @@ endpoint_type conversation_pt_to_endpoint_type(port_type pt)
                return ENDPOINT_IBQP;
        case PT_BLUETOOTH:
                return ENDPOINT_BLUETOOTH;
-       case PT_TDMOP:
-               return ENDPOINT_TDMOP;
        }
 
        DISSECTOR_ASSERT(FALSE);
@@ -1392,7 +1656,7 @@ conversation_get_html_hash(const conversation_key_t key)
        addr1 = address_to_str(NULL, &key->addr1);
        addr2 = address_to_str(NULL, &key->addr2);
        hash = wmem_strdup_printf(NULL, "<tr><td>%s</td><td>%d</td><td>%s</td><td>%d</td></tr>\n",
-                                                       addr1, key->port1, addr2, key->port2);
+                                 addr1, key->port1, addr2, key->port2);
        wmem_free(NULL, addr1);
        wmem_free(NULL, addr2);