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"
39 static const char tstr
[] = " [|ospf2]";
41 static const struct tok ospf_option_values
[] = {
42 { OSPF_OPTION_T
, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
43 { OSPF_OPTION_E
, "External" },
44 { OSPF_OPTION_MC
, "Multicast" },
45 { OSPF_OPTION_NP
, "NSSA" },
46 { OSPF_OPTION_L
, "LLS" },
47 { OSPF_OPTION_DC
, "Demand Circuit" },
48 { OSPF_OPTION_O
, "Opaque" },
49 { OSPF_OPTION_DN
, "Up/Down" },
53 static const struct tok ospf_authtype_values
[] = {
54 { OSPF_AUTH_NONE
, "none" },
55 { OSPF_AUTH_SIMPLE
, "simple" },
56 { OSPF_AUTH_MD5
, "MD5" },
60 static const struct tok ospf_rla_flag_values
[] = {
61 { RLA_FLAG_B
, "ABR" },
62 { RLA_FLAG_E
, "ASBR" },
63 { RLA_FLAG_W1
, "Virtual" },
64 { RLA_FLAG_W2
, "W2" },
68 static const struct tok type2str
[] = {
69 { OSPF_TYPE_HELLO
, "Hello" },
70 { OSPF_TYPE_DD
, "Database Description" },
71 { OSPF_TYPE_LS_REQ
, "LS-Request" },
72 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
73 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
77 static const struct tok lsa_values
[] = {
78 { LS_TYPE_ROUTER
, "Router" },
79 { LS_TYPE_NETWORK
, "Network" },
80 { LS_TYPE_SUM_IP
, "Summary" },
81 { LS_TYPE_SUM_ABR
, "ASBR Summary" },
82 { LS_TYPE_ASE
, "External" },
83 { LS_TYPE_GROUP
, "Multicast Group" },
84 { LS_TYPE_NSSA
, "NSSA" },
85 { LS_TYPE_OPAQUE_LL
, "Link Local Opaque" },
86 { LS_TYPE_OPAQUE_AL
, "Area Local Opaque" },
87 { LS_TYPE_OPAQUE_DW
, "Domain Wide Opaque" },
91 static const struct tok ospf_dd_flag_values
[] = {
92 { OSPF_DB_INIT
, "Init" },
93 { OSPF_DB_MORE
, "More" },
94 { OSPF_DB_MASTER
, "Master" },
95 { OSPF_DB_RESYNC
, "OOBResync" },
99 static const struct tok lsa_opaque_values
[] = {
100 { LS_OPAQUE_TYPE_TE
, "Traffic Engineering" },
101 { LS_OPAQUE_TYPE_GRACE
, "Graceful restart" },
102 { LS_OPAQUE_TYPE_RI
, "Router Information" },
106 static const struct tok lsa_opaque_te_tlv_values
[] = {
107 { LS_OPAQUE_TE_TLV_ROUTER
, "Router Address" },
108 { LS_OPAQUE_TE_TLV_LINK
, "Link" },
112 static const struct tok lsa_opaque_te_link_tlv_subtlv_values
[] = {
113 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
, "Link Type" },
114 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
, "Link ID" },
115 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
, "Local Interface IP address" },
116 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
, "Remote Interface IP address" },
117 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
, "Traffic Engineering Metric" },
118 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
, "Maximum Bandwidth" },
119 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
, "Maximum Reservable Bandwidth" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
, "Unreserved Bandwidth" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
, "Administrative Group" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
, "Link Local/Remote Identifier" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
, "Link Protection Type" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
, "Interface Switching Capability" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
, "Shared Risk Link Group" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
, "Bandwidth Constraints" },
130 static const struct tok lsa_opaque_grace_tlv_values
[] = {
131 { LS_OPAQUE_GRACE_TLV_PERIOD
, "Grace Period" },
132 { LS_OPAQUE_GRACE_TLV_REASON
, "Graceful restart Reason" },
133 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS
, "IPv4 interface address" },
137 static const struct tok lsa_opaque_grace_tlv_reason_values
[] = {
138 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN
, "Unknown" },
139 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART
, "Software Restart" },
140 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE
, "Software Reload/Upgrade" },
141 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH
, "Control Processor Switch" },
145 static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values
[] = {
146 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP
, "Point-to-point" },
147 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA
, "Multi-Access" },
151 static const struct tok lsa_opaque_ri_tlv_values
[] = {
152 { LS_OPAQUE_RI_TLV_CAP
, "Router Capabilities" },
156 static const struct tok lsa_opaque_ri_tlv_cap_values
[] = {
161 { 16, "graceful restart capable" },
162 { 32, "graceful restart helper" },
163 { 64, "Stub router support" },
164 { 128, "Traffic engineering" },
165 { 256, "p2p over LAN" },
166 { 512, "path computation server" },
170 static const struct tok ospf_lls_tlv_values
[] = {
171 { OSPF_LLS_EO
, "Extended Options" },
172 { OSPF_LLS_MD5
, "MD5 Authentication" },
176 static const struct tok ospf_lls_eo_options
[] = {
177 { OSPF_LLS_EO_LR
, "LSDB resync" },
178 { OSPF_LLS_EO_RS
, "Restart" },
183 ospf_print_grace_lsa(netdissect_options
*ndo
,
184 const u_char
*tptr
, u_int ls_length
)
186 u_int tlv_type
, tlv_length
;
189 while (ls_length
> 0) {
192 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
195 tlv_type
= EXTRACT_BE_U_2(tptr
);
196 tlv_length
= EXTRACT_BE_U_2(tptr
+ 2);
200 ND_PRINT((ndo
, "\n\t %s TLV (%u), length %u, value: ",
201 tok2str(lsa_opaque_grace_tlv_values
,"unknown",tlv_type
),
205 if (tlv_length
> ls_length
) {
206 ND_PRINT((ndo
, "\n\t Bogus length %u > %u", tlv_length
,
211 /* Infinite loop protection. */
212 if (tlv_type
== 0 || tlv_length
==0) {
216 ND_TCHECK_LEN(tptr
, tlv_length
);
219 case LS_OPAQUE_GRACE_TLV_PERIOD
:
220 if (tlv_length
!= 4) {
221 ND_PRINT((ndo
, "\n\t Bogus length %u != 4", tlv_length
));
224 ND_PRINT((ndo
, "%us", EXTRACT_BE_U_4(tptr
)));
227 case LS_OPAQUE_GRACE_TLV_REASON
:
228 if (tlv_length
!= 1) {
229 ND_PRINT((ndo
, "\n\t Bogus length %u != 1", tlv_length
));
232 ND_PRINT((ndo
, "%s (%u)",
233 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", EXTRACT_U_1(tptr
)),
237 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
238 if (tlv_length
!= 4) {
239 ND_PRINT((ndo
, "\n\t Bogus length %u != 4", tlv_length
));
242 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
246 if (ndo
->ndo_vflag
<= 1) {
247 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
253 /* in OSPF everything has to be 32-bit aligned, including TLVs */
254 if (tlv_length
%4 != 0)
255 tlv_length
+=4-(tlv_length
%4);
256 ls_length
-=tlv_length
;
266 ospf_print_te_lsa(netdissect_options
*ndo
,
267 const u_char
*tptr
, u_int ls_length
)
269 u_int tlv_type
, tlv_length
, subtlv_type
, subtlv_length
;
270 u_int priority_level
, te_class
, count_srlg
;
271 union { /* int to float conversion buffer for several subTLVs */
276 while (ls_length
!= 0) {
279 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
282 tlv_type
= EXTRACT_BE_U_2(tptr
);
283 tlv_length
= EXTRACT_BE_U_2(tptr
+ 2);
287 ND_PRINT((ndo
, "\n\t %s TLV (%u), length: %u",
288 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
292 if (tlv_length
> ls_length
) {
293 ND_PRINT((ndo
, "\n\t Bogus length %u > %u", tlv_length
,
298 /* Infinite loop protection. */
299 if (tlv_type
== 0 || tlv_length
==0) {
304 case LS_OPAQUE_TE_TLV_LINK
:
305 while (tlv_length
>= sizeof(subtlv_type
) + sizeof(subtlv_length
)) {
306 if (tlv_length
< 4) {
307 ND_PRINT((ndo
, "\n\t Remaining TLV length %u < 4",
312 subtlv_type
= EXTRACT_BE_U_2(tptr
);
313 subtlv_length
= EXTRACT_BE_U_2(tptr
+ 2);
317 /* Infinite loop protection */
318 if (subtlv_type
== 0 || subtlv_length
== 0)
321 ND_PRINT((ndo
, "\n\t %s subTLV (%u), length: %u",
322 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
326 ND_TCHECK_LEN(tptr
, subtlv_length
);
327 switch(subtlv_type
) {
328 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
329 if (subtlv_length
!= 4) {
330 ND_PRINT((ndo
, " != 4"));
333 ND_PRINT((ndo
, ", 0x%08x", EXTRACT_BE_U_4(tptr
)));
335 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
336 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
337 if (subtlv_length
!= 4 && subtlv_length
!= 8) {
338 ND_PRINT((ndo
, " != 4 && != 8"));
341 ND_PRINT((ndo
, ", %s (0x%08x)",
342 ipaddr_string(ndo
, tptr
),
343 EXTRACT_BE_U_4(tptr
)));
344 if (subtlv_length
== 8) /* rfc4203 */
345 ND_PRINT((ndo
, ", %s (0x%08x)",
346 ipaddr_string(ndo
, tptr
+4),
347 EXTRACT_BE_U_4(tptr
+ 4)));
349 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
350 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
351 if (subtlv_length
!= 4) {
352 ND_PRINT((ndo
, " != 4"));
355 ND_PRINT((ndo
, ", %s", ipaddr_string(ndo
, tptr
)));
357 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
358 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
359 if (subtlv_length
!= 4) {
360 ND_PRINT((ndo
, " != 4"));
363 bw
.i
= EXTRACT_BE_U_4(tptr
);
364 ND_PRINT((ndo
, ", %.3f Mbps", bw
.f
* 8 / 1000000));
366 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
367 if (subtlv_length
!= 32) {
368 ND_PRINT((ndo
, " != 32"));
371 for (te_class
= 0; te_class
< 8; te_class
++) {
372 bw
.i
= EXTRACT_BE_U_4(tptr
+ te_class
* 4);
373 ND_PRINT((ndo
, "\n\t\tTE-Class %u: %.3f Mbps",
375 bw
.f
* 8 / 1000000));
378 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
379 if (subtlv_length
< 4) {
380 ND_PRINT((ndo
, " < 4"));
383 /* BC Model Id (1 octet) + Reserved (3 octets) */
384 ND_PRINT((ndo
, "\n\t\tBandwidth Constraints Model ID: %s (%u)",
385 tok2str(diffserv_te_bc_values
, "unknown", EXTRACT_U_1(tptr
)),
387 if (subtlv_length
% 4 != 0) {
388 ND_PRINT((ndo
, "\n\t\tlength %u != N x 4", subtlv_length
));
391 if (subtlv_length
> 36) {
392 ND_PRINT((ndo
, "\n\t\tlength %u > 36", subtlv_length
));
395 /* decode BCs until the subTLV ends */
396 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
397 bw
.i
= EXTRACT_BE_U_4(tptr
+ 4 + te_class
* 4);
398 ND_PRINT((ndo
, "\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
400 bw
.f
* 8 / 1000000));
403 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
404 if (subtlv_length
!= 4) {
405 ND_PRINT((ndo
, " != 4"));
408 ND_PRINT((ndo
, ", Metric %u", EXTRACT_BE_U_4(tptr
)));
410 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
411 /* Protection Cap (1 octet) + Reserved ((3 octets) */
412 if (subtlv_length
!= 4) {
413 ND_PRINT((ndo
, " != 4"));
416 ND_PRINT((ndo
, ", %s",
417 bittok2str(gmpls_link_prot_values
, "none", EXTRACT_U_1(tptr
))));
419 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
420 if (subtlv_length
< 36) {
421 ND_PRINT((ndo
, " < 36"));
424 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
425 ND_PRINT((ndo
, "\n\t\tInterface Switching Capability: %s",
426 tok2str(gmpls_switch_cap_values
, "Unknown", EXTRACT_U_1((tptr
)))));
427 ND_PRINT((ndo
, "\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
428 tok2str(gmpls_encoding_values
, "Unknown", EXTRACT_U_1((tptr
+ 1)))));
429 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
430 bw
.i
= EXTRACT_BE_U_4(tptr
+ 4 + (priority_level
* 4));
431 ND_PRINT((ndo
, "\n\t\t priority level %d: %.3f Mbps",
433 bw
.f
* 8 / 1000000));
436 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
437 if (subtlv_length
!= 1) {
438 ND_PRINT((ndo
, " != 1"));
441 ND_PRINT((ndo
, ", %s (%u)",
442 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",EXTRACT_U_1(tptr
)),
446 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
447 if (subtlv_length
% 4 != 0) {
448 ND_PRINT((ndo
, " != N x 4"));
451 count_srlg
= subtlv_length
/ 4;
453 ND_PRINT((ndo
, "\n\t\t Shared risk group: "));
454 while (count_srlg
> 0) {
455 bw
.i
= EXTRACT_BE_U_4(tptr
);
456 ND_PRINT((ndo
, "%d", bw
.i
));
460 ND_PRINT((ndo
, ", "));
465 if (ndo
->ndo_vflag
<= 1) {
466 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
471 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
472 if (subtlv_length
%4 != 0)
473 subtlv_length
+=4-(subtlv_length
%4);
475 tlv_length
-=subtlv_length
;
481 case LS_OPAQUE_TE_TLV_ROUTER
:
482 if (tlv_length
< 4) {
483 ND_PRINT((ndo
, "\n\t TLV length %u < 4", tlv_length
));
487 ND_PRINT((ndo
, ", %s", ipaddr_string(ndo
, tptr
)));
491 if (ndo
->ndo_vflag
<= 1) {
492 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
497 /* in OSPF everything has to be 32-bit aligned, including TLVs */
498 if (tlv_length
%4 != 0)
499 tlv_length
+=4-(tlv_length
%4);
500 ls_length
-=tlv_length
;
507 ND_PRINT((ndo
, "%s", istr
));
512 ospf_print_lshdr(netdissect_options
*ndo
,
513 const struct lsa_hdr
*lshp
)
518 ND_TCHECK(lshp
->ls_length
);
519 ls_length
= EXTRACT_BE_U_2(lshp
->ls_length
);
520 if (ls_length
< sizeof(struct lsa_hdr
)) {
521 ND_PRINT((ndo
, "\n\t Bogus length %u < header (%lu)", ls_length
,
522 (unsigned long)sizeof(struct lsa_hdr
)));
526 ND_TCHECK(lshp
->ls_seq
); /* XXX - ls_length check checked this */
527 ND_PRINT((ndo
, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
528 ipaddr_string(ndo
, &lshp
->ls_router
),
529 EXTRACT_BE_U_4(lshp
->ls_seq
),
530 EXTRACT_BE_U_2(lshp
->ls_age
),
531 ls_length
- (u_int
)sizeof(struct lsa_hdr
)));
533 ND_TCHECK(lshp
->ls_type
); /* XXX - ls_length check checked this */
534 ls_type
= EXTRACT_U_1(lshp
->ls_type
);
536 /* the LSA header for opaque LSAs was slightly changed */
537 case LS_TYPE_OPAQUE_LL
:
538 case LS_TYPE_OPAQUE_AL
:
539 case LS_TYPE_OPAQUE_DW
:
540 ND_PRINT((ndo
, "\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
541 tok2str(lsa_values
,"unknown",ls_type
),
544 tok2str(lsa_opaque_values
,
546 EXTRACT_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
547 EXTRACT_U_1(lshp
->un_lsa_id
.opaque_field
.opaque_type
),
548 EXTRACT_BE_U_3(lshp
->un_lsa_id
.opaque_field
.opaque_id
)
553 /* all other LSA types use regular style LSA headers */
555 ND_PRINT((ndo
, "\n\t %s LSA (%d), LSA-ID: %s",
556 tok2str(lsa_values
,"unknown",ls_type
),
558 ipaddr_string(ndo
, &lshp
->un_lsa_id
.lsa_id
)));
562 ND_TCHECK(lshp
->ls_options
); /* XXX - ls_length check checked this */
563 ND_PRINT((ndo
, "\n\t Options: [%s]", bittok2str(ospf_option_values
, "none", EXTRACT_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
= EXTRACT_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
= EXTRACT_U_1(tos
->metrics
.tos_type
);
598 ND_PRINT((ndo
, "\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 EXTRACT_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
;
623 const struct in_addr
*ap
;
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 (EXTRACT_U_1(lsap
->ls_hdr
.ls_type
)) {
641 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
642 ND_PRINT((ndo
, "\n\t Router LSA Options: [%s]",
643 bittok2str(ospf_rla_flag_values
, "none", EXTRACT_U_1(lsap
->lsa_un
.un_rla
.rla_flags
))));
645 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
646 j
= EXTRACT_BE_U_2(lsap
->lsa_un
.un_rla
.rla_count
);
647 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
648 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
651 switch (EXTRACT_U_1(rlp
->un_tos
.link
.link_type
)) {
653 case RLA_TYPE_VIRTUAL
:
654 ND_PRINT((ndo
, "\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
655 ipaddr_string(ndo
, &rlp
->link_id
),
656 ipaddr_string(ndo
, &rlp
->link_data
)));
659 case RLA_TYPE_ROUTER
:
660 ND_PRINT((ndo
, "\n\t Neighbor Router-ID: %s, Interface Address: %s",
661 ipaddr_string(ndo
, &rlp
->link_id
),
662 ipaddr_string(ndo
, &rlp
->link_data
)));
665 case RLA_TYPE_TRANSIT
:
666 ND_PRINT((ndo
, "\n\t Neighbor Network-ID: %s, Interface Address: %s",
667 ipaddr_string(ndo
, &rlp
->link_id
),
668 ipaddr_string(ndo
, &rlp
->link_data
)));
672 ND_PRINT((ndo
, "\n\t Stub Network: %s, Mask: %s",
673 ipaddr_string(ndo
, &rlp
->link_id
),
674 ipaddr_string(ndo
, &rlp
->link_data
)));
678 ND_PRINT((ndo
, "\n\t Unknown Router Link Type (%u)",
679 EXTRACT_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 (EXTRACT_U_1(rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
691 case LS_TYPE_NETWORK
:
692 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
693 ND_PRINT((ndo
, "\n\t Mask %s\n\t Connected Routers:",
694 ipaddr_string(ndo
, &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((ndo
, "\n\t %s", ipaddr_string(ndo
, ap
)));
704 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
705 ND_PRINT((ndo
, "\n\t Mask %s",
706 ipaddr_string(ndo
, &lsap
->lsa_un
.un_sla
.sla_mask
)));
707 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
708 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
709 while (lp
< ls_end
) {
713 ul
= EXTRACT_BE_U_4(lp
);
714 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
715 ND_PRINT((ndo
, "\n\t\ttopology %s (%u) metric %d",
716 tok2str(ospf_topology_values
, "Unknown", topology
),
718 ul
& SLA_MASK_METRIC
));
723 case LS_TYPE_SUM_ABR
:
724 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
725 lp
= (const uint8_t *)lsap
->lsa_un
.un_sla
.sla_tosmetric
;
726 while (lp
< ls_end
) {
730 ul
= EXTRACT_BE_U_4(lp
);
731 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
732 ND_PRINT((ndo
, "\n\t\ttopology %s (%u) metric %d",
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(lsap
->lsa_un
.un_nla
.nla_mask
);
743 ND_PRINT((ndo
, "\n\t Mask %s",
744 ipaddr_string(ndo
, &lsap
->lsa_un
.un_asla
.asla_mask
)));
746 ND_TCHECK(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(almp
->asla_tosmetric
);
752 ul
= EXTRACT_BE_U_4(almp
->asla_tosmetric
);
753 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
754 ND_PRINT((ndo
, "\n\t\ttopology %s (%u), type %d, 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((ndo
, " infinite"));
761 ND_PRINT((ndo
, " %d", (ul
& ASLA_MASK_METRIC
)));
763 ND_TCHECK(almp
->asla_forward
);
764 if (almp
->asla_forward
.s_addr
) {
765 ND_PRINT((ndo
, ", forward %s", ipaddr_string(ndo
, &almp
->asla_forward
)));
767 ND_TCHECK(almp
->asla_tag
);
768 if (almp
->asla_tag
.s_addr
) {
769 ND_PRINT((ndo
, ", tag %s", ipaddr_string(ndo
, &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(mcp
->mcla_vid
);
780 switch (EXTRACT_BE_U_4(mcp
->mcla_vtype
)) {
782 case MCLA_VERTEX_ROUTER
:
783 ND_PRINT((ndo
, "\n\t Router Router-ID %s",
784 ipaddr_string(ndo
, &mcp
->mcla_vid
)));
787 case MCLA_VERTEX_NETWORK
:
788 ND_PRINT((ndo
, "\n\t Network Designated Router %s",
789 ipaddr_string(ndo
, &mcp
->mcla_vid
)));
793 ND_PRINT((ndo
, "\n\t unknown VertexType (%u)",
794 EXTRACT_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 (EXTRACT_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((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
815 tlv_type
= EXTRACT_BE_U_2(tptr
);
816 tlv_length
= EXTRACT_BE_U_2(tptr
+ 2);
820 ND_PRINT((ndo
, "\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((ndo
, "\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((ndo
, "\n\t Bogus length %u != 4", tlv_length
));
838 ND_PRINT((ndo
, "Capabilities: %s",
839 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", EXTRACT_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_print_grace_lsa(ndo
, (const u_char
*)(lsap
->lsa_un
.un_grace_tlv
),
861 case LS_OPAQUE_TYPE_TE
:
862 if (ospf_print_te_lsa(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 (EXTRACT_U_1(op
->ospf_type
)) {
902 case OSPF_TYPE_HELLO
:
903 if (!(EXTRACT_U_1(op
->ospf_hello
.hello_options
) & OSPF_OPTION_L
))
908 if (!(EXTRACT_U_1(op
->ospf_db
.db_options
) & OSPF_OPTION_L
))
916 /* dig deeper if LLS data is available; see RFC4813 */
917 length2
= EXTRACT_BE_U_2(op
->ospf_len
);
918 dptr
= (const u_char
*)op
+ length2
;
919 dataend
= (const u_char
*)op
+ length
;
921 if (EXTRACT_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((ndo
, "\n\t[LLS truncated]"));
930 ND_PRINT((ndo
, "\n\t LLS: checksum: 0x%04x", (u_int
) EXTRACT_BE_U_2(dptr
)));
934 length2
= EXTRACT_BE_U_2(dptr
);
935 ND_PRINT((ndo
, ", length: %u", length2
));
939 while (dptr
< dataend
) {
941 lls_type
= EXTRACT_BE_U_2(dptr
);
942 ND_PRINT((ndo
, "\n\t %s (%u)",
943 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
947 lls_len
= EXTRACT_BE_U_2(dptr
);
948 ND_PRINT((ndo
, ", length: %u", lls_len
));
954 ND_PRINT((ndo
, " [should be 4]"));
958 lls_flags
= EXTRACT_BE_U_4(dptr
);
959 ND_PRINT((ndo
, "\n\t Options: 0x%08x [%s]", lls_flags
,
960 bittok2str(ospf_lls_eo_options
, "?", lls_flags
)));
966 ND_PRINT((ndo
, " [should be 20]"));
970 ND_PRINT((ndo
, "\n\t Sequence number: 0x%08x", EXTRACT_BE_U_4(dptr
)));
983 ospf_decode_v2(netdissect_options
*ndo
,
984 const struct ospfhdr
*op
, const u_char
*dataend
)
986 const struct in_addr
*ap
;
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 (EXTRACT_U_1(op
->ospf_type
)) {
994 case OSPF_TYPE_HELLO
:
995 ND_TCHECK(op
->ospf_hello
.hello_options
);
996 ND_PRINT((ndo
, "\n\tOptions [%s]",
997 bittok2str(ospf_option_values
,"none",EXTRACT_U_1(op
->ospf_hello
.hello_options
))));
999 ND_TCHECK(op
->ospf_hello
.hello_deadint
);
1000 ND_PRINT((ndo
, "\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
1001 EXTRACT_BE_U_2(op
->ospf_hello
.hello_helloint
),
1002 EXTRACT_BE_U_4(op
->ospf_hello
.hello_deadint
),
1003 ipaddr_string(ndo
, &op
->ospf_hello
.hello_mask
),
1004 EXTRACT_U_1(op
->ospf_hello
.hello_priority
)));
1006 ND_TCHECK(op
->ospf_hello
.hello_dr
);
1007 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
1008 ND_PRINT((ndo
, "\n\t Designated Router %s",
1009 ipaddr_string(ndo
, &op
->ospf_hello
.hello_dr
)));
1011 ND_TCHECK(op
->ospf_hello
.hello_bdr
);
1012 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
1013 ND_PRINT((ndo
, ", Backup Designated Router %s",
1014 ipaddr_string(ndo
, &op
->ospf_hello
.hello_bdr
)));
1016 ap
= op
->ospf_hello
.hello_neighbor
;
1017 if ((const u_char
*)ap
< dataend
)
1018 ND_PRINT((ndo
, "\n\t Neighbor List:"));
1019 while ((const u_char
*)ap
< dataend
) {
1021 ND_PRINT((ndo
, "\n\t %s", ipaddr_string(ndo
, ap
)));
1027 ND_TCHECK(op
->ospf_db
.db_options
);
1028 ND_PRINT((ndo
, "\n\tOptions [%s]",
1029 bittok2str(ospf_option_values
, "none", EXTRACT_U_1(op
->ospf_db
.db_options
))));
1030 ND_TCHECK(op
->ospf_db
.db_flags
);
1031 ND_PRINT((ndo
, ", DD Flags [%s]",
1032 bittok2str(ospf_dd_flag_values
, "none", EXTRACT_U_1(op
->ospf_db
.db_flags
))));
1033 ND_TCHECK(op
->ospf_db
.db_ifmtu
);
1034 if (EXTRACT_BE_U_2(op
->ospf_db
.db_ifmtu
)) {
1035 ND_PRINT((ndo
, ", MTU: %u", EXTRACT_BE_U_2(op
->ospf_db
.db_ifmtu
)));
1037 ND_TCHECK(op
->ospf_db
.db_seq
);
1038 ND_PRINT((ndo
, ", Sequence: 0x%08x", EXTRACT_BE_U_4(op
->ospf_db
.db_seq
)));
1040 /* Print all the LS adv's */
1041 lshp
= op
->ospf_db
.db_lshdr
;
1042 while (((const u_char
*)lshp
< dataend
) && ospf_print_lshdr(ndo
, lshp
) != -1) {
1047 case OSPF_TYPE_LS_REQ
:
1048 lsrp
= op
->ospf_lsr
;
1049 while ((const u_char
*)lsrp
< dataend
) {
1050 ND_TCHECK_SIZE(lsrp
);
1052 ND_PRINT((ndo
, "\n\t Advertising Router: %s, %s LSA (%u)",
1053 ipaddr_string(ndo
, &lsrp
->ls_router
),
1054 tok2str(lsa_values
,"unknown",EXTRACT_BE_U_4(lsrp
->ls_type
)),
1055 EXTRACT_BE_U_4(lsrp
->ls_type
)));
1057 switch (EXTRACT_BE_U_4(lsrp
->ls_type
)) {
1058 /* the LSA header for opaque LSAs was slightly changed */
1059 case LS_TYPE_OPAQUE_LL
:
1060 case LS_TYPE_OPAQUE_AL
:
1061 case LS_TYPE_OPAQUE_DW
:
1062 ND_PRINT((ndo
, ", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1063 tok2str(lsa_opaque_values
, "unknown",EXTRACT_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
)),
1064 EXTRACT_U_1(lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1065 EXTRACT_BE_U_3(lsrp
->un_ls_stateid
.opaque_field
.opaque_id
)));
1068 ND_PRINT((ndo
, ", LSA-ID: %s",
1069 ipaddr_string(ndo
, &lsrp
->un_ls_stateid
.ls_stateid
)));
1077 case OSPF_TYPE_LS_UPDATE
:
1078 lsap
= op
->ospf_lsu
.lsu_lsa
;
1079 ND_TCHECK(op
->ospf_lsu
.lsu_count
);
1080 lsa_count_max
= EXTRACT_BE_U_4(op
->ospf_lsu
.lsu_count
);
1081 ND_PRINT((ndo
, ", %d LSA%s", lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
)));
1082 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1083 ND_PRINT((ndo
, "\n\t LSA #%u", lsa_count
));
1084 lsap
= (const struct lsa
*)ospf_print_lsa(ndo
, lsap
);
1090 case OSPF_TYPE_LS_ACK
:
1091 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1092 while (ospf_print_lshdr(ndo
, lshp
) != -1) {
1106 ospf_print(netdissect_options
*ndo
,
1107 const u_char
*bp
, u_int length
,
1108 const u_char
*bp2 _U_
)
1110 const struct ospfhdr
*op
;
1111 const u_char
*dataend
;
1114 op
= (const struct ospfhdr
*)bp
;
1116 /* XXX Before we do anything else, strip off the MD5 trailer */
1117 ND_TCHECK(op
->ospf_authtype
);
1118 if (EXTRACT_BE_U_2(op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1119 length
-= OSPF_AUTH_MD5_LEN
;
1120 ndo
->ndo_snapend
-= OSPF_AUTH_MD5_LEN
;
1123 /* If the type is valid translate it, or just print the type */
1124 /* value. If it's not valid, say so and return */
1125 ND_TCHECK(op
->ospf_type
);
1126 cp
= tok2str(type2str
, "unknown LS-type %u", EXTRACT_U_1(op
->ospf_type
));
1127 ND_PRINT((ndo
, "OSPFv%u, %s, length %u", EXTRACT_U_1(op
->ospf_version
), cp
, length
));
1131 if (!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1135 ND_TCHECK(op
->ospf_len
);
1136 if (length
!= EXTRACT_BE_U_2(op
->ospf_len
)) {
1137 ND_PRINT((ndo
, " [len %d]", EXTRACT_BE_U_2(op
->ospf_len
)));
1140 if (length
> EXTRACT_BE_U_2(op
->ospf_len
)) {
1141 dataend
= bp
+ EXTRACT_BE_U_2(op
->ospf_len
);
1143 dataend
= bp
+ length
;
1146 ND_TCHECK(op
->ospf_routerid
);
1147 ND_PRINT((ndo
, "\n\tRouter-ID %s", ipaddr_string(ndo
, &op
->ospf_routerid
)));
1149 ND_TCHECK(op
->ospf_areaid
);
1150 if (op
->ospf_areaid
.s_addr
!= 0)
1151 ND_PRINT((ndo
, ", Area %s", ipaddr_string(ndo
, &op
->ospf_areaid
)));
1153 ND_PRINT((ndo
, ", Backbone Area"));
1155 if (ndo
->ndo_vflag
) {
1156 /* Print authentication data (should we really do this?) */
1157 ND_TCHECK_LEN(op
->ospf_authdata
, sizeof(op
->ospf_authdata
));
1159 ND_PRINT((ndo
, ", Authentication Type: %s (%u)",
1160 tok2str(ospf_authtype_values
, "unknown", EXTRACT_BE_U_2(op
->ospf_authtype
)),
1161 EXTRACT_BE_U_2(op
->ospf_authtype
)));
1163 switch (EXTRACT_BE_U_2(op
->ospf_authtype
)) {
1165 case OSPF_AUTH_NONE
:
1168 case OSPF_AUTH_SIMPLE
:
1169 ND_PRINT((ndo
, "\n\tSimple text password: "));
1170 safeputs(ndo
, op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
1174 ND_PRINT((ndo
, "\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1175 *((op
->ospf_authdata
) + 2),
1176 *((op
->ospf_authdata
) + 3),
1177 EXTRACT_BE_U_4((op
->ospf_authdata
) + 4)));
1184 /* Do rest according to version. */
1185 switch (EXTRACT_U_1(op
->ospf_version
)) {
1188 /* ospf version 2 */
1189 if (ospf_decode_v2(ndo
, op
, dataend
))
1191 if (length
> EXTRACT_BE_U_2(op
->ospf_len
)) {
1192 if (ospf_decode_lls(ndo
, op
, length
))
1198 ND_PRINT((ndo
, " ospf [version %u]", EXTRACT_U_1(op
->ospf_version
)));
1200 } /* end switch on version */
1204 ND_PRINT((ndo
, "%s", tstr
));