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)
28 #include <netdissect-stdinc.h>
30 #include "netdissect.h"
31 #include "addrtoname.h"
37 static const char tstr
[] = " [|ospf2]";
38 static const char istr
[] = " (invalid)";
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_UMD
, "UMD" },
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 uint8_t *tptr
, u_int ls_length
)
186 u_int tlv_type
, tlv_length
;
189 while (ls_length
> 0) {
190 ND_TCHECK2(*tptr
, 4);
192 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
195 tlv_type
= EXTRACT_16BITS(tptr
);
196 tlv_length
= EXTRACT_16BITS(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_TCHECK2(*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_32BITS(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", *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 uint8_t *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) {
277 ND_TCHECK2(*tptr
, 4);
279 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
282 tlv_type
= EXTRACT_16BITS(tptr
);
283 tlv_length
= EXTRACT_16BITS(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",
311 ND_TCHECK2(*tptr
, 4);
312 subtlv_type
= EXTRACT_16BITS(tptr
);
313 subtlv_length
= EXTRACT_16BITS(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_TCHECK2(*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_32BITS(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_32BITS(tptr
)));
344 if (subtlv_length
== 8) /* rfc4203 */
345 ND_PRINT((ndo
, ", %s (0x%08x)",
346 ipaddr_string(ndo
, tptr
+4),
347 EXTRACT_32BITS(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_32BITS(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_32BITS(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", *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_32BITS(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_32BITS(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", *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", *(tptr
))));
427 ND_PRINT((ndo
, "\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
428 tok2str(gmpls_encoding_values
, "Unknown", *(tptr
+ 1))));
429 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
430 bw
.i
= EXTRACT_32BITS(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",*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_32BITS(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
));
486 ND_TCHECK2(*tptr
, 4);
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 register const struct lsa_hdr
*lshp
)
517 ND_TCHECK(lshp
->ls_length
);
518 ls_length
= EXTRACT_16BITS(&lshp
->ls_length
);
519 if (ls_length
< sizeof(struct lsa_hdr
)) {
520 ND_PRINT((ndo
, "\n\t Bogus length %u < header (%lu)", ls_length
,
521 (unsigned long)sizeof(struct lsa_hdr
)));
525 ND_TCHECK(lshp
->ls_seq
); /* XXX - ls_length check checked this */
526 ND_PRINT((ndo
, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
527 ipaddr_string(ndo
, &lshp
->ls_router
),
528 EXTRACT_32BITS(&lshp
->ls_seq
),
529 EXTRACT_16BITS(&lshp
->ls_age
),
530 ls_length
- (u_int
)sizeof(struct lsa_hdr
)));
532 ND_TCHECK(lshp
->ls_type
); /* XXX - ls_length check checked this */
533 switch (lshp
->ls_type
) {
534 /* the LSA header for opaque LSAs was slightly changed */
535 case LS_TYPE_OPAQUE_LL
:
536 case LS_TYPE_OPAQUE_AL
:
537 case LS_TYPE_OPAQUE_DW
:
538 ND_PRINT((ndo
, "\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
539 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
542 tok2str(lsa_opaque_values
,
544 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
545 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
),
546 EXTRACT_24BITS(&lshp
->un_lsa_id
.opaque_field
.opaque_id
)
551 /* all other LSA types use regular style LSA headers */
553 ND_PRINT((ndo
, "\n\t %s LSA (%d), LSA-ID: %s",
554 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
556 ipaddr_string(ndo
, &lshp
->un_lsa_id
.lsa_id
)));
560 ND_TCHECK(lshp
->ls_options
); /* XXX - ls_length check checked this */
561 ND_PRINT((ndo
, "\n\t Options: [%s]", bittok2str(ospf_option_values
, "none", lshp
->ls_options
)));
568 /* draft-ietf-ospf-mt-09 */
569 static const struct tok ospf_topology_values
[] = {
572 { 2, "management " },
577 * Print all the per-topology metrics.
580 ospf_print_tos_metrics(netdissect_options
*ndo
,
581 const union un_tos
*tos
)
586 toscount
= tos
->link
.link_tos_count
+1;
590 * All but the first metric contain a valid topology id.
593 ND_PRINT((ndo
, "\n\t\ttopology %s(%u), metric %u",
594 tok2str(ospf_topology_values
, "",
595 metric_count
? tos
->metrics
.tos_type
: 0),
596 metric_count
? tos
->metrics
.tos_type
: 0,
597 EXTRACT_16BITS(&tos
->metrics
.tos_metric
)));
605 * Print a single link state advertisement. If truncated or if LSA length
606 * field is less than the length of the LSA header, return NULl, else
607 * return pointer to data past end of LSA.
609 static const uint8_t *
610 ospf_print_lsa(netdissect_options
*ndo
,
611 register const struct lsa
*lsap
)
613 register const uint8_t *ls_end
;
614 register const struct rlalink
*rlp
;
615 register const struct in_addr
*ap
;
616 register const struct aslametric
*almp
;
617 register const struct mcla
*mcp
;
618 register const uint32_t *lp
;
619 register int j
, tlv_type
, tlv_length
, topology
;
620 register int ls_length
;
623 tptr
= (const uint8_t *)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
624 ls_length
= ospf_print_lshdr(ndo
, &lsap
->ls_hdr
);
627 ls_end
= (const uint8_t *)lsap
+ ls_length
;
628 ls_length
-= sizeof(struct lsa_hdr
);
630 switch (lsap
->ls_hdr
.ls_type
) {
633 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
634 ND_PRINT((ndo
, "\n\t Router LSA Options: [%s]",
635 bittok2str(ospf_rla_flag_values
, "none", lsap
->lsa_un
.un_rla
.rla_flags
)));
637 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
638 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
639 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
640 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
643 switch (rlp
->un_tos
.link
.link_type
) {
645 case RLA_TYPE_VIRTUAL
:
646 ND_PRINT((ndo
, "\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
647 ipaddr_string(ndo
, &rlp
->link_id
),
648 ipaddr_string(ndo
, &rlp
->link_data
)));
651 case RLA_TYPE_ROUTER
:
652 ND_PRINT((ndo
, "\n\t Neighbor Router-ID: %s, Interface Address: %s",
653 ipaddr_string(ndo
, &rlp
->link_id
),
654 ipaddr_string(ndo
, &rlp
->link_data
)));
657 case RLA_TYPE_TRANSIT
:
658 ND_PRINT((ndo
, "\n\t Neighbor Network-ID: %s, Interface Address: %s",
659 ipaddr_string(ndo
, &rlp
->link_id
),
660 ipaddr_string(ndo
, &rlp
->link_data
)));
664 ND_PRINT((ndo
, "\n\t Stub Network: %s, Mask: %s",
665 ipaddr_string(ndo
, &rlp
->link_id
),
666 ipaddr_string(ndo
, &rlp
->link_data
)));
670 ND_PRINT((ndo
, "\n\t Unknown Router Link Type (%u)",
671 rlp
->un_tos
.link
.link_type
));
675 ospf_print_tos_metrics(ndo
, &rlp
->un_tos
);
677 rlp
= (const struct rlalink
*)((const u_char
*)(rlp
+ 1) +
678 ((rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
682 case LS_TYPE_NETWORK
:
683 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
684 ND_PRINT((ndo
, "\n\t Mask %s\n\t Connected Routers:",
685 ipaddr_string(ndo
, &lsap
->lsa_un
.un_nla
.nla_mask
)));
686 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
687 while ((const u_char
*)ap
< ls_end
) {
689 ND_PRINT((ndo
, "\n\t %s", ipaddr_string(ndo
, ap
)));
695 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
696 ND_PRINT((ndo
, "\n\t Mask %s",
697 ipaddr_string(ndo
, &lsap
->lsa_un
.un_sla
.sla_mask
)));
698 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
699 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
700 while ((const u_char
*)lp
< ls_end
) {
701 register uint32_t ul
;
704 ul
= EXTRACT_32BITS(lp
);
705 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
706 ND_PRINT((ndo
, "\n\t\ttopology %s(%u) metric %d",
707 tok2str(ospf_topology_values
, "", topology
),
709 ul
& SLA_MASK_METRIC
));
714 case LS_TYPE_SUM_ABR
:
715 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
716 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
717 while ((const u_char
*)lp
< ls_end
) {
718 register uint32_t ul
;
721 ul
= EXTRACT_32BITS(lp
);
722 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
723 ND_PRINT((ndo
, "\n\t\ttopology %s(%u) metric %d",
724 tok2str(ospf_topology_values
, "", topology
),
726 ul
& SLA_MASK_METRIC
));
732 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
733 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
734 ND_PRINT((ndo
, "\n\t Mask %s",
735 ipaddr_string(ndo
, &lsap
->lsa_un
.un_asla
.asla_mask
)));
737 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
738 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
739 while ((const u_char
*)almp
< ls_end
) {
740 register uint32_t ul
;
742 ND_TCHECK(almp
->asla_tosmetric
);
743 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
744 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
745 ND_PRINT((ndo
, "\n\t\ttopology %s(%u), type %d, metric",
746 tok2str(ospf_topology_values
, "", topology
),
748 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1));
749 if ((ul
& ASLA_MASK_METRIC
) == 0xffffff)
750 ND_PRINT((ndo
, " infinite"));
752 ND_PRINT((ndo
, " %d", (ul
& ASLA_MASK_METRIC
)));
754 ND_TCHECK(almp
->asla_forward
);
755 if (almp
->asla_forward
.s_addr
) {
756 ND_PRINT((ndo
, ", forward %s", ipaddr_string(ndo
, &almp
->asla_forward
)));
758 ND_TCHECK(almp
->asla_tag
);
759 if (almp
->asla_tag
.s_addr
) {
760 ND_PRINT((ndo
, ", tag %s", ipaddr_string(ndo
, &almp
->asla_tag
)));
767 /* Multicast extensions as of 23 July 1991 */
768 mcp
= lsap
->lsa_un
.un_mcla
;
769 while ((const u_char
*)mcp
< ls_end
) {
770 ND_TCHECK(mcp
->mcla_vid
);
771 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
773 case MCLA_VERTEX_ROUTER
:
774 ND_PRINT((ndo
, "\n\t Router Router-ID %s",
775 ipaddr_string(ndo
, &mcp
->mcla_vid
)));
778 case MCLA_VERTEX_NETWORK
:
779 ND_PRINT((ndo
, "\n\t Network Designated Router %s",
780 ipaddr_string(ndo
, &mcp
->mcla_vid
)));
784 ND_PRINT((ndo
, "\n\t unknown VertexType (%u)",
785 EXTRACT_32BITS(&mcp
->mcla_vtype
)));
792 case LS_TYPE_OPAQUE_LL
: /* fall through */
793 case LS_TYPE_OPAQUE_AL
:
794 case LS_TYPE_OPAQUE_DW
:
796 switch (*(&lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
797 case LS_OPAQUE_TYPE_RI
:
798 tptr
= (const uint8_t *)(&lsap
->lsa_un
.un_ri_tlv
.type
);
800 while (ls_length
!= 0) {
801 ND_TCHECK2(*tptr
, 4);
803 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
806 tlv_type
= EXTRACT_16BITS(tptr
);
807 tlv_length
= EXTRACT_16BITS(tptr
+2);
811 ND_PRINT((ndo
, "\n\t %s TLV (%u), length: %u, value: ",
812 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
816 if (tlv_length
> ls_length
) {
817 ND_PRINT((ndo
, "\n\t Bogus length %u > %u", tlv_length
,
821 ND_TCHECK2(*tptr
, tlv_length
);
824 case LS_OPAQUE_RI_TLV_CAP
:
825 if (tlv_length
!= 4) {
826 ND_PRINT((ndo
, "\n\t Bogus length %u != 4", tlv_length
));
829 ND_PRINT((ndo
, "Capabilities: %s",
830 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", EXTRACT_32BITS(tptr
))));
833 if (ndo
->ndo_vflag
<= 1) {
834 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
841 ls_length
-=tlv_length
;
845 case LS_OPAQUE_TYPE_GRACE
:
846 if (ospf_print_grace_lsa(ndo
, (const uint8_t *)(&lsap
->lsa_un
.un_grace_tlv
.type
),
852 case LS_OPAQUE_TYPE_TE
:
853 if (ospf_print_te_lsa(ndo
, (const uint8_t *)(&lsap
->lsa_un
.un_te_lsa_tlv
.type
),
860 if (ndo
->ndo_vflag
<= 1) {
861 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
869 /* do we want to see an additionally hexdump ? */
870 if (ndo
->ndo_vflag
> 1)
871 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
872 "\n\t ", ls_length
)) {
882 ospf_decode_lls(netdissect_options
*ndo
,
883 register const struct ospfhdr
*op
, register u_int length
)
885 register const u_char
*dptr
;
886 register const u_char
*dataend
;
887 register u_int length2
;
888 register uint16_t lls_type
, lls_len
;
889 register uint32_t lls_flags
;
891 switch (op
->ospf_type
) {
893 case OSPF_TYPE_HELLO
:
894 if (!(op
->ospf_hello
.hello_options
& OSPF_OPTION_L
))
899 if (!(op
->ospf_db
.db_options
& OSPF_OPTION_L
))
907 /* dig deeper if LLS data is available; see RFC4813 */
908 length2
= EXTRACT_16BITS(&op
->ospf_len
);
909 dptr
= (const u_char
*)op
+ length2
;
910 dataend
= (const u_char
*)op
+ length
;
912 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
913 dptr
= dptr
+ op
->ospf_authdata
[3];
914 length2
+= op
->ospf_authdata
[3];
916 if (length2
>= length
) {
917 ND_PRINT((ndo
, "\n\t[LLS truncated]"));
920 ND_TCHECK2(*dptr
, 2);
921 ND_PRINT((ndo
, "\n\t LLS: checksum: 0x%04x", (u_int
)EXTRACT_16BITS(dptr
)));
924 ND_TCHECK2(*dptr
, 2);
925 length2
= EXTRACT_16BITS(dptr
);
926 ND_PRINT((ndo
, ", length: %u", length2
));
930 while (dptr
< dataend
) {
931 ND_TCHECK2(*dptr
, 2);
932 lls_type
= EXTRACT_16BITS(dptr
);
933 ND_PRINT((ndo
, "\n\t %s (%u)",
934 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
937 ND_TCHECK2(*dptr
, 2);
938 lls_len
= EXTRACT_16BITS(dptr
);
939 ND_PRINT((ndo
, ", length: %u", lls_len
));
945 ND_PRINT((ndo
, " [should be 4]"));
948 ND_TCHECK2(*dptr
, 4);
949 lls_flags
= EXTRACT_32BITS(dptr
);
950 ND_PRINT((ndo
, "\n\t Options: 0x%08x [%s]", lls_flags
,
951 bittok2str(ospf_lls_eo_options
, "?", lls_flags
)));
957 ND_PRINT((ndo
, " [should be 20]"));
960 ND_TCHECK2(*dptr
, 4);
961 ND_PRINT((ndo
, "\n\t Sequence number: 0x%08x", EXTRACT_32BITS(dptr
)));
974 ospf_decode_v2(netdissect_options
*ndo
,
975 register const struct ospfhdr
*op
, register const u_char
*dataend
)
977 register const struct in_addr
*ap
;
978 register const struct lsr
*lsrp
;
979 register const struct lsa_hdr
*lshp
;
980 register const struct lsa
*lsap
;
981 register uint32_t lsa_count
,lsa_count_max
;
983 switch (op
->ospf_type
) {
987 * Rob Coltun's special monitoring packets;
992 case OSPF_TYPE_HELLO
:
993 ND_PRINT((ndo
, "\n\tOptions [%s]",
994 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
)));
996 ND_TCHECK(op
->ospf_hello
.hello_deadint
);
997 ND_PRINT((ndo
, "\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
998 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
999 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
1000 ipaddr_string(ndo
, &op
->ospf_hello
.hello_mask
),
1001 op
->ospf_hello
.hello_priority
));
1003 ND_TCHECK(op
->ospf_hello
.hello_dr
);
1004 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
1005 ND_PRINT((ndo
, "\n\t Designated Router %s",
1006 ipaddr_string(ndo
, &op
->ospf_hello
.hello_dr
)));
1008 ND_TCHECK(op
->ospf_hello
.hello_bdr
);
1009 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
1010 ND_PRINT((ndo
, ", Backup Designated Router %s",
1011 ipaddr_string(ndo
, &op
->ospf_hello
.hello_bdr
)));
1013 ap
= op
->ospf_hello
.hello_neighbor
;
1014 if ((const u_char
*)ap
< dataend
)
1015 ND_PRINT((ndo
, "\n\t Neighbor List:"));
1016 while ((const u_char
*)ap
< dataend
) {
1018 ND_PRINT((ndo
, "\n\t %s", ipaddr_string(ndo
, ap
)));
1024 ND_TCHECK(op
->ospf_db
.db_options
);
1025 ND_PRINT((ndo
, "\n\tOptions [%s]",
1026 bittok2str(ospf_option_values
, "none", op
->ospf_db
.db_options
)));
1027 ND_TCHECK(op
->ospf_db
.db_flags
);
1028 ND_PRINT((ndo
, ", DD Flags [%s]",
1029 bittok2str(ospf_dd_flag_values
, "none", op
->ospf_db
.db_flags
)));
1030 ND_TCHECK(op
->ospf_db
.db_ifmtu
);
1031 if (op
->ospf_db
.db_ifmtu
) {
1032 ND_PRINT((ndo
, ", MTU: %u", EXTRACT_16BITS(&op
->ospf_db
.db_ifmtu
)));
1034 ND_TCHECK(op
->ospf_db
.db_seq
);
1035 ND_PRINT((ndo
, ", Sequence: 0x%08x", EXTRACT_32BITS(&op
->ospf_db
.db_seq
)));
1037 /* Print all the LS adv's */
1038 lshp
= op
->ospf_db
.db_lshdr
;
1039 while (((const u_char
*)lshp
< dataend
) && ospf_print_lshdr(ndo
, lshp
) != -1) {
1044 case OSPF_TYPE_LS_REQ
:
1045 lsrp
= op
->ospf_lsr
;
1046 while ((const u_char
*)lsrp
< dataend
) {
1049 ND_PRINT((ndo
, "\n\t Advertising Router: %s, %s LSA (%u)",
1050 ipaddr_string(ndo
, &lsrp
->ls_router
),
1051 tok2str(lsa_values
,"unknown",EXTRACT_32BITS(lsrp
->ls_type
)),
1052 EXTRACT_32BITS(&lsrp
->ls_type
)));
1054 switch (EXTRACT_32BITS(lsrp
->ls_type
)) {
1055 /* the LSA header for opaque LSAs was slightly changed */
1056 case LS_TYPE_OPAQUE_LL
:
1057 case LS_TYPE_OPAQUE_AL
:
1058 case LS_TYPE_OPAQUE_DW
:
1059 ND_PRINT((ndo
, ", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1060 tok2str(lsa_opaque_values
, "unknown",lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1061 lsrp
->un_ls_stateid
.opaque_field
.opaque_type
,
1062 EXTRACT_24BITS(&lsrp
->un_ls_stateid
.opaque_field
.opaque_id
)));
1065 ND_PRINT((ndo
, ", LSA-ID: %s",
1066 ipaddr_string(ndo
, &lsrp
->un_ls_stateid
.ls_stateid
)));
1074 case OSPF_TYPE_LS_UPDATE
:
1075 lsap
= op
->ospf_lsu
.lsu_lsa
;
1076 ND_TCHECK(op
->ospf_lsu
.lsu_count
);
1077 lsa_count_max
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
1078 ND_PRINT((ndo
, ", %d LSA%s", lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
)));
1079 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1080 ND_PRINT((ndo
, "\n\t LSA #%u", lsa_count
));
1081 lsap
= (const struct lsa
*)ospf_print_lsa(ndo
, lsap
);
1087 case OSPF_TYPE_LS_ACK
:
1088 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1089 while (ospf_print_lshdr(ndo
, lshp
) != -1) {
1103 ospf_print(netdissect_options
*ndo
,
1104 register const u_char
*bp
, register u_int length
,
1105 const u_char
*bp2 _U_
)
1107 register const struct ospfhdr
*op
;
1108 register const u_char
*dataend
;
1109 register const char *cp
;
1111 op
= (const struct ospfhdr
*)bp
;
1113 /* XXX Before we do anything else, strip off the MD5 trailer */
1114 ND_TCHECK(op
->ospf_authtype
);
1115 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1116 length
-= OSPF_AUTH_MD5_LEN
;
1117 ndo
->ndo_snapend
-= OSPF_AUTH_MD5_LEN
;
1120 /* If the type is valid translate it, or just print the type */
1121 /* value. If it's not valid, say so and return */
1122 ND_TCHECK(op
->ospf_type
);
1123 cp
= tok2str(type2str
, "unknown LS-type", op
->ospf_type
);
1124 ND_PRINT((ndo
, "OSPFv%u, %s, length %u", op
->ospf_version
, cp
, length
));
1128 if (!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1132 ND_TCHECK(op
->ospf_len
);
1133 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
1134 ND_PRINT((ndo
, " [len %d]", EXTRACT_16BITS(&op
->ospf_len
)));
1137 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1138 dataend
= bp
+ EXTRACT_16BITS(&op
->ospf_len
);
1140 dataend
= bp
+ length
;
1143 ND_TCHECK(op
->ospf_routerid
);
1144 ND_PRINT((ndo
, "\n\tRouter-ID %s", ipaddr_string(ndo
, &op
->ospf_routerid
)));
1146 ND_TCHECK(op
->ospf_areaid
);
1147 if (op
->ospf_areaid
.s_addr
!= 0)
1148 ND_PRINT((ndo
, ", Area %s", ipaddr_string(ndo
, &op
->ospf_areaid
)));
1150 ND_PRINT((ndo
, ", Backbone Area"));
1152 if (ndo
->ndo_vflag
) {
1153 /* Print authentication data (should we really do this?) */
1154 ND_TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
1156 ND_PRINT((ndo
, ", Authentication Type: %s (%u)",
1157 tok2str(ospf_authtype_values
, "unknown", EXTRACT_16BITS(&op
->ospf_authtype
)),
1158 EXTRACT_16BITS(&op
->ospf_authtype
)));
1160 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
1162 case OSPF_AUTH_NONE
:
1165 case OSPF_AUTH_SIMPLE
:
1166 ND_PRINT((ndo
, "\n\tSimple text password: "));
1167 safeputs(ndo
, op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
1171 ND_PRINT((ndo
, "\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1172 *((op
->ospf_authdata
) + 2),
1173 *((op
->ospf_authdata
) + 3),
1174 EXTRACT_32BITS((op
->ospf_authdata
) + 4)));
1181 /* Do rest according to version. */
1182 switch (op
->ospf_version
) {
1185 /* ospf version 2 */
1186 if (ospf_decode_v2(ndo
, op
, dataend
))
1188 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1189 if (ospf_decode_lls(ndo
, op
, length
))
1195 ND_PRINT((ndo
, " ospf [version %d]", op
->ospf_version
));
1197 } /* end switch on version */
1201 ND_PRINT((ndo
, "%s", tstr
));