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