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