10f74e101Schristos /* 20f74e101Schristos * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997 30f74e101Schristos * The Regents of the University of California. All rights reserved. 40f74e101Schristos * 50f74e101Schristos * Redistribution and use in source and binary forms, with or without 60f74e101Schristos * modification, are permitted provided that: (1) source code distributions 70f74e101Schristos * retain the above copyright notice and this paragraph in its entirety, (2) 80f74e101Schristos * distributions including binary code include the above copyright notice and 90f74e101Schristos * this paragraph in its entirety in the documentation or other materials 100f74e101Schristos * provided with the distribution, and (3) all advertising materials mentioning 110f74e101Schristos * features or use of this software display the following acknowledgement: 120f74e101Schristos * ``This product includes software developed by the University of California, 130f74e101Schristos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 140f74e101Schristos * the University nor the names of its contributors may be used to endorse 150f74e101Schristos * or promote products derived from this software without specific prior 160f74e101Schristos * written permission. 170f74e101Schristos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 180f74e101Schristos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 190f74e101Schristos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 200f74e101Schristos * 210f74e101Schristos * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu) 220f74e101Schristos */ 230f74e101Schristos 2411b3aaa1Schristos #include <sys/cdefs.h> 250f74e101Schristos #ifndef lint 26*26ba0b50Schristos __RCSID("$NetBSD: print-ospf6.c,v 1.12 2024/09/02 16:15:32 christos Exp $"); 270f74e101Schristos #endif 280f74e101Schristos 29dc860a36Sspz /* \summary: IPv6 Open Shortest Path First (OSPFv3) printer */ 30dc860a36Sspz 31c74ad251Schristos #include <config.h> 320f74e101Schristos 33c74ad251Schristos #include "netdissect-stdinc.h" 340f74e101Schristos 350f74e101Schristos #include <string.h> 360f74e101Schristos 37fdccd7e4Schristos #include "netdissect.h" 380f74e101Schristos #include "addrtoname.h" 390f74e101Schristos #include "extract.h" 400f74e101Schristos 410f74e101Schristos #include "ospf.h" 42b3a00663Schristos 43b3a00663Schristos #define OSPF_TYPE_HELLO 1 /* Hello */ 44b3a00663Schristos #define OSPF_TYPE_DD 2 /* Database Description */ 45b3a00663Schristos #define OSPF_TYPE_LS_REQ 3 /* Link State Request */ 46b3a00663Schristos #define OSPF_TYPE_LS_UPDATE 4 /* Link State Update */ 47b3a00663Schristos #define OSPF_TYPE_LS_ACK 5 /* Link State Ack */ 48b3a00663Schristos 49b3a00663Schristos /* Options *_options */ 50b3a00663Schristos #define OSPF6_OPTION_V6 0x01 /* V6 bit: A bit for peeping tom */ 51b3a00663Schristos #define OSPF6_OPTION_E 0x02 /* E bit: External routes advertised */ 52b3a00663Schristos #define OSPF6_OPTION_MC 0x04 /* MC bit: Multicast capable */ 53b3a00663Schristos #define OSPF6_OPTION_N 0x08 /* N bit: For type-7 LSA */ 54b3a00663Schristos #define OSPF6_OPTION_R 0x10 /* R bit: Router bit */ 55b3a00663Schristos #define OSPF6_OPTION_DC 0x20 /* DC bit: Demand circuits */ 56b3a00663Schristos /* The field is actually 24-bit (RFC5340 Section A.2). */ 57b3a00663Schristos #define OSPF6_OPTION_AF 0x0100 /* AF bit: Multiple address families */ 58b3a00663Schristos #define OSPF6_OPTION_L 0x0200 /* L bit: Link-local signaling (LLS) */ 59b3a00663Schristos #define OSPF6_OPTION_AT 0x0400 /* AT bit: Authentication trailer */ 60b3a00663Schristos 61b3a00663Schristos 62b3a00663Schristos /* db_flags */ 63b3a00663Schristos #define OSPF6_DB_INIT 0x04 /* */ 64b3a00663Schristos #define OSPF6_DB_MORE 0x02 65b3a00663Schristos #define OSPF6_DB_MASTER 0x01 66b3a00663Schristos #define OSPF6_DB_M6 0x10 /* IPv6 MTU */ 67b3a00663Schristos 68b3a00663Schristos /* ls_type */ 69b3a00663Schristos #define LS_TYPE_ROUTER 1 /* router link */ 70b3a00663Schristos #define LS_TYPE_NETWORK 2 /* network link */ 71b3a00663Schristos #define LS_TYPE_INTER_AP 3 /* Inter-Area-Prefix */ 72b3a00663Schristos #define LS_TYPE_INTER_AR 4 /* Inter-Area-Router */ 73b3a00663Schristos #define LS_TYPE_ASE 5 /* ASE */ 74b3a00663Schristos #define LS_TYPE_GROUP 6 /* Group membership */ 75b3a00663Schristos #define LS_TYPE_NSSA 7 /* NSSA */ 76b3a00663Schristos #define LS_TYPE_LINK 8 /* Link LSA */ 77b3a00663Schristos #define LS_TYPE_INTRA_AP 9 /* Intra-Area-Prefix */ 78b3a00663Schristos #define LS_TYPE_INTRA_ATE 10 /* Intra-Area-TE */ 79b3a00663Schristos #define LS_TYPE_GRACE 11 /* Grace LSA */ 80b3a00663Schristos #define LS_TYPE_RI 12 /* Router information */ 81b3a00663Schristos #define LS_TYPE_INTER_ASTE 13 /* Inter-AS-TE */ 82b3a00663Schristos #define LS_TYPE_L1VPN 14 /* L1VPN */ 83b3a00663Schristos #define LS_TYPE_MASK 0x1fff 84b3a00663Schristos 85b3a00663Schristos #define LS_SCOPE_LINKLOCAL 0x0000 86b3a00663Schristos #define LS_SCOPE_AREA 0x2000 87b3a00663Schristos #define LS_SCOPE_AS 0x4000 88b3a00663Schristos #define LS_SCOPE_MASK 0x6000 89b3a00663Schristos #define LS_SCOPE_U 0x8000 90b3a00663Schristos 91b3a00663Schristos /* rla_link.link_type */ 92b3a00663Schristos #define RLA_TYPE_ROUTER 1 /* point-to-point to another router */ 93b3a00663Schristos #define RLA_TYPE_TRANSIT 2 /* connection to transit network */ 94b3a00663Schristos #define RLA_TYPE_VIRTUAL 4 /* virtual link */ 95b3a00663Schristos 96b3a00663Schristos /* rla_flags */ 97b3a00663Schristos #define RLA_FLAG_B 0x01 98b3a00663Schristos #define RLA_FLAG_E 0x02 99b3a00663Schristos #define RLA_FLAG_V 0x04 100b3a00663Schristos #define RLA_FLAG_W 0x08 101c74ad251Schristos #define RLA_FLAG_Nt 0x10 102b3a00663Schristos 103b3a00663Schristos /* lsa_prefix options */ 104b3a00663Schristos #define LSA_PREFIX_OPT_NU 0x01 105b3a00663Schristos #define LSA_PREFIX_OPT_LA 0x02 106b3a00663Schristos #define LSA_PREFIX_OPT_MC 0x04 107b3a00663Schristos #define LSA_PREFIX_OPT_P 0x08 108b3a00663Schristos #define LSA_PREFIX_OPT_DN 0x10 109c74ad251Schristos #define LSA_PREFIX_OPT_N 0x20 110b3a00663Schristos 111b3a00663Schristos /* sla_tosmetric breakdown */ 112b3a00663Schristos #define SLA_MASK_TOS 0x7f000000 113b3a00663Schristos #define SLA_MASK_METRIC 0x00ffffff 114b3a00663Schristos #define SLA_SHIFT_TOS 24 115b3a00663Schristos 116b3a00663Schristos /* asla_metric */ 117b3a00663Schristos #define ASLA_FLAG_FWDADDR 0x02000000 118b3a00663Schristos #define ASLA_FLAG_ROUTETAG 0x01000000 119b3a00663Schristos #define ASLA_MASK_METRIC 0x00ffffff 120b3a00663Schristos 121b3a00663Schristos /* RFC6506 Section 4.1 */ 122b3a00663Schristos #define OSPF6_AT_HDRLEN 16U 123b3a00663Schristos #define OSPF6_AUTH_TYPE_HMAC 0x0001 124b3a00663Schristos 125c74ad251Schristos typedef nd_uint32_t rtrid_t; 126b3a00663Schristos 127b3a00663Schristos /* link state advertisement header */ 128b3a00663Schristos struct lsa6_hdr { 129c74ad251Schristos nd_uint16_t ls_age; 130c74ad251Schristos nd_uint16_t ls_type; 131b3a00663Schristos rtrid_t ls_stateid; 132b3a00663Schristos rtrid_t ls_router; 133c74ad251Schristos nd_uint32_t ls_seq; 134c74ad251Schristos nd_uint16_t ls_chksum; 135c74ad251Schristos nd_uint16_t ls_length; 136b3a00663Schristos }; 137b3a00663Schristos 138b3a00663Schristos /* Length of an IPv6 address, in bytes. */ 139b3a00663Schristos #define IPV6_ADDR_LEN_BYTES (128/8) 140b3a00663Schristos 141b3a00663Schristos struct lsa6_prefix { 142c74ad251Schristos nd_uint8_t lsa_p_len; 143c74ad251Schristos nd_uint8_t lsa_p_opt; 144c74ad251Schristos nd_uint16_t lsa_p_metric; 145c74ad251Schristos nd_byte lsa_p_prefix[IPV6_ADDR_LEN_BYTES]; /* maximum length */ 146b3a00663Schristos }; 147b3a00663Schristos 148b3a00663Schristos /* link state advertisement */ 149b3a00663Schristos struct lsa6 { 150b3a00663Schristos struct lsa6_hdr ls_hdr; 151b3a00663Schristos 152b3a00663Schristos /* Link state types */ 153b3a00663Schristos union { 154b3a00663Schristos /* Router links advertisements */ 155b3a00663Schristos struct { 156b3a00663Schristos union { 157c74ad251Schristos nd_uint8_t flg; 158c74ad251Schristos nd_uint32_t opt; 159b3a00663Schristos } rla_flgandopt; 160b3a00663Schristos #define rla_flags rla_flgandopt.flg 161b3a00663Schristos #define rla_options rla_flgandopt.opt 162b3a00663Schristos struct rlalink6 { 163c74ad251Schristos nd_uint8_t link_type; 164c74ad251Schristos nd_byte link_zero; 165c74ad251Schristos nd_uint16_t link_metric; 166c74ad251Schristos nd_uint32_t link_ifid; 167c74ad251Schristos nd_uint32_t link_nifid; 168b3a00663Schristos rtrid_t link_nrtid; 169b3a00663Schristos } rla_link[1]; /* may repeat */ 170b3a00663Schristos } un_rla; 171b3a00663Schristos 172b3a00663Schristos /* Network links advertisements */ 173b3a00663Schristos struct { 174c74ad251Schristos nd_uint32_t nla_options; 175b3a00663Schristos rtrid_t nla_router[1]; /* may repeat */ 176b3a00663Schristos } un_nla; 177b3a00663Schristos 178b3a00663Schristos /* Inter Area Prefix LSA */ 179b3a00663Schristos struct { 180c74ad251Schristos nd_uint32_t inter_ap_metric; 181b3a00663Schristos struct lsa6_prefix inter_ap_prefix[1]; 182b3a00663Schristos } un_inter_ap; 183b3a00663Schristos 184b3a00663Schristos /* AS external links advertisements */ 185b3a00663Schristos struct { 186c74ad251Schristos nd_uint32_t asla_metric; 187b3a00663Schristos struct lsa6_prefix asla_prefix[1]; 188b3a00663Schristos /* some optional fields follow */ 189b3a00663Schristos } un_asla; 190b3a00663Schristos 191b3a00663Schristos #if 0 192b3a00663Schristos /* Summary links advertisements */ 193b3a00663Schristos struct { 194c74ad251Schristos nd_ipv4 sla_mask; 195c74ad251Schristos nd_uint32_t sla_tosmetric[1]; /* may repeat */ 196b3a00663Schristos } un_sla; 197b3a00663Schristos 198b3a00663Schristos /* Multicast group membership */ 199b3a00663Schristos struct mcla { 200c74ad251Schristos nd_uint32_t mcla_vtype; 201c74ad251Schristos nd_ipv4 mcla_vid; 202b3a00663Schristos } un_mcla[1]; 203b3a00663Schristos #endif 204b3a00663Schristos 205b3a00663Schristos /* Type 7 LSA */ 206b3a00663Schristos 207b3a00663Schristos /* Link LSA */ 208b3a00663Schristos struct llsa { 209b3a00663Schristos union { 210c74ad251Schristos nd_uint8_t pri; 211c74ad251Schristos nd_uint32_t opt; 212b3a00663Schristos } llsa_priandopt; 213b3a00663Schristos #define llsa_priority llsa_priandopt.pri 214b3a00663Schristos #define llsa_options llsa_priandopt.opt 215c74ad251Schristos nd_ipv6 llsa_lladdr; 216c74ad251Schristos nd_uint32_t llsa_nprefix; 217b3a00663Schristos struct lsa6_prefix llsa_prefix[1]; 218b3a00663Schristos } un_llsa; 219b3a00663Schristos 220b3a00663Schristos /* Intra-Area-Prefix */ 221b3a00663Schristos struct { 222c74ad251Schristos nd_uint16_t intra_ap_nprefix; 223c74ad251Schristos nd_uint16_t intra_ap_lstype; 224b3a00663Schristos rtrid_t intra_ap_lsid; 225b3a00663Schristos rtrid_t intra_ap_rtid; 226b3a00663Schristos struct lsa6_prefix intra_ap_prefix[1]; 227b3a00663Schristos } un_intra_ap; 228b3a00663Schristos } lsa_un; 229b3a00663Schristos }; 230b3a00663Schristos 231b3a00663Schristos /* 232b3a00663Schristos * the main header 233b3a00663Schristos */ 234b3a00663Schristos struct ospf6hdr { 235c74ad251Schristos nd_uint8_t ospf6_version; 236c74ad251Schristos nd_uint8_t ospf6_type; 237c74ad251Schristos nd_uint16_t ospf6_len; 238b3a00663Schristos rtrid_t ospf6_routerid; 239b3a00663Schristos rtrid_t ospf6_areaid; 240c74ad251Schristos nd_uint16_t ospf6_chksum; 241c74ad251Schristos nd_uint8_t ospf6_instanceid; 242c74ad251Schristos nd_uint8_t ospf6_rsvd; 243b3a00663Schristos }; 244b3a00663Schristos 245b3a00663Schristos /* 246b3a00663Schristos * The OSPF6 header length is 16 bytes, regardless of how your compiler 247b3a00663Schristos * might choose to pad the above structure. 248b3a00663Schristos */ 249b3a00663Schristos #define OSPF6HDR_LEN 16 250b3a00663Schristos 251b3a00663Schristos /* Hello packet */ 252b3a00663Schristos struct hello6 { 253c74ad251Schristos nd_uint32_t hello_ifid; 254b3a00663Schristos union { 255c74ad251Schristos nd_uint8_t pri; 256c74ad251Schristos nd_uint32_t opt; 257b3a00663Schristos } hello_priandopt; 258b3a00663Schristos #define hello_priority hello_priandopt.pri 259b3a00663Schristos #define hello_options hello_priandopt.opt 260c74ad251Schristos nd_uint16_t hello_helloint; 261c74ad251Schristos nd_uint16_t hello_deadint; 262b3a00663Schristos rtrid_t hello_dr; 263b3a00663Schristos rtrid_t hello_bdr; 264b3a00663Schristos rtrid_t hello_neighbor[1]; /* may repeat */ 265b3a00663Schristos }; 266b3a00663Schristos 267b3a00663Schristos /* Database Description packet */ 268b3a00663Schristos struct dd6 { 269c74ad251Schristos nd_uint32_t db_options; 270c74ad251Schristos nd_uint16_t db_mtu; 271c74ad251Schristos nd_uint8_t db_mbz; 272c74ad251Schristos nd_uint8_t db_flags; 273c74ad251Schristos nd_uint32_t db_seq; 274b3a00663Schristos struct lsa6_hdr db_lshdr[1]; /* may repeat */ 275b3a00663Schristos }; 276b3a00663Schristos 277b3a00663Schristos /* Link State Request */ 278b3a00663Schristos struct lsr6 { 279c74ad251Schristos nd_uint16_t ls_mbz; 280c74ad251Schristos nd_uint16_t ls_type; 281b3a00663Schristos rtrid_t ls_stateid; 282b3a00663Schristos rtrid_t ls_router; 283b3a00663Schristos }; 284b3a00663Schristos 285b3a00663Schristos /* Link State Update */ 286b3a00663Schristos struct lsu6 { 287c74ad251Schristos nd_uint32_t lsu_count; 288b3a00663Schristos struct lsa6 lsu_lsa[1]; /* may repeat */ 289b3a00663Schristos }; 290b3a00663Schristos 2910f74e101Schristos 2920f74e101Schristos static const struct tok ospf6_option_values[] = { 2930f74e101Schristos { OSPF6_OPTION_V6, "V6" }, 2940f74e101Schristos { OSPF6_OPTION_E, "External" }, 295b3a00663Schristos { OSPF6_OPTION_MC, "Deprecated" }, 2960f74e101Schristos { OSPF6_OPTION_N, "NSSA" }, 2970f74e101Schristos { OSPF6_OPTION_R, "Router" }, 2980f74e101Schristos { OSPF6_OPTION_DC, "Demand Circuit" }, 299b3a00663Schristos { OSPF6_OPTION_AF, "AFs Support" }, 300b3a00663Schristos { OSPF6_OPTION_L, "LLS" }, 301b3a00663Schristos { OSPF6_OPTION_AT, "Authentication Trailer" }, 3020f74e101Schristos { 0, NULL } 3030f74e101Schristos }; 3040f74e101Schristos 3050f74e101Schristos static const struct tok ospf6_rla_flag_values[] = { 3060f74e101Schristos { RLA_FLAG_B, "ABR" }, 3070f74e101Schristos { RLA_FLAG_E, "External" }, 3080f74e101Schristos { RLA_FLAG_V, "Virtual-Link Endpoint" }, 309c74ad251Schristos { RLA_FLAG_W, "Deprecated" }, 310c74ad251Schristos { RLA_FLAG_Nt, "NSSA Translator" }, 3110f74e101Schristos { 0, NULL } 3120f74e101Schristos }; 3130f74e101Schristos 3140f74e101Schristos static const struct tok ospf6_asla_flag_values[] = { 3150f74e101Schristos { ASLA_FLAG_EXTERNAL, "External Type 2" }, 316b3a00663Schristos { ASLA_FLAG_FWDADDR, "Forwarding" }, 3170f74e101Schristos { ASLA_FLAG_ROUTETAG, "Tag" }, 3180f74e101Schristos { 0, NULL } 3190f74e101Schristos }; 3200f74e101Schristos 321870189d2Schristos static const struct tok ospf6_type_values[] = { 3220f74e101Schristos { OSPF_TYPE_HELLO, "Hello" }, 3230f74e101Schristos { OSPF_TYPE_DD, "Database Description" }, 3240f74e101Schristos { OSPF_TYPE_LS_REQ, "LS-Request" }, 3250f74e101Schristos { OSPF_TYPE_LS_UPDATE, "LS-Update" }, 3260f74e101Schristos { OSPF_TYPE_LS_ACK, "LS-Ack" }, 3270f74e101Schristos { 0, NULL } 3280f74e101Schristos }; 3290f74e101Schristos 330870189d2Schristos static const struct tok ospf6_lsa_values[] = { 3310f74e101Schristos { LS_TYPE_ROUTER, "Router" }, 3320f74e101Schristos { LS_TYPE_NETWORK, "Network" }, 3330f74e101Schristos { LS_TYPE_INTER_AP, "Inter-Area Prefix" }, 3340f74e101Schristos { LS_TYPE_INTER_AR, "Inter-Area Router" }, 3350f74e101Schristos { LS_TYPE_ASE, "External" }, 336b3a00663Schristos { LS_TYPE_GROUP, "Deprecated" }, 3370f74e101Schristos { LS_TYPE_NSSA, "NSSA" }, 3380f74e101Schristos { LS_TYPE_LINK, "Link" }, 3390f74e101Schristos { LS_TYPE_INTRA_AP, "Intra-Area Prefix" }, 3400f74e101Schristos { LS_TYPE_INTRA_ATE, "Intra-Area TE" }, 3410f74e101Schristos { LS_TYPE_GRACE, "Grace" }, 342b3a00663Schristos { LS_TYPE_RI, "Router Information" }, 343b3a00663Schristos { LS_TYPE_INTER_ASTE, "Inter-AS-TE" }, 344b3a00663Schristos { LS_TYPE_L1VPN, "Layer 1 VPN" }, 3450f74e101Schristos { 0, NULL } 3460f74e101Schristos }; 3470f74e101Schristos 348870189d2Schristos static const struct tok ospf6_ls_scope_values[] = { 3490f74e101Schristos { LS_SCOPE_LINKLOCAL, "Link Local" }, 3500f74e101Schristos { LS_SCOPE_AREA, "Area Local" }, 3510f74e101Schristos { LS_SCOPE_AS, "Domain Wide" }, 3520f74e101Schristos { 0, NULL } 3530f74e101Schristos }; 3540f74e101Schristos 355870189d2Schristos static const struct tok ospf6_dd_flag_values[] = { 3560f74e101Schristos { OSPF6_DB_INIT, "Init" }, 3570f74e101Schristos { OSPF6_DB_MORE, "More" }, 3580f74e101Schristos { OSPF6_DB_MASTER, "Master" }, 359b3a00663Schristos { OSPF6_DB_M6, "IPv6 MTU" }, 3600f74e101Schristos { 0, NULL } 3610f74e101Schristos }; 3620f74e101Schristos 363870189d2Schristos static const struct tok ospf6_lsa_prefix_option_values[] = { 3640f74e101Schristos { LSA_PREFIX_OPT_NU, "No Unicast" }, 3650f74e101Schristos { LSA_PREFIX_OPT_LA, "Local address" }, 366b3a00663Schristos { LSA_PREFIX_OPT_MC, "Deprecated" }, 3670f74e101Schristos { LSA_PREFIX_OPT_P, "Propagate" }, 3680f74e101Schristos { LSA_PREFIX_OPT_DN, "Down" }, 369c74ad251Schristos { LSA_PREFIX_OPT_N, "N-bit" }, 3700f74e101Schristos { 0, NULL } 3710f74e101Schristos }; 3720f74e101Schristos 373b3a00663Schristos static const struct tok ospf6_auth_type_str[] = { 374b3a00663Schristos { OSPF6_AUTH_TYPE_HMAC, "HMAC" }, 375b3a00663Schristos { 0, NULL } 376b3a00663Schristos }; 3770f74e101Schristos 3780f74e101Schristos static void 379b3a00663Schristos ospf6_print_ls_type(netdissect_options *ndo, 380c74ad251Schristos u_int ls_type, const rtrid_t *ls_stateid) 3810f74e101Schristos { 382c74ad251Schristos ND_PRINT("\n\t %s LSA (%u), %s Scope%s, LSA-ID %s", 3830f74e101Schristos tok2str(ospf6_lsa_values, "Unknown", ls_type & LS_TYPE_MASK), 3840f74e101Schristos ls_type & LS_TYPE_MASK, 3850f74e101Schristos tok2str(ospf6_ls_scope_values, "Unknown", ls_type & LS_SCOPE_MASK), 3860f74e101Schristos ls_type &0x8000 ? ", transitive" : "", /* U-bit */ 387c74ad251Schristos GET_IPADDR_STRING(ls_stateid)); 3880f74e101Schristos } 3890f74e101Schristos 390a8e08e94Skamil UNALIGNED_OK 3910f74e101Schristos static int 392b3a00663Schristos ospf6_print_lshdr(netdissect_options *ndo, 393c74ad251Schristos const struct lsa6_hdr *lshp, const u_char *dataend) 3940f74e101Schristos { 395*26ba0b50Schristos u_int ls_length; 396*26ba0b50Schristos 397fdccd7e4Schristos if ((const u_char *)(lshp + 1) > dataend) 398b3a00663Schristos goto trunc; 3990f74e101Schristos 400*26ba0b50Schristos ls_length = GET_BE_U_2(lshp->ls_length); 401*26ba0b50Schristos if (ls_length < sizeof(struct lsa_hdr)) { 402*26ba0b50Schristos ND_PRINT("\n\t Bogus length %u < header (%zu)", ls_length, 403*26ba0b50Schristos sizeof(struct lsa_hdr)); 404*26ba0b50Schristos goto trunc; 405*26ba0b50Schristos } 406*26ba0b50Schristos 407c74ad251Schristos ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %zu", 408c74ad251Schristos GET_IPADDR_STRING(lshp->ls_router), 409c74ad251Schristos GET_BE_U_4(lshp->ls_seq), 410c74ad251Schristos GET_BE_U_2(lshp->ls_age), 411*26ba0b50Schristos ls_length-sizeof(struct lsa6_hdr)); 4120f74e101Schristos 413c74ad251Schristos ospf6_print_ls_type(ndo, GET_BE_U_2(lshp->ls_type), 414c74ad251Schristos &lshp->ls_stateid); 4150f74e101Schristos 4160f74e101Schristos return (0); 4170f74e101Schristos trunc: 4180f74e101Schristos return (1); 4190f74e101Schristos } 4200f74e101Schristos 4210f74e101Schristos static int 422b3a00663Schristos ospf6_print_lsaprefix(netdissect_options *ndo, 423b3a00663Schristos const uint8_t *tptr, u_int lsa_length) 4240f74e101Schristos { 425fdccd7e4Schristos const struct lsa6_prefix *lsapp = (const struct lsa6_prefix *)tptr; 4260f74e101Schristos u_int wordlen; 427c74ad251Schristos nd_ipv6 prefix; 4280f74e101Schristos 429b3a00663Schristos if (lsa_length < sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES) 4300e9868baSchristos goto trunc; 431b3a00663Schristos lsa_length -= sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES; 432c74ad251Schristos ND_TCHECK_LEN(lsapp, sizeof(*lsapp) - IPV6_ADDR_LEN_BYTES); 433c74ad251Schristos wordlen = (GET_U_1(lsapp->lsa_p_len) + 31) / 32; 434c74ad251Schristos if (wordlen * 4 > sizeof(nd_ipv6)) { 435c74ad251Schristos ND_PRINT(" bogus prefixlen /%u", GET_U_1(lsapp->lsa_p_len)); 4360f74e101Schristos goto trunc; 4370f74e101Schristos } 4380e9868baSchristos if (lsa_length < wordlen * 4) 4390e9868baSchristos goto trunc; 4400e9868baSchristos lsa_length -= wordlen * 4; 441c74ad251Schristos memset(prefix, 0, sizeof(prefix)); 442c74ad251Schristos GET_CPY_BYTES(prefix, lsapp->lsa_p_prefix, wordlen * 4); 443c74ad251Schristos ND_PRINT("\n\t\t%s/%u", ip6addr_string(ndo, prefix), /* local buffer, not packet data; don't use GET_IP6ADDR_STRING() */ 444c74ad251Schristos GET_U_1(lsapp->lsa_p_len)); 445c74ad251Schristos if (GET_U_1(lsapp->lsa_p_opt)) { 446c74ad251Schristos ND_PRINT(", Options [%s]", 4470f74e101Schristos bittok2str(ospf6_lsa_prefix_option_values, 448c74ad251Schristos "none", GET_U_1(lsapp->lsa_p_opt))); 4490f74e101Schristos } 450c74ad251Schristos ND_PRINT(", metric %u", GET_BE_U_2(lsapp->lsa_p_metric)); 451b3a00663Schristos return sizeof(*lsapp) - IPV6_ADDR_LEN_BYTES + wordlen * 4; 4520f74e101Schristos 4530f74e101Schristos trunc: 4540f74e101Schristos return -1; 4550f74e101Schristos } 4560f74e101Schristos 4570f74e101Schristos 4580f74e101Schristos /* 4590f74e101Schristos * Print a single link state advertisement. If truncated return 1, else 0. 4600f74e101Schristos */ 461a8e08e94Skamil UNALIGNED_OK 4620f74e101Schristos static int 463b3a00663Schristos ospf6_print_lsa(netdissect_options *ndo, 464c74ad251Schristos const struct lsa6 *lsap, const u_char *dataend) 4650f74e101Schristos { 466c74ad251Schristos const struct rlalink6 *rlp; 4670f74e101Schristos #if 0 468c74ad251Schristos const struct tos_metric *tosp; 4690f74e101Schristos #endif 470c74ad251Schristos const rtrid_t *ap; 4710f74e101Schristos #if 0 472c74ad251Schristos const struct aslametric *almp; 473c74ad251Schristos const struct mcla *mcp; 4740f74e101Schristos #endif 475c74ad251Schristos const struct llsa *llsap; 476c74ad251Schristos const struct lsa6_prefix *lsapp; 4770f74e101Schristos #if 0 478c74ad251Schristos const uint32_t *lp; 4790f74e101Schristos #endif 480c74ad251Schristos u_int prefixes; 481c74ad251Schristos int bytelen; 482c74ad251Schristos u_int length, lsa_length; 483b3a00663Schristos uint32_t flags32; 484b3a00663Schristos const uint8_t *tptr; 4850f74e101Schristos 486b3a00663Schristos if (ospf6_print_lshdr(ndo, &lsap->ls_hdr, dataend)) 4870f74e101Schristos return (1); 488c74ad251Schristos length = GET_BE_U_2(lsap->ls_hdr.ls_length); 4890e9868baSchristos 4900e9868baSchristos /* 4910e9868baSchristos * The LSA length includes the length of the header; 4920e9868baSchristos * it must have a value that's at least that length. 4930e9868baSchristos * If it does, find the length of what follows the 4940e9868baSchristos * header. 4950e9868baSchristos */ 496fdccd7e4Schristos if (length < sizeof(struct lsa6_hdr) || (const u_char *)lsap + length > dataend) 4970e9868baSchristos return (1); 4980f74e101Schristos lsa_length = length - sizeof(struct lsa6_hdr); 499fdccd7e4Schristos tptr = (const uint8_t *)lsap+sizeof(struct lsa6_hdr); 5000f74e101Schristos 501c74ad251Schristos switch (GET_BE_U_2(lsap->ls_hdr.ls_type)) { 5020f74e101Schristos case LS_TYPE_ROUTER | LS_SCOPE_AREA: 5030e9868baSchristos if (lsa_length < sizeof (lsap->lsa_un.un_rla.rla_options)) 5040e9868baSchristos return (1); 5050e9868baSchristos lsa_length -= sizeof (lsap->lsa_un.un_rla.rla_options); 506c74ad251Schristos ND_PRINT("\n\t Options [%s]", 5070f74e101Schristos bittok2str(ospf6_option_values, "none", 508c74ad251Schristos GET_BE_U_4(lsap->lsa_un.un_rla.rla_options))); 509c74ad251Schristos ND_PRINT(", RLA-Flags [%s]", 5100f74e101Schristos bittok2str(ospf6_rla_flag_values, "none", 511c74ad251Schristos GET_U_1(lsap->lsa_un.un_rla.rla_flags))); 5120f74e101Schristos 5130f74e101Schristos rlp = lsap->lsa_un.un_rla.rla_link; 5140e9868baSchristos while (lsa_length != 0) { 5150e9868baSchristos if (lsa_length < sizeof (*rlp)) 5160e9868baSchristos return (1); 5170e9868baSchristos lsa_length -= sizeof (*rlp); 518c74ad251Schristos ND_TCHECK_SIZE(rlp); 519c74ad251Schristos switch (GET_U_1(rlp->link_type)) { 5200f74e101Schristos 5210f74e101Schristos case RLA_TYPE_VIRTUAL: 522c74ad251Schristos ND_PRINT("\n\t Virtual Link: Neighbor Router-ID %s" 5230f74e101Schristos "\n\t Neighbor Interface-ID %s, Interface %s", 524c74ad251Schristos GET_IPADDR_STRING(rlp->link_nrtid), 525c74ad251Schristos GET_IPADDR_STRING(rlp->link_nifid), 526c74ad251Schristos GET_IPADDR_STRING(rlp->link_ifid)); 5270f74e101Schristos break; 5280f74e101Schristos 5290f74e101Schristos case RLA_TYPE_ROUTER: 530c74ad251Schristos ND_PRINT("\n\t Neighbor Router-ID %s" 5310f74e101Schristos "\n\t Neighbor Interface-ID %s, Interface %s", 532c74ad251Schristos GET_IPADDR_STRING(rlp->link_nrtid), 533c74ad251Schristos GET_IPADDR_STRING(rlp->link_nifid), 534c74ad251Schristos GET_IPADDR_STRING(rlp->link_ifid)); 5350f74e101Schristos break; 5360f74e101Schristos 5370f74e101Schristos case RLA_TYPE_TRANSIT: 538c74ad251Schristos ND_PRINT("\n\t Neighbor Network-ID %s" 5390f74e101Schristos "\n\t Neighbor Interface-ID %s, Interface %s", 540c74ad251Schristos GET_IPADDR_STRING(rlp->link_nrtid), 541c74ad251Schristos GET_IPADDR_STRING(rlp->link_nifid), 542c74ad251Schristos GET_IPADDR_STRING(rlp->link_ifid)); 5430f74e101Schristos break; 5440f74e101Schristos 5450f74e101Schristos default: 546c74ad251Schristos ND_PRINT("\n\t Unknown Router Links Type 0x%02x", 547c74ad251Schristos GET_U_1(rlp->link_type)); 5480f74e101Schristos return (0); 5490f74e101Schristos } 550c74ad251Schristos ND_PRINT(", metric %u", GET_BE_U_2(rlp->link_metric)); 5510f74e101Schristos rlp++; 5520f74e101Schristos } 5530f74e101Schristos break; 5540f74e101Schristos 5550f74e101Schristos case LS_TYPE_NETWORK | LS_SCOPE_AREA: 5560e9868baSchristos if (lsa_length < sizeof (lsap->lsa_un.un_nla.nla_options)) 5570e9868baSchristos return (1); 5580e9868baSchristos lsa_length -= sizeof (lsap->lsa_un.un_nla.nla_options); 559c74ad251Schristos ND_PRINT("\n\t Options [%s]", 5600f74e101Schristos bittok2str(ospf6_option_values, "none", 561c74ad251Schristos GET_BE_U_4(lsap->lsa_un.un_nla.nla_options))); 5620e9868baSchristos 563c74ad251Schristos ND_PRINT("\n\t Connected Routers:"); 5640f74e101Schristos ap = lsap->lsa_un.un_nla.nla_router; 5650e9868baSchristos while (lsa_length != 0) { 5660e9868baSchristos if (lsa_length < sizeof (*ap)) 5670e9868baSchristos return (1); 5680e9868baSchristos lsa_length -= sizeof (*ap); 569c74ad251Schristos ND_PRINT("\n\t\t%s", GET_IPADDR_STRING(ap)); 5700f74e101Schristos ++ap; 5710f74e101Schristos } 5720f74e101Schristos break; 5730f74e101Schristos 5740f74e101Schristos case LS_TYPE_INTER_AP | LS_SCOPE_AREA: 5750e9868baSchristos if (lsa_length < sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric)) 5760e9868baSchristos return (1); 5770e9868baSchristos lsa_length -= sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric); 578c74ad251Schristos ND_PRINT(", metric %u", 579c74ad251Schristos GET_BE_U_4(lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC); 5800e9868baSchristos 581fdccd7e4Schristos tptr = (const uint8_t *)lsap->lsa_un.un_inter_ap.inter_ap_prefix; 5820e9868baSchristos while (lsa_length != 0) { 583b3a00663Schristos bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length); 5840e9868baSchristos if (bytelen < 0) 5850f74e101Schristos goto trunc; 586c74ad251Schristos /* 587c74ad251Schristos * ospf6_print_lsaprefix() will return -1 if 588c74ad251Schristos * the length is too high, so this will not 589c74ad251Schristos * underflow. 590c74ad251Schristos */ 5910e9868baSchristos lsa_length -= bytelen; 5920e9868baSchristos tptr += bytelen; 5930f74e101Schristos } 5940f74e101Schristos break; 5950e9868baSchristos 5960e9868baSchristos case LS_TYPE_ASE | LS_SCOPE_AS: 5970e9868baSchristos if (lsa_length < sizeof (lsap->lsa_un.un_asla.asla_metric)) 5980e9868baSchristos return (1); 5990e9868baSchristos lsa_length -= sizeof (lsap->lsa_un.un_asla.asla_metric); 600c74ad251Schristos flags32 = GET_BE_U_4(lsap->lsa_un.un_asla.asla_metric); 601c74ad251Schristos ND_PRINT("\n\t Flags [%s]", 602c74ad251Schristos bittok2str(ospf6_asla_flag_values, "none", flags32)); 603c74ad251Schristos ND_PRINT(" metric %u", 604c74ad251Schristos GET_BE_U_4(lsap->lsa_un.un_asla.asla_metric) & 605c74ad251Schristos ASLA_MASK_METRIC); 6060e9868baSchristos 607fdccd7e4Schristos tptr = (const uint8_t *)lsap->lsa_un.un_asla.asla_prefix; 608fdccd7e4Schristos lsapp = (const struct lsa6_prefix *)tptr; 609b3a00663Schristos bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length); 6100f74e101Schristos if (bytelen < 0) 6110f74e101Schristos goto trunc; 612c74ad251Schristos /* 613c74ad251Schristos * ospf6_print_lsaprefix() will return -1 if 614c74ad251Schristos * the length is too high, so this will not 615c74ad251Schristos * underflow. 616c74ad251Schristos */ 6170e9868baSchristos lsa_length -= bytelen; 6180e9868baSchristos tptr += bytelen; 6190f74e101Schristos 6200f74e101Schristos if ((flags32 & ASLA_FLAG_FWDADDR) != 0) { 621c74ad251Schristos if (lsa_length < sizeof (nd_ipv6)) 6220e9868baSchristos return (1); 623c74ad251Schristos lsa_length -= sizeof (nd_ipv6); 624c74ad251Schristos ND_PRINT(" forward %s", 625c74ad251Schristos GET_IP6ADDR_STRING(tptr)); 626c74ad251Schristos tptr += sizeof(nd_ipv6); 6270f74e101Schristos } 6280f74e101Schristos 6290f74e101Schristos if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) { 630b3a00663Schristos if (lsa_length < sizeof (uint32_t)) 6310e9868baSchristos return (1); 632b3a00663Schristos lsa_length -= sizeof (uint32_t); 633c74ad251Schristos ND_PRINT(" tag %s", 634c74ad251Schristos GET_IPADDR_STRING(tptr)); 635b3a00663Schristos tptr += sizeof(uint32_t); 6360f74e101Schristos } 6370f74e101Schristos 638c74ad251Schristos if (GET_U_1(lsapp->lsa_p_metric)) { 639b3a00663Schristos if (lsa_length < sizeof (uint32_t)) 6400e9868baSchristos return (1); 641b3a00663Schristos lsa_length -= sizeof (uint32_t); 642c74ad251Schristos ND_PRINT(" RefLSID: %s", 643c74ad251Schristos GET_IPADDR_STRING(tptr)); 644b3a00663Schristos tptr += sizeof(uint32_t); 6450f74e101Schristos } 6460f74e101Schristos break; 6470f74e101Schristos 6480f74e101Schristos case LS_TYPE_LINK: 6490f74e101Schristos /* Link LSA */ 6500f74e101Schristos llsap = &lsap->lsa_un.un_llsa; 6510e9868baSchristos if (lsa_length < sizeof (llsap->llsa_priandopt)) 6520e9868baSchristos return (1); 6530e9868baSchristos lsa_length -= sizeof (llsap->llsa_priandopt); 654c74ad251Schristos ND_TCHECK_SIZE(&llsap->llsa_priandopt); 655c74ad251Schristos ND_PRINT("\n\t Options [%s]", 6560f74e101Schristos bittok2str(ospf6_option_values, "none", 657c74ad251Schristos GET_BE_U_4(llsap->llsa_options))); 6580e9868baSchristos 6590e9868baSchristos if (lsa_length < sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix)) 6600e9868baSchristos return (1); 6610e9868baSchristos lsa_length -= sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix); 662c74ad251Schristos prefixes = GET_BE_U_4(llsap->llsa_nprefix); 663c74ad251Schristos ND_PRINT("\n\t Priority %u, Link-local address %s, Prefixes %u:", 664c74ad251Schristos GET_U_1(llsap->llsa_priority), 665c74ad251Schristos GET_IP6ADDR_STRING(llsap->llsa_lladdr), 666c74ad251Schristos prefixes); 6670f74e101Schristos 668fdccd7e4Schristos tptr = (const uint8_t *)llsap->llsa_prefix; 6690f74e101Schristos while (prefixes > 0) { 670b3a00663Schristos bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length); 6710e9868baSchristos if (bytelen < 0) 6720f74e101Schristos goto trunc; 6730f74e101Schristos prefixes--; 674c74ad251Schristos /* 675c74ad251Schristos * ospf6_print_lsaprefix() will return -1 if 676c74ad251Schristos * the length is too high, so this will not 677c74ad251Schristos * underflow. 678c74ad251Schristos */ 6790e9868baSchristos lsa_length -= bytelen; 6800f74e101Schristos tptr += bytelen; 6810f74e101Schristos } 6820f74e101Schristos break; 6830f74e101Schristos 6840f74e101Schristos case LS_TYPE_INTRA_AP | LS_SCOPE_AREA: 6850f74e101Schristos /* Intra-Area-Prefix LSA */ 6860e9868baSchristos if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid)) 6870e9868baSchristos return (1); 6880e9868baSchristos lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid); 689c74ad251Schristos ND_TCHECK_4(lsap->lsa_un.un_intra_ap.intra_ap_rtid); 690b3a00663Schristos ospf6_print_ls_type(ndo, 691c74ad251Schristos GET_BE_U_2(lsap->lsa_un.un_intra_ap.intra_ap_lstype), 6920f74e101Schristos &lsap->lsa_un.un_intra_ap.intra_ap_lsid); 6930e9868baSchristos 6940e9868baSchristos if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix)) 6950e9868baSchristos return (1); 6960e9868baSchristos lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix); 697c74ad251Schristos prefixes = GET_BE_U_2(lsap->lsa_un.un_intra_ap.intra_ap_nprefix); 698c74ad251Schristos ND_PRINT("\n\t Prefixes %u:", prefixes); 6990f74e101Schristos 700fdccd7e4Schristos tptr = (const uint8_t *)lsap->lsa_un.un_intra_ap.intra_ap_prefix; 7010f74e101Schristos while (prefixes > 0) { 702b3a00663Schristos bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length); 7030e9868baSchristos if (bytelen < 0) 7040f74e101Schristos goto trunc; 7050f74e101Schristos prefixes--; 706c74ad251Schristos /* 707c74ad251Schristos * ospf6_print_lsaprefix() will return -1 if 708c74ad251Schristos * the length is too high, so this will not 709c74ad251Schristos * underflow. 710c74ad251Schristos */ 7110e9868baSchristos lsa_length -= bytelen; 7120f74e101Schristos tptr += bytelen; 7130f74e101Schristos } 7140f74e101Schristos break; 7150f74e101Schristos 7160f74e101Schristos case LS_TYPE_GRACE | LS_SCOPE_LINKLOCAL: 717c74ad251Schristos if (ospf_grace_lsa_print(ndo, tptr, lsa_length) == -1) { 7180f74e101Schristos return 1; 7190f74e101Schristos } 7200f74e101Schristos break; 7210f74e101Schristos 7220f74e101Schristos case LS_TYPE_INTRA_ATE | LS_SCOPE_LINKLOCAL: 723c74ad251Schristos if (ospf_te_lsa_print(ndo, tptr, lsa_length) == -1) { 7240f74e101Schristos return 1; 7250f74e101Schristos } 7260f74e101Schristos break; 7270f74e101Schristos 7280f74e101Schristos default: 729b3a00663Schristos if(!print_unknown_data(ndo,tptr, 7300f74e101Schristos "\n\t ", 7310f74e101Schristos lsa_length)) { 7320f74e101Schristos return (1); 7330f74e101Schristos } 7340e9868baSchristos break; 7350f74e101Schristos } 7360f74e101Schristos 7370f74e101Schristos return (0); 7380f74e101Schristos trunc: 7390f74e101Schristos return (1); 7400f74e101Schristos } 7410f74e101Schristos 742a8e08e94Skamil UNALIGNED_OK 7430f74e101Schristos static int 744b3a00663Schristos ospf6_decode_v3(netdissect_options *ndo, 745c74ad251Schristos const struct ospf6hdr *op, 746c74ad251Schristos const u_char *dataend) 7470f74e101Schristos { 748c74ad251Schristos const rtrid_t *ap; 749c74ad251Schristos const struct lsr6 *lsrp; 750c74ad251Schristos const struct lsa6_hdr *lshp; 751c74ad251Schristos const struct lsa6 *lsap; 752*26ba0b50Schristos uint32_t i; 7530f74e101Schristos 754c74ad251Schristos switch (GET_U_1(op->ospf6_type)) { 7550f74e101Schristos 756b3a00663Schristos case OSPF_TYPE_HELLO: { 757c74ad251Schristos const struct hello6 *hellop = (const struct hello6 *)((const uint8_t *)op + OSPF6HDR_LEN); 758b3a00663Schristos 759c74ad251Schristos ND_PRINT("\n\tOptions [%s]", 7600f74e101Schristos bittok2str(ospf6_option_values, "none", 761c74ad251Schristos GET_BE_U_4(hellop->hello_options))); 7620f74e101Schristos 763c74ad251Schristos ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u", 764c74ad251Schristos GET_BE_U_2(hellop->hello_helloint), 765c74ad251Schristos GET_BE_U_2(hellop->hello_deadint), 766c74ad251Schristos GET_IPADDR_STRING(hellop->hello_ifid), 767c74ad251Schristos GET_U_1(hellop->hello_priority)); 7680f74e101Schristos 769c74ad251Schristos if (GET_BE_U_4(hellop->hello_dr) != 0) 770c74ad251Schristos ND_PRINT("\n\t Designated Router %s", 771c74ad251Schristos GET_IPADDR_STRING(hellop->hello_dr)); 772c74ad251Schristos if (GET_BE_U_4(hellop->hello_bdr) != 0) 773c74ad251Schristos ND_PRINT(", Backup Designated Router %s", 774c74ad251Schristos GET_IPADDR_STRING(hellop->hello_bdr)); 775b3a00663Schristos if (ndo->ndo_vflag > 1) { 776c74ad251Schristos ND_PRINT("\n\t Neighbor List:"); 777b3a00663Schristos ap = hellop->hello_neighbor; 778fdccd7e4Schristos while ((const u_char *)ap < dataend) { 779c74ad251Schristos ND_PRINT("\n\t %s", GET_IPADDR_STRING(ap)); 7800f74e101Schristos ++ap; 7810f74e101Schristos } 7820f74e101Schristos } 7830f74e101Schristos break; /* HELLO */ 784b3a00663Schristos } 7850f74e101Schristos 786b3a00663Schristos case OSPF_TYPE_DD: { 787c74ad251Schristos const struct dd6 *ddp = (const struct dd6 *)((const uint8_t *)op + OSPF6HDR_LEN); 788b3a00663Schristos 789c74ad251Schristos ND_PRINT("\n\tOptions [%s]", 7900f74e101Schristos bittok2str(ospf6_option_values, "none", 791c74ad251Schristos GET_BE_U_4(ddp->db_options))); 792c74ad251Schristos ND_PRINT(", DD Flags [%s]", 793c74ad251Schristos bittok2str(ospf6_dd_flag_values,"none",GET_U_1(ddp->db_flags))); 7940f74e101Schristos 795c74ad251Schristos ND_PRINT(", MTU %u, DD-Sequence 0x%08x", 796c74ad251Schristos GET_BE_U_2(ddp->db_mtu), 797c74ad251Schristos GET_BE_U_4(ddp->db_seq)); 798b3a00663Schristos if (ndo->ndo_vflag > 1) { 7990f74e101Schristos /* Print all the LS adv's */ 800b3a00663Schristos lshp = ddp->db_lshdr; 801fdccd7e4Schristos while ((const u_char *)lshp < dataend) { 802b3a00663Schristos if (ospf6_print_lshdr(ndo, lshp++, dataend)) 803b3a00663Schristos goto trunc; 804b3a00663Schristos } 8050f74e101Schristos } 8060f74e101Schristos break; 807b3a00663Schristos } 8080f74e101Schristos 8090f74e101Schristos case OSPF_TYPE_LS_REQ: 810b3a00663Schristos if (ndo->ndo_vflag > 1) { 811fdccd7e4Schristos lsrp = (const struct lsr6 *)((const uint8_t *)op + OSPF6HDR_LEN); 812fdccd7e4Schristos while ((const u_char *)lsrp < dataend) { 813c74ad251Schristos ND_TCHECK_SIZE(lsrp); 814c74ad251Schristos ND_PRINT("\n\t Advertising Router %s", 815c74ad251Schristos GET_IPADDR_STRING(lsrp->ls_router)); 816c74ad251Schristos ospf6_print_ls_type(ndo, 817c74ad251Schristos GET_BE_U_2(lsrp->ls_type), 8180f74e101Schristos &lsrp->ls_stateid); 8190f74e101Schristos ++lsrp; 8200f74e101Schristos } 8210f74e101Schristos } 8220f74e101Schristos break; 8230f74e101Schristos 8240f74e101Schristos case OSPF_TYPE_LS_UPDATE: 825b3a00663Schristos if (ndo->ndo_vflag > 1) { 826c74ad251Schristos const struct lsu6 *lsup = (const struct lsu6 *)((const uint8_t *)op + OSPF6HDR_LEN); 827b3a00663Schristos 828c74ad251Schristos i = GET_BE_U_4(lsup->lsu_count); 829b3a00663Schristos lsap = lsup->lsu_lsa; 830fdccd7e4Schristos while ((const u_char *)lsap < dataend && i--) { 831b3a00663Schristos if (ospf6_print_lsa(ndo, lsap, dataend)) 8320f74e101Schristos goto trunc; 833fdccd7e4Schristos lsap = (const struct lsa6 *)((const u_char *)lsap + 834c74ad251Schristos GET_BE_U_2(lsap->ls_hdr.ls_length)); 8350f74e101Schristos } 8360f74e101Schristos } 8370f74e101Schristos break; 8380f74e101Schristos 8390f74e101Schristos case OSPF_TYPE_LS_ACK: 840b3a00663Schristos if (ndo->ndo_vflag > 1) { 841fdccd7e4Schristos lshp = (const struct lsa6_hdr *)((const uint8_t *)op + OSPF6HDR_LEN); 842fdccd7e4Schristos while ((const u_char *)lshp < dataend) { 843b3a00663Schristos if (ospf6_print_lshdr(ndo, lshp++, dataend)) 844b3a00663Schristos goto trunc; 8450f74e101Schristos } 8460f74e101Schristos } 8470f74e101Schristos break; 8480f74e101Schristos 8490f74e101Schristos default: 8500f74e101Schristos break; 8510f74e101Schristos } 8520f74e101Schristos return (0); 8530f74e101Schristos trunc: 8540f74e101Schristos return (1); 8550f74e101Schristos } 8560f74e101Schristos 857b3a00663Schristos /* RFC5613 Section 2.2 (w/o the TLVs) */ 858b3a00663Schristos static int 859b3a00663Schristos ospf6_print_lls(netdissect_options *ndo, 860b3a00663Schristos const u_char *cp, const u_int len) 861b3a00663Schristos { 862b3a00663Schristos uint16_t llsdatalen; 863b3a00663Schristos 864b3a00663Schristos if (len == 0) 865b3a00663Schristos return 0; 866b3a00663Schristos if (len < OSPF_LLS_HDRLEN) 867b3a00663Schristos goto trunc; 868b3a00663Schristos /* Checksum */ 869c74ad251Schristos ND_PRINT("\n\tLLS Checksum 0x%04x", GET_BE_U_2(cp)); 870b3a00663Schristos cp += 2; 871b3a00663Schristos /* LLS Data Length */ 872c74ad251Schristos llsdatalen = GET_BE_U_2(cp); 873c74ad251Schristos ND_PRINT(", Data Length %u", llsdatalen); 874b3a00663Schristos if (llsdatalen < OSPF_LLS_HDRLEN || llsdatalen > len) 875b3a00663Schristos goto trunc; 876b3a00663Schristos cp += 2; 877b3a00663Schristos /* LLS TLVs */ 878c74ad251Schristos ND_TCHECK_LEN(cp, llsdatalen - OSPF_LLS_HDRLEN); 879b3a00663Schristos /* FIXME: code in print-ospf.c can be reused to decode the TLVs */ 880b3a00663Schristos 881b3a00663Schristos return llsdatalen; 882b3a00663Schristos trunc: 883b3a00663Schristos return -1; 884b3a00663Schristos } 885b3a00663Schristos 886b3a00663Schristos /* RFC6506 Section 4.1 */ 887b3a00663Schristos static int 888b3a00663Schristos ospf6_decode_at(netdissect_options *ndo, 889b3a00663Schristos const u_char *cp, const u_int len) 890b3a00663Schristos { 891b3a00663Schristos uint16_t authdatalen; 892b3a00663Schristos 893b3a00663Schristos if (len == 0) 894b3a00663Schristos return 0; 895b3a00663Schristos if (len < OSPF6_AT_HDRLEN) 896b3a00663Schristos goto trunc; 897b3a00663Schristos /* Authentication Type */ 898c74ad251Schristos ND_PRINT("\n\tAuthentication Type %s", 899c74ad251Schristos tok2str(ospf6_auth_type_str, "unknown (0x%04x)", GET_BE_U_2(cp))); 900b3a00663Schristos cp += 2; 901b3a00663Schristos /* Auth Data Len */ 902c74ad251Schristos authdatalen = GET_BE_U_2(cp); 903c74ad251Schristos ND_PRINT(", Length %u", authdatalen); 904b3a00663Schristos if (authdatalen < OSPF6_AT_HDRLEN || authdatalen > len) 905b3a00663Schristos goto trunc; 906b3a00663Schristos cp += 2; 907b3a00663Schristos /* Reserved */ 908b3a00663Schristos cp += 2; 909b3a00663Schristos /* Security Association ID */ 910c74ad251Schristos ND_PRINT(", SAID %u", GET_BE_U_2(cp)); 911b3a00663Schristos cp += 2; 912b3a00663Schristos /* Cryptographic Sequence Number (High-Order 32 Bits) */ 913c74ad251Schristos ND_PRINT(", CSN 0x%08x", GET_BE_U_4(cp)); 914b3a00663Schristos cp += 4; 915b3a00663Schristos /* Cryptographic Sequence Number (Low-Order 32 Bits) */ 916c74ad251Schristos ND_PRINT(":%08x", GET_BE_U_4(cp)); 917b3a00663Schristos cp += 4; 918b3a00663Schristos /* Authentication Data */ 919c74ad251Schristos ND_TCHECK_LEN(cp, authdatalen - OSPF6_AT_HDRLEN); 920b3a00663Schristos if (ndo->ndo_vflag > 1) 921b3a00663Schristos print_unknown_data(ndo,cp, "\n\tAuthentication Data ", authdatalen - OSPF6_AT_HDRLEN); 922b3a00663Schristos return 0; 923b3a00663Schristos 924b3a00663Schristos trunc: 925b3a00663Schristos return 1; 926b3a00663Schristos } 927b3a00663Schristos 928b3a00663Schristos /* The trailing data may include LLS and/or AT data (in this specific order). 929b3a00663Schristos * LLS data may be present only in Hello and DBDesc packets with the L-bit set. 930b3a00663Schristos * AT data may be present in Hello and DBDesc packets with the AT-bit set or in 931b3a00663Schristos * any other packet type, thus decode the AT data regardless of the AT-bit. 932b3a00663Schristos */ 933a8e08e94Skamil UNALIGNED_OK 934b3a00663Schristos static int 935b3a00663Schristos ospf6_decode_v3_trailer(netdissect_options *ndo, 936b3a00663Schristos const struct ospf6hdr *op, const u_char *cp, const unsigned len) 937b3a00663Schristos { 938c74ad251Schristos uint8_t type; 939b3a00663Schristos int llslen = 0; 940b3a00663Schristos int lls_hello = 0; 941b3a00663Schristos int lls_dd = 0; 942b3a00663Schristos 943c74ad251Schristos type = GET_U_1(op->ospf6_type); 944c74ad251Schristos if (type == OSPF_TYPE_HELLO) { 945fdccd7e4Schristos const struct hello6 *hellop = (const struct hello6 *)((const uint8_t *)op + OSPF6HDR_LEN); 946c74ad251Schristos if (GET_BE_U_4(hellop->hello_options) & OSPF6_OPTION_L) 947b3a00663Schristos lls_hello = 1; 948c74ad251Schristos } else if (type == OSPF_TYPE_DD) { 949fdccd7e4Schristos const struct dd6 *ddp = (const struct dd6 *)((const uint8_t *)op + OSPF6HDR_LEN); 950c74ad251Schristos if (GET_BE_U_4(ddp->db_options) & OSPF6_OPTION_L) 951b3a00663Schristos lls_dd = 1; 952b3a00663Schristos } 953b3a00663Schristos if ((lls_hello || lls_dd) && (llslen = ospf6_print_lls(ndo, cp, len)) < 0) 954b3a00663Schristos goto trunc; 955b3a00663Schristos return ospf6_decode_at(ndo, cp + llslen, len - llslen); 956b3a00663Schristos 957b3a00663Schristos trunc: 958b3a00663Schristos return 1; 959b3a00663Schristos } 960b3a00663Schristos 961a8e08e94Skamil UNALIGNED_OK 9620f74e101Schristos void 963b3a00663Schristos ospf6_print(netdissect_options *ndo, 964c74ad251Schristos const u_char *bp, u_int length) 9650f74e101Schristos { 966c74ad251Schristos const struct ospf6hdr *op; 967c74ad251Schristos const u_char *dataend; 968c74ad251Schristos const char *cp; 969b3a00663Schristos uint16_t datalen; 9700f74e101Schristos 971c74ad251Schristos ndo->ndo_protocol = "ospf3"; 972fdccd7e4Schristos op = (const struct ospf6hdr *)bp; 9730f74e101Schristos 9740f74e101Schristos /* If the type is valid translate it, or just print the type */ 9750f74e101Schristos /* value. If it's not valid, say so and return */ 976c74ad251Schristos cp = tok2str(ospf6_type_values, "unknown packet type (%u)", 977c74ad251Schristos GET_U_1(op->ospf6_type)); 978c74ad251Schristos ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op->ospf6_version), cp, 979c74ad251Schristos length); 9800f74e101Schristos if (*cp == 'u') { 9810f74e101Schristos return; 9820f74e101Schristos } 9830f74e101Schristos 984b3a00663Schristos if(!ndo->ndo_vflag) { /* non verbose - so lets bail out here */ 9850f74e101Schristos return; 9860f74e101Schristos } 9870f74e101Schristos 988b3a00663Schristos /* OSPFv3 data always comes first and optional trailing data may follow. */ 989c74ad251Schristos datalen = GET_BE_U_2(op->ospf6_len); 990b3a00663Schristos if (datalen > length) { 991c74ad251Schristos ND_PRINT(" [len %u]", datalen); 9920f74e101Schristos return; 9930f74e101Schristos } 994b3a00663Schristos dataend = bp + datalen; 9950f74e101Schristos 996c74ad251Schristos ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op->ospf6_routerid)); 9970f74e101Schristos 998c74ad251Schristos if (GET_BE_U_4(op->ospf6_areaid) != 0) 999c74ad251Schristos ND_PRINT(", Area %s", GET_IPADDR_STRING(op->ospf6_areaid)); 10000f74e101Schristos else 1001c74ad251Schristos ND_PRINT(", Backbone Area"); 1002c74ad251Schristos if (GET_U_1(op->ospf6_instanceid)) 1003c74ad251Schristos ND_PRINT(", Instance %u", GET_U_1(op->ospf6_instanceid)); 10040f74e101Schristos 10050f74e101Schristos /* Do rest according to version. */ 1006c74ad251Schristos switch (GET_U_1(op->ospf6_version)) { 10070f74e101Schristos 10080f74e101Schristos case 3: 10090f74e101Schristos /* ospf version 3 */ 1010b3a00663Schristos if (ospf6_decode_v3(ndo, op, dataend) || 1011b3a00663Schristos ospf6_decode_v3_trailer(ndo, op, dataend, length - datalen)) 10120f74e101Schristos goto trunc; 10130f74e101Schristos break; 10140f74e101Schristos } /* end switch on version */ 10150f74e101Schristos 10160f74e101Schristos return; 10170f74e101Schristos trunc: 1018c74ad251Schristos nd_print_trunc(ndo); 10190f74e101Schristos } 1020