60675579b9e946d40c85df251490626147dfe70a
[obnox/wireshark/wip.git] / packet-ospf.c
1 /* packet-ospf.c
2  * Routines for OSPF packet disassembly
3  * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
4  *
5  * $Id: packet-ospf.c,v 1.4 1998/09/29 21:34:44 hannes Exp $
6  *
7  * At this time, this module is able to analyze OSPF
8  * packets as specified in RFC2328. MOSPF (RFC1584) and other
9  * OSPF Extensions which introduce new Packet types
10  * (e.g the External Atributes LSA) are not supported.
11  *
12  * TOS - support is not fully implemented
13  * 
14  * Ethereal - Network traffic analyzer
15  * By Gerald Combs <gerald@zing.org>
16  * Copyright 1998 Gerald Combs
17  * 
18  * 
19  * This program is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU General Public License
21  * as published by the Free Software Foundation; either version 2
22  * of the License, or (at your option) any later version.
23  * 
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  * 
29  * You should have received a copy of the GNU General Public License
30  * along with this program; if not, write to the Free Software
31  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
32  */
33  
34 #ifdef HAVE_CONFIG_H
35 # include "config.h"
36 #endif
37
38 #include <gtk/gtk.h>
39
40 #include <stdio.h>
41
42 #ifdef HAVE_SYS_TYPES_H
43 # include <sys/types.h>
44 #endif
45
46 #ifdef HAVE_NETINET_IN_H
47 # include <netinet/in.h>
48 #endif
49
50 #include "ethereal.h"
51 #include "packet.h"
52 #include "packet-ospf.h"
53
54
55 void 
56 dissect_ospf(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
57     e_ospfhdr *ospfh;
58
59     GtkWidget *ospf_tree = NULL, *ti; 
60     GtkWidget *ospf_header_tree;
61     char auth_data[9]="";
62     char *packet_type;
63
64     ospfh = (e_ospfhdr *) &pd[offset];
65
66     switch(ospfh->packet_type) {
67         case OSPF_HELLO:
68             packet_type="Hello Packet";
69             break;
70         case OSPF_DB_DESC:
71             packet_type="DB Descr.";
72             break;
73         case OSPF_LS_REQ:
74             packet_type="LS Request";
75             break;
76         case OSPF_LS_UPD:
77             packet_type="LS Update";
78             break;
79         case OSPF_LS_ACK:
80             packet_type="LS Acknowledge";
81             break;
82        default:
83             /* XXX - set it to some string with the value of
84                "ospfh->packet_type"? */
85             break;
86     }
87     if (fd->win_info[COL_NUM]) {
88         strcpy(fd->win_info[COL_PROTOCOL], "OSPF");
89         sprintf(fd->win_info[COL_INFO], "%s", packet_type); 
90     }  
91
92     if (tree) {
93         ti = add_item_to_tree(GTK_WIDGET(tree), offset, ntohs(ospfh->length), "Open Shortest Path First"); 
94         ospf_tree = gtk_tree_new(); 
95         add_subtree(ti, ospf_tree, ETT_OSPF);
96
97         ti = add_item_to_tree(GTK_WIDGET(ospf_tree), offset, OSPF_HEADER_LENGTH, "OSPF Header"); 
98         ospf_header_tree = gtk_tree_new();
99         add_subtree(ti, ospf_header_tree, ETT_OSPF_HDR);
100
101         add_item_to_tree(ospf_header_tree, offset, 1, "OSPF Version: %d", ospfh->version);  
102         add_item_to_tree(ospf_header_tree, offset + 1 , 1, "OSPF Packet Type: %d (%s)", 
103                                                            ospfh->packet_type, packet_type);
104         add_item_to_tree(ospf_header_tree, offset + 2 , 2, "Packet Legth: %d", 
105                                                            ntohs(ospfh->length));
106         add_item_to_tree(ospf_header_tree, offset + 4 , 4, "Source OSPF Router ID: %s", 
107
108                                                            ip_to_str((guint8 *) &(ospfh->routerid)));
109         if (!(ospfh->area)) {
110            add_item_to_tree(ospf_header_tree, offset + 8 , 4, "Area ID: Backbone");
111         } else {
112            add_item_to_tree(ospf_header_tree, offset + 8 , 4, "Area ID: %s", ip_to_str((guint8 *) &(ospfh->area)));
113         }
114         add_item_to_tree(ospf_header_tree, offset + 12 , 2, "Packet Checksum");
115         switch( ntohs(ospfh->auth_type) ) {
116             case OSPF_AUTH_NONE:
117                  add_item_to_tree(ospf_header_tree, offset + 14 , 2, "Auth Type: none");
118                  add_item_to_tree(ospf_header_tree, offset + 16 , 8, "Auth Data (none)");
119                  break;
120             case OSPF_AUTH_SIMPLE:
121                  add_item_to_tree(ospf_header_tree, offset + 14 , 2, "Auth Type: simple");
122                  strncpy(auth_data, &(ospfh->auth_data), 8);
123                  add_item_to_tree(ospf_header_tree, offset + 16 , 8, "Auth Data: %s", auth_data);
124                  break;
125             case OSPF_AUTH_CRYPT:
126                  add_item_to_tree(ospf_header_tree, offset + 14 , 2, "Auth Type: crypt");
127                  add_item_to_tree(ospf_header_tree, offset + 16 , 8, "Auth Data (crypt)");
128                  break;
129             default:
130                  add_item_to_tree(ospf_header_tree, offset + 14 , 2, "Auth Type (unknown)");
131                  add_item_to_tree(ospf_header_tree, offset + 16 , 8, "Auth Data (unknown)");
132         }
133
134     }
135
136     /*  Skip over header */
137     offset += OSPF_HEADER_LENGTH;
138     switch(ospfh->packet_type){
139         case OSPF_HELLO:
140             dissect_ospf_hello(pd, offset, fd, (GtkTree *) ospf_tree); 
141             break;
142         case OSPF_DB_DESC:
143             dissect_ospf_db_desc(pd, offset, fd, (GtkTree *) ospf_tree);   
144             break;
145         case OSPF_LS_REQ:
146             dissect_ospf_ls_req(pd, offset, fd, (GtkTree *) ospf_tree);   
147             break;
148         case OSPF_LS_UPD:
149             dissect_ospf_ls_upd(pd, offset, fd, (GtkTree *) ospf_tree);
150             break;
151         case OSPF_LS_ACK:
152             dissect_ospf_ls_ack(pd, offset, fd, (GtkTree *) ospf_tree);
153             break;
154         default:
155             dissect_data(pd, offset, fd, tree); 
156     }
157 }
158
159 void
160 dissect_ospf_hello(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
161     e_ospf_hello *ospfhello;
162     guint32 *ospfneighbor;
163     char options[20]="";
164     int options_offset;
165
166     GtkWidget *ospf_hello_tree, *ti; 
167
168     ospfhello = (e_ospf_hello *) &pd[offset];
169
170     if (tree) {
171         ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset) , "OSPF Hello Packet"); 
172         ospf_hello_tree = gtk_tree_new(); 
173         add_subtree(ti, ospf_hello_tree, ETT_OSPF_HELLO);
174
175
176         add_item_to_tree(ospf_hello_tree, offset , 4, "Network Mask: %s",  ip_to_str((guint8 *) &ospfhello->network_mask));
177         add_item_to_tree(ospf_hello_tree, offset + 4, 2, "Hello Intervall: %d seconds",  ntohs(ospfhello->hellointervall));
178
179         /* ATTENTION !!! no check for length of options string */
180         options_offset=0;
181         if(( ospfhello->options & OSPF_OPTIONS_E ) == OSPF_OPTIONS_E){
182             strcpy( (char *)(options + options_offset), "E");
183             options_offset+=1;
184         }
185         if(( ospfhello->options & OSPF_OPTIONS_MC ) == OSPF_OPTIONS_MC){
186             strcpy((char *) (options + options_offset), "/MC");
187             options_offset+=3;
188         }
189         if(( ospfhello->options & OSPF_OPTIONS_NP ) == OSPF_OPTIONS_NP){
190             strcpy((char *) (options + options_offset), "/NP");
191             options_offset+=3;
192         }
193         if(( ospfhello->options & OSPF_OPTIONS_EA ) == OSPF_OPTIONS_EA){
194             strcpy((char *) (options + options_offset) , "/EA");
195             options_offset+=3;
196         }
197         if(( ospfhello->options & OSPF_OPTIONS_DC ) == OSPF_OPTIONS_DC){
198             strcpy((char *) (options + options_offset) , "/DC");
199             options_offset+=3;
200         }
201
202         add_item_to_tree(ospf_hello_tree, offset + 6, 1, "Options: %d (%s)",  ospfhello->options, options);
203         add_item_to_tree(ospf_hello_tree, offset + 7, 1, "Router Priority: %d",  ospfhello->priority);
204         add_item_to_tree(ospf_hello_tree, offset + 8, 4, "RouterDeadIntervall: %ld seconds",  (long)ntohl(ospfhello->dead_interval));
205         add_item_to_tree(ospf_hello_tree, offset + 12, 4, "Designated Router: %s",  ip_to_str((guint8 *) &ospfhello->drouter));
206         add_item_to_tree(ospf_hello_tree, offset + 16, 4, "Backup Designated Router: %s",  ip_to_str((guint8 *) &ospfhello->bdrouter));
207
208
209         offset+=20;
210         while(((int)(fd->cap_len - offset)) >= 4){
211             printf("%d", fd->cap_len - offset);
212             ospfneighbor=(guint32 *) &pd[offset];
213             add_item_to_tree(ospf_hello_tree, offset, 4, "Active Neighbor: %s",  ip_to_str((guint8 *) ospfneighbor));
214             offset+=4;
215         }
216     }
217 }
218
219 void
220 dissect_ospf_db_desc(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
221     e_ospf_dbd *ospf_dbd;
222     char options[20]="";
223     int options_offset;
224     char flags[20]="";
225     int flags_offset;
226
227     GtkWidget *ospf_db_desc_tree=NULL, *ti; 
228
229     ospf_dbd = (e_ospf_dbd *) &pd[offset]; 
230
231     if (tree) {
232         ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset) , "OSPF DB Description"); 
233         ospf_db_desc_tree = gtk_tree_new(); 
234         add_subtree(ti, ospf_db_desc_tree, ETT_OSPF_DESC);
235
236         add_item_to_tree(ospf_db_desc_tree, offset, 2, "Interface MTU: %d", ntohs(ospf_dbd->interface_mtu) );
237
238
239         options_offset=0;
240         if(( ospf_dbd->options & OSPF_OPTIONS_E ) == OSPF_OPTIONS_E){
241             strcpy( (char *)(options + options_offset), "_E_");
242             options_offset+=1;
243         }
244         if(( ospf_dbd->options & OSPF_OPTIONS_MC ) == OSPF_OPTIONS_MC){
245             strcpy((char *) (options + options_offset), "_MC_");
246             options_offset+=3;
247         }
248         if(( ospf_dbd->options & OSPF_OPTIONS_NP ) == OSPF_OPTIONS_NP){
249             strcpy((char *) (options + options_offset), "_NP_");
250             options_offset+=3;
251         }
252         if(( ospf_dbd->options & OSPF_OPTIONS_EA ) == OSPF_OPTIONS_EA){
253             strcpy((char *) (options + options_offset) , "_EA_");
254             options_offset+=3;
255         }
256         if(( ospf_dbd->options & OSPF_OPTIONS_DC ) == OSPF_OPTIONS_DC){
257             strcpy((char *) (options + options_offset) , "_DC_");
258             options_offset+=3;
259         }
260
261         add_item_to_tree(ospf_db_desc_tree, offset + 2 , 1, "Options: %d (%s)", ospf_dbd->options, options );
262
263
264         flags_offset=0;
265         if(( ospf_dbd->flags & OSPF_DBD_FLAG_MS ) == OSPF_DBD_FLAG_MS){
266             strcpy( (char *)(flags + flags_offset), "_I_");
267             flags_offset+=1;
268         }
269         if(( ospf_dbd->flags & OSPF_DBD_FLAG_M ) == OSPF_DBD_FLAG_M){
270             strcpy((char *) (flags + flags_offset), "_M_");
271             flags_offset+=3;
272         }
273         if(( ospf_dbd->flags & OSPF_DBD_FLAG_I ) == OSPF_DBD_FLAG_I){
274             strcpy((char *) (flags + flags_offset), "_I_");
275             flags_offset+=3;
276         }
277
278         add_item_to_tree(ospf_db_desc_tree, offset + 3 , 1, "Flags: %d (%s)", ospf_dbd->flags, flags );
279         add_item_to_tree(ospf_db_desc_tree, offset + 4 , 4, "DD Sequence: %ld", (long)ntohl(ospf_dbd->dd_sequence) );
280     }
281     /* LS Headers will be processed here */
282     /* skip to the end of DB-Desc header */
283     offset+=8;
284     while( ((int) (fd->cap_len - offset)) >= OSPF_LSA_HEADER_LENGTH ) {
285        dissect_ospf_lsa(pd, offset, fd, (GtkTree *) tree, FALSE);
286        offset+=OSPF_LSA_HEADER_LENGTH;
287     }
288 }
289
290 void
291 dissect_ospf_ls_req(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
292     e_ospf_ls_req *ospf_lsr;
293
294     GtkWidget *ospf_lsr_tree, *ti; 
295
296
297     /* zero or more LS requests may be within a LS Request */
298     /* we place every request for a LSA in a single subtree */
299     if (tree) {
300         while( ((int) ( fd->cap_len - offset)) >= OSPF_LS_REQ_LENGTH ){
301              ospf_lsr = (e_ospf_ls_req *) &pd[offset]; 
302              ti = add_item_to_tree(GTK_WIDGET(tree), offset, OSPF_LS_REQ_LENGTH, "Link State Request"); 
303              ospf_lsr_tree = gtk_tree_new(); 
304              add_subtree(ti, ospf_lsr_tree, ETT_OSPF_LSR);
305
306              switch( ntohl( ospf_lsr->ls_type ) ){
307                  case OSPF_LSTYPE_ROUTER:
308                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Router-LSA (%ld)", 
309                                        (long)ntohl( ospf_lsr->ls_type ) );
310                      break;
311                  case OSPF_LSTYPE_NETWORK:
312                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Network-LSA (%ld)", 
313                                        (long)ntohl( ospf_lsr->ls_type ) );
314                      break;
315                  case OSPF_LSTYPE_SUMMERY:
316                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Summary-LSA (IP network) (%ld)", 
317                                        (long)ntohl( ospf_lsr->ls_type ) );
318                      break;
319                  case OSPF_LSTYPE_ASBR:
320                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: Summary-LSA (ASBR) (%ld)", 
321                                        (long)ntohl( ospf_lsr->ls_type ) );
322                      break;
323                  case OSPF_LSTYPE_ASEXT:
324                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: AS-External-LSA (ASBR) (%ld)", 
325                                        (long)ntohl( ospf_lsr->ls_type ) );
326                      break;
327                  default:
328                      add_item_to_tree(ospf_lsr_tree, offset, 4, "LS Type: %ld (unknown)", 
329                                        (long)ntohl( ospf_lsr->ls_type ) );
330              }
331
332              add_item_to_tree(ospf_lsr_tree, offset + 4, 4, "Link State ID : %s", 
333                                          ip_to_str((guint8 *) &(ospf_lsr->ls_id)));
334              add_item_to_tree(ospf_lsr_tree, offset + 8, 4, "Advertising Router : %s", 
335                                          ip_to_str((guint8 *) &(ospf_lsr->adv_router)));
336
337              offset+=12;
338         }
339     }
340 }
341 void
342 dissect_ospf_ls_upd(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
343     e_ospf_lsa_upd_hdr *upd_hdr;
344     guint32 lsa_counter; 
345
346     GtkWidget *ospf_lsa_upd_tree=NULL, *ti; 
347
348     upd_hdr = (e_ospf_lsa_upd_hdr *) &pd[offset]; 
349
350     if (tree) {
351         ti = add_item_to_tree(GTK_WIDGET(tree), offset, (fd->cap_len - offset) , "LS Update Packet"); 
352         ospf_lsa_upd_tree = gtk_tree_new(); 
353         add_subtree(ti, ospf_lsa_upd_tree, ETT_OSPF_LSA_UPD);
354
355         add_item_to_tree(ospf_lsa_upd_tree, offset, 4, "Nr oF LSAs: %ld", (long)ntohl(upd_hdr->lsa_nr) );
356     }
357     /* skip to the beginning of the first LSA */
358     offset+=4; /* the LS Upd PAcket contains only a 32 bit #LSAs field */
359     
360     lsa_counter = 0;
361     while(lsa_counter < ntohl(upd_hdr->lsa_nr)){
362         offset+=dissect_ospf_lsa(pd, offset, fd, (GtkTree *) ospf_lsa_upd_tree, TRUE);
363         lsa_counter += 1;
364     }
365 }
366
367 void
368 dissect_ospf_ls_ack(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
369
370     /* the body of a LS Ack packet simply contains zero or more LSA Headers */
371     while( ((int)(fd->cap_len - offset)) >= OSPF_LSA_HEADER_LENGTH ) {
372        dissect_ospf_lsa(pd, offset, fd, (GtkTree *) tree, FALSE);
373        offset+=OSPF_LSA_HEADER_LENGTH;
374     }
375
376 }
377
378 int
379 dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, GtkTree *tree, int disassemble_body) {
380     e_ospf_lsa_hdr      *lsa_hdr;
381     char                *lsa_type;
382
383     /* data strutures for the router LSA */
384     e_ospf_router_lsa           *router_lsa;
385     e_ospf_router_data          *router_data;
386     e_ospf_router_metric        *tos_data;
387     guint16                     link_counter;
388     guint8                      tos_counter;
389     char                        *link_type;
390     char                        *link_id;
391
392     /* data structures for the network lsa */
393     e_ospf_network_lsa  *network_lsa;
394     guint32             *attached_router;
395
396     /* data structures for the summary and ASBR LSAs */
397     e_ospf_summary_lsa  *summary_lsa;
398
399     /* data structures for the AS-External LSA */
400     e_ospf_asexternal_lsa       asext_lsa;
401     guint32                   asext_metric;
402
403     GtkWidget *ospf_lsa_tree, *ti; 
404
405     lsa_hdr = (e_ospf_lsa_hdr *) &pd[offset]; 
406
407              
408
409     switch(lsa_hdr->ls_type) {
410         case OSPF_LSTYPE_ROUTER:
411             lsa_type="Router LSA";
412             break;
413         case OSPF_LSTYPE_NETWORK:
414             lsa_type="Network LSA";
415             break;
416         case OSPF_LSTYPE_SUMMERY:
417             lsa_type="Summery LSA";
418             break;
419         case OSPF_LSTYPE_ASBR:
420             lsa_type="ASBR LSA";
421             break;
422         case OSPF_LSTYPE_ASEXT:
423             lsa_type="AS-external-LSA";
424             break;
425         default:
426             lsa_type="unknown";
427     }
428
429     if (tree) {
430         if(disassemble_body){
431              ti = add_item_to_tree(GTK_WIDGET(tree), offset, ntohs(lsa_hdr->length), 
432                                                       "%s (Type: %d)", lsa_type, lsa_hdr->ls_type); 
433         } else {
434              ti = add_item_to_tree(GTK_WIDGET(tree), offset, OSPF_LSA_HEADER_LENGTH, "LSA Header"); 
435         }
436         ospf_lsa_tree = gtk_tree_new(); 
437         add_subtree(ti, ospf_lsa_tree, ETT_OSPF_LSA);
438
439         
440         add_item_to_tree(ospf_lsa_tree, offset, 2, "LS Age: %d seconds", ntohs(lsa_hdr->ls_age));
441         add_item_to_tree(ospf_lsa_tree, offset + 2, 1, "Options: %d ", lsa_hdr->options);
442         add_item_to_tree(ospf_lsa_tree, offset + 3, 1, "LSA Type: %d (%s)", lsa_hdr->ls_type, lsa_type);
443
444         add_item_to_tree(ospf_lsa_tree, offset + 4, 4, "Linke State ID: %s ", 
445                                                      ip_to_str((guint8 *) &(lsa_hdr->ls_id)));
446
447         add_item_to_tree(ospf_lsa_tree, offset + 8, 4, "Advertising Router: %s ", 
448                                                      ip_to_str((guint8 *) &(lsa_hdr->adv_router)));
449         add_item_to_tree(ospf_lsa_tree, offset + 12, 4, "LS Sequence Number: 0x%04lx ", 
450                                                      (unsigned long)ntohl(lsa_hdr->ls_seq));
451         add_item_to_tree(ospf_lsa_tree, offset + 16, 2, "LS Checksum: %d ", ntohs(lsa_hdr->ls_checksum));
452
453         add_item_to_tree(ospf_lsa_tree, offset + 18, 2, "Length: %d ", ntohs(lsa_hdr->length));
454
455         if(!disassemble_body){
456            return OSPF_LSA_HEADER_LENGTH;
457         }
458
459         /* the LSA body starts afte 20 bytes of LSA Header */
460         offset+=20;
461
462         switch(lsa_hdr->ls_type){
463             case(OSPF_LSTYPE_ROUTER):
464                 router_lsa = (e_ospf_router_lsa *) &pd[offset]; 
465
466                 /* again: flags should be secified in detail */
467                 add_item_to_tree(ospf_lsa_tree, offset, 1, "Flags: 0x%02x ", router_lsa->flags);
468                 add_item_to_tree(ospf_lsa_tree, offset + 2, 2, "Nr. of Links: %d ", 
469                                                                    ntohs(router_lsa->nr_links));
470                 offset += 4;
471                 /* router_lsa->nr_links links follow 
472                  * maybe we should put each of the links into its own subtree ???
473                  */
474                 for(link_counter = 1 ; link_counter <= ntohs(router_lsa->nr_links); link_counter++){
475
476                     router_data = (e_ospf_router_data *)  &pd[offset];
477                     /* check the Link Type and ID */
478                     switch(router_data->link_type) {
479                         case OSPF_LINK_PTP:
480                             link_type="Point-to-point connection to another router";
481                             link_id="Neighboring router's Router ID";
482                             break;
483                         case OSPF_LINK_TRANSIT:
484                             link_type="Connection to a transit network";
485                             link_id="IP address of Designated Router";
486                             break;
487                         case OSPF_LINK_STUB:
488                             link_type="Connection to a stub network";
489                             link_id="IP network/subnet number";
490                             break;
491                         case OSPF_LINK_VIRTUAL:
492                             link_type="Virtual link";
493                             link_id="Neighboring router's Router ID";
494                             break;
495                         default:
496                             link_type="unknown link type";
497                             link_id="unknown link id";
498                     }
499
500                     add_item_to_tree(ospf_lsa_tree, offset, 4, "%s: %s", link_id,
501                                                    ip_to_str((guint8 *) &(router_data->link_id)));
502
503                     /* link_data should be specified in detail (e.g. network mask) (depends on link type)*/
504                     add_item_to_tree(ospf_lsa_tree, offset + 4, 4, "Link Data: %s", 
505                                                    ip_to_str((guint8 *) &(router_data->link_data)));
506
507                     add_item_to_tree(ospf_lsa_tree, offset + 8, 1, "Link Type: %d - %s", 
508                                                               router_data->link_type, link_type);
509                     add_item_to_tree(ospf_lsa_tree, offset + 9, 1, "Nr. of TOS metrics: %d", router_data->nr_tos);
510                     add_item_to_tree(ospf_lsa_tree, offset + 10, 2, "TOS 0 metric: %d", ntohs( router_data->tos0_metric ));
511
512                     offset += 12;
513
514                     /* router_data->nr_tos metrics may follow each link 
515                      * ATTENTION: TOS metrics are not tested (I don't have TOS based routing)
516                      * please send me a mail if it is/isn't working
517                      */
518
519                     for(tos_counter = 1 ; link_counter <= ntohs(router_data->nr_tos); tos_counter++){
520                         tos_data = (e_ospf_router_metric *) &pd[offset];
521                         add_item_to_tree(ospf_lsa_tree, offset, 1, "TOS: %d, Metric: %d", 
522                                                 tos_data->tos, ntohs(tos_data->metric));
523                         offset += 4;
524                     }
525                 }
526                 break;
527             case(OSPF_LSTYPE_NETWORK):
528                 network_lsa = (e_ospf_network_lsa *) &pd[offset]; 
529                 add_item_to_tree(ospf_lsa_tree, offset, 4, "Netmask: %s", 
530                                                  ip_to_str((guint8 *) &(network_lsa->network_mask)));
531                 offset += 4;
532
533                 while( ((int) (fd->cap_len - offset)) >= 4){
534                     attached_router = (guint32 *) &pd[offset];
535                     add_item_to_tree(ospf_lsa_tree, offset, 4, "Attached Router: %s", 
536                                                  ip_to_str((guint8 *) attached_router));
537                     offset += 4;
538                 }
539                 break;
540             case(OSPF_LSTYPE_SUMMERY):
541                 /* Type 3 and 4 LSAs have the same format */
542             case(OSPF_LSTYPE_ASBR):
543                 summary_lsa = (e_ospf_summary_lsa *) &pd[offset]; 
544                 add_item_to_tree(ospf_lsa_tree, offset, 4, "Netmask: %s", 
545                                                  ip_to_str((guint8 *) &(summary_lsa->network_mask)));
546                 /* returns only the TOS 0 metric (even if there are more TOS metrics) */
547                 break;
548             case(OSPF_LSTYPE_ASEXT):
549                 summary_lsa = (e_ospf_summary_lsa *) &pd[offset]; 
550                 add_item_to_tree(ospf_lsa_tree, offset, 4, "Netmask: %s", 
551                                                   ip_to_str((guint8 *) &(summary_lsa->network_mask)));
552
553                 /* asext_lsa = (e_ospf_asexternal_lsa *) &pd[offset + 4]; */
554                 memcpy(&asext_lsa, &pd[offset + 4], sizeof(asext_lsa));
555                 if( (asext_lsa.options & 128) == 128 ) { /* check wether or not E bit is set */
556                    add_item_to_tree(ospf_lsa_tree, offset, 1, 
557                             "External Type: Type 2 (metric is larger than any other link state path)");
558                 } else {
559                    add_item_to_tree(ospf_lsa_tree, offset + 4, 1, 
560                             "External Type: Type 1 (metric is specified in the same units as interface cost)");
561                 }
562                 /* the metric field of a AS-external LAS is specified in 3 bytes -> not well aligned */
563                 /* this routine returns only the TOS 0 metric (even if there are more TOS metrics) */
564                 memcpy(&asext_metric, &pd[offset+4], 4); 
565                 
566                 /* erase the leading 8 bits (the dont belong to the metric */
567                 asext_metric = ntohl(asext_metric) & 0x00ffffff ;
568
569                 add_item_to_tree(ospf_lsa_tree, offset + 5,  3,"Metric: %d", asext_metric);
570                 add_item_to_tree(ospf_lsa_tree, offset + 8,  4,"Forwarding Address: %s", 
571                                                  ip_to_str((guint8 *) &(asext_lsa.gateway)));
572                 add_item_to_tree(ospf_lsa_tree, offset + 12, 4,"External Route Tag: %d", ntohl(asext_lsa.external_tag)); 
573                     
574                 break;
575             default:
576                /* unknown LSA type */
577                 add_item_to_tree(ospf_lsa_tree, offset, (fd->cap_len - offset), "Unknown LSA Type");
578         }
579     }
580     /* return the length of this LSA */
581     return ntohs(lsa_hdr->length);
582 }