]> The Tcpdump Group git mirrors - tcpdump/blob - print-ospf.c
Change -z command help text to -z postrotate-command
[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 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <netdissect-stdinc.h>
29
30 #include "netdissect.h"
31 #include "addrtoname.h"
32 #include "extract.h"
33 #include "gmpls.h"
34
35 #include "ospf.h"
36
37 static const char tstr[] = " [|ospf2]";
38
39 static const struct tok ospf_option_values[] = {
40 { OSPF_OPTION_T, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
41 { OSPF_OPTION_E, "External" },
42 { OSPF_OPTION_MC, "Multicast" },
43 { OSPF_OPTION_NP, "NSSA" },
44 { OSPF_OPTION_L, "LLS" },
45 { OSPF_OPTION_DC, "Demand Circuit" },
46 { OSPF_OPTION_O, "Opaque" },
47 { OSPF_OPTION_DN, "Up/Down" },
48 { 0, NULL }
49 };
50
51 static const struct tok ospf_authtype_values[] = {
52 { OSPF_AUTH_NONE, "none" },
53 { OSPF_AUTH_SIMPLE, "simple" },
54 { OSPF_AUTH_MD5, "MD5" },
55 { 0, NULL }
56 };
57
58 static const struct tok ospf_rla_flag_values[] = {
59 { RLA_FLAG_B, "ABR" },
60 { RLA_FLAG_E, "ASBR" },
61 { RLA_FLAG_W1, "Virtual" },
62 { RLA_FLAG_W2, "W2" },
63 { 0, NULL }
64 };
65
66 static const struct tok type2str[] = {
67 { OSPF_TYPE_UMD, "UMD" },
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_print_grace_lsa(netdissect_options *ndo,
183 const uint8_t *tptr, u_int ls_length)
184 {
185 u_int tlv_type, tlv_length;
186
187
188 while (ls_length > 0) {
189 ND_TCHECK2(*tptr, 4);
190 if (ls_length < 4) {
191 ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
192 return -1;
193 }
194 tlv_type = EXTRACT_16BITS(tptr);
195 tlv_length = EXTRACT_16BITS(tptr+2);
196 tptr+=4;
197 ls_length-=4;
198
199 ND_PRINT((ndo, "\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((ndo, "\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_TCHECK2(*tptr, tlv_length);
216 switch(tlv_type) {
217
218 case LS_OPAQUE_GRACE_TLV_PERIOD:
219 if (tlv_length != 4) {
220 ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
221 return -1;
222 }
223 ND_PRINT((ndo, "%us", EXTRACT_32BITS(tptr)));
224 break;
225
226 case LS_OPAQUE_GRACE_TLV_REASON:
227 if (tlv_length != 1) {
228 ND_PRINT((ndo, "\n\t Bogus length %u != 1", tlv_length));
229 return -1;
230 }
231 ND_PRINT((ndo, "%s (%u)",
232 tok2str(lsa_opaque_grace_tlv_reason_values, "Unknown", *tptr),
233 *tptr));
234 break;
235
236 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS:
237 if (tlv_length != 4) {
238 ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
239 return -1;
240 }
241 ND_PRINT((ndo, "%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_print_te_lsa(netdissect_options *ndo,
266 const uint8_t *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_TCHECK2(*tptr, 4);
277 if (ls_length < 4) {
278 ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
279 return -1;
280 }
281 tlv_type = EXTRACT_16BITS(tptr);
282 tlv_length = EXTRACT_16BITS(tptr+2);
283 tptr+=4;
284 ls_length-=4;
285
286 ND_PRINT((ndo, "\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((ndo, "\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((ndo, "\n\t Remaining TLV length %u < 4",
307 tlv_length));
308 return -1;
309 }
310 ND_TCHECK2(*tptr, 4);
311 subtlv_type = EXTRACT_16BITS(tptr);
312 subtlv_length = EXTRACT_16BITS(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((ndo, "\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_TCHECK2(*tptr, subtlv_length);
326 switch(subtlv_type) {
327 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
328 if (subtlv_length != 4) {
329 ND_PRINT((ndo, " != 4"));
330 goto invalid;
331 }
332 ND_PRINT((ndo, ", 0x%08x", EXTRACT_32BITS(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((ndo, " != 4 && != 8"));
338 goto invalid;
339 }
340 ND_PRINT((ndo, ", %s (0x%08x)",
341 ipaddr_string(ndo, tptr),
342 EXTRACT_32BITS(tptr)));
343 if (subtlv_length == 8) /* rfc4203 */
344 ND_PRINT((ndo, ", %s (0x%08x)",
345 ipaddr_string(ndo, tptr+4),
346 EXTRACT_32BITS(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((ndo, " != 4"));
352 goto invalid;
353 }
354 ND_PRINT((ndo, ", %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((ndo, " != 4"));
360 goto invalid;
361 }
362 bw.i = EXTRACT_32BITS(tptr);
363 ND_PRINT((ndo, ", %.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((ndo, " != 32"));
368 goto invalid;
369 }
370 for (te_class = 0; te_class < 8; te_class++) {
371 bw.i = EXTRACT_32BITS(tptr+te_class*4);
372 ND_PRINT((ndo, "\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((ndo, " < 4"));
380 goto invalid;
381 }
382 /* BC Model Id (1 octet) + Reserved (3 octets) */
383 ND_PRINT((ndo, "\n\t\tBandwidth Constraints Model ID: %s (%u)",
384 tok2str(diffserv_te_bc_values, "unknown", *tptr),
385 *tptr));
386 if (subtlv_length % 4 != 0) {
387 ND_PRINT((ndo, "\n\t\tlength %u != N x 4", subtlv_length));
388 goto invalid;
389 }
390 if (subtlv_length > 36) {
391 ND_PRINT((ndo, "\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_32BITS(tptr+4+te_class*4);
397 ND_PRINT((ndo, "\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((ndo, " != 4"));
405 goto invalid;
406 }
407 ND_PRINT((ndo, ", Metric %u", EXTRACT_32BITS(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((ndo, " != 4"));
413 goto invalid;
414 }
415 ND_PRINT((ndo, ", %s",
416 bittok2str(gmpls_link_prot_values, "none", *tptr)));
417 break;
418 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
419 if (subtlv_length < 36) {
420 ND_PRINT((ndo, " < 36"));
421 goto invalid;
422 }
423 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
424 ND_PRINT((ndo, "\n\t\tInterface Switching Capability: %s",
425 tok2str(gmpls_switch_cap_values, "Unknown", *(tptr))));
426 ND_PRINT((ndo, "\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
427 tok2str(gmpls_encoding_values, "Unknown", *(tptr + 1))));
428 for (priority_level = 0; priority_level < 8; priority_level++) {
429 bw.i = EXTRACT_32BITS(tptr+4+(priority_level*4));
430 ND_PRINT((ndo, "\n\t\t priority level %d: %.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((ndo, " != 1"));
438 goto invalid;
439 }
440 ND_PRINT((ndo, ", %s (%u)",
441 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",*tptr),
442 *tptr));
443 break;
444
445 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
446 if (subtlv_length % 4 != 0) {
447 ND_PRINT((ndo, " != N x 4"));
448 goto invalid;
449 }
450 count_srlg = subtlv_length / 4;
451 if (count_srlg != 0)
452 ND_PRINT((ndo, "\n\t\t Shared risk group: "));
453 while (count_srlg > 0) {
454 bw.i = EXTRACT_32BITS(tptr);
455 ND_PRINT((ndo, "%d", bw.i));
456 tptr+=4;
457 count_srlg--;
458 if (count_srlg > 0)
459 ND_PRINT((ndo, ", "));
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((ndo, "\n\t TLV length %u < 4", tlv_length));
483 return -1;
484 }
485 ND_TCHECK2(*tptr, 4);
486 ND_PRINT((ndo, ", %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((ndo, "%s", istr));
507 return -1;
508 }
509
510 static int
511 ospf_print_lshdr(netdissect_options *ndo,
512 register const struct lsa_hdr *lshp)
513 {
514 u_int ls_length;
515
516 ND_TCHECK(lshp->ls_length);
517 ls_length = EXTRACT_16BITS(&lshp->ls_length);
518 if (ls_length < sizeof(struct lsa_hdr)) {
519 ND_PRINT((ndo, "\n\t Bogus length %u < header (%lu)", ls_length,
520 (unsigned long)sizeof(struct lsa_hdr)));
521 return(-1);
522 }
523
524 ND_TCHECK(lshp->ls_seq); /* XXX - ls_length check checked this */
525 ND_PRINT((ndo, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
526 ipaddr_string(ndo, &lshp->ls_router),
527 EXTRACT_32BITS(&lshp->ls_seq),
528 EXTRACT_16BITS(&lshp->ls_age),
529 ls_length - (u_int)sizeof(struct lsa_hdr)));
530
531 ND_TCHECK(lshp->ls_type); /* XXX - ls_length check checked this */
532 switch (lshp->ls_type) {
533 /* the LSA header for opaque LSAs was slightly changed */
534 case LS_TYPE_OPAQUE_LL:
535 case LS_TYPE_OPAQUE_AL:
536 case LS_TYPE_OPAQUE_DW:
537 ND_PRINT((ndo, "\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
538 tok2str(lsa_values,"unknown",lshp->ls_type),
539 lshp->ls_type,
540
541 tok2str(lsa_opaque_values,
542 "unknown",
543 *(&lshp->un_lsa_id.opaque_field.opaque_type)),
544 *(&lshp->un_lsa_id.opaque_field.opaque_type),
545 EXTRACT_24BITS(&lshp->un_lsa_id.opaque_field.opaque_id)
546
547 ));
548 break;
549
550 /* all other LSA types use regular style LSA headers */
551 default:
552 ND_PRINT((ndo, "\n\t %s LSA (%d), LSA-ID: %s",
553 tok2str(lsa_values,"unknown",lshp->ls_type),
554 lshp->ls_type,
555 ipaddr_string(ndo, &lshp->un_lsa_id.lsa_id)));
556 break;
557 }
558
559 ND_TCHECK(lshp->ls_options); /* XXX - ls_length check checked this */
560 ND_PRINT((ndo, "\n\t Options: [%s]", bittok2str(ospf_option_values, "none", lshp->ls_options)));
561
562 return (ls_length);
563 trunc:
564 return (-1);
565 }
566
567 /* draft-ietf-ospf-mt-09 */
568 static const struct tok ospf_topology_values[] = {
569 { 0, "default " },
570 { 1, "multicast " },
571 { 2, "management " },
572 { 0, NULL }
573 };
574
575 /*
576 * Print all the per-topology metrics.
577 */
578 static void
579 ospf_print_tos_metrics(netdissect_options *ndo,
580 const union un_tos *tos)
581 {
582 int metric_count;
583 int toscount;
584
585 toscount = tos->link.link_tos_count+1;
586 metric_count = 0;
587
588 /*
589 * All but the first metric contain a valid topology id.
590 */
591 while (toscount) {
592 ND_PRINT((ndo, "\n\t\ttopology %s(%u), metric %u",
593 tok2str(ospf_topology_values, "",
594 metric_count ? tos->metrics.tos_type : 0),
595 metric_count ? tos->metrics.tos_type : 0,
596 EXTRACT_16BITS(&tos->metrics.tos_metric)));
597 metric_count++;
598 tos++;
599 toscount--;
600 }
601 }
602
603 /*
604 * Print a single link state advertisement. If truncated or if LSA length
605 * field is less than the length of the LSA header, return NULl, else
606 * return pointer to data past end of LSA.
607 */
608 static const uint8_t *
609 ospf_print_lsa(netdissect_options *ndo,
610 register const struct lsa *lsap)
611 {
612 register const uint8_t *ls_end;
613 register const struct rlalink *rlp;
614 register const struct in_addr *ap;
615 register const struct aslametric *almp;
616 register const struct mcla *mcp;
617 register const uint32_t *lp;
618 register int j, tlv_type, tlv_length, topology;
619 register int ls_length;
620 const uint8_t *tptr;
621
622 tptr = (const uint8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
623 ls_length = ospf_print_lshdr(ndo, &lsap->ls_hdr);
624 if (ls_length == -1)
625 return(NULL);
626 ls_end = (const uint8_t *)lsap + ls_length;
627 ls_length -= sizeof(struct lsa_hdr);
628
629 switch (lsap->ls_hdr.ls_type) {
630
631 case LS_TYPE_ROUTER:
632 ND_TCHECK(lsap->lsa_un.un_rla.rla_flags);
633 ND_PRINT((ndo, "\n\t Router LSA Options: [%s]",
634 bittok2str(ospf_rla_flag_values, "none", lsap->lsa_un.un_rla.rla_flags)));
635
636 ND_TCHECK(lsap->lsa_un.un_rla.rla_count);
637 j = EXTRACT_16BITS(&lsap->lsa_un.un_rla.rla_count);
638 ND_TCHECK(lsap->lsa_un.un_rla.rla_link);
639 rlp = lsap->lsa_un.un_rla.rla_link;
640 while (j--) {
641 ND_TCHECK(*rlp);
642 switch (rlp->un_tos.link.link_type) {
643
644 case RLA_TYPE_VIRTUAL:
645 ND_PRINT((ndo, "\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
646 ipaddr_string(ndo, &rlp->link_id),
647 ipaddr_string(ndo, &rlp->link_data)));
648 break;
649
650 case RLA_TYPE_ROUTER:
651 ND_PRINT((ndo, "\n\t Neighbor Router-ID: %s, Interface Address: %s",
652 ipaddr_string(ndo, &rlp->link_id),
653 ipaddr_string(ndo, &rlp->link_data)));
654 break;
655
656 case RLA_TYPE_TRANSIT:
657 ND_PRINT((ndo, "\n\t Neighbor Network-ID: %s, Interface Address: %s",
658 ipaddr_string(ndo, &rlp->link_id),
659 ipaddr_string(ndo, &rlp->link_data)));
660 break;
661
662 case RLA_TYPE_STUB:
663 ND_PRINT((ndo, "\n\t Stub Network: %s, Mask: %s",
664 ipaddr_string(ndo, &rlp->link_id),
665 ipaddr_string(ndo, &rlp->link_data)));
666 break;
667
668 default:
669 ND_PRINT((ndo, "\n\t Unknown Router Link Type (%u)",
670 rlp->un_tos.link.link_type));
671 return (ls_end);
672 }
673
674 ospf_print_tos_metrics(ndo, &rlp->un_tos);
675
676 rlp = (const struct rlalink *)((const u_char *)(rlp + 1) +
677 ((rlp->un_tos.link.link_tos_count) * sizeof(union un_tos)));
678 }
679 break;
680
681 case LS_TYPE_NETWORK:
682 ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
683 ND_PRINT((ndo, "\n\t Mask %s\n\t Connected Routers:",
684 ipaddr_string(ndo, &lsap->lsa_un.un_nla.nla_mask)));
685 ap = lsap->lsa_un.un_nla.nla_router;
686 while ((const u_char *)ap < ls_end) {
687 ND_TCHECK(*ap);
688 ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
689 ++ap;
690 }
691 break;
692
693 case LS_TYPE_SUM_IP:
694 ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
695 ND_PRINT((ndo, "\n\t Mask %s",
696 ipaddr_string(ndo, &lsap->lsa_un.un_sla.sla_mask)));
697 ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
698 lp = lsap->lsa_un.un_sla.sla_tosmetric;
699 while ((const u_char *)lp < ls_end) {
700 register uint32_t ul;
701
702 ND_TCHECK(*lp);
703 ul = EXTRACT_32BITS(lp);
704 topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
705 ND_PRINT((ndo, "\n\t\ttopology %s(%u) metric %d",
706 tok2str(ospf_topology_values, "", topology),
707 topology,
708 ul & SLA_MASK_METRIC));
709 ++lp;
710 }
711 break;
712
713 case LS_TYPE_SUM_ABR:
714 ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
715 lp = lsap->lsa_un.un_sla.sla_tosmetric;
716 while ((const u_char *)lp < ls_end) {
717 register uint32_t ul;
718
719 ND_TCHECK(*lp);
720 ul = EXTRACT_32BITS(lp);
721 topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
722 ND_PRINT((ndo, "\n\t\ttopology %s(%u) metric %d",
723 tok2str(ospf_topology_values, "", topology),
724 topology,
725 ul & SLA_MASK_METRIC));
726 ++lp;
727 }
728 break;
729
730 case LS_TYPE_ASE:
731 case LS_TYPE_NSSA: /* fall through - those LSAs share the same format */
732 ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
733 ND_PRINT((ndo, "\n\t Mask %s",
734 ipaddr_string(ndo, &lsap->lsa_un.un_asla.asla_mask)));
735
736 ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
737 almp = lsap->lsa_un.un_asla.asla_metric;
738 while ((const u_char *)almp < ls_end) {
739 register uint32_t ul;
740
741 ND_TCHECK(almp->asla_tosmetric);
742 ul = EXTRACT_32BITS(&almp->asla_tosmetric);
743 topology = ((ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
744 ND_PRINT((ndo, "\n\t\ttopology %s(%u), type %d, metric",
745 tok2str(ospf_topology_values, "", topology),
746 topology,
747 (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1));
748 if ((ul & ASLA_MASK_METRIC) == 0xffffff)
749 ND_PRINT((ndo, " infinite"));
750 else
751 ND_PRINT((ndo, " %d", (ul & ASLA_MASK_METRIC)));
752
753 ND_TCHECK(almp->asla_forward);
754 if (almp->asla_forward.s_addr) {
755 ND_PRINT((ndo, ", forward %s", ipaddr_string(ndo, &almp->asla_forward)));
756 }
757 ND_TCHECK(almp->asla_tag);
758 if (almp->asla_tag.s_addr) {
759 ND_PRINT((ndo, ", tag %s", ipaddr_string(ndo, &almp->asla_tag)));
760 }
761 ++almp;
762 }
763 break;
764
765 case LS_TYPE_GROUP:
766 /* Multicast extensions as of 23 July 1991 */
767 mcp = lsap->lsa_un.un_mcla;
768 while ((const u_char *)mcp < ls_end) {
769 ND_TCHECK(mcp->mcla_vid);
770 switch (EXTRACT_32BITS(&mcp->mcla_vtype)) {
771
772 case MCLA_VERTEX_ROUTER:
773 ND_PRINT((ndo, "\n\t Router Router-ID %s",
774 ipaddr_string(ndo, &mcp->mcla_vid)));
775 break;
776
777 case MCLA_VERTEX_NETWORK:
778 ND_PRINT((ndo, "\n\t Network Designated Router %s",
779 ipaddr_string(ndo, &mcp->mcla_vid)));
780 break;
781
782 default:
783 ND_PRINT((ndo, "\n\t unknown VertexType (%u)",
784 EXTRACT_32BITS(&mcp->mcla_vtype)));
785 break;
786 }
787 ++mcp;
788 }
789 break;
790
791 case LS_TYPE_OPAQUE_LL: /* fall through */
792 case LS_TYPE_OPAQUE_AL:
793 case LS_TYPE_OPAQUE_DW:
794
795 switch (*(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
796 case LS_OPAQUE_TYPE_RI:
797 tptr = (const uint8_t *)(&lsap->lsa_un.un_ri_tlv.type);
798
799 while (ls_length != 0) {
800 ND_TCHECK2(*tptr, 4);
801 if (ls_length < 4) {
802 ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
803 return(ls_end);
804 }
805 tlv_type = EXTRACT_16BITS(tptr);
806 tlv_length = EXTRACT_16BITS(tptr+2);
807 tptr+=4;
808 ls_length-=4;
809
810 ND_PRINT((ndo, "\n\t %s TLV (%u), length: %u, value: ",
811 tok2str(lsa_opaque_ri_tlv_values,"unknown",tlv_type),
812 tlv_type,
813 tlv_length));
814
815 if (tlv_length > ls_length) {
816 ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
817 ls_length));
818 return(ls_end);
819 }
820 ND_TCHECK2(*tptr, tlv_length);
821 switch(tlv_type) {
822
823 case LS_OPAQUE_RI_TLV_CAP:
824 if (tlv_length != 4) {
825 ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
826 return(ls_end);
827 }
828 ND_PRINT((ndo, "Capabilities: %s",
829 bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", EXTRACT_32BITS(tptr))));
830 break;
831 default:
832 if (ndo->ndo_vflag <= 1) {
833 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
834 return(ls_end);
835 }
836 break;
837
838 }
839 tptr+=tlv_length;
840 ls_length-=tlv_length;
841 }
842 break;
843
844 case LS_OPAQUE_TYPE_GRACE:
845 if (ospf_print_grace_lsa(ndo, (const uint8_t *)(&lsap->lsa_un.un_grace_tlv.type),
846 ls_length) == -1) {
847 return(ls_end);
848 }
849 break;
850
851 case LS_OPAQUE_TYPE_TE:
852 if (ospf_print_te_lsa(ndo, (const uint8_t *)(&lsap->lsa_un.un_te_lsa_tlv.type),
853 ls_length) == -1) {
854 return(ls_end);
855 }
856 break;
857
858 default:
859 if (ndo->ndo_vflag <= 1) {
860 if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
861 "\n\t ", ls_length))
862 return(ls_end);
863 }
864 break;
865 }
866 }
867
868 /* do we want to see an additionally hexdump ? */
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
875 return (ls_end);
876 trunc:
877 return (NULL);
878 }
879
880 static int
881 ospf_decode_lls(netdissect_options *ndo,
882 register const struct ospfhdr *op, register u_int length)
883 {
884 register const u_char *dptr;
885 register const u_char *dataend;
886 register u_int length2;
887 register uint16_t lls_type, lls_len;
888 register uint32_t lls_flags;
889
890 switch (op->ospf_type) {
891
892 case OSPF_TYPE_HELLO:
893 if (!(op->ospf_hello.hello_options & OSPF_OPTION_L))
894 return (0);
895 break;
896
897 case OSPF_TYPE_DD:
898 if (!(op->ospf_db.db_options & OSPF_OPTION_L))
899 return (0);
900 break;
901
902 default:
903 return (0);
904 }
905
906 /* dig deeper if LLS data is available; see RFC4813 */
907 length2 = EXTRACT_16BITS(&op->ospf_len);
908 dptr = (const u_char *)op + length2;
909 dataend = (const u_char *)op + length;
910
911 if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
912 dptr = dptr + op->ospf_authdata[3];
913 length2 += op->ospf_authdata[3];
914 }
915 if (length2 >= length) {
916 ND_PRINT((ndo, "\n\t[LLS truncated]"));
917 return (1);
918 }
919 ND_TCHECK2(*dptr, 2);
920 ND_PRINT((ndo, "\n\t LLS: checksum: 0x%04x", (u_int)EXTRACT_16BITS(dptr)));
921
922 dptr += 2;
923 ND_TCHECK2(*dptr, 2);
924 length2 = EXTRACT_16BITS(dptr);
925 ND_PRINT((ndo, ", length: %u", length2));
926
927 dptr += 2;
928 ND_TCHECK(*dptr);
929 while (dptr < dataend) {
930 ND_TCHECK2(*dptr, 2);
931 lls_type = EXTRACT_16BITS(dptr);
932 ND_PRINT((ndo, "\n\t %s (%u)",
933 tok2str(ospf_lls_tlv_values,"Unknown TLV",lls_type),
934 lls_type));
935 dptr += 2;
936 ND_TCHECK2(*dptr, 2);
937 lls_len = EXTRACT_16BITS(dptr);
938 ND_PRINT((ndo, ", length: %u", lls_len));
939 dptr += 2;
940 switch (lls_type) {
941
942 case OSPF_LLS_EO:
943 if (lls_len != 4) {
944 ND_PRINT((ndo, " [should be 4]"));
945 lls_len = 4;
946 }
947 ND_TCHECK2(*dptr, 4);
948 lls_flags = EXTRACT_32BITS(dptr);
949 ND_PRINT((ndo, "\n\t Options: 0x%08x [%s]", lls_flags,
950 bittok2str(ospf_lls_eo_options, "?", lls_flags)));
951
952 break;
953
954 case OSPF_LLS_MD5:
955 if (lls_len != 20) {
956 ND_PRINT((ndo, " [should be 20]"));
957 lls_len = 20;
958 }
959 ND_TCHECK2(*dptr, 4);
960 ND_PRINT((ndo, "\n\t Sequence number: 0x%08x", EXTRACT_32BITS(dptr)));
961 break;
962 }
963
964 dptr += lls_len;
965 }
966
967 return (0);
968 trunc:
969 return (1);
970 }
971
972 static int
973 ospf_decode_v2(netdissect_options *ndo,
974 register const struct ospfhdr *op, register const u_char *dataend)
975 {
976 register const struct in_addr *ap;
977 register const struct lsr *lsrp;
978 register const struct lsa_hdr *lshp;
979 register const struct lsa *lsap;
980 register uint32_t lsa_count,lsa_count_max;
981
982 switch (op->ospf_type) {
983
984 case OSPF_TYPE_UMD:
985 /*
986 * Rob Coltun's special monitoring packets;
987 * do nothing
988 */
989 break;
990
991 case OSPF_TYPE_HELLO:
992 ND_PRINT((ndo, "\n\tOptions [%s]",
993 bittok2str(ospf_option_values,"none",op->ospf_hello.hello_options)));
994
995 ND_TCHECK(op->ospf_hello.hello_deadint);
996 ND_PRINT((ndo, "\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u",
997 EXTRACT_16BITS(&op->ospf_hello.hello_helloint),
998 EXTRACT_32BITS(&op->ospf_hello.hello_deadint),
999 ipaddr_string(ndo, &op->ospf_hello.hello_mask),
1000 op->ospf_hello.hello_priority));
1001
1002 ND_TCHECK(op->ospf_hello.hello_dr);
1003 if (op->ospf_hello.hello_dr.s_addr != 0)
1004 ND_PRINT((ndo, "\n\t Designated Router %s",
1005 ipaddr_string(ndo, &op->ospf_hello.hello_dr)));
1006
1007 ND_TCHECK(op->ospf_hello.hello_bdr);
1008 if (op->ospf_hello.hello_bdr.s_addr != 0)
1009 ND_PRINT((ndo, ", Backup Designated Router %s",
1010 ipaddr_string(ndo, &op->ospf_hello.hello_bdr)));
1011
1012 ap = op->ospf_hello.hello_neighbor;
1013 if ((const u_char *)ap < dataend)
1014 ND_PRINT((ndo, "\n\t Neighbor List:"));
1015 while ((const u_char *)ap < dataend) {
1016 ND_TCHECK(*ap);
1017 ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
1018 ++ap;
1019 }
1020 break; /* HELLO */
1021
1022 case OSPF_TYPE_DD:
1023 ND_TCHECK(op->ospf_db.db_options);
1024 ND_PRINT((ndo, "\n\tOptions [%s]",
1025 bittok2str(ospf_option_values, "none", op->ospf_db.db_options)));
1026 ND_TCHECK(op->ospf_db.db_flags);
1027 ND_PRINT((ndo, ", DD Flags [%s]",
1028 bittok2str(ospf_dd_flag_values, "none", op->ospf_db.db_flags)));
1029 ND_TCHECK(op->ospf_db.db_ifmtu);
1030 if (op->ospf_db.db_ifmtu) {
1031 ND_PRINT((ndo, ", MTU: %u", EXTRACT_16BITS(&op->ospf_db.db_ifmtu)));
1032 }
1033 ND_TCHECK(op->ospf_db.db_seq);
1034 ND_PRINT((ndo, ", Sequence: 0x%08x", EXTRACT_32BITS(&op->ospf_db.db_seq)));
1035
1036 /* Print all the LS adv's */
1037 lshp = op->ospf_db.db_lshdr;
1038 while (((const u_char *)lshp < dataend) && ospf_print_lshdr(ndo, lshp) != -1) {
1039 ++lshp;
1040 }
1041 break;
1042
1043 case OSPF_TYPE_LS_REQ:
1044 lsrp = op->ospf_lsr;
1045 while ((const u_char *)lsrp < dataend) {
1046 ND_TCHECK(*lsrp);
1047
1048 ND_PRINT((ndo, "\n\t Advertising Router: %s, %s LSA (%u)",
1049 ipaddr_string(ndo, &lsrp->ls_router),
1050 tok2str(lsa_values,"unknown",EXTRACT_32BITS(lsrp->ls_type)),
1051 EXTRACT_32BITS(&lsrp->ls_type)));
1052
1053 switch (EXTRACT_32BITS(lsrp->ls_type)) {
1054 /* the LSA header for opaque LSAs was slightly changed */
1055 case LS_TYPE_OPAQUE_LL:
1056 case LS_TYPE_OPAQUE_AL:
1057 case LS_TYPE_OPAQUE_DW:
1058 ND_PRINT((ndo, ", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
1059 tok2str(lsa_opaque_values, "unknown",lsrp->un_ls_stateid.opaque_field.opaque_type),
1060 lsrp->un_ls_stateid.opaque_field.opaque_type,
1061 EXTRACT_24BITS(&lsrp->un_ls_stateid.opaque_field.opaque_id)));
1062 break;
1063 default:
1064 ND_PRINT((ndo, ", LSA-ID: %s",
1065 ipaddr_string(ndo, &lsrp->un_ls_stateid.ls_stateid)));
1066 break;
1067 }
1068
1069 ++lsrp;
1070 }
1071 break;
1072
1073 case OSPF_TYPE_LS_UPDATE:
1074 lsap = op->ospf_lsu.lsu_lsa;
1075 ND_TCHECK(op->ospf_lsu.lsu_count);
1076 lsa_count_max = EXTRACT_32BITS(&op->ospf_lsu.lsu_count);
1077 ND_PRINT((ndo, ", %d LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max)));
1078 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
1079 ND_PRINT((ndo, "\n\t LSA #%u", lsa_count));
1080 lsap = (const struct lsa *)ospf_print_lsa(ndo, lsap);
1081 if (lsap == NULL)
1082 goto trunc;
1083 }
1084 break;
1085
1086 case OSPF_TYPE_LS_ACK:
1087 lshp = op->ospf_lsa.lsa_lshdr;
1088 while (ospf_print_lshdr(ndo, lshp) != -1) {
1089 ++lshp;
1090 }
1091 break;
1092
1093 default:
1094 break;
1095 }
1096 return (0);
1097 trunc:
1098 return (1);
1099 }
1100
1101 void
1102 ospf_print(netdissect_options *ndo,
1103 register const u_char *bp, register u_int length,
1104 const u_char *bp2 _U_)
1105 {
1106 register const struct ospfhdr *op;
1107 register const u_char *dataend;
1108 register const char *cp;
1109
1110 op = (const struct ospfhdr *)bp;
1111
1112 /* XXX Before we do anything else, strip off the MD5 trailer */
1113 ND_TCHECK(op->ospf_authtype);
1114 if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
1115 length -= OSPF_AUTH_MD5_LEN;
1116 ndo->ndo_snapend -= OSPF_AUTH_MD5_LEN;
1117 }
1118
1119 /* If the type is valid translate it, or just print the type */
1120 /* value. If it's not valid, say so and return */
1121 ND_TCHECK(op->ospf_type);
1122 cp = tok2str(type2str, "unknown LS-type", op->ospf_type);
1123 ND_PRINT((ndo, "OSPFv%u, %s, length %u", op->ospf_version, cp, length));
1124 if (*cp == 'u')
1125 return;
1126
1127 if (!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
1128 return;
1129 }
1130
1131 ND_TCHECK(op->ospf_len);
1132 if (length != EXTRACT_16BITS(&op->ospf_len)) {
1133 ND_PRINT((ndo, " [len %d]", EXTRACT_16BITS(&op->ospf_len)));
1134 }
1135
1136 if (length > EXTRACT_16BITS(&op->ospf_len)) {
1137 dataend = bp + EXTRACT_16BITS(&op->ospf_len);
1138 } else {
1139 dataend = bp + length;
1140 }
1141
1142 ND_TCHECK(op->ospf_routerid);
1143 ND_PRINT((ndo, "\n\tRouter-ID %s", ipaddr_string(ndo, &op->ospf_routerid)));
1144
1145 ND_TCHECK(op->ospf_areaid);
1146 if (op->ospf_areaid.s_addr != 0)
1147 ND_PRINT((ndo, ", Area %s", ipaddr_string(ndo, &op->ospf_areaid)));
1148 else
1149 ND_PRINT((ndo, ", Backbone Area"));
1150
1151 if (ndo->ndo_vflag) {
1152 /* Print authentication data (should we really do this?) */
1153 ND_TCHECK2(op->ospf_authdata[0], sizeof(op->ospf_authdata));
1154
1155 ND_PRINT((ndo, ", Authentication Type: %s (%u)",
1156 tok2str(ospf_authtype_values, "unknown", EXTRACT_16BITS(&op->ospf_authtype)),
1157 EXTRACT_16BITS(&op->ospf_authtype)));
1158
1159 switch (EXTRACT_16BITS(&op->ospf_authtype)) {
1160
1161 case OSPF_AUTH_NONE:
1162 break;
1163
1164 case OSPF_AUTH_SIMPLE:
1165 ND_PRINT((ndo, "\n\tSimple text password: "));
1166 safeputs(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN);
1167 break;
1168
1169 case OSPF_AUTH_MD5:
1170 ND_PRINT((ndo, "\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
1171 *((op->ospf_authdata) + 2),
1172 *((op->ospf_authdata) + 3),
1173 EXTRACT_32BITS((op->ospf_authdata) + 4)));
1174 break;
1175
1176 default:
1177 return;
1178 }
1179 }
1180 /* Do rest according to version. */
1181 switch (op->ospf_version) {
1182
1183 case 2:
1184 /* ospf version 2 */
1185 if (ospf_decode_v2(ndo, op, dataend))
1186 goto trunc;
1187 if (length > EXTRACT_16BITS(&op->ospf_len)) {
1188 if (ospf_decode_lls(ndo, op, length))
1189 goto trunc;
1190 }
1191 break;
1192
1193 default:
1194 ND_PRINT((ndo, " ospf [version %d]", op->ospf_version));
1195 break;
1196 } /* end switch on version */
1197
1198 return;
1199 trunc:
1200 ND_PRINT((ndo, "%s", tstr));
1201 }