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