]> The Tcpdump Group git mirrors - tcpdump/blob - print-ospf.c
Updated 802.15.4 code
[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 = EXTRACT_BE_U_2(tptr);
195 tlv_length = EXTRACT_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", EXTRACT_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", EXTRACT_U_1(tptr)),
233 EXTRACT_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", ipaddr_string(ndo, tptr));
242 break;
243
244 default:
245 if (ndo->ndo_vflag <= 1) {
246 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
247 return -1;
248 }
249 break;
250
251 }
252 /* in OSPF everything has to be 32-bit aligned, including TLVs */
253 if (tlv_length%4 != 0)
254 tlv_length+=4-(tlv_length%4);
255 ls_length-=tlv_length;
256 tptr+=tlv_length;
257 }
258
259 return 0;
260 trunc:
261 return -1;
262 }
263
264 int
265 ospf_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 = EXTRACT_BE_U_2(tptr);
282 tlv_length = EXTRACT_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 = EXTRACT_BE_U_2(tptr);
312 subtlv_length = EXTRACT_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", EXTRACT_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 ipaddr_string(ndo, tptr),
342 EXTRACT_BE_U_4(tptr));
343 if (subtlv_length == 8) /* rfc4203 */
344 ND_PRINT(", %s (0x%08x)",
345 ipaddr_string(ndo, tptr+4),
346 EXTRACT_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", ipaddr_string(ndo, tptr));
355 break;
356 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
357 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
358 if (subtlv_length != 4) {
359 ND_PRINT(" != 4");
360 goto invalid;
361 }
362 bw.i = EXTRACT_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 = EXTRACT_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", EXTRACT_U_1(tptr)),
385 EXTRACT_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 = EXTRACT_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", EXTRACT_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", EXTRACT_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", EXTRACT_U_1((tptr))));
426 ND_PRINT("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
427 tok2str(gmpls_encoding_values, "Unknown", EXTRACT_U_1((tptr + 1))));
428 for (priority_level = 0; priority_level < 8; priority_level++) {
429 bw.i = EXTRACT_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",EXTRACT_U_1(tptr)),
442 EXTRACT_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 = EXTRACT_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", ipaddr_string(ndo, tptr));
487 break;
488
489 default:
490 if (ndo->ndo_vflag <= 1) {
491 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
492 return -1;
493 }
494 break;
495 }
496 /* in OSPF everything has to be 32-bit aligned, including TLVs */
497 if (tlv_length%4 != 0)
498 tlv_length+=4-(tlv_length%4);
499 ls_length-=tlv_length;
500 tptr+=tlv_length;
501 }
502 return 0;
503 trunc:
504 return -1;
505 invalid:
506 nd_print_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 = EXTRACT_BE_U_2(lshp->ls_length);
519 if (ls_length < sizeof(struct lsa_hdr)) {
520 ND_PRINT("\n\t Bogus length %u < header (%lu)", ls_length,
521 (unsigned long)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 ipaddr_string(ndo, lshp->ls_router),
528 EXTRACT_BE_U_4(lshp->ls_seq),
529 EXTRACT_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 = EXTRACT_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 EXTRACT_U_1(lshp->un_lsa_id.opaque_field.opaque_type)),
546 EXTRACT_U_1(lshp->un_lsa_id.opaque_field.opaque_type),
547 EXTRACT_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 ipaddr_string(ndo, 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]", bittok2str(ospf_option_values, "none", EXTRACT_U_1(lshp->ls_options)));
563
564 return (ls_length);
565 trunc:
566 return (-1);
567 }
568
569 /* draft-ietf-ospf-mt-09 */
570 static const struct tok ospf_topology_values[] = {
571 { 0, "default" },
572 { 1, "multicast" },
573 { 2, "management" },
574 { 0, NULL }
575 };
576
577 /*
578 * Print all the per-topology metrics.
579 */
580 static int
581 ospf_print_tos_metrics(netdissect_options *ndo,
582 const union un_tos *tos)
583 {
584 u_int metric_count;
585 u_int toscount;
586 u_int tos_type;
587
588 toscount = EXTRACT_U_1(tos->link.link_tos_count)+1;
589 metric_count = 0;
590
591 /*
592 * All but the first metric contain a valid topology id.
593 */
594 while (toscount != 0) {
595 ND_TCHECK_SIZE(tos);
596 tos_type = EXTRACT_U_1(tos->metrics.tos_type);
597 ND_PRINT("\n\t\ttopology %s (%u), metric %u",
598 tok2str(ospf_topology_values, "Unknown",
599 metric_count ? tos_type : 0),
600 metric_count ? tos_type : 0,
601 EXTRACT_BE_U_2(tos->metrics.tos_metric));
602 metric_count++;
603 tos++;
604 toscount--;
605 }
606 return 0;
607 trunc:
608 return 1;
609 }
610
611 /*
612 * Print a single link state advertisement. If truncated or if LSA length
613 * field is less than the length of the LSA header, return NULl, else
614 * return pointer to data past end of LSA.
615 */
616 static const uint8_t *
617 ospf_print_lsa(netdissect_options *ndo,
618 const struct lsa *lsap)
619 {
620 const uint8_t *ls_end;
621 const struct rlalink *rlp;
622 const nd_ipv4 *ap;
623 const struct aslametric *almp;
624 const struct mcla *mcp;
625 const uint8_t *lp;
626 int j, tlv_type, tlv_length, topology;
627 int ls_length;
628 const uint8_t *tptr;
629
630 tptr = (const uint8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
631 ls_length = ospf_print_lshdr(ndo, &lsap->ls_hdr);
632 if (ls_length == -1)
633 return(NULL);
634 ls_end = (const uint8_t *)lsap + ls_length;
635 ls_length -= sizeof(struct lsa_hdr);
636
637 switch (EXTRACT_U_1(lsap->ls_hdr.ls_type)) {
638
639 case LS_TYPE_ROUTER:
640 ND_TCHECK_1(lsap->lsa_un.un_rla.rla_flags);
641 ND_PRINT("\n\t Router LSA Options: [%s]",
642 bittok2str(ospf_rla_flag_values, "none", EXTRACT_U_1(lsap->lsa_un.un_rla.rla_flags)));
643
644 ND_TCHECK_2(lsap->lsa_un.un_rla.rla_count);
645 j = EXTRACT_BE_U_2(lsap->lsa_un.un_rla.rla_count);
646 ND_TCHECK_SIZE(lsap->lsa_un.un_rla.rla_link);
647 rlp = lsap->lsa_un.un_rla.rla_link;
648 while (j--) {
649 ND_TCHECK_SIZE(rlp);
650 switch (EXTRACT_U_1(rlp->un_tos.link.link_type)) {
651
652 case RLA_TYPE_VIRTUAL:
653 ND_PRINT("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
654 ipaddr_string(ndo, rlp->link_id),
655 ipaddr_string(ndo, rlp->link_data));
656 break;
657
658 case RLA_TYPE_ROUTER:
659 ND_PRINT("\n\t Neighbor Router-ID: %s, Interface Address: %s",
660 ipaddr_string(ndo, rlp->link_id),
661 ipaddr_string(ndo, rlp->link_data));
662 break;
663
664 case RLA_TYPE_TRANSIT:
665 ND_PRINT("\n\t Neighbor Network-ID: %s, Interface Address: %s",
666 ipaddr_string(ndo, rlp->link_id),
667 ipaddr_string(ndo, rlp->link_data));
668 break;
669
670 case RLA_TYPE_STUB:
671 ND_PRINT("\n\t Stub Network: %s, Mask: %s",
672 ipaddr_string(ndo, rlp->link_id),
673 ipaddr_string(ndo, rlp->link_data));
674 break;
675
676 default:
677 ND_PRINT("\n\t Unknown Router Link Type (%u)",
678 EXTRACT_U_1(rlp->un_tos.link.link_type));
679 return (ls_end);
680 }
681
682 if (ospf_print_tos_metrics(ndo, &rlp->un_tos))
683 goto trunc;
684
685 rlp = (const struct rlalink *)((const u_char *)(rlp + 1) +
686 (EXTRACT_U_1(rlp->un_tos.link.link_tos_count) * sizeof(union un_tos)));
687 }
688 break;
689
690 case LS_TYPE_NETWORK:
691 ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
692 ND_PRINT("\n\t Mask %s\n\t Connected Routers:",
693 ipaddr_string(ndo, lsap->lsa_un.un_nla.nla_mask));
694 ap = lsap->lsa_un.un_nla.nla_router;
695 while ((const u_char *)ap < ls_end) {
696 ND_TCHECK_SIZE(ap);
697 ND_PRINT("\n\t %s", ipaddr_string(ndo, *ap));
698 ++ap;
699 }
700 break;
701
702 case LS_TYPE_SUM_IP:
703 ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
704 ND_PRINT("\n\t Mask %s",
705 ipaddr_string(ndo, lsap->lsa_un.un_sla.sla_mask));
706 ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric);
707 lp = (const uint8_t *)lsap->lsa_un.un_sla.sla_tosmetric;
708 while (lp < ls_end) {
709 uint32_t ul;
710
711 ND_TCHECK_4(lp);
712 ul = EXTRACT_BE_U_4(lp);
713 topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
714 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
715 tok2str(ospf_topology_values, "Unknown", topology),
716 topology,
717 ul & SLA_MASK_METRIC);
718 lp += 4;
719 }
720 break;
721
722 case LS_TYPE_SUM_ABR:
723 ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric);
724 lp = (const uint8_t *)lsap->lsa_un.un_sla.sla_tosmetric;
725 while (lp < ls_end) {
726 uint32_t ul;
727
728 ND_TCHECK_4(lp);
729 ul = EXTRACT_BE_U_4(lp);
730 topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
731 ND_PRINT("\n\t\ttopology %s (%u) metric %u",
732 tok2str(ospf_topology_values, "Unknown", topology),
733 topology,
734 ul & SLA_MASK_METRIC);
735 lp += 4;
736 }
737 break;
738
739 case LS_TYPE_ASE:
740 case LS_TYPE_NSSA: /* fall through - those LSAs share the same format */
741 ND_TCHECK_4(lsap->lsa_un.un_nla.nla_mask);
742 ND_PRINT("\n\t Mask %s",
743 ipaddr_string(ndo, lsap->lsa_un.un_asla.asla_mask));
744
745 ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric);
746 almp = lsap->lsa_un.un_asla.asla_metric;
747 while ((const u_char *)almp < ls_end) {
748 uint32_t ul;
749
750 ND_TCHECK_4(almp->asla_tosmetric);
751 ul = EXTRACT_BE_U_4(almp->asla_tosmetric);
752 topology = ((ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
753 ND_PRINT("\n\t\ttopology %s (%u), type %u, metric",
754 tok2str(ospf_topology_values, "Unknown", topology),
755 topology,
756 (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1);
757 if ((ul & ASLA_MASK_METRIC) == 0xffffff)
758 ND_PRINT(" infinite");
759 else
760 ND_PRINT(" %u", (ul & ASLA_MASK_METRIC));
761
762 ND_TCHECK_4(almp->asla_forward);
763 if (EXTRACT_IPV4_TO_NETWORK_ORDER(almp->asla_forward) != 0) {
764 ND_PRINT(", forward %s", ipaddr_string(ndo, almp->asla_forward));
765 }
766 ND_TCHECK_4(almp->asla_tag);
767 if (EXTRACT_IPV4_TO_NETWORK_ORDER(almp->asla_tag) != 0) {
768 ND_PRINT(", tag %s", ipaddr_string(ndo, almp->asla_tag));
769 }
770 ++almp;
771 }
772 break;
773
774 case LS_TYPE_GROUP:
775 /* Multicast extensions as of 23 July 1991 */
776 mcp = lsap->lsa_un.un_mcla;
777 while ((const u_char *)mcp < ls_end) {
778 ND_TCHECK_4(mcp->mcla_vid);
779 switch (EXTRACT_BE_U_4(mcp->mcla_vtype)) {
780
781 case MCLA_VERTEX_ROUTER:
782 ND_PRINT("\n\t Router Router-ID %s",
783 ipaddr_string(ndo, mcp->mcla_vid));
784 break;
785
786 case MCLA_VERTEX_NETWORK:
787 ND_PRINT("\n\t Network Designated Router %s",
788 ipaddr_string(ndo, mcp->mcla_vid));
789 break;
790
791 default:
792 ND_PRINT("\n\t unknown VertexType (%u)",
793 EXTRACT_BE_U_4(mcp->mcla_vtype));
794 break;
795 }
796 ++mcp;
797 }
798 break;
799
800 case LS_TYPE_OPAQUE_LL: /* fall through */
801 case LS_TYPE_OPAQUE_AL:
802 case LS_TYPE_OPAQUE_DW:
803
804 switch (EXTRACT_U_1(lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
805 case LS_OPAQUE_TYPE_RI:
806 tptr = (const uint8_t *)(lsap->lsa_un.un_ri_tlv);
807
808 while (ls_length != 0) {
809 ND_TCHECK_4(tptr);
810 if (ls_length < 4) {
811 ND_PRINT("\n\t Remaining LS length %u < 4", ls_length);
812 return(ls_end);
813 }
814 tlv_type = EXTRACT_BE_U_2(tptr);
815 tlv_length = EXTRACT_BE_U_2(tptr + 2);
816 tptr+=4;
817 ls_length-=4;
818
819 ND_PRINT("\n\t %s TLV (%u), length: %u, value: ",
820 tok2str(lsa_opaque_ri_tlv_values,"unknown",tlv_type),
821 tlv_type,
822 tlv_length);
823
824 if (tlv_length > ls_length) {
825 ND_PRINT("\n\t Bogus length %u > %u", tlv_length,
826 ls_length);
827 return(ls_end);
828 }
829 ND_TCHECK_LEN(tptr, tlv_length);
830 switch(tlv_type) {
831
832 case LS_OPAQUE_RI_TLV_CAP:
833 if (tlv_length != 4) {
834 ND_PRINT("\n\t Bogus length %u != 4", tlv_length);
835 return(ls_end);
836 }
837 ND_PRINT("Capabilities: %s",
838 bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", EXTRACT_BE_U_4(tptr)));
839 break;
840 default:
841 if (ndo->ndo_vflag <= 1) {
842 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
843 return(ls_end);
844 }
845 break;
846
847 }
848 tptr+=tlv_length;
849 ls_length-=tlv_length;
850 }
851 break;
852
853 case LS_OPAQUE_TYPE_GRACE:
854 if (ospf_grace_lsa_print(ndo, (const u_char *)(lsap->lsa_un.un_grace_tlv),
855 ls_length) == -1) {
856 return(ls_end);
857 }
858 break;
859
860 case LS_OPAQUE_TYPE_TE:
861 if (ospf_te_lsa_print(ndo, (const u_char *)(lsap->lsa_un.un_te_lsa_tlv),
862 ls_length) == -1) {
863 return(ls_end);
864 }
865 break;
866
867 default:
868 if (ndo->ndo_vflag <= 1) {
869 if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
870 "\n\t ", ls_length))
871 return(ls_end);
872 }
873 break;
874 }
875 }
876
877 /* do we want to see an additionally hexdump ? */
878 if (ndo->ndo_vflag> 1)
879 if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
880 "\n\t ", ls_length)) {
881 return(ls_end);
882 }
883
884 return (ls_end);
885 trunc:
886 return (NULL);
887 }
888
889 static int
890 ospf_decode_lls(netdissect_options *ndo,
891 const struct ospfhdr *op, u_int length)
892 {
893 const u_char *dptr;
894 const u_char *dataend;
895 u_int length2;
896 uint16_t lls_type, lls_len;
897 uint32_t lls_flags;
898
899 switch (EXTRACT_U_1(op->ospf_type)) {
900
901 case OSPF_TYPE_HELLO:
902 if (!(EXTRACT_U_1(op->ospf_hello.hello_options) & OSPF_OPTION_L))
903 return (0);
904 break;
905
906 case OSPF_TYPE_DD:
907 if (!(EXTRACT_U_1(op->ospf_db.db_options) & OSPF_OPTION_L))
908 return (0);
909 break;
910
911 default:
912 return (0);
913 }
914
915 /* dig deeper if LLS data is available; see RFC4813 */
916 length2 = EXTRACT_BE_U_2(op->ospf_len);
917 dptr = (const u_char *)op + length2;
918 dataend = (const u_char *)op + length;
919
920 if (EXTRACT_BE_U_2(op->ospf_authtype) == OSPF_AUTH_MD5) {
921 dptr = dptr + op->ospf_authdata[3];
922 length2 += op->ospf_authdata[3];
923 }
924 if (length2 >= length) {
925 ND_PRINT("\n\t[LLS truncated]");
926 return (1);
927 }
928 ND_TCHECK_2(dptr);
929 ND_PRINT("\n\t LLS: checksum: 0x%04x", (u_int) EXTRACT_BE_U_2(dptr));
930
931 dptr += 2;
932 ND_TCHECK_2(dptr);
933 length2 = EXTRACT_BE_U_2(dptr);
934 ND_PRINT(", length: %u", length2);
935
936 dptr += 2;
937 ND_TCHECK_1(dptr);
938 while (dptr < dataend) {
939 ND_TCHECK_2(dptr);
940 lls_type = EXTRACT_BE_U_2(dptr);
941 ND_PRINT("\n\t %s (%u)",
942 tok2str(ospf_lls_tlv_values,"Unknown TLV",lls_type),
943 lls_type);
944 dptr += 2;
945 ND_TCHECK_2(dptr);
946 lls_len = EXTRACT_BE_U_2(dptr);
947 ND_PRINT(", length: %u", lls_len);
948 dptr += 2;
949 switch (lls_type) {
950
951 case OSPF_LLS_EO:
952 if (lls_len != 4) {
953 ND_PRINT(" [should be 4]");
954 lls_len = 4;
955 }
956 ND_TCHECK_4(dptr);
957 lls_flags = EXTRACT_BE_U_4(dptr);
958 ND_PRINT("\n\t Options: 0x%08x [%s]", lls_flags,
959 bittok2str(ospf_lls_eo_options, "?", lls_flags));
960
961 break;
962
963 case OSPF_LLS_MD5:
964 if (lls_len != 20) {
965 ND_PRINT(" [should be 20]");
966 lls_len = 20;
967 }
968 ND_TCHECK_4(dptr);
969 ND_PRINT("\n\t Sequence number: 0x%08x", EXTRACT_BE_U_4(dptr));
970 break;
971 }
972
973 dptr += lls_len;
974 }
975
976 return (0);
977 trunc:
978 return (1);
979 }
980
981 static int
982 ospf_decode_v2(netdissect_options *ndo,
983 const struct ospfhdr *op, const u_char *dataend)
984 {
985 const nd_ipv4 *ap;
986 const struct lsr *lsrp;
987 const struct lsa_hdr *lshp;
988 const struct lsa *lsap;
989 uint32_t lsa_count,lsa_count_max;
990
991 switch (EXTRACT_U_1(op->ospf_type)) {
992
993 case OSPF_TYPE_HELLO:
994 ND_TCHECK_1(op->ospf_hello.hello_options);
995 ND_PRINT("\n\tOptions [%s]",
996 bittok2str(ospf_option_values,"none",EXTRACT_U_1(op->ospf_hello.hello_options)));
997
998 ND_TCHECK_4(op->ospf_hello.hello_deadint);
999 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
1000 EXTRACT_BE_U_2(op->ospf_hello.hello_helloint),
1001 EXTRACT_BE_U_4(op->ospf_hello.hello_deadint),
1002 ipaddr_string(ndo, op->ospf_hello.hello_mask),
1003 EXTRACT_U_1(op->ospf_hello.hello_priority));
1004
1005 ND_TCHECK_4(op->ospf_hello.hello_dr);
1006 if (EXTRACT_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_dr) != 0)
1007 ND_PRINT("\n\t Designated Router %s",
1008 ipaddr_string(ndo, op->ospf_hello.hello_dr));
1009
1010 ND_TCHECK_4(op->ospf_hello.hello_bdr);
1011 if (EXTRACT_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_bdr) != 0)
1012 ND_PRINT(", Backup Designated Router %s",
1013 ipaddr_string(ndo, op->ospf_hello.hello_bdr));
1014
1015 ap = op->ospf_hello.hello_neighbor;
1016 if ((const u_char *)ap < dataend)
1017 ND_PRINT("\n\t Neighbor List:");
1018 while ((const u_char *)ap < dataend) {
1019 ND_TCHECK_SIZE(ap);
1020 ND_PRINT("\n\t %s", ipaddr_string(ndo, *ap));
1021 ++ap;
1022 }
1023 break; /* HELLO */
1024
1025 case OSPF_TYPE_DD:
1026 ND_TCHECK_1(op->ospf_db.db_options);
1027 ND_PRINT("\n\tOptions [%s]",
1028 bittok2str(ospf_option_values, "none", EXTRACT_U_1(op->ospf_db.db_options)));
1029 ND_TCHECK_1(op->ospf_db.db_flags);
1030 ND_PRINT(", DD Flags [%s]",
1031 bittok2str(ospf_dd_flag_values, "none", EXTRACT_U_1(op->ospf_db.db_flags)));
1032 ND_TCHECK_2(op->ospf_db.db_ifmtu);
1033 if (EXTRACT_BE_U_2(op->ospf_db.db_ifmtu)) {
1034 ND_PRINT(", MTU: %u", EXTRACT_BE_U_2(op->ospf_db.db_ifmtu));
1035 }
1036 ND_TCHECK_4(op->ospf_db.db_seq);
1037 ND_PRINT(", Sequence: 0x%08x", EXTRACT_BE_U_4(op->ospf_db.db_seq));
1038
1039 /* Print all the LS adv's */
1040 lshp = op->ospf_db.db_lshdr;
1041 while (((const u_char *)lshp < dataend) && ospf_print_lshdr(ndo, lshp) != -1) {
1042 ++lshp;
1043 }
1044 break;
1045
1046 case OSPF_TYPE_LS_REQ:
1047 lsrp = op->ospf_lsr;
1048 while ((const u_char *)lsrp < dataend) {
1049 ND_TCHECK_SIZE(lsrp);
1050
1051 ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)",
1052 ipaddr_string(ndo, lsrp->ls_router),
1053 tok2str(lsa_values,"unknown",EXTRACT_BE_U_4(lsrp->ls_type)),
1054 EXTRACT_BE_U_4(lsrp->ls_type));
1055
1056 switch (EXTRACT_BE_U_4(lsrp->ls_type)) {
1057 /* the LSA header for opaque LSAs was slightly changed */
1058 case LS_TYPE_OPAQUE_LL:
1059 case LS_TYPE_OPAQUE_AL:
1060 case LS_TYPE_OPAQUE_DW:
1061 ND_PRINT(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1062 tok2str(lsa_opaque_values, "unknown",EXTRACT_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type)),
1063 EXTRACT_U_1(lsrp->un_ls_stateid.opaque_field.opaque_type),
1064 EXTRACT_BE_U_3(lsrp->un_ls_stateid.opaque_field.opaque_id));
1065 break;
1066 default:
1067 ND_PRINT(", LSA-ID: %s",
1068 ipaddr_string(ndo, lsrp->un_ls_stateid.ls_stateid));
1069 break;
1070 }
1071
1072 ++lsrp;
1073 }
1074 break;
1075
1076 case OSPF_TYPE_LS_UPDATE:
1077 lsap = op->ospf_lsu.lsu_lsa;
1078 ND_TCHECK_4(op->ospf_lsu.lsu_count);
1079 lsa_count_max = EXTRACT_BE_U_4(op->ospf_lsu.lsu_count);
1080 ND_PRINT(", %u LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max));
1081 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
1082 ND_PRINT("\n\t LSA #%u", lsa_count);
1083 lsap = (const struct lsa *)ospf_print_lsa(ndo, lsap);
1084 if (lsap == NULL)
1085 goto trunc;
1086 }
1087 break;
1088
1089 case OSPF_TYPE_LS_ACK:
1090 lshp = op->ospf_lsa.lsa_lshdr;
1091 while (ospf_print_lshdr(ndo, lshp) != -1) {
1092 ++lshp;
1093 }
1094 break;
1095
1096 default:
1097 break;
1098 }
1099 return (0);
1100 trunc:
1101 return (1);
1102 }
1103
1104 void
1105 ospf_print(netdissect_options *ndo,
1106 const u_char *bp, u_int length,
1107 const u_char *bp2 _U_)
1108 {
1109 const struct ospfhdr *op;
1110 const u_char *dataend;
1111 const char *cp;
1112
1113 ndo->ndo_protocol = "ospf2";
1114 op = (const struct ospfhdr *)bp;
1115
1116 /* XXX Before we do anything else, strip off the MD5 trailer */
1117 ND_TCHECK_2(op->ospf_authtype);
1118 if (EXTRACT_BE_U_2(op->ospf_authtype) == OSPF_AUTH_MD5) {
1119 length -= OSPF_AUTH_MD5_LEN;
1120 ndo->ndo_snapend -= OSPF_AUTH_MD5_LEN;
1121 }
1122
1123 /* If the type is valid translate it, or just print the type */
1124 /* value. If it's not valid, say so and return */
1125 ND_TCHECK_1(op->ospf_type);
1126 cp = tok2str(type2str, "unknown LS-type %u", EXTRACT_U_1(op->ospf_type));
1127 ND_PRINT("OSPFv%u, %s, length %u", EXTRACT_U_1(op->ospf_version), cp, length);
1128 if (*cp == 'u')
1129 return;
1130
1131 if (!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
1132 return;
1133 }
1134
1135 ND_TCHECK_2(op->ospf_len);
1136 if (length != EXTRACT_BE_U_2(op->ospf_len)) {
1137 ND_PRINT(" [len %u]", EXTRACT_BE_U_2(op->ospf_len));
1138 }
1139
1140 if (length > EXTRACT_BE_U_2(op->ospf_len)) {
1141 dataend = bp + EXTRACT_BE_U_2(op->ospf_len);
1142 } else {
1143 dataend = bp + length;
1144 }
1145
1146 ND_TCHECK_4(op->ospf_routerid);
1147 ND_PRINT("\n\tRouter-ID %s", ipaddr_string(ndo, op->ospf_routerid));
1148
1149 ND_TCHECK_4(op->ospf_areaid);
1150 if (EXTRACT_IPV4_TO_NETWORK_ORDER(op->ospf_areaid) != 0)
1151 ND_PRINT(", Area %s", ipaddr_string(ndo, op->ospf_areaid));
1152 else
1153 ND_PRINT(", Backbone Area");
1154
1155 if (ndo->ndo_vflag) {
1156 /* Print authentication data (should we really do this?) */
1157 ND_TCHECK_LEN(op->ospf_authdata, sizeof(op->ospf_authdata));
1158
1159 ND_PRINT(", Authentication Type: %s (%u)",
1160 tok2str(ospf_authtype_values, "unknown", EXTRACT_BE_U_2(op->ospf_authtype)),
1161 EXTRACT_BE_U_2(op->ospf_authtype));
1162
1163 switch (EXTRACT_BE_U_2(op->ospf_authtype)) {
1164
1165 case OSPF_AUTH_NONE:
1166 break;
1167
1168 case OSPF_AUTH_SIMPLE:
1169 ND_PRINT("\n\tSimple text password: ");
1170 (void)nd_printzp(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN, NULL);
1171 break;
1172
1173 case OSPF_AUTH_MD5:
1174 ND_PRINT("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1175 *((op->ospf_authdata) + 2),
1176 *((op->ospf_authdata) + 3),
1177 EXTRACT_BE_U_4((op->ospf_authdata) + 4));
1178 break;
1179
1180 default:
1181 return;
1182 }
1183 }
1184 /* Do rest according to version. */
1185 switch (EXTRACT_U_1(op->ospf_version)) {
1186
1187 case 2:
1188 /* ospf version 2 */
1189 if (ospf_decode_v2(ndo, op, dataend))
1190 goto trunc;
1191 if (length > EXTRACT_BE_U_2(op->ospf_len)) {
1192 if (ospf_decode_lls(ndo, op, length))
1193 goto trunc;
1194 }
1195 break;
1196
1197 default:
1198 ND_PRINT(" ospf [version %u]", EXTRACT_U_1(op->ospf_version));
1199 break;
1200 } /* end switch on version */
1201
1202 return;
1203 trunc:
1204 nd_print_trunc(ndo);
1205 }