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