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