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_PVD 21 /* RFC 8801 */ 341 #define ND_OPT_ROUTE_INFO 24 /* RFC 4191 */ 342 #define ND_OPT_RDNSS 25 /* RFC 6106 */ 343 #define ND_OPT_DNSSL 31 /* RFC 6106 */ 344 #define ND_OPT_CAPTIVE_PORTAL 37 /* RFC 7710 */ 345 #define ND_OPT_PREF64 38 /* RFC 8781 */ 346 347 struct nd_opt_prefix_info { /* prefix information */ 348 u_int8_t nd_opt_pi_type; 349 u_int8_t nd_opt_pi_len; 350 u_int8_t nd_opt_pi_prefix_len; 351 u_int8_t nd_opt_pi_flags_reserved; 352 u_int32_t nd_opt_pi_valid_time; 353 u_int32_t nd_opt_pi_preferred_time; 354 u_int32_t nd_opt_pi_reserved2; 355 struct in6_addr nd_opt_pi_prefix; 356 }__attribute__((__packed__)); 357 358 #define ND_OPT_PI_FLAG_ONLINK 0x80 359 #define ND_OPT_PI_FLAG_AUTO 0x40 360 361 #define ND_OPT_NONCE_LEN ((1 * 8) - 2) 362 #if ((ND_OPT_NONCE_LEN + 2) % 8) != 0 363 #error "(ND_OPT_NONCE_LEN + 2) must be a multiple of 8." 364 #endif 365 366 struct nd_opt_nonce { /* nonce option */ 367 u_int8_t nd_opt_nonce_type; 368 u_int8_t nd_opt_nonce_len; 369 u_int8_t nd_opt_nonce[ND_OPT_NONCE_LEN]; 370 } __attribute__((__packed__)); 371 372 struct nd_opt_rd_hdr { /* redirected header */ 373 u_int8_t nd_opt_rh_type; 374 u_int8_t nd_opt_rh_len; 375 u_int16_t nd_opt_rh_reserved1; 376 u_int32_t nd_opt_rh_reserved2; 377 /* followed by IP header and data */ 378 } __attribute__((__packed__)); 379 380 struct nd_opt_mtu { /* MTU option */ 381 u_int8_t nd_opt_mtu_type; 382 u_int8_t nd_opt_mtu_len; 383 u_int16_t nd_opt_mtu_reserved; 384 u_int32_t nd_opt_mtu_mtu; 385 }__attribute__((__packed__)); 386 387 struct nd_opt_route_info { /* route info */ 388 u_int8_t nd_opt_rti_type; 389 u_int8_t nd_opt_rti_len; 390 u_int8_t nd_opt_rti_prefixlen; 391 u_int8_t nd_opt_rti_flags; 392 u_int32_t nd_opt_rti_lifetime; 393 /* prefix follows */ 394 }__attribute__((__packed__)); 395 396 struct nd_opt_rdnss { /* recursive domain name system servers */ 397 u_int8_t nd_opt_rdnss_type; 398 u_int8_t nd_opt_rdnss_len; 399 u_int16_t nd_opt_rdnss_reserved; 400 u_int32_t nd_opt_rdnss_lifetime; 401 struct in6_addr nd_opt_rdnss_addr[1]; 402 } __attribute__((__packed__)); 403 404 struct nd_opt_dnssl { /* domain name search list */ 405 u_int8_t nd_opt_dnssl_type; 406 u_int8_t nd_opt_dnssl_len; 407 u_int16_t nd_opt_dnssl_reserved; 408 u_int32_t nd_opt_dnssl_lifetime; 409 u_int8_t nd_opt_dnssl_domains[8]; 410 } __attribute__((__packed__)); 411 412 /* 413 * PREF64 (NAT64 prefix) RFC 8781 414 */ 415 struct nd_opt_pref64 { /* NAT64 prefix */ 416 u_int8_t nd_opt_pref64_type; 417 u_int8_t nd_opt_pref64_len; 418 u_int16_t nd_opt_pref64_scaled_lifetime_plc; 419 u_int32_t nd_opt_pref64_prefix[3]; 420 } __attribute__((__packed__)); 421 422 #define ND_OPT_PREF64_SCALED_LIFETIME_MASK 0xfff8 423 #define ND_OPT_PREF64_PLC_MASK 0x0007 424 #define ND_OPT_PREF64_LIFETIME_MAX 65528 425 #define ND_OPT_PREF64_PLC_32 5 426 #define ND_OPT_PREF64_PLC_40 4 427 #define ND_OPT_PREF64_PLC_48 3 428 #define ND_OPT_PREF64_PLC_56 2 429 #define ND_OPT_PREF64_PLC_64 1 430 #define ND_OPT_PREF64_PLC_96 0 431 432 /* 433 * PvD (Provisioning Domain) RFC 8801 434 */ 435 struct nd_opt_pvd { 436 u_int8_t nd_opt_pvd_type; 437 u_int8_t nd_opt_pvd_len; 438 /* http: 1 bit */ 439 /* legacy: 1 bit */ 440 /* ra: 1 bit */ 441 /* reserved: 9 bits */ 442 /* delay: 4 bits */ 443 u_int8_t nd_opt_flags_delay[2]; 444 u_int16_t nd_opt_pvd_seq; 445 u_int8_t nd_opt_pvd_id[1]; 446 } __attribute__((__packed__)); 447 448 #define ND_OPT_PVD_MIN_LENGTH offsetof(struct nd_opt_pvd, nd_opt_pvd_id) 449 #define ND_OPT_PVD_FLAGS_HTTP 0x80 450 #define ND_OPT_PVD_FLAGS_LEGACY 0x40 451 #define ND_OPT_PVD_FLAGS_RA 0x20 452 #define ND_OPT_PVD_DELAY_MASK 0x0f 453 454 /* 455 * icmp6 namelookup 456 */ 457 458 struct icmp6_namelookup { 459 struct icmp6_hdr icmp6_nl_hdr; 460 u_int8_t icmp6_nl_nonce[8]; 461 int32_t icmp6_nl_ttl; 462 #if 0 463 u_int8_t icmp6_nl_len; 464 u_int8_t icmp6_nl_name[3]; 465 #endif 466 /* could be followed by options */ 467 }__attribute__((__packed__)); 468 469 /* 470 * icmp6 node information 471 */ 472 struct icmp6_nodeinfo { 473 struct icmp6_hdr icmp6_ni_hdr; 474 u_int8_t icmp6_ni_nonce[8]; 475 /* could be followed by reply data */ 476 }__attribute__((__packed__)); 477 478 #define ni_type icmp6_ni_hdr.icmp6_type 479 #define ni_code icmp6_ni_hdr.icmp6_code 480 #define ni_cksum icmp6_ni_hdr.icmp6_cksum 481 #define ni_qtype icmp6_ni_hdr.icmp6_data16[0] 482 #define ni_flags icmp6_ni_hdr.icmp6_data16[1] 483 484 #define NI_QTYPE_NOOP 0 /* NOOP */ 485 #define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */ 486 #define NI_QTYPE_FQDN 2 /* FQDN (draft 04) */ 487 #define NI_QTYPE_DNSNAME 2 /* DNS Name */ 488 #define NI_QTYPE_NODEADDR 3 /* Node Addresses */ 489 #define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */ 490 491 #if BYTE_ORDER == BIG_ENDIAN 492 #define NI_SUPTYPE_FLAG_COMPRESS 0x1 493 #define NI_FQDN_FLAG_VALIDTTL 0x1 494 #elif BYTE_ORDER == LITTLE_ENDIAN 495 #define NI_SUPTYPE_FLAG_COMPRESS 0x0100 496 #define NI_FQDN_FLAG_VALIDTTL 0x0100 497 #endif 498 499 #ifdef NAME_LOOKUPS_04 500 #if BYTE_ORDER == BIG_ENDIAN 501 #define NI_NODEADDR_FLAG_LINKLOCAL 0x1 502 #define NI_NODEADDR_FLAG_SITELOCAL 0x2 503 #define NI_NODEADDR_FLAG_GLOBAL 0x4 504 #define NI_NODEADDR_FLAG_ALL 0x8 505 #define NI_NODEADDR_FLAG_TRUNCATE 0x10 506 #define NI_NODEADDR_FLAG_ANYCAST 0x20 /* just experimental. not in spec */ 507 #elif BYTE_ORDER == LITTLE_ENDIAN 508 #define NI_NODEADDR_FLAG_LINKLOCAL 0x0100 509 #define NI_NODEADDR_FLAG_SITELOCAL 0x0200 510 #define NI_NODEADDR_FLAG_GLOBAL 0x0400 511 #define NI_NODEADDR_FLAG_ALL 0x0800 512 #define NI_NODEADDR_FLAG_TRUNCATE 0x1000 513 #define NI_NODEADDR_FLAG_ANYCAST 0x2000 /* just experimental. not in spec */ 514 #endif 515 #else /* draft-ietf-ipngwg-icmp-name-lookups-05 (and later?) */ 516 #if BYTE_ORDER == BIG_ENDIAN 517 #define NI_NODEADDR_FLAG_TRUNCATE 0x1 518 #define NI_NODEADDR_FLAG_ALL 0x2 519 #define NI_NODEADDR_FLAG_COMPAT 0x4 520 #define NI_NODEADDR_FLAG_LINKLOCAL 0x8 521 #define NI_NODEADDR_FLAG_SITELOCAL 0x10 522 #define NI_NODEADDR_FLAG_GLOBAL 0x20 523 #define NI_NODEADDR_FLAG_ANYCAST 0x40 /* just experimental. not in spec */ 524 #elif BYTE_ORDER == LITTLE_ENDIAN 525 #define NI_NODEADDR_FLAG_TRUNCATE 0x0100 526 #define NI_NODEADDR_FLAG_ALL 0x0200 527 #define NI_NODEADDR_FLAG_COMPAT 0x0400 528 #define NI_NODEADDR_FLAG_LINKLOCAL 0x0800 529 #define NI_NODEADDR_FLAG_SITELOCAL 0x1000 530 #define NI_NODEADDR_FLAG_GLOBAL 0x2000 531 #define NI_NODEADDR_FLAG_ANYCAST 0x4000 /* just experimental. not in spec */ 532 #endif 533 #endif 534 535 struct ni_reply_fqdn { 536 u_int32_t ni_fqdn_ttl; /* TTL */ 537 u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */ 538 u_int8_t ni_fqdn_name[3]; /* XXX: alignment */ 539 }__attribute__((__packed__)); 540 541 /* 542 * Router Renumbering. as router-renum-08.txt 543 */ 544 struct icmp6_router_renum { /* router renumbering header */ 545 struct icmp6_hdr rr_hdr; 546 u_int8_t rr_segnum; 547 u_int8_t rr_flags; 548 u_int16_t rr_maxdelay; 549 u_int32_t rr_reserved; 550 } __attribute__((__packed__)); 551 552 #define ICMP6_RR_FLAGS_TEST 0x80 553 #define ICMP6_RR_FLAGS_REQRESULT 0x40 554 #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20 555 #define ICMP6_RR_FLAGS_SPECSITE 0x10 556 #define ICMP6_RR_FLAGS_PREVDONE 0x08 557 558 #define rr_type rr_hdr.icmp6_type 559 #define rr_code rr_hdr.icmp6_code 560 #define rr_cksum rr_hdr.icmp6_cksum 561 #define rr_seqnum rr_hdr.icmp6_data32[0] 562 563 struct rr_pco_match { /* match prefix part */ 564 u_int8_t rpm_code; 565 u_int8_t rpm_len; 566 u_int8_t rpm_ordinal; 567 u_int8_t rpm_matchlen; 568 u_int8_t rpm_minlen; 569 u_int8_t rpm_maxlen; 570 u_int16_t rpm_reserved; 571 struct in6_addr rpm_prefix; 572 } __attribute__((__packed__)); 573 574 #define RPM_PCO_ADD 1 575 #define RPM_PCO_CHANGE 2 576 #define RPM_PCO_SETGLOBAL 3 577 #define RPM_PCO_MAX 4 578 579 struct rr_pco_use { /* use prefix part */ 580 u_int8_t rpu_uselen; 581 u_int8_t rpu_keeplen; 582 u_int8_t rpu_ramask; 583 u_int8_t rpu_raflags; 584 u_int32_t rpu_vltime; 585 u_int32_t rpu_pltime; 586 u_int32_t rpu_flags; 587 struct in6_addr rpu_prefix; 588 } __attribute__((__packed__)); 589 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80 590 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40 591 592 #if BYTE_ORDER == BIG_ENDIAN 593 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000 594 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000 595 #elif BYTE_ORDER == LITTLE_ENDIAN 596 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80 597 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40 598 #endif 599 600 struct rr_result { /* router renumbering result message */ 601 u_int16_t rrr_flags; 602 u_int8_t rrr_ordinal; 603 u_int8_t rrr_matchedlen; 604 u_int32_t rrr_ifid; 605 struct in6_addr rrr_prefix; 606 } __attribute__((__packed__)); 607 #if BYTE_ORDER == BIG_ENDIAN 608 #define ICMP6_RR_RESULT_FLAGS_OOB 0x0002 609 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001 610 #elif BYTE_ORDER == LITTLE_ENDIAN 611 #define ICMP6_RR_RESULT_FLAGS_OOB 0x0200 612 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100 613 #endif 614 615 /* 616 * icmp6 filter structures. 617 */ 618 619 struct icmp6_filter { 620 u_int32_t icmp6_filt[8]; 621 }; 622 623 #define ICMP6_FILTER_SETPASSALL(filterp) \ 624 memset(filterp, 0xff, sizeof(struct icmp6_filter)) 625 #define ICMP6_FILTER_SETBLOCKALL(filterp) \ 626 memset(filterp, 0x00, sizeof(struct icmp6_filter)) 627 628 #define ICMP6_FILTER_SETPASS(type, filterp) \ 629 (((filterp)->icmp6_filt[(type) >> 5]) |= (1u << ((type) & 31))) 630 #define ICMP6_FILTER_SETBLOCK(type, filterp) \ 631 (((filterp)->icmp6_filt[(type) >> 5]) &= ~(1u << ((type) & 31))) 632 #define ICMP6_FILTER_WILLPASS(type, filterp) \ 633 ((((filterp)->icmp6_filt[(type) >> 5]) & (1u << ((type) & 31))) != 0) 634 #define ICMP6_FILTER_WILLBLOCK(type, filterp) \ 635 ((((filterp)->icmp6_filt[(type) >> 5]) & (1u << ((type) & 31))) == 0) 636 637 /* 638 * Variables related to this implementation 639 * of the internet control message protocol version 6. 640 */ 641 struct icmp6errstat { 642 u_quad_t icp6errs_dst_unreach_noroute; 643 u_quad_t icp6errs_dst_unreach_admin; 644 u_quad_t icp6errs_dst_unreach_beyondscope; 645 u_quad_t icp6errs_dst_unreach_addr; 646 u_quad_t icp6errs_dst_unreach_noport; 647 u_quad_t icp6errs_packet_too_big; 648 u_quad_t icp6errs_time_exceed_transit; 649 u_quad_t icp6errs_time_exceed_reassembly; 650 u_quad_t icp6errs_paramprob_header; 651 u_quad_t icp6errs_paramprob_nextheader; 652 u_quad_t icp6errs_paramprob_option; 653 u_quad_t icp6errs_redirect; /* we regard redirect as an error here */ 654 u_quad_t icp6errs_unknown; 655 }; 656 657 struct icmp6stat { 658 /* statistics related to icmp6 packets generated */ 659 u_quad_t icp6s_error; /* # of calls to icmp6_error */ 660 u_quad_t icp6s_canterror; /* no error 'cuz old was icmp */ 661 u_quad_t icp6s_toofreq; /* no error 'cuz rate limitation */ 662 u_quad_t icp6s_outhist[256]; 663 /* statistics related to input message processed */ 664 u_quad_t icp6s_badcode; /* icmp6_code out of range */ 665 u_quad_t icp6s_tooshort; /* packet < sizeof(struct icmp6_hdr) */ 666 u_quad_t icp6s_checksum; /* bad checksum */ 667 u_quad_t icp6s_badlen; /* calculated bound mismatch */ 668 u_quad_t icp6s_reflect; /* number of responses */ 669 u_quad_t icp6s_inhist[256]; 670 u_quad_t icp6s_nd_toomanyopt; /* too many ND options */ 671 struct icmp6errstat icp6s_outerrhist; 672 #define icp6s_odst_unreach_noroute \ 673 icp6s_outerrhist.icp6errs_dst_unreach_noroute 674 #define icp6s_odst_unreach_admin icp6s_outerrhist.icp6errs_dst_unreach_admin 675 #define icp6s_odst_unreach_beyondscope \ 676 icp6s_outerrhist.icp6errs_dst_unreach_beyondscope 677 #define icp6s_odst_unreach_addr icp6s_outerrhist.icp6errs_dst_unreach_addr 678 #define icp6s_odst_unreach_noport icp6s_outerrhist.icp6errs_dst_unreach_noport 679 #define icp6s_opacket_too_big icp6s_outerrhist.icp6errs_packet_too_big 680 #define icp6s_otime_exceed_transit \ 681 icp6s_outerrhist.icp6errs_time_exceed_transit 682 #define icp6s_otime_exceed_reassembly \ 683 icp6s_outerrhist.icp6errs_time_exceed_reassembly 684 #define icp6s_oparamprob_header icp6s_outerrhist.icp6errs_paramprob_header 685 #define icp6s_oparamprob_nextheader \ 686 icp6s_outerrhist.icp6errs_paramprob_nextheader 687 #define icp6s_oparamprob_option icp6s_outerrhist.icp6errs_paramprob_option 688 #define icp6s_oredirect icp6s_outerrhist.icp6errs_redirect 689 #define icp6s_ounknown icp6s_outerrhist.icp6errs_unknown 690 u_quad_t icp6s_pmtuchg; /* path MTU changes */ 691 u_quad_t icp6s_nd_badopt; /* bad ND options */ 692 u_quad_t icp6s_badns; /* bad neighbor solicitation */ 693 u_quad_t icp6s_badna; /* bad neighbor advertisement */ 694 u_quad_t icp6s_badrs; /* bad router advertisement */ 695 u_quad_t icp6s_badra; /* bad router advertisement */ 696 u_quad_t icp6s_badredirect; /* bad redirect message */ 697 u_quad_t icp6s_rfc6980_drop; /* NDP packet dropped based on RFC 6980 */ 698 u_quad_t icp6s_badpkttoobig; /* bad packet too big */ 699 }; 700 701 /* 702 * Names for ICMP sysctl objects 703 */ 704 #define ICMPV6CTL_STATS 1 705 #define ICMPV6CTL_REDIRACCEPT 2 /* accept/process redirects */ 706 #define ICMPV6CTL_REDIRTIMEOUT 3 /* redirect cache time */ 707 #if 0 /*obsoleted*/ 708 #define ICMPV6CTL_ERRRATELIMIT 5 /* ICMPv6 error rate limitation */ 709 #endif 710 #define ICMPV6CTL_ND6_PRUNE 6 711 #define ICMPV6CTL_ND6_DELAY 8 712 #define ICMPV6CTL_ND6_UMAXTRIES 9 713 #define ICMPV6CTL_ND6_MMAXTRIES 10 714 #define ICMPV6CTL_ND6_USELOOPBACK 11 715 /*#define ICMPV6CTL_ND6_PROXYALL 12 obsoleted, do not reuse here */ 716 #define ICMPV6CTL_NODEINFO 13 717 #define ICMPV6CTL_ERRPPSLIMIT 14 /* ICMPv6 error pps limitation */ 718 #define ICMPV6CTL_ND6_MAXNUDHINT 15 719 #define ICMPV6CTL_MTUDISC_HIWAT 16 720 #define ICMPV6CTL_MTUDISC_LOWAT 17 721 #define ICMPV6CTL_ND6_DEBUG 18 722 #define ICMPV6CTL_ND6_DRLIST 19 723 #define ICMPV6CTL_ND6_PRLIST 20 724 #define ICMPV6CTL_MLD_MAXSRCFILTER 21 725 #define ICMPV6CTL_MLD_SOMAXSRC 22 726 #define ICMPV6CTL_MLD_VERSION 23 727 #define ICMPV6CTL_ND6_MAXQLEN 24 728 #define ICMPV6CTL_ND6_ACCEPT_6TO4 25 729 #define ICMPV6CTL_ND6_OPTIMISTIC_DAD 26 /* RFC 4429 */ 730 #define ICMPV6CTL_ERRPPSLIMIT_RANDOM_INCR 27 731 #define ICMPV6CTL_MAXID 28 732 733 #ifdef BSD_KERNEL_PRIVATE 734 #define ICMPV6CTL_NAMES { \ 735 { 0, 0 }, \ 736 { 0, 0 }, \ 737 { "rediraccept", CTLTYPE_INT }, \ 738 { "redirtimeout", CTLTYPE_INT }, \ 739 { 0, 0 }, \ 740 { 0, 0 }, \ 741 { "nd6_prune", CTLTYPE_INT }, \ 742 { 0, 0 }, \ 743 { "nd6_delay", CTLTYPE_INT }, \ 744 { "nd6_umaxtries", CTLTYPE_INT }, \ 745 { "nd6_mmaxtries", CTLTYPE_INT }, \ 746 { "nd6_useloopback", CTLTYPE_INT }, \ 747 { 0, 0 }, \ 748 { "nodeinfo", CTLTYPE_INT }, \ 749 { "errppslimit", CTLTYPE_INT }, \ 750 { "nd6_maxnudhint", CTLTYPE_INT }, \ 751 { "mtudisc_hiwat", CTLTYPE_INT }, \ 752 { "mtudisc_lowat", CTLTYPE_INT }, \ 753 { "nd6_debug", CTLTYPE_INT }, \ 754 { 0, 0 }, \ 755 { 0, 0 }, \ 756 { 0, 0 }, \ 757 { 0, 0 }, \ 758 { 0, 0 }, \ 759 { 0, 0 }, \ 760 { "nd6_accept_6to4", CTLTYPE_INT }, \ 761 { "nd6_optimistic_dad", CTLTYPE_INT }, \ 762 } 763 764 # ifdef __STDC__ 765 struct rtentry; 766 struct rttimer; 767 struct in6_multi; 768 # endif 769 struct ip6protosw; 770 void icmp6_init(struct ip6protosw *, struct domain *); 771 void icmp6_paramerror(struct mbuf *, int); 772 773 void icmp6_error_flag(struct mbuf *, int, int, int, int); 774 #define ICMP6_ERROR_RST_MRCVIF 0x1 775 776 void icmp6_error(struct mbuf *, int, int, int); 777 int icmp6_input(struct mbuf **, int *, int); 778 void icmp6_reflect(struct mbuf *, size_t); 779 void icmp6_prepare(struct mbuf *); 780 void icmp6_redirect_input(struct mbuf *, int, int); 781 void icmp6_redirect_output(struct mbuf *, struct rtentry *); 782 783 struct ip6ctlparam; 784 void icmp6_mtudisc_update(struct ip6ctlparam *, int); 785 786 extern lck_rw_t icmp6_ifs_rwlock; 787 /* XXX: is this the right place for these macros? */ 788 /* N.B.: if_inet6data is never freed once set, so we don't need to lock */ 789 #define icmp6_ifstat_inc(_ifp, _tag) do { \ 790 if (_ifp != NULL && IN6_IFEXTRA(_ifp) != NULL) { \ 791 IN6_IFEXTRA(_ifp)->icmp6_ifstat._tag++; \ 792 } \ 793 } while (0) 794 795 #define icmp6_ifoutstat_inc(ifp, type, code) do { \ 796 icmp6_ifstat_inc(ifp, ifs6_out_msg); \ 797 if (type < ICMP6_INFOMSG_MASK) \ 798 icmp6_ifstat_inc(ifp, ifs6_out_error); \ 799 switch (type) { \ 800 case ICMP6_DST_UNREACH: \ 801 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \ 802 if (code == ICMP6_DST_UNREACH_ADMIN) \ 803 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib);\ 804 break; \ 805 case ICMP6_PACKET_TOO_BIG: \ 806 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \ 807 break; \ 808 case ICMP6_TIME_EXCEEDED: \ 809 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \ 810 break; \ 811 case ICMP6_PARAM_PROB: \ 812 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \ 813 break; \ 814 case ICMP6_ECHO_REQUEST: \ 815 icmp6_ifstat_inc(ifp, ifs6_out_echo); \ 816 break; \ 817 case ICMP6_ECHO_REPLY: \ 818 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \ 819 break; \ 820 case MLD_LISTENER_QUERY: \ 821 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \ 822 break; \ 823 case MLD_LISTENER_REPORT: \ 824 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \ 825 break; \ 826 case MLD_LISTENER_DONE: \ 827 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \ 828 break; \ 829 case ND_ROUTER_SOLICIT: \ 830 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \ 831 break; \ 832 case ND_ROUTER_ADVERT: \ 833 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \ 834 break; \ 835 case ND_NEIGHBOR_SOLICIT: \ 836 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit);\ 837 break; \ 838 case ND_NEIGHBOR_ADVERT: \ 839 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \ 840 break; \ 841 case ND_REDIRECT: \ 842 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \ 843 break; \ 844 } \ 845 } while (0) 846 847 #define ICMP6_REDIRACCEPT_DEFAULT 1 848 extern int icmp6_rediraccept; /* accept/process redirects */ 849 extern int icmp6_redirtimeout; /* cache time for redirect routes */ 850 851 #define ICMP6_NODEINFO_FQDNOK 0x1 852 #define ICMP6_NODEINFO_NODEADDROK 0x2 853 #define ICMP6_NODEINFO_TMPADDROK 0x4 854 #define ICMP6_NODEINFO_GLOBALOK 0x8 855 856 #endif /* BSD_KERNEL_PRIVATE */ 857 858 #endif /* !_NETINET_ICMP6_H_ */ 859