2 * Routines for OSPF packet disassembly
3 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
5 * $Id: packet-ospf.c,v 1.46 2001/09/14 06:30:42 guy 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.
39 #ifdef HAVE_SYS_TYPES_H
40 # include <sys/types.h>
43 #ifdef HAVE_NETINET_IN_H
44 # include <netinet/in.h>
54 #include "ieee-float.h"
56 #define OSPF_VERSION_2 2
57 #define OSPF_VERSION_3 3
58 #define OSPF_VERSION_2_HEADER_LENGTH 24
59 #define OSPF_VERSION_3_HEADER_LENGTH 16
63 #define OSPF_DB_DESC 2
68 static const value_string pt_vals[] = {
69 {OSPF_HELLO, "Hello Packet" },
70 {OSPF_DB_DESC, "DB Descr." },
71 {OSPF_LS_REQ, "LS Request" },
72 {OSPF_LS_UPD, "LS Update" },
73 {OSPF_LS_ACK, "LS Acknowledge" },
77 #define OSPF_AUTH_NONE 0
78 #define OSPF_AUTH_SIMPLE 1
79 #define OSPF_AUTH_CRYPT 2
81 static const value_string auth_vals[] = {
82 {OSPF_AUTH_NONE, "Null" },
83 {OSPF_AUTH_SIMPLE, "Simple password" },
84 {OSPF_AUTH_CRYPT, "Cryptographic" },
88 #define OSPF_V2_OPTIONS_E 0x02
89 #define OSPF_V2_OPTIONS_MC 0x04
90 #define OSPF_V2_OPTIONS_NP 0x08
91 #define OSPF_V2_OPTIONS_EA 0x10
92 #define OSPF_V2_OPTIONS_DC 0x20
93 #define OSPF_V2_OPTIONS_O 0x40
94 #define OSPF_V2_OPTIONS_DN 0x01
95 #define OSPF_V3_OPTIONS_V6 0x01
96 #define OSPF_V3_OPTIONS_E 0x02
97 #define OSPF_V3_OPTIONS_MC 0x04
98 #define OSPF_V3_OPTIONS_N 0x08
99 #define OSPF_V3_OPTIONS_R 0x10
100 #define OSPF_V3_OPTIONS_DC 0x20
103 #define OSPF_DBD_FLAG_MS 1
104 #define OSPF_DBD_FLAG_M 2
105 #define OSPF_DBD_FLAG_I 4
107 #define OSPF_LS_REQ_LENGTH 12
109 #define OSPF_LSTYPE_ROUTER 1
110 #define OSPF_LSTYPE_NETWORK 2
111 #define OSPF_LSTYPE_SUMMERY 3
112 #define OSPF_LSTYPE_ASBR 4
113 #define OSPF_LSTYPE_ASEXT 5
114 #define OSPF_LSTYPE_GRPMEMBER 6
115 #define OSPF_LSTYPE_ASEXT7 7
116 #define OSPF_LSTYPE_EXTATTR 8
117 #define OSPF_V3_LSTYPE_ROUTER 0x2001
118 #define OSPF_V3_LSTYPE_NETWORK 0x2002
119 #define OSPF_V3_LSTYPE_INTER_AREA_PREFIX 0x2003
120 #define OSPF_V3_LSTYPE_INTER_AREA_ROUTER 0x2004
121 #define OSPF_V3_LSTYPE_AS_EXTERNAL 0x4005
122 #define OSPF_V3_LSTYPE_GROUP_MEMBERSHIP 0x2006
123 #define OSPF_V3_LSTYPE_TYPE_7 0x2007
124 #define OSPF_V3_LSTYPE_LINK 0x0008
125 #define OSPF_V3_LSTYPE_INTRA_AREA_PREFIX 0x2009
127 /* Opaque LSA types */
128 #define OSPF_LSTYPE_OP_LINKLOCAL 9
129 #define OSPF_LSTYPE_OP_AREALOCAL 10
130 #define OSPF_LSTYPE_OP_ASWIDE 11
132 #define OSPF_LINK_PTP 1
133 #define OSPF_LINK_TRANSIT 2
134 #define OSPF_LINK_STUB 3
135 #define OSPF_LINK_VIRTUAL 4
137 #define OSPF_V3_LINK_PTP 1
138 #define OSPF_V3_LINK_TRANSIT 2
139 #define OSPF_V3_LINK_RESERVED 3
140 #define OSPF_V3_LINK_VIRTUAL 4
142 #define OSPF_LSA_HEADER_LENGTH 20
144 /* Known opaque LSAs */
145 #define OSPF_LSA_MPLS_TE 1
148 static const value_string ls_type_vals[] = {
149 {OSPF_LSTYPE_ROUTER, "Router-LSA" },
150 {OSPF_LSTYPE_NETWORK, "Network-LSA" },
151 {OSPF_LSTYPE_SUMMERY, "Summary-LSA (IP network)" },
152 {OSPF_LSTYPE_ASBR, "Summary-LSA (ASBR)" },
153 {OSPF_LSTYPE_ASEXT, "AS-External-LSA (ASBR)" },
154 {OSPF_LSTYPE_GRPMEMBER, "Group Membership LSA" },
155 {OSPF_LSTYPE_ASEXT7, "NSSA AS-External-LSA" },
156 {OSPF_LSTYPE_EXTATTR, "External Attributes LSA" },
157 {OSPF_LSTYPE_OP_LINKLOCAL, "Opaque LSA, Link-local scope" },
158 {OSPF_LSTYPE_OP_AREALOCAL, "Opaque LSA, Area-local scope" },
163 static const value_string v3_ls_type_vals[] = {
164 {OSPF_V3_LSTYPE_ROUTER, "Router-LSA" },
165 {OSPF_V3_LSTYPE_NETWORK, "Network-LSA" },
166 {OSPF_V3_LSTYPE_INTER_AREA_PREFIX, "Inter-Area-Prefix-LSA" },
167 {OSPF_V3_LSTYPE_INTER_AREA_ROUTER, "Inter-Area-Router-LSA" },
168 {OSPF_V3_LSTYPE_AS_EXTERNAL, "AS-External-LSA" },
169 {OSPF_V3_LSTYPE_GROUP_MEMBERSHIP, "Group-Membership-LSA" },
170 {OSPF_V3_LSTYPE_TYPE_7, "Type-LSA" },
171 {OSPF_V3_LSTYPE_LINK, "Link-LSA" },
172 {OSPF_V3_LSTYPE_INTRA_AREA_PREFIX, "Intra-Area-Prefix-LSA" },
178 #define OSPF_V3_ROUTER_LSA_FLAG_B 0x01
179 #define OSPF_V3_ROUTER_LSA_FLAG_E 0x02
180 #define OSPF_V3_ROUTER_LSA_FLAG_V 0x04
181 #define OSPF_V3_ROUTER_LSA_FLAG_W 0x08
183 #define OSPF_V3_PREFIX_OPTION_NU 0x01
184 #define OSPF_V3_PREFIX_OPTION_LA 0x02
185 #define OSPF_V3_PREFIX_OPTION_MC 0x04
186 #define OSPF_V3_PREFIX_OPTION_P 0x08
188 #define OSPF_V3_AS_EXTERNAL_FLAG_T 0x01
189 #define OSPF_V3_AS_EXTERNAL_FLAG_F 0x02
190 #define OSPF_V3_AS_EXTERNAL_FLAG_E 0x04
193 static int proto_ospf = -1;
195 static gint ett_ospf = -1;
196 static gint ett_ospf_hdr = -1;
197 static gint ett_ospf_hello = -1;
198 static gint ett_ospf_desc = -1;
199 static gint ett_ospf_lsr = -1;
200 static gint ett_ospf_lsa = -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 static void dissect_ospf_hello(tvbuff_t*, int, proto_tree*, guint8);
210 static void dissect_ospf_db_desc(tvbuff_t*, int, proto_tree*, guint8);
211 static void dissect_ospf_ls_req(tvbuff_t*, int, proto_tree*, guint8);
212 static void dissect_ospf_ls_upd(tvbuff_t*, int, proto_tree*, guint8);
213 static void dissect_ospf_ls_ack(tvbuff_t*, int, proto_tree*, guint8);
215 /* dissect_ospf_v[23]lsa returns the offset of the next LSA
216 * if disassemble_body is set to FALSE (e.g. in LSA ACK
217 * packets), the offset is set to the offset of the next
220 static int dissect_ospf_v2_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body);
221 static int dissect_ospf_v3_lsa(tvbuff_t*, int, proto_tree*, gboolean disassemble_body);
223 static void dissect_ospf_options(tvbuff_t *, int, proto_tree *, guint8);
225 static void dissect_ospf_v3_prefix_options(tvbuff_t *, int, proto_tree *);
227 static void dissect_ospf_v3_address_prefix(tvbuff_t *, int, int, proto_tree *);
230 dissect_ospf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
232 proto_tree *ospf_tree = NULL;
234 proto_tree *ospf_header_tree;
240 guint16 cksum, computed_cksum;
241 guint length, reported_length;
245 unsigned int ospf_header_length;
251 if (check_col(pinfo->fd, COL_PROTOCOL))
252 col_set_str(pinfo->fd, COL_PROTOCOL, "OSPF");
253 if (check_col(pinfo->fd, COL_INFO))
254 col_clear(pinfo->fd, COL_INFO);
256 version = tvb_get_guint8(tvb, 0);
259 ospf_header_length = OSPF_VERSION_2_HEADER_LENGTH;
262 ospf_header_length = OSPF_VERSION_3_HEADER_LENGTH;
265 ospf_header_length = 0;
269 packet_type = tvb_get_guint8(tvb, 1);
270 if (check_col(pinfo->fd, COL_INFO)) {
271 col_add_str(pinfo->fd, COL_INFO,
272 val_to_str(packet_type, pt_vals, "Unknown (%u)"));
276 ospflen = tvb_get_ntohs(tvb, 2);
278 ti = proto_tree_add_item(tree, proto_ospf, tvb, 0, ospflen, FALSE);
279 ospf_tree = proto_item_add_subtree(ti, ett_ospf);
281 ti = proto_tree_add_text(ospf_tree, tvb, 0, ospf_header_length,
283 ospf_header_tree = proto_item_add_subtree(ti, ett_ospf_hdr);
285 proto_tree_add_text(ospf_header_tree, tvb, 0, 1, "OSPF Version: %u",
287 proto_tree_add_text(ospf_header_tree, tvb, 1, 1, "OSPF Packet Type: %u (%s)",
289 val_to_str(packet_type, pt_vals, "Unknown"));
290 proto_tree_add_text(ospf_header_tree, tvb, 2, 2, "Packet Length: %u",
292 proto_tree_add_text(ospf_header_tree, tvb, 4, 4, "Source OSPF Router ID: %s",
293 ip_to_str(tvb_get_ptr(tvb, 4, 4)));
294 areaid=tvb_get_ntohl(tvb,8);
295 proto_tree_add_text(ospf_header_tree, tvb, 8, 4, "Area ID: %s%s",
296 ip_to_str(tvb_get_ptr(tvb, 8, 4)), areaid == 0 ? " (Backbone)" : "");
297 cksum = tvb_get_ntohs(tvb, 12);
298 length = tvb_length(tvb);
299 /* XXX - include only the length from the OSPF header? */
300 reported_length = tvb_reported_length(tvb);
301 if (!pinfo->fragmented && length >= reported_length
302 && length >= ospf_header_length) {
303 /* The packet isn't part of a fragmented datagram and isn't
304 truncated, so we can checksum it. */
306 /* Header, not including the authentication data (the OSPF
307 checksum excludes the 64-bit authentication field (which is an OSPFv2-only field)). */
308 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, 16);
309 cksum_vec[0].len = 16;
310 if (length > ospf_header_length) {
311 /* Rest of the packet, again not including the
312 authentication data. */
313 reported_length -= ospf_header_length;
314 cksum_vec[1].ptr = tvb_get_ptr(tvb, ospf_header_length, reported_length);
315 cksum_vec[1].len = reported_length;
318 /* There's nothing but a header. */
321 computed_cksum = in_cksum(cksum_vec, cksum_vec_len);
322 if (computed_cksum == 0) {
323 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
324 "Packet Checksum: 0x%04x (correct)", cksum);
326 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
327 "Packet Checksum: 0x%04x (incorrect, should be 0x%04x)",
328 cksum, in_cksum_shouldbe(cksum, computed_cksum));
331 proto_tree_add_text(ospf_header_tree, tvb, 12, 2,
332 "Packet Checksum: 0x%04x", cksum);
336 /* Authentication is only valid for OSPFv2 */
337 if ( version == OSPF_VERSION_2 ) {
338 auth_type = tvb_get_ntohs(tvb, 14);
339 proto_tree_add_text(ospf_header_tree, tvb, 14, 2, "Auth Type: %s",
340 val_to_str(auth_type, auth_vals, "Unknown (%u)"));
344 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data (none)");
347 case OSPF_AUTH_SIMPLE:
348 tvb_get_nstringz0(tvb, 16, 8, auth_data);
349 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data: %s", auth_data);
352 case OSPF_AUTH_CRYPT:
353 proto_tree_add_text(ospf_header_tree, tvb, 18, 1, "Auth Key ID: %u",
354 tvb_get_guint8(tvb, 18));
355 crypto_len = tvb_get_guint8(tvb, 19);
356 proto_tree_add_text(ospf_header_tree, tvb, 19, 1, "Auth Data Length: %u",
358 proto_tree_add_text(ospf_header_tree, tvb, 20, 4, "Auth Crypto Sequence Number: 0x%x",
359 tvb_get_ntohl(tvb, 20));
361 /* Show the message digest that was appended to the end of the
362 OSPF message - but only if it's present (we don't want
363 to get an exception before we've tried dissecting OSPF
365 if (tvb_bytes_exist(tvb, ospflen, crypto_len)) {
366 proto_tree_add_text(ospf_header_tree, tvb, ospflen, crypto_len,
368 tvb_bytes_to_str(tvb, ospflen, crypto_len));
373 proto_tree_add_text(ospf_header_tree, tvb, 16, 8, "Auth Data (unknown)");
379 /* Instance ID and "reserved" is OSPFv3-only */
380 if ( version == OSPF_VERSION_3 ) {
381 instance_ID = tvb_get_guint8(tvb, 14);
382 proto_tree_add_text(ospf_header_tree, tvb, 14, 1, "Instance ID: %u",
384 reserved = tvb_get_guint8(tvb, 15);
385 proto_tree_add_text(ospf_header_tree, tvb, 15, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
390 /* Adjust the length of the tvbuff to match the size of the OSPF
391 * packet (since the dissect routines use it to work out where the
392 * end of the OSPF packet is).
394 tvb_set_reported_length(tvb, ospflen);
396 switch (packet_type){
399 dissect_ospf_hello(tvb, ospf_header_length, ospf_tree, version);
403 dissect_ospf_db_desc(tvb, ospf_header_length, ospf_tree, version);
407 dissect_ospf_ls_req(tvb, ospf_header_length, ospf_tree, version);
411 dissect_ospf_ls_upd(tvb, ospf_header_length, ospf_tree, version);
415 dissect_ospf_ls_ack(tvb, ospf_header_length, ospf_tree, version);
419 dissect_data(tvb, ospf_header_length, pinfo, tree);
426 dissect_ospf_hello(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
428 proto_tree *ospf_hello_tree;
431 ti = proto_tree_add_text(tree, tvb, offset,
432 tvb_length_remaining(tvb, offset),
433 "OSPF Hello Packet");
434 ospf_hello_tree = proto_item_add_subtree(ti, ett_ospf_hello);
438 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4, "Network Mask: %s",
439 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
440 proto_tree_add_text(ospf_hello_tree, tvb, offset + 4, 2,
441 "Hello Interval: %u seconds",
442 tvb_get_ntohs(tvb, offset + 4));
444 dissect_ospf_options(tvb, offset + 6, ospf_hello_tree, version);
445 proto_tree_add_text(ospf_hello_tree, tvb, offset + 7, 1, "Router Priority: %u",
446 tvb_get_guint8(tvb, offset + 7));
447 proto_tree_add_text(ospf_hello_tree, tvb, offset + 8, 4, "Router Dead Interval: %u seconds",
448 tvb_get_ntohl(tvb, offset + 8));
449 proto_tree_add_text(ospf_hello_tree, tvb, offset + 12, 4, "Designated Router: %s",
450 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
451 proto_tree_add_text(ospf_hello_tree, tvb, offset + 16, 4, "Backup Designated Router: %s",
452 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
455 while (tvb_reported_length_remaining(tvb, offset) != 0) {
456 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4,
457 "Active Neighbor: %s",
458 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
463 proto_tree_add_text(ospf_hello_tree, tvb, offset + 0, 4, "Interface ID: %u",
464 tvb_get_ntohl(tvb, offset + 0));
465 proto_tree_add_text(ospf_hello_tree, tvb, offset + 4, 1, "Router Priority: %u",
466 tvb_get_guint8(tvb, offset + 4));
467 dissect_ospf_options(tvb, offset + 5, ospf_hello_tree, version);
468 proto_tree_add_text(ospf_hello_tree, tvb, offset + 8, 2,
469 "Hello Interval: %u seconds",
470 tvb_get_ntohs(tvb, offset + 8));
471 proto_tree_add_text(ospf_hello_tree, tvb, offset + 10, 2, "Router Dead Interval: %u seconds",
472 tvb_get_ntohs(tvb, offset + 10));
473 proto_tree_add_text(ospf_hello_tree, tvb, offset + 12, 4, "Designated Router: %s",
474 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
475 proto_tree_add_text(ospf_hello_tree, tvb, offset + 16, 4, "Backup Designated Router: %s",
476 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
478 while (tvb_reported_length_remaining(tvb, offset) != 0) {
479 proto_tree_add_text(ospf_hello_tree, tvb, offset, 4,
480 "Active Neighbor: %s",
481 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
493 dissect_ospf_db_desc(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
495 proto_tree *ospf_db_desc_tree=NULL;
499 char flags_string[20] = "";
502 ti = proto_tree_add_text(tree, tvb, offset,
503 tvb_length_remaining(tvb, offset),
504 "OSPF DB Description");
505 ospf_db_desc_tree = proto_item_add_subtree(ti, ett_ospf_desc);
511 proto_tree_add_text(ospf_db_desc_tree, tvb, offset, 2, "Interface MTU: %u",
512 tvb_get_ntohs(tvb, offset));
514 dissect_ospf_options(tvb, offset + 2, ospf_db_desc_tree, version);
516 flags = tvb_get_guint8(tvb, offset + 3);
517 if (flags & OSPF_DBD_FLAG_MS)
518 strcat(flags_string, "MS");
519 if (flags & OSPF_DBD_FLAG_M) {
520 if (flags_string[0] != '\0')
521 strcat(flags_string, "/");
522 strcat(flags_string, "M");
524 if (flags & OSPF_DBD_FLAG_I) {
525 if (flags_string[0] != '\0')
526 strcat(flags_string, "/");
527 strcat(flags_string, "I");
529 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 3, 1, "Flags: 0x%x (%s)",
530 flags, flags_string);
531 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 4, 4, "DD Sequence: %u",
532 tvb_get_ntohl(tvb, offset + 4));
539 reserved = tvb_get_guint8(tvb, offset);
540 proto_tree_add_text(ospf_db_desc_tree, tvb, offset, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
543 dissect_ospf_options(tvb, offset + 1, ospf_db_desc_tree, version);
545 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 4, 2, "Interface MTU: %u",
546 tvb_get_ntohs(tvb, offset+4));
548 reserved = tvb_get_guint8(tvb, offset + 6);
549 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 6, 1, (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
552 flags = tvb_get_guint8(tvb, offset + 7);
553 if (flags & OSPF_DBD_FLAG_MS)
554 strcat(flags_string, "MS");
555 if (flags & OSPF_DBD_FLAG_M) {
556 if (flags_string[0] != '\0')
557 strcat(flags_string, "/");
558 strcat(flags_string, "M");
560 if (flags & OSPF_DBD_FLAG_I) {
561 if (flags_string[0] != '\0')
562 strcat(flags_string, "/");
563 strcat(flags_string, "I");
565 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 7, 1, "Flags: 0x%x (%s)",
566 flags, flags_string);
568 proto_tree_add_text(ospf_db_desc_tree, tvb, offset + 8, 4, "DD Sequence: %u",
569 tvb_get_ntohl(tvb, offset + 8));
579 /* LS Headers will be processed here */
580 /* skip to the end of DB-Desc header */
581 while (tvb_reported_length_remaining(tvb, offset) != 0) {
582 if ( version == OSPF_VERSION_2)
583 offset = dissect_ospf_v2_lsa(tvb, offset, tree, FALSE);
585 if ( version == OSPF_VERSION_3)
586 offset = dissect_ospf_v3_lsa(tvb, offset, tree, FALSE);
592 dissect_ospf_ls_req(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
594 proto_tree *ospf_lsr_tree;
599 /* zero or more LS requests may be within a LS Request */
600 /* we place every request for a LSA in a single subtree */
601 while (tvb_reported_length_remaining(tvb, offset) != 0) {
602 ti = proto_tree_add_text(tree, tvb, offset, OSPF_LS_REQ_LENGTH,
603 "Link State Request");
604 ospf_lsr_tree = proto_item_add_subtree(ti, ett_ospf_lsr);
606 reserved = tvb_get_guint8(tvb, offset);
607 proto_tree_add_text(ospf_lsr_tree, tvb, offset, 1,
608 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),
614 ls_type = tvb_get_ntohl(tvb, offset);
615 proto_tree_add_text(ospf_lsr_tree, tvb, offset, 4, "LS Type: %s (%u)",
616 val_to_str(ls_type, ls_type_vals, "Unknown"),
620 ls_type = tvb_get_ntohs(tvb, offset+2);
621 proto_tree_add_text(ospf_lsr_tree, tvb, offset+2, 2, "LS Type: %s (0x%04x)",
622 val_to_str(ls_type, v3_ls_type_vals, "Unknown"),
631 proto_tree_add_text(ospf_lsr_tree, tvb, offset + 4, 4, "Link State ID: %s",
632 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
633 proto_tree_add_text(ospf_lsr_tree, tvb, offset + 8, 4, "Advertising Router: %s",
634 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
641 dissect_ospf_ls_upd(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
643 proto_tree *ospf_lsa_upd_tree=NULL;
648 ti = proto_tree_add_text(tree, tvb, offset,
649 tvb_length_remaining(tvb, offset),
651 ospf_lsa_upd_tree = proto_item_add_subtree(ti, ett_ospf_lsa_upd);
653 lsa_nr = tvb_get_ntohl(tvb, offset);
654 proto_tree_add_text(ospf_lsa_upd_tree, tvb, offset, 4, "Number of LSAs: %u",
656 /* skip to the beginning of the first LSA */
657 offset += 4; /* the LS Upd Packet contains only a 32 bit #LSAs field */
660 while (lsa_counter < lsa_nr) {
661 if ( version == OSPF_VERSION_2)
662 offset = dissect_ospf_v2_lsa(tvb, offset, ospf_lsa_upd_tree, TRUE);
664 if ( version == OSPF_VERSION_3)
665 offset = dissect_ospf_v3_lsa(tvb, offset, ospf_lsa_upd_tree, TRUE);
671 dissect_ospf_ls_ack(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
673 /* the body of a LS Ack packet simply contains zero or more LSA Headers */
674 while (tvb_reported_length_remaining(tvb, offset) != 0) {
675 if ( version == OSPF_VERSION_2)
676 offset = dissect_ospf_v2_lsa(tvb, offset, tree, FALSE);
678 if ( version == OSPF_VERSION_3)
679 offset = dissect_ospf_v3_lsa(tvb, offset, tree, FALSE);
684 * Returns if an LSA is opaque, i.e. requires special treatment
687 is_opaque(int lsa_type)
689 return (lsa_type >= OSPF_LSTYPE_OP_LINKLOCAL &&
690 lsa_type <= OSPF_LSTYPE_OP_ASWIDE);
693 /* MPLS/TE TLV types */
694 #define MPLS_TLV_ROUTER 1
695 #define MPLS_TLV_LINK 2
697 /* MPLS/TE Link STLV types */
705 MPLS_LINK_MAX_RES_BW,
710 static const value_string mpls_link_stlv_str[] = {
711 {MPLS_LINK_TYPE, "Link Type"},
712 {MPLS_LINK_ID, "Link ID"},
713 {MPLS_LINK_LOCAL_IF, "Local Interface IP Address"},
714 {MPLS_LINK_REMOTE_IF, "Remote Interface IP Address"},
715 {MPLS_LINK_TE_METRIC, "Traffic Engineering Metric"},
716 {MPLS_LINK_MAX_BW, "Maximum Bandwidth"},
717 {MPLS_LINK_MAX_RES_BW, "Maximum Reservable Bandwidth"},
718 {MPLS_LINK_UNRES_BW, "Unreserved Bandwidth"},
719 {MPLS_LINK_COLOR, "Resource Class/Color"},
724 * Dissect MPLS/TE opaque LSA
727 dissect_ospf_lsa_mpls(tvbuff_t *tvb, int offset, proto_tree *tree,
731 proto_tree *mpls_tree;
732 proto_tree *tlv_tree;
733 proto_tree *stlv_tree;
739 int stlv_type, stlv_len, stlv_offset;
743 ti = proto_tree_add_text(tree, tvb, offset, length,
744 "MPLS Traffic Engineering LSA");
745 mpls_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls);
747 while (length != 0) {
748 tlv_type = tvb_get_ntohs(tvb, offset);
749 tlv_length = tvb_get_ntohs(tvb, offset + 2);
750 tlv_end_offset = offset + tlv_length + 4;
754 case MPLS_TLV_ROUTER:
755 ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
756 "Router Address: %s",
757 ip_to_str(tvb_get_ptr(tvb, offset+4, 4)));
758 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_router);
759 proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: 1 - Router Address");
760 proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
762 proto_tree_add_text(tlv_tree, tvb, offset+4, 4, "Router Address: %s",
763 ip_to_str(tvb_get_ptr(tvb, offset+4, 4)));
767 ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
769 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
770 proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: 2 - Link Information");
771 proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
773 stlv_offset = offset + 4;
775 /* Walk down the sub-TLVs for link information */
776 while (stlv_offset < tlv_end_offset) {
777 stlv_type = tvb_get_ntohs(tvb, stlv_offset);
778 stlv_len = tvb_get_ntohs(tvb, stlv_offset + 2);
779 stlv_name = val_to_str(stlv_type, mpls_link_stlv_str, "Unknown sub-TLV");
783 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
785 tvb_get_guint8(tvb, stlv_offset + 4));
786 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
787 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
788 "TLV Type: %u: %s", stlv_type, stlv_name);
789 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
791 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 1, "%s: %u", stlv_name,
792 tvb_get_guint8(tvb, stlv_offset + 4));
796 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
797 "%s: %s (%x)", stlv_name,
798 ip_to_str(tvb_get_ptr(tvb, stlv_offset + 4, 4)),
799 tvb_get_ntohl(tvb, stlv_offset + 4));
800 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
801 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
802 "TLV Type: %u: %s", stlv_type, stlv_name);
803 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
805 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %s (%x)", stlv_name,
806 ip_to_str(tvb_get_ptr(tvb, stlv_offset + 4, 4)),
807 tvb_get_ntohl(tvb, stlv_offset + 4));
810 case MPLS_LINK_LOCAL_IF:
811 case MPLS_LINK_REMOTE_IF:
812 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
814 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
815 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
816 "TLV Type: %u: %s", stlv_type, stlv_name);
817 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
819 /* The Local/Remote Interface IP Address sub-TLV is TLV type 3/4, and is 4N
820 octets in length, where N is the number of neighbor addresses. */
821 for (i=0; i < stlv_len; i+=4)
822 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4+i, 4, "%s: %s", stlv_name,
823 ip_to_str(tvb_get_ptr(tvb, stlv_offset+4+i, 4)));
826 case MPLS_LINK_TE_METRIC:
827 case MPLS_LINK_COLOR:
828 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
830 tvb_get_ntohl(tvb, stlv_offset + 4));
831 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
832 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
833 "TLV Type: %u: %s", stlv_type, stlv_name);
834 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
836 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %u", stlv_name,
837 tvb_get_ntohl(tvb, stlv_offset + 4));
840 case MPLS_LINK_MAX_BW:
841 case MPLS_LINK_MAX_RES_BW:
842 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
843 "%s: %ld", stlv_name,
844 tvb_ieee_to_long(tvb, stlv_offset + 4));
845 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
846 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
847 "TLV Type: %u: %s", stlv_type, stlv_name);
848 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
850 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4, 4, "%s: %ld", stlv_name,
851 tvb_ieee_to_long(tvb, stlv_offset + 4));
854 case MPLS_LINK_UNRES_BW:
855 ti = proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
857 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
858 proto_tree_add_text(stlv_tree, tvb, stlv_offset, 2,
859 "TLV Type: %u: %s", stlv_type, stlv_name);
860 proto_tree_add_text(stlv_tree, tvb, stlv_offset+2, 2, "TLV Length: %u",
862 for (i = 0; i < 8; i++) {
863 proto_tree_add_text(stlv_tree, tvb, stlv_offset+4+(i*4), 4,
865 tvb_ieee_to_long(tvb, stlv_offset + 4 + i*4));
870 proto_tree_add_text(tlv_tree, tvb, stlv_offset, stlv_len+4,
871 "Unknown Link sub-TLV: %u", stlv_type);
874 stlv_offset += ((stlv_len+4+3)/4)*4;
879 ti = proto_tree_add_text(mpls_tree, tvb, offset, tlv_length+4,
880 "Unknown LSA: %u", tlv_type);
881 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
882 proto_tree_add_text(tlv_tree, tvb, offset, 2, "TLV Type: %u - Unknown",
884 proto_tree_add_text(tlv_tree, tvb, offset+2, 2, "TLV Length: %u",
886 proto_tree_add_text(tlv_tree, tvb, offset+4, tlv_length, "TLV Data");
890 offset += tlv_length + 4;
891 length -= tlv_length + 4;
896 * Dissect opaque LSAs
899 dissect_ospf_lsa_opaque(tvbuff_t *tvb, int offset, proto_tree *tree,
900 guint8 ls_id_type, guint32 length)
902 switch (ls_id_type) {
904 case OSPF_LSA_MPLS_TE:
905 dissect_ospf_lsa_mpls(tvb, offset, tree, length);
909 proto_tree_add_text(tree, tvb, offset, length,
910 "Unknown LSA Type %u", ls_id_type);
912 } /* switch on opaque LSA id */
916 dissect_ospf_v2_lsa(tvbuff_t *tvb, int offset, proto_tree *tree,
917 gboolean disassemble_body)
919 proto_tree *ospf_lsa_tree;
930 guint16 link_counter;
935 /* AS-external LSA */
941 ls_type = tvb_get_guint8(tvb, offset + 3);
942 ls_length = tvb_get_ntohs(tvb, offset + 18);
943 end_offset = offset + ls_length;
945 if (disassemble_body) {
946 ti = proto_tree_add_text(tree, tvb, offset, ls_length,
947 "%s (Type: %u)", val_to_str(ls_type, ls_type_vals,"Unkown"), ls_type);
949 ti = proto_tree_add_text(tree, tvb, offset, OSPF_LSA_HEADER_LENGTH,
952 ospf_lsa_tree = proto_item_add_subtree(ti, ett_ospf_lsa);
954 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "LS Age: %u seconds",
955 tvb_get_ntohs(tvb, offset));
956 dissect_ospf_options(tvb, offset + 2, ospf_lsa_tree, OSPF_VERSION_2);
957 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 3, 1, "LSA Type: %u (%s)",
958 ls_type, val_to_str(ls_type,ls_type_vals,"Unknown"));
960 if (is_opaque(ls_type)) {
961 ls_id_type = tvb_get_guint8(tvb, offset + 4);
962 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 1, "Link State ID Opaque Type: %u",
964 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 5, 3, "Link State ID Opaque ID: %u",
965 tvb_get_ntoh24(tvb, offset + 5));
968 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link State ID: %s",
969 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
972 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Advertising Router: %s",
973 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
974 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "LS Sequence Number: 0x%04x",
975 tvb_get_ntohl(tvb, offset + 12));
976 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 16, 2, "LS Checksum: %04x",
977 tvb_get_ntohs(tvb, offset + 16));
979 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 18, 2, "Length: %u",
982 /* skip past the LSA header to the body */
983 offset += OSPF_LSA_HEADER_LENGTH;
984 ls_length -= OSPF_LSA_HEADER_LENGTH;
986 if (!disassemble_body)
991 case OSPF_LSTYPE_ROUTER:
992 /* again: flags should be secified in detail */
993 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x",
994 tvb_get_guint8(tvb, offset));
995 nr_links = tvb_get_ntohs(tvb, offset + 2);
996 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2, "Number of Links: %u",
999 /* nr_links links follow
1000 * maybe we should put each of the links into its own subtree ???
1002 for (link_counter = 1; link_counter <= nr_links; link_counter++) {
1003 /* check the Link Type and ID */
1004 link_type = tvb_get_guint8(tvb, offset + 8);
1005 switch (link_type) {
1008 link_type_str="Point-to-point connection to another router";
1009 link_id="Neighboring router's Router ID";
1012 case OSPF_LINK_TRANSIT:
1013 link_type_str="Connection to a transit network";
1014 link_id="IP address of Designated Router";
1017 case OSPF_LINK_STUB:
1018 link_type_str="Connection to a stub network";
1019 link_id="IP network/subnet number";
1022 case OSPF_LINK_VIRTUAL:
1023 link_type_str="Virtual link";
1024 link_id="Neighboring router's Router ID";
1028 link_type_str="Unknown link type";
1029 link_id="Unknown link ID";
1033 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "%s: %s", link_id,
1034 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1036 /* link_data should be specified in detail (e.g. network mask) (depends on link type)*/
1037 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link Data: %s",
1038 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1040 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 1, "Link Type: %u - %s",
1041 link_type, link_type_str);
1042 nr_tos = tvb_get_guint8(tvb, offset + 9);
1043 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 9, 1, "Number of TOS metrics: %u",
1045 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 10, 2, "TOS 0 metric: %u",
1046 tvb_get_ntohs(tvb, offset + 10));
1050 /* nr_tos metrics may follow each link
1051 * ATTENTION: TOS metrics are not tested (I don't have TOS
1053 * please send me a mail if it is/isn't working
1055 for (tos_counter = 1; tos_counter <= nr_tos; tos_counter++) {
1056 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1057 tvb_get_guint8(tvb, offset),
1058 tvb_get_ntohs(tvb, offset + 2));
1064 case OSPF_LSTYPE_NETWORK:
1065 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
1066 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1069 while (offset < end_offset) {
1070 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Attached Router: %s",
1071 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1076 case OSPF_LSTYPE_SUMMERY:
1077 /* Type 3 and 4 LSAs have the same format */
1078 case OSPF_LSTYPE_ASBR:
1079 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
1080 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1083 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Metric: %u",
1084 tvb_get_ntoh24(tvb, offset + 1));
1087 /* TOS-specific information, if any */
1088 while (offset < end_offset) {
1089 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1090 tvb_get_guint8(tvb, offset),
1091 tvb_get_ntoh24(tvb, offset + 1));
1096 case OSPF_LSTYPE_ASEXT:
1097 case OSPF_LSTYPE_ASEXT7:
1098 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Netmask: %s",
1099 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1102 options = tvb_get_guint8(tvb, offset);
1103 if (options & 0x80) { /* check wether or not E bit is set */
1104 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1105 "External Type: Type 2 (metric is larger than any other link state path)");
1107 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1108 "External Type: Type 1 (metric is specified in the same units as interface cost)");
1110 /* the metric field of a AS-external LAS is specified in 3 bytes */
1111 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 1, 3, "Metric: %u",
1112 tvb_get_ntoh24(tvb, offset + 1));
1115 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Forwarding Address: %s",
1116 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1119 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "External Route Tag: %u",
1120 tvb_get_ntohl(tvb, offset));
1123 /* TOS-specific information, if any */
1124 while (offset < end_offset) {
1125 options = tvb_get_guint8(tvb, offset);
1126 if (options & 0x80) { /* check wether or not E bit is set */
1127 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1128 "External Type: Type 2 (metric is larger than any other link state path)");
1130 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1131 "External Type: Type 1 (metric is specified in the same units as interface cost)");
1133 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "TOS: %u, Metric: %u",
1135 tvb_get_ntoh24(tvb, offset + 1));
1138 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Forwarding Address: %s",
1139 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1142 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "External Route Tag: %u",
1143 tvb_get_ntohl(tvb, offset));
1148 case OSPF_LSTYPE_OP_LINKLOCAL:
1149 case OSPF_LSTYPE_OP_AREALOCAL:
1150 case OSPF_LSTYPE_OP_ASWIDE:
1151 dissect_ospf_lsa_opaque(tvb, offset, ospf_lsa_tree, ls_id_type,
1153 offset += ls_length;
1157 /* unknown LSA type */
1158 proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1159 "Unknown LSA Type");
1160 offset += ls_length;
1163 /* return the offset of the next LSA */
1168 dissect_ospf_v3_lsa(tvbuff_t *tvb, int offset, proto_tree *tree,
1169 gboolean disassemble_body)
1171 proto_tree *ospf_lsa_tree;
1183 guint16 link_counter;
1185 char *link_type_str;
1188 guint8 router_lsa_flags;
1189 char router_lsa_flags_string[5];
1191 /* AS-external LSA */
1197 guint8 router_priority;
1198 guint32 number_prefixes;
1199 guint8 prefix_length;
1202 guint16 referenced_ls_type;
1203 char *referenced_ls_type_str;
1206 guint8 flags_string[4];
1207 guint32 external_route_tag;
1210 ls_type = tvb_get_ntohs(tvb, offset + 2);
1211 ls_length = tvb_get_ntohs(tvb, offset + 18);
1212 end_offset = offset + ls_length;
1214 if (disassemble_body) {
1215 ti = proto_tree_add_text(tree, tvb, offset, ls_length,
1216 "%s (Type: 0x%04x)", val_to_str(ls_type, v3_ls_type_vals,"Unknown"), ls_type);
1218 ti = proto_tree_add_text(tree, tvb, offset, OSPF_LSA_HEADER_LENGTH,
1221 ospf_lsa_tree = proto_item_add_subtree(ti, ett_ospf_lsa);
1223 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2, "LS Age: %u seconds",
1224 tvb_get_ntohs(tvb, offset));
1226 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2, "LSA Type: 0x%04x (%s)",
1227 ls_type, val_to_str(ls_type, v3_ls_type_vals,"Unkown"));
1230 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Link State ID: %s",
1231 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1233 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Advertising Router: %s",
1234 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
1235 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "LS Sequence Number: %d",
1236 tvb_get_ntohl(tvb, offset + 12));
1237 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 16, 2, "LS Checksum: %04x",
1238 tvb_get_ntohs(tvb, offset + 16));
1240 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 18, 2, "Length: %u",
1243 /* skip past the LSA header to the body */
1244 offset += OSPF_LSA_HEADER_LENGTH;
1245 ls_length -= OSPF_LSA_HEADER_LENGTH;
1247 if (!disassemble_body)
1253 case OSPF_V3_LSTYPE_ROUTER:
1255 /* flags field in an router-lsa */
1256 router_lsa_flags=tvb_get_guint8(tvb,offset);
1257 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_B)
1258 router_lsa_flags_string[3] = 'B';
1260 router_lsa_flags_string[3] = '.';
1261 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_E)
1262 router_lsa_flags_string[2] = 'E';
1264 router_lsa_flags_string[2] = '.';
1265 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_V)
1266 router_lsa_flags_string[1] = 'V';
1268 router_lsa_flags_string[1] = '.';
1269 if (router_lsa_flags & OSPF_V3_ROUTER_LSA_FLAG_W)
1270 router_lsa_flags_string[0] = 'W';
1272 router_lsa_flags_string[0] = '.';
1274 router_lsa_flags_string[4]=0;
1276 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x (%s)",
1277 router_lsa_flags, router_lsa_flags_string);
1279 /* options field in an router-lsa */
1280 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1282 /* skip the router-lsa flags and options */
1287 proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1288 "Router Interfaces:");
1290 /* scan all router-lsa router interfaces */
1291 /* maybe we should put each of the links into its own subtree ??? */
1292 while (ls_length > 0 ) {
1294 /* check the type */
1295 link_type = tvb_get_guint8(tvb, offset);
1296 switch (link_type) {
1298 case OSPF_V3_LINK_PTP:
1299 link_type_str="Point-to-point connection to another router";
1302 case OSPF_V3_LINK_TRANSIT:
1303 link_type_str="Connection to a transit network";
1306 case OSPF_V3_LINK_RESERVED:
1307 link_type_str="Connection to a stub network";
1310 case OSPF_V3_LINK_VIRTUAL:
1311 link_type_str="Virtual link";
1315 link_type_str="Unknown link type";
1319 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Type: %u (%s)", link_type,link_type_str);
1321 /* reserved field */
1322 reserved = tvb_get_guint8(tvb, offset+1);
1323 proto_tree_add_text(ospf_lsa_tree, tvb, offset+1, 1,
1324 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1327 metric=tvb_get_ntohs(tvb, offset+2);
1328 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 2, 2,"Metric: %u",metric);
1331 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Interface ID: %u",
1332 tvb_get_ntohl(tvb, offset + 4));
1334 /* Neighbor Interface ID */
1335 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Neighbor Interface ID: %u",
1336 tvb_get_ntohl(tvb, offset + 8));
1338 /* Neighbor Router ID */
1339 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 12, 4, "Neighbor Router ID: %s",
1340 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
1342 /* skip to the (possible) next entry */
1349 case OSPF_V3_LSTYPE_NETWORK:
1351 /* reserved field */
1352 reserved = tvb_get_guint8(tvb, offset);
1353 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1354 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1356 /* options field in an network-lsa */
1357 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1362 while (ls_length > 0 ) {
1363 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Attached Router: %s",
1364 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1371 case OSPF_V3_LSTYPE_INTER_AREA_PREFIX:
1373 /* reserved field */
1374 reserved = tvb_get_guint8(tvb, offset);
1375 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1376 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1379 metric=tvb_get_ntoh24(tvb, offset+11);
1380 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 1, 3,"Metric: %u",metric);
1383 prefix_length=tvb_get_guint8(tvb, offset+4);
1384 proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1, "PrefixLength: %u",prefix_length);
1386 /* prefix options */
1387 dissect_ospf_v3_prefix_options(tvb, offset+5, ospf_lsa_tree);
1389 /* 16 bits reserved */
1390 reserved16=tvb_get_ntohs(tvb, offset+6);
1391 proto_tree_add_text(ospf_lsa_tree, tvb, offset+6, 2,
1392 (reserved16 == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved16);
1396 /* address_prefix */
1397 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1399 offset+=(prefix_length+31)/32*4;
1404 case OSPF_V3_LSTYPE_INTER_AREA_ROUTER:
1406 /* reserved field */
1407 reserved = tvb_get_guint8(tvb, offset);
1408 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1,
1409 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1411 /* options field in an inter-area-router-lsa */
1412 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1414 /* reserved field */
1415 reserved = tvb_get_guint8(tvb, offset+4);
1416 proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1,
1417 (reserved == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved);
1420 metric=tvb_get_ntoh24(tvb, offset+6);
1421 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 6, 3,"Metric: %u",metric);
1423 /* Destination Router ID */
1424 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Destination Router ID: %s",
1425 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
1431 case OSPF_V3_LSTYPE_AS_EXTERNAL:
1434 flags=tvb_get_guint8(tvb, offset);
1435 if (flags & OSPF_V3_AS_EXTERNAL_FLAG_E)
1436 flags_string[0] = 'E';
1438 flags_string[0] = '.';
1439 if (flags & OSPF_V3_AS_EXTERNAL_FLAG_F)
1440 flags_string[1] = 'F';
1442 flags_string[1] = '.';
1443 if (flags & OSPF_V3_AS_EXTERNAL_FLAG_T)
1444 flags_string[2] = 'T';
1446 flags_string[2] = '.';
1450 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Flags: 0x%02x (%s)",
1451 flags, flags_string);
1453 /* 24 bits metric */
1454 metric=tvb_get_ntohs(tvb, offset+1);
1455 proto_tree_add_text(ospf_lsa_tree, tvb, offset+1, 3,
1456 "Metric: %u", metric);
1459 prefix_length=tvb_get_guint8(tvb, offset+4);
1460 proto_tree_add_text(ospf_lsa_tree, tvb, offset+4, 1, "PrefixLength: %u",prefix_length);
1462 /* prefix options */
1463 dissect_ospf_v3_prefix_options(tvb, offset+5, ospf_lsa_tree);
1465 /* referenced LS type */
1466 referenced_ls_type=tvb_get_ntohs(tvb, offset+6);
1467 proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,"Referenced LS type 0x%04x (%s)",
1468 referenced_ls_type, val_to_str(referenced_ls_type, v3_ls_type_vals, "Unknown"));
1472 /* address_prefix */
1473 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1475 offset+=(prefix_length+31)/32*4;
1477 /* Forwarding Address (optional - only if F-flag is on) */
1478 if ( (offset < end_offset) && (flags & OSPF_V3_AS_EXTERNAL_FLAG_F) ) {
1479 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 16,"Forwarding Address: %s",
1480 ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset, 16)));
1485 /* External Route Tag (optional - only if T-flag is on) */
1486 if ( (offset < end_offset) && (flags & OSPF_V3_AS_EXTERNAL_FLAG_T) ) {
1487 external_route_tag=tvb_get_ntohl(tvb, offset);
1488 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4,"External Route Tag: 0x%04x",
1489 external_route_tag);
1494 /* Referenced Link State ID (optional - only if Referenced LS type is non-zero */
1495 if ( (offset < end_offset) && (referenced_ls_type != 0) ) {
1496 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 4, "Referenced Link State ID: %s",
1497 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1503 case OSPF_V3_LSTYPE_LINK:
1505 /* router priority */
1506 router_priority=tvb_get_guint8(tvb, offset);
1507 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "Router Priority: %u", router_priority);
1509 /* options field in an link-lsa */
1510 dissect_ospf_options(tvb, offset + 1, ospf_lsa_tree, OSPF_VERSION_3);
1512 /* Link-local Interface Address */
1513 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 16, "Link-local Interface Address: %s",
1514 ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, 16)));
1516 /* Number prefixes */
1517 number_prefixes=tvb_get_ntohl(tvb, offset + 20);
1518 proto_tree_add_text(ospf_lsa_tree, tvb, offset+20, 4, "# prefixes: %d",number_prefixes);
1522 while (number_prefixes > 0) {
1525 prefix_length=tvb_get_guint8(tvb, offset);
1526 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "PrefixLength: %u",prefix_length);
1528 /* prefix options */
1529 dissect_ospf_v3_prefix_options(tvb, offset+1, ospf_lsa_tree);
1531 /* 16 bits reserved */
1532 reserved16=tvb_get_ntohs(tvb, offset+2);
1533 proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,
1534 (reserved16 == 0 ? "Reserved: %u" : "Reserved: %u (incorrect, should be 0)"),reserved16);
1538 /* address_prefix */
1539 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1541 offset+=(prefix_length+31)/32*4;
1548 case OSPF_V3_LSTYPE_INTRA_AREA_PREFIX:
1551 number_prefixes=tvb_get_ntohs(tvb, offset);
1552 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 2,"# prefixes: %u",number_prefixes);
1554 /* referenced LS type */
1555 referenced_ls_type=tvb_get_ntohs(tvb, offset+2);
1556 proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,"Referenced LS type 0x%04x (%s)",
1557 referenced_ls_type, val_to_str(referenced_ls_type, v3_ls_type_vals, "Unknown"));
1559 /* Referenced Link State ID */
1560 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 4, 4, "Referenced Link State ID: %s",
1561 ip_to_str(tvb_get_ptr(tvb, offset + 4, 4)));
1563 /* Referenced Advertising Router */
1564 proto_tree_add_text(ospf_lsa_tree, tvb, offset + 8, 4, "Referenced Advertising Router: %s",
1565 ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
1569 while (number_prefixes > 0) {
1572 prefix_length=tvb_get_guint8(tvb, offset);
1573 proto_tree_add_text(ospf_lsa_tree, tvb, offset, 1, "PrefixLength: %u",prefix_length);
1575 /* prefix options */
1576 dissect_ospf_v3_prefix_options(tvb, offset+1, ospf_lsa_tree);
1578 /* 16 bits metric */
1579 metric=tvb_get_ntohs(tvb, offset+2);
1580 proto_tree_add_text(ospf_lsa_tree, tvb, offset+2, 2,
1581 "Metric: %u", metric);
1585 /* address_prefix */
1586 dissect_ospf_v3_address_prefix(tvb, offset, prefix_length, ospf_lsa_tree);
1588 offset+=(prefix_length+31)/32*4;
1595 /* unknown LSA type */
1596 proto_tree_add_text(ospf_lsa_tree, tvb, offset, ls_length,
1597 "Unknown LSA Type 0x%04x",ls_type);
1598 offset += ls_length;
1601 /* return the offset of the next LSA */
1607 dissect_ospf_options(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 version)
1609 guint8 options_ospfv2;
1610 guint32 options_ospfv3;
1611 char options_string[20] = "";
1613 /* ATTENTION !!! no check for length of options string - with OSPFv3 maximum length is 14 characters */
1615 switch ( version ) {
1617 case OSPF_VERSION_2:
1619 options_ospfv2 = tvb_get_guint8(tvb, offset);
1621 if (options_ospfv2 & OSPF_V2_OPTIONS_E)
1622 strcat(options_string, "E");
1624 if (options_ospfv2 & OSPF_V2_OPTIONS_MC) {
1625 if (options_string[0] != '\0')
1626 strcat(options_string, "/");
1627 strcat(options_string, "MC");
1630 if (options_ospfv2 & OSPF_V2_OPTIONS_NP) {
1631 if (options_string[0] != '\0')
1632 strcat(options_string, "/");
1633 strcat(options_string, "NP");
1636 if (options_ospfv2 & OSPF_V2_OPTIONS_EA) {
1637 if (options_string[0] != '\0')
1638 strcat(options_string, "/");
1639 strcat(options_string, "EA");
1642 if (options_ospfv2 & OSPF_V2_OPTIONS_DC) {
1643 if (options_string[0] != '\0')
1644 strcat(options_string, "/");
1645 strcat(options_string, "DC");
1648 if (options_ospfv2 & OSPF_V2_OPTIONS_O) {
1649 if (options_string[0] != '\0')
1650 strcat(options_string, "/");
1651 strcat(options_string, "O");
1654 if (options_ospfv2 & OSPF_V2_OPTIONS_DN) {
1655 if (options_string[0] != '\0')
1656 strcat(options_string, "/");
1657 strcat(options_string, "DN");
1660 proto_tree_add_text(tree, tvb, offset, 1, "Options: 0x%x (%s)",
1661 options_ospfv2, options_string);
1665 case OSPF_VERSION_3:
1667 options_ospfv3 = tvb_get_ntoh24(tvb, offset);
1669 if (options_ospfv3 & OSPF_V3_OPTIONS_V6)
1670 strcat(options_string, "V6");
1672 if (options_ospfv3 & OSPF_V3_OPTIONS_E)
1673 if (options_string[0] != '\0')
1674 strcat(options_string, "/");
1675 strcat(options_string, "E");
1677 if (options_ospfv3 & OSPF_V3_OPTIONS_MC) {
1678 if (options_string[0] != '\0')
1679 strcat(options_string, "/");
1680 strcat(options_string, "MC");
1683 if (options_ospfv3 & OSPF_V3_OPTIONS_N) {
1684 if (options_string[0] != '\0')
1685 strcat(options_string, "/");
1686 strcat(options_string, "N");
1689 if (options_ospfv3 & OSPF_V3_OPTIONS_R) {
1690 if (options_string[0] != '\0')
1691 strcat(options_string, "/");
1692 strcat(options_string, "R");
1695 if (options_ospfv3 & OSPF_V3_OPTIONS_DC) {
1696 if (options_string[0] != '\0')
1697 strcat(options_string, "/");
1698 strcat(options_string, "DC");
1701 proto_tree_add_text(tree, tvb, offset, 3, "Options: 0x%x (%s)",
1702 options_ospfv3, options_string);
1712 static void dissect_ospf_v3_prefix_options(tvbuff_t *tvb, int offset, proto_tree *tree)
1715 guint8 prefix_options;
1716 char prefix_options_string[11];
1721 prefix_options=tvb_get_guint8(tvb, offset);
1723 strcpy(prefix_options_string,"");
1725 if (prefix_options & OSPF_V3_PREFIX_OPTION_P) {
1726 strcat(prefix_options_string, "P");
1730 if (prefix_options & OSPF_V3_PREFIX_OPTION_MC) {
1731 if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
1732 strcat(prefix_options_string, "/");
1735 strcat(prefix_options_string, "MC");
1739 if (prefix_options & OSPF_V3_PREFIX_OPTION_LA) {
1740 if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
1741 strcat(prefix_options_string, "/");
1744 strcat(prefix_options_string, "LA");
1748 if (prefix_options & OSPF_V3_PREFIX_OPTION_NU) {
1749 if ( (position > 0) && (prefix_options_string[position-1] != '/') ) {
1750 strcat(prefix_options_string, "/");
1753 strcat(prefix_options_string, "NU");
1756 prefix_options_string[10]=0;
1758 proto_tree_add_text(tree, tvb, offset, 1, "PrefixOptions: 0x%02x (%s)",prefix_options, prefix_options_string);
1763 static void dissect_ospf_v3_address_prefix(tvbuff_t *tvb, int offset, int prefix_length, proto_tree *tree)
1771 guint8 bytes_to_process;
1774 start_offset=offset;
1777 bytes_to_process=((prefix_length+31)/32)*4;
1779 while (bytes_to_process > 0 ) {
1781 value=tvb_get_guint8(tvb, offset);
1783 if ( (position > 0) && ( (position%2) == 0 ) )
1784 buffer[bufpos++]=':';
1786 sprintf(bytebuf,"%02x",value);
1787 buffer[bufpos++]=bytebuf[0];
1788 buffer[bufpos++]=bytebuf[1];
1796 proto_tree_add_text(tree, tvb, start_offset, ((prefix_length+31)/32)*4, "Address Prefix: %s",buffer);
1802 proto_register_ospf(void)
1804 /* static hf_register_info hf[] = {
1806 { "Name", "ospf.abbreviation", TYPE, VALS_POINTER }},
1808 static gint *ett[] = {
1817 &ett_ospf_lsa_mpls_router,
1818 &ett_ospf_lsa_mpls_link,
1819 &ett_ospf_lsa_mpls_link_stlv
1822 proto_ospf = proto_register_protocol("Open Shortest Path First",
1824 /* proto_register_field_array(proto_ospf, hf, array_length(hf));*/
1825 proto_register_subtree_array(ett, array_length(ett));
1829 proto_reg_handoff_ospf(void)
1831 dissector_add("ip.proto", IP_PROTO_OSPF, dissect_ospf, proto_ospf);