1 /* conversation_table.h
2 * GUI independent helper routines common to all conversations taps.
3 * Refactored original conversations_table by Ronnie Sahlberg
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #ifndef __CONVERSATION_TABLE_H__
13 #define __CONVERSATION_TABLE_H__
17 #include "conversation.h"
18 #include "wmem/wmem.h"
22 #endif /* __cplusplus */
25 * Conversation definitions.
37 /* Filter direction */
42 CONV_DIR_A_TO_FROM_ANY,
45 CONV_DIR_ANY_TO_FROM_B,
50 /** Conversation hash + value storage
51 * Hash table keys are conv_key_t. Hash table values are indexes into conv_array.
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) */
59 /** Key for hash lookups */
60 typedef struct _conversation_key_t {
73 struct _conversation_item_t;
74 typedef const char* (*conv_get_filter_type)(struct _conversation_item_t* item, conv_filter_type_e filter);
76 typedef struct _ct_dissector_info {
77 conv_get_filter_type get_filter_type;
78 } ct_dissector_info_t;
80 struct _hostlist_talker_t;
81 typedef const char* (*host_get_filter_type)(struct _hostlist_talker_t* item, conv_filter_type_e filter_type);
83 typedef struct _hostlist_dissector_info {
84 host_get_filter_type get_filter_type;
85 } hostlist_dissector_info_t;
87 #define CONV_FILTER_INVALID "INVALID"
91 typedef void (*conv_gui_init_cb)(struct register_ct* ct, const char *filter);
93 typedef void (*host_gui_init_cb)(struct register_ct* host, const char *filter);
95 /** Structure for information about a registered conversation */
96 typedef struct register_ct register_ct_t;
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 */
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 */
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 */
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 */
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 */
130 gboolean modified; /**< new to redraw the row */
134 #define HOSTLIST_TAP_PREFIX "endpoints"
136 /** Register the conversation table for the conversation and endpoint windows.
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
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);
145 /** Should port columns be hidden?
147 * @param ct Registered conversation
148 * @return TRUE if port columns should be hidden for this conversation type.
150 WS_DLL_PUBLIC gboolean get_conversation_hide_ports(register_ct_t* ct);
152 /** Get protocol ID from conversation
154 * @param ct Registered conversation
155 * @return protocol id of conversation
157 WS_DLL_PUBLIC int get_conversation_proto_id(register_ct_t* ct);
159 /** Get tap function handler from conversation
161 * @param ct Registered conversation
162 * @return tap function handler of conversation
164 WS_DLL_PUBLIC tap_packet_cb get_conversation_packet_func(register_ct_t* ct);
166 /** Get tap function handler from hostlist
168 * @param ct Registered conversation
169 * @return tap function handler of conversation
171 WS_DLL_PUBLIC tap_packet_cb get_hostlist_packet_func(register_ct_t* ct);
173 /** get conversation from protocol ID
175 * @param proto_id protocol ID
176 * @return tap function handler of conversation
178 WS_DLL_PUBLIC register_ct_t* get_conversation_by_proto_id(int proto_id);
180 /** Register "initialization function" used by the GUI to create conversation
181 * table display in GUI
183 * @param init_cb callback function that will be called when converation table "display
184 * is instantiated in GUI
186 WS_DLL_PUBLIC void conversation_table_set_gui_info(conv_gui_init_cb init_cb);
188 /** Register "initialization function" used by the GUI to create hostlist
189 * table display in GUI
191 * @param init_cb callback function that will be called when hostlist "display"
192 * is instantiated in GUI
194 WS_DLL_PUBLIC void hostlist_table_set_gui_info(host_gui_init_cb init_cb);
196 /** Iterator to walk converation tables and execute func
198 * @param func action to be performed on all converation tables
199 * @param user_data any data needed to help perform function
201 WS_DLL_PUBLIC void conversation_table_iterate_tables(wmem_foreach_func func, void* user_data);
203 /** Total number of converation tables
205 WS_DLL_PUBLIC guint conversation_table_get_num(void);
207 /** Remove all entries from the conversation table.
209 * @param ch the table to reset
211 WS_DLL_PUBLIC void reset_conversation_table_data(conv_hash_t *ch);
213 /** Remove all entries from the hostlist table.
215 * @param ch the table to reset
217 WS_DLL_PUBLIC void reset_hostlist_table_data(conv_hash_t *ch);
219 /** Initialize dissector conversation for stats and (possibly) GUI.
221 * @param opt_arg filter string to compare with dissector
222 * @param userdata register_ct_t* for dissector conversation
224 WS_DLL_PUBLIC void dissector_conversation_init(const char *opt_arg, void* userdata);
226 /** Initialize dissector hostlist for stats and (possibly) GUI.
228 * @param opt_arg filter string to compare with dissector
229 * @param userdata register_ct_t* for dissector conversation
231 WS_DLL_PUBLIC void dissector_hostlist_init(const char *opt_arg, void* userdata);
233 /** Get the string representation of an address.
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.
240 WS_DLL_PUBLIC char *get_conversation_address(wmem_allocator_t *allocator, address *addr, gboolean resolve_names);
242 /** Get the string representation of a port.
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.
250 WS_DLL_PUBLIC char *get_conversation_port(wmem_allocator_t *allocator, guint32 port, endpoint_type etype, gboolean resolve_names);
252 /** Get a display filter for the given conversation and direction.
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
258 WS_DLL_PUBLIC char *get_conversation_filter(conv_item_t *conv_item, conv_direction_e direction);
260 /** Get a display filter for the given hostlist.
262 * @param host The hostlist.
263 * @return A string, allocated using the wmem NULL allocator,
264 * representing the conversation.
266 WS_DLL_PUBLIC char *get_hostlist_filter(hostlist_talker_t *host);
268 /** Add some data to the conversation table.
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)
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);
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
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
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);
308 /** Add some data to the table.
310 * @param ch the table hash to add the data to
311 * @param addr address
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)
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);
324 #endif /* __cplusplus */
326 #endif /* __CONVERSATION_TABLE_H__ */
334 * indent-tabs-mode: nil
337 * ex: set shiftwidth=4 tabstop=8 expandtab:
338 * :indentSize=4:tabSize=8:noTabs=true: