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