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
>= sizeof(subtlv_type
) + sizeof(subtlv_length
)) {
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 ND_TCHECK_LEN(tptr
, subtlv_length
);
326 switch(subtlv_type
) {
327 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
328 if (subtlv_length
!= 4) {
332 ND_PRINT(", 0x%08x", GET_BE_U_4(tptr
));
334 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
335 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
336 if (subtlv_length
!= 4 && subtlv_length
!= 8) {
337 ND_PRINT(" != 4 && != 8");
340 ND_PRINT(", %s (0x%08x)",
341 GET_IPADDR_STRING(tptr
),
343 if (subtlv_length
== 8) /* rfc4203 */
344 ND_PRINT(", %s (0x%08x)",
345 GET_IPADDR_STRING(tptr
+4),
346 GET_BE_U_4(tptr
+ 4));
348 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
349 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
350 if (subtlv_length
!= 4) {
354 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
356 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
357 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
358 if (subtlv_length
!= 4) {
362 bw
.i
= GET_BE_U_4(tptr
);
363 ND_PRINT(", %.3f Mbps", bw
.f
* 8 / 1000000);
365 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
366 if (subtlv_length
!= 32) {
370 for (te_class
= 0; te_class
< 8; te_class
++) {
371 bw
.i
= GET_BE_U_4(tptr
+ te_class
* 4);
372 ND_PRINT("\n\t\tTE-Class %u: %.3f Mbps",
377 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
378 if (subtlv_length
< 4) {
382 /* BC Model Id (1 octet) + Reserved (3 octets) */
383 ND_PRINT("\n\t\tBandwidth Constraints Model ID: %s (%u)",
384 tok2str(diffserv_te_bc_values
, "unknown", GET_U_1(tptr
)),
386 if (subtlv_length
% 4 != 0) {
387 ND_PRINT("\n\t\tlength %u != N x 4", subtlv_length
);
390 if (subtlv_length
> 36) {
391 ND_PRINT("\n\t\tlength %u > 36", subtlv_length
);
394 /* decode BCs until the subTLV ends */
395 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
396 bw
.i
= GET_BE_U_4(tptr
+ 4 + te_class
* 4);
397 ND_PRINT("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
402 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
403 if (subtlv_length
!= 4) {
407 ND_PRINT(", Metric %u", GET_BE_U_4(tptr
));
409 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
410 /* Protection Cap (1 octet) + Reserved ((3 octets) */
411 if (subtlv_length
!= 4) {
416 bittok2str(gmpls_link_prot_values
, "none", GET_U_1(tptr
)));
418 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
419 if (subtlv_length
< 36) {
423 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
424 ND_PRINT("\n\t\tInterface Switching Capability: %s",
425 tok2str(gmpls_switch_cap_values
, "Unknown", GET_U_1((tptr
))));
426 ND_PRINT("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
427 tok2str(gmpls_encoding_values
, "Unknown", GET_U_1((tptr
+ 1))));
428 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
429 bw
.i
= GET_BE_U_4(tptr
+ 4 + (priority_level
* 4));
430 ND_PRINT("\n\t\t priority level %u: %.3f Mbps",
435 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
436 if (subtlv_length
!= 1) {
440 ND_PRINT(", %s (%u)",
441 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",GET_U_1(tptr
)),
445 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
446 if (subtlv_length
% 4 != 0) {
447 ND_PRINT(" != N x 4");
450 count_srlg
= subtlv_length
/ 4;
452 ND_PRINT("\n\t\t Shared risk group: ");
453 while (count_srlg
> 0) {
454 bw
.i
= GET_BE_U_4(tptr
);
455 ND_PRINT("%u", bw
.i
);
464 if (ndo
->ndo_vflag
<= 1) {
465 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
470 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
471 if (subtlv_length
%4 != 0)
472 subtlv_length
+=4-(subtlv_length
%4);
474 tlv_length
-=subtlv_length
;
480 case LS_OPAQUE_TE_TLV_ROUTER
:
481 if (tlv_length
< 4) {
482 ND_PRINT("\n\t TLV length %u < 4", tlv_length
);
486 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
490 if (ndo
->ndo_vflag
<= 1) {
491 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
496 /* in OSPF everything has to be 32-bit aligned, including TLVs */
497 if (tlv_length
%4 != 0)
498 tlv_length
+=4-(tlv_length
%4);
499 ls_length
-=tlv_length
;
506 nd_print_invalid(ndo
);
511 ospf_print_lshdr(netdissect_options
*ndo
,
512 const struct lsa_hdr
*lshp
)
517 ND_TCHECK_2(lshp
->ls_length
);
518 ls_length
= GET_BE_U_2(lshp
->ls_length
);
519 if (ls_length
< sizeof(struct lsa_hdr
)) {
520 ND_PRINT("\n\t Bogus length %u < header (%zu)", ls_length
,
521 sizeof(struct lsa_hdr
));
525 ND_TCHECK_4(lshp
->ls_seq
); /* XXX - ls_length check checked this */
526 ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
527 GET_IPADDR_STRING(lshp
->ls_router
),
528 GET_BE_U_4(lshp
->ls_seq
),
529 GET_BE_U_2(lshp
->ls_age
),
530 ls_length
- (u_int
)sizeof(struct lsa_hdr
));
532 ND_TCHECK_1(lshp
->ls_type
); /* XXX - ls_length check checked this */
533 ls_type
= GET_U_1(lshp
->ls_type
);
535 /* the LSA header for opaque LSAs was slightly changed */
536 case LS_TYPE_OPAQUE_LL
:
537 case LS_TYPE_OPAQUE_AL
:
538 case LS_TYPE_OPAQUE_DW
:
539 ND_PRINT("\n\t %s LSA (%u), Opaque-Type %s LSA (%u), Opaque-ID %u",
540 tok2str(lsa_values
,"unknown",ls_type
),
543 tok2str(lsa_opaque_values
,
545 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
546 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
),
547 GET_BE_U_3(lshp
->un_lsa_id
.opaque_field
.opaque_id
)
552 /* all other LSA types use regular style LSA headers */
554 ND_PRINT("\n\t %s LSA (%u), LSA-ID: %s",
555 tok2str(lsa_values
,"unknown",ls_type
),
557 GET_IPADDR_STRING(lshp
->un_lsa_id
.lsa_id
));
561 ND_TCHECK_1(lshp
->ls_options
); /* XXX - ls_length check checked this */
562 ND_PRINT("\n\t Options: [%s]",
563 bittok2str(ospf_option_values
, "none", GET_U_1(lshp
->ls_options
)));
570 /* draft-ietf-ospf-mt-09 */
571 static const struct tok ospf_topology_values
[] = {
579 * Print all the per-topology metrics.
582 ospf_print_tos_metrics(netdissect_options
*ndo
,
583 const union un_tos
*tos
)
589 toscount
= GET_U_1(tos
->link
.link_tos_count
)+1;
593 * All but the first metric contain a valid topology id.
595 while (toscount
!= 0) {
597 tos_type
= GET_U_1(tos
->metrics
.tos_type
);
598 ND_PRINT("\n\t\ttopology %s (%u), metric %u",
599 tok2str(ospf_topology_values
, "Unknown",
600 metric_count
? tos_type
: 0),
601 metric_count
? tos_type
: 0,
602 GET_BE_U_2(tos
->metrics
.tos_metric
));
613 * Print a single link state advertisement. If truncated or if LSA length
614 * field is less than the length of the LSA header, return NULl, else
615 * return pointer to data past end of LSA.
617 static const uint8_t *
618 ospf_print_lsa(netdissect_options
*ndo
,
619 const struct lsa
*lsap
)
621 const uint8_t *ls_end
;
622 const struct rlalink
*rlp
;
624 const struct aslametric
*almp
;
625 const struct mcla
*mcp
;
627 int j
, tlv_type
, tlv_length
, topology
;
631 tptr
= (const uint8_t *)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
632 ls_length
= ospf_print_lshdr(ndo
, &lsap
->ls_hdr
);
635 ls_end
= (const uint8_t *)lsap
+ ls_length
;
636 ls_length
-= sizeof(struct lsa_hdr
);
638 switch (GET_U_1(lsap
->ls_hdr
.ls_type
)) {
641 ND_TCHECK_1(lsap
->lsa_un
.un_rla
.rla_flags
);
642 ND_PRINT("\n\t Router LSA Options: [%s]",
643 bittok2str(ospf_rla_flag_values
, "none", GET_U_1(lsap
->lsa_un
.un_rla
.rla_flags
)));
645 ND_TCHECK_2(lsap
->lsa_un
.un_rla
.rla_count
);
646 j
= GET_BE_U_2(lsap
->lsa_un
.un_rla
.rla_count
);
647 ND_TCHECK_SIZE(lsap
->lsa_un
.un_rla
.rla_link
);
648 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
651 switch (GET_U_1(rlp
->un_tos
.link
.link_type
)) {
653 case RLA_TYPE_VIRTUAL
:
654 ND_PRINT("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
655 GET_IPADDR_STRING(rlp
->link_id
),
656 GET_IPADDR_STRING(rlp
->link_data
));
659 case RLA_TYPE_ROUTER
:
660 ND_PRINT("\n\t Neighbor Router-ID: %s, Interface Address: %s",
661 GET_IPADDR_STRING(rlp
->link_id
),
662 GET_IPADDR_STRING(rlp
->link_data
));
665 case RLA_TYPE_TRANSIT
:
666 ND_PRINT("\n\t Neighbor Network-ID: %s, Interface Address: %s",
667 GET_IPADDR_STRING(rlp
->link_id
),
668 GET_IPADDR_STRING(rlp
->link_data
));
672 ND_PRINT("\n\t Stub Network: %s, Mask: %s",
673 GET_IPADDR_STRING(rlp
->link_id
),
674 GET_IPADDR_STRING(rlp
->link_data
));
678 ND_PRINT("\n\t Unknown Router Link Type (%u)",
679 GET_U_1(rlp
->un_tos
.link
.link_type
));
683 if (ospf_print_tos_metrics(ndo
, &rlp
->un_tos
))
686 rlp
= (const struct rlalink
*)((const u_char
*)(rlp
+ 1) +
687 (GET_U_1(rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
691 case LS_TYPE_NETWORK
:
692 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
693 ND_PRINT("\n\t Mask %s\n\t Connected Routers:",
694 GET_IPADDR_STRING(lsap
->lsa_un
.un_nla
.nla_mask
));
695 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
696 while ((const u_char
*)ap
< ls_end
) {
698 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap
));
704 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
705 ND_PRINT("\n\t Mask %s",
706 GET_IPADDR_STRING(lsap
->lsa_un
.un_sla
.sla_mask
));
707 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
708 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
709 while (lp
< ls_end
) {
714 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
715 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
716 tok2str(ospf_topology_values
, "Unknown", topology
),
718 ul
& SLA_MASK_METRIC
);
723 case LS_TYPE_SUM_ABR
:
724 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
725 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
726 while (lp
< ls_end
) {
731 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
732 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
733 tok2str(ospf_topology_values
, "Unknown", topology
),
735 ul
& SLA_MASK_METRIC
);
741 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
742 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
743 ND_PRINT("\n\t Mask %s",
744 GET_IPADDR_STRING(lsap
->lsa_un
.un_asla
.asla_mask
));
746 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
747 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
748 while ((const u_char
*)almp
< ls_end
) {
751 ND_TCHECK_4(almp
->asla_tosmetric
);
752 ul
= GET_BE_U_4(almp
->asla_tosmetric
);
753 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
754 ND_PRINT("\n\t\ttopology %s (%u), type %u, metric",
755 tok2str(ospf_topology_values
, "Unknown", topology
),
757 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1);
758 if ((ul
& ASLA_MASK_METRIC
) == 0xffffff)
759 ND_PRINT(" infinite");
761 ND_PRINT(" %u", (ul
& ASLA_MASK_METRIC
));
763 ND_TCHECK_4(almp
->asla_forward
);
764 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_forward
) != 0) {
765 ND_PRINT(", forward %s", GET_IPADDR_STRING(almp
->asla_forward
));
767 ND_TCHECK_4(almp
->asla_tag
);
768 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_tag
) != 0) {
769 ND_PRINT(", tag %s", GET_IPADDR_STRING(almp
->asla_tag
));
776 /* Multicast extensions as of 23 July 1991 */
777 mcp
= lsap
->lsa_un
.un_mcla
;
778 while ((const u_char
*)mcp
< ls_end
) {
779 ND_TCHECK_4(mcp
->mcla_vid
);
780 switch (GET_BE_U_4(mcp
->mcla_vtype
)) {
782 case MCLA_VERTEX_ROUTER
:
783 ND_PRINT("\n\t Router Router-ID %s",
784 GET_IPADDR_STRING(mcp
->mcla_vid
));
787 case MCLA_VERTEX_NETWORK
:
788 ND_PRINT("\n\t Network Designated Router %s",
789 GET_IPADDR_STRING(mcp
->mcla_vid
));
793 ND_PRINT("\n\t unknown VertexType (%u)",
794 GET_BE_U_4(mcp
->mcla_vtype
));
801 case LS_TYPE_OPAQUE_LL
: /* fall through */
802 case LS_TYPE_OPAQUE_AL
:
803 case LS_TYPE_OPAQUE_DW
:
805 switch (GET_U_1(lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
806 case LS_OPAQUE_TYPE_RI
:
807 tptr
= (const uint8_t *)(lsap
->lsa_un
.un_ri_tlv
);
809 while (ls_length
!= 0) {
812 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length
);
815 tlv_type
= GET_BE_U_2(tptr
);
816 tlv_length
= GET_BE_U_2(tptr
+ 2);
820 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
821 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
825 if (tlv_length
> ls_length
) {
826 ND_PRINT("\n\t Bogus length %u > %u", tlv_length
,
830 ND_TCHECK_LEN(tptr
, tlv_length
);
833 case LS_OPAQUE_RI_TLV_CAP
:
834 if (tlv_length
!= 4) {
835 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
838 ND_PRINT("Capabilities: %s",
839 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", GET_BE_U_4(tptr
)));
842 if (ndo
->ndo_vflag
<= 1) {
843 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
850 ls_length
-=tlv_length
;
854 case LS_OPAQUE_TYPE_GRACE
:
855 if (ospf_grace_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_grace_tlv
),
861 case LS_OPAQUE_TYPE_TE
:
862 if (ospf_te_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_te_lsa_tlv
),
869 if (ndo
->ndo_vflag
<= 1) {
870 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
878 /* do we want to see an additionally hexdump ? */
879 if (ndo
->ndo_vflag
> 1)
880 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
881 "\n\t ", ls_length
)) {
891 ospf_decode_lls(netdissect_options
*ndo
,
892 const struct ospfhdr
*op
, u_int length
)
895 const u_char
*dataend
;
897 uint16_t lls_type
, lls_len
;
900 switch (GET_U_1(op
->ospf_type
)) {
902 case OSPF_TYPE_HELLO
:
903 if (!(GET_U_1(op
->ospf_hello
.hello_options
) & OSPF_OPTION_L
))
908 if (!(GET_U_1(op
->ospf_db
.db_options
) & OSPF_OPTION_L
))
916 /* dig deeper if LLS data is available; see RFC4813 */
917 length2
= GET_BE_U_2(op
->ospf_len
);
918 dptr
= (const u_char
*)op
+ length2
;
919 dataend
= (const u_char
*)op
+ length
;
921 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
922 dptr
= dptr
+ op
->ospf_authdata
[3];
923 length2
+= op
->ospf_authdata
[3];
925 if (length2
>= length
) {
926 ND_PRINT("\n\t[LLS truncated]");
930 ND_PRINT("\n\t LLS: checksum: 0x%04x", (u_int
) GET_BE_U_2(dptr
));
934 length2
= GET_BE_U_2(dptr
);
935 ND_PRINT(", length: %u", length2
);
939 while (dptr
< dataend
) {
941 lls_type
= GET_BE_U_2(dptr
);
942 ND_PRINT("\n\t %s (%u)",
943 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
947 lls_len
= GET_BE_U_2(dptr
);
948 ND_PRINT(", length: %u", lls_len
);
954 ND_PRINT(" [should be 4]");
958 lls_flags
= GET_BE_U_4(dptr
);
959 ND_PRINT("\n\t Options: 0x%08x [%s]", lls_flags
,
960 bittok2str(ospf_lls_eo_options
, "?", lls_flags
));
966 ND_PRINT(" [should be 20]");
970 ND_PRINT("\n\t Sequence number: 0x%08x", GET_BE_U_4(dptr
));
983 ospf_decode_v2(netdissect_options
*ndo
,
984 const struct ospfhdr
*op
, const u_char
*dataend
)
987 const struct lsr
*lsrp
;
988 const struct lsa_hdr
*lshp
;
989 const struct lsa
*lsap
;
990 uint32_t lsa_count
,lsa_count_max
;
992 switch (GET_U_1(op
->ospf_type
)) {
994 case OSPF_TYPE_HELLO
:
995 ND_TCHECK_1(op
->ospf_hello
.hello_options
);
996 ND_PRINT("\n\tOptions [%s]",
997 bittok2str(ospf_option_values
,"none",GET_U_1(op
->ospf_hello
.hello_options
)));
999 ND_TCHECK_4(op
->ospf_hello
.hello_deadint
);
1000 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
1001 GET_BE_U_2(op
->ospf_hello
.hello_helloint
),
1002 GET_BE_U_4(op
->ospf_hello
.hello_deadint
),
1003 GET_IPADDR_STRING(op
->ospf_hello
.hello_mask
),
1004 GET_U_1(op
->ospf_hello
.hello_priority
));
1006 ND_TCHECK_4(op
->ospf_hello
.hello_dr
);
1007 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_dr
) != 0)
1008 ND_PRINT("\n\t Designated Router %s",
1009 GET_IPADDR_STRING(op
->ospf_hello
.hello_dr
));
1011 ND_TCHECK_4(op
->ospf_hello
.hello_bdr
);
1012 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_bdr
) != 0)
1013 ND_PRINT(", Backup Designated Router %s",
1014 GET_IPADDR_STRING(op
->ospf_hello
.hello_bdr
));
1016 ap
= op
->ospf_hello
.hello_neighbor
;
1017 if ((const u_char
*)ap
< dataend
)
1018 ND_PRINT("\n\t Neighbor List:");
1019 while ((const u_char
*)ap
< dataend
) {
1021 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap
));
1027 ND_TCHECK_1(op
->ospf_db
.db_options
);
1028 ND_PRINT("\n\tOptions [%s]",
1029 bittok2str(ospf_option_values
, "none", GET_U_1(op
->ospf_db
.db_options
)));
1030 ND_TCHECK_1(op
->ospf_db
.db_flags
);
1031 ND_PRINT(", DD Flags [%s]",
1032 bittok2str(ospf_dd_flag_values
, "none", GET_U_1(op
->ospf_db
.db_flags
)));
1033 ND_TCHECK_2(op
->ospf_db
.db_ifmtu
);
1034 if (GET_BE_U_2(op
->ospf_db
.db_ifmtu
)) {
1035 ND_PRINT(", MTU: %u",
1036 GET_BE_U_2(op
->ospf_db
.db_ifmtu
));
1038 ND_TCHECK_4(op
->ospf_db
.db_seq
);
1039 ND_PRINT(", Sequence: 0x%08x", GET_BE_U_4(op
->ospf_db
.db_seq
));
1041 /* Print all the LS adv's */
1042 lshp
= op
->ospf_db
.db_lshdr
;
1043 while (((const u_char
*)lshp
< dataend
) && ospf_print_lshdr(ndo
, lshp
) != -1) {
1048 case OSPF_TYPE_LS_REQ
:
1049 lsrp
= op
->ospf_lsr
;
1050 while ((const u_char
*)lsrp
< dataend
) {
1051 ND_TCHECK_SIZE(lsrp
);
1053 ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)",
1054 GET_IPADDR_STRING(lsrp
->ls_router
),
1055 tok2str(lsa_values
,"unknown",GET_BE_U_4(lsrp
->ls_type
)),
1056 GET_BE_U_4(lsrp
->ls_type
));
1058 switch (GET_BE_U_4(lsrp
->ls_type
)) {
1059 /* the LSA header for opaque LSAs was slightly changed */
1060 case LS_TYPE_OPAQUE_LL
:
1061 case LS_TYPE_OPAQUE_AL
:
1062 case LS_TYPE_OPAQUE_DW
:
1063 ND_PRINT(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1064 tok2str(lsa_opaque_values
, "unknown",GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
)),
1065 GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1066 GET_BE_U_3(lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
1069 ND_PRINT(", LSA-ID: %s",
1070 GET_IPADDR_STRING(lsrp
->un_ls_stateid
.ls_stateid
));
1078 case OSPF_TYPE_LS_UPDATE
:
1079 lsap
= op
->ospf_lsu
.lsu_lsa
;
1080 ND_TCHECK_4(op
->ospf_lsu
.lsu_count
);
1081 lsa_count_max
= GET_BE_U_4(op
->ospf_lsu
.lsu_count
);
1082 ND_PRINT(", %u LSA%s", lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
));
1083 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1084 ND_PRINT("\n\t LSA #%u", lsa_count
);
1085 lsap
= (const struct lsa
*)ospf_print_lsa(ndo
, lsap
);
1091 case OSPF_TYPE_LS_ACK
:
1092 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1093 while (ospf_print_lshdr(ndo
, lshp
) != -1) {
1107 ospf_print(netdissect_options
*ndo
,
1108 const u_char
*bp
, u_int length
,
1109 const u_char
*bp2 _U_
)
1111 const struct ospfhdr
*op
;
1112 const u_char
*dataend
;
1115 ndo
->ndo_protocol
= "ospf2";
1116 op
= (const struct ospfhdr
*)bp
;
1118 /* XXX Before we do anything else, strip off the MD5 trailer */
1119 ND_TCHECK_2(op
->ospf_authtype
);
1120 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1121 length
-= OSPF_AUTH_MD5_LEN
;
1122 ndo
->ndo_snapend
-= OSPF_AUTH_MD5_LEN
;
1125 /* If the type is valid translate it, or just print the type */
1126 /* value. If it's not valid, say so and return */
1127 ND_TCHECK_1(op
->ospf_type
);
1128 cp
= tok2str(type2str
, "unknown LS-type %u", GET_U_1(op
->ospf_type
));
1129 ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op
->ospf_version
), cp
,
1134 if (!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1138 ND_TCHECK_2(op
->ospf_len
);
1139 if (length
!= GET_BE_U_2(op
->ospf_len
)) {
1140 ND_PRINT(" [len %u]", GET_BE_U_2(op
->ospf_len
));
1143 if (length
> GET_BE_U_2(op
->ospf_len
)) {
1144 dataend
= bp
+ GET_BE_U_2(op
->ospf_len
);
1146 dataend
= bp
+ length
;
1149 ND_TCHECK_4(op
->ospf_routerid
);
1150 ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op
->ospf_routerid
));
1152 ND_TCHECK_4(op
->ospf_areaid
);
1153 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_areaid
) != 0)
1154 ND_PRINT(", Area %s", GET_IPADDR_STRING(op
->ospf_areaid
));
1156 ND_PRINT(", Backbone Area");
1158 if (ndo
->ndo_vflag
) {
1159 /* Print authentication data (should we really do this?) */
1160 ND_TCHECK_LEN(op
->ospf_authdata
, sizeof(op
->ospf_authdata
));
1162 ND_PRINT(", Authentication Type: %s (%u)",
1163 tok2str(ospf_authtype_values
, "unknown", GET_BE_U_2(op
->ospf_authtype
)),
1164 GET_BE_U_2(op
->ospf_authtype
));
1166 switch (GET_BE_U_2(op
->ospf_authtype
)) {
1168 case OSPF_AUTH_NONE
:
1171 case OSPF_AUTH_SIMPLE
:
1172 ND_PRINT("\n\tSimple text password: ");
1173 (void)nd_printzp(ndo
, op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
, NULL
);
1177 ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1178 *((op
->ospf_authdata
) + 2),
1179 *((op
->ospf_authdata
) + 3),
1180 GET_BE_U_4((op
->ospf_authdata
) + 4));
1187 /* Do rest according to version. */
1188 switch (GET_U_1(op
->ospf_version
)) {
1191 /* ospf version 2 */
1192 if (ospf_decode_v2(ndo
, op
, dataend
))
1194 if (length
> GET_BE_U_2(op
->ospf_len
)) {
1195 if (ospf_decode_lls(ndo
, op
, length
))
1201 ND_PRINT(" ospf [version %u]", GET_U_1(op
->ospf_version
));
1203 } /* end switch on version */
1207 nd_print_trunc(ndo
);