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)
28 #include <tcpdump-stdinc.h>
32 #include "interface.h"
33 #include "addrtoname.h"
41 static const char tstr
[] = " [|ospf2]";
43 static const struct tok ospf_option_values
[] = {
44 { OSPF_OPTION_T
, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
45 { OSPF_OPTION_E
, "External" },
46 { OSPF_OPTION_MC
, "Multicast" },
47 { OSPF_OPTION_NP
, "NSSA" },
48 { OSPF_OPTION_L
, "LLS" },
49 { OSPF_OPTION_DC
, "Demand Circuit" },
50 { OSPF_OPTION_O
, "Opaque" },
51 { OSPF_OPTION_DN
, "Up/Down" },
55 static const struct tok ospf_authtype_values
[] = {
56 { OSPF_AUTH_NONE
, "none" },
57 { OSPF_AUTH_SIMPLE
, "simple" },
58 { OSPF_AUTH_MD5
, "MD5" },
62 static const struct tok ospf_rla_flag_values
[] = {
63 { RLA_FLAG_B
, "ABR" },
64 { RLA_FLAG_E
, "ASBR" },
65 { RLA_FLAG_W1
, "Virtual" },
66 { RLA_FLAG_W2
, "W2" },
70 static const struct tok type2str
[] = {
71 { OSPF_TYPE_UMD
, "UMD" },
72 { OSPF_TYPE_HELLO
, "Hello" },
73 { OSPF_TYPE_DD
, "Database Description" },
74 { OSPF_TYPE_LS_REQ
, "LS-Request" },
75 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
76 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
80 static const struct tok lsa_values
[] = {
81 { LS_TYPE_ROUTER
, "Router" },
82 { LS_TYPE_NETWORK
, "Network" },
83 { LS_TYPE_SUM_IP
, "Summary" },
84 { LS_TYPE_SUM_ABR
, "ASBR Summary" },
85 { LS_TYPE_ASE
, "External" },
86 { LS_TYPE_GROUP
, "Multicast Group" },
87 { LS_TYPE_NSSA
, "NSSA" },
88 { LS_TYPE_OPAQUE_LL
, "Link Local Opaque" },
89 { LS_TYPE_OPAQUE_AL
, "Area Local Opaque" },
90 { LS_TYPE_OPAQUE_DW
, "Domain Wide Opaque" },
94 static const struct tok ospf_dd_flag_values
[] = {
95 { OSPF_DB_INIT
, "Init" },
96 { OSPF_DB_MORE
, "More" },
97 { OSPF_DB_MASTER
, "Master" },
98 { OSPF_DB_RESYNC
, "OOBResync" },
102 static const struct tok lsa_opaque_values
[] = {
103 { LS_OPAQUE_TYPE_TE
, "Traffic Engineering" },
104 { LS_OPAQUE_TYPE_GRACE
, "Graceful restart" },
105 { LS_OPAQUE_TYPE_RI
, "Router Information" },
109 static const struct tok lsa_opaque_te_tlv_values
[] = {
110 { LS_OPAQUE_TE_TLV_ROUTER
, "Router Address" },
111 { LS_OPAQUE_TE_TLV_LINK
, "Link" },
115 static const struct tok lsa_opaque_te_link_tlv_subtlv_values
[] = {
116 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
, "Link Type" },
117 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
, "Link ID" },
118 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
, "Local Interface IP address" },
119 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
, "Remote Interface IP address" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
, "Traffic Engineering Metric" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
, "Maximum Bandwidth" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
, "Maximum Reservable Bandwidth" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
, "Unreserved Bandwidth" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
, "Administrative Group" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
, "Link Local/Remote Identifier" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
, "Link Protection Type" },
127 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
, "Interface Switching Capability" },
128 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
, "Shared Risk Link Group" },
129 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
, "Bandwidth Constraints" },
133 static const struct tok lsa_opaque_grace_tlv_values
[] = {
134 { LS_OPAQUE_GRACE_TLV_PERIOD
, "Grace Period" },
135 { LS_OPAQUE_GRACE_TLV_REASON
, "Graceful restart Reason" },
136 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS
, "IPv4 interface address" },
140 static const struct tok lsa_opaque_grace_tlv_reason_values
[] = {
141 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN
, "Unknown" },
142 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART
, "Software Restart" },
143 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE
, "Software Reload/Upgrade" },
144 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH
, "Control Processor Switch" },
148 static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values
[] = {
149 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP
, "Point-to-point" },
150 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA
, "Multi-Access" },
154 static const struct tok lsa_opaque_ri_tlv_values
[] = {
155 { LS_OPAQUE_RI_TLV_CAP
, "Router Capabilities" },
159 static const struct tok lsa_opaque_ri_tlv_cap_values
[] = {
164 { 16, "graceful restart capable" },
165 { 32, "graceful restart helper" },
166 { 64, "Stub router support" },
167 { 128, "Traffic engineering" },
168 { 256, "p2p over LAN" },
169 { 512, "path computation server" },
173 static const struct tok ospf_lls_tlv_values
[] = {
174 { OSPF_LLS_EO
, "Extended Options" },
175 { OSPF_LLS_MD5
, "MD5 Authentication" },
179 static const struct tok ospf_lls_eo_options
[] = {
180 { OSPF_LLS_EO_LR
, "LSDB resync" },
181 { OSPF_LLS_EO_RS
, "Restart" },
185 static int ospf_print_lshdr(const struct lsa_hdr
*);
186 static const u_char
*ospf_print_lsa(const struct lsa
*);
187 static int ospf_decode_v2(const struct ospfhdr
*, const u_char
*);
188 static int ospf_decode_lls(const struct ospfhdr
*, register u_int
);
191 ospf_print_grace_lsa (const u_int8_t
*tptr
, u_int ls_length
) {
193 u_int tlv_type
, tlv_length
;
196 while (ls_length
> 0) {
199 printf("\n\t Remaining LS length %u < 4", ls_length
);
202 tlv_type
= EXTRACT_16BITS(tptr
);
203 tlv_length
= EXTRACT_16BITS(tptr
+2);
207 printf("\n\t %s TLV (%u), length %u, value: ",
208 tok2str(lsa_opaque_grace_tlv_values
,"unknown",tlv_type
),
212 if (tlv_length
> ls_length
) {
213 printf("\n\t Bogus length %u > %u", tlv_length
,
218 /* Infinite loop protection. */
219 if (tlv_type
== 0 || tlv_length
==0) {
223 TCHECK2(*tptr
, tlv_length
);
226 case LS_OPAQUE_GRACE_TLV_PERIOD
:
227 if (tlv_length
!= 4) {
228 printf("\n\t Bogus length %u != 4", tlv_length
);
231 printf("%us",EXTRACT_32BITS(tptr
));
234 case LS_OPAQUE_GRACE_TLV_REASON
:
235 if (tlv_length
!= 1) {
236 printf("\n\t Bogus length %u != 1", tlv_length
);
240 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", *tptr
),
244 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
245 if (tlv_length
!= 4) {
246 printf("\n\t Bogus length %u != 4", tlv_length
);
249 printf("%s", ipaddr_string(tptr
));
254 if(!print_unknown_data(gndo
,tptr
,"\n\t ",tlv_length
))
260 /* in OSPF everything has to be 32-bit aligned, including TLVs */
261 if (tlv_length
%4 != 0)
262 tlv_length
+=4-(tlv_length
%4);
263 ls_length
-=tlv_length
;
273 ospf_print_te_lsa (const u_int8_t
*tptr
, u_int ls_length
) {
275 u_int tlv_type
, tlv_length
, subtlv_type
, subtlv_length
;
276 u_int priority_level
, te_class
, count_srlg
;
277 union { /* int to float conversion buffer for several subTLVs */
282 while (ls_length
!= 0) {
285 printf("\n\t Remaining LS length %u < 4", ls_length
);
288 tlv_type
= EXTRACT_16BITS(tptr
);
289 tlv_length
= EXTRACT_16BITS(tptr
+2);
293 printf("\n\t %s TLV (%u), length: %u",
294 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
298 if (tlv_length
> ls_length
) {
299 printf("\n\t Bogus length %u > %u", tlv_length
,
304 /* Infinite loop protection. */
305 if (tlv_type
== 0 || tlv_length
==0) {
310 case LS_OPAQUE_TE_TLV_LINK
:
311 while (tlv_length
>= sizeof(subtlv_type
) + sizeof(subtlv_length
)) {
312 if (tlv_length
< 4) {
313 printf("\n\t Remaining TLV length %u < 4",
318 subtlv_type
= EXTRACT_16BITS(tptr
);
319 subtlv_length
= EXTRACT_16BITS(tptr
+2);
323 printf("\n\t %s subTLV (%u), length: %u",
324 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
328 TCHECK2(*tptr
, subtlv_length
);
329 switch(subtlv_type
) {
330 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
331 printf(", 0x%08x", EXTRACT_32BITS(tptr
));
333 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
334 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
335 printf(", %s (0x%08x)",
337 EXTRACT_32BITS(tptr
));
338 if (subtlv_length
== 8) /* rfc4203 */
339 printf(", %s (0x%08x)",
340 ipaddr_string(tptr
+4),
341 EXTRACT_32BITS(tptr
+4));
343 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
344 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
345 printf(", %s", ipaddr_string(tptr
));
347 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
348 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
349 bw
.i
= EXTRACT_32BITS(tptr
);
350 printf(", %.3f Mbps", bw
.f
*8/1000000 );
352 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
353 for (te_class
= 0; te_class
< 8; te_class
++) {
354 bw
.i
= EXTRACT_32BITS(tptr
+te_class
*4);
355 printf("\n\t\tTE-Class %u: %.3f Mbps",
360 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
361 printf("\n\t\tBandwidth Constraints Model ID: %s (%u)",
362 tok2str(diffserv_te_bc_values
, "unknown", *tptr
),
364 /* decode BCs until the subTLV ends */
365 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
366 bw
.i
= EXTRACT_32BITS(tptr
+4+te_class
*4);
367 printf("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
372 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
373 printf(", Metric %u", EXTRACT_32BITS(tptr
));
375 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
376 printf(", %s, Priority %u",
377 bittok2str(gmpls_link_prot_values
, "none", *tptr
),
380 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
381 printf("\n\t\tInterface Switching Capability: %s",
382 tok2str(gmpls_switch_cap_values
, "Unknown", *(tptr
)));
383 printf("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
384 tok2str(gmpls_encoding_values
, "Unknown", *(tptr
+1)));
385 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
386 bw
.i
= EXTRACT_32BITS(tptr
+4+(priority_level
*4));
387 printf("\n\t\t priority level %d: %.3f Mbps",
392 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
394 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",*tptr
),
398 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
399 count_srlg
= subtlv_length
/ 4;
401 printf("\n\t\t Shared risk group: ");
402 while (count_srlg
> 0) {
403 bw
.i
= EXTRACT_32BITS(tptr
);
414 if(!print_unknown_data(gndo
,tptr
,"\n\t\t",subtlv_length
))
419 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
420 if (subtlv_length
%4 != 0)
421 subtlv_length
+=4-(subtlv_length
%4);
423 tlv_length
-=subtlv_length
;
429 case LS_OPAQUE_TE_TLV_ROUTER
:
430 if (tlv_length
< 4) {
431 printf("\n\t TLV length %u < 4", tlv_length
);
435 printf(", %s", ipaddr_string(tptr
));
440 if(!print_unknown_data(gndo
,tptr
,"\n\t ",tlv_length
))
445 /* in OSPF everything has to be 32-bit aligned, including TLVs */
446 if (tlv_length
%4 != 0)
447 tlv_length
+=4-(tlv_length
%4);
448 ls_length
-=tlv_length
;
458 ospf_print_lshdr(register const struct lsa_hdr
*lshp
)
462 TCHECK(lshp
->ls_length
);
463 ls_length
= EXTRACT_16BITS(&lshp
->ls_length
);
464 if (ls_length
< sizeof(struct lsa_hdr
)) {
465 printf("\n\t Bogus length %u < header (%lu)", ls_length
,
466 (unsigned long)sizeof(struct lsa_hdr
));
470 TCHECK(lshp
->ls_seq
); /* XXX - ls_length check checked this */
471 printf("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
472 ipaddr_string(&lshp
->ls_router
),
473 EXTRACT_32BITS(&lshp
->ls_seq
),
474 EXTRACT_16BITS(&lshp
->ls_age
),
475 ls_length
-(u_int
)sizeof(struct lsa_hdr
));
477 TCHECK(lshp
->ls_type
); /* XXX - ls_length check checked this */
478 switch (lshp
->ls_type
) {
479 /* the LSA header for opaque LSAs was slightly changed */
480 case LS_TYPE_OPAQUE_LL
:
481 case LS_TYPE_OPAQUE_AL
:
482 case LS_TYPE_OPAQUE_DW
:
483 printf("\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
484 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
487 tok2str(lsa_opaque_values
,
489 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
490 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
),
491 EXTRACT_24BITS(&lshp
->un_lsa_id
.opaque_field
.opaque_id
)
496 /* all other LSA types use regular style LSA headers */
498 printf("\n\t %s LSA (%d), LSA-ID: %s",
499 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
501 ipaddr_string(&lshp
->un_lsa_id
.lsa_id
));
505 TCHECK(lshp
->ls_options
); /* XXX - ls_length check checked this */
506 printf("\n\t Options: [%s]", bittok2str(ospf_option_values
,"none",lshp
->ls_options
));
513 /* draft-ietf-ospf-mt-09 */
514 static const struct tok ospf_topology_values
[] = {
517 { 2, "management " },
522 * Print all the per-topology metrics.
525 ospf_print_tos_metrics(const union un_tos
*tos
)
530 toscount
= tos
->link
.link_tos_count
+1;
534 * All but the first metric contain a valid topology id.
537 printf("\n\t\ttopology %s(%u), metric %u",
538 tok2str(ospf_topology_values
, "",
539 metric_count
? tos
->metrics
.tos_type
: 0),
540 metric_count
? tos
->metrics
.tos_type
: 0,
541 EXTRACT_16BITS(&tos
->metrics
.tos_metric
));
549 * Print a single link state advertisement. If truncated or if LSA length
550 * field is less than the length of the LSA header, return NULl, else
551 * return pointer to data past end of LSA.
553 static const u_int8_t
*
554 ospf_print_lsa(register const struct lsa
*lsap
)
556 register const u_int8_t
*ls_end
;
557 register const struct rlalink
*rlp
;
558 register const struct in_addr
*ap
;
559 register const struct aslametric
*almp
;
560 register const struct mcla
*mcp
;
561 register const u_int32_t
*lp
;
562 register int j
, tlv_type
, tlv_length
, topology
;
563 register int ls_length
;
564 const u_int8_t
*tptr
;
566 tptr
= (u_int8_t
*)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
567 ls_length
= ospf_print_lshdr(&lsap
->ls_hdr
);
570 ls_end
= (u_int8_t
*)lsap
+ ls_length
;
571 ls_length
-= sizeof(struct lsa_hdr
);
573 switch (lsap
->ls_hdr
.ls_type
) {
576 TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
577 printf("\n\t Router LSA Options: [%s]", bittok2str(ospf_rla_flag_values
,"none",lsap
->lsa_un
.un_rla
.rla_flags
));
579 TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
580 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
581 TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
582 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
585 switch (rlp
->un_tos
.link
.link_type
) {
587 case RLA_TYPE_VIRTUAL
:
588 printf("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
589 ipaddr_string(&rlp
->link_id
),
590 ipaddr_string(&rlp
->link_data
));
593 case RLA_TYPE_ROUTER
:
594 printf("\n\t Neighbor Router-ID: %s, Interface Address: %s",
595 ipaddr_string(&rlp
->link_id
),
596 ipaddr_string(&rlp
->link_data
));
599 case RLA_TYPE_TRANSIT
:
600 printf("\n\t Neighbor Network-ID: %s, Interface Address: %s",
601 ipaddr_string(&rlp
->link_id
),
602 ipaddr_string(&rlp
->link_data
));
606 printf("\n\t Stub Network: %s, Mask: %s",
607 ipaddr_string(&rlp
->link_id
),
608 ipaddr_string(&rlp
->link_data
));
612 printf("\n\t Unknown Router Link Type (%u)",
613 rlp
->un_tos
.link
.link_type
);
617 ospf_print_tos_metrics(&rlp
->un_tos
);
619 rlp
= (struct rlalink
*)((u_char
*)(rlp
+ 1) +
620 ((rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
624 case LS_TYPE_NETWORK
:
625 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
626 printf("\n\t Mask %s\n\t Connected Routers:",
627 ipaddr_string(&lsap
->lsa_un
.un_nla
.nla_mask
));
628 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
629 while ((u_char
*)ap
< ls_end
) {
631 printf("\n\t %s", ipaddr_string(ap
));
637 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
638 printf("\n\t Mask %s",
639 ipaddr_string(&lsap
->lsa_un
.un_sla
.sla_mask
));
640 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
641 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
642 while ((u_char
*)lp
< ls_end
) {
643 register u_int32_t ul
;
646 ul
= EXTRACT_32BITS(lp
);
647 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
648 printf("\n\t\ttopology %s(%u) metric %d",
649 tok2str(ospf_topology_values
, "", topology
),
651 ul
& SLA_MASK_METRIC
);
656 case LS_TYPE_SUM_ABR
:
657 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
658 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
659 while ((u_char
*)lp
< ls_end
) {
660 register u_int32_t ul
;
663 ul
= EXTRACT_32BITS(lp
);
664 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
665 printf("\n\t\ttopology %s(%u) metric %d",
666 tok2str(ospf_topology_values
, "", topology
),
668 ul
& SLA_MASK_METRIC
);
674 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
675 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
676 printf("\n\t Mask %s",
677 ipaddr_string(&lsap
->lsa_un
.un_asla
.asla_mask
));
679 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
680 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
681 while ((u_char
*)almp
< ls_end
) {
682 register u_int32_t ul
;
684 TCHECK(almp
->asla_tosmetric
);
685 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
686 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
687 printf("\n\t\ttopology %s(%u), type %d, metric",
688 tok2str(ospf_topology_values
, "", topology
),
690 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1);
691 if ((ul
& ASLA_MASK_METRIC
)==0xffffff)
694 printf(" %d", (ul
& ASLA_MASK_METRIC
));
696 TCHECK(almp
->asla_forward
);
697 if (almp
->asla_forward
.s_addr
) {
698 printf(", forward %s",
699 ipaddr_string(&almp
->asla_forward
));
701 TCHECK(almp
->asla_tag
);
702 if (almp
->asla_tag
.s_addr
) {
704 ipaddr_string(&almp
->asla_tag
));
711 /* Multicast extensions as of 23 July 1991 */
712 mcp
= lsap
->lsa_un
.un_mcla
;
713 while ((u_char
*)mcp
< ls_end
) {
714 TCHECK(mcp
->mcla_vid
);
715 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
717 case MCLA_VERTEX_ROUTER
:
718 printf("\n\t Router Router-ID %s",
719 ipaddr_string(&mcp
->mcla_vid
));
722 case MCLA_VERTEX_NETWORK
:
723 printf("\n\t Network Designated Router %s",
724 ipaddr_string(&mcp
->mcla_vid
));
728 printf("\n\t unknown VertexType (%u)",
729 EXTRACT_32BITS(&mcp
->mcla_vtype
));
736 case LS_TYPE_OPAQUE_LL
: /* fall through */
737 case LS_TYPE_OPAQUE_AL
:
738 case LS_TYPE_OPAQUE_DW
:
740 switch (*(&lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
741 case LS_OPAQUE_TYPE_RI
:
742 tptr
= (u_int8_t
*)(&lsap
->lsa_un
.un_ri_tlv
.type
);
744 while (ls_length
!= 0) {
747 printf("\n\t Remaining LS length %u < 4", ls_length
);
750 tlv_type
= EXTRACT_16BITS(tptr
);
751 tlv_length
= EXTRACT_16BITS(tptr
+2);
755 printf("\n\t %s TLV (%u), length: %u, value: ",
756 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
760 if (tlv_length
> ls_length
) {
761 printf("\n\t Bogus length %u > %u", tlv_length
,
765 TCHECK2(*tptr
, tlv_length
);
768 case LS_OPAQUE_RI_TLV_CAP
:
769 if (tlv_length
!= 4) {
770 printf("\n\t Bogus length %u != 4", tlv_length
);
773 printf("Capabilities: %s",
774 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", EXTRACT_32BITS(tptr
)));
778 if(!print_unknown_data(gndo
,tptr
,"\n\t ",tlv_length
))
785 ls_length
-=tlv_length
;
789 case LS_OPAQUE_TYPE_GRACE
:
790 if (ospf_print_grace_lsa((u_int8_t
*)(&lsap
->lsa_un
.un_grace_tlv
.type
),
796 case LS_OPAQUE_TYPE_TE
:
797 if (ospf_print_te_lsa((u_int8_t
*)(&lsap
->lsa_un
.un_te_lsa_tlv
.type
),
805 if(!print_unknown_data(gndo
,(u_int8_t
*)lsap
->lsa_un
.un_unknown
,
813 /* do we want to see an additionally hexdump ? */
815 if(!print_unknown_data(gndo
,(u_int8_t
*)lsap
->lsa_un
.un_unknown
,
816 "\n\t ", ls_length
)) {
826 ospf_decode_lls(register const struct ospfhdr
*op
,
827 register u_int length
)
829 register const u_char
*dptr
;
830 register const u_char
*dataend
;
831 register u_int length2
;
832 register u_int16_t lls_type
, lls_len
;
833 register u_int32_t lls_flags
;
835 switch (op
->ospf_type
) {
837 case OSPF_TYPE_HELLO
:
838 if (!(op
->ospf_hello
.hello_options
& OSPF_OPTION_L
))
843 if (!(op
->ospf_db
.db_options
& OSPF_OPTION_L
))
851 /* dig deeper if LLS data is available; see RFC4813 */
852 length2
= EXTRACT_16BITS(&op
->ospf_len
);
853 dptr
= (u_char
*)op
+ length2
;
854 dataend
= (u_char
*)op
+ length
;
856 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
857 dptr
= dptr
+ op
->ospf_authdata
[3];
858 length2
+= op
->ospf_authdata
[3];
860 if (length2
>= length
) {
861 printf("\n\t[LLS truncated]");
865 printf("\n\t LLS: checksum: 0x%04x", (u_int
)EXTRACT_16BITS(dptr
));
869 length2
= EXTRACT_16BITS(dptr
);
870 printf(", length: %u", length2
);
874 while (dptr
< dataend
) {
876 lls_type
= EXTRACT_16BITS(dptr
);
877 printf("\n\t %s (%u)",
878 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
882 lls_len
= EXTRACT_16BITS(dptr
);
883 printf(", length: %u", lls_len
);
889 printf(" [should be 4]");
893 lls_flags
= EXTRACT_32BITS(dptr
);
894 printf("\n\t Options: 0x%08x [%s]", lls_flags
,
895 bittok2str(ospf_lls_eo_options
,"?",lls_flags
));
901 printf(" [should be 20]");
905 printf("\n\t Sequence number: 0x%08x", EXTRACT_32BITS(dptr
));
918 ospf_decode_v2(register const struct ospfhdr
*op
,
919 register const u_char
*dataend
)
921 register const struct in_addr
*ap
;
922 register const struct lsr
*lsrp
;
923 register const struct lsa_hdr
*lshp
;
924 register const struct lsa
*lsap
;
925 register u_int32_t lsa_count
,lsa_count_max
;
927 switch (op
->ospf_type
) {
931 * Rob Coltun's special monitoring packets;
936 case OSPF_TYPE_HELLO
:
937 printf("\n\tOptions [%s]",
938 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
));
940 TCHECK(op
->ospf_hello
.hello_deadint
);
941 printf("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
942 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
943 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
944 ipaddr_string(&op
->ospf_hello
.hello_mask
),
945 op
->ospf_hello
.hello_priority
);
947 TCHECK(op
->ospf_hello
.hello_dr
);
948 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
949 printf("\n\t Designated Router %s",
950 ipaddr_string(&op
->ospf_hello
.hello_dr
));
952 TCHECK(op
->ospf_hello
.hello_bdr
);
953 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
954 printf(", Backup Designated Router %s",
955 ipaddr_string(&op
->ospf_hello
.hello_bdr
));
957 ap
= op
->ospf_hello
.hello_neighbor
;
958 if ((u_char
*)ap
< dataend
)
959 printf("\n\t Neighbor List:");
960 while ((u_char
*)ap
< dataend
) {
962 printf("\n\t %s", ipaddr_string(ap
));
968 TCHECK(op
->ospf_db
.db_options
);
969 printf("\n\tOptions [%s]",
970 bittok2str(ospf_option_values
,"none",op
->ospf_db
.db_options
));
971 TCHECK(op
->ospf_db
.db_flags
);
972 printf(", DD Flags [%s]",
973 bittok2str(ospf_dd_flag_values
,"none",op
->ospf_db
.db_flags
));
974 TCHECK(op
->ospf_db
.db_ifmtu
);
975 if (op
->ospf_db
.db_ifmtu
) {
976 printf(", MTU: %u", EXTRACT_16BITS(&op
->ospf_db
.db_ifmtu
));
978 TCHECK(op
->ospf_db
.db_seq
);
979 printf(", Sequence: 0x%08x", EXTRACT_32BITS(&op
->ospf_db
.db_seq
));
981 /* Print all the LS adv's */
982 lshp
= op
->ospf_db
.db_lshdr
;
983 while (((u_char
*)lshp
< dataend
) && ospf_print_lshdr(lshp
) != -1) {
988 case OSPF_TYPE_LS_REQ
:
990 while ((u_char
*)lsrp
< dataend
) {
993 printf("\n\t Advertising Router: %s, %s LSA (%u)",
994 ipaddr_string(&lsrp
->ls_router
),
995 tok2str(lsa_values
,"unknown",EXTRACT_32BITS(lsrp
->ls_type
)),
996 EXTRACT_32BITS(&lsrp
->ls_type
));
998 switch (EXTRACT_32BITS(lsrp
->ls_type
)) {
999 /* the LSA header for opaque LSAs was slightly changed */
1000 case LS_TYPE_OPAQUE_LL
:
1001 case LS_TYPE_OPAQUE_AL
:
1002 case LS_TYPE_OPAQUE_DW
:
1003 printf(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1004 tok2str(lsa_opaque_values
, "unknown",lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1005 lsrp
->un_ls_stateid
.opaque_field
.opaque_type
,
1006 EXTRACT_24BITS(&lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
1009 printf(", LSA-ID: %s",
1010 ipaddr_string(&lsrp
->un_ls_stateid
.ls_stateid
));
1018 case OSPF_TYPE_LS_UPDATE
:
1019 lsap
= op
->ospf_lsu
.lsu_lsa
;
1020 TCHECK(op
->ospf_lsu
.lsu_count
);
1021 lsa_count_max
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
1022 printf(", %d LSA%s",lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
));
1023 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1024 printf("\n\t LSA #%u",lsa_count
);
1025 lsap
= (const struct lsa
*)ospf_print_lsa(lsap
);
1031 case OSPF_TYPE_LS_ACK
:
1032 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1033 while (ospf_print_lshdr(lshp
) != -1) {
1047 ospf_print(register const u_char
*bp
, register u_int length
,
1048 const u_char
*bp2 _U_
)
1050 register const struct ospfhdr
*op
;
1051 register const u_char
*dataend
;
1052 register const char *cp
;
1054 op
= (struct ospfhdr
*)bp
;
1056 /* XXX Before we do anything else, strip off the MD5 trailer */
1057 TCHECK(op
->ospf_authtype
);
1058 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1059 length
-= OSPF_AUTH_MD5_LEN
;
1060 snapend
-= OSPF_AUTH_MD5_LEN
;
1063 /* If the type is valid translate it, or just print the type */
1064 /* value. If it's not valid, say so and return */
1065 TCHECK(op
->ospf_type
);
1066 cp
= tok2str(type2str
, "unknown LS-type", op
->ospf_type
);
1067 printf("OSPFv%u, %s, length %u",
1074 if(!vflag
) { /* non verbose - so lets bail out here */
1078 TCHECK(op
->ospf_len
);
1079 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
1080 printf(" [len %d]", EXTRACT_16BITS(&op
->ospf_len
));
1083 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1084 dataend
= bp
+ EXTRACT_16BITS(&op
->ospf_len
);
1086 dataend
= bp
+ length
;
1089 TCHECK(op
->ospf_routerid
);
1090 printf("\n\tRouter-ID %s", ipaddr_string(&op
->ospf_routerid
));
1092 TCHECK(op
->ospf_areaid
);
1093 if (op
->ospf_areaid
.s_addr
!= 0)
1094 printf(", Area %s", ipaddr_string(&op
->ospf_areaid
));
1096 printf(", Backbone Area");
1099 /* Print authentication data (should we really do this?) */
1100 TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
1102 printf(", Authentication Type: %s (%u)",
1103 tok2str(ospf_authtype_values
,"unknown",EXTRACT_16BITS(&op
->ospf_authtype
)),
1104 EXTRACT_16BITS(&op
->ospf_authtype
));
1106 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
1108 case OSPF_AUTH_NONE
:
1111 case OSPF_AUTH_SIMPLE
:
1112 printf("\n\tSimple text password: ");
1113 safeputs((const char *)op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
1117 printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1118 *((op
->ospf_authdata
)+2),
1119 *((op
->ospf_authdata
)+3),
1120 EXTRACT_32BITS((op
->ospf_authdata
)+4));
1127 /* Do rest according to version. */
1128 switch (op
->ospf_version
) {
1131 /* ospf version 2 */
1132 if (ospf_decode_v2(op
, dataend
))
1134 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1135 if (ospf_decode_lls(op
, length
))
1141 printf(" ospf [version %d]", op
->ospf_version
);
1143 } /* end switch on version */
1147 fputs(tstr
, stdout
);