2 * Routines for OSPF packet disassembly
3 * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
5 * $Id: packet-ospf.c,v 1.22 2000/04/16 22:46:20 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.
12 * TOS - support is not fully implemented
14 * Ethereal - Network traffic analyzer
15 * By Gerald Combs <gerald@zing.org>
16 * Copyright 1998 Gerald Combs
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version 2
22 * of the License, or (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 #ifdef HAVE_SYS_TYPES_H
39 # include <sys/types.h>
42 #ifdef HAVE_NETINET_IN_H
43 # include <netinet/in.h>
51 #include "packet-ospf.h"
52 #include "packet-ip.h"
53 #include "ieee-float.h"
55 static int proto_ospf = -1;
57 static gint ett_ospf = -1;
58 static gint ett_ospf_hdr = -1;
59 static gint ett_ospf_hello = -1;
60 static gint ett_ospf_desc = -1;
61 static gint ett_ospf_lsr = -1;
62 static gint ett_ospf_lsa = -1;
63 static gint ett_ospf_lsa_upd = -1;
65 /* Trees for opaque LSAs */
66 static gint ett_ospf_lsa_mpls = -1;
67 static gint ett_ospf_lsa_mpls_router = -1;
68 static gint ett_ospf_lsa_mpls_link = -1;
69 static gint ett_ospf_lsa_mpls_link_stlv = -1;
71 static void dissect_ospf_hello(const u_char*, int, frame_data*, proto_tree*);
72 static void dissect_ospf_db_desc(const u_char*, int, frame_data*, proto_tree*);
73 static void dissect_ospf_ls_req(const u_char*, int, frame_data*, proto_tree*);
74 static void dissect_ospf_ls_upd(const u_char*, int, frame_data*, proto_tree*);
75 static void dissect_ospf_ls_ack(const u_char*, int, frame_data*, proto_tree*);
77 /* dissect_ospf_lsa returns the length of the LSA
78 * if disassemble_body is set to FALSE (e.g. in LSA ACK
79 * packets), the LSA-header length is returned (20)
81 static int dissect_ospf_lsa(const u_char*, int, frame_data*, proto_tree*, int disassemble_body);
84 dissect_ospf(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
86 e_ospf_crypto *crypto;
87 int i, saved_len, ospflen;
89 proto_tree *ospf_tree = NULL;
91 proto_tree *ospf_header_tree;
92 char auth_data[(2 * 16) + 1]="";
94 static value_string pt_vals[] = { {OSPF_HELLO, "Hello Packet" },
95 {OSPF_DB_DESC, "DB Descr." },
96 {OSPF_LS_REQ, "LS Request" },
97 {OSPF_LS_UPD, "LS Update" },
98 {OSPF_LS_ACK, "LS Acknowledge" },
101 memcpy(&ospfh, &pd[offset], sizeof(e_ospfhdr));
103 packet_type = match_strval(ospfh.packet_type, pt_vals);
104 if (check_col(fd, COL_PROTOCOL))
105 col_add_str(fd, COL_PROTOCOL, "OSPF");
106 if (check_col(fd, COL_INFO)) {
107 if (packet_type != NULL)
108 col_add_str(fd, COL_INFO, packet_type);
110 col_add_fstr(fd, COL_INFO, "Unknown (%d)", ospfh.packet_type);
114 ti = proto_tree_add_item(tree, proto_ospf, offset, ntohs(ospfh.length), NULL);
115 ospf_tree = proto_item_add_subtree(ti, ett_ospf);
117 ti = proto_tree_add_text(ospf_tree, offset, OSPF_HEADER_LENGTH, "OSPF Header");
118 ospf_header_tree = proto_item_add_subtree(ti, ett_ospf_hdr);
120 proto_tree_add_text(ospf_header_tree, offset, 1, "OSPF Version: %d", ospfh.version);
121 proto_tree_add_text(ospf_header_tree, offset + 1 , 1, "OSPF Packet Type: %d (%s)",
123 (packet_type != NULL ?
126 proto_tree_add_text(ospf_header_tree, offset + 2 , 2, "Packet Length: %d",
127 ntohs(ospfh.length));
128 proto_tree_add_text(ospf_header_tree, offset + 4 , 4, "Source OSPF Router ID: %s",
130 ip_to_str((guint8 *) &(ospfh.routerid)));
132 proto_tree_add_text(ospf_header_tree, offset + 8 , 4, "Area ID: Backbone");
134 proto_tree_add_text(ospf_header_tree, offset + 8 , 4, "Area ID: %s", ip_to_str((guint8 *) &(ospfh.area)));
136 proto_tree_add_text(ospf_header_tree, offset + 12 , 2, "Packet Checksum: 0x%x",
137 ntohs(ospfh.checksum));
138 switch( ntohs(ospfh.auth_type) ) {
140 proto_tree_add_text(ospf_header_tree, offset + 14 , 2, "Auth Type: none");
141 proto_tree_add_text(ospf_header_tree, offset + 16 , 8, "Auth Data (none)");
143 case OSPF_AUTH_SIMPLE:
144 proto_tree_add_text(ospf_header_tree, offset + 14 , 2, "Auth Type: simple");
145 strncpy(auth_data, (char *) &ospfh.auth_data, 8);
146 proto_tree_add_text(ospf_header_tree, offset + 16 , 8, "Auth Data: %s", auth_data);
148 case OSPF_AUTH_CRYPT:
149 crypto = (e_ospf_crypto *)ospfh.auth_data;
150 proto_tree_add_text(ospf_header_tree, offset + 14 , 2, "Auth Type: crypt");
151 proto_tree_add_text(ospf_header_tree, offset + 18 , 1, "Auth Key ID: %d",
153 proto_tree_add_text(ospf_header_tree, offset + 19 , 1, "Auth Data Length: %d",
155 proto_tree_add_text(ospf_header_tree, offset + 20 , 4, "Auth Crypto Sequence Number: 0x%lx",
156 (unsigned long)ntohl(crypto->sequence_num));
158 ospflen = ntohs(ospfh.length);
159 for (i = 0; i < crypto->length && i < (sizeof(auth_data)/2); i++)
160 sprintf(&auth_data[i*2],"%02x",pd[offset + ospflen + i]);
161 proto_tree_add_text(ospf_header_tree, offset + ospflen , 16, "Auth Data: %s", auth_data);
164 proto_tree_add_text(ospf_header_tree, offset + 14 , 2, "Auth Type (unknown)");
165 proto_tree_add_text(ospf_header_tree, offset + 16 , 8, "Auth Data (unknown)");
170 /* Temporarily adjust the captured length to match the size of the OSPF
171 * packet (since the dissect routines use it to work out where the end of
172 * the ospf packet is).
174 saved_len = pi.captured_len;
175 if (BYTES_ARE_IN_FRAME(offset, ntohs(ospfh.length))) {
176 pi.captured_len = offset + ntohs(ospfh.length);
179 /* Skip over header */
180 offset += OSPF_HEADER_LENGTH;
182 switch(ospfh.packet_type){
184 dissect_ospf_hello(pd, offset, fd, ospf_tree);
187 dissect_ospf_db_desc(pd, offset, fd, ospf_tree);
190 dissect_ospf_ls_req(pd, offset, fd, ospf_tree);
193 dissect_ospf_ls_upd(pd, offset, fd, ospf_tree);
196 dissect_ospf_ls_ack(pd, offset, fd, ospf_tree);
199 pi.captured_len = saved_len;
200 dissect_data(pd, offset, fd, tree);
202 pi.captured_len = saved_len;
206 dissect_ospf_hello(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
207 e_ospf_hello ospfhello;
208 guint32 *ospfneighbor;
212 proto_tree *ospf_hello_tree;
215 memcpy(&ospfhello, &pd[offset], sizeof(e_ospf_hello));
218 ti = proto_tree_add_text(tree, offset, END_OF_FRAME, "OSPF Hello Packet");
219 ospf_hello_tree = proto_item_add_subtree(ti, ett_ospf_hello);
222 proto_tree_add_text(ospf_hello_tree, offset , 4, "Network Mask: %s", ip_to_str((guint8 *) &ospfhello.network_mask));
223 proto_tree_add_text(ospf_hello_tree, offset + 4, 2, "Hello Interval: %d seconds", ntohs(ospfhello.hellointervall));
225 /* ATTENTION !!! no check for length of options string */
227 if(( ospfhello.options & OSPF_OPTIONS_E ) == OSPF_OPTIONS_E){
228 strcpy( (char *)(options + options_offset), "E");
231 if(( ospfhello.options & OSPF_OPTIONS_MC ) == OSPF_OPTIONS_MC){
232 strcpy((char *) (options + options_offset), "/MC");
235 if(( ospfhello.options & OSPF_OPTIONS_NP ) == OSPF_OPTIONS_NP){
236 strcpy((char *) (options + options_offset), "/NP");
239 if(( ospfhello.options & OSPF_OPTIONS_EA ) == OSPF_OPTIONS_EA){
240 strcpy((char *) (options + options_offset) , "/EA");
243 if(( ospfhello.options & OSPF_OPTIONS_DC ) == OSPF_OPTIONS_DC){
244 strcpy((char *) (options + options_offset) , "/DC");
248 proto_tree_add_text(ospf_hello_tree, offset + 6, 1, "Options: %d (%s)", ospfhello.options, options);
249 proto_tree_add_text(ospf_hello_tree, offset + 7, 1, "Router Priority: %d", ospfhello.priority);
250 proto_tree_add_text(ospf_hello_tree, offset + 8, 4, "Router Dead Interval: %ld seconds", (long)ntohl(ospfhello.dead_interval));
251 proto_tree_add_text(ospf_hello_tree, offset + 12, 4, "Designated Router: %s", ip_to_str((guint8 *) &ospfhello.drouter));
252 proto_tree_add_text(ospf_hello_tree, offset + 16, 4, "Backup Designated Router: %s", ip_to_str((guint8 *) &ospfhello.bdrouter));
256 while(((int)(pi.captured_len - offset)) >= 4){
257 ospfneighbor=(guint32 *) &pd[offset];
258 proto_tree_add_text(ospf_hello_tree, offset, 4, "Active Neighbor: %s", ip_to_str((guint8 *) ospfneighbor));
265 dissect_ospf_db_desc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
272 proto_tree *ospf_db_desc_tree=NULL;
275 memcpy(&ospf_dbd, &pd[offset], sizeof(e_ospf_dbd));
278 ti = proto_tree_add_text(tree, offset, END_OF_FRAME, "OSPF DB Description");
279 ospf_db_desc_tree = proto_item_add_subtree(ti, ett_ospf_desc);
281 proto_tree_add_text(ospf_db_desc_tree, offset, 2, "Interface MTU: %d", ntohs(ospf_dbd.interface_mtu) );
285 if(( ospf_dbd.options & OSPF_OPTIONS_E ) == OSPF_OPTIONS_E){
286 strcpy( (char *)(options + options_offset), "_E_");
289 if(( ospf_dbd.options & OSPF_OPTIONS_MC ) == OSPF_OPTIONS_MC){
290 strcpy((char *) (options + options_offset), "_MC_");
293 if(( ospf_dbd.options & OSPF_OPTIONS_NP ) == OSPF_OPTIONS_NP){
294 strcpy((char *) (options + options_offset), "_NP_");
297 if(( ospf_dbd.options & OSPF_OPTIONS_EA ) == OSPF_OPTIONS_EA){
298 strcpy((char *) (options + options_offset) , "_EA_");
301 if(( ospf_dbd.options & OSPF_OPTIONS_DC ) == OSPF_OPTIONS_DC){
302 strcpy((char *) (options + options_offset) , "_DC_");
306 proto_tree_add_text(ospf_db_desc_tree, offset + 2 , 1, "Options: %d (%s)", ospf_dbd.options, options );
310 if(( ospf_dbd.flags & OSPF_DBD_FLAG_MS ) == OSPF_DBD_FLAG_MS){
311 strcpy( (char *)(flags + flags_offset), "_I_");
314 if(( ospf_dbd.flags & OSPF_DBD_FLAG_M ) == OSPF_DBD_FLAG_M){
315 strcpy((char *) (flags + flags_offset), "_M_");
318 if(( ospf_dbd.flags & OSPF_DBD_FLAG_I ) == OSPF_DBD_FLAG_I){
319 strcpy((char *) (flags + flags_offset), "_I_");
323 proto_tree_add_text(ospf_db_desc_tree, offset + 3 , 1, "Flags: %d (%s)", ospf_dbd.flags, flags );
324 proto_tree_add_text(ospf_db_desc_tree, offset + 4 , 4, "DD Sequence: %ld", (long)ntohl(ospf_dbd.dd_sequence) );
326 /* LS Headers will be processed here */
327 /* skip to the end of DB-Desc header */
329 while( ((int) (pi.captured_len - offset)) >= OSPF_LSA_HEADER_LENGTH ) {
330 dissect_ospf_lsa(pd, offset, fd, tree, FALSE);
331 offset+=OSPF_LSA_HEADER_LENGTH;
336 dissect_ospf_ls_req(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
337 e_ospf_ls_req ospf_lsr;
339 proto_tree *ospf_lsr_tree;
343 /* zero or more LS requests may be within a LS Request */
344 /* we place every request for a LSA in a single subtree */
346 while( ((int) (pi.captured_len - offset)) >= OSPF_LS_REQ_LENGTH ){
347 memcpy(&ospf_lsr, &pd[offset], sizeof(e_ospf_ls_req));
348 ti = proto_tree_add_text(tree, offset, OSPF_LS_REQ_LENGTH, "Link State Request");
349 ospf_lsr_tree = proto_item_add_subtree(ti, ett_ospf_lsr);
351 switch( ntohl( ospf_lsr.ls_type ) ){
352 case OSPF_LSTYPE_ROUTER:
353 proto_tree_add_text(ospf_lsr_tree, offset, 4, "LS Type: Router-LSA (%ld)",
354 (long)ntohl( ospf_lsr.ls_type ) );
356 case OSPF_LSTYPE_NETWORK:
357 proto_tree_add_text(ospf_lsr_tree, offset, 4, "LS Type: Network-LSA (%ld)",
358 (long)ntohl( ospf_lsr.ls_type ) );
360 case OSPF_LSTYPE_SUMMERY:
361 proto_tree_add_text(ospf_lsr_tree, offset, 4, "LS Type: Summary-LSA (IP network) (%ld)",
362 (long)ntohl( ospf_lsr.ls_type ) );
364 case OSPF_LSTYPE_ASBR:
365 proto_tree_add_text(ospf_lsr_tree, offset, 4, "LS Type: Summary-LSA (ASBR) (%ld)",
366 (long)ntohl( ospf_lsr.ls_type ) );
368 case OSPF_LSTYPE_ASEXT:
369 proto_tree_add_text(ospf_lsr_tree, offset, 4, "LS Type: AS-External-LSA (ASBR) (%ld)",
370 (long)ntohl( ospf_lsr.ls_type ) );
373 proto_tree_add_text(ospf_lsr_tree, offset, 4, "LS Type: %ld (unknown)",
374 (long)ntohl( ospf_lsr.ls_type ) );
377 proto_tree_add_text(ospf_lsr_tree, offset + 4, 4, "Link State ID : %s",
378 ip_to_str((guint8 *) &(ospf_lsr.ls_id)));
379 proto_tree_add_text(ospf_lsr_tree, offset + 8, 4, "Advertising Router : %s",
380 ip_to_str((guint8 *) &(ospf_lsr.adv_router)));
388 dissect_ospf_ls_upd(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
389 e_ospf_lsa_upd_hdr upd_hdr;
392 proto_tree *ospf_lsa_upd_tree=NULL;
395 memcpy(&upd_hdr, &pd[offset], sizeof(e_ospf_lsa_upd_hdr));
398 ti = proto_tree_add_text(tree, offset, END_OF_FRAME, "LS Update Packet");
399 ospf_lsa_upd_tree = proto_item_add_subtree(ti, ett_ospf_lsa_upd);
401 proto_tree_add_text(ospf_lsa_upd_tree, offset, 4, "Nr oF LSAs: %ld", (long)ntohl(upd_hdr.lsa_nr) );
403 /* skip to the beginning of the first LSA */
404 offset+=4; /* the LS Upd PAcket contains only a 32 bit #LSAs field */
407 while(lsa_counter < ntohl(upd_hdr.lsa_nr)){
408 offset+=dissect_ospf_lsa(pd, offset, fd, ospf_lsa_upd_tree, TRUE);
414 dissect_ospf_ls_ack(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
416 /* the body of a LS Ack packet simply contains zero or more LSA Headers */
417 while( ((int)(pi.captured_len - offset)) >= OSPF_LSA_HEADER_LENGTH ) {
418 dissect_ospf_lsa(pd, offset, fd, tree, FALSE);
419 offset+=OSPF_LSA_HEADER_LENGTH;
425 * Returns if an LSA is opaque, i.e. requires special treatment
427 int is_opaque(int lsa_type)
429 return (lsa_type >= 9 && lsa_type <= 11);
432 /* MPLS/TE TLV types */
433 #define MPLS_TLV_ROUTER 1
434 #define MPLS_TLV_LINK 2
436 /* MPLS/TE Link STLV types */
444 MPLS_LINK_MAX_RES_BW,
449 static value_string mpls_link_stlv_str[] = {
450 {MPLS_LINK_TYPE, "Link Type"},
451 {MPLS_LINK_ID, "Link ID"},
452 {MPLS_LINK_LOCAL_IF, "Local Interface IP Address"},
453 {MPLS_LINK_REMOTE_IF, "Remote Interface IP Address"},
454 {MPLS_LINK_TE_METRIC, "Traffic Engineering Metric"},
455 {MPLS_LINK_MAX_BW, "Maximum Bandwidth"},
456 {MPLS_LINK_MAX_RES_BW, "Maximum Reservable Bandwidth"},
457 {MPLS_LINK_UNRES_BW, "Unreserved Bandwidth"},
458 {MPLS_LINK_COLOR, "Resource Class/Color"},
462 * Dissect MPLS/TE opaque LSA
465 void dissect_ospf_lsa_mpls(const u_char *pd,
469 e_ospf_lsa_hdr *lsa_hdr) {
471 proto_tree *mpls_tree;
472 proto_tree *tlv_tree;
473 proto_tree *stlv_tree;
480 int stlv_type, stlv_len;
484 ti = proto_tree_add_text(tree, offset, ntohs(lsa_hdr->length) - 20,
485 "MPLS Traffic Engineering LSA");
486 mpls_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls);
488 for (length = 0; length < ntohs(lsa_hdr->length) - 20; length += 4) {
489 tlv_type = pntohs(pd+offset+length);
490 tlv_length = pntohs(pd+offset+length + 2);
493 case MPLS_TLV_ROUTER:
494 ti = proto_tree_add_text(mpls_tree, offset+length, tlv_length+4,
495 "Router Address: %s",
496 ip_to_str((pd+offset+length+4)));
497 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_router);
498 proto_tree_add_text(tlv_tree, offset+length, 2, "TLV Type: 1 - Router Address");
499 proto_tree_add_text(tlv_tree, offset+length+2, 2, "TLV Length: %d", tlv_length);
500 proto_tree_add_text(tlv_tree, offset+length+4, 4, "Router Address: %s",
501 ip_to_str((pd+offset+length+4)));
504 ti = proto_tree_add_text(mpls_tree, offset+length, tlv_length+4,
506 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
507 proto_tree_add_text(tlv_tree, offset+length, 2, "TLV Type: 2 - Link Information");
508 proto_tree_add_text(tlv_tree, offset+length+2, 2, "TLV Length: %d", tlv_length);
510 /* Walk down the sub-TLVs for link information */
511 for (link_len = length + 4; link_len < length + 4 + tlv_length; link_len += 4) {
512 stlv_type = pntohs(pd+offset+link_len);
513 stlv_len = pntohs(pd+offset+link_len + 2);
514 stlv_name = val_to_str(stlv_type, mpls_link_stlv_str, "Unknown sub-TLV");
518 ti = proto_tree_add_text(tlv_tree, offset+link_len, stlv_len+4,
520 *((guint8 *)pd + offset + link_len + 4));
521 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
522 proto_tree_add_text(stlv_tree, offset+link_len, 2,
523 "TLV Type: %d: %s", stlv_type, stlv_name);
524 proto_tree_add_text(stlv_tree, offset+link_len+2, 2, "TLV Length: %d", stlv_len);
525 proto_tree_add_text(stlv_tree, offset+link_len+4, 1, "%s: %d", stlv_name,
526 *((guint8 *)pd + offset + link_len + 4));
530 ti = proto_tree_add_text(tlv_tree, offset+link_len, stlv_len+4,
531 "%s: %s (%x)", stlv_name,
532 ip_to_str(pd + offset + link_len + 4),
533 pntohl(pd + offset + link_len + 4));
534 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
535 proto_tree_add_text(stlv_tree, offset+link_len, 2,
536 "TLV Type: %d: %s", stlv_type, stlv_name);
537 proto_tree_add_text(stlv_tree, offset+link_len+2, 2, "TLV Length: %d", stlv_len);
538 proto_tree_add_text(stlv_tree, offset+link_len+4, 4, "%s: %s (%x)", stlv_name,
539 ip_to_str(pd + offset + link_len + 4),
540 pntohl(pd + offset + link_len + 4));
543 case MPLS_LINK_LOCAL_IF:
544 case MPLS_LINK_REMOTE_IF:
545 ti = proto_tree_add_text(tlv_tree, offset+link_len, stlv_len+4,
547 ip_to_str(pd+offset+link_len+4));
548 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
549 proto_tree_add_text(stlv_tree, offset+link_len, 2,
550 "TLV Type: %d: %s", stlv_type, stlv_name);
551 proto_tree_add_text(stlv_tree, offset+link_len+2, 2, "TLV Length: %d", stlv_len);
552 proto_tree_add_text(stlv_tree, offset+link_len+4, 4, "%s: %s", stlv_name,
553 ip_to_str(pd+offset+link_len+4));
557 case MPLS_LINK_TE_METRIC:
558 case MPLS_LINK_COLOR:
559 ti = proto_tree_add_text(tlv_tree, offset+link_len, stlv_len+4,
561 pntohl(pd + offset + link_len + 4));
562 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
563 proto_tree_add_text(stlv_tree, offset+link_len, 2,
564 "TLV Type: %d: %s", stlv_type, stlv_name);
565 proto_tree_add_text(stlv_tree, offset+link_len+2, 2, "TLV Length: %d", stlv_len);
566 proto_tree_add_text(stlv_tree, offset+link_len+4, 4, "%s: %d", stlv_name,
567 pntohl(pd + offset + link_len + 4));
570 case MPLS_LINK_MAX_BW:
571 case MPLS_LINK_MAX_RES_BW:
572 ti = proto_tree_add_text(tlv_tree, offset+link_len, stlv_len+4,
573 "%s: %ld", stlv_name,
574 pieee_to_long(pd + offset + link_len + 4));
575 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
576 proto_tree_add_text(stlv_tree, offset+link_len, 2,
577 "TLV Type: %d: %s", stlv_type, stlv_name);
578 proto_tree_add_text(stlv_tree, offset+link_len+2, 2, "TLV Length: %d", stlv_len);
579 proto_tree_add_text(stlv_tree, offset+link_len+4, 4, "%s: %ld", stlv_name,
580 pieee_to_long(pd + offset + link_len + 4));
583 case MPLS_LINK_UNRES_BW:
584 ti = proto_tree_add_text(tlv_tree, offset+link_len, stlv_len+4,
586 stlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link_stlv);
587 proto_tree_add_text(stlv_tree, offset+link_len, 2,
588 "TLV Type: %d: %s", stlv_type, stlv_name);
589 proto_tree_add_text(stlv_tree, offset+link_len+2, 2, "TLV Length: %d", stlv_len);
591 proto_tree_add_text(stlv_tree, offset+link_len+4+(i*4), 4,
593 pieee_to_long(pd + offset + link_len + 4 + i*4));
597 proto_tree_add_text(tlv_tree, offset+link_len, stlv_len+4,
598 "Unknown Link sub-TLV: %d", stlv_type);
600 link_len += ((stlv_len+3)/4)*4;
606 ti = proto_tree_add_text(mpls_tree, offset+length, tlv_length+4,
607 "Unknown LSA: %d", tlv_type);
608 tlv_tree = proto_item_add_subtree(ti, ett_ospf_lsa_mpls_link);
609 proto_tree_add_text(tlv_tree, offset+length, 2, "TLV Type: %d - Unknown", tlv_type);
610 proto_tree_add_text(tlv_tree, offset+length+2, 2, "TLV Length: %d", tlv_length);
611 proto_tree_add_text(tlv_tree, offset+length+4, tlv_length, "TLV Data");
615 length += tlv_length;
621 * Dissect opaque LSAs
623 void dissect_ospf_lsa_opaque(const u_char *pd,
627 e_ospf_lsa_hdr *lsa_hdr) {
628 guint8 opaque_id = *((guint8 *) &(lsa_hdr->ls_id));
632 case OSPF_LSA_MPLS_TE:
633 dissect_ospf_lsa_mpls(pd, offset, fd, tree, lsa_hdr);
637 proto_tree_add_text(tree, offset, END_OF_FRAME, "Unknown LSA Type");
639 } /* switch on opaque LSA id */
643 dissect_ospf_lsa(const u_char *pd, int offset, frame_data *fd, proto_tree *tree, int disassemble_body) {
644 e_ospf_lsa_hdr lsa_hdr;
648 /* data strutures for the router LSA */
649 e_ospf_router_lsa router_lsa;
650 e_ospf_router_data router_data;
651 e_ospf_router_metric tos_data;
652 guint16 link_counter;
657 /* data structures for the network lsa */
658 e_ospf_network_lsa network_lsa;
659 guint32 *attached_router;
661 /* data structures for the summary and ASBR LSAs */
662 e_ospf_summary_lsa summary_lsa;
664 /* data structures for the AS-External LSA */
665 e_ospf_asexternal_lsa asext_lsa;
666 guint32 asext_metric;
668 /* data structures for opaque LSA */
671 proto_tree *ospf_lsa_tree;
674 memcpy(&lsa_hdr, &pd[offset], sizeof(e_ospf_lsa_hdr));
678 switch(lsa_hdr.ls_type) {
679 case OSPF_LSTYPE_ROUTER:
680 lsa_type="Router LSA";
682 case OSPF_LSTYPE_NETWORK:
683 lsa_type="Network LSA";
685 case OSPF_LSTYPE_SUMMERY:
686 lsa_type="Summary LSA";
688 case OSPF_LSTYPE_ASBR:
691 case OSPF_LSTYPE_ASEXT:
692 lsa_type="AS-external-LSA";
694 case OSPF_LSTYPE_OP_LINKLOCAL:
695 lsa_type="Opaque LSA, Link-local scope";
697 case OSPF_LSTYPE_OP_AREALOCAL:
698 lsa_type="Opaque LSA, Area-local scope";
700 case OSPF_LSTYPE_OP_ASWIDE:
701 lsa_type="Opaque LSA, AS-wide scope";
708 if(disassemble_body){
709 ti = proto_tree_add_text(tree, offset, ntohs(lsa_hdr.length),
710 "%s (Type: %d)", lsa_type, lsa_hdr.ls_type);
712 ti = proto_tree_add_text(tree, offset, OSPF_LSA_HEADER_LENGTH, "LSA Header");
714 ospf_lsa_tree = proto_item_add_subtree(ti, ett_ospf_lsa);
717 proto_tree_add_text(ospf_lsa_tree, offset, 2, "LS Age: %d seconds", ntohs(lsa_hdr.ls_age));
718 proto_tree_add_text(ospf_lsa_tree, offset + 2, 1, "Options: %d ", lsa_hdr.options);
719 proto_tree_add_text(ospf_lsa_tree, offset + 3, 1, "LSA Type: %d (%s)", lsa_hdr.ls_type, lsa_type);
721 if (is_opaque(lsa_hdr.ls_type)) {
722 ls_id = ntohl(lsa_hdr.ls_id);
723 proto_tree_add_text(ospf_lsa_tree, offset + 4, 1, "Link State ID Opaque Type: %u ",
724 (ls_id >> 24) & 0xff);
725 proto_tree_add_text(ospf_lsa_tree, offset + 5, 3, "Link State ID Opaque ID: %u ",
728 proto_tree_add_text(ospf_lsa_tree, offset + 4, 4, "Link State ID: %s ",
729 ip_to_str((guint8 *) &(lsa_hdr.ls_id)));
731 proto_tree_add_text(ospf_lsa_tree, offset + 8, 4, "Advertising Router: %s ",
732 ip_to_str((guint8 *) &(lsa_hdr.adv_router)));
733 proto_tree_add_text(ospf_lsa_tree, offset + 12, 4, "LS Sequence Number: 0x%04lx ",
734 (unsigned long)ntohl(lsa_hdr.ls_seq));
735 proto_tree_add_text(ospf_lsa_tree, offset + 16, 2, "LS Checksum: %d ", ntohs(lsa_hdr.ls_checksum));
737 proto_tree_add_text(ospf_lsa_tree, offset + 18, 2, "Length: %d ", ntohs(lsa_hdr.length));
739 if(!disassemble_body){
740 return OSPF_LSA_HEADER_LENGTH;
743 lsa_end = offset + ntohs(lsa_hdr.length);
744 /* the LSA body starts after 20 bytes of LSA Header */
747 switch(lsa_hdr.ls_type){
748 case(OSPF_LSTYPE_ROUTER):
749 memcpy(&router_lsa, &pd[offset], sizeof(e_ospf_router_lsa));
751 /* again: flags should be secified in detail */
752 proto_tree_add_text(ospf_lsa_tree, offset, 1, "Flags: 0x%02x ", router_lsa.flags);
753 proto_tree_add_text(ospf_lsa_tree, offset + 2, 2, "Nr. of Links: %d ",
754 ntohs(router_lsa.nr_links));
756 /* router_lsa.nr_links links follow
757 * maybe we should put each of the links into its own subtree ???
759 for(link_counter = 1 ; link_counter <= ntohs(router_lsa.nr_links); link_counter++){
761 memcpy(&router_data, &pd[offset], sizeof(e_ospf_router_data));
762 /* check the Link Type and ID */
763 switch(router_data.link_type) {
765 link_type="Point-to-point connection to another router";
766 link_id="Neighboring router's Router ID";
768 case OSPF_LINK_TRANSIT:
769 link_type="Connection to a transit network";
770 link_id="IP address of Designated Router";
773 link_type="Connection to a stub network";
774 link_id="IP network/subnet number";
776 case OSPF_LINK_VIRTUAL:
777 link_type="Virtual link";
778 link_id="Neighboring router's Router ID";
781 link_type="unknown link type";
782 link_id="unknown link id";
785 proto_tree_add_text(ospf_lsa_tree, offset, 4, "%s: %s", link_id,
786 ip_to_str((guint8 *) &(router_data.link_id)));
788 /* link_data should be specified in detail (e.g. network mask) (depends on link type)*/
789 proto_tree_add_text(ospf_lsa_tree, offset + 4, 4, "Link Data: %s",
790 ip_to_str((guint8 *) &(router_data.link_data)));
792 proto_tree_add_text(ospf_lsa_tree, offset + 8, 1, "Link Type: %d - %s",
793 router_data.link_type, link_type);
794 proto_tree_add_text(ospf_lsa_tree, offset + 9, 1, "Nr. of TOS metrics: %d", router_data.nr_tos);
795 proto_tree_add_text(ospf_lsa_tree, offset + 10, 2, "TOS 0 metric: %d", ntohs( router_data.tos0_metric ));
799 /* router_data.nr_tos metrics may follow each link
800 * ATTENTION: TOS metrics are not tested (I don't have TOS based routing)
801 * please send me a mail if it is/isn't working
804 for(tos_counter = 1 ; link_counter <= ntohs(router_data.nr_tos); tos_counter++){
805 memcpy(&tos_data, &pd[offset], sizeof(e_ospf_router_metric));
806 proto_tree_add_text(ospf_lsa_tree, offset, 1, "TOS: %d, Metric: %d",
807 tos_data.tos, ntohs(tos_data.metric));
812 case(OSPF_LSTYPE_NETWORK):
813 memcpy(&network_lsa, &pd[offset], sizeof(e_ospf_network_lsa));
814 proto_tree_add_text(ospf_lsa_tree, offset, 4, "Netmask: %s",
815 ip_to_str((guint8 *) &(network_lsa.network_mask)));
818 while( (lsa_end - offset) >= 4){
819 attached_router = (guint32 *) &pd[offset];
820 proto_tree_add_text(ospf_lsa_tree, offset, 4, "Attached Router: %s",
821 ip_to_str((guint8 *) attached_router));
825 case(OSPF_LSTYPE_SUMMERY):
826 /* Type 3 and 4 LSAs have the same format */
827 case(OSPF_LSTYPE_ASBR):
828 memcpy(&summary_lsa, &pd[offset], sizeof(e_ospf_summary_lsa));
829 proto_tree_add_text(ospf_lsa_tree, offset, 4, "Netmask: %s",
830 ip_to_str((guint8 *) &(summary_lsa.network_mask)));
831 /* returns only the TOS 0 metric (even if there are more TOS metrics) */
833 case(OSPF_LSTYPE_ASEXT):
834 memcpy(&summary_lsa, &pd[offset], sizeof(e_ospf_summary_lsa));
835 proto_tree_add_text(ospf_lsa_tree, offset, 4, "Netmask: %s",
836 ip_to_str((guint8 *) &(summary_lsa.network_mask)));
838 /* asext_lsa = (e_ospf_asexternal_lsa *) &pd[offset + 4]; */
839 memcpy(&asext_lsa, &pd[offset + 4], sizeof(asext_lsa));
840 if( (asext_lsa.options & 128) == 128 ) { /* check wether or not E bit is set */
841 proto_tree_add_text(ospf_lsa_tree, offset, 1,
842 "External Type: Type 2 (metric is larger than any other link state path)");
844 proto_tree_add_text(ospf_lsa_tree, offset + 4, 1,
845 "External Type: Type 1 (metric is specified in the same units as interface cost)");
847 /* the metric field of a AS-external LAS is specified in 3 bytes -> not well aligned */
848 /* this routine returns only the TOS 0 metric (even if there are more TOS metrics) */
849 memcpy(&asext_metric, &pd[offset+4], 4);
851 /* erase the leading 8 bits (the dont belong to the metric */
852 asext_metric = ntohl(asext_metric) & 0x00ffffff ;
854 proto_tree_add_text(ospf_lsa_tree, offset + 5, 3,"Metric: %d", asext_metric);
855 proto_tree_add_text(ospf_lsa_tree, offset + 8, 4,"Forwarding Address: %s",
856 ip_to_str((guint8 *) &(asext_lsa.gateway)));
857 proto_tree_add_text(ospf_lsa_tree, offset + 12, 4,"External Route Tag: %ld", (long)ntohl(asext_lsa.external_tag));
861 case OSPF_LSTYPE_OP_LINKLOCAL:
862 case OSPF_LSTYPE_OP_AREALOCAL:
863 case OSPF_LSTYPE_OP_ASWIDE:
864 dissect_ospf_lsa_opaque(pd, offset, fd, ospf_lsa_tree, &lsa_hdr);
868 /* unknown LSA type */
869 proto_tree_add_text(ospf_lsa_tree, offset, END_OF_FRAME, "Unknown LSA Type");
872 /* return the length of this LSA */
873 return ntohs(lsa_hdr.length);
877 proto_register_ospf(void)
879 /* static hf_register_info hf[] = {
881 { "Name", "ospf.abbreviation", TYPE, VALS_POINTER }},
883 static gint *ett[] = {
892 &ett_ospf_lsa_mpls_router,
893 &ett_ospf_lsa_mpls_link,
894 &ett_ospf_lsa_mpls_link_stlv
897 proto_ospf = proto_register_protocol("Open Shortest Path First", "ospf");
898 /* proto_register_field_array(proto_ospf, hf, array_length(hf));*/
899 proto_register_subtree_array(ett, array_length(ett));
903 proto_reg_handoff_ospf(void)
905 dissector_add("ip.proto", IP_PROTO_OSPF, dissect_ospf);