QUIC: Update IETF draft URL (draft-08)
[metze/wireshark/wip.git] / epan / follow.h
1 /* follow.h
2  *
3  * Copyright 1998 Mike Hall <mlh@io.com>
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
25 #ifndef __FOLLOW_H__
26 #define __FOLLOW_H__
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32 #include <epan/epan.h>
33 #include <epan/packet.h>
34 #include <epan/ipv6.h>
35 #include <epan/wmem/wmem.h>
36 #include "ws_symbol_export.h"
37
38 typedef enum {
39   TCP_STREAM = 0,
40   UDP_STREAM,
41   MAX_STREAM
42 } stream_type;
43
44 typedef enum {
45     FRS_OK,
46     FRS_OPEN_ERROR,
47     FRS_READ_ERROR,
48     FRS_PRINT_ERROR
49 } frs_return_t;
50
51 /* Type of follow we are doing */
52 typedef enum {
53     FOLLOW_TCP,
54     FOLLOW_SSL,
55     FOLLOW_UDP,
56     FOLLOW_HTTP
57 } follow_type_t;
58
59 /* Show Type */
60 typedef enum {
61     SHOW_ASCII,
62     SHOW_EBCDIC,
63     SHOW_HEXDUMP,
64     SHOW_CARRAY,
65     SHOW_RAW,
66     SHOW_YAML,
67     SHOW_UTF8,
68     SHOW_UTF16
69 } show_type_t;
70
71
72 /* Show Stream */
73 typedef enum {
74     FROM_CLIENT,
75     FROM_SERVER,
76     BOTH_HOSTS
77 } show_stream_t;
78
79 typedef union _stream_addr {
80   guint32 ipv4;
81   ws_in6_addr ipv6;
82 } stream_addr;
83
84 struct _follow_info;
85
86 typedef gboolean (*follow_print_line_func)(char *, size_t, gboolean, void *);
87 typedef frs_return_t (*follow_read_stream_func)(struct _follow_info *follow_info, follow_print_line_func follow_print, void *arg);
88
89 typedef struct {
90     gboolean is_server;
91     guint32 packet_num;
92     guint32 seq; /* TCP only */
93     GByteArray *data;
94 } follow_record_t;
95
96 typedef struct _follow_info {
97     show_stream_t   show_stream;
98     char            *filter_out_filter;
99     GList           *payload;
100     guint           bytes_written[2]; /* Index with FROM_CLIENT or FROM_SERVER for readability. */
101     guint32         seq[2]; /* TCP only */
102     GList           *fragments[2]; /* TCP only */
103     guint           client_port;
104     guint           server_port;
105     address         client_ip;
106     address         server_ip;
107     void*           gui_data;
108 } follow_info_t;
109
110 struct register_follow;
111 typedef struct register_follow register_follow_t;
112
113 typedef gchar* (*follow_conv_filter_func)(packet_info* pinfo, int* stream);
114 typedef gchar* (*follow_index_filter_func)(int stream);
115 typedef gchar* (*follow_address_filter_func)(address* src_addr, address* dst_addr, int src_port, int dst_port);
116 typedef gchar* (*follow_port_to_display_func)(wmem_allocator_t *allocator, guint port);
117 typedef gboolean (*follow_tap_func)(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const void *data);
118
119 WS_DLL_PUBLIC
120 void register_follow_stream(const int proto_id, const char* tap_listener,
121                             follow_conv_filter_func conv_filter, follow_index_filter_func index_filter, follow_address_filter_func address_filter,
122                             follow_port_to_display_func port_to_display, follow_tap_func tap_handler);
123
124 /** Get protocol ID from registered follower
125  *
126  * @param follower Registered follower
127  * @return protocol id of follower
128  */
129 WS_DLL_PUBLIC int get_follow_proto_id(register_follow_t* follower);
130
131 /** Get tap name string from registered follower (used for register_tap_listener)
132  *
133  * @param follower Registered follower
134  * @return tap name string of follower
135  */
136 WS_DLL_PUBLIC const char* get_follow_tap_string(register_follow_t* follower);
137
138 /** Get a registered follower by protocol short name
139  *
140  * @param proto_short_name Protocol short name
141  * @return tap registered follower if match, otherwise NULL
142  */
143 WS_DLL_PUBLIC register_follow_t* get_follow_by_name(const char* proto_short_name);
144
145 /** Provide function that builds a follow filter based on the current packet's conversation.
146  *
147  * @param follower [in] Registered follower
148  * @return A filter function handler
149  */
150 WS_DLL_PUBLIC follow_conv_filter_func get_follow_conv_func(register_follow_t* follower);
151
152 /** Provide function that builds a follow filter based on stream.
153  *
154  * @param follower [in] Registered follower
155  * @return A filter function handler
156  */
157 WS_DLL_PUBLIC follow_index_filter_func get_follow_index_func(register_follow_t* follower);
158
159 /** Provide function that builds a follow filter based on address/port pairs.
160  *
161  * @param follower [in] Registered follower
162  * @return A filter function handler
163  */
164 WS_DLL_PUBLIC follow_address_filter_func get_follow_address_func(register_follow_t* follower);
165
166 /** Provide function that resolves port number to name based on follower.
167  *
168  * @param follower [in] Registered follower
169  * @return A port resolver function handler
170  */
171 WS_DLL_PUBLIC follow_port_to_display_func get_follow_port_to_display(register_follow_t* follower);
172
173 /** Provide function that handles tap data (tap_packet_cb parameter of register_tap_listener)
174  *
175  * @param follower [in] Registered follower
176  * @return A tap data handler
177  */
178 WS_DLL_PUBLIC follow_tap_func get_follow_tap_handler(register_follow_t* follower);
179
180
181 /** Tap function handler when dissector's tap provides follow data as a tvb.
182  * Used by TCP, UDP and HTTP followers
183  */
184 WS_DLL_PUBLIC gboolean
185 follow_tvb_tap_listener(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, const void *data);
186
187 /** Interator to walk all registered followers and execute func
188  *
189  * @param func action to be performed on all converation tables
190  * @param user_data any data needed to help perform function
191  */
192 WS_DLL_PUBLIC void follow_iterate_followers(wmem_foreach_func func, gpointer user_data);
193
194 /** Generate -z stat (tap) name for a follower
195  * Currently used only by TShark
196  *
197  * @param follower [in] Registered follower
198  * @return A tap data handler
199  */
200 WS_DLL_PUBLIC gchar* follow_get_stat_tap_string(register_follow_t* follower);
201
202 /** Clear counters, addresses and ports of follow_info_t
203  *
204  * @param info [in] follower info
205  */
206 WS_DLL_PUBLIC void follow_reset_stream(follow_info_t* info);
207
208 /** Free follow_info_t structure
209  * Free everything except the GUI element
210  *
211  * @param follow_info [in] follower info
212  */
213 WS_DLL_PUBLIC void follow_info_free(follow_info_t* follow_info);
214
215 #ifdef __cplusplus
216 }
217 #endif /* __cplusplus */
218
219 #endif