#include <string.h> and/or #include <stdio.h> not needed.
[obnox/wireshark/wip.git] / epan / dissectors / 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$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25 /*
26  * At this time, this module is able to analyze OSPF
27  * packets as specified in RFC2328. MOSPF (RFC1584) and other
28  * OSPF Extensions which introduce new Packet types
29  * (e.g the External Atributes LSA) are not supported.
30  * Furthermore RFC2740 (OSPFv3 - OSPF for IPv6) is now supported
31  *   - (c) 2001 Palle Lyckegaard <palle[AT]lyckegaard.dk>
32  *
33  * Added support to E-NNI routing (OIF2003.259.02)
34  *   - (c) 2004 Roberto Morro <roberto.morro[AT]tilab.com>
35  *
36  * Added support for OSPF restart signaling:
37  *       draft-nguyen-ospf-lls-05.txt
38  *       draft-nguyen-ospf-oob-resync-05.txt
39  *       draft-nguyen-ospf-restart-05.txt
40  *   - (c) 2005 Michael Rozhavsky <mrozhavsky@fortinet.com>
41  *
42  * Added support of MPLS Diffserv-aware TE (RFC 4124); new BC sub-TLV
43  *   - (c) 2006 (FF) <francesco.fondelli[AT]gmail.com>
44  *
45  * Added support for decoding the TLVs in a grace-LSA
46  *   - (c) 2007 Todd J Martin <todd.martin@acm.org>
47  *
48  * Added support for draft-ietf-ospf-manet-or-02
49  * Added support for draft-ietf-ospf-af-alt-06
50  *   - (c) 2008 Cisco Systems
51  *
52  * Added support for Multi-Topology (MT) Routing (RFC4915)
53  *   - (c) 2009 Stig Bjorlykke <stig@bjorlykke.org>, Thales Norway AS
54  *
55  */
56
57 #ifdef HAVE_CONFIG_H
58 # include "config.h"
59 #endif
60
61 #include <string.h>
62 #include <glib.h>
63 #include <epan/packet.h>
64 #include <epan/ipproto.h>
65 #include <epan/in_cksum.h>
66 #include <epan/emem.h>
67 #include <epan/addr_resolv.h>
68 #include "packet-rsvp.h"
69
70 #define OSPF_VERSION_2 2
71 #define OSPF_VERSION_3 3
72 #define OSPF_AF_4 4
73 #define OSPF_AF_6 6
74 #define OSPF_VERSION_2_HEADER_LENGTH    24
75 #define OSPF_VERSION_3_HEADER_LENGTH    16
76
77
78 #define OSPF_HELLO      1
79 #define OSPF_DB_DESC    2
80 #define OSPF_LS_REQ     3
81 #define OSPF_LS_UPD     4
82 #define OSPF_LS_ACK     5
83
84 static const value_string pt_vals[] = {
85         {OSPF_HELLO,   "Hello Packet"   },
86         {OSPF_DB_DESC, "DB Description" },
87         {OSPF_LS_REQ,  "LS Request"     },
88         {OSPF_LS_UPD,  "LS Update"      },
89         {OSPF_LS_ACK,  "LS Acknowledge" },
90         {0,             NULL            }
91 };
92
93 #define OSPF_AUTH_NONE          0
94 #define OSPF_AUTH_SIMPLE        1
95 #define OSPF_AUTH_CRYPT         2
96
97 static const value_string auth_vals[] = {
98         {OSPF_AUTH_NONE,   "Null"            },
99         {OSPF_AUTH_SIMPLE, "Simple password" },
100         {OSPF_AUTH_CRYPT,  "Cryptographic"   },
101         {0,                NULL              }
102 };
103
104 #define OSPF_V2_OPTIONS_MT              0x01
105 #define OSPF_V2_OPTIONS_E               0x02
106 #define OSPF_V2_OPTIONS_MC              0x04
107 #define OSPF_V2_OPTIONS_NP              0x08
108 #define OSPF_V2_OPTIONS_L               0x10
109 #define OSPF_V2_OPTIONS_DC              0x20
110 #define OSPF_V2_OPTIONS_O               0x40
111 #define OSPF_V2_OPTIONS_DN              0x80
112 #define OSPF_V3_OPTIONS_V6              0x01
113 #define OSPF_V3_OPTIONS_E               0x02
114 #define OSPF_V3_OPTIONS_MC              0x04
115 #define OSPF_V3_OPTIONS_N               0x08
116 #define OSPF_V3_OPTIONS_R               0x10
117 #define OSPF_V3_OPTIONS_DC              0x20
118 #define OSPF_V3_OPTIONS_AF              0x0100
119 #define OSPF_V3_OPTIONS_L               0x0200
120 #define OSPF_V3_OPTIONS_I               0x0400
121 #define OSPF_V3_OPTIONS_F               0x0800
122
123 #define OSPF_LLS_EXT_OPTIONS_LR         0x00000001
124 #define OSPF_LLS_EXT_OPTIONS_RS         0x00000002
125
126 #define OSPF_V3_LLS_EXT_OPTIONS_LR      0x00000001
127 #define OSPF_V3_LLS_EXT_OPTIONS_RS      0x00000002
128
129 #define OSPF_V3_LLS_STATE_OPTIONS_R     0x80
130 #define OSPF_V3_LLS_STATE_OPTIONS_A     0x40
131 #define OSPF_V3_LLS_STATE_OPTIONS_N     0x20
132 #define OSPF_V3_LLS_RELAY_OPTIONS_A     0x80
133 #define OSPF_V3_LLS_RELAY_OPTIONS_N     0x40
134
135 #define OSPF_DBD_FLAG_MS        1
136 #define OSPF_DBD_FLAG_M         2
137 #define OSPF_DBD_FLAG_I         4
138 #define OSPF_DBD_FLAG_R         8
139
140 #define OSPF_LS_REQ_LENGTH      12
141
142 #define OSPF_LSTYPE_ROUTER      1
143 #define OSPF_LSTYPE_NETWORK     2
144 #define OSPF_LSTYPE_SUMMERY     3
145 #define OSPF_LSTYPE_ASBR        4
146 #define OSPF_LSTYPE_ASEXT       5
147 #define OSPF_LSTYPE_GRPMEMBER   6
148 #define OSPF_LSTYPE_ASEXT7      7
149 #define OSPF_LSTYPE_EXTATTR     8
150 #define OSPF_V3_LSTYPE_ROUTER                0x2001
151 #define OSPF_V3_LSTYPE_NETWORK               0x2002
152 #define OSPF_V3_LSTYPE_INTER_AREA_PREFIX     0x2003
153 #define OSPF_V3_LSTYPE_INTER_AREA_ROUTER     0x2004
154 #define OSPF_V3_LSTYPE_AS_EXTERNAL           0x4005
155 #define OSPF_V3_LSTYPE_GROUP_MEMBERSHIP      0x2006
156 #define OSPF_V3_LSTYPE_TYPE_7                0x2007
157 #define OSPF_V3_LSTYPE_LINK                  0x0008
158 #define OSPF_V3_LSTYPE_INTRA_AREA_PREFIX     0x2009
159
160 /* Opaque LSA types */
161 #define OSPF_LSTYPE_OP_LINKLOCAL 9
162 #define OSPF_LSTYPE_OP_AREALOCAL 10
163 #define OSPF_LSTYPE_OP_ASWIDE    11
164
165 #define OSPF_LINK_PTP           1
166 #define OSPF_LINK_TRANSIT       2
167 #define OSPF_LINK_STUB          3
168 #define OSPF_LINK_VIRTUAL       4
169
170 #define OSPF_V3_LINK_PTP        1
171 #define OSPF_V3_LINK_TRANSIT    2
172 #define OSPF_V3_LINK_RESERVED   3
173 #define OSPF_V3_LINK_VIRTUAL    4
174
175 #define OSPF_LSA_HEADER_LENGTH  20
176
177 #define OSPF_DNA_LSA            0x8000
178 /* Known opaque LSAs */
179 #define OSPF_LSA_MPLS_TE        1
180 #define OSPF_LSA_GRACE        3
181 #define OSPF_RESTART_REASON_UNKNOWN   0
182 #define OSPF_RESTART_REASON_SWRESTART 1
183 #define OSPF_RESTART_REASON_SWRELOAD  2
184 #define OSPF_RESTART_REASON_SWITCH    3
185
186 static const value_string restart_reason_vals[] = {
187     {OSPF_RESTART_REASON_UNKNOWN,     "Unknown"                  },
188     {OSPF_RESTART_REASON_SWRESTART,   "Software Restart"         },
189     {OSPF_RESTART_REASON_SWRELOAD,    "Software Reload/Upgrade"  },
190     {OSPF_RESTART_REASON_SWITCH,      "Processor Switchover"     },
191     {0, NULL}
192 };
193
194 /* grace-LSA TLV Types */
195 #define GRACE_TLV_PERIOD 1
196 #define GRACE_TLV_REASON 2
197 #define GRACE_TLV_IP 3
198
199 static const value_string grace_tlv_type_vals[] = {
200     {GRACE_TLV_PERIOD,     "grace-LSA Grace Period"},
201     {GRACE_TLV_REASON,     "grace-LSA Restart Reason"},
202     {GRACE_TLV_IP,         "grace-LSA Restart IP"},
203     {0, NULL}
204 };
205
206 static const value_string ls_type_vals[] = {
207         {OSPF_LSTYPE_ROUTER,                  "Router-LSA"                   },
208         {OSPF_LSTYPE_NETWORK,                 "Network-LSA"                  },
209         {OSPF_LSTYPE_SUMMERY,                 "Summary-LSA (IP network)"     },
210         {OSPF_LSTYPE_ASBR,                    "Summary-LSA (ASBR)"           },
211         {OSPF_LSTYPE_ASEXT,                   "AS-External-LSA (ASBR)"       },
212         {OSPF_LSTYPE_GRPMEMBER,               "Group Membership LSA"         },
213         {OSPF_LSTYPE_ASEXT7,                  "NSSA AS-External-LSA"         },
214         {OSPF_LSTYPE_EXTATTR,                 "External Attributes LSA"      },
215         {OSPF_LSTYPE_OP_LINKLOCAL,            "Opaque LSA, Link-local scope" },
216         {OSPF_LSTYPE_OP_AREALOCAL,            "Opaque LSA, Area-local scope" },
217         {0,                                   NULL                           }
218
219 };
220
221 static const value_string ls_opaque_type_vals[] = {
222         {OSPF_LSA_MPLS_TE, "Traffic Engineering LSA"                },
223         {2,                "Sycamore Optical Topology Descriptions" },
224         {OSPF_LSA_GRACE,   "grace-LSA"                              },
225         {0,                NULL                                     }
226 };
227
228 static const value_string v3_ls_type_vals[] = {
229         {OSPF_V3_LSTYPE_ROUTER,               "Router-LSA"                   },
230         {OSPF_V3_LSTYPE_NETWORK,              "Network-LSA"                  },
231         {OSPF_V3_LSTYPE_INTER_AREA_PREFIX,    "Inter-Area-Prefix-LSA"        },
232         {OSPF_V3_LSTYPE_INTER_AREA_ROUTER,    "Inter-Area-Router-LSA"        },
233         {OSPF_V3_LSTYPE_AS_EXTERNAL,          "AS-External-LSA"              },
234         {OSPF_V3_LSTYPE_GROUP_MEMBERSHIP,     "Group-Membership-LSA"         },
235         {OSPF_V3_LSTYPE_TYPE_7,               "Type-LSA"                     },
236         {OSPF_V3_LSTYPE_LINK,                 "Link-LSA"                     },
237         {OSPF_V3_LSTYPE_INTRA_AREA_PREFIX,    "Intra-Area-Prefix-LSA"        },
238         {0,                                   NULL                           }
239
240 };
241
242 static const value_string lls_tlv_type_vals[] = {
243         {1,                                   "Extended options TLV"         },
244         {2,                                   "Crypto Authentication TLV"    },
245         {0,                                   NULL                           }
246 };
247
248 /* OSPFv3 LLS TLV Types */
249 #define LLS_V3_EXT_OPT       1
250 #define LLS_V3_STATE_CHECK   3
251 #define LLS_V3_NBR_DROP      4
252 #define LLS_V3_RELAYS        7
253 #define LLS_V3_WILLING       8
254 #define LLS_V3_RQST_FROM     5
255 #define LLS_V3_FULL_STATE    6
256
257 static const value_string lls_v3_tlv_type_vals[] = {
258     {LLS_V3_EXT_OPT,                      "Extended Options TLV"          },
259     {LLS_V3_STATE_CHECK,                  "State Check Sequence TLV"      },
260     {LLS_V3_NBR_DROP,                     "Neighbor Drop TLV"             },
261     {LLS_V3_RELAYS,                       "Active Overlapping Relays TLV" },
262     {LLS_V3_WILLING,                      "Willingness TLV"               },
263     {LLS_V3_RQST_FROM,                    "Request From LTV"              },
264     {LLS_V3_FULL_STATE,                   "Full State For TLV"            },
265     {0,                                   NULL                            }
266 };
267
268 static const value_string mpls_link_stlv_ltype_str[] = {
269     {1, "Point-to-point"},
270     {2, "Multi-access"},
271     {0, NULL}
272 };
273
274 /* FF: from www.iana.org/assignments/bandwidth-constraints-model-ids */
275 static const range_string mpls_link_stlv_bcmodel_rvals[] = {
276     { 0,     0, "(Russian Dolls Model - RDM)"                       },
277     { 1,     1, "(Maximum Allocation Model - MAM)"                  },
278     { 2,     2, "(Maximum Allocation with Reservation Model - MAR)" },
279     { 3,   239, "(Unassigned, Specification Required)"              },
280     { 240, 255, "(Reserved, Private Use)"                           },
281     { 0,     0, NULL                                                }
282 };
283
284 #define OSPF_V2_ROUTER_LSA_FLAG_B 0x01
285 #define OSPF_V2_ROUTER_LSA_FLAG_E 0x02
286 #define OSPF_V2_ROUTER_LSA_FLAG_V 0x04
287 #define OSPF_V2_ROUTER_LSA_FLAG_W 0x08
288 #define OSPF_V2_ROUTER_LSA_FLAG_N 0x10
289 #define OSPF_V3_ROUTER_LSA_FLAG_B 0x01
290 #define OSPF_V3_ROUTER_LSA_FLAG_E 0x02
291 #define OSPF_V3_ROUTER_LSA_FLAG_V 0x04
292 #define OSPF_V3_ROUTER_LSA_FLAG_W 0x08
293
294 #define OSPF_V3_PREFIX_OPTION_NU 0x01
295 #define OSPF_V3_PREFIX_OPTION_LA 0x02
296 #define OSPF_V3_PREFIX_OPTION_MC 0x04
297 #define OSPF_V3_PREFIX_OPTION_P  0x08
298
299 #define OSPF_V3_AS_EXTERNAL_FLAG_T 0x01
300 #define OSPF_V3_AS_EXTERNAL_FLAG_F 0x02
301 #define OSPF_V3_AS_EXTERNAL_FLAG_E 0x04
302
303
304 static int proto_ospf = -1;
305
306 static gint ett_ospf = -1;
307 static gint ett_ospf_hdr = -1;
308 static gint ett_ospf_hello = -1;
309 static gint ett_ospf_desc = -1;
310 static gint ett_ospf_lsr = -1;
311 static gint ett_ospf_lsa = -1;
312 static gint ett_ospf_lsa_router_link = -1;
313 static gint ett_ospf_lsa_upd = -1;
314 static gint ett_ospf_v2_options = -1;
315 static gint ett_ospf_v3_options = -1;
316 static gint ett_ospf_dbd = -1;
317 static gint ett_ospf_lls_data_block = -1;
318 static gint ett_ospf_lls_tlv = -1;
319 static gint ett_ospf_lls_ext_options = -1;
320 static gint ett_ospf_v3_lls_ext_options_tlv = -1;
321 static gint ett_ospf_v3_lls_ext_options = -1;
322 static gint ett_ospf_v3_lls_state_tlv = -1;
323 static gint ett_ospf_v3_lls_state_scs = -1;
324 static gint ett_ospf_v3_lls_state_options = -1;
325 static gint ett_ospf_v3_lls_drop_tlv = -1;
326 static gint ett_ospf_v3_lls_relay_tlv = -1;
327 static gint ett_ospf_v3_lls_relay_added = -1;
328 static gint ett_ospf_v3_lls_relay_options = -1;
329 static gint ett_ospf_v3_lls_willingness_tlv = -1;
330 static gint ett_ospf_v3_lls_willingness = -1;
331 static gint ett_ospf_v3_lls_rf_tlv = -1;
332 static gint ett_ospf_v3_lls_fsf_tlv = -1;
333 static gint ett_ospf_v2_router_lsa_flags = -1;
334 static gint ett_ospf_v3_router_lsa_flags = -1;
335 static gint ett_ospf_v3_as_external_flags = -1;
336 static gint ett_ospf_v3_prefix_options = -1;
337
338 /* Trees for opaque LSAs */
339 static gint ett_ospf_lsa_mpls = -1;
340 static gint ett_ospf_lsa_mpls_router = -1;
341 static gint ett_ospf_lsa_mpls_link = -1;
342 static gint ett_ospf_lsa_mpls_link_stlv = -1;
343 static gint ett_ospf_lsa_mpls_link_stlv_admingrp = -1;
344 static gint ett_ospf_lsa_oif_tna = -1;
345 static gint ett_ospf_lsa_oif_tna_stlv = -1;
346 static gint ett_ospf_lsa_grace_tlv = -1;
347
348
349
350 static const true_false_string tfs_v2_options_dc = {
351         "Demand Circuits are supported",
352         "Demand Circuits are NOT supported"
353 };
354 static const true_false_string tfs_v2_options_l = {
355         "The packet contains LLS data block",
356         "The packet does NOT contain LLS data block"
357 };
358 static const true_false_string tfs_v2_options_np = {
359         "NSSA is supported",
360         "NSSA is NOT supported"
361 };
362 static const true_false_string tfs_v2_options_mc = {
363         "Multicast Capable",
364         "NOT Multicast Capable"
365 };
366 static const true_false_string tfs_v2_options_e = {
367         "External Routing Capability",
368         "NO External Routing Capability"
369 };
370 static const true_false_string tfs_v2_options_mt = {
371         "Multi-Topology Routing",
372         "NO Multi-Topology Routing"
373 };
374 static const true_false_string tfs_v2_options_o = {
375         "O-bit is SET",
376         "O-bit is NOT set"
377 };
378 static const true_false_string tfs_v2_options_dn = {
379         "DN-bit is SET",
380         "DN-bit is NOT set"
381 };
382 static const true_false_string tfs_v3_options_v6 = {
383         "V6 is SET",
384         "V6 is NOT set"
385 };
386 static const true_false_string tfs_v3_options_e = {
387         "E is SET",
388         "E is NOT set"
389 };
390 static const true_false_string tfs_v3_options_mc = {
391         "MC is SET",
392         "MC is NOT set"
393 };
394 static const true_false_string tfs_v3_options_n = {
395         "N is SET",
396         "N is NOT set"
397 };
398 static const true_false_string tfs_v3_options_r = {
399         "R is SET",
400         "R is NOT set"
401 };
402 static const true_false_string tfs_v3_options_dc = {
403         "DC is SET",
404         "DC is NOT set"
405 };
406 static const true_false_string tfs_v3_options_af = {
407         "AF is SET",
408         "AF is NOT set"
409 };
410 static const true_false_string tfs_v3_options_l = {
411         "L is SET",
412         "L is NOT set"
413 };
414 static const true_false_string tfs_v3_options_i = {
415         "I is SET",
416         "I is NOT set"
417 };
418 static const true_false_string tfs_v3_options_f = {
419         "F is SET",
420         "F is NOT set"
421 };
422 static const true_false_string tfs_dbd_i = {
423         "Init bit is SET",
424         "Init bit is NOT set"
425 };
426 static const true_false_string tfs_dbd_m = {
427         "More bit is SET",
428         "More bit is NOT set"
429 };
430 static const true_false_string tfs_dbd_ms = {
431         "Master/Slave bit is SET",
432         "Master/Slave bit is NOT set"
433 };
434 static const true_false_string tfs_dbd_r = {
435         "OOBResync bit is SET",
436         "OOBResync bit is NOT set"
437 };
438 static const true_false_string tfs_lls_ext_options_lr = {
439         "LSDB Resynchronization (LR-bit) is SET",
440         "LSDB Resynchronization (LR-bit) is NOT set"
441 };
442 static const true_false_string tfs_lls_ext_options_rs = {
443         "Restart Signal (RS-bit) is SET",
444         "Restart Signal (RS-bit) is NOT set"
445 };
446 static const true_false_string tfs_v3_lls_ext_options_lr = {
447         "LSDB Resynchronization (LR-bit) is SET",
448         "LSDB Resynchronization (LR-bit) is NOT set"
449 };
450 static const true_false_string tfs_v3_lls_ext_options_rs = {
451         "Restart Signal (RS-bit) is SET",
452         "Restart Signal (RS-bit) is NOT set"
453 };
454 static const true_false_string tfs_v3_lls_state_options_r = {
455         "Request (R-bit) is SET",
456         "Request (R-bit) is NOT set",
457 };
458 static const true_false_string tfs_v3_lls_state_options_a = {
459         "Answer (A-bit) is SET",
460         "Answer (A-bit) is NOT set",
461 };
462 static const true_false_string tfs_v3_lls_state_options_n = {
463         "Incomplete (N-bit) is SET",
464         "Incomplete (N-bit) is NOT set",
465 };
466 static const true_false_string tfs_v3_lls_relay_options_a = {
467         "Always (A-bit) is SET",
468         "Always (A-bit) is NOT set",
469 };
470 static const true_false_string tfs_v3_lls_relay_options_n = {
471         "Never (N-bit) is SET",
472         "Never (N-bit) is NOT set",
473 };
474 static const true_false_string tfs_v2_router_lsa_flags_b = {
475         "Area border router",
476         "NO Area border router"
477 };
478 static const true_false_string tfs_v2_router_lsa_flags_e = {
479         "AS boundary router",
480         "NO AS boundary router"
481 };
482 static const true_false_string tfs_v2_router_lsa_flags_v = {
483         "Virtual link endpoint",
484         "NO Virtual link endpoint"
485 };
486 static const true_false_string tfs_v2_router_lsa_flags_w = {
487         "Wild-card multicast receiver",
488         "NO Wild-card multicast receiver"
489 };
490 static const true_false_string tfs_v2_router_lsa_flags_n = {
491         "N flag",
492         "NO N flag"
493 };
494 static const true_false_string tfs_v3_router_lsa_flags_b = {
495         "Area border router",
496         "NO Area border router"
497 };
498 static const true_false_string tfs_v3_router_lsa_flags_e = {
499         "AS boundary router",
500         "NO AS boundary router"
501 };
502 static const true_false_string tfs_v3_router_lsa_flags_v = {
503         "Virtual link endpoint",
504         "NO Virtual link endpoint"
505 };
506 static const true_false_string tfs_v3_router_lsa_flags_w = {
507         "Wild-card multicast receiver",
508         "NO Wild-card multicast receiver"
509 };
510 static const true_false_string tfs_v3_as_external_flags_t = {
511         "External Route Tag is included",
512         "External Route Tag is NOT included"
513 };
514 static const true_false_string tfs_v3_as_external_flags_f = {
515         "Forwarding Address is included",
516         "Forwarding Address is NOT included"
517 };
518 static const true_false_string tfs_v3_as_external_flags_e = {
519         "Type 2 external metric",
520         "Type 1 external metric"
521 };
522 static const true_false_string tfs_v3_prefix_options_nu = {
523         "NoUnicast capability bit is SET",
524         "NoUnicast capability bit is NOT set"
525 };
526 static const true_false_string tfs_v3_prefix_options_la = {
527         "LocalAddress capability bit is SET",
528         "LocalAddress capability bit is NOT set"
529 };
530 static const true_false_string tfs_v3_prefix_options_mc = {
531         "Multicast capability bit is SET",
532         "Multicast capability bit is NOT set"
533 };
534 static const true_false_string tfs_v3_prefix_options_p = {
535         "Propagate bit is SET",
536         "Propagate bit is NOT set"
537 };
538
539 /*-----------------------------------------------------------------------
540  * OSPF Filtering
541  *-----------------------------------------------------------------------*/
542
543 /* The OSPF filtering keys */
544 enum {
545
546     OSPFF_MSG_TYPE,
547
548     OSPFF_MSG_MIN,
549     OSPFF_MSG_HELLO,
550     OSPFF_MSG_DB_DESC,
551     OSPFF_MSG_LS_REQ,
552     OSPFF_MSG_LS_UPD,
553     OSPFF_MSG_LS_ACK,
554
555     OSPFF_LS_TYPE,
556     OSPFF_LS_OPAQUE_TYPE,
557
558     OSPFF_LS_MPLS_TE_INSTANCE,
559
560     OSPFF_LS_MIN,
561     OSPFF_LS_ROUTER,
562     OSPFF_LS_NETWORK,
563     OSPFF_LS_SUMMARY,
564     OSPFF_LS_ASBR,
565     OSPFF_LS_ASEXT,
566     OSPFF_LS_GRPMEMBER,
567     OSPFF_LS_ASEXT7,
568     OSPFF_LS_EXTATTR,
569     OSPFF_LS_OPAQUE,
570
571     OSPFF_SRC_ROUTER,
572     OSPFF_ADV_ROUTER,
573     OSPFF_LS_MPLS,
574     OSPFF_LS_MPLS_ROUTERID,
575
576     OSPFF_LS_MPLS_LINKTYPE,
577     OSPFF_LS_MPLS_LINKID,
578     OSPFF_LS_MPLS_LOCAL_ADDR,
579     OSPFF_LS_MPLS_REMOTE_ADDR,
580     OSPFF_LS_MPLS_LOCAL_IFID,
581     OSPFF_LS_MPLS_REMOTE_IFID,
582     OSPFF_LS_MPLS_LINKCOLOR,
583     OSPFF_LS_MPLS_BC_MODEL_ID,
584     OSPFF_LS_OIF_LOCAL_NODE_ID,
585     OSPFF_LS_OIF_REMOTE_NODE_ID,
586
587     OSPFF_V2_OPTIONS,
588     OSPFF_V2_OPTIONS_MT,
589     OSPFF_V2_OPTIONS_E,
590     OSPFF_V2_OPTIONS_MC,
591     OSPFF_V2_OPTIONS_NP,
592     OSPFF_V2_OPTIONS_L,
593     OSPFF_V2_OPTIONS_DC,
594     OSPFF_V2_OPTIONS_O,
595     OSPFF_V2_OPTIONS_DN,
596     OSPFF_V3_OPTIONS,
597     OSPFF_V3_OPTIONS_V6,
598     OSPFF_V3_OPTIONS_E,
599     OSPFF_V3_OPTIONS_MC,
600     OSPFF_V3_OPTIONS_N,
601     OSPFF_V3_OPTIONS_R,
602     OSPFF_V3_OPTIONS_DC,
603     OSPFF_V3_OPTIONS_AF,
604     OSPFF_V3_OPTIONS_L,
605     OSPFF_V3_OPTIONS_I,
606     OSPFF_V3_OPTIONS_F,
607     OSPFF_DBD,
608     OSPFF_DBD_R,
609     OSPFF_DBD_I,
610     OSPFF_DBD_M,
611     OSPFF_DBD_MS,
612     OSPFF_LLS_EXT_OPTIONS_TLV,
613     OSPFF_LLS_EXT_OPTIONS,
614     OSPFF_LLS_EXT_OPTIONS_LR,
615     OSPFF_LLS_EXT_OPTIONS_RS,
616     OSPFF_V3_LLS_EXT_OPTIONS_TLV,
617     OSPFF_V3_LLS_EXT_OPTIONS,
618     OSPFF_V3_LLS_EXT_OPTIONS_LR,
619     OSPFF_V3_LLS_EXT_OPTIONS_RS,
620     OSPFF_V3_LLS_STATE_TLV,
621     OSPFF_V3_LLS_STATE_SCS,
622     OSPFF_V3_LLS_STATE_OPTIONS,
623     OSPFF_V3_LLS_STATE_OPTIONS_R,
624     OSPFF_V3_LLS_STATE_OPTIONS_A,
625     OSPFF_V3_LLS_STATE_OPTIONS_N,
626     OSPFF_V3_LLS_DROP_TLV,
627     OSPFF_V3_LLS_RELAY_TLV,
628     OSPFF_V3_LLS_RELAY_ADDED,
629     OSPFF_V3_LLS_RELAY_OPTIONS,
630     OSPFF_V3_LLS_RELAY_OPTIONS_A,
631     OSPFF_V3_LLS_RELAY_OPTIONS_N,
632     OSPFF_V3_LLS_WILLINGNESS_TLV,
633     OSPFF_V3_LLS_WILLINGNESS,
634     OSPFF_V3_LLS_RF_TLV,
635     OSPFF_V3_LLS_FSF_TLV,
636     OSPFF_V2_ROUTER_LSA_FLAG,
637     OSPFF_V2_ROUTER_LSA_FLAG_B,
638     OSPFF_V2_ROUTER_LSA_FLAG_E,
639     OSPFF_V2_ROUTER_LSA_FLAG_V,
640     OSPFF_V2_ROUTER_LSA_FLAG_W,
641     OSPFF_V2_ROUTER_LSA_FLAG_N,
642     OSPFF_V3_ROUTER_LSA_FLAG,
643     OSPFF_V3_ROUTER_LSA_FLAG_B,
644     OSPFF_V3_ROUTER_LSA_FLAG_E,
645     OSPFF_V3_ROUTER_LSA_FLAG_V,
646     OSPFF_V3_ROUTER_LSA_FLAG_W,
647     OSPFF_V3_AS_EXTERNAL_FLAG,
648     OSPFF_V3_AS_EXTERNAL_FLAG_T,
649     OSPFF_V3_AS_EXTERNAL_FLAG_F,
650     OSPFF_V3_AS_EXTERNAL_FLAG_E,
651     OSPFF_V3_PREFIX_OPTION,
652     OSPFF_V3_PREFIX_OPTION_NU,
653     OSPFF_V3_PREFIX_OPTION_LA,
654     OSPFF_V3_PREFIX_OPTION_MC,
655     OSPFF_V3_PREFIX_OPTION_P,
656
657     OSPFF_V2_GRACE_TLV,
658     OSPFF_V2_GRACE_PERIOD,
659     OSPFF_V2_GRACE_REASON,
660     OSPFF_V2_GRACE_IP,
661
662     OSPFF_MAX
663 };
664
665 static int hf_ospf_filter[OSPFF_MAX];
666
667 static gint ospf_msg_type_to_filter (guint8 msg_type)
668 {
669     if (msg_type >= OSPF_HELLO &&
670         msg_type <= OSPF_LS_ACK)
671         return msg_type + OSPFF_MSG_MIN;
672     return -1;
673 }
674
675 static gint ospf_ls_type_to_filter (guint8 ls_type)
676 {
677     if (ls_type >= OSPF_LSTYPE_ROUTER &&
678         ls_type <= OSPF_LSTYPE_EXTATTR)
679         return OSPFF_LS_MIN + ls_type;
680     else if (ls_type >= OSPF_LSTYPE_OP_LINKLOCAL &&
681              ls_type <= OSPF_LSTYPE_OP_ASWIDE)
682         return OSPFF_LS_OPAQUE;
683     else
684         return -1;
685 }
686
687 typedef struct _bitfield_info {
688     int         hfindex;
689     gint        *ett;
690     int         *idx;
691     int         num;
692 } bitfield_info;
693
694 static int bf_dbd[] = {
695     OSPFF_DBD_R,
696     OSPFF_DBD_I,
697     OSPFF_DBD_M,
698     OSPFF_DBD_MS
699 };
700 static int bf_lls_ext_options[] = {
701     OSPFF_LLS_EXT_OPTIONS_RS,
702     OSPFF_LLS_EXT_OPTIONS_LR
703 };
704 static int bf_v3_lls_ext_options[] = {
705     OSPFF_V3_LLS_EXT_OPTIONS_LR,
706     OSPFF_V3_LLS_EXT_OPTIONS_RS
707 };
708
709 static int bf_v3_lls_state_options[] = {
710     OSPFF_V3_LLS_STATE_OPTIONS_R,
711     OSPFF_V3_LLS_STATE_OPTIONS_A,
712     OSPFF_V3_LLS_STATE_OPTIONS_N
713 };
714 static int bf_v3_lls_relay_options[] = {
715     OSPFF_V3_LLS_RELAY_OPTIONS_A,
716     OSPFF_V3_LLS_RELAY_OPTIONS_N
717 };
718 static int bf_v2_router_lsa_flags[] = {
719     OSPFF_V2_ROUTER_LSA_FLAG_V,
720     OSPFF_V2_ROUTER_LSA_FLAG_E,
721     OSPFF_V2_ROUTER_LSA_FLAG_B
722 };
723 static int bf_v2_router_lsa_mt_flags[] = {
724     OSPFF_V2_ROUTER_LSA_FLAG_N,
725     OSPFF_V2_ROUTER_LSA_FLAG_W,
726     OSPFF_V2_ROUTER_LSA_FLAG_V,
727     OSPFF_V2_ROUTER_LSA_FLAG_E,
728     OSPFF_V2_ROUTER_LSA_FLAG_B
729 };
730 static int bf_v3_router_lsa_flags[] = {
731     OSPFF_V3_ROUTER_LSA_FLAG_W,
732     OSPFF_V3_ROUTER_LSA_FLAG_V,
733     OSPFF_V3_ROUTER_LSA_FLAG_E,
734     OSPFF_V3_ROUTER_LSA_FLAG_B
735 };
736 static int bf_v3_as_external_flags[] = {
737     OSPFF_V3_AS_EXTERNAL_FLAG_E,
738     OSPFF_V3_AS_EXTERNAL_FLAG_F,
739     OSPFF_V3_AS_EXTERNAL_FLAG_T
740 };
741 static int bf_v2_options[] = {
742     OSPFF_V2_OPTIONS_DN,
743     OSPFF_V2_OPTIONS_O,
744     OSPFF_V2_OPTIONS_DC,
745     OSPFF_V2_OPTIONS_L,
746     OSPFF_V2_OPTIONS_NP,
747     OSPFF_V2_OPTIONS_MC,
748     OSPFF_V2_OPTIONS_E,
749     OSPFF_V2_OPTIONS_MT
750 };
751 static int bf_v3_options[] = {
752     OSPFF_V3_OPTIONS_F,
753     OSPFF_V3_OPTIONS_I,
754     OSPFF_V3_OPTIONS_L,
755     OSPFF_V3_OPTIONS_AF,
756     OSPFF_V3_OPTIONS_DC,
757     OSPFF_V3_OPTIONS_R,
758     OSPFF_V3_OPTIONS_N,
759     OSPFF_V3_OPTIONS_MC,
760     OSPFF_V3_OPTIONS_E,
761     OSPFF_V3_OPTIONS_V6
762 };
763 static int bf_v3_prefix_options[] = {
764     OSPFF_V3_PREFIX_OPTION_P,
765     OSPFF_V3_PREFIX_OPTION_MC,
766     OSPFF_V3_PREFIX_OPTION_LA,
767     OSPFF_V3_PREFIX_OPTION_NU
768 };
769
770 static bitfield_info bfinfo_dbd = {
771     OSPFF_DBD, &ett_ospf_dbd,
772     bf_dbd, array_length(bf_dbd)
773 };
774 static bitfield_info bfinfo_lls_ext_options = {
775     OSPFF_LLS_EXT_OPTIONS, &ett_ospf_lls_ext_options,
776     bf_lls_ext_options, array_length(bf_lls_ext_options)
777 };
778 static bitfield_info bfinfo_v3_lls_ext_options = {
779     OSPFF_V3_LLS_EXT_OPTIONS, &ett_ospf_v3_lls_ext_options,
780     bf_v3_lls_ext_options, array_length(bf_v3_lls_ext_options)
781 };
782 static bitfield_info bfinfo_v3_lls_state_options = {
783     OSPFF_V3_LLS_STATE_OPTIONS, &ett_ospf_v3_lls_state_options,
784     bf_v3_lls_state_options, array_length(bf_v3_lls_state_options)
785 };
786 static bitfield_info bfinfo_v3_lls_relay_options = {
787     OSPFF_V3_LLS_RELAY_OPTIONS, &ett_ospf_v3_lls_relay_options,
788     bf_v3_lls_relay_options, array_length(bf_v3_lls_relay_options)
789 };
790 static bitfield_info bfinfo_v2_router_lsa_flags = {
791     OSPFF_V2_ROUTER_LSA_FLAG, &ett_ospf_v2_router_lsa_flags,
792     bf_v2_router_lsa_flags, array_length(bf_v2_router_lsa_flags)
793 };
794 static bitfield_info bfinfo_v2_router_lsa_mt_flags = {
795     OSPFF_V2_ROUTER_LSA_FLAG, &ett_ospf_v2_router_lsa_flags,
796     bf_v2_router_lsa_mt_flags, array_length(bf_v2_router_lsa_mt_flags)
797 };
798 static bitfield_info bfinfo_v3_router_lsa_flags = {
799     OSPFF_V3_ROUTER_LSA_FLAG, &ett_ospf_v3_router_lsa_flags,
800     bf_v3_router_lsa_flags, array_length(bf_v3_router_lsa_flags)
801 };
802 static bitfield_info bfinfo_v3_as_external_flags = {
803     OSPFF_V3_AS_EXTERNAL_FLAG, &ett_ospf_v3_as_external_flags,
804     bf_v3_as_external_flags, array_length(bf_v3_as_external_flags)
805 };
806 static bitfield_info bfinfo_v2_options = {
807     OSPFF_V2_OPTIONS, &ett_ospf_v2_options,
808     bf_v2_options, array_length(bf_v2_options)
809 };
810 static bitfield_info bfinfo_v3_options = {
811     OSPFF_V3_OPTIONS, &ett_ospf_v3_options,
812     bf_v3_options, array_length(bf_v3_options)
813 };
814 static bitfield_info bfinfo_v3_prefix_options = {
815     OSPFF_V3_PREFIX_OPTION, &ett_ospf_v3_prefix_options,
816     bf_v3_prefix_options, array_length(bf_v3_prefix_options)
817 };
818
819 #define MAX_OPTIONS_LEN 128
820 static void
821 dissect_ospf_bitfield (proto_tree *parent_tree, tvbuff_t *tvb, int offset,
822                         bitfield_info *bfinfo)
823 {
824     proto_item *item = NULL;
825     proto_tree *tree = NULL;
826     guint32 flags;
827     char *str;
828     gint length, pos;
829     gint i;
830     header_field_info *hfinfo;
831     int hfindex, idx;
832     gint returned_length;
833
834     hfindex = hf_ospf_filter[bfinfo->hfindex];
835     hfinfo = proto_registrar_get_nth(hfindex);
836     switch (hfinfo->type) {
837         case FT_UINT8:
838             flags = tvb_get_guint8(tvb, offset);
839             length = 1;
840             break;
841         case FT_UINT16:
842             flags = tvb_get_ntohs(tvb, offset);
843             length = 2;
844             break;
845         case FT_UINT24:
846             flags = tvb_get_ntoh24(tvb, offset);
847             length = 3;
848             break;
849         case FT_UINT32:
850             flags = tvb_get_ntohl(tvb, offset);
851             length = 4;
852             break;
853         default:
854             return;
855     }
856
857     if (parent_tree) {
858         item = proto_tree_add_uint(parent_tree, hfindex, tvb, offset, length, flags);
859         tree = proto_item_add_subtree(item, *bfinfo->ett);
860
861         str = ep_alloc(MAX_OPTIONS_LEN);
862         str[0] = 0;
863         for (i = 0, pos = 0; i < bfinfo->num; i++) {
864             idx = hf_ospf_filter[bfinfo->idx[i]];
865             hfinfo = proto_registrar_get_nth(idx);
866             if (flags & hfinfo->bitmask) {
867                 returned_length = g_snprintf(&str[pos], MAX_OPTIONS_LEN-pos, "%s%s",
868                                   pos ? ", " : "",
869                                   hfinfo->name);
870                 pos += MIN(returned_length, MAX_OPTIONS_LEN-pos);
871             }
872             proto_tree_add_boolean(tree, idx, tvb, offset, length, flags);
873         }
874         if (str[0]) {
875             proto_item_append_text(item, " (%s)", str);
876         }
877     }
878 }
879
880 static dissector_handle_t data_handle;
881
882 static void dissect_ospf_hello(tvbuff_t*, int, proto_tree*, guint8, guint16);
883 static void dissect_ospf_db_desc(tvbuff_t*, int, proto_tree*, guint8, guint16, guint8);
884 static void dissect_ospf_ls_req(tvbuff_t*, int, proto_tree*, guint8, guint16);
885 static void dissect_ospf_ls_upd(tvbuff_t*, int, proto_tree*, guint8, guint16, guint8);
886 static void dissect_ospf_ls_ack(tvbuff_t*, int, proto_tree*, guint8, guint16, guint8);
887 static void dissect_ospf_lls_data_block(tvbuff_t*, int, proto_tree*, guint8);
888
889 /* dissect_ospf_v[23]lsa returns the offset of the next LSA
890  * if disassemble_body is set to FALSE (e.g. in LSA ACK
891  * packets), the offset is set to the offset of the next
892  * LSA header
893  */
894 static int dissect_ospf_v2_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body);
895 static int dissect_ospf_v3_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body,
896                                guint8);
897
898 static void dissect_ospf_v3_address_prefix(tvbuff_t *, int, int, proto_tree *, guint8);
899
900 static int
901 ospf_has_lls_block(tvbuff_t *tvb, int offset, guint8 packet_type, guint8 version)
902 {
903     guint8 flags;
904     guint32 v3flags;
905
906     /* LLS block can be found only in HELLO and DBDESC packets */
907     switch (packet_type) {
908     case OSPF_HELLO:
909         switch (version) {
910         case OSPF_VERSION_2:
911             flags = tvb_get_guint8 (tvb, offset + 6);
912             return flags & OSPF_V2_OPTIONS_L;
913         case OSPF_VERSION_3:
914             v3flags = tvb_get_ntohl(tvb, offset + 5);
915             v3flags = v3flags >> 8;
916             return v3flags & OSPF_V3_OPTIONS_L;
917         }
918     case OSPF_DB_DESC:
919         switch (version) {
920         case OSPF_VERSION_2:
921             flags = tvb_get_guint8 (tvb, offset + 2);
922             return flags & OSPF_V2_OPTIONS_L;
923         case OSPF_VERSION_3:
924             v3flags = tvb_get_ntohl(tvb, offset + 1);
925             v3flags = v3flags >> 8;
926             return v3flags & OSPF_V3_OPTIONS_L;
927         }
928     }
929
930     return 0;
931 }
932
933 static void
934 dissect_ospf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
935 {
936     proto_tree *ospf_tree = NULL;
937     proto_item *ti, *hidden_item;
938     proto_tree *ospf_header_tree;
939     guint8  version;
940     guint8  packet_type;
941     guint16 ospflen;
942     vec_t cksum_vec[4];
943     int cksum_vec_len;
944     guint32 phdr[2];
945     guint16 cksum, computed_cksum;
946     guint length, reported_length;
947     guint16 auth_type;
948     char auth_data[8+1];
949     int crypto_len = 0;
950     unsigned int ospf_header_length;
951     guint8 instance_ID;
952     guint8 reserved;
953     guint32 areaid;
954     guint8  address_family = OSPF_AF_6;
955
956     col_set_str(pinfo->cinfo, COL_PROTOCOL, "OSPF");
957     col_clear(pinfo->cinfo, COL_INFO);
958
959     version = tvb_get_guint8(tvb, 0);
960     switch (version) {
961         case OSPF_VERSION_2:
962             ospf_header_length = OSPF_VERSION_2_HEADER_LENGTH;
963             break;
964         case OSPF_VERSION_3:
965             ospf_header_length = OSPF_VERSION_3_HEADER_LENGTH;
966             break;
967         default:
968             ospf_header_length = 14;
969             break;
970     }
971
972     packet_type = tvb_get_guint8(tvb, 1);
973         col_add_str(pinfo->cinfo, COL_INFO,
974                     val_to_str(packet_type, pt_vals, "Unknown (%u)"));
975
976     if (tree) {
977         ospflen = tvb_get_ntohs(tvb, 2);
978
979         ti = proto_tree_add_item(tree, proto_ospf, tvb, 0, -1, FALSE);
980         ospf_tree = proto_item_add_subtree(ti, ett_ospf);
981
982         ti = proto_tree_add_text(ospf_tree, tvb, 0, ospf_header_length,
983                                  "OSPF Header");
984         ospf_header_tree = proto_item_add_subtree(ti, ett_ospf_hdr);
985
986         proto_tree_add_text(ospf_header_tree, tvb, 0, 1, "OSPF Version: %u",
987                             version);
988         proto_tree_add_item(ospf_header_tree, hf_ospf_filter[OSPFF_MSG_TYPE],
989                             tvb, 1, 1, FALSE);
990         if (ospf_msg_type_to_filter(packet_type) != -1) {
991                 hidden_item = proto_tree_add_item(ospf_header_tree,
992                                            hf_ospf_filter[ospf_msg_type_to_filter(packet_type)],
993                                            tvb, 1, 1, FALSE);
994                 PROTO_ITEM_SET_HIDDEN(hidden_item);
995         }
996         proto_tree_add_text(ospf_header_tree, tvb, 2, 2, "Packet Length: %u",
997                             ospflen);
998         proto_tree_add_item(ospf_header_tree, hf_ospf_filter[OSPFF_SRC_ROUTER],
999                             tvb, 4, 4, FALSE);
1000         areaid=tvb_get_ntohl(tvb,8);
1001         proto_tree_add_text(ospf_header_tree, tvb, 8, 4, "Area ID: %s%s",
1002                                ip_to_str(tvb_get_ptr(tvb, 8, 4)), areaid == 0 ? " (Backbone)" : "");
1003
1004         /*
1005          * Quit at this point if it's an unknown OSPF version.
1006          */
1007         switch (version) {
1008
1009         case OSPF_VERSION_2:
1010         case OSPF_VERSION_3:
1011             break;
1012
1013         default:
1014             cksum = tvb_get_ntohs(tvb, 12);
1015             if (cksum == 0) {
1016                 /* No checksum supplied in the packet. */
1017                 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
1018                     "Packet Checksum: 0x%04x (none)", cksum);
1019             } else {
1020                 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
1021                     "Packet Checksum: 0x%04x", cksum);
1022             }
1023             proto_tree_add_text(ospf_tree, tvb, 14, -1,
1024                 "Unknown OSPF version %u", version);
1025             return;
1026         }
1027
1028         cksum = tvb_get_ntohs(tvb, 12);
1029         length = tvb_length(tvb);
1030         /* XXX - include only the length from the OSPF header? */
1031         reported_length = tvb_reported_length(tvb);
1032         if (cksum == 0) {
1033             /* No checksum supplied in the packet. */
1034             proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
1035                 "Packet Checksum: 0x%04x (none)", cksum);
1036         } else if (!pinfo->fragmented && length >= reported_length
1037                 && length >= ospf_header_length) {
1038             /* The packet isn't part of a fragmented datagram and isn't
1039                truncated, so we can checksum it. */
1040
1041             switch (version) {
1042
1043             case OSPF_VERSION_2:
1044                 /* Header, not including the authentication data (the OSPFv2
1045                    checksum excludes the 64-bit authentication field). */
1046                 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, 16);
1047                 cksum_vec[0].len = 16;
1048                 if (length > ospf_header_length) {
1049                     /* Rest of the packet, again not including the
1050                        authentication data. */
1051                     reported_length -= ospf_header_length;
1052                     cksum_vec[1].ptr = tvb_get_ptr(tvb, ospf_header_length, reported_length);
1053                     cksum_vec[1].len = reported_length;
1054                     cksum_vec_len = 2;
1055                 } else {
1056                     /* There's nothing but a header. */
1057                     cksum_vec_len = 1;
1058                 }
1059                 break;
1060
1061             case OSPF_VERSION_3:
1062                 /* IPv6-style checksum, covering the entire OSPF packet
1063                    and a prepended IPv6 pseudo-header. */
1064
1065                 /* Set up the fields of the pseudo-header. */
1066                 cksum_vec[0].ptr = pinfo->src.data;
1067                 cksum_vec[0].len = pinfo->src.len;
1068                 cksum_vec[1].ptr = pinfo->dst.data;
1069                 cksum_vec[1].len = pinfo->dst.len;
1070                 cksum_vec[2].ptr = (const guint8 *)&phdr;
1071                 phdr[0] = g_htonl(ospflen);
1072                 phdr[1] = g_htonl(IP_PROTO_OSPF);
1073                 cksum_vec[2].len = 8;
1074
1075                 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, reported_length);
1076                 cksum_vec[3].len = reported_length;
1077                 cksum_vec_len = 4;
1078                 break;
1079
1080             default:
1081                 DISSECTOR_ASSERT_NOT_REACHED();
1082                 cksum_vec_len = 0;
1083                 break;
1084             }
1085             computed_cksum = in_cksum(cksum_vec, cksum_vec_len);
1086             if (computed_cksum == 0) {
1087                 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
1088                         "Packet Checksum: 0x%04x [correct]", cksum);
1089             } else {
1090                 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
1091                         "Packet Checksum: 0x%04x [incorrect, should be 0x%04x]",
1092                         cksum, in_cksum_shouldbe(cksum, computed_cksum));
1093             }
1094         } else {
1095             proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
1096                 "Packet Checksum: 0x%04x", cksum);
1097         }
1098
1099
1100         switch (version) {
1101
1102         case OSPF_VERSION_2:
1103             /* Authentication is only valid for OSPFv2 */
1104             auth_type = tvb_get_ntohs(tvb, 14);
1105             proto_tree_add_text(ospf_header_tree, tvb, 14, 2, "Auth Type: %s",
1106                             val_to_str(auth_type, auth_vals, "Unknown (%u)"));
1107             switch (auth_type) {
1108
1109             case OSPF_AUTH_NONE:
1110                 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data (none)");
1111                 break;
1112
1113             case OSPF_AUTH_SIMPLE:
1114                 tvb_get_nstringz0(tvb, 16, 8+1, auth_data);
1115                 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data: %s", auth_data);
1116                 break;
1117
1118             case OSPF_AUTH_CRYPT:
1119                 proto_tree_add_text(ospf_header_tree, tvb, 18, 1, "Auth Key ID: %u",
1120                                 tvb_get_guint8(tvb, 18));
1121                 crypto_len = tvb_get_guint8(tvb, 19);
1122                 proto_tree_add_text(ospf_header_tree, tvb, 19, 1, "Auth Data Length: %u",
1123                                 crypto_len);
1124                 proto_tree_add_text(ospf_header_tree, tvb, 20, 4, "Auth Crypto Sequence Number: 0x%x",
1125                                 tvb_get_ntohl(tvb, 20));
1126
1127                 /* Show the message digest that was appended to the end of the
1128                    OSPF message - but only if it's present (we don't want
1129                    to get an exception before we've tried dissecting OSPF
1130                    message). */
1131                 if (tvb_bytes_exist(tvb, ospflen, crypto_len)) {
1132                     proto_tree_add_text(ospf_header_tree, tvb, ospflen, crypto_len,
1133                                     "Auth Data: %s",
1134                                     tvb_bytes_to_str(tvb, ospflen, crypto_len));
1135                     proto_tree_set_appendix(ospf_header_tree, tvb, ospflen, crypto_len);
1136                 }
1137                 break;
1138
1139             default:
1140                 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data (unknown)");
1141                 break;
1142             }
1143             break;
1144
1145         case OSPF_VERSION_3:
1146             /* Instance ID and "reserved" is OSPFv3-only */
1147             instance_ID = tvb_get_guint8(tvb, 14);
1148             ti = proto_tree_add_text(ospf_header_tree, tvb, 14, 1, "Instance ID: %u",
1149                             instance_ID);
1150
1151             if (instance_ID < 32) {
1152                 proto_item_append_text(ti, " (IPv6 unicast AF)");
1153                 address_family = OSPF_AF_6;
1154             } else if (instance_ID < 64) {
1155                 proto_item_append_text(ti, " (IPv6 multicast AF)");
1156                 address_family = OSPF_AF_6;
1157             } else if (instance_ID < 96) {
1158                 proto_item_append_text(ti, " (IPv4 unicast AF)");
1159                 address_family = OSPF_AF_4;
1160             } else if (instance_ID < 128) {
1161                 proto_item_append_text(ti, " (IPv4 multicast AF)");
1162                 address_family = OSPF_AF_4;
1163             } else {
1164                 proto_item_append_text(ti, " (Reserved)");
1165                 address_family = OSPF_AF_6;
1166             }
1167
1168             reserved = tvb_get_guint8(tvb, 15);
1169             proto_tree_add_text(ospf_header_tree, tvb, 15, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u [incorrect, should be 0]"),
1170                                 reserved);
1171             break;
1172         }
1173
1174         switch (packet_type){
1175
1176         case OSPF_HELLO:
1177             dissect_ospf_hello(tvb, ospf_header_length, ospf_tree, version,
1178                             (guint16)(ospflen - ospf_header_length));
1179             break;
1180
1181         case OSPF_DB_DESC:
1182             dissect_ospf_db_desc(tvb, (int)ospf_header_length, ospf_tree, version,
1183                                  (guint16)(ospflen - ospf_header_length),
1184                                  address_family);
1185             break;
1186
1187         case OSPF_LS_REQ:
1188             dissect_ospf_ls_req(tvb, (int)ospf_header_length, ospf_tree, version,
1189                                 (guint16)(ospflen - ospf_header_length));
1190             break;
1191
1192         case OSPF_LS_UPD:
1193             dissect_ospf_ls_upd(tvb, (int)ospf_header_length, ospf_tree, version,
1194                                 (guint16)(ospflen - ospf_header_length),
1195                                 address_family);
1196             break;
1197
1198         case OSPF_LS_ACK:
1199             dissect_ospf_ls_ack(tvb, (int)ospf_header_length, ospf_tree, version,
1200                                 (guint16)(ospflen - ospf_header_length),
1201                                 address_family);
1202             break;
1203
1204         default:
1205             call_dissector(data_handle,
1206                 tvb_new_subset_remaining(tvb, ospf_header_length), pinfo, tree);
1207             break;
1208         }
1209
1210         /* take care of the LLS data block */
1211         if (ospf_has_lls_block(tvb, ospf_header_length, packet_type, version)) {
1212             dissect_ospf_lls_data_block(tvb, ospflen + crypto_len, ospf_tree,
1213                             version);
1214         }
1215     }
1216 }
1217
1218 static int
1219 dissect_ospfv2_lls_tlv(tvbuff_t *tvb, int offset, proto_tree *tree)
1220 {
1221     proto_item *ti;
1222     proto_tree *ospf_lls_tlv_tree;
1223     guint16 type;
1224     guint16 length;
1225
1226     type = tvb_get_ntohs(tvb, offset);
1227     length = tvb_get_ntohs(tvb, offset + 2);
1228
1229     ti = proto_tree_add_text(tree, tvb, offset, length + 4, "%s",
1230                     val_to_str(type, lls_tlv_type_vals, "Unknown TLV"));
1231     ospf_lls_tlv_tree = proto_item_add_subtree(ti, ett_ospf_lls_tlv);
1232
1233     proto_tree_add_text(ospf_lls_tlv_tree, tvb, offset, 2,
1234                     "Type: %d", type);
1235     proto_tree_add_text(ospf_lls_tlv_tree, tvb, offset + 2, 2,
1236                     "Length: %d", length);
1237
1238     switch(type) {
1239         case 1:
1240             dissect_ospf_bitfield(ospf_lls_tlv_tree, tvb, offset + 4, &bfinfo_lls_ext_options);
1241             break;
1242         case 2:
1243             proto_tree_add_text(ospf_lls_tlv_tree, tvb, offset + 4, 4,
1244                             "Sequence number 0x%08x",
1245                             tvb_get_ntohl(tvb, offset + 4));
1246             proto_tree_add_text(ospf_lls_tlv_tree, tvb, offset + 8, length - 4,
1247                             "Auth Data: %s",
1248                             tvb_bytes_to_str(tvb, offset + 8, length - 4));
1249             break;
1250     }
1251
1252     return offset + length + 4;
1253 }
1254
1255 static int
1256 dissect_ospfv3_lls_tlv(tvbuff_t *tvb, int offset, proto_tree *tree)
1257 {
1258     proto_item *ti;
1259     proto_tree *ospf_lls_tlv_tree;
1260     guint16 type;
1261     guint16 length;
1262     guint8 relays_added;
1263     int orig_offset;
1264
1265     type = tvb_get_ntohs(tvb, offset);
1266     length = tvb_get_ntohs(tvb, offset + 2);
1267
1268     switch(type) {
1269     case LLS_V3_EXT_OPT:
1270         ti = proto_tree_add_item(tree, hf_ospf_filter[OSPFF_V3_LLS_EXT_OPTIONS_TLV], tvb,
1271                                  offset, length + 4, FALSE);
1272        break;
1273     case LLS_V3_STATE_CHECK:
1274         ti = proto_tree_add_item(tree, hf_ospf_filter[OSPFF_V3_LLS_STATE_TLV], tvb,
1275                                  offset, length + 4, FALSE);
1276         break;
1277     case LLS_V3_NBR_DROP:
1278         ti = proto_tree_add_item(tree, hf_ospf_filter[OSPFF_V3_LLS_DROP_TLV], tvb,
1279                                  offset, length + 4, FALSE);
1280         break;
1281     case LLS_V3_RELAYS:
1282         ti = proto_tree_add_item(tree, hf_ospf_filter[OSPFF_V3_LLS_RELAY_TLV], tvb,
1283                                  offset, length + 4, FALSE);
1284         break;
1285     case LLS_V3_WILLING:
1286         ti = proto_tree_add_item(tree, hf_ospf_filter[OSPFF_V3_LLS_WILLINGNESS_TLV], tvb,
1287                                  offset, length + 4, FALSE);
1288         break;
1289     case LLS_V3_RQST_FROM:
1290          ti = proto_tree_add_item(tree, hf_ospf_filter[OSPFF_V3_LLS_RF_TLV], tvb,
1291                                   offset, length + 4, FALSE);
1292          break;
1293     case LLS_V3_FULL_STATE:
1294         ti = proto_tree_add_item(tree, hf_ospf_filter[OSPFF_V3_LLS_FSF_TLV], tvb,
1295                                  offset, length + 4, FALSE);
1296         break;
1297     default:
1298         ti = proto_tree_add_text(tree, tvb, offset, length + 4, "%s",
1299                                  val_to_str(type, lls_v3_tlv_type_vals, "Unknown TLV"));
1300     }
1301
1302     ospf_lls_tlv_tree = proto_item_add_subtree(ti, ett_ospf_lls_tlv);
1303     proto_tree_add_text(ospf_lls_tlv_tree, tvb, offset, 2,
1304                         "Type: %d", type);
1305     proto_tree_add_text(ospf_lls_tlv_tree, tvb, offset + 2, 2,
1306                         "Length: %d", length);
1307
1308     orig_offset = offset;
1309
1310     switch (type) {
1311     case LLS_V3_EXT_OPT:
1312         proto_tree_add_text(ospf_lls_tlv_tree, tvb, offset + 4, 4,
1313                             "Extended Options: 0x%08x",
1314                             tvb_get_ntohl(tvb, offset + 4));
1315
1316         dissect_ospf_bitfield(ospf_lls_tlv_tree, tvb, offset + 4, &bfinfo_v3_lls_ext_options);
1317         break;
1318     case LLS_V3_STATE_CHECK:
1319         proto_tree_add_item(ospf_lls_tlv_tree, hf_ospf_filter[OSPFF_V3_LLS_STATE_SCS],
1320                             tvb, offset+4, 2, FALSE);
1321
1322         dissect_ospf_bitfield(ospf_lls_tlv_tree, tvb, offset + 6,
1323                               &bfinfo_v3_lls_state_options);
1324         break;
1325     case LLS_V3_NBR_DROP:
1326         offset += 4;
1327         while (orig_offset + length >= offset) {
1328             proto_tree_add_text(ospf_lls_tlv_tree, tvb, offset, 4,
1329                                 "Dropped Neighbor: %s",
1330                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1331             offset += 4;
1332         }
1333         offset = orig_offset;
1334         break;
1335     case LLS_V3_RELAYS:
1336         relays_added = tvb_get_guint8(tvb, offset+4);
1337         proto_tree_add_item(ospf_lls_tlv_tree, hf_ospf_filter[OSPFF_V3_LLS_RELAY_ADDED],
1338                             tvb, offset+4, 1, FALSE);
1339         dissect_ospf_bitfield(ospf_lls_tlv_tree, tvb, offset + 5,
1340                               &bfinfo_v3_lls_relay_options);
1341         offset += 8;
1342         while (orig_offset + length >= offset) {
1343             ti = proto_tree_add_text(ospf_lls_tlv_tree, tvb, offset, 4,
1344                                 "Neighbor: %s",
1345                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1346             if (relays_added > 0) {
1347                 proto_item_append_text(ti, " Added");
1348             } else {
1349                 proto_item_append_text(ti, " Deleted");
1350             }
1351
1352             relays_added--;
1353             offset += 4;
1354         }
1355         break;
1356     case LLS_V3_WILLING:
1357         proto_tree_add_item(ospf_lls_tlv_tree, hf_ospf_filter[OSPFF_V3_LLS_WILLINGNESS],
1358                             tvb, offset+4, 1, FALSE);
1359
1360         break;
1361     case LLS_V3_RQST_FROM:
1362         offset += 4;
1363         while (orig_offset + length >= offset) {
1364             proto_tree_add_text(ospf_lls_tlv_tree, tvb, offset, 4,
1365                                 "Request From: %s",
1366                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1367             offset += 4;
1368         }
1369         offset = orig_offset;
1370         break;
1371     case LLS_V3_FULL_STATE:
1372            offset += 4;
1373         while (orig_offset + length >= offset) {
1374             proto_tree_add_text(ospf_lls_tlv_tree, tvb, offset, 4,
1375                                 "Full State For: %s",
1376                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1377             offset += 4;
1378         }
1379         offset = orig_offset;
1380         break;
1381     }
1382
1383     return offset + length + 4;
1384 }
1385
1386
1387 static void
1388 dissect_ospf_lls_data_block(tvbuff_t *tvb, int offset, proto_tree *tree,
1389                 guint8 version)
1390 {
1391     proto_tree *ospf_lls_data_block_tree;
1392     proto_item *ti;
1393     guint16 ospf_lls_len;
1394     int orig_offset = offset;
1395
1396     ospf_lls_len = tvb_get_ntohs(tvb, offset + 2);
1397     ti = proto_tree_add_text(tree, tvb, offset, -1, "OSPF LLS Data Block");
1398     ospf_lls_data_block_tree = proto_item_add_subtree(ti,
1399                     ett_ospf_lls_data_block);
1400
1401     /* TODO: verify checksum */
1402     proto_tree_add_text(ospf_lls_data_block_tree, tvb, offset, 2,
1403                     "Checksum: 0x%04x", tvb_get_ntohs(tvb, offset));
1404     proto_tree_add_text(ospf_lls_data_block_tree, tvb, offset + 2, 2,
1405                     "LLS Data Length: %d bytes", ospf_lls_len * 4);
1406
1407     offset += 4;
1408     while (orig_offset + ospf_lls_len * 4 > offset) {
1409         switch (version) {
1410         case OSPF_VERSION_2:
1411             offset = dissect_ospfv2_lls_tlv (tvb, offset, ospf_lls_data_block_tree);
1412             break;
1413         case OSPF_VERSION_3:
1414             offset = dissect_ospfv3_lls_tlv (tvb, offset, ospf_lls_data_block_tree);
1415             break;
1416         }
1417     }
1418 }
1419
1420 static void
1421 dissect_ospf_hello(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version,
1422                 guint16 length)
1423 {
1424     proto_tree *ospf_hello_tree;
1425     proto_item *ti;
1426     int orig_offset = offset;
1427
1428     ti = proto_tree_add_text(tree, tvb, offset, length, "OSPF Hello Packet");
1429     ospf_hello_tree = proto_item_add_subtree(ti, ett_ospf_hello);
1430
1431     switch (version ) {
1432         case OSPF_VERSION_2:
1433             proto_tree_add_text(ospf_hello_tree, tvb, offset, 4, "Network Mask: %s",
1434                         ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1435             proto_tree_add_text(ospf_hello_tree, tvb, offset + 4, 2,
1436                         "Hello Interval: %u seconds",
1437                         tvb_get_ntohs(tvb, offset + 4));
1438
1439             dissect_ospf_bitfield(ospf_hello_tree, tvb, offset + 6, &bfinfo_v2_options);
1440             proto_tree_add_text(ospf_hello_tree, tvb, offset + 7, 1, "Router Priority: %u",
1441                         tvb_get_guint8(tvb, offset + 7));
1442             proto_tree_add_text(ospf_hello_tree, tvb, offset + 8, 4, "Router Dead Interval: %u seconds",
1443                         tvb_get_ntohl(tvb, offset + 8));
1444             proto_tree_add_text(ospf_hello_tree, tvb, offset + 12, 4, "Designated Router: %s",
1445                         ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
1446             proto_tree_add_text(ospf_hello_tree, tvb, offset + 16, 4, "Backup Designated Router: %s",
1447                         ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
1448
1449             offset += 20;
1450             while (orig_offset + length > offset) {
1451                 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4,
1452                             "Active Neighbor: %s",
1453                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1454                 offset += 4;
1455             }
1456             break;
1457         case OSPF_VERSION_3:
1458             proto_tree_add_text(ospf_hello_tree, tvb, offset + 0, 4, "Interface ID: %u",
1459                         tvb_get_ntohl(tvb, offset + 0));
1460             proto_tree_add_text(ospf_hello_tree, tvb, offset + 4, 1, "Router Priority: %u",
1461                         tvb_get_guint8(tvb, offset + 4));
1462             dissect_ospf_bitfield(ospf_hello_tree, tvb, offset + 5, &bfinfo_v3_options);
1463             proto_tree_add_text(ospf_hello_tree, tvb, offset + 8, 2,
1464                         "Hello Interval: %u seconds",
1465                         tvb_get_ntohs(tvb, offset + 8));
1466             proto_tree_add_text(ospf_hello_tree, tvb, offset + 10, 2, "Router Dead Interval: %u seconds",
1467                         tvb_get_ntohs(tvb, offset + 10));
1468             proto_tree_add_text(ospf_hello_tree, tvb, offset + 12, 4, "Designated Router: %s",
1469                         ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
1470             proto_tree_add_text(ospf_hello_tree, tvb, offset + 16, 4, "Backup Designated Router: %s",
1471                         ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
1472             offset += 20;
1473             while (orig_offset + length > offset) {
1474                 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4,
1475                             "Active Neighbor: %s",
1476                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1477                 offset += 4;
1478             }
1479
1480             break;
1481     }
1482 }
1483
1484 static void
1485 dissect_ospf_db_desc(tvbuff_t *tvb, int offset, proto_tree *tree,
1486                      guint8 version, guint16 length, guint8 address_family)
1487 {
1488     proto_tree *ospf_db_desc_tree=NULL;
1489     proto_item *ti;
1490     guint8 reserved;
1491     int orig_offset = offset;
1492
1493     if (tree) {
1494         ti = proto_tree_add_text(tree, tvb, offset, length, "OSPF DB Description");
1495         ospf_db_desc_tree = proto_item_add_subtree(ti, ett_ospf_desc);
1496
1497         switch (version ) {
1498
1499             case OSPF_VERSION_2:
1500                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset, 2, "Interface MTU: %u",
1501                             tvb_get_ntohs(tvb, offset));
1502
1503                 dissect_ospf_bitfield(ospf_db_desc_tree, tvb, offset + 2, &bfinfo_v2_options);
1504                 dissect_ospf_bitfield(ospf_db_desc_tree, tvb, offset + 3, &bfinfo_dbd);
1505
1506                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 4, 4, "DD Sequence: %u",
1507                             tvb_get_ntohl(tvb, offset + 4));
1508
1509                 offset += 8;
1510                 break;
1511
1512             case OSPF_VERSION_3:
1513
1514                 reserved = tvb_get_guint8(tvb, offset);
1515                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u [incorrect, should be 0]"),
1516                                 reserved);
1517
1518                 dissect_ospf_bitfield(ospf_db_desc_tree, tvb, offset + 1, &bfinfo_v3_options);
1519
1520                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 4, 2, "Interface MTU: %u",
1521                             tvb_get_ntohs(tvb, offset+4));
1522
1523                 reserved = tvb_get_guint8(tvb, offset + 6);
1524                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 6, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u [incorrect, should be 0]"),
1525                                 reserved);
1526
1527                 dissect_ospf_bitfield(ospf_db_desc_tree, tvb, offset + 7, &bfinfo_dbd);
1528
1529                 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 8, 4, "DD Sequence: %u",
1530                             tvb_get_ntohl(tvb, offset + 8));
1531
1532                 offset += 12;
1533                 break;
1534         }
1535     }
1536
1537     /* LS Headers will be processed here */
1538     /* skip to the end of DB-Desc header */
1539     while (orig_offset + length > offset) {
1540       if ( version == OSPF_VERSION_2)
1541           offset = dissect_ospf_v2_lsa(tvb, offset, tree, FALSE);
1542       else
1543           if ( version == OSPF_VERSION_3)
1544               offset = dissect_ospf_v3_lsa(tvb, offset, tree, FALSE, address_family);
1545     }
1546
1547 }
1548
1549 static void
1550 dissect_ospf_ls_req(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version,
1551                     guint16 length)
1552 {
1553     proto_tree *ospf_lsr_tree;
1554     proto_item *ti;
1555     guint32 ls_type;
1556     guint16 reserved;
1557     int orig_offset = offset;
1558
1559     /* zero or more LS requests may be within a LS Request */
1560     /* we place every request for a LSA in a single subtree */
1561     while (orig_offset + length > offset) {
1562         ti = proto_tree_add_text(tree, tvb, offset, OSPF_LS_REQ_LENGTH,
1563                                  "Link State Request");
1564         ospf_lsr_tree = proto_item_add_subtree(ti, ett_ospf_lsr);
1565
1566         switch ( version ) {
1567
1568             case OSPF_VERSION_2:
1569                 proto_tree_add_item(ospf_lsr_tree, hf_ospf_filter[OSPFF_LS_TYPE],
1570                                     tvb, offset, 4, FALSE);
1571                 break;
1572             case OSPF_VERSION_3:
1573                 reserved = tvb_get_ntohs(tvb, offset);
1574                 proto_tree_add_text(ospf_lsr_tree, tvb, offset, 2,
1575                     (reserved == 0 ? "Reserved: %u" :  "Reserved: %u [incorrect, should be 0]"), reserved);
1576                 ls_type = tvb_get_ntohs(tvb, offset+2);
1577                 proto_tree_add_text(ospf_lsr_tree, tvb, offset+2, 2, "LS Type: %s (0x%04x)",
1578                             val_to_str(ls_type, v3_ls_type_vals, "Unknown"),
1579                             ls_type);
1580                 break;
1581         }
1582
1583
1584         proto_tree_add_text(ospf_lsr_tree, tvb, offset + 4, 4, "Link State ID: %s",
1585                             ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1586         proto_tree_add_item(ospf_lsr_tree, hf_ospf_filter[OSPFF_ADV_ROUTER],
1587                             tvb, offset + 8, 4, FALSE);
1588
1589         offset += 12;
1590     }
1591 }
1592
1593 static void
1594 dissect_ospf_ls_upd(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version,
1595                     guint16 length, guint8 address_family)
1596 {
1597     proto_tree *ospf_lsa_upd_tree=NULL;
1598     proto_item *ti;
1599     guint32 lsa_nr;
1600     guint32 lsa_counter;
1601
1602     ti = proto_tree_add_text(tree, tvb, offset, length, "LS Update Packet");
1603     ospf_lsa_upd_tree = proto_item_add_subtree(ti, ett_ospf_lsa_upd);
1604
1605     lsa_nr = tvb_get_ntohl(tvb, offset);
1606     proto_tree_add_text(ospf_lsa_upd_tree, tvb, offset, 4, "Number of LSAs: %u",
1607                         lsa_nr);
1608     /* skip to the beginning of the first LSA */
1609     offset += 4; /* the LS Upd Packet contains only a 32 bit #LSAs field */
1610
1611     lsa_counter = 0;
1612     while (lsa_counter < lsa_nr) {
1613         if ( version == OSPF_VERSION_2)
1614             offset = dissect_ospf_v2_lsa(tvb, offset, ospf_lsa_upd_tree, TRUE);
1615         else if ( version == OSPF_VERSION_3)
1616             offset = dissect_ospf_v3_lsa(tvb, offset, ospf_lsa_upd_tree, TRUE,
1617                                          address_family);
1618         else
1619             /* We could potentially waste CPU cycles looping */
1620             lsa_counter = lsa_nr;
1621
1622         lsa_counter += 1;
1623     }
1624 }
1625
1626 static void
1627 dissect_ospf_ls_ack(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version,
1628                     guint16 length, guint8 address_family)
1629 {
1630     int orig_offset = offset;
1631     /* the body of a LS Ack packet simply contains zero or more LSA Headers */
1632     while (orig_offset + length > offset) {
1633         if ( version == OSPF_VERSION_2)
1634             offset = dissect_ospf_v2_lsa(tvb, offset, tree, FALSE);
1635         else
1636             if ( version == OSPF_VERSION_3)
1637                 offset = dissect_ospf_v3_lsa(tvb, offset, tree, FALSE,
1638                                              address_family);
1639     }
1640 }
1641
1642 /*
1643  * Returns if an LSA is opaque, i.e. requires special treatment
1644  */
1645 static int
1646 is_opaque(int lsa_type)
1647 {
1648     return (lsa_type >= OSPF_LSTYPE_OP_LINKLOCAL &&
1649         lsa_type <= OSPF_LSTYPE_OP_ASWIDE);
1650 }
1651
1652 /* MPLS/TE TLV types */
1653 #define MPLS_TLV_ROUTER    1
1654 #define MPLS_TLV_LINK      2
1655 #define OIF_TLV_TNA    32768
1656
1657 /* MPLS/TE Link STLV types */
1658 enum {
1659     MPLS_LINK_TYPE       = 1,           /* RFC 3630, OSPF-TE   */
1660     MPLS_LINK_ID,
1661     MPLS_LINK_LOCAL_IF,
1662     MPLS_LINK_REMOTE_IF,
1663     MPLS_LINK_TE_METRIC,
1664     MPLS_LINK_MAX_BW,
1665     MPLS_LINK_MAX_RES_BW,
1666     MPLS_LINK_UNRES_BW,
1667     MPLS_LINK_COLOR,
1668     MPLS_LINK_LOCAL_REMOTE_ID = 11,     /* RFC 4203, GMPLS     */
1669     MPLS_LINK_PROTECTION = 14,
1670     MPLS_LINK_IF_SWITCHING_DESC,
1671     MPLS_LINK_SHARED_RISK_GROUP,
1672     MPLS_LINK_BANDWIDTH_CONSTRAINT = 17 /* RFC 4124, OSPF-DSTE */
1673 };
1674
1675
1676 /* OIF TLV types */
1677 enum {
1678     OIF_LOCAL_NODE_ID = 32773,
1679     OIF_REMOTE_NODE_ID,
1680     OIF_SONET_SDH_SWITCHING_CAPABILITY,
1681     OIF_TNA_IPv4_ADDRESS,
1682     OIF_NODE_ID,
1683     OIF_TNA_IPv6_ADDRESS,
1684     OIF_TNA_NSAP_ADDRESS
1685 };
1686
1687 static const value_string mpls_link_stlv_str[] = {
1688     {MPLS_LINK_TYPE, "Link Type"},
1689     {MPLS_LINK_ID, "Link ID"},
1690     {MPLS_LINK_LOCAL_IF, "Local Interface IP Address"},
1691     {MPLS_LINK_REMOTE_IF, "Remote Interface IP Address"},
1692     {MPLS_LINK_TE_METRIC, "Traffic Engineering Metric"},
1693     {MPLS_LINK_MAX_BW, "Maximum Bandwidth"},
1694     {MPLS_LINK_MAX_RES_BW, "Maximum Reservable Bandwidth"},
1695     {MPLS_LINK_UNRES_BW, "Unreserved Bandwidth"},
1696     {MPLS_LINK_COLOR, "Resource Class/Color"},
1697     {MPLS_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier"},
1698     {MPLS_LINK_PROTECTION, "Link Protection Type"},
1699     {MPLS_LINK_IF_SWITCHING_DESC, "Interface Switching Capability Descriptor"},
1700     {MPLS_LINK_SHARED_RISK_GROUP, "Shared Risk Link Group"},
1701     {MPLS_LINK_BANDWIDTH_CONSTRAINT, "Bandwidth Constraints"},
1702     {OIF_LOCAL_NODE_ID, "Local Node ID"},
1703     {OIF_REMOTE_NODE_ID, "Remote Node ID"},
1704     {OIF_SONET_SDH_SWITCHING_CAPABILITY, "Sonet/SDH Interface Switching Capability"},
1705     {0, NULL},
1706 };
1707
1708 static const value_string oif_stlv_str[] = {
1709     {OIF_TNA_IPv4_ADDRESS, "TNA address"},
1710     {OIF_NODE_ID, "Node ID"},
1711     {OIF_TNA_IPv6_ADDRESS, "TNA address"},
1712     {OIF_TNA_NSAP_ADDRESS, "TNA address"},
1713     {0, NULL},
1714 };
1715
1716 /*
1717  * Dissect MPLS/TE opaque LSA
1718  */
1719 static void
1720 dissect_ospf_lsa_mpls(tvbuff_t *tvb, int offset, proto_tree *tree,
1721                       guint32 length)
1722 {
1723     proto_item *ti, *hidden_item;
1724     proto_tree *mpls_tree;
1725     proto_tree *tlv_tree;
1726     proto_tree *stlv_tree;
1727     proto_tree *stlv_admingrp_tree = NULL;
1728
1729     int tlv_type;
1730     int tlv_length;
1731     int tlv_end_offset;
1732
1733     int stlv_type, stlv_len, stlv_offset;
1734     const char *stlv_name;
1735     guint32 stlv_admingrp, mask;
1736     int i;
1737     guint8 switch_cap;
1738
1739     const guint8 allzero[] = { 0x00, 0x00, 0x00 };
1740     guint num_bcs = 0;
1741
1742     ti = proto_tree_add_text(tree, tvb, offset, length,
1743                              "MPLS Traffic Engineering LSA");
1744     hidden_item = proto_tree_add_item(tree, hf_ospf_filter[OSPFF_LS_MPLS],
1745                                tvb, offset, 2, FALSE);
1746     PROTO_ITEM_SET_HIDDEN(hidden_item);
1747     mpls_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls);
1748
1749     while (length != 0) {
1750         tlv_type = tvb_get_ntohs(tvb, offset);
1751         tlv_length = tvb_get_ntohs(tvb, offset + 2);
1752         tlv_end_offset = offset + tlv_length + 4;
1753
1754         switch (tlv_type) {
1755
1756         case MPLS_TLV_ROUTER:
1757             ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
1758                                      "Router Address: %s",
1759                                      ip_to_str(tvb_get_ptr(tvb, offset+4, 4)));
1760             tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_router);
1761             proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: 1 - Router Address");
1762             proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
1763                                 tlv_length);
1764             proto_tree_add_item(tlv_tree, hf_ospf_filter[OSPFF_LS_MPLS_ROUTERID],
1765                                 tvb, offset+4, 4, FALSE);
1766             break;
1767
1768         case MPLS_TLV_LINK:
1769             ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
1770                                      "Link Information");
1771             tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
1772             proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: 2 - Link Information");
1773             proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
1774                                 tlv_length);
1775             stlv_offset = offset + 4;
1776
1777             /* Walk down the sub-TLVs for link information */
1778             while (stlv_offset < tlv_end_offset) {
1779                 stlv_type = tvb_get_ntohs(tvb, stlv_offset);
1780                 stlv_len = tvb_get_ntohs(tvb, stlv_offset + 2);
1781                 stlv_name = val_to_str(stlv_type, mpls_link_stlv_str, "Unknown sub-TLV");
1782                 switch (stlv_type) {
1783
1784                 case MPLS_LINK_TYPE:
1785                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1786                                      "%s: %u - %s", stlv_name,
1787                                      tvb_get_guint8(tvb, stlv_offset + 4),
1788                                      val_to_str(tvb_get_guint8(tvb, stlv_offset + 4),
1789                                         mpls_link_stlv_ltype_str, "Unknown Link Type"));
1790                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1791                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1792                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1793                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1794                                         stlv_len);
1795                     proto_tree_add_item(stlv_tree, hf_ospf_filter[OSPFF_LS_MPLS_LINKTYPE],
1796                                         tvb, stlv_offset+4, 1,FALSE);
1797                     break;
1798
1799                 case MPLS_LINK_ID:
1800                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1801                                              "%s: %s", stlv_name,
1802                                              ip_to_str(tvb_get_ptr(tvb, stlv_offset + 4, 4)));
1803                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1804                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1805                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1806                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1807                                         stlv_len);
1808                     proto_tree_add_item(stlv_tree, hf_ospf_filter[OSPFF_LS_MPLS_LINKID],
1809                                         tvb, stlv_offset+4, 4, FALSE);
1810                     break;
1811
1812                 case MPLS_LINK_LOCAL_IF:
1813                 case MPLS_LINK_REMOTE_IF:
1814                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1815                                              "%s", stlv_name);
1816                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1817                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1818                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1819                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1820                                         stlv_len);
1821                     /*   The Local/Remote Interface IP Address sub-TLV is TLV type 3/4, and is 4N
1822                        octets in length, where N is the number of neighbor addresses. */
1823                     for (i=0; i < stlv_len; i+=4)
1824                       proto_tree_add_item(stlv_tree,
1825                                           stlv_type==MPLS_LINK_LOCAL_IF ?
1826                                           hf_ospf_filter[OSPFF_LS_MPLS_LOCAL_ADDR] :
1827                                           hf_ospf_filter[OSPFF_LS_MPLS_REMOTE_ADDR],
1828                                           tvb, stlv_offset+4+i, 4, FALSE);
1829                     break;
1830
1831                 case MPLS_LINK_TE_METRIC:
1832                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1833                                              "%s: %u", stlv_name,
1834                                              tvb_get_ntohl(tvb, stlv_offset + 4));
1835                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1836                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1837                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1838                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1839                                         stlv_len);
1840                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %u", stlv_name,
1841                                         tvb_get_ntohl(tvb, stlv_offset + 4));
1842                     break;
1843
1844                 case MPLS_LINK_COLOR:
1845                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1846                                              "%s: 0x%08x", stlv_name,
1847                                              tvb_get_ntohl(tvb, stlv_offset + 4));
1848                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1849                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1850                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1851                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1852                                         stlv_len);
1853                     stlv_admingrp = tvb_get_ntohl(tvb, stlv_offset + 4);
1854                     mask = 1;
1855                     ti = proto_tree_add_item(stlv_tree, hf_ospf_filter[OSPFF_LS_MPLS_LINKCOLOR],
1856                                         tvb, stlv_offset+4, 4, FALSE);
1857                     stlv_admingrp_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv_admingrp);
1858                     if (stlv_admingrp_tree == NULL)
1859                         return;
1860                     for (i = 0 ; i < 32 ; i++) {
1861                         if ((stlv_admingrp & mask) != 0) {
1862                             proto_tree_add_text(stlv_admingrp_tree, tvb, stlv_offset+4,
1863                                 4, "Group %d", i);
1864                         }
1865                         mask <<= 1;
1866                     }
1867                     break;
1868
1869                 case MPLS_LINK_MAX_BW:
1870                 case MPLS_LINK_MAX_RES_BW:
1871                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1872                                              "%s: %.10g bytes/s (%.0f bits/s)", stlv_name,
1873                                              tvb_get_ntohieee_float(tvb, stlv_offset + 4),
1874                                              tvb_get_ntohieee_float(tvb, stlv_offset + 4) * 8.0);
1875                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1876                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1877                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1878                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1879                                         stlv_len);
1880                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %.10g bytes/s (%.0f bits/s)", stlv_name,
1881                                         tvb_get_ntohieee_float(tvb, stlv_offset + 4),
1882                                         tvb_get_ntohieee_float(tvb, stlv_offset + 4) * 8.0);
1883                     break;
1884
1885                 case MPLS_LINK_UNRES_BW:
1886                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1887                                              "%s", stlv_name);
1888                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1889                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1890                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1891                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1892                                         stlv_len);
1893                     for (i = 0; i < 8; i++) {
1894                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+4+(i*4), 4,
1895                                             "Pri (or TE-Class) %d: %.10g bytes/s (%.0f bits/s)", i,
1896                                             tvb_get_ntohieee_float(tvb, stlv_offset + 4 + i*4),
1897                                             tvb_get_ntohieee_float(tvb, stlv_offset + 4 + i*4) * 8.0);
1898                     }
1899                     break;
1900
1901                 case MPLS_LINK_BANDWIDTH_CONSTRAINT:
1902                     /*
1903                       The "Bandwidth Constraints" sub-TLV format is illustrated below:
1904
1905                       0                   1                   2                   3
1906                       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1907                       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1908                       | BC Model Id   |           Reserved                            |
1909                       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1910                       |                       BC0 value                               |
1911                       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1912                       //                       . . .                                 //
1913                       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1914                       |                       BCh value                               |
1915                       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1916                     */
1917
1918                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1919                                              "%s", stlv_name);
1920
1921                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1922
1923                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1924                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1925
1926                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1927                                         stlv_len);
1928
1929                     proto_tree_add_item(stlv_tree, hf_ospf_filter[OSPFF_LS_MPLS_BC_MODEL_ID],
1930                         tvb, stlv_offset+4, 1, FALSE);
1931
1932                     /* 3 octets reserved +5, +6 and +7 (all 0x00) */
1933                     if(tvb_memeql(tvb, stlv_offset+5, allzero, 3) == -1) {
1934                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+5, 3,
1935                                             "Warning: these bytes are reserved and must be 0x00");
1936                     }
1937
1938                     if(((stlv_len % 4)!=0)) {
1939                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, stlv_len,
1940                                             "Malformed Packet: Length must be N x 4 octets");
1941                         break;
1942                     }
1943
1944                     /* stlv_len shound range from 4 to 36 bytes */
1945                     num_bcs = (stlv_len - 4)/4;
1946
1947                     if(num_bcs>8) {
1948                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, stlv_len,
1949                                             "Malformed Packet: too many BC (%u)", num_bcs);
1950                         break;
1951                     }
1952
1953                     if(num_bcs==0) {
1954                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, stlv_len,
1955                                             "Malformed Packet: Bandwidth Constraints sub-TLV with no BC?");
1956                         break;
1957                     }
1958
1959                     for(i = 0; i < (int) num_bcs; i++) {
1960                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+8+(i*4), 4,
1961                                             "BC %d: %.10g bytes/s (%.0f bits/s)", i,
1962                                             tvb_get_ntohieee_float(tvb, stlv_offset + 8 + i*4),
1963                                             tvb_get_ntohieee_float(tvb, stlv_offset + 8 + i*4) * 8.0);
1964                     }
1965                     break;
1966
1967                 case MPLS_LINK_LOCAL_REMOTE_ID:
1968                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1969                                              "%s: %d (0x%x) - %d (0x%x)", stlv_name,
1970                                              tvb_get_ntohl(tvb, stlv_offset + 4),
1971                                              tvb_get_ntohl(tvb, stlv_offset + 4),
1972                                              tvb_get_ntohl(tvb, stlv_offset + 8),
1973                                              tvb_get_ntohl(tvb, stlv_offset + 8));
1974                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1975
1976                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1977                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1978                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1979                                         stlv_len);
1980                     proto_tree_add_item(stlv_tree,
1981                                         hf_ospf_filter[OSPFF_LS_MPLS_LOCAL_IFID],
1982                                         tvb, stlv_offset+4, 4, FALSE);
1983                     proto_tree_add_item(stlv_tree,
1984                                         hf_ospf_filter[OSPFF_LS_MPLS_REMOTE_IFID],
1985                                         tvb, stlv_offset+8, 4, FALSE);
1986                     break;
1987
1988                 case MPLS_LINK_IF_SWITCHING_DESC:
1989                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1990                                              "%s", stlv_name);
1991                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1992                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1993                                         "TLV Type: %u: %s", stlv_type, stlv_name);
1994                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1995                                         stlv_len);
1996                     switch_cap = tvb_get_guint8 (tvb, stlv_offset+4);
1997                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "Switching Type: %s",
1998                                         rval_to_str(tvb_get_guint8(tvb,stlv_offset+4),
1999                                                    gmpls_switching_type_rvals, "Unknown (%d)"));
2000                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+5, 1, "Encoding: %s",
2001                                         rval_to_str(tvb_get_guint8(tvb,stlv_offset+5),
2002                                                    gmpls_lsp_enc_rvals, "Unknown (%d)"));
2003                     for (i = 0; i < 8; i++) {
2004                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+8+(i*4), 4,
2005                                             "Pri %d: %.10g bytes/s (%.0f bits/s)", i,
2006                                             tvb_get_ntohieee_float(tvb, stlv_offset + 8 + i*4),
2007                                             tvb_get_ntohieee_float(tvb, stlv_offset + 8 + i*4) * 8.0);
2008                     }
2009                     if (switch_cap >=1 && switch_cap <=4) {           /* PSC-1 .. PSC-4 */
2010                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+40, 4,
2011                                             "Minimum LSP bandwidth: %.10g bytes/s (%.0f bits/s)",
2012                                             tvb_get_ntohieee_float(tvb, stlv_offset + 40),
2013                                             tvb_get_ntohieee_float(tvb, stlv_offset + 40) * 8.0);
2014                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+44, 2,
2015                                             "Interface MTU: %d", tvb_get_ntohs(tvb, stlv_offset+44));
2016                     }
2017
2018                     if (switch_cap == 100) {                         /* TDM */
2019                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+40, 4,
2020                                             "Minimum LSP bandwidth: %.10g bytes/s (%.0f bits/s)",
2021                                             tvb_get_ntohieee_float(tvb, stlv_offset + 40),
2022                                             tvb_get_ntohieee_float(tvb, stlv_offset + 40) * 8.0);
2023                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+44, 2,
2024                                             "SONET/SDH: %s",
2025                                             tvb_get_guint8(tvb, stlv_offset+44) ?
2026                                             "Arbitrary" : "Standard");
2027                     }
2028                     break;
2029                 case MPLS_LINK_PROTECTION:
2030                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
2031                                              "%s", stlv_name);
2032                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
2033                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
2034                                         "TLV Type: %u: %s", stlv_type, stlv_name);
2035                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
2036                                         stlv_len);
2037                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "Protection Capability: %s (0x%x)",
2038                                         val_to_str(tvb_get_guint8(tvb,stlv_offset+4), gmpls_protection_cap_str, "Unknown (%d)"),tvb_get_guint8(tvb,stlv_offset+4));
2039                     break;
2040
2041                 case MPLS_LINK_SHARED_RISK_GROUP:
2042                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
2043                                              "%s", stlv_name);
2044                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
2045                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
2046                                         "TLV Type: %u: %s", stlv_type, stlv_name);
2047                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
2048                                         stlv_len);
2049                     for (i=0; i < stlv_len; i+=4)
2050                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+4+i, 4, "Shared Risk Link Group: %u",
2051                                         tvb_get_ntohl(tvb,stlv_offset+4+i));
2052                     break;
2053
2054                 case OIF_LOCAL_NODE_ID:
2055                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
2056                                              "%s: %s", stlv_name,
2057                                              ip_to_str(tvb_get_ptr(tvb, stlv_offset + 4, 4)));
2058                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
2059                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
2060                                         "TLV Type: %u: %s", stlv_type, stlv_name);
2061                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
2062                                         stlv_len);
2063                     proto_tree_add_item(stlv_tree,
2064                                         hf_ospf_filter[OSPFF_LS_OIF_LOCAL_NODE_ID],
2065                                         tvb, stlv_offset + 4, 4, FALSE);
2066                     break;
2067
2068                 case OIF_REMOTE_NODE_ID:
2069                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
2070                                              "%s: %s", stlv_name,
2071                                              ip_to_str(tvb_get_ptr(tvb, stlv_offset + 4, 4)));
2072                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
2073                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
2074                                         "TLV Type: %u: %s", stlv_type, stlv_name);
2075                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
2076                                         stlv_len);
2077                     proto_tree_add_item(stlv_tree,
2078                                         hf_ospf_filter[OSPFF_LS_OIF_REMOTE_NODE_ID],
2079                                         tvb, stlv_offset + 4, 4, FALSE);
2080                     break;
2081
2082                 case OIF_SONET_SDH_SWITCHING_CAPABILITY:
2083                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4, "%s", stlv_name);
2084                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
2085                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
2086                                         "TLV Type: %u: %s", stlv_type, stlv_name);
2087                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
2088                                         stlv_len);
2089                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "Switching Cap: %s",
2090                                         rval_to_str(tvb_get_guint8 (tvb, stlv_offset+4),
2091                                                    gmpls_switching_type_rvals, "Unknown (%d)"));
2092                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+5, 1, "Encoding: %s",
2093                                         rval_to_str(tvb_get_guint8(tvb,stlv_offset+5),
2094                                                    gmpls_lsp_enc_rvals, "Unknown (%d)"));
2095                     for (i = 0; i < (stlv_len - 4) / 4; i++) {
2096                         proto_tree_add_text(stlv_tree, tvb, stlv_offset+8+(i*4), 4,
2097                                             "%s: %d free timeslots",
2098                                             val_to_str(tvb_get_guint8(tvb, stlv_offset+8+(i*4)),
2099                                                        gmpls_sonet_signal_type_str,
2100                                                        "Unknown Signal Type (%d)"),
2101                                             tvb_get_ntoh24(tvb, stlv_offset + 9 + i*4));
2102                     }
2103
2104                     break;
2105                 default:
2106                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
2107                                         "Unknown Link sub-TLV: %u", stlv_type);
2108                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
2109                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
2110                                         "TLV Type: %u: %s", stlv_type, stlv_name);
2111                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
2112                                         stlv_len);
2113                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, stlv_len,
2114                                         "TLV Value");
2115                     break;
2116                 }
2117                 stlv_offset += ((stlv_len+4+3)/4)*4;
2118             }
2119             break;
2120
2121         case OIF_TLV_TNA:
2122             ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
2123                                      "TNA Information");
2124             tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_oif_tna);
2125             proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: 32768 - TNA Information");
2126             proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
2127                                 tlv_length);
2128             stlv_offset = offset + 4;
2129
2130             /* Walk down the sub-TLVs for TNA information */
2131             while (stlv_offset < tlv_end_offset) {
2132                 stlv_type = tvb_get_ntohs(tvb, stlv_offset);
2133                 stlv_len = tvb_get_ntohs(tvb, stlv_offset + 2);
2134                 stlv_name = val_to_str(stlv_type, oif_stlv_str, "Unknown sub-TLV");
2135                 switch (stlv_type) {
2136
2137                 case OIF_NODE_ID:
2138                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
2139                                              "%s: %s", stlv_name,
2140                                              ip_to_str(tvb_get_ptr(tvb, stlv_offset + 4, 4)));
2141                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_oif_tna_stlv);
2142                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
2143                                         "TLV Type: %u: %s", stlv_type, stlv_name);
2144                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
2145                                         stlv_len);
2146                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %s", stlv_name,
2147                                         ip_to_str(tvb_get_ptr(tvb, stlv_offset + 4, 4)));
2148                     break;
2149
2150                 case OIF_TNA_IPv4_ADDRESS:
2151                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
2152                                              "%s (IPv4): %s", stlv_name,
2153                                              ip_to_str(tvb_get_ptr(tvb, stlv_offset + 8, 4)));
2154                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_oif_tna_stlv);
2155                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
2156                                         "TLV Type: %u: %s (IPv4)", stlv_type, stlv_name);
2157                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u", stlv_len);
2158                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "Addr Length: %u",
2159                                         tvb_get_guint8 (tvb, stlv_offset+4));
2160                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+8, stlv_len - 4, "TNA Addr: %s",
2161                                         ip_to_str(tvb_get_ptr(tvb, stlv_offset + 8, 4)));
2162                     break;
2163
2164                 case OIF_TNA_IPv6_ADDRESS:
2165                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
2166                                              "%s (IPv6): %s", stlv_name,
2167                                              ip6_to_str((const struct e_in6_addr *)
2168                                                          tvb_get_ptr(tvb, stlv_offset + 8, 16)));
2169                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_oif_tna_stlv);
2170                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
2171                                         "TLV Type: %u: %s (IPv6)", stlv_type, stlv_name);
2172                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u", stlv_len);
2173                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "Addr Length: %u",
2174                                         tvb_get_guint8 (tvb, stlv_offset+4));
2175                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+8, stlv_len - 4, "TNA Addr: %s",
2176                                         ip6_to_str((const struct e_in6_addr *)
2177                                                     tvb_get_ptr(tvb, stlv_offset + 8, 16)));
2178                     break;
2179
2180                 case OIF_TNA_NSAP_ADDRESS:
2181                     ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
2182                                              "%s (NSAP): %s", stlv_name,
2183                                              tvb_bytes_to_str (tvb, stlv_offset + 8, stlv_len - 4));
2184                     stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_oif_tna_stlv);
2185                     proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
2186                                         "TLV Type: %u: %s (NSAP)", stlv_type, stlv_name);
2187                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u", stlv_len);
2188                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "Addr Length: %u",
2189                                             tvb_get_guint8 (tvb, stlv_offset+4));
2190                     proto_tree_add_text(stlv_tree, tvb, stlv_offset+8, stlv_len - 4, "TNA Addr: %s",
2191                                         tvb_bytes_to_str(tvb, stlv_offset+8, stlv_len - 4));
2192                     break;
2193
2194                 default:
2195                     proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
2196                                         "Unknown Link sub-TLV: %u", stlv_type);
2197                     break;
2198                 }
2199                 stlv_offset += ((stlv_len+4+3)/4)*4;
2200             }
2201             break;
2202         default:
2203             ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
2204                                      "Unknown LSA: %u", tlv_type);
2205             tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
2206             proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: %u - Unknown",
2207                                 tlv_type);
2208             proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
2209                                 tlv_length);
2210             proto_tree_add_text(tlv_tree, tvb, offset+4, tlv_length, "TLV Data");
2211             break;
2212         }
2213
2214         offset += tlv_length + 4;
2215         length -= tlv_length + 4;
2216     }
2217 }
2218
2219 /*
2220  * Dissect the TLVs within a Grace-LSA as defined by RFC 3623
2221  */
2222 static void dissect_ospf_lsa_grace_tlv (tvbuff_t *tvb, int offset,
2223                                     proto_tree *tree, guint32 length)
2224 {
2225     guint16 tlv_type;
2226     guint16 tlv_length;
2227     int tlv_length_with_pad; /* The total length of the TLV including the type
2228                                 and length fields and any padding */
2229     guint32 grace_period;
2230     guint8 restart_reason;
2231     guint32 restart_ip;
2232     proto_tree *tlv_tree;
2233     proto_item *tree_item;
2234     proto_item *grace_tree_item;
2235
2236     if (!tree) { return; }
2237
2238     while (length > 0)
2239     {
2240         tlv_type = tvb_get_ntohs(tvb, offset);
2241         tlv_length = tvb_get_ntohs(tvb, offset + 2);
2242         /* The total length of the TLV including the type, length, value and
2243          * pad bytes (TLVs are padded to 4 octet alignment).
2244          */
2245         tlv_length_with_pad = tlv_length + 4 + ((4 - (tlv_length % 4)) % 4);
2246
2247         tree_item = proto_tree_add_item(tree, hf_ospf_filter[OSPFF_V2_GRACE_TLV], tvb, offset,
2248                 tlv_length_with_pad, FALSE);
2249         tlv_tree = proto_item_add_subtree(tree_item, ett_ospf_lsa_grace_tlv);
2250         proto_tree_add_text(tlv_tree, tvb, offset, 2, "Type: %s (%u)",
2251                 val_to_str(tlv_type, grace_tlv_type_vals, "Unknown grace-LSA TLV"), tlv_type);
2252         proto_tree_add_text(tlv_tree, tvb, offset + 2, 2, "Length: %u", tlv_length);
2253
2254         switch (tlv_type) {
2255             case GRACE_TLV_PERIOD:
2256                 grace_period = tvb_get_ntohl(tvb, offset + 4);
2257                 grace_tree_item = proto_tree_add_item(tlv_tree, hf_ospf_filter[OSPFF_V2_GRACE_PERIOD], tvb,
2258                         offset + 4, tlv_length, FALSE);
2259                 proto_item_append_text(grace_tree_item, " seconds");
2260                 proto_item_set_text(tree_item, "Grace Period: %u seconds", grace_period);
2261                 break;
2262             case GRACE_TLV_REASON:
2263                 restart_reason = tvb_get_guint8(tvb, offset + 4);
2264                 proto_tree_add_item(tlv_tree, hf_ospf_filter[OSPFF_V2_GRACE_REASON], tvb, offset + 4,
2265                         tlv_length, FALSE);
2266                 proto_item_set_text(tree_item, "Restart Reason: %s (%u)",
2267                         val_to_str(restart_reason, restart_reason_vals, "Unknown Restart Reason"),
2268                         restart_reason);
2269                 break;
2270             case GRACE_TLV_IP:
2271                 restart_ip = tvb_get_ipv4(tvb, offset + 4);
2272                 proto_tree_add_item(tlv_tree, hf_ospf_filter[OSPFF_V2_GRACE_IP], tvb, offset + 4,
2273                         tlv_length, FALSE);
2274                 proto_item_set_text(tree_item, "Restart IP: %s (%s)",
2275                         get_hostname(restart_ip), ip_to_str((guint8 *)&restart_ip));
2276                 break;
2277             default:
2278                 proto_item_set_text(tree_item, "Unknown grace-LSA TLV");
2279                 break;
2280         }
2281         if (4 + tlv_length < tlv_length_with_pad) {
2282             proto_tree_add_text(tlv_tree, tvb, offset + 4 + tlv_length,
2283                     tlv_length_with_pad - (4 + tlv_length), "Pad Bytes (%u)",
2284                     tlv_length_with_pad - (4 + tlv_length) );
2285         }
2286         offset += tlv_length_with_pad;
2287         length -= tlv_length_with_pad;
2288     }
2289 }
2290
2291 /*
2292  * Dissect opaque LSAs
2293  */
2294 static void
2295 dissect_ospf_lsa_opaque(tvbuff_t *tvb, int offset, proto_tree *tree,
2296                         guint8 ls_id_type, guint32 length)
2297 {
2298     switch (ls_id_type) {
2299
2300     case OSPF_LSA_MPLS_TE:
2301         dissect_ospf_lsa_mpls(tvb, offset, tree, length);
2302         break;
2303     case OSPF_LSA_GRACE:
2304         dissect_ospf_lsa_grace_tlv(tvb, offset, tree, length);
2305         break;
2306
2307     default:
2308         proto_tree_add_text(tree, tvb, offset, length,
2309                             "Unknown LSA Type %u", ls_id_type);
2310         break;
2311     } /* switch on opaque LSA id */
2312 }
2313
2314 static int
2315 dissect_ospf_v2_lsa(tvbuff_t *tvb, int offset, proto_tree *tree,
2316                  gboolean disassemble_body)
2317 {
2318     proto_tree *ospf_lsa_tree;
2319     proto_item *ti, *hidden_item;
2320
2321     guint8               ls_type;
2322     guint16              ls_length;
2323     int                  end_offset;
2324     guint16              nr_links;
2325     guint16              nr_metric;
2326
2327     /* router LSA */
2328     guint8               link_type;
2329     guint16              link_counter;
2330     guint8               metric_counter;
2331     const char          *link_type_str;
2332     const char          *link_type_short_str;
2333     const char          *link_id;
2334     const char          *metric_type_str;
2335
2336     /* AS-external LSA */
2337     guint8               options;
2338
2339     /* opaque LSA */
2340     guint8               ls_id_type;
2341
2342     ls_type = tvb_get_guint8(tvb, offset + 3);
2343     ls_length = tvb_get_ntohs(tvb, offset + 18);
2344     end_offset = offset + ls_length;
2345
2346     if (disassemble_body) {
2347         ti = proto_tree_add_text(tree, tvb, offset, ls_length,
2348                                  "LS Type: %s",
2349                                  val_to_str(ls_type, ls_type_vals, "Unknown (%d)"));
2350     } else {
2351         ti = proto_tree_add_text(tree, tvb, offset, OSPF_LSA_HEADER_LENGTH,
2352                                  "LSA Header");
2353     }
2354     ospf_lsa_tree = proto_item_add_subtree(ti, ett_ospf_lsa);
2355
2356     proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "LS Age: %u seconds",
2357                         tvb_get_ntohs(tvb, offset) & ~OSPF_DNA_LSA);
2358     proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "Do Not Age: %s",
2359                         (tvb_get_ntohs(tvb, offset) & OSPF_DNA_LSA) ? "True" : "False");
2360     options = tvb_get_guint8 (tvb, offset + 2);
2361     dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset + 2, &bfinfo_v2_options);
2362     proto_tree_add_item(ospf_lsa_tree, hf_ospf_filter[OSPFF_LS_TYPE], tvb,
2363                         offset + 3, 1, FALSE);
2364     if (ospf_ls_type_to_filter(ls_type) != -1) {
2365         hidden_item = proto_tree_add_item(ospf_lsa_tree,
2366                                           hf_ospf_filter[ospf_ls_type_to_filter(ls_type)], tvb,
2367                                           offset + 3, 1, FALSE);
2368         PROTO_ITEM_SET_HIDDEN(hidden_item);
2369     }
2370
2371     if (options & OSPF_V2_OPTIONS_MT) {
2372         metric_type_str = "MT-ID";
2373     } else {
2374         metric_type_str = "TOS";
2375     }
2376
2377     if (is_opaque(ls_type)) {
2378         ls_id_type = tvb_get_guint8(tvb, offset + 4);
2379         proto_tree_add_uint(ospf_lsa_tree, hf_ospf_filter[OSPFF_LS_OPAQUE_TYPE],
2380                             tvb, offset + 4, 1, ls_id_type);
2381
2382         switch (ls_id_type) {
2383
2384         case OSPF_LSA_MPLS_TE:
2385             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 5, 1, "Link State ID TE-LSA Reserved: %u",
2386                                 tvb_get_guint8(tvb, offset + 5));
2387             proto_tree_add_item(ospf_lsa_tree, hf_ospf_filter[OSPFF_LS_MPLS_TE_INSTANCE],
2388                                 tvb, offset + 6, 2, FALSE);
2389             break;
2390
2391         default:
2392             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 5, 3, "Link State ID Opaque ID: %u",
2393                                 tvb_get_ntoh24(tvb, offset + 5));
2394             break;
2395         }
2396     } else {
2397         ls_id_type = 0;
2398         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link State ID: %s",
2399                             ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
2400     }
2401
2402     proto_tree_add_item(ospf_lsa_tree, hf_ospf_filter[OSPFF_ADV_ROUTER],
2403                         tvb, offset + 8, 4, FALSE);
2404     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "LS Sequence Number: 0x%08x",
2405                         tvb_get_ntohl(tvb, offset + 12));
2406     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 16, 2, "LS Checksum: 0x%04x",
2407                         tvb_get_ntohs(tvb, offset + 16));
2408
2409     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 18, 2, "Length: %u",
2410                         ls_length);
2411
2412     /* skip past the LSA header to the body */
2413     offset += OSPF_LSA_HEADER_LENGTH;
2414     if (ls_length <= OSPF_LSA_HEADER_LENGTH)
2415         return offset;  /* no data, or bogus length */
2416     ls_length -= OSPF_LSA_HEADER_LENGTH;
2417
2418     if (!disassemble_body)
2419         return offset;
2420
2421     switch (ls_type){
2422
2423     case OSPF_LSTYPE_ROUTER:
2424         /* flags field in an router-lsa */
2425         if (options & OSPF_V2_OPTIONS_MT) {
2426             dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset, &bfinfo_v2_router_lsa_mt_flags);
2427         } else {
2428             dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset, &bfinfo_v2_router_lsa_flags);
2429         }
2430
2431         nr_links = tvb_get_ntohs(tvb, offset + 2);
2432         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2, "Number of Links: %u",
2433                             nr_links);
2434         offset += 4;
2435         /* nr_links links follow
2436          * maybe we should put each of the links into its own subtree ???
2437          */
2438         for (link_counter = 1; link_counter <= nr_links; link_counter++) {
2439             proto_tree *ospf_lsa_router_link_tree;
2440             proto_item *ti_local;
2441
2442
2443             /* check the Link Type and ID */
2444             link_type = tvb_get_guint8(tvb, offset + 8);
2445             switch (link_type) {
2446
2447             case OSPF_LINK_PTP:
2448                 link_type_str="Point-to-point connection to another router";
2449                 link_type_short_str="PTP";
2450                 link_id="Neighboring router's Router ID";
2451                 break;
2452
2453             case OSPF_LINK_TRANSIT:
2454                 link_type_str="Connection to a transit network";
2455                 link_type_short_str="Transit";
2456                 link_id="IP address of Designated Router";
2457                 break;
2458
2459             case OSPF_LINK_STUB:
2460                 link_type_str="Connection to a stub network";
2461                 link_type_short_str="Stub";
2462                 link_id="IP network/subnet number";
2463                 break;
2464
2465             case OSPF_LINK_VIRTUAL:
2466                 link_type_str="Virtual link";
2467                 link_type_short_str="Virtual";
2468                 link_id="Neighboring router's Router ID";
2469                 break;
2470
2471             default:
2472                 link_type_str="Unknown link type";
2473                 link_type_short_str="Unknown";
2474                 link_id="Unknown link ID";
2475                 break;
2476             }
2477
2478             nr_metric = tvb_get_guint8(tvb, offset + 9);
2479
2480
2481             ti_local = proto_tree_add_text(ospf_lsa_tree, tvb, offset, 12 + 4 * nr_metric,
2482                                      "Type: %-8s ID: %-15s Data: %-15s Metric: %d",
2483                                      link_type_short_str,
2484                                      ip_to_str(tvb_get_ptr(tvb, offset, 4)),
2485                                      ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)),
2486                                      tvb_get_ntohs(tvb, offset + 10));
2487
2488             ospf_lsa_router_link_tree = proto_item_add_subtree(ti_local, ett_ospf_lsa_router_link);
2489
2490             proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset, 4, "%s: %s", link_id,
2491                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
2492
2493             /* link_data should be specified in detail (e.g. network mask) (depends on link type)*/
2494             proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset + 4, 4, "Link Data: %s",
2495                                 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
2496
2497             proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset + 8, 1, "Link Type: %u - %s",
2498                                 link_type, link_type_str);
2499             proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset + 9, 1, "Number of %s metrics: %u",
2500                                 metric_type_str, nr_metric);
2501             proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset + 10, 2, "%s 0 metric: %u",
2502                                 metric_type_str, tvb_get_ntohs(tvb, offset + 10));
2503
2504             offset += 12;
2505
2506             /* nr_metric metrics may follow each link
2507              * According to RFC4915 the TOS metrics was never deployed and was subsequently deprecated,
2508              * but decoding still present because MT-ID use the same structure.
2509              */
2510             for (metric_counter = 1; metric_counter <= nr_metric; metric_counter++) {
2511                 proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset, 4, "%s: %u, Metric: %u",
2512                                     metric_type_str,
2513                                     tvb_get_guint8(tvb, offset),
2514                                     tvb_get_ntohs(tvb, offset + 2));
2515                 offset += 4;
2516             }
2517         }
2518         break;
2519
2520     case OSPF_LSTYPE_NETWORK:
2521         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
2522                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
2523         offset += 4;
2524
2525         while (offset < end_offset) {
2526             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Attached Router: %s",
2527                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
2528             offset += 4;
2529         }
2530         break;
2531
2532     case OSPF_LSTYPE_SUMMERY:
2533     /* Type 3 and 4 LSAs have the same format */
2534     case OSPF_LSTYPE_ASBR:
2535         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
2536                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
2537         offset += 4;
2538
2539         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Metric: %u",
2540                             tvb_get_ntoh24(tvb, offset + 1));
2541         offset += 4;
2542
2543         /* Metric specific information, if any */
2544         while (offset < end_offset) {
2545             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "%s: %u, Metric: %u",
2546                                 metric_type_str,
2547                                 tvb_get_guint8(tvb, offset),
2548                                 tvb_get_ntoh24(tvb, offset + 1));
2549             offset += 4;
2550         }
2551         break;
2552
2553     case OSPF_LSTYPE_ASEXT:
2554     case OSPF_LSTYPE_ASEXT7:
2555         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
2556                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
2557         offset += 4;
2558
2559         options = tvb_get_guint8(tvb, offset);
2560         if (options & 0x80) { /* check whether or not E bit is set */
2561             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
2562                     "External Type: Type 2 (metric is larger than any other link state path)");
2563         } else {
2564             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
2565                     "External Type: Type 1 (metric is specified in the same units as interface cost)");
2566         }
2567         /* the metric field of a AS-external LAS is specified in 3 bytes */
2568         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 1, 3, "Metric: %u",
2569                             tvb_get_ntoh24(tvb, offset + 1));
2570         offset += 4;
2571
2572         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Forwarding Address: %s",
2573                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
2574         offset += 4;
2575
2576         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "External Route Tag: %u",
2577                             tvb_get_ntohl(tvb, offset));
2578         offset += 4;
2579
2580         /* Metric specific information, if any */
2581         while (offset < end_offset) {
2582             options = tvb_get_guint8(tvb, offset);
2583             if (options & 0x80) { /* check whether or not E bit is set */
2584                 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
2585                         "External Type: Type 2 (metric is larger than any other link state path)");
2586             } else {
2587                 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
2588                         "External Type: Type 1 (metric is specified in the same units as interface cost)");
2589             }
2590             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "%s: %u, Metric: %u",
2591                                 metric_type_str, options & 0x7F,
2592                                 tvb_get_ntoh24(tvb, offset + 1));
2593             offset += 4;
2594
2595             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Forwarding Address: %s",
2596                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
2597             offset += 4;
2598
2599             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "External Route Tag: %u",
2600                                 tvb_get_ntohl(tvb, offset));
2601             offset += 4;
2602         }
2603         break;
2604
2605     case OSPF_LSTYPE_OP_LINKLOCAL:
2606     case OSPF_LSTYPE_OP_AREALOCAL:
2607     case OSPF_LSTYPE_OP_ASWIDE:
2608         /*
2609          * RFC 2370 opaque LSAs.
2610          */
2611         dissect_ospf_lsa_opaque(tvb, offset, ospf_lsa_tree, ls_id_type,
2612                                 ls_length);
2613         offset += ls_length;
2614         break;
2615
2616     default:
2617         /* unknown LSA type */
2618         proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
2619                             "Unknown LSA Type");
2620         offset += ls_length;
2621         break;
2622     }
2623     /* return the offset of the next LSA */
2624     return offset;
2625 }
2626
2627 static int
2628 dissect_ospf_v3_lsa(tvbuff_t *tvb, int offset, proto_tree *tree,
2629                     gboolean disassemble_body, guint8 address_family)
2630 {
2631     proto_tree *ospf_lsa_tree;
2632     proto_item *ti;
2633
2634     guint16              ls_type;
2635     guint16              ls_length;
2636     int                  end_offset;
2637     guint8               reserved;
2638
2639     /* router LSA */
2640     guint8               link_type;
2641     const char          *link_type_str;
2642     guint32              metric;
2643
2644     guint8               router_priority;
2645     guint32              number_prefixes;
2646     guint8               prefix_length;
2647     guint16              reserved16;
2648
2649     guint16              referenced_ls_type;
2650
2651     guint8               flags;
2652     guint32              external_route_tag;
2653
2654
2655     ls_type = tvb_get_ntohs(tvb, offset + 2);
2656     ls_length = tvb_get_ntohs(tvb, offset + 18);
2657     end_offset = offset + ls_length;
2658
2659     if (disassemble_body) {
2660         ti = proto_tree_add_text(tree, tvb, offset, ls_length,
2661                                  "%s (Type: 0x%04x)", val_to_str(ls_type, v3_ls_type_vals,"Unknown"), ls_type);
2662     } else {
2663         ti = proto_tree_add_text(tree, tvb, offset, OSPF_LSA_HEADER_LENGTH,
2664                                  "LSA Header");
2665     }
2666     ospf_lsa_tree = proto_item_add_subtree(ti, ett_ospf_lsa);
2667
2668     proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "LS Age: %u seconds",
2669                         tvb_get_ntohs(tvb, offset) & ~OSPF_DNA_LSA);
2670     proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "Do Not Age: %s",
2671                         (tvb_get_ntohs(tvb, offset) & OSPF_DNA_LSA) ? "True" : "False");
2672
2673     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2, "LSA Type: 0x%04x (%s)",
2674                         ls_type, val_to_str(ls_type, v3_ls_type_vals,"Unkown"));
2675
2676     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link State ID: %s",
2677                             ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
2678
2679     proto_tree_add_item(ospf_lsa_tree, hf_ospf_filter[OSPFF_ADV_ROUTER],
2680                         tvb, offset + 8, 4, FALSE);
2681     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "LS Sequence Number: 0x%08x",
2682                         tvb_get_ntohl(tvb, offset + 12));
2683     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 16, 2, "LS Checksum: 0x%04x",
2684                         tvb_get_ntohs(tvb, offset + 16));
2685
2686     proto_tree_add_text(ospf_lsa_tree, tvb, offset + 18, 2, "Length: %u",
2687                         ls_length);
2688
2689     /* skip past the LSA header to the body */
2690     offset += OSPF_LSA_HEADER_LENGTH;
2691     ls_length -= OSPF_LSA_HEADER_LENGTH;
2692
2693     if (!disassemble_body)
2694         return offset;
2695
2696     switch (ls_type){
2697
2698
2699     case OSPF_V3_LSTYPE_ROUTER:
2700         /* flags field in an router-lsa */
2701         dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset, &bfinfo_v3_router_lsa_flags);
2702
2703         /* options field in an router-lsa */
2704         dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset + 1, &bfinfo_v3_options);
2705
2706         /* skip the router-lsa flags and options */
2707         offset+=4;
2708         ls_length-=4;
2709
2710         if (ls_length > 0)
2711              proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
2712                    "Router Interfaces:");
2713
2714         /* scan all router-lsa router interfaces */
2715         /* maybe we should put each of the links into its own subtree ??? */
2716         while (ls_length > 0 ) {
2717
2718             /* check the type */
2719             link_type = tvb_get_guint8(tvb, offset);
2720             switch (link_type) {
2721
2722                 case OSPF_V3_LINK_PTP:
2723                     link_type_str="Point-to-point connection to another router";
2724                     break;
2725
2726                 case OSPF_V3_LINK_TRANSIT:
2727                     link_type_str="Connection to a transit network";
2728                     break;
2729
2730                 case OSPF_V3_LINK_RESERVED:
2731                     link_type_str="Connection to a stub network";
2732                     break;
2733
2734                 case OSPF_V3_LINK_VIRTUAL:
2735                     link_type_str="Virtual link";
2736                     break;
2737
2738                 default:
2739                     link_type_str="Unknown link type";
2740                     break;
2741             }
2742
2743             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Type: %u (%s)", link_type,link_type_str);
2744
2745             /* reserved field */
2746             reserved = tvb_get_guint8(tvb, offset+1);
2747             proto_tree_add_text(ospf_lsa_tree, tvb, offset+1, 1,
2748                (reserved == 0 ? "Reserved: %u" : "Reserved: %u [incorrect, should be 0]"),reserved);
2749
2750             /* metric */
2751             metric=tvb_get_ntohs(tvb, offset+2);
2752             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2,"Metric: %u",metric);
2753
2754             /* Interface ID */
2755             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Interface ID: %u",
2756                         tvb_get_ntohl(tvb, offset + 4));
2757
2758             /* Neighbor Interface ID */
2759             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Neighbor Interface ID: %u",
2760                         tvb_get_ntohl(tvb, offset + 8));
2761
2762             /* Neighbor Router ID */
2763             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "Neighbor Router ID: %s",
2764                 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
2765
2766             /* skip to the (possible) next entry */
2767             offset+=16;
2768             ls_length-=16;
2769
2770         }
2771         break;
2772
2773     case OSPF_V3_LSTYPE_NETWORK:
2774
2775         /* reserved field */
2776         reserved = tvb_get_guint8(tvb, offset);
2777         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
2778                (reserved == 0 ? "Reserved: %u" : "Reserved: %u [incorrect, should be 0]"),reserved);
2779
2780         /* options field in an network-lsa */
2781         dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset + 1, &bfinfo_v3_options);
2782
2783         offset += 4;
2784         ls_length-=4;
2785
2786         while (ls_length > 0 ) {
2787             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Attached Router: %s",
2788                                 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
2789             ls_length-=4;
2790             offset += 4;
2791         }
2792         break;
2793
2794
2795     case OSPF_V3_LSTYPE_INTER_AREA_PREFIX:
2796
2797         /* reserved field */
2798         reserved = tvb_get_guint8(tvb, offset);
2799         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
2800                (reserved == 0 ? "Reserved: %u" : "Reserved: %u [incorrect, should be 0]"),reserved);
2801
2802         /* metric */
2803         metric=tvb_get_ntoh24(tvb, offset+1);
2804         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 1, 3,"Metric: %u",metric);
2805
2806         /* prefix length */
2807         prefix_length=tvb_get_guint8(tvb, offset+4);
2808         proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1, "PrefixLength: %u",prefix_length);
2809
2810         /* prefix options */
2811         dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset+5, &bfinfo_v3_prefix_options);
2812
2813         /* 16 bits reserved */
2814         reserved16=tvb_get_ntohs(tvb, offset+6);
2815         proto_tree_add_text(ospf_lsa_tree, tvb, offset+6, 2,
2816                (reserved16 == 0 ? "Reserved: %u" : "Reserved: %u [incorrect, should be 0]"),reserved16);
2817
2818         offset+=8;
2819
2820         /* address_prefix */
2821         dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree, address_family);
2822
2823         offset+=(prefix_length+31)/32*4;
2824
2825         break;
2826
2827
2828     case OSPF_V3_LSTYPE_INTER_AREA_ROUTER:
2829
2830         /* reserved field */
2831         reserved = tvb_get_guint8(tvb, offset);
2832         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
2833                (reserved == 0 ? "Reserved: %u" : "Reserved: %u [incorrect, should be 0]"),reserved);
2834
2835         /* options field in an inter-area-router-lsa */
2836         dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset + 1, &bfinfo_v3_options);
2837
2838         /* reserved field */
2839         reserved = tvb_get_guint8(tvb, offset+4);
2840         proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1,
2841                (reserved == 0 ? "Reserved: %u" : "Reserved: %u [incorrect, should be 0]"),reserved);
2842
2843         /* metric */
2844         metric=tvb_get_ntoh24(tvb, offset+5);
2845         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 5, 3,"Metric: %u",metric);
2846
2847         /* Destination Router ID */
2848         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Destination Router ID: %s",
2849                 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
2850
2851         offset+=12;
2852         break;
2853
2854
2855     case OSPF_V3_LSTYPE_TYPE_7:
2856     case OSPF_V3_LSTYPE_AS_EXTERNAL:
2857
2858         /* flags */
2859         dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset, &bfinfo_v3_as_external_flags);
2860         flags=tvb_get_guint8(tvb, offset);
2861
2862         /* 24 bits metric */
2863         metric=tvb_get_ntoh24(tvb, offset+1);
2864         proto_tree_add_text(ospf_lsa_tree, tvb, offset+1, 3,
2865                                 "Metric: %u", metric);
2866
2867         /* prefix length */
2868         prefix_length=tvb_get_guint8(tvb, offset+4);
2869         proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1, "PrefixLength: %u",prefix_length);
2870
2871         /* prefix options */
2872         dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset+5, &bfinfo_v3_prefix_options);
2873
2874         /* referenced LS type */
2875         referenced_ls_type=tvb_get_ntohs(tvb, offset+6);
2876         proto_tree_add_text(ospf_lsa_tree, tvb, offset+6, 2,"Referenced LS type 0x%04x (%s)",
2877                             referenced_ls_type, val_to_str(referenced_ls_type, v3_ls_type_vals, "Unknown"));
2878
2879         offset+=8;
2880
2881         /* address_prefix */
2882         dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree, address_family);
2883
2884         offset+=(prefix_length+31)/32*4;
2885
2886         /* Forwarding Address (optional - only if F-flag is on) */
2887         if ( (offset < end_offset) && (flags & OSPF_V3_AS_EXTERNAL_FLAG_F) ) {
2888             if (address_family == OSPF_AF_6) {
2889             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 16,"Forwarding Address: %s",
2890               ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset, 16)));
2891             } else {
2892                 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 16,"Forwarding Address: %s",
2893                                     ip_to_str(tvb_get_ptr(tvb, offset, 4)));
2894             }
2895
2896             offset+=16;
2897         }
2898
2899         /* External Route Tag (optional - only if T-flag is on) */
2900         if ( (offset < end_offset) && (flags & OSPF_V3_AS_EXTERNAL_FLAG_T) ) {
2901             external_route_tag=tvb_get_ntohl(tvb, offset);
2902             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4,"External Route Tag: %u",
2903                                 external_route_tag);
2904
2905             offset+=4;
2906         }
2907
2908         /* Referenced Link State ID (optional - only if Referenced LS type is non-zero */
2909         if ( (offset < end_offset) && (referenced_ls_type != 0) ) {
2910             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Referenced Link State ID: %s",
2911                             ip_to_str(tvb_get_ptr(tvb, offset, 4)));
2912             offset+=4;
2913         }
2914
2915         break;
2916
2917     case OSPF_V3_LSTYPE_LINK:
2918
2919         /* router priority */
2920         router_priority=tvb_get_guint8(tvb, offset);
2921         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Router Priority: %u", router_priority);
2922
2923         /* options field in an link-lsa */
2924         dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset + 1, &bfinfo_v3_options);
2925
2926         /* Link-local Interface Address */
2927         if (address_family == OSPF_AF_6) {
2928             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 16, "Link-local Interface Address: %s",
2929                                 ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, 16)));
2930         } else {
2931             proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 16, "Link-local Interface Address: %s",
2932                                 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
2933         }
2934         /* Number prefixes */
2935         number_prefixes=tvb_get_ntohl(tvb, offset + 20);
2936         proto_tree_add_text(ospf_lsa_tree, tvb, offset+20, 4, "# prefixes: %d",number_prefixes);
2937
2938         offset+=24;
2939
2940         while (number_prefixes > 0) {
2941
2942             /* prefix length */
2943             prefix_length=tvb_get_guint8(tvb, offset);
2944             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "PrefixLength: %u",prefix_length);
2945
2946             /* prefix options */
2947             dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset+1, &bfinfo_v3_prefix_options);
2948
2949             /* 16 bits reserved */
2950             reserved16=tvb_get_ntohs(tvb, offset+2);
2951             proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,
2952                (reserved16 == 0 ? "Reserved: %u" : "Reserved: %u [incorrect, should be 0]"),reserved16);
2953
2954             offset+=4;
2955
2956             /* address_prefix */
2957             dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree, address_family);
2958
2959             offset+=(prefix_length+31)/32*4;
2960
2961             number_prefixes--;
2962
2963         }
2964         break;
2965
2966     case OSPF_V3_LSTYPE_INTRA_AREA_PREFIX:
2967
2968         /* # prefixes */
2969         number_prefixes=tvb_get_ntohs(tvb, offset);
2970         proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2,"# prefixes: %u",number_prefixes);
2971
2972         /* referenced LS type */
2973         referenced_ls_type=tvb_get_ntohs(tvb, offset+2);
2974         proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,"Referenced LS type 0x%04x (%s)",
2975                             referenced_ls_type, val_to_str(referenced_ls_type, v3_ls_type_vals, "Unknown"));
2976
2977         /* Referenced Link State ID */
2978         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Referenced Link State ID: %s",
2979                             ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
2980
2981         /* Referenced Advertising Router */
2982         proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Referenced Advertising Router: %s",
2983                             ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
2984
2985         offset+=12;
2986
2987         while (number_prefixes > 0) {
2988
2989             /* prefix length */
2990             prefix_length=tvb_get_guint8(tvb, offset);
2991             proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "PrefixLength: %u",prefix_length);
2992
2993             /* prefix options */
2994             dissect_ospf_bitfield(ospf_lsa_tree, tvb, offset+1, &bfinfo_v3_prefix_options);
2995
2996             /* 16 bits metric */
2997             metric=tvb_get_ntohs(tvb, offset+2);
2998             proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,
2999                                 "Metric: %u", metric);
3000
3001             offset+=4;
3002
3003             /* address_prefix */
3004             dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree, address_family);
3005
3006             offset+=(prefix_length+31)/32*4;
3007
3008             number_prefixes--;
3009         }
3010         break;
3011
3012     default:
3013         /* unknown LSA type */
3014         proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
3015                             "Unknown LSA Type 0x%04x",ls_type);
3016         offset += ls_length;
3017         break;
3018     }
3019     /* return the offset of the next LSA */
3020     return offset;
3021 }
3022
3023 static void dissect_ospf_v3_address_prefix(tvbuff_t *tvb, int offset, int prefix_length, proto_tree *tree,
3024                                            guint8 address_family)
3025 {
3026
3027     int bytes_to_process;
3028     struct e_in6_addr prefix;
3029
3030     bytes_to_process=((prefix_length+31)/32)*4;
3031
3032     if (prefix_length > 128) {
3033         proto_tree_add_text(tree, tvb, offset, bytes_to_process,
3034             "Address Prefix: length is invalid (%d, should be <= 128)",
3035             prefix_length);
3036         return;
3037     }
3038
3039     memset(prefix.bytes, 0, sizeof prefix.bytes);
3040     if (bytes_to_process != 0) {
3041         tvb_memcpy(tvb, prefix.bytes, offset, bytes_to_process);
3042         if (prefix_length % 8) {
3043             prefix.bytes[bytes_to_process - 1] &=
3044                 ((0xff00 >> (prefix_length % 8)) & 0xff);
3045         }
3046     }
3047     if (address_family == OSPF_AF_6) {
3048         proto_tree_add_text(tree, tvb, offset, bytes_to_process,
3049                             "Address Prefix: %s", ip6_to_str(&prefix));
3050     } else {
3051         proto_tree_add_text(tree, tvb, offset, bytes_to_process,
3052                             "Address Prefix: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
3053     }
3054
3055 }
3056
3057
3058 void
3059 proto_register_ospf(void)
3060 {
3061         static hf_register_info ospff_info[] = {
3062
3063                 /* Message type number */
3064                 {&hf_ospf_filter[OSPFF_MSG_TYPE],
3065                  { "Message Type", "ospf.msg", FT_UINT8, BASE_DEC, VALS(pt_vals), 0x0,
3066                         NULL, HFILL }},
3067
3068                 /* Message types */
3069                 {&hf_ospf_filter[OSPFF_MSG_HELLO],
3070                  { "Hello", "ospf.msg.hello", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3071                         NULL, HFILL }},
3072                 {&hf_ospf_filter[OSPFF_MSG_DB_DESC],
3073                  { "Database Description", "ospf.msg.dbdesc", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3074                         NULL, HFILL }},
3075                 {&hf_ospf_filter[OSPFF_MSG_LS_REQ],
3076                  { "Link State Adv Request", "ospf.msg.lsreq", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3077                         NULL, HFILL }},
3078                 {&hf_ospf_filter[OSPFF_MSG_LS_UPD],
3079                  { "Link State Adv Update", "ospf.msg.lsupdate", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3080                         NULL, HFILL }},
3081                 {&hf_ospf_filter[OSPFF_MSG_LS_ACK],
3082                  { "Link State Adv Acknowledgement", "ospf.msg.lsack", FT_BOOLEAN,
3083                    BASE_NONE, NULL, 0x0, NULL, HFILL }},
3084
3085
3086
3087                 /* LS Types */
3088                 {&hf_ospf_filter[OSPFF_LS_TYPE],
3089                  { "Link-State Advertisement Type", "ospf.lsa", FT_UINT8, BASE_DEC,
3090                    VALS(ls_type_vals), 0x0, NULL, HFILL }},
3091                 {&hf_ospf_filter[OSPFF_LS_OPAQUE_TYPE],
3092                  { "Link State ID Opaque Type", "ospf.lsid_opaque_type", FT_UINT8, BASE_DEC,
3093                    VALS(ls_opaque_type_vals), 0x0, NULL, HFILL }},
3094
3095                 {&hf_ospf_filter[OSPFF_LS_MPLS_TE_INSTANCE],
3096                  { "Link State ID TE-LSA Instance", "ospf.lsid_te_lsa.instance", FT_UINT16, BASE_DEC,
3097                    NULL, 0x0, NULL, HFILL }},
3098
3099                 {&hf_ospf_filter[OSPFF_LS_ROUTER],
3100                  { "Router LSA", "ospf.lsa.router", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3101                         NULL, HFILL }},
3102                 {&hf_ospf_filter[OSPFF_LS_NETWORK],
3103                  { "Network LSA", "ospf.lsa.network", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3104                         NULL, HFILL }},
3105                 {&hf_ospf_filter[OSPFF_LS_SUMMARY],
3106                  { "Summary LSA (IP Network)", "ospf.lsa.summary", FT_BOOLEAN, BASE_NONE,
3107                    NULL, 0x0, NULL, HFILL }},
3108                 {&hf_ospf_filter[OSPFF_LS_ASBR],
3109                  { "Summary LSA (ASBR)", "ospf.lsa.asbr", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3110                         NULL, HFILL }},
3111                 {&hf_ospf_filter[OSPFF_LS_ASEXT],
3112                  { "AS-External LSA (ASBR)", "ospf.lsa.asext", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3113                         NULL, HFILL }},
3114                 {&hf_ospf_filter[OSPFF_LS_GRPMEMBER],
3115                  { "Group Membership LSA", "ospf.lsa.member", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3116                         NULL, HFILL }},
3117                 {&hf_ospf_filter[OSPFF_LS_ASEXT7],
3118                  { "NSSA AS-External LSA", "ospf.lsa.nssa", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3119                         NULL, HFILL }},
3120                 {&hf_ospf_filter[OSPFF_LS_EXTATTR],
3121                  { "External Attributes LSA", "ospf.lsa.attr", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3122                         NULL, HFILL }},
3123                 {&hf_ospf_filter[OSPFF_LS_OPAQUE],
3124                  { "Opaque LSA", "ospf.lsa.opaque", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3125                         NULL, HFILL }},
3126
3127                 /* Other interesting OSPF values */
3128
3129                 {&hf_ospf_filter[OSPFF_SRC_ROUTER],
3130                  { "Source OSPF Router", "ospf.srcrouter", FT_IPv4, BASE_NONE, NULL, 0x0,
3131                    NULL, HFILL }},
3132
3133                 {&hf_ospf_filter[OSPFF_ADV_ROUTER],
3134                  { "Advertising Router", "ospf.advrouter", FT_IPv4, BASE_NONE, NULL, 0x0,
3135                    NULL, HFILL }},
3136
3137            {&hf_ospf_filter[OSPFF_LS_MPLS],
3138                  { "MPLS Traffic Engineering LSA", "ospf.lsa.mpls", FT_BOOLEAN,
3139                    BASE_NONE, NULL, 0x0, NULL, HFILL }},
3140
3141                 {&hf_ospf_filter[OSPFF_LS_MPLS_ROUTERID],
3142                  { "MPLS/TE Router ID", "ospf.mpls.routerid", FT_IPv4, BASE_NONE, NULL, 0x0,
3143                    NULL, HFILL }},
3144
3145                 {&hf_ospf_filter[OSPFF_LS_MPLS_LINKTYPE],
3146                  { "MPLS/TE Link Type", "ospf.mpls.linktype", FT_UINT8, BASE_DEC,
3147                    VALS(mpls_link_stlv_ltype_str), 0x0, NULL, HFILL }},
3148                 {&hf_ospf_filter[OSPFF_LS_MPLS_LINKID],
3149                  { "MPLS/TE Link ID", "ospf.mpls.linkid", FT_IPv4, BASE_NONE, NULL, 0x0,
3150                    NULL, HFILL }},
3151                 {&hf_ospf_filter[OSPFF_LS_MPLS_LOCAL_ADDR],
3152                  { "MPLS/TE Local Interface Address", "ospf.mpls.local_addr", FT_IPv4,
3153                    BASE_NONE, NULL, 0x0, NULL, HFILL }},
3154                 {&hf_ospf_filter[OSPFF_LS_MPLS_REMOTE_ADDR],
3155                  { "MPLS/TE Remote Interface Address", "ospf.mpls.remote_addr", FT_IPv4,
3156                    BASE_NONE, NULL, 0x0, NULL, HFILL }},
3157                 {&hf_ospf_filter[OSPFF_LS_MPLS_LOCAL_IFID],
3158                  { "MPLS/TE Local Interface Index", "ospf.mpls.local_id", FT_UINT32,
3159                    BASE_DEC, NULL, 0x0, NULL, HFILL }},
3160                 {&hf_ospf_filter[OSPFF_LS_MPLS_REMOTE_IFID],
3161                  { "MPLS/TE Remote Interface Index", "ospf.mpls.remote_id", FT_UINT32,
3162                    BASE_DEC, NULL, 0x0, NULL, HFILL }},
3163                 {&hf_ospf_filter[OSPFF_LS_MPLS_LINKCOLOR],
3164                  { "MPLS/TE Link Resource Class/Color", "ospf.mpls.linkcolor", FT_UINT32,
3165                    BASE_HEX, NULL, 0x0, NULL, HFILL }},
3166                 {&hf_ospf_filter[OSPFF_LS_MPLS_BC_MODEL_ID],
3167                  { "MPLS/DSTE Bandwidth Constraints Model Id", "ospf.mpls.bc", FT_UINT8,
3168                    BASE_RANGE_STRING | BASE_DEC, RVALS(&mpls_link_stlv_bcmodel_rvals), 0x0,
3169                    NULL, HFILL }},
3170
3171                 {&hf_ospf_filter[OSPFF_LS_OIF_LOCAL_NODE_ID],
3172                  { "Local Node ID", "ospf.oif.local_node_id", FT_IPv4,
3173                    BASE_NONE, NULL, 0x0, NULL, HFILL }},
3174                 {&hf_ospf_filter[OSPFF_LS_OIF_REMOTE_NODE_ID],
3175                  { "Remote Node ID", "ospf.oif.remote_node_id", FT_IPv4,
3176                    BASE_NONE, NULL, 0x0, NULL, HFILL }},
3177
3178                 {&hf_ospf_filter[OSPFF_V2_OPTIONS],
3179                  { "Options", "ospf.v2.options", FT_UINT8, BASE_HEX,
3180                    NULL, 0x0, NULL, HFILL }},
3181                 {&hf_ospf_filter[OSPFF_V2_OPTIONS_MT],
3182                  { "MT", "ospf.v2.options.mt", FT_BOOLEAN, 8,
3183                    TFS(&tfs_v2_options_mt), OSPF_V2_OPTIONS_MT, "", HFILL }},
3184                 {&hf_ospf_filter[OSPFF_V2_OPTIONS_E],
3185                  { "E", "ospf.v2.options.e", FT_BOOLEAN, 8,
3186                    TFS(&tfs_v2_options_e), OSPF_V2_OPTIONS_E, NULL, HFILL }},
3187                 {&hf_ospf_filter[OSPFF_V2_OPTIONS_MC],
3188                  { "MC", "ospf.v2.options.mc", FT_BOOLEAN, 8,
3189                    TFS(&tfs_v2_options_mc), OSPF_V2_OPTIONS_MC, NULL, HFILL }},
3190                 {&hf_ospf_filter[OSPFF_V2_OPTIONS_NP],
3191                  { "NP", "ospf.v2.options.np", FT_BOOLEAN, 8,
3192                    TFS(&tfs_v2_options_np), OSPF_V2_OPTIONS_NP, NULL, HFILL }},
3193                 {&hf_ospf_filter[OSPFF_V2_OPTIONS_L],
3194                  { "L", "ospf.v2.options.l", FT_BOOLEAN, 8,
3195                    TFS(&tfs_v2_options_l), OSPF_V2_OPTIONS_L, NULL, HFILL }},
3196                 {&hf_ospf_filter[OSPFF_V2_OPTIONS_DC],
3197                  { "DC", "ospf.v2.options.dc", FT_BOOLEAN, 8,
3198                    TFS(&tfs_v2_options_dc), OSPF_V2_OPTIONS_DC, NULL, HFILL }},
3199                 {&hf_ospf_filter[OSPFF_V2_OPTIONS_O],
3200                  { "O", "ospf.v2.options.o", FT_BOOLEAN, 8,
3201                    TFS(&tfs_v2_options_o), OSPF_V2_OPTIONS_O, NULL, HFILL }},
3202                 {&hf_ospf_filter[OSPFF_V2_OPTIONS_DN],
3203                  { "DN", "ospf.v2.options.dn", FT_BOOLEAN, 8,
3204                    TFS(&tfs_v2_options_dn), OSPF_V2_OPTIONS_DN, NULL, HFILL }},
3205                 {&hf_ospf_filter[OSPFF_V3_OPTIONS],
3206                  { "Options", "ospf.v3.options", FT_UINT24, BASE_HEX,
3207                    NULL, 0x0, NULL, HFILL }},
3208                 {&hf_ospf_filter[OSPFF_V3_OPTIONS_V6],
3209                  { "V6", "ospf.v3.options.v6", FT_BOOLEAN, 24,
3210                    TFS(&tfs_v3_options_v6), OSPF_V3_OPTIONS_V6, NULL, HFILL }},
3211                 {&hf_ospf_filter[OSPFF_V3_OPTIONS_E],
3212                  { "E", "ospf.v3.options.e", FT_BOOLEAN, 24,
3213                    TFS(&tfs_v3_options_e), OSPF_V3_OPTIONS_E, NULL, HFILL }},
3214                 {&hf_ospf_filter[OSPFF_V3_OPTIONS_MC],
3215                  { "MC", "ospf.v3.options.mc", FT_BOOLEAN, 24,
3216                    TFS(&tfs_v3_options_mc), OSPF_V3_OPTIONS_MC, NULL, HFILL }},
3217                 {&hf_ospf_filter[OSPFF_V3_OPTIONS_N],
3218                  { "N", "ospf.v3.options.n", FT_BOOLEAN, 24,
3219                    TFS(&tfs_v3_options_n), OSPF_V3_OPTIONS_N, NULL, HFILL }},
3220                 {&hf_ospf_filter[OSPFF_V3_OPTIONS_R],
3221                  { "R", "ospf.v3.options.r", FT_BOOLEAN, 24,
3222                    TFS(&tfs_v3_options_r), OSPF_V3_OPTIONS_R, NULL, HFILL }},
3223                 {&hf_ospf_filter[OSPFF_V3_OPTIONS_DC],
3224                  { "DC", "ospf.v3.options.dc", FT_BOOLEAN, 24,
3225                    TFS(&tfs_v3_options_dc), OSPF_V3_OPTIONS_DC, NULL, HFILL }},
3226                 {&hf_ospf_filter[OSPFF_V3_OPTIONS_AF],
3227                  { "AF", "ospf.v3.options.af", FT_BOOLEAN, 24,
3228                    TFS(&tfs_v3_options_af), OSPF_V3_OPTIONS_AF, NULL, HFILL }},
3229                 {&hf_ospf_filter[OSPFF_V3_OPTIONS_L],
3230                  { "L", "ospf.v3.options.l", FT_BOOLEAN, 24,
3231                    TFS(&tfs_v3_options_l), OSPF_V3_OPTIONS_L, NULL, HFILL }},
3232                 {&hf_ospf_filter[OSPFF_V3_OPTIONS_I],
3233                  { "I", "ospf.v3.options.i", FT_BOOLEAN, 24,
3234                    TFS(&tfs_v3_options_i), OSPF_V3_OPTIONS_I, NULL, HFILL }},
3235                 {&hf_ospf_filter[OSPFF_V3_OPTIONS_F],
3236                  { "F", "ospf.v3.options.f", FT_BOOLEAN, 24,
3237                    TFS(&tfs_v3_options_f), OSPF_V3_OPTIONS_F, NULL, HFILL }},
3238                 {&hf_ospf_filter[OSPFF_DBD],
3239                  { "DB Description", "ospf.dbd", FT_UINT8, BASE_HEX,
3240                    NULL, 0x0, NULL, HFILL }},
3241                 {&hf_ospf_filter[OSPFF_DBD_R],
3242                  { "R", "ospf.dbd.r", FT_BOOLEAN, 8,
3243                    TFS(&tfs_dbd_r), OSPF_DBD_FLAG_R, NULL, HFILL }},
3244                 {&hf_ospf_filter[OSPFF_DBD_I],
3245                  { "I", "ospf.dbd.i", FT_BOOLEAN, 8,
3246                    TFS(&tfs_dbd_i), OSPF_DBD_FLAG_I, NULL, HFILL }},
3247                 {&hf_ospf_filter[OSPFF_DBD_M],
3248                  { "M", "ospf.dbd.m", FT_BOOLEAN, 8,
3249                    TFS(&tfs_dbd_m), OSPF_DBD_FLAG_M, NULL, HFILL }},
3250                 {&hf_ospf_filter[OSPFF_DBD_MS],
3251                  { "MS", "ospf.dbd.ms", FT_BOOLEAN, 8,
3252                    TFS(&tfs_dbd_ms), OSPF_DBD_FLAG_MS, NULL, HFILL }},
3253                 {&hf_ospf_filter[OSPFF_LLS_EXT_OPTIONS],
3254                  { "Options", "ospf.lls.ext.options", FT_UINT32, BASE_HEX,
3255                    NULL, 0x0, NULL, HFILL }},
3256                 {&hf_ospf_filter[OSPFF_LLS_EXT_OPTIONS_LR],
3257                  { "LR", "ospf.lls.ext.options.lr", FT_BOOLEAN, 32,
3258                    TFS(&tfs_lls_ext_options_lr), OSPF_LLS_EXT_OPTIONS_LR, NULL, HFILL }},
3259                 {&hf_ospf_filter[OSPFF_LLS_EXT_OPTIONS_RS],
3260                  { "RS", "ospf.lls.ext.options.rs", FT_BOOLEAN, 32,
3261                    TFS(&tfs_lls_ext_options_rs), OSPF_LLS_EXT_OPTIONS_RS, NULL, HFILL }},
3262                 {&hf_ospf_filter[OSPFF_V2_ROUTER_LSA_FLAG],
3263                  { "Flags", "ospf.v2.router.lsa.flags", FT_UINT8, BASE_HEX,
3264                    NULL, 0x0, NULL, HFILL }},
3265                 {&hf_ospf_filter[OSPFF_V2_ROUTER_LSA_FLAG_B],
3266                  { "B", "ospf.v2.router.lsa.flags.b", FT_BOOLEAN, 8,
3267                    TFS(&tfs_v2_router_lsa_flags_b), OSPF_V2_ROUTER_LSA_FLAG_B, NULL, HFILL }},
3268                 {&hf_ospf_filter[OSPFF_V2_ROUTER_LSA_FLAG_E],
3269                  { "E", "ospf.v2.router.lsa.flags.e", FT_BOOLEAN, 8,
3270                    TFS(&tfs_v2_router_lsa_flags_e), OSPF_V2_ROUTER_LSA_FLAG_E, NULL, HFILL }},
3271                 {&hf_ospf_filter[OSPFF_V2_ROUTER_LSA_FLAG_V],
3272                  { "V", "ospf.v2.router.lsa.flags.v", FT_BOOLEAN, 8,
3273                    TFS(&tfs_v2_router_lsa_flags_v), OSPF_V2_ROUTER_LSA_FLAG_V, NULL, HFILL }},
3274                 {&hf_ospf_filter[OSPFF_V2_ROUTER_LSA_FLAG_W],
3275                  { "W", "ospf.v2.router.lsa.flags.w", FT_BOOLEAN, 8,
3276                    TFS(&tfs_v2_router_lsa_flags_w), OSPF_V2_ROUTER_LSA_FLAG_W, "", HFILL }},
3277                 {&hf_ospf_filter[OSPFF_V2_ROUTER_LSA_FLAG_N],
3278                  { "N", "ospf.v2.router.lsa.flags.n", FT_BOOLEAN, 8,
3279                    TFS(&tfs_v2_router_lsa_flags_n), OSPF_V2_ROUTER_LSA_FLAG_N, "", HFILL }},
3280                 {&hf_ospf_filter[OSPFF_V3_ROUTER_LSA_FLAG],
3281                  { "Flags", "ospf.v3.router.lsa.flags", FT_UINT8, BASE_HEX,
3282                    NULL, 0x0, NULL, HFILL }},
3283                 {&hf_ospf_filter[OSPFF_V3_ROUTER_LSA_FLAG_B],
3284                  { "B", "ospf.v3.router.lsa.flags.b", FT_BOOLEAN, 8,
3285                    TFS(&tfs_v3_router_lsa_flags_b), OSPF_V3_ROUTER_LSA_FLAG_B, NULL, HFILL }},
3286                 {&hf_ospf_filter[OSPFF_V3_ROUTER_LSA_FLAG_E],
3287                  { "E", "ospf.v3.router.lsa.flags.e", FT_BOOLEAN, 8,
3288                    TFS(&tfs_v3_router_lsa_flags_e), OSPF_V3_ROUTER_LSA_FLAG_E, NULL, HFILL }},
3289                 {&hf_ospf_filter[OSPFF_V3_ROUTER_LSA_FLAG_V],
3290                  { "V", "ospf.v3.router.lsa.flags.v", FT_BOOLEAN, 8,
3291                    TFS(&tfs_v3_router_lsa_flags_v), OSPF_V3_ROUTER_LSA_FLAG_V, NULL, HFILL }},
3292                 {&hf_ospf_filter[OSPFF_V3_ROUTER_LSA_FLAG_W],
3293                  { "W", "ospf.v3.router.lsa.flags.w", FT_BOOLEAN, 8,
3294                    TFS(&tfs_v3_router_lsa_flags_w), OSPF_V3_ROUTER_LSA_FLAG_W, NULL, HFILL }},
3295                 {&hf_ospf_filter[OSPFF_V3_AS_EXTERNAL_FLAG],
3296                  { "Flags", "ospf.v3.as.external.flags", FT_UINT8, BASE_HEX,
3297                    NULL, 0x0, NULL, HFILL }},
3298                 {&hf_ospf_filter[OSPFF_V3_AS_EXTERNAL_FLAG_T],
3299                  { "T", "ospf.v3.as.external.flags.t", FT_BOOLEAN, 8,
3300                    TFS(&tfs_v3_as_external_flags_t), OSPF_V3_AS_EXTERNAL_FLAG_T, NULL, HFILL }},
3301                 {&hf_ospf_filter[OSPFF_V3_AS_EXTERNAL_FLAG_F],
3302                  { "F", "ospf.v3.as.external.flags.f", FT_BOOLEAN, 8,
3303                    TFS(&tfs_v3_as_external_flags_f), OSPF_V3_AS_EXTERNAL_FLAG_F, NULL, HFILL }},
3304                 {&hf_ospf_filter[OSPFF_V3_AS_EXTERNAL_FLAG_E],
3305                  { "E", "ospf.v3.as.external.flags.e", FT_BOOLEAN, 8,
3306                    TFS(&tfs_v3_as_external_flags_e), OSPF_V3_AS_EXTERNAL_FLAG_E, NULL, HFILL }},
3307                 {&hf_ospf_filter[OSPFF_V3_PREFIX_OPTION],
3308                  { "PrefixOptions", "ospf.v3.prefix.options", FT_UINT8, BASE_HEX,
3309                    NULL, 0x0, NULL, HFILL }},
3310                 {&hf_ospf_filter[OSPFF_V3_PREFIX_OPTION_NU],
3311                  { "NU", "ospf.v3.prefix.options.nu", FT_BOOLEAN, 8,
3312                    TFS(&tfs_v3_prefix_options_nu), OSPF_V3_PREFIX_OPTION_NU, NULL, HFILL }},
3313                 {&hf_ospf_filter[OSPFF_V3_PREFIX_OPTION_LA],
3314                  { "LA", "ospf.v3.prefix.options.la", FT_BOOLEAN, 8,
3315                    TFS(&tfs_v3_prefix_options_la), OSPF_V3_PREFIX_OPTION_LA, NULL, HFILL }},
3316                 {&hf_ospf_filter[OSPFF_V3_PREFIX_OPTION_MC],
3317                  { "MC", "ospf.v3.prefix.options.mc", FT_BOOLEAN, 8,
3318                    TFS(&tfs_v3_prefix_options_mc), OSPF_V3_PREFIX_OPTION_MC, NULL, HFILL }},
3319                 {&hf_ospf_filter[OSPFF_V3_PREFIX_OPTION_P],
3320                  { "P", "ospf.v3.prefix.options.p", FT_BOOLEAN, 8,
3321                    TFS(&tfs_v3_prefix_options_p), OSPF_V3_PREFIX_OPTION_P, NULL, HFILL }},
3322
3323                 /* OSPF Restart TLVs  */
3324                 {&hf_ospf_filter[OSPFF_V2_GRACE_TLV],
3325                  { "Grace TLV", "ospf.v2.grace", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL}},
3326                 {&hf_ospf_filter[OSPFF_V2_GRACE_PERIOD],
3327                  { "Grace Period", "ospf.v2.grace.period", FT_UINT32, BASE_DEC,
3328                    NULL, 0x0,
3329                    "The number of seconds neighbors should advertise the router as fully adjacent",
3330                    HFILL }},
3331                 {&hf_ospf_filter[OSPFF_V2_GRACE_REASON],
3332                  { "Restart Reason", "ospf.v2.grace.reason", FT_UINT8, BASE_DEC,
3333                    VALS(restart_reason_vals), 0x0, "The reason the router is restarting", HFILL }},
3334                 {&hf_ospf_filter[OSPFF_V2_GRACE_IP],
3335                  { "Restart IP", "ospf.v2.grace.ip", FT_IPv4, BASE_NONE,
3336                    NULL, 0x0, "The IP address of the interface originating this LSA", HFILL }},
3337
3338                 /* OSPFv3 LLS TLVs */
3339                 {&hf_ospf_filter[OSPFF_V3_LLS_EXT_OPTIONS_TLV],
3340                  { "Extended Options TLV", "ospf.v3.lls.ext.options.tlv", FT_NONE, BASE_NONE,
3341                    NULL, 0x0, NULL, HFILL }},
3342                 {&hf_ospf_filter[OSPFF_V3_LLS_EXT_OPTIONS],
3343                  { "Options", "ospf.v3.lls.ext.options", FT_UINT32,  BASE_HEX,
3344                    NULL, 0x0, NULL, HFILL }},
3345                 {&hf_ospf_filter[OSPFF_V3_LLS_EXT_OPTIONS_LR],
3346                  { "LR", "ospf.v3.lls.ext.options.lr", FT_BOOLEAN, 32,
3347                    TFS(&tfs_v3_lls_ext_options_lr), OSPF_V3_LLS_EXT_OPTIONS_LR, NULL, HFILL }},
3348                 {&hf_ospf_filter[OSPFF_V3_LLS_EXT_OPTIONS_RS],
3349                  { "RS", "ospf.v3.lls.ext.options.rs", FT_BOOLEAN, 32,
3350                    TFS(&tfs_v3_lls_ext_options_rs), OSPF_V3_LLS_EXT_OPTIONS_RS, NULL, HFILL }},
3351                 {&hf_ospf_filter[OSPFF_V3_LLS_STATE_TLV],
3352                  { "State Check Sequence TLV", "ospf.v3.lls.state.tlv", FT_NONE, BASE_NONE,
3353                    NULL, 0x0, NULL, HFILL }},
3354                 {&hf_ospf_filter[OSPFF_V3_LLS_STATE_SCS],
3355                  { "SCS Number", "ospf.v3.lls.state.scs", FT_UINT16,  BASE_DEC,
3356                    NULL, 0x0, NULL, HFILL }},
3357                 {&hf_ospf_filter[OSPFF_V3_LLS_STATE_OPTIONS],
3358                  { "Options", "ospf.v3.lls.state.options", FT_UINT8,  BASE_HEX,
3359                    NULL, 0x0, NULL, HFILL }},
3360                 {&hf_ospf_filter[OSPFF_V3_LLS_STATE_OPTIONS_R],
3361                  { "R", "ospf.v3.lls.state.options.r", FT_BOOLEAN, 8,
3362                    TFS(&tfs_v3_lls_state_options_r), OSPF_V3_LLS_STATE_OPTIONS_R, NULL, HFILL }},
3363                 {&hf_ospf_filter[OSPFF_V3_LLS_STATE_OPTIONS_A],
3364                  { "A", "ospf.v3.lls.state.options.a", FT_BOOLEAN, 8,
3365                    TFS(&tfs_v3_lls_state_options_a), OSPF_V3_LLS_STATE_OPTIONS_A , NULL, HFILL }},
3366                 {&hf_ospf_filter[OSPFF_V3_LLS_STATE_OPTIONS_N],
3367                  { "N", "ospf.v3.lls.state.options.n", FT_BOOLEAN, 8,
3368                    TFS(&tfs_v3_lls_state_options_n), OSPF_V3_LLS_STATE_OPTIONS_N ,NULL, HFILL }},
3369                 {&hf_ospf_filter[OSPFF_V3_LLS_DROP_TLV],
3370                  { "Neighbor Drop TLV", "ospf.v3.lls.drop.tlv", FT_NONE, BASE_NONE,
3371                    NULL, 0x0, NULL, HFILL }},
3372                  {&hf_ospf_filter[OSPFF_V3_LLS_RELAY_TLV],
3373                  { "Active Overlapping Relays TLV", "ospf.v3.lls.relay.tlv", FT_NONE, BASE_NONE,
3374                    NULL, 0x0, NULL, HFILL }},
3375                 {&hf_ospf_filter[OSPFF_V3_LLS_RELAY_ADDED],
3376                  { "Relays Added", "ospf.v3.lls.relay.added", FT_UINT8,  BASE_DEC,
3377                    NULL, 0x0, NULL, HFILL }},
3378                 {&hf_ospf_filter[OSPFF_V3_LLS_RELAY_OPTIONS],
3379                  { "Options", "ospf.v3.lls.relay.options", FT_UINT8,  BASE_HEX,
3380                    NULL, 0x0, NULL, HFILL }},
3381                 {&hf_ospf_filter[OSPFF_V3_LLS_RELAY_OPTIONS_A],
3382                  { "A", "ospf.v3.lls.relay.options.a", FT_BOOLEAN, 8,
3383                    TFS(&tfs_v3_lls_relay_options_a), OSPF_V3_LLS_RELAY_OPTIONS_A , NULL, HFILL }},
3384                 {&hf_ospf_filter[OSPFF_V3_LLS_RELAY_OPTIONS_N],
3385                  { "N", "ospf.v3.lls.relay.options.n", FT_BOOLEAN, 8,
3386                    TFS(&tfs_v3_lls_relay_options_n), OSPF_V3_LLS_RELAY_OPTIONS_N ,NULL, HFILL }},
3387                 {&hf_ospf_filter[OSPFF_V3_LLS_WILLINGNESS_TLV],
3388                  { "Willingness TLV", "ospf.v3.lls.willingness.tlv", FT_NONE, BASE_NONE,
3389                    NULL, 0x0, NULL, HFILL }},
3390                 {&hf_ospf_filter[OSPFF_V3_LLS_WILLINGNESS],
3391                  { "Willingness", "ospf.v3.lls.willingness", FT_UINT8,  BASE_DEC,
3392                    NULL, 0x0, NULL, HFILL }},
3393                 {&hf_ospf_filter[OSPFF_V3_LLS_RF_TLV],
3394                  { "Request From TLV", "ospf.v3.lls.rf.tlv", FT_NONE, BASE_NONE,
3395                    NULL, 0x0, NULL, HFILL }},
3396                 {&hf_ospf_filter[OSPFF_V3_LLS_FSF_TLV],
3397                  { "Full State For TLV", "ospf.v3.lls.fsf.tlv", FT_NONE, BASE_NONE,
3398                    NULL, 0x0, NULL, HFILL }}
3399         };
3400
3401     static gint *ett[] = {
3402         &ett_ospf,
3403         &ett_ospf_hdr,
3404         &ett_ospf_hello,
3405         &ett_ospf_desc,
3406         &ett_ospf_lsr,
3407         &ett_ospf_lsa,
3408         &ett_ospf_lsa_router_link,
3409         &ett_ospf_lsa_upd,
3410         &ett_ospf_lsa_mpls,
3411         &ett_ospf_lsa_mpls_router,
3412         &ett_ospf_lsa_mpls_link,
3413         &ett_ospf_lsa_mpls_link_stlv,
3414         &ett_ospf_lsa_mpls_link_stlv_admingrp,
3415         &ett_ospf_lsa_oif_tna,
3416         &ett_ospf_lsa_oif_tna_stlv,
3417         &ett_ospf_lsa_grace_tlv,
3418         &ett_ospf_v2_options,
3419         &ett_ospf_v3_options,
3420         &ett_ospf_dbd,
3421         &ett_ospf_lls_data_block,
3422         &ett_ospf_lls_tlv,
3423         &ett_ospf_lls_ext_options,
3424         &ett_ospf_v3_lls_ext_options_tlv,
3425         &ett_ospf_v3_lls_ext_options,
3426         &ett_ospf_v3_lls_state_tlv,
3427         &ett_ospf_v3_lls_state_scs,
3428         &ett_ospf_v3_lls_state_options,
3429         &ett_ospf_v3_lls_drop_tlv,
3430         &ett_ospf_v3_lls_relay_tlv,
3431         &ett_ospf_v3_lls_relay_added,
3432         &ett_ospf_v3_lls_relay_options,
3433         &ett_ospf_v3_lls_willingness_tlv,
3434         &ett_ospf_v3_lls_willingness,
3435         &ett_ospf_v3_lls_rf_tlv,
3436         &ett_ospf_v3_lls_fsf_tlv,
3437         &ett_ospf_v2_router_lsa_flags,
3438         &ett_ospf_v3_router_lsa_flags,
3439         &ett_ospf_v3_as_external_flags,
3440         &ett_ospf_v3_prefix_options
3441     };
3442
3443     proto_ospf = proto_register_protocol("Open Shortest Path First",
3444                                          "OSPF", "ospf");
3445     proto_register_field_array(proto_ospf, ospff_info, array_length(ospff_info));
3446     proto_register_subtree_array(ett, array_length(ett));
3447 }
3448
3449 void
3450 proto_reg_handoff_ospf(void)
3451 {
3452     dissector_handle_t ospf_handle;
3453
3454     ospf_handle = create_dissector_handle(dissect_ospf, proto_ospf);
3455     dissector_add("ip.proto", IP_PROTO_OSPF, ospf_handle);
3456     data_handle = find_dissector("data");
3457 }