2 * Routines for building lists of packets that are part of a "conversation"
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef __CONVERSATION_H__
24 #define __CONVERSATION_H__
26 #include "ws_symbol_export.h"
30 #endif /* __cplusplus */
36 * Flags to pass to "conversation_new()" to indicate that the address 2
37 * and/or port 2 values for the conversation should be wildcards.
38 * The CONVERSATION_TEMPLATE option tells that any of the other supplied
39 * port and / or address wildcards will be used to match an infinite number
40 * of new connections to the conversation(s) that have the CONVERSATION_-
41 * TEMPLATE flag set. Any conversation created without the CONVERSATION_-
42 * TEMPLATE flag will be altered once the first connections (connection
43 * oriented protocols only) to include the newly found information which
44 * matched the wildcard options.
48 #define NO_PORT2_FORCE 0x04
49 #define CONVERSATION_TEMPLATE 0x08
52 * Flags to pass to "find_conversation()" to indicate that the address B
53 * and/or port B search arguments are wildcards.
55 #define NO_ADDR_B 0x01
56 #define NO_PORT_B 0x02
58 #include "packet.h" /* for conversation dissector type */
61 * Data structure representing a conversation.
63 typedef struct conversation_key {
64 struct conversation_key *next;
72 typedef struct conversation {
73 struct conversation *next; /** pointer to next conversation on hash chain */
74 struct conversation *last; /** pointer to the last conversation on hash chain */
75 struct conversation *latest_found;
76 /** pointer to the last conversation on hash chain */
77 guint32 conv_index; /** unique ID for conversation */
78 guint32 setup_frame; /** frame number that setup this conversation */
79 /* Assume that setup_frame is also the lowest frame number for now. */
80 guint32 last_frame; /** highest frame number in this conversation */
81 wmem_tree_t *data_list; /** list of data associated with conversation */
82 wmem_tree_t *dissector_tree;
83 /** tree containing protocol dissector client associated with conversation */
84 guint options; /** wildcard flags */
85 conversation_key *key_ptr; /** pointer to the key for this conversation */
89 * Create a new hash tables for conversations.
91 extern void conversation_init(void);
94 * Initialize some variables every time a file is loaded or re-loaded.
96 extern void conversation_epan_reset(void);
99 * Given two address/port pairs for a packet, create a new conversation
100 * to contain packets between those address/port pairs.
102 * The options field is used to specify whether the address 2 value
103 * and/or port 2 value are not given and any value is acceptable
104 * when searching for this conversation.
106 WS_DLL_PUBLIC conversation_t *conversation_new(const guint32 setup_frame, const address *addr1, const address *addr2,
107 const port_type ptype, const guint32 port1, const guint32 port2, const guint options);
110 * Given two address/port pairs for a packet, search for a conversation
111 * containing packets between those address/port pairs. Returns NULL if
114 * We try to find the most exact match that we can, and then proceed to
115 * try wildcard matches on the "addr_b" and/or "port_b" argument if a more
116 * exact match failed.
118 * Either or both of the "addr_b" and "port_b" arguments may be specified as
119 * a wildcard by setting the NO_ADDR_B or NO_PORT_B flags in the "options"
120 * argument. We do only wildcard matches on addresses and ports specified
125 * if neither "addr_b" nor "port_b" were specified as wildcards, we
126 * do an exact match (addr_a/port_a and addr_b/port_b) and, if that
127 * succeeds, we return a pointer to the matched conversation;
129 * otherwise, if "port_b" wasn't specified as a wildcard, we try to
130 * match any address 2 with the specified port 2 (addr_a/port_a and
131 * {any}/addr_b) and, if that succeeds, we return a pointer to the
132 * matched conversation;
134 * otherwise, if "addr_b" wasn't specified as a wildcard, we try to
135 * match any port 2 with the specified address 2 (addr_a/port_a and
136 * addr_b/{any}) and, if that succeeds, we return a pointer to the
137 * matched conversation;
139 * otherwise, we try to match any address 2 and any port 2
140 * (addr_a/port_a and {any}/{any}) and, if that succeeds, we return
141 * a pointer to the matched conversation;
143 * otherwise, we found no matching conversation, and return NULL.
145 WS_DLL_PUBLIC conversation_t *find_conversation(const guint32 frame_num, const address *addr_a, const address *addr_b,
146 const port_type ptype, const guint32 port_a, const guint32 port_b, const guint options);
148 /** A helper function that calls find_conversation() using data from pinfo
149 * The frame number and addresses are taken from pinfo.
151 WS_DLL_PUBLIC conversation_t *find_conversation_pinfo(packet_info *pinfo, const guint options);
153 /** A helper function that calls find_conversation() and, if a conversation is
154 * not found, calls conversation_new().
155 * The frame number and addresses are taken from pinfo.
156 * No options are used, though we could extend this API to include an options
159 WS_DLL_PUBLIC conversation_t *find_or_create_conversation(packet_info *pinfo);
161 WS_DLL_PUBLIC void conversation_add_proto_data(conversation_t *conv, const int proto,
163 WS_DLL_PUBLIC void *conversation_get_proto_data(const conversation_t *conv, const int proto);
164 WS_DLL_PUBLIC void conversation_delete_proto_data(conversation_t *conv, const int proto);
166 WS_DLL_PUBLIC void conversation_set_dissector(conversation_t *conversation,
167 const dissector_handle_t handle);
169 WS_DLL_PUBLIC void conversation_set_dissector_from_frame_number(conversation_t *conversation,
170 const guint32 starting_frame_num, const dissector_handle_t handle);
172 WS_DLL_PUBLIC dissector_handle_t conversation_get_dissector(conversation_t *conversation,
173 const guint32 frame_num);
176 * Given two address/port pairs for a packet, search for a matching
177 * conversation and, if found and it has a conversation dissector,
178 * call that dissector and return TRUE, otherwise return FALSE.
180 * This helper uses call_dissector_only which will NOT call the default
181 * "data" dissector if the packet was rejected.
182 * Our caller is responsible to call the data dissector explicitly in case
183 * this function returns FALSE.
186 try_conversation_dissector(const address *addr_a, const address *addr_b, const port_type ptype,
187 const guint32 port_a, const guint32 port_b, tvbuff_t *tvb, packet_info *pinfo,
188 proto_tree *tree, void* data);
190 /* These routines are used to set undefined values for a conversation */
192 extern void conversation_set_port2(conversation_t *conv, const guint32 port);
193 extern void conversation_set_addr2(conversation_t *conv, const address *addr);
196 wmem_map_t *get_conversation_hashtable_exact(void);
199 wmem_map_t *get_conversation_hashtable_no_addr2(void);
202 wmem_map_t * get_conversation_hashtable_no_port2(void);
205 wmem_map_t *get_conversation_hashtable_no_addr2_or_port2(void);
210 #endif /* __cplusplus */
212 #endif /* conversation.h */