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 <tcpdump-stdinc.h>
30 #include "interface.h"
31 #include "addrtoname.h"
37 static const char tstr
[] = " [|ospf2]";
39 static const struct tok ospf_option_values
[] = {
40 { OSPF_OPTION_T
, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
41 { OSPF_OPTION_E
, "External" },
42 { OSPF_OPTION_MC
, "Multicast" },
43 { OSPF_OPTION_NP
, "NSSA" },
44 { OSPF_OPTION_L
, "LLS" },
45 { OSPF_OPTION_DC
, "Demand Circuit" },
46 { OSPF_OPTION_O
, "Opaque" },
47 { OSPF_OPTION_DN
, "Up/Down" },
51 static const struct tok ospf_authtype_values
[] = {
52 { OSPF_AUTH_NONE
, "none" },
53 { OSPF_AUTH_SIMPLE
, "simple" },
54 { OSPF_AUTH_MD5
, "MD5" },
58 static const struct tok ospf_rla_flag_values
[] = {
59 { RLA_FLAG_B
, "ABR" },
60 { RLA_FLAG_E
, "ASBR" },
61 { RLA_FLAG_W1
, "Virtual" },
62 { RLA_FLAG_W2
, "W2" },
66 static const struct tok type2str
[] = {
67 { OSPF_TYPE_UMD
, "UMD" },
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_print_grace_lsa(netdissect_options
*ndo
,
183 const uint8_t *tptr
, u_int ls_length
)
185 u_int tlv_type
, tlv_length
;
188 while (ls_length
> 0) {
189 ND_TCHECK2(*tptr
, 4);
191 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
194 tlv_type
= EXTRACT_16BITS(tptr
);
195 tlv_length
= EXTRACT_16BITS(tptr
+2);
199 ND_PRINT((ndo
, "\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((ndo
, "\n\t Bogus length %u > %u", tlv_length
,
210 /* Infinite loop protection. */
211 if (tlv_type
== 0 || tlv_length
==0) {
215 ND_TCHECK2(*tptr
, tlv_length
);
218 case LS_OPAQUE_GRACE_TLV_PERIOD
:
219 if (tlv_length
!= 4) {
220 ND_PRINT((ndo
, "\n\t Bogus length %u != 4", tlv_length
));
223 ND_PRINT((ndo
, "%us", EXTRACT_32BITS(tptr
)));
226 case LS_OPAQUE_GRACE_TLV_REASON
:
227 if (tlv_length
!= 1) {
228 ND_PRINT((ndo
, "\n\t Bogus length %u != 1", tlv_length
));
231 ND_PRINT((ndo
, "%s (%u)",
232 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", *tptr
),
236 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
237 if (tlv_length
!= 4) {
238 ND_PRINT((ndo
, "\n\t Bogus length %u != 4", tlv_length
));
241 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, 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_print_te_lsa(netdissect_options
*ndo
,
266 const uint8_t *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) {
276 ND_TCHECK2(*tptr
, 4);
278 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
281 tlv_type
= EXTRACT_16BITS(tptr
);
282 tlv_length
= EXTRACT_16BITS(tptr
+2);
286 ND_PRINT((ndo
, "\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((ndo
, "\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((ndo
, "\n\t Remaining TLV length %u < 4",
310 ND_TCHECK2(*tptr
, 4);
311 subtlv_type
= EXTRACT_16BITS(tptr
);
312 subtlv_length
= EXTRACT_16BITS(tptr
+2);
316 ND_PRINT((ndo
, "\n\t %s subTLV (%u), length: %u",
317 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
321 ND_TCHECK2(*tptr
, subtlv_length
);
322 switch(subtlv_type
) {
323 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
324 ND_PRINT((ndo
, ", 0x%08x", EXTRACT_32BITS(tptr
)));
326 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
327 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
328 ND_PRINT((ndo
, ", %s (0x%08x)",
329 ipaddr_string(ndo
, tptr
),
330 EXTRACT_32BITS(tptr
)));
331 if (subtlv_length
== 8) /* rfc4203 */
332 ND_PRINT((ndo
, ", %s (0x%08x)",
333 ipaddr_string(ndo
, tptr
+4),
334 EXTRACT_32BITS(tptr
+ 4)));
336 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
337 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
338 ND_PRINT((ndo
, ", %s", ipaddr_string(ndo
, tptr
)));
340 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
341 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
342 bw
.i
= EXTRACT_32BITS(tptr
);
343 ND_PRINT((ndo
, ", %.3f Mbps", bw
.f
* 8 / 1000000));
345 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
346 for (te_class
= 0; te_class
< 8; te_class
++) {
347 bw
.i
= EXTRACT_32BITS(tptr
+te_class
*4);
348 ND_PRINT((ndo
, "\n\t\tTE-Class %u: %.3f Mbps",
350 bw
.f
* 8 / 1000000));
353 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
354 ND_PRINT((ndo
, "\n\t\tBandwidth Constraints Model ID: %s (%u)",
355 tok2str(diffserv_te_bc_values
, "unknown", *tptr
),
357 /* decode BCs until the subTLV ends */
358 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
359 bw
.i
= EXTRACT_32BITS(tptr
+4+te_class
*4);
360 ND_PRINT((ndo
, "\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
362 bw
.f
* 8 / 1000000));
365 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
366 ND_PRINT((ndo
, ", Metric %u", EXTRACT_32BITS(tptr
)));
368 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
369 ND_PRINT((ndo
, ", %s, Priority %u",
370 bittok2str(gmpls_link_prot_values
, "none", *tptr
),
373 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
374 ND_PRINT((ndo
, "\n\t\tInterface Switching Capability: %s",
375 tok2str(gmpls_switch_cap_values
, "Unknown", *(tptr
))));
376 ND_PRINT((ndo
, "\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
377 tok2str(gmpls_encoding_values
, "Unknown", *(tptr
+ 1))));
378 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
379 bw
.i
= EXTRACT_32BITS(tptr
+4+(priority_level
*4));
380 ND_PRINT((ndo
, "\n\t\t priority level %d: %.3f Mbps",
382 bw
.f
* 8 / 1000000));
385 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
386 ND_PRINT((ndo
, ", %s (%u)",
387 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",*tptr
),
391 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
392 count_srlg
= subtlv_length
/ 4;
394 ND_PRINT((ndo
, "\n\t\t Shared risk group: "));
395 while (count_srlg
> 0) {
396 bw
.i
= EXTRACT_32BITS(tptr
);
397 ND_PRINT((ndo
, "%d", bw
.i
));
401 ND_PRINT((ndo
, ", "));
406 if (ndo
->ndo_vflag
<= 1) {
407 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
412 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
413 if (subtlv_length
%4 != 0)
414 subtlv_length
+=4-(subtlv_length
%4);
416 tlv_length
-=subtlv_length
;
422 case LS_OPAQUE_TE_TLV_ROUTER
:
423 if (tlv_length
< 4) {
424 ND_PRINT((ndo
, "\n\t TLV length %u < 4", tlv_length
));
427 ND_TCHECK2(*tptr
, 4);
428 ND_PRINT((ndo
, ", %s", ipaddr_string(ndo
, tptr
)));
432 if (ndo
->ndo_vflag
<= 1) {
433 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
438 /* in OSPF everything has to be 32-bit aligned, including TLVs */
439 if (tlv_length
%4 != 0)
440 tlv_length
+=4-(tlv_length
%4);
441 ls_length
-=tlv_length
;
450 ospf_print_lshdr(netdissect_options
*ndo
,
451 register const struct lsa_hdr
*lshp
)
455 ND_TCHECK(lshp
->ls_length
);
456 ls_length
= EXTRACT_16BITS(&lshp
->ls_length
);
457 if (ls_length
< sizeof(struct lsa_hdr
)) {
458 ND_PRINT((ndo
, "\n\t Bogus length %u < header (%lu)", ls_length
,
459 (unsigned long)sizeof(struct lsa_hdr
)));
463 ND_TCHECK(lshp
->ls_seq
); /* XXX - ls_length check checked this */
464 ND_PRINT((ndo
, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
465 ipaddr_string(ndo
, &lshp
->ls_router
),
466 EXTRACT_32BITS(&lshp
->ls_seq
),
467 EXTRACT_16BITS(&lshp
->ls_age
),
468 ls_length
- (u_int
)sizeof(struct lsa_hdr
)));
470 ND_TCHECK(lshp
->ls_type
); /* XXX - ls_length check checked this */
471 switch (lshp
->ls_type
) {
472 /* the LSA header for opaque LSAs was slightly changed */
473 case LS_TYPE_OPAQUE_LL
:
474 case LS_TYPE_OPAQUE_AL
:
475 case LS_TYPE_OPAQUE_DW
:
476 ND_PRINT((ndo
, "\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
477 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
480 tok2str(lsa_opaque_values
,
482 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
483 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
),
484 EXTRACT_24BITS(&lshp
->un_lsa_id
.opaque_field
.opaque_id
)
489 /* all other LSA types use regular style LSA headers */
491 ND_PRINT((ndo
, "\n\t %s LSA (%d), LSA-ID: %s",
492 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
494 ipaddr_string(ndo
, &lshp
->un_lsa_id
.lsa_id
)));
498 ND_TCHECK(lshp
->ls_options
); /* XXX - ls_length check checked this */
499 ND_PRINT((ndo
, "\n\t Options: [%s]", bittok2str(ospf_option_values
, "none", lshp
->ls_options
)));
506 /* draft-ietf-ospf-mt-09 */
507 static const struct tok ospf_topology_values
[] = {
510 { 2, "management " },
515 * Print all the per-topology metrics.
518 ospf_print_tos_metrics(netdissect_options
*ndo
,
519 const union un_tos
*tos
)
524 toscount
= tos
->link
.link_tos_count
+1;
528 * All but the first metric contain a valid topology id.
531 ND_PRINT((ndo
, "\n\t\ttopology %s(%u), metric %u",
532 tok2str(ospf_topology_values
, "",
533 metric_count
? tos
->metrics
.tos_type
: 0),
534 metric_count
? tos
->metrics
.tos_type
: 0,
535 EXTRACT_16BITS(&tos
->metrics
.tos_metric
)));
543 * Print a single link state advertisement. If truncated or if LSA length
544 * field is less than the length of the LSA header, return NULl, else
545 * return pointer to data past end of LSA.
547 static const uint8_t *
548 ospf_print_lsa(netdissect_options
*ndo
,
549 register const struct lsa
*lsap
)
551 register const uint8_t *ls_end
;
552 register const struct rlalink
*rlp
;
553 register const struct in_addr
*ap
;
554 register const struct aslametric
*almp
;
555 register const struct mcla
*mcp
;
556 register const uint32_t *lp
;
557 register int j
, tlv_type
, tlv_length
, topology
;
558 register int ls_length
;
561 tptr
= (const uint8_t *)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
562 ls_length
= ospf_print_lshdr(ndo
, &lsap
->ls_hdr
);
565 ls_end
= (const uint8_t *)lsap
+ ls_length
;
566 ls_length
-= sizeof(struct lsa_hdr
);
568 switch (lsap
->ls_hdr
.ls_type
) {
571 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
572 ND_PRINT((ndo
, "\n\t Router LSA Options: [%s]",
573 bittok2str(ospf_rla_flag_values
, "none", lsap
->lsa_un
.un_rla
.rla_flags
)));
575 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
576 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
577 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
578 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
581 switch (rlp
->un_tos
.link
.link_type
) {
583 case RLA_TYPE_VIRTUAL
:
584 ND_PRINT((ndo
, "\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
585 ipaddr_string(ndo
, &rlp
->link_id
),
586 ipaddr_string(ndo
, &rlp
->link_data
)));
589 case RLA_TYPE_ROUTER
:
590 ND_PRINT((ndo
, "\n\t Neighbor Router-ID: %s, Interface Address: %s",
591 ipaddr_string(ndo
, &rlp
->link_id
),
592 ipaddr_string(ndo
, &rlp
->link_data
)));
595 case RLA_TYPE_TRANSIT
:
596 ND_PRINT((ndo
, "\n\t Neighbor Network-ID: %s, Interface Address: %s",
597 ipaddr_string(ndo
, &rlp
->link_id
),
598 ipaddr_string(ndo
, &rlp
->link_data
)));
602 ND_PRINT((ndo
, "\n\t Stub Network: %s, Mask: %s",
603 ipaddr_string(ndo
, &rlp
->link_id
),
604 ipaddr_string(ndo
, &rlp
->link_data
)));
608 ND_PRINT((ndo
, "\n\t Unknown Router Link Type (%u)",
609 rlp
->un_tos
.link
.link_type
));
613 ospf_print_tos_metrics(ndo
, &rlp
->un_tos
);
615 rlp
= (const struct rlalink
*)((const u_char
*)(rlp
+ 1) +
616 ((rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
620 case LS_TYPE_NETWORK
:
621 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
622 ND_PRINT((ndo
, "\n\t Mask %s\n\t Connected Routers:",
623 ipaddr_string(ndo
, &lsap
->lsa_un
.un_nla
.nla_mask
)));
624 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
625 while ((const u_char
*)ap
< ls_end
) {
627 ND_PRINT((ndo
, "\n\t %s", ipaddr_string(ndo
, ap
)));
633 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
634 ND_PRINT((ndo
, "\n\t Mask %s",
635 ipaddr_string(ndo
, &lsap
->lsa_un
.un_sla
.sla_mask
)));
636 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
637 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
638 while ((const u_char
*)lp
< ls_end
) {
639 register uint32_t ul
;
642 ul
= EXTRACT_32BITS(lp
);
643 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
644 ND_PRINT((ndo
, "\n\t\ttopology %s(%u) metric %d",
645 tok2str(ospf_topology_values
, "", topology
),
647 ul
& SLA_MASK_METRIC
));
652 case LS_TYPE_SUM_ABR
:
653 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
654 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
655 while ((const u_char
*)lp
< ls_end
) {
656 register uint32_t ul
;
659 ul
= EXTRACT_32BITS(lp
);
660 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
661 ND_PRINT((ndo
, "\n\t\ttopology %s(%u) metric %d",
662 tok2str(ospf_topology_values
, "", topology
),
664 ul
& SLA_MASK_METRIC
));
670 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
671 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
672 ND_PRINT((ndo
, "\n\t Mask %s",
673 ipaddr_string(ndo
, &lsap
->lsa_un
.un_asla
.asla_mask
)));
675 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
676 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
677 while ((const u_char
*)almp
< ls_end
) {
678 register uint32_t ul
;
680 ND_TCHECK(almp
->asla_tosmetric
);
681 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
682 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
683 ND_PRINT((ndo
, "\n\t\ttopology %s(%u), type %d, metric",
684 tok2str(ospf_topology_values
, "", topology
),
686 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1));
687 if ((ul
& ASLA_MASK_METRIC
) == 0xffffff)
688 ND_PRINT((ndo
, " infinite"));
690 ND_PRINT((ndo
, " %d", (ul
& ASLA_MASK_METRIC
)));
692 ND_TCHECK(almp
->asla_forward
);
693 if (almp
->asla_forward
.s_addr
) {
694 ND_PRINT((ndo
, ", forward %s", ipaddr_string(ndo
, &almp
->asla_forward
)));
696 ND_TCHECK(almp
->asla_tag
);
697 if (almp
->asla_tag
.s_addr
) {
698 ND_PRINT((ndo
, ", tag %s", ipaddr_string(ndo
, &almp
->asla_tag
)));
705 /* Multicast extensions as of 23 July 1991 */
706 mcp
= lsap
->lsa_un
.un_mcla
;
707 while ((const u_char
*)mcp
< ls_end
) {
708 ND_TCHECK(mcp
->mcla_vid
);
709 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
711 case MCLA_VERTEX_ROUTER
:
712 ND_PRINT((ndo
, "\n\t Router Router-ID %s",
713 ipaddr_string(ndo
, &mcp
->mcla_vid
)));
716 case MCLA_VERTEX_NETWORK
:
717 ND_PRINT((ndo
, "\n\t Network Designated Router %s",
718 ipaddr_string(ndo
, &mcp
->mcla_vid
)));
722 ND_PRINT((ndo
, "\n\t unknown VertexType (%u)",
723 EXTRACT_32BITS(&mcp
->mcla_vtype
)));
730 case LS_TYPE_OPAQUE_LL
: /* fall through */
731 case LS_TYPE_OPAQUE_AL
:
732 case LS_TYPE_OPAQUE_DW
:
734 switch (*(&lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
735 case LS_OPAQUE_TYPE_RI
:
736 tptr
= (const uint8_t *)(&lsap
->lsa_un
.un_ri_tlv
.type
);
738 while (ls_length
!= 0) {
739 ND_TCHECK2(*tptr
, 4);
741 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
744 tlv_type
= EXTRACT_16BITS(tptr
);
745 tlv_length
= EXTRACT_16BITS(tptr
+2);
749 ND_PRINT((ndo
, "\n\t %s TLV (%u), length: %u, value: ",
750 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
754 if (tlv_length
> ls_length
) {
755 ND_PRINT((ndo
, "\n\t Bogus length %u > %u", tlv_length
,
759 ND_TCHECK2(*tptr
, tlv_length
);
762 case LS_OPAQUE_RI_TLV_CAP
:
763 if (tlv_length
!= 4) {
764 ND_PRINT((ndo
, "\n\t Bogus length %u != 4", tlv_length
));
767 ND_PRINT((ndo
, "Capabilities: %s",
768 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", EXTRACT_32BITS(tptr
))));
771 if (ndo
->ndo_vflag
<= 1) {
772 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
779 ls_length
-=tlv_length
;
783 case LS_OPAQUE_TYPE_GRACE
:
784 if (ospf_print_grace_lsa(ndo
, (const uint8_t *)(&lsap
->lsa_un
.un_grace_tlv
.type
),
790 case LS_OPAQUE_TYPE_TE
:
791 if (ospf_print_te_lsa(ndo
, (const uint8_t *)(&lsap
->lsa_un
.un_te_lsa_tlv
.type
),
798 if (ndo
->ndo_vflag
<= 1) {
799 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
807 /* do we want to see an additionally hexdump ? */
808 if (ndo
->ndo_vflag
> 1)
809 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
810 "\n\t ", ls_length
)) {
820 ospf_decode_lls(netdissect_options
*ndo
,
821 register const struct ospfhdr
*op
, register u_int length
)
823 register const u_char
*dptr
;
824 register const u_char
*dataend
;
825 register u_int length2
;
826 register uint16_t lls_type
, lls_len
;
827 register uint32_t lls_flags
;
829 switch (op
->ospf_type
) {
831 case OSPF_TYPE_HELLO
:
832 if (!(op
->ospf_hello
.hello_options
& OSPF_OPTION_L
))
837 if (!(op
->ospf_db
.db_options
& OSPF_OPTION_L
))
845 /* dig deeper if LLS data is available; see RFC4813 */
846 length2
= EXTRACT_16BITS(&op
->ospf_len
);
847 dptr
= (const u_char
*)op
+ length2
;
848 dataend
= (const u_char
*)op
+ length
;
850 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
851 dptr
= dptr
+ op
->ospf_authdata
[3];
852 length2
+= op
->ospf_authdata
[3];
854 if (length2
>= length
) {
855 ND_PRINT((ndo
, "\n\t[LLS truncated]"));
858 ND_TCHECK2(*dptr
, 2);
859 ND_PRINT((ndo
, "\n\t LLS: checksum: 0x%04x", (u_int
)EXTRACT_16BITS(dptr
)));
862 ND_TCHECK2(*dptr
, 2);
863 length2
= EXTRACT_16BITS(dptr
);
864 ND_PRINT((ndo
, ", length: %u", length2
));
868 while (dptr
< dataend
) {
869 ND_TCHECK2(*dptr
, 2);
870 lls_type
= EXTRACT_16BITS(dptr
);
871 ND_PRINT((ndo
, "\n\t %s (%u)",
872 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
875 ND_TCHECK2(*dptr
, 2);
876 lls_len
= EXTRACT_16BITS(dptr
);
877 ND_PRINT((ndo
, ", length: %u", lls_len
));
883 ND_PRINT((ndo
, " [should be 4]"));
886 ND_TCHECK2(*dptr
, 4);
887 lls_flags
= EXTRACT_32BITS(dptr
);
888 ND_PRINT((ndo
, "\n\t Options: 0x%08x [%s]", lls_flags
,
889 bittok2str(ospf_lls_eo_options
, "?", lls_flags
)));
895 ND_PRINT((ndo
, " [should be 20]"));
898 ND_TCHECK2(*dptr
, 4);
899 ND_PRINT((ndo
, "\n\t Sequence number: 0x%08x", EXTRACT_32BITS(dptr
)));
912 ospf_decode_v2(netdissect_options
*ndo
,
913 register const struct ospfhdr
*op
, register const u_char
*dataend
)
915 register const struct in_addr
*ap
;
916 register const struct lsr
*lsrp
;
917 register const struct lsa_hdr
*lshp
;
918 register const struct lsa
*lsap
;
919 register uint32_t lsa_count
,lsa_count_max
;
921 switch (op
->ospf_type
) {
925 * Rob Coltun's special monitoring packets;
930 case OSPF_TYPE_HELLO
:
931 ND_PRINT((ndo
, "\n\tOptions [%s]",
932 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
)));
934 ND_TCHECK(op
->ospf_hello
.hello_deadint
);
935 ND_PRINT((ndo
, "\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
936 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
937 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
938 ipaddr_string(ndo
, &op
->ospf_hello
.hello_mask
),
939 op
->ospf_hello
.hello_priority
));
941 ND_TCHECK(op
->ospf_hello
.hello_dr
);
942 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
943 ND_PRINT((ndo
, "\n\t Designated Router %s",
944 ipaddr_string(ndo
, &op
->ospf_hello
.hello_dr
)));
946 ND_TCHECK(op
->ospf_hello
.hello_bdr
);
947 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
948 ND_PRINT((ndo
, ", Backup Designated Router %s",
949 ipaddr_string(ndo
, &op
->ospf_hello
.hello_bdr
)));
951 ap
= op
->ospf_hello
.hello_neighbor
;
952 if ((const u_char
*)ap
< dataend
)
953 ND_PRINT((ndo
, "\n\t Neighbor List:"));
954 while ((const u_char
*)ap
< dataend
) {
956 ND_PRINT((ndo
, "\n\t %s", ipaddr_string(ndo
, ap
)));
962 ND_TCHECK(op
->ospf_db
.db_options
);
963 ND_PRINT((ndo
, "\n\tOptions [%s]",
964 bittok2str(ospf_option_values
, "none", op
->ospf_db
.db_options
)));
965 ND_TCHECK(op
->ospf_db
.db_flags
);
966 ND_PRINT((ndo
, ", DD Flags [%s]",
967 bittok2str(ospf_dd_flag_values
, "none", op
->ospf_db
.db_flags
)));
968 ND_TCHECK(op
->ospf_db
.db_ifmtu
);
969 if (op
->ospf_db
.db_ifmtu
) {
970 ND_PRINT((ndo
, ", MTU: %u", EXTRACT_16BITS(&op
->ospf_db
.db_ifmtu
)));
972 ND_TCHECK(op
->ospf_db
.db_seq
);
973 ND_PRINT((ndo
, ", Sequence: 0x%08x", EXTRACT_32BITS(&op
->ospf_db
.db_seq
)));
975 /* Print all the LS adv's */
976 lshp
= op
->ospf_db
.db_lshdr
;
977 while (((const u_char
*)lshp
< dataend
) && ospf_print_lshdr(ndo
, lshp
) != -1) {
982 case OSPF_TYPE_LS_REQ
:
984 while ((const u_char
*)lsrp
< dataend
) {
987 ND_PRINT((ndo
, "\n\t Advertising Router: %s, %s LSA (%u)",
988 ipaddr_string(ndo
, &lsrp
->ls_router
),
989 tok2str(lsa_values
,"unknown",EXTRACT_32BITS(lsrp
->ls_type
)),
990 EXTRACT_32BITS(&lsrp
->ls_type
)));
992 switch (EXTRACT_32BITS(lsrp
->ls_type
)) {
993 /* the LSA header for opaque LSAs was slightly changed */
994 case LS_TYPE_OPAQUE_LL
:
995 case LS_TYPE_OPAQUE_AL
:
996 case LS_TYPE_OPAQUE_DW
:
997 ND_PRINT((ndo
, ", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
998 tok2str(lsa_opaque_values
, "unknown",lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
999 lsrp
->un_ls_stateid
.opaque_field
.opaque_type
,
1000 EXTRACT_24BITS(&lsrp
->un_ls_stateid
.opaque_field
.opaque_id
)));
1003 ND_PRINT((ndo
, ", LSA-ID: %s",
1004 ipaddr_string(ndo
, &lsrp
->un_ls_stateid
.ls_stateid
)));
1012 case OSPF_TYPE_LS_UPDATE
:
1013 lsap
= op
->ospf_lsu
.lsu_lsa
;
1014 ND_TCHECK(op
->ospf_lsu
.lsu_count
);
1015 lsa_count_max
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
1016 ND_PRINT((ndo
, ", %d LSA%s", lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
)));
1017 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1018 ND_PRINT((ndo
, "\n\t LSA #%u", lsa_count
));
1019 lsap
= (const struct lsa
*)ospf_print_lsa(ndo
, lsap
);
1025 case OSPF_TYPE_LS_ACK
:
1026 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1027 while (ospf_print_lshdr(ndo
, lshp
) != -1) {
1041 ospf_print(netdissect_options
*ndo
,
1042 register const u_char
*bp
, register u_int length
,
1043 const u_char
*bp2 _U_
)
1045 register const struct ospfhdr
*op
;
1046 register const u_char
*dataend
;
1047 register const char *cp
;
1049 op
= (const struct ospfhdr
*)bp
;
1051 /* XXX Before we do anything else, strip off the MD5 trailer */
1052 ND_TCHECK(op
->ospf_authtype
);
1053 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1054 length
-= OSPF_AUTH_MD5_LEN
;
1055 ndo
->ndo_snapend
-= OSPF_AUTH_MD5_LEN
;
1058 /* If the type is valid translate it, or just print the type */
1059 /* value. If it's not valid, say so and return */
1060 ND_TCHECK(op
->ospf_type
);
1061 cp
= tok2str(type2str
, "unknown LS-type", op
->ospf_type
);
1062 ND_PRINT((ndo
, "OSPFv%u, %s, length %u", op
->ospf_version
, cp
, length
));
1066 if (!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1070 ND_TCHECK(op
->ospf_len
);
1071 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
1072 ND_PRINT((ndo
, " [len %d]", EXTRACT_16BITS(&op
->ospf_len
)));
1075 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1076 dataend
= bp
+ EXTRACT_16BITS(&op
->ospf_len
);
1078 dataend
= bp
+ length
;
1081 ND_TCHECK(op
->ospf_routerid
);
1082 ND_PRINT((ndo
, "\n\tRouter-ID %s", ipaddr_string(ndo
, &op
->ospf_routerid
)));
1084 ND_TCHECK(op
->ospf_areaid
);
1085 if (op
->ospf_areaid
.s_addr
!= 0)
1086 ND_PRINT((ndo
, ", Area %s", ipaddr_string(ndo
, &op
->ospf_areaid
)));
1088 ND_PRINT((ndo
, ", Backbone Area"));
1090 if (ndo
->ndo_vflag
) {
1091 /* Print authentication data (should we really do this?) */
1092 ND_TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
1094 ND_PRINT((ndo
, ", Authentication Type: %s (%u)",
1095 tok2str(ospf_authtype_values
, "unknown", EXTRACT_16BITS(&op
->ospf_authtype
)),
1096 EXTRACT_16BITS(&op
->ospf_authtype
)));
1098 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
1100 case OSPF_AUTH_NONE
:
1103 case OSPF_AUTH_SIMPLE
:
1104 ND_PRINT((ndo
, "\n\tSimple text password: "));
1105 safeputs(ndo
, op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
1109 ND_PRINT((ndo
, "\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1110 *((op
->ospf_authdata
) + 2),
1111 *((op
->ospf_authdata
) + 3),
1112 EXTRACT_32BITS((op
->ospf_authdata
) + 4)));
1119 /* Do rest according to version. */
1120 switch (op
->ospf_version
) {
1123 /* ospf version 2 */
1124 if (ospf_decode_v2(ndo
, op
, dataend
))
1126 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1127 if (ospf_decode_lls(ndo
, op
, length
))
1133 ND_PRINT((ndo
, " ospf [version %d]", op
->ospf_version
));
1135 } /* end switch on version */
1139 ND_PRINT((ndo
, "%s", tstr
));