60694e852c1cc9be26e31c348c5c652a43cfff17
[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  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
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 typedef struct _tsn {
87         guint32 frame_number;
88         guint32 secs;    /* Absolute seconds */
89         guint32 usecs;
90         address src;
91         address dst;
92         guint32 first_tsn;
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 initiate_tag;
104         guint32 n_tvbs;
105 } sctp_tmp_info_t;
106
107 typedef struct _sctp_min_max {
108         guint32 tmp_min_secs;
109         guint32 tmp_min_usecs;
110         guint32 tmp_max_secs;
111         guint32 tmp_max_usecs;
112         guint32 tmp_min_tsn1;
113         guint32 tmp_min_tsn2;
114         guint32 tmp_max_tsn1;
115         guint32 tmp_max_tsn2;
116         gint    tmp_secs;
117 } sctp_min_max_t;
118
119 struct tsn_sort{
120         guint32 tsnumber;
121         guint32 secs;
122         guint32 usecs;
123         guint32 offset;
124         guint32 length;
125         guint32 framenumber;
126 };
127
128 typedef struct _sctp_addr_chunk {
129         guint32  direction;
130         address* addr;
131         guint32  addr_count[13];
132 } sctp_addr_chunk;
133
134 typedef struct _sctp_assoc_info {
135         address   src;
136         address   dst;
137         guint16   port1;
138         guint16   port2;
139         guint32   verification_tag1;
140         guint32   verification_tag2;
141         guint32   initiate_tag;
142         guint32   n_tvbs;
143         GList     *addr1;
144         GList     *addr2;
145         guint16   instream1;
146         guint16   outstream1;
147         guint16   instream2;
148         guint16   outstream2;
149         guint32   n_adler32_calculated;
150         guint32   n_adler32_correct;
151         guint32   n_crc32c_calculated;
152         guint32   n_crc32c_correct;
153         gchar     checksum_type[8];
154         guint32   n_checksum_errors;
155         guint32   n_bundling_errors;
156         guint32   n_padding_errors;
157         guint32   n_length_errors;
158         guint32   n_value_errors;
159         guint32   n_data_chunks;
160         guint32   n_data_bytes;
161         guint32   n_packets;
162         guint32   n_data_chunks_ep1;
163         guint32   n_data_bytes_ep1;
164         guint32   n_data_chunks_ep2;
165         guint32   n_data_bytes_ep2;
166         guint32   n_sack_chunks_ep1;
167         guint32   n_sack_chunks_ep2;
168         guint32   n_array_tsn1;
169         guint32   n_array_tsn2;
170         guint32   max_window1;
171         guint32   max_window2;
172         gboolean  init;
173         gboolean  initack;
174         guint8    initack_dir;
175         guint8    direction;
176         guint32   min_secs;
177         guint32   min_usecs;
178         guint32   max_secs;
179         guint32   max_usecs;
180         guint32   min_tsn1;
181         guint32   min_tsn2;
182         guint32   max_tsn1;
183         guint32   max_tsn2;
184         guint32   max_bytes1;
185         guint32   max_bytes2;
186         GSList    *min_max;
187         GList     *frame_numbers;
188         GList     *tsn1;
189         GPtrArray *sort_tsn1;
190         GPtrArray *sort_sack1;
191         GList     *sack1;
192         GList     *tsn2;
193         GPtrArray *sort_tsn2;
194         GPtrArray *sort_sack2;
195         GList     *sack2;
196         gboolean  check_address;
197         GList*    error_info_list;
198         guint32   chunk_count[NUM_CHUNKS];
199         guint32   ep1_chunk_count[NUM_CHUNKS];
200         guint32   ep2_chunk_count[NUM_CHUNKS];
201         GList*    addr_chunk_count;
202 } sctp_assoc_info_t;
203
204 typedef struct _sctp_error_info {
205         guint32 frame_number;
206         gchar   chunk_info[200];
207         const gchar  *info_text;
208 } sctp_error_info_t;
209
210
211 typedef struct _sctp_allassocs_info {
212         guint32  sum_tvbs;
213         GList*   assoc_info_list;
214         gboolean is_registered;
215         GList*   children;
216 } sctp_allassocs_info_t;
217
218
219
220 struct notes {
221         GtkWidget   *checktype;
222         GtkWidget   *checksum;
223         GtkWidget   *bundling;
224         GtkWidget   *padding;
225         GtkWidget   *length;
226         GtkWidget   *value;
227         GtkWidget   *chunks_ep1;
228         GtkWidget   *bytes_ep1;
229         GtkWidget   *chunks_ep2;
230         GtkWidget   *bytes_ep2;
231         struct page *page2;
232         struct page *page3;
233 };
234
235 struct page {
236         GtkWidget *addr_frame;
237         GtkWidget *scrolled_window;
238         GtkWidget *clist;
239         GtkWidget *port;
240         GtkWidget *veritag;
241         GtkWidget *max_in;
242         GtkWidget *min_in;
243         GtkWidget *max_out;
244         GtkWidget *min_out;
245 };
246
247 struct sctp_analyse {
248         sctp_assoc_info_t *assoc;
249         GtkWidget*        window;
250         struct notes      *analyse_nb;
251         GList             *children;
252         guint16           num_children;
253 };
254
255 typedef struct _sctp_graph_t {
256         gboolean  needs_redraw;
257         gfloat    x_interval;
258         gfloat    y_interval;
259         GtkWidget *window;
260         GtkWidget *draw_area;
261         GdkPixmap *pixmap;
262         gint      pixmap_width;
263         gint      pixmap_height;
264         gint      graph_type;
265         gdouble   x_old;
266         gdouble   y_old;
267         gdouble   x_new;
268         gdouble   y_new;
269         guint16   offset;
270         guint16   length;
271         gboolean  tmp;
272         gboolean  rectangle;
273         gboolean  rectangle_present;
274         guint32   rect_x_min;
275         guint32   rect_x_max;
276         guint32   rect_y_min;
277         guint32   rect_y_max;
278         guint32   x1_tmp_sec;
279         guint32   x2_tmp_sec;
280         guint32   x1_tmp_usec;
281         guint32   x2_tmp_usec;
282         guint32   x1_akt_sec;
283         guint32   x2_akt_sec;
284         guint32   x1_akt_usec;
285         guint32   x2_akt_usec;
286         guint32   tmp_width;
287         guint32   axis_width;
288         guint32   y1_tmp;
289         guint32   y2_tmp;
290         guint32   tmp_min_tsn1;
291         guint32   tmp_max_tsn1;
292         guint32   tmp_min_tsn2;
293         guint32   tmp_max_tsn2;
294         guint32   min_x;
295         guint32   max_x;
296         guint32   min_y;
297         guint32   max_y;
298         gboolean  uoff;
299 } sctp_graph_t;
300
301
302
303 struct sctp_udata {
304         sctp_assoc_info_t   *assoc;
305         sctp_graph_t        *io;
306         struct sctp_analyse *parent;
307         guint16             dir;
308 };
309
310
311 void register_tap_listener_sctp_stat(void);
312
313 const sctp_allassocs_info_t* sctp_stat_get_info(void);
314
315 void sctp_stat_scan(void);
316
317 void remove_tap_listener_sctp_stat(void);
318
319 void assoc_analyse(sctp_assoc_info_t* assoc);
320
321 const sctp_assoc_info_t* get_selected_assoc(void);
322
323 void create_graph(guint16 dir, struct sctp_analyse* u_data);
324
325 void create_byte_graph(guint16 dir, struct sctp_analyse* u_data);
326
327 void sctp_error_dlg_show(sctp_assoc_info_t* assoc);
328
329 void sctp_stat_dlg_update(void);
330
331 void sctp_chunk_stat_dlg_update(struct sctp_udata* udata, unsigned int direction);
332
333 void sctp_chunk_dlg_show(struct sctp_analyse* userdata);
334
335 void sctp_chunk_stat_dlg_show(unsigned int direction, struct sctp_analyse* userdata);
336
337 GtkWidget *get_stat_dlg(void);
338
339 GtkWidget *get_chunk_stat_dlg(void);
340
341 void update_analyse_dlg(struct sctp_analyse* u_data);
342
343 void sctp_analyse_start(GtkWidget *w _U_, gpointer data _U_);
344
345 void increase_childcount(struct sctp_analyse *parent);
346
347 void decrease_childcount(struct sctp_analyse *parent);
348
349 void set_child(struct sctp_udata *child, struct sctp_analyse *parent);
350
351 void remove_child(struct sctp_udata *child, struct sctp_analyse *parent);
352
353 void decrease_analyse_childcount(void);
354
355 void increase_analyse_childcount(void);
356
357 void set_analyse_child(struct sctp_analyse *child);
358
359 void remove_analyse_child(struct sctp_analyse *child);
360
361 void sctp_set_assoc_filter(void);
362