]> The Tcpdump Group git mirrors - tcpdump/blob - print-ospf.c
ospf: when processing LS_OPAQUE_TYPE_RI, don't modify ls_length.
[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 /* \summary: Open Shortest Path First (OSPF) printer */
25
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29
30 #include "netdissect-stdinc.h"
31
32 #include "netdissect.h"
33 #include "addrtoname.h"
34 #include "extract.h"
35 #include "gmpls.h"
36
37 #include "ospf.h"
38
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_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 >= sizeof(subtlv_type) + sizeof(subtlv_length)) {
305 if (tlv_length < 4) {
306 ND_PRINT("\n\t Remaining TLV length %u < 4",
307 tlv_length);
308 return -1;
309 }
310 ND_TCHECK_4(tptr);
311 subtlv_type = GET_BE_U_2(tptr);
312 subtlv_length = GET_BE_U_2(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("\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_TCHECK_LEN(tptr, subtlv_length);
326 switch(subtlv_type) {
327 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
328 if (subtlv_length != 4) {
329 ND_PRINT(" != 4");
330 goto invalid;
331 }
332 ND_PRINT(", 0x%08x", GET_BE_U_4(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(" != 4 && != 8");
338 goto invalid;
339 }
340 ND_PRINT(", %s (0x%08x)",
341 GET_IPADDR_STRING(tptr),
342 GET_BE_U_4(tptr));
343 if (subtlv_length == 8) /* rfc4203 */
344 ND_PRINT(", %s (0x%08x)",
345 GET_IPADDR_STRING(tptr+4),
346 GET_BE_U_4(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(" != 4");
352 goto invalid;
353 }
354 ND_PRINT(", %s", GET_IPADDR_STRING(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(" != 4");
360 goto invalid;
361 }
362 bw.i = GET_BE_U_4(tptr);
363 ND_PRINT(", %.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(" != 32");
368 goto invalid;
369 }
370 for (te_class = 0; te_class < 8; te_class++) {
371 bw.i = GET_BE_U_4(tptr + te_class * 4);
372 ND_PRINT("\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(" < 4");
380 goto invalid;
381 }
382 /* BC Model Id (1 octet) + Reserved (3 octets) */
383 ND_PRINT("\n\t\tBandwidth Constraints Model ID: %s (%u)",
384 tok2str(diffserv_te_bc_values, "unknown", GET_U_1(tptr)),
385 GET_U_1(tptr));
386 if (subtlv_length % 4 != 0) {
387 ND_PRINT("\n\t\tlength %u != N x 4", subtlv_length);
388 goto invalid;
389 }
390 if (subtlv_length > 36) {
391 ND_PRINT("\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 = GET_BE_U_4(tptr + 4 + te_class * 4);
397 ND_PRINT("\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(" != 4");
405 goto invalid;
406 }
407 ND_PRINT(", Metric %u", GET_BE_U_4(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(" != 4");
413 goto invalid;
414 }
415 ND_PRINT(", %s",
416 bittok2str(gmpls_link_prot_values, "none", GET_U_1(tptr)));
417 break;
418 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
419 if (subtlv_length < 36) {
420 ND_PRINT(" < 36");
421 goto invalid;
422 }
423 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
424 ND_PRINT("\n\t\tInterface Switching Capability: %s",
425 tok2str(gmpls_switch_cap_values, "Unknown", GET_U_1((tptr))));
426 ND_PRINT("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
427 tok2str(gmpls_encoding_values, "Unknown", GET_U_1((tptr + 1))));
428 for (priority_level = 0; priority_level < 8; priority_level++) {
429 bw.i = GET_BE_U_4(tptr + 4 + (priority_level * 4));
430 ND_PRINT("\n\t\t priority level %u: %.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(" != 1");
438 goto invalid;
439 }
440 ND_PRINT(", %s (%u)",
441 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",GET_U_1(tptr)),
442 GET_U_1(tptr));
443 break;
444
445 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
446 if (subtlv_length % 4 != 0) {
447 ND_PRINT(" != N x 4");
448 goto invalid;
449 }
450 count_srlg = subtlv_length / 4;
451 if (count_srlg != 0)
452 ND_PRINT("\n\t\t Shared risk group: ");
453 while (count_srlg > 0) {
454 bw.i = GET_BE_U_4(tptr);
455 ND_PRINT("%u", bw.i);
456 tptr+=4;
457 count_srlg--;
458 if (count_srlg > 0)
459 ND_PRINT(", ");
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("\n\t TLV length %u < 4", tlv_length);
483 return -1;
484 }
485 ND_TCHECK_4(tptr);
486 ND_PRINT(", %s", GET_IPADDR_STRING(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_invalid(ndo);
507 return -1;
508 }
509
510 static int
511 ospf_print_lshdr(netdissect_options *ndo,
512 const struct lsa_hdr *lshp)
513 {
514 u_int ls_type;
515 u_int ls_length;
516
517 ND_TCHECK_2(lshp->ls_length);
518 ls_length = GET_BE_U_2(lshp->ls_length);
519 if (ls_length < sizeof(struct lsa_hdr)) {
520 ND_PRINT("\n\t Bogus length %u < header (%zu)", ls_length,
521 sizeof(struct lsa_hdr));
522 return(-1);
523 }
524
525 ND_TCHECK_4(lshp->ls_seq); /* XXX - ls_length check checked this */
526 ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
527 GET_IPADDR_STRING(lshp->ls_router),
528 GET_BE_U_4(lshp->ls_seq),
529 GET_BE_U_2(lshp->ls_age),
530 ls_length - (u_int)sizeof(struct lsa_hdr));
531
532 ND_TCHECK_1(lshp->ls_type); /* XXX - ls_length check checked this */
533 ls_type = GET_U_1(lshp->ls_type);
534 switch (ls_type) {
535 /* the LSA header for opaque LSAs was slightly changed */
536 case LS_TYPE_OPAQUE_LL:
537 case LS_TYPE_OPAQUE_AL:
538 case LS_TYPE_OPAQUE_DW:
539 ND_PRINT("\n\t %s LSA (%u), Opaque-Type %s LSA (%u), Opaque-ID %u",
540 tok2str(lsa_values,"unknown",ls_type),
541 ls_type,
542
543 tok2str(lsa_opaque_values,
544 "unknown",
545 GET_U_1(lshp->un_lsa_id.opaque_field.opaque_type)),
546 GET_U_1(lshp->un_lsa_id.opaque_field.opaque_type),
547 GET_BE_U_3(lshp->un_lsa_id.opaque_field.opaque_id)
548
549 );
550 break;
551
552 /* all other LSA types use regular style LSA headers */
553 default:
554 ND_PRINT("\n\t %s LSA (%u), LSA-ID: %s",
555 tok2str(lsa_values,"unknown",ls_type),
556 ls_type,
557 GET_IPADDR_STRING(lshp->un_lsa_id.lsa_id));
558 break;
559 }
560
561 ND_TCHECK_1(lshp->ls_options); /* XXX - ls_length check checked this */
562 ND_PRINT("\n\t Options: [%s]",
563 bittok2str(ospf_option_values, "none", GET_U_1(lshp->ls_options)));
564
565 return (ls_length);
566 trunc:
567 return (-1);
568 }
569
570 /* draft-ietf-ospf-mt-09 */
571 static const struct tok ospf_topology_values[] = {
572 { 0, "default" },
573 { 1, "multicast" },
574 { 2, "management" },
575 { 0, NULL }
576 };
577
578 /*
579 * Print all the per-topology metrics.
580 */
581 static int
582 ospf_print_tos_metrics(netdissect_options *ndo,
583 const union un_tos *tos)
584 {
585 u_int metric_count;
586 u_int toscount;
587 u_int tos_type;
588
589 toscount = GET_U_1(tos->link.link_tos_count)+1;
590 metric_count = 0;
591
592 /*
593 * All but the first metric contain a valid topology id.
594 */
595 while (toscount != 0) {
596 ND_TCHECK_SIZE(tos);
597 tos_type = GET_U_1(tos->metrics.tos_type);
598 ND_PRINT("\n\t\ttopology %s (%u), metric %u",
599 tok2str(ospf_topology_values, "Unknown",
600 metric_count ? tos_type : 0),
601 metric_count ? tos_type : 0,
602 GET_BE_U_2(tos->metrics.tos_metric));
603 metric_count++;
604 tos++;
605 toscount--;
606 }
607 return 0;
608 trunc:
609 return 1;
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 int j, tlv_type, tlv_length, topology;
628 int ls_length;
629 const uint8_t *tptr;
630
631 tptr = (const uint8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
632 ls_length = ospf_print_lshdr(ndo, &lsap->ls_hdr);
633 if (ls_length == -1)
634 return(NULL);
635 ls_end = (const uint8_t *)lsap + ls_length;
636 ls_length -= sizeof(struct lsa_hdr);
637
638 switch (GET_U_1(lsap->ls_hdr.ls_type)) {
639
640 case LS_TYPE_ROUTER:
641 ND_TCHECK_1(lsap->lsa_un.un_rla.rla_flags);
642 ND_PRINT("\n\t Router LSA Options: [%s]",
643 bittok2str(ospf_rla_flag_values, "none", GET_U_1(lsap->lsa_un.un_rla.rla_flags)));
644
645 ND_TCHECK_2(lsap->lsa_un.un_rla.rla_count);
646 j = GET_BE_U_2(lsap->lsa_un.un_rla.rla_count);
647 ND_TCHECK_SIZE(lsap->lsa_un.un_rla.rla_link);
648 rlp = lsap->lsa_un.un_rla.rla_link;
649 while (j--) {
650 ND_TCHECK_SIZE(rlp);
651 switch (GET_U_1(rlp->un_tos.link.link_type)) {
652
653 case RLA_TYPE_VIRTUAL:
654 ND_PRINT("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
655 GET_IPADDR_STRING(rlp->link_id),
656 GET_IPADDR_STRING(rlp->link_data));
657 break;
658
659 case RLA_TYPE_ROUTER:
660 ND_PRINT("\n\t Neighbor Router-ID: %s, Interface Address: %s",
661 GET_IPADDR_STRING(rlp->link_id),
662 GET_IPADDR_STRING(rlp->link_data));
663 break;
664
665 case RLA_TYPE_TRANSIT:
666 ND_PRINT("\n\t Neighbor Network-ID: %s, Interface Address: %s",
667 GET_IPADDR_STRING(rlp->link_id),
668 GET_IPADDR_STRING(rlp->link_data));
669 break;
670
671 case RLA_TYPE_STUB:
672 ND_PRINT("\n\t Stub Network: %s, Mask: %s",
673 GET_IPADDR_STRING(rlp->link_id),
674 GET_IPADDR_STRING(rlp->link_data));
675 break;
676
677 default:
678 ND_PRINT("\n\t Unknown Router Link Type (%u)",
679 GET_U_1(rlp->un_tos.link.link_type));
680 return (ls_end);
681 }
682
683 if (ospf_print_tos_metrics(ndo, &rlp->un_tos))
684 goto trunc;
685
686 rlp = (const struct rlalink *)((const u_char *)(rlp + 1) +
687 (GET_U_1(rlp->un_tos.link.link_tos_count) * sizeof(union un_tos)));
688 }
689 break;
690
691 case LS_TYPE_NETWORK:
692 ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
693 ND_PRINT("\n\t Mask %s\n\t Connected Routers:",
694 GET_IPADDR_STRING(lsap->lsa_un.un_nla.nla_mask));
695 ap = lsap->lsa_un.un_nla.nla_router;
696 while ((const u_char *)ap < ls_end) {
697 ND_TCHECK_SIZE(ap);
698 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap));
699 ++ap;
700 }
701 break;
702
703 case LS_TYPE_SUM_IP:
704 ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
705 ND_PRINT("\n\t Mask %s",
706 GET_IPADDR_STRING(lsap->lsa_un.un_sla.sla_mask));
707 ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric);
708 lp = (const uint8_t *)lsap->lsa_un.un_sla.sla_tosmetric;
709 while (lp < ls_end) {
710 uint32_t ul;
711
712 ND_TCHECK_4(lp);
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 ND_TCHECK_4(lp);
730 ul = GET_BE_U_4(lp);
731 topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
732 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
733 tok2str(ospf_topology_values, "Unknown", topology),
734 topology,
735 ul & SLA_MASK_METRIC);
736 lp += 4;
737 }
738 break;
739
740 case LS_TYPE_ASE:
741 case LS_TYPE_NSSA: /* fall through - those LSAs share the same format */
742 ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
743 ND_PRINT("\n\t Mask %s",
744 GET_IPADDR_STRING(lsap->lsa_un.un_asla.asla_mask));
745
746 ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric);
747 almp = lsap->lsa_un.un_asla.asla_metric;
748 while ((const u_char *)almp < ls_end) {
749 uint32_t ul;
750
751 ND_TCHECK_4(almp->asla_tosmetric);
752 ul = GET_BE_U_4(almp->asla_tosmetric);
753 topology = ((ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
754 ND_PRINT("\n\t\ttopology %s (%u), type %u, metric",
755 tok2str(ospf_topology_values, "Unknown", topology),
756 topology,
757 (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1);
758 if ((ul & ASLA_MASK_METRIC) == 0xffffff)
759 ND_PRINT(" infinite");
760 else
761 ND_PRINT(" %u", (ul & ASLA_MASK_METRIC));
762
763 ND_TCHECK_4(almp->asla_forward);
764 if (GET_IPV4_TO_NETWORK_ORDER(almp->asla_forward) != 0) {
765 ND_PRINT(", forward %s", GET_IPADDR_STRING(almp->asla_forward));
766 }
767 ND_TCHECK_4(almp->asla_tag);
768 if (GET_IPV4_TO_NETWORK_ORDER(almp->asla_tag) != 0) {
769 ND_PRINT(", tag %s", GET_IPADDR_STRING(almp->asla_tag));
770 }
771 ++almp;
772 }
773 break;
774
775 case LS_TYPE_GROUP:
776 /* Multicast extensions as of 23 July 1991 */
777 mcp = lsap->lsa_un.un_mcla;
778 while ((const u_char *)mcp < ls_end) {
779 ND_TCHECK_4(mcp->mcla_vid);
780 switch (GET_BE_U_4(mcp->mcla_vtype)) {
781
782 case MCLA_VERTEX_ROUTER:
783 ND_PRINT("\n\t Router Router-ID %s",
784 GET_IPADDR_STRING(mcp->mcla_vid));
785 break;
786
787 case MCLA_VERTEX_NETWORK:
788 ND_PRINT("\n\t Network Designated Router %s",
789 GET_IPADDR_STRING(mcp->mcla_vid));
790 break;
791
792 default:
793 ND_PRINT("\n\t unknown VertexType (%u)",
794 GET_BE_U_4(mcp->mcla_vtype));
795 break;
796 }
797 ++mcp;
798 }
799 break;
800
801 case LS_TYPE_OPAQUE_LL: /* fall through */
802 case LS_TYPE_OPAQUE_AL:
803 case LS_TYPE_OPAQUE_DW:
804
805 switch (GET_U_1(lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
806 case LS_OPAQUE_TYPE_RI:
807 tptr = (const uint8_t *)(lsap->lsa_un.un_ri_tlv);
808
809 int ls_length_remaining = ls_length;
810 while (ls_length_remaining != 0) {
811 ND_TCHECK_4(tptr);
812 if (ls_length_remaining < 4) {
813 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length_remaining);
814 return(ls_end);
815 }
816 tlv_type = GET_BE_U_2(tptr);
817 tlv_length = GET_BE_U_2(tptr + 2);
818 tptr+=4;
819 ls_length_remaining-=4;
820
821 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
822 tok2str(lsa_opaque_ri_tlv_values,"unknown",tlv_type),
823 tlv_type,
824 tlv_length);
825
826 if (tlv_length > ls_length_remaining) {
827 ND_PRINT("\n\t Bogus length %u > remaining LS length %u", tlv_length,
828 ls_length_remaining);
829 return(ls_end);
830 }
831 ND_TCHECK_LEN(tptr, tlv_length);
832 switch(tlv_type) {
833
834 case LS_OPAQUE_RI_TLV_CAP:
835 if (tlv_length != 4) {
836 ND_PRINT("\n\t Bogus length %u != 4", tlv_length);
837 return(ls_end);
838 }
839 ND_PRINT("Capabilities: %s",
840 bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", GET_BE_U_4(tptr)));
841 break;
842 default:
843 if (ndo->ndo_vflag <= 1) {
844 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
845 return(ls_end);
846 }
847 break;
848
849 }
850 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 int
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 (0);
906 break;
907
908 case OSPF_TYPE_DD:
909 if (!(GET_U_1(op->ospf_db.db_options) & OSPF_OPTION_L))
910 return (0);
911 break;
912
913 default:
914 return (0);
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 + op->ospf_authdata[3];
924 length2 += op->ospf_authdata[3];
925 }
926 if (length2 >= length) {
927 ND_PRINT("\n\t[LLS truncated]");
928 return (1);
929 }
930 ND_TCHECK_2(dptr);
931 ND_PRINT("\n\t LLS: checksum: 0x%04x", (u_int) GET_BE_U_2(dptr));
932
933 dptr += 2;
934 ND_TCHECK_2(dptr);
935 length2 = GET_BE_U_2(dptr);
936 ND_PRINT(", length: %u", length2);
937
938 dptr += 2;
939 ND_TCHECK_1(dptr);
940 while (dptr < dataend) {
941 ND_TCHECK_2(dptr);
942 lls_type = GET_BE_U_2(dptr);
943 ND_PRINT("\n\t %s (%u)",
944 tok2str(ospf_lls_tlv_values,"Unknown TLV",lls_type),
945 lls_type);
946 dptr += 2;
947 ND_TCHECK_2(dptr);
948 lls_len = GET_BE_U_2(dptr);
949 ND_PRINT(", length: %u", lls_len);
950 dptr += 2;
951 switch (lls_type) {
952
953 case OSPF_LLS_EO:
954 if (lls_len != 4) {
955 ND_PRINT(" [should be 4]");
956 lls_len = 4;
957 }
958 ND_TCHECK_4(dptr);
959 lls_flags = GET_BE_U_4(dptr);
960 ND_PRINT("\n\t Options: 0x%08x [%s]", lls_flags,
961 bittok2str(ospf_lls_eo_options, "?", lls_flags));
962
963 break;
964
965 case OSPF_LLS_MD5:
966 if (lls_len != 20) {
967 ND_PRINT(" [should be 20]");
968 lls_len = 20;
969 }
970 ND_TCHECK_4(dptr);
971 ND_PRINT("\n\t Sequence number: 0x%08x", GET_BE_U_4(dptr));
972 break;
973 }
974
975 dptr += lls_len;
976 }
977
978 return (0);
979 trunc:
980 return (1);
981 }
982
983 static int
984 ospf_decode_v2(netdissect_options *ndo,
985 const struct ospfhdr *op, const u_char *dataend)
986 {
987 const nd_ipv4 *ap;
988 const struct lsr *lsrp;
989 const struct lsa_hdr *lshp;
990 const struct lsa *lsap;
991 uint32_t lsa_count,lsa_count_max;
992
993 switch (GET_U_1(op->ospf_type)) {
994
995 case OSPF_TYPE_HELLO:
996 ND_TCHECK_1(op->ospf_hello.hello_options);
997 ND_PRINT("\n\tOptions [%s]",
998 bittok2str(ospf_option_values,"none",GET_U_1(op->ospf_hello.hello_options)));
999
1000 ND_TCHECK_4(op->ospf_hello.hello_deadint);
1001 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
1002 GET_BE_U_2(op->ospf_hello.hello_helloint),
1003 GET_BE_U_4(op->ospf_hello.hello_deadint),
1004 GET_IPADDR_STRING(op->ospf_hello.hello_mask),
1005 GET_U_1(op->ospf_hello.hello_priority));
1006
1007 ND_TCHECK_4(op->ospf_hello.hello_dr);
1008 if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_dr) != 0)
1009 ND_PRINT("\n\t Designated Router %s",
1010 GET_IPADDR_STRING(op->ospf_hello.hello_dr));
1011
1012 ND_TCHECK_4(op->ospf_hello.hello_bdr);
1013 if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_bdr) != 0)
1014 ND_PRINT(", Backup Designated Router %s",
1015 GET_IPADDR_STRING(op->ospf_hello.hello_bdr));
1016
1017 ap = op->ospf_hello.hello_neighbor;
1018 if ((const u_char *)ap < dataend)
1019 ND_PRINT("\n\t Neighbor List:");
1020 while ((const u_char *)ap < dataend) {
1021 ND_TCHECK_SIZE(ap);
1022 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap));
1023 ++ap;
1024 }
1025 break; /* HELLO */
1026
1027 case OSPF_TYPE_DD:
1028 ND_TCHECK_1(op->ospf_db.db_options);
1029 ND_PRINT("\n\tOptions [%s]",
1030 bittok2str(ospf_option_values, "none", GET_U_1(op->ospf_db.db_options)));
1031 ND_TCHECK_1(op->ospf_db.db_flags);
1032 ND_PRINT(", DD Flags [%s]",
1033 bittok2str(ospf_dd_flag_values, "none", GET_U_1(op->ospf_db.db_flags)));
1034 ND_TCHECK_2(op->ospf_db.db_ifmtu);
1035 if (GET_BE_U_2(op->ospf_db.db_ifmtu)) {
1036 ND_PRINT(", MTU: %u",
1037 GET_BE_U_2(op->ospf_db.db_ifmtu));
1038 }
1039 ND_TCHECK_4(op->ospf_db.db_seq);
1040 ND_PRINT(", Sequence: 0x%08x", GET_BE_U_4(op->ospf_db.db_seq));
1041
1042 /* Print all the LS adv's */
1043 lshp = op->ospf_db.db_lshdr;
1044 while (((const u_char *)lshp < dataend) && ospf_print_lshdr(ndo, lshp) != -1) {
1045 ++lshp;
1046 }
1047 break;
1048
1049 case OSPF_TYPE_LS_REQ:
1050 lsrp = op->ospf_lsr;
1051 while ((const u_char *)lsrp < dataend) {
1052 ND_TCHECK_SIZE(lsrp);
1053
1054 ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)",
1055 GET_IPADDR_STRING(lsrp->ls_router),
1056 tok2str(lsa_values,"unknown",GET_BE_U_4(lsrp->ls_type)),
1057 GET_BE_U_4(lsrp->ls_type));
1058
1059 switch (GET_BE_U_4(lsrp->ls_type)) {
1060 /* the LSA header for opaque LSAs was slightly changed */
1061 case LS_TYPE_OPAQUE_LL:
1062 case LS_TYPE_OPAQUE_AL:
1063 case LS_TYPE_OPAQUE_DW:
1064 ND_PRINT(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1065 tok2str(lsa_opaque_values, "unknown",GET_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type)),
1066 GET_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type),
1067 GET_BE_U_3(lsrp->un_ls_stateid.opaque_field.opaque_id));
1068 break;
1069 default:
1070 ND_PRINT(", LSA-ID: %s",
1071 GET_IPADDR_STRING(lsrp->un_ls_stateid.ls_stateid));
1072 break;
1073 }
1074
1075 ++lsrp;
1076 }
1077 break;
1078
1079 case OSPF_TYPE_LS_UPDATE:
1080 lsap = op->ospf_lsu.lsu_lsa;
1081 ND_TCHECK_4(op->ospf_lsu.lsu_count);
1082 lsa_count_max = GET_BE_U_4(op->ospf_lsu.lsu_count);
1083 ND_PRINT(", %u LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max));
1084 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
1085 ND_PRINT("\n\t LSA #%u", lsa_count);
1086 lsap = (const struct lsa *)ospf_print_lsa(ndo, lsap);
1087 if (lsap == NULL)
1088 goto trunc;
1089 }
1090 break;
1091
1092 case OSPF_TYPE_LS_ACK:
1093 lshp = op->ospf_lsa.lsa_lshdr;
1094 while (ospf_print_lshdr(ndo, lshp) != -1) {
1095 ++lshp;
1096 }
1097 break;
1098
1099 default:
1100 break;
1101 }
1102 return (0);
1103 trunc:
1104 return (1);
1105 }
1106
1107 void
1108 ospf_print(netdissect_options *ndo,
1109 const u_char *bp, u_int length,
1110 const u_char *bp2 _U_)
1111 {
1112 const struct ospfhdr *op;
1113 const u_char *dataend;
1114 const char *cp;
1115
1116 ndo->ndo_protocol = "ospf2";
1117 op = (const struct ospfhdr *)bp;
1118
1119 /* XXX Before we do anything else, strip off the MD5 trailer */
1120 ND_TCHECK_2(op->ospf_authtype);
1121 if (GET_BE_U_2(op->ospf_authtype) == OSPF_AUTH_MD5) {
1122 length -= OSPF_AUTH_MD5_LEN;
1123 ndo->ndo_snapend -= OSPF_AUTH_MD5_LEN;
1124 }
1125
1126 /* If the type is valid translate it, or just print the type */
1127 /* value. If it's not valid, say so and return */
1128 ND_TCHECK_1(op->ospf_type);
1129 cp = tok2str(type2str, "unknown LS-type %u", GET_U_1(op->ospf_type));
1130 ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op->ospf_version), cp,
1131 length);
1132 if (*cp == 'u')
1133 return;
1134
1135 if (!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
1136 return;
1137 }
1138
1139 ND_TCHECK_2(op->ospf_len);
1140 if (length != GET_BE_U_2(op->ospf_len)) {
1141 ND_PRINT(" [len %u]", GET_BE_U_2(op->ospf_len));
1142 }
1143
1144 if (length > GET_BE_U_2(op->ospf_len)) {
1145 dataend = bp + GET_BE_U_2(op->ospf_len);
1146 } else {
1147 dataend = bp + length;
1148 }
1149
1150 ND_TCHECK_4(op->ospf_routerid);
1151 ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op->ospf_routerid));
1152
1153 ND_TCHECK_4(op->ospf_areaid);
1154 if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_areaid) != 0)
1155 ND_PRINT(", Area %s", GET_IPADDR_STRING(op->ospf_areaid));
1156 else
1157 ND_PRINT(", Backbone Area");
1158
1159 if (ndo->ndo_vflag) {
1160 /* Print authentication data (should we really do this?) */
1161 ND_TCHECK_LEN(op->ospf_authdata, sizeof(op->ospf_authdata));
1162
1163 ND_PRINT(", Authentication Type: %s (%u)",
1164 tok2str(ospf_authtype_values, "unknown", GET_BE_U_2(op->ospf_authtype)),
1165 GET_BE_U_2(op->ospf_authtype));
1166
1167 switch (GET_BE_U_2(op->ospf_authtype)) {
1168
1169 case OSPF_AUTH_NONE:
1170 break;
1171
1172 case OSPF_AUTH_SIMPLE:
1173 ND_PRINT("\n\tSimple text password: ");
1174 (void)nd_printzp(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN, NULL);
1175 break;
1176
1177 case OSPF_AUTH_MD5:
1178 ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1179 *((op->ospf_authdata) + 2),
1180 *((op->ospf_authdata) + 3),
1181 GET_BE_U_4((op->ospf_authdata) + 4));
1182 break;
1183
1184 default:
1185 return;
1186 }
1187 }
1188 /* Do rest according to version. */
1189 switch (GET_U_1(op->ospf_version)) {
1190
1191 case 2:
1192 /* ospf version 2 */
1193 if (ospf_decode_v2(ndo, op, dataend))
1194 goto trunc;
1195 if (length > GET_BE_U_2(op->ospf_len)) {
1196 if (ospf_decode_lls(ndo, op, length))
1197 goto trunc;
1198 }
1199 break;
1200
1201 default:
1202 ND_PRINT(" ospf [version %u]", GET_U_1(op->ospf_version));
1203 break;
1204 } /* end switch on version */
1205
1206 return;
1207 trunc:
1208 nd_print_trunc(ndo);
1209 }