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",
310 subtlv_type
= GET_BE_U_2(tptr
);
311 subtlv_length
= GET_BE_U_2(tptr
+ 2);
315 /* Infinite loop protection */
316 if (subtlv_type
== 0 || subtlv_length
== 0)
319 ND_PRINT("\n\t %s subTLV (%u), length: %u",
320 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
324 if (tlv_length
< subtlv_length
) {
325 ND_PRINT("\n\t Remaining TLV length %u < %u",
326 tlv_length
+ 4, subtlv_length
+ 4);
329 ND_TCHECK_LEN(tptr
, subtlv_length
);
330 switch(subtlv_type
) {
331 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
332 if (subtlv_length
!= 4) {
336 ND_PRINT(", 0x%08x", GET_BE_U_4(tptr
));
338 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
339 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
340 if (subtlv_length
!= 4 && subtlv_length
!= 8) {
341 ND_PRINT(" != 4 && != 8");
344 ND_PRINT(", %s (0x%08x)",
345 GET_IPADDR_STRING(tptr
),
347 if (subtlv_length
== 8) /* rfc4203 */
348 ND_PRINT(", %s (0x%08x)",
349 GET_IPADDR_STRING(tptr
+4),
350 GET_BE_U_4(tptr
+ 4));
352 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
353 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
354 if (subtlv_length
!= 4) {
358 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
360 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
361 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
362 if (subtlv_length
!= 4) {
366 bw
.i
= GET_BE_U_4(tptr
);
367 ND_PRINT(", %.3f Mbps", bw
.f
* 8 / 1000000);
369 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
370 if (subtlv_length
!= 32) {
374 for (te_class
= 0; te_class
< 8; te_class
++) {
375 bw
.i
= GET_BE_U_4(tptr
+ te_class
* 4);
376 ND_PRINT("\n\t\tTE-Class %u: %.3f Mbps",
381 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
382 if (subtlv_length
< 4) {
386 /* BC Model Id (1 octet) + Reserved (3 octets) */
387 ND_PRINT("\n\t\tBandwidth Constraints Model ID: %s (%u)",
388 tok2str(diffserv_te_bc_values
, "unknown", GET_U_1(tptr
)),
390 if (subtlv_length
% 4 != 0) {
391 ND_PRINT("\n\t\tlength %u != N x 4", subtlv_length
);
394 if (subtlv_length
> 36) {
395 ND_PRINT("\n\t\tlength %u > 36", subtlv_length
);
398 /* decode BCs until the subTLV ends */
399 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
400 bw
.i
= GET_BE_U_4(tptr
+ 4 + te_class
* 4);
401 ND_PRINT("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
406 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
407 if (subtlv_length
!= 4) {
411 ND_PRINT(", Metric %u", GET_BE_U_4(tptr
));
413 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
414 /* Protection Cap (1 octet) + Reserved ((3 octets) */
415 if (subtlv_length
!= 4) {
420 bittok2str(gmpls_link_prot_values
, "none", GET_U_1(tptr
)));
422 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
423 if (subtlv_length
< 36) {
427 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
428 ND_PRINT("\n\t\tInterface Switching Capability: %s",
429 tok2str(gmpls_switch_cap_values
, "Unknown", GET_U_1((tptr
))));
430 ND_PRINT("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
431 tok2str(gmpls_encoding_values
, "Unknown", GET_U_1((tptr
+ 1))));
432 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
433 bw
.i
= GET_BE_U_4(tptr
+ 4 + (priority_level
* 4));
434 ND_PRINT("\n\t\t priority level %u: %.3f Mbps",
439 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
440 if (subtlv_length
!= 1) {
444 ND_PRINT(", %s (%u)",
445 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",GET_U_1(tptr
)),
449 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
450 if (subtlv_length
% 4 != 0) {
451 ND_PRINT(" != N x 4");
454 count_srlg
= subtlv_length
/ 4;
456 ND_PRINT("\n\t\t Shared risk group: ");
457 while (count_srlg
> 0) {
458 bw
.i
= GET_BE_U_4(tptr
);
459 ND_PRINT("%u", bw
.i
);
468 if (ndo
->ndo_vflag
<= 1) {
469 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
474 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
475 if (subtlv_length
%4 != 0)
476 subtlv_length
+=4-(subtlv_length
%4);
478 if (tlv_length
< subtlv_length
) {
479 ND_PRINT("\n\t Remaining TLV length %u < %u",
480 tlv_length
+ 4, subtlv_length
+ 4);
483 tlv_length
-=subtlv_length
;
489 case LS_OPAQUE_TE_TLV_ROUTER
:
490 if (tlv_length
< 4) {
491 ND_PRINT("\n\t TLV length %u < 4", tlv_length
);
495 ND_PRINT(", %s", GET_IPADDR_STRING(tptr
));
499 if (ndo
->ndo_vflag
<= 1) {
500 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
505 /* in OSPF everything has to be 32-bit aligned, including TLVs */
506 if (tlv_length
%4 != 0)
507 tlv_length
+=4-(tlv_length
%4);
508 if (tlv_length
> ls_length
) {
509 ND_PRINT("\n\t Bogus padded length %u > %u", tlv_length
,
513 ls_length
-=tlv_length
;
520 nd_print_invalid(ndo
);
525 ospf_print_lshdr(netdissect_options
*ndo
,
526 const struct lsa_hdr
*lshp
)
531 ls_length
= GET_BE_U_2(lshp
->ls_length
);
532 if (ls_length
< sizeof(struct lsa_hdr
)) {
533 ND_PRINT("\n\t Bogus length %u < header (%zu)", ls_length
,
534 sizeof(struct lsa_hdr
));
537 ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
538 GET_IPADDR_STRING(lshp
->ls_router
),
539 GET_BE_U_4(lshp
->ls_seq
),
540 GET_BE_U_2(lshp
->ls_age
),
541 ls_length
- (u_int
)sizeof(struct lsa_hdr
));
542 ls_type
= GET_U_1(lshp
->ls_type
);
544 /* the LSA header for opaque LSAs was slightly changed */
545 case LS_TYPE_OPAQUE_LL
:
546 case LS_TYPE_OPAQUE_AL
:
547 case LS_TYPE_OPAQUE_DW
:
548 ND_PRINT("\n\t %s LSA (%u), Opaque-Type %s LSA (%u), Opaque-ID %u",
549 tok2str(lsa_values
,"unknown",ls_type
),
552 tok2str(lsa_opaque_values
,
554 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
555 GET_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
),
556 GET_BE_U_3(lshp
->un_lsa_id
.opaque_field
.opaque_id
)
561 /* all other LSA types use regular style LSA headers */
563 ND_PRINT("\n\t %s LSA (%u), LSA-ID: %s",
564 tok2str(lsa_values
,"unknown",ls_type
),
566 GET_IPADDR_STRING(lshp
->un_lsa_id
.lsa_id
));
569 ND_PRINT("\n\t Options: [%s]",
570 bittok2str(ospf_option_values
, "none", GET_U_1(lshp
->ls_options
)));
575 /* draft-ietf-ospf-mt-09 */
576 static const struct tok ospf_topology_values
[] = {
584 * Print all the per-topology metrics.
587 ospf_print_tos_metrics(netdissect_options
*ndo
,
588 const union un_tos
*tos
)
594 toscount
= GET_U_1(tos
->link
.link_tos_count
)+1;
598 * All but the first metric contain a valid topology id.
600 while (toscount
!= 0) {
602 tos_type
= GET_U_1(tos
->metrics
.tos_type
);
603 ND_PRINT("\n\t\ttopology %s (%u), metric %u",
604 tok2str(ospf_topology_values
, "Unknown",
605 metric_count
? tos_type
: 0),
606 metric_count
? tos_type
: 0,
607 GET_BE_U_2(tos
->metrics
.tos_metric
));
618 * Print a single link state advertisement. If truncated or if LSA length
619 * field is less than the length of the LSA header, return NULl, else
620 * return pointer to data past end of LSA.
622 static const uint8_t *
623 ospf_print_lsa(netdissect_options
*ndo
,
624 const struct lsa
*lsap
)
626 const uint8_t *ls_end
;
627 const struct rlalink
*rlp
;
629 const struct aslametric
*almp
;
630 const struct mcla
*mcp
;
632 u_int tlv_type
, tlv_length
, rla_count
, topology
;
633 int ospf_print_lshdr_ret
;
637 tptr
= (const uint8_t *)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
638 ospf_print_lshdr_ret
= ospf_print_lshdr(ndo
, &lsap
->ls_hdr
);
639 if (ospf_print_lshdr_ret
< 0)
641 ls_length
= (u_int
)ospf_print_lshdr_ret
;
642 ls_end
= (const uint8_t *)lsap
+ ls_length
;
644 * ospf_print_lshdr() returns -1 if the length is too short,
645 * so we know ls_length is >= sizeof(struct lsa_hdr).
647 ls_length
-= sizeof(struct lsa_hdr
);
649 switch (GET_U_1(lsap
->ls_hdr
.ls_type
)) {
652 ND_PRINT("\n\t Router LSA Options: [%s]",
653 bittok2str(ospf_rla_flag_values
, "none", GET_U_1(lsap
->lsa_un
.un_rla
.rla_flags
)));
655 rla_count
= GET_BE_U_2(lsap
->lsa_un
.un_rla
.rla_count
);
656 ND_TCHECK_SIZE(lsap
->lsa_un
.un_rla
.rla_link
);
657 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
658 for (u_int i
= rla_count
; i
!= 0; i
--) {
660 switch (GET_U_1(rlp
->un_tos
.link
.link_type
)) {
662 case RLA_TYPE_VIRTUAL
:
663 ND_PRINT("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
664 GET_IPADDR_STRING(rlp
->link_id
),
665 GET_IPADDR_STRING(rlp
->link_data
));
668 case RLA_TYPE_ROUTER
:
669 ND_PRINT("\n\t 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_TRANSIT
:
675 ND_PRINT("\n\t Neighbor Network-ID: %s, Interface Address: %s",
676 GET_IPADDR_STRING(rlp
->link_id
),
677 GET_IPADDR_STRING(rlp
->link_data
));
681 ND_PRINT("\n\t Stub Network: %s, Mask: %s",
682 GET_IPADDR_STRING(rlp
->link_id
),
683 GET_IPADDR_STRING(rlp
->link_data
));
687 ND_PRINT("\n\t Unknown Router Link Type (%u)",
688 GET_U_1(rlp
->un_tos
.link
.link_type
));
692 if (ospf_print_tos_metrics(ndo
, &rlp
->un_tos
))
695 rlp
= (const struct rlalink
*)((const u_char
*)(rlp
+ 1) +
696 (GET_U_1(rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
700 case LS_TYPE_NETWORK
:
701 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
702 ND_PRINT("\n\t Mask %s\n\t Connected Routers:",
703 GET_IPADDR_STRING(lsap
->lsa_un
.un_nla
.nla_mask
));
704 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
705 while ((const u_char
*)ap
< ls_end
) {
707 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap
));
713 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
714 ND_PRINT("\n\t Mask %s",
715 GET_IPADDR_STRING(lsap
->lsa_un
.un_sla
.sla_mask
));
716 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
717 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
718 while (lp
< ls_end
) {
722 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
723 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
724 tok2str(ospf_topology_values
, "Unknown", topology
),
726 ul
& SLA_MASK_METRIC
);
731 case LS_TYPE_SUM_ABR
:
732 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
733 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
734 while (lp
< ls_end
) {
738 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
739 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
740 tok2str(ospf_topology_values
, "Unknown", topology
),
742 ul
& SLA_MASK_METRIC
);
748 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
749 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_mask
);
750 ND_PRINT("\n\t Mask %s",
751 GET_IPADDR_STRING(lsap
->lsa_un
.un_asla
.asla_mask
));
753 ND_TCHECK_SIZE(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
754 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
755 while ((const u_char
*)almp
< ls_end
) {
758 ul
= GET_BE_U_4(almp
->asla_tosmetric
);
759 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
760 ND_PRINT("\n\t\ttopology %s (%u), type %u, metric",
761 tok2str(ospf_topology_values
, "Unknown", topology
),
763 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1);
764 if ((ul
& ASLA_MASK_METRIC
) == 0xffffff)
765 ND_PRINT(" infinite");
767 ND_PRINT(" %u", (ul
& ASLA_MASK_METRIC
));
769 ND_TCHECK_4(almp
->asla_forward
);
770 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_forward
) != 0) {
771 ND_PRINT(", forward %s", GET_IPADDR_STRING(almp
->asla_forward
));
773 ND_TCHECK_4(almp
->asla_tag
);
774 if (GET_IPV4_TO_NETWORK_ORDER(almp
->asla_tag
) != 0) {
775 ND_PRINT(", tag %s", GET_IPADDR_STRING(almp
->asla_tag
));
782 /* Multicast extensions as of 23 July 1991 */
783 mcp
= lsap
->lsa_un
.un_mcla
;
784 while ((const u_char
*)mcp
< ls_end
) {
785 ND_TCHECK_4(mcp
->mcla_vid
);
786 switch (GET_BE_U_4(mcp
->mcla_vtype
)) {
788 case MCLA_VERTEX_ROUTER
:
789 ND_PRINT("\n\t Router Router-ID %s",
790 GET_IPADDR_STRING(mcp
->mcla_vid
));
793 case MCLA_VERTEX_NETWORK
:
794 ND_PRINT("\n\t Network Designated Router %s",
795 GET_IPADDR_STRING(mcp
->mcla_vid
));
799 ND_PRINT("\n\t unknown VertexType (%u)",
800 GET_BE_U_4(mcp
->mcla_vtype
));
807 case LS_TYPE_OPAQUE_LL
: /* fall through */
808 case LS_TYPE_OPAQUE_AL
:
809 case LS_TYPE_OPAQUE_DW
:
811 switch (GET_U_1(lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
812 case LS_OPAQUE_TYPE_RI
:
813 tptr
= (const uint8_t *)(lsap
->lsa_un
.un_ri_tlv
);
815 u_int ls_length_remaining
= ls_length
;
816 while (ls_length_remaining
!= 0) {
818 if (ls_length_remaining
< 4) {
819 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length_remaining
);
822 tlv_type
= GET_BE_U_2(tptr
);
823 tlv_length
= GET_BE_U_2(tptr
+ 2);
825 ls_length_remaining
-=4;
827 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
828 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
832 if (tlv_length
> ls_length_remaining
) {
833 ND_PRINT("\n\t Bogus length %u > remaining LS length %u", tlv_length
,
834 ls_length_remaining
);
837 ND_TCHECK_LEN(tptr
, tlv_length
);
840 case LS_OPAQUE_RI_TLV_CAP
:
841 if (tlv_length
!= 4) {
842 ND_PRINT("\n\t Bogus length %u != 4", tlv_length
);
845 ND_PRINT("Capabilities: %s",
846 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", GET_BE_U_4(tptr
)));
849 if (ndo
->ndo_vflag
<= 1) {
850 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
857 ls_length_remaining
-=tlv_length
;
861 case LS_OPAQUE_TYPE_GRACE
:
862 if (ospf_grace_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_grace_tlv
),
868 case LS_OPAQUE_TYPE_TE
:
869 if (ospf_te_lsa_print(ndo
, (const u_char
*)(lsap
->lsa_un
.un_te_lsa_tlv
),
876 if (ndo
->ndo_vflag
<= 1) {
877 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
885 /* do we want to see an additionally hexdump ? */
886 if (ndo
->ndo_vflag
> 1)
887 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
888 "\n\t ", ls_length
)) {
898 ospf_decode_lls(netdissect_options
*ndo
,
899 const struct ospfhdr
*op
, u_int length
)
902 const u_char
*dataend
;
904 uint16_t lls_type
, lls_len
;
907 switch (GET_U_1(op
->ospf_type
)) {
909 case OSPF_TYPE_HELLO
:
910 if (!(GET_U_1(op
->ospf_hello
.hello_options
) & OSPF_OPTION_L
))
915 if (!(GET_U_1(op
->ospf_db
.db_options
) & OSPF_OPTION_L
))
923 /* dig deeper if LLS data is available; see RFC4813 */
924 length2
= GET_BE_U_2(op
->ospf_len
);
925 dptr
= (const u_char
*)op
+ length2
;
926 dataend
= (const u_char
*)op
+ length
;
928 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
929 dptr
= dptr
+ op
->ospf_authdata
[3];
930 length2
+= op
->ospf_authdata
[3];
932 if (length2
>= length
) {
933 ND_PRINT("\n\t[LLS truncated]");
936 ND_PRINT("\n\t LLS: checksum: 0x%04x", (u_int
) GET_BE_U_2(dptr
));
939 length2
= GET_BE_U_2(dptr
);
940 ND_PRINT(", length: %u", length2
);
943 while (dptr
< dataend
) {
944 lls_type
= GET_BE_U_2(dptr
);
945 ND_PRINT("\n\t %s (%u)",
946 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
949 lls_len
= GET_BE_U_2(dptr
);
950 ND_PRINT(", length: %u", lls_len
);
956 ND_PRINT(" [should be 4]");
959 lls_flags
= GET_BE_U_4(dptr
);
960 ND_PRINT("\n\t Options: 0x%08x [%s]", lls_flags
,
961 bittok2str(ospf_lls_eo_options
, "?", lls_flags
));
967 ND_PRINT(" [should be 20]");
970 ND_PRINT("\n\t Sequence number: 0x%08x", GET_BE_U_4(dptr
));
981 ospf_decode_v2(netdissect_options
*ndo
,
982 const struct ospfhdr
*op
, const u_char
*dataend
)
985 const struct lsr
*lsrp
;
986 const struct lsa_hdr
*lshp
;
987 const struct lsa
*lsap
;
988 uint32_t lsa_count
,lsa_count_max
;
990 switch (GET_U_1(op
->ospf_type
)) {
992 case OSPF_TYPE_HELLO
:
993 ND_PRINT("\n\tOptions [%s]",
994 bittok2str(ospf_option_values
,"none",GET_U_1(op
->ospf_hello
.hello_options
)));
996 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
997 GET_BE_U_2(op
->ospf_hello
.hello_helloint
),
998 GET_BE_U_4(op
->ospf_hello
.hello_deadint
),
999 GET_IPADDR_STRING(op
->ospf_hello
.hello_mask
),
1000 GET_U_1(op
->ospf_hello
.hello_priority
));
1002 ND_TCHECK_4(op
->ospf_hello
.hello_dr
);
1003 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_dr
) != 0)
1004 ND_PRINT("\n\t Designated Router %s",
1005 GET_IPADDR_STRING(op
->ospf_hello
.hello_dr
));
1007 ND_TCHECK_4(op
->ospf_hello
.hello_bdr
);
1008 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_hello
.hello_bdr
) != 0)
1009 ND_PRINT(", Backup Designated Router %s",
1010 GET_IPADDR_STRING(op
->ospf_hello
.hello_bdr
));
1012 ap
= op
->ospf_hello
.hello_neighbor
;
1013 if ((const u_char
*)ap
< dataend
)
1014 ND_PRINT("\n\t Neighbor List:");
1015 while ((const u_char
*)ap
< dataend
) {
1017 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap
));
1023 ND_PRINT("\n\tOptions [%s]",
1024 bittok2str(ospf_option_values
, "none", GET_U_1(op
->ospf_db
.db_options
)));
1025 ND_PRINT(", DD Flags [%s]",
1026 bittok2str(ospf_dd_flag_values
, "none", GET_U_1(op
->ospf_db
.db_flags
)));
1027 if (GET_BE_U_2(op
->ospf_db
.db_ifmtu
)) {
1028 ND_PRINT(", MTU: %u",
1029 GET_BE_U_2(op
->ospf_db
.db_ifmtu
));
1031 ND_PRINT(", Sequence: 0x%08x", GET_BE_U_4(op
->ospf_db
.db_seq
));
1033 /* Print all the LS adv's */
1034 lshp
= op
->ospf_db
.db_lshdr
;
1035 while (((const u_char
*)lshp
< dataend
) && ospf_print_lshdr(ndo
, lshp
) != -1) {
1040 case OSPF_TYPE_LS_REQ
:
1041 lsrp
= op
->ospf_lsr
;
1042 while ((const u_char
*)lsrp
< dataend
) {
1043 ND_TCHECK_SIZE(lsrp
);
1045 ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)",
1046 GET_IPADDR_STRING(lsrp
->ls_router
),
1047 tok2str(lsa_values
,"unknown",GET_BE_U_4(lsrp
->ls_type
)),
1048 GET_BE_U_4(lsrp
->ls_type
));
1050 switch (GET_BE_U_4(lsrp
->ls_type
)) {
1051 /* the LSA header for opaque LSAs was slightly changed */
1052 case LS_TYPE_OPAQUE_LL
:
1053 case LS_TYPE_OPAQUE_AL
:
1054 case LS_TYPE_OPAQUE_DW
:
1055 ND_PRINT(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1056 tok2str(lsa_opaque_values
, "unknown",GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
)),
1057 GET_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1058 GET_BE_U_3(lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
1061 ND_PRINT(", LSA-ID: %s",
1062 GET_IPADDR_STRING(lsrp
->un_ls_stateid
.ls_stateid
));
1070 case OSPF_TYPE_LS_UPDATE
:
1071 lsap
= op
->ospf_lsu
.lsu_lsa
;
1072 lsa_count_max
= GET_BE_U_4(op
->ospf_lsu
.lsu_count
);
1073 ND_PRINT(", %u LSA%s", lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
));
1074 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1075 ND_PRINT("\n\t LSA #%u", lsa_count
);
1076 lsap
= (const struct lsa
*)ospf_print_lsa(ndo
, lsap
);
1082 case OSPF_TYPE_LS_ACK
:
1083 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1084 while (ospf_print_lshdr(ndo
, lshp
) != -1) {
1098 ospf_print(netdissect_options
*ndo
,
1099 const u_char
*bp
, u_int length
,
1100 const u_char
*bp2 _U_
)
1102 const struct ospfhdr
*op
;
1103 const u_char
*dataend
;
1106 ndo
->ndo_protocol
= "ospf2";
1107 op
= (const struct ospfhdr
*)bp
;
1109 /* XXX Before we do anything else, strip off the MD5 trailer */
1110 if (GET_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1111 length
-= OSPF_AUTH_MD5_LEN
;
1112 ndo
->ndo_snapend
-= OSPF_AUTH_MD5_LEN
;
1115 /* If the type is valid translate it, or just print the type */
1116 /* value. If it's not valid, say so and return */
1117 cp
= tok2str(type2str
, "unknown LS-type %u", GET_U_1(op
->ospf_type
));
1118 ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op
->ospf_version
), cp
,
1123 if (!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1127 if (length
!= GET_BE_U_2(op
->ospf_len
)) {
1128 ND_PRINT(" [len %u]", GET_BE_U_2(op
->ospf_len
));
1131 if (length
> GET_BE_U_2(op
->ospf_len
)) {
1132 dataend
= bp
+ GET_BE_U_2(op
->ospf_len
);
1134 dataend
= bp
+ length
;
1137 ND_TCHECK_4(op
->ospf_routerid
);
1138 ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op
->ospf_routerid
));
1140 ND_TCHECK_4(op
->ospf_areaid
);
1141 if (GET_IPV4_TO_NETWORK_ORDER(op
->ospf_areaid
) != 0)
1142 ND_PRINT(", Area %s", GET_IPADDR_STRING(op
->ospf_areaid
));
1144 ND_PRINT(", Backbone Area");
1146 if (ndo
->ndo_vflag
) {
1147 /* Print authentication data (should we really do this?) */
1148 ND_TCHECK_LEN(op
->ospf_authdata
, sizeof(op
->ospf_authdata
));
1150 ND_PRINT(", Authentication Type: %s (%u)",
1151 tok2str(ospf_authtype_values
, "unknown", GET_BE_U_2(op
->ospf_authtype
)),
1152 GET_BE_U_2(op
->ospf_authtype
));
1154 switch (GET_BE_U_2(op
->ospf_authtype
)) {
1156 case OSPF_AUTH_NONE
:
1159 case OSPF_AUTH_SIMPLE
:
1160 ND_PRINT("\n\tSimple text password: ");
1161 (void)nd_printzp(ndo
, op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
, NULL
);
1165 ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1166 *((op
->ospf_authdata
) + 2),
1167 *((op
->ospf_authdata
) + 3),
1168 GET_BE_U_4((op
->ospf_authdata
) + 4));
1175 /* Do rest according to version. */
1176 switch (GET_U_1(op
->ospf_version
)) {
1179 /* ospf version 2 */
1180 if (ospf_decode_v2(ndo
, op
, dataend
))
1182 if (length
> GET_BE_U_2(op
->ospf_len
)) {
1183 if (ospf_decode_lls(ndo
, op
, length
))
1189 ND_PRINT(" ospf [version %u]", GET_U_1(op
->ospf_version
));
1191 } /* end switch on version */
1195 nd_print_trunc(ndo
);