Added graphical SCTP analysis implemented by Irene Ruengeler.
[obnox/wireshark/wip.git] / gtk / sctp_stat.h
1 /* 
2  * Copyright 2004, Irene Ruengeler <i.ruengeler [AT] fh-muenster.de>
3  *
4  * $Id: sctp_stat.h 11436 2004-07-19 21:42:01Z tuexen $
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 <sys/types.h>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
29
30 #define SCTP_DATA_CHUNK_ID               0
31 #define SCTP_INIT_CHUNK_ID               1
32 #define SCTP_INIT_ACK_CHUNK_ID           2
33 #define SCTP_SACK_CHUNK_ID               3
34
35 #define CHUNK_TYPE_LENGTH             1
36 #define CHUNK_FLAGS_LENGTH            1
37 #define CHUNK_LENGTH_LENGTH           2
38
39 #define CHUNK_HEADER_OFFSET           0
40 #define CHUNK_TYPE_OFFSET             CHUNK_HEADER_OFFSET
41 #define CHUNK_FLAGS_OFFSET            (CHUNK_TYPE_OFFSET + CHUNK_TYPE_LENGTH)
42 #define CHUNK_LENGTH_OFFSET           (CHUNK_FLAGS_OFFSET + CHUNK_FLAGS_LENGTH)
43 #define CHUNK_VALUE_OFFSET            (CHUNK_LENGTH_OFFSET + CHUNK_LENGTH_LENGTH)
44
45 #define INIT_CHUNK_INITIATE_TAG_LENGTH               4
46 #define INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH      4
47 #define INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH 2
48 #define INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH  2
49
50
51 #define INIT_CHUNK_INITIATE_TAG_OFFSET               CHUNK_VALUE_OFFSET
52 #define INIT_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET      (INIT_CHUNK_INITIATE_TAG_OFFSET + \
53                                                       INIT_CHUNK_INITIATE_TAG_LENGTH )
54 #define INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_OFFSET (INIT_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET + \
55                                                       INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH )
56 #define INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_OFFSET  (INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_OFFSET + \
57                                                       INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH )
58 #define INIT_CHUNK_INITIAL_TSN_OFFSET                (INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_OFFSET + \
59                                                       INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH )
60
61 #define DATA_CHUNK_TSN_LENGTH         4
62 #define DATA_CHUNK_TSN_OFFSET         (CHUNK_VALUE_OFFSET + 0)
63 #define DATA_CHUNK_STREAM_ID_OFFSET   (DATA_CHUNK_TSN_OFFSET + DATA_CHUNK_TSN_LENGTH)
64
65
66 typedef struct _v4address {
67         address_type    type;
68         int                             len;
69         guint32                 data;
70 }       v4address;
71
72 typedef struct _tsn {
73         guint32 frame_number;
74         guint32      secs;    /* Absolute seconds */
75         guint32      usecs;
76         struct sockaddr_storage src;
77         struct sockaddr_storage dst;
78         GList           *tsns;
79 } tsn_t;
80
81 typedef struct _sctp_tmp_info {
82         struct sockaddr_storage src;
83         struct sockaddr_storage dst;
84         guint16 port1;
85         guint16 port2;
86         guint32 verification_tag1;
87         guint32 verification_tag2;
88         guint32 n_tvbs;
89 }sctp_tmp_info_t;
90
91 typedef struct _sctp_min_max {
92         guint32 tmp_min_secs;
93         guint32         tmp_min_usecs;
94         guint32         tmp_max_secs;
95         guint32 tmp_max_usecs;
96         guint32 tmp_min_tsn1;
97         guint32 tmp_min_tsn2;
98         guint32 tmp_max_tsn1;
99         guint32 tmp_max_tsn2;
100         gint    tmp_secs;
101 } sctp_min_max_t;
102
103 struct tsn_sort{
104         guint32 tsnumber;
105         guint32 secs;
106         guint32 usecs;
107         guint32 offset;
108         guint32 length;
109 };
110
111
112 typedef struct _sctp_assoc_info {
113         //guint16       assoc_id;
114         struct sockaddr_storage src;
115         struct sockaddr_storage dst;
116         guint16 port1;
117         guint16 port2;
118         guint32 verification_tag1;
119         guint32 verification_tag2;
120         guint32 n_tvbs;
121         GList   *addr1;
122         GList   *addr2;
123         guint16 instream1;
124         guint16 outstream1;
125         guint16 instream2;
126         guint16 outstream2;
127         guint32 n_adler32_calculated;
128         guint32 n_adler32_correct;
129         guint32 n_crc32c_calculated;
130         guint32 n_crc32c_correct;
131         char checksum_type[8];
132         guint32 n_checksum_errors;
133         guint32 n_bundling_errors;
134         guint32 n_padding_errors;
135         guint32 n_length_errors;
136         guint32 n_value_errors;
137         guint32 n_data_chunks;
138         guint32 n_data_bytes;
139         guint32 n_packets;
140         guint32 n_data_chunks_ep1;
141         guint32 n_data_bytes_ep1;
142         guint32 n_data_chunks_ep2;
143         guint32 n_data_bytes_ep2;
144         guint32 n_sack_chunks_ep1;
145         guint32 n_sack_chunks_ep2;
146         guint32 n_array_tsn1;
147         guint32 n_array_tsn2;
148         guint32 max_window1;
149         guint32 max_window2;
150         gboolean init;
151         gboolean initack;
152         guint8 initack_dir;
153         guint8 direction;
154         guint32 min_secs;
155         guint32         min_usecs;
156         guint32         max_secs;
157         guint32 max_usecs;
158         guint32 min_tsn1;
159         guint32 min_tsn2;
160         guint32 max_tsn1;
161         guint32 max_tsn2;
162         guint32 max_bytes1;
163         guint32 max_bytes2;
164         GSList *min_max;
165         GList *frame_numbers;
166         GList *tsn1;
167         GArray *sort_tsn1;
168         GArray *sort_sack1;
169         GList *sack1;
170         GList *tsn2;
171         GArray *sort_tsn2;
172         GArray *sort_sack2;
173         GList *sack2;
174         gboolean check_address;
175         GList*  error_info_list;
176 } sctp_assoc_info_t;
177
178 typedef struct _sctp_error_info {
179         guint32 frame_number;
180         char    chunk_info[200];
181         char    *info_text;
182 }       sctp_error_info_t;
183
184
185 typedef struct _sctp_allassocs_info {
186 guint32 sum_tvbs;
187 GList*  assoc_info_list;
188 gboolean is_registered;
189 GList*  children;
190 } sctp_allassocs_info_t;
191
192
193 //Data structures for sctp_assoc_analyse
194
195 struct notes {
196         GtkWidget *checktype;
197         GtkWidget *checksum;
198         GtkWidget *bundling;
199         GtkWidget *padding;
200         GtkWidget *length;
201         GtkWidget *value;
202         GtkWidget *chunks_ep1;
203         GtkWidget *bytes_ep1;
204         GtkWidget *chunks_ep2;
205         GtkWidget *bytes_ep2;
206         struct page *page2;
207         struct page *page3;
208 };
209
210 struct page {
211         GtkWidget *addr_frame;
212         GtkWidget *scrolled_window;
213         GtkWidget *clist;
214         GtkWidget *port;
215         GtkWidget *veritag;
216         GtkWidget *max_in;
217         GtkWidget *min_in;
218         GtkWidget *max_out;
219         GtkWidget *min_out;
220 };
221
222 struct sctp_analyse {
223         sctp_assoc_info_t* assoc;
224         GtkWidget* window;
225         struct notes *analyse_nb;
226         GList *children;
227         guint16 num_children;
228 };
229
230 //Data Structures for sctp_graph_dlg
231
232 typedef struct _sctp_graph_t {
233         gboolean needs_redraw;
234         gfloat x_interval;
235         gfloat y_interval;
236         GtkWidget *window;
237         GtkWidget *draw_area;
238         GdkPixmap *pixmap;
239         int pixmap_width;
240         int pixmap_height;
241         int graph_type;
242         gdouble x_old;
243         gdouble y_old;
244         gdouble x_new;
245         gdouble y_new;
246         guint16 offset;
247         guint16 length;
248         gboolean tmp;
249         gboolean rectangle;
250         guint32 x1_tmp_sec;
251         guint32 x2_tmp_sec;
252         guint32 x1_tmp_usec;
253         guint32 x2_tmp_usec;
254         guint32 tmp_width;
255         guint32 axis_width;
256         guint32 y1_tmp;
257         guint32 y2_tmp;
258         guint32 tmp_min_tsn1;
259         guint32 tmp_max_tsn1;
260         guint32 tmp_min_tsn2;
261         guint32 tmp_max_tsn2;
262         guint32 min_x;
263         guint32 max_x;
264         guint32 min_y;
265         guint32 max_y;
266 } sctp_graph_t;
267
268
269
270 struct sctp_udata {
271         sctp_assoc_info_t * assoc;
272         sctp_graph_t *io;
273         struct sctp_analyse* parent;
274         guint16 dir;
275 };
276
277
278 void register_tap_listener_sctp_stat(void);
279
280 const sctp_allassocs_info_t* sctp_stat_get_info(void);
281
282 void sctp_stat_scan(void);
283
284 void remove_tap_listener_sctp_stat(void);
285
286 void reset(sctp_allassocs_info_t *tapdata _U_);
287
288
289 void assoc_analyse(sctp_assoc_info_t* assoc);
290
291 const sctp_assoc_info_t* get_selected_assoc(void);
292
293 void create_graph(guint16 dir, struct sctp_analyse* u_data);
294
295 void create_byte_graph(guint16 dir, struct sctp_analyse* u_data);
296
297 void sctp_error_dlg_show();
298
299 void sctp_stat_dlg_update(void);
300
301 GtkWidget *get_stat_dlg(void);
302
303 void update_analyse_dlg(struct sctp_analyse* u_data);
304
305 void sctp_analyse_start(GtkWidget *w _U_, gpointer data _U_);
306
307 void increase_childcount(struct sctp_analyse *parent);
308
309 void decrease_childcount(struct sctp_analyse *parent);
310
311 void set_child(struct sctp_udata *child, struct sctp_analyse *parent);
312
313 void remove_child(struct sctp_udata *child, struct sctp_analyse *parent);
314
315 void decrease_analyse_childcount();
316
317 void increase_analyse_childcount();
318
319 void set_analyse_child(struct sctp_analyse *child);
320
321 void remove_analyse_child(struct sctp_analyse *child);
322