]> The Tcpdump Group git mirrors - tcpdump/blob - print-ospf.c
Remove all storage class specifier 'register'
[tcpdump] / print-ospf.c
1 /*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
22 */
23
24 /* \summary: Open Shortest Path First (OSPF) printer */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include <netdissect-stdinc.h>
31
32 #include "netdissect.h"
33 #include "addrtoname.h"
34 #include "extract.h"
35 #include "gmpls.h"
36
37 #include "ospf.h"
38
39 static const char tstr[] = " [|ospf2]";
40
41 static const struct tok ospf_option_values[] = {
42 { OSPF_OPTION_T, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
43 { OSPF_OPTION_E, "External" },
44 { OSPF_OPTION_MC, "Multicast" },
45 { OSPF_OPTION_NP, "NSSA" },
46 { OSPF_OPTION_L, "LLS" },
47 { OSPF_OPTION_DC, "Demand Circuit" },
48 { OSPF_OPTION_O, "Opaque" },
49 { OSPF_OPTION_DN, "Up/Down" },
50 { 0, NULL }
51 };
52
53 static const struct tok ospf_authtype_values[] = {
54 { OSPF_AUTH_NONE, "none" },
55 { OSPF_AUTH_SIMPLE, "simple" },
56 { OSPF_AUTH_MD5, "MD5" },
57 { 0, NULL }
58 };
59
60 static const struct tok ospf_rla_flag_values[] = {
61 { RLA_FLAG_B, "ABR" },
62 { RLA_FLAG_E, "ASBR" },
63 { RLA_FLAG_W1, "Virtual" },
64 { RLA_FLAG_W2, "W2" },
65 { 0, NULL }
66 };
67
68 static const struct tok type2str[] = {
69 { OSPF_TYPE_HELLO, "Hello" },
70 { OSPF_TYPE_DD, "Database Description" },
71 { OSPF_TYPE_LS_REQ, "LS-Request" },
72 { OSPF_TYPE_LS_UPDATE, "LS-Update" },
73 { OSPF_TYPE_LS_ACK, "LS-Ack" },
74 { 0, NULL }
75 };
76
77 static const struct tok lsa_values[] = {
78 { LS_TYPE_ROUTER, "Router" },
79 { LS_TYPE_NETWORK, "Network" },
80 { LS_TYPE_SUM_IP, "Summary" },
81 { LS_TYPE_SUM_ABR, "ASBR Summary" },
82 { LS_TYPE_ASE, "External" },
83 { LS_TYPE_GROUP, "Multicast Group" },
84 { LS_TYPE_NSSA, "NSSA" },
85 { LS_TYPE_OPAQUE_LL, "Link Local Opaque" },
86 { LS_TYPE_OPAQUE_AL, "Area Local Opaque" },
87 { LS_TYPE_OPAQUE_DW, "Domain Wide Opaque" },
88 { 0, NULL }
89 };
90
91 static const struct tok ospf_dd_flag_values[] = {
92 { OSPF_DB_INIT, "Init" },
93 { OSPF_DB_MORE, "More" },
94 { OSPF_DB_MASTER, "Master" },
95 { OSPF_DB_RESYNC, "OOBResync" },
96 { 0, NULL }
97 };
98
99 static const struct tok lsa_opaque_values[] = {
100 { LS_OPAQUE_TYPE_TE, "Traffic Engineering" },
101 { LS_OPAQUE_TYPE_GRACE, "Graceful restart" },
102 { LS_OPAQUE_TYPE_RI, "Router Information" },
103 { 0, NULL }
104 };
105
106 static const struct tok lsa_opaque_te_tlv_values[] = {
107 { LS_OPAQUE_TE_TLV_ROUTER, "Router Address" },
108 { LS_OPAQUE_TE_TLV_LINK, "Link" },
109 { 0, NULL }
110 };
111
112 static const struct tok lsa_opaque_te_link_tlv_subtlv_values[] = {
113 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE, "Link Type" },
114 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID, "Link ID" },
115 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP, "Local Interface IP address" },
116 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP, "Remote Interface IP address" },
117 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC, "Traffic Engineering Metric" },
118 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW, "Maximum Bandwidth" },
119 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW, "Maximum Reservable Bandwidth" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW, "Unreserved Bandwidth" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP, "Administrative Group" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE, "Link Protection Type" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR, "Interface Switching Capability" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP, "Shared Risk Link Group" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS, "Bandwidth Constraints" },
127 { 0, NULL }
128 };
129
130 static const struct tok lsa_opaque_grace_tlv_values[] = {
131 { LS_OPAQUE_GRACE_TLV_PERIOD, "Grace Period" },
132 { LS_OPAQUE_GRACE_TLV_REASON, "Graceful restart Reason" },
133 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS, "IPv4 interface address" },
134 { 0, NULL }
135 };
136
137 static const struct tok lsa_opaque_grace_tlv_reason_values[] = {
138 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN, "Unknown" },
139 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART, "Software Restart" },
140 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE, "Software Reload/Upgrade" },
141 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH, "Control Processor Switch" },
142 { 0, NULL }
143 };
144
145 static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = {
146 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP, "Point-to-point" },
147 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA, "Multi-Access" },
148 { 0, NULL }
149 };
150
151 static const struct tok lsa_opaque_ri_tlv_values[] = {
152 { LS_OPAQUE_RI_TLV_CAP, "Router Capabilities" },
153 { 0, NULL }
154 };
155
156 static const struct tok lsa_opaque_ri_tlv_cap_values[] = {
157 { 1, "Reserved" },
158 { 2, "Reserved" },
159 { 4, "Reserved" },
160 { 8, "Reserved" },
161 { 16, "graceful restart capable" },
162 { 32, "graceful restart helper" },
163 { 64, "Stub router support" },
164 { 128, "Traffic engineering" },
165 { 256, "p2p over LAN" },
166 { 512, "path computation server" },
167 { 0, NULL }
168 };
169
170 static const struct tok ospf_lls_tlv_values[] = {
171 { OSPF_LLS_EO, "Extended Options" },
172 { OSPF_LLS_MD5, "MD5 Authentication" },
173 { 0, NULL }
174 };
175
176 static const struct tok ospf_lls_eo_options[] = {
177 { OSPF_LLS_EO_LR, "LSDB resync" },
178 { OSPF_LLS_EO_RS, "Restart" },
179 { 0, NULL }
180 };
181
182 int
183 ospf_print_grace_lsa(netdissect_options *ndo,
184 const uint8_t *tptr, u_int ls_length)
185 {
186 u_int tlv_type, tlv_length;
187
188
189 while (ls_length > 0) {
190 ND_TCHECK_4(tptr);
191 if (ls_length < 4) {
192 ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
193 return -1;
194 }
195 tlv_type = EXTRACT_BE_U_2(tptr);
196 tlv_length = EXTRACT_BE_U_2(tptr + 2);
197 tptr+=4;
198 ls_length-=4;
199
200 ND_PRINT((ndo, "\n\t %s TLV (%u), length %u, value: ",
201 tok2str(lsa_opaque_grace_tlv_values,"unknown",tlv_type),
202 tlv_type,
203 tlv_length));
204
205 if (tlv_length > ls_length) {
206 ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
207 ls_length));
208 return -1;
209 }
210
211 /* Infinite loop protection. */
212 if (tlv_type == 0 || tlv_length ==0) {
213 return -1;
214 }
215
216 ND_TCHECK_LEN(tptr, tlv_length);
217 switch(tlv_type) {
218
219 case LS_OPAQUE_GRACE_TLV_PERIOD:
220 if (tlv_length != 4) {
221 ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
222 return -1;
223 }
224 ND_PRINT((ndo, "%us", EXTRACT_BE_U_4(tptr)));
225 break;
226
227 case LS_OPAQUE_GRACE_TLV_REASON:
228 if (tlv_length != 1) {
229 ND_PRINT((ndo, "\n\t Bogus length %u != 1", tlv_length));
230 return -1;
231 }
232 ND_PRINT((ndo, "%s (%u)",
233 tok2str(lsa_opaque_grace_tlv_reason_values, "Unknown", EXTRACT_U_1(tptr)),
234 EXTRACT_U_1(tptr)));
235 break;
236
237 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS:
238 if (tlv_length != 4) {
239 ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
240 return -1;
241 }
242 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
243 break;
244
245 default:
246 if (ndo->ndo_vflag <= 1) {
247 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
248 return -1;
249 }
250 break;
251
252 }
253 /* in OSPF everything has to be 32-bit aligned, including TLVs */
254 if (tlv_length%4 != 0)
255 tlv_length+=4-(tlv_length%4);
256 ls_length-=tlv_length;
257 tptr+=tlv_length;
258 }
259
260 return 0;
261 trunc:
262 return -1;
263 }
264
265 int
266 ospf_print_te_lsa(netdissect_options *ndo,
267 const uint8_t *tptr, u_int ls_length)
268 {
269 u_int tlv_type, tlv_length, subtlv_type, subtlv_length;
270 u_int priority_level, te_class, count_srlg;
271 union { /* int to float conversion buffer for several subTLVs */
272 float f;
273 uint32_t i;
274 } bw;
275
276 while (ls_length != 0) {
277 ND_TCHECK_4(tptr);
278 if (ls_length < 4) {
279 ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
280 return -1;
281 }
282 tlv_type = EXTRACT_BE_U_2(tptr);
283 tlv_length = EXTRACT_BE_U_2(tptr + 2);
284 tptr+=4;
285 ls_length-=4;
286
287 ND_PRINT((ndo, "\n\t %s TLV (%u), length: %u",
288 tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type),
289 tlv_type,
290 tlv_length));
291
292 if (tlv_length > ls_length) {
293 ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
294 ls_length));
295 return -1;
296 }
297
298 /* Infinite loop protection. */
299 if (tlv_type == 0 || tlv_length ==0) {
300 return -1;
301 }
302
303 switch(tlv_type) {
304 case LS_OPAQUE_TE_TLV_LINK:
305 while (tlv_length >= sizeof(subtlv_type) + sizeof(subtlv_length)) {
306 if (tlv_length < 4) {
307 ND_PRINT((ndo, "\n\t Remaining TLV length %u < 4",
308 tlv_length));
309 return -1;
310 }
311 ND_TCHECK_4(tptr);
312 subtlv_type = EXTRACT_BE_U_2(tptr);
313 subtlv_length = EXTRACT_BE_U_2(tptr + 2);
314 tptr+=4;
315 tlv_length-=4;
316
317 /* Infinite loop protection */
318 if (subtlv_type == 0 || subtlv_length == 0)
319 goto invalid;
320
321 ND_PRINT((ndo, "\n\t %s subTLV (%u), length: %u",
322 tok2str(lsa_opaque_te_link_tlv_subtlv_values,"unknown",subtlv_type),
323 subtlv_type,
324 subtlv_length));
325
326 ND_TCHECK_LEN(tptr, subtlv_length);
327 switch(subtlv_type) {
328 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
329 if (subtlv_length != 4) {
330 ND_PRINT((ndo, " != 4"));
331 goto invalid;
332 }
333 ND_PRINT((ndo, ", 0x%08x", EXTRACT_BE_U_4(tptr)));
334 break;
335 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID:
336 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID:
337 if (subtlv_length != 4 && subtlv_length != 8) {
338 ND_PRINT((ndo, " != 4 && != 8"));
339 goto invalid;
340 }
341 ND_PRINT((ndo, ", %s (0x%08x)",
342 ipaddr_string(ndo, tptr),
343 EXTRACT_BE_U_4(tptr)));
344 if (subtlv_length == 8) /* rfc4203 */
345 ND_PRINT((ndo, ", %s (0x%08x)",
346 ipaddr_string(ndo, tptr+4),
347 EXTRACT_BE_U_4(tptr + 4)));
348 break;
349 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP:
350 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP:
351 if (subtlv_length != 4) {
352 ND_PRINT((ndo, " != 4"));
353 goto invalid;
354 }
355 ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr)));
356 break;
357 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
358 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
359 if (subtlv_length != 4) {
360 ND_PRINT((ndo, " != 4"));
361 goto invalid;
362 }
363 bw.i = EXTRACT_BE_U_4(tptr);
364 ND_PRINT((ndo, ", %.3f Mbps", bw.f * 8 / 1000000));
365 break;
366 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW:
367 if (subtlv_length != 32) {
368 ND_PRINT((ndo, " != 32"));
369 goto invalid;
370 }
371 for (te_class = 0; te_class < 8; te_class++) {
372 bw.i = EXTRACT_BE_U_4(tptr + te_class * 4);
373 ND_PRINT((ndo, "\n\t\tTE-Class %u: %.3f Mbps",
374 te_class,
375 bw.f * 8 / 1000000));
376 }
377 break;
378 case LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS:
379 if (subtlv_length < 4) {
380 ND_PRINT((ndo, " < 4"));
381 goto invalid;
382 }
383 /* BC Model Id (1 octet) + Reserved (3 octets) */
384 ND_PRINT((ndo, "\n\t\tBandwidth Constraints Model ID: %s (%u)",
385 tok2str(diffserv_te_bc_values, "unknown", EXTRACT_U_1(tptr)),
386 EXTRACT_U_1(tptr)));
387 if (subtlv_length % 4 != 0) {
388 ND_PRINT((ndo, "\n\t\tlength %u != N x 4", subtlv_length));
389 goto invalid;
390 }
391 if (subtlv_length > 36) {
392 ND_PRINT((ndo, "\n\t\tlength %u > 36", subtlv_length));
393 goto invalid;
394 }
395 /* decode BCs until the subTLV ends */
396 for (te_class = 0; te_class < (subtlv_length-4)/4; te_class++) {
397 bw.i = EXTRACT_BE_U_4(tptr + 4 + te_class * 4);
398 ND_PRINT((ndo, "\n\t\t Bandwidth constraint CT%u: %.3f Mbps",
399 te_class,
400 bw.f * 8 / 1000000));
401 }
402 break;
403 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC:
404 if (subtlv_length != 4) {
405 ND_PRINT((ndo, " != 4"));
406 goto invalid;
407 }
408 ND_PRINT((ndo, ", Metric %u", EXTRACT_BE_U_4(tptr)));
409 break;
410 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE:
411 /* Protection Cap (1 octet) + Reserved ((3 octets) */
412 if (subtlv_length != 4) {
413 ND_PRINT((ndo, " != 4"));
414 goto invalid;
415 }
416 ND_PRINT((ndo, ", %s",
417 bittok2str(gmpls_link_prot_values, "none", EXTRACT_U_1(tptr))));
418 break;
419 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
420 if (subtlv_length < 36) {
421 ND_PRINT((ndo, " < 36"));
422 goto invalid;
423 }
424 /* Switching Cap (1 octet) + Encoding (1) + Reserved (2) */
425 ND_PRINT((ndo, "\n\t\tInterface Switching Capability: %s",
426 tok2str(gmpls_switch_cap_values, "Unknown", EXTRACT_U_1((tptr)))));
427 ND_PRINT((ndo, "\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
428 tok2str(gmpls_encoding_values, "Unknown", EXTRACT_U_1((tptr + 1)))));
429 for (priority_level = 0; priority_level < 8; priority_level++) {
430 bw.i = EXTRACT_BE_U_4(tptr + 4 + (priority_level * 4));
431 ND_PRINT((ndo, "\n\t\t priority level %d: %.3f Mbps",
432 priority_level,
433 bw.f * 8 / 1000000));
434 }
435 break;
436 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE:
437 if (subtlv_length != 1) {
438 ND_PRINT((ndo, " != 1"));
439 goto invalid;
440 }
441 ND_PRINT((ndo, ", %s (%u)",
442 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",EXTRACT_U_1(tptr)),
443 EXTRACT_U_1(tptr)));
444 break;
445
446 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
447 if (subtlv_length % 4 != 0) {
448 ND_PRINT((ndo, " != N x 4"));
449 goto invalid;
450 }
451 count_srlg = subtlv_length / 4;
452 if (count_srlg != 0)
453 ND_PRINT((ndo, "\n\t\t Shared risk group: "));
454 while (count_srlg > 0) {
455 bw.i = EXTRACT_BE_U_4(tptr);
456 ND_PRINT((ndo, "%d", bw.i));
457 tptr+=4;
458 count_srlg--;
459 if (count_srlg > 0)
460 ND_PRINT((ndo, ", "));
461 }
462 break;
463
464 default:
465 if (ndo->ndo_vflag <= 1) {
466 if (!print_unknown_data(ndo, tptr, "\n\t\t", subtlv_length))
467 return -1;
468 }
469 break;
470 }
471 /* in OSPF everything has to be 32-bit aligned, including subTLVs */
472 if (subtlv_length%4 != 0)
473 subtlv_length+=4-(subtlv_length%4);
474
475 tlv_length-=subtlv_length;
476 tptr+=subtlv_length;
477
478 }
479 break;
480
481 case LS_OPAQUE_TE_TLV_ROUTER:
482 if (tlv_length < 4) {
483 ND_PRINT((ndo, "\n\t TLV length %u < 4", tlv_length));
484 return -1;
485 }
486 ND_TCHECK_4(tptr);
487 ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr)));
488 break;
489
490 default:
491 if (ndo->ndo_vflag <= 1) {
492 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
493 return -1;
494 }
495 break;
496 }
497 /* in OSPF everything has to be 32-bit aligned, including TLVs */
498 if (tlv_length%4 != 0)
499 tlv_length+=4-(tlv_length%4);
500 ls_length-=tlv_length;
501 tptr+=tlv_length;
502 }
503 return 0;
504 trunc:
505 return -1;
506 invalid:
507 ND_PRINT((ndo, "%s", istr));
508 return -1;
509 }
510
511 static int
512 ospf_print_lshdr(netdissect_options *ndo,
513 const struct lsa_hdr *lshp)
514 {
515 u_int ls_length;
516
517 ND_TCHECK(lshp->ls_length);
518 ls_length = EXTRACT_BE_U_2(&lshp->ls_length);
519 if (ls_length < sizeof(struct lsa_hdr)) {
520 ND_PRINT((ndo, "\n\t Bogus length %u < header (%lu)", ls_length,
521 (unsigned long)sizeof(struct lsa_hdr)));
522 return(-1);
523 }
524
525 ND_TCHECK(lshp->ls_seq); /* XXX - ls_length check checked this */
526 ND_PRINT((ndo, "\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(lshp->ls_type); /* XXX - ls_length check checked this */
533 switch (lshp->ls_type) {
534 /* the LSA header for opaque LSAs was slightly changed */
535 case LS_TYPE_OPAQUE_LL:
536 case LS_TYPE_OPAQUE_AL:
537 case LS_TYPE_OPAQUE_DW:
538 ND_PRINT((ndo, "\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u",
539 tok2str(lsa_values,"unknown",lshp->ls_type),
540 lshp->ls_type,
541
542 tok2str(lsa_opaque_values,
543 "unknown",
544 *(&lshp->un_lsa_id.opaque_field.opaque_type)),
545 *(&lshp->un_lsa_id.opaque_field.opaque_type),
546 EXTRACT_BE_U_3(&lshp->un_lsa_id.opaque_field.opaque_id)
547
548 ));
549 break;
550
551 /* all other LSA types use regular style LSA headers */
552 default:
553 ND_PRINT((ndo, "\n\t %s LSA (%d), LSA-ID: %s",
554 tok2str(lsa_values,"unknown",lshp->ls_type),
555 lshp->ls_type,
556 ipaddr_string(ndo, &lshp->un_lsa_id.lsa_id)));
557 break;
558 }
559
560 ND_TCHECK(lshp->ls_options); /* XXX - ls_length check checked this */
561 ND_PRINT((ndo, "\n\t Options: [%s]", bittok2str(ospf_option_values, "none", lshp->ls_options)));
562
563 return (ls_length);
564 trunc:
565 return (-1);
566 }
567
568 /* draft-ietf-ospf-mt-09 */
569 static const struct tok ospf_topology_values[] = {
570 { 0, "default" },
571 { 1, "multicast" },
572 { 2, "management" },
573 { 0, NULL }
574 };
575
576 /*
577 * Print all the per-topology metrics.
578 */
579 static int
580 ospf_print_tos_metrics(netdissect_options *ndo,
581 const union un_tos *tos)
582 {
583 int metric_count;
584 int toscount;
585
586 toscount = tos->link.link_tos_count+1;
587 metric_count = 0;
588
589 /*
590 * All but the first metric contain a valid topology id.
591 */
592 while (toscount > 0) {
593 ND_TCHECK(*tos);
594 ND_PRINT((ndo, "\n\t\ttopology %s (%u), metric %u",
595 tok2str(ospf_topology_values, "Unknown",
596 metric_count ? tos->metrics.tos_type : 0),
597 metric_count ? tos->metrics.tos_type : 0,
598 EXTRACT_BE_U_2(&tos->metrics.tos_metric)));
599 metric_count++;
600 tos++;
601 toscount--;
602 }
603 return 0;
604 trunc:
605 return 1;
606 }
607
608 /*
609 * Print a single link state advertisement. If truncated or if LSA length
610 * field is less than the length of the LSA header, return NULl, else
611 * return pointer to data past end of LSA.
612 */
613 static const uint8_t *
614 ospf_print_lsa(netdissect_options *ndo,
615 const struct lsa *lsap)
616 {
617 const uint8_t *ls_end;
618 const struct rlalink *rlp;
619 const struct in_addr *ap;
620 const struct aslametric *almp;
621 const struct mcla *mcp;
622 const uint32_t *lp;
623 int j, tlv_type, tlv_length, topology;
624 int ls_length;
625 const uint8_t *tptr;
626
627 tptr = (const uint8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
628 ls_length = ospf_print_lshdr(ndo, &lsap->ls_hdr);
629 if (ls_length == -1)
630 return(NULL);
631 ls_end = (const uint8_t *)lsap + ls_length;
632 ls_length -= sizeof(struct lsa_hdr);
633
634 switch (lsap->ls_hdr.ls_type) {
635
636 case LS_TYPE_ROUTER:
637 ND_TCHECK(lsap->lsa_un.un_rla.rla_flags);
638 ND_PRINT((ndo, "\n\t Router LSA Options: [%s]",
639 bittok2str(ospf_rla_flag_values, "none", lsap->lsa_un.un_rla.rla_flags)));
640
641 ND_TCHECK(lsap->lsa_un.un_rla.rla_count);
642 j = EXTRACT_BE_U_2(&lsap->lsa_un.un_rla.rla_count);
643 ND_TCHECK(lsap->lsa_un.un_rla.rla_link);
644 rlp = lsap->lsa_un.un_rla.rla_link;
645 while (j--) {
646 ND_TCHECK(*rlp);
647 switch (rlp->un_tos.link.link_type) {
648
649 case RLA_TYPE_VIRTUAL:
650 ND_PRINT((ndo, "\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
651 ipaddr_string(ndo, &rlp->link_id),
652 ipaddr_string(ndo, &rlp->link_data)));
653 break;
654
655 case RLA_TYPE_ROUTER:
656 ND_PRINT((ndo, "\n\t Neighbor Router-ID: %s, Interface Address: %s",
657 ipaddr_string(ndo, &rlp->link_id),
658 ipaddr_string(ndo, &rlp->link_data)));
659 break;
660
661 case RLA_TYPE_TRANSIT:
662 ND_PRINT((ndo, "\n\t Neighbor Network-ID: %s, Interface Address: %s",
663 ipaddr_string(ndo, &rlp->link_id),
664 ipaddr_string(ndo, &rlp->link_data)));
665 break;
666
667 case RLA_TYPE_STUB:
668 ND_PRINT((ndo, "\n\t Stub Network: %s, Mask: %s",
669 ipaddr_string(ndo, &rlp->link_id),
670 ipaddr_string(ndo, &rlp->link_data)));
671 break;
672
673 default:
674 ND_PRINT((ndo, "\n\t Unknown Router Link Type (%u)",
675 rlp->un_tos.link.link_type));
676 return (ls_end);
677 }
678
679 if (ospf_print_tos_metrics(ndo, &rlp->un_tos))
680 goto trunc;
681
682 rlp = (const struct rlalink *)((const u_char *)(rlp + 1) +
683 ((rlp->un_tos.link.link_tos_count) * sizeof(union un_tos)));
684 }
685 break;
686
687 case LS_TYPE_NETWORK:
688 ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
689 ND_PRINT((ndo, "\n\t Mask %s\n\t Connected Routers:",
690 ipaddr_string(ndo, &lsap->lsa_un.un_nla.nla_mask)));
691 ap = lsap->lsa_un.un_nla.nla_router;
692 while ((const u_char *)ap < ls_end) {
693 ND_TCHECK(*ap);
694 ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
695 ++ap;
696 }
697 break;
698
699 case LS_TYPE_SUM_IP:
700 ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
701 ND_PRINT((ndo, "\n\t Mask %s",
702 ipaddr_string(ndo, &lsap->lsa_un.un_sla.sla_mask)));
703 ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
704 lp = lsap->lsa_un.un_sla.sla_tosmetric;
705 while ((const u_char *)lp < ls_end) {
706 uint32_t ul;
707
708 ND_TCHECK(*lp);
709 ul = EXTRACT_BE_U_4(lp);
710 topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
711 ND_PRINT((ndo, "\n\t\ttopology %s (%u) metric %d",
712 tok2str(ospf_topology_values, "Unknown", topology),
713 topology,
714 ul & SLA_MASK_METRIC));
715 ++lp;
716 }
717 break;
718
719 case LS_TYPE_SUM_ABR:
720 ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
721 lp = lsap->lsa_un.un_sla.sla_tosmetric;
722 while ((const u_char *)lp < ls_end) {
723 uint32_t ul;
724
725 ND_TCHECK(*lp);
726 ul = EXTRACT_BE_U_4(lp);
727 topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS;
728 ND_PRINT((ndo, "\n\t\ttopology %s (%u) metric %d",
729 tok2str(ospf_topology_values, "Unknown", topology),
730 topology,
731 ul & SLA_MASK_METRIC));
732 ++lp;
733 }
734 break;
735
736 case LS_TYPE_ASE:
737 case LS_TYPE_NSSA: /* fall through - those LSAs share the same format */
738 ND_TCHECK(lsap->lsa_un.un_nla.nla_mask);
739 ND_PRINT((ndo, "\n\t Mask %s",
740 ipaddr_string(ndo, &lsap->lsa_un.un_asla.asla_mask)));
741
742 ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
743 almp = lsap->lsa_un.un_asla.asla_metric;
744 while ((const u_char *)almp < ls_end) {
745 uint32_t ul;
746
747 ND_TCHECK(almp->asla_tosmetric);
748 ul = EXTRACT_BE_U_4(&almp->asla_tosmetric);
749 topology = ((ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
750 ND_PRINT((ndo, "\n\t\ttopology %s (%u), type %d, metric",
751 tok2str(ospf_topology_values, "Unknown", topology),
752 topology,
753 (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1));
754 if ((ul & ASLA_MASK_METRIC) == 0xffffff)
755 ND_PRINT((ndo, " infinite"));
756 else
757 ND_PRINT((ndo, " %d", (ul & ASLA_MASK_METRIC)));
758
759 ND_TCHECK(almp->asla_forward);
760 if (almp->asla_forward.s_addr) {
761 ND_PRINT((ndo, ", forward %s", ipaddr_string(ndo, &almp->asla_forward)));
762 }
763 ND_TCHECK(almp->asla_tag);
764 if (almp->asla_tag.s_addr) {
765 ND_PRINT((ndo, ", tag %s", ipaddr_string(ndo, &almp->asla_tag)));
766 }
767 ++almp;
768 }
769 break;
770
771 case LS_TYPE_GROUP:
772 /* Multicast extensions as of 23 July 1991 */
773 mcp = lsap->lsa_un.un_mcla;
774 while ((const u_char *)mcp < ls_end) {
775 ND_TCHECK(mcp->mcla_vid);
776 switch (EXTRACT_BE_U_4(&mcp->mcla_vtype)) {
777
778 case MCLA_VERTEX_ROUTER:
779 ND_PRINT((ndo, "\n\t Router Router-ID %s",
780 ipaddr_string(ndo, &mcp->mcla_vid)));
781 break;
782
783 case MCLA_VERTEX_NETWORK:
784 ND_PRINT((ndo, "\n\t Network Designated Router %s",
785 ipaddr_string(ndo, &mcp->mcla_vid)));
786 break;
787
788 default:
789 ND_PRINT((ndo, "\n\t unknown VertexType (%u)",
790 EXTRACT_BE_U_4(&mcp->mcla_vtype)));
791 break;
792 }
793 ++mcp;
794 }
795 break;
796
797 case LS_TYPE_OPAQUE_LL: /* fall through */
798 case LS_TYPE_OPAQUE_AL:
799 case LS_TYPE_OPAQUE_DW:
800
801 switch (*(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
802 case LS_OPAQUE_TYPE_RI:
803 tptr = (const uint8_t *)(&lsap->lsa_un.un_ri_tlv.type);
804
805 while (ls_length != 0) {
806 ND_TCHECK_4(tptr);
807 if (ls_length < 4) {
808 ND_PRINT((ndo, "\n\t Remaining LS length %u < 4", ls_length));
809 return(ls_end);
810 }
811 tlv_type = EXTRACT_BE_U_2(tptr);
812 tlv_length = EXTRACT_BE_U_2(tptr + 2);
813 tptr+=4;
814 ls_length-=4;
815
816 ND_PRINT((ndo, "\n\t %s TLV (%u), length: %u, value: ",
817 tok2str(lsa_opaque_ri_tlv_values,"unknown",tlv_type),
818 tlv_type,
819 tlv_length));
820
821 if (tlv_length > ls_length) {
822 ND_PRINT((ndo, "\n\t Bogus length %u > %u", tlv_length,
823 ls_length));
824 return(ls_end);
825 }
826 ND_TCHECK_LEN(tptr, tlv_length);
827 switch(tlv_type) {
828
829 case LS_OPAQUE_RI_TLV_CAP:
830 if (tlv_length != 4) {
831 ND_PRINT((ndo, "\n\t Bogus length %u != 4", tlv_length));
832 return(ls_end);
833 }
834 ND_PRINT((ndo, "Capabilities: %s",
835 bittok2str(lsa_opaque_ri_tlv_cap_values, "Unknown", EXTRACT_BE_U_4(tptr))));
836 break;
837 default:
838 if (ndo->ndo_vflag <= 1) {
839 if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))
840 return(ls_end);
841 }
842 break;
843
844 }
845 tptr+=tlv_length;
846 ls_length-=tlv_length;
847 }
848 break;
849
850 case LS_OPAQUE_TYPE_GRACE:
851 if (ospf_print_grace_lsa(ndo, (const uint8_t *)(&lsap->lsa_un.un_grace_tlv.type),
852 ls_length) == -1) {
853 return(ls_end);
854 }
855 break;
856
857 case LS_OPAQUE_TYPE_TE:
858 if (ospf_print_te_lsa(ndo, (const uint8_t *)(&lsap->lsa_un.un_te_lsa_tlv.type),
859 ls_length) == -1) {
860 return(ls_end);
861 }
862 break;
863
864 default:
865 if (ndo->ndo_vflag <= 1) {
866 if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
867 "\n\t ", ls_length))
868 return(ls_end);
869 }
870 break;
871 }
872 }
873
874 /* do we want to see an additionally hexdump ? */
875 if (ndo->ndo_vflag> 1)
876 if (!print_unknown_data(ndo, (const uint8_t *)lsap->lsa_un.un_unknown,
877 "\n\t ", ls_length)) {
878 return(ls_end);
879 }
880
881 return (ls_end);
882 trunc:
883 return (NULL);
884 }
885
886 static int
887 ospf_decode_lls(netdissect_options *ndo,
888 const struct ospfhdr *op, u_int length)
889 {
890 const u_char *dptr;
891 const u_char *dataend;
892 u_int length2;
893 uint16_t lls_type, lls_len;
894 uint32_t lls_flags;
895
896 switch (op->ospf_type) {
897
898 case OSPF_TYPE_HELLO:
899 if (!(op->ospf_hello.hello_options & OSPF_OPTION_L))
900 return (0);
901 break;
902
903 case OSPF_TYPE_DD:
904 if (!(op->ospf_db.db_options & OSPF_OPTION_L))
905 return (0);
906 break;
907
908 default:
909 return (0);
910 }
911
912 /* dig deeper if LLS data is available; see RFC4813 */
913 length2 = EXTRACT_BE_U_2(&op->ospf_len);
914 dptr = (const u_char *)op + length2;
915 dataend = (const u_char *)op + length;
916
917 if (EXTRACT_BE_U_2(&op->ospf_authtype) == OSPF_AUTH_MD5) {
918 dptr = dptr + op->ospf_authdata[3];
919 length2 += op->ospf_authdata[3];
920 }
921 if (length2 >= length) {
922 ND_PRINT((ndo, "\n\t[LLS truncated]"));
923 return (1);
924 }
925 ND_TCHECK_2(dptr);
926 ND_PRINT((ndo, "\n\t LLS: checksum: 0x%04x", (u_int) EXTRACT_BE_U_2(dptr)));
927
928 dptr += 2;
929 ND_TCHECK_2(dptr);
930 length2 = EXTRACT_BE_U_2(dptr);
931 ND_PRINT((ndo, ", length: %u", length2));
932
933 dptr += 2;
934 ND_TCHECK_1(dptr);
935 while (dptr < dataend) {
936 ND_TCHECK_2(dptr);
937 lls_type = EXTRACT_BE_U_2(dptr);
938 ND_PRINT((ndo, "\n\t %s (%u)",
939 tok2str(ospf_lls_tlv_values,"Unknown TLV",lls_type),
940 lls_type));
941 dptr += 2;
942 ND_TCHECK_2(dptr);
943 lls_len = EXTRACT_BE_U_2(dptr);
944 ND_PRINT((ndo, ", length: %u", lls_len));
945 dptr += 2;
946 switch (lls_type) {
947
948 case OSPF_LLS_EO:
949 if (lls_len != 4) {
950 ND_PRINT((ndo, " [should be 4]"));
951 lls_len = 4;
952 }
953 ND_TCHECK_4(dptr);
954 lls_flags = EXTRACT_BE_U_4(dptr);
955 ND_PRINT((ndo, "\n\t Options: 0x%08x [%s]", lls_flags,
956 bittok2str(ospf_lls_eo_options, "?", lls_flags)));
957
958 break;
959
960 case OSPF_LLS_MD5:
961 if (lls_len != 20) {
962 ND_PRINT((ndo, " [should be 20]"));
963 lls_len = 20;
964 }
965 ND_TCHECK_4(dptr);
966 ND_PRINT((ndo, "\n\t Sequence number: 0x%08x", EXTRACT_BE_U_4(dptr)));
967 break;
968 }
969
970 dptr += lls_len;
971 }
972
973 return (0);
974 trunc:
975 return (1);
976 }
977
978 static int
979 ospf_decode_v2(netdissect_options *ndo,
980 const struct ospfhdr *op, const u_char *dataend)
981 {
982 const struct in_addr *ap;
983 const struct lsr *lsrp;
984 const struct lsa_hdr *lshp;
985 const struct lsa *lsap;
986 uint32_t lsa_count,lsa_count_max;
987
988 switch (op->ospf_type) {
989
990 case OSPF_TYPE_HELLO:
991 ND_TCHECK(op->ospf_hello.hello_options);
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_BE_U_2(&op->ospf_hello.hello_helloint),
998 EXTRACT_BE_U_4(&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_BE_U_2(&op->ospf_db.db_ifmtu)));
1032 }
1033 ND_TCHECK(op->ospf_db.db_seq);
1034 ND_PRINT((ndo, ", Sequence: 0x%08x", EXTRACT_BE_U_4(&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_BE_U_4(lsrp->ls_type)),
1051 EXTRACT_BE_U_4(&lsrp->ls_type)));
1052
1053 switch (EXTRACT_BE_U_4(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_BE_U_3(&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_BE_U_4(&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 const u_char *bp, u_int length,
1104 const u_char *bp2 _U_)
1105 {
1106 const struct ospfhdr *op;
1107 const u_char *dataend;
1108 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_BE_U_2(&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 %u", 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_BE_U_2(&op->ospf_len)) {
1133 ND_PRINT((ndo, " [len %d]", EXTRACT_BE_U_2(&op->ospf_len)));
1134 }
1135
1136 if (length > EXTRACT_BE_U_2(&op->ospf_len)) {
1137 dataend = bp + EXTRACT_BE_U_2(&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_TCHECK_LEN(op->ospf_authdata, sizeof(op->ospf_authdata));
1154
1155 ND_PRINT((ndo, ", Authentication Type: %s (%u)",
1156 tok2str(ospf_authtype_values, "unknown", EXTRACT_BE_U_2(&op->ospf_authtype)),
1157 EXTRACT_BE_U_2(&op->ospf_authtype)));
1158
1159 switch (EXTRACT_BE_U_2(&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_BE_U_4((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_BE_U_2(&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 }