]> The Tcpdump Group git mirrors - tcpdump/blob - print-ospf.c
Merge pull request #492 from vel21ripn/nflog-print
[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 while (ls_length != 0) {
810 ND_TCHECK_4(tptr);
811 if (ls_length < 4) {
812 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length);
813 return(ls_end);
814 }
815 tlv_type = GET_BE_U_2(tptr);
816 tlv_length = GET_BE_U_2(tptr + 2);
817 tptr+=4;
818 ls_length-=4;
819
820 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
821 tok2str(lsa_opaque_ri_tlv_values,"unknown",tlv_type),
822 tlv_type,
823 tlv_length);
824
825 if (tlv_length > ls_length) {
826 ND_PRINT("\n\t Bogus length %u > %u", tlv_length,
827 ls_length);
828 return(ls_end);
829 }
830 ND_TCHECK_LEN(tptr, tlv_length);
831 switch(tlv_type) {
832
833 case LS_OPAQUE_RI_TLV_CAP:
834 if (tlv_length != 4) {
835 ND_PRINT("\n\t Bogus length %u != 4", tlv_length);
836 return(ls_end);
837 }
838 ND_PRINT("Capabilities: %s",
839 bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", GET_BE_U_4(tptr)));
840 break;
841 default:
842 if (ndo->ndo_vflag <= 1) {
843 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
844 return(ls_end);
845 }
846 break;
847
848 }
849 tptr+=tlv_length;
850 ls_length-=tlv_length;
851 }
852 break;
853
854 case LS_OPAQUE_TYPE_GRACE:
855 if (ospf_grace_lsa_print(ndo, (const u_char *)(lsap->lsa_un.un_grace_tlv),
856 ls_length) == -1) {
857 return(ls_end);
858 }
859 break;
860
861 case LS_OPAQUE_TYPE_TE:
862 if (ospf_te_lsa_print(ndo, (const u_char *)(lsap->lsa_un.un_te_lsa_tlv),
863 ls_length) == -1) {
864 return(ls_end);
865 }
866 break;
867
868 default:
869 if (ndo->ndo_vflag <= 1) {
870 if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
871 "\n\t ", ls_length))
872 return(ls_end);
873 }
874 break;
875 }
876 }
877
878 /* do we want to see an additionally hexdump ? */
879 if (ndo->ndo_vflag> 1)
880 if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
881 "\n\t ", ls_length)) {
882 return(ls_end);
883 }
884
885 return (ls_end);
886 trunc:
887 return (NULL);
888 }
889
890 static int
891 ospf_decode_lls(netdissect_options *ndo,
892 const struct ospfhdr *op, u_int length)
893 {
894 const u_char *dptr;
895 const u_char *dataend;
896 u_int length2;
897 uint16_t lls_type, lls_len;
898 uint32_t lls_flags;
899
900 switch (GET_U_1(op->ospf_type)) {
901
902 case OSPF_TYPE_HELLO:
903 if (!(GET_U_1(op->ospf_hello.hello_options) & OSPF_OPTION_L))
904 return (0);
905 break;
906
907 case OSPF_TYPE_DD:
908 if (!(GET_U_1(op->ospf_db.db_options) & OSPF_OPTION_L))
909 return (0);
910 break;
911
912 default:
913 return (0);
914 }
915
916 /* dig deeper if LLS data is available; see RFC4813 */
917 length2 = GET_BE_U_2(op->ospf_len);
918 dptr = (const u_char *)op + length2;
919 dataend = (const u_char *)op + length;
920
921 if (GET_BE_U_2(op->ospf_authtype) == OSPF_AUTH_MD5) {
922 dptr = dptr + op->ospf_authdata[3];
923 length2 += op->ospf_authdata[3];
924 }
925 if (length2 >= length) {
926 ND_PRINT("\n\t[LLS truncated]");
927 return (1);
928 }
929 ND_TCHECK_2(dptr);
930 ND_PRINT("\n\t LLS: checksum: 0x%04x", (u_int) GET_BE_U_2(dptr));
931
932 dptr += 2;
933 ND_TCHECK_2(dptr);
934 length2 = GET_BE_U_2(dptr);
935 ND_PRINT(", length: %u", length2);
936
937 dptr += 2;
938 ND_TCHECK_1(dptr);
939 while (dptr < dataend) {
940 ND_TCHECK_2(dptr);
941 lls_type = GET_BE_U_2(dptr);
942 ND_PRINT("\n\t %s (%u)",
943 tok2str(ospf_lls_tlv_values,"Unknown TLV",lls_type),
944 lls_type);
945 dptr += 2;
946 ND_TCHECK_2(dptr);
947 lls_len = GET_BE_U_2(dptr);
948 ND_PRINT(", length: %u", lls_len);
949 dptr += 2;
950 switch (lls_type) {
951
952 case OSPF_LLS_EO:
953 if (lls_len != 4) {
954 ND_PRINT(" [should be 4]");
955 lls_len = 4;
956 }
957 ND_TCHECK_4(dptr);
958 lls_flags = GET_BE_U_4(dptr);
959 ND_PRINT("\n\t Options: 0x%08x [%s]", lls_flags,
960 bittok2str(ospf_lls_eo_options, "?", lls_flags));
961
962 break;
963
964 case OSPF_LLS_MD5:
965 if (lls_len != 20) {
966 ND_PRINT(" [should be 20]");
967 lls_len = 20;
968 }
969 ND_TCHECK_4(dptr);
970 ND_PRINT("\n\t Sequence number: 0x%08x", GET_BE_U_4(dptr));
971 break;
972 }
973
974 dptr += lls_len;
975 }
976
977 return (0);
978 trunc:
979 return (1);
980 }
981
982 static int
983 ospf_decode_v2(netdissect_options *ndo,
984 const struct ospfhdr *op, const u_char *dataend)
985 {
986 const nd_ipv4 *ap;
987 const struct lsr *lsrp;
988 const struct lsa_hdr *lshp;
989 const struct lsa *lsap;
990 uint32_t lsa_count,lsa_count_max;
991
992 switch (GET_U_1(op->ospf_type)) {
993
994 case OSPF_TYPE_HELLO:
995 ND_TCHECK_1(op->ospf_hello.hello_options);
996 ND_PRINT("\n\tOptions [%s]",
997 bittok2str(ospf_option_values,"none",GET_U_1(op->ospf_hello.hello_options)));
998
999 ND_TCHECK_4(op->ospf_hello.hello_deadint);
1000 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
1001 GET_BE_U_2(op->ospf_hello.hello_helloint),
1002 GET_BE_U_4(op->ospf_hello.hello_deadint),
1003 GET_IPADDR_STRING(op->ospf_hello.hello_mask),
1004 GET_U_1(op->ospf_hello.hello_priority));
1005
1006 ND_TCHECK_4(op->ospf_hello.hello_dr);
1007 if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_dr) != 0)
1008 ND_PRINT("\n\t Designated Router %s",
1009 GET_IPADDR_STRING(op->ospf_hello.hello_dr));
1010
1011 ND_TCHECK_4(op->ospf_hello.hello_bdr);
1012 if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_bdr) != 0)
1013 ND_PRINT(", Backup Designated Router %s",
1014 GET_IPADDR_STRING(op->ospf_hello.hello_bdr));
1015
1016 ap = op->ospf_hello.hello_neighbor;
1017 if ((const u_char *)ap < dataend)
1018 ND_PRINT("\n\t Neighbor List:");
1019 while ((const u_char *)ap < dataend) {
1020 ND_TCHECK_SIZE(ap);
1021 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap));
1022 ++ap;
1023 }
1024 break; /* HELLO */
1025
1026 case OSPF_TYPE_DD:
1027 ND_TCHECK_1(op->ospf_db.db_options);
1028 ND_PRINT("\n\tOptions [%s]",
1029 bittok2str(ospf_option_values, "none", GET_U_1(op->ospf_db.db_options)));
1030 ND_TCHECK_1(op->ospf_db.db_flags);
1031 ND_PRINT(", DD Flags [%s]",
1032 bittok2str(ospf_dd_flag_values, "none", GET_U_1(op->ospf_db.db_flags)));
1033 ND_TCHECK_2(op->ospf_db.db_ifmtu);
1034 if (GET_BE_U_2(op->ospf_db.db_ifmtu)) {
1035 ND_PRINT(", MTU: %u",
1036 GET_BE_U_2(op->ospf_db.db_ifmtu));
1037 }
1038 ND_TCHECK_4(op->ospf_db.db_seq);
1039 ND_PRINT(", Sequence: 0x%08x", GET_BE_U_4(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_SIZE(lsrp);
1052
1053 ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)",
1054 GET_IPADDR_STRING(lsrp->ls_router),
1055 tok2str(lsa_values,"unknown",GET_BE_U_4(lsrp->ls_type)),
1056 GET_BE_U_4(lsrp->ls_type));
1057
1058 switch (GET_BE_U_4(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(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1064 tok2str(lsa_opaque_values, "unknown",GET_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type)),
1065 GET_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type),
1066 GET_BE_U_3(lsrp->un_ls_stateid.opaque_field.opaque_id));
1067 break;
1068 default:
1069 ND_PRINT(", LSA-ID: %s",
1070 GET_IPADDR_STRING(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_4(op->ospf_lsu.lsu_count);
1081 lsa_count_max = GET_BE_U_4(op->ospf_lsu.lsu_count);
1082 ND_PRINT(", %u 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("\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 const u_char *bp, u_int length,
1109 const u_char *bp2 _U_)
1110 {
1111 const struct ospfhdr *op;
1112 const u_char *dataend;
1113 const char *cp;
1114
1115 ndo->ndo_protocol = "ospf2";
1116 op = (const struct ospfhdr *)bp;
1117
1118 /* XXX Before we do anything else, strip off the MD5 trailer */
1119 ND_TCHECK_2(op->ospf_authtype);
1120 if (GET_BE_U_2(op->ospf_authtype) == OSPF_AUTH_MD5) {
1121 length -= OSPF_AUTH_MD5_LEN;
1122 ndo->ndo_snapend -= OSPF_AUTH_MD5_LEN;
1123 }
1124
1125 /* If the type is valid translate it, or just print the type */
1126 /* value. If it's not valid, say so and return */
1127 ND_TCHECK_1(op->ospf_type);
1128 cp = tok2str(type2str, "unknown LS-type %u", GET_U_1(op->ospf_type));
1129 ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op->ospf_version), cp,
1130 length);
1131 if (*cp == 'u')
1132 return;
1133
1134 if (!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
1135 return;
1136 }
1137
1138 ND_TCHECK_2(op->ospf_len);
1139 if (length != GET_BE_U_2(op->ospf_len)) {
1140 ND_PRINT(" [len %u]", GET_BE_U_2(op->ospf_len));
1141 }
1142
1143 if (length > GET_BE_U_2(op->ospf_len)) {
1144 dataend = bp + GET_BE_U_2(op->ospf_len);
1145 } else {
1146 dataend = bp + length;
1147 }
1148
1149 ND_TCHECK_4(op->ospf_routerid);
1150 ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op->ospf_routerid));
1151
1152 ND_TCHECK_4(op->ospf_areaid);
1153 if (GET_IPV4_TO_NETWORK_ORDER(op->ospf_areaid) != 0)
1154 ND_PRINT(", Area %s", GET_IPADDR_STRING(op->ospf_areaid));
1155 else
1156 ND_PRINT(", Backbone Area");
1157
1158 if (ndo->ndo_vflag) {
1159 /* Print authentication data (should we really do this?) */
1160 ND_TCHECK_LEN(op->ospf_authdata, sizeof(op->ospf_authdata));
1161
1162 ND_PRINT(", Authentication Type: %s (%u)",
1163 tok2str(ospf_authtype_values, "unknown", GET_BE_U_2(op->ospf_authtype)),
1164 GET_BE_U_2(op->ospf_authtype));
1165
1166 switch (GET_BE_U_2(op->ospf_authtype)) {
1167
1168 case OSPF_AUTH_NONE:
1169 break;
1170
1171 case OSPF_AUTH_SIMPLE:
1172 ND_PRINT("\n\tSimple text password: ");
1173 (void)nd_printzp(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN, NULL);
1174 break;
1175
1176 case OSPF_AUTH_MD5:
1177 ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1178 *((op->ospf_authdata) + 2),
1179 *((op->ospf_authdata) + 3),
1180 GET_BE_U_4((op->ospf_authdata) + 4));
1181 break;
1182
1183 default:
1184 return;
1185 }
1186 }
1187 /* Do rest according to version. */
1188 switch (GET_U_1(op->ospf_version)) {
1189
1190 case 2:
1191 /* ospf version 2 */
1192 if (ospf_decode_v2(ndo, op, dataend))
1193 goto trunc;
1194 if (length > GET_BE_U_2(op->ospf_len)) {
1195 if (ospf_decode_lls(ndo, op, length))
1196 goto trunc;
1197 }
1198 break;
1199
1200 default:
1201 ND_PRINT(" ospf [version %u]", GET_U_1(op->ospf_version));
1202 break;
1203 } /* end switch on version */
1204
1205 return;
1206 trunc:
1207 nd_print_trunc(ndo);
1208 }