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