Use the tap_dfilter_dlg mechanism.
[obnox/wireshark/wip.git] / gtk / sctp_stat.h
1 /* 
2  * Copyright 2004, Irene Ruengeler <i.ruengeler [AT] fh-muenster.de>
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24  
25 #include <epan/dissectors/packet-sctp.h>
26 #include <epan/address.h>
27 #ifndef WIN32
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #endif
32
33 #define SCTP_DATA_CHUNK_ID               0
34 #define SCTP_INIT_CHUNK_ID               1
35 #define SCTP_INIT_ACK_CHUNK_ID           2
36 #define SCTP_SACK_CHUNK_ID               3
37 #define SCTP_HEARTBEAT_CHUNK_ID          4
38 #define SCTP_HEARTBEAT_ACK_CHUNK_ID      5
39 #define SCTP_ABORT_CHUNK_ID              6
40 #define SCTP_SHUTDOWN_CHUNK_ID           7
41 #define SCTP_SHUTDOWN_ACK_CHUNK_ID       8
42 #define SCTP_ERROR_CHUNK_ID              9
43 #define SCTP_COOKIE_ECHO_CHUNK_ID       10
44 #define SCTP_COOKIE_ACK_CHUNK_ID        11
45
46 #define CHUNK_TYPE_LENGTH             1
47 #define CHUNK_FLAGS_LENGTH            1
48 #define CHUNK_LENGTH_LENGTH           2
49
50 #define CHUNK_HEADER_OFFSET           0
51 #define CHUNK_TYPE_OFFSET             CHUNK_HEADER_OFFSET
52 #define CHUNK_FLAGS_OFFSET            (CHUNK_TYPE_OFFSET + CHUNK_TYPE_LENGTH)
53 #define CHUNK_LENGTH_OFFSET           (CHUNK_FLAGS_OFFSET + CHUNK_FLAGS_LENGTH)
54 #define CHUNK_VALUE_OFFSET            (CHUNK_LENGTH_OFFSET + CHUNK_LENGTH_LENGTH)
55
56 #define INIT_CHUNK_INITIATE_TAG_LENGTH               4
57 #define INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH      4
58 #define INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH 2
59 #define INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH  2
60
61
62 #define INIT_CHUNK_INITIATE_TAG_OFFSET               CHUNK_VALUE_OFFSET
63 #define INIT_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET      (INIT_CHUNK_INITIATE_TAG_OFFSET + \
64                                                       INIT_CHUNK_INITIATE_TAG_LENGTH )
65 #define INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_OFFSET (INIT_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET + \
66                                                       INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH )
67 #define INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_OFFSET  (INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_OFFSET + \
68                                                       INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH )
69 #define INIT_CHUNK_INITIAL_TSN_OFFSET                (INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_OFFSET + \
70                                                       INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH )
71
72 #define DATA_CHUNK_TSN_LENGTH         4
73 #define DATA_CHUNK_TSN_OFFSET         (CHUNK_VALUE_OFFSET + 0)
74 #define DATA_CHUNK_STREAM_ID_OFFSET   (DATA_CHUNK_TSN_OFFSET + DATA_CHUNK_TSN_LENGTH)
75 #define DATA_CHUNK_STREAM_ID_LENGTH   2
76 #define DATA_CHUNK_STREAM_SEQ_NUMBER_LENGTH 2
77 #define DATA_CHUNK_PAYLOAD_PROTOCOL_ID_LENGTH 4
78 #define DATA_CHUNK_HEADER_LENGTH      (CHUNK_HEADER_LENGTH + \
79                                        DATA_CHUNK_TSN_LENGTH + \
80                                        DATA_CHUNK_STREAM_ID_LENGTH + \
81                                        DATA_CHUNK_STREAM_SEQ_NUMBER_LENGTH + \
82                                        DATA_CHUNK_PAYLOAD_PROTOCOL_ID_LENGTH)
83 #define MAX_ADDRESS_LEN                47
84 #define NUM_CHUNKS                     13
85
86
87 typedef struct _tsn {
88         guint32 frame_number;
89         guint32 secs;    /* Absolute seconds */
90         guint32 usecs;
91         address src;
92         address dst;
93         GList   *tsns;
94 } tsn_t;
95
96 typedef struct _sctp_tmp_info {
97         address src;
98         address dst;
99         guint16 port1;
100         guint16 port2;
101         guint32 verification_tag1;
102         guint32 verification_tag2;
103         guint32 n_tvbs;
104 } sctp_tmp_info_t;
105
106 typedef struct _sctp_min_max {
107         guint32 tmp_min_secs;
108         guint32 tmp_min_usecs;
109         guint32 tmp_max_secs;
110         guint32 tmp_max_usecs;
111         guint32 tmp_min_tsn1;
112         guint32 tmp_min_tsn2;
113         guint32 tmp_max_tsn1;
114         guint32 tmp_max_tsn2;
115         gint    tmp_secs;
116 } sctp_min_max_t;
117
118 struct tsn_sort{
119         guint32 tsnumber;
120         guint32 secs;
121         guint32 usecs;
122         guint32 offset;
123         guint32 length;
124 };
125
126 typedef struct _sctp_addr_chunk {
127         guint32  direction;
128         address* addr;
129         guint32  addr_count[13];
130 } sctp_addr_chunk;
131
132 typedef struct _sctp_assoc_info {
133         address   src;
134         address   dst;
135         guint16   port1;
136         guint16   port2;
137         guint32   verification_tag1;
138         guint32   verification_tag2;
139         guint32   n_tvbs;
140         GList     *addr1;
141         GList     *addr2;
142         guint16   instream1;
143         guint16   outstream1;
144         guint16   instream2;
145         guint16   outstream2;
146         guint32   n_adler32_calculated;
147         guint32   n_adler32_correct;
148         guint32   n_crc32c_calculated;
149         guint32   n_crc32c_correct;
150         guint8    checksum_type[8];
151         guint32   n_checksum_errors;
152         guint32   n_bundling_errors;
153         guint32   n_padding_errors;
154         guint32   n_length_errors;
155         guint32   n_value_errors;
156         guint32   n_data_chunks;
157         guint32   n_data_bytes;
158         guint32   n_packets;
159         guint32   n_data_chunks_ep1;
160         guint32   n_data_bytes_ep1;
161         guint32   n_data_chunks_ep2;
162         guint32   n_data_bytes_ep2;
163         guint32   n_sack_chunks_ep1;
164         guint32   n_sack_chunks_ep2;
165         guint32   n_array_tsn1;
166         guint32   n_array_tsn2;
167         guint32   max_window1;
168         guint32   max_window2;
169         gboolean  init;
170         gboolean  initack;
171         guint8    initack_dir;
172         guint8    direction;
173         guint32   min_secs;
174         guint32   min_usecs;
175         guint32   max_secs;
176         guint32   max_usecs;
177         guint32   min_tsn1;
178         guint32   min_tsn2;
179         guint32   max_tsn1;
180         guint32   max_tsn2;
181         guint32   max_bytes1;
182         guint32   max_bytes2;
183         GSList    *min_max;
184         GList     *frame_numbers;
185         GList     *tsn1;
186         GPtrArray *sort_tsn1;
187         GPtrArray *sort_sack1;
188         GList     *sack1;
189         GList     *tsn2;
190         GPtrArray *sort_tsn2;
191         GPtrArray *sort_sack2;
192         GList     *sack2;
193         gboolean  check_address;
194         GList*    error_info_list;
195         guint32   chunk_count[NUM_CHUNKS];
196         guint32   ep1_chunk_count[NUM_CHUNKS];
197         guint32   ep2_chunk_count[NUM_CHUNKS];
198         GList*    addr_chunk_count;
199 } sctp_assoc_info_t;
200
201 typedef struct _sctp_error_info {
202         guint32 frame_number;
203         gchar   chunk_info[200];
204         const gchar  *info_text;
205 } sctp_error_info_t;
206
207
208 typedef struct _sctp_allassocs_info {
209         guint32  sum_tvbs;
210         GList*   assoc_info_list;
211         gboolean is_registered;
212         GList*   children;
213 } sctp_allassocs_info_t;
214
215
216
217 struct notes {
218         GtkWidget   *checktype;
219         GtkWidget   *checksum;
220         GtkWidget   *bundling;
221         GtkWidget   *padding;
222         GtkWidget   *length;
223         GtkWidget   *value;
224         GtkWidget   *chunks_ep1;
225         GtkWidget   *bytes_ep1;
226         GtkWidget   *chunks_ep2;
227         GtkWidget   *bytes_ep2;
228         struct page *page2;
229         struct page *page3;
230 };
231
232 struct page {
233         GtkWidget *addr_frame;
234         GtkWidget *scrolled_window;
235         GtkWidget *clist;
236         GtkWidget *port;
237         GtkWidget *veritag;
238         GtkWidget *max_in;
239         GtkWidget *min_in;
240         GtkWidget *max_out;
241         GtkWidget *min_out;
242 };
243
244 struct sctp_analyse {
245         sctp_assoc_info_t *assoc;
246         GtkWidget*        window;
247         struct notes      *analyse_nb;
248         GList             *children;
249         guint16           num_children;
250 };
251
252 typedef struct _sctp_graph_t {
253         gboolean  needs_redraw;
254         gfloat    x_interval;
255         gfloat    y_interval;
256         GtkWidget *window;
257         GtkWidget *draw_area;
258         GdkPixmap *pixmap;
259         gint      pixmap_width;
260         gint      pixmap_height;
261         gint      graph_type;
262         gdouble   x_old;
263         gdouble   y_old;
264         gdouble   x_new;
265         gdouble   y_new;
266         guint16   offset;
267         guint16   length;
268         gboolean  tmp;
269         gboolean  rectangle;
270         guint32   x1_tmp_sec;
271         guint32   x2_tmp_sec;
272         guint32   x1_tmp_usec;
273         guint32   x2_tmp_usec;
274         guint32   tmp_width;
275         guint32   axis_width;
276         guint32   y1_tmp;
277         guint32   y2_tmp;
278         guint32   tmp_min_tsn1;
279         guint32   tmp_max_tsn1;
280         guint32   tmp_min_tsn2;
281         guint32   tmp_max_tsn2;
282         guint32   min_x;
283         guint32   max_x;
284         guint32   min_y;
285         guint32   max_y;
286 } sctp_graph_t;
287
288
289
290 struct sctp_udata {
291         sctp_assoc_info_t   *assoc;
292         sctp_graph_t        *io;
293         struct sctp_analyse *parent;
294         guint16             dir;
295 };
296
297
298 void register_tap_listener_sctp_stat(void);
299
300 const sctp_allassocs_info_t* sctp_stat_get_info(void);
301
302 void sctp_stat_scan(void);
303
304 void remove_tap_listener_sctp_stat(void);
305
306 void assoc_analyse(sctp_assoc_info_t* assoc);
307
308 const sctp_assoc_info_t* get_selected_assoc(void);
309
310 void create_graph(guint16 dir, struct sctp_analyse* u_data);
311
312 void create_byte_graph(guint16 dir, struct sctp_analyse* u_data);
313
314 void sctp_error_dlg_show(sctp_assoc_info_t* assoc);
315
316 void sctp_stat_dlg_update(void);
317
318 void sctp_chunk_stat_dlg_update(struct sctp_udata* udata, unsigned int direction);
319
320 void sctp_chunk_dlg_show(struct sctp_analyse* userdata);
321
322 void sctp_chunk_stat_dlg_show(unsigned int direction, struct sctp_analyse* userdata);
323
324 GtkWidget *get_stat_dlg(void);
325
326 GtkWidget *get_chunk_stat_dlg(void);
327
328 void update_analyse_dlg(struct sctp_analyse* u_data);
329
330 void sctp_analyse_start(GtkWidget *w _U_, gpointer data _U_);
331
332 void increase_childcount(struct sctp_analyse *parent);
333
334 void decrease_childcount(struct sctp_analyse *parent);
335
336 void set_child(struct sctp_udata *child, struct sctp_analyse *parent);
337
338 void remove_child(struct sctp_udata *child, struct sctp_analyse *parent);
339
340 void decrease_analyse_childcount(void);
341
342 void increase_analyse_childcount(void);
343
344 void set_analyse_child(struct sctp_analyse *child);
345
346 void remove_analyse_child(struct sctp_analyse *child);