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