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