2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
24 /* \summary: Open Shortest Path First (OSPF) printer */
30 #include <netdissect-stdinc.h>
32 #include "netdissect.h"
33 #include "addrtoname.h"
39 static const char tstr[] = " [|ospf2]";
41 static const struct tok ospf_option_values[] = {
42 { OSPF_OPTION_T, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
43 { OSPF_OPTION_E, "External" },
44 { OSPF_OPTION_MC, "Multicast" },
45 { OSPF_OPTION_NP, "NSSA" },
46 { OSPF_OPTION_L, "LLS" },
47 { OSPF_OPTION_DC, "Demand Circuit" },
48 { OSPF_OPTION_O, "Opaque" },
49 { OSPF_OPTION_DN, "Up/Down" },
53 static const struct tok ospf_authtype_values[] = {
54 { OSPF_AUTH_NONE, "none" },
55 { OSPF_AUTH_SIMPLE, "simple" },
56 { OSPF_AUTH_MD5, "MD5" },
60 static const struct tok ospf_rla_flag_values[] = {
61 { RLA_FLAG_B, "ABR" },
62 { RLA_FLAG_E, "ASBR" },
63 { RLA_FLAG_W1, "Virtual" },
64 { RLA_FLAG_W2, "W2" },
68 static const struct tok type2str[] = {
69 { OSPF_TYPE_UMD, "UMD" },
70 { OSPF_TYPE_HELLO, "Hello" },
71 { OSPF_TYPE_DD, "Database Description" },
72 { OSPF_TYPE_LS_REQ, "LS-Request" },
73 { OSPF_TYPE_LS_UPDATE, "LS-Update" },
74 { OSPF_TYPE_LS_ACK, "LS-Ack" },
78 static const struct tok lsa_values[] = {
79 { LS_TYPE_ROUTER, "Router" },
80 { LS_TYPE_NETWORK, "Network" },
81 { LS_TYPE_SUM_IP, "Summary" },
82 { LS_TYPE_SUM_ABR, "ASBR Summary" },
83 { LS_TYPE_ASE, "External" },
84 { LS_TYPE_GROUP, "Multicast Group" },
85 { LS_TYPE_NSSA, "NSSA" },
86 { LS_TYPE_OPAQUE_LL, "Link Local Opaque" },
87 { LS_TYPE_OPAQUE_AL, "Area Local Opaque" },
88 { LS_TYPE_OPAQUE_DW, "Domain Wide Opaque" },
92 static const struct tok ospf_dd_flag_values[] = {
93 { OSPF_DB_INIT, "Init" },
94 { OSPF_DB_MORE, "More" },
95 { OSPF_DB_MASTER, "Master" },
96 { OSPF_DB_RESYNC, "OOBResync" },
100 static const struct tok lsa_opaque_values[] = {
101 { LS_OPAQUE_TYPE_TE, "Traffic Engineering" },
102 { LS_OPAQUE_TYPE_GRACE, "Graceful restart" },
103 { LS_OPAQUE_TYPE_RI, "Router Information" },
107 static const struct tok lsa_opaque_te_tlv_values[] = {
108 { LS_OPAQUE_TE_TLV_ROUTER, "Router Address" },
109 { LS_OPAQUE_TE_TLV_LINK, "Link" },
113 static const struct tok lsa_opaque_te_link_tlv_subtlv_values[] = {
114 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE, "Link Type" },
115 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID, "Link ID" },
116 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP, "Local Interface IP address" },
117 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP, "Remote Interface IP address" },
118 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC, "Traffic Engineering Metric" },
119 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW, "Maximum Bandwidth" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW, "Maximum Reservable Bandwidth" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW, "Unreserved Bandwidth" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP, "Administrative Group" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE, "Link Protection Type" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR, "Interface Switching Capability" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP, "Shared Risk Link Group" },
127 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS, "Bandwidth Constraints" },
131 static const struct tok lsa_opaque_grace_tlv_values[] = {
132 { LS_OPAQUE_GRACE_TLV_PERIOD, "Grace Period" },
133 { LS_OPAQUE_GRACE_TLV_REASON, "Graceful restart Reason" },
134 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS, "IPv4 interface address" },
138 static const struct tok lsa_opaque_grace_tlv_reason_values[] = {
139 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN, "Unknown" },
140 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART, "Software Restart" },
141 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE, "Software Reload/Upgrade" },
142 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH, "Control Processor Switch" },
146 static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = {
147 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP, "Point-to-point" },
148 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA, "Multi-Access" },
152 static const struct tok lsa_opaque_ri_tlv_values[] = {
153 { LS_OPAQUE_RI_TLV_CAP, "Router Capabilities" },
157 static const struct tok lsa_opaque_ri_tlv_cap_values[] = {
162 { 16, "graceful restart capable" },
163 { 32, "graceful restart helper" },
164 { 64, "Stub router support" },
165 { 128, "Traffic engineering" },
166 { 256, "p2p over LAN" },
167 { 512, "path computation server" },
171 static const struct tok ospf_lls_tlv_values[] = {
172 { OSPF_LLS_EO, "Extended Options" },
173 { OSPF_LLS_MD5, "MD5 Authentication" },
177 static const struct tok ospf_lls_eo_options[] = {
178 { OSPF_LLS_EO_LR, "LSDB resync" },
179 { OSPF_LLS_EO_RS, "Restart" },
184 ospf_print_grace_lsa(netdissect_options *ndo,
185 const uint8_t *tptr, u_int ls_length)
187 u_int tlv_type, tlv_length;
190 while (ls_length > 0) {
191 ND_TCHECK2(*tptr, 4);
193 ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
196 tlv_type = EXTRACT_16BITS(tptr);
197 tlv_length = EXTRACT_16BITS(tptr+2);
201 ND_PRINT((ndo, "\n\t %s TLV (%u), length %u, value: ",
202 tok2str(lsa_opaque_grace_tlv_values,"unknown",tlv_type),
206 if (tlv_length > ls_length) {
207 ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
212 /* Infinite loop protection. */
213 if (tlv_type == 0 || tlv_length ==0) {
217 ND_TCHECK2(*tptr, tlv_length);
220 case LS_OPAQUE_GRACE_TLV_PERIOD:
221 if (tlv_length != 4) {
222 ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
225 ND_PRINT((ndo, "%us", EXTRACT_32BITS(tptr)));
228 case LS_OPAQUE_GRACE_TLV_REASON:
229 if (tlv_length != 1) {
230 ND_PRINT((ndo, "\n\t Bogus length %u != 1", tlv_length));
233 ND_PRINT((ndo, "%s (%u)",
234 tok2str(lsa_opaque_grace_tlv_reason_values, "Unknown", *tptr),
238 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS:
239 if (tlv_length != 4) {
240 ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
243 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
247 if (ndo->ndo_vflag <= 1) {
248 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
254 /* in OSPF everything has to be 32-bit aligned, including TLVs */
255 if (tlv_length%4 != 0)
256 tlv_length+=4-(tlv_length%4);
257 ls_length-=tlv_length;
267 ospf_print_te_lsa(netdissect_options *ndo,
268 const uint8_t *tptr, u_int ls_length)
270 u_int tlv_type, tlv_length, subtlv_type, subtlv_length;
271 u_int priority_level, te_class, count_srlg;
272 union { /* int to float conversion buffer for several subTLVs */
277 while (ls_length != 0) {
278 ND_TCHECK2(*tptr, 4);
280 ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
283 tlv_type = EXTRACT_16BITS(tptr);
284 tlv_length = EXTRACT_16BITS(tptr+2);
288 ND_PRINT((ndo, "\n\t %s TLV (%u), length: %u",
289 tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type),
293 if (tlv_length > ls_length) {
294 ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
299 /* Infinite loop protection. */
300 if (tlv_type == 0 || tlv_length ==0) {
305 case LS_OPAQUE_TE_TLV_LINK:
306 while (tlv_length >= sizeof(subtlv_type) + sizeof(subtlv_length)) {
307 if (tlv_length < 4) {
308 ND_PRINT((ndo, "\n\t Remaining TLV length %u < 4",
312 ND_TCHECK2(*tptr, 4);
313 subtlv_type = EXTRACT_16BITS(tptr);
314 subtlv_length = EXTRACT_16BITS(tptr+2);
318 /* Infinite loop protection */
319 if (subtlv_type == 0 || subtlv_length == 0)
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 if (subtlv_length != 4) {
331 ND_PRINT((ndo, " != 4"));
334 ND_PRINT((ndo, ", 0x%08x", EXTRACT_32BITS(tptr)));
336 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID:
337 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID:
338 if (subtlv_length != 4 && subtlv_length != 8) {
339 ND_PRINT((ndo, " != 4 && != 8"));
342 ND_PRINT((ndo, ", %s (0x%08x)",
343 ipaddr_string(ndo, tptr),
344 EXTRACT_32BITS(tptr)));
345 if (subtlv_length == 8) /* rfc4203 */
346 ND_PRINT((ndo, ", %s (0x%08x)",
347 ipaddr_string(ndo, tptr+4),
348 EXTRACT_32BITS(tptr + 4)));
350 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP:
351 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP:
352 if (subtlv_length != 4) {
353 ND_PRINT((ndo, " != 4"));
356 ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr)));
358 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
359 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
360 if (subtlv_length != 4) {
361 ND_PRINT((ndo, " != 4"));
364 bw.i = EXTRACT_32BITS(tptr);
365 ND_PRINT((ndo, ", %.3f Mbps", bw.f * 8 / 1000000));
367 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW:
368 if (subtlv_length != 32) {
369 ND_PRINT((ndo, " != 32"));
372 for (te_class = 0; te_class < 8; te_class++) {
373 bw.i = EXTRACT_32BITS(tptr+te_class*4);
374 ND_PRINT((ndo, "\n\t\tTE-Class %u: %.3f Mbps",
376 bw.f * 8 / 1000000));
379 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS:
380 if (subtlv_length < 4) {
381 ND_PRINT((ndo, " < 4"));
384 /* BC Model Id (1 octet) + Reserved (3 octets) */
385 ND_PRINT((ndo, "\n\t\tBandwidth Constraints Model ID: %s (%u)",
386 tok2str(diffserv_te_bc_values, "unknown", *tptr),
388 if (subtlv_length % 4 != 0) {
389 ND_PRINT((ndo, "\n\t\tlength %u != N x 4", subtlv_length));
392 if (subtlv_length > 36) {
393 ND_PRINT((ndo, "\n\t\tlength %u > 36", subtlv_length));
396 /* decode BCs until the subTLV ends */
397 for (te_class = 0; te_class < (subtlv_length-4)/4; te_class++) {
398 bw.i = EXTRACT_32BITS(tptr+4+te_class*4);
399 ND_PRINT((ndo, "\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
401 bw.f * 8 / 1000000));
404 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC:
405 if (subtlv_length != 4) {
406 ND_PRINT((ndo, " != 4"));
409 ND_PRINT((ndo, ", Metric %u", EXTRACT_32BITS(tptr)));
411 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE:
412 /* Protection Cap (1 octet) + Reserved ((3 octets) */
413 if (subtlv_length != 4) {
414 ND_PRINT((ndo, " != 4"));
417 ND_PRINT((ndo, ", %s",
418 bittok2str(gmpls_link_prot_values, "none", *tptr)));
420 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
421 if (subtlv_length < 36) {
422 ND_PRINT((ndo, " < 36"));
425 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
426 ND_PRINT((ndo, "\n\t\tInterface Switching Capability: %s",
427 tok2str(gmpls_switch_cap_values, "Unknown", *(tptr))));
428 ND_PRINT((ndo, "\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
429 tok2str(gmpls_encoding_values, "Unknown", *(tptr + 1))));
430 for (priority_level = 0; priority_level < 8; priority_level++) {
431 bw.i = EXTRACT_32BITS(tptr+4+(priority_level*4));
432 ND_PRINT((ndo, "\n\t\t priority level %d: %.3f Mbps",
434 bw.f * 8 / 1000000));
437 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE:
438 if (subtlv_length != 1) {
439 ND_PRINT((ndo, " != 1"));
442 ND_PRINT((ndo, ", %s (%u)",
443 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",*tptr),
447 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
448 if (subtlv_length % 4 != 0) {
449 ND_PRINT((ndo, " != N x 4"));
452 count_srlg = subtlv_length / 4;
454 ND_PRINT((ndo, "\n\t\t Shared risk group: "));
455 while (count_srlg > 0) {
456 bw.i = EXTRACT_32BITS(tptr);
457 ND_PRINT((ndo, "%d", bw.i));
461 ND_PRINT((ndo, ", "));
466 if (ndo->ndo_vflag <= 1) {
467 if (!print_unknown_data(ndo, tptr, "\n\t\t", subtlv_length))
472 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
473 if (subtlv_length%4 != 0)
474 subtlv_length+=4-(subtlv_length%4);
476 tlv_length-=subtlv_length;
482 case LS_OPAQUE_TE_TLV_ROUTER:
483 if (tlv_length < 4) {
484 ND_PRINT((ndo, "\n\t TLV length %u < 4", tlv_length));
487 ND_TCHECK2(*tptr, 4);
488 ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr)));
492 if (ndo->ndo_vflag <= 1) {
493 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
498 /* in OSPF everything has to be 32-bit aligned, including TLVs */
499 if (tlv_length%4 != 0)
500 tlv_length+=4-(tlv_length%4);
501 ls_length-=tlv_length;
508 ND_PRINT((ndo, "%s", istr));
513 ospf_print_lshdr(netdissect_options *ndo,
514 register const struct lsa_hdr *lshp)
518 ND_TCHECK(lshp->ls_length);
519 ls_length = EXTRACT_16BITS(&lshp->ls_length);
520 if (ls_length < sizeof(struct lsa_hdr)) {
521 ND_PRINT((ndo, "\n\t Bogus length %u < header (%lu)", ls_length,
522 (unsigned long)sizeof(struct lsa_hdr)));
526 ND_TCHECK(lshp->ls_seq); /* XXX - ls_length check checked this */
527 ND_PRINT((ndo, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
528 ipaddr_string(ndo, &lshp->ls_router),
529 EXTRACT_32BITS(&lshp->ls_seq),
530 EXTRACT_16BITS(&lshp->ls_age),
531 ls_length - (u_int)sizeof(struct lsa_hdr)));
533 ND_TCHECK(lshp->ls_type); /* XXX - ls_length check checked this */
534 switch (lshp->ls_type) {
535 /* the LSA header for opaque LSAs was slightly changed */
536 case LS_TYPE_OPAQUE_LL:
537 case LS_TYPE_OPAQUE_AL:
538 case LS_TYPE_OPAQUE_DW:
539 ND_PRINT((ndo, "\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
540 tok2str(lsa_values,"unknown",lshp->ls_type),
543 tok2str(lsa_opaque_values,
545 *(&lshp->un_lsa_id.opaque_field.opaque_type)),
546 *(&lshp->un_lsa_id.opaque_field.opaque_type),
547 EXTRACT_24BITS(&lshp->un_lsa_id.opaque_field.opaque_id)
552 /* all other LSA types use regular style LSA headers */
554 ND_PRINT((ndo, "\n\t %s LSA (%d), LSA-ID: %s",
555 tok2str(lsa_values,"unknown",lshp->ls_type),
557 ipaddr_string(ndo, &lshp->un_lsa_id.lsa_id)));
561 ND_TCHECK(lshp->ls_options); /* XXX - ls_length check checked this */
562 ND_PRINT((ndo, "\n\t Options: [%s]", bittok2str(ospf_option_values, "none", lshp->ls_options)));
569 /* draft-ietf-ospf-mt-09 */
570 static const struct tok ospf_topology_values[] = {
578 * Print all the per-topology metrics.
581 ospf_print_tos_metrics(netdissect_options *ndo,
582 const union un_tos *tos)
587 toscount = tos->link.link_tos_count+1;
591 * All but the first metric contain a valid topology id.
593 while (toscount > 0) {
595 ND_PRINT((ndo, "\n\t\ttopology %s (%u), metric %u",
596 tok2str(ospf_topology_values, "Unknown",
597 metric_count ? tos->metrics.tos_type : 0),
598 metric_count ? tos->metrics.tos_type : 0,
599 EXTRACT_16BITS(&tos->metrics.tos_metric)));
610 * Print a single link state advertisement. If truncated or if LSA length
611 * field is less than the length of the LSA header, return NULl, else
612 * return pointer to data past end of LSA.
614 static const uint8_t *
615 ospf_print_lsa(netdissect_options *ndo,
616 register const struct lsa *lsap)
618 register const uint8_t *ls_end;
619 register const struct rlalink *rlp;
620 register const struct in_addr *ap;
621 register const struct aslametric *almp;
622 register const struct mcla *mcp;
623 register const uint32_t *lp;
624 register int j, tlv_type, tlv_length, topology;
625 register int ls_length;
628 tptr = (const uint8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
629 ls_length = ospf_print_lshdr(ndo, &lsap->ls_hdr);
632 ls_end = (const uint8_t *)lsap + ls_length;
633 ls_length -= sizeof(struct lsa_hdr);
635 switch (lsap->ls_hdr.ls_type) {
638 ND_TCHECK(lsap->lsa_un.un_rla.rla_flags);
639 ND_PRINT((ndo, "\n\t Router LSA Options: [%s]",
640 bittok2str(ospf_rla_flag_values, "none", lsap->lsa_un.un_rla.rla_flags)));
642 ND_TCHECK(lsap->lsa_un.un_rla.rla_count);
643 j = EXTRACT_16BITS(&lsap->lsa_un.un_rla.rla_count);
644 ND_TCHECK(lsap->lsa_un.un_rla.rla_link);
645 rlp = lsap->lsa_un.un_rla.rla_link;
648 switch (rlp->un_tos.link.link_type) {
650 case RLA_TYPE_VIRTUAL:
651 ND_PRINT((ndo, "\n\t Virtual Link: 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_ROUTER:
657 ND_PRINT((ndo, "\n\t Neighbor Router-ID: %s, Interface Address: %s",
658 ipaddr_string(ndo, &rlp->link_id),
659 ipaddr_string(ndo, &rlp->link_data)));
662 case RLA_TYPE_TRANSIT:
663 ND_PRINT((ndo, "\n\t Neighbor Network-ID: %s, Interface Address: %s",
664 ipaddr_string(ndo, &rlp->link_id),
665 ipaddr_string(ndo, &rlp->link_data)));
669 ND_PRINT((ndo, "\n\t Stub Network: %s, Mask: %s",
670 ipaddr_string(ndo, &rlp->link_id),
671 ipaddr_string(ndo, &rlp->link_data)));
675 ND_PRINT((ndo, "\n\t Unknown Router Link Type (%u)",
676 rlp->un_tos.link.link_type));
680 if (ospf_print_tos_metrics(ndo, &rlp->un_tos))
683 rlp = (const struct rlalink *)((const u_char *)(rlp + 1) +
684 ((rlp->un_tos.link.link_tos_count) * sizeof(union un_tos)));
688 case LS_TYPE_NETWORK:
689 ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
690 ND_PRINT((ndo, "\n\t Mask %s\n\t Connected Routers:",
691 ipaddr_string(ndo, &lsap->lsa_un.un_nla.nla_mask)));
692 ap = lsap->lsa_un.un_nla.nla_router;
693 while ((const u_char *)ap < ls_end) {
695 ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
701 ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
702 ND_PRINT((ndo, "\n\t Mask %s",
703 ipaddr_string(ndo, &lsap->lsa_un.un_sla.sla_mask)));
704 ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
705 lp = lsap->lsa_un.un_sla.sla_tosmetric;
706 while ((const u_char *)lp < ls_end) {
707 register uint32_t ul;
709 ND_TCHECK_32BITS(lp);
710 ul = EXTRACT_32BITS(lp);
711 topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
712 ND_PRINT((ndo, "\n\t\ttopology %s (%u) metric %d",
713 tok2str(ospf_topology_values, "Unknown", topology),
715 ul & SLA_MASK_METRIC));
720 case LS_TYPE_SUM_ABR:
721 ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
722 lp = lsap->lsa_un.un_sla.sla_tosmetric;
723 while ((const u_char *)lp < ls_end) {
724 register uint32_t ul;
726 ND_TCHECK_32BITS(lp);
727 ul = EXTRACT_32BITS(lp);
728 topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
729 ND_PRINT((ndo, "\n\t\ttopology %s (%u) metric %d",
730 tok2str(ospf_topology_values, "Unknown", topology),
732 ul & SLA_MASK_METRIC));
738 case LS_TYPE_NSSA: /* fall through - those LSAs share the same format */
739 ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
740 ND_PRINT((ndo, "\n\t Mask %s",
741 ipaddr_string(ndo, &lsap->lsa_un.un_asla.asla_mask)));
743 ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
744 almp = lsap->lsa_un.un_asla.asla_metric;
745 while ((const u_char *)almp < ls_end) {
746 register uint32_t ul;
748 ND_TCHECK(almp->asla_tosmetric);
749 ul = EXTRACT_32BITS(&almp->asla_tosmetric);
750 topology = ((ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
751 ND_PRINT((ndo, "\n\t\ttopology %s (%u), type %d, metric",
752 tok2str(ospf_topology_values, "Unknown", topology),
754 (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1));
755 if ((ul & ASLA_MASK_METRIC) == 0xffffff)
756 ND_PRINT((ndo, " infinite"));
758 ND_PRINT((ndo, " %d", (ul & ASLA_MASK_METRIC)));
760 ND_TCHECK(almp->asla_forward);
761 if (almp->asla_forward.s_addr) {
762 ND_PRINT((ndo, ", forward %s", ipaddr_string(ndo, &almp->asla_forward)));
764 ND_TCHECK(almp->asla_tag);
765 if (almp->asla_tag.s_addr) {
766 ND_PRINT((ndo, ", tag %s", ipaddr_string(ndo, &almp->asla_tag)));
773 /* Multicast extensions as of 23 July 1991 */
774 mcp = lsap->lsa_un.un_mcla;
775 while ((const u_char *)mcp < ls_end) {
776 ND_TCHECK(mcp->mcla_vid);
777 switch (EXTRACT_32BITS(&mcp->mcla_vtype)) {
779 case MCLA_VERTEX_ROUTER:
780 ND_PRINT((ndo, "\n\t Router Router-ID %s",
781 ipaddr_string(ndo, &mcp->mcla_vid)));
784 case MCLA_VERTEX_NETWORK:
785 ND_PRINT((ndo, "\n\t Network Designated Router %s",
786 ipaddr_string(ndo, &mcp->mcla_vid)));
790 ND_PRINT((ndo, "\n\t unknown VertexType (%u)",
791 EXTRACT_32BITS(&mcp->mcla_vtype)));
798 case LS_TYPE_OPAQUE_LL: /* fall through */
799 case LS_TYPE_OPAQUE_AL:
800 case LS_TYPE_OPAQUE_DW:
802 switch (*(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
803 case LS_OPAQUE_TYPE_RI:
804 tptr = (const uint8_t *)(&lsap->lsa_un.un_ri_tlv.type);
806 while (ls_length != 0) {
807 ND_TCHECK2(*tptr, 4);
809 ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
812 tlv_type = EXTRACT_16BITS(tptr);
813 tlv_length = EXTRACT_16BITS(tptr+2);
817 ND_PRINT((ndo, "\n\t %s TLV (%u), length: %u, value: ",
818 tok2str(lsa_opaque_ri_tlv_values,"unknown",tlv_type),
822 if (tlv_length > ls_length) {
823 ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
827 ND_TCHECK2(*tptr, tlv_length);
830 case LS_OPAQUE_RI_TLV_CAP:
831 if (tlv_length != 4) {
832 ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
835 ND_PRINT((ndo, "Capabilities: %s",
836 bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", EXTRACT_32BITS(tptr))));
839 if (ndo->ndo_vflag <= 1) {
840 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
847 ls_length-=tlv_length;
851 case LS_OPAQUE_TYPE_GRACE:
852 if (ospf_print_grace_lsa(ndo, (const uint8_t *)(&lsap->lsa_un.un_grace_tlv.type),
858 case LS_OPAQUE_TYPE_TE:
859 if (ospf_print_te_lsa(ndo, (const uint8_t *)(&lsap->lsa_un.un_te_lsa_tlv.type),
866 if (ndo->ndo_vflag <= 1) {
867 if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
875 /* do we want to see an additionally hexdump ? */
876 if (ndo->ndo_vflag> 1)
877 if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
878 "\n\t ", ls_length)) {
888 ospf_decode_lls(netdissect_options *ndo,
889 register const struct ospfhdr *op, register u_int length)
891 register const u_char *dptr;
892 register const u_char *dataend;
893 register u_int length2;
894 register uint16_t lls_type, lls_len;
895 register uint32_t lls_flags;
897 switch (op->ospf_type) {
899 case OSPF_TYPE_HELLO:
900 if (!(op->ospf_hello.hello_options & OSPF_OPTION_L))
905 if (!(op->ospf_db.db_options & OSPF_OPTION_L))
913 /* dig deeper if LLS data is available; see RFC4813 */
914 length2 = EXTRACT_16BITS(&op->ospf_len);
915 dptr = (const u_char *)op + length2;
916 dataend = (const u_char *)op + length;
918 if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
919 dptr = dptr + op->ospf_authdata[3];
920 length2 += op->ospf_authdata[3];
922 if (length2 >= length) {
923 ND_PRINT((ndo, "\n\t[LLS truncated]"));
926 ND_TCHECK2(*dptr, 2);
927 ND_PRINT((ndo, "\n\t LLS: checksum: 0x%04x", (u_int)EXTRACT_16BITS(dptr)));
930 ND_TCHECK2(*dptr, 2);
931 length2 = EXTRACT_16BITS(dptr);
932 ND_PRINT((ndo, ", length: %u", length2));
936 while (dptr < dataend) {
937 ND_TCHECK2(*dptr, 2);
938 lls_type = EXTRACT_16BITS(dptr);
939 ND_PRINT((ndo, "\n\t %s (%u)",
940 tok2str(ospf_lls_tlv_values,"Unknown TLV",lls_type),
943 ND_TCHECK2(*dptr, 2);
944 lls_len = EXTRACT_16BITS(dptr);
945 ND_PRINT((ndo, ", length: %u", lls_len));
951 ND_PRINT((ndo, " [should be 4]"));
954 ND_TCHECK2(*dptr, 4);
955 lls_flags = EXTRACT_32BITS(dptr);
956 ND_PRINT((ndo, "\n\t Options: 0x%08x [%s]", lls_flags,
957 bittok2str(ospf_lls_eo_options, "?", lls_flags)));
963 ND_PRINT((ndo, " [should be 20]"));
966 ND_TCHECK2(*dptr, 4);
967 ND_PRINT((ndo, "\n\t Sequence number: 0x%08x", EXTRACT_32BITS(dptr)));
980 ospf_decode_v2(netdissect_options *ndo,
981 register const struct ospfhdr *op, register const u_char *dataend)
983 register const struct in_addr *ap;
984 register const struct lsr *lsrp;
985 register const struct lsa_hdr *lshp;
986 register const struct lsa *lsap;
987 register uint32_t lsa_count,lsa_count_max;
989 switch (op->ospf_type) {
993 * Rob Coltun's special monitoring packets;
998 case OSPF_TYPE_HELLO:
999 ND_TCHECK(op->ospf_hello.hello_options);
1000 ND_PRINT((ndo, "\n\tOptions [%s]",
1001 bittok2str(ospf_option_values,"none",op->ospf_hello.hello_options)));
1003 ND_TCHECK(op->ospf_hello.hello_deadint);
1004 ND_PRINT((ndo, "\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
1005 EXTRACT_16BITS(&op->ospf_hello.hello_helloint),
1006 EXTRACT_32BITS(&op->ospf_hello.hello_deadint),
1007 ipaddr_string(ndo, &op->ospf_hello.hello_mask),
1008 op->ospf_hello.hello_priority));
1010 ND_TCHECK(op->ospf_hello.hello_dr);
1011 if (op->ospf_hello.hello_dr.s_addr != 0)
1012 ND_PRINT((ndo, "\n\t Designated Router %s",
1013 ipaddr_string(ndo, &op->ospf_hello.hello_dr)));
1015 ND_TCHECK(op->ospf_hello.hello_bdr);
1016 if (op->ospf_hello.hello_bdr.s_addr != 0)
1017 ND_PRINT((ndo, ", Backup Designated Router %s",
1018 ipaddr_string(ndo, &op->ospf_hello.hello_bdr)));
1020 ap = op->ospf_hello.hello_neighbor;
1021 if ((const u_char *)ap < dataend)
1022 ND_PRINT((ndo, "\n\t Neighbor List:"));
1023 while ((const u_char *)ap < dataend) {
1025 ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
1031 ND_TCHECK(op->ospf_db.db_options);
1032 ND_PRINT((ndo, "\n\tOptions [%s]",
1033 bittok2str(ospf_option_values, "none", op->ospf_db.db_options)));
1034 ND_TCHECK(op->ospf_db.db_flags);
1035 ND_PRINT((ndo, ", DD Flags [%s]",
1036 bittok2str(ospf_dd_flag_values, "none", op->ospf_db.db_flags)));
1037 ND_TCHECK(op->ospf_db.db_ifmtu);
1038 if (op->ospf_db.db_ifmtu) {
1039 ND_PRINT((ndo, ", MTU: %u", EXTRACT_16BITS(&op->ospf_db.db_ifmtu)));
1041 ND_TCHECK(op->ospf_db.db_seq);
1042 ND_PRINT((ndo, ", Sequence: 0x%08x", EXTRACT_32BITS(&op->ospf_db.db_seq)));
1044 /* Print all the LS adv's */
1045 lshp = op->ospf_db.db_lshdr;
1046 while (((const u_char *)lshp < dataend) && ospf_print_lshdr(ndo, lshp) != -1) {
1051 case OSPF_TYPE_LS_REQ:
1052 lsrp = op->ospf_lsr;
1053 while ((const u_char *)lsrp < dataend) {
1056 ND_PRINT((ndo, "\n\t Advertising Router: %s, %s LSA (%u)",
1057 ipaddr_string(ndo, &lsrp->ls_router),
1058 tok2str(lsa_values,"unknown",EXTRACT_32BITS(lsrp->ls_type)),
1059 EXTRACT_32BITS(&lsrp->ls_type)));
1061 switch (EXTRACT_32BITS(lsrp->ls_type)) {
1062 /* the LSA header for opaque LSAs was slightly changed */
1063 case LS_TYPE_OPAQUE_LL:
1064 case LS_TYPE_OPAQUE_AL:
1065 case LS_TYPE_OPAQUE_DW:
1066 ND_PRINT((ndo, ", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1067 tok2str(lsa_opaque_values, "unknown",lsrp->un_ls_stateid.opaque_field.opaque_type),
1068 lsrp->un_ls_stateid.opaque_field.opaque_type,
1069 EXTRACT_24BITS(&lsrp->un_ls_stateid.opaque_field.opaque_id)));
1072 ND_PRINT((ndo, ", LSA-ID: %s",
1073 ipaddr_string(ndo, &lsrp->un_ls_stateid.ls_stateid)));
1081 case OSPF_TYPE_LS_UPDATE:
1082 lsap = op->ospf_lsu.lsu_lsa;
1083 ND_TCHECK(op->ospf_lsu.lsu_count);
1084 lsa_count_max = EXTRACT_32BITS(&op->ospf_lsu.lsu_count);
1085 ND_PRINT((ndo, ", %d LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max)));
1086 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
1087 ND_PRINT((ndo, "\n\t LSA #%u", lsa_count));
1088 lsap = (const struct lsa *)ospf_print_lsa(ndo, lsap);
1094 case OSPF_TYPE_LS_ACK:
1095 lshp = op->ospf_lsa.lsa_lshdr;
1096 while (ospf_print_lshdr(ndo, lshp) != -1) {
1110 ospf_print(netdissect_options *ndo,
1111 register const u_char *bp, register u_int length,
1112 const u_char *bp2 _U_)
1114 register const struct ospfhdr *op;
1115 register const u_char *dataend;
1116 register const char *cp;
1118 op = (const struct ospfhdr *)bp;
1120 /* XXX Before we do anything else, strip off the MD5 trailer */
1121 ND_TCHECK(op->ospf_authtype);
1122 if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
1123 length -= OSPF_AUTH_MD5_LEN;
1124 ndo->ndo_snapend -= OSPF_AUTH_MD5_LEN;
1127 /* If the type is valid translate it, or just print the type */
1128 /* value. If it's not valid, say so and return */
1129 ND_TCHECK(op->ospf_type);
1130 cp = tok2str(type2str, "unknown LS-type", op->ospf_type);
1131 ND_PRINT((ndo, "OSPFv%u, %s, length %u", op->ospf_version, cp, length));
1135 if (!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
1139 ND_TCHECK(op->ospf_len);
1140 if (length != EXTRACT_16BITS(&op->ospf_len)) {
1141 ND_PRINT((ndo, " [len %d]", EXTRACT_16BITS(&op->ospf_len)));
1144 if (length > EXTRACT_16BITS(&op->ospf_len)) {
1145 dataend = bp + EXTRACT_16BITS(&op->ospf_len);
1147 dataend = bp + length;
1150 ND_TCHECK(op->ospf_routerid);
1151 ND_PRINT((ndo, "\n\tRouter-ID %s", ipaddr_string(ndo, &op->ospf_routerid)));
1153 ND_TCHECK(op->ospf_areaid);
1154 if (op->ospf_areaid.s_addr != 0)
1155 ND_PRINT((ndo, ", Area %s", ipaddr_string(ndo, &op->ospf_areaid)));
1157 ND_PRINT((ndo, ", Backbone Area"));
1159 if (ndo->ndo_vflag) {
1160 /* Print authentication data (should we really do this?) */
1161 ND_TCHECK2(op->ospf_authdata[0], sizeof(op->ospf_authdata));
1163 ND_PRINT((ndo, ", Authentication Type: %s (%u)",
1164 tok2str(ospf_authtype_values, "unknown", EXTRACT_16BITS(&op->ospf_authtype)),
1165 EXTRACT_16BITS(&op->ospf_authtype)));
1167 switch (EXTRACT_16BITS(&op->ospf_authtype)) {
1169 case OSPF_AUTH_NONE:
1172 case OSPF_AUTH_SIMPLE:
1173 ND_PRINT((ndo, "\n\tSimple text password: "));
1174 safeputs(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN);
1178 ND_PRINT((ndo, "\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1179 *((op->ospf_authdata) + 2),
1180 *((op->ospf_authdata) + 3),
1181 EXTRACT_32BITS((op->ospf_authdata) + 4)));
1188 /* Do rest according to version. */
1189 switch (op->ospf_version) {
1192 /* ospf version 2 */
1193 if (ospf_decode_v2(ndo, op, dataend))
1195 if (length > EXTRACT_16BITS(&op->ospf_len)) {
1196 if (ospf_decode_lls(ndo, op, length))
1202 ND_PRINT((ndo, " ospf [version %d]", op->ospf_version));
1204 } /* end switch on version */
1208 ND_PRINT((ndo, "%s", tstr));