NAS EPS: upgrade dissector to v13.5.0
[metze/wireshark/wip.git] / epan / conversation_table.h
1 /* conversation_table.h
2  * GUI independent helper routines common to all conversations taps.
3  * Refactored original conversations_table by Ronnie Sahlberg
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #ifndef __CONVERSATION_TABLE_H__
25 #define __CONVERSATION_TABLE_H__
26
27 #include "conv_id.h"
28 #include "tap.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 /** @file
35  *  Conversation definitions.
36  */
37
38 typedef enum {
39     CONV_FT_SRC_ADDRESS,
40     CONV_FT_DST_ADDRESS,
41     CONV_FT_ANY_ADDRESS,
42     CONV_FT_SRC_PORT,
43     CONV_FT_DST_PORT,
44     CONV_FT_ANY_PORT
45 } conv_filter_type_e;
46
47 /* Filter direction */
48 typedef enum {
49     CONV_DIR_A_TO_FROM_B,
50     CONV_DIR_A_TO_B,
51     CONV_DIR_A_FROM_B,
52     CONV_DIR_A_TO_FROM_ANY,
53     CONV_DIR_A_TO_ANY,
54     CONV_DIR_A_FROM_ANY,
55     CONV_DIR_ANY_TO_FROM_B,
56     CONV_DIR_ANY_TO_B,
57     CONV_DIR_ANY_FROM_B
58 } conv_direction_e;
59
60 /** Conversation hash + value storage
61  * Hash table keys are conv_key_t. Hash table values are indexes into conv_array.
62  */
63 typedef struct _conversation_hash_t {
64     GHashTable  *hashtable;       /**< conversations hash table */
65     GArray      *conv_array;      /**< array of conversation values */
66     void        *user_data;       /**< "GUI" specifics (if necessary) */
67 } conv_hash_t;
68
69 /** Key for hash lookups */
70 typedef struct _conversation_key_t {
71     address     addr1;
72     address     addr2;
73     guint32     port1;
74     guint32     port2;
75     conv_id_t   conv_id;
76 } conv_key_t;
77
78 typedef struct {
79     address  myaddress;
80     guint32  port;
81 } host_key_t;
82
83 struct _conversation_item_t;
84 typedef const char* (*conv_get_filter_type)(struct _conversation_item_t* item, conv_filter_type_e filter);
85
86 typedef struct _ct_dissector_info {
87     conv_get_filter_type get_filter_type;
88 } ct_dissector_info_t;
89
90 struct _hostlist_talker_t;
91 typedef const char* (*host_get_filter_type)(struct _hostlist_talker_t* item, conv_filter_type_e filter_type);
92
93 typedef struct _hostlist_dissector_info {
94     host_get_filter_type get_filter_type;
95 } hostlist_dissector_info_t;
96
97 #define CONV_FILTER_INVALID "INVALID"
98
99
100 struct register_ct;
101 typedef void (*conv_gui_init_cb)(struct register_ct* ct, const char *filter);
102
103 typedef void (*host_gui_init_cb)(struct register_ct* host, const char *filter);
104
105 /** Structure for information about a registered conversation */
106 typedef struct register_ct register_ct_t;
107
108 /** Conversation information */
109 typedef struct _conversation_item_t {
110     ct_dissector_info_t *dissector_info; /**< conversation information provided by dissector */
111     address             src_address;    /**< source address */
112     address             dst_address;    /**< destination address */
113     port_type           ptype;          /**< port_type (e.g. PT_TCP) */
114     guint32             src_port;       /**< source port */
115     guint32             dst_port;       /**< destination port */
116     conv_id_t           conv_id;        /**< conversation id */
117
118     guint64             rx_frames;      /**< number of received packets */
119     guint64             tx_frames;      /**< number of transmitted packets */
120     guint64             rx_bytes;       /**< number of received bytes */
121     guint64             tx_bytes;       /**< number of transmitted bytes */
122
123     nstime_t            start_time;     /**< relative start time for the conversation */
124     nstime_t            stop_time;      /**< relative stop time for the conversation */
125     nstime_t            start_abs_time; /**< absolute start time for the conversation */
126
127     gboolean            modified;       /**< new to redraw the row (only used in GTK+) */
128 } conv_item_t;
129
130 /** Hostlist information */
131 typedef struct _hostlist_talker_t {
132     hostlist_dissector_info_t *dissector_info; /**< conversation information provided by dissector */
133     address myaddress;      /**< address */
134     port_type  ptype;       /**< port_type (e.g. PT_TCP) */
135     guint32 port;           /**< port */
136
137     guint64 rx_frames;      /**< number of received packets */
138     guint64 tx_frames;      /**< number of transmitted packets */
139     guint64 rx_bytes;       /**< number of received bytes */
140     guint64 tx_bytes;       /**< number of transmitted bytes */
141
142     gboolean modified;      /**< new to redraw the row */
143
144 } hostlist_talker_t;
145
146 #define HOSTLIST_TAP_PREFIX     "endpoints"
147
148 /** Register the conversation table for the conversation and endpoint windows.
149  *
150  * @param proto_id is the protocol with conversation
151  * @param hide_ports hide the port columns
152  * @param conv_packet_func the registered conversation tap name
153  * @param hostlist_func the registered hostlist tap name
154  */
155 extern void register_conversation_table(const int proto_id, gboolean hide_ports, tap_packet_cb conv_packet_func, tap_packet_cb hostlist_func);
156
157 /** Should port columns be hidden?
158  *
159  * @param ct Registered conversation
160  * @return TRUE if port columns should be hidden for this conversation type.
161  */
162 WS_DLL_PUBLIC gboolean get_conversation_hide_ports(register_ct_t* ct);
163
164 /** Get protocol ID from conversation
165  *
166  * @param ct Registered conversation
167  * @return protocol id of conversation
168  */
169 WS_DLL_PUBLIC int get_conversation_proto_id(register_ct_t* ct);
170
171 /** Get tap function handler from conversation
172  *
173  * @param ct Registered conversation
174  * @return tap function handler of conversation
175  */
176 WS_DLL_PUBLIC tap_packet_cb get_conversation_packet_func(register_ct_t* ct);
177
178 /** Get tap function handler from hostlist
179  *
180  * @param ct Registered conversation
181  * @return tap function handler of conversation
182  */
183 WS_DLL_PUBLIC tap_packet_cb get_hostlist_packet_func(register_ct_t* ct);
184
185 /** get conversation from protocol ID
186  *
187  * @param proto_id protocol ID
188  * @return tap function handler of conversation
189  */
190 WS_DLL_PUBLIC register_ct_t* get_conversation_by_proto_id(int proto_id);
191
192 /** Register "initialization function" used by the GUI to create conversation
193  * table display in GUI
194  *
195  * @param init_cb callback function that will be called when converation table "display
196  * is instantiated in GUI
197  */
198 WS_DLL_PUBLIC void conversation_table_set_gui_info(conv_gui_init_cb init_cb);
199
200 /** Register "initialization function" used by the GUI to create hostlist
201  * table display in GUI
202  *
203  * @param init_cb callback function that will be called when hostlist "display"
204  * is instantiated in GUI
205  */
206 WS_DLL_PUBLIC void hostlist_table_set_gui_info(host_gui_init_cb init_cb);
207
208 /** Interator to walk converation tables and execute func
209  * a GUI menu (only used in GTK)
210  *
211  * @param func action to be performed on all converation tables
212  * @param user_data any data needed to help perform function
213  */
214 WS_DLL_PUBLIC void conversation_table_iterate_tables(GFunc func, gpointer user_data);
215
216 /** Total number of converation tables
217  */
218 WS_DLL_PUBLIC guint conversation_table_get_num(void);
219
220 /** Get conversation table by its number
221  * Tables are ordered alphabetically by title.
222  *
223  * @param table_num Item to fetch.
224  * @return table pointer or NULL.
225  */
226 WS_DLL_PUBLIC register_ct_t* get_conversation_table_by_num(guint table_num);
227
228 /** Remove all entries from the conversation table.
229  *
230  * @param ch the table to reset
231  */
232 WS_DLL_PUBLIC void reset_conversation_table_data(conv_hash_t *ch);
233
234 /** Remove all entries from the hostlist table.
235  *
236  * @param ch the table to reset
237  */
238 WS_DLL_PUBLIC void reset_hostlist_table_data(conv_hash_t *ch);
239
240 /** Initialize dissector conversation for stats and (possibly) GUI.
241  *
242  * @param opt_arg filter string to compare with dissector
243  * @param userdata register_ct_t* for dissector conversation
244  */
245 WS_DLL_PUBLIC void dissector_conversation_init(const char *opt_arg, void* userdata);
246
247 /** Initialize dissector hostlist for stats and (possibly) GUI.
248  *
249  * @param opt_arg filter string to compare with dissector
250  * @param userdata register_ct_t* for dissector conversation
251  */
252 WS_DLL_PUBLIC void dissector_hostlist_init(const char *opt_arg, void* userdata);
253
254 /** Get the string representation of an address.
255  *
256  * @param allocator The wmem allocator to use when allocating the string
257  * @param addr The address.
258  * @param resolve_names Enable name resolution.
259  * @return A string representing the address.
260  */
261 WS_DLL_PUBLIC char *get_conversation_address(wmem_allocator_t *allocator, address *addr, gboolean resolve_names);
262
263 /** Get the string representation of a port.
264  *
265  * @param allocator The wmem allocator to use when allocating the string
266  * @param port The port number.
267  * @param ptype The port type.
268  * @param resolve_names Enable name resolution.
269  * @return A string representing the port.
270  */
271 WS_DLL_PUBLIC char *get_conversation_port(wmem_allocator_t *allocator, guint32 port, port_type ptype, gboolean resolve_names);
272
273 /** Get a display filter for the given conversation and direction.
274  *
275  * @param conv_item The conversation.
276  * @param direction The desired direction.
277  * @return An g_allocated string representing the conversation that must be freed
278  */
279 WS_DLL_PUBLIC char *get_conversation_filter(conv_item_t *conv_item, conv_direction_e direction);
280
281 /** Get a display filter for the given hostlist.
282  *
283  * @param host The hostlist.
284  * @return A string, allocated using the wmem NULL allocator,
285  * representing the conversation.
286  */
287 WS_DLL_PUBLIC char *get_hostlist_filter(hostlist_talker_t *host);
288
289 /** Add some data to the conversation table.
290  *
291  * @param ch the table to add the data to
292  * @param src source address
293  * @param dst destination address
294  * @param src_port source port
295  * @param dst_port destination port
296  * @param num_frames number of packets
297  * @param num_bytes number of bytes
298  * @param ts timestamp
299  * @param abs_ts absolute timestamp
300  * @param ct_info callback handlers from the dissector
301  * @param ptype the port type (e.g. PT_TCP)
302  */
303 extern void add_conversation_table_data(conv_hash_t *ch, const address *src, const address *dst,
304             guint32 src_port, guint32 dst_port, int num_frames, int num_bytes, nstime_t *ts, nstime_t *abs_ts,
305             ct_dissector_info_t *ct_info, port_type ptype);
306
307 /** Add some data to the conversation table, passing a value to be used in
308  *  addition to the address and port quadruple to uniquely identify the
309  *  conversation.
310  *
311  * @param ch the table to add the data to
312  * @param src source address
313  * @param dst destination address
314  * @param src_port source port
315  * @param dst_port destination port
316  * @param num_frames number of packets
317  * @param num_bytes number of bytes
318  * @param ts timestamp
319  * @param abs_ts absolute timestamp
320  * @param ct_info callback handlers from the dissector
321  * @param ptype the port type (e.g. PT_TCP)
322  * @param conv_id a value to help differentiate the conversation in case the address and port quadruple is not sufficiently unique
323  */
324 extern void
325 add_conversation_table_data_with_conv_id(conv_hash_t *ch, const address *src, const address *dst, guint32 src_port,
326     guint32 dst_port, conv_id_t conv_id, int num_frames, int num_bytes,
327     nstime_t *ts, nstime_t *abs_ts, ct_dissector_info_t *ct_info, port_type ptype);
328
329 /** Add some data to the table.
330  *
331  * @param ch the table hash to add the data to
332  * @param addr address
333  * @param port port
334  * @param sender TRUE, if this is a sender
335  * @param num_frames number of packets
336  * @param num_bytes number of bytes
337  * @param host_info conversation information provided by dissector
338  * @param port_type_val the port type (e.g. PT_TCP)
339  */
340 void add_hostlist_table_data(conv_hash_t *ch, const address *addr,
341                              guint32 port, gboolean sender, int num_frames, int num_bytes, hostlist_dissector_info_t *host_info, port_type port_type_val);
342
343 #ifdef __cplusplus
344 }
345 #endif /* __cplusplus */
346
347 #endif /* __CONVERSATION_TABLE_H__ */
348
349 /*
350  * Editor modelines
351  *
352  * Local Variables:
353  * c-basic-offset: 4
354  * tab-width: 8
355  * indent-tabs-mode: nil
356  * End:
357  *
358  * ex: set shiftwidth=4 tabstop=8 expandtab:
359  * :indentSize=4:tabSize=8:noTabs=true:
360  */