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)
24 /* \summary: Open Shortest Path First (OSPF) printer */
30 #include "netdissect-stdinc.h"
32 #include "netdissect.h"
33 #include "addrtoname.h"
40 static const struct tok ospf_option_values
[] = {
41 { OSPF_OPTION_T
, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
42 { OSPF_OPTION_E
, "External" },
43 { OSPF_OPTION_MC
, "Multicast" },
44 { OSPF_OPTION_NP
, "NSSA" },
45 { OSPF_OPTION_L
, "LLS" },
46 { OSPF_OPTION_DC
, "Demand Circuit" },
47 { OSPF_OPTION_O
, "Opaque" },
48 { OSPF_OPTION_DN
, "Up/Down" },
52 static const struct tok ospf_authtype_values
[] = {
53 { OSPF_AUTH_NONE
, "none" },
54 { OSPF_AUTH_SIMPLE
, "simple" },
55 { OSPF_AUTH_MD5
, "MD5" },
59 static const struct tok ospf_rla_flag_values
[] = {
60 { RLA_FLAG_B
, "ABR" },
61 { RLA_FLAG_E
, "ASBR" },
62 { RLA_FLAG_W1
, "Virtual" },
63 { RLA_FLAG_W2
, "W2" },
67 static const struct tok type2str
[] = {
68 { OSPF_TYPE_HELLO
, "Hello" },
69 { OSPF_TYPE_DD
, "Database Description" },
70 { OSPF_TYPE_LS_REQ
, "LS-Request" },
71 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
72 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
76 static const struct tok lsa_values
[] = {
77 { LS_TYPE_ROUTER
, "Router" },
78 { LS_TYPE_NETWORK
, "Network" },
79 { LS_TYPE_SUM_IP
, "Summary" },
80 { LS_TYPE_SUM_ABR
, "ASBR Summary" },
81 { LS_TYPE_ASE
, "External" },
82 { LS_TYPE_GROUP
, "Multicast Group" },
83 { LS_TYPE_NSSA
, "NSSA" },
84 { LS_TYPE_OPAQUE_LL
, "Link Local Opaque" },
85 { LS_TYPE_OPAQUE_AL
, "Area Local Opaque" },
86 { LS_TYPE_OPAQUE_DW
, "Domain Wide Opaque" },
90 static const struct tok ospf_dd_flag_values
[] = {
91 { OSPF_DB_INIT
, "Init" },
92 { OSPF_DB_MORE
, "More" },
93 { OSPF_DB_MASTER
, "Master" },
94 { OSPF_DB_RESYNC
, "OOBResync" },
98 static const struct tok lsa_opaque_values
[] = {
99 { LS_OPAQUE_TYPE_TE
, "Traffic Engineering" },
100 { LS_OPAQUE_TYPE_GRACE
, "Graceful restart" },
101 { LS_OPAQUE_TYPE_RI
, "Router Information" },
105 static const struct tok lsa_opaque_te_tlv_values
[] = {
106 { LS_OPAQUE_TE_TLV_ROUTER
, "Router Address" },
107 { LS_OPAQUE_TE_TLV_LINK
, "Link" },
111 static const struct tok lsa_opaque_te_link_tlv_subtlv_values
[] = {
112 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
, "Link Type" },
113 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
, "Link ID" },
114 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
, "Local Interface IP address" },
115 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
, "Remote Interface IP address" },
116 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
, "Traffic Engineering Metric" },
117 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
, "Maximum Bandwidth" },
118 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
, "Maximum Reservable Bandwidth" },
119 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
, "Unreserved Bandwidth" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
, "Administrative Group" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
, "Link Local/Remote Identifier" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
, "Link Protection Type" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
, "Interface Switching Capability" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
, "Shared Risk Link Group" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
, "Bandwidth Constraints" },
129 static const struct tok lsa_opaque_grace_tlv_values
[] = {
130 { LS_OPAQUE_GRACE_TLV_PERIOD
, "Grace Period" },
131 { LS_OPAQUE_GRACE_TLV_REASON
, "Graceful restart Reason" },
132 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS
, "IPv4 interface address" },
136 static const struct tok lsa_opaque_grace_tlv_reason_values
[] = {
137 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN
, "Unknown" },
138 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART
, "Software Restart" },
139 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE
, "Software Reload/Upgrade" },
140 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH
, "Control Processor Switch" },
144 static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values
[] = {
145 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP
, "Point-to-point" },
146 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA
, "Multi-Access" },
150 static const struct tok lsa_opaque_ri_tlv_values
[] = {
151 { LS_OPAQUE_RI_TLV_CAP
, "Router Capabilities" },
155 static const struct tok lsa_opaque_ri_tlv_cap_values
[] = {
160 { 16, "graceful restart capable" },
161 { 32, "graceful restart helper" },
162 { 64, "Stub router support" },
163 { 128, "Traffic engineering" },
164 { 256, "p2p over LAN" },
165 { 512, "path computation server" },
169 static const struct tok ospf_lls_tlv_values
[] = {
170 { OSPF_LLS_EO
, "Extended Options" },
171 { OSPF_LLS_MD5
, "MD5 Authentication" },
175 static const struct tok ospf_lls_eo_options
[] = {
176 { OSPF_LLS_EO_LR
, "LSDB resync" },
177 { OSPF_LLS_EO_RS
, "Restart" },
182 ospf_grace_lsa_print(netdissect_options
*ndo
,
183 const u_char
*tptr
, u_int ls_length
)
185 u_int tlv_type
, tlv_length
;
188 while (ls_length
> 0) {
191 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length
);
194 tlv_type
= GET_BE_U_2(tptr
);
195 tlv_length
= GET_BE_U_2(tptr
+ 2);
199 ND_PRINT("\n\t %s TLV (%u), length %u, value: ",
200 tok2str(lsa_opaque_grace_tlv_values
,"unknown",tlv_type
),
204 if (tlv_length
> ls_length
) {
205 ND_PRINT("\n\t Bogus length %u > %u", tlv_length
,
210 /* Infinite loop protection. */
211 if (tlv_type
== 0 || tlv_length
==0) {
215 ND_TCHECK_LEN(tptr
, tlv_length
);
218 case LS_OPAQUE_GRACE_TLV_PERIOD
:
219 if (tlv_length
!= 4) {
220 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
223 ND_PRINT("%us", GET_BE_U_4(tptr
));
226 case LS_OPAQUE_GRACE_TLV_REASON
:
227 if (tlv_length
!= 1) {
228 ND_PRINT("\n\t Bogus length %u != 1", tlv_length
);
232 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", GET_U_1(tptr
)),
236 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
237 if (tlv_length
!= 4) {
238 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
241 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
245 if (ndo
->ndo_vflag
<= 1) {
246 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
252 /* in OSPF everything has to be 32-bit aligned, including TLVs */
253 if (tlv_length
%4 != 0)
254 tlv_length
+=4-(tlv_length
%4);
255 ls_length
-=tlv_length
;
265 ospf_te_lsa_print(netdissect_options
*ndo
,
266 const u_char
*tptr
, u_int ls_length
)
268 u_int tlv_type
, tlv_length
, subtlv_type
, subtlv_length
;
269 u_int priority_level
, te_class
, count_srlg
;
270 union { /* int to float conversion buffer for several subTLVs */
275 while (ls_length
!= 0) {
278 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length
);
281 tlv_type
= GET_BE_U_2(tptr
);
282 tlv_length
= GET_BE_U_2(tptr
+ 2);
286 ND_PRINT("\n\t %s TLV (%u), length: %u",
287 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
291 if (tlv_length
> ls_length
) {
292 ND_PRINT("\n\t Bogus length %u > %u", tlv_length
,
297 /* Infinite loop protection. */
298 if (tlv_type
== 0 || tlv_length
==0) {
303 case LS_OPAQUE_TE_TLV_LINK
:
304 while (tlv_length
!= 0) {
305 if (tlv_length
< 4) {
306 ND_PRINT("\n\t Remaining TLV length %u < 4",
311 subtlv_type
= GET_BE_U_2(tptr
);
312 subtlv_length
= GET_BE_U_2(tptr
+ 2);
316 /* Infinite loop protection */
317 if (subtlv_type
== 0 || subtlv_length
== 0)
320 ND_PRINT("\n\t %s subTLV (%u), length: %u",
321 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
325 if (tlv_length
< subtlv_length
) {
326 ND_PRINT("\n\t Remaining TLV length %u < %u",
327 tlv_length
+ 4, subtlv_length
+ 4);
330 ND_TCHECK_LEN(tptr
, subtlv_length
);
331 switch(subtlv_type
) {
332 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
333 if (subtlv_length
!= 4) {
337 ND_PRINT(", 0x%08x", GET_BE_U_4(tptr
));
339 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
340 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
341 if (subtlv_length
!= 4 && subtlv_length
!= 8) {
342 ND_PRINT(" != 4 && != 8");
345 ND_PRINT(", %s (0x%08x)",
346 GET_IPADDR_STRING(tptr
),
348 if (subtlv_length
== 8) /* rfc4203 */
349 ND_PRINT(", %s (0x%08x)",
350 GET_IPADDR_STRING(tptr
+4),
351 GET_BE_U_4(tptr
+ 4));
353 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
354 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
355 if (subtlv_length
!= 4) {
359 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
361 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
362 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
363 if (subtlv_length
!= 4) {
367 bw
.i
= GET_BE_U_4(tptr
);
368 ND_PRINT(", %.3f Mbps", bw
.f
* 8 / 1000000);
370 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
371 if (subtlv_length
!= 32) {
375 for (te_class
= 0; te_class
< 8; te_class
++) {
376 bw
.i
= GET_BE_U_4(tptr
+ te_class
* 4);
377 ND_PRINT("\n\t\tTE-Class %u: %.3f Mbps",
382 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
383 if (subtlv_length
< 4) {
387 /* BC Model Id (1 octet) + Reserved (3 octets) */
388 ND_PRINT("\n\t\tBandwidth Constraints Model ID: %s (%u)",
389 tok2str(diffserv_te_bc_values
, "unknown", GET_U_1(tptr
)),
391 if (subtlv_length
% 4 != 0) {
392 ND_PRINT("\n\t\tlength %u != N x 4", subtlv_length
);
395 if (subtlv_length
> 36) {
396 ND_PRINT("\n\t\tlength %u > 36", subtlv_length
);
399 /* decode BCs until the subTLV ends */
400 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
401 bw
.i
= GET_BE_U_4(tptr
+ 4 + te_class
* 4);
402 ND_PRINT("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
407 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
408 if (subtlv_length
!= 4) {
412 ND_PRINT(", Metric %u", GET_BE_U_4(tptr
));
414 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
415 /* Protection Cap (1 octet) + Reserved ((3 octets) */
416 if (subtlv_length
!= 4) {
421 bittok2str(gmpls_link_prot_values
, "none", GET_U_1(tptr
)));
423 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
424 if (subtlv_length
< 36) {
428 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
429 ND_PRINT("\n\t\tInterface Switching Capability: %s",
430 tok2str(gmpls_switch_cap_values
, "Unknown", GET_U_1((tptr
))));
431 ND_PRINT("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
432 tok2str(gmpls_encoding_values
, "Unknown", GET_U_1((tptr
+ 1))));
433 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
434 bw
.i
= GET_BE_U_4(tptr
+ 4 + (priority_level
* 4));
435 ND_PRINT("\n\t\t priority level %u: %.3f Mbps",
440 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
441 if (subtlv_length
!= 1) {
445 ND_PRINT(", %s (%u)",
446 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",GET_U_1(tptr
)),
450 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
451 if (subtlv_length
% 4 != 0) {
452 ND_PRINT(" != N x 4");
455 count_srlg
= subtlv_length
/ 4;
457 ND_PRINT("\n\t\t Shared risk group: ");
458 while (count_srlg
> 0) {
459 bw
.i
= GET_BE_U_4(tptr
);
460 ND_PRINT("%u", bw
.i
);
469 if (ndo
->ndo_vflag
<= 1) {
470 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
475 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
476 if (subtlv_length
%4 != 0)
477 subtlv_length
+=4-(subtlv_length
%4);
479 if (tlv_length
< subtlv_length
) {
480 ND_PRINT("\n\t Remaining TLV length %u < %u",
481 tlv_length
+ 4, subtlv_length
+ 4);
484 tlv_length
-=subtlv_length
;
490 case LS_OPAQUE_TE_TLV_ROUTER
:
491 if (tlv_length
< 4) {
492 ND_PRINT("\n\t TLV length %u < 4", tlv_length
);
496 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
500 if (ndo
->ndo_vflag
<= 1) {
501 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
506 /* in OSPF everything has to be 32-bit aligned, including TLVs */
507 if (tlv_length
%4 != 0)
508 tlv_length
+=4-(tlv_length
%4);
509 if (tlv_length
> ls_length
) {
510 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
514 ls_length
-=tlv_length
;
521 nd_print_invalid(ndo
);
526 ospf_print_lshdr(netdissect_options
*ndo
,
527 const struct lsa_hdr
*lshp
)
532 ND_TCHECK_2(lshp
->ls_length
);
533 ls_length
= GET_BE_U_2(lshp
->ls_length
);
534 if (ls_length
< sizeof(struct lsa_hdr
)) {
535 ND_PRINT("\n\t Bogus length %u < header (%zu)", ls_length
,
536 sizeof(struct lsa_hdr
));
540 ND_TCHECK_4(lshp
->ls_seq
); /* XXX - ls_length check checked this */
541 ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
542 GET_IPADDR_STRING(lshp
->ls_router
),
543 GET_BE_U_4(lshp
->ls_seq
),
544 GET_BE_U_2(lshp
->ls_age
),
545 ls_length
- (u_int
)sizeof(struct lsa_hdr
));
547 ND_TCHECK_1(lshp
->ls_type
); /* XXX - ls_length check checked this */
548 ls_type
= GET_U_1(lshp
->ls_type
);
550 /* the LSA header for opaque LSAs was slightly changed */
551 case LS_TYPE_OPAQUE_LL
:
552 case LS_TYPE_OPAQUE_AL
:
553 case LS_TYPE_OPAQUE_DW
:
554 ND_PRINT("\n\t %s LSA (%u), Opaque-Type %s LSA (%u), Opaque-ID %u",
555 tok2str(lsa_values
,"unknown",ls_type
),
558 tok2str(lsa_opaque_values
,
560 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
561 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
),
562 GET_BE_U_3(lshp
->un_lsa_id
.opaque_field
.opaque_id
)
567 /* all other LSA types use regular style LSA headers */
569 ND_PRINT("\n\t %s LSA (%u), LSA-ID: %s",
570 tok2str(lsa_values
,"unknown",ls_type
),
572 GET_IPADDR_STRING(lshp
->un_lsa_id
.lsa_id
));
576 ND_TCHECK_1(lshp
->ls_options
); /* XXX - ls_length check checked this */
577 ND_PRINT("\n\t Options: [%s]",
578 bittok2str(ospf_option_values
, "none", GET_U_1(lshp
->ls_options
)));
585 /* draft-ietf-ospf-mt-09 */
586 static const struct tok ospf_topology_values
[] = {
594 * Print all the per-topology metrics.
597 ospf_print_tos_metrics(netdissect_options
*ndo
,
598 const union un_tos
*tos
)
604 toscount
= GET_U_1(tos
->link
.link_tos_count
)+1;
608 * All but the first metric contain a valid topology id.
610 while (toscount
!= 0) {
612 tos_type
= GET_U_1(tos
->metrics
.tos_type
);
613 ND_PRINT("\n\t\ttopology %s (%u), metric %u",
614 tok2str(ospf_topology_values
, "Unknown",
615 metric_count
? tos_type
: 0),
616 metric_count
? tos_type
: 0,
617 GET_BE_U_2(tos
->metrics
.tos_metric
));
628 * Print a single link state advertisement. If truncated or if LSA length
629 * field is less than the length of the LSA header, return NULl, else
630 * return pointer to data past end of LSA.
632 static const uint8_t *
633 ospf_print_lsa(netdissect_options
*ndo
,
634 const struct lsa
*lsap
)
636 const uint8_t *ls_end
;
637 const struct rlalink
*rlp
;
639 const struct aslametric
*almp
;
640 const struct mcla
*mcp
;
642 int j
, tlv_type
, tlv_length
, topology
;
646 tptr
= (const uint8_t *)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
647 ls_length
= ospf_print_lshdr(ndo
, &lsap
->ls_hdr
);
650 ls_end
= (const uint8_t *)lsap
+ ls_length
;
651 ls_length
-= sizeof(struct lsa_hdr
);
653 switch (GET_U_1(lsap
->ls_hdr
.ls_type
)) {
656 ND_TCHECK_1(lsap
->lsa_un
.un_rla
.rla_flags
);
657 ND_PRINT("\n\t Router LSA Options: [%s]",
658 bittok2str(ospf_rla_flag_values
, "none", GET_U_1(lsap
->lsa_un
.un_rla
.rla_flags
)));
660 ND_TCHECK_2(lsap
->lsa_un
.un_rla
.rla_count
);
661 j
= GET_BE_U_2(lsap
->lsa_un
.un_rla
.rla_count
);
662 ND_TCHECK_SIZE(lsap
->lsa_un
.un_rla
.rla_link
);
663 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
666 switch (GET_U_1(rlp
->un_tos
.link
.link_type
)) {
668 case RLA_TYPE_VIRTUAL
:
669 ND_PRINT("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
670 GET_IPADDR_STRING(rlp
->link_id
),
671 GET_IPADDR_STRING(rlp
->link_data
));
674 case RLA_TYPE_ROUTER
:
675 ND_PRINT("\n\t Neighbor Router-ID: %s, Interface Address: %s",
676 GET_IPADDR_STRING(rlp
->link_id
),
677 GET_IPADDR_STRING(rlp
->link_data
));
680 case RLA_TYPE_TRANSIT
:
681 ND_PRINT("\n\t Neighbor Network-ID: %s, Interface Address: %s",
682 GET_IPADDR_STRING(rlp
->link_id
),
683 GET_IPADDR_STRING(rlp
->link_data
));
687 ND_PRINT("\n\t Stub Network: %s, Mask: %s",
688 GET_IPADDR_STRING(rlp
->link_id
),
689 GET_IPADDR_STRING(rlp
->link_data
));
693 ND_PRINT("\n\t Unknown Router Link Type (%u)",
694 GET_U_1(rlp
->un_tos
.link
.link_type
));
698 if (ospf_print_tos_metrics(ndo
, &rlp
->un_tos
))
701 rlp
= (const struct rlalink
*)((const u_char
*)(rlp
+ 1) +
702 (GET_U_1(rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
706 case LS_TYPE_NETWORK
:
707 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
708 ND_PRINT("\n\t Mask %s\n\t Connected Routers:",
709 GET_IPADDR_STRING(lsap
->lsa_un
.un_nla
.nla_mask
));
710 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
711 while ((const u_char
*)ap
< ls_end
) {
713 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap
));
719 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
720 ND_PRINT("\n\t Mask %s",
721 GET_IPADDR_STRING(lsap
->lsa_un
.un_sla
.sla_mask
));
722 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
723 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
724 while (lp
< ls_end
) {
729 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
730 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
731 tok2str(ospf_topology_values
, "Unknown", topology
),
733 ul
& SLA_MASK_METRIC
);
738 case LS_TYPE_SUM_ABR
:
739 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
740 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
741 while (lp
< ls_end
) {
746 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
747 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
748 tok2str(ospf_topology_values
, "Unknown", topology
),
750 ul
& SLA_MASK_METRIC
);
756 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
757 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
758 ND_PRINT("\n\t Mask %s",
759 GET_IPADDR_STRING(lsap
->lsa_un
.un_asla
.asla_mask
));
761 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
762 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
763 while ((const u_char
*)almp
< ls_end
) {
766 ND_TCHECK_4(almp
->asla_tosmetric
);
767 ul
= GET_BE_U_4(almp
->asla_tosmetric
);
768 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
769 ND_PRINT("\n\t\ttopology %s (%u), type %u, metric",
770 tok2str(ospf_topology_values
, "Unknown", topology
),
772 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1);
773 if ((ul
& ASLA_MASK_METRIC
) == 0xffffff)
774 ND_PRINT(" infinite");
776 ND_PRINT(" %u", (ul
& ASLA_MASK_METRIC
));
778 ND_TCHECK_4(almp
->asla_forward
);
779 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_forward
) != 0) {
780 ND_PRINT(", forward %s", GET_IPADDR_STRING(almp
->asla_forward
));
782 ND_TCHECK_4(almp
->asla_tag
);
783 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_tag
) != 0) {
784 ND_PRINT(", tag %s", GET_IPADDR_STRING(almp
->asla_tag
));
791 /* Multicast extensions as of 23 July 1991 */
792 mcp
= lsap
->lsa_un
.un_mcla
;
793 while ((const u_char
*)mcp
< ls_end
) {
794 ND_TCHECK_4(mcp
->mcla_vid
);
795 switch (GET_BE_U_4(mcp
->mcla_vtype
)) {
797 case MCLA_VERTEX_ROUTER
:
798 ND_PRINT("\n\t Router Router-ID %s",
799 GET_IPADDR_STRING(mcp
->mcla_vid
));
802 case MCLA_VERTEX_NETWORK
:
803 ND_PRINT("\n\t Network Designated Router %s",
804 GET_IPADDR_STRING(mcp
->mcla_vid
));
808 ND_PRINT("\n\t unknown VertexType (%u)",
809 GET_BE_U_4(mcp
->mcla_vtype
));
816 case LS_TYPE_OPAQUE_LL
: /* fall through */
817 case LS_TYPE_OPAQUE_AL
:
818 case LS_TYPE_OPAQUE_DW
:
820 switch (GET_U_1(lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
821 case LS_OPAQUE_TYPE_RI
:
822 tptr
= (const uint8_t *)(lsap
->lsa_un
.un_ri_tlv
);
824 int ls_length_remaining
= ls_length
;
825 while (ls_length_remaining
!= 0) {
827 if (ls_length_remaining
< 4) {
828 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length_remaining
);
831 tlv_type
= GET_BE_U_2(tptr
);
832 tlv_length
= GET_BE_U_2(tptr
+ 2);
834 ls_length_remaining
-=4;
836 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
837 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
841 if (tlv_length
> ls_length_remaining
) {
842 ND_PRINT("\n\t Bogus length %u > remaining LS length %u", tlv_length
,
843 ls_length_remaining
);
846 ND_TCHECK_LEN(tptr
, tlv_length
);
849 case LS_OPAQUE_RI_TLV_CAP
:
850 if (tlv_length
!= 4) {
851 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
854 ND_PRINT("Capabilities: %s",
855 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", GET_BE_U_4(tptr
)));
858 if (ndo
->ndo_vflag
<= 1) {
859 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
866 ls_length_remaining
-=tlv_length
;
870 case LS_OPAQUE_TYPE_GRACE
:
871 if (ospf_grace_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_grace_tlv
),
877 case LS_OPAQUE_TYPE_TE
:
878 if (ospf_te_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_te_lsa_tlv
),
885 if (ndo
->ndo_vflag
<= 1) {
886 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
894 /* do we want to see an additionally hexdump ? */
895 if (ndo
->ndo_vflag
> 1)
896 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
897 "\n\t ", ls_length
)) {
907 ospf_decode_lls(netdissect_options
*ndo
,
908 const struct ospfhdr
*op
, u_int length
)
911 const u_char
*dataend
;
913 uint16_t lls_type
, lls_len
;
916 switch (GET_U_1(op
->ospf_type
)) {
918 case OSPF_TYPE_HELLO
:
919 if (!(GET_U_1(op
->ospf_hello
.hello_options
) & OSPF_OPTION_L
))
924 if (!(GET_U_1(op
->ospf_db
.db_options
) & OSPF_OPTION_L
))
932 /* dig deeper if LLS data is available; see RFC4813 */
933 length2
= GET_BE_U_2(op
->ospf_len
);
934 dptr
= (const u_char
*)op
+ length2
;
935 dataend
= (const u_char
*)op
+ length
;
937 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
938 dptr
= dptr
+ op
->ospf_authdata
[3];
939 length2
+= op
->ospf_authdata
[3];
941 if (length2
>= length
) {
942 ND_PRINT("\n\t[LLS truncated]");
946 ND_PRINT("\n\t LLS: checksum: 0x%04x", (u_int
) GET_BE_U_2(dptr
));
950 length2
= GET_BE_U_2(dptr
);
951 ND_PRINT(", length: %u", length2
);
955 while (dptr
< dataend
) {
957 lls_type
= GET_BE_U_2(dptr
);
958 ND_PRINT("\n\t %s (%u)",
959 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
963 lls_len
= GET_BE_U_2(dptr
);
964 ND_PRINT(", length: %u", lls_len
);
970 ND_PRINT(" [should be 4]");
974 lls_flags
= GET_BE_U_4(dptr
);
975 ND_PRINT("\n\t Options: 0x%08x [%s]", lls_flags
,
976 bittok2str(ospf_lls_eo_options
, "?", lls_flags
));
982 ND_PRINT(" [should be 20]");
986 ND_PRINT("\n\t Sequence number: 0x%08x", GET_BE_U_4(dptr
));
999 ospf_decode_v2(netdissect_options
*ndo
,
1000 const struct ospfhdr
*op
, const u_char
*dataend
)
1003 const struct lsr
*lsrp
;
1004 const struct lsa_hdr
*lshp
;
1005 const struct lsa
*lsap
;
1006 uint32_t lsa_count
,lsa_count_max
;
1008 switch (GET_U_1(op
->ospf_type
)) {
1010 case OSPF_TYPE_HELLO
:
1011 ND_TCHECK_1(op
->ospf_hello
.hello_options
);
1012 ND_PRINT("\n\tOptions [%s]",
1013 bittok2str(ospf_option_values
,"none",GET_U_1(op
->ospf_hello
.hello_options
)));
1015 ND_TCHECK_4(op
->ospf_hello
.hello_deadint
);
1016 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
1017 GET_BE_U_2(op
->ospf_hello
.hello_helloint
),
1018 GET_BE_U_4(op
->ospf_hello
.hello_deadint
),
1019 GET_IPADDR_STRING(op
->ospf_hello
.hello_mask
),
1020 GET_U_1(op
->ospf_hello
.hello_priority
));
1022 ND_TCHECK_4(op
->ospf_hello
.hello_dr
);
1023 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_dr
) != 0)
1024 ND_PRINT("\n\t Designated Router %s",
1025 GET_IPADDR_STRING(op
->ospf_hello
.hello_dr
));
1027 ND_TCHECK_4(op
->ospf_hello
.hello_bdr
);
1028 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_bdr
) != 0)
1029 ND_PRINT(", Backup Designated Router %s",
1030 GET_IPADDR_STRING(op
->ospf_hello
.hello_bdr
));
1032 ap
= op
->ospf_hello
.hello_neighbor
;
1033 if ((const u_char
*)ap
< dataend
)
1034 ND_PRINT("\n\t Neighbor List:");
1035 while ((const u_char
*)ap
< dataend
) {
1037 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap
));
1043 ND_TCHECK_1(op
->ospf_db
.db_options
);
1044 ND_PRINT("\n\tOptions [%s]",
1045 bittok2str(ospf_option_values
, "none", GET_U_1(op
->ospf_db
.db_options
)));
1046 ND_TCHECK_1(op
->ospf_db
.db_flags
);
1047 ND_PRINT(", DD Flags [%s]",
1048 bittok2str(ospf_dd_flag_values
, "none", GET_U_1(op
->ospf_db
.db_flags
)));
1049 ND_TCHECK_2(op
->ospf_db
.db_ifmtu
);
1050 if (GET_BE_U_2(op
->ospf_db
.db_ifmtu
)) {
1051 ND_PRINT(", MTU: %u",
1052 GET_BE_U_2(op
->ospf_db
.db_ifmtu
));
1054 ND_TCHECK_4(op
->ospf_db
.db_seq
);
1055 ND_PRINT(", Sequence: 0x%08x", GET_BE_U_4(op
->ospf_db
.db_seq
));
1057 /* Print all the LS adv's */
1058 lshp
= op
->ospf_db
.db_lshdr
;
1059 while (((const u_char
*)lshp
< dataend
) && ospf_print_lshdr(ndo
, lshp
) != -1) {
1064 case OSPF_TYPE_LS_REQ
:
1065 lsrp
= op
->ospf_lsr
;
1066 while ((const u_char
*)lsrp
< dataend
) {
1067 ND_TCHECK_SIZE(lsrp
);
1069 ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)",
1070 GET_IPADDR_STRING(lsrp
->ls_router
),
1071 tok2str(lsa_values
,"unknown",GET_BE_U_4(lsrp
->ls_type
)),
1072 GET_BE_U_4(lsrp
->ls_type
));
1074 switch (GET_BE_U_4(lsrp
->ls_type
)) {
1075 /* the LSA header for opaque LSAs was slightly changed */
1076 case LS_TYPE_OPAQUE_LL
:
1077 case LS_TYPE_OPAQUE_AL
:
1078 case LS_TYPE_OPAQUE_DW
:
1079 ND_PRINT(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1080 tok2str(lsa_opaque_values
, "unknown",GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
)),
1081 GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1082 GET_BE_U_3(lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
1085 ND_PRINT(", LSA-ID: %s",
1086 GET_IPADDR_STRING(lsrp
->un_ls_stateid
.ls_stateid
));
1094 case OSPF_TYPE_LS_UPDATE
:
1095 lsap
= op
->ospf_lsu
.lsu_lsa
;
1096 ND_TCHECK_4(op
->ospf_lsu
.lsu_count
);
1097 lsa_count_max
= GET_BE_U_4(op
->ospf_lsu
.lsu_count
);
1098 ND_PRINT(", %u LSA%s", lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
));
1099 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1100 ND_PRINT("\n\t LSA #%u", lsa_count
);
1101 lsap
= (const struct lsa
*)ospf_print_lsa(ndo
, lsap
);
1107 case OSPF_TYPE_LS_ACK
:
1108 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1109 while (ospf_print_lshdr(ndo
, lshp
) != -1) {
1123 ospf_print(netdissect_options
*ndo
,
1124 const u_char
*bp
, u_int length
,
1125 const u_char
*bp2 _U_
)
1127 const struct ospfhdr
*op
;
1128 const u_char
*dataend
;
1131 ndo
->ndo_protocol
= "ospf2";
1132 op
= (const struct ospfhdr
*)bp
;
1134 /* XXX Before we do anything else, strip off the MD5 trailer */
1135 ND_TCHECK_2(op
->ospf_authtype
);
1136 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1137 length
-= OSPF_AUTH_MD5_LEN
;
1138 ndo
->ndo_snapend
-= OSPF_AUTH_MD5_LEN
;
1141 /* If the type is valid translate it, or just print the type */
1142 /* value. If it's not valid, say so and return */
1143 ND_TCHECK_1(op
->ospf_type
);
1144 cp
= tok2str(type2str
, "unknown LS-type %u", GET_U_1(op
->ospf_type
));
1145 ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op
->ospf_version
), cp
,
1150 if (!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1154 ND_TCHECK_2(op
->ospf_len
);
1155 if (length
!= GET_BE_U_2(op
->ospf_len
)) {
1156 ND_PRINT(" [len %u]", GET_BE_U_2(op
->ospf_len
));
1159 if (length
> GET_BE_U_2(op
->ospf_len
)) {
1160 dataend
= bp
+ GET_BE_U_2(op
->ospf_len
);
1162 dataend
= bp
+ length
;
1165 ND_TCHECK_4(op
->ospf_routerid
);
1166 ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op
->ospf_routerid
));
1168 ND_TCHECK_4(op
->ospf_areaid
);
1169 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_areaid
) != 0)
1170 ND_PRINT(", Area %s", GET_IPADDR_STRING(op
->ospf_areaid
));
1172 ND_PRINT(", Backbone Area");
1174 if (ndo
->ndo_vflag
) {
1175 /* Print authentication data (should we really do this?) */
1176 ND_TCHECK_LEN(op
->ospf_authdata
, sizeof(op
->ospf_authdata
));
1178 ND_PRINT(", Authentication Type: %s (%u)",
1179 tok2str(ospf_authtype_values
, "unknown", GET_BE_U_2(op
->ospf_authtype
)),
1180 GET_BE_U_2(op
->ospf_authtype
));
1182 switch (GET_BE_U_2(op
->ospf_authtype
)) {
1184 case OSPF_AUTH_NONE
:
1187 case OSPF_AUTH_SIMPLE
:
1188 ND_PRINT("\n\tSimple text password: ");
1189 (void)nd_printzp(ndo
, op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
, NULL
);
1193 ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1194 *((op
->ospf_authdata
) + 2),
1195 *((op
->ospf_authdata
) + 3),
1196 GET_BE_U_4((op
->ospf_authdata
) + 4));
1203 /* Do rest according to version. */
1204 switch (GET_U_1(op
->ospf_version
)) {
1207 /* ospf version 2 */
1208 if (ospf_decode_v2(ndo
, op
, dataend
))
1210 if (length
> GET_BE_U_2(op
->ospf_len
)) {
1211 if (ospf_decode_lls(ndo
, op
, length
))
1217 ND_PRINT(" ospf [version %u]", GET_U_1(op
->ospf_version
));
1219 } /* end switch on version */
1223 nd_print_trunc(ndo
);