1 /* sequence-analysis.h 2 * Flow sequence analysis 3 * 4 * Copied from gtk/graph_analysis.h 5 * 6 * Copyright 2004, Verso Technologies Inc. 7 * By Alejandro Vaquero <alejandrovaquero@yahoo.com> 8 * 9 * based on rtp_analysis.c and io_stat 10 * 11 * 12 * Wireshark - Network traffic analyzer 13 * By Gerald Combs <gerald@wireshark.org> 14 * Copyright 1998 Gerald Combs 15 * 16 * SPDX-License-Identifier: GPL-2.0-or-later 17 */ 18 19 #ifndef __EPAN_SEQUENCE_ANALYSIS_H__ 20 #define __EPAN_SEQUENCE_ANALYSIS_H__ 21 22 #include "ws_symbol_export.h" 23 24 #include <glib.h> 25 26 #include "packet_info.h" 27 #include "tap.h" 28 #include "address.h" 29 #include "wsutil/file_util.h" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif /* __cplusplus */ 34 35 #define MAX_NUM_NODES 40 36 37 /** defines an entry for the graph analysis */ 38 typedef struct _seq_analysis_item { 39 guint32 frame_number; 40 address src_addr; 41 guint16 port_src; 42 address dst_addr; 43 guint16 port_dst; 44 gchar *frame_label; /**< the label on top of the arrow */ 45 gchar *time_str; /**< timestamp */ 46 gchar *comment; /**< a comment that appears at the right of the graph */ 47 guint16 conv_num; /**< The conversation number. Used for coloring VoIP calls. */ 48 unsigned fg_color; /**< Foreground color, 0xRRGGBB. Qt only. */ 49 unsigned bg_color; /**< Background color, 0xRRGGBB. Qt only. */ 50 gboolean has_color_filter; /**< Set if packet has color filter. Qt only. */ 51 gboolean display; /**< indicate if the packet is displayed or not in the graph */ 52 guint src_node; /**< this is used by graph_analysis.c to identify the node */ 53 guint dst_node; /**< a node is an IP address that will be displayed in columns */ 54 guint16 line_style; /**< the arrow line width in pixels*/ 55 guint32 info_type; /**< type of info for item */ 56 gpointer info_ptr; /**< ptr to info for item */ 57 } seq_analysis_item_t; 58 59 /** defines the graph analysis structure */ 60 typedef struct _seq_analysis_info { 61 const char* name; /**< Name of sequence analysis */ 62 gboolean any_addr; /**< any addr (DL+net) vs net-only */ 63 int nconv; /**< number of conversations in the list */ 64 GQueue* items; /**< list of seq_analysis_info_t */ 65 GHashTable *ht; /**< hash table of seq_analysis_info_t */ 66 address nodes[MAX_NUM_NODES]; /**< horizontal node list */ 67 guint32 num_nodes; /**< actual number of nodes */ 68 } seq_analysis_info_t; 69 70 /** Structure for information about a registered sequence analysis function */ 71 typedef struct register_analysis register_analysis_t; 72 73 #if 0 74 #define SEQ_ANALYSIS_DEBUG(...) { \ 75 char *SEQ_ANALYSIS_DEBUG_MSG = g_strdup_printf(__VA_ARGS__); \ 76 ws_warning("sequence analysis: %s:%d %s", G_STRFUNC, __LINE__, SEQ_ANALYSIS_DEBUG_MSG); \ 77 g_free(SEQ_ANALYSIS_DEBUG_MSG); \ 78 } 79 #else 80 #define SEQ_ANALYSIS_DEBUG() 81 #endif 82 83 WS_DLL_PUBLIC void register_seq_analysis(const char* name, const char* ui_name, const int proto_id, const char* tap_listener, guint tap_flags, tap_packet_cb tap_func); 84 85 /** Helper function to get sequence analysis name 86 * 87 * @param analysis Registered sequence analysis 88 * @return sequence analysis name string 89 */ 90 WS_DLL_PUBLIC const char* sequence_analysis_get_name(register_analysis_t* analysis); 91 92 /** Helper function to get tap listener name 93 * 94 * @param analysis Registered sequence analysis 95 * @return sequence analysis tap listener string 96 */ 97 WS_DLL_PUBLIC const char* sequence_analysis_get_tap_listener_name(register_analysis_t* analysis); 98 99 /** Helper function to get UI name 100 * 101 * @param analysis Registered sequence analysis 102 * @return sequence analysis UI string 103 */ 104 WS_DLL_PUBLIC const char* sequence_analysis_get_ui_name(register_analysis_t* analysis); 105 106 /** Get tap function handler from sequence analysis 107 * 108 * @param analysis Registered sequence analysis 109 * @return tap function handler of sequence analysis 110 */ 111 WS_DLL_PUBLIC tap_packet_cb sequence_analysis_get_packet_func(register_analysis_t* analysis); 112 113 /** Helper function to get tap flags 114 * 115 * @param analysis Registered sequence analysis 116 * @return sequence analysis tap flags 117 */ 118 WS_DLL_PUBLIC guint sequence_analysis_get_tap_flags(register_analysis_t* analysis); 119 120 /** Helper function to create a sequence analysis item with address fields populated 121 * Allocate a seq_analysis_item_t to return and populate the time_str and src_addr and dst_addr 122 * members based on seq_analysis_info_t any_addr member 123 * 124 * @param pinfo packet info 125 * @param sainfo info determining address type 126 * @return sequence analysis tap flags 127 */ 128 WS_DLL_PUBLIC seq_analysis_item_t* sequence_analysis_create_sai_with_addresses(packet_info *pinfo, seq_analysis_info_t *sainfo); 129 130 /** Helper function to set colors for analysis the same as Wireshark display 131 * 132 * @param pinfo packet info 133 * @param sai item to set color 134 */ 135 WS_DLL_PUBLIC void sequence_analysis_use_color_filter(packet_info *pinfo, seq_analysis_item_t *sai); 136 137 /** Helper function to set frame label and comments to use protocol and info column data 138 * 139 * @param pinfo packet info 140 * @param sai item to set label and comments 141 */ 142 WS_DLL_PUBLIC void sequence_analysis_use_col_info_as_label_comment(packet_info *pinfo, seq_analysis_item_t *sai); 143 144 /** Find a registered sequence analysis "protocol" by name 145 * 146 * @param name Registered sequence analysis to find 147 * @return registered sequence analysis, NULL if not found 148 */ 149 WS_DLL_PUBLIC register_analysis_t* sequence_analysis_find_by_name(const char* name); 150 151 /** Interator to walk sequence_analysis tables and execute func 152 * 153 * @param func action to be performed on all sequence_analysis tables 154 * @param user_data any data needed to help perform function 155 */ 156 WS_DLL_PUBLIC void sequence_analysis_table_iterate_tables(wmem_foreach_func func, gpointer user_data); 157 158 /** Create and initialize a seq_analysis_info_t struct 159 * @return A pointer to a newly allocated seq_analysis_info_t struct. 160 */ 161 WS_DLL_PUBLIC seq_analysis_info_t *sequence_analysis_info_new(void); 162 163 /** Free a seq_analysis_info_t struct. 164 * @param sainfo A pointer to the seq_analysis_info_t struct to be freed. 165 */ 166 WS_DLL_PUBLIC void sequence_analysis_info_free(seq_analysis_info_t * sainfo); 167 168 /** Sort a seq_analysis_info_t struct. 169 * @param sainfo A pointer to the seq_analysis_info_t struct to be sorted 170 */ 171 WS_DLL_PUBLIC void sequence_analysis_list_sort(seq_analysis_info_t *sainfo); 172 173 /** Free the segment list 174 * 175 * @param sainfo Sequence analysis information. 176 */ 177 WS_DLL_PUBLIC void sequence_analysis_list_free(seq_analysis_info_t *sainfo); 178 179 /** Fill in the node address list 180 * 181 * @param sainfo Sequence analysis information. 182 * @return The number of transaction items (not nodes) processed. 183 */ 184 WS_DLL_PUBLIC int sequence_analysis_get_nodes(seq_analysis_info_t *sainfo); 185 186 /** Free the node address list 187 * 188 * @param sainfo Sequence analysis information. 189 */ 190 WS_DLL_PUBLIC void sequence_analysis_free_nodes(seq_analysis_info_t *sainfo); 191 192 193 /** Write an ASCII version of the sequence diagram to a file. 194 * 195 * @param of File to write. 196 * @param sainfo Sequence analysis information. 197 * @param first_node Start drawing at this node. 198 */ 199 WS_DLL_PUBLIC void sequence_analysis_dump_to_file(FILE *of, seq_analysis_info_t *sainfo, unsigned int first_node); 200 201 #ifdef __cplusplus 202 } 203 #endif /* __cplusplus */ 204 205 #endif /* __EPAN_SEQUENCE_ANALYSIS_H__ */ 206 207 /* 208 * Editor modelines 209 * 210 * Local Variables: 211 * c-basic-offset: 4 212 * tab-width: 8 213 * indent-tabs-mode: nil 214 * End: 215 * 216 * ex: set shiftwidth=4 tabstop=8 expandtab: 217 * :indentSize=4:tabSize=8:noTabs=true: 218 */ 219