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]";
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 /* Infinite loop protection */
317 if (subtlv_type
== 0 || subtlv_length
== 0)
320 ND_PRINT((ndo
, "\n\t %s subTLV (%u), length: %u",
321 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
325 ND_TCHECK2(*tptr
, subtlv_length
);
326 switch(subtlv_type
) {
327 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
328 if (subtlv_length
!= 4) {
329 ND_PRINT((ndo
, " != 4"));
332 ND_PRINT((ndo
, ", 0x%08x", EXTRACT_32BITS(tptr
)));
334 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
335 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
336 if (subtlv_length
!= 4 && subtlv_length
!= 8) {
337 ND_PRINT((ndo
, " != 4 && != 8"));
340 ND_PRINT((ndo
, ", %s (0x%08x)",
341 ipaddr_string(ndo
, tptr
),
342 EXTRACT_32BITS(tptr
)));
343 if (subtlv_length
== 8) /* rfc4203 */
344 ND_PRINT((ndo
, ", %s (0x%08x)",
345 ipaddr_string(ndo
, tptr
+4),
346 EXTRACT_32BITS(tptr
+ 4)));
348 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
349 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
350 if (subtlv_length
!= 4) {
351 ND_PRINT((ndo
, " != 4"));
354 ND_PRINT((ndo
, ", %s", ipaddr_string(ndo
, tptr
)));
356 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
357 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
358 if (subtlv_length
!= 4) {
359 ND_PRINT((ndo
, " != 4"));
362 bw
.i
= EXTRACT_32BITS(tptr
);
363 ND_PRINT((ndo
, ", %.3f Mbps", bw
.f
* 8 / 1000000));
365 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
366 if (subtlv_length
!= 32) {
367 ND_PRINT((ndo
, " != 32"));
370 for (te_class
= 0; te_class
< 8; te_class
++) {
371 bw
.i
= EXTRACT_32BITS(tptr
+te_class
*4);
372 ND_PRINT((ndo
, "\n\t\tTE-Class %u: %.3f Mbps",
374 bw
.f
* 8 / 1000000));
377 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS
:
378 if (subtlv_length
< 4) {
379 ND_PRINT((ndo
, " < 4"));
382 /* BC Model Id (1 octet) + Reserved (3 octets) */
383 ND_PRINT((ndo
, "\n\t\tBandwidth Constraints Model ID: %s (%u)",
384 tok2str(diffserv_te_bc_values
, "unknown", *tptr
),
386 if (subtlv_length
% 4 != 0) {
387 ND_PRINT((ndo
, "\n\t\tlength %u != N x 4", subtlv_length
));
390 if (subtlv_length
> 36) {
391 ND_PRINT((ndo
, "\n\t\tlength %u > 36", subtlv_length
));
394 /* decode BCs until the subTLV ends */
395 for (te_class
= 0; te_class
< (subtlv_length
-4)/4; te_class
++) {
396 bw
.i
= EXTRACT_32BITS(tptr
+4+te_class
*4);
397 ND_PRINT((ndo
, "\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
399 bw
.f
* 8 / 1000000));
402 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
403 if (subtlv_length
!= 4) {
404 ND_PRINT((ndo
, " != 4"));
407 ND_PRINT((ndo
, ", Metric %u", EXTRACT_32BITS(tptr
)));
409 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
410 /* Protection Cap (1 octet) + Reserved ((3 octets) */
411 if (subtlv_length
!= 4) {
412 ND_PRINT((ndo
, " != 4"));
415 ND_PRINT((ndo
, ", %s",
416 bittok2str(gmpls_link_prot_values
, "none", *tptr
)));
418 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
419 if (subtlv_length
< 36) {
420 ND_PRINT((ndo
, " < 36"));
423 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
424 ND_PRINT((ndo
, "\n\t\tInterface Switching Capability: %s",
425 tok2str(gmpls_switch_cap_values
, "Unknown", *(tptr
))));
426 ND_PRINT((ndo
, "\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
427 tok2str(gmpls_encoding_values
, "Unknown", *(tptr
+ 1))));
428 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
429 bw
.i
= EXTRACT_32BITS(tptr
+4+(priority_level
*4));
430 ND_PRINT((ndo
, "\n\t\t priority level %d: %.3f Mbps",
432 bw
.f
* 8 / 1000000));
435 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
436 if (subtlv_length
!= 1) {
437 ND_PRINT((ndo
, " != 1"));
440 ND_PRINT((ndo
, ", %s (%u)",
441 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",*tptr
),
445 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
446 if (subtlv_length
% 4 != 0) {
447 ND_PRINT((ndo
, " != N x 4"));
450 count_srlg
= subtlv_length
/ 4;
452 ND_PRINT((ndo
, "\n\t\t Shared risk group: "));
453 while (count_srlg
> 0) {
454 bw
.i
= EXTRACT_32BITS(tptr
);
455 ND_PRINT((ndo
, "%d", bw
.i
));
459 ND_PRINT((ndo
, ", "));
464 if (ndo
->ndo_vflag
<= 1) {
465 if (!print_unknown_data(ndo
, tptr
, "\n\t\t", subtlv_length
))
470 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
471 if (subtlv_length
%4 != 0)
472 subtlv_length
+=4-(subtlv_length
%4);
474 tlv_length
-=subtlv_length
;
480 case LS_OPAQUE_TE_TLV_ROUTER
:
481 if (tlv_length
< 4) {
482 ND_PRINT((ndo
, "\n\t TLV length %u < 4", tlv_length
));
485 ND_TCHECK2(*tptr
, 4);
486 ND_PRINT((ndo
, ", %s", ipaddr_string(ndo
, tptr
)));
490 if (ndo
->ndo_vflag
<= 1) {
491 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
496 /* in OSPF everything has to be 32-bit aligned, including TLVs */
497 if (tlv_length
%4 != 0)
498 tlv_length
+=4-(tlv_length
%4);
499 ls_length
-=tlv_length
;
506 ND_PRINT((ndo
, "%s", istr
));
511 ospf_print_lshdr(netdissect_options
*ndo
,
512 register const struct lsa_hdr
*lshp
)
516 ND_TCHECK(lshp
->ls_length
);
517 ls_length
= EXTRACT_16BITS(&lshp
->ls_length
);
518 if (ls_length
< sizeof(struct lsa_hdr
)) {
519 ND_PRINT((ndo
, "\n\t Bogus length %u < header (%lu)", ls_length
,
520 (unsigned long)sizeof(struct lsa_hdr
)));
524 ND_TCHECK(lshp
->ls_seq
); /* XXX - ls_length check checked this */
525 ND_PRINT((ndo
, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
526 ipaddr_string(ndo
, &lshp
->ls_router
),
527 EXTRACT_32BITS(&lshp
->ls_seq
),
528 EXTRACT_16BITS(&lshp
->ls_age
),
529 ls_length
- (u_int
)sizeof(struct lsa_hdr
)));
531 ND_TCHECK(lshp
->ls_type
); /* XXX - ls_length check checked this */
532 switch (lshp
->ls_type
) {
533 /* the LSA header for opaque LSAs was slightly changed */
534 case LS_TYPE_OPAQUE_LL
:
535 case LS_TYPE_OPAQUE_AL
:
536 case LS_TYPE_OPAQUE_DW
:
537 ND_PRINT((ndo
, "\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
538 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
541 tok2str(lsa_opaque_values
,
543 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
544 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
),
545 EXTRACT_24BITS(&lshp
->un_lsa_id
.opaque_field
.opaque_id
)
550 /* all other LSA types use regular style LSA headers */
552 ND_PRINT((ndo
, "\n\t %s LSA (%d), LSA-ID: %s",
553 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
555 ipaddr_string(ndo
, &lshp
->un_lsa_id
.lsa_id
)));
559 ND_TCHECK(lshp
->ls_options
); /* XXX - ls_length check checked this */
560 ND_PRINT((ndo
, "\n\t Options: [%s]", bittok2str(ospf_option_values
, "none", lshp
->ls_options
)));
567 /* draft-ietf-ospf-mt-09 */
568 static const struct tok ospf_topology_values
[] = {
571 { 2, "management " },
576 * Print all the per-topology metrics.
579 ospf_print_tos_metrics(netdissect_options
*ndo
,
580 const union un_tos
*tos
)
585 toscount
= tos
->link
.link_tos_count
+1;
589 * All but the first metric contain a valid topology id.
592 ND_PRINT((ndo
, "\n\t\ttopology %s(%u), metric %u",
593 tok2str(ospf_topology_values
, "",
594 metric_count
? tos
->metrics
.tos_type
: 0),
595 metric_count
? tos
->metrics
.tos_type
: 0,
596 EXTRACT_16BITS(&tos
->metrics
.tos_metric
)));
604 * Print a single link state advertisement. If truncated or if LSA length
605 * field is less than the length of the LSA header, return NULl, else
606 * return pointer to data past end of LSA.
608 static const uint8_t *
609 ospf_print_lsa(netdissect_options
*ndo
,
610 register const struct lsa
*lsap
)
612 register const uint8_t *ls_end
;
613 register const struct rlalink
*rlp
;
614 register const struct in_addr
*ap
;
615 register const struct aslametric
*almp
;
616 register const struct mcla
*mcp
;
617 register const uint32_t *lp
;
618 register int j
, tlv_type
, tlv_length
, topology
;
619 register int ls_length
;
622 tptr
= (const uint8_t *)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
623 ls_length
= ospf_print_lshdr(ndo
, &lsap
->ls_hdr
);
626 ls_end
= (const uint8_t *)lsap
+ ls_length
;
627 ls_length
-= sizeof(struct lsa_hdr
);
629 switch (lsap
->ls_hdr
.ls_type
) {
632 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
633 ND_PRINT((ndo
, "\n\t Router LSA Options: [%s]",
634 bittok2str(ospf_rla_flag_values
, "none", lsap
->lsa_un
.un_rla
.rla_flags
)));
636 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
637 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
638 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
639 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
642 switch (rlp
->un_tos
.link
.link_type
) {
644 case RLA_TYPE_VIRTUAL
:
645 ND_PRINT((ndo
, "\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
646 ipaddr_string(ndo
, &rlp
->link_id
),
647 ipaddr_string(ndo
, &rlp
->link_data
)));
650 case RLA_TYPE_ROUTER
:
651 ND_PRINT((ndo
, "\n\t Neighbor Router-ID: %s, Interface Address: %s",
652 ipaddr_string(ndo
, &rlp
->link_id
),
653 ipaddr_string(ndo
, &rlp
->link_data
)));
656 case RLA_TYPE_TRANSIT
:
657 ND_PRINT((ndo
, "\n\t Neighbor Network-ID: %s, Interface Address: %s",
658 ipaddr_string(ndo
, &rlp
->link_id
),
659 ipaddr_string(ndo
, &rlp
->link_data
)));
663 ND_PRINT((ndo
, "\n\t Stub Network: %s, Mask: %s",
664 ipaddr_string(ndo
, &rlp
->link_id
),
665 ipaddr_string(ndo
, &rlp
->link_data
)));
669 ND_PRINT((ndo
, "\n\t Unknown Router Link Type (%u)",
670 rlp
->un_tos
.link
.link_type
));
674 ospf_print_tos_metrics(ndo
, &rlp
->un_tos
);
676 rlp
= (const struct rlalink
*)((const u_char
*)(rlp
+ 1) +
677 ((rlp
->un_tos
.link
.link_tos_count
) * sizeof(union un_tos
)));
681 case LS_TYPE_NETWORK
:
682 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
683 ND_PRINT((ndo
, "\n\t Mask %s\n\t Connected Routers:",
684 ipaddr_string(ndo
, &lsap
->lsa_un
.un_nla
.nla_mask
)));
685 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
686 while ((const u_char
*)ap
< ls_end
) {
688 ND_PRINT((ndo
, "\n\t %s", ipaddr_string(ndo
, ap
)));
694 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
695 ND_PRINT((ndo
, "\n\t Mask %s",
696 ipaddr_string(ndo
, &lsap
->lsa_un
.un_sla
.sla_mask
)));
697 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
698 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
699 while ((const u_char
*)lp
< ls_end
) {
700 register uint32_t ul
;
703 ul
= EXTRACT_32BITS(lp
);
704 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
705 ND_PRINT((ndo
, "\n\t\ttopology %s(%u) metric %d",
706 tok2str(ospf_topology_values
, "", topology
),
708 ul
& SLA_MASK_METRIC
));
713 case LS_TYPE_SUM_ABR
:
714 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
715 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
716 while ((const u_char
*)lp
< ls_end
) {
717 register uint32_t ul
;
720 ul
= EXTRACT_32BITS(lp
);
721 topology
= (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
;
722 ND_PRINT((ndo
, "\n\t\ttopology %s(%u) metric %d",
723 tok2str(ospf_topology_values
, "", topology
),
725 ul
& SLA_MASK_METRIC
));
731 case LS_TYPE_NSSA
: /* fall through - those LSAs share the same format */
732 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
733 ND_PRINT((ndo
, "\n\t Mask %s",
734 ipaddr_string(ndo
, &lsap
->lsa_un
.un_asla
.asla_mask
)));
736 ND_TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
737 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
738 while ((const u_char
*)almp
< ls_end
) {
739 register uint32_t ul
;
741 ND_TCHECK(almp
->asla_tosmetric
);
742 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
743 topology
= ((ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
744 ND_PRINT((ndo
, "\n\t\ttopology %s(%u), type %d, metric",
745 tok2str(ospf_topology_values
, "", topology
),
747 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1));
748 if ((ul
& ASLA_MASK_METRIC
) == 0xffffff)
749 ND_PRINT((ndo
, " infinite"));
751 ND_PRINT((ndo
, " %d", (ul
& ASLA_MASK_METRIC
)));
753 ND_TCHECK(almp
->asla_forward
);
754 if (almp
->asla_forward
.s_addr
) {
755 ND_PRINT((ndo
, ", forward %s", ipaddr_string(ndo
, &almp
->asla_forward
)));
757 ND_TCHECK(almp
->asla_tag
);
758 if (almp
->asla_tag
.s_addr
) {
759 ND_PRINT((ndo
, ", tag %s", ipaddr_string(ndo
, &almp
->asla_tag
)));
766 /* Multicast extensions as of 23 July 1991 */
767 mcp
= lsap
->lsa_un
.un_mcla
;
768 while ((const u_char
*)mcp
< ls_end
) {
769 ND_TCHECK(mcp
->mcla_vid
);
770 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
772 case MCLA_VERTEX_ROUTER
:
773 ND_PRINT((ndo
, "\n\t Router Router-ID %s",
774 ipaddr_string(ndo
, &mcp
->mcla_vid
)));
777 case MCLA_VERTEX_NETWORK
:
778 ND_PRINT((ndo
, "\n\t Network Designated Router %s",
779 ipaddr_string(ndo
, &mcp
->mcla_vid
)));
783 ND_PRINT((ndo
, "\n\t unknown VertexType (%u)",
784 EXTRACT_32BITS(&mcp
->mcla_vtype
)));
791 case LS_TYPE_OPAQUE_LL
: /* fall through */
792 case LS_TYPE_OPAQUE_AL
:
793 case LS_TYPE_OPAQUE_DW
:
795 switch (*(&lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
796 case LS_OPAQUE_TYPE_RI
:
797 tptr
= (const uint8_t *)(&lsap
->lsa_un
.un_ri_tlv
.type
);
799 while (ls_length
!= 0) {
800 ND_TCHECK2(*tptr
, 4);
802 ND_PRINT((ndo
, "\n\t Remaining LS length %u < 4", ls_length
));
805 tlv_type
= EXTRACT_16BITS(tptr
);
806 tlv_length
= EXTRACT_16BITS(tptr
+2);
810 ND_PRINT((ndo
, "\n\t %s TLV (%u), length: %u, value: ",
811 tok2str(lsa_opaque_ri_tlv_values
,"unknown",tlv_type
),
815 if (tlv_length
> ls_length
) {
816 ND_PRINT((ndo
, "\n\t Bogus length %u > %u", tlv_length
,
820 ND_TCHECK2(*tptr
, tlv_length
);
823 case LS_OPAQUE_RI_TLV_CAP
:
824 if (tlv_length
!= 4) {
825 ND_PRINT((ndo
, "\n\t Bogus length %u != 4", tlv_length
));
828 ND_PRINT((ndo
, "Capabilities: %s",
829 bittok2str(lsa_opaque_ri_tlv_cap_values
, "Unknown", EXTRACT_32BITS(tptr
))));
832 if (ndo
->ndo_vflag
<= 1) {
833 if (!print_unknown_data(ndo
, tptr
, "\n\t ", tlv_length
))
840 ls_length
-=tlv_length
;
844 case LS_OPAQUE_TYPE_GRACE
:
845 if (ospf_print_grace_lsa(ndo
, (const uint8_t *)(&lsap
->lsa_un
.un_grace_tlv
.type
),
851 case LS_OPAQUE_TYPE_TE
:
852 if (ospf_print_te_lsa(ndo
, (const uint8_t *)(&lsap
->lsa_un
.un_te_lsa_tlv
.type
),
859 if (ndo
->ndo_vflag
<= 1) {
860 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
868 /* do we want to see an additionally hexdump ? */
869 if (ndo
->ndo_vflag
> 1)
870 if (!print_unknown_data(ndo
, (const uint8_t *)lsap
->lsa_un
.un_unknown
,
871 "\n\t ", ls_length
)) {
881 ospf_decode_lls(netdissect_options
*ndo
,
882 register const struct ospfhdr
*op
, register u_int length
)
884 register const u_char
*dptr
;
885 register const u_char
*dataend
;
886 register u_int length2
;
887 register uint16_t lls_type
, lls_len
;
888 register uint32_t lls_flags
;
890 switch (op
->ospf_type
) {
892 case OSPF_TYPE_HELLO
:
893 if (!(op
->ospf_hello
.hello_options
& OSPF_OPTION_L
))
898 if (!(op
->ospf_db
.db_options
& OSPF_OPTION_L
))
906 /* dig deeper if LLS data is available; see RFC4813 */
907 length2
= EXTRACT_16BITS(&op
->ospf_len
);
908 dptr
= (const u_char
*)op
+ length2
;
909 dataend
= (const u_char
*)op
+ length
;
911 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
912 dptr
= dptr
+ op
->ospf_authdata
[3];
913 length2
+= op
->ospf_authdata
[3];
915 if (length2
>= length
) {
916 ND_PRINT((ndo
, "\n\t[LLS truncated]"));
919 ND_TCHECK2(*dptr
, 2);
920 ND_PRINT((ndo
, "\n\t LLS: checksum: 0x%04x", (u_int
)EXTRACT_16BITS(dptr
)));
923 ND_TCHECK2(*dptr
, 2);
924 length2
= EXTRACT_16BITS(dptr
);
925 ND_PRINT((ndo
, ", length: %u", length2
));
929 while (dptr
< dataend
) {
930 ND_TCHECK2(*dptr
, 2);
931 lls_type
= EXTRACT_16BITS(dptr
);
932 ND_PRINT((ndo
, "\n\t %s (%u)",
933 tok2str(ospf_lls_tlv_values
,"Unknown TLV",lls_type
),
936 ND_TCHECK2(*dptr
, 2);
937 lls_len
= EXTRACT_16BITS(dptr
);
938 ND_PRINT((ndo
, ", length: %u", lls_len
));
944 ND_PRINT((ndo
, " [should be 4]"));
947 ND_TCHECK2(*dptr
, 4);
948 lls_flags
= EXTRACT_32BITS(dptr
);
949 ND_PRINT((ndo
, "\n\t Options: 0x%08x [%s]", lls_flags
,
950 bittok2str(ospf_lls_eo_options
, "?", lls_flags
)));
956 ND_PRINT((ndo
, " [should be 20]"));
959 ND_TCHECK2(*dptr
, 4);
960 ND_PRINT((ndo
, "\n\t Sequence number: 0x%08x", EXTRACT_32BITS(dptr
)));
973 ospf_decode_v2(netdissect_options
*ndo
,
974 register const struct ospfhdr
*op
, register const u_char
*dataend
)
976 register const struct in_addr
*ap
;
977 register const struct lsr
*lsrp
;
978 register const struct lsa_hdr
*lshp
;
979 register const struct lsa
*lsap
;
980 register uint32_t lsa_count
,lsa_count_max
;
982 switch (op
->ospf_type
) {
986 * Rob Coltun's special monitoring packets;
991 case OSPF_TYPE_HELLO
:
992 ND_PRINT((ndo
, "\n\tOptions [%s]",
993 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
)));
995 ND_TCHECK(op
->ospf_hello
.hello_deadint
);
996 ND_PRINT((ndo
, "\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
997 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
998 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
999 ipaddr_string(ndo
, &op
->ospf_hello
.hello_mask
),
1000 op
->ospf_hello
.hello_priority
));
1002 ND_TCHECK(op
->ospf_hello
.hello_dr
);
1003 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
1004 ND_PRINT((ndo
, "\n\t Designated Router %s",
1005 ipaddr_string(ndo
, &op
->ospf_hello
.hello_dr
)));
1007 ND_TCHECK(op
->ospf_hello
.hello_bdr
);
1008 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
1009 ND_PRINT((ndo
, ", Backup Designated Router %s",
1010 ipaddr_string(ndo
, &op
->ospf_hello
.hello_bdr
)));
1012 ap
= op
->ospf_hello
.hello_neighbor
;
1013 if ((const u_char
*)ap
< dataend
)
1014 ND_PRINT((ndo
, "\n\t Neighbor List:"));
1015 while ((const u_char
*)ap
< dataend
) {
1017 ND_PRINT((ndo
, "\n\t %s", ipaddr_string(ndo
, ap
)));
1023 ND_TCHECK(op
->ospf_db
.db_options
);
1024 ND_PRINT((ndo
, "\n\tOptions [%s]",
1025 bittok2str(ospf_option_values
, "none", op
->ospf_db
.db_options
)));
1026 ND_TCHECK(op
->ospf_db
.db_flags
);
1027 ND_PRINT((ndo
, ", DD Flags [%s]",
1028 bittok2str(ospf_dd_flag_values
, "none", op
->ospf_db
.db_flags
)));
1029 ND_TCHECK(op
->ospf_db
.db_ifmtu
);
1030 if (op
->ospf_db
.db_ifmtu
) {
1031 ND_PRINT((ndo
, ", MTU: %u", EXTRACT_16BITS(&op
->ospf_db
.db_ifmtu
)));
1033 ND_TCHECK(op
->ospf_db
.db_seq
);
1034 ND_PRINT((ndo
, ", Sequence: 0x%08x", EXTRACT_32BITS(&op
->ospf_db
.db_seq
)));
1036 /* Print all the LS adv's */
1037 lshp
= op
->ospf_db
.db_lshdr
;
1038 while (((const u_char
*)lshp
< dataend
) && ospf_print_lshdr(ndo
, lshp
) != -1) {
1043 case OSPF_TYPE_LS_REQ
:
1044 lsrp
= op
->ospf_lsr
;
1045 while ((const u_char
*)lsrp
< dataend
) {
1048 ND_PRINT((ndo
, "\n\t Advertising Router: %s, %s LSA (%u)",
1049 ipaddr_string(ndo
, &lsrp
->ls_router
),
1050 tok2str(lsa_values
,"unknown",EXTRACT_32BITS(lsrp
->ls_type
)),
1051 EXTRACT_32BITS(&lsrp
->ls_type
)));
1053 switch (EXTRACT_32BITS(lsrp
->ls_type
)) {
1054 /* the LSA header for opaque LSAs was slightly changed */
1055 case LS_TYPE_OPAQUE_LL
:
1056 case LS_TYPE_OPAQUE_AL
:
1057 case LS_TYPE_OPAQUE_DW
:
1058 ND_PRINT((ndo
, ", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1059 tok2str(lsa_opaque_values
, "unknown",lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
1060 lsrp
->un_ls_stateid
.opaque_field
.opaque_type
,
1061 EXTRACT_24BITS(&lsrp
->un_ls_stateid
.opaque_field
.opaque_id
)));
1064 ND_PRINT((ndo
, ", LSA-ID: %s",
1065 ipaddr_string(ndo
, &lsrp
->un_ls_stateid
.ls_stateid
)));
1073 case OSPF_TYPE_LS_UPDATE
:
1074 lsap
= op
->ospf_lsu
.lsu_lsa
;
1075 ND_TCHECK(op
->ospf_lsu
.lsu_count
);
1076 lsa_count_max
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
1077 ND_PRINT((ndo
, ", %d LSA%s", lsa_count_max
, PLURAL_SUFFIX(lsa_count_max
)));
1078 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
1079 ND_PRINT((ndo
, "\n\t LSA #%u", lsa_count
));
1080 lsap
= (const struct lsa
*)ospf_print_lsa(ndo
, lsap
);
1086 case OSPF_TYPE_LS_ACK
:
1087 lshp
= op
->ospf_lsa
.lsa_lshdr
;
1088 while (ospf_print_lshdr(ndo
, lshp
) != -1) {
1102 ospf_print(netdissect_options
*ndo
,
1103 register const u_char
*bp
, register u_int length
,
1104 const u_char
*bp2 _U_
)
1106 register const struct ospfhdr
*op
;
1107 register const u_char
*dataend
;
1108 register const char *cp
;
1110 op
= (const struct ospfhdr
*)bp
;
1112 /* XXX Before we do anything else, strip off the MD5 trailer */
1113 ND_TCHECK(op
->ospf_authtype
);
1114 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
1115 length
-= OSPF_AUTH_MD5_LEN
;
1116 ndo
->ndo_snapend
-= OSPF_AUTH_MD5_LEN
;
1119 /* If the type is valid translate it, or just print the type */
1120 /* value. If it's not valid, say so and return */
1121 ND_TCHECK(op
->ospf_type
);
1122 cp
= tok2str(type2str
, "unknown LS-type", op
->ospf_type
);
1123 ND_PRINT((ndo
, "OSPFv%u, %s, length %u", op
->ospf_version
, cp
, length
));
1127 if (!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1131 ND_TCHECK(op
->ospf_len
);
1132 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
1133 ND_PRINT((ndo
, " [len %d]", EXTRACT_16BITS(&op
->ospf_len
)));
1136 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1137 dataend
= bp
+ EXTRACT_16BITS(&op
->ospf_len
);
1139 dataend
= bp
+ length
;
1142 ND_TCHECK(op
->ospf_routerid
);
1143 ND_PRINT((ndo
, "\n\tRouter-ID %s", ipaddr_string(ndo
, &op
->ospf_routerid
)));
1145 ND_TCHECK(op
->ospf_areaid
);
1146 if (op
->ospf_areaid
.s_addr
!= 0)
1147 ND_PRINT((ndo
, ", Area %s", ipaddr_string(ndo
, &op
->ospf_areaid
)));
1149 ND_PRINT((ndo
, ", Backbone Area"));
1151 if (ndo
->ndo_vflag
) {
1152 /* Print authentication data (should we really do this?) */
1153 ND_TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
1155 ND_PRINT((ndo
, ", Authentication Type: %s (%u)",
1156 tok2str(ospf_authtype_values
, "unknown", EXTRACT_16BITS(&op
->ospf_authtype
)),
1157 EXTRACT_16BITS(&op
->ospf_authtype
)));
1159 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
1161 case OSPF_AUTH_NONE
:
1164 case OSPF_AUTH_SIMPLE
:
1165 ND_PRINT((ndo
, "\n\tSimple text password: "));
1166 safeputs(ndo
, op
->ospf_authdata
, OSPF_AUTH_SIMPLE_LEN
);
1170 ND_PRINT((ndo
, "\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1171 *((op
->ospf_authdata
) + 2),
1172 *((op
->ospf_authdata
) + 3),
1173 EXTRACT_32BITS((op
->ospf_authdata
) + 4)));
1180 /* Do rest according to version. */
1181 switch (op
->ospf_version
) {
1184 /* ospf version 2 */
1185 if (ospf_decode_v2(ndo
, op
, dataend
))
1187 if (length
> EXTRACT_16BITS(&op
->ospf_len
)) {
1188 if (ospf_decode_lls(ndo
, op
, length
))
1194 ND_PRINT((ndo
, " ospf [version %d]", op
->ospf_version
));
1196 } /* end switch on version */
1200 ND_PRINT((ndo
, "%s", tstr
));