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