2 * Routines for OSPF packet disassembly
3 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
5 * $Id: packet-ospf.c,v 1.74 2003/01/21 20:29:42 jmayer Exp $
7 * At this time, this module is able to analyze OSPF
8 * packets as specified in RFC2328. MOSPF (RFC1584) and other
9 * OSPF Extensions which introduce new Packet types
10 * (e.g the External Atributes LSA) are not supported.
11 * Furthermore RFC2740 (OSPFv3 - OSPF for IPv6) is now supported
12 * - (c) 2001 Palle Lyckegaard <palle[AT]lyckegaard.dk>
14 * TOS - support is not fully implemented
16 * Ethereal - Network traffic analyzer
17 * By Gerald Combs <gerald@ethereal.com>
18 * Copyright 1998 Gerald Combs
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License
22 * as published by the Free Software Foundation; either version 2
23 * of the License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
43 #include <epan/packet.h>
46 #include "packet-rsvp.h"
48 #define OSPF_VERSION_2 2
49 #define OSPF_VERSION_3 3
50 #define OSPF_VERSION_2_HEADER_LENGTH 24
51 #define OSPF_VERSION_3_HEADER_LENGTH 16
55 #define OSPF_DB_DESC 2
60 static const value_string pt_vals[] = {
61 {OSPF_HELLO, "Hello Packet" },
62 {OSPF_DB_DESC, "DB Descr." },
63 {OSPF_LS_REQ, "LS Request" },
64 {OSPF_LS_UPD, "LS Update" },
65 {OSPF_LS_ACK, "LS Acknowledge" },
69 #define OSPF_AUTH_NONE 0
70 #define OSPF_AUTH_SIMPLE 1
71 #define OSPF_AUTH_CRYPT 2
73 static const value_string auth_vals[] = {
74 {OSPF_AUTH_NONE, "Null" },
75 {OSPF_AUTH_SIMPLE, "Simple password" },
76 {OSPF_AUTH_CRYPT, "Cryptographic" },
80 #define OSPF_V2_OPTIONS_DN 0x01
81 #define OSPF_V2_OPTIONS_E 0x02
82 #define OSPF_V2_OPTIONS_MC 0x04
83 #define OSPF_V2_OPTIONS_NP 0x08
84 #define OSPF_V2_OPTIONS_EA 0x10
85 #define OSPF_V2_OPTIONS_DC 0x20
86 #define OSPF_V2_OPTIONS_O 0x40
87 #define OSPF_V3_OPTIONS_V6 0x01
88 #define OSPF_V3_OPTIONS_E 0x02
89 #define OSPF_V3_OPTIONS_MC 0x04
90 #define OSPF_V3_OPTIONS_N 0x08
91 #define OSPF_V3_OPTIONS_R 0x10
92 #define OSPF_V3_OPTIONS_DC 0x20
95 #define OSPF_DBD_FLAG_MS 1
96 #define OSPF_DBD_FLAG_M 2
97 #define OSPF_DBD_FLAG_I 4
99 #define OSPF_LS_REQ_LENGTH 12
101 #define OSPF_LSTYPE_ROUTER 1
102 #define OSPF_LSTYPE_NETWORK 2
103 #define OSPF_LSTYPE_SUMMERY 3
104 #define OSPF_LSTYPE_ASBR 4
105 #define OSPF_LSTYPE_ASEXT 5
106 #define OSPF_LSTYPE_GRPMEMBER 6
107 #define OSPF_LSTYPE_ASEXT7 7
108 #define OSPF_LSTYPE_EXTATTR 8
109 #define OSPF_V3_LSTYPE_ROUTER 0x2001
110 #define OSPF_V3_LSTYPE_NETWORK 0x2002
111 #define OSPF_V3_LSTYPE_INTER_AREA_PREFIX 0x2003
112 #define OSPF_V3_LSTYPE_INTER_AREA_ROUTER 0x2004
113 #define OSPF_V3_LSTYPE_AS_EXTERNAL 0x4005
114 #define OSPF_V3_LSTYPE_GROUP_MEMBERSHIP 0x2006
115 #define OSPF_V3_LSTYPE_TYPE_7 0x2007
116 #define OSPF_V3_LSTYPE_LINK 0x0008
117 #define OSPF_V3_LSTYPE_INTRA_AREA_PREFIX 0x2009
119 /* Opaque LSA types */
120 #define OSPF_LSTYPE_OP_LINKLOCAL 9
121 #define OSPF_LSTYPE_OP_AREALOCAL 10
122 #define OSPF_LSTYPE_OP_ASWIDE 11
124 #define OSPF_LINK_PTP 1
125 #define OSPF_LINK_TRANSIT 2
126 #define OSPF_LINK_STUB 3
127 #define OSPF_LINK_VIRTUAL 4
129 #define OSPF_V3_LINK_PTP 1
130 #define OSPF_V3_LINK_TRANSIT 2
131 #define OSPF_V3_LINK_RESERVED 3
132 #define OSPF_V3_LINK_VIRTUAL 4
134 #define OSPF_LSA_HEADER_LENGTH 20
136 /* Known opaque LSAs */
137 #define OSPF_LSA_MPLS_TE 1
140 static const value_string ls_type_vals[] = {
141 {OSPF_LSTYPE_ROUTER, "Router-LSA" },
142 {OSPF_LSTYPE_NETWORK, "Network-LSA" },
143 {OSPF_LSTYPE_SUMMERY, "Summary-LSA (IP network)" },
144 {OSPF_LSTYPE_ASBR, "Summary-LSA (ASBR)" },
145 {OSPF_LSTYPE_ASEXT, "AS-External-LSA (ASBR)" },
146 {OSPF_LSTYPE_GRPMEMBER, "Group Membership LSA" },
147 {OSPF_LSTYPE_ASEXT7, "NSSA AS-External-LSA" },
148 {OSPF_LSTYPE_EXTATTR, "External Attributes LSA" },
149 {OSPF_LSTYPE_OP_LINKLOCAL, "Opaque LSA, Link-local scope" },
150 {OSPF_LSTYPE_OP_AREALOCAL, "Opaque LSA, Area-local scope" },
155 static const value_string ls_opaque_type_vals[] = {
156 {OSPF_LSA_MPLS_TE, "Traffic Engineering LSA" },
157 {2, "Sycamore Optical Topology Descriptions" },
162 static const value_string v3_ls_type_vals[] = {
163 {OSPF_V3_LSTYPE_ROUTER, "Router-LSA" },
164 {OSPF_V3_LSTYPE_NETWORK, "Network-LSA" },
165 {OSPF_V3_LSTYPE_INTER_AREA_PREFIX, "Inter-Area-Prefix-LSA" },
166 {OSPF_V3_LSTYPE_INTER_AREA_ROUTER, "Inter-Area-Router-LSA" },
167 {OSPF_V3_LSTYPE_AS_EXTERNAL, "AS-External-LSA" },
168 {OSPF_V3_LSTYPE_GROUP_MEMBERSHIP, "Group-Membership-LSA" },
169 {OSPF_V3_LSTYPE_TYPE_7, "Type-LSA" },
170 {OSPF_V3_LSTYPE_LINK, "Link-LSA" },
171 {OSPF_V3_LSTYPE_INTRA_AREA_PREFIX, "Intra-Area-Prefix-LSA" },
177 #define OSPF_V3_ROUTER_LSA_FLAG_B 0x01
178 #define OSPF_V3_ROUTER_LSA_FLAG_E 0x02
179 #define OSPF_V3_ROUTER_LSA_FLAG_V 0x04
180 #define OSPF_V3_ROUTER_LSA_FLAG_W 0x08
182 #define OSPF_V3_PREFIX_OPTION_NU 0x01
183 #define OSPF_V3_PREFIX_OPTION_LA 0x02
184 #define OSPF_V3_PREFIX_OPTION_MC 0x04
185 #define OSPF_V3_PREFIX_OPTION_P 0x08
187 #define OSPF_V3_AS_EXTERNAL_FLAG_T 0x01
188 #define OSPF_V3_AS_EXTERNAL_FLAG_F 0x02
189 #define OSPF_V3_AS_EXTERNAL_FLAG_E 0x04
192 static int proto_ospf = -1;
194 static gint ett_ospf = -1;
195 static gint ett_ospf_hdr = -1;
196 static gint ett_ospf_hello = -1;
197 static gint ett_ospf_desc = -1;
198 static gint ett_ospf_lsr = -1;
199 static gint ett_ospf_lsa = -1;
200 static gint ett_ospf_lsa_router_link = -1;
201 static gint ett_ospf_lsa_upd = -1;
203 /* Trees for opaque LSAs */
204 static gint ett_ospf_lsa_mpls = -1;
205 static gint ett_ospf_lsa_mpls_router = -1;
206 static gint ett_ospf_lsa_mpls_link = -1;
207 static gint ett_ospf_lsa_mpls_link_stlv = -1;
209 /*-----------------------------------------------------------------------
211 *-----------------------------------------------------------------------*/
213 /* The OSPF filtering keys */
226 OSPFF_LS_OPAQUE_TYPE,
228 OSPFF_LS_MPLS_TE_INSTANCE,
244 OSPFF_LS_MPLS_ROUTERID,
246 OSPFF_LS_MPLS_LINKID,
247 OSPFF_LS_MPLS_LOCAL_ADDR,
248 OSPFF_LS_MPLS_REMOTE_ADDR,
249 OSPFF_LS_MPLS_LOCAL_IFID,
250 OSPFF_LS_MPLS_REMOTE_IFID,
255 static int ospf_filter[OSPFF_MAX];
257 static hf_register_info ospff_info[] = {
259 /* Message type number */
260 {&ospf_filter[OSPFF_MSG_TYPE],
261 { "Message Type", "ospf.msg", FT_UINT8, BASE_DEC, VALS(pt_vals), 0x0,
265 {&ospf_filter[OSPFF_MSG_HELLO],
266 { "Hello", "ospf.msg.hello", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
268 {&ospf_filter[OSPFF_MSG_DB_DESC],
269 { "Database Description", "ospf.msg.dbdesc", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
271 {&ospf_filter[OSPFF_MSG_LS_REQ],
272 { "Link State Adv Request", "ospf.msg.lsreq", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
274 {&ospf_filter[OSPFF_MSG_LS_UPD],
275 { "Link State Adv Update", "ospf.msg.lsupdate", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
277 {&ospf_filter[OSPFF_MSG_LS_ACK],
278 { "Link State Adv Acknowledgement", "ospf.msg.lsack", FT_BOOLEAN,
279 BASE_NONE, NULL, 0x0, "", HFILL }},
284 {&ospf_filter[OSPFF_LS_TYPE],
285 { "Link-State Advertisement Type", "ospf.lsa", FT_UINT8, BASE_DEC,
286 VALS(ls_type_vals), 0x0, "", HFILL }},
287 {&ospf_filter[OSPFF_LS_OPAQUE_TYPE],
288 { "Link State ID Opaque Type", "ospf.lsid_opaque_type", FT_UINT8, BASE_DEC,
289 VALS(ls_opaque_type_vals), 0x0, "", HFILL }},
291 {&ospf_filter[OSPFF_LS_MPLS_TE_INSTANCE],
292 { "Link State ID TE-LSA Instance", "ospf.lsid_te_lsa.instance", FT_UINT16, BASE_DEC,
293 NULL, 0x0, "", HFILL }},
295 {&ospf_filter[OSPFF_LS_ROUTER],
296 { "Router LSA", "ospf.lsa.router", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
298 {&ospf_filter[OSPFF_LS_NETWORK],
299 { "Network LSA", "ospf.lsa.network", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
301 {&ospf_filter[OSPFF_LS_SUMMARY],
302 { "Summary LSA (IP Network)", "ospf.lsa.summary", FT_BOOLEAN, BASE_NONE,
303 NULL, 0x0, "", HFILL }},
304 {&ospf_filter[OSPFF_LS_ASBR],
305 { "Summary LSA (ASBR)", "ospf.lsa.asbr", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
307 {&ospf_filter[OSPFF_LS_ASEXT],
308 { "AS-External LSA (ASBR)", "ospf.lsa.asext", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
310 {&ospf_filter[OSPFF_LS_GRPMEMBER],
311 { "Group Membership LSA", "ospf.lsa.member", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
313 {&ospf_filter[OSPFF_LS_ASEXT7],
314 { "NSSA AS-External LSA", "ospf.lsa.nssa", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
316 {&ospf_filter[OSPFF_LS_EXTATTR],
317 { "External Attributes LSA", "ospf.lsa.attr", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
319 {&ospf_filter[OSPFF_LS_OPAQUE],
320 { "Opaque LSA", "ospf.lsa.opaque", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
323 /* Other interesting OSPF values */
325 {&ospf_filter[OSPFF_SRC_ROUTER],
326 { "Source OSPF Router", "ospf.srcrouter", FT_IPv4, BASE_NONE, NULL, 0x0,
329 {&ospf_filter[OSPFF_ADV_ROUTER],
330 { "Advertising Router", "ospf.advrouter", FT_IPv4, BASE_NONE, NULL, 0x0,
333 {&ospf_filter[OSPFF_LS_MPLS],
334 { "MPLS Traffic Engineering LSA", "ospf.lsa.mpls", FT_BOOLEAN,
335 BASE_NONE, NULL, 0x0, "", HFILL }},
337 {&ospf_filter[OSPFF_LS_MPLS_ROUTERID],
338 { "MPLS/TE Router ID", "ospf.mpls.routerid", FT_IPv4, BASE_NONE, NULL, 0x0,
341 {&ospf_filter[OSPFF_LS_MPLS_LINKID],
342 { "MPLS/TE Link ID", "ospf.mpls.linkid", FT_IPv4, BASE_NONE, NULL, 0x0,
344 {&ospf_filter[OSPFF_LS_MPLS_LOCAL_ADDR],
345 { "MPLS/TE Local Interface Address", "ospf.mpls.local_addr", FT_IPv4,
346 BASE_NONE, NULL, 0x0, "", HFILL }},
347 {&ospf_filter[OSPFF_LS_MPLS_REMOTE_ADDR],
348 { "MPLS/TE Remote Interface Address", "ospf.mpls.remote_addr", FT_IPv4,
349 BASE_NONE, NULL, 0x0, "", HFILL }},
350 {&ospf_filter[OSPFF_LS_MPLS_LOCAL_IFID],
351 { "MPLS/TE Local Interface Index", "ospf.mpls.local_id", FT_UINT32,
352 BASE_DEC, NULL, 0x0, "", HFILL }},
353 {&ospf_filter[OSPFF_LS_MPLS_REMOTE_IFID],
354 { "MPLS/TE Remote Interface Index", "ospf.mpls.remote_id", FT_UINT32,
355 BASE_DEC, NULL, 0x0, "", HFILL }},
361 static guint8 ospf_msg_type_to_filter (guint8 msg_type)
363 if (msg_type >= OSPF_HELLO &&
364 msg_type <= OSPF_LS_ACK)
365 return msg_type + OSPFF_MSG_MIN;
369 static guint8 ospf_ls_type_to_filter (guint8 ls_type)
371 if (ls_type >= OSPF_LSTYPE_ROUTER &&
372 ls_type <= OSPF_LSTYPE_EXTATTR)
373 return OSPFF_LS_MIN + ls_type;
374 else if (ls_type >= OSPF_LSTYPE_OP_LINKLOCAL &&
375 ls_type <= OSPF_LSTYPE_OP_ASWIDE)
376 return OSPFF_LS_OPAQUE;
381 static dissector_handle_t data_handle;
383 static void dissect_ospf_hello(tvbuff_t*, int, proto_tree*, guint8);
384 static void dissect_ospf_db_desc(tvbuff_t*, int, proto_tree*, guint8);
385 static void dissect_ospf_ls_req(tvbuff_t*, int, proto_tree*, guint8);
386 static void dissect_ospf_ls_upd(tvbuff_t*, int, proto_tree*, guint8);
387 static void dissect_ospf_ls_ack(tvbuff_t*, int, proto_tree*, guint8);
389 /* dissect_ospf_v[23]lsa returns the offset of the next LSA
390 * if disassemble_body is set to FALSE (e.g. in LSA ACK
391 * packets), the offset is set to the offset of the next
394 static int dissect_ospf_v2_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body);
395 static int dissect_ospf_v3_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body);
397 static void dissect_ospf_options(tvbuff_t *, int, proto_tree *, guint8);
399 static void dissect_ospf_v3_prefix_options(tvbuff_t *, int, proto_tree *);
401 static void dissect_ospf_v3_address_prefix(tvbuff_t *, int, int, proto_tree *);
404 dissect_ospf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
406 proto_tree *ospf_tree = NULL;
408 proto_tree *ospf_header_tree;
415 guint16 cksum, computed_cksum;
416 guint length, reported_length;
420 unsigned int ospf_header_length;
426 if (check_col(pinfo->cinfo, COL_PROTOCOL))
427 col_set_str(pinfo->cinfo, COL_PROTOCOL, "OSPF");
428 if (check_col(pinfo->cinfo, COL_INFO))
429 col_clear(pinfo->cinfo, COL_INFO);
431 version = tvb_get_guint8(tvb, 0);
434 ospf_header_length = OSPF_VERSION_2_HEADER_LENGTH;
437 ospf_header_length = OSPF_VERSION_3_HEADER_LENGTH;
440 ospf_header_length = 0;
444 packet_type = tvb_get_guint8(tvb, 1);
445 if (check_col(pinfo->cinfo, COL_INFO)) {
446 col_add_str(pinfo->cinfo, COL_INFO,
447 val_to_str(packet_type, pt_vals, "Unknown (%u)"));
451 ospflen = tvb_get_ntohs(tvb, 2);
453 ti = proto_tree_add_item(tree, proto_ospf, tvb, 0, ospflen, FALSE);
454 ospf_tree = proto_item_add_subtree(ti, ett_ospf);
456 ti = proto_tree_add_text(ospf_tree, tvb, 0, ospf_header_length,
458 ospf_header_tree = proto_item_add_subtree(ti, ett_ospf_hdr);
460 proto_tree_add_text(ospf_header_tree, tvb, 0, 1, "OSPF Version: %u",
462 proto_tree_add_item(ospf_header_tree, ospf_filter[OSPFF_MSG_TYPE],
464 proto_tree_add_item_hidden(ospf_header_tree,
465 ospf_filter[ospf_msg_type_to_filter(packet_type)],
467 proto_tree_add_text(ospf_header_tree, tvb, 2, 2, "Packet Length: %u",
469 proto_tree_add_item(ospf_header_tree, ospf_filter[OSPFF_SRC_ROUTER],
471 areaid=tvb_get_ntohl(tvb,8);
472 proto_tree_add_text(ospf_header_tree, tvb, 8, 4, "Area ID: %s%s",
473 ip_to_str(tvb_get_ptr(tvb, 8, 4)), areaid == 0 ? " (Backbone)" : "");
474 cksum = tvb_get_ntohs(tvb, 12);
475 length = tvb_length(tvb);
476 /* XXX - include only the length from the OSPF header? */
477 reported_length = tvb_reported_length(tvb);
479 /* No checksum supplied in the packet. */
480 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
481 "Packet Checksum: 0x%04x (none)", cksum);
482 } else if (!pinfo->fragmented && length >= reported_length
483 && length >= ospf_header_length
484 && (version == OSPF_VERSION_2 || version == OSPF_VERSION_3)) {
485 /* The packet isn't part of a fragmented datagram and isn't
486 truncated, and we know how to checksum this version of
487 OSPF, so we can checksum it. */
492 /* Header, not including the authentication data (the OSPFv2
493 checksum excludes the 64-bit authentication field). */
494 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, 16);
495 cksum_vec[0].len = 16;
496 if (length > ospf_header_length) {
497 /* Rest of the packet, again not including the
498 authentication data. */
499 reported_length -= ospf_header_length;
500 cksum_vec[1].ptr = tvb_get_ptr(tvb, ospf_header_length, reported_length);
501 cksum_vec[1].len = reported_length;
504 /* There's nothing but a header. */
510 /* IPv6-style checksum, covering the entire OSPF packet
511 and a prepended IPv6 pseudo-header. */
513 /* Set up the fields of the pseudo-header. */
514 cksum_vec[0].ptr = pinfo->src.data;
515 cksum_vec[0].len = pinfo->src.len;
516 cksum_vec[1].ptr = pinfo->dst.data;
517 cksum_vec[1].len = pinfo->dst.len;
518 cksum_vec[2].ptr = (const guint8 *)&phdr;
519 phdr[0] = g_htonl(ospflen);
520 phdr[1] = g_htonl(IP_PROTO_OSPF);
521 cksum_vec[2].len = 8;
523 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, reported_length);
524 cksum_vec[3].len = reported_length;
529 g_assert_not_reached();
532 computed_cksum = in_cksum(cksum_vec, cksum_vec_len);
533 if (computed_cksum == 0) {
534 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
535 "Packet Checksum: 0x%04x (correct)", cksum);
537 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
538 "Packet Checksum: 0x%04x (incorrect, should be 0x%04x)",
539 cksum, in_cksum_shouldbe(cksum, computed_cksum));
542 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
543 "Packet Checksum: 0x%04x", cksum);
547 /* Authentication is only valid for OSPFv2 */
548 if ( version == OSPF_VERSION_2 ) {
549 auth_type = tvb_get_ntohs(tvb, 14);
550 proto_tree_add_text(ospf_header_tree, tvb, 14, 2, "Auth Type: %s",
551 val_to_str(auth_type, auth_vals, "Unknown (%u)"));
555 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data (none)");
558 case OSPF_AUTH_SIMPLE:
559 tvb_get_nstringz0(tvb, 16, 8, auth_data);
560 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data: %s", auth_data);
563 case OSPF_AUTH_CRYPT:
564 proto_tree_add_text(ospf_header_tree, tvb, 18, 1, "Auth Key ID: %u",
565 tvb_get_guint8(tvb, 18));
566 crypto_len = tvb_get_guint8(tvb, 19);
567 proto_tree_add_text(ospf_header_tree, tvb, 19, 1, "Auth Data Length: %u",
569 proto_tree_add_text(ospf_header_tree, tvb, 20, 4, "Auth Crypto Sequence Number: 0x%x",
570 tvb_get_ntohl(tvb, 20));
572 /* Show the message digest that was appended to the end of the
573 OSPF message - but only if it's present (we don't want
574 to get an exception before we've tried dissecting OSPF
576 if (tvb_bytes_exist(tvb, ospflen, crypto_len)) {
577 proto_tree_add_text(ospf_header_tree, tvb, ospflen, crypto_len,
579 tvb_bytes_to_str(tvb, ospflen, crypto_len));
584 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data (unknown)");
590 /* Instance ID and "reserved" is OSPFv3-only */
591 if ( version == OSPF_VERSION_3 ) {
592 instance_ID = tvb_get_guint8(tvb, 14);
593 proto_tree_add_text(ospf_header_tree, tvb, 14, 1, "Instance ID: %u",
595 reserved = tvb_get_guint8(tvb, 15);
596 proto_tree_add_text(ospf_header_tree, tvb, 15, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
601 /* Adjust the length of the tvbuff to match the size of the OSPF
602 * packet (since the dissect routines use it to work out where the
603 * end of the OSPF packet is).
605 tvb_set_reported_length(tvb, ospflen);
607 switch (packet_type){
610 dissect_ospf_hello(tvb, ospf_header_length, ospf_tree, version);
614 dissect_ospf_db_desc(tvb, ospf_header_length, ospf_tree, version);
618 dissect_ospf_ls_req(tvb, ospf_header_length, ospf_tree, version);
622 dissect_ospf_ls_upd(tvb, ospf_header_length, ospf_tree, version);
626 dissect_ospf_ls_ack(tvb, ospf_header_length, ospf_tree, version);
630 call_dissector(data_handle,
631 tvb_new_subset(tvb, ospf_header_length, -1, -1), pinfo, tree);
638 dissect_ospf_hello(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
640 proto_tree *ospf_hello_tree;
643 ti = proto_tree_add_text(tree, tvb, offset, -1, "OSPF Hello Packet");
644 ospf_hello_tree = proto_item_add_subtree(ti, ett_ospf_hello);
648 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4, "Network Mask: %s",
649 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
650 proto_tree_add_text(ospf_hello_tree, tvb, offset + 4, 2,
651 "Hello Interval: %u seconds",
652 tvb_get_ntohs(tvb, offset + 4));
654 dissect_ospf_options(tvb, offset + 6, ospf_hello_tree, version);
655 proto_tree_add_text(ospf_hello_tree, tvb, offset + 7, 1, "Router Priority: %u",
656 tvb_get_guint8(tvb, offset + 7));
657 proto_tree_add_text(ospf_hello_tree, tvb, offset + 8, 4, "Router Dead Interval: %u seconds",
658 tvb_get_ntohl(tvb, offset + 8));
659 proto_tree_add_text(ospf_hello_tree, tvb, offset + 12, 4, "Designated Router: %s",
660 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
661 proto_tree_add_text(ospf_hello_tree, tvb, offset + 16, 4, "Backup Designated Router: %s",
662 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
665 while (tvb_reported_length_remaining(tvb, offset) != 0) {
666 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4,
667 "Active Neighbor: %s",
668 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
673 proto_tree_add_text(ospf_hello_tree, tvb, offset + 0, 4, "Interface ID: %u",
674 tvb_get_ntohl(tvb, offset + 0));
675 proto_tree_add_text(ospf_hello_tree, tvb, offset + 4, 1, "Router Priority: %u",
676 tvb_get_guint8(tvb, offset + 4));
677 dissect_ospf_options(tvb, offset + 5, ospf_hello_tree, version);
678 proto_tree_add_text(ospf_hello_tree, tvb, offset + 8, 2,
679 "Hello Interval: %u seconds",
680 tvb_get_ntohs(tvb, offset + 8));
681 proto_tree_add_text(ospf_hello_tree, tvb, offset + 10, 2, "Router Dead Interval: %u seconds",
682 tvb_get_ntohs(tvb, offset + 10));
683 proto_tree_add_text(ospf_hello_tree, tvb, offset + 12, 4, "Designated Router: %s",
684 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
685 proto_tree_add_text(ospf_hello_tree, tvb, offset + 16, 4, "Backup Designated Router: %s",
686 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
688 while (tvb_reported_length_remaining(tvb, offset) != 0) {
689 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4,
690 "Active Neighbor: %s",
691 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
703 dissect_ospf_db_desc(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
705 proto_tree *ospf_db_desc_tree=NULL;
709 char flags_string[20] = "";
712 ti = proto_tree_add_text(tree, tvb, offset, -1, "OSPF DB Description");
713 ospf_db_desc_tree = proto_item_add_subtree(ti, ett_ospf_desc);
719 proto_tree_add_text(ospf_db_desc_tree, tvb, offset, 2, "Interface MTU: %u",
720 tvb_get_ntohs(tvb, offset));
722 dissect_ospf_options(tvb, offset + 2, ospf_db_desc_tree, version);
724 flags = tvb_get_guint8(tvb, offset + 3);
725 if (flags & OSPF_DBD_FLAG_MS)
726 strcat(flags_string, "MS");
727 if (flags & OSPF_DBD_FLAG_M) {
728 if (flags_string[0] != '\0')
729 strcat(flags_string, "/");
730 strcat(flags_string, "M");
732 if (flags & OSPF_DBD_FLAG_I) {
733 if (flags_string[0] != '\0')
734 strcat(flags_string, "/");
735 strcat(flags_string, "I");
737 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 3, 1, "Flags: 0x%x (%s)",
738 flags, flags_string);
739 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 4, 4, "DD Sequence: %u",
740 tvb_get_ntohl(tvb, offset + 4));
747 reserved = tvb_get_guint8(tvb, offset);
748 proto_tree_add_text(ospf_db_desc_tree, tvb, offset, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
751 dissect_ospf_options(tvb, offset + 1, ospf_db_desc_tree, version);
753 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 4, 2, "Interface MTU: %u",
754 tvb_get_ntohs(tvb, offset+4));
756 reserved = tvb_get_guint8(tvb, offset + 6);
757 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 6, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
760 flags = tvb_get_guint8(tvb, offset + 7);
761 if (flags & OSPF_DBD_FLAG_MS)
762 strcat(flags_string, "MS");
763 if (flags & OSPF_DBD_FLAG_M) {
764 if (flags_string[0] != '\0')
765 strcat(flags_string, "/");
766 strcat(flags_string, "M");
768 if (flags & OSPF_DBD_FLAG_I) {
769 if (flags_string[0] != '\0')
770 strcat(flags_string, "/");
771 strcat(flags_string, "I");
773 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 7, 1, "Flags: 0x%x (%s)",
774 flags, flags_string);
776 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 8, 4, "DD Sequence: %u",
777 tvb_get_ntohl(tvb, offset + 8));
787 /* LS Headers will be processed here */
788 /* skip to the end of DB-Desc header */
789 while (tvb_reported_length_remaining(tvb, offset) != 0) {
790 if ( version == OSPF_VERSION_2)
791 offset = dissect_ospf_v2_lsa(tvb, offset, tree, FALSE);
793 if ( version == OSPF_VERSION_3)
794 offset = dissect_ospf_v3_lsa(tvb, offset, tree, FALSE);
800 dissect_ospf_ls_req(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
802 proto_tree *ospf_lsr_tree;
807 /* zero or more LS requests may be within a LS Request */
808 /* we place every request for a LSA in a single subtree */
809 while (tvb_reported_length_remaining(tvb, offset) != 0) {
810 ti = proto_tree_add_text(tree, tvb, offset, OSPF_LS_REQ_LENGTH,
811 "Link State Request");
812 ospf_lsr_tree = proto_item_add_subtree(ti, ett_ospf_lsr);
817 ls_type = tvb_get_ntohl(tvb, offset);
818 proto_tree_add_item(ospf_lsr_tree, ospf_filter[OSPFF_LS_TYPE],
819 tvb, offset, 4, FALSE);
822 reserved = tvb_get_ntohs(tvb, offset);
823 proto_tree_add_text(ospf_lsr_tree, tvb, offset, 2,
824 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"), reserved);
825 ls_type = tvb_get_ntohs(tvb, offset+2);
826 proto_tree_add_text(ospf_lsr_tree, tvb, offset+2, 2, "LS Type: %s (0x%04x)",
827 val_to_str(ls_type, v3_ls_type_vals, "Unknown"),
836 proto_tree_add_text(ospf_lsr_tree, tvb, offset + 4, 4, "Link State ID: %s",
837 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
838 proto_tree_add_item(ospf_lsr_tree, ospf_filter[OSPFF_ADV_ROUTER],
839 tvb, offset + 8, 4, FALSE);
846 dissect_ospf_ls_upd(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
848 proto_tree *ospf_lsa_upd_tree=NULL;
853 ti = proto_tree_add_text(tree, tvb, offset, -1, "LS Update Packet");
854 ospf_lsa_upd_tree = proto_item_add_subtree(ti, ett_ospf_lsa_upd);
856 lsa_nr = tvb_get_ntohl(tvb, offset);
857 proto_tree_add_text(ospf_lsa_upd_tree, tvb, offset, 4, "Number of LSAs: %u",
859 /* skip to the beginning of the first LSA */
860 offset += 4; /* the LS Upd Packet contains only a 32 bit #LSAs field */
863 while (lsa_counter < lsa_nr) {
864 if ( version == OSPF_VERSION_2)
865 offset = dissect_ospf_v2_lsa(tvb, offset, ospf_lsa_upd_tree, TRUE);
867 if ( version == OSPF_VERSION_3)
868 offset = dissect_ospf_v3_lsa(tvb, offset, ospf_lsa_upd_tree, TRUE);
874 dissect_ospf_ls_ack(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
876 /* the body of a LS Ack packet simply contains zero or more LSA Headers */
877 while (tvb_reported_length_remaining(tvb, offset) != 0) {
878 if ( version == OSPF_VERSION_2)
879 offset = dissect_ospf_v2_lsa(tvb, offset, tree, FALSE);
881 if ( version == OSPF_VERSION_3)
882 offset = dissect_ospf_v3_lsa(tvb, offset, tree, FALSE);
887 * Returns if an LSA is opaque, i.e. requires special treatment
890 is_opaque(int lsa_type)
892 return (lsa_type >= OSPF_LSTYPE_OP_LINKLOCAL &&
893 lsa_type <= OSPF_LSTYPE_OP_ASWIDE);
896 /* MPLS/TE TLV types */
897 #define MPLS_TLV_ROUTER 1
898 #define MPLS_TLV_LINK 2
900 /* MPLS/TE Link STLV types */
908 MPLS_LINK_MAX_RES_BW,
911 MPLS_LINK_LOCAL_ID = 11,
913 MPLS_LINK_PROTECTION = 14,
914 MPLS_LINK_IF_SWITCHING_DESC,
915 MPLS_LINK_SHARED_RISK_GROUP,
918 static const value_string mpls_link_stlv_str[] = {
919 {MPLS_LINK_TYPE, "Link Type"},
920 {MPLS_LINK_ID, "Link ID"},
921 {MPLS_LINK_LOCAL_IF, "Local Interface IP Address"},
922 {MPLS_LINK_REMOTE_IF, "Remote Interface IP Address"},
923 {MPLS_LINK_TE_METRIC, "Traffic Engineering Metric"},
924 {MPLS_LINK_MAX_BW, "Maximum Bandwidth"},
925 {MPLS_LINK_MAX_RES_BW, "Maximum Reservable Bandwidth"},
926 {MPLS_LINK_UNRES_BW, "Unreserved Bandwidth"},
927 {MPLS_LINK_COLOR, "Resource Class/Color"},
928 {MPLS_LINK_LOCAL_ID, "Link Local Identifier"},
929 {MPLS_LINK_REMOTE_ID, "Link Remote Identifier"},
930 {MPLS_LINK_PROTECTION, "Link Protection Type"},
931 {MPLS_LINK_IF_SWITCHING_DESC, "Interface Switching Capability Descriptor"},
932 {MPLS_LINK_SHARED_RISK_GROUP, "Shared Risk Link Group"},
937 * Dissect MPLS/TE opaque LSA
940 dissect_ospf_lsa_mpls(tvbuff_t *tvb, int offset, proto_tree *tree,
944 proto_tree *mpls_tree;
945 proto_tree *tlv_tree;
946 proto_tree *stlv_tree;
952 int stlv_type, stlv_len, stlv_offset;
956 ti = proto_tree_add_text(tree, tvb, offset, length,
957 "MPLS Traffic Engineering LSA");
958 proto_tree_add_item_hidden(tree, ospf_filter[OSPFF_LS_MPLS],
959 tvb, offset, 2, FALSE);
960 mpls_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls);
962 while (length != 0) {
963 tlv_type = tvb_get_ntohs(tvb, offset);
964 tlv_length = tvb_get_ntohs(tvb, offset + 2);
965 tlv_end_offset = offset + tlv_length + 4;
969 case MPLS_TLV_ROUTER:
970 ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
971 "Router Address: %s",
972 ip_to_str(tvb_get_ptr(tvb, offset+4, 4)));
973 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_router);
974 proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: 1 - Router Address");
975 proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
977 proto_tree_add_item(tlv_tree, ospf_filter[OSPFF_LS_MPLS_ROUTERID],
978 tvb, offset+4, 4, FALSE);
982 ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
984 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
985 proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: 2 - Link Information");
986 proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
988 stlv_offset = offset + 4;
990 /* Walk down the sub-TLVs for link information */
991 while (stlv_offset < tlv_end_offset) {
992 stlv_type = tvb_get_ntohs(tvb, stlv_offset);
993 stlv_len = tvb_get_ntohs(tvb, stlv_offset + 2);
994 stlv_name = val_to_str(stlv_type, mpls_link_stlv_str, "Unknown sub-TLV");
998 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1000 tvb_get_guint8(tvb, stlv_offset + 4));
1001 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1002 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1003 "TLV Type: %u: %s", stlv_type, stlv_name);
1004 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1006 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "%s: %u", stlv_name,
1007 tvb_get_guint8(tvb, stlv_offset + 4));
1011 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1012 "%s: %s (%x)", stlv_name,
1013 ip_to_str(tvb_get_ptr(tvb, stlv_offset + 4, 4)),
1014 tvb_get_ntohl(tvb, stlv_offset + 4));
1015 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1016 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1017 "TLV Type: %u: %s", stlv_type, stlv_name);
1018 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1020 proto_tree_add_item(stlv_tree, ospf_filter[OSPFF_LS_MPLS_LINKID],
1021 tvb, stlv_offset+4, 4, FALSE);
1024 case MPLS_LINK_LOCAL_IF:
1025 case MPLS_LINK_REMOTE_IF:
1026 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1028 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1029 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1030 "TLV Type: %u: %s", stlv_type, stlv_name);
1031 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1033 /* The Local/Remote Interface IP Address sub-TLV is TLV type 3/4, and is 4N
1034 octets in length, where N is the number of neighbor addresses. */
1035 for (i=0; i < stlv_len; i+=4)
1036 proto_tree_add_item(stlv_tree,
1037 stlv_type==MPLS_LINK_LOCAL_IF ?
1038 ospf_filter[OSPFF_LS_MPLS_LOCAL_ADDR] :
1039 ospf_filter[OSPFF_LS_MPLS_REMOTE_ADDR],
1040 tvb, stlv_offset+4+i, 4, FALSE);
1043 case MPLS_LINK_TE_METRIC:
1044 case MPLS_LINK_COLOR:
1045 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1046 "%s: %u", stlv_name,
1047 tvb_get_ntohl(tvb, stlv_offset + 4));
1048 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1049 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1050 "TLV Type: %u: %s", stlv_type, stlv_name);
1051 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1053 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %u", stlv_name,
1054 tvb_get_ntohl(tvb, stlv_offset + 4));
1057 case MPLS_LINK_MAX_BW:
1058 case MPLS_LINK_MAX_RES_BW:
1059 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1060 "%s: %.10g", stlv_name,
1061 tvb_get_ntohieee_float(tvb, stlv_offset + 4));
1062 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1063 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1064 "TLV Type: %u: %s", stlv_type, stlv_name);
1065 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1067 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %.10g", stlv_name,
1068 tvb_get_ntohieee_float(tvb, stlv_offset + 4));
1071 case MPLS_LINK_UNRES_BW:
1072 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1074 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1075 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1076 "TLV Type: %u: %s", stlv_type, stlv_name);
1077 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1079 for (i = 0; i < 8; i++) {
1080 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4+(i*4), 4,
1081 "Pri %d: %.10g bytes/s (%.0f bits/s)", i,
1082 tvb_get_ntohieee_float(tvb, stlv_offset + 4 + i*4),
1083 tvb_get_ntohieee_float(tvb, stlv_offset + 4 + i*4) * 8.0);
1087 case MPLS_LINK_LOCAL_ID:
1088 case MPLS_LINK_REMOTE_ID:
1089 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1090 "%s: %d (0x%x)", stlv_name,
1091 tvb_get_ntohl(tvb, stlv_offset + 4),
1092 tvb_get_ntohl(tvb, stlv_offset + 4));
1093 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1094 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1095 "TLV Type: %u: %s", stlv_type, stlv_name);
1096 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1098 proto_tree_add_item(stlv_tree,
1099 stlv_type==MPLS_LINK_LOCAL_ID ?
1100 ospf_filter[OSPFF_LS_MPLS_LOCAL_IFID] :
1101 ospf_filter[OSPFF_LS_MPLS_REMOTE_IFID],
1102 tvb, stlv_offset+4, 4, FALSE);
1105 case MPLS_LINK_IF_SWITCHING_DESC:
1106 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1108 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1109 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1110 "TLV Type: %u: %s", stlv_type, stlv_name);
1111 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1113 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "Switching Type: %s",
1114 val_to_str(tvb_get_guint8(tvb,stlv_offset+4),
1115 gmpls_switching_type_str, "Unknown (%d)"));
1116 proto_tree_add_text(stlv_tree, tvb, stlv_offset+5, 1, "Encoding: %s",
1117 val_to_str(tvb_get_guint8(tvb,stlv_offset+5),
1118 gmpls_lsp_enc_str, "Unknown (%d)"));
1119 for (i = 0; i < 8; i++) {
1120 proto_tree_add_text(stlv_tree, tvb, stlv_offset+8+(i*4), 4,
1121 "Pri %d: %.10g bytes/s (%.0f bits/s)", i,
1122 tvb_get_ntohieee_float(tvb, stlv_offset + 8 + i*4),
1123 tvb_get_ntohieee_float(tvb, stlv_offset + 8 + i*4) * 8.0);
1128 proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1129 "Unknown Link sub-TLV: %u", stlv_type);
1132 stlv_offset += ((stlv_len+4+3)/4)*4;
1137 ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
1138 "Unknown LSA: %u", tlv_type);
1139 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
1140 proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: %u - Unknown",
1142 proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
1144 proto_tree_add_text(tlv_tree, tvb, offset+4, tlv_length, "TLV Data");
1148 offset += tlv_length + 4;
1149 length -= tlv_length + 4;
1154 * Dissect opaque LSAs
1157 dissect_ospf_lsa_opaque(tvbuff_t *tvb, int offset, proto_tree *tree,
1158 guint8 ls_id_type, guint32 length)
1160 switch (ls_id_type) {
1162 case OSPF_LSA_MPLS_TE:
1163 dissect_ospf_lsa_mpls(tvb, offset, tree, length);
1167 proto_tree_add_text(tree, tvb, offset, length,
1168 "Unknown LSA Type %u", ls_id_type);
1170 } /* switch on opaque LSA id */
1174 dissect_ospf_v2_lsa(tvbuff_t *tvb, int offset, proto_tree *tree,
1175 gboolean disassemble_body)
1177 proto_tree *ospf_lsa_tree;
1188 guint16 link_counter;
1190 char *link_type_str;
1191 char *link_type_short_str;
1194 /* AS-external LSA */
1200 ls_type = tvb_get_guint8(tvb, offset + 3);
1201 ls_length = tvb_get_ntohs(tvb, offset + 18);
1202 end_offset = offset + ls_length;
1204 if (disassemble_body) {
1205 ti = proto_tree_add_text(tree, tvb, offset, ls_length,
1207 val_to_str(ls_type, ls_type_vals, "Unknown (%d)"));
1209 ti = proto_tree_add_text(tree, tvb, offset, OSPF_LSA_HEADER_LENGTH,
1212 ospf_lsa_tree = proto_item_add_subtree(ti, ett_ospf_lsa);
1214 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "LS Age: %u seconds",
1215 tvb_get_ntohs(tvb, offset));
1216 dissect_ospf_options(tvb, offset + 2, ospf_lsa_tree, OSPF_VERSION_2);
1217 proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_LS_TYPE], tvb,
1218 offset + 3, 1, FALSE);
1219 proto_tree_add_item_hidden(ospf_lsa_tree,
1220 ospf_filter[ospf_ls_type_to_filter(ls_type)], tvb,
1221 offset + 3, 1, FALSE);
1223 if (is_opaque(ls_type)) {
1224 ls_id_type = tvb_get_guint8(tvb, offset + 4);
1225 proto_tree_add_uint(ospf_lsa_tree, ospf_filter[OSPFF_LS_OPAQUE_TYPE],
1226 tvb, offset + 4, 1, ls_id_type);
1228 switch (ls_id_type) {
1230 case OSPF_LSA_MPLS_TE:
1231 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 5, 1, "Link State ID TE-LSA Reserved: %u",
1232 tvb_get_guint8(tvb, offset + 5));
1233 proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_LS_MPLS_TE_INSTANCE],
1234 tvb, offset + 6, 2, FALSE);
1238 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 5, 3, "Link State ID Opaque ID: %u",
1239 tvb_get_ntoh24(tvb, offset + 5));
1244 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link State ID: %s",
1245 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1248 proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_ADV_ROUTER],
1249 tvb, offset + 8, 4, FALSE);
1250 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "LS Sequence Number: 0x%08x",
1251 tvb_get_ntohl(tvb, offset + 12));
1252 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 16, 2, "LS Checksum: %04x",
1253 tvb_get_ntohs(tvb, offset + 16));
1255 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 18, 2, "Length: %u",
1258 /* skip past the LSA header to the body */
1259 offset += OSPF_LSA_HEADER_LENGTH;
1260 if (ls_length <= OSPF_LSA_HEADER_LENGTH)
1261 return offset; /* no data, or bogus length */
1262 ls_length -= OSPF_LSA_HEADER_LENGTH;
1264 if (!disassemble_body)
1269 case OSPF_LSTYPE_ROUTER:
1270 /* again: flags should be secified in detail */
1271 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x",
1272 tvb_get_guint8(tvb, offset));
1273 nr_links = tvb_get_ntohs(tvb, offset + 2);
1274 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2, "Number of Links: %u",
1277 /* nr_links links follow
1278 * maybe we should put each of the links into its own subtree ???
1280 for (link_counter = 1; link_counter <= nr_links; link_counter++) {
1281 proto_tree *ospf_lsa_router_link_tree;
1282 proto_item *ti_local;
1285 /* check the Link Type and ID */
1286 link_type = tvb_get_guint8(tvb, offset + 8);
1287 switch (link_type) {
1290 link_type_str="Point-to-point connection to another router";
1291 link_type_short_str="PTP";
1292 link_id="Neighboring router's Router ID";
1295 case OSPF_LINK_TRANSIT:
1296 link_type_str="Connection to a transit network";
1297 link_type_short_str="Transit";
1298 link_id="IP address of Designated Router";
1301 case OSPF_LINK_STUB:
1302 link_type_str="Connection to a stub network";
1303 link_type_short_str="Stub";
1304 link_id="IP network/subnet number";
1307 case OSPF_LINK_VIRTUAL:
1308 link_type_str="Virtual link";
1309 link_type_short_str="Virtual";
1310 link_id="Neighboring router's Router ID";
1314 link_type_str="Unknown link type";
1315 link_type_short_str="Unknown";
1316 link_id="Unknown link ID";
1320 nr_tos = tvb_get_guint8(tvb, offset + 9);
1323 ti_local = proto_tree_add_text(ospf_lsa_tree, tvb, offset, 12 + 4 * nr_tos,
1324 "Type: %-8s ID: %-15s Data: %-15s Metric: %d",
1325 link_type_short_str,
1326 ip_to_str(tvb_get_ptr(tvb, offset, 4)),
1327 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)),
1328 tvb_get_ntohs(tvb, offset + 10));
1330 ospf_lsa_router_link_tree = proto_item_add_subtree(ti_local, ett_ospf_lsa_router_link);
1332 proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset, 4, "%s: %s", link_id,
1333 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1335 /* link_data should be specified in detail (e.g. network mask) (depends on link type)*/
1336 proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset + 4, 4, "Link Data: %s",
1337 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1339 proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset + 8, 1, "Link Type: %u - %s",
1340 link_type, link_type_str);
1341 proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset + 9, 1, "Number of TOS metrics: %u",
1343 proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset + 10, 2, "TOS 0 metric: %u",
1344 tvb_get_ntohs(tvb, offset + 10));
1348 /* nr_tos metrics may follow each link
1349 * ATTENTION: TOS metrics are not tested (I don't have TOS
1351 * please send me a mail if it is/isn't working
1353 for (tos_counter = 1; tos_counter <= nr_tos; tos_counter++) {
1354 proto_tree_add_text(ospf_lsa_router_link_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1355 tvb_get_guint8(tvb, offset),
1356 tvb_get_ntohs(tvb, offset + 2));
1362 case OSPF_LSTYPE_NETWORK:
1363 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
1364 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1367 while (offset < end_offset) {
1368 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Attached Router: %s",
1369 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1374 case OSPF_LSTYPE_SUMMERY:
1375 /* Type 3 and 4 LSAs have the same format */
1376 case OSPF_LSTYPE_ASBR:
1377 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
1378 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1381 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Metric: %u",
1382 tvb_get_ntoh24(tvb, offset + 1));
1385 /* TOS-specific information, if any */
1386 while (offset < end_offset) {
1387 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1388 tvb_get_guint8(tvb, offset),
1389 tvb_get_ntoh24(tvb, offset + 1));
1394 case OSPF_LSTYPE_ASEXT:
1395 case OSPF_LSTYPE_ASEXT7:
1396 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
1397 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1400 options = tvb_get_guint8(tvb, offset);
1401 if (options & 0x80) { /* check wether or not E bit is set */
1402 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1403 "External Type: Type 2 (metric is larger than any other link state path)");
1405 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1406 "External Type: Type 1 (metric is specified in the same units as interface cost)");
1408 /* the metric field of a AS-external LAS is specified in 3 bytes */
1409 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 1, 3, "Metric: %u",
1410 tvb_get_ntoh24(tvb, offset + 1));
1413 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Forwarding Address: %s",
1414 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1417 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "External Route Tag: %u",
1418 tvb_get_ntohl(tvb, offset));
1421 /* TOS-specific information, if any */
1422 while (offset < end_offset) {
1423 options = tvb_get_guint8(tvb, offset);
1424 if (options & 0x80) { /* check wether or not E bit is set */
1425 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1426 "External Type: Type 2 (metric is larger than any other link state path)");
1428 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1429 "External Type: Type 1 (metric is specified in the same units as interface cost)");
1431 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1433 tvb_get_ntoh24(tvb, offset + 1));
1436 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Forwarding Address: %s",
1437 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1440 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "External Route Tag: %u",
1441 tvb_get_ntohl(tvb, offset));
1446 case OSPF_LSTYPE_OP_LINKLOCAL:
1447 case OSPF_LSTYPE_OP_AREALOCAL:
1448 case OSPF_LSTYPE_OP_ASWIDE:
1450 * RFC 2370 opaque LSAs.
1452 dissect_ospf_lsa_opaque(tvb, offset, ospf_lsa_tree, ls_id_type,
1454 offset += ls_length;
1458 /* unknown LSA type */
1459 proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1460 "Unknown LSA Type");
1461 offset += ls_length;
1464 /* return the offset of the next LSA */
1469 dissect_ospf_v3_lsa(tvbuff_t *tvb, int offset, proto_tree *tree,
1470 gboolean disassemble_body)
1472 proto_tree *ospf_lsa_tree;
1482 char *link_type_str;
1485 guint8 router_lsa_flags;
1486 char router_lsa_flags_string[5];
1488 guint8 router_priority;
1489 guint32 number_prefixes;
1490 guint8 prefix_length;
1493 guint16 referenced_ls_type;
1496 guint8 flags_string[4];
1497 guint32 external_route_tag;
1500 ls_type = tvb_get_ntohs(tvb, offset + 2);
1501 ls_length = tvb_get_ntohs(tvb, offset + 18);
1502 end_offset = offset + ls_length;
1504 if (disassemble_body) {
1505 ti = proto_tree_add_text(tree, tvb, offset, ls_length,
1506 "%s (Type: 0x%04x)", val_to_str(ls_type, v3_ls_type_vals,"Unknown"), ls_type);
1508 ti = proto_tree_add_text(tree, tvb, offset, OSPF_LSA_HEADER_LENGTH,
1511 ospf_lsa_tree = proto_item_add_subtree(ti, ett_ospf_lsa);
1513 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "LS Age: %u seconds",
1514 tvb_get_ntohs(tvb, offset));
1516 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2, "LSA Type: 0x%04x (%s)",
1517 ls_type, val_to_str(ls_type, v3_ls_type_vals,"Unkown"));
1519 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link State ID: %s",
1520 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1522 proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_ADV_ROUTER],
1523 tvb, offset + 8, 4, FALSE);
1524 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "LS Sequence Number: 0x%08x",
1525 tvb_get_ntohl(tvb, offset + 12));
1526 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 16, 2, "LS Checksum: %04x",
1527 tvb_get_ntohs(tvb, offset + 16));
1529 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 18, 2, "Length: %u",
1532 /* skip past the LSA header to the body */
1533 offset += OSPF_LSA_HEADER_LENGTH;
1534 ls_length -= OSPF_LSA_HEADER_LENGTH;
1536 if (!disassemble_body)
1542 case OSPF_V3_LSTYPE_ROUTER:
1544 /* flags field in an router-lsa */
1545 router_lsa_flags=tvb_get_guint8(tvb,offset);
1546 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_B)
1547 router_lsa_flags_string[3] = 'B';
1549 router_lsa_flags_string[3] = '.';
1550 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_E)
1551 router_lsa_flags_string[2] = 'E';
1553 router_lsa_flags_string[2] = '.';
1554 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_V)
1555 router_lsa_flags_string[1] = 'V';
1557 router_lsa_flags_string[1] = '.';
1558 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_W)
1559 router_lsa_flags_string[0] = 'W';
1561 router_lsa_flags_string[0] = '.';
1563 router_lsa_flags_string[4]=0;
1565 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x (%s)",
1566 router_lsa_flags, router_lsa_flags_string);
1568 /* options field in an router-lsa */
1569 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1571 /* skip the router-lsa flags and options */
1576 proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1577 "Router Interfaces:");
1579 /* scan all router-lsa router interfaces */
1580 /* maybe we should put each of the links into its own subtree ??? */
1581 while (ls_length > 0 ) {
1583 /* check the type */
1584 link_type = tvb_get_guint8(tvb, offset);
1585 switch (link_type) {
1587 case OSPF_V3_LINK_PTP:
1588 link_type_str="Point-to-point connection to another router";
1591 case OSPF_V3_LINK_TRANSIT:
1592 link_type_str="Connection to a transit network";
1595 case OSPF_V3_LINK_RESERVED:
1596 link_type_str="Connection to a stub network";
1599 case OSPF_V3_LINK_VIRTUAL:
1600 link_type_str="Virtual link";
1604 link_type_str="Unknown link type";
1608 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Type: %u (%s)", link_type,link_type_str);
1610 /* reserved field */
1611 reserved = tvb_get_guint8(tvb, offset+1);
1612 proto_tree_add_text(ospf_lsa_tree, tvb, offset+1, 1,
1613 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1616 metric=tvb_get_ntohs(tvb, offset+2);
1617 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2,"Metric: %u",metric);
1620 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Interface ID: %u",
1621 tvb_get_ntohl(tvb, offset + 4));
1623 /* Neighbor Interface ID */
1624 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Neighbor Interface ID: %u",
1625 tvb_get_ntohl(tvb, offset + 8));
1627 /* Neighbor Router ID */
1628 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "Neighbor Router ID: %s",
1629 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
1631 /* skip to the (possible) next entry */
1638 case OSPF_V3_LSTYPE_NETWORK:
1640 /* reserved field */
1641 reserved = tvb_get_guint8(tvb, offset);
1642 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1643 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1645 /* options field in an network-lsa */
1646 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1651 while (ls_length > 0 ) {
1652 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Attached Router: %s",
1653 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1660 case OSPF_V3_LSTYPE_INTER_AREA_PREFIX:
1662 /* reserved field */
1663 reserved = tvb_get_guint8(tvb, offset);
1664 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1665 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1668 metric=tvb_get_ntoh24(tvb, offset+11);
1669 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 1, 3,"Metric: %u",metric);
1672 prefix_length=tvb_get_guint8(tvb, offset+4);
1673 proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1, "PrefixLength: %u",prefix_length);
1675 /* prefix options */
1676 dissect_ospf_v3_prefix_options(tvb, offset+5, ospf_lsa_tree);
1678 /* 16 bits reserved */
1679 reserved16=tvb_get_ntohs(tvb, offset+6);
1680 proto_tree_add_text(ospf_lsa_tree, tvb, offset+6, 2,
1681 (reserved16 == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved16);
1685 /* address_prefix */
1686 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1688 offset+=(prefix_length+31)/32*4;
1693 case OSPF_V3_LSTYPE_INTER_AREA_ROUTER:
1695 /* reserved field */
1696 reserved = tvb_get_guint8(tvb, offset);
1697 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1698 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1700 /* options field in an inter-area-router-lsa */
1701 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1703 /* reserved field */
1704 reserved = tvb_get_guint8(tvb, offset+4);
1705 proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1,
1706 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1709 metric=tvb_get_ntoh24(tvb, offset+6);
1710 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 6, 3,"Metric: %u",metric);
1712 /* Destination Router ID */
1713 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Destination Router ID: %s",
1714 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
1720 case OSPF_V3_LSTYPE_AS_EXTERNAL:
1723 flags=tvb_get_guint8(tvb, offset);
1724 if (flags & OSPF_V3_AS_EXTERNAL_FLAG_E)
1725 flags_string[0] = 'E';
1727 flags_string[0] = '.';
1728 if (flags & OSPF_V3_AS_EXTERNAL_FLAG_F)
1729 flags_string[1] = 'F';
1731 flags_string[1] = '.';
1732 if (flags & OSPF_V3_AS_EXTERNAL_FLAG_T)
1733 flags_string[2] = 'T';
1735 flags_string[2] = '.';
1739 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x (%s)",
1740 flags, flags_string);
1742 /* 24 bits metric */
1743 metric=tvb_get_ntoh24(tvb, offset+1);
1744 proto_tree_add_text(ospf_lsa_tree, tvb, offset+1, 3,
1745 "Metric: %u", metric);
1748 prefix_length=tvb_get_guint8(tvb, offset+4);
1749 proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1, "PrefixLength: %u",prefix_length);
1751 /* prefix options */
1752 dissect_ospf_v3_prefix_options(tvb, offset+5, ospf_lsa_tree);
1754 /* referenced LS type */
1755 referenced_ls_type=tvb_get_ntohs(tvb, offset+6);
1756 proto_tree_add_text(ospf_lsa_tree, tvb, offset+6, 2,"Referenced LS type 0x%04x (%s)",
1757 referenced_ls_type, val_to_str(referenced_ls_type, v3_ls_type_vals, "Unknown"));
1761 /* address_prefix */
1762 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1764 offset+=(prefix_length+31)/32*4;
1766 /* Forwarding Address (optional - only if F-flag is on) */
1767 if ( (offset < end_offset) && (flags & OSPF_V3_AS_EXTERNAL_FLAG_F) ) {
1768 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 16,"Forwarding Address: %s",
1769 ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset, 16)));
1774 /* External Route Tag (optional - only if T-flag is on) */
1775 if ( (offset < end_offset) && (flags & OSPF_V3_AS_EXTERNAL_FLAG_T) ) {
1776 external_route_tag=tvb_get_ntohl(tvb, offset);
1777 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4,"External Route Tag: %u",
1778 external_route_tag);
1783 /* Referenced Link State ID (optional - only if Referenced LS type is non-zero */
1784 if ( (offset < end_offset) && (referenced_ls_type != 0) ) {
1785 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Referenced Link State ID: %s",
1786 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1792 case OSPF_V3_LSTYPE_LINK:
1794 /* router priority */
1795 router_priority=tvb_get_guint8(tvb, offset);
1796 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Router Priority: %u", router_priority);
1798 /* options field in an link-lsa */
1799 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1801 /* Link-local Interface Address */
1802 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 16, "Link-local Interface Address: %s",
1803 ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, 16)));
1805 /* Number prefixes */
1806 number_prefixes=tvb_get_ntohl(tvb, offset + 20);
1807 proto_tree_add_text(ospf_lsa_tree, tvb, offset+20, 4, "# prefixes: %d",number_prefixes);
1811 while (number_prefixes > 0) {
1814 prefix_length=tvb_get_guint8(tvb, offset);
1815 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "PrefixLength: %u",prefix_length);
1817 /* prefix options */
1818 dissect_ospf_v3_prefix_options(tvb, offset+1, ospf_lsa_tree);
1820 /* 16 bits reserved */
1821 reserved16=tvb_get_ntohs(tvb, offset+2);
1822 proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,
1823 (reserved16 == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved16);
1827 /* address_prefix */
1828 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1830 offset+=(prefix_length+31)/32*4;
1837 case OSPF_V3_LSTYPE_INTRA_AREA_PREFIX:
1840 number_prefixes=tvb_get_ntohs(tvb, offset);
1841 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2,"# prefixes: %u",number_prefixes);
1843 /* referenced LS type */
1844 referenced_ls_type=tvb_get_ntohs(tvb, offset+2);
1845 proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,"Referenced LS type 0x%04x (%s)",
1846 referenced_ls_type, val_to_str(referenced_ls_type, v3_ls_type_vals, "Unknown"));
1848 /* Referenced Link State ID */
1849 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Referenced Link State ID: %s",
1850 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1852 /* Referenced Advertising Router */
1853 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Referenced Advertising Router: %s",
1854 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
1858 while (number_prefixes > 0) {
1861 prefix_length=tvb_get_guint8(tvb, offset);
1862 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "PrefixLength: %u",prefix_length);
1864 /* prefix options */
1865 dissect_ospf_v3_prefix_options(tvb, offset+1, ospf_lsa_tree);
1867 /* 16 bits metric */
1868 metric=tvb_get_ntohs(tvb, offset+2);
1869 proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,
1870 "Metric: %u", metric);
1874 /* address_prefix */
1875 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1877 offset+=(prefix_length+31)/32*4;
1884 /* unknown LSA type */
1885 proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1886 "Unknown LSA Type 0x%04x",ls_type);
1887 offset += ls_length;
1890 /* return the offset of the next LSA */
1896 dissect_ospf_options(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
1898 guint8 options_ospfv2;
1899 guint32 options_ospfv3;
1900 char options_string[20] = "";
1902 /* ATTENTION !!! no check for length of options string - with OSPFv3 maximum length is 14 characters */
1904 switch ( version ) {
1906 case OSPF_VERSION_2:
1908 options_ospfv2 = tvb_get_guint8(tvb, offset);
1910 if (options_ospfv2 & OSPF_V2_OPTIONS_E)
1911 strcat(options_string, "E");
1913 if (options_ospfv2 & OSPF_V2_OPTIONS_MC) {
1914 if (options_string[0] != '\0')
1915 strcat(options_string, "/");
1916 strcat(options_string, "MC");
1919 if (options_ospfv2 & OSPF_V2_OPTIONS_NP) {
1920 if (options_string[0] != '\0')
1921 strcat(options_string, "/");
1922 strcat(options_string, "NP");
1925 if (options_ospfv2 & OSPF_V2_OPTIONS_EA) {
1926 if (options_string[0] != '\0')
1927 strcat(options_string, "/");
1928 strcat(options_string, "EA");
1931 if (options_ospfv2 & OSPF_V2_OPTIONS_DC) {
1932 if (options_string[0] != '\0')
1933 strcat(options_string, "/");
1934 strcat(options_string, "DC");
1937 if (options_ospfv2 & OSPF_V2_OPTIONS_O) {
1938 if (options_string[0] != '\0')
1939 strcat(options_string, "/");
1940 strcat(options_string, "O");
1943 if (options_ospfv2 & OSPF_V2_OPTIONS_DN) {
1944 if (options_string[0] != '\0')
1945 strcat(options_string, "/");
1946 strcat(options_string, "DN");
1949 proto_tree_add_text(tree, tvb, offset, 1, "Options: 0x%x (%s)",
1950 options_ospfv2, options_string);
1954 case OSPF_VERSION_3:
1956 options_ospfv3 = tvb_get_ntoh24(tvb, offset);
1958 if (options_ospfv3 & OSPF_V3_OPTIONS_V6)
1959 strcat(options_string, "V6");
1961 if (options_ospfv3 & OSPF_V3_OPTIONS_E)
1962 if (options_string[0] != '\0')
1963 strcat(options_string, "/");
1964 strcat(options_string, "E");
1966 if (options_ospfv3 & OSPF_V3_OPTIONS_MC) {
1967 if (options_string[0] != '\0')
1968 strcat(options_string, "/");
1969 strcat(options_string, "MC");
1972 if (options_ospfv3 & OSPF_V3_OPTIONS_N) {
1973 if (options_string[0] != '\0')
1974 strcat(options_string, "/");
1975 strcat(options_string, "N");
1978 if (options_ospfv3 & OSPF_V3_OPTIONS_R) {
1979 if (options_string[0] != '\0')
1980 strcat(options_string, "/");
1981 strcat(options_string, "R");
1984 if (options_ospfv3 & OSPF_V3_OPTIONS_DC) {
1985 if (options_string[0] != '\0')
1986 strcat(options_string, "/");
1987 strcat(options_string, "DC");
1990 proto_tree_add_text(tree, tvb, offset, 3, "Options: 0x%x (%s)",
1991 options_ospfv3, options_string);
2001 static void dissect_ospf_v3_prefix_options(tvbuff_t *tvb, int offset, proto_tree *tree)
2004 guint8 prefix_options;
2005 char prefix_options_string[11];
2010 prefix_options=tvb_get_guint8(tvb, offset);
2012 strcpy(prefix_options_string,"");
2014 if (prefix_options & OSPF_V3_PREFIX_OPTION_P) {
2015 strcat(prefix_options_string, "P");
2019 if (prefix_options & OSPF_V3_PREFIX_OPTION_MC) {
2020 if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
2021 strcat(prefix_options_string, "/");
2024 strcat(prefix_options_string, "MC");
2028 if (prefix_options & OSPF_V3_PREFIX_OPTION_LA) {
2029 if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
2030 strcat(prefix_options_string, "/");
2033 strcat(prefix_options_string, "LA");
2037 if (prefix_options & OSPF_V3_PREFIX_OPTION_NU) {
2038 if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
2039 strcat(prefix_options_string, "/");
2042 strcat(prefix_options_string, "NU");
2045 prefix_options_string[10]=0;
2047 proto_tree_add_text(tree, tvb, offset, 1, "PrefixOptions: 0x%02x (%s)",prefix_options, prefix_options_string);
2052 static void dissect_ospf_v3_address_prefix(tvbuff_t *tvb, int offset, int prefix_length, proto_tree *tree)
2060 guint8 bytes_to_process;
2063 start_offset=offset;
2066 bytes_to_process=((prefix_length+31)/32)*4;
2068 while (bytes_to_process > 0 ) {
2070 value=tvb_get_guint8(tvb, offset);
2072 if ( (position > 0) && ( (position%2) == 0 ) )
2073 buffer[bufpos++]=':';
2075 sprintf(bytebuf,"%02x",value);
2076 buffer[bufpos++]=bytebuf[0];
2077 buffer[bufpos++]=bytebuf[1];
2085 proto_tree_add_text(tree, tvb, start_offset, ((prefix_length+31)/32)*4, "Address Prefix: %s",buffer);
2091 proto_register_ospf(void)
2093 static gint *ett[] = {
2100 &ett_ospf_lsa_router_link,
2103 &ett_ospf_lsa_mpls_router,
2104 &ett_ospf_lsa_mpls_link,
2105 &ett_ospf_lsa_mpls_link_stlv
2108 proto_ospf = proto_register_protocol("Open Shortest Path First",
2110 proto_register_field_array(proto_ospf, ospff_info, array_length(ospff_info));
2111 proto_register_subtree_array(ett, array_length(ett));
2115 proto_reg_handoff_ospf(void)
2117 dissector_handle_t ospf_handle;
2119 ospf_handle = create_dissector_handle(dissect_ospf, proto_ospf);
2120 dissector_add("ip.proto", IP_PROTO_OSPF, ospf_handle);
2121 data_handle = find_dissector("data");