2 * Routines for OSPF packet disassembly
3 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
5 * $Id: packet-ospf.c,v 1.69 2002/08/02 23:35:55 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_E 0x02
81 #define OSPF_V2_OPTIONS_MC 0x04
82 #define OSPF_V2_OPTIONS_NP 0x08
83 #define OSPF_V2_OPTIONS_EA 0x10
84 #define OSPF_V2_OPTIONS_DC 0x20
85 #define OSPF_V2_OPTIONS_O 0x40
86 #define OSPF_V2_OPTIONS_DN 0x01
87 #define OSPF_V3_OPTIONS_V6 0x01
88 #define OSPF_V3_OPTIONS_E 0x02
89 #define OSPF_V3_OPTIONS_MC 0x04
90 #define OSPF_V3_OPTIONS_N 0x08
91 #define OSPF_V3_OPTIONS_R 0x10
92 #define OSPF_V3_OPTIONS_DC 0x20
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_upd = -1;
202 /* Trees for opaque LSAs */
203 static gint ett_ospf_lsa_mpls = -1;
204 static gint ett_ospf_lsa_mpls_router = -1;
205 static gint ett_ospf_lsa_mpls_link = -1;
206 static gint ett_ospf_lsa_mpls_link_stlv = -1;
208 /*-----------------------------------------------------------------------
210 *-----------------------------------------------------------------------*/
212 /* The OSPF filtering keys */
225 OSPFF_LS_OPAQUE_TYPE,
227 OSPFF_LS_MPLS_TE_INSTANCE,
243 OSPFF_LS_MPLS_ROUTERID,
245 OSPFF_LS_MPLS_LINKID,
246 OSPFF_LS_MPLS_LOCAL_ADDR,
247 OSPFF_LS_MPLS_REMOTE_ADDR,
248 OSPFF_LS_MPLS_LOCAL_IFID,
249 OSPFF_LS_MPLS_REMOTE_IFID,
254 static int ospf_filter[OSPFF_MAX];
256 static hf_register_info ospff_info[] = {
258 /* Message type number */
259 {&ospf_filter[OSPFF_MSG_TYPE],
260 { "Message Type", "ospf.msg", FT_UINT8, BASE_DEC, VALS(pt_vals), 0x0,
264 {&ospf_filter[OSPFF_MSG_HELLO],
265 { "Hello", "ospf.msg.hello", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
267 {&ospf_filter[OSPFF_MSG_DB_DESC],
268 { "Database Description", "ospf.msg.dbdesc", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
270 {&ospf_filter[OSPFF_MSG_LS_REQ],
271 { "Link State Adv Request", "ospf.msg.lsreq", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
273 {&ospf_filter[OSPFF_MSG_LS_UPD],
274 { "Link State Adv Update", "ospf.msg.lsupdate", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
276 {&ospf_filter[OSPFF_MSG_LS_ACK],
277 { "Link State Adv Acknowledgement", "ospf.msg.lsack", FT_BOOLEAN,
278 BASE_NONE, NULL, 0x0, "", HFILL }},
283 {&ospf_filter[OSPFF_LS_TYPE],
284 { "Link-State Advertisement Type", "ospf.lsa", FT_UINT8, BASE_DEC,
285 VALS(ls_type_vals), 0x0, "", HFILL }},
286 {&ospf_filter[OSPFF_LS_OPAQUE_TYPE],
287 { "Link State ID Opaque Type", "ospf.lsid_opaque_type", FT_UINT8, BASE_DEC,
288 VALS(ls_opaque_type_vals), 0x0, "", HFILL }},
290 {&ospf_filter[OSPFF_LS_MPLS_TE_INSTANCE],
291 { "Link State ID TE-LSA Instance", "ospf.lsid_te_lsa.instance", FT_UINT16, BASE_DEC,
292 NULL, 0x0, "", HFILL }},
294 {&ospf_filter[OSPFF_LS_ROUTER],
295 { "Router LSA", "ospf.lsa.router", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
297 {&ospf_filter[OSPFF_LS_NETWORK],
298 { "Network LSA", "ospf.lsa.network", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
300 {&ospf_filter[OSPFF_LS_SUMMARY],
301 { "Summary LSA (IP Network)", "ospf.lsa.summary", FT_BOOLEAN, BASE_NONE,
302 NULL, 0x0, "", HFILL }},
303 {&ospf_filter[OSPFF_LS_ASBR],
304 { "Summary LSA (ASBR)", "ospf.lsa.asbr", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
306 {&ospf_filter[OSPFF_LS_ASEXT],
307 { "AS-External LSA (ASBR)", "ospf.lsa.asext", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
309 {&ospf_filter[OSPFF_LS_GRPMEMBER],
310 { "Group Membership LSA", "ospf.lsa.member", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
312 {&ospf_filter[OSPFF_LS_ASEXT7],
313 { "NSSA AS-External LSA", "ospf.lsa.nssa", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
315 {&ospf_filter[OSPFF_LS_EXTATTR],
316 { "External Attributes LSA", "ospf.lsa.attr", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
318 {&ospf_filter[OSPFF_LS_OPAQUE],
319 { "Opaque LSA", "ospf.lsa.opaque", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
322 /* Other interesting OSPF values */
324 {&ospf_filter[OSPFF_SRC_ROUTER],
325 { "Source OSPF Router", "ospf.srcrouter", FT_IPv4, BASE_NONE, NULL, 0x0,
328 {&ospf_filter[OSPFF_ADV_ROUTER],
329 { "Advertising Router", "ospf.advrouter", FT_IPv4, BASE_NONE, NULL, 0x0,
332 {&ospf_filter[OSPFF_LS_MPLS],
333 { "MPLS Traffic Engineering LSA", "ospf.lsa.mpls", FT_BOOLEAN,
334 BASE_NONE, NULL, 0x0, "", HFILL }},
336 {&ospf_filter[OSPFF_LS_MPLS_ROUTERID],
337 { "MPLS/TE Router ID", "ospf.mpls.routerid", FT_IPv4, BASE_NONE, NULL, 0x0,
340 {&ospf_filter[OSPFF_LS_MPLS_LINKID],
341 { "MPLS/TE Link ID", "ospf.mpls.linkid", FT_IPv4, BASE_NONE, NULL, 0x0,
343 {&ospf_filter[OSPFF_LS_MPLS_LOCAL_ADDR],
344 { "MPLS/TE Local Interface Address", "ospf.mpls.local_addr", FT_IPv4,
345 BASE_NONE, NULL, 0x0, "", HFILL }},
346 {&ospf_filter[OSPFF_LS_MPLS_REMOTE_ADDR],
347 { "MPLS/TE Remote Interface Address", "ospf.mpls.remote_addr", FT_IPv4,
348 BASE_NONE, NULL, 0x0, "", HFILL }},
349 {&ospf_filter[OSPFF_LS_MPLS_LOCAL_IFID],
350 { "MPLS/TE Local Interface Index", "ospf.mpls.local_id", FT_UINT32,
351 BASE_DEC, NULL, 0x0, "", HFILL }},
352 {&ospf_filter[OSPFF_LS_MPLS_REMOTE_IFID],
353 { "MPLS/TE Remote Interface Index", "ospf.mpls.remote_id", FT_UINT32,
354 BASE_DEC, NULL, 0x0, "", HFILL }},
360 static guint8 ospf_msg_type_to_filter (guint8 msg_type)
362 if (msg_type >= OSPF_HELLO &&
363 msg_type <= OSPF_LS_ACK)
364 return msg_type + OSPFF_MSG_MIN;
368 static guint8 ospf_ls_type_to_filter (guint8 ls_type)
370 if (ls_type >= OSPF_LSTYPE_ROUTER &&
371 ls_type <= OSPF_LSTYPE_EXTATTR)
372 return OSPFF_LS_MIN + ls_type;
373 else if (ls_type >= OSPF_LSTYPE_OP_LINKLOCAL &&
374 ls_type <= OSPF_LSTYPE_OP_ASWIDE)
375 return OSPFF_LS_OPAQUE;
380 static dissector_handle_t data_handle;
382 static void dissect_ospf_hello(tvbuff_t*, int, proto_tree*, guint8);
383 static void dissect_ospf_db_desc(tvbuff_t*, int, proto_tree*, guint8);
384 static void dissect_ospf_ls_req(tvbuff_t*, int, proto_tree*, guint8);
385 static void dissect_ospf_ls_upd(tvbuff_t*, int, proto_tree*, guint8);
386 static void dissect_ospf_ls_ack(tvbuff_t*, int, proto_tree*, guint8);
388 /* dissect_ospf_v[23]lsa returns the offset of the next LSA
389 * if disassemble_body is set to FALSE (e.g. in LSA ACK
390 * packets), the offset is set to the offset of the next
393 static int dissect_ospf_v2_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body);
394 static int dissect_ospf_v3_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body);
396 static void dissect_ospf_options(tvbuff_t *, int, proto_tree *, guint8);
398 static void dissect_ospf_v3_prefix_options(tvbuff_t *, int, proto_tree *);
400 static void dissect_ospf_v3_address_prefix(tvbuff_t *, int, int, proto_tree *);
403 dissect_ospf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
405 proto_tree *ospf_tree = NULL;
407 proto_tree *ospf_header_tree;
414 guint16 cksum, computed_cksum;
415 guint length, reported_length;
419 unsigned int ospf_header_length;
425 if (check_col(pinfo->cinfo, COL_PROTOCOL))
426 col_set_str(pinfo->cinfo, COL_PROTOCOL, "OSPF");
427 if (check_col(pinfo->cinfo, COL_INFO))
428 col_clear(pinfo->cinfo, COL_INFO);
430 version = tvb_get_guint8(tvb, 0);
433 ospf_header_length = OSPF_VERSION_2_HEADER_LENGTH;
436 ospf_header_length = OSPF_VERSION_3_HEADER_LENGTH;
439 ospf_header_length = 0;
443 packet_type = tvb_get_guint8(tvb, 1);
444 if (check_col(pinfo->cinfo, COL_INFO)) {
445 col_add_str(pinfo->cinfo, COL_INFO,
446 val_to_str(packet_type, pt_vals, "Unknown (%u)"));
450 ospflen = tvb_get_ntohs(tvb, 2);
452 ti = proto_tree_add_item(tree, proto_ospf, tvb, 0, ospflen, FALSE);
453 ospf_tree = proto_item_add_subtree(ti, ett_ospf);
455 ti = proto_tree_add_text(ospf_tree, tvb, 0, ospf_header_length,
457 ospf_header_tree = proto_item_add_subtree(ti, ett_ospf_hdr);
459 proto_tree_add_text(ospf_header_tree, tvb, 0, 1, "OSPF Version: %u",
461 proto_tree_add_item(ospf_header_tree, ospf_filter[OSPFF_MSG_TYPE],
463 proto_tree_add_item_hidden(ospf_header_tree,
464 ospf_filter[ospf_msg_type_to_filter(packet_type)],
466 proto_tree_add_text(ospf_header_tree, tvb, 2, 2, "Packet Length: %u",
468 proto_tree_add_item(ospf_header_tree, ospf_filter[OSPFF_SRC_ROUTER],
470 areaid=tvb_get_ntohl(tvb,8);
471 proto_tree_add_text(ospf_header_tree, tvb, 8, 4, "Area ID: %s%s",
472 ip_to_str(tvb_get_ptr(tvb, 8, 4)), areaid == 0 ? " (Backbone)" : "");
473 cksum = tvb_get_ntohs(tvb, 12);
474 length = tvb_length(tvb);
475 /* XXX - include only the length from the OSPF header? */
476 reported_length = tvb_reported_length(tvb);
478 /* No checksum supplied in the packet. */
479 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
480 "Packet Checksum: 0x%04x (none)", cksum);
481 } else if (!pinfo->fragmented && length >= reported_length
482 && length >= ospf_header_length
483 && (version == OSPF_VERSION_2 || version == OSPF_VERSION_3)) {
484 /* The packet isn't part of a fragmented datagram and isn't
485 truncated, and we know how to checksum this version of
486 OSPF, so we can checksum it. */
491 /* Header, not including the authentication data (the OSPFv2
492 checksum excludes the 64-bit authentication field). */
493 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, 16);
494 cksum_vec[0].len = 16;
495 if (length > ospf_header_length) {
496 /* Rest of the packet, again not including the
497 authentication data. */
498 reported_length -= ospf_header_length;
499 cksum_vec[1].ptr = tvb_get_ptr(tvb, ospf_header_length, reported_length);
500 cksum_vec[1].len = reported_length;
503 /* There's nothing but a header. */
509 /* IPv6-style checksum, covering the entire OSPF packet
510 and a prepended IPv6 pseudo-header. */
512 /* Set up the fields of the pseudo-header. */
513 cksum_vec[0].ptr = pinfo->src.data;
514 cksum_vec[0].len = pinfo->src.len;
515 cksum_vec[1].ptr = pinfo->dst.data;
516 cksum_vec[1].len = pinfo->dst.len;
517 cksum_vec[2].ptr = (const guint8 *)&phdr;
518 phdr[0] = g_htonl(ospflen);
519 phdr[1] = g_htonl(IP_PROTO_OSPF);
520 cksum_vec[2].len = 8;
522 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, reported_length);
523 cksum_vec[3].len = reported_length;
528 g_assert_not_reached();
531 computed_cksum = in_cksum(cksum_vec, cksum_vec_len);
532 if (computed_cksum == 0) {
533 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
534 "Packet Checksum: 0x%04x (correct)", cksum);
536 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
537 "Packet Checksum: 0x%04x (incorrect, should be 0x%04x)",
538 cksum, in_cksum_shouldbe(cksum, computed_cksum));
541 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
542 "Packet Checksum: 0x%04x", cksum);
546 /* Authentication is only valid for OSPFv2 */
547 if ( version == OSPF_VERSION_2 ) {
548 auth_type = tvb_get_ntohs(tvb, 14);
549 proto_tree_add_text(ospf_header_tree, tvb, 14, 2, "Auth Type: %s",
550 val_to_str(auth_type, auth_vals, "Unknown (%u)"));
554 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data (none)");
557 case OSPF_AUTH_SIMPLE:
558 tvb_get_nstringz0(tvb, 16, 8, auth_data);
559 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data: %s", auth_data);
562 case OSPF_AUTH_CRYPT:
563 proto_tree_add_text(ospf_header_tree, tvb, 18, 1, "Auth Key ID: %u",
564 tvb_get_guint8(tvb, 18));
565 crypto_len = tvb_get_guint8(tvb, 19);
566 proto_tree_add_text(ospf_header_tree, tvb, 19, 1, "Auth Data Length: %u",
568 proto_tree_add_text(ospf_header_tree, tvb, 20, 4, "Auth Crypto Sequence Number: 0x%x",
569 tvb_get_ntohl(tvb, 20));
571 /* Show the message digest that was appended to the end of the
572 OSPF message - but only if it's present (we don't want
573 to get an exception before we've tried dissecting OSPF
575 if (tvb_bytes_exist(tvb, ospflen, crypto_len)) {
576 proto_tree_add_text(ospf_header_tree, tvb, ospflen, crypto_len,
578 tvb_bytes_to_str(tvb, ospflen, crypto_len));
583 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data (unknown)");
589 /* Instance ID and "reserved" is OSPFv3-only */
590 if ( version == OSPF_VERSION_3 ) {
591 instance_ID = tvb_get_guint8(tvb, 14);
592 proto_tree_add_text(ospf_header_tree, tvb, 14, 1, "Instance ID: %u",
594 reserved = tvb_get_guint8(tvb, 15);
595 proto_tree_add_text(ospf_header_tree, tvb, 15, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
600 /* Adjust the length of the tvbuff to match the size of the OSPF
601 * packet (since the dissect routines use it to work out where the
602 * end of the OSPF packet is).
604 tvb_set_reported_length(tvb, ospflen);
606 switch (packet_type){
609 dissect_ospf_hello(tvb, ospf_header_length, ospf_tree, version);
613 dissect_ospf_db_desc(tvb, ospf_header_length, ospf_tree, version);
617 dissect_ospf_ls_req(tvb, ospf_header_length, ospf_tree, version);
621 dissect_ospf_ls_upd(tvb, ospf_header_length, ospf_tree, version);
625 dissect_ospf_ls_ack(tvb, ospf_header_length, ospf_tree, version);
629 call_dissector(data_handle,
630 tvb_new_subset(tvb, ospf_header_length, -1, -1), pinfo, tree);
637 dissect_ospf_hello(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
639 proto_tree *ospf_hello_tree;
642 ti = proto_tree_add_text(tree, tvb, offset, -1, "OSPF Hello Packet");
643 ospf_hello_tree = proto_item_add_subtree(ti, ett_ospf_hello);
647 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4, "Network Mask: %s",
648 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
649 proto_tree_add_text(ospf_hello_tree, tvb, offset + 4, 2,
650 "Hello Interval: %u seconds",
651 tvb_get_ntohs(tvb, offset + 4));
653 dissect_ospf_options(tvb, offset + 6, ospf_hello_tree, version);
654 proto_tree_add_text(ospf_hello_tree, tvb, offset + 7, 1, "Router Priority: %u",
655 tvb_get_guint8(tvb, offset + 7));
656 proto_tree_add_text(ospf_hello_tree, tvb, offset + 8, 4, "Router Dead Interval: %u seconds",
657 tvb_get_ntohl(tvb, offset + 8));
658 proto_tree_add_text(ospf_hello_tree, tvb, offset + 12, 4, "Designated Router: %s",
659 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
660 proto_tree_add_text(ospf_hello_tree, tvb, offset + 16, 4, "Backup Designated Router: %s",
661 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
664 while (tvb_reported_length_remaining(tvb, offset) != 0) {
665 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4,
666 "Active Neighbor: %s",
667 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
672 proto_tree_add_text(ospf_hello_tree, tvb, offset + 0, 4, "Interface ID: %u",
673 tvb_get_ntohl(tvb, offset + 0));
674 proto_tree_add_text(ospf_hello_tree, tvb, offset + 4, 1, "Router Priority: %u",
675 tvb_get_guint8(tvb, offset + 4));
676 dissect_ospf_options(tvb, offset + 5, ospf_hello_tree, version);
677 proto_tree_add_text(ospf_hello_tree, tvb, offset + 8, 2,
678 "Hello Interval: %u seconds",
679 tvb_get_ntohs(tvb, offset + 8));
680 proto_tree_add_text(ospf_hello_tree, tvb, offset + 10, 2, "Router Dead Interval: %u seconds",
681 tvb_get_ntohs(tvb, offset + 10));
682 proto_tree_add_text(ospf_hello_tree, tvb, offset + 12, 4, "Designated Router: %s",
683 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
684 proto_tree_add_text(ospf_hello_tree, tvb, offset + 16, 4, "Backup Designated Router: %s",
685 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
687 while (tvb_reported_length_remaining(tvb, offset) != 0) {
688 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4,
689 "Active Neighbor: %s",
690 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
702 dissect_ospf_db_desc(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
704 proto_tree *ospf_db_desc_tree=NULL;
708 char flags_string[20] = "";
711 ti = proto_tree_add_text(tree, tvb, offset, -1, "OSPF DB Description");
712 ospf_db_desc_tree = proto_item_add_subtree(ti, ett_ospf_desc);
718 proto_tree_add_text(ospf_db_desc_tree, tvb, offset, 2, "Interface MTU: %u",
719 tvb_get_ntohs(tvb, offset));
721 dissect_ospf_options(tvb, offset + 2, ospf_db_desc_tree, version);
723 flags = tvb_get_guint8(tvb, offset + 3);
724 if (flags & OSPF_DBD_FLAG_MS)
725 strcat(flags_string, "MS");
726 if (flags & OSPF_DBD_FLAG_M) {
727 if (flags_string[0] != '\0')
728 strcat(flags_string, "/");
729 strcat(flags_string, "M");
731 if (flags & OSPF_DBD_FLAG_I) {
732 if (flags_string[0] != '\0')
733 strcat(flags_string, "/");
734 strcat(flags_string, "I");
736 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 3, 1, "Flags: 0x%x (%s)",
737 flags, flags_string);
738 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 4, 4, "DD Sequence: %u",
739 tvb_get_ntohl(tvb, offset + 4));
746 reserved = tvb_get_guint8(tvb, offset);
747 proto_tree_add_text(ospf_db_desc_tree, tvb, offset, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
750 dissect_ospf_options(tvb, offset + 1, ospf_db_desc_tree, version);
752 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 4, 2, "Interface MTU: %u",
753 tvb_get_ntohs(tvb, offset+4));
755 reserved = tvb_get_guint8(tvb, offset + 6);
756 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 6, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
759 flags = tvb_get_guint8(tvb, offset + 7);
760 if (flags & OSPF_DBD_FLAG_MS)
761 strcat(flags_string, "MS");
762 if (flags & OSPF_DBD_FLAG_M) {
763 if (flags_string[0] != '\0')
764 strcat(flags_string, "/");
765 strcat(flags_string, "M");
767 if (flags & OSPF_DBD_FLAG_I) {
768 if (flags_string[0] != '\0')
769 strcat(flags_string, "/");
770 strcat(flags_string, "I");
772 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 7, 1, "Flags: 0x%x (%s)",
773 flags, flags_string);
775 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 8, 4, "DD Sequence: %u",
776 tvb_get_ntohl(tvb, offset + 8));
786 /* LS Headers will be processed here */
787 /* skip to the end of DB-Desc header */
788 while (tvb_reported_length_remaining(tvb, offset) != 0) {
789 if ( version == OSPF_VERSION_2)
790 offset = dissect_ospf_v2_lsa(tvb, offset, tree, FALSE);
792 if ( version == OSPF_VERSION_3)
793 offset = dissect_ospf_v3_lsa(tvb, offset, tree, FALSE);
799 dissect_ospf_ls_req(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
801 proto_tree *ospf_lsr_tree;
806 /* zero or more LS requests may be within a LS Request */
807 /* we place every request for a LSA in a single subtree */
808 while (tvb_reported_length_remaining(tvb, offset) != 0) {
809 ti = proto_tree_add_text(tree, tvb, offset, OSPF_LS_REQ_LENGTH,
810 "Link State Request");
811 ospf_lsr_tree = proto_item_add_subtree(ti, ett_ospf_lsr);
816 ls_type = tvb_get_ntohl(tvb, offset);
817 proto_tree_add_item(ospf_lsr_tree, ospf_filter[OSPFF_LS_TYPE],
818 tvb, offset, 4, FALSE);
821 reserved = tvb_get_ntohs(tvb, offset);
822 proto_tree_add_text(ospf_lsr_tree, tvb, offset, 2,
823 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"), reserved);
824 ls_type = tvb_get_ntohs(tvb, offset+2);
825 proto_tree_add_text(ospf_lsr_tree, tvb, offset+2, 2, "LS Type: %s (0x%04x)",
826 val_to_str(ls_type, v3_ls_type_vals, "Unknown"),
835 proto_tree_add_text(ospf_lsr_tree, tvb, offset + 4, 4, "Link State ID: %s",
836 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
837 proto_tree_add_item(ospf_lsr_tree, ospf_filter[OSPFF_ADV_ROUTER],
838 tvb, offset + 8, 4, FALSE);
845 dissect_ospf_ls_upd(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
847 proto_tree *ospf_lsa_upd_tree=NULL;
852 ti = proto_tree_add_text(tree, tvb, offset, -1, "LS Update Packet");
853 ospf_lsa_upd_tree = proto_item_add_subtree(ti, ett_ospf_lsa_upd);
855 lsa_nr = tvb_get_ntohl(tvb, offset);
856 proto_tree_add_text(ospf_lsa_upd_tree, tvb, offset, 4, "Number of LSAs: %u",
858 /* skip to the beginning of the first LSA */
859 offset += 4; /* the LS Upd Packet contains only a 32 bit #LSAs field */
862 while (lsa_counter < lsa_nr) {
863 if ( version == OSPF_VERSION_2)
864 offset = dissect_ospf_v2_lsa(tvb, offset, ospf_lsa_upd_tree, TRUE);
866 if ( version == OSPF_VERSION_3)
867 offset = dissect_ospf_v3_lsa(tvb, offset, ospf_lsa_upd_tree, TRUE);
873 dissect_ospf_ls_ack(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
875 /* the body of a LS Ack packet simply contains zero or more LSA Headers */
876 while (tvb_reported_length_remaining(tvb, offset) != 0) {
877 if ( version == OSPF_VERSION_2)
878 offset = dissect_ospf_v2_lsa(tvb, offset, tree, FALSE);
880 if ( version == OSPF_VERSION_3)
881 offset = dissect_ospf_v3_lsa(tvb, offset, tree, FALSE);
886 * Returns if an LSA is opaque, i.e. requires special treatment
889 is_opaque(int lsa_type)
891 return (lsa_type >= OSPF_LSTYPE_OP_LINKLOCAL &&
892 lsa_type <= OSPF_LSTYPE_OP_ASWIDE);
895 /* MPLS/TE TLV types */
896 #define MPLS_TLV_ROUTER 1
897 #define MPLS_TLV_LINK 2
899 /* MPLS/TE Link STLV types */
907 MPLS_LINK_MAX_RES_BW,
910 MPLS_LINK_LOCAL_ID = 11,
912 MPLS_LINK_PROTECTION = 14,
913 MPLS_LINK_IF_SWITCHING_DESC,
914 MPLS_LINK_SHARED_RISK_GROUP,
917 static const value_string mpls_link_stlv_str[] = {
918 {MPLS_LINK_TYPE, "Link Type"},
919 {MPLS_LINK_ID, "Link ID"},
920 {MPLS_LINK_LOCAL_IF, "Local Interface IP Address"},
921 {MPLS_LINK_REMOTE_IF, "Remote Interface IP Address"},
922 {MPLS_LINK_TE_METRIC, "Traffic Engineering Metric"},
923 {MPLS_LINK_MAX_BW, "Maximum Bandwidth"},
924 {MPLS_LINK_MAX_RES_BW, "Maximum Reservable Bandwidth"},
925 {MPLS_LINK_UNRES_BW, "Unreserved Bandwidth"},
926 {MPLS_LINK_COLOR, "Resource Class/Color"},
927 {MPLS_LINK_LOCAL_ID, "Link Local Identifier"},
928 {MPLS_LINK_REMOTE_ID, "Link Remote Identifier"},
929 {MPLS_LINK_PROTECTION, "Link Protection Type"},
930 {MPLS_LINK_IF_SWITCHING_DESC, "Interface Switching Capability Descriptor"},
931 {MPLS_LINK_SHARED_RISK_GROUP, "Shared Risk Link Group"},
936 * Dissect MPLS/TE opaque LSA
939 dissect_ospf_lsa_mpls(tvbuff_t *tvb, int offset, proto_tree *tree,
943 proto_tree *mpls_tree;
944 proto_tree *tlv_tree;
945 proto_tree *stlv_tree;
951 int stlv_type, stlv_len, stlv_offset;
955 ti = proto_tree_add_text(tree, tvb, offset, length,
956 "MPLS Traffic Engineering LSA");
957 proto_tree_add_item_hidden(tree, ospf_filter[OSPFF_LS_MPLS],
958 tvb, offset, 2, FALSE);
959 mpls_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls);
961 while (length != 0) {
962 tlv_type = tvb_get_ntohs(tvb, offset);
963 tlv_length = tvb_get_ntohs(tvb, offset + 2);
964 tlv_end_offset = offset + tlv_length + 4;
968 case MPLS_TLV_ROUTER:
969 ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
970 "Router Address: %s",
971 ip_to_str(tvb_get_ptr(tvb, offset+4, 4)));
972 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_router);
973 proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: 1 - Router Address");
974 proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
976 proto_tree_add_item(tlv_tree, ospf_filter[OSPFF_LS_MPLS_ROUTERID],
977 tvb, offset+4, 4, FALSE);
981 ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
983 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
984 proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: 2 - Link Information");
985 proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
987 stlv_offset = offset + 4;
989 /* Walk down the sub-TLVs for link information */
990 while (stlv_offset < tlv_end_offset) {
991 stlv_type = tvb_get_ntohs(tvb, stlv_offset);
992 stlv_len = tvb_get_ntohs(tvb, stlv_offset + 2);
993 stlv_name = val_to_str(stlv_type, mpls_link_stlv_str, "Unknown sub-TLV");
997 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
999 tvb_get_guint8(tvb, stlv_offset + 4));
1000 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1001 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1002 "TLV Type: %u: %s", stlv_type, stlv_name);
1003 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1005 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "%s: %u", stlv_name,
1006 tvb_get_guint8(tvb, stlv_offset + 4));
1010 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1011 "%s: %s (%x)", stlv_name,
1012 ip_to_str(tvb_get_ptr(tvb, stlv_offset + 4, 4)),
1013 tvb_get_ntohl(tvb, stlv_offset + 4));
1014 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1015 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1016 "TLV Type: %u: %s", stlv_type, stlv_name);
1017 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1019 proto_tree_add_item(stlv_tree, ospf_filter[OSPFF_LS_MPLS_LINKID],
1020 tvb, stlv_offset+4, 4, FALSE);
1023 case MPLS_LINK_LOCAL_IF:
1024 case MPLS_LINK_REMOTE_IF:
1025 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1027 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1028 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1029 "TLV Type: %u: %s", stlv_type, stlv_name);
1030 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1032 /* The Local/Remote Interface IP Address sub-TLV is TLV type 3/4, and is 4N
1033 octets in length, where N is the number of neighbor addresses. */
1034 for (i=0; i < stlv_len; i+=4)
1035 proto_tree_add_item(stlv_tree,
1036 stlv_type==MPLS_LINK_LOCAL_IF ?
1037 ospf_filter[OSPFF_LS_MPLS_LOCAL_ADDR] :
1038 ospf_filter[OSPFF_LS_MPLS_REMOTE_ADDR],
1039 tvb, stlv_offset+4+i, 4, FALSE);
1042 case MPLS_LINK_TE_METRIC:
1043 case MPLS_LINK_COLOR:
1044 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1045 "%s: %u", stlv_name,
1046 tvb_get_ntohl(tvb, stlv_offset + 4));
1047 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1048 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1049 "TLV Type: %u: %s", stlv_type, stlv_name);
1050 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1052 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %u", stlv_name,
1053 tvb_get_ntohl(tvb, stlv_offset + 4));
1056 case MPLS_LINK_MAX_BW:
1057 case MPLS_LINK_MAX_RES_BW:
1058 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1059 "%s: %.10g", stlv_name,
1060 tvb_get_ntohieee_float(tvb, stlv_offset + 4));
1061 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1062 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1063 "TLV Type: %u: %s", stlv_type, stlv_name);
1064 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1066 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %.10g", stlv_name,
1067 tvb_get_ntohieee_float(tvb, stlv_offset + 4));
1070 case MPLS_LINK_UNRES_BW:
1071 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1073 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1074 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1075 "TLV Type: %u: %s", stlv_type, stlv_name);
1076 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1078 for (i = 0; i < 8; i++) {
1079 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4+(i*4), 4,
1080 "Pri %d: %.10g bytes/s (%.0f bits/s)", i,
1081 tvb_get_ntohieee_float(tvb, stlv_offset + 4 + i*4),
1082 tvb_get_ntohieee_float(tvb, stlv_offset + 4 + i*4) * 8.0);
1086 case MPLS_LINK_LOCAL_ID:
1087 case MPLS_LINK_REMOTE_ID:
1088 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1089 "%s: %d (0x%x)", stlv_name,
1090 tvb_get_ntohl(tvb, stlv_offset + 4),
1091 tvb_get_ntohl(tvb, stlv_offset + 4));
1092 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1093 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1094 "TLV Type: %u: %s", stlv_type, stlv_name);
1095 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1097 proto_tree_add_item(stlv_tree,
1098 stlv_type==MPLS_LINK_LOCAL_ID ?
1099 ospf_filter[OSPFF_LS_MPLS_LOCAL_IFID] :
1100 ospf_filter[OSPFF_LS_MPLS_REMOTE_IFID],
1101 tvb, stlv_offset+4, 4, FALSE);
1104 case MPLS_LINK_IF_SWITCHING_DESC:
1105 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1107 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
1108 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
1109 "TLV Type: %u: %s", stlv_type, stlv_name);
1110 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
1112 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "Switching Type: %s",
1113 val_to_str(tvb_get_guint8(tvb,stlv_offset+4),
1114 gmpls_switching_type_str, "Unknown (%d)"));
1115 proto_tree_add_text(stlv_tree, tvb, stlv_offset+5, 1, "Encoding: %s",
1116 val_to_str(tvb_get_guint8(tvb,stlv_offset+5),
1117 gmpls_lsp_enc_str, "Unknown (%d)"));
1118 for (i = 0; i < 8; i++) {
1119 proto_tree_add_text(stlv_tree, tvb, stlv_offset+8+(i*4), 4,
1120 "Pri %d: %.10g bytes/s (%.0f bits/s)", i,
1121 tvb_get_ntohieee_float(tvb, stlv_offset + 8 + i*4),
1122 tvb_get_ntohieee_float(tvb, stlv_offset + 8 + i*4) * 8.0);
1127 proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
1128 "Unknown Link sub-TLV: %u", stlv_type);
1131 stlv_offset += ((stlv_len+4+3)/4)*4;
1136 ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
1137 "Unknown LSA: %u", tlv_type);
1138 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
1139 proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: %u - Unknown",
1141 proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
1143 proto_tree_add_text(tlv_tree, tvb, offset+4, tlv_length, "TLV Data");
1147 offset += tlv_length + 4;
1148 length -= tlv_length + 4;
1153 * Dissect opaque LSAs
1156 dissect_ospf_lsa_opaque(tvbuff_t *tvb, int offset, proto_tree *tree,
1157 guint8 ls_id_type, guint32 length)
1159 switch (ls_id_type) {
1161 case OSPF_LSA_MPLS_TE:
1162 dissect_ospf_lsa_mpls(tvb, offset, tree, length);
1166 proto_tree_add_text(tree, tvb, offset, length,
1167 "Unknown LSA Type %u", ls_id_type);
1169 } /* switch on opaque LSA id */
1173 dissect_ospf_v2_lsa(tvbuff_t *tvb, int offset, proto_tree *tree,
1174 gboolean disassemble_body)
1176 proto_tree *ospf_lsa_tree;
1187 guint16 link_counter;
1189 char *link_type_str;
1192 /* AS-external LSA */
1198 ls_type = tvb_get_guint8(tvb, offset + 3);
1199 ls_length = tvb_get_ntohs(tvb, offset + 18);
1200 end_offset = offset + ls_length;
1202 if (disassemble_body) {
1203 ti = proto_tree_add_text(tree, tvb, offset, ls_length,
1205 val_to_str(ls_type, ls_type_vals, "Unknown (%d)"));
1207 ti = proto_tree_add_text(tree, tvb, offset, OSPF_LSA_HEADER_LENGTH,
1210 ospf_lsa_tree = proto_item_add_subtree(ti, ett_ospf_lsa);
1212 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "LS Age: %u seconds",
1213 tvb_get_ntohs(tvb, offset));
1214 dissect_ospf_options(tvb, offset + 2, ospf_lsa_tree, OSPF_VERSION_2);
1215 proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_LS_TYPE], tvb,
1216 offset + 3, 1, FALSE);
1217 proto_tree_add_item_hidden(ospf_lsa_tree,
1218 ospf_filter[ospf_ls_type_to_filter(ls_type)], tvb,
1219 offset + 3, 1, FALSE);
1221 if (is_opaque(ls_type)) {
1222 ls_id_type = tvb_get_guint8(tvb, offset + 4);
1223 proto_tree_add_uint(ospf_lsa_tree, ospf_filter[OSPFF_LS_OPAQUE_TYPE],
1224 tvb, offset + 4, 1, ls_id_type);
1226 switch (ls_id_type) {
1228 case OSPF_LSA_MPLS_TE:
1229 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 5, 1, "Link State ID TE-LSA Reserved: %u",
1230 tvb_get_guint8(tvb, offset + 5));
1231 proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_LS_MPLS_TE_INSTANCE],
1232 tvb, offset + 6, 2, FALSE);
1236 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 5, 3, "Link State ID Opaque ID: %u",
1237 tvb_get_ntoh24(tvb, offset + 5));
1242 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link State ID: %s",
1243 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1246 proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_ADV_ROUTER],
1247 tvb, offset + 8, 4, FALSE);
1248 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "LS Sequence Number: 0x%04x",
1249 tvb_get_ntohl(tvb, offset + 12));
1250 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 16, 2, "LS Checksum: %04x",
1251 tvb_get_ntohs(tvb, offset + 16));
1253 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 18, 2, "Length: %u",
1256 /* skip past the LSA header to the body */
1257 offset += OSPF_LSA_HEADER_LENGTH;
1258 if (ls_length <= OSPF_LSA_HEADER_LENGTH)
1259 return offset; /* no data, or bogus length */
1260 ls_length -= OSPF_LSA_HEADER_LENGTH;
1262 if (!disassemble_body)
1267 case OSPF_LSTYPE_ROUTER:
1268 /* again: flags should be secified in detail */
1269 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x",
1270 tvb_get_guint8(tvb, offset));
1271 nr_links = tvb_get_ntohs(tvb, offset + 2);
1272 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2, "Number of Links: %u",
1275 /* nr_links links follow
1276 * maybe we should put each of the links into its own subtree ???
1278 for (link_counter = 1; link_counter <= nr_links; link_counter++) {
1279 /* check the Link Type and ID */
1280 link_type = tvb_get_guint8(tvb, offset + 8);
1281 switch (link_type) {
1284 link_type_str="Point-to-point connection to another router";
1285 link_id="Neighboring router's Router ID";
1288 case OSPF_LINK_TRANSIT:
1289 link_type_str="Connection to a transit network";
1290 link_id="IP address of Designated Router";
1293 case OSPF_LINK_STUB:
1294 link_type_str="Connection to a stub network";
1295 link_id="IP network/subnet number";
1298 case OSPF_LINK_VIRTUAL:
1299 link_type_str="Virtual link";
1300 link_id="Neighboring router's Router ID";
1304 link_type_str="Unknown link type";
1305 link_id="Unknown link ID";
1309 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "%s: %s", link_id,
1310 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1312 /* link_data should be specified in detail (e.g. network mask) (depends on link type)*/
1313 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link Data: %s",
1314 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1316 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 1, "Link Type: %u - %s",
1317 link_type, link_type_str);
1318 nr_tos = tvb_get_guint8(tvb, offset + 9);
1319 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 9, 1, "Number of TOS metrics: %u",
1321 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 10, 2, "TOS 0 metric: %u",
1322 tvb_get_ntohs(tvb, offset + 10));
1326 /* nr_tos metrics may follow each link
1327 * ATTENTION: TOS metrics are not tested (I don't have TOS
1329 * please send me a mail if it is/isn't working
1331 for (tos_counter = 1; tos_counter <= nr_tos; tos_counter++) {
1332 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1333 tvb_get_guint8(tvb, offset),
1334 tvb_get_ntohs(tvb, offset + 2));
1340 case OSPF_LSTYPE_NETWORK:
1341 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
1342 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1345 while (offset < end_offset) {
1346 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Attached Router: %s",
1347 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1352 case OSPF_LSTYPE_SUMMERY:
1353 /* Type 3 and 4 LSAs have the same format */
1354 case OSPF_LSTYPE_ASBR:
1355 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
1356 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1359 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Metric: %u",
1360 tvb_get_ntoh24(tvb, offset + 1));
1363 /* TOS-specific information, if any */
1364 while (offset < end_offset) {
1365 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1366 tvb_get_guint8(tvb, offset),
1367 tvb_get_ntoh24(tvb, offset + 1));
1372 case OSPF_LSTYPE_ASEXT:
1373 case OSPF_LSTYPE_ASEXT7:
1374 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
1375 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1378 options = tvb_get_guint8(tvb, offset);
1379 if (options & 0x80) { /* check wether or not E bit is set */
1380 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1381 "External Type: Type 2 (metric is larger than any other link state path)");
1383 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1384 "External Type: Type 1 (metric is specified in the same units as interface cost)");
1386 /* the metric field of a AS-external LAS is specified in 3 bytes */
1387 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 1, 3, "Metric: %u",
1388 tvb_get_ntoh24(tvb, offset + 1));
1391 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Forwarding Address: %s",
1392 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1395 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "External Route Tag: %u",
1396 tvb_get_ntohl(tvb, offset));
1399 /* TOS-specific information, if any */
1400 while (offset < end_offset) {
1401 options = tvb_get_guint8(tvb, offset);
1402 if (options & 0x80) { /* check wether or not E bit is set */
1403 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1404 "External Type: Type 2 (metric is larger than any other link state path)");
1406 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1407 "External Type: Type 1 (metric is specified in the same units as interface cost)");
1409 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1411 tvb_get_ntoh24(tvb, offset + 1));
1414 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Forwarding Address: %s",
1415 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1418 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "External Route Tag: %u",
1419 tvb_get_ntohl(tvb, offset));
1424 case OSPF_LSTYPE_OP_LINKLOCAL:
1425 case OSPF_LSTYPE_OP_AREALOCAL:
1426 case OSPF_LSTYPE_OP_ASWIDE:
1428 * RFC 2370 opaque LSAs.
1430 dissect_ospf_lsa_opaque(tvb, offset, ospf_lsa_tree, ls_id_type,
1432 offset += ls_length;
1436 /* unknown LSA type */
1437 proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1438 "Unknown LSA Type");
1439 offset += ls_length;
1442 /* return the offset of the next LSA */
1447 dissect_ospf_v3_lsa(tvbuff_t *tvb, int offset, proto_tree *tree,
1448 gboolean disassemble_body)
1450 proto_tree *ospf_lsa_tree;
1460 char *link_type_str;
1463 guint8 router_lsa_flags;
1464 char router_lsa_flags_string[5];
1466 guint8 router_priority;
1467 guint32 number_prefixes;
1468 guint8 prefix_length;
1471 guint16 referenced_ls_type;
1474 guint8 flags_string[4];
1475 guint32 external_route_tag;
1478 ls_type = tvb_get_ntohs(tvb, offset + 2);
1479 ls_length = tvb_get_ntohs(tvb, offset + 18);
1480 end_offset = offset + ls_length;
1482 if (disassemble_body) {
1483 ti = proto_tree_add_text(tree, tvb, offset, ls_length,
1484 "%s (Type: 0x%04x)", val_to_str(ls_type, v3_ls_type_vals,"Unknown"), ls_type);
1486 ti = proto_tree_add_text(tree, tvb, offset, OSPF_LSA_HEADER_LENGTH,
1489 ospf_lsa_tree = proto_item_add_subtree(ti, ett_ospf_lsa);
1491 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "LS Age: %u seconds",
1492 tvb_get_ntohs(tvb, offset));
1494 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2, "LSA Type: 0x%04x (%s)",
1495 ls_type, val_to_str(ls_type, v3_ls_type_vals,"Unkown"));
1497 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link State ID: %s",
1498 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1500 proto_tree_add_item(ospf_lsa_tree, ospf_filter[OSPFF_ADV_ROUTER],
1501 tvb, offset + 8, 4, FALSE);
1502 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "LS Sequence Number: %d",
1503 tvb_get_ntohl(tvb, offset + 12));
1504 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 16, 2, "LS Checksum: %04x",
1505 tvb_get_ntohs(tvb, offset + 16));
1507 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 18, 2, "Length: %u",
1510 /* skip past the LSA header to the body */
1511 offset += OSPF_LSA_HEADER_LENGTH;
1512 ls_length -= OSPF_LSA_HEADER_LENGTH;
1514 if (!disassemble_body)
1520 case OSPF_V3_LSTYPE_ROUTER:
1522 /* flags field in an router-lsa */
1523 router_lsa_flags=tvb_get_guint8(tvb,offset);
1524 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_B)
1525 router_lsa_flags_string[3] = 'B';
1527 router_lsa_flags_string[3] = '.';
1528 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_E)
1529 router_lsa_flags_string[2] = 'E';
1531 router_lsa_flags_string[2] = '.';
1532 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_V)
1533 router_lsa_flags_string[1] = 'V';
1535 router_lsa_flags_string[1] = '.';
1536 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_W)
1537 router_lsa_flags_string[0] = 'W';
1539 router_lsa_flags_string[0] = '.';
1541 router_lsa_flags_string[4]=0;
1543 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x (%s)",
1544 router_lsa_flags, router_lsa_flags_string);
1546 /* options field in an router-lsa */
1547 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1549 /* skip the router-lsa flags and options */
1554 proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1555 "Router Interfaces:");
1557 /* scan all router-lsa router interfaces */
1558 /* maybe we should put each of the links into its own subtree ??? */
1559 while (ls_length > 0 ) {
1561 /* check the type */
1562 link_type = tvb_get_guint8(tvb, offset);
1563 switch (link_type) {
1565 case OSPF_V3_LINK_PTP:
1566 link_type_str="Point-to-point connection to another router";
1569 case OSPF_V3_LINK_TRANSIT:
1570 link_type_str="Connection to a transit network";
1573 case OSPF_V3_LINK_RESERVED:
1574 link_type_str="Connection to a stub network";
1577 case OSPF_V3_LINK_VIRTUAL:
1578 link_type_str="Virtual link";
1582 link_type_str="Unknown link type";
1586 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Type: %u (%s)", link_type,link_type_str);
1588 /* reserved field */
1589 reserved = tvb_get_guint8(tvb, offset+1);
1590 proto_tree_add_text(ospf_lsa_tree, tvb, offset+1, 1,
1591 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1594 metric=tvb_get_ntohs(tvb, offset+2);
1595 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2,"Metric: %u",metric);
1598 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Interface ID: %u",
1599 tvb_get_ntohl(tvb, offset + 4));
1601 /* Neighbor Interface ID */
1602 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Neighbor Interface ID: %u",
1603 tvb_get_ntohl(tvb, offset + 8));
1605 /* Neighbor Router ID */
1606 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "Neighbor Router ID: %s",
1607 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
1609 /* skip to the (possible) next entry */
1616 case OSPF_V3_LSTYPE_NETWORK:
1618 /* reserved field */
1619 reserved = tvb_get_guint8(tvb, offset);
1620 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1621 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1623 /* options field in an network-lsa */
1624 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1629 while (ls_length > 0 ) {
1630 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Attached Router: %s",
1631 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1638 case OSPF_V3_LSTYPE_INTER_AREA_PREFIX:
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);
1646 metric=tvb_get_ntoh24(tvb, offset+11);
1647 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 1, 3,"Metric: %u",metric);
1650 prefix_length=tvb_get_guint8(tvb, offset+4);
1651 proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1, "PrefixLength: %u",prefix_length);
1653 /* prefix options */
1654 dissect_ospf_v3_prefix_options(tvb, offset+5, ospf_lsa_tree);
1656 /* 16 bits reserved */
1657 reserved16=tvb_get_ntohs(tvb, offset+6);
1658 proto_tree_add_text(ospf_lsa_tree, tvb, offset+6, 2,
1659 (reserved16 == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved16);
1663 /* address_prefix */
1664 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1666 offset+=(prefix_length+31)/32*4;
1671 case OSPF_V3_LSTYPE_INTER_AREA_ROUTER:
1673 /* reserved field */
1674 reserved = tvb_get_guint8(tvb, offset);
1675 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1676 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1678 /* options field in an inter-area-router-lsa */
1679 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1681 /* reserved field */
1682 reserved = tvb_get_guint8(tvb, offset+4);
1683 proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1,
1684 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1687 metric=tvb_get_ntoh24(tvb, offset+6);
1688 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 6, 3,"Metric: %u",metric);
1690 /* Destination Router ID */
1691 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Destination Router ID: %s",
1692 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
1698 case OSPF_V3_LSTYPE_AS_EXTERNAL:
1701 flags=tvb_get_guint8(tvb, offset);
1702 if (flags & OSPF_V3_AS_EXTERNAL_FLAG_E)
1703 flags_string[0] = 'E';
1705 flags_string[0] = '.';
1706 if (flags & OSPF_V3_AS_EXTERNAL_FLAG_F)
1707 flags_string[1] = 'F';
1709 flags_string[1] = '.';
1710 if (flags & OSPF_V3_AS_EXTERNAL_FLAG_T)
1711 flags_string[2] = 'T';
1713 flags_string[2] = '.';
1717 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x (%s)",
1718 flags, flags_string);
1720 /* 24 bits metric */
1721 metric=tvb_get_ntoh24(tvb, offset+1);
1722 proto_tree_add_text(ospf_lsa_tree, tvb, offset+1, 3,
1723 "Metric: %u", metric);
1726 prefix_length=tvb_get_guint8(tvb, offset+4);
1727 proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1, "PrefixLength: %u",prefix_length);
1729 /* prefix options */
1730 dissect_ospf_v3_prefix_options(tvb, offset+5, ospf_lsa_tree);
1732 /* referenced LS type */
1733 referenced_ls_type=tvb_get_ntohs(tvb, offset+6);
1734 proto_tree_add_text(ospf_lsa_tree, tvb, offset+6, 2,"Referenced LS type 0x%04x (%s)",
1735 referenced_ls_type, val_to_str(referenced_ls_type, v3_ls_type_vals, "Unknown"));
1739 /* address_prefix */
1740 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1742 offset+=(prefix_length+31)/32*4;
1744 /* Forwarding Address (optional - only if F-flag is on) */
1745 if ( (offset < end_offset) && (flags & OSPF_V3_AS_EXTERNAL_FLAG_F) ) {
1746 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 16,"Forwarding Address: %s",
1747 ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset, 16)));
1752 /* External Route Tag (optional - only if T-flag is on) */
1753 if ( (offset < end_offset) && (flags & OSPF_V3_AS_EXTERNAL_FLAG_T) ) {
1754 external_route_tag=tvb_get_ntohl(tvb, offset);
1755 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4,"External Route Tag: 0x%04x",
1756 external_route_tag);
1761 /* Referenced Link State ID (optional - only if Referenced LS type is non-zero */
1762 if ( (offset < end_offset) && (referenced_ls_type != 0) ) {
1763 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Referenced Link State ID: %s",
1764 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1770 case OSPF_V3_LSTYPE_LINK:
1772 /* router priority */
1773 router_priority=tvb_get_guint8(tvb, offset);
1774 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Router Priority: %u", router_priority);
1776 /* options field in an link-lsa */
1777 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1779 /* Link-local Interface Address */
1780 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 16, "Link-local Interface Address: %s",
1781 ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, 16)));
1783 /* Number prefixes */
1784 number_prefixes=tvb_get_ntohl(tvb, offset + 20);
1785 proto_tree_add_text(ospf_lsa_tree, tvb, offset+20, 4, "# prefixes: %d",number_prefixes);
1789 while (number_prefixes > 0) {
1792 prefix_length=tvb_get_guint8(tvb, offset);
1793 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "PrefixLength: %u",prefix_length);
1795 /* prefix options */
1796 dissect_ospf_v3_prefix_options(tvb, offset+1, ospf_lsa_tree);
1798 /* 16 bits reserved */
1799 reserved16=tvb_get_ntohs(tvb, offset+2);
1800 proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,
1801 (reserved16 == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved16);
1805 /* address_prefix */
1806 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1808 offset+=(prefix_length+31)/32*4;
1815 case OSPF_V3_LSTYPE_INTRA_AREA_PREFIX:
1818 number_prefixes=tvb_get_ntohs(tvb, offset);
1819 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2,"# prefixes: %u",number_prefixes);
1821 /* referenced LS type */
1822 referenced_ls_type=tvb_get_ntohs(tvb, offset+2);
1823 proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,"Referenced LS type 0x%04x (%s)",
1824 referenced_ls_type, val_to_str(referenced_ls_type, v3_ls_type_vals, "Unknown"));
1826 /* Referenced Link State ID */
1827 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Referenced Link State ID: %s",
1828 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1830 /* Referenced Advertising Router */
1831 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Referenced Advertising Router: %s",
1832 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
1836 while (number_prefixes > 0) {
1839 prefix_length=tvb_get_guint8(tvb, offset);
1840 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "PrefixLength: %u",prefix_length);
1842 /* prefix options */
1843 dissect_ospf_v3_prefix_options(tvb, offset+1, ospf_lsa_tree);
1845 /* 16 bits metric */
1846 metric=tvb_get_ntohs(tvb, offset+2);
1847 proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,
1848 "Metric: %u", metric);
1852 /* address_prefix */
1853 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1855 offset+=(prefix_length+31)/32*4;
1862 /* unknown LSA type */
1863 proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1864 "Unknown LSA Type 0x%04x",ls_type);
1865 offset += ls_length;
1868 /* return the offset of the next LSA */
1874 dissect_ospf_options(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
1876 guint8 options_ospfv2;
1877 guint32 options_ospfv3;
1878 char options_string[20] = "";
1880 /* ATTENTION !!! no check for length of options string - with OSPFv3 maximum length is 14 characters */
1882 switch ( version ) {
1884 case OSPF_VERSION_2:
1886 options_ospfv2 = tvb_get_guint8(tvb, offset);
1888 if (options_ospfv2 & OSPF_V2_OPTIONS_E)
1889 strcat(options_string, "E");
1891 if (options_ospfv2 & OSPF_V2_OPTIONS_MC) {
1892 if (options_string[0] != '\0')
1893 strcat(options_string, "/");
1894 strcat(options_string, "MC");
1897 if (options_ospfv2 & OSPF_V2_OPTIONS_NP) {
1898 if (options_string[0] != '\0')
1899 strcat(options_string, "/");
1900 strcat(options_string, "NP");
1903 if (options_ospfv2 & OSPF_V2_OPTIONS_EA) {
1904 if (options_string[0] != '\0')
1905 strcat(options_string, "/");
1906 strcat(options_string, "EA");
1909 if (options_ospfv2 & OSPF_V2_OPTIONS_DC) {
1910 if (options_string[0] != '\0')
1911 strcat(options_string, "/");
1912 strcat(options_string, "DC");
1915 if (options_ospfv2 & OSPF_V2_OPTIONS_O) {
1916 if (options_string[0] != '\0')
1917 strcat(options_string, "/");
1918 strcat(options_string, "O");
1921 if (options_ospfv2 & OSPF_V2_OPTIONS_DN) {
1922 if (options_string[0] != '\0')
1923 strcat(options_string, "/");
1924 strcat(options_string, "DN");
1927 proto_tree_add_text(tree, tvb, offset, 1, "Options: 0x%x (%s)",
1928 options_ospfv2, options_string);
1932 case OSPF_VERSION_3:
1934 options_ospfv3 = tvb_get_ntoh24(tvb, offset);
1936 if (options_ospfv3 & OSPF_V3_OPTIONS_V6)
1937 strcat(options_string, "V6");
1939 if (options_ospfv3 & OSPF_V3_OPTIONS_E)
1940 if (options_string[0] != '\0')
1941 strcat(options_string, "/");
1942 strcat(options_string, "E");
1944 if (options_ospfv3 & OSPF_V3_OPTIONS_MC) {
1945 if (options_string[0] != '\0')
1946 strcat(options_string, "/");
1947 strcat(options_string, "MC");
1950 if (options_ospfv3 & OSPF_V3_OPTIONS_N) {
1951 if (options_string[0] != '\0')
1952 strcat(options_string, "/");
1953 strcat(options_string, "N");
1956 if (options_ospfv3 & OSPF_V3_OPTIONS_R) {
1957 if (options_string[0] != '\0')
1958 strcat(options_string, "/");
1959 strcat(options_string, "R");
1962 if (options_ospfv3 & OSPF_V3_OPTIONS_DC) {
1963 if (options_string[0] != '\0')
1964 strcat(options_string, "/");
1965 strcat(options_string, "DC");
1968 proto_tree_add_text(tree, tvb, offset, 3, "Options: 0x%x (%s)",
1969 options_ospfv3, options_string);
1979 static void dissect_ospf_v3_prefix_options(tvbuff_t *tvb, int offset, proto_tree *tree)
1982 guint8 prefix_options;
1983 char prefix_options_string[11];
1988 prefix_options=tvb_get_guint8(tvb, offset);
1990 strcpy(prefix_options_string,"");
1992 if (prefix_options & OSPF_V3_PREFIX_OPTION_P) {
1993 strcat(prefix_options_string, "P");
1997 if (prefix_options & OSPF_V3_PREFIX_OPTION_MC) {
1998 if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
1999 strcat(prefix_options_string, "/");
2002 strcat(prefix_options_string, "MC");
2006 if (prefix_options & OSPF_V3_PREFIX_OPTION_LA) {
2007 if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
2008 strcat(prefix_options_string, "/");
2011 strcat(prefix_options_string, "LA");
2015 if (prefix_options & OSPF_V3_PREFIX_OPTION_NU) {
2016 if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
2017 strcat(prefix_options_string, "/");
2020 strcat(prefix_options_string, "NU");
2023 prefix_options_string[10]=0;
2025 proto_tree_add_text(tree, tvb, offset, 1, "PrefixOptions: 0x%02x (%s)",prefix_options, prefix_options_string);
2030 static void dissect_ospf_v3_address_prefix(tvbuff_t *tvb, int offset, int prefix_length, proto_tree *tree)
2038 guint8 bytes_to_process;
2041 start_offset=offset;
2044 bytes_to_process=((prefix_length+31)/32)*4;
2046 while (bytes_to_process > 0 ) {
2048 value=tvb_get_guint8(tvb, offset);
2050 if ( (position > 0) && ( (position%2) == 0 ) )
2051 buffer[bufpos++]=':';
2053 sprintf(bytebuf,"%02x",value);
2054 buffer[bufpos++]=bytebuf[0];
2055 buffer[bufpos++]=bytebuf[1];
2063 proto_tree_add_text(tree, tvb, start_offset, ((prefix_length+31)/32)*4, "Address Prefix: %s",buffer);
2069 proto_register_ospf(void)
2071 static gint *ett[] = {
2080 &ett_ospf_lsa_mpls_router,
2081 &ett_ospf_lsa_mpls_link,
2082 &ett_ospf_lsa_mpls_link_stlv
2085 proto_ospf = proto_register_protocol("Open Shortest Path First",
2087 proto_register_field_array(proto_ospf, ospff_info, array_length(ospff_info));
2088 proto_register_subtree_array(ett, array_length(ett));
2092 proto_reg_handoff_ospf(void)
2094 dissector_handle_t ospf_handle;
2096 ospf_handle = create_dissector_handle(dissect_ospf, proto_ospf);
2097 dissector_add("ip.proto", IP_PROTO_OSPF, ospf_handle);
2098 data_handle = find_dissector("data");