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