From Robin Seggelmann: Improve SCTP chunk statistics.
[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 #ifndef __SCTP_STAT_H__ 
26 #define __SCTP_STAT_H__ 
27
28 #include <epan/dissectors/packet-sctp.h>
29 #include <epan/address.h>
30 #ifndef _WIN32
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #else
35 #ifdef HAVE_WINSOCK2_H
36 #include <winsock2.h>
37 #endif
38 #endif
39
40 #define SCTP_DATA_CHUNK_ID               0
41 #define SCTP_INIT_CHUNK_ID               1
42 #define SCTP_INIT_ACK_CHUNK_ID           2
43 #define SCTP_SACK_CHUNK_ID               3
44 #define SCTP_HEARTBEAT_CHUNK_ID          4
45 #define SCTP_HEARTBEAT_ACK_CHUNK_ID      5
46 #define SCTP_ABORT_CHUNK_ID              6
47 #define SCTP_SHUTDOWN_CHUNK_ID           7
48 #define SCTP_SHUTDOWN_ACK_CHUNK_ID       8
49 #define SCTP_ERROR_CHUNK_ID              9
50 #define SCTP_COOKIE_ECHO_CHUNK_ID       10
51 #define SCTP_COOKIE_ACK_CHUNK_ID        11
52 #define SCTP_ECNE_CHUNK_ID              12
53 #define SCTP_CWR_CHUNK_ID               13
54 #define SCTP_SHUTDOWN_COMPLETE_CHUNK_ID 14
55 #define SCTP_AUTH_CHUNK_ID              15 
56 #define SCTP_NR_SACK_CHUNK_ID           16
57 #define SCTP_FORWARD_TSN_CHUNK_ID     0xc0
58 #define SCTP_ASCONF_ACK_CHUNK_ID      0x80
59 #define SCTP_PKTDROP_CHUNK_ID         0x81
60 #define SCTP_ASCONF_CHUNK_ID          0xc1
61 #define SCTP_IETF_EXT                  255
62
63 #define IS_SCTP_CHUNK_TYPE(t) \
64         (((t) <= 16) || ((t) == 0xC0) || ((t) == 0xC1) || ((t) == 0x80) || ((t) == 0x81))
65
66 #define CHUNK_TYPE_LENGTH             1
67 #define CHUNK_FLAGS_LENGTH            1
68 #define CHUNK_LENGTH_LENGTH           2
69
70 #define CHUNK_HEADER_OFFSET           0
71 #define CHUNK_TYPE_OFFSET             CHUNK_HEADER_OFFSET
72 #define CHUNK_FLAGS_OFFSET            (CHUNK_TYPE_OFFSET + CHUNK_TYPE_LENGTH)
73 #define CHUNK_LENGTH_OFFSET           (CHUNK_FLAGS_OFFSET + CHUNK_FLAGS_LENGTH)
74 #define CHUNK_VALUE_OFFSET            (CHUNK_LENGTH_OFFSET + CHUNK_LENGTH_LENGTH)
75
76 #define INIT_CHUNK_INITIATE_TAG_LENGTH               4
77 #define INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH      4
78 #define INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH 2
79 #define INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH  2
80
81
82 #define INIT_CHUNK_INITIATE_TAG_OFFSET               CHUNK_VALUE_OFFSET
83 #define INIT_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET      (INIT_CHUNK_INITIATE_TAG_OFFSET + \
84                                                       INIT_CHUNK_INITIATE_TAG_LENGTH )
85 #define INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_OFFSET (INIT_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET + \
86                                                       INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH )
87 #define INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_OFFSET  (INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_OFFSET + \
88                                                       INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH )
89 #define INIT_CHUNK_INITIAL_TSN_OFFSET                (INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_OFFSET + \
90                                                       INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH )
91
92 #define DATA_CHUNK_TSN_LENGTH         4
93 #define DATA_CHUNK_TSN_OFFSET         (CHUNK_VALUE_OFFSET + 0)
94 #define DATA_CHUNK_STREAM_ID_OFFSET   (DATA_CHUNK_TSN_OFFSET + DATA_CHUNK_TSN_LENGTH)
95 #define DATA_CHUNK_STREAM_ID_LENGTH   2
96 #define DATA_CHUNK_STREAM_SEQ_NUMBER_LENGTH 2
97 #define DATA_CHUNK_PAYLOAD_PROTOCOL_ID_LENGTH 4
98 #define DATA_CHUNK_HEADER_LENGTH      (CHUNK_HEADER_LENGTH + \
99                                        DATA_CHUNK_TSN_LENGTH + \
100                                        DATA_CHUNK_STREAM_ID_LENGTH + \
101                                        DATA_CHUNK_STREAM_SEQ_NUMBER_LENGTH + \
102                                        DATA_CHUNK_PAYLOAD_PROTOCOL_ID_LENGTH)
103 #define MAX_ADDRESS_LEN                47
104
105 /* The below value is 256 */
106 #define NUM_CHUNKS      0xff
107
108 /* This variable is used as an index into arrays
109  * which store the cumulative information corresponding
110  * all chunks with Chunk Type greater > 16
111  * The value for the below variable is 17
112  */
113 #define OTHER_CHUNKS_INDEX      0xfe
114
115 /* VNB */
116 /* This variable stores the maximum chunk type value
117  * that can be associated with a sctp chunk.
118  */
119 #define MAX_SCTP_CHUNK_TYPE 256
120
121 typedef struct _tsn {
122         guint32 frame_number;
123         guint32 secs;    /* Absolute seconds */
124         guint32 usecs;
125         address src;
126         address dst;
127         guint32 first_tsn;
128         GList   *tsns;
129 } tsn_t;
130
131 typedef struct _sctp_tmp_info {
132         address src;
133         address dst;
134         guint16 port1;
135         guint16 port2;
136         guint32 verification_tag1;
137         guint32 verification_tag2;
138         guint32 initiate_tag;
139         guint32 n_tvbs;
140 } sctp_tmp_info_t;
141
142 typedef struct _sctp_min_max {
143         guint32 tmp_min_secs;
144         guint32 tmp_min_usecs;
145         guint32 tmp_max_secs;
146         guint32 tmp_max_usecs;
147         guint32 tmp_min_tsn1;
148         guint32 tmp_min_tsn2;
149         guint32 tmp_max_tsn1;
150         guint32 tmp_max_tsn2;
151         gint    tmp_secs;
152 } sctp_min_max_t;
153
154 struct tsn_sort{
155         guint32 tsnumber;
156         guint32 secs;
157         guint32 usecs;
158         guint32 offset;
159         guint32 length;
160         guint32 framenumber;
161 };
162
163 typedef struct _sctp_addr_chunk {
164         guint32  direction;
165         address* addr;
166         /* The array is initialized to MAX_SCTP_CHUNK_TYPE
167          * so that there is no memory overwrite
168          * when accessed using sctp chunk type as index.
169          */
170         guint32  addr_count[MAX_SCTP_CHUNK_TYPE];
171 } sctp_addr_chunk;
172
173 typedef struct _sctp_assoc_info {
174         address   src;
175         address   dst;
176         guint16   port1;
177         guint16   port2;
178         guint32   verification_tag1;
179         guint32   verification_tag2;
180         guint32   initiate_tag;
181         guint32   n_tvbs;
182         GList     *addr1;
183         GList     *addr2;
184         guint16   instream1;
185         guint16   outstream1;
186         guint16   instream2;
187         guint16   outstream2;
188         guint32   n_adler32_calculated;
189         guint32   n_adler32_correct;
190         guint32   n_crc32c_calculated;
191         guint32   n_crc32c_correct;
192         gchar     checksum_type[8];
193         guint32   n_checksum_errors;
194         guint32   n_bundling_errors;
195         guint32   n_padding_errors;
196         guint32   n_length_errors;
197         guint32   n_value_errors;
198         guint32   n_data_chunks;
199         guint32   n_data_bytes;
200         guint32   n_packets;
201         guint32   n_data_chunks_ep1;
202         guint32   n_data_bytes_ep1;
203         guint32   n_data_chunks_ep2;
204         guint32   n_data_bytes_ep2;
205         guint32   n_sack_chunks_ep1;
206         guint32   n_sack_chunks_ep2;
207         guint32   n_array_tsn1;
208         guint32   n_array_tsn2;
209         guint32   max_window1;
210         guint32   max_window2;
211         gboolean  init;
212         gboolean  initack;
213         guint8    initack_dir;
214         guint8    direction;
215         guint32   min_secs;
216         guint32   min_usecs;
217         guint32   max_secs;
218         guint32   max_usecs;
219         guint32   min_tsn1;
220         guint32   min_tsn2;
221         guint32   max_tsn1;
222         guint32   max_tsn2;
223         guint32   max_bytes1;
224         guint32   max_bytes2;
225         GSList    *min_max;
226         GList     *frame_numbers;
227         GList     *tsn1;
228         GPtrArray *sort_tsn1;
229         GPtrArray *sort_sack1;
230         GList     *sack1;
231         GList     *tsn2;
232         GPtrArray *sort_tsn2;
233         GPtrArray *sort_sack2;
234         GList     *sack2;
235         gboolean  check_address;
236         GList*    error_info_list;
237         /* The array is initialized to MAX_SCTP_CHUNK_TYPE
238          * so that there is no memory overwrite
239          * when accessed using sctp chunk type as index.
240          */
241         guint32   chunk_count[MAX_SCTP_CHUNK_TYPE];
242         guint32   ep1_chunk_count[MAX_SCTP_CHUNK_TYPE];
243         guint32   ep2_chunk_count[MAX_SCTP_CHUNK_TYPE];
244         GList*    addr_chunk_count;
245 } sctp_assoc_info_t;
246
247 typedef struct _sctp_error_info {
248         guint32 frame_number;
249         gchar   chunk_info[200];
250         const gchar  *info_text;
251 } sctp_error_info_t;
252
253
254 typedef struct _sctp_allassocs_info {
255         guint32  sum_tvbs;
256         GList*   assoc_info_list;
257         gboolean is_registered;
258         GList*   children;
259 } sctp_allassocs_info_t;
260
261
262
263 struct notes {
264         GtkWidget   *checktype;
265         GtkWidget   *checksum;
266         GtkWidget   *bundling;
267         GtkWidget   *padding;
268         GtkWidget   *length;
269         GtkWidget   *value;
270         GtkWidget   *chunks_ep1;
271         GtkWidget   *bytes_ep1;
272         GtkWidget   *chunks_ep2;
273         GtkWidget   *bytes_ep2;
274         struct page *page2;
275         struct page *page3;
276 };
277
278 struct page {
279         GtkWidget *addr_frame;
280         GtkWidget *scrolled_window;
281         GtkWidget *clist;
282         GtkWidget *port;
283         GtkWidget *veritag;
284         GtkWidget *max_in;
285         GtkWidget *min_in;
286         GtkWidget *max_out;
287         GtkWidget *min_out;
288 };
289
290 struct sctp_analyse {
291         sctp_assoc_info_t *assoc;
292         GtkWidget*        window;
293         struct notes      *analyse_nb;
294         GList             *children;
295         guint16           num_children;
296 };
297
298 typedef struct _sctp_graph_t {
299         gboolean  needs_redraw;
300         gfloat    x_interval;
301         gfloat    y_interval;
302         GtkWidget *window;
303         GtkWidget *draw_area;
304         GdkPixmap *pixmap;
305         gint      pixmap_width;
306         gint      pixmap_height;
307         gint      graph_type;
308         gdouble   x_old;
309         gdouble   y_old;
310         gdouble   x_new;
311         gdouble   y_new;
312         guint16   offset;
313         guint16   length;
314         gboolean  tmp;
315         gboolean  rectangle;
316         gboolean  rectangle_present;
317         guint32   rect_x_min;
318         guint32   rect_x_max;
319         guint32   rect_y_min;
320         guint32   rect_y_max;
321         guint32   x1_tmp_sec;
322         guint32   x2_tmp_sec;
323         guint32   x1_tmp_usec;
324         guint32   x2_tmp_usec;
325         guint32   x1_akt_sec;
326         guint32   x2_akt_sec;
327         guint32   x1_akt_usec;
328         guint32   x2_akt_usec;
329         guint32   tmp_width;
330         guint32   axis_width;
331         guint32   y1_tmp;
332         guint32   y2_tmp;
333         guint32   tmp_min_tsn1;
334         guint32   tmp_max_tsn1;
335         guint32   tmp_min_tsn2;
336         guint32   tmp_max_tsn2;
337         guint32   min_x;
338         guint32   max_x;
339         guint32   min_y;
340         guint32   max_y;
341         gboolean  uoff;
342 } sctp_graph_t;
343
344
345
346 struct sctp_udata {
347         sctp_assoc_info_t   *assoc;
348         sctp_graph_t        *io;
349         struct sctp_analyse *parent;
350         guint16             dir;
351 };
352
353
354 void register_tap_listener_sctp_stat(void);
355
356 const sctp_allassocs_info_t* sctp_stat_get_info(void);
357
358 void sctp_stat_scan(void);
359
360 void remove_tap_listener_sctp_stat(void);
361
362 void assoc_analyse(sctp_assoc_info_t* assoc);
363
364 const sctp_assoc_info_t* get_selected_assoc(void);
365
366 void create_graph(guint16 dir, struct sctp_analyse* u_data);
367
368 void create_byte_graph(guint16 dir, struct sctp_analyse* u_data);
369
370 void sctp_error_dlg_show(sctp_assoc_info_t* assoc);
371
372 void sctp_stat_dlg_update(void);
373
374 void sctp_chunk_stat_dlg_update(struct sctp_udata* udata, unsigned int direction);
375
376 void sctp_chunk_dlg_show(struct sctp_analyse* userdata);
377
378 void sctp_chunk_stat_dlg_show(unsigned int direction, struct sctp_analyse* userdata);
379
380 GtkWidget *get_stat_dlg(void);
381
382 GtkWidget *get_chunk_stat_dlg(void);
383
384 void update_analyse_dlg(struct sctp_analyse* u_data);
385
386 void sctp_analyse_start(GtkWidget *w _U_, gpointer data _U_);
387
388 void increase_childcount(struct sctp_analyse *parent);
389
390 void decrease_childcount(struct sctp_analyse *parent);
391
392 void set_child(struct sctp_udata *child, struct sctp_analyse *parent);
393
394 void remove_child(struct sctp_udata *child, struct sctp_analyse *parent);
395
396 void decrease_analyse_childcount(void);
397
398 void increase_analyse_childcount(void);
399
400 void set_analyse_child(struct sctp_analyse *child);
401
402 void remove_analyse_child(struct sctp_analyse *child);
403
404 void sctp_set_assoc_filter(void);
405  
406 #endif /* __SCTP_STAT_H__ */