1 /*
2  * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3  *        The Regents of the University of California.  All rights reserved.
4  *
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
16  * written permission.
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.
20  *
21  * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
22  */
23 
24 #include <sys/cdefs.h>
25 #ifndef lint
26 __RCSID("$NetBSD: print-ospf.c,v 1.11 2024/09/02 16:15:32 christos Exp $");
27 #endif
28 
29 /* \summary: Open Shortest Path First (OSPF) printer */
30 
31 #include <config.h>
32 
33 #include "netdissect-stdinc.h"
34 
35 #include "netdissect.h"
36 #include "addrtoname.h"
37 #include "extract.h"
38 #include "gmpls.h"
39 
40 #include "ospf.h"
41 
42 
43 static const struct tok ospf_option_values[] = {
44           { OSPF_OPTION_MT,   "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
45           { OSPF_OPTION_E,    "External" },
46           { OSPF_OPTION_MC,   "Multicast" },
47           { OSPF_OPTION_NP,   "NSSA" },
48           { OSPF_OPTION_L,    "LLS" },
49           { OSPF_OPTION_DC,   "Demand Circuit" },
50           { OSPF_OPTION_O,    "Opaque" },
51           { OSPF_OPTION_DN,   "Up/Down" },
52           { 0,                          NULL }
53 };
54 
55 static const struct tok ospf_authtype_values[] = {
56           { OSPF_AUTH_NONE,   "none" },
57           { OSPF_AUTH_SIMPLE, "simple" },
58           { OSPF_AUTH_MD5,    "MD5" },
59           { 0,                          NULL }
60 };
61 
62 static const struct tok ospf_rla_flag_values[] = {
63           { RLA_FLAG_B,                 "ABR" },
64           { RLA_FLAG_E,                 "ASBR" },
65           { RLA_FLAG_V,                 "Virtual" },
66           { RLA_FLAG_W,                 "Wildcard" },
67           { RLA_FLAG_NT,                "Nt" },
68           { RLA_FLAG_H,                 "Host" },
69           { 0,                          NULL }
70 };
71 
72 static const struct tok type2str[] = {
73           { OSPF_TYPE_HELLO,  "Hello" },
74           { OSPF_TYPE_DD,               "Database Description" },
75           { OSPF_TYPE_LS_REQ, "LS-Request" },
76           { OSPF_TYPE_LS_UPDATE,        "LS-Update" },
77           { OSPF_TYPE_LS_ACK, "LS-Ack" },
78           { 0,                          NULL }
79 };
80 
81 static const struct tok lsa_values[] = {
82           { LS_TYPE_ROUTER,       "Router" },
83           { LS_TYPE_NETWORK,      "Network" },
84           { LS_TYPE_SUM_IP,       "Summary" },
85           { LS_TYPE_SUM_ABR,      "ASBR Summary" },
86           { LS_TYPE_ASE,          "External" },
87           { LS_TYPE_GROUP,        "Multicast Group" },
88           { LS_TYPE_NSSA,         "NSSA" },
89           { LS_TYPE_OPAQUE_LL,    "Link Local Opaque" },
90           { LS_TYPE_OPAQUE_AL,    "Area Local Opaque" },
91           { LS_TYPE_OPAQUE_DW,    "Domain Wide Opaque" },
92           { 0,                          NULL }
93 };
94 
95 static const struct tok ospf_dd_flag_values[] = {
96           { OSPF_DB_INIT,             "Init" },
97           { OSPF_DB_MORE,             "More" },
98           { OSPF_DB_MASTER,   "Master" },
99     { OSPF_DB_RESYNC,         "OOBResync" },
100           { 0,                          NULL }
101 };
102 
103 static const struct tok lsa_opaque_values[] = {
104           { LS_OPAQUE_TYPE_TE,    "Traffic Engineering" },
105           { LS_OPAQUE_TYPE_GRACE, "Graceful restart" },
106           { LS_OPAQUE_TYPE_RI,    "Router Information" },
107           { 0,                          NULL }
108 };
109 
110 static const struct tok lsa_opaque_te_tlv_values[] = {
111           { LS_OPAQUE_TE_TLV_ROUTER, "Router Address" },
112           { LS_OPAQUE_TE_TLV_LINK,   "Link" },
113           { 0,                          NULL }
114 };
115 
116 static const struct tok lsa_opaque_te_link_tlv_subtlv_values[] = {
117           { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE,            "Link Type" },
118           { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID,              "Link ID" },
119           { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP,             "Local Interface IP address" },
120           { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP,            "Remote Interface IP address" },
121           { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC,            "Traffic Engineering Metric" },
122           { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW,               "Maximum Bandwidth" },
123           { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW,           "Maximum Reservable Bandwidth" },
124           { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW,             "Unreserved Bandwidth" },
125           { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP,          "Administrative Group" },
126           { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
127           { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE, "Link Protection Type" },
128           { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR,    "Interface Switching Capability" },
129           { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP,    "Shared Risk Link Group" },
130           { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS,       "Bandwidth Constraints" },
131           { 0,                          NULL }
132 };
133 
134 static const struct tok lsa_opaque_grace_tlv_values[] = {
135           { LS_OPAQUE_GRACE_TLV_PERIOD,             "Grace Period" },
136           { LS_OPAQUE_GRACE_TLV_REASON,             "Graceful restart Reason" },
137           { LS_OPAQUE_GRACE_TLV_INT_ADDRESS,        "IPv4 interface address" },
138           { 0,                        NULL }
139 };
140 
141 static const struct tok lsa_opaque_grace_tlv_reason_values[] = {
142           { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN,     "Unknown" },
143           { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART,  "Software Restart" },
144           { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE,  "Software Reload/Upgrade" },
145           { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH,   "Control Processor Switch" },
146           { 0,                        NULL }
147 };
148 
149 static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = {
150           { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP, "Point-to-point" },
151           { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA,  "Multi-Access" },
152           { 0,                          NULL }
153 };
154 
155 static const struct tok lsa_opaque_ri_tlv_values[] = {
156           { LS_OPAQUE_RI_TLV_CAP, "Router Capabilities" },
157           { 0,                        NULL }
158 };
159 
160 static const struct tok lsa_opaque_ri_tlv_cap_values[] = {
161           { 1, "Reserved" },
162           { 2, "Reserved" },
163           { 4, "Reserved" },
164           { 8, "Reserved" },
165           { 16, "graceful restart capable" },
166           { 32, "graceful restart helper" },
167           { 64, "Stub router support" },
168           { 128, "Traffic engineering" },
169           { 256, "p2p over LAN" },
170           { 512, "path computation server" },
171           { 0,                        NULL }
172 };
173 
174 static const struct tok ospf_lls_tlv_values[] = {
175           { OSPF_LLS_EO,      "Extended Options" },
176           { OSPF_LLS_MD5,     "MD5 Authentication" },
177           { 0,      NULL }
178 };
179 
180 static const struct tok ospf_lls_eo_options[] = {
181           { OSPF_LLS_EO_LR,   "LSDB resync" },
182           { OSPF_LLS_EO_RS,   "Restart" },
183           { 0,      NULL }
184 };
185 
186 int
ospf_grace_lsa_print(netdissect_options * ndo,const u_char * tptr,u_int ls_length)187 ospf_grace_lsa_print(netdissect_options *ndo,
188                      const u_char *tptr, u_int ls_length)
189 {
190     u_int tlv_type, tlv_length;
191 
192 
193     while (ls_length > 0) {
194         ND_TCHECK_4(tptr);
195         if (ls_length < 4) {
196             ND_PRINT("\n\t    Remaining LS length %u < 4", ls_length);
197             return -1;
198         }
199         tlv_type = GET_BE_U_2(tptr);
200         tlv_length = GET_BE_U_2(tptr + 2);
201         tptr+=4;
202         ls_length-=4;
203 
204         ND_PRINT("\n\t    %s TLV (%u), length %u, value: ",
205                tok2str(lsa_opaque_grace_tlv_values,"unknown",tlv_type),
206                tlv_type,
207                tlv_length);
208 
209         if (tlv_length > ls_length) {
210             ND_PRINT("\n\t    Bogus length %u > %u", tlv_length,
211                    ls_length);
212             return -1;
213         }
214 
215         /* Infinite loop protection. */
216         if (tlv_type == 0 || tlv_length ==0) {
217             return -1;
218         }
219 
220         ND_TCHECK_LEN(tptr, tlv_length);
221         switch(tlv_type) {
222 
223         case LS_OPAQUE_GRACE_TLV_PERIOD:
224             if (tlv_length != 4) {
225                 ND_PRINT("\n\t    Bogus length %u != 4", tlv_length);
226                 return -1;
227             }
228             ND_PRINT("%us", GET_BE_U_4(tptr));
229             break;
230 
231         case LS_OPAQUE_GRACE_TLV_REASON:
232             if (tlv_length != 1) {
233                 ND_PRINT("\n\t    Bogus length %u != 1", tlv_length);
234                 return -1;
235             }
236             ND_PRINT("%s (%u)",
237                    tok2str(lsa_opaque_grace_tlv_reason_values, "Unknown", GET_U_1(tptr)),
238                    GET_U_1(tptr));
239             break;
240 
241         case LS_OPAQUE_GRACE_TLV_INT_ADDRESS:
242             if (tlv_length != 4) {
243                 ND_PRINT("\n\t    Bogus length %u != 4", tlv_length);
244                 return -1;
245             }
246             ND_PRINT("%s", GET_IPADDR_STRING(tptr));
247             break;
248 
249         default:
250             if (ndo->ndo_vflag <= 1) {
251                 if (!print_unknown_data(ndo, tptr, "\n\t      ", tlv_length))
252                     return -1;
253             }
254             break;
255 
256         }
257         /* in OSPF everything has to be 32-bit aligned, including TLVs */
258         if (tlv_length%4 != 0)
259             tlv_length+=4-(tlv_length%4);
260         ls_length-=tlv_length;
261         tptr+=tlv_length;
262     }
263 
264     return 0;
265 trunc:
266     return -1;
267 }
268 
269 int
ospf_te_lsa_print(netdissect_options * ndo,const u_char * tptr,u_int ls_length)270 ospf_te_lsa_print(netdissect_options *ndo,
271                   const u_char *tptr, u_int ls_length)
272 {
273     u_int tlv_type, tlv_length, subtlv_type, subtlv_length;
274     u_int priority_level, te_class, count_srlg;
275     union { /* int to float conversion buffer for several subTLVs */
276         float f;
277         uint32_t i;
278     } bw;
279 
280     while (ls_length != 0) {
281         ND_TCHECK_4(tptr);
282         if (ls_length < 4) {
283             ND_PRINT("\n\t    Remaining LS length %u < 4", ls_length);
284             return -1;
285         }
286         tlv_type = GET_BE_U_2(tptr);
287         tlv_length = GET_BE_U_2(tptr + 2);
288         tptr+=4;
289         ls_length-=4;
290 
291         ND_PRINT("\n\t    %s TLV (%u), length: %u",
292                tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type),
293                tlv_type,
294                tlv_length);
295 
296         if (tlv_length > ls_length) {
297             ND_PRINT("\n\t    Bogus length %u > %u", tlv_length,
298                    ls_length);
299             return -1;
300         }
301 
302         /* Infinite loop protection. */
303         if (tlv_type == 0 || tlv_length ==0) {
304             return -1;
305         }
306 
307         switch(tlv_type) {
308         case LS_OPAQUE_TE_TLV_LINK:
309             while (tlv_length != 0) {
310                 if (tlv_length < 4) {
311                     ND_PRINT("\n\t    Remaining TLV length %u < 4",
312                            tlv_length);
313                     return -1;
314                 }
315                 subtlv_type = GET_BE_U_2(tptr);
316                 subtlv_length = GET_BE_U_2(tptr + 2);
317                 tptr+=4;
318                 tlv_length-=4;
319 
320                     /* Infinite loop protection */
321                     if (subtlv_type == 0 || subtlv_length == 0)
322                         goto invalid;
323 
324                 ND_PRINT("\n\t      %s subTLV (%u), length: %u",
325                        tok2str(lsa_opaque_te_link_tlv_subtlv_values,"unknown",subtlv_type),
326                        subtlv_type,
327                        subtlv_length);
328 
329                 if (tlv_length < subtlv_length) {
330                     ND_PRINT("\n\t    Remaining TLV length %u < %u",
331                            tlv_length + 4, subtlv_length + 4);
332                     return -1;
333                 }
334                 ND_TCHECK_LEN(tptr, subtlv_length);
335                 switch(subtlv_type) {
336                 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
337                         if (subtlv_length != 4) {
338                               ND_PRINT(" != 4");
339                               goto invalid;
340                         }
341                     ND_PRINT(", 0x%08x", GET_BE_U_4(tptr));
342                     break;
343                 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID:
344                 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID:
345                         if (subtlv_length != 4 && subtlv_length != 8) {
346                               ND_PRINT(" != 4 && != 8");
347                               goto invalid;
348                         }
349                     ND_PRINT(", %s (0x%08x)",
350                            GET_IPADDR_STRING(tptr),
351                            GET_BE_U_4(tptr));
352                     if (subtlv_length == 8) /* rfc4203 */
353                         ND_PRINT(", %s (0x%08x)",
354                                GET_IPADDR_STRING(tptr+4),
355                                GET_BE_U_4(tptr + 4));
356                     break;
357                 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP:
358                 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP:
359                         if (subtlv_length != 4) {
360                               ND_PRINT(" != 4");
361                               goto invalid;
362                         }
363                     ND_PRINT(", %s", GET_IPADDR_STRING(tptr));
364                     break;
365                 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
366                 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
367                         if (subtlv_length != 4) {
368                               ND_PRINT(" != 4");
369                               goto invalid;
370                         }
371                     bw.i = GET_BE_U_4(tptr);
372                     ND_PRINT(", %.3f Mbps", bw.f * 8 / 1000000);
373                     break;
374                 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW:
375                         if (subtlv_length != 32) {
376                               ND_PRINT(" != 32");
377                               goto invalid;
378                         }
379                     for (te_class = 0; te_class < 8; te_class++) {
380                         bw.i = GET_BE_U_4(tptr + te_class * 4);
381                         ND_PRINT("\n\t\tTE-Class %u: %.3f Mbps",
382                                te_class,
383                                bw.f * 8 / 1000000);
384                     }
385                     break;
386                 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS:
387                         if (subtlv_length < 4) {
388                               ND_PRINT(" < 4");
389                               goto invalid;
390                         }
391                         /* BC Model Id (1 octet) + Reserved (3 octets) */
392                     ND_PRINT("\n\t\tBandwidth Constraints Model ID: %s (%u)",
393                            tok2str(diffserv_te_bc_values, "unknown", GET_U_1(tptr)),
394                            GET_U_1(tptr));
395                         if (subtlv_length % 4 != 0) {
396                               ND_PRINT("\n\t\tlength %u != N x 4", subtlv_length);
397                               goto invalid;
398                         }
399                         if (subtlv_length > 36) {
400                               ND_PRINT("\n\t\tlength %u > 36", subtlv_length);
401                               goto invalid;
402                         }
403                     /* decode BCs until the subTLV ends */
404                     for (te_class = 0; te_class < (subtlv_length-4)/4; te_class++) {
405                         bw.i = GET_BE_U_4(tptr + 4 + te_class * 4);
406                         ND_PRINT("\n\t\t  Bandwidth constraint CT%u: %.3f Mbps",
407                                te_class,
408                                bw.f * 8 / 1000000);
409                     }
410                     break;
411                 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC:
412                         if (subtlv_length != 4) {
413                               ND_PRINT(" != 4");
414                               goto invalid;
415                         }
416                     ND_PRINT(", Metric %u", GET_BE_U_4(tptr));
417                     break;
418                 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE:
419                         /* Protection Cap (1 octet) + Reserved ((3 octets) */
420                         if (subtlv_length != 4) {
421                               ND_PRINT(" != 4");
422                               goto invalid;
423                         }
424                     ND_PRINT(", %s",
425                              bittok2str(gmpls_link_prot_values, "none", GET_U_1(tptr)));
426                     break;
427                 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
428                         if (subtlv_length < 36) {
429                               ND_PRINT(" < 36");
430                               goto invalid;
431                         }
432                         /* Switching Cap (1 octet) + Encoding (1) +  Reserved (2) */
433                     ND_PRINT("\n\t\tInterface Switching Capability: %s",
434                            tok2str(gmpls_switch_cap_values, "Unknown", GET_U_1((tptr))));
435                     ND_PRINT("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
436                            tok2str(gmpls_encoding_values, "Unknown", GET_U_1((tptr + 1))));
437                     for (priority_level = 0; priority_level < 8; priority_level++) {
438                         bw.i = GET_BE_U_4(tptr + 4 + (priority_level * 4));
439                         ND_PRINT("\n\t\t  priority level %u: %.3f Mbps",
440                                priority_level,
441                                bw.f * 8 / 1000000);
442                     }
443                     break;
444                 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE:
445                         if (subtlv_length != 1) {
446                               ND_PRINT(" != 1");
447                               goto invalid;
448                         }
449                     ND_PRINT(", %s (%u)",
450                            tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",GET_U_1(tptr)),
451                            GET_U_1(tptr));
452                     break;
453 
454                 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
455                         if (subtlv_length % 4 != 0) {
456                               ND_PRINT(" != N x 4");
457                               goto invalid;
458                         }
459                     count_srlg = subtlv_length / 4;
460                     if (count_srlg != 0)
461                         ND_PRINT("\n\t\t  Shared risk group: ");
462                     while (count_srlg > 0) {
463                         bw.i = GET_BE_U_4(tptr);
464                         ND_PRINT("%u", bw.i);
465                         tptr+=4;
466                         count_srlg--;
467                         if (count_srlg > 0)
468                             ND_PRINT(", ");
469                     }
470                     break;
471 
472                 default:
473                     if (ndo->ndo_vflag <= 1) {
474                         if (!print_unknown_data(ndo, tptr, "\n\t\t", subtlv_length))
475                             return -1;
476                     }
477                     break;
478                 }
479                 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
480                 if (subtlv_length%4 != 0)
481                     subtlv_length+=4-(subtlv_length%4);
482 
483                 if (tlv_length < subtlv_length) {
484                     ND_PRINT("\n\t    Remaining TLV length %u < %u",
485                            tlv_length + 4, subtlv_length + 4);
486                     return -1;
487                 }
488                 tlv_length-=subtlv_length;
489                 tptr+=subtlv_length;
490 
491             }
492             break;
493 
494         case LS_OPAQUE_TE_TLV_ROUTER:
495             if (tlv_length < 4) {
496                 ND_PRINT("\n\t    TLV length %u < 4", tlv_length);
497                 return -1;
498             }
499             ND_PRINT(", %s", GET_IPADDR_STRING(tptr));
500             break;
501 
502         default:
503             if (ndo->ndo_vflag <= 1) {
504                 if (!print_unknown_data(ndo, tptr, "\n\t      ", tlv_length))
505                     return -1;
506             }
507             break;
508         }
509         /* in OSPF everything has to be 32-bit aligned, including TLVs */
510         if (tlv_length%4 != 0)
511             tlv_length+=4-(tlv_length%4);
512         if (tlv_length > ls_length) {
513             ND_PRINT("\n\t    Bogus padded length %u > %u", tlv_length,
514                    ls_length);
515             return -1;
516         }
517         ls_length-=tlv_length;
518         tptr+=tlv_length;
519     }
520     return 0;
521 trunc:
522     return -1;
523 invalid:
524     nd_print_invalid(ndo);
525     return -1;
526 }
527 
528 static int
ospf_print_lshdr(netdissect_options * ndo,const struct lsa_hdr * lshp)529 ospf_print_lshdr(netdissect_options *ndo,
530                  const struct lsa_hdr *lshp)
531 {
532         u_int ls_type;
533         u_int ls_length;
534 
535         ls_length = GET_BE_U_2(lshp->ls_length);
536         if (ls_length < sizeof(struct lsa_hdr)) {
537                 ND_PRINT("\n\t    Bogus length %u < header (%zu)", ls_length,
538                     sizeof(struct lsa_hdr));
539                 return(-1);
540         }
541         ND_PRINT("\n\t  Advertising Router %s, seq 0x%08x, age %us, length %zu",
542                   GET_IPADDR_STRING(lshp->ls_router),
543                   GET_BE_U_4(lshp->ls_seq),
544                   GET_BE_U_2(lshp->ls_age),
545                   ls_length - sizeof(struct lsa_hdr));
546         ls_type = GET_U_1(lshp->ls_type);
547         switch (ls_type) {
548         /* the LSA header for opaque LSAs was slightly changed */
549         case LS_TYPE_OPAQUE_LL:
550         case LS_TYPE_OPAQUE_AL:
551         case LS_TYPE_OPAQUE_DW:
552             ND_PRINT("\n\t    %s LSA (%u), Opaque-Type %s LSA (%u), Opaque-ID %u",
553                    tok2str(lsa_values,"unknown",ls_type),
554                    ls_type,
555 
556                        tok2str(lsa_opaque_values,
557                                  "unknown",
558                                  GET_U_1(lshp->un_lsa_id.opaque_field.opaque_type)),
559                        GET_U_1(lshp->un_lsa_id.opaque_field.opaque_type),
560                        GET_BE_U_3(lshp->un_lsa_id.opaque_field.opaque_id)
561 
562                    );
563             break;
564 
565         /* all other LSA types use regular style LSA headers */
566         default:
567             ND_PRINT("\n\t    %s LSA (%u), LSA-ID: %s",
568                    tok2str(lsa_values,"unknown",ls_type),
569                    ls_type,
570                    GET_IPADDR_STRING(lshp->un_lsa_id.lsa_id));
571             break;
572         }
573         ND_PRINT("\n\t    Options: [%s]",
574                      bittok2str(ospf_option_values, "none", GET_U_1(lshp->ls_options)));
575 
576         return (ls_length);
577 }
578 
579 /* draft-ietf-ospf-mt-09 */
580 static const struct tok ospf_topology_values[] = {
581     { 0, "default" },
582     { 1, "multicast" },
583     { 2, "management" },
584     { 0, NULL }
585 };
586 
587 /*
588  * Print all the per-topology metrics.
589  */
590 static void
ospf_print_tos_metrics(netdissect_options * ndo,const union un_tos * tos)591 ospf_print_tos_metrics(netdissect_options *ndo,
592                        const union un_tos *tos)
593 {
594     u_int metric_count;
595     u_int toscount;
596     u_int tos_type;
597 
598     toscount = GET_U_1(tos->link.link_tos_count)+1;
599     metric_count = 0;
600 
601     /*
602      * All but the first metric contain a valid topology id.
603      */
604     while (toscount != 0) {
605         tos_type = GET_U_1(tos->metrics.tos_type);
606         ND_PRINT("\n\t\ttopology %s (%u), metric %u",
607                tok2str(ospf_topology_values, "Unknown",
608                        metric_count ? tos_type : 0),
609                metric_count ? tos_type : 0,
610                GET_BE_U_2(tos->metrics.tos_metric));
611         metric_count++;
612         tos++;
613         toscount--;
614     }
615 }
616 
617 /*
618  * Print a single link state advertisement.  If truncated or if LSA length
619  * field is less than the length of the LSA header, return NULl, else
620  * return pointer to data past end of LSA.
621  */
622 static const uint8_t *
ospf_print_lsa(netdissect_options * ndo,const struct lsa * lsap)623 ospf_print_lsa(netdissect_options *ndo,
624                const struct lsa *lsap)
625 {
626           const uint8_t *ls_end;
627           const struct rlalink *rlp;
628           const nd_ipv4 *ap;
629           const struct aslametric *almp;
630           const struct mcla *mcp;
631           const uint8_t *lp;
632           u_int tlv_type, tlv_length, rla_count, topology;
633           int ospf_print_lshdr_ret;
634           u_int ls_length;
635           const uint8_t *tptr;
636 
637           tptr = (const uint8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
638           ospf_print_lshdr_ret = ospf_print_lshdr(ndo, &lsap->ls_hdr);
639           if (ospf_print_lshdr_ret < 0)
640                     return(NULL);
641           ls_length = (u_int)ospf_print_lshdr_ret;
642           ls_end = (const uint8_t *)lsap + ls_length;
643           /*
644            * ospf_print_lshdr() returns -1 if the length is too short,
645            * so we know ls_length is >= sizeof(struct lsa_hdr).
646            */
647           ls_length -= sizeof(struct lsa_hdr);
648 
649           switch (GET_U_1(lsap->ls_hdr.ls_type)) {
650 
651           case LS_TYPE_ROUTER:
652                     ND_PRINT("\n\t    Router LSA Options: [%s]",
653                               bittok2str(ospf_rla_flag_values, "none", GET_U_1(lsap->lsa_un.un_rla.rla_flags)));
654 
655                     rla_count = GET_BE_U_2(lsap->lsa_un.un_rla.rla_count);
656                     ND_TCHECK_SIZE(lsap->lsa_un.un_rla.rla_link);
657                     rlp = lsap->lsa_un.un_rla.rla_link;
658                     for (u_int i = rla_count; i != 0; i--) {
659                               ND_TCHECK_SIZE(rlp);
660                               switch (GET_U_1(rlp->un_tos.link.link_type)) {
661 
662                               case RLA_TYPE_VIRTUAL:
663                                         ND_PRINT("\n\t      Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
664                                             GET_IPADDR_STRING(rlp->link_id),
665                                             GET_IPADDR_STRING(rlp->link_data));
666                                         break;
667 
668                               case RLA_TYPE_ROUTER:
669                                         ND_PRINT("\n\t      Neighbor Router-ID: %s, Interface Address: %s",
670                                             GET_IPADDR_STRING(rlp->link_id),
671                                             GET_IPADDR_STRING(rlp->link_data));
672                                         break;
673 
674                               case RLA_TYPE_TRANSIT:
675                                         ND_PRINT("\n\t      Neighbor Network-ID: %s, Interface Address: %s",
676                                             GET_IPADDR_STRING(rlp->link_id),
677                                             GET_IPADDR_STRING(rlp->link_data));
678                                         break;
679 
680                               case RLA_TYPE_STUB:
681                                         ND_PRINT("\n\t      Stub Network: %s, Mask: %s",
682                                             GET_IPADDR_STRING(rlp->link_id),
683                                             GET_IPADDR_STRING(rlp->link_data));
684                                         break;
685 
686                               default:
687                                         ND_PRINT("\n\t      Unknown Router Link Type (%u)",
688                                             GET_U_1(rlp->un_tos.link.link_type));
689                                         return (ls_end);
690                               }
691 
692                               ospf_print_tos_metrics(ndo, &rlp->un_tos);
693 
694                               rlp = (const struct rlalink *)((const u_char *)(rlp + 1) +
695                                   (GET_U_1(rlp->un_tos.link.link_tos_count) * sizeof(union un_tos)));
696                     }
697                     break;
698 
699           case LS_TYPE_NETWORK:
700                     ND_PRINT("\n\t    Mask %s\n\t    Connected Routers:",
701                         GET_IPADDR_STRING(lsap->lsa_un.un_nla.nla_mask));
702                     ap = lsap->lsa_un.un_nla.nla_router;
703                     while ((const u_char *)ap < ls_end) {
704                               ND_PRINT("\n\t      %s", GET_IPADDR_STRING(ap));
705                               ++ap;
706                     }
707                     break;
708 
709           case LS_TYPE_SUM_IP:
710                     ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
711                     ND_PRINT("\n\t    Mask %s",
712                         GET_IPADDR_STRING(lsap->lsa_un.un_sla.sla_mask));
713                     ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric);
714                     lp = (const uint8_t *)lsap->lsa_un.un_sla.sla_tosmetric;
715                     while (lp < ls_end) {
716                               uint32_t ul;
717 
718                               ul = GET_BE_U_4(lp);
719                         topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
720                               ND_PRINT("\n\t\ttopology %s (%u) metric %u",
721                                tok2str(ospf_topology_values, "Unknown", topology),
722                                topology,
723                                ul & SLA_MASK_METRIC);
724                               lp += 4;
725                     }
726                     break;
727 
728           case LS_TYPE_SUM_ABR:
729                     ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric);
730                     lp = (const uint8_t *)lsap->lsa_un.un_sla.sla_tosmetric;
731                     while (lp < ls_end) {
732                               uint32_t ul;
733 
734                               ul = GET_BE_U_4(lp);
735                         topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
736                               ND_PRINT("\n\t\ttopology %s (%u) metric %u",
737                                tok2str(ospf_topology_values, "Unknown", topology),
738                                topology,
739                                ul & SLA_MASK_METRIC);
740                               lp += 4;
741                     }
742                     break;
743 
744           case LS_TYPE_ASE:
745         case LS_TYPE_NSSA: /* fall through - those LSAs share the same format */
746                     ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
747                     ND_PRINT("\n\t    Mask %s",
748                         GET_IPADDR_STRING(lsap->lsa_un.un_asla.asla_mask));
749 
750                     ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric);
751                     almp = lsap->lsa_un.un_asla.asla_metric;
752                     while ((const u_char *)almp < ls_end) {
753                               uint32_t ul;
754 
755                               ul = GET_BE_U_4(almp->asla_tosmetric);
756                         topology = ((ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
757                               ND_PRINT("\n\t\ttopology %s (%u), type %u, metric",
758                                tok2str(ospf_topology_values, "Unknown", topology),
759                                topology,
760                                (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1);
761                               if ((ul & ASLA_MASK_METRIC) == 0xffffff)
762                                         ND_PRINT(" infinite");
763                               else
764                                         ND_PRINT(" %u", (ul & ASLA_MASK_METRIC));
765 
766                               if (GET_IPV4_TO_NETWORK_ORDER(almp->asla_forward) != 0) {
767                                         ND_PRINT(", forward %s", GET_IPADDR_STRING(almp->asla_forward));
768                               }
769                               if (GET_IPV4_TO_NETWORK_ORDER(almp->asla_tag) != 0) {
770                                         ND_PRINT(", tag %s", GET_IPADDR_STRING(almp->asla_tag));
771                               }
772                               ++almp;
773                     }
774                     break;
775 
776           case LS_TYPE_GROUP:
777                     /* Multicast extensions as of 23 July 1991 */
778                     mcp = lsap->lsa_un.un_mcla;
779                     while ((const u_char *)mcp < ls_end) {
780                               switch (GET_BE_U_4(mcp->mcla_vtype)) {
781 
782                               case MCLA_VERTEX_ROUTER:
783                                         ND_PRINT("\n\t    Router Router-ID %s",
784                                             GET_IPADDR_STRING(mcp->mcla_vid));
785                                         break;
786 
787                               case MCLA_VERTEX_NETWORK:
788                                         ND_PRINT("\n\t    Network Designated Router %s",
789                                             GET_IPADDR_STRING(mcp->mcla_vid));
790                                         break;
791 
792                               default:
793                                         ND_PRINT("\n\t    unknown VertexType (%u)",
794                                             GET_BE_U_4(mcp->mcla_vtype));
795                                         break;
796                               }
797                     ++mcp;
798                     }
799                     break;
800 
801           case LS_TYPE_OPAQUE_LL: /* fall through */
802           case LS_TYPE_OPAQUE_AL:
803           case LS_TYPE_OPAQUE_DW:
804 
805               switch (GET_U_1(lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
806             case LS_OPAQUE_TYPE_RI:
807                     tptr = (const uint8_t *)(lsap->lsa_un.un_ri_tlv);
808 
809                     u_int ls_length_remaining = ls_length;
810                     while (ls_length_remaining != 0) {
811                     ND_TCHECK_4(tptr);
812                         if (ls_length_remaining < 4) {
813                         ND_PRINT("\n\t    Remaining LS length %u < 4", ls_length_remaining);
814                         return(ls_end);
815                     }
816                     tlv_type = GET_BE_U_2(tptr);
817                     tlv_length = GET_BE_U_2(tptr + 2);
818                     tptr+=4;
819                     ls_length_remaining-=4;
820 
821                     ND_PRINT("\n\t    %s TLV (%u), length: %u, value: ",
822                            tok2str(lsa_opaque_ri_tlv_values,"unknown",tlv_type),
823                            tlv_type,
824                            tlv_length);
825 
826                     if (tlv_length > ls_length_remaining) {
827                         ND_PRINT("\n\t    Bogus length %u > remaining LS length %u", tlv_length,
828                             ls_length_remaining);
829                         return(ls_end);
830                     }
831                     ND_TCHECK_LEN(tptr, tlv_length);
832                     switch(tlv_type) {
833 
834                     case LS_OPAQUE_RI_TLV_CAP:
835                         if (tlv_length != 4) {
836                             ND_PRINT("\n\t    Bogus length %u != 4", tlv_length);
837                             return(ls_end);
838                         }
839                         ND_PRINT("Capabilities: %s",
840                                bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", GET_BE_U_4(tptr)));
841                         break;
842                     default:
843                         if (ndo->ndo_vflag <= 1) {
844                             if (!print_unknown_data(ndo, tptr, "\n\t      ", tlv_length))
845                                 return(ls_end);
846                         }
847                         break;
848 
849                     }
850 
851                     /* in OSPF everything has to be 32-bit aligned, including TLVs */
852                     if (tlv_length % 4) {
853                         tlv_length += (4 - (tlv_length % 4));
854                     }
855                     tptr+=tlv_length;
856                     ls_length_remaining-=tlv_length;
857                 }
858                 break;
859 
860             case LS_OPAQUE_TYPE_GRACE:
861                 if (ospf_grace_lsa_print(ndo, (const u_char *)(lsap->lsa_un.un_grace_tlv),
862                                          ls_length) == -1) {
863                     return(ls_end);
864                 }
865                 break;
866 
867               case LS_OPAQUE_TYPE_TE:
868                 if (ospf_te_lsa_print(ndo, (const u_char *)(lsap->lsa_un.un_te_lsa_tlv),
869                                       ls_length) == -1) {
870                     return(ls_end);
871                 }
872                 break;
873 
874             default:
875                 if (ndo->ndo_vflag <= 1) {
876                     if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
877                                            "\n\t    ", ls_length))
878                         return(ls_end);
879                 }
880                 break;
881             }
882         }
883 
884         /* do we want to see an additionally hexdump ? */
885         if (ndo->ndo_vflag> 1)
886             if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
887                                    "\n\t    ", ls_length)) {
888                 return(ls_end);
889             }
890 
891           return (ls_end);
892 trunc:
893           return (NULL);
894 }
895 
896 static void
ospf_decode_lls(netdissect_options * ndo,const struct ospfhdr * op,u_int length)897 ospf_decode_lls(netdissect_options *ndo,
898                 const struct ospfhdr *op, u_int length)
899 {
900     const u_char *dptr;
901     const u_char *dataend;
902     u_int length2;
903     uint16_t lls_type, lls_len;
904     uint32_t lls_flags;
905 
906     switch (GET_U_1(op->ospf_type)) {
907 
908     case OSPF_TYPE_HELLO:
909         if (!(GET_U_1(op->ospf_hello.hello_options) & OSPF_OPTION_L))
910             return;
911         break;
912 
913     case OSPF_TYPE_DD:
914         if (!(GET_U_1(op->ospf_db.db_options) & OSPF_OPTION_L))
915             return;
916         break;
917 
918     default:
919         return;
920     }
921 
922     /* dig deeper if LLS data is available; see RFC4813 */
923     length2 = GET_BE_U_2(op->ospf_len);
924     dptr = (const u_char *)op + length2;
925     dataend = (const u_char *)op + length;
926 
927     if (GET_BE_U_2(op->ospf_authtype) == OSPF_AUTH_MD5) {
928         dptr = dptr + GET_U_1(op->ospf_authdata + 3);
929         length2 += GET_U_1(op->ospf_authdata + 3);
930     }
931     if (length2 >= length) {
932         ND_PRINT("\n\t[LLS truncated]");
933         return;
934     }
935     ND_PRINT("\n\t  LLS: checksum: 0x%04x", (u_int) GET_BE_U_2(dptr));
936 
937     dptr += 2;
938     length2 = GET_BE_U_2(dptr);
939     ND_PRINT(", length: %u", length2);
940 
941     dptr += 2;
942     while (dptr < dataend) {
943         lls_type = GET_BE_U_2(dptr);
944         ND_PRINT("\n\t    %s (%u)",
945                tok2str(ospf_lls_tlv_values,"Unknown TLV",lls_type),
946                lls_type);
947         dptr += 2;
948         lls_len = GET_BE_U_2(dptr);
949         ND_PRINT(", length: %u", lls_len);
950         dptr += 2;
951         switch (lls_type) {
952 
953         case OSPF_LLS_EO:
954             if (lls_len != 4) {
955                 ND_PRINT(" [should be 4]");
956                 lls_len = 4;
957             }
958             lls_flags = GET_BE_U_4(dptr);
959             ND_PRINT("\n\t      Options: 0x%08x [%s]", lls_flags,
960                    bittok2str(ospf_lls_eo_options, "?", lls_flags));
961 
962             break;
963 
964         case OSPF_LLS_MD5:
965             if (lls_len != 20) {
966                 ND_PRINT(" [should be 20]");
967                 lls_len = 20;
968             }
969             ND_PRINT("\n\t      Sequence number: 0x%08x", GET_BE_U_4(dptr));
970             break;
971         }
972 
973         dptr += lls_len;
974     }
975 }
976 
977 static int
ospf_decode_v2(netdissect_options * ndo,const struct ospfhdr * op,const u_char * dataend)978 ospf_decode_v2(netdissect_options *ndo,
979                const struct ospfhdr *op, const u_char *dataend)
980 {
981           const nd_ipv4 *ap;
982           const struct lsr *lsrp;
983           const struct lsa_hdr *lshp;
984           const struct lsa *lsap;
985           uint32_t lsa_count,lsa_count_max;
986 
987           switch (GET_U_1(op->ospf_type)) {
988 
989           case OSPF_TYPE_HELLO:
990                     ND_PRINT("\n\tOptions [%s]",
991                               bittok2str(ospf_option_values,"none",GET_U_1(op->ospf_hello.hello_options)));
992 
993                     ND_PRINT("\n\t  Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
994                               GET_BE_U_2(op->ospf_hello.hello_helloint),
995                               GET_BE_U_4(op->ospf_hello.hello_deadint),
996                               GET_IPADDR_STRING(op->ospf_hello.hello_mask),
997                               GET_U_1(op->ospf_hello.hello_priority));
998 
999                     if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_dr) != 0)
1000                               ND_PRINT("\n\t  Designated Router %s",
1001                                   GET_IPADDR_STRING(op->ospf_hello.hello_dr));
1002 
1003                     if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_bdr) != 0)
1004                               ND_PRINT(", Backup Designated Router %s",
1005                                         GET_IPADDR_STRING(op->ospf_hello.hello_bdr));
1006 
1007                     ap = op->ospf_hello.hello_neighbor;
1008                     if ((const u_char *)ap < dataend)
1009                               ND_PRINT("\n\t  Neighbor List:");
1010                     while ((const u_char *)ap < dataend) {
1011                               ND_PRINT("\n\t    %s", GET_IPADDR_STRING(ap));
1012                               ++ap;
1013                     }
1014                     break;    /* HELLO */
1015 
1016           case OSPF_TYPE_DD:
1017                     ND_PRINT("\n\tOptions [%s]",
1018                               bittok2str(ospf_option_values, "none", GET_U_1(op->ospf_db.db_options)));
1019                     ND_PRINT(", DD Flags [%s]",
1020                               bittok2str(ospf_dd_flag_values, "none", GET_U_1(op->ospf_db.db_flags)));
1021                     if (GET_BE_U_2(op->ospf_db.db_ifmtu)) {
1022                               ND_PRINT(", MTU: %u",
1023                                          GET_BE_U_2(op->ospf_db.db_ifmtu));
1024                     }
1025                     ND_PRINT(", Sequence: 0x%08x", GET_BE_U_4(op->ospf_db.db_seq));
1026 
1027                     /* Print all the LS adv's */
1028                     lshp = op->ospf_db.db_lshdr;
1029                     while (((const u_char *)lshp < dataend) && ospf_print_lshdr(ndo, lshp) != -1) {
1030                               ++lshp;
1031                     }
1032                     break;
1033 
1034           case OSPF_TYPE_LS_REQ:
1035                 lsrp = op->ospf_lsr;
1036                 while ((const u_char *)lsrp < dataend) {
1037                     ND_TCHECK_SIZE(lsrp);
1038 
1039                     ND_PRINT("\n\t  Advertising Router: %s, %s LSA (%u)",
1040                            GET_IPADDR_STRING(lsrp->ls_router),
1041                            tok2str(lsa_values,"unknown",GET_BE_U_4(lsrp->ls_type)),
1042                            GET_BE_U_4(lsrp->ls_type));
1043 
1044                     switch (GET_BE_U_4(lsrp->ls_type)) {
1045                         /* the LSA header for opaque LSAs was slightly changed */
1046                     case LS_TYPE_OPAQUE_LL:
1047                     case LS_TYPE_OPAQUE_AL:
1048                     case LS_TYPE_OPAQUE_DW:
1049                         ND_PRINT(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1050                                tok2str(lsa_opaque_values, "unknown",GET_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type)),
1051                                GET_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type),
1052                                GET_BE_U_3(lsrp->un_ls_stateid.opaque_field.opaque_id));
1053                         break;
1054                     default:
1055                         ND_PRINT(", LSA-ID: %s",
1056                                GET_IPADDR_STRING(lsrp->un_ls_stateid.ls_stateid));
1057                         break;
1058                     }
1059 
1060                     ++lsrp;
1061                 }
1062                     break;
1063 
1064           case OSPF_TYPE_LS_UPDATE:
1065                 lsap = op->ospf_lsu.lsu_lsa;
1066                 lsa_count_max = GET_BE_U_4(op->ospf_lsu.lsu_count);
1067                 ND_PRINT(", %u LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max));
1068                 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
1069                     ND_PRINT("\n\t  LSA #%u", lsa_count);
1070                         lsap = (const struct lsa *)ospf_print_lsa(ndo, lsap);
1071                         if (lsap == NULL)
1072                                 goto trunc;
1073                 }
1074                     break;
1075 
1076           case OSPF_TYPE_LS_ACK:
1077                 lshp = op->ospf_lsa.lsa_lshdr;
1078                 while ((const u_char *)lshp < dataend) {
1079                     ospf_print_lshdr(ndo, lshp);
1080                     ++lshp;
1081                 }
1082                 break;
1083 
1084           default:
1085                     break;
1086           }
1087           return (0);
1088 trunc:
1089           return (1);
1090 }
1091 
1092 void
ospf_print(netdissect_options * ndo,const u_char * bp,u_int length,const u_char * bp2 _U_)1093 ospf_print(netdissect_options *ndo,
1094            const u_char *bp, u_int length,
1095            const u_char *bp2 _U_)
1096 {
1097           const struct ospfhdr *op;
1098           const u_char *dataend;
1099           const char *cp;
1100 
1101           ndo->ndo_protocol = "ospf2";
1102           op = (const struct ospfhdr *)bp;
1103 
1104           /* XXX Before we do anything else, strip off the MD5 trailer */
1105           if (GET_BE_U_2(op->ospf_authtype) == OSPF_AUTH_MD5) {
1106                     length -= OSPF_AUTH_MD5_LEN;
1107                     ndo->ndo_snapend -= OSPF_AUTH_MD5_LEN;
1108           }
1109 
1110           /* If the type is valid translate it, or just print the type */
1111           /* value.  If it's not valid, say so and return */
1112           cp = tok2str(type2str, "unknown LS-type %u", GET_U_1(op->ospf_type));
1113           ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op->ospf_version), cp,
1114                      length);
1115           if (*cp == 'u')
1116                     return;
1117 
1118           if (!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
1119                     return;
1120           }
1121 
1122           if (length != GET_BE_U_2(op->ospf_len)) {
1123                     ND_PRINT(" [len %u]", GET_BE_U_2(op->ospf_len));
1124           }
1125 
1126           if (length > GET_BE_U_2(op->ospf_len)) {
1127                     dataend = bp + GET_BE_U_2(op->ospf_len);
1128           } else {
1129                     dataend = bp + length;
1130           }
1131 
1132           ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op->ospf_routerid));
1133 
1134           if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_areaid) != 0)
1135                     ND_PRINT(", Area %s", GET_IPADDR_STRING(op->ospf_areaid));
1136           else
1137                     ND_PRINT(", Backbone Area");
1138 
1139           if (ndo->ndo_vflag) {
1140                     /* Print authentication data (should we really do this?) */
1141                     ND_TCHECK_LEN(op->ospf_authdata, sizeof(op->ospf_authdata));
1142 
1143                     ND_PRINT(", Authentication Type: %s (%u)",
1144                               tok2str(ospf_authtype_values, "unknown", GET_BE_U_2(op->ospf_authtype)),
1145                               GET_BE_U_2(op->ospf_authtype));
1146 
1147                     switch (GET_BE_U_2(op->ospf_authtype)) {
1148 
1149                     case OSPF_AUTH_NONE:
1150                               break;
1151 
1152                     case OSPF_AUTH_SIMPLE:
1153                               ND_PRINT("\n\tSimple text password: ");
1154                               nd_printjnp(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN);
1155                               break;
1156 
1157                     case OSPF_AUTH_MD5:
1158                               ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1159                                         GET_U_1(op->ospf_authdata + 2),
1160                                         GET_U_1(op->ospf_authdata + 3),
1161                                         GET_BE_U_4((op->ospf_authdata) + 4));
1162                               break;
1163 
1164                     default:
1165                               return;
1166                     }
1167           }
1168           /* Do rest according to version.         */
1169           switch (GET_U_1(op->ospf_version)) {
1170 
1171           case 2:
1172                     /* ospf version 2 */
1173                     if (ospf_decode_v2(ndo, op, dataend))
1174                               goto trunc;
1175                     if (length > GET_BE_U_2(op->ospf_len))
1176                               ospf_decode_lls(ndo, op, length);
1177                     break;
1178 
1179           default:
1180                     ND_PRINT(" ospf [version %u]", GET_U_1(op->ospf_version));
1181                     break;
1182           }                             /* end switch on version */
1183 
1184           return;
1185 trunc:
1186           nd_trunc_longjmp(ndo);
1187 }
1188