Home | History | Annotate | Line # | Download | only in dist
print-ospf6.c revision 1.1.1.5
      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 #ifdef HAVE_CONFIG_H
     25 #include "config.h"
     26 #endif
     27 
     28 #include <netdissect-stdinc.h>
     29 
     30 #include <string.h>
     31 
     32 #include "netdissect.h"
     33 #include "addrtoname.h"
     34 #include "extract.h"
     35 
     36 #include "ospf.h"
     37 
     38 #define	OSPF_TYPE_HELLO         1	/* Hello */
     39 #define	OSPF_TYPE_DD            2	/* Database Description */
     40 #define	OSPF_TYPE_LS_REQ        3	/* Link State Request */
     41 #define	OSPF_TYPE_LS_UPDATE     4	/* Link State Update */
     42 #define	OSPF_TYPE_LS_ACK        5	/* Link State Ack */
     43 
     44 /* Options *_options	*/
     45 #define OSPF6_OPTION_V6	0x01	/* V6 bit: A bit for peeping tom */
     46 #define OSPF6_OPTION_E	0x02	/* E bit: External routes advertised	*/
     47 #define OSPF6_OPTION_MC	0x04	/* MC bit: Multicast capable */
     48 #define OSPF6_OPTION_N	0x08	/* N bit: For type-7 LSA */
     49 #define OSPF6_OPTION_R	0x10	/* R bit: Router bit */
     50 #define OSPF6_OPTION_DC	0x20	/* DC bit: Demand circuits */
     51 /* The field is actually 24-bit (RFC5340 Section A.2). */
     52 #define OSPF6_OPTION_AF	0x0100	/* AF bit: Multiple address families */
     53 #define OSPF6_OPTION_L	0x0200	/* L bit: Link-local signaling (LLS) */
     54 #define OSPF6_OPTION_AT	0x0400	/* AT bit: Authentication trailer */
     55 
     56 
     57 /* db_flags	*/
     58 #define	OSPF6_DB_INIT		0x04	    /*	*/
     59 #define	OSPF6_DB_MORE		0x02
     60 #define	OSPF6_DB_MASTER		0x01
     61 #define	OSPF6_DB_M6		0x10  /* IPv6 MTU */
     62 
     63 /* ls_type	*/
     64 #define	LS_TYPE_ROUTER		1   /* router link */
     65 #define	LS_TYPE_NETWORK		2   /* network link */
     66 #define	LS_TYPE_INTER_AP	3   /* Inter-Area-Prefix */
     67 #define	LS_TYPE_INTER_AR	4   /* Inter-Area-Router */
     68 #define	LS_TYPE_ASE		5   /* ASE */
     69 #define	LS_TYPE_GROUP		6   /* Group membership */
     70 #define	LS_TYPE_NSSA		7   /* NSSA */
     71 #define	LS_TYPE_LINK		8   /* Link LSA */
     72 #define	LS_TYPE_INTRA_AP	9   /* Intra-Area-Prefix */
     73 #define LS_TYPE_INTRA_ATE       10  /* Intra-Area-TE */
     74 #define LS_TYPE_GRACE           11  /* Grace LSA */
     75 #define LS_TYPE_RI		12  /* Router information */
     76 #define LS_TYPE_INTER_ASTE	13  /* Inter-AS-TE */
     77 #define LS_TYPE_L1VPN		14  /* L1VPN */
     78 #define LS_TYPE_MASK		0x1fff
     79 
     80 #define LS_SCOPE_LINKLOCAL	0x0000
     81 #define LS_SCOPE_AREA		0x2000
     82 #define LS_SCOPE_AS		0x4000
     83 #define LS_SCOPE_MASK		0x6000
     84 #define LS_SCOPE_U              0x8000
     85 
     86 /* rla_link.link_type	*/
     87 #define	RLA_TYPE_ROUTER		1   /* point-to-point to another router	*/
     88 #define	RLA_TYPE_TRANSIT	2   /* connection to transit network	*/
     89 #define RLA_TYPE_VIRTUAL	4   /* virtual link			*/
     90 
     91 /* rla_flags	*/
     92 #define	RLA_FLAG_B	0x01
     93 #define	RLA_FLAG_E	0x02
     94 #define	RLA_FLAG_V	0x04
     95 #define	RLA_FLAG_W	0x08
     96 #define RLA_FLAG_N      0x10
     97 
     98 /* lsa_prefix options */
     99 #define LSA_PREFIX_OPT_NU 0x01
    100 #define LSA_PREFIX_OPT_LA 0x02
    101 #define LSA_PREFIX_OPT_MC 0x04
    102 #define LSA_PREFIX_OPT_P  0x08
    103 #define LSA_PREFIX_OPT_DN 0x10
    104 
    105 /* sla_tosmetric breakdown	*/
    106 #define	SLA_MASK_TOS		0x7f000000
    107 #define	SLA_MASK_METRIC		0x00ffffff
    108 #define SLA_SHIFT_TOS		24
    109 
    110 /* asla_metric */
    111 #define ASLA_FLAG_FWDADDR	0x02000000
    112 #define ASLA_FLAG_ROUTETAG	0x01000000
    113 #define	ASLA_MASK_METRIC	0x00ffffff
    114 
    115 /* RFC6506 Section 4.1 */
    116 #define OSPF6_AT_HDRLEN             16U
    117 #define OSPF6_AUTH_TYPE_HMAC        0x0001
    118 
    119 typedef uint32_t rtrid_t;
    120 
    121 /* link state advertisement header */
    122 struct lsa6_hdr {
    123     uint16_t ls_age;
    124     uint16_t ls_type;
    125     rtrid_t ls_stateid;
    126     rtrid_t ls_router;
    127     uint32_t ls_seq;
    128     uint16_t ls_chksum;
    129     uint16_t ls_length;
    130 };
    131 
    132 /* Length of an IPv6 address, in bytes. */
    133 #define IPV6_ADDR_LEN_BYTES (128/8)
    134 
    135 struct lsa6_prefix {
    136     uint8_t lsa_p_len;
    137     uint8_t lsa_p_opt;
    138     uint16_t lsa_p_metric;
    139     uint8_t lsa_p_prefix[IPV6_ADDR_LEN_BYTES]; /* maximum length */
    140 };
    141 
    142 /* link state advertisement */
    143 struct lsa6 {
    144     struct lsa6_hdr ls_hdr;
    145 
    146     /* Link state types */
    147     union {
    148 	/* Router links advertisements */
    149 	struct {
    150 	    union {
    151 		uint8_t flg;
    152 		uint32_t opt;
    153 	    } rla_flgandopt;
    154 #define rla_flags	rla_flgandopt.flg
    155 #define rla_options	rla_flgandopt.opt
    156 	    struct rlalink6 {
    157 		uint8_t link_type;
    158 		uint8_t link_zero[1];
    159 		uint16_t link_metric;
    160 		uint32_t link_ifid;
    161 		uint32_t link_nifid;
    162 		rtrid_t link_nrtid;
    163 	    } rla_link[1];		/* may repeat	*/
    164 	} un_rla;
    165 
    166 	/* Network links advertisements */
    167 	struct {
    168 	    uint32_t nla_options;
    169 	    rtrid_t nla_router[1];	/* may repeat	*/
    170 	} un_nla;
    171 
    172 	/* Inter Area Prefix LSA */
    173 	struct {
    174 	    uint32_t inter_ap_metric;
    175 	    struct lsa6_prefix inter_ap_prefix[1];
    176 	} un_inter_ap;
    177 
    178 	/* AS external links advertisements */
    179 	struct {
    180 	    uint32_t asla_metric;
    181 	    struct lsa6_prefix asla_prefix[1];
    182 	    /* some optional fields follow */
    183 	} un_asla;
    184 
    185 #if 0
    186 	/* Summary links advertisements */
    187 	struct {
    188 	    struct in_addr sla_mask;
    189 	    uint32_t sla_tosmetric[1];	/* may repeat	*/
    190 	} un_sla;
    191 
    192 	/* Multicast group membership */
    193 	struct mcla {
    194 	    uint32_t mcla_vtype;
    195 	    struct in_addr mcla_vid;
    196 	} un_mcla[1];
    197 #endif
    198 
    199 	/* Type 7 LSA */
    200 
    201 	/* Link LSA */
    202 	struct llsa {
    203 	    union {
    204 		uint8_t pri;
    205 		uint32_t opt;
    206 	    } llsa_priandopt;
    207 #define llsa_priority	llsa_priandopt.pri
    208 #define llsa_options	llsa_priandopt.opt
    209 	    struct in6_addr llsa_lladdr;
    210 	    uint32_t llsa_nprefix;
    211 	    struct lsa6_prefix llsa_prefix[1];
    212 	} un_llsa;
    213 
    214 	/* Intra-Area-Prefix */
    215 	struct {
    216 	    uint16_t intra_ap_nprefix;
    217 	    uint16_t intra_ap_lstype;
    218 	    rtrid_t intra_ap_lsid;
    219 	    rtrid_t intra_ap_rtid;
    220 	    struct lsa6_prefix intra_ap_prefix[1];
    221 	} un_intra_ap;
    222     } lsa_un;
    223 };
    224 
    225 /*
    226  * the main header
    227  */
    228 struct ospf6hdr {
    229     uint8_t ospf6_version;
    230     uint8_t ospf6_type;
    231     uint16_t ospf6_len;
    232     rtrid_t ospf6_routerid;
    233     rtrid_t ospf6_areaid;
    234     uint16_t ospf6_chksum;
    235     uint8_t ospf6_instanceid;
    236     uint8_t ospf6_rsvd;
    237 };
    238 
    239 /*
    240  * The OSPF6 header length is 16 bytes, regardless of how your compiler
    241  * might choose to pad the above structure.
    242  */
    243 #define OSPF6HDR_LEN    16
    244 
    245 /* Hello packet */
    246 struct hello6 {
    247     uint32_t hello_ifid;
    248     union {
    249 	uint8_t pri;
    250 	uint32_t opt;
    251     } hello_priandopt;
    252 #define hello_priority	hello_priandopt.pri
    253 #define hello_options	hello_priandopt.opt
    254     uint16_t hello_helloint;
    255     uint16_t hello_deadint;
    256     rtrid_t hello_dr;
    257     rtrid_t hello_bdr;
    258     rtrid_t hello_neighbor[1]; /* may repeat	*/
    259 };
    260 
    261 /* Database Description packet */
    262 struct dd6 {
    263     uint32_t db_options;
    264     uint16_t db_mtu;
    265     uint8_t db_mbz;
    266     uint8_t db_flags;
    267     uint32_t db_seq;
    268     struct lsa6_hdr db_lshdr[1]; /* may repeat	*/
    269 };
    270 
    271 /* Link State Request */
    272 struct lsr6 {
    273     uint16_t ls_mbz;
    274     uint16_t ls_type;
    275     rtrid_t ls_stateid;
    276     rtrid_t ls_router;
    277 };
    278 
    279 /* Link State Update */
    280 struct lsu6 {
    281     uint32_t lsu_count;
    282     struct lsa6 lsu_lsa[1]; /* may repeat	*/
    283 };
    284 
    285 static const char tstr[] = " [|ospf3]";
    286 
    287 static const struct tok ospf6_option_values[] = {
    288 	{ OSPF6_OPTION_V6,	"V6" },
    289 	{ OSPF6_OPTION_E,	"External" },
    290 	{ OSPF6_OPTION_MC,	"Deprecated" },
    291 	{ OSPF6_OPTION_N,	"NSSA" },
    292 	{ OSPF6_OPTION_R,	"Router" },
    293 	{ OSPF6_OPTION_DC,	"Demand Circuit" },
    294 	{ OSPF6_OPTION_AF,	"AFs Support" },
    295 	{ OSPF6_OPTION_L,	"LLS" },
    296 	{ OSPF6_OPTION_AT,	"Authentication Trailer" },
    297 	{ 0,			NULL }
    298 };
    299 
    300 static const struct tok ospf6_rla_flag_values[] = {
    301 	{ RLA_FLAG_B,		"ABR" },
    302 	{ RLA_FLAG_E,		"External" },
    303 	{ RLA_FLAG_V,		"Virtual-Link Endpoint" },
    304 	{ RLA_FLAG_W,		"Wildcard Receiver" },
    305         { RLA_FLAG_N,           "NSSA Translator" },
    306 	{ 0,			NULL }
    307 };
    308 
    309 static const struct tok ospf6_asla_flag_values[] = {
    310 	{ ASLA_FLAG_EXTERNAL,	"External Type 2" },
    311 	{ ASLA_FLAG_FWDADDR,	"Forwarding" },
    312 	{ ASLA_FLAG_ROUTETAG,	"Tag" },
    313 	{ 0,			NULL }
    314 };
    315 
    316 static const struct tok ospf6_type_values[] = {
    317 	{ OSPF_TYPE_HELLO,	"Hello" },
    318 	{ OSPF_TYPE_DD,		"Database Description" },
    319 	{ OSPF_TYPE_LS_REQ,	"LS-Request" },
    320 	{ OSPF_TYPE_LS_UPDATE,	"LS-Update" },
    321 	{ OSPF_TYPE_LS_ACK,	"LS-Ack" },
    322 	{ 0,			NULL }
    323 };
    324 
    325 static const struct tok ospf6_lsa_values[] = {
    326 	{ LS_TYPE_ROUTER,       "Router" },
    327 	{ LS_TYPE_NETWORK,      "Network" },
    328 	{ LS_TYPE_INTER_AP,     "Inter-Area Prefix" },
    329 	{ LS_TYPE_INTER_AR,     "Inter-Area Router" },
    330 	{ LS_TYPE_ASE,          "External" },
    331 	{ LS_TYPE_GROUP,        "Deprecated" },
    332 	{ LS_TYPE_NSSA,         "NSSA" },
    333 	{ LS_TYPE_LINK,         "Link" },
    334 	{ LS_TYPE_INTRA_AP,     "Intra-Area Prefix" },
    335         { LS_TYPE_INTRA_ATE,    "Intra-Area TE" },
    336         { LS_TYPE_GRACE,        "Grace" },
    337 	{ LS_TYPE_RI,           "Router Information" },
    338 	{ LS_TYPE_INTER_ASTE,   "Inter-AS-TE" },
    339 	{ LS_TYPE_L1VPN,        "Layer 1 VPN" },
    340 	{ 0,			NULL }
    341 };
    342 
    343 static const struct tok ospf6_ls_scope_values[] = {
    344 	{ LS_SCOPE_LINKLOCAL,   "Link Local" },
    345 	{ LS_SCOPE_AREA,        "Area Local" },
    346 	{ LS_SCOPE_AS,          "Domain Wide" },
    347 	{ 0,			NULL }
    348 };
    349 
    350 static const struct tok ospf6_dd_flag_values[] = {
    351 	{ OSPF6_DB_INIT,	"Init" },
    352 	{ OSPF6_DB_MORE,	"More" },
    353 	{ OSPF6_DB_MASTER,	"Master" },
    354 	{ OSPF6_DB_M6,		"IPv6 MTU" },
    355 	{ 0,			NULL }
    356 };
    357 
    358 static const struct tok ospf6_lsa_prefix_option_values[] = {
    359         { LSA_PREFIX_OPT_NU, "No Unicast" },
    360         { LSA_PREFIX_OPT_LA, "Local address" },
    361         { LSA_PREFIX_OPT_MC, "Deprecated" },
    362         { LSA_PREFIX_OPT_P, "Propagate" },
    363         { LSA_PREFIX_OPT_DN, "Down" },
    364 	{ 0, NULL }
    365 };
    366 
    367 static const struct tok ospf6_auth_type_str[] = {
    368 	{ OSPF6_AUTH_TYPE_HMAC,        "HMAC" },
    369 	{ 0, NULL }
    370 };
    371 
    372 static void
    373 ospf6_print_ls_type(netdissect_options *ndo,
    374                     register u_int ls_type, register const rtrid_t *ls_stateid)
    375 {
    376         ND_PRINT((ndo, "\n\t    %s LSA (%d), %s Scope%s, LSA-ID %s",
    377                tok2str(ospf6_lsa_values, "Unknown", ls_type & LS_TYPE_MASK),
    378                ls_type & LS_TYPE_MASK,
    379                tok2str(ospf6_ls_scope_values, "Unknown", ls_type & LS_SCOPE_MASK),
    380                ls_type &0x8000 ? ", transitive" : "", /* U-bit */
    381                ipaddr_string(ndo, ls_stateid)));
    382 }
    383 
    384 static int
    385 ospf6_print_lshdr(netdissect_options *ndo,
    386                   register const struct lsa6_hdr *lshp, const u_char *dataend)
    387 {
    388 	if ((const u_char *)(lshp + 1) > dataend)
    389 		goto trunc;
    390 	ND_TCHECK(lshp->ls_type);
    391 	ND_TCHECK(lshp->ls_seq);
    392 
    393 	ND_PRINT((ndo, "\n\t  Advertising Router %s, seq 0x%08x, age %us, length %u",
    394                ipaddr_string(ndo, &lshp->ls_router),
    395                EXTRACT_32BITS(&lshp->ls_seq),
    396                EXTRACT_16BITS(&lshp->ls_age),
    397                EXTRACT_16BITS(&lshp->ls_length)-(u_int)sizeof(struct lsa6_hdr)));
    398 
    399 	ospf6_print_ls_type(ndo, EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid);
    400 
    401 	return (0);
    402 trunc:
    403 	return (1);
    404 }
    405 
    406 static int
    407 ospf6_print_lsaprefix(netdissect_options *ndo,
    408                       const uint8_t *tptr, u_int lsa_length)
    409 {
    410 	const struct lsa6_prefix *lsapp = (const struct lsa6_prefix *)tptr;
    411 	u_int wordlen;
    412 	struct in6_addr prefix;
    413 
    414 	if (lsa_length < sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES)
    415 		goto trunc;
    416 	lsa_length -= sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES;
    417 	ND_TCHECK2(*lsapp, sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES);
    418 	wordlen = (lsapp->lsa_p_len + 31) / 32;
    419 	if (wordlen * 4 > sizeof(struct in6_addr)) {
    420 		ND_PRINT((ndo, " bogus prefixlen /%d", lsapp->lsa_p_len));
    421 		goto trunc;
    422 	}
    423 	if (lsa_length < wordlen * 4)
    424 		goto trunc;
    425 	lsa_length -= wordlen * 4;
    426 	ND_TCHECK2(lsapp->lsa_p_prefix, wordlen * 4);
    427 	memset(&prefix, 0, sizeof(prefix));
    428 	memcpy(&prefix, lsapp->lsa_p_prefix, wordlen * 4);
    429 	ND_PRINT((ndo, "\n\t\t%s/%d", ip6addr_string(ndo, &prefix),
    430 		lsapp->lsa_p_len));
    431         if (lsapp->lsa_p_opt) {
    432             ND_PRINT((ndo, ", Options [%s]",
    433                    bittok2str(ospf6_lsa_prefix_option_values,
    434                               "none", lsapp->lsa_p_opt)));
    435         }
    436         ND_PRINT((ndo, ", metric %u", EXTRACT_16BITS(&lsapp->lsa_p_metric)));
    437 	return sizeof(*lsapp) - IPV6_ADDR_LEN_BYTES + wordlen * 4;
    438 
    439 trunc:
    440 	return -1;
    441 }
    442 
    443 
    444 /*
    445  * Print a single link state advertisement.  If truncated return 1, else 0.
    446  */
    447 static int
    448 ospf6_print_lsa(netdissect_options *ndo,
    449                 register const struct lsa6 *lsap, const u_char *dataend)
    450 {
    451 	register const struct rlalink6 *rlp;
    452 #if 0
    453 	register const struct tos_metric *tosp;
    454 #endif
    455 	register const rtrid_t *ap;
    456 #if 0
    457 	register const struct aslametric *almp;
    458 	register const struct mcla *mcp;
    459 #endif
    460 	register const struct llsa *llsap;
    461 	register const struct lsa6_prefix *lsapp;
    462 #if 0
    463 	register const uint32_t *lp;
    464 #endif
    465 	register u_int prefixes;
    466 	register int bytelen;
    467 	register u_int length, lsa_length;
    468 	uint32_t flags32;
    469 	const uint8_t *tptr;
    470 
    471 	if (ospf6_print_lshdr(ndo, &lsap->ls_hdr, dataend))
    472 		return (1);
    473 	ND_TCHECK(lsap->ls_hdr.ls_length);
    474         length = EXTRACT_16BITS(&lsap->ls_hdr.ls_length);
    475 
    476 	/*
    477 	 * The LSA length includes the length of the header;
    478 	 * it must have a value that's at least that length.
    479 	 * If it does, find the length of what follows the
    480 	 * header.
    481 	 */
    482         if (length < sizeof(struct lsa6_hdr) || (const u_char *)lsap + length > dataend)
    483         	return (1);
    484         lsa_length = length - sizeof(struct lsa6_hdr);
    485         tptr = (const uint8_t *)lsap+sizeof(struct lsa6_hdr);
    486 
    487 	switch (EXTRACT_16BITS(&lsap->ls_hdr.ls_type)) {
    488 	case LS_TYPE_ROUTER | LS_SCOPE_AREA:
    489 		if (lsa_length < sizeof (lsap->lsa_un.un_rla.rla_options))
    490 			return (1);
    491 		lsa_length -= sizeof (lsap->lsa_un.un_rla.rla_options);
    492 		ND_TCHECK(lsap->lsa_un.un_rla.rla_options);
    493 		ND_PRINT((ndo, "\n\t      Options [%s]",
    494 		          bittok2str(ospf6_option_values, "none",
    495 		          EXTRACT_32BITS(&lsap->lsa_un.un_rla.rla_options))));
    496 		ND_PRINT((ndo, ", RLA-Flags [%s]",
    497 		          bittok2str(ospf6_rla_flag_values, "none",
    498 		          lsap->lsa_un.un_rla.rla_flags)));
    499 
    500 		rlp = lsap->lsa_un.un_rla.rla_link;
    501 		while (lsa_length != 0) {
    502 			if (lsa_length < sizeof (*rlp))
    503 				return (1);
    504 			lsa_length -= sizeof (*rlp);
    505 			ND_TCHECK(*rlp);
    506 			switch (rlp->link_type) {
    507 
    508 			case RLA_TYPE_VIRTUAL:
    509 				ND_PRINT((ndo, "\n\t      Virtual Link: Neighbor Router-ID %s"
    510                                        "\n\t      Neighbor Interface-ID %s, Interface %s",
    511                                        ipaddr_string(ndo, &rlp->link_nrtid),
    512                                        ipaddr_string(ndo, &rlp->link_nifid),
    513                                        ipaddr_string(ndo, &rlp->link_ifid)));
    514                                 break;
    515 
    516 			case RLA_TYPE_ROUTER:
    517 				ND_PRINT((ndo, "\n\t      Neighbor Router-ID %s"
    518                                        "\n\t      Neighbor Interface-ID %s, Interface %s",
    519                                        ipaddr_string(ndo, &rlp->link_nrtid),
    520                                        ipaddr_string(ndo, &rlp->link_nifid),
    521                                        ipaddr_string(ndo, &rlp->link_ifid)));
    522 				break;
    523 
    524 			case RLA_TYPE_TRANSIT:
    525 				ND_PRINT((ndo, "\n\t      Neighbor Network-ID %s"
    526                                        "\n\t      Neighbor Interface-ID %s, Interface %s",
    527 				    ipaddr_string(ndo, &rlp->link_nrtid),
    528 				    ipaddr_string(ndo, &rlp->link_nifid),
    529 				    ipaddr_string(ndo, &rlp->link_ifid)));
    530 				break;
    531 
    532 			default:
    533 				ND_PRINT((ndo, "\n\t      Unknown Router Links Type 0x%02x",
    534 				    rlp->link_type));
    535 				return (0);
    536 			}
    537 			ND_PRINT((ndo, ", metric %d", EXTRACT_16BITS(&rlp->link_metric)));
    538 			rlp++;
    539 		}
    540 		break;
    541 
    542 	case LS_TYPE_NETWORK | LS_SCOPE_AREA:
    543 		if (lsa_length < sizeof (lsap->lsa_un.un_nla.nla_options))
    544 			return (1);
    545 		lsa_length -= sizeof (lsap->lsa_un.un_nla.nla_options);
    546 		ND_TCHECK(lsap->lsa_un.un_nla.nla_options);
    547 		ND_PRINT((ndo, "\n\t      Options [%s]",
    548 		          bittok2str(ospf6_option_values, "none",
    549 		          EXTRACT_32BITS(&lsap->lsa_un.un_nla.nla_options))));
    550 
    551 		ND_PRINT((ndo, "\n\t      Connected Routers:"));
    552 		ap = lsap->lsa_un.un_nla.nla_router;
    553 		while (lsa_length != 0) {
    554 			if (lsa_length < sizeof (*ap))
    555 				return (1);
    556 			lsa_length -= sizeof (*ap);
    557 			ND_TCHECK(*ap);
    558 			ND_PRINT((ndo, "\n\t\t%s", ipaddr_string(ndo, ap)));
    559 			++ap;
    560 		}
    561 		break;
    562 
    563 	case LS_TYPE_INTER_AP | LS_SCOPE_AREA:
    564 		if (lsa_length < sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric))
    565 			return (1);
    566 		lsa_length -= sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric);
    567 		ND_TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric);
    568 		ND_PRINT((ndo, ", metric %u",
    569 			EXTRACT_32BITS(&lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC));
    570 
    571 		tptr = (const uint8_t *)lsap->lsa_un.un_inter_ap.inter_ap_prefix;
    572 		while (lsa_length != 0) {
    573 			bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
    574 			if (bytelen < 0)
    575 				goto trunc;
    576 			lsa_length -= bytelen;
    577 			tptr += bytelen;
    578 		}
    579 		break;
    580 
    581 	case LS_TYPE_ASE | LS_SCOPE_AS:
    582 		if (lsa_length < sizeof (lsap->lsa_un.un_asla.asla_metric))
    583 			return (1);
    584 		lsa_length -= sizeof (lsap->lsa_un.un_asla.asla_metric);
    585 		ND_TCHECK(lsap->lsa_un.un_asla.asla_metric);
    586 		flags32 = EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric);
    587 		ND_PRINT((ndo, "\n\t     Flags [%s]",
    588 		          bittok2str(ospf6_asla_flag_values, "none", flags32)));
    589 		ND_PRINT((ndo, " metric %u",
    590 		       EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric) &
    591 		       ASLA_MASK_METRIC));
    592 
    593 		tptr = (const uint8_t *)lsap->lsa_un.un_asla.asla_prefix;
    594 		lsapp = (const struct lsa6_prefix *)tptr;
    595 		bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
    596 		if (bytelen < 0)
    597 			goto trunc;
    598 		lsa_length -= bytelen;
    599 		tptr += bytelen;
    600 
    601 		if ((flags32 & ASLA_FLAG_FWDADDR) != 0) {
    602 			const struct in6_addr *fwdaddr6;
    603 
    604 			fwdaddr6 = (const struct in6_addr *)tptr;
    605 			if (lsa_length < sizeof (*fwdaddr6))
    606 				return (1);
    607 			lsa_length -= sizeof (*fwdaddr6);
    608 			ND_TCHECK(*fwdaddr6);
    609 			ND_PRINT((ndo, " forward %s",
    610 			       ip6addr_string(ndo, fwdaddr6)));
    611 			tptr += sizeof(*fwdaddr6);
    612 		}
    613 
    614 		if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) {
    615 			if (lsa_length < sizeof (uint32_t))
    616 				return (1);
    617 			lsa_length -= sizeof (uint32_t);
    618 			ND_TCHECK(*(const uint32_t *)tptr);
    619 			ND_PRINT((ndo, " tag %s",
    620 			       ipaddr_string(ndo, (const uint32_t *)tptr)));
    621 			tptr += sizeof(uint32_t);
    622 		}
    623 
    624 		if (lsapp->lsa_p_metric) {
    625 			if (lsa_length < sizeof (uint32_t))
    626 				return (1);
    627 			lsa_length -= sizeof (uint32_t);
    628 			ND_TCHECK(*(const uint32_t *)tptr);
    629 			ND_PRINT((ndo, " RefLSID: %s",
    630 			       ipaddr_string(ndo, (const uint32_t *)tptr)));
    631 			tptr += sizeof(uint32_t);
    632 		}
    633 		break;
    634 
    635 	case LS_TYPE_LINK:
    636 		/* Link LSA */
    637 		llsap = &lsap->lsa_un.un_llsa;
    638 		if (lsa_length < sizeof (llsap->llsa_priandopt))
    639 			return (1);
    640 		lsa_length -= sizeof (llsap->llsa_priandopt);
    641 		ND_TCHECK(llsap->llsa_priandopt);
    642 		ND_PRINT((ndo, "\n\t      Options [%s]",
    643 		          bittok2str(ospf6_option_values, "none",
    644 		          EXTRACT_32BITS(&llsap->llsa_options))));
    645 
    646 		if (lsa_length < sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix))
    647 			return (1);
    648 		lsa_length -= sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix);
    649                 prefixes = EXTRACT_32BITS(&llsap->llsa_nprefix);
    650 		ND_PRINT((ndo, "\n\t      Priority %d, Link-local address %s, Prefixes %d:",
    651                        llsap->llsa_priority,
    652                        ip6addr_string(ndo, &llsap->llsa_lladdr),
    653                        prefixes));
    654 
    655 		tptr = (const uint8_t *)llsap->llsa_prefix;
    656 		while (prefixes > 0) {
    657 			bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
    658 			if (bytelen < 0)
    659 				goto trunc;
    660 			prefixes--;
    661 			lsa_length -= bytelen;
    662 			tptr += bytelen;
    663 		}
    664 		break;
    665 
    666 	case LS_TYPE_INTRA_AP | LS_SCOPE_AREA:
    667 		/* Intra-Area-Prefix LSA */
    668 		if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid))
    669 			return (1);
    670 		lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid);
    671 		ND_TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid);
    672 		ospf6_print_ls_type(ndo,
    673 			EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_lstype),
    674 			&lsap->lsa_un.un_intra_ap.intra_ap_lsid);
    675 
    676 		if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix))
    677 			return (1);
    678 		lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
    679 		ND_TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
    680                 prefixes = EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
    681 		ND_PRINT((ndo, "\n\t      Prefixes %d:", prefixes));
    682 
    683 		tptr = (const uint8_t *)lsap->lsa_un.un_intra_ap.intra_ap_prefix;
    684 		while (prefixes > 0) {
    685 			bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
    686 			if (bytelen < 0)
    687 				goto trunc;
    688 			prefixes--;
    689 			lsa_length -= bytelen;
    690 			tptr += bytelen;
    691 		}
    692 		break;
    693 
    694         case LS_TYPE_GRACE | LS_SCOPE_LINKLOCAL:
    695                 if (ospf_print_grace_lsa(ndo, tptr, lsa_length) == -1) {
    696                     return 1;
    697                 }
    698                 break;
    699 
    700         case LS_TYPE_INTRA_ATE | LS_SCOPE_LINKLOCAL:
    701                 if (ospf_print_te_lsa(ndo, tptr, lsa_length) == -1) {
    702                     return 1;
    703                 }
    704                 break;
    705 
    706 	default:
    707                 if(!print_unknown_data(ndo,tptr,
    708                                        "\n\t      ",
    709                                        lsa_length)) {
    710                     return (1);
    711                 }
    712                 break;
    713 	}
    714 
    715 	return (0);
    716 trunc:
    717 	return (1);
    718 }
    719 
    720 static int
    721 ospf6_decode_v3(netdissect_options *ndo,
    722                 register const struct ospf6hdr *op,
    723                 register const u_char *dataend)
    724 {
    725 	register const rtrid_t *ap;
    726 	register const struct lsr6 *lsrp;
    727 	register const struct lsa6_hdr *lshp;
    728 	register const struct lsa6 *lsap;
    729 	register int i;
    730 
    731 	switch (op->ospf6_type) {
    732 
    733 	case OSPF_TYPE_HELLO: {
    734 		register const struct hello6 *hellop = (const struct hello6 *)((const uint8_t *)op + OSPF6HDR_LEN);
    735 
    736 		ND_PRINT((ndo, "\n\tOptions [%s]",
    737 		          bittok2str(ospf6_option_values, "none",
    738 		          EXTRACT_32BITS(&hellop->hello_options))));
    739 
    740 		ND_TCHECK(hellop->hello_deadint);
    741 		ND_PRINT((ndo, "\n\t  Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u",
    742 		          EXTRACT_16BITS(&hellop->hello_helloint),
    743 		          EXTRACT_16BITS(&hellop->hello_deadint),
    744 		          ipaddr_string(ndo, &hellop->hello_ifid),
    745 		          hellop->hello_priority));
    746 
    747 		ND_TCHECK(hellop->hello_dr);
    748 		if (EXTRACT_32BITS(&hellop->hello_dr) != 0)
    749 			ND_PRINT((ndo, "\n\t  Designated Router %s",
    750 			    ipaddr_string(ndo, &hellop->hello_dr)));
    751 		ND_TCHECK(hellop->hello_bdr);
    752 		if (EXTRACT_32BITS(&hellop->hello_bdr) != 0)
    753 			ND_PRINT((ndo, ", Backup Designated Router %s",
    754 			    ipaddr_string(ndo, &hellop->hello_bdr)));
    755 		if (ndo->ndo_vflag > 1) {
    756 			ND_PRINT((ndo, "\n\t  Neighbor List:"));
    757 			ap = hellop->hello_neighbor;
    758 			while ((const u_char *)ap < dataend) {
    759 				ND_TCHECK(*ap);
    760 				ND_PRINT((ndo, "\n\t    %s", ipaddr_string(ndo, ap)));
    761 				++ap;
    762 			}
    763 		}
    764 		break;	/* HELLO */
    765 	}
    766 
    767 	case OSPF_TYPE_DD: {
    768 		register const struct dd6 *ddp = (const struct dd6 *)((const uint8_t *)op + OSPF6HDR_LEN);
    769 
    770 		ND_TCHECK(ddp->db_options);
    771 		ND_PRINT((ndo, "\n\tOptions [%s]",
    772 		          bittok2str(ospf6_option_values, "none",
    773 		          EXTRACT_32BITS(&ddp->db_options))));
    774 		ND_TCHECK(ddp->db_flags);
    775 		ND_PRINT((ndo, ", DD Flags [%s]",
    776 		          bittok2str(ospf6_dd_flag_values,"none",ddp->db_flags)));
    777 
    778 		ND_TCHECK(ddp->db_seq);
    779 		ND_PRINT((ndo, ", MTU %u, DD-Sequence 0x%08x",
    780                        EXTRACT_16BITS(&ddp->db_mtu),
    781                        EXTRACT_32BITS(&ddp->db_seq)));
    782 		if (ndo->ndo_vflag > 1) {
    783 			/* Print all the LS adv's */
    784 			lshp = ddp->db_lshdr;
    785 			while ((const u_char *)lshp < dataend) {
    786 				if (ospf6_print_lshdr(ndo, lshp++, dataend))
    787 					goto trunc;
    788 			}
    789 		}
    790 		break;
    791 	}
    792 
    793 	case OSPF_TYPE_LS_REQ:
    794 		if (ndo->ndo_vflag > 1) {
    795 			lsrp = (const struct lsr6 *)((const uint8_t *)op + OSPF6HDR_LEN);
    796 			while ((const u_char *)lsrp < dataend) {
    797 				ND_TCHECK(*lsrp);
    798 				ND_PRINT((ndo, "\n\t  Advertising Router %s",
    799 				          ipaddr_string(ndo, &lsrp->ls_router)));
    800 				ospf6_print_ls_type(ndo, EXTRACT_16BITS(&lsrp->ls_type),
    801                                                     &lsrp->ls_stateid);
    802 				++lsrp;
    803 			}
    804 		}
    805 		break;
    806 
    807 	case OSPF_TYPE_LS_UPDATE:
    808 		if (ndo->ndo_vflag > 1) {
    809 			register const struct lsu6 *lsup = (const struct lsu6 *)((const uint8_t *)op + OSPF6HDR_LEN);
    810 
    811 			ND_TCHECK(lsup->lsu_count);
    812 			i = EXTRACT_32BITS(&lsup->lsu_count);
    813 			lsap = lsup->lsu_lsa;
    814 			while ((const u_char *)lsap < dataend && i--) {
    815 				if (ospf6_print_lsa(ndo, lsap, dataend))
    816 					goto trunc;
    817 				lsap = (const struct lsa6 *)((const u_char *)lsap +
    818 				    EXTRACT_16BITS(&lsap->ls_hdr.ls_length));
    819 			}
    820 		}
    821 		break;
    822 
    823 	case OSPF_TYPE_LS_ACK:
    824 		if (ndo->ndo_vflag > 1) {
    825 			lshp = (const struct lsa6_hdr *)((const uint8_t *)op + OSPF6HDR_LEN);
    826 			while ((const u_char *)lshp < dataend) {
    827 				if (ospf6_print_lshdr(ndo, lshp++, dataend))
    828 					goto trunc;
    829 			}
    830 		}
    831 		break;
    832 
    833 	default:
    834 		break;
    835 	}
    836 	return (0);
    837 trunc:
    838 	return (1);
    839 }
    840 
    841 /* RFC5613 Section 2.2 (w/o the TLVs) */
    842 static int
    843 ospf6_print_lls(netdissect_options *ndo,
    844                 const u_char *cp, const u_int len)
    845 {
    846 	uint16_t llsdatalen;
    847 
    848 	if (len == 0)
    849 		return 0;
    850 	if (len < OSPF_LLS_HDRLEN)
    851 		goto trunc;
    852 	/* Checksum */
    853 	ND_TCHECK2(*cp, 2);
    854 	ND_PRINT((ndo, "\n\tLLS Checksum 0x%04x", EXTRACT_16BITS(cp)));
    855 	cp += 2;
    856 	/* LLS Data Length */
    857 	ND_TCHECK2(*cp, 2);
    858 	llsdatalen = EXTRACT_16BITS(cp);
    859 	ND_PRINT((ndo, ", Data Length %u", llsdatalen));
    860 	if (llsdatalen < OSPF_LLS_HDRLEN || llsdatalen > len)
    861 		goto trunc;
    862 	cp += 2;
    863 	/* LLS TLVs */
    864 	ND_TCHECK2(*cp, llsdatalen - OSPF_LLS_HDRLEN);
    865 	/* FIXME: code in print-ospf.c can be reused to decode the TLVs */
    866 
    867 	return llsdatalen;
    868 trunc:
    869 	return -1;
    870 }
    871 
    872 /* RFC6506 Section 4.1 */
    873 static int
    874 ospf6_decode_at(netdissect_options *ndo,
    875                 const u_char *cp, const u_int len)
    876 {
    877 	uint16_t authdatalen;
    878 
    879 	if (len == 0)
    880 		return 0;
    881 	if (len < OSPF6_AT_HDRLEN)
    882 		goto trunc;
    883 	/* Authentication Type */
    884 	ND_TCHECK2(*cp, 2);
    885 	ND_PRINT((ndo, "\n\tAuthentication Type %s", tok2str(ospf6_auth_type_str, "unknown (0x%04x)", EXTRACT_16BITS(cp))));
    886 	cp += 2;
    887 	/* Auth Data Len */
    888 	ND_TCHECK2(*cp, 2);
    889 	authdatalen = EXTRACT_16BITS(cp);
    890 	ND_PRINT((ndo, ", Length %u", authdatalen));
    891 	if (authdatalen < OSPF6_AT_HDRLEN || authdatalen > len)
    892 		goto trunc;
    893 	cp += 2;
    894 	/* Reserved */
    895 	ND_TCHECK2(*cp, 2);
    896 	cp += 2;
    897 	/* Security Association ID */
    898 	ND_TCHECK2(*cp, 2);
    899 	ND_PRINT((ndo, ", SAID %u", EXTRACT_16BITS(cp)));
    900 	cp += 2;
    901 	/* Cryptographic Sequence Number (High-Order 32 Bits) */
    902 	ND_TCHECK2(*cp, 4);
    903 	ND_PRINT((ndo, ", CSN 0x%08x", EXTRACT_32BITS(cp)));
    904 	cp += 4;
    905 	/* Cryptographic Sequence Number (Low-Order 32 Bits) */
    906 	ND_TCHECK2(*cp, 4);
    907 	ND_PRINT((ndo, ":%08x", EXTRACT_32BITS(cp)));
    908 	cp += 4;
    909 	/* Authentication Data */
    910 	ND_TCHECK2(*cp, authdatalen - OSPF6_AT_HDRLEN);
    911 	if (ndo->ndo_vflag > 1)
    912 		print_unknown_data(ndo,cp, "\n\tAuthentication Data ", authdatalen - OSPF6_AT_HDRLEN);
    913 	return 0;
    914 
    915 trunc:
    916 	return 1;
    917 }
    918 
    919 /* The trailing data may include LLS and/or AT data (in this specific order).
    920  * LLS data may be present only in Hello and DBDesc packets with the L-bit set.
    921  * AT data may be present in Hello and DBDesc packets with the AT-bit set or in
    922  * any other packet type, thus decode the AT data regardless of the AT-bit.
    923  */
    924 static int
    925 ospf6_decode_v3_trailer(netdissect_options *ndo,
    926                         const struct ospf6hdr *op, const u_char *cp, const unsigned len)
    927 {
    928 	int llslen = 0;
    929 	int lls_hello = 0;
    930 	int lls_dd = 0;
    931 
    932 	if (op->ospf6_type == OSPF_TYPE_HELLO) {
    933 		const struct hello6 *hellop = (const struct hello6 *)((const uint8_t *)op + OSPF6HDR_LEN);
    934 		if (EXTRACT_32BITS(&hellop->hello_options) & OSPF6_OPTION_L)
    935 			lls_hello = 1;
    936 	} else if (op->ospf6_type == OSPF_TYPE_DD) {
    937 		const struct dd6 *ddp = (const struct dd6 *)((const uint8_t *)op + OSPF6HDR_LEN);
    938 		if (EXTRACT_32BITS(&ddp->db_options) & OSPF6_OPTION_L)
    939 			lls_dd = 1;
    940 	}
    941 	if ((lls_hello || lls_dd) && (llslen = ospf6_print_lls(ndo, cp, len)) < 0)
    942 		goto trunc;
    943 	return ospf6_decode_at(ndo, cp + llslen, len - llslen);
    944 
    945 trunc:
    946 	return 1;
    947 }
    948 
    949 void
    950 ospf6_print(netdissect_options *ndo,
    951             register const u_char *bp, register u_int length)
    952 {
    953 	register const struct ospf6hdr *op;
    954 	register const u_char *dataend;
    955 	register const char *cp;
    956 	uint16_t datalen;
    957 
    958 	op = (const struct ospf6hdr *)bp;
    959 
    960 	/* If the type is valid translate it, or just print the type */
    961 	/* value.  If it's not valid, say so and return */
    962 	ND_TCHECK(op->ospf6_type);
    963 	cp = tok2str(ospf6_type_values, "unknown packet type (%u)", op->ospf6_type);
    964 	ND_PRINT((ndo, "OSPFv%u, %s, length %d", op->ospf6_version, cp, length));
    965 	if (*cp == 'u') {
    966 		return;
    967 	}
    968 
    969 	if(!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
    970 		return;
    971 	}
    972 
    973 	/* OSPFv3 data always comes first and optional trailing data may follow. */
    974 	ND_TCHECK(op->ospf6_len);
    975 	datalen = EXTRACT_16BITS(&op->ospf6_len);
    976 	if (datalen > length) {
    977 		ND_PRINT((ndo, " [len %d]", datalen));
    978 		return;
    979 	}
    980 	dataend = bp + datalen;
    981 
    982 	ND_TCHECK(op->ospf6_routerid);
    983 	ND_PRINT((ndo, "\n\tRouter-ID %s", ipaddr_string(ndo, &op->ospf6_routerid)));
    984 
    985 	ND_TCHECK(op->ospf6_areaid);
    986 	if (EXTRACT_32BITS(&op->ospf6_areaid) != 0)
    987 		ND_PRINT((ndo, ", Area %s", ipaddr_string(ndo, &op->ospf6_areaid)));
    988 	else
    989 		ND_PRINT((ndo, ", Backbone Area"));
    990 	ND_TCHECK(op->ospf6_instanceid);
    991 	if (op->ospf6_instanceid)
    992 		ND_PRINT((ndo, ", Instance %u", op->ospf6_instanceid));
    993 
    994 	/* Do rest according to version.	 */
    995 	switch (op->ospf6_version) {
    996 
    997 	case 3:
    998 		/* ospf version 3 */
    999 		if (ospf6_decode_v3(ndo, op, dataend) ||
   1000 		    ospf6_decode_v3_trailer(ndo, op, dataend, length - datalen))
   1001 			goto trunc;
   1002 		break;
   1003 	}			/* end switch on version */
   1004 
   1005 	return;
   1006 trunc:
   1007 	ND_PRINT((ndo, "%s", tstr));
   1008 }
   1009