Removed trailing whitespaces from .h and .c files using the
[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.69 2002/08/02 23:35:55 jmayer 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  * Furthermore RFC2740 (OSPFv3 - OSPF for IPv6) is now supported
12  *   - (c) 2001 Palle Lyckegaard <palle[AT]lyckegaard.dk>
13  *
14  * TOS - support is not fully implemented
15  * 
16  * Ethereal - Network traffic analyzer
17  * By Gerald Combs <gerald@ethereal.com>
18  * Copyright 1998 Gerald Combs
19  * 
20  * This program is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU General Public License
22  * as published by the Free Software Foundation; either version 2
23  * of the License, or (at your option) any later version.
24  * 
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  * 
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
33  */
34  
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include <stdio.h>
40 #include <string.h>
41
42 #include <glib.h>
43 #include <epan/packet.h>
44 #include "ipproto.h"
45 #include "in_cksum.h"
46 #include "packet-rsvp.h"
47
48 #define OSPF_VERSION_2 2
49 #define OSPF_VERSION_3 3
50 #define OSPF_VERSION_2_HEADER_LENGTH    24
51 #define OSPF_VERSION_3_HEADER_LENGTH    16
52
53
54 #define OSPF_HELLO      1
55 #define OSPF_DB_DESC    2
56 #define OSPF_LS_REQ     3
57 #define OSPF_LS_UPD     4
58 #define OSPF_LS_ACK     5
59
60 static const value_string pt_vals[] = {
61         {OSPF_HELLO,   "Hello Packet"   },
62         {OSPF_DB_DESC, "DB Descr."      },
63         {OSPF_LS_REQ,  "LS Request"     },
64         {OSPF_LS_UPD,  "LS Update"      },
65         {OSPF_LS_ACK,  "LS Acknowledge" },
66         {0,             NULL            }
67 };
68
69 #define OSPF_AUTH_NONE          0
70 #define OSPF_AUTH_SIMPLE        1
71 #define OSPF_AUTH_CRYPT         2
72
73 static const value_string auth_vals[] = {
74         {OSPF_AUTH_NONE,   "Null"            },
75         {OSPF_AUTH_SIMPLE, "Simple password" },
76         {OSPF_AUTH_CRYPT,  "Cryptographic"   },
77         {0,                NULL              }
78 };
79
80 #define OSPF_V2_OPTIONS_E               0x02
81 #define OSPF_V2_OPTIONS_MC              0x04
82 #define OSPF_V2_OPTIONS_NP              0x08
83 #define OSPF_V2_OPTIONS_EA              0x10
84 #define OSPF_V2_OPTIONS_DC              0x20
85 #define OSPF_V2_OPTIONS_O               0x40
86 #define OSPF_V2_OPTIONS_DN              0x01
87 #define OSPF_V3_OPTIONS_V6              0x01    
88 #define OSPF_V3_OPTIONS_E               0x02
89 #define OSPF_V3_OPTIONS_MC              0x04
90 #define OSPF_V3_OPTIONS_N               0x08
91 #define OSPF_V3_OPTIONS_R               0x10
92 #define OSPF_V3_OPTIONS_DC              0x20
93
94
95 #define OSPF_DBD_FLAG_MS        1
96 #define OSPF_DBD_FLAG_M         2
97 #define OSPF_DBD_FLAG_I         4
98
99 #define OSPF_LS_REQ_LENGTH      12
100
101 #define OSPF_LSTYPE_ROUTER      1
102 #define OSPF_LSTYPE_NETWORK     2
103 #define OSPF_LSTYPE_SUMMERY     3
104 #define OSPF_LSTYPE_ASBR        4
105 #define OSPF_LSTYPE_ASEXT       5
106 #define OSPF_LSTYPE_GRPMEMBER   6
107 #define OSPF_LSTYPE_ASEXT7      7
108 #define OSPF_LSTYPE_EXTATTR     8
109 #define OSPF_V3_LSTYPE_ROUTER                0x2001
110 #define OSPF_V3_LSTYPE_NETWORK               0x2002
111 #define OSPF_V3_LSTYPE_INTER_AREA_PREFIX     0x2003
112 #define OSPF_V3_LSTYPE_INTER_AREA_ROUTER     0x2004
113 #define OSPF_V3_LSTYPE_AS_EXTERNAL           0x4005
114 #define OSPF_V3_LSTYPE_GROUP_MEMBERSHIP      0x2006     
115 #define OSPF_V3_LSTYPE_TYPE_7                0x2007
116 #define OSPF_V3_LSTYPE_LINK                  0x0008
117 #define OSPF_V3_LSTYPE_INTRA_AREA_PREFIX     0x2009
118
119 /* Opaque LSA types */
120 #define OSPF_LSTYPE_OP_LINKLOCAL 9
121 #define OSPF_LSTYPE_OP_AREALOCAL 10
122 #define OSPF_LSTYPE_OP_ASWIDE    11
123
124 #define OSPF_LINK_PTP           1
125 #define OSPF_LINK_TRANSIT       2
126 #define OSPF_LINK_STUB          3
127 #define OSPF_LINK_VIRTUAL       4
128
129 #define OSPF_V3_LINK_PTP        1
130 #define OSPF_V3_LINK_TRANSIT    2
131 #define OSPF_V3_LINK_RESERVED   3
132 #define OSPF_V3_LINK_VIRTUAL    4
133
134 #define OSPF_LSA_HEADER_LENGTH  20
135
136 /* Known opaque LSAs */
137 #define OSPF_LSA_MPLS_TE        1
138
139
140 static const value_string ls_type_vals[] = {
141         {OSPF_LSTYPE_ROUTER,                  "Router-LSA"                   },
142         {OSPF_LSTYPE_NETWORK,                 "Network-LSA"                  },
143         {OSPF_LSTYPE_SUMMERY,                 "Summary-LSA (IP network)"     },
144         {OSPF_LSTYPE_ASBR,                    "Summary-LSA (ASBR)"           },
145         {OSPF_LSTYPE_ASEXT,                   "AS-External-LSA (ASBR)"       },
146         {OSPF_LSTYPE_GRPMEMBER,               "Group Membership LSA"         },
147         {OSPF_LSTYPE_ASEXT7,                  "NSSA AS-External-LSA"         },
148         {OSPF_LSTYPE_EXTATTR,                 "External Attributes LSA"      },
149         {OSPF_LSTYPE_OP_LINKLOCAL,            "Opaque LSA, Link-local scope" },
150         {OSPF_LSTYPE_OP_AREALOCAL,            "Opaque LSA, Area-local scope" },
151         {0,                                   NULL                           }
152
153 };
154
155 static const value_string ls_opaque_type_vals[] = {
156         {OSPF_LSA_MPLS_TE, "Traffic Engineering LSA"                },
157         {2,                "Sycamore Optical Topology Descriptions" },
158         {3,                "grace-LSA"                              },
159         {0,                NULL                                     }
160 };
161
162 static const value_string v3_ls_type_vals[] = {
163         {OSPF_V3_LSTYPE_ROUTER,               "Router-LSA"                   }, 
164         {OSPF_V3_LSTYPE_NETWORK,              "Network-LSA"                  }, 
165         {OSPF_V3_LSTYPE_INTER_AREA_PREFIX,    "Inter-Area-Prefix-LSA"        }, 
166         {OSPF_V3_LSTYPE_INTER_AREA_ROUTER,    "Inter-Area-Router-LSA"        }, 
167         {OSPF_V3_LSTYPE_AS_EXTERNAL,          "AS-External-LSA"              }, 
168         {OSPF_V3_LSTYPE_GROUP_MEMBERSHIP,     "Group-Membership-LSA"         }, 
169         {OSPF_V3_LSTYPE_TYPE_7,               "Type-LSA"                     }, 
170         {OSPF_V3_LSTYPE_LINK,                 "Link-LSA"                     },
171         {OSPF_V3_LSTYPE_INTRA_AREA_PREFIX,    "Intra-Area-Prefix-LSA"        },
172         {0,                                   NULL                           }
173
174 };
175
176
177 #define OSPF_V3_ROUTER_LSA_FLAG_B 0x01
178 #define OSPF_V3_ROUTER_LSA_FLAG_E 0x02
179 #define OSPF_V3_ROUTER_LSA_FLAG_V 0x04
180 #define OSPF_V3_ROUTER_LSA_FLAG_W 0x08
181
182 #define OSPF_V3_PREFIX_OPTION_NU 0x01
183 #define OSPF_V3_PREFIX_OPTION_LA 0x02
184 #define OSPF_V3_PREFIX_OPTION_MC 0x04
185 #define OSPF_V3_PREFIX_OPTION_P  0x08
186
187 #define OSPF_V3_AS_EXTERNAL_FLAG_T 0x01
188 #define OSPF_V3_AS_EXTERNAL_FLAG_F 0x02
189 #define OSPF_V3_AS_EXTERNAL_FLAG_E 0x04
190
191
192 static int proto_ospf = -1;
193
194 static gint ett_ospf = -1;
195 static gint ett_ospf_hdr = -1;
196 static gint ett_ospf_hello = -1;
197 static gint ett_ospf_desc = -1;
198 static gint ett_ospf_lsr = -1;
199 static gint ett_ospf_lsa = -1;
200 static gint ett_ospf_lsa_upd = -1;
201
202 /* Trees for opaque LSAs */
203 static gint ett_ospf_lsa_mpls = -1;
204 static gint ett_ospf_lsa_mpls_router = -1;
205 static gint ett_ospf_lsa_mpls_link = -1;
206 static gint ett_ospf_lsa_mpls_link_stlv = -1;
207
208 /*-----------------------------------------------------------------------
209  * OSPF Filtering
210  *-----------------------------------------------------------------------*/
211
212 /* The OSPF filtering keys */
213 enum {
214
215     OSPFF_MSG_TYPE,
216
217     OSPFF_MSG_MIN,
218     OSPFF_MSG_HELLO,
219     OSPFF_MSG_DB_DESC,
220     OSPFF_MSG_LS_REQ,
221     OSPFF_MSG_LS_UPD,
222     OSPFF_MSG_LS_ACK,
223     
224     OSPFF_LS_TYPE,
225     OSPFF_LS_OPAQUE_TYPE,
226
227     OSPFF_LS_MPLS_TE_INSTANCE,
228
229     OSPFF_LS_MIN,
230     OSPFF_LS_ROUTER,
231     OSPFF_LS_NETWORK,
232     OSPFF_LS_SUMMARY,
233     OSPFF_LS_ASBR,
234     OSPFF_LS_ASEXT,
235     OSPFF_LS_GRPMEMBER,
236     OSPFF_LS_ASEXT7,
237     OSPFF_LS_EXTATTR,
238     OSPFF_LS_OPAQUE,
239
240     OSPFF_SRC_ROUTER,
241     OSPFF_ADV_ROUTER,
242     OSPFF_LS_MPLS,
243     OSPFF_LS_MPLS_ROUTERID,
244
245     OSPFF_LS_MPLS_LINKID,
246     OSPFF_LS_MPLS_LOCAL_ADDR,
247     OSPFF_LS_MPLS_REMOTE_ADDR,
248     OSPFF_LS_MPLS_LOCAL_IFID,
249     OSPFF_LS_MPLS_REMOTE_IFID,
250
251     OSPFF_MAX
252 };
253
254 static int ospf_filter[OSPFF_MAX];
255
256 static hf_register_info ospff_info[] = {
257
258     /* Message type number */
259     {&ospf_filter[OSPFF_MSG_TYPE], 
260      { "Message Type", "ospf.msg", FT_UINT8, BASE_DEC, VALS(pt_vals), 0x0,
261         "", HFILL }},
262
263     /* Message types */
264     {&ospf_filter[OSPFF_MSG_HELLO], 
265      { "Hello", "ospf.msg.hello", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
266         "", HFILL }},
267     {&ospf_filter[OSPFF_MSG_DB_DESC], 
268      { "Database Description", "ospf.msg.dbdesc", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
269         "", HFILL }},
270     {&ospf_filter[OSPFF_MSG_LS_REQ], 
271      { "Link State Adv Request", "ospf.msg.lsreq", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
272         "", HFILL }},
273     {&ospf_filter[OSPFF_MSG_LS_UPD], 
274      { "Link State Adv Update", "ospf.msg.lsupdate", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
275         "", HFILL }},
276     {&ospf_filter[OSPFF_MSG_LS_ACK], 
277      { "Link State Adv Acknowledgement", "ospf.msg.lsack", FT_BOOLEAN, 
278        BASE_NONE, NULL, 0x0, "", HFILL }},
279
280
281
282     /* LS Types */
283     {&ospf_filter[OSPFF_LS_TYPE], 
284      { "Link-State Advertisement Type", "ospf.lsa", FT_UINT8, BASE_DEC, 
285        VALS(ls_type_vals), 0x0, "", HFILL }},
286     {&ospf_filter[OSPFF_LS_OPAQUE_TYPE], 
287      { "Link State ID Opaque Type", "ospf.lsid_opaque_type", FT_UINT8, BASE_DEC, 
288        VALS(ls_opaque_type_vals), 0x0, "", HFILL }},
289
290     {&ospf_filter[OSPFF_LS_MPLS_TE_INSTANCE], 
291      { "Link State ID TE-LSA Instance", "ospf.lsid_te_lsa.instance", FT_UINT16, BASE_DEC, 
292        NULL, 0x0, "", HFILL }},
293
294     {&ospf_filter[OSPFF_LS_ROUTER], 
295      { "Router LSA", "ospf.lsa.router", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
296         "", HFILL }},
297     {&ospf_filter[OSPFF_LS_NETWORK], 
298      { "Network LSA", "ospf.lsa.network", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
299         "", HFILL }},
300     {&ospf_filter[OSPFF_LS_SUMMARY], 
301      { "Summary LSA (IP Network)", "ospf.lsa.summary", FT_BOOLEAN, BASE_NONE, 
302        NULL, 0x0, "", HFILL }},
303     {&ospf_filter[OSPFF_LS_ASBR], 
304      { "Summary LSA (ASBR)", "ospf.lsa.asbr", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
305         "", HFILL }},
306     {&ospf_filter[OSPFF_LS_ASEXT], 
307      { "AS-External LSA (ASBR)", "ospf.lsa.asext", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
308         "", HFILL }},
309     {&ospf_filter[OSPFF_LS_GRPMEMBER], 
310      { "Group Membership LSA", "ospf.lsa.member", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
311         "", HFILL }},
312     {&ospf_filter[OSPFF_LS_ASEXT7], 
313      { "NSSA AS-External LSA", "ospf.lsa.nssa", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
314         "", HFILL }},
315     {&ospf_filter[OSPFF_LS_EXTATTR], 
316      { "External Attributes LSA", "ospf.lsa.attr", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
317         "", HFILL }},
318     {&ospf_filter[OSPFF_LS_OPAQUE], 
319      { "Opaque LSA", "ospf.lsa.opaque", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
320         "", HFILL }},
321
322     /* Other interesting OSPF values */
323
324     {&ospf_filter[OSPFF_SRC_ROUTER], 
325      { "Source OSPF Router", "ospf.srcrouter", FT_IPv4, BASE_NONE, NULL, 0x0, 
326        "", HFILL }}, 
327
328     {&ospf_filter[OSPFF_ADV_ROUTER], 
329      { "Advertising Router", "ospf.advrouter", FT_IPv4, BASE_NONE, NULL, 0x0, 
330        "", HFILL }}, 
331
332    {&ospf_filter[OSPFF_LS_MPLS], 
333      { "MPLS Traffic Engineering LSA", "ospf.lsa.mpls", FT_BOOLEAN, 
334        BASE_NONE, NULL, 0x0, "", HFILL }},
335
336     {&ospf_filter[OSPFF_LS_MPLS_ROUTERID], 
337      { "MPLS/TE Router ID", "ospf.mpls.routerid", FT_IPv4, BASE_NONE, NULL, 0x0, 
338        "", HFILL }},
339
340     {&ospf_filter[OSPFF_LS_MPLS_LINKID], 
341      { "MPLS/TE Link ID", "ospf.mpls.linkid", FT_IPv4, BASE_NONE, NULL, 0x0, 
342        "", HFILL }},
343     {&ospf_filter[OSPFF_LS_MPLS_LOCAL_ADDR], 
344      { "MPLS/TE Local Interface Address", "ospf.mpls.local_addr", FT_IPv4, 
345        BASE_NONE, NULL, 0x0, "", HFILL }},
346     {&ospf_filter[OSPFF_LS_MPLS_REMOTE_ADDR], 
347      { "MPLS/TE Remote Interface Address", "ospf.mpls.remote_addr", FT_IPv4, 
348        BASE_NONE, NULL, 0x0, "", HFILL }},
349     {&ospf_filter[OSPFF_LS_MPLS_LOCAL_IFID], 
350      { "MPLS/TE Local Interface Index", "ospf.mpls.local_id", FT_UINT32, 
351        BASE_DEC, NULL, 0x0, "", HFILL }},
352     {&ospf_filter[OSPFF_LS_MPLS_REMOTE_IFID], 
353      { "MPLS/TE Remote Interface Index", "ospf.mpls.remote_id", FT_UINT32, 
354        BASE_DEC, NULL, 0x0, "", HFILL }},
355
356
357
358 };
359
360 static guint8 ospf_msg_type_to_filter (guint8 msg_type)
361 {
362     if (msg_type >= OSPF_HELLO && 
363         msg_type <= OSPF_LS_ACK) 
364         return msg_type + OSPFF_MSG_MIN;
365     return -1;
366 }
367
368 static guint8 ospf_ls_type_to_filter (guint8 ls_type)
369 {
370     if (ls_type >= OSPF_LSTYPE_ROUTER && 
371         ls_type <= OSPF_LSTYPE_EXTATTR) 
372         return OSPFF_LS_MIN + ls_type;
373     else if (ls_type >= OSPF_LSTYPE_OP_LINKLOCAL && 
374              ls_type <= OSPF_LSTYPE_OP_ASWIDE)
375         return OSPFF_LS_OPAQUE;
376     else
377         return -1;
378 }
379
380 static dissector_handle_t data_handle;
381
382 static void dissect_ospf_hello(tvbuff_t*, int, proto_tree*, guint8);
383 static void dissect_ospf_db_desc(tvbuff_t*, int, proto_tree*, guint8); 
384 static void dissect_ospf_ls_req(tvbuff_t*, int, proto_tree*, guint8); 
385 static void dissect_ospf_ls_upd(tvbuff_t*, int, proto_tree*, guint8); 
386 static void dissect_ospf_ls_ack(tvbuff_t*, int, proto_tree*, guint8); 
387
388 /* dissect_ospf_v[23]lsa returns the offset of the next LSA
389  * if disassemble_body is set to FALSE (e.g. in LSA ACK 
390  * packets), the offset is set to the offset of the next
391  * LSA header
392  */
393 static int dissect_ospf_v2_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body); 
394 static int dissect_ospf_v3_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body); 
395
396 static void dissect_ospf_options(tvbuff_t *, int, proto_tree *, guint8);
397
398 static void dissect_ospf_v3_prefix_options(tvbuff_t *, int, proto_tree *);
399
400 static void dissect_ospf_v3_address_prefix(tvbuff_t *, int, int, proto_tree *);
401
402 static void 
403 dissect_ospf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
404 {
405     proto_tree *ospf_tree = NULL;
406     proto_item *ti; 
407     proto_tree *ospf_header_tree;
408     guint8  version;
409     guint8  packet_type;
410     guint16 ospflen;
411     vec_t cksum_vec[4];
412     int cksum_vec_len;
413     guint32 phdr[2];
414     guint16 cksum, computed_cksum;
415     guint length, reported_length;
416     guint16 auth_type;
417     char auth_data[8];
418     int crypto_len;
419     unsigned int ospf_header_length;
420     guint8 instance_ID;
421     guint8 reserved;
422     guint32 areaid;
423
424
425     if (check_col(pinfo->cinfo, COL_PROTOCOL))
426         col_set_str(pinfo->cinfo, COL_PROTOCOL, "OSPF");
427     if (check_col(pinfo->cinfo, COL_INFO))
428         col_clear(pinfo->cinfo, COL_INFO);
429
430     version = tvb_get_guint8(tvb, 0);
431     switch (version) {
432         case OSPF_VERSION_2:
433             ospf_header_length = OSPF_VERSION_2_HEADER_LENGTH;
434             break;
435         case OSPF_VERSION_3:
436             ospf_header_length = OSPF_VERSION_3_HEADER_LENGTH;
437             break;
438         default:
439             ospf_header_length = 0;
440             break;
441     }
442
443     packet_type = tvb_get_guint8(tvb, 1);
444     if (check_col(pinfo->cinfo, COL_INFO)) {
445         col_add_str(pinfo->cinfo, COL_INFO,
446                     val_to_str(packet_type, pt_vals, "Unknown (%u)"));
447     }  
448
449     if (tree) {
450         ospflen = tvb_get_ntohs(tvb, 2);
451
452         ti = proto_tree_add_item(tree, proto_ospf, tvb, 0, ospflen, FALSE);
453         ospf_tree = proto_item_add_subtree(ti, ett_ospf);
454
455         ti = proto_tree_add_text(ospf_tree, tvb, 0, ospf_header_length,
456                                  "OSPF Header"); 
457         ospf_header_tree = proto_item_add_subtree(ti, ett_ospf_hdr);
458
459         proto_tree_add_text(ospf_header_tree, tvb, 0, 1, "OSPF Version: %u",
460                             version);  
461         proto_tree_add_item(ospf_header_tree, ospf_filter[OSPFF_MSG_TYPE], 
462                             tvb, 1, 1, FALSE);
463         proto_tree_add_item_hidden(ospf_header_tree, 
464                                    ospf_filter[ospf_msg_type_to_filter(packet_type)],
465                                    tvb, 1, 1, FALSE);
466         proto_tree_add_text(ospf_header_tree, tvb, 2, 2, "Packet Length: %u",
467                             ospflen);
468         proto_tree_add_item(ospf_header_tree, ospf_filter[OSPFF_SRC_ROUTER], 
469                             tvb, 4, 4, FALSE);
470         areaid=tvb_get_ntohl(tvb,8);
471         proto_tree_add_text(ospf_header_tree, tvb, 8, 4, "Area ID: %s%s",
472                                ip_to_str(tvb_get_ptr(tvb, 8, 4)), areaid == 0 ? " (Backbone)" : "");
473         cksum = tvb_get_ntohs(tvb, 12);
474         length = tvb_length(tvb);
475         /* XXX - include only the length from the OSPF header? */
476         reported_length = tvb_reported_length(tvb);
477         if (cksum == 0) {
478                 /* No checksum supplied in the packet. */
479                 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
480                     "Packet Checksum: 0x%04x (none)", cksum);
481         } else if (!pinfo->fragmented && length >= reported_length
482                 && length >= ospf_header_length
483                 && (version == OSPF_VERSION_2 || version == OSPF_VERSION_3)) {
484             /* The packet isn't part of a fragmented datagram and isn't
485                truncated, and we know how to checksum this version of
486                OSPF, so we can checksum it. */
487
488             switch (version) {
489
490             case OSPF_VERSION_2:
491                 /* Header, not including the authentication data (the OSPFv2
492                    checksum excludes the 64-bit authentication field). */
493                 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, 16);
494                 cksum_vec[0].len = 16;
495                 if (length > ospf_header_length) {
496                     /* Rest of the packet, again not including the
497                        authentication data. */
498                     reported_length -= ospf_header_length;
499                     cksum_vec[1].ptr = tvb_get_ptr(tvb, ospf_header_length, reported_length);
500                     cksum_vec[1].len = reported_length;
501                     cksum_vec_len = 2;
502                 } else {
503                     /* There's nothing but a header. */
504                     cksum_vec_len = 1;
505                 }
506                 break;
507
508             case OSPF_VERSION_3:
509                 /* IPv6-style checksum, covering the entire OSPF packet
510                    and a prepended IPv6 pseudo-header. */
511
512                 /* Set up the fields of the pseudo-header. */
513                 cksum_vec[0].ptr = pinfo->src.data;
514                 cksum_vec[0].len = pinfo->src.len;
515                 cksum_vec[1].ptr = pinfo->dst.data;
516                 cksum_vec[1].len = pinfo->dst.len;
517                 cksum_vec[2].ptr = (const guint8 *)&phdr;
518                 phdr[0] = g_htonl(ospflen);
519                 phdr[1] = g_htonl(IP_PROTO_OSPF);
520                 cksum_vec[2].len = 8;
521
522                 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, reported_length);
523                 cksum_vec[3].len = reported_length;
524                 cksum_vec_len = 4;
525                 break;
526
527             default:
528                 g_assert_not_reached();
529                 cksum_vec_len = 0;
530             }
531             computed_cksum = in_cksum(cksum_vec, cksum_vec_len);
532             if (computed_cksum == 0) {
533                 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
534                         "Packet Checksum: 0x%04x (correct)", cksum);
535             } else {
536                 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
537                         "Packet Checksum: 0x%04x (incorrect, should be 0x%04x)",
538                         cksum, in_cksum_shouldbe(cksum, computed_cksum));
539             }
540         } else {
541             proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
542                 "Packet Checksum: 0x%04x", cksum);
543         }
544
545
546         /* Authentication is only valid for OSPFv2 */
547         if ( version == OSPF_VERSION_2 ) {        
548             auth_type = tvb_get_ntohs(tvb, 14);
549             proto_tree_add_text(ospf_header_tree, tvb, 14, 2, "Auth Type: %s",
550                             val_to_str(auth_type, auth_vals, "Unknown (%u)"));
551             switch (auth_type) {
552
553             case OSPF_AUTH_NONE:
554                 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data (none)");
555                 break;
556
557             case OSPF_AUTH_SIMPLE:
558                 tvb_get_nstringz0(tvb, 16, 8, auth_data);
559                 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data: %s", auth_data);
560                 break;
561
562             case OSPF_AUTH_CRYPT:
563                 proto_tree_add_text(ospf_header_tree, tvb, 18, 1, "Auth Key ID: %u",
564                                 tvb_get_guint8(tvb, 18));
565                 crypto_len = tvb_get_guint8(tvb, 19);
566                 proto_tree_add_text(ospf_header_tree, tvb, 19, 1, "Auth Data Length: %u",
567                                 crypto_len);
568                 proto_tree_add_text(ospf_header_tree, tvb, 20, 4, "Auth Crypto Sequence Number: 0x%x",
569                                 tvb_get_ntohl(tvb, 20));
570   
571                 /* Show the message digest that was appended to the end of the
572                    OSPF message - but only if it's present (we don't want
573                    to get an exception before we've tried dissecting OSPF
574                    message). */
575                 if (tvb_bytes_exist(tvb, ospflen, crypto_len)) {
576                     proto_tree_add_text(ospf_header_tree, tvb, ospflen, crypto_len,
577                                     "Auth Data: %s",
578                                     tvb_bytes_to_str(tvb, ospflen, crypto_len));
579                 }
580                 break;
581
582             default:
583                 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data (unknown)");
584                 break;
585             }
586
587         }
588
589         /* Instance ID and "reserved" is OSPFv3-only */
590         if ( version == OSPF_VERSION_3 ) {
591             instance_ID = tvb_get_guint8(tvb, 14);
592             proto_tree_add_text(ospf_header_tree, tvb, 14, 1, "Instance ID: %u",
593                             instance_ID);
594             reserved = tvb_get_guint8(tvb, 15);
595             proto_tree_add_text(ospf_header_tree, tvb, 15, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
596                                 reserved);
597
598         }
599
600         /* Adjust the length of the tvbuff to match the size of the OSPF
601          * packet (since the dissect routines use it to work out where the
602          * end of the OSPF packet is).
603          */
604         tvb_set_reported_length(tvb, ospflen);
605
606         switch (packet_type){
607
608         case OSPF_HELLO:
609             dissect_ospf_hello(tvb, ospf_header_length, ospf_tree, version);
610             break;
611
612         case OSPF_DB_DESC:
613             dissect_ospf_db_desc(tvb, ospf_header_length, ospf_tree, version);
614             break;
615
616         case OSPF_LS_REQ:
617             dissect_ospf_ls_req(tvb, ospf_header_length, ospf_tree, version);
618             break;
619
620         case OSPF_LS_UPD:
621             dissect_ospf_ls_upd(tvb, ospf_header_length, ospf_tree, version);
622             break;
623
624         case OSPF_LS_ACK:
625             dissect_ospf_ls_ack(tvb, ospf_header_length, ospf_tree, version);
626             break;
627
628         default:
629             call_dissector(data_handle,
630                 tvb_new_subset(tvb, ospf_header_length, -1, -1), pinfo, tree);
631             break;
632         }
633     }
634 }
635
636 static void
637 dissect_ospf_hello(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
638 {
639     proto_tree *ospf_hello_tree;
640     proto_item *ti; 
641
642     ti = proto_tree_add_text(tree, tvb, offset, -1, "OSPF Hello Packet");
643     ospf_hello_tree = proto_item_add_subtree(ti, ett_ospf_hello);
644     
645     switch (version ) {
646         case OSPF_VERSION_2:
647             proto_tree_add_text(ospf_hello_tree, tvb, offset, 4, "Network Mask: %s",
648                         ip_to_str(tvb_get_ptr(tvb, offset, 4)));
649             proto_tree_add_text(ospf_hello_tree, tvb, offset + 4, 2,
650                         "Hello Interval: %u seconds",
651                         tvb_get_ntohs(tvb, offset + 4));
652
653             dissect_ospf_options(tvb, offset + 6, ospf_hello_tree, version);
654             proto_tree_add_text(ospf_hello_tree, tvb, offset + 7, 1, "Router Priority: %u",
655                         tvb_get_guint8(tvb, offset + 7));
656             proto_tree_add_text(ospf_hello_tree, tvb, offset + 8, 4, "Router Dead Interval: %u seconds",
657                         tvb_get_ntohl(tvb, offset + 8));
658             proto_tree_add_text(ospf_hello_tree, tvb, offset + 12, 4, "Designated Router: %s",
659                         ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
660             proto_tree_add_text(ospf_hello_tree, tvb, offset + 16, 4, "Backup Designated Router: %s",
661                         ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
662
663             offset += 20;
664             while (tvb_reported_length_remaining(tvb, offset) != 0) {
665                 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4,
666                             "Active Neighbor: %s",
667                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
668                 offset += 4;
669             }
670             break;
671         case OSPF_VERSION_3:
672             proto_tree_add_text(ospf_hello_tree, tvb, offset + 0, 4, "Interface ID: %u",
673                         tvb_get_ntohl(tvb, offset + 0));
674             proto_tree_add_text(ospf_hello_tree, tvb, offset + 4, 1, "Router Priority: %u",
675                         tvb_get_guint8(tvb, offset + 4));
676             dissect_ospf_options(tvb, offset + 5, ospf_hello_tree, version);
677             proto_tree_add_text(ospf_hello_tree, tvb, offset + 8, 2,
678                         "Hello Interval: %u seconds",
679                         tvb_get_ntohs(tvb, offset + 8));
680             proto_tree_add_text(ospf_hello_tree, tvb, offset + 10, 2, "Router Dead Interval: %u seconds",
681                         tvb_get_ntohs(tvb, offset + 10));
682             proto_tree_add_text(ospf_hello_tree, tvb, offset + 12, 4, "Designated Router: %s",
683                         ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
684             proto_tree_add_text(ospf_hello_tree, tvb, offset + 16, 4, "Backup Designated Router: %s",
685                         ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
686             offset += 20;
687             while (tvb_reported_length_remaining(tvb, offset) != 0) {
688                 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4,
689                             "Active Neighbor: %s",
690                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
691                 offset += 4;
692             }
693
694             break;
695
696         default:    
697             break;
698     }
699 }
700
701 static void
702 dissect_ospf_db_desc(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
703 {
704     proto_tree *ospf_db_desc_tree=NULL;
705     proto_item *ti; 
706     guint8 flags;
707     guint8 reserved;
708     char flags_string[20] = "";
709
710     if (tree) {
711         ti = proto_tree_add_text(tree, tvb, offset, -1, "OSPF DB Description"); 
712         ospf_db_desc_tree = proto_item_add_subtree(ti, ett_ospf_desc);
713
714         switch (version ) {
715  
716             case OSPF_VERSION_2:
717
718                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset, 2, "Interface MTU: %u",
719                             tvb_get_ntohs(tvb, offset));
720
721                 dissect_ospf_options(tvb, offset + 2, ospf_db_desc_tree, version);
722
723                 flags = tvb_get_guint8(tvb, offset + 3);
724                 if (flags & OSPF_DBD_FLAG_MS)
725                     strcat(flags_string, "MS");
726                 if (flags & OSPF_DBD_FLAG_M) {
727                     if (flags_string[0] != '\0')
728                         strcat(flags_string, "/");
729                     strcat(flags_string, "M");
730                 }
731                 if (flags & OSPF_DBD_FLAG_I) {
732                     if (flags_string[0] != '\0')
733                         strcat(flags_string, "/");
734                     strcat(flags_string, "I");
735                 }
736                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 3, 1, "Flags: 0x%x (%s)",
737                             flags, flags_string);
738                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 4, 4, "DD Sequence: %u",
739                             tvb_get_ntohl(tvb, offset + 4));
740
741                 offset += 8;
742                 break;
743
744             case OSPF_VERSION_3:
745
746                 reserved = tvb_get_guint8(tvb, offset);
747                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
748                                 reserved);
749
750                 dissect_ospf_options(tvb, offset + 1, ospf_db_desc_tree, version);
751
752                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 4, 2, "Interface MTU: %u",
753                             tvb_get_ntohs(tvb, offset+4));
754
755                 reserved = tvb_get_guint8(tvb, offset + 6);
756                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 6, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
757                                 reserved);
758
759                 flags = tvb_get_guint8(tvb, offset + 7);
760                 if (flags & OSPF_DBD_FLAG_MS)
761                     strcat(flags_string, "MS");
762                 if (flags & OSPF_DBD_FLAG_M) {
763                     if (flags_string[0] != '\0')
764                         strcat(flags_string, "/");
765                     strcat(flags_string, "M");
766                 }
767                 if (flags & OSPF_DBD_FLAG_I) {
768                     if (flags_string[0] != '\0')
769                         strcat(flags_string, "/");
770                     strcat(flags_string, "I");
771                 }
772                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 7, 1, "Flags: 0x%x (%s)",
773                             flags, flags_string);
774
775                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 8, 4, "DD Sequence: %u",
776                             tvb_get_ntohl(tvb, offset + 8));
777
778                 offset += 12;
779                 break;
780
781             default:
782                 break;
783         }
784     }
785
786     /* LS Headers will be processed here */
787     /* skip to the end of DB-Desc header */
788     while (tvb_reported_length_remaining(tvb, offset) != 0) {
789       if ( version == OSPF_VERSION_2)
790           offset = dissect_ospf_v2_lsa(tvb, offset, tree, FALSE);
791       else
792           if ( version == OSPF_VERSION_3)
793               offset = dissect_ospf_v3_lsa(tvb, offset, tree, FALSE);
794     }
795
796 }
797
798 static void
799 dissect_ospf_ls_req(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
800 {
801     proto_tree *ospf_lsr_tree;
802     proto_item *ti;
803     guint32 ls_type;
804     guint8 reserved;
805
806     /* zero or more LS requests may be within a LS Request */
807     /* we place every request for a LSA in a single subtree */
808     while (tvb_reported_length_remaining(tvb, offset) != 0) {
809         ti = proto_tree_add_text(tree, tvb, offset, OSPF_LS_REQ_LENGTH,
810                                  "Link State Request"); 
811         ospf_lsr_tree = proto_item_add_subtree(ti, ett_ospf_lsr);
812       
813         switch ( version ) {
814
815             case OSPF_VERSION_2:
816                 ls_type = tvb_get_ntohl(tvb, offset);
817                 proto_tree_add_item(ospf_lsr_tree, ospf_filter[OSPFF_LS_TYPE], 
818                                     tvb, offset, 4, FALSE);
819                 break;
820             case OSPF_VERSION_3:
821                 reserved = tvb_get_ntohs(tvb, offset);
822                 proto_tree_add_text(ospf_lsr_tree, tvb, offset, 2,
823                     (reserved == 0 ? "Reserved: %u" :  "Reserved: %u (incorrect, should be 0)"), reserved);
824                 ls_type = tvb_get_ntohs(tvb, offset+2);
825                 proto_tree_add_text(ospf_lsr_tree, tvb, offset+2, 2, "LS Type: %s (0x%04x)",
826                             val_to_str(ls_type, v3_ls_type_vals, "Unknown"),
827                             ls_type);
828                   break;
829             default:
830                  ls_type=0;
831                  break;
832         }
833
834
835         proto_tree_add_text(ospf_lsr_tree, tvb, offset + 4, 4, "Link State ID: %s", 
836                             ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
837         proto_tree_add_item(ospf_lsr_tree, ospf_filter[OSPFF_ADV_ROUTER],
838                             tvb, offset + 8, 4, FALSE);
839
840         offset += 12;
841     }
842 }
843
844 static void
845 dissect_ospf_ls_upd(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
846 {
847     proto_tree *ospf_lsa_upd_tree=NULL;
848     proto_item *ti;
849     guint32 lsa_nr;
850     guint32 lsa_counter; 
851
852     ti = proto_tree_add_text(tree, tvb, offset, -1, "LS Update Packet");
853     ospf_lsa_upd_tree = proto_item_add_subtree(ti, ett_ospf_lsa_upd);
854
855     lsa_nr = tvb_get_ntohl(tvb, offset);
856     proto_tree_add_text(ospf_lsa_upd_tree, tvb, offset, 4, "Number of LSAs: %u",
857                         lsa_nr);
858     /* skip to the beginning of the first LSA */
859     offset += 4; /* the LS Upd Packet contains only a 32 bit #LSAs field */
860     
861     lsa_counter = 0;
862     while (lsa_counter < lsa_nr) {
863         if ( version == OSPF_VERSION_2)
864             offset = dissect_ospf_v2_lsa(tvb, offset, ospf_lsa_upd_tree, TRUE);
865         else
866             if ( version == OSPF_VERSION_3)
867                 offset = dissect_ospf_v3_lsa(tvb, offset, ospf_lsa_upd_tree, TRUE);
868         lsa_counter += 1;
869     }
870 }
871
872 static void
873 dissect_ospf_ls_ack(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
874 {
875     /* the body of a LS Ack packet simply contains zero or more LSA Headers */
876     while (tvb_reported_length_remaining(tvb, offset) != 0) {
877         if ( version == OSPF_VERSION_2)
878             offset = dissect_ospf_v2_lsa(tvb, offset, tree, FALSE);
879         else
880             if ( version == OSPF_VERSION_3)
881               offset = dissect_ospf_v3_lsa(tvb, offset, tree, FALSE);
882     }
883 }
884
885 /*
886  * Returns if an LSA is opaque, i.e. requires special treatment 
887  */
888 static int
889 is_opaque(int lsa_type)
890 {
891     return (lsa_type >= OSPF_LSTYPE_OP_LINKLOCAL &&
892         lsa_type <= OSPF_LSTYPE_OP_ASWIDE);
893 }
894
895 /* MPLS/TE TLV types */
896 #define MPLS_TLV_ROUTER    1
897 #define MPLS_TLV_LINK      2
898
899 /* MPLS/TE Link STLV types */
900 enum {
901     MPLS_LINK_TYPE       = 1,
902     MPLS_LINK_ID,
903     MPLS_LINK_LOCAL_IF,
904     MPLS_LINK_REMOTE_IF,
905     MPLS_LINK_TE_METRIC,
906     MPLS_LINK_MAX_BW,
907     MPLS_LINK_MAX_RES_BW,
908     MPLS_LINK_UNRES_BW,
909     MPLS_LINK_COLOR,
910     MPLS_LINK_LOCAL_ID = 11,
911     MPLS_LINK_REMOTE_ID,
912     MPLS_LINK_PROTECTION = 14,
913     MPLS_LINK_IF_SWITCHING_DESC,
914     MPLS_LINK_SHARED_RISK_GROUP,
915 };
916
917 static const value_string mpls_link_stlv_str[] = {
918     {MPLS_LINK_TYPE, "Link Type"},
919     {MPLS_LINK_ID, "Link ID"},
920     {MPLS_LINK_LOCAL_IF, "Local Interface IP Address"},
921     {MPLS_LINK_REMOTE_IF, "Remote Interface IP Address"},
922     {MPLS_LINK_TE_METRIC, "Traffic Engineering Metric"},
923     {MPLS_LINK_MAX_BW, "Maximum Bandwidth"},
924     {MPLS_LINK_MAX_RES_BW, "Maximum Reservable Bandwidth"},
925     {MPLS_LINK_UNRES_BW, "Unreserved Bandwidth"},
926     {MPLS_LINK_COLOR, "Resource Class/Color"},
927     {MPLS_LINK_LOCAL_ID, "Link Local Identifier"},
928     {MPLS_LINK_REMOTE_ID, "Link Remote Identifier"},
929     {MPLS_LINK_PROTECTION, "Link Protection Type"},
930     {MPLS_LINK_IF_SWITCHING_DESC, "Interface Switching Capability Descriptor"},
931     {MPLS_LINK_SHARED_RISK_GROUP, "Shared Risk Link Group"},
932     {0, NULL},
933 };
934
935 /* 
936  * Dissect MPLS/TE opaque LSA 
937  */
938 static void
939 dissect_ospf_lsa_mpls(tvbuff_t *tvb, int offset, proto_tree *tree,
940                       guint32 length)
941 {
942     proto_item *ti; 
943     proto_tree *mpls_tree;
944     proto_tree *tlv_tree;
945     proto_tree *stlv_tree;
946
947     int tlv_type;
948     int tlv_length;
949     int tlv_end_offset;
950
951     int stlv_type, stlv_len, stlv_offset;
952     char *stlv_name;
953     int i;
954
955     ti = proto_tree_add_text(tree, tvb, offset, length,
956                              "MPLS Traffic Engineering LSA");
957     proto_tree_add_item_hidden(tree, ospf_filter[OSPFF_LS_MPLS],
958                                tvb, offset, 2, FALSE);
959     mpls_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls);
960
961     while (length != 0) {
962         tlv_type = tvb_get_ntohs(tvb, offset);
963         tlv_length = tvb_get_ntohs(tvb, offset + 2);
964         tlv_end_offset = offset + tlv_length + 4;
965
966         switch (tlv_type) {
967
968         case MPLS_TLV_ROUTER:
969             ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
970                                      "Router Address: %s", 
971                                      ip_to_str(tvb_get_ptr(tvb, offset+4, 4)));
972             tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_router);
973             proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: 1 - Router Address");
974             proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
975                                 tlv_length);
976             proto_tree_add_item(tlv_tree, ospf_filter[OSPFF_LS_MPLS_ROUTERID],
977                                 tvb, offset+4, 4, FALSE);
978             break;
979
980         case MPLS_TLV_LINK:
981             ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
982                                      "Link Information");
983             tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
984             proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: 2 - Link Information");
985             proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
986                                 tlv_length);
987             stlv_offset = offset + 4;
988
989             /* Walk down the sub-TLVs for link information */
990             while (stlv_offset < tlv_end_offset) {
991                 stlv_type = tvb_get_ntohs(tvb, stlv_offset);
992                 stlv_len = tvb_get_ntohs(tvb, stlv_offset + 2);
993                 stlv_name = val_to_str(stlv_type, mpls_link_stlv_str, "Unknown sub-TLV");
994                 switch (stlv_type) {
995
996                 case MPLS_LINK_TYPE:
997                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
998                                              "%s: %u", stlv_name,
999                                              tvb_get_guint8(tvb, stlv_offset + 4));
1000                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1001                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1002                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1003                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1004                                         stlv_len);
1005                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "%s: %u", stlv_name,
1006                                         tvb_get_guint8(tvb, stlv_offset + 4));
1007                     break;
1008
1009                 case MPLS_LINK_ID:
1010                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1011                                              "%s: %s (%x)", stlv_name,
1012                                              ip_to_str(tvb_get_ptr(tvb, stlv_offset + 4, 4)),
1013                                              tvb_get_ntohl(tvb, stlv_offset + 4));
1014                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1015                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1016                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1017                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1018                                         stlv_len);
1019                     proto_tree_add_item(stlv_tree, ospf_filter[OSPFF_LS_MPLS_LINKID],
1020                                         tvb, stlv_offset+4, 4, FALSE);
1021                     break;
1022
1023                 case MPLS_LINK_LOCAL_IF:
1024                 case MPLS_LINK_REMOTE_IF:
1025                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1026                                              "%s", stlv_name);
1027                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1028                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1029                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1030                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1031                                         stlv_len);
1032                     /*   The Local/Remote Interface IP Address sub-TLV is TLV type 3/4, and is 4N
1033                        octets in length, where N is the number of neighbor addresses. */
1034                     for (i=0; i < stlv_len; i+=4)
1035                       proto_tree_add_item(stlv_tree, 
1036                                           stlv_type==MPLS_LINK_LOCAL_IF ? 
1037                                           ospf_filter[OSPFF_LS_MPLS_LOCAL_ADDR] : 
1038                                           ospf_filter[OSPFF_LS_MPLS_REMOTE_ADDR],
1039                                           tvb, stlv_offset+4+i, 4, FALSE);
1040                     break;
1041
1042                 case MPLS_LINK_TE_METRIC:
1043                 case MPLS_LINK_COLOR:
1044                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1045                                              "%s: %u", stlv_name,
1046                                              tvb_get_ntohl(tvb, stlv_offset + 4));
1047                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1048                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1049                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1050                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1051                                         stlv_len);
1052                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %u", stlv_name,
1053                                         tvb_get_ntohl(tvb, stlv_offset + 4));
1054                     break;
1055
1056                 case MPLS_LINK_MAX_BW:
1057                 case MPLS_LINK_MAX_RES_BW:
1058                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1059                                              "%s: %.10g", stlv_name,
1060                                              tvb_get_ntohieee_float(tvb, stlv_offset + 4));
1061                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1062                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1063                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1064                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1065                                         stlv_len);
1066                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %.10g", stlv_name,
1067                                         tvb_get_ntohieee_float(tvb, stlv_offset + 4));
1068                     break;
1069
1070                 case MPLS_LINK_UNRES_BW:
1071                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1072                                              "%s", stlv_name);
1073                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1074                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1075                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1076                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1077                                         stlv_len);
1078                     for (i = 0; i < 8; i++) {
1079                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+4+(i*4), 4,
1080                                             "Pri %d: %.10g bytes/s (%.0f bits/s)", i,
1081                                             tvb_get_ntohieee_float(tvb, stlv_offset + 4 + i*4),
1082                                             tvb_get_ntohieee_float(tvb, stlv_offset + 4 + i*4) * 8.0);
1083                     }
1084                     break;
1085
1086                 case MPLS_LINK_LOCAL_ID:
1087                 case MPLS_LINK_REMOTE_ID:
1088                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1089                                              "%s: %d (0x%x)", stlv_name,
1090                                              tvb_get_ntohl(tvb, stlv_offset + 4),
1091                                              tvb_get_ntohl(tvb, stlv_offset + 4));
1092                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1093                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1094                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1095                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1096                                         stlv_len);
1097                     proto_tree_add_item(stlv_tree, 
1098                                         stlv_type==MPLS_LINK_LOCAL_ID ? 
1099                                         ospf_filter[OSPFF_LS_MPLS_LOCAL_IFID] : 
1100                                         ospf_filter[OSPFF_LS_MPLS_REMOTE_IFID],
1101                                         tvb, stlv_offset+4, 4, FALSE);
1102                     break;
1103
1104                 case MPLS_LINK_IF_SWITCHING_DESC:
1105                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1106                                              "%s", stlv_name);
1107                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1108                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1109                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1110                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1111                                         stlv_len);
1112                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "Switching Type: %s", 
1113                                         val_to_str(tvb_get_guint8(tvb,stlv_offset+4), 
1114                                                    gmpls_switching_type_str, "Unknown (%d)"));
1115                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+5, 1, "Encoding: %s", 
1116                                         val_to_str(tvb_get_guint8(tvb,stlv_offset+5), 
1117                                                    gmpls_lsp_enc_str, "Unknown (%d)"));
1118                     for (i = 0; i < 8; i++) {
1119                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+8+(i*4), 4,
1120                                             "Pri %d: %.10g bytes/s (%.0f bits/s)", i,
1121                                             tvb_get_ntohieee_float(tvb, stlv_offset + 8 + i*4),
1122                                             tvb_get_ntohieee_float(tvb, stlv_offset + 8 + i*4) * 8.0);
1123                     }
1124                     break;
1125
1126                 default:
1127                     proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1128                                         "Unknown Link sub-TLV: %u", stlv_type);
1129                     break;
1130                 }
1131                 stlv_offset += ((stlv_len+4+3)/4)*4;
1132             }
1133             break;
1134
1135         default:
1136             ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4, 
1137                                      "Unknown LSA: %u", tlv_type);
1138             tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
1139             proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: %u - Unknown",
1140                                 tlv_type);
1141             proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
1142                                 tlv_length);
1143             proto_tree_add_text(tlv_tree, tvb, offset+4, tlv_length, "TLV Data");
1144             break;
1145         }
1146
1147         offset += tlv_length + 4;
1148         length -= tlv_length + 4;
1149     }
1150 }
1151
1152 /*
1153  * Dissect opaque LSAs
1154  */
1155 static void
1156 dissect_ospf_lsa_opaque(tvbuff_t *tvb, int offset, proto_tree *tree,
1157                         guint8 ls_id_type, guint32 length)
1158 {
1159     switch (ls_id_type) {
1160
1161     case OSPF_LSA_MPLS_TE:
1162         dissect_ospf_lsa_mpls(tvb, offset, tree, length);
1163         break;
1164
1165     default:
1166         proto_tree_add_text(tree, tvb, offset, length,
1167                             "Unknown LSA Type %u", ls_id_type);
1168         break;
1169     } /* switch on opaque LSA id */
1170 }
1171
1172 static int
1173 dissect_ospf_v2_lsa(tvbuff_t *tvb, int offset, proto_tree *tree,
1174                  gboolean disassemble_body)
1175 {
1176     proto_tree *ospf_lsa_tree;
1177     proto_item *ti; 
1178
1179     guint8               ls_type;
1180     guint16              ls_length;
1181     int                  end_offset;
1182     guint8               nr_links;
1183     guint16              nr_tos;
1184
1185     /* router LSA */
1186     guint8               link_type;
1187     guint16              link_counter;
1188     guint8               tos_counter;
1189     char                *link_type_str;
1190     char                *link_id;
1191
1192     /* AS-external LSA */
1193     guint8               options;
1194
1195     /* opaque LSA */
1196     guint8               ls_id_type;
1197
1198     ls_type = tvb_get_guint8(tvb, offset + 3);
1199     ls_length = tvb_get_ntohs(tvb, offset + 18);
1200     end_offset = offset + ls_length;
1201
1202     if (disassemble_body) {
1203         ti = proto_tree_add_text(tree, tvb, offset, ls_length, 
1204                                  "LS Type: %s", 
1205                                  val_to_str(ls_type, ls_type_vals, "Unknown (%d)")); 
1206     } else {
1207         ti = proto_tree_add_text(tree, tvb, offset, OSPF_LSA_HEADER_LENGTH,
1208                                  "LSA Header"); 
1209     }
1210     ospf_lsa_tree = proto_item_add_subtree(ti, ett_ospf_lsa);
1211
1212     proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "LS Age: %u seconds",
1213                         tvb_get_ntohs(tvb, offset));
1214     dissect_ospf_options(tvb, offset + 2, ospf_lsa_tree, OSPF_VERSION_2);
1215     proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_LS_TYPE], tvb, 
1216                         offset + 3, 1, FALSE); 
1217     proto_tree_add_item_hidden(ospf_lsa_tree, 
1218                                ospf_filter[ospf_ls_type_to_filter(ls_type)], tvb, 
1219                                offset + 3, 1, FALSE); 
1220
1221     if (is_opaque(ls_type)) {
1222         ls_id_type = tvb_get_guint8(tvb, offset + 4);
1223         proto_tree_add_uint(ospf_lsa_tree, ospf_filter[OSPFF_LS_OPAQUE_TYPE],
1224                             tvb, offset + 4, 1, ls_id_type);
1225
1226         switch (ls_id_type) {
1227
1228         case OSPF_LSA_MPLS_TE:
1229             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 5, 1, "Link State ID TE-LSA Reserved: %u",
1230                                 tvb_get_guint8(tvb, offset + 5));
1231             proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_LS_MPLS_TE_INSTANCE],
1232                                 tvb, offset + 6, 2, FALSE);
1233             break;
1234
1235         default:
1236             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 5, 3, "Link State ID Opaque ID: %u",
1237                                 tvb_get_ntoh24(tvb, offset + 5));
1238             break;
1239         }
1240     } else {
1241         ls_id_type = 0;
1242         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link State ID: %s",
1243                             ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1244     }
1245
1246     proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_ADV_ROUTER],
1247                         tvb, offset + 8, 4, FALSE);
1248     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "LS Sequence Number: 0x%04x",
1249                         tvb_get_ntohl(tvb, offset + 12));
1250     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 16, 2, "LS Checksum: %04x",
1251                         tvb_get_ntohs(tvb, offset + 16));
1252
1253     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 18, 2, "Length: %u",
1254                         ls_length);
1255
1256     /* skip past the LSA header to the body */
1257     offset += OSPF_LSA_HEADER_LENGTH;
1258     if (ls_length <= OSPF_LSA_HEADER_LENGTH)
1259         return offset;  /* no data, or bogus length */
1260     ls_length -= OSPF_LSA_HEADER_LENGTH;
1261
1262     if (!disassemble_body)
1263         return offset;
1264
1265     switch (ls_type){
1266
1267     case OSPF_LSTYPE_ROUTER:
1268         /* again: flags should be secified in detail */
1269         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x",
1270                             tvb_get_guint8(tvb, offset));
1271         nr_links = tvb_get_ntohs(tvb, offset + 2);
1272         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2, "Number of Links: %u",
1273                             nr_links);
1274         offset += 4;
1275         /* nr_links links follow 
1276          * maybe we should put each of the links into its own subtree ???
1277          */
1278         for (link_counter = 1; link_counter <= nr_links; link_counter++) {
1279             /* check the Link Type and ID */
1280             link_type = tvb_get_guint8(tvb, offset + 8);
1281             switch (link_type) {
1282
1283             case OSPF_LINK_PTP:
1284                 link_type_str="Point-to-point connection to another router";
1285                 link_id="Neighboring router's Router ID";
1286                 break;
1287
1288             case OSPF_LINK_TRANSIT:
1289                 link_type_str="Connection to a transit network";
1290                 link_id="IP address of Designated Router";
1291                 break;
1292
1293             case OSPF_LINK_STUB:
1294                 link_type_str="Connection to a stub network";
1295                 link_id="IP network/subnet number";
1296                 break;
1297
1298             case OSPF_LINK_VIRTUAL:
1299                 link_type_str="Virtual link";
1300                 link_id="Neighboring router's Router ID";
1301                 break;
1302
1303             default:
1304                 link_type_str="Unknown link type";
1305                 link_id="Unknown link ID";
1306                 break;
1307             }
1308
1309             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "%s: %s", link_id,
1310                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1311
1312             /* link_data should be specified in detail (e.g. network mask) (depends on link type)*/
1313             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link Data: %s",
1314                                 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1315
1316             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 1, "Link Type: %u - %s",
1317                                 link_type, link_type_str);
1318             nr_tos = tvb_get_guint8(tvb, offset + 9);
1319             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 9, 1, "Number of TOS metrics: %u",
1320                                 nr_tos);
1321             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 10, 2, "TOS 0 metric: %u",
1322                                 tvb_get_ntohs(tvb, offset + 10));
1323
1324             offset += 12;
1325
1326             /* nr_tos metrics may follow each link 
1327              * ATTENTION: TOS metrics are not tested (I don't have TOS
1328              * based routing)
1329              * please send me a mail if it is/isn't working
1330              */
1331             for (tos_counter = 1; tos_counter <= nr_tos; tos_counter++) {
1332                 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1333                                     tvb_get_guint8(tvb, offset),
1334                                     tvb_get_ntohs(tvb, offset + 2));
1335                 offset += 4;
1336             }
1337         }
1338         break;
1339
1340     case OSPF_LSTYPE_NETWORK:
1341         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
1342                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1343         offset += 4;
1344
1345         while (offset < end_offset) {
1346             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Attached Router: %s",
1347                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1348             offset += 4;
1349         }
1350         break;
1351
1352     case OSPF_LSTYPE_SUMMERY:
1353     /* Type 3 and 4 LSAs have the same format */
1354     case OSPF_LSTYPE_ASBR:
1355         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
1356                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1357         offset += 4;
1358
1359         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Metric: %u",
1360                             tvb_get_ntoh24(tvb, offset + 1));
1361         offset += 4;
1362
1363         /* TOS-specific information, if any */
1364         while (offset < end_offset) {
1365             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1366                                 tvb_get_guint8(tvb, offset),
1367                                 tvb_get_ntoh24(tvb, offset + 1));
1368             offset += 4;
1369         }
1370         break;
1371
1372     case OSPF_LSTYPE_ASEXT:
1373     case OSPF_LSTYPE_ASEXT7:
1374         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s", 
1375                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1376         offset += 4;
1377
1378         options = tvb_get_guint8(tvb, offset);
1379         if (options & 0x80) { /* check wether or not E bit is set */
1380             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1381                     "External Type: Type 2 (metric is larger than any other link state path)");
1382         } else {
1383             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1384                     "External Type: Type 1 (metric is specified in the same units as interface cost)");
1385         }
1386         /* the metric field of a AS-external LAS is specified in 3 bytes */
1387         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 1, 3, "Metric: %u",
1388                             tvb_get_ntoh24(tvb, offset + 1));
1389         offset += 4;
1390
1391         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Forwarding Address: %s", 
1392                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1393         offset += 4;
1394
1395         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "External Route Tag: %u",
1396                             tvb_get_ntohl(tvb, offset));
1397         offset += 4;
1398
1399         /* TOS-specific information, if any */
1400         while (offset < end_offset) {
1401             options = tvb_get_guint8(tvb, offset);
1402             if (options & 0x80) { /* check wether or not E bit is set */
1403                 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1404                         "External Type: Type 2 (metric is larger than any other link state path)");
1405             } else {
1406                 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1407                         "External Type: Type 1 (metric is specified in the same units as interface cost)");
1408             }
1409             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1410                                 options & 0x7F,
1411                                 tvb_get_ntoh24(tvb, offset + 1));
1412             offset += 4;
1413
1414             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Forwarding Address: %s", 
1415                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1416             offset += 4;
1417
1418             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "External Route Tag: %u",
1419                                 tvb_get_ntohl(tvb, offset));
1420             offset += 4;
1421         }
1422         break;
1423
1424     case OSPF_LSTYPE_OP_LINKLOCAL:
1425     case OSPF_LSTYPE_OP_AREALOCAL:
1426     case OSPF_LSTYPE_OP_ASWIDE:
1427         /*
1428          * RFC 2370 opaque LSAs.
1429          */
1430         dissect_ospf_lsa_opaque(tvb, offset, ospf_lsa_tree, ls_id_type,
1431                                 ls_length);
1432         offset += ls_length;
1433         break;
1434
1435     default:
1436         /* unknown LSA type */
1437         proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1438                             "Unknown LSA Type");
1439         offset += ls_length;
1440         break;
1441     }
1442     /* return the offset of the next LSA */
1443     return offset;
1444 }
1445
1446 static int
1447 dissect_ospf_v3_lsa(tvbuff_t *tvb, int offset, proto_tree *tree,
1448                  gboolean disassemble_body)
1449 {
1450     proto_tree *ospf_lsa_tree;
1451     proto_item *ti; 
1452
1453     guint16              ls_type;
1454     guint16              ls_length;
1455     int                  end_offset;
1456     guint8               reserved;
1457
1458     /* router LSA */
1459     guint8               link_type;
1460     char                *link_type_str;
1461     guint32              metric;
1462
1463     guint8               router_lsa_flags;
1464     char                 router_lsa_flags_string[5];
1465
1466     guint8               router_priority;
1467     guint32              number_prefixes;
1468     guint8               prefix_length;
1469     guint16              reserved16;
1470
1471     guint16              referenced_ls_type;
1472
1473     guint8               flags;
1474     guint8               flags_string[4];
1475     guint32              external_route_tag;
1476
1477
1478     ls_type = tvb_get_ntohs(tvb, offset + 2);
1479     ls_length = tvb_get_ntohs(tvb, offset + 18);
1480     end_offset = offset + ls_length;
1481
1482     if (disassemble_body) {
1483         ti = proto_tree_add_text(tree, tvb, offset, ls_length,
1484                                  "%s (Type: 0x%04x)", val_to_str(ls_type, v3_ls_type_vals,"Unknown"), ls_type); 
1485     } else {
1486         ti = proto_tree_add_text(tree, tvb, offset, OSPF_LSA_HEADER_LENGTH,
1487                                  "LSA Header"); 
1488     }
1489     ospf_lsa_tree = proto_item_add_subtree(ti, ett_ospf_lsa);
1490
1491     proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "LS Age: %u seconds",
1492                         tvb_get_ntohs(tvb, offset));
1493
1494     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2, "LSA Type: 0x%04x (%s)",
1495                         ls_type, val_to_str(ls_type, v3_ls_type_vals,"Unkown"));
1496
1497     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link State ID: %s",
1498                             ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1499
1500     proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_ADV_ROUTER],
1501                         tvb, offset + 8, 4, FALSE);
1502     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "LS Sequence Number: %d",
1503                         tvb_get_ntohl(tvb, offset + 12));
1504     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 16, 2, "LS Checksum: %04x",
1505                         tvb_get_ntohs(tvb, offset + 16));
1506
1507     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 18, 2, "Length: %u",
1508                         ls_length);
1509
1510     /* skip past the LSA header to the body */
1511     offset += OSPF_LSA_HEADER_LENGTH;
1512     ls_length -= OSPF_LSA_HEADER_LENGTH;
1513
1514     if (!disassemble_body)
1515         return offset;
1516
1517     switch (ls_type){
1518
1519
1520     case OSPF_V3_LSTYPE_ROUTER:
1521
1522       /* flags field in an router-lsa */
1523         router_lsa_flags=tvb_get_guint8(tvb,offset);
1524         if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_B)
1525             router_lsa_flags_string[3] = 'B';
1526         else
1527             router_lsa_flags_string[3] = '.';
1528         if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_E)
1529             router_lsa_flags_string[2] = 'E';
1530         else
1531             router_lsa_flags_string[2] = '.';
1532         if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_V)
1533             router_lsa_flags_string[1] = 'V';
1534         else
1535             router_lsa_flags_string[1] = '.';
1536         if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_W)
1537             router_lsa_flags_string[0] = 'W';
1538         else
1539             router_lsa_flags_string[0] = '.';
1540
1541         router_lsa_flags_string[4]=0;
1542
1543         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x (%s)",
1544                             router_lsa_flags, router_lsa_flags_string);
1545
1546         /* options field in an router-lsa */
1547         dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1548
1549         /* skip the router-lsa flags and options */
1550         offset+=4;
1551         ls_length-=4;
1552
1553         if (ls_length > 0)
1554              proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1555                    "Router Interfaces:"); 
1556
1557         /* scan all router-lsa router interfaces */
1558         /* maybe we should put each of the links into its own subtree ??? */
1559         while (ls_length > 0 ) {
1560
1561             /* check the type */
1562             link_type = tvb_get_guint8(tvb, offset);
1563             switch (link_type) {
1564
1565                 case OSPF_V3_LINK_PTP:
1566                     link_type_str="Point-to-point connection to another router";
1567                     break;
1568
1569                 case OSPF_V3_LINK_TRANSIT:
1570                     link_type_str="Connection to a transit network";
1571                     break;
1572
1573                 case OSPF_V3_LINK_RESERVED:
1574                     link_type_str="Connection to a stub network";
1575                     break;
1576
1577                 case OSPF_V3_LINK_VIRTUAL:
1578                     link_type_str="Virtual link";
1579                     break;
1580
1581                 default:
1582                     link_type_str="Unknown link type";
1583                     break;
1584             }
1585
1586             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Type: %u (%s)", link_type,link_type_str);
1587
1588             /* reserved field */
1589             reserved = tvb_get_guint8(tvb, offset+1);
1590             proto_tree_add_text(ospf_lsa_tree, tvb, offset+1, 1,
1591                (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1592
1593             /* metric */
1594             metric=tvb_get_ntohs(tvb, offset+2);
1595             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2,"Metric: %u",metric);
1596
1597             /* Interface ID */
1598             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Interface ID: %u",
1599                         tvb_get_ntohl(tvb, offset + 4));
1600
1601             /* Neighbor Interface ID */
1602             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Neighbor Interface ID: %u",
1603                         tvb_get_ntohl(tvb, offset + 8));
1604
1605             /* Neighbor Router ID */
1606             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "Neighbor Router ID: %s",
1607                 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
1608
1609             /* skip to the (possible) next entry */
1610             offset+=16;
1611             ls_length-=16;
1612
1613         }
1614         break;
1615
1616     case OSPF_V3_LSTYPE_NETWORK:
1617
1618         /* reserved field */
1619         reserved = tvb_get_guint8(tvb, offset);
1620         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1621                (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1622
1623         /* options field in an network-lsa */
1624         dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1625
1626         offset += 4;
1627         ls_length-=4;
1628
1629         while (ls_length > 0 ) {
1630             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Attached Router: %s",
1631                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1632             ls_length-=4;
1633             offset += 4;
1634         }
1635         break;
1636
1637
1638     case OSPF_V3_LSTYPE_INTER_AREA_PREFIX:
1639
1640         /* reserved field */
1641         reserved = tvb_get_guint8(tvb, offset);
1642         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1643                (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1644
1645         /* metric */
1646         metric=tvb_get_ntoh24(tvb, offset+11);
1647         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 1, 3,"Metric: %u",metric);
1648
1649         /* prefix length */
1650         prefix_length=tvb_get_guint8(tvb, offset+4);
1651         proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1, "PrefixLength: %u",prefix_length);
1652
1653         /* prefix options */
1654         dissect_ospf_v3_prefix_options(tvb, offset+5, ospf_lsa_tree);
1655
1656         /* 16 bits reserved */
1657         reserved16=tvb_get_ntohs(tvb, offset+6);
1658         proto_tree_add_text(ospf_lsa_tree, tvb, offset+6, 2,
1659                (reserved16 == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved16);
1660
1661         offset+=8;
1662
1663         /* address_prefix */
1664         dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1665
1666         offset+=(prefix_length+31)/32*4;
1667
1668         break;
1669
1670
1671     case OSPF_V3_LSTYPE_INTER_AREA_ROUTER:
1672
1673         /* reserved field */
1674         reserved = tvb_get_guint8(tvb, offset);
1675         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1676                (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1677
1678         /* options field in an inter-area-router-lsa */
1679         dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1680
1681         /* reserved field */
1682         reserved = tvb_get_guint8(tvb, offset+4);
1683         proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1,
1684                (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1685
1686         /* metric */
1687         metric=tvb_get_ntoh24(tvb, offset+6);
1688         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 6, 3,"Metric: %u",metric);
1689
1690         /* Destination Router ID */
1691         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Destination Router ID: %s",
1692                 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
1693
1694         offset+=12;
1695         break;
1696
1697
1698     case OSPF_V3_LSTYPE_AS_EXTERNAL:
1699
1700         /* flags */
1701         flags=tvb_get_guint8(tvb, offset);
1702         if (flags & OSPF_V3_AS_EXTERNAL_FLAG_E)
1703             flags_string[0] = 'E';
1704         else
1705             flags_string[0] = '.';
1706         if (flags & OSPF_V3_AS_EXTERNAL_FLAG_F)
1707             flags_string[1] = 'F';
1708         else
1709             flags_string[1] = '.';
1710         if (flags & OSPF_V3_AS_EXTERNAL_FLAG_T)
1711             flags_string[2] = 'T';
1712         else
1713             flags_string[2] = '.';
1714
1715         flags_string[3]=0;
1716
1717         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x (%s)",
1718                             flags, flags_string);
1719         
1720         /* 24 bits metric */
1721         metric=tvb_get_ntoh24(tvb, offset+1);
1722         proto_tree_add_text(ospf_lsa_tree, tvb, offset+1, 3,
1723                                 "Metric: %u", metric);
1724
1725         /* prefix length */
1726         prefix_length=tvb_get_guint8(tvb, offset+4);
1727         proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1, "PrefixLength: %u",prefix_length);
1728
1729         /* prefix options */
1730         dissect_ospf_v3_prefix_options(tvb, offset+5, ospf_lsa_tree);
1731
1732         /* referenced LS type */
1733         referenced_ls_type=tvb_get_ntohs(tvb, offset+6);
1734         proto_tree_add_text(ospf_lsa_tree, tvb, offset+6, 2,"Referenced LS type 0x%04x (%s)",
1735                             referenced_ls_type, val_to_str(referenced_ls_type, v3_ls_type_vals, "Unknown"));
1736
1737         offset+=8;
1738
1739         /* address_prefix */
1740         dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1741        
1742         offset+=(prefix_length+31)/32*4;
1743
1744         /* Forwarding Address (optional - only if F-flag is on) */
1745         if ( (offset < end_offset) && (flags & OSPF_V3_AS_EXTERNAL_FLAG_F) ) {
1746             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 16,"Forwarding Address: %s",
1747               ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset, 16)));
1748
1749             offset+=16;
1750         }
1751
1752         /* External Route Tag (optional - only if T-flag is on) */
1753         if ( (offset < end_offset) && (flags & OSPF_V3_AS_EXTERNAL_FLAG_T) ) {
1754             external_route_tag=tvb_get_ntohl(tvb, offset);
1755             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4,"External Route Tag: 0x%04x",
1756                                 external_route_tag);
1757
1758             offset+=4;
1759         }
1760
1761         /* Referenced Link State ID (optional - only if Referenced LS type is non-zero */
1762         if ( (offset < end_offset) && (referenced_ls_type != 0) ) {
1763             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Referenced Link State ID: %s", 
1764                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1765             offset+=4;
1766         }
1767
1768         break;
1769
1770     case OSPF_V3_LSTYPE_LINK:
1771
1772         /* router priority */
1773         router_priority=tvb_get_guint8(tvb, offset);
1774         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Router Priority: %u", router_priority);
1775
1776         /* options field in an link-lsa */
1777         dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1778
1779         /* Link-local Interface Address */
1780         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 16, "Link-local Interface Address: %s",
1781            ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, 16)));
1782
1783         /* Number prefixes */
1784         number_prefixes=tvb_get_ntohl(tvb, offset + 20);
1785         proto_tree_add_text(ospf_lsa_tree, tvb, offset+20, 4, "# prefixes: %d",number_prefixes);
1786
1787         offset+=24;
1788
1789         while (number_prefixes > 0) {
1790
1791             /* prefix length */
1792             prefix_length=tvb_get_guint8(tvb, offset);
1793             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "PrefixLength: %u",prefix_length);
1794
1795             /* prefix options */
1796             dissect_ospf_v3_prefix_options(tvb, offset+1, ospf_lsa_tree);
1797
1798             /* 16 bits reserved */
1799             reserved16=tvb_get_ntohs(tvb, offset+2);
1800             proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,
1801                (reserved16 == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved16);
1802
1803             offset+=4;
1804
1805             /* address_prefix */
1806             dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1807        
1808             offset+=(prefix_length+31)/32*4;
1809
1810             number_prefixes--;
1811
1812         }             
1813         break;
1814
1815     case OSPF_V3_LSTYPE_INTRA_AREA_PREFIX:
1816
1817         /* # prefixes */
1818         number_prefixes=tvb_get_ntohs(tvb, offset);
1819         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2,"# prefixes: %u",number_prefixes);
1820
1821         /* referenced LS type */
1822         referenced_ls_type=tvb_get_ntohs(tvb, offset+2);
1823         proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,"Referenced LS type 0x%04x (%s)",
1824                             referenced_ls_type, val_to_str(referenced_ls_type, v3_ls_type_vals, "Unknown"));
1825
1826         /* Referenced Link State ID */
1827         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Referenced Link State ID: %s", 
1828                             ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1829
1830         /* Referenced Advertising Router */
1831         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Referenced Advertising Router: %s", 
1832                             ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
1833
1834         offset+=12;
1835
1836         while (number_prefixes > 0) {
1837
1838             /* prefix length */
1839             prefix_length=tvb_get_guint8(tvb, offset);
1840             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "PrefixLength: %u",prefix_length);
1841
1842             /* prefix options */
1843             dissect_ospf_v3_prefix_options(tvb, offset+1, ospf_lsa_tree);
1844
1845             /* 16 bits metric */
1846             metric=tvb_get_ntohs(tvb, offset+2);
1847             proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,
1848                                 "Metric: %u", metric);
1849
1850             offset+=4;
1851
1852             /* address_prefix */
1853             dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1854        
1855             offset+=(prefix_length+31)/32*4;
1856
1857             number_prefixes--;
1858         }
1859         break;
1860
1861     default:
1862         /* unknown LSA type */
1863         proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1864                             "Unknown LSA Type 0x%04x",ls_type);
1865         offset += ls_length;
1866         break;
1867     }
1868     /* return the offset of the next LSA */
1869     return offset;
1870 }
1871
1872
1873 static void
1874 dissect_ospf_options(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
1875 {
1876     guint8 options_ospfv2;
1877     guint32 options_ospfv3;
1878     char options_string[20] = "";
1879
1880     /* ATTENTION !!! no check for length of options string  - with OSPFv3 maximum length is 14 characters */
1881
1882     switch ( version ) {
1883
1884         case OSPF_VERSION_2:
1885
1886             options_ospfv2 = tvb_get_guint8(tvb, offset);
1887
1888             if (options_ospfv2 & OSPF_V2_OPTIONS_E)
1889                 strcat(options_string, "E");
1890
1891             if (options_ospfv2 & OSPF_V2_OPTIONS_MC) {
1892                 if (options_string[0] != '\0')
1893                     strcat(options_string, "/");
1894                 strcat(options_string, "MC");
1895             }
1896
1897             if (options_ospfv2 & OSPF_V2_OPTIONS_NP) {
1898                 if (options_string[0] != '\0')
1899                     strcat(options_string, "/");
1900                 strcat(options_string, "NP");
1901             }
1902
1903             if (options_ospfv2 & OSPF_V2_OPTIONS_EA) {
1904                 if (options_string[0] != '\0')
1905                     strcat(options_string, "/");
1906                 strcat(options_string, "EA");
1907             }
1908
1909             if (options_ospfv2 & OSPF_V2_OPTIONS_DC) {
1910                 if (options_string[0] != '\0')
1911                     strcat(options_string, "/");
1912                 strcat(options_string, "DC");
1913             }
1914
1915             if (options_ospfv2 & OSPF_V2_OPTIONS_O) {
1916                 if (options_string[0] != '\0')
1917                     strcat(options_string, "/");
1918                 strcat(options_string, "O");
1919             }
1920
1921             if (options_ospfv2 & OSPF_V2_OPTIONS_DN) {
1922                 if (options_string[0] != '\0')
1923                     strcat(options_string, "/");
1924                 strcat(options_string, "DN");  
1925             }
1926
1927             proto_tree_add_text(tree, tvb, offset, 1, "Options: 0x%x (%s)",
1928                         options_ospfv2, options_string);
1929             break;
1930
1931
1932         case OSPF_VERSION_3:
1933
1934             options_ospfv3 = tvb_get_ntoh24(tvb, offset);
1935
1936             if (options_ospfv3 & OSPF_V3_OPTIONS_V6)
1937                 strcat(options_string, "V6");
1938
1939             if (options_ospfv3 & OSPF_V3_OPTIONS_E)
1940                 if (options_string[0] != '\0')
1941                     strcat(options_string, "/");
1942                 strcat(options_string, "E");
1943
1944             if (options_ospfv3 & OSPF_V3_OPTIONS_MC) {
1945                 if (options_string[0] != '\0')
1946                     strcat(options_string, "/");
1947                 strcat(options_string, "MC");
1948             }
1949
1950             if (options_ospfv3 & OSPF_V3_OPTIONS_N) {
1951                 if (options_string[0] != '\0')
1952                     strcat(options_string, "/");
1953                 strcat(options_string, "N");
1954             }
1955
1956             if (options_ospfv3 & OSPF_V3_OPTIONS_R) {
1957                 if (options_string[0] != '\0')
1958                     strcat(options_string, "/");
1959                 strcat(options_string, "R");
1960             }
1961
1962             if (options_ospfv3 & OSPF_V3_OPTIONS_DC) {
1963                 if (options_string[0] != '\0')
1964                     strcat(options_string, "/");
1965                 strcat(options_string, "DC");
1966             }
1967
1968             proto_tree_add_text(tree, tvb, offset, 3, "Options: 0x%x (%s)",
1969                         options_ospfv3, options_string);
1970             break;
1971
1972         default:
1973             break;
1974     }
1975
1976 }
1977
1978
1979 static void dissect_ospf_v3_prefix_options(tvbuff_t *tvb, int offset, proto_tree *tree)
1980 {
1981
1982     guint8 prefix_options;
1983     char prefix_options_string[11];
1984     guint8 position;
1985
1986     position=0;
1987     
1988     prefix_options=tvb_get_guint8(tvb, offset);
1989
1990     strcpy(prefix_options_string,"");
1991
1992     if (prefix_options & OSPF_V3_PREFIX_OPTION_P) {
1993         strcat(prefix_options_string, "P");
1994         position++;
1995     }
1996
1997     if (prefix_options & OSPF_V3_PREFIX_OPTION_MC) {
1998         if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
1999             strcat(prefix_options_string, "/");
2000             position++;
2001         }
2002         strcat(prefix_options_string, "MC");
2003         position+=2;
2004     }
2005
2006     if (prefix_options & OSPF_V3_PREFIX_OPTION_LA) {
2007         if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
2008             strcat(prefix_options_string, "/");
2009             position++;
2010         }
2011         strcat(prefix_options_string, "LA");
2012         position+=2;
2013     }
2014
2015     if (prefix_options & OSPF_V3_PREFIX_OPTION_NU) {
2016         if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
2017             strcat(prefix_options_string, "/");
2018             position++;
2019         }
2020         strcat(prefix_options_string, "NU");
2021     }
2022
2023     prefix_options_string[10]=0;
2024
2025     proto_tree_add_text(tree, tvb, offset, 1, "PrefixOptions: 0x%02x (%s)",prefix_options, prefix_options_string);
2026
2027 }
2028
2029
2030 static void dissect_ospf_v3_address_prefix(tvbuff_t *tvb, int offset, int prefix_length, proto_tree *tree)
2031 {
2032
2033     guint8 value;
2034     guint8 position;
2035     guint8 bufpos;
2036     gchar  buffer[32+7];
2037     gchar  bytebuf[3];
2038     guint8 bytes_to_process;
2039     int start_offset;
2040
2041     start_offset=offset;
2042     position=0;
2043     bufpos=0;
2044     bytes_to_process=((prefix_length+31)/32)*4;
2045
2046     while (bytes_to_process > 0 ) {
2047
2048         value=tvb_get_guint8(tvb, offset);
2049
2050         if ( (position > 0) && ( (position%2) == 0 ) )
2051             buffer[bufpos++]=':';
2052
2053         sprintf(bytebuf,"%02x",value);
2054         buffer[bufpos++]=bytebuf[0];        
2055         buffer[bufpos++]=bytebuf[1];        
2056         
2057         position++;
2058         offset++;
2059         bytes_to_process--;
2060     }
2061
2062     buffer[bufpos]=0;  
2063     proto_tree_add_text(tree, tvb, start_offset, ((prefix_length+31)/32)*4, "Address Prefix: %s",buffer);
2064
2065 }
2066
2067
2068 void
2069 proto_register_ospf(void)
2070 {
2071     static gint *ett[] = {
2072         &ett_ospf,
2073         &ett_ospf_hdr,
2074         &ett_ospf_hello,
2075         &ett_ospf_desc,
2076         &ett_ospf_lsr,
2077         &ett_ospf_lsa,
2078         &ett_ospf_lsa_upd,
2079         &ett_ospf_lsa_mpls,
2080         &ett_ospf_lsa_mpls_router,
2081         &ett_ospf_lsa_mpls_link,
2082         &ett_ospf_lsa_mpls_link_stlv
2083     };
2084
2085     proto_ospf = proto_register_protocol("Open Shortest Path First",
2086                                          "OSPF", "ospf");
2087     proto_register_field_array(proto_ospf, ospff_info, array_length(ospff_info));
2088     proto_register_subtree_array(ett, array_length(ett));
2089 }
2090
2091 void
2092 proto_reg_handoff_ospf(void)
2093 {
2094     dissector_handle_t ospf_handle;
2095
2096     ospf_handle = create_dissector_handle(dissect_ospf, proto_ospf);
2097     dissector_add("ip.proto", IP_PROTO_OSPF, ospf_handle);
2098     data_handle = find_dissector("data");
2099 }