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 const char tstr
[] = " [|ospf2]";
48 static const struct tok ospf_option_values
[] = {
49 { OSPF_OPTION_T
, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
50 { OSPF_OPTION_E
, "External" },
51 { OSPF_OPTION_MC
, "Multicast" },
52 { OSPF_OPTION_NP
, "NSSA" },
53 { OSPF_OPTION_L
, "LLS" },
54 { OSPF_OPTION_DC
, "Demand Circuit" },
55 { OSPF_OPTION_O
, "Opaque" },
56 { OSPF_OPTION_DN
, "Up/Down" },
60 static const struct tok ospf_authtype_values
[] = {
61 { OSPF_AUTH_NONE
, "none" },
62 { OSPF_AUTH_SIMPLE
, "simple" },
63 { OSPF_AUTH_MD5
, "MD5" },
67 static const struct tok ospf_rla_flag_values
[] = {
68 { RLA_FLAG_B
, "ABR" },
69 { RLA_FLAG_E
, "ASBR" },
70 { RLA_FLAG_W1
, "Virtual" },
71 { RLA_FLAG_W2
, "W2" },
75 static const struct tok type2str
[] = {
76 { OSPF_TYPE_UMD
, "UMD" },
77 { OSPF_TYPE_HELLO
, "Hello" },
78 { OSPF_TYPE_DD
, "Database Description" },
79 { OSPF_TYPE_LS_REQ
, "LS-Request" },
80 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
81 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
85 static const struct tok lsa_values
[] = {
86 { LS_TYPE_ROUTER
, "Router" },
87 { LS_TYPE_NETWORK
, "Network" },
88 { LS_TYPE_SUM_IP
, "Summary" },
89 { LS_TYPE_SUM_ABR
, "ASBR Summary" },
90 { LS_TYPE_ASE
, "External" },
91 { LS_TYPE_GROUP
, "Multicast Group" },
92 { LS_TYPE_NSSA
, "NSSA" },
93 { LS_TYPE_OPAQUE_LL
, "Link Local Opaque" },
94 { LS_TYPE_OPAQUE_AL
, "Area Local Opaque" },
95 { LS_TYPE_OPAQUE_DW
, "Domain Wide Opaque" },
99 static const struct tok ospf_dd_flag_values
[] = {
100 { OSPF_DB_INIT
, "Init" },
101 { OSPF_DB_MORE
, "More" },
102 { OSPF_DB_MASTER
, "Master" },
103 { OSPF_DB_RESYNC
, "OOBResync" },
107 static const struct tok lsa_opaque_values
[] = {
108 { LS_OPAQUE_TYPE_TE
, "Traffic Engineering" },
109 { LS_OPAQUE_TYPE_GRACE
, "Graceful restart" },
110 { LS_OPAQUE_TYPE_RI
, "Router Information" },
114 static const struct tok lsa_opaque_te_tlv_values
[] = {
115 { LS_OPAQUE_TE_TLV_ROUTER
, "Router Address" },
116 { LS_OPAQUE_TE_TLV_LINK
, "Link" },
120 static const struct tok lsa_opaque_te_link_tlv_subtlv_values
[] = {
121 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
, "Link Type" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
, "Link ID" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
, "Local Interface IP address" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
, "Remote Interface IP address" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
, "Traffic Engineering Metric" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
, "Maximum Bandwidth" },
127 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
, "Maximum Reservable Bandwidth" },
128 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
, "Unreserved Bandwidth" },
129 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
, "Administrative Group" },
130 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
, "Link Local/Remote Identifier" },
131 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
, "Link Protection Type" },
132 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
, "Interface Switching Capability" },
133 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
, "Shared Risk Link Group" },
134 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
, "Bandwidth Constraints" },
138 static const struct tok lsa_opaque_grace_tlv_values
[] = {
139 { LS_OPAQUE_GRACE_TLV_PERIOD
, "Grace Period" },
140 { LS_OPAQUE_GRACE_TLV_REASON
, "Graceful restart Reason" },
141 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS
, "IPv4 interface address" },
145 static const struct tok lsa_opaque_grace_tlv_reason_values
[] = {
146 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN
, "Unknown" },
147 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART
, "Software Restart" },
148 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE
, "Software Reload/Upgrade" },
149 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH
, "Control Processor Switch" },
153 static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values
[] = {
154 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP
, "Point-to-point" },
155 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA
, "Multi-Access" },
159 static const struct tok lsa_opaque_ri_tlv_values
[] = {
160 { LS_OPAQUE_RI_TLV_CAP
, "Router Capabilities" },
164 static const struct tok lsa_opaque_ri_tlv_cap_values
[] = {
169 { 16, "graceful restart capable" },
170 { 32, "graceful restart helper" },
171 { 64, "Stub router support" },
172 { 128, "Traffic engineering" },
173 { 256, "p2p over LAN" },
174 { 512, "path computation server" },
178 static const struct tok ospf_lls_tlv_values
[] = {
179 { OSPF_LLS_EO
, "Extended Options" },
180 { OSPF_LLS_MD5
, "MD5 Authentication" },
184 static const struct tok ospf_lls_eo_options
[] = {
185 { OSPF_LLS_EO_LR
, "LSDB resync" },
186 { OSPF_LLS_EO_RS
, "Restart" },
190 static int ospf_print_lshdr(const struct lsa_hdr
*);
191 static const u_char
*ospf_print_lsa(const struct lsa
*);
192 static int ospf_decode_v2(const struct ospfhdr
*, const u_char
*);
193 static int ospf_decode_lls(const struct ospfhdr
*, register u_int
);
196 ospf_print_grace_lsa (const u_int8_t
*tptr
, u_int ls_length
) {
198 u_int tlv_type
, tlv_length
;
201 while (ls_length
> 0) {
204 printf("\n\t Remaining LS length %u < 4", ls_length
);
207 tlv_type
= EXTRACT_16BITS(tptr
);
208 tlv_length
= EXTRACT_16BITS(tptr
+2);
212 printf("\n\t %s TLV (%u), length %u, value: ",
213 tok2str(lsa_opaque_grace_tlv_values
,"unknown",tlv_type
),
217 if (tlv_length
> ls_length
) {
218 printf("\n\t Bogus length %u > %u", tlv_length
,
223 /* Infinite loop protection. */
224 if (tlv_type
== 0 || tlv_length
==0) {
228 TCHECK2(*tptr
, tlv_length
);
231 case LS_OPAQUE_GRACE_TLV_PERIOD
:
232 if (tlv_length
!= 4) {
233 printf("\n\t Bogus length %u != 4", tlv_length
);
236 printf("%us",EXTRACT_32BITS(tptr
));
239 case LS_OPAQUE_GRACE_TLV_REASON
:
240 if (tlv_length
!= 1) {
241 printf("\n\t Bogus length %u != 1", tlv_length
);
245 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", *tptr
),
249 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
250 if (tlv_length
!= 4) {
251 printf("\n\t Bogus length %u != 4", tlv_length
);
254 printf("%s", ipaddr_string(tptr
));
259 if(!print_unknown_data(gndo
,tptr
,"\n\t ",tlv_length
))
265 /* in OSPF everything has to be 32-bit aligned, including TLVs */
266 if (tlv_length
%4 != 0)
267 tlv_length
+=4-(tlv_length
%4);
268 ls_length
-=tlv_length
;
278 ospf_print_te_lsa (const u_int8_t
*tptr
, u_int ls_length
) {
280 u_int tlv_type
, tlv_length
, subtlv_type
, subtlv_length
;
281 u_int priority_level
, te_class
, count_srlg
;
282 union { /* int to float conversion buffer for several subTLVs */
287 while (ls_length
!= 0) {
290 printf("\n\t Remaining LS length %u < 4", ls_length
);
293 tlv_type
= EXTRACT_16BITS(tptr
);
294 tlv_length
= EXTRACT_16BITS(tptr
+2);
298 printf("\n\t %s TLV (%u), length: %u",
299 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
303 if (tlv_length
> ls_length
) {
304 printf("\n\t Bogus length %u > %u", tlv_length
,
309 /* Infinite loop protection. */
310 if (tlv_type
== 0 || tlv_length
==0) {
315 case LS_OPAQUE_TE_TLV_LINK
:
316 while (tlv_length
>= sizeof(subtlv_type
) + sizeof(subtlv_length
)) {
317 if (tlv_length
< 4) {
318 printf("\n\t Remaining TLV length %u < 4",
323 subtlv_type
= EXTRACT_16BITS(tptr
);
324 subtlv_length
= EXTRACT_16BITS(tptr
+2);
328 printf("\n\t %s subTLV (%u), length: %u",
329 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
333 TCHECK2(*tptr
, subtlv_length
);
334 switch(subtlv_type
) {
335 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
336 printf(", 0x%08x", EXTRACT_32BITS(tptr
));
338 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
339 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
340 printf(", %s (0x%08x)",
342 EXTRACT_32BITS(tptr
));
343 if (subtlv_length
== 8) /* rfc4203 */
344 printf(", %s (0x%08x)",
345 ipaddr_string(tptr
+4),
346 EXTRACT_32BITS(tptr
+4));
348 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
349 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
350 printf(", %s", ipaddr_string(tptr
));
352 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
353 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
354 bw
.i
= EXTRACT_32BITS(tptr
);
355 printf(", %.3f Mbps", bw
.f
*8/1000000 );
357 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
358 for (te_class
= 0; te_class
< 8; te_class
++) {
359 bw
.i
= EXTRACT_32BITS(tptr
+te_class
*4);
360 printf("\n\t\tTE-Class %u: %.3f Mbps",
365 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
366 printf("\n\t\tBandwidth Constraints Model ID: %s (%u)",
367 tok2str(diffserv_te_bc_values
, "unknown", *tptr
),
369 /* decode BCs until the subTLV ends */
370 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
371 bw
.i
= EXTRACT_32BITS(tptr
+4+te_class
*4);
372 printf("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
377 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
378 printf(", Metric %u", EXTRACT_32BITS(tptr
));
380 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
381 printf(", %s, Priority %u",
382 bittok2str(gmpls_link_prot_values
, "none", *tptr
),
385 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
386 printf("\n\t\tInterface Switching Capability: %s",
387 tok2str(gmpls_switch_cap_values
, "Unknown", *(tptr
)));
388 printf("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
389 tok2str(gmpls_encoding_values
, "Unknown", *(tptr
+1)));
390 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
391 bw
.i
= EXTRACT_32BITS(tptr
+4+(priority_level
*4));
392 printf("\n\t\t priority level %d: %.3f Mbps",
397 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
399 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",*tptr
),
403 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
404 count_srlg
= subtlv_length
/ 4;
406 printf("\n\t\t Shared risk group: ");
407 while (count_srlg
> 0) {
408 bw
.i
= EXTRACT_32BITS(tptr
);
419 if(!print_unknown_data(gndo
,tptr
,"\n\t\t",subtlv_length
))
424 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
425 if (subtlv_length
%4 != 0)
426 subtlv_length
+=4-(subtlv_length
%4);
428 tlv_length
-=subtlv_length
;
434 case LS_OPAQUE_TE_TLV_ROUTER
:
435 if (tlv_length
< 4) {
436 printf("\n\t TLV length %u < 4", tlv_length
);
440 printf(", %s", ipaddr_string(tptr
));
445 if(!print_unknown_data(gndo
,tptr
,"\n\t ",tlv_length
))
450 /* in OSPF everything has to be 32-bit aligned, including TLVs */
451 if (tlv_length
%4 != 0)
452 tlv_length
+=4-(tlv_length
%4);
453 ls_length
-=tlv_length
;
463 ospf_print_lshdr(register const struct lsa_hdr
*lshp
)
467 TCHECK(lshp
->ls_length
);
468 ls_length
= EXTRACT_16BITS(&lshp
->ls_length
);
469 if (ls_length
< sizeof(struct lsa_hdr
)) {
470 printf("\n\t Bogus length %u < header (%lu)", ls_length
,
471 (unsigned long)sizeof(struct lsa_hdr
));
475 TCHECK(lshp
->ls_seq
); /* XXX - ls_length check checked this */
476 printf("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
477 ipaddr_string(&lshp
->ls_router
),
478 EXTRACT_32BITS(&lshp
->ls_seq
),
479 EXTRACT_16BITS(&lshp
->ls_age
),
480 ls_length
-(u_int
)sizeof(struct lsa_hdr
));
482 TCHECK(lshp
->ls_type
); /* XXX - ls_length check checked this */
483 switch (lshp
->ls_type
) {
484 /* the LSA header for opaque LSAs was slightly changed */
485 case LS_TYPE_OPAQUE_LL
:
486 case LS_TYPE_OPAQUE_AL
:
487 case LS_TYPE_OPAQUE_DW
:
488 printf("\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
489 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
492 tok2str(lsa_opaque_values
,
494 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
495 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
),
496 EXTRACT_24BITS(&lshp
->un_lsa_id
.opaque_field
.opaque_id
)
501 /* all other LSA types use regular style LSA headers */
503 printf("\n\t %s LSA (%d), LSA-ID: %s",
504 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
506 ipaddr_string(&lshp
->un_lsa_id
.lsa_id
));
510 TCHECK(lshp
->ls_options
); /* XXX - ls_length check checked this */
511 printf("\n\t Options: [%s]", bittok2str(ospf_option_values
,"none",lshp
->ls_options
));
518 /* draft-ietf-ospf-mt-09 */
519 static const struct tok ospf_topology_values
[] = {
522 { 2, "management " },
527 * Print all the per-topology metrics.
530 ospf_print_tos_metrics(const union un_tos
*tos
)
535 toscount
= tos
->link
.link_tos_count
+1;
539 * All but the first metric contain a valid topology id.
542 printf("\n\t\ttopology %s(%u), metric %u",
543 tok2str(ospf_topology_values
, "",
544 metric_count
? tos
->metrics
.tos_type
: 0),
545 metric_count
? tos
->metrics
.tos_type
: 0,
546 EXTRACT_16BITS(&tos
->metrics
.tos_metric
));
554 * Print a single link state advertisement. If truncated or if LSA length
555 * field is less than the length of the LSA header, return NULl, else
556 * return pointer to data past end of LSA.
558 static const u_int8_t
*
559 ospf_print_lsa(register const struct lsa
*lsap
)
561 register const u_int8_t
*ls_end
;
562 register const struct rlalink
*rlp
;
563 register const struct in_addr
*ap
;
564 register const struct aslametric
*almp
;
565 register const struct mcla
*mcp
;
566 register const u_int32_t
*lp
;
567 register int j
, tlv_type
, tlv_length
, topology
;
568 register int ls_length
;
569 const u_int8_t
*tptr
;
571 tptr
= (u_int8_t
*)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
572 ls_length
= ospf_print_lshdr(&lsap
->ls_hdr
);
575 ls_end
= (u_int8_t
*)lsap
+ ls_length
;
576 ls_length
-= sizeof(struct lsa_hdr
);
578 switch (lsap
->ls_hdr
.ls_type
) {
581 TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
582 printf("\n\t Router LSA Options: [%s]", bittok2str(ospf_rla_flag_values
,"none",lsap
->lsa_un
.un_rla
.rla_flags
));
584 TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
585 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
586 TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
587 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
590 switch (rlp
->un_tos
.link
.link_type
) {
592 case RLA_TYPE_VIRTUAL
:
593 printf("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
594 ipaddr_string(&rlp
->link_id
),
595 ipaddr_string(&rlp
->link_data
));
598 case RLA_TYPE_ROUTER
:
599 printf("\n\t Neighbor Router-ID: %s, Interface Address: %s",
600 ipaddr_string(&rlp
->link_id
),
601 ipaddr_string(&rlp
->link_data
));
604 case RLA_TYPE_TRANSIT
:
605 printf("\n\t Neighbor Network-ID: %s, Interface Address: %s",
606 ipaddr_string(&rlp
->link_id
),
607 ipaddr_string(&rlp
->link_data
));
611 printf("\n\t Stub Network: %s, Mask: %s",
612 ipaddr_string(&rlp
->link_id
),
613 ipaddr_string(&rlp
->link_data
));
617 printf("\n\t Unknown Router Link Type (%u)",
618 rlp
->un_tos
.link
.link_type
);
622 ospf_print_tos_metrics(&rlp
->un_tos
);
624 rlp
= (struct rlalink
*)((u_char
*)(rlp
+ 1) +
625 ((rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
629 case LS_TYPE_NETWORK
:
630 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
631 printf("\n\t Mask %s\n\t Connected Routers:",
632 ipaddr_string(&lsap
->lsa_un
.un_nla
.nla_mask
));
633 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
634 while ((u_char
*)ap
< ls_end
) {
636 printf("\n\t %s", ipaddr_string(ap
));
642 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
643 printf("\n\t Mask %s",
644 ipaddr_string(&lsap
->lsa_un
.un_sla
.sla_mask
));
645 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
646 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
647 while ((u_char
*)lp
< ls_end
) {
648 register u_int32_t ul
;
651 ul
= EXTRACT_32BITS(lp
);
652 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
653 printf("\n\t\ttopology %s(%u) metric %d",
654 tok2str(ospf_topology_values
, "", topology
),
656 ul
& SLA_MASK_METRIC
);
661 case LS_TYPE_SUM_ABR
:
662 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
663 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
664 while ((u_char
*)lp
< ls_end
) {
665 register u_int32_t ul
;
668 ul
= EXTRACT_32BITS(lp
);
669 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
670 printf("\n\t\ttopology %s(%u) metric %d",
671 tok2str(ospf_topology_values
, "", topology
),
673 ul
& SLA_MASK_METRIC
);
679 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
680 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
681 printf("\n\t Mask %s",
682 ipaddr_string(&lsap
->lsa_un
.un_asla
.asla_mask
));
684 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
685 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
686 while ((u_char
*)almp
< ls_end
) {
687 register u_int32_t ul
;
689 TCHECK(almp
->asla_tosmetric
);
690 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
691 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
692 printf("\n\t\ttopology %s(%u), type %d, metric",
693 tok2str(ospf_topology_values
, "", topology
),
695 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1);
696 if ((ul
& ASLA_MASK_METRIC
)==0xffffff)
699 printf(" %d", (ul
& ASLA_MASK_METRIC
));
701 TCHECK(almp
->asla_forward
);
702 if (almp
->asla_forward
.s_addr
) {
703 printf(", forward %s",
704 ipaddr_string(&almp
->asla_forward
));
706 TCHECK(almp
->asla_tag
);
707 if (almp
->asla_tag
.s_addr
) {
709 ipaddr_string(&almp
->asla_tag
));
716 /* Multicast extensions as of 23 July 1991 */
717 mcp
= lsap
->lsa_un
.un_mcla
;
718 while ((u_char
*)mcp
< ls_end
) {
719 TCHECK(mcp
->mcla_vid
);
720 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
722 case MCLA_VERTEX_ROUTER
:
723 printf("\n\t Router Router-ID %s",
724 ipaddr_string(&mcp
->mcla_vid
));
727 case MCLA_VERTEX_NETWORK
:
728 printf("\n\t Network Designated Router %s",
729 ipaddr_string(&mcp
->mcla_vid
));
733 printf("\n\t unknown VertexType (%u)",
734 EXTRACT_32BITS(&mcp
->mcla_vtype
));
741 case LS_TYPE_OPAQUE_LL
: /* fall through */
742 case LS_TYPE_OPAQUE_AL
:
743 case LS_TYPE_OPAQUE_DW
:
745 switch (*(&lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
746 case LS_OPAQUE_TYPE_RI
:
747 tptr
= (u_int8_t
*)(&lsap
->lsa_un
.un_ri_tlv
.type
);
749 while (ls_length
!= 0) {
752 printf("\n\t Remaining LS length %u < 4", ls_length
);
755 tlv_type
= EXTRACT_16BITS(tptr
);
756 tlv_length
= EXTRACT_16BITS(tptr
+2);
760 printf("\n\t %s TLV (%u), length: %u, value: ",
761 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
765 if (tlv_length
> ls_length
) {
766 printf("\n\t Bogus length %u > %u", tlv_length
,
770 TCHECK2(*tptr
, tlv_length
);
773 case LS_OPAQUE_RI_TLV_CAP
:
774 if (tlv_length
!= 4) {
775 printf("\n\t Bogus length %u != 4", tlv_length
);
778 printf("Capabilities: %s",
779 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", EXTRACT_32BITS(tptr
)));
783 if(!print_unknown_data(gndo
,tptr
,"\n\t ",tlv_length
))
790 ls_length
-=tlv_length
;
794 case LS_OPAQUE_TYPE_GRACE
:
795 if (ospf_print_grace_lsa((u_int8_t
*)(&lsap
->lsa_un
.un_grace_tlv
.type
),
801 case LS_OPAQUE_TYPE_TE
:
802 if (ospf_print_te_lsa((u_int8_t
*)(&lsap
->lsa_un
.un_te_lsa_tlv
.type
),
810 if(!print_unknown_data(gndo
,(u_int8_t
*)lsap
->lsa_un
.un_unknown
,
818 /* do we want to see an additionally hexdump ? */
820 if(!print_unknown_data(gndo
,(u_int8_t
*)lsap
->lsa_un
.un_unknown
,
821 "\n\t ", ls_length
)) {
831 ospf_decode_lls(register const struct ospfhdr
*op
,
832 register u_int length
)
834 register const u_char
*dptr
;
835 register const u_char
*dataend
;
836 register u_int length2
;
837 register u_int16_t lls_type
, lls_len
;
838 register u_int32_t lls_flags
;
840 switch (op
->ospf_type
) {
842 case OSPF_TYPE_HELLO
:
843 if (!(op
->ospf_hello
.hello_options
& OSPF_OPTION_L
))
848 if (!(op
->ospf_db
.db_options
& OSPF_OPTION_L
))
856 /* dig deeper if LLS data is available; see RFC4813 */
857 length2
= EXTRACT_16BITS(&op
->ospf_len
);
858 dptr
= (u_char
*)op
+ length2
;
859 dataend
= (u_char
*)op
+ length
;
861 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
862 dptr
= dptr
+ op
->ospf_authdata
[3];
863 length2
+= op
->ospf_authdata
[3];
865 if (length2
>= length
) {
866 printf("\n\t[LLS truncated]");
870 printf("\n\t LLS: checksum: 0x%04x", (u_int
)EXTRACT_16BITS(dptr
));
874 length2
= EXTRACT_16BITS(dptr
);
875 printf(", length: %u", length2
);
879 while (dptr
< dataend
) {
881 lls_type
= EXTRACT_16BITS(dptr
);
882 printf("\n\t %s (%u)",
883 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
887 lls_len
= EXTRACT_16BITS(dptr
);
888 printf(", length: %u", lls_len
);
894 printf(" [should be 4]");
898 lls_flags
= EXTRACT_32BITS(dptr
);
899 printf("\n\t Options: 0x%08x [%s]", lls_flags
,
900 bittok2str(ospf_lls_eo_options
,"?",lls_flags
));
906 printf(" [should be 20]");
910 printf("\n\t Sequence number: 0x%08x", EXTRACT_32BITS(dptr
));
923 ospf_decode_v2(register const struct ospfhdr
*op
,
924 register const u_char
*dataend
)
926 register const struct in_addr
*ap
;
927 register const struct lsr
*lsrp
;
928 register const struct lsa_hdr
*lshp
;
929 register const struct lsa
*lsap
;
930 register u_int32_t lsa_count
,lsa_count_max
;
932 switch (op
->ospf_type
) {
936 * Rob Coltun's special monitoring packets;
941 case OSPF_TYPE_HELLO
:
942 printf("\n\tOptions [%s]",
943 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
));
945 TCHECK(op
->ospf_hello
.hello_deadint
);
946 printf("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
947 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
948 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
949 ipaddr_string(&op
->ospf_hello
.hello_mask
),
950 op
->ospf_hello
.hello_priority
);
952 TCHECK(op
->ospf_hello
.hello_dr
);
953 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
954 printf("\n\t Designated Router %s",
955 ipaddr_string(&op
->ospf_hello
.hello_dr
));
957 TCHECK(op
->ospf_hello
.hello_bdr
);
958 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
959 printf(", Backup Designated Router %s",
960 ipaddr_string(&op
->ospf_hello
.hello_bdr
));
962 ap
= op
->ospf_hello
.hello_neighbor
;
963 if ((u_char
*)ap
< dataend
)
964 printf("\n\t Neighbor List:");
965 while ((u_char
*)ap
< dataend
) {
967 printf("\n\t %s", ipaddr_string(ap
));
973 TCHECK(op
->ospf_db
.db_options
);
974 printf("\n\tOptions [%s]",
975 bittok2str(ospf_option_values
,"none",op
->ospf_db
.db_options
));
976 TCHECK(op
->ospf_db
.db_flags
);
977 printf(", DD Flags [%s]",
978 bittok2str(ospf_dd_flag_values
,"none",op
->ospf_db
.db_flags
));
979 TCHECK(op
->ospf_db
.db_ifmtu
);
980 if (op
->ospf_db
.db_ifmtu
) {
981 printf(", MTU: %u", EXTRACT_16BITS(&op
->ospf_db
.db_ifmtu
));
983 TCHECK(op
->ospf_db
.db_seq
);
984 printf(", Sequence: 0x%08x", EXTRACT_32BITS(&op
->ospf_db
.db_seq
));
986 /* Print all the LS adv's */
987 lshp
= op
->ospf_db
.db_lshdr
;
988 while (((u_char
*)lshp
< dataend
) && ospf_print_lshdr(lshp
) != -1) {
993 case OSPF_TYPE_LS_REQ
:
995 while ((u_char
*)lsrp
< dataend
) {
998 printf("\n\t Advertising Router: %s, %s LSA (%u)",
999 ipaddr_string(&lsrp
->ls_router
),
1000 tok2str(lsa_values
,"unknown",EXTRACT_32BITS(lsrp
->ls_type
)),
1001 EXTRACT_32BITS(&lsrp
->ls_type
));
1003 switch (EXTRACT_32BITS(lsrp
->ls_type
)) {
1004 /* the LSA header for opaque LSAs was slightly changed */
1005 case LS_TYPE_OPAQUE_LL
:
1006 case LS_TYPE_OPAQUE_AL
:
1007 case LS_TYPE_OPAQUE_DW
:
1008 printf(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1009 tok2str(lsa_opaque_values
, "unknown",lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1010 lsrp
->un_ls_stateid
.opaque_field
.opaque_type
,
1011 EXTRACT_24BITS(&lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
1014 printf(", LSA-ID: %s",
1015 ipaddr_string(&lsrp
->un_ls_stateid
.ls_stateid
));
1023 case OSPF_TYPE_LS_UPDATE
:
1024 lsap
= op
->ospf_lsu
.lsu_lsa
;
1025 TCHECK(op
->ospf_lsu
.lsu_count
);
1026 lsa_count_max
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
1027 printf(", %d LSA%s",lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
));
1028 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1029 printf("\n\t LSA #%u",lsa_count
);
1030 lsap
= (const struct lsa
*)ospf_print_lsa(lsap
);
1036 case OSPF_TYPE_LS_ACK
:
1037 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1038 while (ospf_print_lshdr(lshp
) != -1) {
1052 ospf_print(register const u_char
*bp
, register u_int length
,
1053 const u_char
*bp2 _U_
)
1055 register const struct ospfhdr
*op
;
1056 register const u_char
*dataend
;
1057 register const char *cp
;
1059 op
= (struct ospfhdr
*)bp
;
1061 /* XXX Before we do anything else, strip off the MD5 trailer */
1062 TCHECK(op
->ospf_authtype
);
1063 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1064 length
-= OSPF_AUTH_MD5_LEN
;
1065 snapend
-= OSPF_AUTH_MD5_LEN
;
1068 /* If the type is valid translate it, or just print the type */
1069 /* value. If it's not valid, say so and return */
1070 TCHECK(op
->ospf_type
);
1071 cp
= tok2str(type2str
, "unknown LS-type", op
->ospf_type
);
1072 printf("OSPFv%u, %s, length %u",
1079 if(!vflag
) { /* non verbose - so lets bail out here */
1083 TCHECK(op
->ospf_len
);
1084 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
1085 printf(" [len %d]", EXTRACT_16BITS(&op
->ospf_len
));
1088 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1089 dataend
= bp
+ EXTRACT_16BITS(&op
->ospf_len
);
1091 dataend
= bp
+ length
;
1094 TCHECK(op
->ospf_routerid
);
1095 printf("\n\tRouter-ID %s", ipaddr_string(&op
->ospf_routerid
));
1097 TCHECK(op
->ospf_areaid
);
1098 if (op
->ospf_areaid
.s_addr
!= 0)
1099 printf(", Area %s", ipaddr_string(&op
->ospf_areaid
));
1101 printf(", Backbone Area");
1104 /* Print authentication data (should we really do this?) */
1105 TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
1107 printf(", Authentication Type: %s (%u)",
1108 tok2str(ospf_authtype_values
,"unknown",EXTRACT_16BITS(&op
->ospf_authtype
)),
1109 EXTRACT_16BITS(&op
->ospf_authtype
));
1111 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
1113 case OSPF_AUTH_NONE
:
1116 case OSPF_AUTH_SIMPLE
:
1117 printf("\n\tSimple text password: ");
1118 safeputs((const char *)op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
1122 printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1123 *((op
->ospf_authdata
)+2),
1124 *((op
->ospf_authdata
)+3),
1125 EXTRACT_32BITS((op
->ospf_authdata
)+4));
1132 /* Do rest according to version. */
1133 switch (op
->ospf_version
) {
1136 /* ospf version 2 */
1137 if (ospf_decode_v2(op
, dataend
))
1139 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1140 if (ospf_decode_lls(op
, length
))
1146 printf(" ospf [version %d]", op
->ospf_version
);
1148 } /* end switch on version */
1152 fputs(tstr
, stdout
);