xref: /netbsd-src/external/bsd/tcpdump/dist/print-ospf6.c (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
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 #include <sys/cdefs.h>
25 #ifndef lint
26 #if 0
27 static const char rcsid[] _U_ =
28     "@(#) Header: /tcpdump/master/tcpdump/print-ospf6.c,v 1.15 2006-09-13 06:31:11 guy Exp  (LBL)";
29 #else
30 __RCSID("$NetBSD: print-ospf6.c,v 1.4 2013/12/31 17:33:31 christos Exp $");
31 #endif
32 #endif
33 
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
37 
38 #include <tcpdump-stdinc.h>
39 
40 #include <stdio.h>
41 #include <string.h>
42 
43 #include "interface.h"
44 #include "addrtoname.h"
45 #include "extract.h"
46 
47 #include "ospf.h"
48 #include "ospf6.h"
49 
50 static const struct tok ospf6_option_values[] = {
51 	{ OSPF6_OPTION_V6,	"V6" },
52 	{ OSPF6_OPTION_E,	"External" },
53 	{ OSPF6_OPTION_MC,	"Multicast" },
54 	{ OSPF6_OPTION_N,	"NSSA" },
55 	{ OSPF6_OPTION_R,	"Router" },
56 	{ OSPF6_OPTION_DC,	"Demand Circuit" },
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,	"Fforwarding" },
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,        "Multicast Group" },
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 	{ 0,			NULL }
98 };
99 
100 static const struct tok ospf6_ls_scope_values[] = {
101 	{ LS_SCOPE_LINKLOCAL,   "Link Local" },
102 	{ LS_SCOPE_AREA,        "Area Local" },
103 	{ LS_SCOPE_AS,          "Domain Wide" },
104 	{ 0,			NULL }
105 };
106 
107 static const struct tok ospf6_dd_flag_values[] = {
108 	{ OSPF6_DB_INIT,	"Init" },
109 	{ OSPF6_DB_MORE,	"More" },
110 	{ OSPF6_DB_MASTER,	"Master" },
111 	{ 0,			NULL }
112 };
113 
114 static const struct tok ospf6_lsa_prefix_option_values[] = {
115         { LSA_PREFIX_OPT_NU, "No Unicast" },
116         { LSA_PREFIX_OPT_LA, "Local address" },
117         { LSA_PREFIX_OPT_MC, "Multicast" },
118         { LSA_PREFIX_OPT_P, "Propagate" },
119         { LSA_PREFIX_OPT_DN, "Down" },
120 	{ 0, NULL }
121 };
122 
123 static char tstr[] = " [|ospf3]";
124 
125 /* Forwards */
126 static void ospf6_print_ls_type(u_int, const rtrid_t *);
127 static int ospf6_print_lshdr(const struct lsa6_hdr *);
128 static int ospf6_print_lsa(const struct lsa6 *);
129 static int ospf6_decode_v3(const struct ospf6hdr *, const u_char *);
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)
145 {
146 
147 	TCHECK(lshp->ls_type);
148 	TCHECK(lshp->ls_seq);
149 
150 	printf("\n\t  Advertising Router %s, seq 0x%08x, age %us, length %u",
151                ipaddr_string(&lshp->ls_router),
152                EXTRACT_32BITS(&lshp->ls_seq),
153                EXTRACT_16BITS(&lshp->ls_age),
154                EXTRACT_16BITS(&lshp->ls_length)-(u_int)sizeof(struct lsa6_hdr));
155 
156 	ospf6_print_ls_type(EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid);
157 
158 	return (0);
159 trunc:
160 	return (1);
161 }
162 
163 static int
164 ospf6_print_lsaprefix(const u_int8_t *tptr, u_int lsa_length)
165 {
166 	const struct lsa6_prefix *lsapp = (struct lsa6_prefix *)tptr;
167 	u_int wordlen;
168 	struct in6_addr prefix;
169 
170 	if (lsa_length < sizeof (*lsapp) - 4)
171 		goto trunc;
172 	lsa_length -= sizeof (*lsapp) - 4;
173 	TCHECK2(*lsapp, sizeof (*lsapp) - 4);
174 	wordlen = (lsapp->lsa_p_len + 31) / 32;
175 	if (wordlen * 4 > sizeof(struct in6_addr)) {
176 		printf(" bogus prefixlen /%d", lsapp->lsa_p_len);
177 		goto trunc;
178 	}
179 	if (lsa_length < wordlen * 4)
180 		goto trunc;
181 	lsa_length -= wordlen * 4;
182 	TCHECK2(lsapp->lsa_p_prefix, wordlen * 4);
183 	memset(&prefix, 0, sizeof(prefix));
184 	memcpy(&prefix, lsapp->lsa_p_prefix, wordlen * 4);
185 	printf("\n\t\t%s/%d", ip6addr_string(&prefix),
186 		lsapp->lsa_p_len);
187         if (lsapp->lsa_p_opt) {
188             printf(", Options [%s]",
189                    bittok2str(ospf6_lsa_prefix_option_values,
190                               "none", lsapp->lsa_p_opt));
191         }
192         printf(", metric %u", EXTRACT_16BITS(&lsapp->lsa_p_metric));
193 	return sizeof(*lsapp) - 4 + wordlen * 4;
194 
195 trunc:
196 	return -1;
197 }
198 
199 
200 /*
201  * Print a single link state advertisement.  If truncated return 1, else 0.
202  */
203 static int
204 ospf6_print_lsa(register const struct lsa6 *lsap)
205 {
206 	register const struct rlalink6 *rlp;
207 #if 0
208 	register const struct tos_metric *tosp;
209 #endif
210 	register const rtrid_t *ap;
211 #if 0
212 	register const struct aslametric *almp;
213 	register const struct mcla *mcp;
214 #endif
215 	register const struct llsa *llsap;
216 	register const struct lsa6_prefix *lsapp;
217 #if 0
218 	register const u_int32_t *lp;
219 #endif
220 	register u_int prefixes;
221 	register int bytelen;
222 	register u_int length, lsa_length;
223 	u_int32_t flags32;
224 	const u_int8_t *tptr;
225 
226 	if (ospf6_print_lshdr(&lsap->ls_hdr))
227 		return (1);
228 	TCHECK(lsap->ls_hdr.ls_length);
229         length = EXTRACT_16BITS(&lsap->ls_hdr.ls_length);
230 
231 	/*
232 	 * The LSA length includes the length of the header;
233 	 * it must have a value that's at least that length.
234 	 * If it does, find the length of what follows the
235 	 * header.
236 	 */
237         if (length < sizeof(struct lsa6_hdr))
238         	return (1);
239         lsa_length = length - sizeof(struct lsa6_hdr);
240         tptr = (u_int8_t *)lsap+sizeof(struct lsa6_hdr);
241 
242 	switch (EXTRACT_16BITS(&lsap->ls_hdr.ls_type)) {
243 	case LS_TYPE_ROUTER | LS_SCOPE_AREA:
244 		if (lsa_length < sizeof (lsap->lsa_un.un_rla.rla_options))
245 			return (1);
246 		lsa_length -= sizeof (lsap->lsa_un.un_rla.rla_options);
247 		TCHECK(lsap->lsa_un.un_rla.rla_options);
248                 printf("\n\t      Options [%s]",
249                        bittok2str(ospf6_option_values, "none",
250                                   EXTRACT_32BITS(&lsap->lsa_un.un_rla.rla_options)));
251                 printf(", RLA-Flags [%s]",
252                        bittok2str(ospf6_rla_flag_values, "none",
253                                   lsap->lsa_un.un_rla.rla_flags));
254 
255 		rlp = lsap->lsa_un.un_rla.rla_link;
256 		while (lsa_length != 0) {
257 			if (lsa_length < sizeof (*rlp))
258 				return (1);
259 			lsa_length -= sizeof (*rlp);
260 			TCHECK(*rlp);
261 			switch (rlp->link_type) {
262 
263 			case RLA_TYPE_VIRTUAL:
264 				printf("\n\t      Virtual Link: Neighbor Router-ID %s"
265                                        "\n\t      Neighbor Interface-ID %s, Interface %s",
266                                        ipaddr_string(&rlp->link_nrtid),
267                                        ipaddr_string(&rlp->link_nifid),
268                                        ipaddr_string(&rlp->link_ifid));
269                                 break;
270 
271 			case RLA_TYPE_ROUTER:
272 				printf("\n\t      Neighbor Router-ID %s"
273                                        "\n\t      Neighbor Interface-ID %s, Interface %s",
274                                        ipaddr_string(&rlp->link_nrtid),
275                                        ipaddr_string(&rlp->link_nifid),
276                                        ipaddr_string(&rlp->link_ifid));
277 				break;
278 
279 			case RLA_TYPE_TRANSIT:
280 				printf("\n\t      Neighbor Network-ID %s"
281                                        "\n\t      Neighbor Interface-ID %s, Interface %s",
282 				    ipaddr_string(&rlp->link_nrtid),
283 				    ipaddr_string(&rlp->link_nifid),
284 				    ipaddr_string(&rlp->link_ifid));
285 				break;
286 
287 			default:
288 				printf("\n\t      Unknown Router Links Type 0x%02x",
289 				    rlp->link_type);
290 				return (0);
291 			}
292 			printf(", metric %d", EXTRACT_16BITS(&rlp->link_metric));
293 			rlp++;
294 		}
295 		break;
296 
297 	case LS_TYPE_NETWORK | LS_SCOPE_AREA:
298 		if (lsa_length < sizeof (lsap->lsa_un.un_nla.nla_options))
299 			return (1);
300 		lsa_length -= sizeof (lsap->lsa_un.un_nla.nla_options);
301 		TCHECK(lsap->lsa_un.un_nla.nla_options);
302                 printf("\n\t      Options [%s]",
303                        bittok2str(ospf6_option_values, "none",
304                                   EXTRACT_32BITS(&lsap->lsa_un.un_nla.nla_options)));
305 
306 		printf("\n\t      Connected Routers:");
307 		ap = lsap->lsa_un.un_nla.nla_router;
308 		while (lsa_length != 0) {
309 			if (lsa_length < sizeof (*ap))
310 				return (1);
311 			lsa_length -= sizeof (*ap);
312 			TCHECK(*ap);
313 			printf("\n\t\t%s", ipaddr_string(ap));
314 			++ap;
315 		}
316 		break;
317 
318 	case LS_TYPE_INTER_AP | LS_SCOPE_AREA:
319 		if (lsa_length < sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric))
320 			return (1);
321 		lsa_length -= sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric);
322 		TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric);
323 		printf(", metric %u",
324 			EXTRACT_32BITS(&lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC);
325 
326 		tptr = (u_int8_t *)lsap->lsa_un.un_inter_ap.inter_ap_prefix;
327 		while (lsa_length != 0) {
328 			bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
329 			if (bytelen < 0)
330 				goto trunc;
331 			lsa_length -= bytelen;
332 			tptr += bytelen;
333 		}
334 		break;
335 
336 	case LS_TYPE_ASE | LS_SCOPE_AS:
337 		if (lsa_length < sizeof (lsap->lsa_un.un_asla.asla_metric))
338 			return (1);
339 		lsa_length -= sizeof (lsap->lsa_un.un_asla.asla_metric);
340 		TCHECK(lsap->lsa_un.un_asla.asla_metric);
341 		flags32 = EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric);
342                 printf("\n\t     Flags [%s]",
343                        bittok2str(ospf6_asla_flag_values, "none", flags32));
344 		printf(" metric %u",
345 		       EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric) &
346 		       ASLA_MASK_METRIC);
347 
348 		tptr = (u_int8_t *)lsap->lsa_un.un_asla.asla_prefix;
349 		lsapp = (struct lsa6_prefix *)tptr;
350 		bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
351 		if (bytelen < 0)
352 			goto trunc;
353 		lsa_length -= bytelen;
354 		tptr += bytelen;
355 
356 		if ((flags32 & ASLA_FLAG_FWDADDR) != 0) {
357 			struct in6_addr *fwdaddr6;
358 
359 			fwdaddr6 = (struct in6_addr *)tptr;
360 			if (lsa_length < sizeof (*fwdaddr6))
361 				return (1);
362 			lsa_length -= sizeof (*fwdaddr6);
363 			TCHECK(*fwdaddr6);
364 			printf(" forward %s",
365 			       ip6addr_string(fwdaddr6));
366 			tptr += sizeof(*fwdaddr6);
367 		}
368 
369 		if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) {
370 			if (lsa_length < sizeof (u_int32_t))
371 				return (1);
372 			lsa_length -= sizeof (u_int32_t);
373 			TCHECK(*(u_int32_t *)tptr);
374 			printf(" tag %s",
375 			       ipaddr_string((u_int32_t *)tptr));
376 			tptr += sizeof(u_int32_t);
377 		}
378 
379 		if (lsapp->lsa_p_metric) {
380 			if (lsa_length < sizeof (u_int32_t))
381 				return (1);
382 			lsa_length -= sizeof (u_int32_t);
383 			TCHECK(*(u_int32_t *)tptr);
384 			printf(" RefLSID: %s",
385 			       ipaddr_string((u_int32_t *)tptr));
386 			tptr += sizeof(u_int32_t);
387 		}
388 		break;
389 
390 	case LS_TYPE_LINK:
391 		/* Link LSA */
392 		llsap = &lsap->lsa_un.un_llsa;
393 		if (lsa_length < sizeof (llsap->llsa_priandopt))
394 			return (1);
395 		lsa_length -= sizeof (llsap->llsa_priandopt);
396 		TCHECK(llsap->llsa_priandopt);
397                 printf("\n\t      Options [%s]",
398                        bittok2str(ospf6_option_values, "none",
399                                   EXTRACT_32BITS(&llsap->llsa_options)));
400 
401 		if (lsa_length < sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix))
402 			return (1);
403 		lsa_length -= sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix);
404                 prefixes = EXTRACT_32BITS(&llsap->llsa_nprefix);
405 		printf("\n\t      Priority %d, Link-local address %s, Prefixes %d:",
406                        llsap->llsa_priority,
407                        ip6addr_string(&llsap->llsa_lladdr),
408                        prefixes);
409 
410 		tptr = (u_int8_t *)llsap->llsa_prefix;
411 		while (prefixes > 0) {
412 			bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
413 			if (bytelen < 0)
414 				goto trunc;
415 			prefixes--;
416 			lsa_length -= bytelen;
417 			tptr += bytelen;
418 		}
419 		break;
420 
421 	case LS_TYPE_INTRA_AP | LS_SCOPE_AREA:
422 		/* Intra-Area-Prefix LSA */
423 		if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid))
424 			return (1);
425 		lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid);
426 		TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid);
427 		ospf6_print_ls_type(
428 			EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_lstype),
429 			&lsap->lsa_un.un_intra_ap.intra_ap_lsid);
430 
431 		if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix))
432 			return (1);
433 		lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
434 		TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
435                 prefixes = EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
436 		printf("\n\t      Prefixes %d:", prefixes);
437 
438 		tptr = (u_int8_t *)lsap->lsa_un.un_intra_ap.intra_ap_prefix;
439 		while (prefixes > 0) {
440 			bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
441 			if (bytelen < 0)
442 				goto trunc;
443 			prefixes--;
444 			lsa_length -= bytelen;
445 			tptr += bytelen;
446 		}
447 		break;
448 
449         case LS_TYPE_GRACE | LS_SCOPE_LINKLOCAL:
450                 if (ospf_print_grace_lsa(tptr, lsa_length) == -1) {
451                     return 1;
452                 }
453                 break;
454 
455         case LS_TYPE_INTRA_ATE | LS_SCOPE_LINKLOCAL:
456                 if (ospf_print_te_lsa(tptr, lsa_length) == -1) {
457                     return 1;
458                 }
459                 break;
460 
461 	default:
462                 if(!print_unknown_data(tptr,
463                                        "\n\t      ",
464                                        lsa_length)) {
465                     return (1);
466                 }
467                 break;
468 	}
469 
470 	return (0);
471 trunc:
472 	return (1);
473 }
474 
475 static int
476 ospf6_decode_v3(register const struct ospf6hdr *op,
477     register const u_char *dataend)
478 {
479 	register const rtrid_t *ap;
480 	register const struct lsr6 *lsrp;
481 	register const struct lsa6_hdr *lshp;
482 	register const struct lsa6 *lsap;
483 	register int i;
484 
485 	switch (op->ospf6_type) {
486 
487 	case OSPF_TYPE_HELLO:
488                 printf("\n\tOptions [%s]",
489                        bittok2str(ospf6_option_values, "none",
490                                   EXTRACT_32BITS(&op->ospf6_hello.hello_options)));
491 
492                 TCHECK(op->ospf6_hello.hello_deadint);
493                 printf("\n\t  Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u",
494                        EXTRACT_16BITS(&op->ospf6_hello.hello_helloint),
495                        EXTRACT_16BITS(&op->ospf6_hello.hello_deadint),
496                        ipaddr_string(&op->ospf6_hello.hello_ifid),
497                        op->ospf6_hello.hello_priority);
498 
499 		TCHECK(op->ospf6_hello.hello_dr);
500 		if (op->ospf6_hello.hello_dr != 0)
501 			printf("\n\t  Designated Router %s",
502 			    ipaddr_string(&op->ospf6_hello.hello_dr));
503 		TCHECK(op->ospf6_hello.hello_bdr);
504 		if (op->ospf6_hello.hello_bdr != 0)
505 			printf(", Backup Designated Router %s",
506 			    ipaddr_string(&op->ospf6_hello.hello_bdr));
507 		if (vflag) {
508 			printf("\n\t  Neighbor List:");
509 			ap = op->ospf6_hello.hello_neighbor;
510 			while ((u_char *)ap < dataend) {
511 				TCHECK(*ap);
512 				printf("\n\t    %s", ipaddr_string(ap));
513 				++ap;
514 			}
515 		}
516 		break;	/* HELLO */
517 
518 	case OSPF_TYPE_DD:
519 		TCHECK(op->ospf6_db.db_options);
520                 printf("\n\tOptions [%s]",
521                        bittok2str(ospf6_option_values, "none",
522                                   EXTRACT_32BITS(&op->ospf6_db.db_options)));
523 		TCHECK(op->ospf6_db.db_flags);
524                 printf(", DD Flags [%s]",
525                        bittok2str(ospf6_dd_flag_values,"none",op->ospf6_db.db_flags));
526 
527 		TCHECK(op->ospf6_db.db_seq);
528 		printf(", MTU %u, DD-Sequence 0x%08x",
529                        EXTRACT_16BITS(&op->ospf6_db.db_mtu),
530                        EXTRACT_32BITS(&op->ospf6_db.db_seq));
531 
532                 /* Print all the LS adv's */
533                 lshp = op->ospf6_db.db_lshdr;
534                 while (!ospf6_print_lshdr(lshp)) {
535                     ++lshp;
536                 }
537 		break;
538 
539 	case OSPF_TYPE_LS_REQ:
540 		if (vflag) {
541 			lsrp = op->ospf6_lsr;
542 			while ((u_char *)lsrp < dataend) {
543 				TCHECK(*lsrp);
544                                 printf("\n\t  Advertising Router %s",
545                                        ipaddr_string(&lsrp->ls_router));
546 				ospf6_print_ls_type(EXTRACT_16BITS(&lsrp->ls_type),
547                                                     &lsrp->ls_stateid);
548 				++lsrp;
549 			}
550 		}
551 		break;
552 
553 	case OSPF_TYPE_LS_UPDATE:
554 		if (vflag) {
555 			lsap = op->ospf6_lsu.lsu_lsa;
556 			TCHECK(op->ospf6_lsu.lsu_count);
557 			i = EXTRACT_32BITS(&op->ospf6_lsu.lsu_count);
558 			while (i--) {
559 				if (ospf6_print_lsa(lsap))
560 					goto trunc;
561 				lsap = (struct lsa6 *)((u_char *)lsap +
562 				    EXTRACT_16BITS(&lsap->ls_hdr.ls_length));
563 			}
564 		}
565 		break;
566 
567 
568 	case OSPF_TYPE_LS_ACK:
569 		if (vflag) {
570 			lshp = op->ospf6_lsa.lsa_lshdr;
571 
572 			while (!ospf6_print_lshdr(lshp)) {
573 				++lshp;
574 			}
575 		}
576 		break;
577 
578 	default:
579 		break;
580 	}
581 	return (0);
582 trunc:
583 	return (1);
584 }
585 
586 void
587 ospf6_print(register const u_char *bp, register u_int length)
588 {
589 	register const struct ospf6hdr *op;
590 	register const u_char *dataend;
591 	register const char *cp;
592 
593 	op = (struct ospf6hdr *)bp;
594 
595 	/* If the type is valid translate it, or just print the type */
596 	/* value.  If it's not valid, say so and return */
597 	TCHECK(op->ospf6_type);
598 	cp = tok2str(ospf6_type_values, "unknown LS-type", op->ospf6_type);
599 	printf("OSPFv%u, %s, length %d", op->ospf6_version, cp, length);
600 	if (*cp == 'u') {
601 		return;
602         }
603 
604         if(!vflag) { /* non verbose - so lets bail out here */
605                 return;
606         }
607 
608 	TCHECK(op->ospf6_len);
609 	if (length != EXTRACT_16BITS(&op->ospf6_len)) {
610 		printf(" [len %d]", EXTRACT_16BITS(&op->ospf6_len));
611 		return;
612 	}
613 	dataend = bp + length;
614 
615 	/* Print the routerid if it is not the same as the source */
616 	TCHECK(op->ospf6_routerid);
617 	printf("\n\tRouter-ID %s", ipaddr_string(&op->ospf6_routerid));
618 
619 	TCHECK(op->ospf6_areaid);
620 	if (op->ospf6_areaid != 0)
621 		printf(", Area %s", ipaddr_string(&op->ospf6_areaid));
622 	else
623 		printf(", Backbone Area");
624 	TCHECK(op->ospf6_instanceid);
625 	if (op->ospf6_instanceid)
626 		printf(", Instance %u", op->ospf6_instanceid);
627 
628 	/* Do rest according to version.	 */
629 	switch (op->ospf6_version) {
630 
631 	case 3:
632 		/* ospf version 3 */
633 		if (ospf6_decode_v3(op, dataend))
634 			goto trunc;
635 		break;
636 
637 	default:
638 		printf(" ospf [version %d]", op->ospf6_version);
639 		break;
640 	}			/* end switch on version */
641 
642 	return;
643 trunc:
644 	fputs(tstr, stdout);
645 }
646