1 /* $NetBSD: print-ospf.c,v 1.5 2007/07/24 11:53:46 drochner Exp $ */
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
26 #include <sys/cdefs.h>
29 static const char rcsid
[] _U_
=
30 "@(#) Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.56.2.4 2006/12/13 08:24:27 hannes Exp (LBL)";
32 __RCSID("$NetBSD: print-ospf.c,v 1.5 2007/07/24 11:53:46 drochner Exp $");
40 #include <tcpdump-stdinc.h>
44 #include "interface.h"
45 #include "addrtoname.h"
53 static struct tok ospf_option_values
[] = {
54 { OSPF_OPTION_T
, "TOS" },
55 { OSPF_OPTION_E
, "External" },
56 { OSPF_OPTION_MC
, "Multicast" },
57 { OSPF_OPTION_NP
, "NSSA" },
58 { OSPF_OPTION_EA
, "Advertise External" },
59 { OSPF_OPTION_DC
, "Demand Circuit" },
60 { OSPF_OPTION_O
, "Opaque" },
61 { OSPF_OPTION_DN
, "Up/Down" },
65 static struct tok ospf_authtype_values
[] = {
66 { OSPF_AUTH_NONE
, "none" },
67 { OSPF_AUTH_SIMPLE
, "simple" },
68 { OSPF_AUTH_MD5
, "MD5" },
72 static struct tok ospf_rla_flag_values
[] = {
73 { RLA_FLAG_B
, "ABR" },
74 { RLA_FLAG_E
, "ASBR" },
75 { RLA_FLAG_W1
, "Virtual" },
76 { RLA_FLAG_W2
, "W2" },
80 static struct tok type2str
[] = {
81 { OSPF_TYPE_UMD
, "UMD" },
82 { OSPF_TYPE_HELLO
, "Hello" },
83 { OSPF_TYPE_DD
, "Database Description" },
84 { OSPF_TYPE_LS_REQ
, "LS-Request" },
85 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
86 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
90 static struct tok lsa_values
[] = {
91 { LS_TYPE_ROUTER
, "Router" },
92 { LS_TYPE_NETWORK
, "Network" },
93 { LS_TYPE_SUM_IP
, "Summary" },
94 { LS_TYPE_SUM_ABR
, "ASBR Summary" },
95 { LS_TYPE_ASE
, "External" },
96 { LS_TYPE_GROUP
, "Multicast Group" },
97 { LS_TYPE_NSSA
, "NSSA" },
98 { LS_TYPE_OPAQUE_LL
, "Link Local Opaque" },
99 { LS_TYPE_OPAQUE_AL
, "Area Local Opaque" },
100 { LS_TYPE_OPAQUE_DW
, "Domain Wide Opaque" },
104 static struct tok ospf_dd_flag_values
[] = {
105 { OSPF_DB_INIT
, "Init" },
106 { OSPF_DB_MORE
, "More" },
107 { OSPF_DB_MASTER
, "Master" },
111 static struct tok lsa_opaque_values
[] = {
112 { LS_OPAQUE_TYPE_TE
, "Traffic Engineering" },
113 { LS_OPAQUE_TYPE_GRACE
, "Graceful restart" },
114 { LS_OPAQUE_TYPE_RI
, "Router Information" },
118 static struct tok lsa_opaque_te_tlv_values
[] = {
119 { LS_OPAQUE_TE_TLV_ROUTER
, "Router Address" },
120 { LS_OPAQUE_TE_TLV_LINK
, "Link" },
124 static struct tok lsa_opaque_te_link_tlv_subtlv_values
[] = {
125 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
, "Link Type" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
, "Link ID" },
127 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
, "Local Interface IP address" },
128 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
, "Remote Interface IP address" },
129 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
, "Traffic Engineering Metric" },
130 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
, "Maximum Bandwidth" },
131 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
, "Maximum Reservable Bandwidth" },
132 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
, "Unreserved Bandwidth" },
133 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
, "Administrative Group" },
134 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
, "Link Local/Remote Identifier" },
135 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
, "Link Protection Type" },
136 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
, "Interface Switching Capability" },
137 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
, "Shared Risk Link Group" },
138 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
, "Bandwidth Constraints" },
142 static struct tok lsa_opaque_grace_tlv_values
[] = {
143 { LS_OPAQUE_GRACE_TLV_PERIOD
, "Grace Period" },
144 { LS_OPAQUE_GRACE_TLV_REASON
, "Graceful restart Reason" },
145 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS
, "IPv4 interface address" },
149 static struct tok lsa_opaque_grace_tlv_reason_values
[] = {
150 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN
, "Unknown" },
151 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART
, "Software Restart" },
152 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE
, "Software Reload/Upgrade" },
153 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH
, "Control Processor Switch" },
157 static struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values
[] = {
158 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP
, "Point-to-point" },
159 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA
, "Multi-Access" },
163 static struct tok lsa_opaque_ri_tlv_values
[] = {
164 { LS_OPAQUE_RI_TLV_CAP
, "Router Capabilities" },
168 static struct tok lsa_opaque_ri_tlv_cap_values
[] = {
173 { 16, "graceful restart capable" },
174 { 32, "graceful restart helper" },
175 { 64, "Stub router support" },
176 { 128, "Traffic engineering" },
177 { 256, "p2p over LAN" },
178 { 512, "path computation server" },
182 static char tstr
[] = " [|ospf]";
185 #define inline __inline
188 static int ospf_print_lshdr(const struct lsa_hdr
*);
189 static const u_char
*ospf_print_lsa(const struct lsa
*);
190 static int ospf_decode_v2(const struct ospfhdr
*, const u_char
*);
193 ospf_print_lshdr(register const struct lsa_hdr
*lshp
)
197 TCHECK(lshp
->ls_length
);
198 ls_length
= EXTRACT_16BITS(&lshp
->ls_length
);
199 if (ls_length
< sizeof(struct lsa_hdr
)) {
200 printf("\n\t Bogus length %u < %lu", ls_length
,
201 (unsigned long)sizeof(struct lsa_hdr
));
205 TCHECK(lshp
->ls_seq
); /* XXX - ls_length check checked this */
206 printf("\n\t Advertising Router: %s, seq 0x%08x, age %us, length: %u",
207 ipaddr_string(&lshp
->ls_router
),
208 EXTRACT_32BITS(&lshp
->ls_seq
),
209 EXTRACT_16BITS(&lshp
->ls_age
),
210 ls_length
-(u_int
)sizeof(struct lsa_hdr
));
212 TCHECK(lshp
->ls_type
); /* XXX - ls_length check checked this */
213 switch (lshp
->ls_type
) {
214 /* the LSA header for opaque LSAs was slightly changed */
215 case LS_TYPE_OPAQUE_LL
:
216 case LS_TYPE_OPAQUE_AL
:
217 case LS_TYPE_OPAQUE_DW
:
218 printf("\n\t %s LSA (%d), Opaque-Type: %s LSA (%u), Opaque-ID: %u",
219 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
222 tok2str(lsa_opaque_values
,
224 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
225 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
),
226 EXTRACT_24BITS(&lshp
->un_lsa_id
.opaque_field
.opaque_id
)
231 /* all other LSA types use regular style LSA headers */
233 printf("\n\t %s LSA (%d), LSA-ID: %s",
234 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
236 ipaddr_string(&lshp
->un_lsa_id
.lsa_id
));
240 TCHECK(lshp
->ls_options
); /* XXX - ls_length check checked this */
241 printf("\n\t Options: [%s]", bittok2str(ospf_option_values
,"none",lshp
->ls_options
));
249 * Print a single link state advertisement. If truncated or if LSA length
250 * field is less than the length of the LSA header, return NULl, else
251 * return pointer to data past end of LSA.
253 static const u_int8_t
*
254 ospf_print_lsa(register const struct lsa
*lsap
)
256 register const u_int8_t
*ls_end
;
257 register const struct rlalink
*rlp
;
258 register const struct tos_metric
*tosp
;
259 register const struct in_addr
*ap
;
260 register const struct aslametric
*almp
;
261 register const struct mcla
*mcp
;
262 register const u_int32_t
*lp
;
263 register int j
, k
, tlv_type
, tlv_length
, subtlv_type
, subtlv_length
, priority_level
, te_class
;
264 register int ls_length
;
265 const u_int8_t
*tptr
;
267 union { /* int to float conversion buffer for several subTLVs */
272 tptr
= (u_int8_t
*)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
273 ls_length
= ospf_print_lshdr(&lsap
->ls_hdr
);
276 ls_end
= (u_int8_t
*)lsap
+ ls_length
;
277 ls_length
-= sizeof(struct lsa_hdr
);
279 switch (lsap
->ls_hdr
.ls_type
) {
282 TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
283 printf("\n\t Router LSA Options: [%s]", bittok2str(ospf_rla_flag_values
,"none",lsap
->lsa_un
.un_rla
.rla_flags
));
285 TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
286 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
287 TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
288 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
291 switch (rlp
->link_type
) {
293 case RLA_TYPE_VIRTUAL
:
294 printf("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
295 ipaddr_string(&rlp
->link_id
),
296 ipaddr_string(&rlp
->link_data
));
299 case RLA_TYPE_ROUTER
:
300 printf("\n\t Neighbor Router-ID: %s, Interface Address: %s",
301 ipaddr_string(&rlp
->link_id
),
302 ipaddr_string(&rlp
->link_data
));
305 case RLA_TYPE_TRANSIT
:
306 printf("\n\t Neighbor Network-ID: %s, Interface Address: %s",
307 ipaddr_string(&rlp
->link_id
),
308 ipaddr_string(&rlp
->link_data
));
312 printf("\n\t Stub Network: %s, Mask: %s",
313 ipaddr_string(&rlp
->link_id
),
314 ipaddr_string(&rlp
->link_data
));
318 printf("\n\t Unknown Router Link Type (%u)",
322 printf(", tos 0, metric: %d", EXTRACT_16BITS(&rlp
->link_tos0metric
));
323 tosp
= (struct tos_metric
*)
324 ((sizeof rlp
->link_tos0metric
) + (u_char
*) rlp
);
325 for (k
= 0; k
< (int) rlp
->link_toscount
; ++k
, ++tosp
) {
327 printf(", tos %d, metric: %d",
329 EXTRACT_16BITS(&tosp
->tos_metric
));
331 rlp
= (struct rlalink
*)((u_char
*)(rlp
+ 1) +
332 ((rlp
->link_toscount
) * sizeof(*tosp
)));
336 case LS_TYPE_NETWORK
:
337 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
338 printf("\n\t Mask %s\n\t Connected Routers:",
339 ipaddr_string(&lsap
->lsa_un
.un_nla
.nla_mask
));
340 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
341 while ((u_char
*)ap
< ls_end
) {
343 printf("\n\t %s", ipaddr_string(ap
));
349 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
350 printf("\n\t Mask %s",
351 ipaddr_string(&lsap
->lsa_un
.un_sla
.sla_mask
));
352 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
353 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
354 /* suppress tos if its not supported */
355 if(!((lsap
->ls_hdr
.ls_options
)&OSPF_OPTION_T
)) {
356 printf(", metric: %u", EXTRACT_32BITS(lp
)&SLA_MASK_METRIC
);
359 while ((u_char
*)lp
< ls_end
) {
360 register u_int32_t ul
;
363 ul
= EXTRACT_32BITS(lp
);
364 printf(", tos %d metric %d",
365 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
366 ul
& SLA_MASK_METRIC
);
371 case LS_TYPE_SUM_ABR
:
372 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
373 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
374 /* suppress tos if its not supported */
375 if(!((lsap
->ls_hdr
.ls_options
)&OSPF_OPTION_T
)) {
376 printf(", metric: %u", EXTRACT_32BITS(lp
)&SLA_MASK_METRIC
);
379 while ((u_char
*)lp
< ls_end
) {
380 register u_int32_t ul
;
383 ul
= EXTRACT_32BITS(lp
);
384 printf(", tos %d metric %d",
385 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
386 ul
& SLA_MASK_METRIC
);
392 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
393 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
394 printf("\n\t Mask %s",
395 ipaddr_string(&lsap
->lsa_un
.un_asla
.asla_mask
));
397 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
398 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
399 while ((u_char
*)almp
< ls_end
) {
400 register u_int32_t ul
;
402 TCHECK(almp
->asla_tosmetric
);
403 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
404 printf(", type %d, tos %d metric:",
405 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1,
406 (ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
407 if ((ul
& ASLA_MASK_METRIC
)==0xffffff)
410 printf(" %d", (ul
& ASLA_MASK_METRIC
));
412 TCHECK(almp
->asla_forward
);
413 if (almp
->asla_forward
.s_addr
) {
414 printf(", forward %s",
415 ipaddr_string(&almp
->asla_forward
));
417 TCHECK(almp
->asla_tag
);
418 if (almp
->asla_tag
.s_addr
) {
420 ipaddr_string(&almp
->asla_tag
));
427 /* Multicast extensions as of 23 July 1991 */
428 mcp
= lsap
->lsa_un
.un_mcla
;
429 while ((u_char
*)mcp
< ls_end
) {
430 TCHECK(mcp
->mcla_vid
);
431 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
433 case MCLA_VERTEX_ROUTER
:
434 printf("\n\t Router Router-ID %s",
435 ipaddr_string(&mcp
->mcla_vid
));
438 case MCLA_VERTEX_NETWORK
:
439 printf("\n\t Network Designated Router %s",
440 ipaddr_string(&mcp
->mcla_vid
));
444 printf("\n\t unknown VertexType (%u)",
445 EXTRACT_32BITS(&mcp
->mcla_vtype
));
452 case LS_TYPE_OPAQUE_LL
: /* fall through */
453 case LS_TYPE_OPAQUE_AL
:
454 case LS_TYPE_OPAQUE_DW
:
456 switch (*(&lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
457 case LS_OPAQUE_TYPE_RI
:
458 tptr
= (u_int8_t
*)(&lsap
->lsa_un
.un_ri_tlv
.type
);
460 while (ls_length
!= 0) {
463 printf("\n\t Remaining LS length %u < 4", ls_length
);
466 tlv_type
= EXTRACT_16BITS(tptr
);
467 tlv_length
= EXTRACT_16BITS(tptr
+2);
471 printf("\n\t %s TLV (%u), length: %u, value: ",
472 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
476 if (tlv_length
> ls_length
) {
477 printf("\n\t Bogus length %u > %u", tlv_length
,
481 ls_length
-=tlv_length
;
482 TCHECK2(*tptr
, tlv_length
);
485 case LS_OPAQUE_RI_TLV_CAP
:
486 if (tlv_length
!= 4) {
487 printf("\n\t Bogus length %u != 4", tlv_length
);
490 printf("Capabilities: %s",
491 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", EXTRACT_32BITS(tptr
)));
495 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
505 case LS_OPAQUE_TYPE_GRACE
:
506 tptr
= (u_int8_t
*)(&lsap
->lsa_un
.un_grace_tlv
.type
);
508 while (ls_length
!= 0) {
511 printf("\n\t Remaining LS length %u < 4", ls_length
);
514 tlv_type
= EXTRACT_16BITS(tptr
);
515 tlv_length
= EXTRACT_16BITS(tptr
+2);
519 printf("\n\t %s TLV (%u), length: %u, value: ",
520 tok2str(lsa_opaque_grace_tlv_values
,"unknown",tlv_type
),
524 if (tlv_length
> ls_length
) {
525 printf("\n\t Bogus length %u > %u", tlv_length
,
529 ls_length
-=tlv_length
;
530 TCHECK2(*tptr
, tlv_length
);
533 case LS_OPAQUE_GRACE_TLV_PERIOD
:
534 if (tlv_length
!= 4) {
535 printf("\n\t Bogus length %u != 4", tlv_length
);
538 printf("%us",EXTRACT_32BITS(tptr
));
540 case LS_OPAQUE_GRACE_TLV_REASON
:
541 if (tlv_length
!= 1) {
542 printf("\n\t Bogus length %u != 1", tlv_length
);
546 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", *tptr
),
549 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
550 if (tlv_length
!= 4) {
551 printf("\n\t Bogus length %u != 4", tlv_length
);
554 printf("%s", ipaddr_string(tptr
));
558 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
568 case LS_OPAQUE_TYPE_TE
:
569 tptr
= (u_int8_t
*)(&lsap
->lsa_un
.un_te_lsa_tlv
.type
);
571 while (ls_length
!= 0) {
574 printf("\n\t Remaining LS length %u < 4", ls_length
);
577 tlv_type
= EXTRACT_16BITS(tptr
);
578 tlv_length
= EXTRACT_16BITS(tptr
+2);
582 printf("\n\t %s TLV (%u), length: %u",
583 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
587 if (tlv_length
> ls_length
) {
588 printf("\n\t Bogus length %u > %u", tlv_length
,
592 ls_length
-=tlv_length
;
594 case LS_OPAQUE_TE_TLV_LINK
:
595 while (tlv_length
!= 0) {
596 if (tlv_length
< 4) {
597 printf("\n\t Remaining TLV length %u < 4",
602 subtlv_type
= EXTRACT_16BITS(tptr
);
603 subtlv_length
= EXTRACT_16BITS(tptr
+2);
607 printf("\n\t %s subTLV (%u), length: %u",
608 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
612 TCHECK2(*tptr
, subtlv_length
);
613 switch(subtlv_type
) {
614 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
615 printf(", 0x%08x", EXTRACT_32BITS(tptr
));
617 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
618 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
619 printf(", %s (0x%08x)",
621 EXTRACT_32BITS(tptr
));
622 if (subtlv_length
== 8) /* draft-ietf-ccamp-ospf-gmpls-extensions */
623 printf(", %s (0x%08x)",
624 ipaddr_string(tptr
+4),
625 EXTRACT_32BITS(tptr
+4));
627 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
628 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
629 printf(", %s", ipaddr_string(tptr
));
631 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
632 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
633 bw
.i
= EXTRACT_32BITS(tptr
);
634 printf(", %.3f Mbps", bw
.f
*8/1000000 );
636 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
637 for (te_class
= 0; te_class
< 8; te_class
++) {
638 bw
.i
= EXTRACT_32BITS(tptr
+te_class
*4);
639 printf("\n\t\tTE-Class %u: %.3f Mbps",
644 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
645 printf("\n\t\tBandwidth Constraints Model ID: %s (%u)",
646 tok2str(diffserv_te_bc_values
, "unknown", *tptr
),
648 /* decode BCs until the subTLV ends */
649 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
650 bw
.i
= EXTRACT_32BITS(tptr
+4+te_class
*4);
651 printf("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
656 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
657 printf(", Metric %u", EXTRACT_32BITS(tptr
));
659 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
660 printf(", %s, Priority %u",
661 bittok2str(gmpls_link_prot_values
, "none", *tptr
),
664 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
665 printf("\n\t\tInterface Switching Capability: %s",
666 tok2str(gmpls_switch_cap_values
, "Unknown", *(tptr
)));
667 printf("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
668 tok2str(gmpls_encoding_values
, "Unknown", *(tptr
+1)));
669 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
670 bw
.i
= EXTRACT_32BITS(tptr
+4+(priority_level
*4));
671 printf("\n\t\t priority level %d: %.3f Mbps",
676 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
678 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",*tptr
),
682 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
683 count_srlg
= subtlv_length
/ 4;
685 printf("\n\t\t Shared risk group: ");
686 while (count_srlg
> 0) {
687 bw
.i
= EXTRACT_32BITS(tptr
);
698 if(!print_unknown_data(tptr
,"\n\t\t",subtlv_length
))
703 /* in OSPF everything has to be 32-bit aligned, including TLVs */
704 if (subtlv_length
%4 != 0)
705 subtlv_length
+=4-(subtlv_length
%4);
707 tlv_length
-=subtlv_length
;
713 case LS_OPAQUE_TE_TLV_ROUTER
:
714 if (tlv_length
< 4) {
715 printf("\n\t TLV length %u < 4", tlv_length
);
719 printf(", %s", ipaddr_string(tptr
));
724 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
736 if(!print_unknown_data((u_int8_t
*)lsap
->lsa_un
.un_unknown
,
743 /* do we want to see an additionally hexdump ? */
745 if(!print_unknown_data((u_int8_t
*)lsap
->lsa_un
.un_unknown
,
746 "\n\t ", ls_length
)) {
756 ospf_decode_v2(register const struct ospfhdr
*op
,
757 register const u_char
*dataend
)
759 register const struct in_addr
*ap
;
760 register const struct lsr
*lsrp
;
761 register const struct lsa_hdr
*lshp
;
762 register const struct lsa
*lsap
;
763 register u_int32_t lsa_count
,lsa_count_max
;
765 switch (op
->ospf_type
) {
769 * Rob Coltun's special monitoring packets;
774 case OSPF_TYPE_HELLO
:
775 printf("\n\tOptions: [%s]",
776 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
));
778 TCHECK(op
->ospf_hello
.hello_deadint
);
779 printf("\n\t Hello Timer: %us, Dead Timer %us, Mask: %s, Priority: %u",
780 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
781 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
782 ipaddr_string(&op
->ospf_hello
.hello_mask
),
783 op
->ospf_hello
.hello_priority
);
785 TCHECK(op
->ospf_hello
.hello_dr
);
786 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
787 printf("\n\t Designated Router %s",
788 ipaddr_string(&op
->ospf_hello
.hello_dr
));
790 TCHECK(op
->ospf_hello
.hello_bdr
);
791 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
792 printf(", Backup Designated Router %s",
793 ipaddr_string(&op
->ospf_hello
.hello_bdr
));
795 ap
= op
->ospf_hello
.hello_neighbor
;
796 if ((u_char
*)ap
< dataend
)
797 printf("\n\t Neighbor List:");
798 while ((u_char
*)ap
< dataend
) {
800 printf("\n\t %s", ipaddr_string(ap
));
806 TCHECK(op
->ospf_db
.db_options
);
807 printf("\n\tOptions: [%s]",
808 bittok2str(ospf_option_values
,"none",op
->ospf_db
.db_options
));
809 TCHECK(op
->ospf_db
.db_flags
);
810 printf(", DD Flags: [%s]",
811 bittok2str(ospf_dd_flag_values
,"none",op
->ospf_db
.db_flags
));
814 /* Print all the LS adv's */
815 lshp
= op
->ospf_db
.db_lshdr
;
816 while (ospf_print_lshdr(lshp
) != -1) {
822 case OSPF_TYPE_LS_REQ
:
824 while ((u_char
*)lsrp
< dataend
) {
827 printf("\n\t Advertising Router: %s, %s LSA (%u)",
828 ipaddr_string(&lsrp
->ls_router
),
829 tok2str(lsa_values
,"unknown",EXTRACT_32BITS(lsrp
->ls_type
)),
830 EXTRACT_32BITS(&lsrp
->ls_type
));
832 switch (EXTRACT_32BITS(lsrp
->ls_type
)) {
833 /* the LSA header for opaque LSAs was slightly changed */
834 case LS_TYPE_OPAQUE_LL
:
835 case LS_TYPE_OPAQUE_AL
:
836 case LS_TYPE_OPAQUE_DW
:
837 printf(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
838 tok2str(lsa_opaque_values
, "unknown",lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
839 lsrp
->un_ls_stateid
.opaque_field
.opaque_type
,
840 EXTRACT_24BITS(&lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
843 printf(", LSA-ID: %s",
844 ipaddr_string(&lsrp
->un_ls_stateid
.ls_stateid
));
852 case OSPF_TYPE_LS_UPDATE
:
853 lsap
= op
->ospf_lsu
.lsu_lsa
;
854 TCHECK(op
->ospf_lsu
.lsu_count
);
855 lsa_count_max
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
856 printf(", %d LSA%s",lsa_count_max
, lsa_count_max
> 1 ? "s" : "");
857 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
858 printf("\n\t LSA #%u",lsa_count
);
859 lsap
= (const struct lsa
*)ospf_print_lsa(lsap
);
865 case OSPF_TYPE_LS_ACK
:
866 lshp
= op
->ospf_lsa
.lsa_lshdr
;
867 while (ospf_print_lshdr(lshp
) != -1) {
873 printf("v2 type (%d)", op
->ospf_type
);
882 ospf_print(register const u_char
*bp
, register u_int length
,
883 const u_char
*bp2 _U_
)
885 register const struct ospfhdr
*op
;
886 register const u_char
*dataend
;
887 register const char *cp
;
889 op
= (struct ospfhdr
*)bp
;
891 /* XXX Before we do anything else, strip off the MD5 trailer */
892 TCHECK(op
->ospf_authtype
);
893 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
894 length
-= OSPF_AUTH_MD5_LEN
;
895 snapend
-= OSPF_AUTH_MD5_LEN
;
898 /* If the type is valid translate it, or just print the type */
899 /* value. If it's not valid, say so and return */
900 TCHECK(op
->ospf_type
);
901 cp
= tok2str(type2str
, "unknown LS-type", op
->ospf_type
);
902 printf("OSPFv%u, %s, length: %u",
909 if(!vflag
) /* non verbose - so lets bail out here */
912 TCHECK(op
->ospf_len
);
913 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
914 printf(" [len %d]", EXTRACT_16BITS(&op
->ospf_len
));
917 dataend
= bp
+ length
;
919 TCHECK(op
->ospf_routerid
);
920 printf("\n\tRouter-ID: %s", ipaddr_string(&op
->ospf_routerid
));
922 TCHECK(op
->ospf_areaid
);
923 if (op
->ospf_areaid
.s_addr
!= 0)
924 printf(", Area %s", ipaddr_string(&op
->ospf_areaid
));
926 printf(", Backbone Area");
929 /* Print authentication data (should we really do this?) */
930 TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
932 printf(", Authentication Type: %s (%u)",
933 tok2str(ospf_authtype_values
,"unknown",EXTRACT_16BITS(&op
->ospf_authtype
)),
934 EXTRACT_16BITS(&op
->ospf_authtype
));
936 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
941 case OSPF_AUTH_SIMPLE
:
942 printf("\n\tSimple text password: ");
943 safeputs((char *)(op
->ospf_authdata
), OSPF_AUTH_SIMPLE_LEN
);
947 printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
948 *((op
->ospf_authdata
)+2),
949 *((op
->ospf_authdata
)+3),
950 EXTRACT_32BITS((op
->ospf_authdata
)+4));
957 /* Do rest according to version. */
958 switch (op
->ospf_version
) {
962 if (ospf_decode_v2(op
, dataend
))
967 printf(" ospf [version %d]", op
->ospf_version
);
969 } /* end switch on version */