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