2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
25 static const char rcsid
[] _U_
=
26 "@(#) $Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.62 2007-07-24 16:01:42 hannes Exp $ (LBL)";
33 #include <tcpdump-stdinc.h>
37 #include "interface.h"
38 #include "addrtoname.h"
46 static struct tok ospf_option_values
[] = {
47 { OSPF_OPTION_T
, "TOS" },
48 { OSPF_OPTION_E
, "External" },
49 { OSPF_OPTION_MC
, "Multicast" },
50 { OSPF_OPTION_NP
, "NSSA" },
51 { OSPF_OPTION_EA
, "Advertise External" },
52 { OSPF_OPTION_DC
, "Demand Circuit" },
53 { OSPF_OPTION_O
, "Opaque" },
54 { OSPF_OPTION_DN
, "Up/Down" },
58 static struct tok ospf_authtype_values
[] = {
59 { OSPF_AUTH_NONE
, "none" },
60 { OSPF_AUTH_SIMPLE
, "simple" },
61 { OSPF_AUTH_MD5
, "MD5" },
65 static struct tok ospf_rla_flag_values
[] = {
66 { RLA_FLAG_B
, "ABR" },
67 { RLA_FLAG_E
, "ASBR" },
68 { RLA_FLAG_W1
, "Virtual" },
69 { RLA_FLAG_W2
, "W2" },
73 static struct tok type2str
[] = {
74 { OSPF_TYPE_UMD
, "UMD" },
75 { OSPF_TYPE_HELLO
, "Hello" },
76 { OSPF_TYPE_DD
, "Database Description" },
77 { OSPF_TYPE_LS_REQ
, "LS-Request" },
78 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
79 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
83 static struct tok lsa_values
[] = {
84 { LS_TYPE_ROUTER
, "Router" },
85 { LS_TYPE_NETWORK
, "Network" },
86 { LS_TYPE_SUM_IP
, "Summary" },
87 { LS_TYPE_SUM_ABR
, "ASBR Summary" },
88 { LS_TYPE_ASE
, "External" },
89 { LS_TYPE_GROUP
, "Multicast Group" },
90 { LS_TYPE_NSSA
, "NSSA" },
91 { LS_TYPE_OPAQUE_LL
, "Link Local Opaque" },
92 { LS_TYPE_OPAQUE_AL
, "Area Local Opaque" },
93 { LS_TYPE_OPAQUE_DW
, "Domain Wide Opaque" },
97 static struct tok ospf_dd_flag_values
[] = {
98 { OSPF_DB_INIT
, "Init" },
99 { OSPF_DB_MORE
, "More" },
100 { OSPF_DB_MASTER
, "Master" },
104 static struct tok lsa_opaque_values
[] = {
105 { LS_OPAQUE_TYPE_TE
, "Traffic Engineering" },
106 { LS_OPAQUE_TYPE_GRACE
, "Graceful restart" },
107 { LS_OPAQUE_TYPE_RI
, "Router Information" },
111 static struct tok lsa_opaque_te_tlv_values
[] = {
112 { LS_OPAQUE_TE_TLV_ROUTER
, "Router Address" },
113 { LS_OPAQUE_TE_TLV_LINK
, "Link" },
117 static struct tok lsa_opaque_te_link_tlv_subtlv_values
[] = {
118 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
, "Link Type" },
119 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
, "Link ID" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
, "Local Interface IP address" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
, "Remote Interface IP address" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
, "Traffic Engineering Metric" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
, "Maximum Bandwidth" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
, "Maximum Reservable Bandwidth" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
, "Unreserved Bandwidth" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
, "Administrative Group" },
127 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
, "Link Local/Remote Identifier" },
128 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
, "Link Protection Type" },
129 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
, "Interface Switching Capability" },
130 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
, "Shared Risk Link Group" },
131 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
, "Bandwidth Constraints" },
135 static struct tok lsa_opaque_grace_tlv_values
[] = {
136 { LS_OPAQUE_GRACE_TLV_PERIOD
, "Grace Period" },
137 { LS_OPAQUE_GRACE_TLV_REASON
, "Graceful restart Reason" },
138 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS
, "IPv4 interface address" },
142 static struct tok lsa_opaque_grace_tlv_reason_values
[] = {
143 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN
, "Unknown" },
144 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART
, "Software Restart" },
145 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE
, "Software Reload/Upgrade" },
146 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH
, "Control Processor Switch" },
150 static struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values
[] = {
151 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP
, "Point-to-point" },
152 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA
, "Multi-Access" },
156 static struct tok lsa_opaque_ri_tlv_values
[] = {
157 { LS_OPAQUE_RI_TLV_CAP
, "Router Capabilities" },
161 static struct tok lsa_opaque_ri_tlv_cap_values
[] = {
166 { 16, "graceful restart capable" },
167 { 32, "graceful restart helper" },
168 { 64, "Stub router support" },
169 { 128, "Traffic engineering" },
170 { 256, "p2p over LAN" },
171 { 512, "path computation server" },
175 static char tstr
[] = " [|ospf2]";
178 #define inline __inline
181 static int ospf_print_lshdr(const struct lsa_hdr
*);
182 static const u_char
*ospf_print_lsa(const struct lsa
*);
183 static int ospf_decode_v2(const struct ospfhdr
*, const u_char
*);
186 ospf_print_grace_lsa (u_int8_t
*tptr
, u_int ls_length
) {
188 u_int tlv_type
, tlv_length
;
191 while (ls_length
> 0) {
194 printf("\n\t Remaining LS length %u < 4", ls_length
);
197 tlv_type
= EXTRACT_16BITS(tptr
);
198 tlv_length
= EXTRACT_16BITS(tptr
+2);
202 printf("\n\t %s TLV (%u), length %u, value: ",
203 tok2str(lsa_opaque_grace_tlv_values
,"unknown",tlv_type
),
207 if (tlv_length
> ls_length
) {
208 printf("\n\t Bogus length %u > %u", tlv_length
,
213 /* Infinite loop protection. */
214 if (tlv_type
== 0 || tlv_length
==0) {
218 TCHECK2(*tptr
, tlv_length
);
221 case LS_OPAQUE_GRACE_TLV_PERIOD
:
222 if (tlv_length
!= 4) {
223 printf("\n\t Bogus length %u != 4", tlv_length
);
226 printf("%us",EXTRACT_32BITS(tptr
));
229 case LS_OPAQUE_GRACE_TLV_REASON
:
230 if (tlv_length
!= 1) {
231 printf("\n\t Bogus length %u != 1", tlv_length
);
235 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", *tptr
),
239 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
240 if (tlv_length
!= 4) {
241 printf("\n\t Bogus length %u != 4", tlv_length
);
244 printf("%s", ipaddr_string(tptr
));
249 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
255 /* in OSPF everything has to be 32-bit aligned, including TLVs */
256 if (tlv_length
%4 != 0)
257 tlv_length
+=4-(tlv_length
%4);
258 ls_length
-=tlv_length
;
268 ospf_print_te_lsa (u_int8_t
*tptr
, u_int ls_length
) {
270 u_int tlv_type
, tlv_length
, subtlv_type
, subtlv_length
;
271 u_int priority_level
, te_class
, count_srlg
;
272 union { /* int to float conversion buffer for several subTLVs */
277 while (ls_length
!= 0) {
280 printf("\n\t Remaining LS length %u < 4", ls_length
);
283 tlv_type
= EXTRACT_16BITS(tptr
);
284 tlv_length
= EXTRACT_16BITS(tptr
+2);
288 printf("\n\t %s TLV (%u), length: %u",
289 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
293 if (tlv_length
> ls_length
) {
294 printf("\n\t Bogus length %u > %u", tlv_length
,
299 /* Infinite loop protection. */
300 if (tlv_type
== 0 || tlv_length
==0) {
305 case LS_OPAQUE_TE_TLV_LINK
:
306 while (tlv_length
>= sizeof(subtlv_type
) + sizeof(subtlv_length
)) {
307 if (tlv_length
< 4) {
308 printf("\n\t Remaining TLV length %u < 4",
313 subtlv_type
= EXTRACT_16BITS(tptr
);
314 subtlv_length
= EXTRACT_16BITS(tptr
+2);
318 printf("\n\t %s subTLV (%u), length: %u",
319 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
323 TCHECK2(*tptr
, subtlv_length
);
324 switch(subtlv_type
) {
325 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
326 printf(", 0x%08x", EXTRACT_32BITS(tptr
));
328 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
329 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
330 printf(", %s (0x%08x)",
332 EXTRACT_32BITS(tptr
));
333 if (subtlv_length
== 8) /* rfc4203 */
334 printf(", %s (0x%08x)",
335 ipaddr_string(tptr
+4),
336 EXTRACT_32BITS(tptr
+4));
338 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
339 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
340 printf(", %s", ipaddr_string(tptr
));
342 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
343 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
344 bw
.i
= EXTRACT_32BITS(tptr
);
345 printf(", %.3f Mbps", bw
.f
*8/1000000 );
347 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
348 for (te_class
= 0; te_class
< 8; te_class
++) {
349 bw
.i
= EXTRACT_32BITS(tptr
+te_class
*4);
350 printf("\n\t\tTE-Class %u: %.3f Mbps",
355 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
356 printf("\n\t\tBandwidth Constraints Model ID: %s (%u)",
357 tok2str(diffserv_te_bc_values
, "unknown", *tptr
),
359 /* decode BCs until the subTLV ends */
360 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
361 bw
.i
= EXTRACT_32BITS(tptr
+4+te_class
*4);
362 printf("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
367 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
368 printf(", Metric %u", EXTRACT_32BITS(tptr
));
370 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
371 printf(", %s, Priority %u",
372 bittok2str(gmpls_link_prot_values
, "none", *tptr
),
375 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
376 printf("\n\t\tInterface Switching Capability: %s",
377 tok2str(gmpls_switch_cap_values
, "Unknown", *(tptr
)));
378 printf("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
379 tok2str(gmpls_encoding_values
, "Unknown", *(tptr
+1)));
380 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
381 bw
.i
= EXTRACT_32BITS(tptr
+4+(priority_level
*4));
382 printf("\n\t\t priority level %d: %.3f Mbps",
387 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
389 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",*tptr
),
393 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
394 count_srlg
= subtlv_length
/ 4;
396 printf("\n\t\t Shared risk group: ");
397 while (count_srlg
> 0) {
398 bw
.i
= EXTRACT_32BITS(tptr
);
409 if(!print_unknown_data(tptr
,"\n\t\t",subtlv_length
))
414 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
415 if (subtlv_length
%4 != 0)
416 subtlv_length
+=4-(subtlv_length
%4);
418 tlv_length
-=subtlv_length
;
424 case LS_OPAQUE_TE_TLV_ROUTER
:
425 if (tlv_length
< 4) {
426 printf("\n\t TLV length %u < 4", tlv_length
);
430 printf(", %s", ipaddr_string(tptr
));
435 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
440 /* in OSPF everything has to be 32-bit aligned, including TLVs */
441 if (tlv_length
%4 != 0)
442 tlv_length
+=4-(tlv_length
%4);
443 ls_length
-=tlv_length
;
453 ospf_print_lshdr(register const struct lsa_hdr
*lshp
)
457 TCHECK(lshp
->ls_length
);
458 ls_length
= EXTRACT_16BITS(&lshp
->ls_length
);
459 if (ls_length
< sizeof(struct lsa_hdr
)) {
460 printf("\n\t Bogus length %u < %lu", ls_length
,
461 (unsigned long)sizeof(struct lsa_hdr
));
465 TCHECK(lshp
->ls_seq
); /* XXX - ls_length check checked this */
466 printf("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
467 ipaddr_string(&lshp
->ls_router
),
468 EXTRACT_32BITS(&lshp
->ls_seq
),
469 EXTRACT_16BITS(&lshp
->ls_age
),
470 ls_length
-(u_int
)sizeof(struct lsa_hdr
));
472 TCHECK(lshp
->ls_type
); /* XXX - ls_length check checked this */
473 switch (lshp
->ls_type
) {
474 /* the LSA header for opaque LSAs was slightly changed */
475 case LS_TYPE_OPAQUE_LL
:
476 case LS_TYPE_OPAQUE_AL
:
477 case LS_TYPE_OPAQUE_DW
:
478 printf("\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
479 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
482 tok2str(lsa_opaque_values
,
484 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
485 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
),
486 EXTRACT_24BITS(&lshp
->un_lsa_id
.opaque_field
.opaque_id
)
491 /* all other LSA types use regular style LSA headers */
493 printf("\n\t %s LSA (%d), LSA-ID: %s",
494 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
496 ipaddr_string(&lshp
->un_lsa_id
.lsa_id
));
500 TCHECK(lshp
->ls_options
); /* XXX - ls_length check checked this */
501 printf("\n\t Options: [%s]", bittok2str(ospf_option_values
,"none",lshp
->ls_options
));
509 * Print a single link state advertisement. If truncated or if LSA length
510 * field is less than the length of the LSA header, return NULl, else
511 * return pointer to data past end of LSA.
513 static const u_int8_t
*
514 ospf_print_lsa(register const struct lsa
*lsap
)
516 register const u_int8_t
*ls_end
;
517 register const struct rlalink
*rlp
;
518 register const struct tos_metric
*tosp
;
519 register const struct in_addr
*ap
;
520 register const struct aslametric
*almp
;
521 register const struct mcla
*mcp
;
522 register const u_int32_t
*lp
;
523 register int j
, k
, tlv_type
, tlv_length
;
524 register int ls_length
;
525 const u_int8_t
*tptr
;
527 tptr
= (u_int8_t
*)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
528 ls_length
= ospf_print_lshdr(&lsap
->ls_hdr
);
531 ls_end
= (u_int8_t
*)lsap
+ ls_length
;
532 ls_length
-= sizeof(struct lsa_hdr
);
534 switch (lsap
->ls_hdr
.ls_type
) {
537 TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
538 printf("\n\t Router LSA Options: [%s]", bittok2str(ospf_rla_flag_values
,"none",lsap
->lsa_un
.un_rla
.rla_flags
));
540 TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
541 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
542 TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
543 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
546 switch (rlp
->link_type
) {
548 case RLA_TYPE_VIRTUAL
:
549 printf("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
550 ipaddr_string(&rlp
->link_id
),
551 ipaddr_string(&rlp
->link_data
));
554 case RLA_TYPE_ROUTER
:
555 printf("\n\t Neighbor Router-ID: %s, Interface Address: %s",
556 ipaddr_string(&rlp
->link_id
),
557 ipaddr_string(&rlp
->link_data
));
560 case RLA_TYPE_TRANSIT
:
561 printf("\n\t Neighbor Network-ID: %s, Interface Address: %s",
562 ipaddr_string(&rlp
->link_id
),
563 ipaddr_string(&rlp
->link_data
));
567 printf("\n\t Stub Network: %s, Mask: %s",
568 ipaddr_string(&rlp
->link_id
),
569 ipaddr_string(&rlp
->link_data
));
573 printf("\n\t Unknown Router Link Type (%u)",
577 printf(", tos 0, metric: %d", EXTRACT_16BITS(&rlp
->link_tos0metric
));
578 tosp
= (struct tos_metric
*)
579 ((sizeof rlp
->link_tos0metric
) + (u_char
*) rlp
);
580 for (k
= 0; k
< (int) rlp
->link_toscount
; ++k
, ++tosp
) {
582 printf(", tos %d, metric: %d",
584 EXTRACT_16BITS(&tosp
->tos_metric
));
586 rlp
= (struct rlalink
*)((u_char
*)(rlp
+ 1) +
587 ((rlp
->link_toscount
) * sizeof(*tosp
)));
591 case LS_TYPE_NETWORK
:
592 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
593 printf("\n\t Mask %s\n\t Connected Routers:",
594 ipaddr_string(&lsap
->lsa_un
.un_nla
.nla_mask
));
595 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
596 while ((u_char
*)ap
< ls_end
) {
598 printf("\n\t %s", ipaddr_string(ap
));
604 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
605 printf("\n\t Mask %s",
606 ipaddr_string(&lsap
->lsa_un
.un_sla
.sla_mask
));
607 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
608 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
609 /* suppress tos if its not supported */
610 if(!((lsap
->ls_hdr
.ls_options
)&OSPF_OPTION_T
)) {
611 printf(", metric %u", EXTRACT_32BITS(lp
)&SLA_MASK_METRIC
);
614 while ((u_char
*)lp
< ls_end
) {
615 register u_int32_t ul
;
618 ul
= EXTRACT_32BITS(lp
);
619 printf(", tos %d metric %d",
620 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
621 ul
& SLA_MASK_METRIC
);
626 case LS_TYPE_SUM_ABR
:
627 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
628 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
629 /* suppress tos if its not supported */
630 if(!((lsap
->ls_hdr
.ls_options
)&OSPF_OPTION_T
)) {
631 printf(", metric: %u", EXTRACT_32BITS(lp
)&SLA_MASK_METRIC
);
634 while ((u_char
*)lp
< ls_end
) {
635 register u_int32_t ul
;
638 ul
= EXTRACT_32BITS(lp
);
639 printf(", tos %d metric %d",
640 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
641 ul
& SLA_MASK_METRIC
);
647 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
648 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
649 printf("\n\t Mask %s",
650 ipaddr_string(&lsap
->lsa_un
.un_asla
.asla_mask
));
652 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
653 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
654 while ((u_char
*)almp
< ls_end
) {
655 register u_int32_t ul
;
657 TCHECK(almp
->asla_tosmetric
);
658 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
659 printf(", type %d, tos %d metric:",
660 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1,
661 (ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
662 if ((ul
& ASLA_MASK_METRIC
)==0xffffff)
665 printf(" %d", (ul
& ASLA_MASK_METRIC
));
667 TCHECK(almp
->asla_forward
);
668 if (almp
->asla_forward
.s_addr
) {
669 printf(", forward %s",
670 ipaddr_string(&almp
->asla_forward
));
672 TCHECK(almp
->asla_tag
);
673 if (almp
->asla_tag
.s_addr
) {
675 ipaddr_string(&almp
->asla_tag
));
682 /* Multicast extensions as of 23 July 1991 */
683 mcp
= lsap
->lsa_un
.un_mcla
;
684 while ((u_char
*)mcp
< ls_end
) {
685 TCHECK(mcp
->mcla_vid
);
686 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
688 case MCLA_VERTEX_ROUTER
:
689 printf("\n\t Router Router-ID %s",
690 ipaddr_string(&mcp
->mcla_vid
));
693 case MCLA_VERTEX_NETWORK
:
694 printf("\n\t Network Designated Router %s",
695 ipaddr_string(&mcp
->mcla_vid
));
699 printf("\n\t unknown VertexType (%u)",
700 EXTRACT_32BITS(&mcp
->mcla_vtype
));
707 case LS_TYPE_OPAQUE_LL
: /* fall through */
708 case LS_TYPE_OPAQUE_AL
:
709 case LS_TYPE_OPAQUE_DW
:
711 switch (*(&lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
712 case LS_OPAQUE_TYPE_RI
:
713 tptr
= (u_int8_t
*)(&lsap
->lsa_un
.un_ri_tlv
.type
);
715 while (ls_length
!= 0) {
718 printf("\n\t Remaining LS length %u < 4", ls_length
);
721 tlv_type
= EXTRACT_16BITS(tptr
);
722 tlv_length
= EXTRACT_16BITS(tptr
+2);
726 printf("\n\t %s TLV (%u), length: %u, value: ",
727 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
731 if (tlv_length
> ls_length
) {
732 printf("\n\t Bogus length %u > %u", tlv_length
,
736 ls_length
-=tlv_length
;
737 TCHECK2(*tptr
, tlv_length
);
740 case LS_OPAQUE_RI_TLV_CAP
:
741 if (tlv_length
!= 4) {
742 printf("\n\t Bogus length %u != 4", tlv_length
);
745 printf("Capabilities: %s",
746 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", EXTRACT_32BITS(tptr
)));
750 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
760 case LS_OPAQUE_TYPE_GRACE
:
761 if (ospf_print_grace_lsa((u_int8_t
*)(&lsap
->lsa_un
.un_grace_tlv
.type
),
767 case LS_OPAQUE_TYPE_TE
:
768 if (ospf_print_te_lsa((u_int8_t
*)(&lsap
->lsa_un
.un_te_lsa_tlv
.type
),
776 if(!print_unknown_data((u_int8_t
*)lsap
->lsa_un
.un_unknown
,
784 /* do we want to see an additionally hexdump ? */
786 if(!print_unknown_data((u_int8_t
*)lsap
->lsa_un
.un_unknown
,
787 "\n\t ", ls_length
)) {
797 ospf_decode_v2(register const struct ospfhdr
*op
,
798 register const u_char
*dataend
)
800 register const struct in_addr
*ap
;
801 register const struct lsr
*lsrp
;
802 register const struct lsa_hdr
*lshp
;
803 register const struct lsa
*lsap
;
804 register u_int32_t lsa_count
,lsa_count_max
;
806 switch (op
->ospf_type
) {
810 * Rob Coltun's special monitoring packets;
815 case OSPF_TYPE_HELLO
:
816 printf("\n\tOptions [%s]",
817 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
));
819 TCHECK(op
->ospf_hello
.hello_deadint
);
820 printf("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
821 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
822 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
823 ipaddr_string(&op
->ospf_hello
.hello_mask
),
824 op
->ospf_hello
.hello_priority
);
826 TCHECK(op
->ospf_hello
.hello_dr
);
827 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
828 printf("\n\t Designated Router %s",
829 ipaddr_string(&op
->ospf_hello
.hello_dr
));
831 TCHECK(op
->ospf_hello
.hello_bdr
);
832 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
833 printf(", Backup Designated Router %s",
834 ipaddr_string(&op
->ospf_hello
.hello_bdr
));
836 ap
= op
->ospf_hello
.hello_neighbor
;
837 if ((u_char
*)ap
< dataend
)
838 printf("\n\t Neighbor List:");
839 while ((u_char
*)ap
< dataend
) {
841 printf("\n\t %s", ipaddr_string(ap
));
847 TCHECK(op
->ospf_db
.db_options
);
848 printf("\n\tOptions [%s]",
849 bittok2str(ospf_option_values
,"none",op
->ospf_db
.db_options
));
850 TCHECK(op
->ospf_db
.db_flags
);
851 printf(", DD Flags [%s]",
852 bittok2str(ospf_dd_flag_values
,"none",op
->ospf_db
.db_flags
));
854 /* Print all the LS adv's */
855 lshp
= op
->ospf_db
.db_lshdr
;
856 while (ospf_print_lshdr(lshp
) != -1) {
861 case OSPF_TYPE_LS_REQ
:
863 while ((u_char
*)lsrp
< dataend
) {
866 printf("\n\t Advertising Router: %s, %s LSA (%u)",
867 ipaddr_string(&lsrp
->ls_router
),
868 tok2str(lsa_values
,"unknown",EXTRACT_32BITS(lsrp
->ls_type
)),
869 EXTRACT_32BITS(&lsrp
->ls_type
));
871 switch (EXTRACT_32BITS(lsrp
->ls_type
)) {
872 /* the LSA header for opaque LSAs was slightly changed */
873 case LS_TYPE_OPAQUE_LL
:
874 case LS_TYPE_OPAQUE_AL
:
875 case LS_TYPE_OPAQUE_DW
:
876 printf(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
877 tok2str(lsa_opaque_values
, "unknown",lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
878 lsrp
->un_ls_stateid
.opaque_field
.opaque_type
,
879 EXTRACT_24BITS(&lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
882 printf(", LSA-ID: %s",
883 ipaddr_string(&lsrp
->un_ls_stateid
.ls_stateid
));
891 case OSPF_TYPE_LS_UPDATE
:
892 lsap
= op
->ospf_lsu
.lsu_lsa
;
893 TCHECK(op
->ospf_lsu
.lsu_count
);
894 lsa_count_max
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
895 printf(", %d LSA%s",lsa_count_max
, lsa_count_max
> 1 ? "s" : "");
896 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
897 printf("\n\t LSA #%u",lsa_count
);
898 lsap
= (const struct lsa
*)ospf_print_lsa(lsap
);
904 case OSPF_TYPE_LS_ACK
:
905 lshp
= op
->ospf_lsa
.lsa_lshdr
;
906 while (ospf_print_lshdr(lshp
) != -1) {
920 ospf_print(register const u_char
*bp
, register u_int length
,
921 const u_char
*bp2 _U_
)
923 register const struct ospfhdr
*op
;
924 register const u_char
*dataend
;
925 register const char *cp
;
927 op
= (struct ospfhdr
*)bp
;
929 /* XXX Before we do anything else, strip off the MD5 trailer */
930 TCHECK(op
->ospf_authtype
);
931 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
932 length
-= OSPF_AUTH_MD5_LEN
;
933 snapend
-= OSPF_AUTH_MD5_LEN
;
936 /* If the type is valid translate it, or just print the type */
937 /* value. If it's not valid, say so and return */
938 TCHECK(op
->ospf_type
);
939 cp
= tok2str(type2str
, "unknown LS-type", op
->ospf_type
);
940 printf("OSPFv%u, %s, length %u",
947 if(!vflag
) { /* non verbose - so lets bail out here */
951 TCHECK(op
->ospf_len
);
952 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
953 printf(" [len %d]", EXTRACT_16BITS(&op
->ospf_len
));
956 dataend
= bp
+ length
;
958 TCHECK(op
->ospf_routerid
);
959 printf("\n\tRouter-ID %s", ipaddr_string(&op
->ospf_routerid
));
961 TCHECK(op
->ospf_areaid
);
962 if (op
->ospf_areaid
.s_addr
!= 0)
963 printf(", Area %s", ipaddr_string(&op
->ospf_areaid
));
965 printf(", Backbone Area");
968 /* Print authentication data (should we really do this?) */
969 TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
971 printf(", Authentication Type: %s (%u)",
972 tok2str(ospf_authtype_values
,"unknown",EXTRACT_16BITS(&op
->ospf_authtype
)),
973 EXTRACT_16BITS(&op
->ospf_authtype
));
975 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
980 case OSPF_AUTH_SIMPLE
:
981 printf("\n\tSimple text password: ");
982 safeputs((const char *)op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
986 printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
987 *((op
->ospf_authdata
)+2),
988 *((op
->ospf_authdata
)+3),
989 EXTRACT_32BITS((op
->ospf_authdata
)+4));
996 /* Do rest according to version. */
997 switch (op
->ospf_version
) {
1000 /* ospf version 2 */
1001 if (ospf_decode_v2(op
, dataend
))
1006 printf(" ospf [version %d]", op
->ospf_version
);
1008 } /* end switch on version */
1012 fputs(tstr
, stdout
);