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.66 2007-10-08 07:53:21 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
, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
48 { OSPF_OPTION_E
, "External" },
49 { OSPF_OPTION_MC
, "Multicast" },
50 { OSPF_OPTION_NP
, "NSSA" },
51 { OSPF_OPTION_L
, "LLS" },
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" },
101 { OSPF_DB_RESYNC
, "OOBResync" },
105 static struct tok lsa_opaque_values
[] = {
106 { LS_OPAQUE_TYPE_TE
, "Traffic Engineering" },
107 { LS_OPAQUE_TYPE_GRACE
, "Graceful restart" },
108 { LS_OPAQUE_TYPE_RI
, "Router Information" },
112 static struct tok lsa_opaque_te_tlv_values
[] = {
113 { LS_OPAQUE_TE_TLV_ROUTER
, "Router Address" },
114 { LS_OPAQUE_TE_TLV_LINK
, "Link" },
118 static struct tok lsa_opaque_te_link_tlv_subtlv_values
[] = {
119 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
, "Link Type" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
, "Link ID" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
, "Local Interface IP address" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
, "Remote Interface IP address" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
, "Traffic Engineering Metric" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
, "Maximum Bandwidth" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
, "Maximum Reservable Bandwidth" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
, "Unreserved Bandwidth" },
127 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
, "Administrative Group" },
128 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
, "Link Local/Remote Identifier" },
129 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
, "Link Protection Type" },
130 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
, "Interface Switching Capability" },
131 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
, "Shared Risk Link Group" },
132 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
, "Bandwidth Constraints" },
136 static struct tok lsa_opaque_grace_tlv_values
[] = {
137 { LS_OPAQUE_GRACE_TLV_PERIOD
, "Grace Period" },
138 { LS_OPAQUE_GRACE_TLV_REASON
, "Graceful restart Reason" },
139 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS
, "IPv4 interface address" },
143 static struct tok lsa_opaque_grace_tlv_reason_values
[] = {
144 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN
, "Unknown" },
145 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART
, "Software Restart" },
146 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE
, "Software Reload/Upgrade" },
147 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH
, "Control Processor Switch" },
151 static struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values
[] = {
152 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP
, "Point-to-point" },
153 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA
, "Multi-Access" },
157 static struct tok lsa_opaque_ri_tlv_values
[] = {
158 { LS_OPAQUE_RI_TLV_CAP
, "Router Capabilities" },
162 static struct tok lsa_opaque_ri_tlv_cap_values
[] = {
167 { 16, "graceful restart capable" },
168 { 32, "graceful restart helper" },
169 { 64, "Stub router support" },
170 { 128, "Traffic engineering" },
171 { 256, "p2p over LAN" },
172 { 512, "path computation server" },
176 static struct tok ospf_lls_tlv_values
[] = {
177 { OSPF_LLS_EO
, "Extended Options" },
178 { OSPF_LLS_MD5
, "MD5 Authentication" },
182 static struct tok ospf_lls_eo_options
[] = {
183 { OSPF_LLS_EO_LR
, "LSDB resync" },
184 { OSPF_LLS_EO_RS
, "Restart" },
188 static char tstr
[] = " [|ospf2]";
191 #define inline __inline
194 static int ospf_print_lshdr(const struct lsa_hdr
*);
195 static const u_char
*ospf_print_lsa(const struct lsa
*);
196 static int ospf_decode_v2(const struct ospfhdr
*, const u_char
*);
197 static int ospf_decode_lls(const struct ospfhdr
*, register u_int
);
200 ospf_print_grace_lsa (u_int8_t
*tptr
, u_int ls_length
) {
202 u_int tlv_type
, tlv_length
;
205 while (ls_length
> 0) {
208 printf("\n\t Remaining LS length %u < 4", ls_length
);
211 tlv_type
= EXTRACT_16BITS(tptr
);
212 tlv_length
= EXTRACT_16BITS(tptr
+2);
216 printf("\n\t %s TLV (%u), length %u, value: ",
217 tok2str(lsa_opaque_grace_tlv_values
,"unknown",tlv_type
),
221 if (tlv_length
> ls_length
) {
222 printf("\n\t Bogus length %u > %u", tlv_length
,
227 /* Infinite loop protection. */
228 if (tlv_type
== 0 || tlv_length
==0) {
232 TCHECK2(*tptr
, tlv_length
);
235 case LS_OPAQUE_GRACE_TLV_PERIOD
:
236 if (tlv_length
!= 4) {
237 printf("\n\t Bogus length %u != 4", tlv_length
);
240 printf("%us",EXTRACT_32BITS(tptr
));
243 case LS_OPAQUE_GRACE_TLV_REASON
:
244 if (tlv_length
!= 1) {
245 printf("\n\t Bogus length %u != 1", tlv_length
);
249 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", *tptr
),
253 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
254 if (tlv_length
!= 4) {
255 printf("\n\t Bogus length %u != 4", tlv_length
);
258 printf("%s", ipaddr_string(tptr
));
263 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
269 /* in OSPF everything has to be 32-bit aligned, including TLVs */
270 if (tlv_length
%4 != 0)
271 tlv_length
+=4-(tlv_length
%4);
272 ls_length
-=tlv_length
;
282 ospf_print_te_lsa (u_int8_t
*tptr
, u_int ls_length
) {
284 u_int tlv_type
, tlv_length
, subtlv_type
, subtlv_length
;
285 u_int priority_level
, te_class
, count_srlg
;
286 union { /* int to float conversion buffer for several subTLVs */
291 while (ls_length
!= 0) {
294 printf("\n\t Remaining LS length %u < 4", ls_length
);
297 tlv_type
= EXTRACT_16BITS(tptr
);
298 tlv_length
= EXTRACT_16BITS(tptr
+2);
302 printf("\n\t %s TLV (%u), length: %u",
303 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
307 if (tlv_length
> ls_length
) {
308 printf("\n\t Bogus length %u > %u", tlv_length
,
313 /* Infinite loop protection. */
314 if (tlv_type
== 0 || tlv_length
==0) {
319 case LS_OPAQUE_TE_TLV_LINK
:
320 while (tlv_length
>= sizeof(subtlv_type
) + sizeof(subtlv_length
)) {
321 if (tlv_length
< 4) {
322 printf("\n\t Remaining TLV length %u < 4",
327 subtlv_type
= EXTRACT_16BITS(tptr
);
328 subtlv_length
= EXTRACT_16BITS(tptr
+2);
332 printf("\n\t %s subTLV (%u), length: %u",
333 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
337 TCHECK2(*tptr
, subtlv_length
);
338 switch(subtlv_type
) {
339 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
340 printf(", 0x%08x", EXTRACT_32BITS(tptr
));
342 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
343 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
344 printf(", %s (0x%08x)",
346 EXTRACT_32BITS(tptr
));
347 if (subtlv_length
== 8) /* rfc4203 */
348 printf(", %s (0x%08x)",
349 ipaddr_string(tptr
+4),
350 EXTRACT_32BITS(tptr
+4));
352 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
353 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
354 printf(", %s", ipaddr_string(tptr
));
356 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
357 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
358 bw
.i
= EXTRACT_32BITS(tptr
);
359 printf(", %.3f Mbps", bw
.f
*8/1000000 );
361 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
362 for (te_class
= 0; te_class
< 8; te_class
++) {
363 bw
.i
= EXTRACT_32BITS(tptr
+te_class
*4);
364 printf("\n\t\tTE-Class %u: %.3f Mbps",
369 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
370 printf("\n\t\tBandwidth Constraints Model ID: %s (%u)",
371 tok2str(diffserv_te_bc_values
, "unknown", *tptr
),
373 /* decode BCs until the subTLV ends */
374 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
375 bw
.i
= EXTRACT_32BITS(tptr
+4+te_class
*4);
376 printf("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
381 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
382 printf(", Metric %u", EXTRACT_32BITS(tptr
));
384 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
385 printf(", %s, Priority %u",
386 bittok2str(gmpls_link_prot_values
, "none", *tptr
),
389 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
390 printf("\n\t\tInterface Switching Capability: %s",
391 tok2str(gmpls_switch_cap_values
, "Unknown", *(tptr
)));
392 printf("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
393 tok2str(gmpls_encoding_values
, "Unknown", *(tptr
+1)));
394 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
395 bw
.i
= EXTRACT_32BITS(tptr
+4+(priority_level
*4));
396 printf("\n\t\t priority level %d: %.3f Mbps",
401 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
403 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",*tptr
),
407 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
408 count_srlg
= subtlv_length
/ 4;
410 printf("\n\t\t Shared risk group: ");
411 while (count_srlg
> 0) {
412 bw
.i
= EXTRACT_32BITS(tptr
);
423 if(!print_unknown_data(tptr
,"\n\t\t",subtlv_length
))
428 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
429 if (subtlv_length
%4 != 0)
430 subtlv_length
+=4-(subtlv_length
%4);
432 tlv_length
-=subtlv_length
;
438 case LS_OPAQUE_TE_TLV_ROUTER
:
439 if (tlv_length
< 4) {
440 printf("\n\t TLV length %u < 4", tlv_length
);
444 printf(", %s", ipaddr_string(tptr
));
449 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
454 /* in OSPF everything has to be 32-bit aligned, including TLVs */
455 if (tlv_length
%4 != 0)
456 tlv_length
+=4-(tlv_length
%4);
457 ls_length
-=tlv_length
;
467 ospf_print_lshdr(register const struct lsa_hdr
*lshp
)
471 TCHECK(lshp
->ls_length
);
472 ls_length
= EXTRACT_16BITS(&lshp
->ls_length
);
473 if (ls_length
< sizeof(struct lsa_hdr
)) {
474 printf("\n\t Bogus length %u < header (%lu)", ls_length
,
475 (unsigned long)sizeof(struct lsa_hdr
));
479 TCHECK(lshp
->ls_seq
); /* XXX - ls_length check checked this */
480 printf("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
481 ipaddr_string(&lshp
->ls_router
),
482 EXTRACT_32BITS(&lshp
->ls_seq
),
483 EXTRACT_16BITS(&lshp
->ls_age
),
484 ls_length
-(u_int
)sizeof(struct lsa_hdr
));
486 TCHECK(lshp
->ls_type
); /* XXX - ls_length check checked this */
487 switch (lshp
->ls_type
) {
488 /* the LSA header for opaque LSAs was slightly changed */
489 case LS_TYPE_OPAQUE_LL
:
490 case LS_TYPE_OPAQUE_AL
:
491 case LS_TYPE_OPAQUE_DW
:
492 printf("\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
493 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
496 tok2str(lsa_opaque_values
,
498 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
499 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
),
500 EXTRACT_24BITS(&lshp
->un_lsa_id
.opaque_field
.opaque_id
)
505 /* all other LSA types use regular style LSA headers */
507 printf("\n\t %s LSA (%d), LSA-ID: %s",
508 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
510 ipaddr_string(&lshp
->un_lsa_id
.lsa_id
));
514 TCHECK(lshp
->ls_options
); /* XXX - ls_length check checked this */
515 printf("\n\t Options: [%s]", bittok2str(ospf_option_values
,"none",lshp
->ls_options
));
522 /* draft-ietf-ospf-mt-09 */
523 static struct tok ospf_topology_values
[] = {
526 { 2, "management " },
531 * Print all the per-topology metrics.
534 ospf_print_tos_metrics(const union un_tos
*tos
)
539 toscount
= tos
->link
.link_tos_count
+1;
543 * All but the first metric contain a valid topology id.
546 printf("\n\t\ttopology %s(%u), metric %u",
547 tok2str(ospf_topology_values
, "",
548 metric_count
? tos
->metrics
.tos_type
: 0),
549 metric_count
? tos
->metrics
.tos_type
: 0,
550 EXTRACT_16BITS(&tos
->metrics
.tos_metric
));
558 * Print a single link state advertisement. If truncated or if LSA length
559 * field is less than the length of the LSA header, return NULl, else
560 * return pointer to data past end of LSA.
562 static const u_int8_t
*
563 ospf_print_lsa(register const struct lsa
*lsap
)
565 register const u_int8_t
*ls_end
;
566 register const struct rlalink
*rlp
;
567 register const struct in_addr
*ap
;
568 register const struct aslametric
*almp
;
569 register const struct mcla
*mcp
;
570 register const u_int32_t
*lp
;
571 register int j
, tlv_type
, tlv_length
, topology
;
572 register int ls_length
;
573 const u_int8_t
*tptr
;
575 tptr
= (u_int8_t
*)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
576 ls_length
= ospf_print_lshdr(&lsap
->ls_hdr
);
579 ls_end
= (u_int8_t
*)lsap
+ ls_length
;
580 ls_length
-= sizeof(struct lsa_hdr
);
582 switch (lsap
->ls_hdr
.ls_type
) {
585 TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
586 printf("\n\t Router LSA Options: [%s]", bittok2str(ospf_rla_flag_values
,"none",lsap
->lsa_un
.un_rla
.rla_flags
));
588 TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
589 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
590 TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
591 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
594 switch (rlp
->un_tos
.link
.link_type
) {
596 case RLA_TYPE_VIRTUAL
:
597 printf("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
598 ipaddr_string(&rlp
->link_id
),
599 ipaddr_string(&rlp
->link_data
));
602 case RLA_TYPE_ROUTER
:
603 printf("\n\t Neighbor Router-ID: %s, Interface Address: %s",
604 ipaddr_string(&rlp
->link_id
),
605 ipaddr_string(&rlp
->link_data
));
608 case RLA_TYPE_TRANSIT
:
609 printf("\n\t Neighbor Network-ID: %s, Interface Address: %s",
610 ipaddr_string(&rlp
->link_id
),
611 ipaddr_string(&rlp
->link_data
));
615 printf("\n\t Stub Network: %s, Mask: %s",
616 ipaddr_string(&rlp
->link_id
),
617 ipaddr_string(&rlp
->link_data
));
621 printf("\n\t Unknown Router Link Type (%u)",
622 rlp
->un_tos
.link
.link_type
);
626 ospf_print_tos_metrics(&rlp
->un_tos
);
628 rlp
= (struct rlalink
*)((u_char
*)(rlp
+ 1) +
629 ((rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
633 case LS_TYPE_NETWORK
:
634 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
635 printf("\n\t Mask %s\n\t Connected Routers:",
636 ipaddr_string(&lsap
->lsa_un
.un_nla
.nla_mask
));
637 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
638 while ((u_char
*)ap
< ls_end
) {
640 printf("\n\t %s", ipaddr_string(ap
));
646 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
647 printf("\n\t Mask %s",
648 ipaddr_string(&lsap
->lsa_un
.un_sla
.sla_mask
));
649 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
650 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
651 while ((u_char
*)lp
< ls_end
) {
652 register u_int32_t ul
;
655 ul
= EXTRACT_32BITS(lp
);
656 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
657 printf("\n\t\ttopology %s(%u) metric %d",
658 tok2str(ospf_topology_values
, "", topology
),
660 ul
& SLA_MASK_METRIC
);
665 case LS_TYPE_SUM_ABR
:
666 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
667 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
668 while ((u_char
*)lp
< ls_end
) {
669 register u_int32_t ul
;
672 ul
= EXTRACT_32BITS(lp
);
673 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
674 printf("\n\t\ttopology %s(%u) metric %d",
675 tok2str(ospf_topology_values
, "", topology
),
677 ul
& SLA_MASK_METRIC
);
683 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
684 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
685 printf("\n\t Mask %s",
686 ipaddr_string(&lsap
->lsa_un
.un_asla
.asla_mask
));
688 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
689 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
690 while ((u_char
*)almp
< ls_end
) {
691 register u_int32_t ul
;
693 TCHECK(almp
->asla_tosmetric
);
694 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
695 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
696 printf("\n\t\ttopology %s(%u), type %d, metric",
697 tok2str(ospf_topology_values
, "", topology
),
699 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1);
700 if ((ul
& ASLA_MASK_METRIC
)==0xffffff)
703 printf(" %d", (ul
& ASLA_MASK_METRIC
));
705 TCHECK(almp
->asla_forward
);
706 if (almp
->asla_forward
.s_addr
) {
707 printf(", forward %s",
708 ipaddr_string(&almp
->asla_forward
));
710 TCHECK(almp
->asla_tag
);
711 if (almp
->asla_tag
.s_addr
) {
713 ipaddr_string(&almp
->asla_tag
));
720 /* Multicast extensions as of 23 July 1991 */
721 mcp
= lsap
->lsa_un
.un_mcla
;
722 while ((u_char
*)mcp
< ls_end
) {
723 TCHECK(mcp
->mcla_vid
);
724 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
726 case MCLA_VERTEX_ROUTER
:
727 printf("\n\t Router Router-ID %s",
728 ipaddr_string(&mcp
->mcla_vid
));
731 case MCLA_VERTEX_NETWORK
:
732 printf("\n\t Network Designated Router %s",
733 ipaddr_string(&mcp
->mcla_vid
));
737 printf("\n\t unknown VertexType (%u)",
738 EXTRACT_32BITS(&mcp
->mcla_vtype
));
745 case LS_TYPE_OPAQUE_LL
: /* fall through */
746 case LS_TYPE_OPAQUE_AL
:
747 case LS_TYPE_OPAQUE_DW
:
749 switch (*(&lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
750 case LS_OPAQUE_TYPE_RI
:
751 tptr
= (u_int8_t
*)(&lsap
->lsa_un
.un_ri_tlv
.type
);
753 while (ls_length
!= 0) {
756 printf("\n\t Remaining LS length %u < 4", ls_length
);
759 tlv_type
= EXTRACT_16BITS(tptr
);
760 tlv_length
= EXTRACT_16BITS(tptr
+2);
764 printf("\n\t %s TLV (%u), length: %u, value: ",
765 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
769 if (tlv_length
> ls_length
) {
770 printf("\n\t Bogus length %u > %u", tlv_length
,
774 TCHECK2(*tptr
, tlv_length
);
777 case LS_OPAQUE_RI_TLV_CAP
:
778 if (tlv_length
!= 4) {
779 printf("\n\t Bogus length %u != 4", tlv_length
);
782 printf("Capabilities: %s",
783 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", EXTRACT_32BITS(tptr
)));
787 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
794 ls_length
-=tlv_length
;
798 case LS_OPAQUE_TYPE_GRACE
:
799 if (ospf_print_grace_lsa((u_int8_t
*)(&lsap
->lsa_un
.un_grace_tlv
.type
),
805 case LS_OPAQUE_TYPE_TE
:
806 if (ospf_print_te_lsa((u_int8_t
*)(&lsap
->lsa_un
.un_te_lsa_tlv
.type
),
814 if(!print_unknown_data((u_int8_t
*)lsap
->lsa_un
.un_unknown
,
822 /* do we want to see an additionally hexdump ? */
824 if(!print_unknown_data((u_int8_t
*)lsap
->lsa_un
.un_unknown
,
825 "\n\t ", ls_length
)) {
835 ospf_decode_lls(register const struct ospfhdr
*op
,
836 register u_int length
)
838 register const u_char
*dptr
;
839 register const u_char
*dataend
;
840 register u_int length2
;
841 register u_int16_t lls_type
, lls_len
;
842 register u_int32_t lls_flags
;
844 switch (op
->ospf_type
) {
846 case OSPF_TYPE_HELLO
:
847 if (!(op
->ospf_hello
.hello_options
& OSPF_OPTION_L
))
852 if (!(op
->ospf_db
.db_options
& OSPF_OPTION_L
))
860 /* dig deeper if LLS data is available; see RFC4813 */
861 length2
= EXTRACT_16BITS(&op
->ospf_len
);
862 dptr
= (u_char
*)op
+ length2
;
863 dataend
= (u_char
*)op
+ length
;
865 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
866 dptr
= dptr
+ op
->ospf_authdata
[3];
867 length2
+= op
->ospf_authdata
[3];
869 if (length2
>= length
) {
870 printf("\n\t[LLS truncated]");
874 printf("\n\t LLS: checksum: 0x%04x", (u_int
)EXTRACT_16BITS(dptr
));
878 length2
= EXTRACT_16BITS(dptr
);
879 printf(", length: %u", length2
);
883 while (dptr
< dataend
) {
885 lls_type
= EXTRACT_16BITS(dptr
);
886 printf("\n\t %s (%u)",
887 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
891 lls_len
= EXTRACT_16BITS(dptr
);
892 printf(", length: %u", lls_len
);
898 printf(" [should be 4]");
902 lls_flags
= EXTRACT_32BITS(dptr
);
903 printf("\n\t Options: 0x%08x [%s]", lls_flags
,
904 bittok2str(ospf_lls_eo_options
,"?",lls_flags
));
910 printf(" [should be 20]");
914 printf("\n\t Sequence number: 0x%08x", EXTRACT_32BITS(dptr
));
927 ospf_decode_v2(register const struct ospfhdr
*op
,
928 register const u_char
*dataend
)
930 register const struct in_addr
*ap
;
931 register const struct lsr
*lsrp
;
932 register const struct lsa_hdr
*lshp
;
933 register const struct lsa
*lsap
;
934 register u_int32_t lsa_count
,lsa_count_max
;
936 switch (op
->ospf_type
) {
940 * Rob Coltun's special monitoring packets;
945 case OSPF_TYPE_HELLO
:
946 printf("\n\tOptions [%s]",
947 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
));
949 TCHECK(op
->ospf_hello
.hello_deadint
);
950 printf("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
951 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
952 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
953 ipaddr_string(&op
->ospf_hello
.hello_mask
),
954 op
->ospf_hello
.hello_priority
);
956 TCHECK(op
->ospf_hello
.hello_dr
);
957 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
958 printf("\n\t Designated Router %s",
959 ipaddr_string(&op
->ospf_hello
.hello_dr
));
961 TCHECK(op
->ospf_hello
.hello_bdr
);
962 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
963 printf(", Backup Designated Router %s",
964 ipaddr_string(&op
->ospf_hello
.hello_bdr
));
966 ap
= op
->ospf_hello
.hello_neighbor
;
967 if ((u_char
*)ap
< dataend
)
968 printf("\n\t Neighbor List:");
969 while ((u_char
*)ap
< dataend
) {
971 printf("\n\t %s", ipaddr_string(ap
));
977 TCHECK(op
->ospf_db
.db_options
);
978 printf("\n\tOptions [%s]",
979 bittok2str(ospf_option_values
,"none",op
->ospf_db
.db_options
));
980 TCHECK(op
->ospf_db
.db_flags
);
981 printf(", DD Flags [%s]",
982 bittok2str(ospf_dd_flag_values
,"none",op
->ospf_db
.db_flags
));
983 TCHECK(op
->ospf_db
.db_ifmtu
);
984 if (op
->ospf_db
.db_ifmtu
) {
985 printf(", MTU: %u", EXTRACT_16BITS(&op
->ospf_db
.db_ifmtu
));
987 TCHECK(op
->ospf_db
.db_seq
);
988 printf(", Sequence: 0x%08x", EXTRACT_32BITS(&op
->ospf_db
.db_seq
));
990 /* Print all the LS adv's */
991 lshp
= op
->ospf_db
.db_lshdr
;
992 while (((u_char
*)lshp
< dataend
) && ospf_print_lshdr(lshp
) != -1) {
997 case OSPF_TYPE_LS_REQ
:
999 while ((u_char
*)lsrp
< dataend
) {
1002 printf("\n\t Advertising Router: %s, %s LSA (%u)",
1003 ipaddr_string(&lsrp
->ls_router
),
1004 tok2str(lsa_values
,"unknown",EXTRACT_32BITS(lsrp
->ls_type
)),
1005 EXTRACT_32BITS(&lsrp
->ls_type
));
1007 switch (EXTRACT_32BITS(lsrp
->ls_type
)) {
1008 /* the LSA header for opaque LSAs was slightly changed */
1009 case LS_TYPE_OPAQUE_LL
:
1010 case LS_TYPE_OPAQUE_AL
:
1011 case LS_TYPE_OPAQUE_DW
:
1012 printf(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1013 tok2str(lsa_opaque_values
, "unknown",lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1014 lsrp
->un_ls_stateid
.opaque_field
.opaque_type
,
1015 EXTRACT_24BITS(&lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
1018 printf(", LSA-ID: %s",
1019 ipaddr_string(&lsrp
->un_ls_stateid
.ls_stateid
));
1027 case OSPF_TYPE_LS_UPDATE
:
1028 lsap
= op
->ospf_lsu
.lsu_lsa
;
1029 TCHECK(op
->ospf_lsu
.lsu_count
);
1030 lsa_count_max
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
1031 printf(", %d LSA%s",lsa_count_max
, lsa_count_max
> 1 ? "s" : "");
1032 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1033 printf("\n\t LSA #%u",lsa_count
);
1034 lsap
= (const struct lsa
*)ospf_print_lsa(lsap
);
1040 case OSPF_TYPE_LS_ACK
:
1041 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1042 while (ospf_print_lshdr(lshp
) != -1) {
1056 ospf_print(register const u_char
*bp
, register u_int length
,
1057 const u_char
*bp2 _U_
)
1059 register const struct ospfhdr
*op
;
1060 register const u_char
*dataend
;
1061 register const char *cp
;
1063 op
= (struct ospfhdr
*)bp
;
1065 /* XXX Before we do anything else, strip off the MD5 trailer */
1066 TCHECK(op
->ospf_authtype
);
1067 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1068 length
-= OSPF_AUTH_MD5_LEN
;
1069 snapend
-= OSPF_AUTH_MD5_LEN
;
1072 /* If the type is valid translate it, or just print the type */
1073 /* value. If it's not valid, say so and return */
1074 TCHECK(op
->ospf_type
);
1075 cp
= tok2str(type2str
, "unknown LS-type", op
->ospf_type
);
1076 printf("OSPFv%u, %s, length %u",
1083 if(!vflag
) { /* non verbose - so lets bail out here */
1087 TCHECK(op
->ospf_len
);
1088 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
1089 printf(" [len %d]", EXTRACT_16BITS(&op
->ospf_len
));
1092 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1093 dataend
= bp
+ EXTRACT_16BITS(&op
->ospf_len
);
1095 dataend
= bp
+ length
;
1098 TCHECK(op
->ospf_routerid
);
1099 printf("\n\tRouter-ID %s", ipaddr_string(&op
->ospf_routerid
));
1101 TCHECK(op
->ospf_areaid
);
1102 if (op
->ospf_areaid
.s_addr
!= 0)
1103 printf(", Area %s", ipaddr_string(&op
->ospf_areaid
));
1105 printf(", Backbone Area");
1108 /* Print authentication data (should we really do this?) */
1109 TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
1111 printf(", Authentication Type: %s (%u)",
1112 tok2str(ospf_authtype_values
,"unknown",EXTRACT_16BITS(&op
->ospf_authtype
)),
1113 EXTRACT_16BITS(&op
->ospf_authtype
));
1115 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
1117 case OSPF_AUTH_NONE
:
1120 case OSPF_AUTH_SIMPLE
:
1121 printf("\n\tSimple text password: ");
1122 safeputs((const char *)op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
1126 printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1127 *((op
->ospf_authdata
)+2),
1128 *((op
->ospf_authdata
)+3),
1129 EXTRACT_32BITS((op
->ospf_authdata
)+4));
1136 /* Do rest according to version. */
1137 switch (op
->ospf_version
) {
1140 /* ospf version 2 */
1141 if (ospf_decode_v2(op
, dataend
))
1143 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1144 if (ospf_decode_lls(op
, length
))
1150 printf(" ospf [version %d]", op
->ospf_version
);
1152 } /* end switch on version */
1156 fputs(tstr
, stdout
);