1 /* $KAME: icmp6.h,v 1.46 2001/04/27 15:09:48 itojun Exp $ */ 2 3 /*- 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the project nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 /*- 35 * Copyright (c) 1982, 1986, 1993 36 * The Regents of the University of California. All rights reserved. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 3. Neither the name of the University nor the names of its contributors 47 * may be used to endorse or promote products derived from this software 48 * without specific prior written permission. 49 * 50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 * SUCH DAMAGE. 61 */ 62 63 #ifndef _NETINET_ICMP6_H_ 64 #define _NETINET_ICMP6_H_ 65 66 #include <sys/stdint.h> 67 68 #define ICMPV6_PLD_MAXLEN 1232 /* IPV6_MMTU - sizeof(struct ip6_hdr) 69 - sizeof(struct icmp6_hdr) */ 70 71 struct icmp6_hdr { 72 u_int8_t icmp6_type; /* type field */ 73 u_int8_t icmp6_code; /* code field */ 74 u_int16_t icmp6_cksum; /* checksum field */ 75 union { 76 u_int32_t icmp6_un_data32[1]; /* type-specific field */ 77 u_int16_t icmp6_un_data16[2]; /* type-specific field */ 78 u_int8_t icmp6_un_data8[4]; /* type-specific field */ 79 } icmp6_dataun; 80 } __packed; 81 82 #define icmp6_data32 icmp6_dataun.icmp6_un_data32 83 #define icmp6_data16 icmp6_dataun.icmp6_un_data16 84 #define icmp6_data8 icmp6_dataun.icmp6_un_data8 85 #define icmp6_pptr icmp6_data32[0] /* parameter prob */ 86 #define icmp6_mtu icmp6_data32[0] /* packet too big */ 87 #define icmp6_id icmp6_data16[0] /* echo request/reply */ 88 #define icmp6_seq icmp6_data16[1] /* echo request/reply */ 89 #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */ 90 91 #define ICMP6_DST_UNREACH 1 /* dest unreachable, codes: */ 92 #define ICMP6_PACKET_TOO_BIG 2 /* packet too big */ 93 #define ICMP6_TIME_EXCEEDED 3 /* time exceeded, code: */ 94 #define ICMP6_PARAM_PROB 4 /* ip6 header bad */ 95 96 #define ICMP6_ECHO_REQUEST 128 /* echo service */ 97 #define ICMP6_ECHO_REPLY 129 /* echo reply */ 98 #define MLD_LISTENER_QUERY 130 /* multicast listener query */ 99 #define MLD_LISTENER_REPORT 131 /* multicast listener report */ 100 #define MLD_LISTENER_DONE 132 /* multicast listener done */ 101 #define MLD_LISTENER_REDUCTION MLD_LISTENER_DONE /* RFC3542 definition */ 102 103 /* RFC2292 decls */ 104 #define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */ 105 #define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */ 106 #define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */ 107 108 #ifndef _KERNEL 109 /* the followings are for backward compatibility to old KAME apps. */ 110 #define MLD6_LISTENER_QUERY MLD_LISTENER_QUERY 111 #define MLD6_LISTENER_REPORT MLD_LISTENER_REPORT 112 #define MLD6_LISTENER_DONE MLD_LISTENER_DONE 113 #endif 114 115 #define ND_ROUTER_SOLICIT 133 /* router solicitation */ 116 #define ND_ROUTER_ADVERT 134 /* router advertisement */ 117 #define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */ 118 #define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisement */ 119 #define ND_REDIRECT 137 /* redirect */ 120 121 #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */ 122 123 #define ICMP6_WRUREQUEST 139 /* who are you request */ 124 #define ICMP6_WRUREPLY 140 /* who are you reply */ 125 #define ICMP6_FQDN_QUERY 139 /* FQDN query */ 126 #define ICMP6_FQDN_REPLY 140 /* FQDN reply */ 127 #define ICMP6_NI_QUERY 139 /* node information request */ 128 #define ICMP6_NI_REPLY 140 /* node information reply */ 129 #define MLDV2_LISTENER_REPORT 143 /* RFC3810 listener report */ 130 131 /* The definitions below are experimental. TBA */ 132 #define MLD_MTRACE_RESP 200 /* mtrace resp (to sender) */ 133 #define MLD_MTRACE 201 /* mtrace messages */ 134 135 #ifndef _KERNEL 136 #define MLD6_MTRACE_RESP MLD_MTRACE_RESP 137 #define MLD6_MTRACE MLD_MTRACE 138 #endif 139 140 #define ICMP6_MAXTYPE 201 141 142 #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */ 143 #define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */ 144 #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor(obsolete) */ 145 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */ 146 #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */ 147 #define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */ 148 #define ICMP6_DST_UNREACH_POLICY 5 /* failed ingress/egress policy */ 149 #define ICMP6_DST_UNREACH_REJECT 6 /* Reject route to destination */ 150 #define ICMP6_DST_UNREACH_SRCROUTE 7 /* Error in source routing header */ 151 152 #define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */ 153 #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */ 154 155 #define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */ 156 #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */ 157 #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */ 158 159 #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */ 160 161 #define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */ 162 #define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */ 163 #define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */ 164 165 #define ICMP6_NI_SUCCESS 0 /* node information successful reply */ 166 #define ICMP6_NI_REFUSED 1 /* node information request is refused */ 167 #define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */ 168 169 #define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */ 170 #define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */ 171 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 /* rr seq num reset */ 172 173 /* Used in kernel only */ 174 #define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */ 175 #define ND_REDIRECT_ROUTER 1 /* redirect to a better router */ 176 177 /* 178 * Multicast Listener Discovery 179 */ 180 struct mld_hdr { 181 struct icmp6_hdr mld_icmp6_hdr; 182 struct in6_addr mld_addr; /* multicast address */ 183 } __packed; 184 185 /* definitions to provide backward compatibility to old KAME applications */ 186 #ifndef _KERNEL 187 #define mld6_hdr mld_hdr 188 #define mld6_type mld_type 189 #define mld6_code mld_code 190 #define mld6_cksum mld_cksum 191 #define mld6_maxdelay mld_maxdelay 192 #define mld6_reserved mld_reserved 193 #define mld6_addr mld_addr 194 #endif 195 196 /* shortcut macro definitions */ 197 #define mld_type mld_icmp6_hdr.icmp6_type 198 #define mld_code mld_icmp6_hdr.icmp6_code 199 #define mld_cksum mld_icmp6_hdr.icmp6_cksum 200 #define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0] 201 #define mld_reserved mld_icmp6_hdr.icmp6_data16[1] 202 #define mld_v2_reserved mld_icmp6_hdr.icmp6_data16[0] 203 #define mld_v2_numrecs mld_icmp6_hdr.icmp6_data16[1] 204 205 /* 206 * Neighbor Discovery 207 */ 208 209 struct nd_router_solicit { /* router solicitation */ 210 struct icmp6_hdr nd_rs_hdr; 211 /* could be followed by options */ 212 } __packed; 213 214 #define nd_rs_type nd_rs_hdr.icmp6_type 215 #define nd_rs_code nd_rs_hdr.icmp6_code 216 #define nd_rs_cksum nd_rs_hdr.icmp6_cksum 217 #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0] 218 219 struct nd_router_advert { /* router advertisement */ 220 struct icmp6_hdr nd_ra_hdr; 221 u_int32_t nd_ra_reachable; /* reachable time */ 222 u_int32_t nd_ra_retransmit; /* retransmit timer */ 223 /* could be followed by options */ 224 } __packed; 225 226 #define nd_ra_type nd_ra_hdr.icmp6_type 227 #define nd_ra_code nd_ra_hdr.icmp6_code 228 #define nd_ra_cksum nd_ra_hdr.icmp6_cksum 229 #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0] 230 #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1] 231 #define ND_RA_FLAG_MANAGED 0x80 232 #define ND_RA_FLAG_OTHER 0x40 233 #define ND_RA_FLAG_HA 0x20 234 235 /* 236 * Router preference values based on draft-draves-ipngwg-router-selection-01. 237 * These are non-standard definitions. 238 */ 239 #define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */ 240 241 #define ND_RA_FLAG_RTPREF_HIGH 0x08 /* 00001000 */ 242 #define ND_RA_FLAG_RTPREF_MEDIUM 0x00 /* 00000000 */ 243 #define ND_RA_FLAG_RTPREF_LOW 0x18 /* 00011000 */ 244 #define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */ 245 246 #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1] 247 248 struct nd_neighbor_solicit { /* neighbor solicitation */ 249 struct icmp6_hdr nd_ns_hdr; 250 struct in6_addr nd_ns_target; /*target address */ 251 /* could be followed by options */ 252 } __packed; 253 254 #define nd_ns_type nd_ns_hdr.icmp6_type 255 #define nd_ns_code nd_ns_hdr.icmp6_code 256 #define nd_ns_cksum nd_ns_hdr.icmp6_cksum 257 #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0] 258 259 struct nd_neighbor_advert { /* neighbor advertisement */ 260 struct icmp6_hdr nd_na_hdr; 261 struct in6_addr nd_na_target; /* target address */ 262 /* could be followed by options */ 263 } __packed; 264 265 #define nd_na_type nd_na_hdr.icmp6_type 266 #define nd_na_code nd_na_hdr.icmp6_code 267 #define nd_na_cksum nd_na_hdr.icmp6_cksum 268 #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0] 269 #if BYTE_ORDER == BIG_ENDIAN 270 #define ND_NA_FLAG_ROUTER 0x80000000 271 #define ND_NA_FLAG_SOLICITED 0x40000000 272 #define ND_NA_FLAG_OVERRIDE 0x20000000 273 #else 274 #if BYTE_ORDER == LITTLE_ENDIAN 275 #define ND_NA_FLAG_ROUTER 0x80 276 #define ND_NA_FLAG_SOLICITED 0x40 277 #define ND_NA_FLAG_OVERRIDE 0x20 278 #endif 279 #endif 280 281 struct nd_redirect { /* redirect */ 282 struct icmp6_hdr nd_rd_hdr; 283 struct in6_addr nd_rd_target; /* target address */ 284 struct in6_addr nd_rd_dst; /* destination address */ 285 /* could be followed by options */ 286 } __packed; 287 288 #define nd_rd_type nd_rd_hdr.icmp6_type 289 #define nd_rd_code nd_rd_hdr.icmp6_code 290 #define nd_rd_cksum nd_rd_hdr.icmp6_cksum 291 #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0] 292 293 struct nd_opt_hdr { /* Neighbor discovery option header */ 294 u_int8_t nd_opt_type; 295 u_int8_t nd_opt_len; 296 /* followed by option specific data*/ 297 } __packed; 298 299 #define ND_OPT_SOURCE_LINKADDR 1 300 #define ND_OPT_TARGET_LINKADDR 2 301 #define ND_OPT_PREFIX_INFORMATION 3 302 #define ND_OPT_REDIRECTED_HEADER 4 303 #define ND_OPT_MTU 5 304 #define ND_OPT_NONCE 14 /* RFC 3971 */ 305 #define ND_OPT_ROUTE_INFO 24 /* RFC 4191 */ 306 #define ND_OPT_RDNSS 25 /* RFC 6106 */ 307 #define ND_OPT_DNSSL 31 /* RFC 6106 */ 308 #define ND_OPT_PREF64 38 /* RFC 8781 */ 309 #define ND_OPT_MAX 38 310 311 struct nd_opt_prefix_info { /* prefix information */ 312 u_int8_t nd_opt_pi_type; 313 u_int8_t nd_opt_pi_len; 314 u_int8_t nd_opt_pi_prefix_len; 315 u_int8_t nd_opt_pi_flags_reserved; 316 u_int32_t nd_opt_pi_valid_time; 317 u_int32_t nd_opt_pi_preferred_time; 318 u_int32_t nd_opt_pi_reserved2; 319 struct in6_addr nd_opt_pi_prefix; 320 } __packed; 321 322 #define ND_OPT_PI_FLAG_ONLINK 0x80 323 #define ND_OPT_PI_FLAG_AUTO 0x40 324 325 struct nd_opt_rd_hdr { /* redirected header */ 326 u_int8_t nd_opt_rh_type; 327 u_int8_t nd_opt_rh_len; 328 u_int16_t nd_opt_rh_reserved1; 329 u_int32_t nd_opt_rh_reserved2; 330 /* followed by IP header and data */ 331 } __packed; 332 333 struct nd_opt_mtu { /* MTU option */ 334 u_int8_t nd_opt_mtu_type; 335 u_int8_t nd_opt_mtu_len; 336 u_int16_t nd_opt_mtu_reserved; 337 u_int32_t nd_opt_mtu_mtu; 338 } __packed; 339 340 #define ND_OPT_NONCE_LEN ((1 * 8) - 2) 341 #if ((ND_OPT_NONCE_LEN + 2) % 8) != 0 342 #error "(ND_OPT_NONCE_LEN + 2) must be a multiple of 8." 343 #endif 344 struct nd_opt_nonce { /* nonce option */ 345 u_int8_t nd_opt_nonce_type; 346 u_int8_t nd_opt_nonce_len; 347 u_int8_t nd_opt_nonce[ND_OPT_NONCE_LEN]; 348 } __packed; 349 350 struct nd_opt_route_info { /* route info */ 351 u_int8_t nd_opt_rti_type; 352 u_int8_t nd_opt_rti_len; 353 u_int8_t nd_opt_rti_prefixlen; 354 u_int8_t nd_opt_rti_flags; 355 u_int32_t nd_opt_rti_lifetime; 356 /* prefix follows */ 357 } __packed; 358 359 #define ND_OPT_RTI_FLAG_PRF_MASK 0x18 /* 00011000 */ 360 361 struct nd_opt_rdnss { /* RDNSS option (RFC 6106) */ 362 u_int8_t nd_opt_rdnss_type; 363 u_int8_t nd_opt_rdnss_len; 364 u_int16_t nd_opt_rdnss_reserved; 365 u_int32_t nd_opt_rdnss_lifetime; 366 /* followed by list of recursive DNS servers */ 367 } __packed; 368 369 struct nd_opt_dnssl { /* DNSSL option (RFC 6106) */ 370 u_int8_t nd_opt_dnssl_type; 371 u_int8_t nd_opt_dnssl_len; 372 u_int16_t nd_opt_dnssl_reserved; 373 u_int32_t nd_opt_dnssl_lifetime; 374 /* followed by list of DNS search domains */ 375 } __packed; 376 377 struct nd_opt_pref64 { /* PREF64 option (RFC 8781) */ 378 uint8_t nd_opt_pref64_type; 379 uint8_t nd_opt_pref64_len; 380 /* bits 0-12 are the SL, bits 13-15 are the PLC */ 381 uint16_t nd_opt_pref64_sl_plc; 382 char nd_opt_prefix[12]; 383 } __packed; 384 385 /* 386 * icmp6 namelookup 387 */ 388 389 struct icmp6_namelookup { 390 struct icmp6_hdr icmp6_nl_hdr; 391 u_int8_t icmp6_nl_nonce[8]; 392 int32_t icmp6_nl_ttl; 393 #if 0 394 u_int8_t icmp6_nl_len; 395 u_int8_t icmp6_nl_name[3]; 396 #endif 397 /* could be followed by options */ 398 } __packed; 399 400 /* 401 * icmp6 node information 402 */ 403 struct icmp6_nodeinfo { 404 struct icmp6_hdr icmp6_ni_hdr; 405 u_int8_t icmp6_ni_nonce[8]; 406 /* could be followed by reply data */ 407 } __packed; 408 409 #define ni_type icmp6_ni_hdr.icmp6_type 410 #define ni_code icmp6_ni_hdr.icmp6_code 411 #define ni_cksum icmp6_ni_hdr.icmp6_cksum 412 #define ni_qtype icmp6_ni_hdr.icmp6_data16[0] 413 #define ni_flags icmp6_ni_hdr.icmp6_data16[1] 414 415 #define NI_QTYPE_NOOP 0 /* NOOP */ 416 #define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */ 417 #define NI_QTYPE_FQDN 2 /* FQDN (draft 04) */ 418 #define NI_QTYPE_DNSNAME 2 /* DNS Name */ 419 #define NI_QTYPE_NODEADDR 3 /* Node Addresses */ 420 #define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */ 421 422 #if BYTE_ORDER == BIG_ENDIAN 423 #define NI_SUPTYPE_FLAG_COMPRESS 0x1 424 #define NI_FQDN_FLAG_VALIDTTL 0x1 425 #elif BYTE_ORDER == LITTLE_ENDIAN 426 #define NI_SUPTYPE_FLAG_COMPRESS 0x0100 427 #define NI_FQDN_FLAG_VALIDTTL 0x0100 428 #endif 429 430 #ifdef NAME_LOOKUPS_04 431 #if BYTE_ORDER == BIG_ENDIAN 432 #define NI_NODEADDR_FLAG_LINKLOCAL 0x1 433 #define NI_NODEADDR_FLAG_SITELOCAL 0x2 434 #define NI_NODEADDR_FLAG_GLOBAL 0x4 435 #define NI_NODEADDR_FLAG_ALL 0x8 436 #define NI_NODEADDR_FLAG_TRUNCATE 0x10 437 #define NI_NODEADDR_FLAG_ANYCAST 0x20 /* just experimental. not in spec */ 438 #elif BYTE_ORDER == LITTLE_ENDIAN 439 #define NI_NODEADDR_FLAG_LINKLOCAL 0x0100 440 #define NI_NODEADDR_FLAG_SITELOCAL 0x0200 441 #define NI_NODEADDR_FLAG_GLOBAL 0x0400 442 #define NI_NODEADDR_FLAG_ALL 0x0800 443 #define NI_NODEADDR_FLAG_TRUNCATE 0x1000 444 #define NI_NODEADDR_FLAG_ANYCAST 0x2000 /* just experimental. not in spec */ 445 #endif 446 #else /* draft-ietf-ipngwg-icmp-name-lookups-05 (and later?) */ 447 #if BYTE_ORDER == BIG_ENDIAN 448 #define NI_NODEADDR_FLAG_TRUNCATE 0x1 449 #define NI_NODEADDR_FLAG_ALL 0x2 450 #define NI_NODEADDR_FLAG_COMPAT 0x4 451 #define NI_NODEADDR_FLAG_LINKLOCAL 0x8 452 #define NI_NODEADDR_FLAG_SITELOCAL 0x10 453 #define NI_NODEADDR_FLAG_GLOBAL 0x20 454 #define NI_NODEADDR_FLAG_ANYCAST 0x40 /* just experimental. not in spec */ 455 #elif BYTE_ORDER == LITTLE_ENDIAN 456 #define NI_NODEADDR_FLAG_TRUNCATE 0x0100 457 #define NI_NODEADDR_FLAG_ALL 0x0200 458 #define NI_NODEADDR_FLAG_COMPAT 0x0400 459 #define NI_NODEADDR_FLAG_LINKLOCAL 0x0800 460 #define NI_NODEADDR_FLAG_SITELOCAL 0x1000 461 #define NI_NODEADDR_FLAG_GLOBAL 0x2000 462 #define NI_NODEADDR_FLAG_ANYCAST 0x4000 /* just experimental. not in spec */ 463 #endif 464 #endif 465 466 struct ni_reply_fqdn { 467 u_int32_t ni_fqdn_ttl; /* TTL */ 468 u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */ 469 u_int8_t ni_fqdn_name[3]; /* XXX: alignment */ 470 } __packed; 471 472 /* 473 * Router Renumbering. as router-renum-08.txt 474 */ 475 struct icmp6_router_renum { /* router renumbering header */ 476 struct icmp6_hdr rr_hdr; 477 u_int8_t rr_segnum; 478 u_int8_t rr_flags; 479 u_int16_t rr_maxdelay; 480 u_int32_t rr_reserved; 481 } __packed; 482 483 #define ICMP6_RR_FLAGS_TEST 0x80 484 #define ICMP6_RR_FLAGS_REQRESULT 0x40 485 #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20 486 #define ICMP6_RR_FLAGS_SPECSITE 0x10 487 #define ICMP6_RR_FLAGS_PREVDONE 0x08 488 489 #define rr_type rr_hdr.icmp6_type 490 #define rr_code rr_hdr.icmp6_code 491 #define rr_cksum rr_hdr.icmp6_cksum 492 #define rr_seqnum rr_hdr.icmp6_data32[0] 493 494 struct rr_pco_match { /* match prefix part */ 495 u_int8_t rpm_code; 496 u_int8_t rpm_len; 497 u_int8_t rpm_ordinal; 498 u_int8_t rpm_matchlen; 499 u_int8_t rpm_minlen; 500 u_int8_t rpm_maxlen; 501 u_int16_t rpm_reserved; 502 struct in6_addr rpm_prefix; 503 } __packed; 504 505 #define RPM_PCO_ADD 1 506 #define RPM_PCO_CHANGE 2 507 #define RPM_PCO_SETGLOBAL 3 508 #define RPM_PCO_MAX 4 509 510 struct rr_pco_use { /* use prefix part */ 511 u_int8_t rpu_uselen; 512 u_int8_t rpu_keeplen; 513 u_int8_t rpu_ramask; 514 u_int8_t rpu_raflags; 515 u_int32_t rpu_vltime; 516 u_int32_t rpu_pltime; 517 u_int32_t rpu_flags; 518 struct in6_addr rpu_prefix; 519 } __packed; 520 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80 521 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40 522 523 #if BYTE_ORDER == BIG_ENDIAN 524 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000 525 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000 526 #elif BYTE_ORDER == LITTLE_ENDIAN 527 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80 528 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40 529 #endif 530 531 struct rr_result { /* router renumbering result message */ 532 u_int16_t rrr_flags; 533 u_int8_t rrr_ordinal; 534 u_int8_t rrr_matchedlen; 535 u_int32_t rrr_ifid; 536 struct in6_addr rrr_prefix; 537 } __packed; 538 #if BYTE_ORDER == BIG_ENDIAN 539 #define ICMP6_RR_RESULT_FLAGS_OOB 0x0002 540 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001 541 #elif BYTE_ORDER == LITTLE_ENDIAN 542 #define ICMP6_RR_RESULT_FLAGS_OOB 0x0200 543 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100 544 #endif 545 546 /* 547 * icmp6 filter structures. 548 */ 549 550 struct icmp6_filter { 551 u_int32_t icmp6_filt[8]; 552 }; 553 554 #ifdef _KERNEL 555 #define ICMP6_FILTER_SETPASSALL(filterp) \ 556 do { \ 557 int i; u_char *p; \ 558 p = (u_char *)filterp; \ 559 for (i = 0; i < sizeof(struct icmp6_filter); i++) \ 560 p[i] = 0xff; \ 561 } while (/*CONSTCOND*/ 0) 562 #define ICMP6_FILTER_SETBLOCKALL(filterp) \ 563 bzero(filterp, sizeof(struct icmp6_filter)) 564 #else /* _KERNEL */ 565 #define ICMP6_FILTER_SETPASSALL(filterp) \ 566 memset(filterp, 0xff, sizeof(struct icmp6_filter)) 567 #define ICMP6_FILTER_SETBLOCKALL(filterp) \ 568 memset(filterp, 0x00, sizeof(struct icmp6_filter)) 569 #endif /* _KERNEL */ 570 571 #define ICMP6_FILTER_SETPASS(type, filterp) \ 572 (((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31))) 573 #define ICMP6_FILTER_SETBLOCK(type, filterp) \ 574 (((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))) 575 #define ICMP6_FILTER_WILLPASS(type, filterp) \ 576 ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0) 577 #define ICMP6_FILTER_WILLBLOCK(type, filterp) \ 578 ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0) 579 580 /* 581 * Variables related to this implementation 582 * of the internet control message protocol version 6. 583 */ 584 struct icmp6stat { 585 /* statistics related to icmp6 packets generated */ 586 uint64_t icp6s_error; /* # of calls to icmp6_error */ 587 uint64_t icp6s_canterror; /* no error 'cuz old was icmp */ 588 uint64_t icp6s_toofreq; /* no error 'cuz rate limitation */ 589 uint64_t icp6s_outhist[256]; 590 /* statistics related to input message processed */ 591 uint64_t icp6s_badcode; /* icmp6_code out of range */ 592 uint64_t icp6s_tooshort; /* packet < sizeof(struct icmp6_hdr) */ 593 uint64_t icp6s_checksum; /* bad checksum */ 594 uint64_t icp6s_badlen; /* calculated bound mismatch */ 595 uint64_t icp6s_dropped; /* # of packets dropped waiting for a resolution */ 596 /* 597 * number of responses: this member is inherited from netinet code, but 598 * for netinet6 code, it is already available in icp6s_outhist[]. 599 */ 600 uint64_t icp6s_reflect; 601 uint64_t icp6s_inhist[256]; 602 uint64_t icp6s_nd_toomanyopt; /* too many ND options */ 603 uint64_t icp6s_odst_unreach_noroute; 604 uint64_t icp6s_odst_unreach_admin; 605 uint64_t icp6s_odst_unreach_beyondscope; 606 uint64_t icp6s_odst_unreach_addr; 607 uint64_t icp6s_odst_unreach_noport; 608 uint64_t icp6s_opacket_too_big; 609 uint64_t icp6s_otime_exceed_transit; 610 uint64_t icp6s_otime_exceed_reassembly; 611 uint64_t icp6s_oparamprob_header; 612 uint64_t icp6s_oparamprob_nextheader; 613 uint64_t icp6s_oparamprob_option; 614 uint64_t icp6s_oredirect; 615 uint64_t icp6s_ounknown; 616 uint64_t icp6s_pmtuchg; /* path MTU changes */ 617 uint64_t icp6s_nd_badopt; /* bad ND options */ 618 uint64_t icp6s_badns; /* bad neighbor solicitation */ 619 uint64_t icp6s_badna; /* bad neighbor advertisement */ 620 uint64_t icp6s_badrs; /* bad router solicitation */ 621 uint64_t icp6s_badra; /* bad router advertisement */ 622 uint64_t icp6s_badredirect; /* bad redirect message */ 623 uint64_t icp6s_overflowdefrtr; /* Too many default routers. */ 624 uint64_t icp6s_overflowprfx; /* Too many prefixes. */ 625 uint64_t icp6s_overflownndp; /* Too many neighbour entries. */ 626 uint64_t icp6s_overflowredirect;/* Too many redirects. */ 627 uint64_t icp6s_invlhlim; /* Invalid hop limit. */ 628 uint64_t icp6s_spare[32]; 629 }; 630 631 #ifdef _KERNEL 632 #include <sys/counter.h> 633 #include <netinet/in_kdtrace.h> 634 635 #ifdef SYSCTL_DECL 636 SYSCTL_DECL(_net_inet6_icmp6); 637 #endif 638 639 VNET_PCPUSTAT_DECLARE(struct icmp6stat, icmp6stat); 640 /* 641 * In-kernel consumers can use these accessor macros directly to update 642 * stats. 643 */ 644 #define ICMP6STAT_ADD(name, val) \ 645 do { \ 646 MIB_SDT_PROBE1(icmp6, count, name, (val)); \ 647 VNET_PCPUSTAT_ADD(struct icmp6stat, icmp6stat, name, (val)); \ 648 } while (0) 649 #define ICMP6STAT_INC(name) ICMP6STAT_ADD(name, 1) 650 #define ICMP6STAT_INC2(name, type) \ 651 do { \ 652 MIB_SDT_PROBE2(icmp6, count, name, 1, type); \ 653 VNET_PCPUSTAT_ADD(struct icmp6stat, icmp6stat, name[type], 1); \ 654 } while (0) 655 656 /* 657 * Kernel module consumers must use this accessor macro. 658 */ 659 void kmod_icmp6stat_inc(int statnum); 660 #define KMOD_ICMP6STAT_INC(name) \ 661 do { \ 662 MIB_SDT_PROBE1(icmp6, count, name, 1); \ 663 kmod_icmp6stat_inc( \ 664 offsetof(struct icmp6stat, name) / sizeof(uint64_t)); \ 665 } while (0) 666 #endif 667 668 /* 669 * Names for ICMP sysctl objects 670 */ 671 #define ICMPV6CTL_STATS 1 672 #define ICMPV6CTL_REDIRACCEPT 2 /* accept/process redirects */ 673 #define ICMPV6CTL_REDIRTIMEOUT 3 /* redirect cache time */ 674 #if 0 /*obsoleted*/ 675 #define ICMPV6CTL_ERRRATELIMIT 5 /* ICMPv6 error rate limitation */ 676 #endif 677 #define ICMPV6CTL_ND6_PRUNE 6 678 #define ICMPV6CTL_ND6_DELAY 8 679 #define ICMPV6CTL_ND6_UMAXTRIES 9 680 #define ICMPV6CTL_ND6_MMAXTRIES 10 681 #define ICMPV6CTL_ND6_USELOOPBACK 11 682 /*#define ICMPV6CTL_ND6_PROXYALL 12 obsoleted, do not reuse here */ 683 #define ICMPV6CTL_NODEINFO 13 684 #define ICMPV6CTL_ERRPPSLIMIT 14 /* ICMPv6 error pps limitation */ 685 #define ICMPV6CTL_ND6_MAXNUDHINT 15 686 #define ICMPV6CTL_MTUDISC_HIWAT 16 687 #define ICMPV6CTL_MTUDISC_LOWAT 17 688 #define ICMPV6CTL_ND6_DEBUG 18 689 #define ICMPV6CTL_ND6_DRLIST 19 690 #define ICMPV6CTL_ND6_PRLIST 20 691 #define ICMPV6CTL_MLD_MAXSRCFILTER 21 692 #define ICMPV6CTL_MLD_SOMAXSRC 22 693 #define ICMPV6CTL_MLD_VERSION 23 694 #define ICMPV6CTL_ND6_MAXQLEN 24 695 #define ICMPV6CTL_NODEINFO_OLDMCPREFIX 25 696 #define ICMPV6CTL_MAXID 26 697 698 #ifdef _KERNEL 699 # ifdef __STDC__ 700 struct nhop_object; 701 struct rttimer; 702 struct in6_multi; 703 # endif 704 void icmp6_paramerror(struct mbuf *, int); 705 int icmp6_errmap(const struct icmp6_hdr *); 706 void icmp6_error(struct mbuf *, int, int, int); 707 void icmp6_error2(struct mbuf *, int, int, int, struct ifnet *); 708 int icmp6_input(struct mbuf **, int *, int); 709 void icmp6_prepare(struct mbuf *); 710 void icmp6_redirect_input(struct mbuf *, int); 711 void icmp6_redirect_output(struct mbuf *, struct nhop_object *); 712 int icmp6_ratelimit(const struct in6_addr *, const int, const int); 713 714 /* XXX: is this the right place for these macros? */ 715 #define icmp6_ifstat_inc(ifp, tag) \ 716 do { \ 717 if (ifp) \ 718 counter_u64_add((ifp)->if_inet6->icmp6_ifstat[ \ 719 offsetof(struct icmp6_ifstat, tag) / sizeof(uint64_t)], 1);\ 720 } while (/*CONSTCOND*/ 0) 721 722 #define icmp6_ifoutstat_inc(ifp, type, code) \ 723 do { \ 724 icmp6_ifstat_inc(ifp, ifs6_out_msg); \ 725 if (type < ICMP6_INFOMSG_MASK) \ 726 icmp6_ifstat_inc(ifp, ifs6_out_error); \ 727 switch (type) { \ 728 case ICMP6_DST_UNREACH: \ 729 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \ 730 if (code == ICMP6_DST_UNREACH_ADMIN) \ 731 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib); \ 732 break; \ 733 case ICMP6_PACKET_TOO_BIG: \ 734 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \ 735 break; \ 736 case ICMP6_TIME_EXCEEDED: \ 737 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \ 738 break; \ 739 case ICMP6_PARAM_PROB: \ 740 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \ 741 break; \ 742 case ICMP6_ECHO_REQUEST: \ 743 icmp6_ifstat_inc(ifp, ifs6_out_echo); \ 744 break; \ 745 case ICMP6_ECHO_REPLY: \ 746 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \ 747 break; \ 748 case MLD_LISTENER_QUERY: \ 749 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \ 750 break; \ 751 case MLD_LISTENER_REPORT: \ 752 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \ 753 break; \ 754 case MLD_LISTENER_DONE: \ 755 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \ 756 break; \ 757 case ND_ROUTER_SOLICIT: \ 758 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \ 759 break; \ 760 case ND_ROUTER_ADVERT: \ 761 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \ 762 break; \ 763 case ND_NEIGHBOR_SOLICIT: \ 764 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit); \ 765 break; \ 766 case ND_NEIGHBOR_ADVERT: \ 767 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \ 768 break; \ 769 case ND_REDIRECT: \ 770 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \ 771 break; \ 772 } \ 773 } while (/*CONSTCOND*/ 0) 774 775 #define ICMP6_NODEINFO_FQDNOK 0x1 776 #define ICMP6_NODEINFO_NODEADDROK 0x2 777 #define ICMP6_NODEINFO_TMPADDROK 0x4 778 #define ICMP6_NODEINFO_GLOBALOK 0x8 779 #endif /* _KERNEL */ 780 781 #endif /* not _NETINET_ICMP6_H_ */ 782