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 #include <sys/cdefs.h>
26 __RCSID("$NetBSD: print-ospf.c,v 1.6 2015/03/31 21:59:35 christos Exp $");
29 #define NETDISSECT_REWORKED
34 #include <tcpdump-stdinc.h>
36 #include "interface.h"
37 #include "addrtoname.h"
43 static const char tstr
[] = " [|ospf2]";
45 static const struct tok ospf_option_values
[] = {
46 { OSPF_OPTION_T
, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
47 { OSPF_OPTION_E
, "External" },
48 { OSPF_OPTION_MC
, "Multicast" },
49 { OSPF_OPTION_NP
, "NSSA" },
50 { OSPF_OPTION_L
, "LLS" },
51 { OSPF_OPTION_DC
, "Demand Circuit" },
52 { OSPF_OPTION_O
, "Opaque" },
53 { OSPF_OPTION_DN
, "Up/Down" },
57 static const struct tok ospf_authtype_values
[] = {
58 { OSPF_AUTH_NONE
, "none" },
59 { OSPF_AUTH_SIMPLE
, "simple" },
60 { OSPF_AUTH_MD5
, "MD5" },
64 static const struct tok ospf_rla_flag_values
[] = {
65 { RLA_FLAG_B
, "ABR" },
66 { RLA_FLAG_E
, "ASBR" },
67 { RLA_FLAG_W1
, "Virtual" },
68 { RLA_FLAG_W2
, "W2" },
72 static const struct tok type2str
[] = {
73 { OSPF_TYPE_UMD
, "UMD" },
74 { OSPF_TYPE_HELLO
, "Hello" },
75 { OSPF_TYPE_DD
, "Database Description" },
76 { OSPF_TYPE_LS_REQ
, "LS-Request" },
77 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
78 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
82 static const struct tok lsa_values
[] = {
83 { LS_TYPE_ROUTER
, "Router" },
84 { LS_TYPE_NETWORK
, "Network" },
85 { LS_TYPE_SUM_IP
, "Summary" },
86 { LS_TYPE_SUM_ABR
, "ASBR Summary" },
87 { LS_TYPE_ASE
, "External" },
88 { LS_TYPE_GROUP
, "Multicast Group" },
89 { LS_TYPE_NSSA
, "NSSA" },
90 { LS_TYPE_OPAQUE_LL
, "Link Local Opaque" },
91 { LS_TYPE_OPAQUE_AL
, "Area Local Opaque" },
92 { LS_TYPE_OPAQUE_DW
, "Domain Wide Opaque" },
96 static const struct tok ospf_dd_flag_values
[] = {
97 { OSPF_DB_INIT
, "Init" },
98 { OSPF_DB_MORE
, "More" },
99 { OSPF_DB_MASTER
, "Master" },
100 { OSPF_DB_RESYNC
, "OOBResync" },
104 static const struct tok lsa_opaque_values
[] = {
105 { LS_OPAQUE_TYPE_TE
, "Traffic Engineering" },
106 { LS_OPAQUE_TYPE_GRACE
, "Graceful restart" },
107 { LS_OPAQUE_TYPE_RI
, "Router Information" },
111 static const struct tok lsa_opaque_te_tlv_values
[] = {
112 { LS_OPAQUE_TE_TLV_ROUTER
, "Router Address" },
113 { LS_OPAQUE_TE_TLV_LINK
, "Link" },
117 static const struct tok lsa_opaque_te_link_tlv_subtlv_values
[] = {
118 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
, "Link Type" },
119 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
, "Link ID" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
, "Local Interface IP address" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
, "Remote Interface IP address" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
, "Traffic Engineering Metric" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
, "Maximum Bandwidth" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
, "Maximum Reservable Bandwidth" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
, "Unreserved Bandwidth" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
, "Administrative Group" },
127 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
, "Link Local/Remote Identifier" },
128 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
, "Link Protection Type" },
129 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
, "Interface Switching Capability" },
130 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
, "Shared Risk Link Group" },
131 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
, "Bandwidth Constraints" },
135 static const struct tok lsa_opaque_grace_tlv_values
[] = {
136 { LS_OPAQUE_GRACE_TLV_PERIOD
, "Grace Period" },
137 { LS_OPAQUE_GRACE_TLV_REASON
, "Graceful restart Reason" },
138 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS
, "IPv4 interface address" },
142 static const struct tok lsa_opaque_grace_tlv_reason_values
[] = {
143 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN
, "Unknown" },
144 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART
, "Software Restart" },
145 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE
, "Software Reload/Upgrade" },
146 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH
, "Control Processor Switch" },
150 static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values
[] = {
151 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP
, "Point-to-point" },
152 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA
, "Multi-Access" },
156 static const struct tok lsa_opaque_ri_tlv_values
[] = {
157 { LS_OPAQUE_RI_TLV_CAP
, "Router Capabilities" },
161 static const struct tok lsa_opaque_ri_tlv_cap_values
[] = {
166 { 16, "graceful restart capable" },
167 { 32, "graceful restart helper" },
168 { 64, "Stub router support" },
169 { 128, "Traffic engineering" },
170 { 256, "p2p over LAN" },
171 { 512, "path computation server" },
175 static const struct tok ospf_lls_tlv_values
[] = {
176 { OSPF_LLS_EO
, "Extended Options" },
177 { OSPF_LLS_MD5
, "MD5 Authentication" },
181 static const struct tok ospf_lls_eo_options
[] = {
182 { OSPF_LLS_EO_LR
, "LSDB resync" },
183 { OSPF_LLS_EO_RS
, "Restart" },
188 ospf_print_grace_lsa(netdissect_options
*ndo
,
189 const uint8_t *tptr
, u_int ls_length
)
191 u_int tlv_type
, tlv_length
;
194 while (ls_length
> 0) {
195 ND_TCHECK2(*tptr
, 4);
197 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
200 tlv_type
= EXTRACT_16BITS(tptr
);
201 tlv_length
= EXTRACT_16BITS(tptr
+2);
205 ND_PRINT((ndo
, "\n\t %s TLV (%u), length %u, value: ",
206 tok2str(lsa_opaque_grace_tlv_values
,"unknown",tlv_type
),
210 if (tlv_length
> ls_length
) {
211 ND_PRINT((ndo
, "\n\t Bogus length %u > %u", tlv_length
,
216 /* Infinite loop protection. */
217 if (tlv_type
== 0 || tlv_length
==0) {
221 ND_TCHECK2(*tptr
, tlv_length
);
224 case LS_OPAQUE_GRACE_TLV_PERIOD
:
225 if (tlv_length
!= 4) {
226 ND_PRINT((ndo
, "\n\t Bogus length %u != 4", tlv_length
));
229 ND_PRINT((ndo
, "%us", EXTRACT_32BITS(tptr
)));
232 case LS_OPAQUE_GRACE_TLV_REASON
:
233 if (tlv_length
!= 1) {
234 ND_PRINT((ndo
, "\n\t Bogus length %u != 1", tlv_length
));
237 ND_PRINT((ndo
, "%s (%u)",
238 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", *tptr
),
242 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
243 if (tlv_length
!= 4) {
244 ND_PRINT((ndo
, "\n\t Bogus length %u != 4", tlv_length
));
247 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
251 if (ndo
->ndo_vflag
<= 1) {
252 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
258 /* in OSPF everything has to be 32-bit aligned, including TLVs */
259 if (tlv_length
%4 != 0)
260 tlv_length
+=4-(tlv_length
%4);
261 ls_length
-=tlv_length
;
271 ospf_print_te_lsa(netdissect_options
*ndo
,
272 const uint8_t *tptr
, u_int ls_length
)
274 u_int tlv_type
, tlv_length
, subtlv_type
, subtlv_length
;
275 u_int priority_level
, te_class
, count_srlg
;
276 union { /* int to float conversion buffer for several subTLVs */
281 while (ls_length
!= 0) {
282 ND_TCHECK2(*tptr
, 4);
284 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
287 tlv_type
= EXTRACT_16BITS(tptr
);
288 tlv_length
= EXTRACT_16BITS(tptr
+2);
292 ND_PRINT((ndo
, "\n\t %s TLV (%u), length: %u",
293 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
297 if (tlv_length
> ls_length
) {
298 ND_PRINT((ndo
, "\n\t Bogus length %u > %u", tlv_length
,
303 /* Infinite loop protection. */
304 if (tlv_type
== 0 || tlv_length
==0) {
309 case LS_OPAQUE_TE_TLV_LINK
:
310 while (tlv_length
>= sizeof(subtlv_type
) + sizeof(subtlv_length
)) {
311 if (tlv_length
< 4) {
312 ND_PRINT((ndo
, "\n\t Remaining TLV length %u < 4",
316 ND_TCHECK2(*tptr
, 4);
317 subtlv_type
= EXTRACT_16BITS(tptr
);
318 subtlv_length
= EXTRACT_16BITS(tptr
+2);
322 ND_PRINT((ndo
, "\n\t %s subTLV (%u), length: %u",
323 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
327 ND_TCHECK2(*tptr
, subtlv_length
);
328 switch(subtlv_type
) {
329 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
330 ND_PRINT((ndo
, ", 0x%08x", EXTRACT_32BITS(tptr
)));
332 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
333 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
334 ND_PRINT((ndo
, ", %s (0x%08x)",
335 ipaddr_string(ndo
, tptr
),
336 EXTRACT_32BITS(tptr
)));
337 if (subtlv_length
== 8) /* rfc4203 */
338 ND_PRINT((ndo
, ", %s (0x%08x)",
339 ipaddr_string(ndo
, tptr
+4),
340 EXTRACT_32BITS(tptr
+ 4)));
342 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
343 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
344 ND_PRINT((ndo
, ", %s", ipaddr_string(ndo
, tptr
)));
346 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
347 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
348 bw
.i
= EXTRACT_32BITS(tptr
);
349 ND_PRINT((ndo
, ", %.3f Mbps", bw
.f
* 8 / 1000000));
351 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
352 for (te_class
= 0; te_class
< 8; te_class
++) {
353 bw
.i
= EXTRACT_32BITS(tptr
+te_class
*4);
354 ND_PRINT((ndo
, "\n\t\tTE-Class %u: %.3f Mbps",
356 bw
.f
* 8 / 1000000));
359 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
360 ND_PRINT((ndo
, "\n\t\tBandwidth Constraints Model ID: %s (%u)",
361 tok2str(diffserv_te_bc_values
, "unknown", *tptr
),
363 /* decode BCs until the subTLV ends */
364 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
365 bw
.i
= EXTRACT_32BITS(tptr
+4+te_class
*4);
366 ND_PRINT((ndo
, "\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
368 bw
.f
* 8 / 1000000));
371 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
372 ND_PRINT((ndo
, ", Metric %u", EXTRACT_32BITS(tptr
)));
374 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
375 ND_PRINT((ndo
, ", %s, Priority %u",
376 bittok2str(gmpls_link_prot_values
, "none", *tptr
),
379 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
380 ND_PRINT((ndo
, "\n\t\tInterface Switching Capability: %s",
381 tok2str(gmpls_switch_cap_values
, "Unknown", *(tptr
))));
382 ND_PRINT((ndo
, "\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
383 tok2str(gmpls_encoding_values
, "Unknown", *(tptr
+ 1))));
384 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
385 bw
.i
= EXTRACT_32BITS(tptr
+4+(priority_level
*4));
386 ND_PRINT((ndo
, "\n\t\t priority level %d: %.3f Mbps",
388 bw
.f
* 8 / 1000000));
391 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
392 ND_PRINT((ndo
, ", %s (%u)",
393 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",*tptr
),
397 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
398 count_srlg
= subtlv_length
/ 4;
400 ND_PRINT((ndo
, "\n\t\t Shared risk group: "));
401 while (count_srlg
> 0) {
402 bw
.i
= EXTRACT_32BITS(tptr
);
403 ND_PRINT((ndo
, "%d", bw
.i
));
407 ND_PRINT((ndo
, ", "));
412 if (ndo
->ndo_vflag
<= 1) {
413 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
418 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
419 if (subtlv_length
%4 != 0)
420 subtlv_length
+=4-(subtlv_length
%4);
422 tlv_length
-=subtlv_length
;
428 case LS_OPAQUE_TE_TLV_ROUTER
:
429 if (tlv_length
< 4) {
430 ND_PRINT((ndo
, "\n\t TLV length %u < 4", tlv_length
));
433 ND_TCHECK2(*tptr
, 4);
434 ND_PRINT((ndo
, ", %s", ipaddr_string(ndo
, tptr
)));
438 if (ndo
->ndo_vflag
<= 1) {
439 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
444 /* in OSPF everything has to be 32-bit aligned, including TLVs */
445 if (tlv_length
%4 != 0)
446 tlv_length
+=4-(tlv_length
%4);
447 ls_length
-=tlv_length
;
456 ospf_print_lshdr(netdissect_options
*ndo
,
457 register const struct lsa_hdr
*lshp
)
461 ND_TCHECK(lshp
->ls_length
);
462 ls_length
= EXTRACT_16BITS(&lshp
->ls_length
);
463 if (ls_length
< sizeof(struct lsa_hdr
)) {
464 ND_PRINT((ndo
, "\n\t Bogus length %u < header (%lu)", ls_length
,
465 (unsigned long)sizeof(struct lsa_hdr
)));
469 ND_TCHECK(lshp
->ls_seq
); /* XXX - ls_length check checked this */
470 ND_PRINT((ndo
, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
471 ipaddr_string(ndo
, &lshp
->ls_router
),
472 EXTRACT_32BITS(&lshp
->ls_seq
),
473 EXTRACT_16BITS(&lshp
->ls_age
),
474 ls_length
- (u_int
)sizeof(struct lsa_hdr
)));
476 ND_TCHECK(lshp
->ls_type
); /* XXX - ls_length check checked this */
477 switch (lshp
->ls_type
) {
478 /* the LSA header for opaque LSAs was slightly changed */
479 case LS_TYPE_OPAQUE_LL
:
480 case LS_TYPE_OPAQUE_AL
:
481 case LS_TYPE_OPAQUE_DW
:
482 ND_PRINT((ndo
, "\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
483 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
486 tok2str(lsa_opaque_values
,
488 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
489 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
),
490 EXTRACT_24BITS(&lshp
->un_lsa_id
.opaque_field
.opaque_id
)
495 /* all other LSA types use regular style LSA headers */
497 ND_PRINT((ndo
, "\n\t %s LSA (%d), LSA-ID: %s",
498 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
500 ipaddr_string(ndo
, &lshp
->un_lsa_id
.lsa_id
)));
504 ND_TCHECK(lshp
->ls_options
); /* XXX - ls_length check checked this */
505 ND_PRINT((ndo
, "\n\t Options: [%s]", bittok2str(ospf_option_values
, "none", lshp
->ls_options
)));
512 /* draft-ietf-ospf-mt-09 */
513 static const struct tok ospf_topology_values
[] = {
516 { 2, "management " },
521 * Print all the per-topology metrics.
524 ospf_print_tos_metrics(netdissect_options
*ndo
,
525 const union un_tos
*tos
)
530 toscount
= tos
->link
.link_tos_count
+1;
534 * All but the first metric contain a valid topology id.
537 ND_PRINT((ndo
, "\n\t\ttopology %s(%u), metric %u",
538 tok2str(ospf_topology_values
, "",
539 metric_count
? tos
->metrics
.tos_type
: 0),
540 metric_count
? tos
->metrics
.tos_type
: 0,
541 EXTRACT_16BITS(&tos
->metrics
.tos_metric
)));
549 * Print a single link state advertisement. If truncated or if LSA length
550 * field is less than the length of the LSA header, return NULl, else
551 * return pointer to data past end of LSA.
553 static const uint8_t *
554 ospf_print_lsa(netdissect_options
*ndo
,
555 register const struct lsa
*lsap
)
557 register const uint8_t *ls_end
;
558 register const struct rlalink
*rlp
;
559 register const struct in_addr
*ap
;
560 register const struct aslametric
*almp
;
561 register const struct mcla
*mcp
;
562 register const uint32_t *lp
;
563 register int j
, tlv_type
, tlv_length
, topology
;
564 register int ls_length
;
567 tptr
= (uint8_t *)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
568 ls_length
= ospf_print_lshdr(ndo
, &lsap
->ls_hdr
);
571 ls_end
= (uint8_t *)lsap
+ ls_length
;
572 ls_length
-= sizeof(struct lsa_hdr
);
574 switch (lsap
->ls_hdr
.ls_type
) {
577 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
578 ND_PRINT((ndo
, "\n\t Router LSA Options: [%s]",
579 bittok2str(ospf_rla_flag_values
, "none", lsap
->lsa_un
.un_rla
.rla_flags
)));
581 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
582 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
583 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
584 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
587 switch (rlp
->un_tos
.link
.link_type
) {
589 case RLA_TYPE_VIRTUAL
:
590 ND_PRINT((ndo
, "\n\t Virtual Link: 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_ROUTER
:
596 ND_PRINT((ndo
, "\n\t Neighbor Router-ID: %s, Interface Address: %s",
597 ipaddr_string(ndo
, &rlp
->link_id
),
598 ipaddr_string(ndo
, &rlp
->link_data
)));
601 case RLA_TYPE_TRANSIT
:
602 ND_PRINT((ndo
, "\n\t Neighbor Network-ID: %s, Interface Address: %s",
603 ipaddr_string(ndo
, &rlp
->link_id
),
604 ipaddr_string(ndo
, &rlp
->link_data
)));
608 ND_PRINT((ndo
, "\n\t Stub Network: %s, Mask: %s",
609 ipaddr_string(ndo
, &rlp
->link_id
),
610 ipaddr_string(ndo
, &rlp
->link_data
)));
614 ND_PRINT((ndo
, "\n\t Unknown Router Link Type (%u)",
615 rlp
->un_tos
.link
.link_type
));
619 ospf_print_tos_metrics(ndo
, &rlp
->un_tos
);
621 rlp
= (struct rlalink
*)((u_char
*)(rlp
+ 1) +
622 ((rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
626 case LS_TYPE_NETWORK
:
627 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
628 ND_PRINT((ndo
, "\n\t Mask %s\n\t Connected Routers:",
629 ipaddr_string(ndo
, &lsap
->lsa_un
.un_nla
.nla_mask
)));
630 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
631 while ((u_char
*)ap
< ls_end
) {
633 ND_PRINT((ndo
, "\n\t %s", ipaddr_string(ndo
, ap
)));
639 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
640 ND_PRINT((ndo
, "\n\t Mask %s",
641 ipaddr_string(ndo
, &lsap
->lsa_un
.un_sla
.sla_mask
)));
642 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
643 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
644 while ((u_char
*)lp
< ls_end
) {
645 register uint32_t ul
;
648 ul
= EXTRACT_32BITS(lp
);
649 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
650 ND_PRINT((ndo
, "\n\t\ttopology %s(%u) metric %d",
651 tok2str(ospf_topology_values
, "", topology
),
653 ul
& SLA_MASK_METRIC
));
658 case LS_TYPE_SUM_ABR
:
659 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
660 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
661 while ((u_char
*)lp
< ls_end
) {
662 register uint32_t ul
;
665 ul
= EXTRACT_32BITS(lp
);
666 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
667 ND_PRINT((ndo
, "\n\t\ttopology %s(%u) metric %d",
668 tok2str(ospf_topology_values
, "", topology
),
670 ul
& SLA_MASK_METRIC
));
676 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
677 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
678 ND_PRINT((ndo
, "\n\t Mask %s",
679 ipaddr_string(ndo
, &lsap
->lsa_un
.un_asla
.asla_mask
)));
681 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
682 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
683 while ((u_char
*)almp
< ls_end
) {
684 register uint32_t ul
;
686 ND_TCHECK(almp
->asla_tosmetric
);
687 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
688 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
689 ND_PRINT((ndo
, "\n\t\ttopology %s(%u), type %d, metric",
690 tok2str(ospf_topology_values
, "", topology
),
692 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1));
693 if ((ul
& ASLA_MASK_METRIC
) == 0xffffff)
694 ND_PRINT((ndo
, " infinite"));
696 ND_PRINT((ndo
, " %d", (ul
& ASLA_MASK_METRIC
)));
698 ND_TCHECK(almp
->asla_forward
);
699 if (almp
->asla_forward
.s_addr
) {
700 ND_PRINT((ndo
, ", forward %s", ipaddr_string(ndo
, &almp
->asla_forward
)));
702 ND_TCHECK(almp
->asla_tag
);
703 if (almp
->asla_tag
.s_addr
) {
704 ND_PRINT((ndo
, ", tag %s", ipaddr_string(ndo
, &almp
->asla_tag
)));
711 /* Multicast extensions as of 23 July 1991 */
712 mcp
= lsap
->lsa_un
.un_mcla
;
713 while ((u_char
*)mcp
< ls_end
) {
714 ND_TCHECK(mcp
->mcla_vid
);
715 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
717 case MCLA_VERTEX_ROUTER
:
718 ND_PRINT((ndo
, "\n\t Router Router-ID %s",
719 ipaddr_string(ndo
, &mcp
->mcla_vid
)));
722 case MCLA_VERTEX_NETWORK
:
723 ND_PRINT((ndo
, "\n\t Network Designated Router %s",
724 ipaddr_string(ndo
, &mcp
->mcla_vid
)));
728 ND_PRINT((ndo
, "\n\t unknown VertexType (%u)",
729 EXTRACT_32BITS(&mcp
->mcla_vtype
)));
736 case LS_TYPE_OPAQUE_LL
: /* fall through */
737 case LS_TYPE_OPAQUE_AL
:
738 case LS_TYPE_OPAQUE_DW
:
740 switch (*(&lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
741 case LS_OPAQUE_TYPE_RI
:
742 tptr
= (uint8_t *)(&lsap
->lsa_un
.un_ri_tlv
.type
);
744 while (ls_length
!= 0) {
745 ND_TCHECK2(*tptr
, 4);
747 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
750 tlv_type
= EXTRACT_16BITS(tptr
);
751 tlv_length
= EXTRACT_16BITS(tptr
+2);
755 ND_PRINT((ndo
, "\n\t %s TLV (%u), length: %u, value: ",
756 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
760 if (tlv_length
> ls_length
) {
761 ND_PRINT((ndo
, "\n\t Bogus length %u > %u", tlv_length
,
765 ND_TCHECK2(*tptr
, tlv_length
);
768 case LS_OPAQUE_RI_TLV_CAP
:
769 if (tlv_length
!= 4) {
770 ND_PRINT((ndo
, "\n\t Bogus length %u != 4", tlv_length
));
773 ND_PRINT((ndo
, "Capabilities: %s",
774 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", EXTRACT_32BITS(tptr
))));
777 if (ndo
->ndo_vflag
<= 1) {
778 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
785 ls_length
-=tlv_length
;
789 case LS_OPAQUE_TYPE_GRACE
:
790 if (ospf_print_grace_lsa(ndo
, (uint8_t *)(&lsap
->lsa_un
.un_grace_tlv
.type
),
796 case LS_OPAQUE_TYPE_TE
:
797 if (ospf_print_te_lsa(ndo
, (uint8_t *)(&lsap
->lsa_un
.un_te_lsa_tlv
.type
),
804 if (ndo
->ndo_vflag
<= 1) {
805 if (!print_unknown_data(ndo
, (uint8_t *)lsap
->lsa_un
.un_unknown
,
813 /* do we want to see an additionally hexdump ? */
814 if (ndo
->ndo_vflag
> 1)
815 if (!print_unknown_data(ndo
, (uint8_t *)lsap
->lsa_un
.un_unknown
,
816 "\n\t ", ls_length
)) {
826 ospf_decode_lls(netdissect_options
*ndo
,
827 register const struct ospfhdr
*op
, register u_int length
)
829 register const u_char
*dptr
;
830 register const u_char
*dataend
;
831 register u_int length2
;
832 register uint16_t lls_type
, lls_len
;
833 register uint32_t lls_flags
;
835 switch (op
->ospf_type
) {
837 case OSPF_TYPE_HELLO
:
838 if (!(op
->ospf_hello
.hello_options
& OSPF_OPTION_L
))
843 if (!(op
->ospf_db
.db_options
& OSPF_OPTION_L
))
851 /* dig deeper if LLS data is available; see RFC4813 */
852 length2
= EXTRACT_16BITS(&op
->ospf_len
);
853 dptr
= (u_char
*)op
+ length2
;
854 dataend
= (u_char
*)op
+ length
;
856 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
857 dptr
= dptr
+ op
->ospf_authdata
[3];
858 length2
+= op
->ospf_authdata
[3];
860 if (length2
>= length
) {
861 ND_PRINT((ndo
, "\n\t[LLS truncated]"));
864 ND_TCHECK2(*dptr
, 2);
865 ND_PRINT((ndo
, "\n\t LLS: checksum: 0x%04x", (u_int
)EXTRACT_16BITS(dptr
)));
868 ND_TCHECK2(*dptr
, 2);
869 length2
= EXTRACT_16BITS(dptr
);
870 ND_PRINT((ndo
, ", length: %u", length2
));
874 while (dptr
< dataend
) {
875 ND_TCHECK2(*dptr
, 2);
876 lls_type
= EXTRACT_16BITS(dptr
);
877 ND_PRINT((ndo
, "\n\t %s (%u)",
878 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
881 ND_TCHECK2(*dptr
, 2);
882 lls_len
= EXTRACT_16BITS(dptr
);
883 ND_PRINT((ndo
, ", length: %u", lls_len
));
889 ND_PRINT((ndo
, " [should be 4]"));
892 ND_TCHECK2(*dptr
, 4);
893 lls_flags
= EXTRACT_32BITS(dptr
);
894 ND_PRINT((ndo
, "\n\t Options: 0x%08x [%s]", lls_flags
,
895 bittok2str(ospf_lls_eo_options
, "?", lls_flags
)));
901 ND_PRINT((ndo
, " [should be 20]"));
904 ND_TCHECK2(*dptr
, 4);
905 ND_PRINT((ndo
, "\n\t Sequence number: 0x%08x", EXTRACT_32BITS(dptr
)));
918 ospf_decode_v2(netdissect_options
*ndo
,
919 register const struct ospfhdr
*op
, register const u_char
*dataend
)
921 register const struct in_addr
*ap
;
922 register const struct lsr
*lsrp
;
923 register const struct lsa_hdr
*lshp
;
924 register const struct lsa
*lsap
;
925 register uint32_t lsa_count
,lsa_count_max
;
927 switch (op
->ospf_type
) {
931 * Rob Coltun's special monitoring packets;
936 case OSPF_TYPE_HELLO
:
937 ND_PRINT((ndo
, "\n\tOptions [%s]",
938 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
)));
940 ND_TCHECK(op
->ospf_hello
.hello_deadint
);
941 ND_PRINT((ndo
, "\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
942 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
943 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
944 ipaddr_string(ndo
, &op
->ospf_hello
.hello_mask
),
945 op
->ospf_hello
.hello_priority
));
947 ND_TCHECK(op
->ospf_hello
.hello_dr
);
948 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
949 ND_PRINT((ndo
, "\n\t Designated Router %s",
950 ipaddr_string(ndo
, &op
->ospf_hello
.hello_dr
)));
952 ND_TCHECK(op
->ospf_hello
.hello_bdr
);
953 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
954 ND_PRINT((ndo
, ", Backup Designated Router %s",
955 ipaddr_string(ndo
, &op
->ospf_hello
.hello_bdr
)));
957 ap
= op
->ospf_hello
.hello_neighbor
;
958 if ((u_char
*)ap
< dataend
)
959 ND_PRINT((ndo
, "\n\t Neighbor List:"));
960 while ((u_char
*)ap
< dataend
) {
962 ND_PRINT((ndo
, "\n\t %s", ipaddr_string(ndo
, ap
)));
968 ND_TCHECK(op
->ospf_db
.db_options
);
969 ND_PRINT((ndo
, "\n\tOptions [%s]",
970 bittok2str(ospf_option_values
, "none", op
->ospf_db
.db_options
)));
971 ND_TCHECK(op
->ospf_db
.db_flags
);
972 ND_PRINT((ndo
, ", DD Flags [%s]",
973 bittok2str(ospf_dd_flag_values
, "none", op
->ospf_db
.db_flags
)));
974 ND_TCHECK(op
->ospf_db
.db_ifmtu
);
975 if (op
->ospf_db
.db_ifmtu
) {
976 ND_PRINT((ndo
, ", MTU: %u", EXTRACT_16BITS(&op
->ospf_db
.db_ifmtu
)));
978 ND_TCHECK(op
->ospf_db
.db_seq
);
979 ND_PRINT((ndo
, ", Sequence: 0x%08x", EXTRACT_32BITS(&op
->ospf_db
.db_seq
)));
981 /* Print all the LS adv's */
982 lshp
= op
->ospf_db
.db_lshdr
;
983 while (((u_char
*)lshp
< dataend
) && ospf_print_lshdr(ndo
, lshp
) != -1) {
988 case OSPF_TYPE_LS_REQ
:
990 while ((u_char
*)lsrp
< dataend
) {
993 ND_PRINT((ndo
, "\n\t Advertising Router: %s, %s LSA (%u)",
994 ipaddr_string(ndo
, &lsrp
->ls_router
),
995 tok2str(lsa_values
,"unknown",EXTRACT_32BITS(lsrp
->ls_type
)),
996 EXTRACT_32BITS(&lsrp
->ls_type
)));
998 switch (EXTRACT_32BITS(lsrp
->ls_type
)) {
999 /* the LSA header for opaque LSAs was slightly changed */
1000 case LS_TYPE_OPAQUE_LL
:
1001 case LS_TYPE_OPAQUE_AL
:
1002 case LS_TYPE_OPAQUE_DW
:
1003 ND_PRINT((ndo
, ", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1004 tok2str(lsa_opaque_values
, "unknown",lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1005 lsrp
->un_ls_stateid
.opaque_field
.opaque_type
,
1006 EXTRACT_24BITS(&lsrp
->un_ls_stateid
.opaque_field
.opaque_id
)));
1009 ND_PRINT((ndo
, ", LSA-ID: %s",
1010 ipaddr_string(ndo
, &lsrp
->un_ls_stateid
.ls_stateid
)));
1018 case OSPF_TYPE_LS_UPDATE
:
1019 lsap
= op
->ospf_lsu
.lsu_lsa
;
1020 ND_TCHECK(op
->ospf_lsu
.lsu_count
);
1021 lsa_count_max
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
1022 ND_PRINT((ndo
, ", %d LSA%s", lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
)));
1023 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1024 ND_PRINT((ndo
, "\n\t LSA #%u", lsa_count
));
1025 lsap
= (const struct lsa
*)ospf_print_lsa(ndo
, lsap
);
1031 case OSPF_TYPE_LS_ACK
:
1032 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1033 while (ospf_print_lshdr(ndo
, lshp
) != -1) {
1047 ospf_print(netdissect_options
*ndo
,
1048 register const u_char
*bp
, register u_int length
,
1049 const u_char
*bp2 _U_
)
1051 register const struct ospfhdr
*op
;
1052 register const u_char
*dataend
;
1053 register const char *cp
;
1055 op
= (struct ospfhdr
*)bp
;
1057 /* XXX Before we do anything else, strip off the MD5 trailer */
1058 ND_TCHECK(op
->ospf_authtype
);
1059 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1060 length
-= OSPF_AUTH_MD5_LEN
;
1061 ndo
->ndo_snapend
-= OSPF_AUTH_MD5_LEN
;
1064 /* If the type is valid translate it, or just print the type */
1065 /* value. If it's not valid, say so and return */
1066 ND_TCHECK(op
->ospf_type
);
1067 cp
= tok2str(type2str
, "unknown LS-type", op
->ospf_type
);
1068 ND_PRINT((ndo
, "OSPFv%u, %s, length %u", op
->ospf_version
, cp
, length
));
1072 if (!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1076 ND_TCHECK(op
->ospf_len
);
1077 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
1078 ND_PRINT((ndo
, " [len %d]", EXTRACT_16BITS(&op
->ospf_len
)));
1081 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1082 dataend
= bp
+ EXTRACT_16BITS(&op
->ospf_len
);
1084 dataend
= bp
+ length
;
1087 ND_TCHECK(op
->ospf_routerid
);
1088 ND_PRINT((ndo
, "\n\tRouter-ID %s", ipaddr_string(ndo
, &op
->ospf_routerid
)));
1090 ND_TCHECK(op
->ospf_areaid
);
1091 if (op
->ospf_areaid
.s_addr
!= 0)
1092 ND_PRINT((ndo
, ", Area %s", ipaddr_string(ndo
, &op
->ospf_areaid
)));
1094 ND_PRINT((ndo
, ", Backbone Area"));
1096 if (ndo
->ndo_vflag
) {
1097 /* Print authentication data (should we really do this?) */
1098 ND_TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
1100 ND_PRINT((ndo
, ", Authentication Type: %s (%u)",
1101 tok2str(ospf_authtype_values
, "unknown", EXTRACT_16BITS(&op
->ospf_authtype
)),
1102 EXTRACT_16BITS(&op
->ospf_authtype
)));
1104 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
1106 case OSPF_AUTH_NONE
:
1109 case OSPF_AUTH_SIMPLE
:
1110 ND_PRINT((ndo
, "\n\tSimple text password: "));
1111 safeputs(ndo
, op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
1115 ND_PRINT((ndo
, "\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1116 *((op
->ospf_authdata
) + 2),
1117 *((op
->ospf_authdata
) + 3),
1118 EXTRACT_32BITS((op
->ospf_authdata
) + 4)));
1125 /* Do rest according to version. */
1126 switch (op
->ospf_version
) {
1129 /* ospf version 2 */
1130 if (ospf_decode_v2(ndo
, op
, dataend
))
1132 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1133 if (ospf_decode_lls(ndo
, op
, length
))
1139 ND_PRINT((ndo
, " ospf [version %d]", op
->ospf_version
));
1141 } /* end switch on version */
1145 ND_PRINT((ndo
, "%s", tstr
));