]> The Tcpdump Group git mirrors - tcpdump/blob - print-ospf.c
Rename the fn_printX() functions to nd_printX()
[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 static const char tstr[] = " [|ospf2]";
40
41 static const struct tok ospf_option_values[] = {
42 { OSPF_OPTION_T, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
43 { OSPF_OPTION_E, "External" },
44 { OSPF_OPTION_MC, "Multicast" },
45 { OSPF_OPTION_NP, "NSSA" },
46 { OSPF_OPTION_L, "LLS" },
47 { OSPF_OPTION_DC, "Demand Circuit" },
48 { OSPF_OPTION_O, "Opaque" },
49 { OSPF_OPTION_DN, "Up/Down" },
50 { 0, NULL }
51 };
52
53 static const struct tok ospf_authtype_values[] = {
54 { OSPF_AUTH_NONE, "none" },
55 { OSPF_AUTH_SIMPLE, "simple" },
56 { OSPF_AUTH_MD5, "MD5" },
57 { 0, NULL }
58 };
59
60 static const struct tok ospf_rla_flag_values[] = {
61 { RLA_FLAG_B, "ABR" },
62 { RLA_FLAG_E, "ASBR" },
63 { RLA_FLAG_W1, "Virtual" },
64 { RLA_FLAG_W2, "W2" },
65 { 0, NULL }
66 };
67
68 static const struct tok type2str[] = {
69 { OSPF_TYPE_HELLO, "Hello" },
70 { OSPF_TYPE_DD, "Database Description" },
71 { OSPF_TYPE_LS_REQ, "LS-Request" },
72 { OSPF_TYPE_LS_UPDATE, "LS-Update" },
73 { OSPF_TYPE_LS_ACK, "LS-Ack" },
74 { 0, NULL }
75 };
76
77 static const struct tok lsa_values[] = {
78 { LS_TYPE_ROUTER, "Router" },
79 { LS_TYPE_NETWORK, "Network" },
80 { LS_TYPE_SUM_IP, "Summary" },
81 { LS_TYPE_SUM_ABR, "ASBR Summary" },
82 { LS_TYPE_ASE, "External" },
83 { LS_TYPE_GROUP, "Multicast Group" },
84 { LS_TYPE_NSSA, "NSSA" },
85 { LS_TYPE_OPAQUE_LL, "Link Local Opaque" },
86 { LS_TYPE_OPAQUE_AL, "Area Local Opaque" },
87 { LS_TYPE_OPAQUE_DW, "Domain Wide Opaque" },
88 { 0, NULL }
89 };
90
91 static const struct tok ospf_dd_flag_values[] = {
92 { OSPF_DB_INIT, "Init" },
93 { OSPF_DB_MORE, "More" },
94 { OSPF_DB_MASTER, "Master" },
95 { OSPF_DB_RESYNC, "OOBResync" },
96 { 0, NULL }
97 };
98
99 static const struct tok lsa_opaque_values[] = {
100 { LS_OPAQUE_TYPE_TE, "Traffic Engineering" },
101 { LS_OPAQUE_TYPE_GRACE, "Graceful restart" },
102 { LS_OPAQUE_TYPE_RI, "Router Information" },
103 { 0, NULL }
104 };
105
106 static const struct tok lsa_opaque_te_tlv_values[] = {
107 { LS_OPAQUE_TE_TLV_ROUTER, "Router Address" },
108 { LS_OPAQUE_TE_TLV_LINK, "Link" },
109 { 0, NULL }
110 };
111
112 static const struct tok lsa_opaque_te_link_tlv_subtlv_values[] = {
113 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE, "Link Type" },
114 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID, "Link ID" },
115 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP, "Local Interface IP address" },
116 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP, "Remote Interface IP address" },
117 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC, "Traffic Engineering Metric" },
118 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW, "Maximum Bandwidth" },
119 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW, "Maximum Reservable Bandwidth" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW, "Unreserved Bandwidth" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP, "Administrative Group" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE, "Link Protection Type" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR, "Interface Switching Capability" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP, "Shared Risk Link Group" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS, "Bandwidth Constraints" },
127 { 0, NULL }
128 };
129
130 static const struct tok lsa_opaque_grace_tlv_values[] = {
131 { LS_OPAQUE_GRACE_TLV_PERIOD, "Grace Period" },
132 { LS_OPAQUE_GRACE_TLV_REASON, "Graceful restart Reason" },
133 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS, "IPv4 interface address" },
134 { 0, NULL }
135 };
136
137 static const struct tok lsa_opaque_grace_tlv_reason_values[] = {
138 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN, "Unknown" },
139 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART, "Software Restart" },
140 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE, "Software Reload/Upgrade" },
141 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH, "Control Processor Switch" },
142 { 0, NULL }
143 };
144
145 static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = {
146 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP, "Point-to-point" },
147 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA, "Multi-Access" },
148 { 0, NULL }
149 };
150
151 static const struct tok lsa_opaque_ri_tlv_values[] = {
152 { LS_OPAQUE_RI_TLV_CAP, "Router Capabilities" },
153 { 0, NULL }
154 };
155
156 static const struct tok lsa_opaque_ri_tlv_cap_values[] = {
157 { 1, "Reserved" },
158 { 2, "Reserved" },
159 { 4, "Reserved" },
160 { 8, "Reserved" },
161 { 16, "graceful restart capable" },
162 { 32, "graceful restart helper" },
163 { 64, "Stub router support" },
164 { 128, "Traffic engineering" },
165 { 256, "p2p over LAN" },
166 { 512, "path computation server" },
167 { 0, NULL }
168 };
169
170 static const struct tok ospf_lls_tlv_values[] = {
171 { OSPF_LLS_EO, "Extended Options" },
172 { OSPF_LLS_MD5, "MD5 Authentication" },
173 { 0, NULL }
174 };
175
176 static const struct tok ospf_lls_eo_options[] = {
177 { OSPF_LLS_EO_LR, "LSDB resync" },
178 { OSPF_LLS_EO_RS, "Restart" },
179 { 0, NULL }
180 };
181
182 int
183 ospf_grace_lsa_print(netdissect_options *ndo,
184 const u_char *tptr, u_int ls_length)
185 {
186 u_int tlv_type, tlv_length;
187
188
189 while (ls_length > 0) {
190 ND_TCHECK_4(tptr);
191 if (ls_length < 4) {
192 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length);
193 return -1;
194 }
195 tlv_type = EXTRACT_BE_U_2(tptr);
196 tlv_length = EXTRACT_BE_U_2(tptr + 2);
197 tptr+=4;
198 ls_length-=4;
199
200 ND_PRINT("\n\t %s TLV (%u), length %u, value: ",
201 tok2str(lsa_opaque_grace_tlv_values,"unknown",tlv_type),
202 tlv_type,
203 tlv_length);
204
205 if (tlv_length > ls_length) {
206 ND_PRINT("\n\t Bogus length %u > %u", tlv_length,
207 ls_length);
208 return -1;
209 }
210
211 /* Infinite loop protection. */
212 if (tlv_type == 0 || tlv_length ==0) {
213 return -1;
214 }
215
216 ND_TCHECK_LEN(tptr, tlv_length);
217 switch(tlv_type) {
218
219 case LS_OPAQUE_GRACE_TLV_PERIOD:
220 if (tlv_length != 4) {
221 ND_PRINT("\n\t Bogus length %u != 4", tlv_length);
222 return -1;
223 }
224 ND_PRINT("%us", EXTRACT_BE_U_4(tptr));
225 break;
226
227 case LS_OPAQUE_GRACE_TLV_REASON:
228 if (tlv_length != 1) {
229 ND_PRINT("\n\t Bogus length %u != 1", tlv_length);
230 return -1;
231 }
232 ND_PRINT("%s (%u)",
233 tok2str(lsa_opaque_grace_tlv_reason_values, "Unknown", EXTRACT_U_1(tptr)),
234 EXTRACT_U_1(tptr));
235 break;
236
237 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS:
238 if (tlv_length != 4) {
239 ND_PRINT("\n\t Bogus length %u != 4", tlv_length);
240 return -1;
241 }
242 ND_PRINT("%s", ipaddr_string(ndo, tptr));
243 break;
244
245 default:
246 if (ndo->ndo_vflag <= 1) {
247 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
248 return -1;
249 }
250 break;
251
252 }
253 /* in OSPF everything has to be 32-bit aligned, including TLVs */
254 if (tlv_length%4 != 0)
255 tlv_length+=4-(tlv_length%4);
256 ls_length-=tlv_length;
257 tptr+=tlv_length;
258 }
259
260 return 0;
261 trunc:
262 return -1;
263 }
264
265 int
266 ospf_te_lsa_print(netdissect_options *ndo,
267 const u_char *tptr, u_int ls_length)
268 {
269 u_int tlv_type, tlv_length, subtlv_type, subtlv_length;
270 u_int priority_level, te_class, count_srlg;
271 union { /* int to float conversion buffer for several subTLVs */
272 float f;
273 uint32_t i;
274 } bw;
275
276 while (ls_length != 0) {
277 ND_TCHECK_4(tptr);
278 if (ls_length < 4) {
279 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length);
280 return -1;
281 }
282 tlv_type = EXTRACT_BE_U_2(tptr);
283 tlv_length = EXTRACT_BE_U_2(tptr + 2);
284 tptr+=4;
285 ls_length-=4;
286
287 ND_PRINT("\n\t %s TLV (%u), length: %u",
288 tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type),
289 tlv_type,
290 tlv_length);
291
292 if (tlv_length > ls_length) {
293 ND_PRINT("\n\t Bogus length %u > %u", tlv_length,
294 ls_length);
295 return -1;
296 }
297
298 /* Infinite loop protection. */
299 if (tlv_type == 0 || tlv_length ==0) {
300 return -1;
301 }
302
303 switch(tlv_type) {
304 case LS_OPAQUE_TE_TLV_LINK:
305 while (tlv_length >= sizeof(subtlv_type) + sizeof(subtlv_length)) {
306 if (tlv_length < 4) {
307 ND_PRINT("\n\t Remaining TLV length %u < 4",
308 tlv_length);
309 return -1;
310 }
311 ND_TCHECK_4(tptr);
312 subtlv_type = EXTRACT_BE_U_2(tptr);
313 subtlv_length = EXTRACT_BE_U_2(tptr + 2);
314 tptr+=4;
315 tlv_length-=4;
316
317 /* Infinite loop protection */
318 if (subtlv_type == 0 || subtlv_length == 0)
319 goto invalid;
320
321 ND_PRINT("\n\t %s subTLV (%u), length: %u",
322 tok2str(lsa_opaque_te_link_tlv_subtlv_values,"unknown",subtlv_type),
323 subtlv_type,
324 subtlv_length);
325
326 ND_TCHECK_LEN(tptr, subtlv_length);
327 switch(subtlv_type) {
328 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
329 if (subtlv_length != 4) {
330 ND_PRINT(" != 4");
331 goto invalid;
332 }
333 ND_PRINT(", 0x%08x", EXTRACT_BE_U_4(tptr));
334 break;
335 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID:
336 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID:
337 if (subtlv_length != 4 && subtlv_length != 8) {
338 ND_PRINT(" != 4 && != 8");
339 goto invalid;
340 }
341 ND_PRINT(", %s (0x%08x)",
342 ipaddr_string(ndo, tptr),
343 EXTRACT_BE_U_4(tptr));
344 if (subtlv_length == 8) /* rfc4203 */
345 ND_PRINT(", %s (0x%08x)",
346 ipaddr_string(ndo, tptr+4),
347 EXTRACT_BE_U_4(tptr + 4));
348 break;
349 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP:
350 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP:
351 if (subtlv_length != 4) {
352 ND_PRINT(" != 4");
353 goto invalid;
354 }
355 ND_PRINT(", %s", ipaddr_string(ndo, tptr));
356 break;
357 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
358 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
359 if (subtlv_length != 4) {
360 ND_PRINT(" != 4");
361 goto invalid;
362 }
363 bw.i = EXTRACT_BE_U_4(tptr);
364 ND_PRINT(", %.3f Mbps", bw.f * 8 / 1000000);
365 break;
366 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW:
367 if (subtlv_length != 32) {
368 ND_PRINT(" != 32");
369 goto invalid;
370 }
371 for (te_class = 0; te_class < 8; te_class++) {
372 bw.i = EXTRACT_BE_U_4(tptr + te_class * 4);
373 ND_PRINT("\n\t\tTE-Class %u: %.3f Mbps",
374 te_class,
375 bw.f * 8 / 1000000);
376 }
377 break;
378 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS:
379 if (subtlv_length < 4) {
380 ND_PRINT(" < 4");
381 goto invalid;
382 }
383 /* BC Model Id (1 octet) + Reserved (3 octets) */
384 ND_PRINT("\n\t\tBandwidth Constraints Model ID: %s (%u)",
385 tok2str(diffserv_te_bc_values, "unknown", EXTRACT_U_1(tptr)),
386 EXTRACT_U_1(tptr));
387 if (subtlv_length % 4 != 0) {
388 ND_PRINT("\n\t\tlength %u != N x 4", subtlv_length);
389 goto invalid;
390 }
391 if (subtlv_length > 36) {
392 ND_PRINT("\n\t\tlength %u > 36", subtlv_length);
393 goto invalid;
394 }
395 /* decode BCs until the subTLV ends */
396 for (te_class = 0; te_class < (subtlv_length-4)/4; te_class++) {
397 bw.i = EXTRACT_BE_U_4(tptr + 4 + te_class * 4);
398 ND_PRINT("\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
399 te_class,
400 bw.f * 8 / 1000000);
401 }
402 break;
403 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC:
404 if (subtlv_length != 4) {
405 ND_PRINT(" != 4");
406 goto invalid;
407 }
408 ND_PRINT(", Metric %u", EXTRACT_BE_U_4(tptr));
409 break;
410 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE:
411 /* Protection Cap (1 octet) + Reserved ((3 octets) */
412 if (subtlv_length != 4) {
413 ND_PRINT(" != 4");
414 goto invalid;
415 }
416 ND_PRINT(", %s",
417 bittok2str(gmpls_link_prot_values, "none", EXTRACT_U_1(tptr)));
418 break;
419 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
420 if (subtlv_length < 36) {
421 ND_PRINT(" < 36");
422 goto invalid;
423 }
424 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
425 ND_PRINT("\n\t\tInterface Switching Capability: %s",
426 tok2str(gmpls_switch_cap_values, "Unknown", EXTRACT_U_1((tptr))));
427 ND_PRINT("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
428 tok2str(gmpls_encoding_values, "Unknown", EXTRACT_U_1((tptr + 1))));
429 for (priority_level = 0; priority_level < 8; priority_level++) {
430 bw.i = EXTRACT_BE_U_4(tptr + 4 + (priority_level * 4));
431 ND_PRINT("\n\t\t priority level %u: %.3f Mbps",
432 priority_level,
433 bw.f * 8 / 1000000);
434 }
435 break;
436 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE:
437 if (subtlv_length != 1) {
438 ND_PRINT(" != 1");
439 goto invalid;
440 }
441 ND_PRINT(", %s (%u)",
442 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",EXTRACT_U_1(tptr)),
443 EXTRACT_U_1(tptr));
444 break;
445
446 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
447 if (subtlv_length % 4 != 0) {
448 ND_PRINT(" != N x 4");
449 goto invalid;
450 }
451 count_srlg = subtlv_length / 4;
452 if (count_srlg != 0)
453 ND_PRINT("\n\t\t Shared risk group: ");
454 while (count_srlg > 0) {
455 bw.i = EXTRACT_BE_U_4(tptr);
456 ND_PRINT("%u", bw.i);
457 tptr+=4;
458 count_srlg--;
459 if (count_srlg > 0)
460 ND_PRINT(", ");
461 }
462 break;
463
464 default:
465 if (ndo->ndo_vflag <= 1) {
466 if (!print_unknown_data(ndo, tptr, "\n\t\t", subtlv_length))
467 return -1;
468 }
469 break;
470 }
471 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
472 if (subtlv_length%4 != 0)
473 subtlv_length+=4-(subtlv_length%4);
474
475 tlv_length-=subtlv_length;
476 tptr+=subtlv_length;
477
478 }
479 break;
480
481 case LS_OPAQUE_TE_TLV_ROUTER:
482 if (tlv_length < 4) {
483 ND_PRINT("\n\t TLV length %u < 4", tlv_length);
484 return -1;
485 }
486 ND_TCHECK_4(tptr);
487 ND_PRINT(", %s", ipaddr_string(ndo, tptr));
488 break;
489
490 default:
491 if (ndo->ndo_vflag <= 1) {
492 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
493 return -1;
494 }
495 break;
496 }
497 /* in OSPF everything has to be 32-bit aligned, including TLVs */
498 if (tlv_length%4 != 0)
499 tlv_length+=4-(tlv_length%4);
500 ls_length-=tlv_length;
501 tptr+=tlv_length;
502 }
503 return 0;
504 trunc:
505 return -1;
506 invalid:
507 ND_PRINT("%s", istr);
508 return -1;
509 }
510
511 static int
512 ospf_print_lshdr(netdissect_options *ndo,
513 const struct lsa_hdr *lshp)
514 {
515 u_int ls_type;
516 u_int ls_length;
517
518 ND_TCHECK_2(lshp->ls_length);
519 ls_length = EXTRACT_BE_U_2(lshp->ls_length);
520 if (ls_length < sizeof(struct lsa_hdr)) {
521 ND_PRINT("\n\t Bogus length %u < header (%lu)", ls_length,
522 (unsigned long)sizeof(struct lsa_hdr));
523 return(-1);
524 }
525
526 ND_TCHECK_4(lshp->ls_seq); /* XXX - ls_length check checked this */
527 ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
528 ipaddr_string(ndo, lshp->ls_router),
529 EXTRACT_BE_U_4(lshp->ls_seq),
530 EXTRACT_BE_U_2(lshp->ls_age),
531 ls_length - (u_int)sizeof(struct lsa_hdr));
532
533 ND_TCHECK_1(lshp->ls_type); /* XXX - ls_length check checked this */
534 ls_type = EXTRACT_U_1(lshp->ls_type);
535 switch (ls_type) {
536 /* the LSA header for opaque LSAs was slightly changed */
537 case LS_TYPE_OPAQUE_LL:
538 case LS_TYPE_OPAQUE_AL:
539 case LS_TYPE_OPAQUE_DW:
540 ND_PRINT("\n\t %s LSA (%u), Opaque-Type %s LSA (%u), Opaque-ID %u",
541 tok2str(lsa_values,"unknown",ls_type),
542 ls_type,
543
544 tok2str(lsa_opaque_values,
545 "unknown",
546 EXTRACT_U_1(lshp->un_lsa_id.opaque_field.opaque_type)),
547 EXTRACT_U_1(lshp->un_lsa_id.opaque_field.opaque_type),
548 EXTRACT_BE_U_3(lshp->un_lsa_id.opaque_field.opaque_id)
549
550 );
551 break;
552
553 /* all other LSA types use regular style LSA headers */
554 default:
555 ND_PRINT("\n\t %s LSA (%u), LSA-ID: %s",
556 tok2str(lsa_values,"unknown",ls_type),
557 ls_type,
558 ipaddr_string(ndo, lshp->un_lsa_id.lsa_id));
559 break;
560 }
561
562 ND_TCHECK_1(lshp->ls_options); /* XXX - ls_length check checked this */
563 ND_PRINT("\n\t Options: [%s]", bittok2str(ospf_option_values, "none", EXTRACT_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 = EXTRACT_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 = EXTRACT_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 EXTRACT_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 (EXTRACT_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", EXTRACT_U_1(lsap->lsa_un.un_rla.rla_flags)));
644
645 ND_TCHECK_2(lsap->lsa_un.un_rla.rla_count);
646 j = EXTRACT_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 (EXTRACT_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 ipaddr_string(ndo, rlp->link_id),
656 ipaddr_string(ndo, rlp->link_data));
657 break;
658
659 case RLA_TYPE_ROUTER:
660 ND_PRINT("\n\t Neighbor Router-ID: %s, Interface Address: %s",
661 ipaddr_string(ndo, rlp->link_id),
662 ipaddr_string(ndo, rlp->link_data));
663 break;
664
665 case RLA_TYPE_TRANSIT:
666 ND_PRINT("\n\t Neighbor Network-ID: %s, Interface Address: %s",
667 ipaddr_string(ndo, rlp->link_id),
668 ipaddr_string(ndo, rlp->link_data));
669 break;
670
671 case RLA_TYPE_STUB:
672 ND_PRINT("\n\t Stub Network: %s, Mask: %s",
673 ipaddr_string(ndo, rlp->link_id),
674 ipaddr_string(ndo, rlp->link_data));
675 break;
676
677 default:
678 ND_PRINT("\n\t Unknown Router Link Type (%u)",
679 EXTRACT_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 (EXTRACT_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 ipaddr_string(ndo, 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", ipaddr_string(ndo, *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 ipaddr_string(ndo, 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 = EXTRACT_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 = EXTRACT_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 ipaddr_string(ndo, 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 = EXTRACT_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 (EXTRACT_IPV4_TO_NETWORK_ORDER(almp->asla_forward) != 0) {
765 ND_PRINT(", forward %s", ipaddr_string(ndo, almp->asla_forward));
766 }
767 ND_TCHECK_4(almp->asla_tag);
768 if (EXTRACT_IPV4_TO_NETWORK_ORDER(almp->asla_tag) != 0) {
769 ND_PRINT(", tag %s", ipaddr_string(ndo, 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 (EXTRACT_BE_U_4(mcp->mcla_vtype)) {
781
782 case MCLA_VERTEX_ROUTER:
783 ND_PRINT("\n\t Router Router-ID %s",
784 ipaddr_string(ndo, mcp->mcla_vid));
785 break;
786
787 case MCLA_VERTEX_NETWORK:
788 ND_PRINT("\n\t Network Designated Router %s",
789 ipaddr_string(ndo, mcp->mcla_vid));
790 break;
791
792 default:
793 ND_PRINT("\n\t unknown VertexType (%u)",
794 EXTRACT_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 (EXTRACT_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 = EXTRACT_BE_U_2(tptr);
816 tlv_length = EXTRACT_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", EXTRACT_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 (EXTRACT_U_1(op->ospf_type)) {
901
902 case OSPF_TYPE_HELLO:
903 if (!(EXTRACT_U_1(op->ospf_hello.hello_options) & OSPF_OPTION_L))
904 return (0);
905 break;
906
907 case OSPF_TYPE_DD:
908 if (!(EXTRACT_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 = EXTRACT_BE_U_2(op->ospf_len);
918 dptr = (const u_char *)op + length2;
919 dataend = (const u_char *)op + length;
920
921 if (EXTRACT_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) EXTRACT_BE_U_2(dptr));
931
932 dptr += 2;
933 ND_TCHECK_2(dptr);
934 length2 = EXTRACT_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 = EXTRACT_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 = EXTRACT_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 = EXTRACT_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", EXTRACT_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 (EXTRACT_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",EXTRACT_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 EXTRACT_BE_U_2(op->ospf_hello.hello_helloint),
1002 EXTRACT_BE_U_4(op->ospf_hello.hello_deadint),
1003 ipaddr_string(ndo, op->ospf_hello.hello_mask),
1004 EXTRACT_U_1(op->ospf_hello.hello_priority));
1005
1006 ND_TCHECK_4(op->ospf_hello.hello_dr);
1007 if (EXTRACT_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_dr) != 0)
1008 ND_PRINT("\n\t Designated Router %s",
1009 ipaddr_string(ndo, op->ospf_hello.hello_dr));
1010
1011 ND_TCHECK_4(op->ospf_hello.hello_bdr);
1012 if (EXTRACT_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_bdr) != 0)
1013 ND_PRINT(", Backup Designated Router %s",
1014 ipaddr_string(ndo, 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", ipaddr_string(ndo, *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", EXTRACT_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", EXTRACT_U_1(op->ospf_db.db_flags)));
1033 ND_TCHECK_2(op->ospf_db.db_ifmtu);
1034 if (EXTRACT_BE_U_2(op->ospf_db.db_ifmtu)) {
1035 ND_PRINT(", MTU: %u", EXTRACT_BE_U_2(op->ospf_db.db_ifmtu));
1036 }
1037 ND_TCHECK_4(op->ospf_db.db_seq);
1038 ND_PRINT(", Sequence: 0x%08x", EXTRACT_BE_U_4(op->ospf_db.db_seq));
1039
1040 /* Print all the LS adv's */
1041 lshp = op->ospf_db.db_lshdr;
1042 while (((const u_char *)lshp < dataend) && ospf_print_lshdr(ndo, lshp) != -1) {
1043 ++lshp;
1044 }
1045 break;
1046
1047 case OSPF_TYPE_LS_REQ:
1048 lsrp = op->ospf_lsr;
1049 while ((const u_char *)lsrp < dataend) {
1050 ND_TCHECK_SIZE(lsrp);
1051
1052 ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)",
1053 ipaddr_string(ndo, lsrp->ls_router),
1054 tok2str(lsa_values,"unknown",EXTRACT_BE_U_4(lsrp->ls_type)),
1055 EXTRACT_BE_U_4(lsrp->ls_type));
1056
1057 switch (EXTRACT_BE_U_4(lsrp->ls_type)) {
1058 /* the LSA header for opaque LSAs was slightly changed */
1059 case LS_TYPE_OPAQUE_LL:
1060 case LS_TYPE_OPAQUE_AL:
1061 case LS_TYPE_OPAQUE_DW:
1062 ND_PRINT(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1063 tok2str(lsa_opaque_values, "unknown",EXTRACT_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type)),
1064 EXTRACT_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type),
1065 EXTRACT_BE_U_3(lsrp->un_ls_stateid.opaque_field.opaque_id));
1066 break;
1067 default:
1068 ND_PRINT(", LSA-ID: %s",
1069 ipaddr_string(ndo, lsrp->un_ls_stateid.ls_stateid));
1070 break;
1071 }
1072
1073 ++lsrp;
1074 }
1075 break;
1076
1077 case OSPF_TYPE_LS_UPDATE:
1078 lsap = op->ospf_lsu.lsu_lsa;
1079 ND_TCHECK_4(op->ospf_lsu.lsu_count);
1080 lsa_count_max = EXTRACT_BE_U_4(op->ospf_lsu.lsu_count);
1081 ND_PRINT(", %u LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max));
1082 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
1083 ND_PRINT("\n\t LSA #%u", lsa_count);
1084 lsap = (const struct lsa *)ospf_print_lsa(ndo, lsap);
1085 if (lsap == NULL)
1086 goto trunc;
1087 }
1088 break;
1089
1090 case OSPF_TYPE_LS_ACK:
1091 lshp = op->ospf_lsa.lsa_lshdr;
1092 while (ospf_print_lshdr(ndo, lshp) != -1) {
1093 ++lshp;
1094 }
1095 break;
1096
1097 default:
1098 break;
1099 }
1100 return (0);
1101 trunc:
1102 return (1);
1103 }
1104
1105 void
1106 ospf_print(netdissect_options *ndo,
1107 const u_char *bp, u_int length,
1108 const u_char *bp2 _U_)
1109 {
1110 const struct ospfhdr *op;
1111 const u_char *dataend;
1112 const char *cp;
1113
1114 ndo->ndo_protocol = "ospf";
1115 op = (const struct ospfhdr *)bp;
1116
1117 /* XXX Before we do anything else, strip off the MD5 trailer */
1118 ND_TCHECK_2(op->ospf_authtype);
1119 if (EXTRACT_BE_U_2(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_1(op->ospf_type);
1127 cp = tok2str(type2str, "unknown LS-type %u", EXTRACT_U_1(op->ospf_type));
1128 ND_PRINT("OSPFv%u, %s, length %u", EXTRACT_U_1(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_2(op->ospf_len);
1137 if (length != EXTRACT_BE_U_2(op->ospf_len)) {
1138 ND_PRINT(" [len %u]", EXTRACT_BE_U_2(op->ospf_len));
1139 }
1140
1141 if (length > EXTRACT_BE_U_2(op->ospf_len)) {
1142 dataend = bp + EXTRACT_BE_U_2(op->ospf_len);
1143 } else {
1144 dataend = bp + length;
1145 }
1146
1147 ND_TCHECK_4(op->ospf_routerid);
1148 ND_PRINT("\n\tRouter-ID %s", ipaddr_string(ndo, op->ospf_routerid));
1149
1150 ND_TCHECK_4(op->ospf_areaid);
1151 if (EXTRACT_IPV4_TO_NETWORK_ORDER(op->ospf_areaid) != 0)
1152 ND_PRINT(", Area %s", ipaddr_string(ndo, op->ospf_areaid));
1153 else
1154 ND_PRINT(", Backbone Area");
1155
1156 if (ndo->ndo_vflag) {
1157 /* Print authentication data (should we really do this?) */
1158 ND_TCHECK_LEN(op->ospf_authdata, sizeof(op->ospf_authdata));
1159
1160 ND_PRINT(", Authentication Type: %s (%u)",
1161 tok2str(ospf_authtype_values, "unknown", EXTRACT_BE_U_2(op->ospf_authtype)),
1162 EXTRACT_BE_U_2(op->ospf_authtype));
1163
1164 switch (EXTRACT_BE_U_2(op->ospf_authtype)) {
1165
1166 case OSPF_AUTH_NONE:
1167 break;
1168
1169 case OSPF_AUTH_SIMPLE:
1170 ND_PRINT("\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("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1176 *((op->ospf_authdata) + 2),
1177 *((op->ospf_authdata) + 3),
1178 EXTRACT_BE_U_4((op->ospf_authdata) + 4));
1179 break;
1180
1181 default:
1182 return;
1183 }
1184 }
1185 /* Do rest according to version. */
1186 switch (EXTRACT_U_1(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_BE_U_2(op->ospf_len)) {
1193 if (ospf_decode_lls(ndo, op, length))
1194 goto trunc;
1195 }
1196 break;
1197
1198 default:
1199 ND_PRINT(" ospf [version %u]", EXTRACT_U_1(op->ospf_version));
1200 break;
1201 } /* end switch on version */
1202
1203 return;
1204 trunc:
1205 ND_PRINT("%s", tstr);
1206 }