]> The Tcpdump Group git mirrors - tcpdump/blob - print-ospf6.c
dba73ab815ffa86dfff8d82d33393c14524af7f2
[tcpdump] / print-ospf6.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 #ifndef lint
25 static const char rcsid[] _U_ =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-ospf6.c,v 1.15 2006-09-13 06:31:11 guy Exp $ (LBL)";
27 #endif
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <tcpdump-stdinc.h>
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include "interface.h"
39 #include "addrtoname.h"
40 #include "extract.h"
41
42 #include "ospf.h"
43 #include "ospf6.h"
44
45 static const char tstr[] = " [|ospf3]";
46
47 static const struct tok ospf6_option_values[] = {
48 { OSPF6_OPTION_V6, "V6" },
49 { OSPF6_OPTION_E, "External" },
50 { OSPF6_OPTION_MC, "Deprecated" },
51 { OSPF6_OPTION_N, "NSSA" },
52 { OSPF6_OPTION_R, "Router" },
53 { OSPF6_OPTION_DC, "Demand Circuit" },
54 { OSPF6_OPTION_AF, "AFs Support" },
55 { OSPF6_OPTION_L, "LLS" },
56 { OSPF6_OPTION_AT, "Authentication Trailer" },
57 { 0, NULL }
58 };
59
60 static const struct tok ospf6_rla_flag_values[] = {
61 { RLA_FLAG_B, "ABR" },
62 { RLA_FLAG_E, "External" },
63 { RLA_FLAG_V, "Virtual-Link Endpoint" },
64 { RLA_FLAG_W, "Wildcard Receiver" },
65 { RLA_FLAG_N, "NSSA Translator" },
66 { 0, NULL }
67 };
68
69 static const struct tok ospf6_asla_flag_values[] = {
70 { ASLA_FLAG_EXTERNAL, "External Type 2" },
71 { ASLA_FLAG_FWDADDR, "Forwarding" },
72 { ASLA_FLAG_ROUTETAG, "Tag" },
73 { 0, NULL }
74 };
75
76 static const struct tok ospf6_type_values[] = {
77 { OSPF_TYPE_HELLO, "Hello" },
78 { OSPF_TYPE_DD, "Database Description" },
79 { OSPF_TYPE_LS_REQ, "LS-Request" },
80 { OSPF_TYPE_LS_UPDATE, "LS-Update" },
81 { OSPF_TYPE_LS_ACK, "LS-Ack" },
82 { 0, NULL }
83 };
84
85 static const struct tok ospf6_lsa_values[] = {
86 { LS_TYPE_ROUTER, "Router" },
87 { LS_TYPE_NETWORK, "Network" },
88 { LS_TYPE_INTER_AP, "Inter-Area Prefix" },
89 { LS_TYPE_INTER_AR, "Inter-Area Router" },
90 { LS_TYPE_ASE, "External" },
91 { LS_TYPE_GROUP, "Deprecated" },
92 { LS_TYPE_NSSA, "NSSA" },
93 { LS_TYPE_LINK, "Link" },
94 { LS_TYPE_INTRA_AP, "Intra-Area Prefix" },
95 { LS_TYPE_INTRA_ATE, "Intra-Area TE" },
96 { LS_TYPE_GRACE, "Grace" },
97 { LS_TYPE_RI, "Router Information" },
98 { LS_TYPE_INTER_ASTE, "Inter-AS-TE" },
99 { LS_TYPE_L1VPN, "Layer 1 VPN" },
100 { 0, NULL }
101 };
102
103 static const struct tok ospf6_ls_scope_values[] = {
104 { LS_SCOPE_LINKLOCAL, "Link Local" },
105 { LS_SCOPE_AREA, "Area Local" },
106 { LS_SCOPE_AS, "Domain Wide" },
107 { 0, NULL }
108 };
109
110 static const struct tok ospf6_dd_flag_values[] = {
111 { OSPF6_DB_INIT, "Init" },
112 { OSPF6_DB_MORE, "More" },
113 { OSPF6_DB_MASTER, "Master" },
114 { OSPF6_DB_M6, "IPv6 MTU" },
115 { 0, NULL }
116 };
117
118 static const struct tok ospf6_lsa_prefix_option_values[] = {
119 { LSA_PREFIX_OPT_NU, "No Unicast" },
120 { LSA_PREFIX_OPT_LA, "Local address" },
121 { LSA_PREFIX_OPT_MC, "Deprecated" },
122 { LSA_PREFIX_OPT_P, "Propagate" },
123 { LSA_PREFIX_OPT_DN, "Down" },
124 { 0, NULL }
125 };
126
127 static const struct tok ospf6_auth_type_str[] = {
128 { OSPF6_AUTH_TYPE_HMAC, "HMAC" },
129 { 0, NULL }
130 };
131
132 static void
133 ospf6_print_ls_type(register u_int ls_type, register const rtrid_t *ls_stateid)
134 {
135 printf("\n\t %s LSA (%d), %s Scope%s, LSA-ID %s",
136 tok2str(ospf6_lsa_values, "Unknown", ls_type & LS_TYPE_MASK),
137 ls_type & LS_TYPE_MASK,
138 tok2str(ospf6_ls_scope_values, "Unknown", ls_type & LS_SCOPE_MASK),
139 ls_type &0x8000 ? ", transitive" : "", /* U-bit */
140 ipaddr_string(ls_stateid));
141 }
142
143 static int
144 ospf6_print_lshdr(register const struct lsa6_hdr *lshp, const u_char *dataend)
145 {
146 if ((u_char *)(lshp + 1) > dataend)
147 goto trunc;
148 TCHECK(lshp->ls_type);
149 TCHECK(lshp->ls_seq);
150
151 printf("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
152 ipaddr_string(&lshp->ls_router),
153 EXTRACT_32BITS(&lshp->ls_seq),
154 EXTRACT_16BITS(&lshp->ls_age),
155 EXTRACT_16BITS(&lshp->ls_length)-(u_int)sizeof(struct lsa6_hdr));
156
157 ospf6_print_ls_type(EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid);
158
159 return (0);
160 trunc:
161 return (1);
162 }
163
164 static int
165 ospf6_print_lsaprefix(const u_int8_t *tptr, u_int lsa_length)
166 {
167 const struct lsa6_prefix *lsapp = (struct lsa6_prefix *)tptr;
168 u_int wordlen;
169 struct in6_addr prefix;
170
171 if (lsa_length < sizeof (*lsapp) - 4)
172 goto trunc;
173 lsa_length -= sizeof (*lsapp) - 4;
174 TCHECK2(*lsapp, sizeof (*lsapp) - 4);
175 wordlen = (lsapp->lsa_p_len + 31) / 32;
176 if (wordlen * 4 > sizeof(struct in6_addr)) {
177 printf(" bogus prefixlen /%d", lsapp->lsa_p_len);
178 goto trunc;
179 }
180 if (lsa_length < wordlen * 4)
181 goto trunc;
182 lsa_length -= wordlen * 4;
183 TCHECK2(lsapp->lsa_p_prefix, wordlen * 4);
184 memset(&prefix, 0, sizeof(prefix));
185 memcpy(&prefix, lsapp->lsa_p_prefix, wordlen * 4);
186 printf("\n\t\t%s/%d", ip6addr_string(&prefix),
187 lsapp->lsa_p_len);
188 if (lsapp->lsa_p_opt) {
189 printf(", Options [%s]",
190 bittok2str(ospf6_lsa_prefix_option_values,
191 "none", lsapp->lsa_p_opt));
192 }
193 printf(", metric %u", EXTRACT_16BITS(&lsapp->lsa_p_metric));
194 return sizeof(*lsapp) - 4 + wordlen * 4;
195
196 trunc:
197 return -1;
198 }
199
200
201 /*
202 * Print a single link state advertisement. If truncated return 1, else 0.
203 */
204 static int
205 ospf6_print_lsa(register const struct lsa6 *lsap, const u_char *dataend)
206 {
207 register const struct rlalink6 *rlp;
208 #if 0
209 register const struct tos_metric *tosp;
210 #endif
211 register const rtrid_t *ap;
212 #if 0
213 register const struct aslametric *almp;
214 register const struct mcla *mcp;
215 #endif
216 register const struct llsa *llsap;
217 register const struct lsa6_prefix *lsapp;
218 #if 0
219 register const u_int32_t *lp;
220 #endif
221 register u_int prefixes;
222 register int bytelen;
223 register u_int length, lsa_length;
224 u_int32_t flags32;
225 const u_int8_t *tptr;
226
227 if (ospf6_print_lshdr(&lsap->ls_hdr, dataend))
228 return (1);
229 TCHECK(lsap->ls_hdr.ls_length);
230 length = EXTRACT_16BITS(&lsap->ls_hdr.ls_length);
231
232 /*
233 * The LSA length includes the length of the header;
234 * it must have a value that's at least that length.
235 * If it does, find the length of what follows the
236 * header.
237 */
238 if (length < sizeof(struct lsa6_hdr) || (u_char *)lsap + length > dataend)
239 return (1);
240 lsa_length = length - sizeof(struct lsa6_hdr);
241 tptr = (u_int8_t *)lsap+sizeof(struct lsa6_hdr);
242
243 switch (EXTRACT_16BITS(&lsap->ls_hdr.ls_type)) {
244 case LS_TYPE_ROUTER | LS_SCOPE_AREA:
245 if (lsa_length < sizeof (lsap->lsa_un.un_rla.rla_options))
246 return (1);
247 lsa_length -= sizeof (lsap->lsa_un.un_rla.rla_options);
248 TCHECK(lsap->lsa_un.un_rla.rla_options);
249 printf("\n\t Options [%s]",
250 bittok2str(ospf6_option_values, "none",
251 EXTRACT_32BITS(&lsap->lsa_un.un_rla.rla_options)));
252 printf(", RLA-Flags [%s]",
253 bittok2str(ospf6_rla_flag_values, "none",
254 lsap->lsa_un.un_rla.rla_flags));
255
256 rlp = lsap->lsa_un.un_rla.rla_link;
257 while (lsa_length != 0) {
258 if (lsa_length < sizeof (*rlp))
259 return (1);
260 lsa_length -= sizeof (*rlp);
261 TCHECK(*rlp);
262 switch (rlp->link_type) {
263
264 case RLA_TYPE_VIRTUAL:
265 printf("\n\t Virtual Link: Neighbor Router-ID %s"
266 "\n\t Neighbor Interface-ID %s, Interface %s",
267 ipaddr_string(&rlp->link_nrtid),
268 ipaddr_string(&rlp->link_nifid),
269 ipaddr_string(&rlp->link_ifid));
270 break;
271
272 case RLA_TYPE_ROUTER:
273 printf("\n\t Neighbor Router-ID %s"
274 "\n\t Neighbor Interface-ID %s, Interface %s",
275 ipaddr_string(&rlp->link_nrtid),
276 ipaddr_string(&rlp->link_nifid),
277 ipaddr_string(&rlp->link_ifid));
278 break;
279
280 case RLA_TYPE_TRANSIT:
281 printf("\n\t Neighbor Network-ID %s"
282 "\n\t Neighbor Interface-ID %s, Interface %s",
283 ipaddr_string(&rlp->link_nrtid),
284 ipaddr_string(&rlp->link_nifid),
285 ipaddr_string(&rlp->link_ifid));
286 break;
287
288 default:
289 printf("\n\t Unknown Router Links Type 0x%02x",
290 rlp->link_type);
291 return (0);
292 }
293 printf(", metric %d", EXTRACT_16BITS(&rlp->link_metric));
294 rlp++;
295 }
296 break;
297
298 case LS_TYPE_NETWORK | LS_SCOPE_AREA:
299 if (lsa_length < sizeof (lsap->lsa_un.un_nla.nla_options))
300 return (1);
301 lsa_length -= sizeof (lsap->lsa_un.un_nla.nla_options);
302 TCHECK(lsap->lsa_un.un_nla.nla_options);
303 printf("\n\t Options [%s]",
304 bittok2str(ospf6_option_values, "none",
305 EXTRACT_32BITS(&lsap->lsa_un.un_nla.nla_options)));
306
307 printf("\n\t Connected Routers:");
308 ap = lsap->lsa_un.un_nla.nla_router;
309 while (lsa_length != 0) {
310 if (lsa_length < sizeof (*ap))
311 return (1);
312 lsa_length -= sizeof (*ap);
313 TCHECK(*ap);
314 printf("\n\t\t%s", ipaddr_string(ap));
315 ++ap;
316 }
317 break;
318
319 case LS_TYPE_INTER_AP | LS_SCOPE_AREA:
320 if (lsa_length < sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric))
321 return (1);
322 lsa_length -= sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric);
323 TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric);
324 printf(", metric %u",
325 EXTRACT_32BITS(&lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC);
326
327 tptr = (u_int8_t *)lsap->lsa_un.un_inter_ap.inter_ap_prefix;
328 while (lsa_length != 0) {
329 bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
330 if (bytelen < 0)
331 goto trunc;
332 lsa_length -= bytelen;
333 tptr += bytelen;
334 }
335 break;
336
337 case LS_TYPE_ASE | LS_SCOPE_AS:
338 if (lsa_length < sizeof (lsap->lsa_un.un_asla.asla_metric))
339 return (1);
340 lsa_length -= sizeof (lsap->lsa_un.un_asla.asla_metric);
341 TCHECK(lsap->lsa_un.un_asla.asla_metric);
342 flags32 = EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric);
343 printf("\n\t Flags [%s]",
344 bittok2str(ospf6_asla_flag_values, "none", flags32));
345 printf(" metric %u",
346 EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric) &
347 ASLA_MASK_METRIC);
348
349 tptr = (u_int8_t *)lsap->lsa_un.un_asla.asla_prefix;
350 lsapp = (struct lsa6_prefix *)tptr;
351 bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
352 if (bytelen < 0)
353 goto trunc;
354 lsa_length -= bytelen;
355 tptr += bytelen;
356
357 if ((flags32 & ASLA_FLAG_FWDADDR) != 0) {
358 struct in6_addr *fwdaddr6;
359
360 fwdaddr6 = (struct in6_addr *)tptr;
361 if (lsa_length < sizeof (*fwdaddr6))
362 return (1);
363 lsa_length -= sizeof (*fwdaddr6);
364 TCHECK(*fwdaddr6);
365 printf(" forward %s",
366 ip6addr_string(fwdaddr6));
367 tptr += sizeof(*fwdaddr6);
368 }
369
370 if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) {
371 if (lsa_length < sizeof (u_int32_t))
372 return (1);
373 lsa_length -= sizeof (u_int32_t);
374 TCHECK(*(u_int32_t *)tptr);
375 printf(" tag %s",
376 ipaddr_string((u_int32_t *)tptr));
377 tptr += sizeof(u_int32_t);
378 }
379
380 if (lsapp->lsa_p_metric) {
381 if (lsa_length < sizeof (u_int32_t))
382 return (1);
383 lsa_length -= sizeof (u_int32_t);
384 TCHECK(*(u_int32_t *)tptr);
385 printf(" RefLSID: %s",
386 ipaddr_string((u_int32_t *)tptr));
387 tptr += sizeof(u_int32_t);
388 }
389 break;
390
391 case LS_TYPE_LINK:
392 /* Link LSA */
393 llsap = &lsap->lsa_un.un_llsa;
394 if (lsa_length < sizeof (llsap->llsa_priandopt))
395 return (1);
396 lsa_length -= sizeof (llsap->llsa_priandopt);
397 TCHECK(llsap->llsa_priandopt);
398 printf("\n\t Options [%s]",
399 bittok2str(ospf6_option_values, "none",
400 EXTRACT_32BITS(&llsap->llsa_options)));
401
402 if (lsa_length < sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix))
403 return (1);
404 lsa_length -= sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix);
405 prefixes = EXTRACT_32BITS(&llsap->llsa_nprefix);
406 printf("\n\t Priority %d, Link-local address %s, Prefixes %d:",
407 llsap->llsa_priority,
408 ip6addr_string(&llsap->llsa_lladdr),
409 prefixes);
410
411 tptr = (u_int8_t *)llsap->llsa_prefix;
412 while (prefixes > 0) {
413 bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
414 if (bytelen < 0)
415 goto trunc;
416 prefixes--;
417 lsa_length -= bytelen;
418 tptr += bytelen;
419 }
420 break;
421
422 case LS_TYPE_INTRA_AP | LS_SCOPE_AREA:
423 /* Intra-Area-Prefix LSA */
424 if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid))
425 return (1);
426 lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid);
427 TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid);
428 ospf6_print_ls_type(
429 EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_lstype),
430 &lsap->lsa_un.un_intra_ap.intra_ap_lsid);
431
432 if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix))
433 return (1);
434 lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
435 TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
436 prefixes = EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
437 printf("\n\t Prefixes %d:", prefixes);
438
439 tptr = (u_int8_t *)lsap->lsa_un.un_intra_ap.intra_ap_prefix;
440 while (prefixes > 0) {
441 bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
442 if (bytelen < 0)
443 goto trunc;
444 prefixes--;
445 lsa_length -= bytelen;
446 tptr += bytelen;
447 }
448 break;
449
450 case LS_TYPE_GRACE | LS_SCOPE_LINKLOCAL:
451 if (ospf_print_grace_lsa(tptr, lsa_length) == -1) {
452 return 1;
453 }
454 break;
455
456 case LS_TYPE_INTRA_ATE | LS_SCOPE_LINKLOCAL:
457 if (ospf_print_te_lsa(tptr, lsa_length) == -1) {
458 return 1;
459 }
460 break;
461
462 default:
463 if(!print_unknown_data(tptr,
464 "\n\t ",
465 lsa_length)) {
466 return (1);
467 }
468 break;
469 }
470
471 return (0);
472 trunc:
473 return (1);
474 }
475
476 static int
477 ospf6_decode_v3(register const struct ospf6hdr *op,
478 register const u_char *dataend)
479 {
480 register const rtrid_t *ap;
481 register const struct lsr6 *lsrp;
482 register const struct lsa6_hdr *lshp;
483 register const struct lsa6 *lsap;
484 register int i;
485
486 switch (op->ospf6_type) {
487
488 case OSPF_TYPE_HELLO:
489 printf("\n\tOptions [%s]",
490 bittok2str(ospf6_option_values, "none",
491 EXTRACT_32BITS(&op->ospf6_hello.hello_options)));
492
493 TCHECK(op->ospf6_hello.hello_deadint);
494 printf("\n\t Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u",
495 EXTRACT_16BITS(&op->ospf6_hello.hello_helloint),
496 EXTRACT_16BITS(&op->ospf6_hello.hello_deadint),
497 ipaddr_string(&op->ospf6_hello.hello_ifid),
498 op->ospf6_hello.hello_priority);
499
500 TCHECK(op->ospf6_hello.hello_dr);
501 if (op->ospf6_hello.hello_dr != 0)
502 printf("\n\t Designated Router %s",
503 ipaddr_string(&op->ospf6_hello.hello_dr));
504 TCHECK(op->ospf6_hello.hello_bdr);
505 if (op->ospf6_hello.hello_bdr != 0)
506 printf(", Backup Designated Router %s",
507 ipaddr_string(&op->ospf6_hello.hello_bdr));
508 if (vflag > 1) {
509 printf("\n\t Neighbor List:");
510 ap = op->ospf6_hello.hello_neighbor;
511 while ((u_char *)ap < dataend) {
512 TCHECK(*ap);
513 printf("\n\t %s", ipaddr_string(ap));
514 ++ap;
515 }
516 }
517 break; /* HELLO */
518
519 case OSPF_TYPE_DD:
520 TCHECK(op->ospf6_db.db_options);
521 printf("\n\tOptions [%s]",
522 bittok2str(ospf6_option_values, "none",
523 EXTRACT_32BITS(&op->ospf6_db.db_options)));
524 TCHECK(op->ospf6_db.db_flags);
525 printf(", DD Flags [%s]",
526 bittok2str(ospf6_dd_flag_values,"none",op->ospf6_db.db_flags));
527
528 TCHECK(op->ospf6_db.db_seq);
529 printf(", MTU %u, DD-Sequence 0x%08x",
530 EXTRACT_16BITS(&op->ospf6_db.db_mtu),
531 EXTRACT_32BITS(&op->ospf6_db.db_seq));
532 if (vflag > 1) {
533 /* Print all the LS adv's */
534 lshp = op->ospf6_db.db_lshdr;
535 while ((u_char *)lshp < dataend) {
536 if (ospf6_print_lshdr(lshp++, dataend))
537 goto trunc;
538 }
539 }
540 break;
541
542 case OSPF_TYPE_LS_REQ:
543 if (vflag > 1) {
544 lsrp = op->ospf6_lsr;
545 while ((u_char *)lsrp < dataend) {
546 TCHECK(*lsrp);
547 printf("\n\t Advertising Router %s",
548 ipaddr_string(&lsrp->ls_router));
549 ospf6_print_ls_type(EXTRACT_16BITS(&lsrp->ls_type),
550 &lsrp->ls_stateid);
551 ++lsrp;
552 }
553 }
554 break;
555
556 case OSPF_TYPE_LS_UPDATE:
557 if (vflag > 1) {
558 lsap = op->ospf6_lsu.lsu_lsa;
559 TCHECK(op->ospf6_lsu.lsu_count);
560 i = EXTRACT_32BITS(&op->ospf6_lsu.lsu_count);
561 while ((u_char *)lsap < dataend && i--) {
562 if (ospf6_print_lsa(lsap, dataend))
563 goto trunc;
564 lsap = (struct lsa6 *)((u_char *)lsap +
565 EXTRACT_16BITS(&lsap->ls_hdr.ls_length));
566 }
567 }
568 break;
569
570
571 case OSPF_TYPE_LS_ACK:
572 if (vflag > 1) {
573 lshp = op->ospf6_lsa.lsa_lshdr;
574 while ((u_char *)lshp < dataend) {
575 if (ospf6_print_lshdr(lshp++, dataend))
576 goto trunc;
577 }
578 }
579 break;
580
581 default:
582 break;
583 }
584 return (0);
585 trunc:
586 return (1);
587 }
588
589 /* RFC5613 Section 2.2 (w/o the TLVs) */
590 static int
591 ospf6_print_lls(const u_char *cp, const u_int len)
592 {
593 uint16_t llsdatalen;
594
595 if (len == 0)
596 return 0;
597 if (len < OSPF_LLS_HDRLEN)
598 goto trunc;
599 /* Checksum */
600 TCHECK2(*cp, 2);
601 printf("\n\tLLS Checksum 0x%04x", EXTRACT_16BITS(cp));
602 cp += 2;
603 /* LLS Data Length */
604 TCHECK2(*cp, 2);
605 llsdatalen = EXTRACT_16BITS(cp);
606 printf(", Data Length %u", llsdatalen);
607 if (llsdatalen < OSPF_LLS_HDRLEN || llsdatalen > len)
608 goto trunc;
609 cp += 2;
610 /* LLS TLVs */
611 TCHECK2(*cp, llsdatalen - OSPF_LLS_HDRLEN);
612 /* FIXME: code in print-ospf.c can be reused to decode the TLVs */
613
614 return llsdatalen;
615 trunc:
616 return -1;
617 }
618
619 /* RFC6506 Section 4.1 */
620 static int
621 ospf6_decode_at(const u_char *cp, const u_int len)
622 {
623 uint16_t authdatalen;
624
625 if (len == 0)
626 return 0;
627 if (len < OSPF6_AT_HDRLEN)
628 goto trunc;
629 /* Authentication Type */
630 TCHECK2(*cp, 2);
631 printf("\n\tAuthentication Type %s", tok2str(ospf6_auth_type_str, "unknown (0x%04x)", EXTRACT_16BITS(cp)));
632 cp += 2;
633 /* Auth Data Len */
634 TCHECK2(*cp, 2);
635 authdatalen = EXTRACT_16BITS(cp);
636 printf(", Length %u", authdatalen);
637 if (authdatalen < OSPF6_AT_HDRLEN || authdatalen > len)
638 goto trunc;
639 cp += 2;
640 /* Reserved */
641 TCHECK2(*cp, 2);
642 cp += 2;
643 /* Security Association ID */
644 TCHECK2(*cp, 2);
645 printf(", SAID %u", EXTRACT_16BITS(cp));
646 cp += 2;
647 /* Cryptographic Sequence Number (High-Order 32 Bits) */
648 TCHECK2(*cp, 4);
649 printf(", CSN 0x%08x", EXTRACT_32BITS(cp));
650 cp += 4;
651 /* Cryptographic Sequence Number (Low-Order 32 Bits) */
652 TCHECK2(*cp, 4);
653 printf(":%08x", EXTRACT_32BITS(cp));
654 cp += 4;
655 /* Authentication Data */
656 TCHECK2(*cp, authdatalen - OSPF6_AT_HDRLEN);
657 if (vflag > 1)
658 print_unknown_data(cp, "\n\tAuthentication Data ", authdatalen - OSPF6_AT_HDRLEN);
659 return 0;
660
661 trunc:
662 return 1;
663 }
664
665 /* The trailing data may include LLS and/or AT data (in this specific order).
666 * LLS data may be present only in Hello and DBDesc packets with the L-bit set.
667 * AT data may be present in Hello and DBDesc packets with the AT-bit set or in
668 * any other packet type, thus decode the AT data regardless of the AT-bit.
669 */
670 static int
671 ospf6_decode_v3_trailer(const struct ospf6hdr *op, const u_char *cp, const unsigned len)
672 {
673 int llslen = 0;
674 u_char lls_hello = op->ospf6_type == OSPF_TYPE_HELLO &&
675 op->ospf6_hello.hello_options & OSPF6_OPTION_L;
676 u_char lls_dd = op->ospf6_type == OSPF_TYPE_DD &&
677 op->ospf6_db.db_options & OSPF6_OPTION_L;
678
679 if ((lls_hello || lls_dd) && (llslen = ospf6_print_lls(cp, len)) < 0)
680 goto trunc;
681 return ospf6_decode_at(cp + llslen, len - llslen);
682
683 trunc:
684 return 1;
685 }
686
687 void
688 ospf6_print(register const u_char *bp, register u_int length)
689 {
690 register const struct ospf6hdr *op;
691 register const u_char *dataend;
692 register const char *cp;
693 uint16_t datalen;
694
695 op = (struct ospf6hdr *)bp;
696
697 /* If the type is valid translate it, or just print the type */
698 /* value. If it's not valid, say so and return */
699 TCHECK(op->ospf6_type);
700 cp = tok2str(ospf6_type_values, "unknown packet type (%u)", op->ospf6_type);
701 printf("OSPFv%u, %s, length %d", op->ospf6_version, cp, length);
702 if (*cp == 'u') {
703 return;
704 }
705
706 if(!vflag) { /* non verbose - so lets bail out here */
707 return;
708 }
709
710 /* OSPFv3 data always comes first and optional trailing data may follow. */
711 TCHECK(op->ospf6_len);
712 datalen = EXTRACT_16BITS(&op->ospf6_len);
713 if (datalen > length) {
714 printf(" [len %d]", datalen);
715 return;
716 }
717 dataend = bp + datalen;
718
719 TCHECK(op->ospf6_routerid);
720 printf("\n\tRouter-ID %s", ipaddr_string(&op->ospf6_routerid));
721
722 TCHECK(op->ospf6_areaid);
723 if (op->ospf6_areaid != 0)
724 printf(", Area %s", ipaddr_string(&op->ospf6_areaid));
725 else
726 printf(", Backbone Area");
727 TCHECK(op->ospf6_instanceid);
728 if (op->ospf6_instanceid)
729 printf(", Instance %u", op->ospf6_instanceid);
730
731 /* Do rest according to version. */
732 switch (op->ospf6_version) {
733
734 case 3:
735 /* ospf version 3 */
736 if (ospf6_decode_v3(op, dataend) ||
737 ospf6_decode_v3_trailer(op, dataend, length - datalen))
738 goto trunc;
739 break;
740 } /* end switch on version */
741
742 return;
743 trunc:
744 fputs(tstr, stdout);
745 }