| 1 | /* |
| 2 | * Copyright (c) 2000-2017 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 | /* |
| 29 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
| 30 | * All rights reserved. |
| 31 | * |
| 32 | * Redistribution and use in source and binary forms, with or without |
| 33 | * modification, are permitted provided that the following conditions |
| 34 | * are met: |
| 35 | * 1. Redistributions of source code must retain the above copyright |
| 36 | * notice, this list of conditions and the following disclaimer. |
| 37 | * 2. Redistributions in binary form must reproduce the above copyright |
| 38 | * notice, this list of conditions and the following disclaimer in the |
| 39 | * documentation and/or other materials provided with the distribution. |
| 40 | * 3. Neither the name of the project nor the names of its contributors |
| 41 | * may be used to endorse or promote products derived from this software |
| 42 | * without specific prior written permission. |
| 43 | * |
| 44 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
| 45 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 46 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 47 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
| 48 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 49 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 50 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 51 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 52 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 53 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 54 | * SUCH DAMAGE. |
| 55 | */ |
| 56 | |
| 57 | #ifndef _NETINET6_ND6_H_ |
| 58 | #define _NETINET6_ND6_H_ |
| 59 | #include <sys/appleapiopts.h> |
| 60 | #include <net/net_kev.h> |
| 61 | |
| 62 | /* see net/route.h, or net/if_inarp.h */ |
| 63 | #ifndef RTF_ANNOUNCE |
| 64 | #define RTF_ANNOUNCE RTF_PROTO2 |
| 65 | #endif |
| 66 | |
| 67 | #include <sys/queue.h> |
| 68 | |
| 69 | #ifdef BSD_KERNEL_PRIVATE |
| 70 | #include <net/flowadv.h> |
| 71 | #include <kern/locks.h> |
| 72 | #include <sys/tree.h> |
| 73 | #include <sys/eventhandler.h> |
| 74 | #include <netinet6/nd6_var.h> |
| 75 | |
| 76 | struct llinfo_nd6 { |
| 77 | /* |
| 78 | * The following are protected by rnh_lock |
| 79 | */ |
| 80 | struct llinfo_nd6 *ln_next; |
| 81 | struct llinfo_nd6 *ln_prev; |
| 82 | struct rtentry *ln_rt; |
| 83 | /* |
| 84 | * The following are protected by rt_lock |
| 85 | */ |
| 86 | struct ifnet *ln_exclifp; /* excluded interface (prefix proxy) */ |
| 87 | struct mbuf *ln_hold; /* last packet until resolved/timeout */ |
| 88 | uint32_t ln_asked; /* # of queries already sent for this addr */ |
| 89 | short ln_state; /* reachability state */ |
| 90 | short ln_router; /* 2^0: ND6 router bit */ |
| 91 | u_int32_t ln_flags; /* flags; see below */ |
| 92 | u_int64_t ln_expire; /* lifetime for NDP state transition */ |
| 93 | u_int64_t ln_lastused; /* last used timestamp */ |
| 94 | struct if_llreach *ln_llreach; /* link-layer reachability record */ |
| 95 | }; |
| 96 | |
| 97 | /* Values for ln_flags */ |
| 98 | #define ND6_LNF_TIMER_SKIP 0x1 /* modified by nd6_timer() */ |
| 99 | #define ND6_LNF_IN_USE 0x2 /* currently in llinfo_nd6 list */ |
| 100 | #endif /* BSD_KERNEL_PRIVATE */ |
| 101 | |
| 102 | #define ND6_LLINFO_PURGE -3 |
| 103 | #define ND6_LLINFO_NOSTATE -2 |
| 104 | /* |
| 105 | * We don't need the WAITDELETE state any more, but we keep the definition |
| 106 | * in a comment line instead of removing it. This is necessary to avoid |
| 107 | * unintentionally reusing the value for another purpose, which might |
| 108 | * affect backward compatibility with old applications. |
| 109 | * (20000711 jinmei@kame.net) |
| 110 | */ |
| 111 | /* #define ND6_LLINFO_WAITDELETE -1 */ |
| 112 | #define ND6_LLINFO_INCOMPLETE 0 |
| 113 | #define ND6_LLINFO_REACHABLE 1 |
| 114 | #define ND6_LLINFO_STALE 2 |
| 115 | #define ND6_LLINFO_DELAY 3 |
| 116 | #define ND6_LLINFO_PROBE 4 |
| 117 | |
| 118 | #ifdef BSD_KERNEL_PRIVATE |
| 119 | |
| 120 | #define ND6_CACHE_STATE_TRANSITION(ln, nstate) do {\ |
| 121 | struct rtentry *ln_rt = (ln)->ln_rt; \ |
| 122 | if (nd6_debug >= 1) {\ |
| 123 | nd6log((LOG_INFO,\ |
| 124 | "[%s:%d]: NDP cache entry changed from %s -> %s",\ |
| 125 | __func__,\ |
| 126 | __LINE__,\ |
| 127 | ndcache_state2str((ln)->ln_state),\ |
| 128 | ndcache_state2str(nstate)));\ |
| 129 | if (ln_rt != NULL)\ |
| 130 | nd6log((LOG_INFO,\ |
| 131 | " for address: %s.\n",\ |
| 132 | ip6_sprintf(&SIN6(rt_key(ln_rt))->sin6_addr)));\ |
| 133 | else\ |
| 134 | nd6log((LOG_INFO, "\n"));\ |
| 135 | }\ |
| 136 | (ln)->ln_state = nstate;\ |
| 137 | } while(0) |
| 138 | |
| 139 | #define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE) |
| 140 | #define ND6_LLINFO_PERMANENT(n) \ |
| 141 | (((n)->ln_expire == 0) && ((n)->ln_state > ND6_LLINFO_INCOMPLETE)) |
| 142 | |
| 143 | #define ND6_EUI64_GBIT 0x01 |
| 144 | #define ND6_EUI64_UBIT 0x02 |
| 145 | |
| 146 | #define ND6_EUI64_TO_IFID(in6) \ |
| 147 | do {(in6)->s6_addr[8] ^= ND6_EUI64_UBIT; } while (0) |
| 148 | |
| 149 | #define ND6_EUI64_GROUP(in6) ((in6)->s6_addr[8] & ND6_EUI64_GBIT) |
| 150 | #define ND6_EUI64_INDIVIDUAL(in6) (!ND6_EUI64_GROUP(in6)) |
| 151 | #define ND6_EUI64_LOCAL(in6) ((in6)->s6_addr[8] & ND6_EUI64_UBIT) |
| 152 | #define ND6_EUI64_UNIVERSAL(in6) (!ND6_EUI64_LOCAL(in6)) |
| 153 | #define ND6_IFID_LOCAL(in6) (!ND6_EUI64_LOCAL(in6)) |
| 154 | #define ND6_IFID_UNIVERSAL(in6) (!ND6_EUI64_UNIVERSAL(in6)) |
| 155 | #endif /* BSD_KERNEL_PRIVATE */ |
| 156 | |
| 157 | #if !defined(BSD_KERNEL_PRIVATE) |
| 158 | struct nd_ifinfo { |
| 159 | #else |
| 160 | /* For binary compatibility, this structure must not change */ |
| 161 | /* NOTE: nd_ifinfo is defined in nd6_var.h */ |
| 162 | struct nd_ifinfo_compat { |
| 163 | #endif /* !BSD_KERNEL_PRIVATE */ |
| 164 | u_int32_t linkmtu; /* LinkMTU */ |
| 165 | u_int32_t maxmtu; /* Upper bound of LinkMTU */ |
| 166 | u_int32_t basereachable; /* BaseReachableTime */ |
| 167 | u_int32_t reachable; /* Reachable Time */ |
| 168 | u_int32_t retrans; /* Retrans Timer */ |
| 169 | u_int32_t flags; /* Flags */ |
| 170 | int recalctm; /* BaseReacable re-calculation timer */ |
| 171 | u_int8_t chlim; /* CurHopLimit */ |
| 172 | u_int8_t receivedra; |
| 173 | /* the following 3 members are for privacy extension for addrconf */ |
| 174 | u_int8_t randomseed0[8]; /* upper 64 bits of SHA1 digest */ |
| 175 | u_int8_t randomseed1[8]; /* lower 64 bits (usually the EUI64 IFID) */ |
| 176 | u_int8_t randomid[8]; /* current random ID */ |
| 177 | }; |
| 178 | |
| 179 | #define ND6_IFF_PERFORMNUD 0x1 |
| 180 | #if defined(PRIVATE) |
| 181 | |
| 182 | /* |
| 183 | * APPLE: not used. Interface specific router advertisements are handled with a |
| 184 | * specific ifnet flag: IFEF_ACCEPT_RTADVD |
| 185 | */ |
| 186 | #define ND6_IFF_ACCEPT_RTADV 0x2 |
| 187 | |
| 188 | /* APPLE: NOT USED not related to ND. */ |
| 189 | #define ND6_IFF_PREFER_SOURCE 0x4 |
| 190 | |
| 191 | /* IPv6 operation is disabled due to * DAD failure. (XXX: not ND-specific) */ |
| 192 | #define ND6_IFF_IFDISABLED 0x8 |
| 193 | |
| 194 | #define ND6_IFF_DONT_SET_IFROUTE 0x10 /* NOT USED */ |
| 195 | #endif /* PRIVATE */ |
| 196 | #define ND6_IFF_PROXY_PREFIXES 0x20 |
| 197 | #define ND6_IFF_IGNORE_NA 0x40 |
| 198 | #if defined(PRIVATE) |
| 199 | #define ND6_IFF_INSECURE 0x80 |
| 200 | #endif |
| 201 | #define ND6_IFF_REPLICATED 0x100 /* sleep proxy registered */ |
| 202 | #define ND6_IFF_DAD 0x200 /* Perform DAD on the interface */ |
| 203 | |
| 204 | struct in6_nbrinfo { |
| 205 | char ifname[IFNAMSIZ]; /* if name, e.g. "en0" */ |
| 206 | struct in6_addr addr; /* IPv6 address of the neighbor */ |
| 207 | long asked; /* # of queries already sent for this addr */ |
| 208 | int isrouter; /* if it acts as a router */ |
| 209 | int state; /* reachability state */ |
| 210 | int expire; /* lifetime for NDP state transition */ |
| 211 | }; |
| 212 | |
| 213 | #if defined(BSD_KERNEL_PRIVATE) |
| 214 | struct in6_nbrinfo_32 { |
| 215 | char ifname[IFNAMSIZ]; |
| 216 | struct in6_addr addr; |
| 217 | u_int32_t asked; |
| 218 | int isrouter; |
| 219 | int state; |
| 220 | int expire; |
| 221 | }; |
| 222 | |
| 223 | struct in6_nbrinfo_64 { |
| 224 | char ifname[IFNAMSIZ]; |
| 225 | struct in6_addr addr; |
| 226 | long asked; |
| 227 | int isrouter __attribute__((aligned(8))); |
| 228 | int state; |
| 229 | int expire; |
| 230 | } __attribute__((aligned(8))); |
| 231 | #endif /* BSD_KERNEL_PRIVATE */ |
| 232 | |
| 233 | #define DRLSTSIZ 10 |
| 234 | #define PRLSTSIZ 10 |
| 235 | |
| 236 | struct in6_drlist { |
| 237 | char ifname[IFNAMSIZ]; |
| 238 | struct { |
| 239 | struct in6_addr rtaddr; |
| 240 | u_char flags; |
| 241 | u_short rtlifetime; |
| 242 | u_long expire; |
| 243 | u_short if_index; |
| 244 | } defrouter[DRLSTSIZ]; |
| 245 | }; |
| 246 | |
| 247 | #if defined(BSD_KERNEL_PRIVATE) |
| 248 | struct in6_drlist_32 { |
| 249 | char ifname[IFNAMSIZ]; |
| 250 | struct { |
| 251 | struct in6_addr rtaddr; |
| 252 | u_char flags; |
| 253 | u_short rtlifetime; |
| 254 | u_int32_t expire; |
| 255 | u_short if_index; |
| 256 | } defrouter[DRLSTSIZ]; |
| 257 | }; |
| 258 | |
| 259 | struct in6_drlist_64 { |
| 260 | char ifname[IFNAMSIZ]; |
| 261 | struct { |
| 262 | struct in6_addr rtaddr; |
| 263 | u_char flags; |
| 264 | u_short rtlifetime; |
| 265 | u_long expire __attribute__((aligned(8))); |
| 266 | u_short if_index __attribute__((aligned(8))); |
| 267 | } defrouter[DRLSTSIZ] __attribute__((aligned(8))); |
| 268 | }; |
| 269 | #endif /* BSD_KERNEL_PRIVATE */ |
| 270 | |
| 271 | /* valid values for stateflags */ |
| 272 | #define NDDRF_INSTALLED 0x1 /* installed in the routing table */ |
| 273 | #define NDDRF_IFSCOPE 0x2 /* installed as a scoped route */ |
| 274 | #define NDDRF_STATIC 0x4 /* for internal use only */ |
| 275 | #define NDDRF_MAPPED 0x8 /* Default router addr is mapped to a different one for routing */ |
| 276 | |
| 277 | struct in6_defrouter { |
| 278 | struct sockaddr_in6 rtaddr; |
| 279 | u_char flags; |
| 280 | u_char stateflags; |
| 281 | u_short rtlifetime; |
| 282 | u_long expire; |
| 283 | u_short if_index; |
| 284 | }; |
| 285 | |
| 286 | #if defined(BSD_KERNEL_PRIVATE) |
| 287 | struct in6_defrouter_32 { |
| 288 | struct sockaddr_in6 rtaddr; |
| 289 | u_char flags; |
| 290 | u_char stateflags; |
| 291 | u_short rtlifetime; |
| 292 | u_int32_t expire; |
| 293 | u_short if_index; |
| 294 | }; |
| 295 | |
| 296 | struct in6_defrouter_64 { |
| 297 | struct sockaddr_in6 rtaddr; |
| 298 | u_char flags; |
| 299 | u_char stateflags; |
| 300 | u_short rtlifetime; |
| 301 | u_long expire __attribute__((aligned(8))); |
| 302 | u_short if_index __attribute__((aligned(8))); |
| 303 | } __attribute__((aligned(8))); |
| 304 | #endif /* BSD_KERNEL_PRIVATE */ |
| 305 | |
| 306 | struct in6_prlist { |
| 307 | char ifname[IFNAMSIZ]; |
| 308 | struct { |
| 309 | struct in6_addr prefix; |
| 310 | struct prf_ra raflags; |
| 311 | u_char prefixlen; |
| 312 | u_char origin; |
| 313 | u_long vltime; |
| 314 | u_long pltime; |
| 315 | u_long expire; |
| 316 | u_short if_index; |
| 317 | u_short advrtrs; /* number of advertisement routers */ |
| 318 | struct in6_addr advrtr[DRLSTSIZ]; /* XXX: explicit limit */ |
| 319 | } prefix[PRLSTSIZ]; |
| 320 | }; |
| 321 | |
| 322 | #if defined(BSD_KERNEL_PRIVATE) |
| 323 | struct in6_prlist_32 { |
| 324 | char ifname[IFNAMSIZ]; |
| 325 | struct { |
| 326 | struct in6_addr prefix; |
| 327 | struct prf_ra raflags; |
| 328 | u_char prefixlen; |
| 329 | u_char origin; |
| 330 | u_int32_t vltime; |
| 331 | u_int32_t pltime; |
| 332 | u_int32_t expire; |
| 333 | u_short if_index; |
| 334 | u_short advrtrs; |
| 335 | struct in6_addr advrtr[DRLSTSIZ]; |
| 336 | } prefix[PRLSTSIZ]; |
| 337 | }; |
| 338 | |
| 339 | struct in6_prlist_64 { |
| 340 | char ifname[IFNAMSIZ]; |
| 341 | struct { |
| 342 | struct in6_addr prefix; |
| 343 | struct prf_ra raflags; |
| 344 | u_char prefixlen; |
| 345 | u_char origin; |
| 346 | u_long vltime __attribute__((aligned(8))); |
| 347 | u_long pltime __attribute__((aligned(8))); |
| 348 | u_long expire __attribute__((aligned(8))); |
| 349 | u_short if_index; |
| 350 | u_short advrtrs; |
| 351 | u_int32_t pad; |
| 352 | struct in6_addr advrtr[DRLSTSIZ]; |
| 353 | } prefix[PRLSTSIZ]; |
| 354 | }; |
| 355 | #endif /* BSD_KERNEL_PRIVATE */ |
| 356 | |
| 357 | struct in6_prefix { |
| 358 | struct sockaddr_in6 prefix; |
| 359 | struct prf_ra raflags; |
| 360 | u_char prefixlen; |
| 361 | u_char origin; |
| 362 | u_long vltime; |
| 363 | u_long pltime; |
| 364 | u_long expire; |
| 365 | u_int32_t flags; |
| 366 | int refcnt; |
| 367 | u_short if_index; |
| 368 | u_short advrtrs; /* number of advertisement routers */ |
| 369 | /* struct sockaddr_in6 advrtr[] */ |
| 370 | }; |
| 371 | |
| 372 | #if defined(BSD_KERNEL_PRIVATE) |
| 373 | struct in6_prefix_32 { |
| 374 | struct sockaddr_in6 prefix; |
| 375 | struct prf_ra raflags; |
| 376 | u_char prefixlen; |
| 377 | u_char origin; |
| 378 | u_int32_t vltime; |
| 379 | u_int32_t pltime; |
| 380 | u_int32_t expire; |
| 381 | u_int32_t flags; |
| 382 | int refcnt; |
| 383 | u_short if_index; |
| 384 | u_short advrtrs; /* number of advertisement routers */ |
| 385 | /* struct sockaddr_in6 advrtr[] */ |
| 386 | }; |
| 387 | |
| 388 | struct in6_prefix_64 { |
| 389 | struct sockaddr_in6 prefix; |
| 390 | struct prf_ra raflags; |
| 391 | u_char prefixlen; |
| 392 | u_char origin; |
| 393 | u_long vltime __attribute__((aligned(8))); |
| 394 | u_long pltime __attribute__((aligned(8))); |
| 395 | u_long expire __attribute__((aligned(8))); |
| 396 | u_int32_t flags __attribute__((aligned(8))); |
| 397 | int refcnt; |
| 398 | u_short if_index; |
| 399 | u_short advrtrs; |
| 400 | /* struct sockaddr_in6 advrtr[] */ |
| 401 | }; |
| 402 | #endif /* BSD_KERNEL_PRIVATE */ |
| 403 | |
| 404 | struct in6_ondireq { |
| 405 | char ifname[IFNAMSIZ]; |
| 406 | struct { |
| 407 | u_int32_t linkmtu; /* LinkMTU */ |
| 408 | u_int32_t maxmtu; /* Upper bound of LinkMTU */ |
| 409 | u_int32_t basereachable; /* BaseReachableTime */ |
| 410 | u_int32_t reachable; /* Reachable Time */ |
| 411 | u_int32_t retrans; /* Retrans Timer */ |
| 412 | u_int32_t flags; /* Flags */ |
| 413 | int recalctm; /* BaseReacable re-calculation timer */ |
| 414 | u_int8_t chlim; /* CurHopLimit */ |
| 415 | u_int8_t receivedra; |
| 416 | } ndi; |
| 417 | }; |
| 418 | |
| 419 | #if !defined(BSD_KERNEL_PRIVATE) |
| 420 | struct in6_ndireq { |
| 421 | char ifname[IFNAMSIZ]; |
| 422 | struct nd_ifinfo ndi; |
| 423 | }; |
| 424 | #else |
| 425 | struct in6_ndireq { |
| 426 | char ifname[IFNAMSIZ]; |
| 427 | struct nd_ifinfo_compat ndi; |
| 428 | }; |
| 429 | #endif /* !BSD_KERNEL_PRIVATE */ |
| 430 | |
| 431 | struct in6_ndifreq { |
| 432 | char ifname[IFNAMSIZ]; |
| 433 | u_long ifindex; |
| 434 | }; |
| 435 | |
| 436 | #define MAX_RTR_SOLICITATION_DELAY 1 /* 1sec */ |
| 437 | #define RTR_SOLICITATION_INTERVAL 4 /* 4sec */ |
| 438 | |
| 439 | #if defined(BSD_KERNEL_PRIVATE) |
| 440 | struct in6_ndifreq_32 { |
| 441 | char ifname[IFNAMSIZ]; |
| 442 | u_int32_t ifindex; |
| 443 | }; |
| 444 | |
| 445 | struct in6_ndifreq_64 { |
| 446 | char ifname[IFNAMSIZ]; |
| 447 | u_long ifindex __attribute__((aligned(8))); |
| 448 | }; |
| 449 | #endif /* BSD_KERNEL_PRIVATE */ |
| 450 | |
| 451 | /* Prefix status */ |
| 452 | #define NDPRF_ONLINK 0x1 |
| 453 | #define NDPRF_DETACHED 0x2 |
| 454 | #define NDPRF_STATIC 0x100 |
| 455 | #define NDPRF_IFSCOPE 0x1000 |
| 456 | #define NDPRF_PRPROXY 0x2000 |
| 457 | #ifdef BSD_KERNEL_PRIVATE |
| 458 | #define NDPRF_PROCESSED_ONLINK 0x08000 |
| 459 | #define NDPRF_PROCESSED_SERVICE 0x10000 |
| 460 | #define NDPRF_DEFUNCT 0x20000 |
| 461 | #define NDPRF_CLAT46 0x40000 |
| 462 | #endif |
| 463 | |
| 464 | /* protocol constants */ |
| 465 | #define MAX_RTR_SOLICITATION_DELAY 1 /* 1sec */ |
| 466 | #define RTR_SOLICITATION_INTERVAL 4 /* 4sec */ |
| 467 | #define MAX_RTR_SOLICITATIONS 3 |
| 468 | |
| 469 | #define ND6_INFINITE_LIFETIME 0xffffffff |
| 470 | #define ND6_MAX_LIFETIME 0x7fffffff |
| 471 | |
| 472 | #ifdef BSD_KERNEL_PRIVATE |
| 473 | #define ND_IFINFO(ifp) \ |
| 474 | ((ifp == NULL) ? NULL : \ |
| 475 | ((IN6_IFEXTRA(ifp) == NULL) ? NULL : \ |
| 476 | (&IN6_IFEXTRA(ifp)->nd_ifinfo))) |
| 477 | |
| 478 | /* |
| 479 | * In a more readable form, we derive linkmtu based on: |
| 480 | * |
| 481 | * if (ifp == NULL) |
| 482 | * linkmtu = IPV6_MMTU |
| 483 | * else if (ND_IFINFO(ifp) == NULL || !ND_IFINFO(ifp)->initialized) |
| 484 | * linkmtu = ifp->if_mtu; |
| 485 | * else if (ND_IFINFO(ifp)->linkmtu && ND_IFINFO(ifp)->linkmtu < ifp->if_mtu) |
| 486 | * linkmtu = ND_IFINFO(ifp)->linkmtu; |
| 487 | * else if ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < ifp->if_mtu)) |
| 488 | * linkmtu = ND_IFINFO(ifp)->maxmtu; |
| 489 | * else |
| 490 | * linkmtu = ifp->if_mtu; |
| 491 | */ |
| 492 | #define IN6_LINKMTU(ifp) \ |
| 493 | (ifp == NULL ? IPV6_MMTU : \ |
| 494 | (ND_IFINFO(ifp) == NULL || !ND_IFINFO(ifp)->initialized) ? \ |
| 495 | (ifp)->if_mtu : ((ND_IFINFO(ifp)->linkmtu && \ |
| 496 | ND_IFINFO(ifp)->linkmtu < (ifp)->if_mtu) ? ND_IFINFO(ifp)->linkmtu : \ |
| 497 | ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < (ifp)->if_mtu) ? \ |
| 498 | ND_IFINFO(ifp)->maxmtu : (ifp)->if_mtu))) |
| 499 | |
| 500 | /* node constants */ |
| 501 | #define MAX_REACHABLE_TIME 3600000 /* msec */ |
| 502 | #define REACHABLE_TIME 30000 /* msec */ |
| 503 | #define RETRANS_TIMER 1000 /* msec */ |
| 504 | #define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */ |
| 505 | #define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */ |
| 506 | #define DEF_TEMP_VALID_LIFETIME 604800 /* 1 week */ |
| 507 | #define DEF_TEMP_PREFERRED_LIFETIME 86400 /* 1 day */ |
| 508 | #define TEMPADDR_REGEN_ADVANCE 5 /* sec */ |
| 509 | #define MAX_TEMP_DESYNC_FACTOR 600 /* 10 min */ |
| 510 | #define ND_COMPUTE_RTIME(x) \ |
| 511 | (((MIN_RANDOM_FACTOR * (x >> 10)) + (RandomULong() & \ |
| 512 | ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000) |
| 513 | |
| 514 | /* prefix expiry times */ |
| 515 | #define ND6_PREFIX_EXPIRY_UNSPEC -1 |
| 516 | #define ND6_PREFIX_EXPIRY_NEVER 0 |
| 517 | |
| 518 | TAILQ_HEAD(nd_drhead, nd_defrouter); |
| 519 | struct nd_defrouter { |
| 520 | decl_lck_mtx_data(, nddr_lock); |
| 521 | TAILQ_ENTRY(nd_defrouter) dr_entry; |
| 522 | struct in6_addr rtaddr; |
| 523 | u_int32_t nddr_refcount; |
| 524 | u_int32_t nddr_debug; |
| 525 | u_int64_t expire; |
| 526 | u_int64_t base_calendartime; /* calendar time at creation */ |
| 527 | u_int64_t base_uptime; /* uptime at creation */ |
| 528 | u_char flags; /* flags on RA message */ |
| 529 | u_char stateflags; |
| 530 | u_short rtlifetime; |
| 531 | int err; |
| 532 | struct ifnet *ifp; |
| 533 | struct in6_addr rtaddr_mapped; /* Mapped gateway address for routing */ |
| 534 | void (*nddr_trace)(struct nd_defrouter *, int); /* trace callback fn */ |
| 535 | }; |
| 536 | |
| 537 | #define NDDR_LOCK_ASSERT_HELD(_nddr) \ |
| 538 | LCK_MTX_ASSERT(&(_nddr)->nddr_lock, LCK_MTX_ASSERT_OWNED) |
| 539 | |
| 540 | #define NDDR_LOCK_ASSERT_NOTHELD(_nddr) \ |
| 541 | LCK_MTX_ASSERT(&(_nddr)->nddr_lock, LCK_MTX_ASSERT_NOTOWNED) |
| 542 | |
| 543 | #define NDDR_LOCK(_nddr) \ |
| 544 | lck_mtx_lock(&(_nddr)->nddr_lock) |
| 545 | |
| 546 | #define NDDR_LOCK_SPIN(_nddr) \ |
| 547 | lck_mtx_lock_spin(&(_nddr)->nddr_lock) |
| 548 | |
| 549 | #define NDDR_CONVERT_LOCK(_nddr) do { \ |
| 550 | NDPR_LOCK_ASSERT_HELD(_nddr); \ |
| 551 | lck_mtx_convert_spin(&(_nddr)->nddr_lock); \ |
| 552 | } while (0) |
| 553 | |
| 554 | #define NDDR_UNLOCK(_nddr) \ |
| 555 | lck_mtx_unlock(&(_nddr)->nddr_lock) |
| 556 | |
| 557 | #define NDDR_ADDREF(_nddr) \ |
| 558 | nddr_addref(_nddr, 0) |
| 559 | |
| 560 | #define NDDR_ADDREF_LOCKED(_nddr) \ |
| 561 | nddr_addref(_nddr, 1) |
| 562 | |
| 563 | #define NDDR_REMREF(_nddr) do { \ |
| 564 | (void) nddr_remref(_nddr, 0); \ |
| 565 | } while (0) |
| 566 | |
| 567 | #define NDDR_REMREF_LOCKED(_nddr) \ |
| 568 | nddr_remref(_nddr, 1) |
| 569 | |
| 570 | /* define struct prproxy_sols_tree */ |
| 571 | RB_HEAD(prproxy_sols_tree, nd6_prproxy_soltgt); |
| 572 | |
| 573 | struct nd_prefix { |
| 574 | decl_lck_mtx_data(, ndpr_lock); |
| 575 | u_int32_t ndpr_refcount; /* reference count */ |
| 576 | u_int32_t ndpr_debug; /* see ifa_debug flags */ |
| 577 | struct ifnet *ndpr_ifp; |
| 578 | struct rtentry *ndpr_rt; |
| 579 | LIST_ENTRY(nd_prefix) ndpr_entry; |
| 580 | struct sockaddr_in6 ndpr_prefix; /* prefix */ |
| 581 | struct in6_addr ndpr_mask; /* netmask derived from the prefix */ |
| 582 | struct in6_addr ndpr_addr; /* address that is derived from the prefix */ |
| 583 | u_int32_t ndpr_vltime; /* advertised valid lifetime */ |
| 584 | u_int32_t ndpr_pltime; /* advertised preferred lifetime */ |
| 585 | u_int64_t ndpr_preferred; /* preferred time of the prefix */ |
| 586 | u_int64_t ndpr_expire; /* expiration time of the prefix */ |
| 587 | u_int64_t ndpr_lastupdate; /* rx time of last advertisement */ |
| 588 | u_int64_t ndpr_base_calendartime; /* calendar time at creation */ |
| 589 | u_int64_t ndpr_base_uptime; /* uptime at creation */ |
| 590 | struct prf_ra ndpr_flags; |
| 591 | unsigned int ndpr_genid; /* protects ndpr_advrtrs */ |
| 592 | u_int32_t ndpr_stateflags; /* actual state flags */ |
| 593 | /* list of routers that advertise the prefix: */ |
| 594 | LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs; |
| 595 | u_char ndpr_plen; |
| 596 | int ndpr_addrcnt; /* reference counter from addresses */ |
| 597 | u_int32_t ndpr_allmulti_cnt; /* total all-multi reqs */ |
| 598 | u_int32_t ndpr_prproxy_sols_cnt; /* total # of proxied NS */ |
| 599 | struct prproxy_sols_tree ndpr_prproxy_sols; /* tree of proxied NS */ |
| 600 | void (*ndpr_trace)(struct nd_prefix *, int); /* trace callback fn */ |
| 601 | }; |
| 602 | |
| 603 | #define ndpr_next ndpr_entry.le_next |
| 604 | |
| 605 | #define ndpr_raf ndpr_flags |
| 606 | #define ndpr_raf_onlink ndpr_flags.onlink |
| 607 | #define ndpr_raf_auto ndpr_flags.autonomous |
| 608 | #define ndpr_raf_router ndpr_flags.router |
| 609 | /* |
| 610 | * We keep expired prefix for certain amount of time, for validation purposes. |
| 611 | * 1800s = MaxRtrAdvInterval |
| 612 | */ |
| 613 | #define NDPR_KEEP_EXPIRED (1800 * 2) |
| 614 | |
| 615 | #define NDPR_LOCK_ASSERT_HELD(_ndpr) \ |
| 616 | LCK_MTX_ASSERT(&(_ndpr)->ndpr_lock, LCK_MTX_ASSERT_OWNED) |
| 617 | |
| 618 | #define NDPR_LOCK_ASSERT_NOTHELD(_ndpr) \ |
| 619 | LCK_MTX_ASSERT(&(_ndpr)->ndpr_lock, LCK_MTX_ASSERT_NOTOWNED) |
| 620 | |
| 621 | #define NDPR_LOCK(_ndpr) \ |
| 622 | lck_mtx_lock(&(_ndpr)->ndpr_lock) |
| 623 | |
| 624 | #define NDPR_LOCK_SPIN(_ndpr) \ |
| 625 | lck_mtx_lock_spin(&(_ndpr)->ndpr_lock) |
| 626 | |
| 627 | #define NDPR_CONVERT_LOCK(_ndpr) do { \ |
| 628 | NDPR_LOCK_ASSERT_HELD(_ndpr); \ |
| 629 | lck_mtx_convert_spin(&(_ndpr)->ndpr_lock); \ |
| 630 | } while (0) |
| 631 | |
| 632 | #define NDPR_UNLOCK(_ndpr) \ |
| 633 | lck_mtx_unlock(&(_ndpr)->ndpr_lock) |
| 634 | |
| 635 | #define NDPR_ADDREF(_ndpr) \ |
| 636 | ndpr_addref(_ndpr, 0) |
| 637 | |
| 638 | #define NDPR_ADDREF_LOCKED(_ndpr) \ |
| 639 | ndpr_addref(_ndpr, 1) |
| 640 | |
| 641 | #define NDPR_REMREF(_ndpr) do { \ |
| 642 | (void) ndpr_remref(_ndpr, 0); \ |
| 643 | } while (0) |
| 644 | |
| 645 | #define NDPR_REMREF_LOCKED(_ndpr) \ |
| 646 | ndpr_remref(_ndpr, 1) |
| 647 | |
| 648 | /* |
| 649 | * Message format for use in obtaining information about prefixes |
| 650 | * from inet6 sysctl function |
| 651 | */ |
| 652 | struct inet6_ndpr_msghdr { |
| 653 | u_short inpm_msglen; /* to skip over non-understood messages */ |
| 654 | u_char inpm_version; /* future binary compatibility */ |
| 655 | u_char inpm_type; /* message type */ |
| 656 | struct in6_addr inpm_prefix; |
| 657 | u_int32_t prm_vltim; |
| 658 | u_int32_t prm_pltime; |
| 659 | u_int32_t prm_expire; |
| 660 | u_int32_t prm_preferred; |
| 661 | struct in6_prflags prm_flags; |
| 662 | u_short prm_index; /* index for associated ifp */ |
| 663 | u_char prm_plen; /* length of prefix in bits */ |
| 664 | }; |
| 665 | |
| 666 | #define prm_raf_onlink prm_flags.prf_ra.onlink |
| 667 | #define prm_raf_auto prm_flags.prf_ra.autonomous |
| 668 | |
| 669 | #define prm_statef_onlink prm_flags.prf_state.onlink |
| 670 | |
| 671 | #define prm_rrf_decrvalid prm_flags.prf_rr.decrvalid |
| 672 | #define prm_rrf_decrprefd prm_flags.prf_rr.decrprefd |
| 673 | |
| 674 | struct nd_pfxrouter { |
| 675 | LIST_ENTRY(nd_pfxrouter) pfr_entry; |
| 676 | #define pfr_next pfr_entry.le_next |
| 677 | struct nd_defrouter *router; |
| 678 | }; |
| 679 | |
| 680 | LIST_HEAD(nd_prhead, nd_prefix); |
| 681 | |
| 682 | struct nd_prefix_list { |
| 683 | struct nd_prefix_list *next; |
| 684 | struct nd_prefix pr; |
| 685 | }; |
| 686 | #endif /* BSD_KERNEL_PRIVATE */ |
| 687 | |
| 688 | #if defined(PRIVATE) |
| 689 | struct kev_nd6_ndfailure { |
| 690 | struct net_event_data link_data; |
| 691 | }; |
| 692 | |
| 693 | struct kev_nd6_ndalive { |
| 694 | struct net_event_data link_data; |
| 695 | }; |
| 696 | |
| 697 | struct nd6_ra_prefix { |
| 698 | struct sockaddr_in6 prefix; |
| 699 | struct prf_ra raflags; |
| 700 | u_int32_t prefixlen; |
| 701 | u_int32_t origin; |
| 702 | u_int64_t vltime; |
| 703 | u_int64_t pltime; |
| 704 | u_int64_t expire; |
| 705 | u_int32_t flags; |
| 706 | u_int32_t refcnt; |
| 707 | u_int32_t if_index; |
| 708 | u_int32_t pad; |
| 709 | }; |
| 710 | |
| 711 | /* ND6 router advertisement valid bits */ |
| 712 | #define KEV_ND6_DATA_VALID_MTU (0x1 << 0) |
| 713 | #define KEV_ND6_DATA_VALID_PREFIX (0x1 << 1) |
| 714 | |
| 715 | struct kev_nd6_ra_data { |
| 716 | u_int32_t mtu; |
| 717 | u_int32_t list_index; |
| 718 | u_int32_t list_length; |
| 719 | u_int32_t flags; |
| 720 | struct nd6_ra_prefix prefix; |
| 721 | u_int32_t pad; |
| 722 | }; |
| 723 | |
| 724 | struct kev_nd6_event { |
| 725 | struct net_event_data link_data; |
| 726 | struct in6_addr in6_address; |
| 727 | uint32_t val; |
| 728 | }; |
| 729 | |
| 730 | struct nd6_lookup_ipv6_args { |
| 731 | char ifname[IFNAMSIZ]; |
| 732 | struct sockaddr_in6 ip6_dest; |
| 733 | u_int32_t ll_dest_len; |
| 734 | union { |
| 735 | char buffer[256]; |
| 736 | struct sockaddr_dl _sdl; |
| 737 | } ll_dest_; |
| 738 | }; |
| 739 | #define ll_dest_sdl ll_dest_._sdl |
| 740 | |
| 741 | #endif /* PRIVATE */ |
| 742 | |
| 743 | #if defined(BSD_KERNEL_PRIVATE) |
| 744 | /* nd6.c */ |
| 745 | extern int nd6_prune; |
| 746 | extern int nd6_prune_lazy; |
| 747 | extern int nd6_delay; |
| 748 | extern int nd6_umaxtries; |
| 749 | extern int nd6_mmaxtries; |
| 750 | extern int nd6_useloopback; |
| 751 | extern int nd6_accept_6to4; |
| 752 | extern int nd6_maxnudhint; |
| 753 | extern int nd6_gctimer; |
| 754 | extern struct llinfo_nd6 llinfo_nd6; |
| 755 | extern struct nd_drhead nd_defrouter; |
| 756 | extern struct nd_prhead nd_prefix; |
| 757 | extern int nd6_debug; |
| 758 | extern int nd6_onlink_ns_rfc4861; |
| 759 | extern int nd6_optimistic_dad; |
| 760 | |
| 761 | #define nd6log0(x) do { log x; } while (0) |
| 762 | #define nd6log(x) do { if (nd6_debug >= 1) log x; } while (0) |
| 763 | #define nd6log2(x) do { if (nd6_debug >= 2) log x; } while (0) |
| 764 | |
| 765 | #define ND6_OPTIMISTIC_DAD_LINKLOCAL (1 << 0) |
| 766 | #define ND6_OPTIMISTIC_DAD_AUTOCONF (1 << 1) |
| 767 | #define ND6_OPTIMISTIC_DAD_TEMPORARY (1 << 2) |
| 768 | #define ND6_OPTIMISTIC_DAD_DYNAMIC (1 << 3) |
| 769 | #define ND6_OPTIMISTIC_DAD_SECURED (1 << 4) |
| 770 | #define ND6_OPTIMISTIC_DAD_MANUAL (1 << 5) |
| 771 | |
| 772 | /* nd6_rtr.c */ |
| 773 | extern int nd6_defifindex; |
| 774 | extern int ip6_desync_factor; /* seconds */ |
| 775 | /* ND6_INFINITE_LIFETIME does not apply to temporary addresses */ |
| 776 | extern u_int32_t ip6_temp_preferred_lifetime; /* seconds */ |
| 777 | extern u_int32_t ip6_temp_valid_lifetime; /* seconds */ |
| 778 | extern int ip6_temp_regen_advance; /* seconds */ |
| 779 | |
| 780 | union nd_opts { |
| 781 | struct nd_opt_hdr *nd_opt_array[16]; /* max = target address list */ |
| 782 | struct { |
| 783 | struct nd_opt_hdr *zero; |
| 784 | struct nd_opt_hdr *src_lladdr; |
| 785 | struct nd_opt_hdr *tgt_lladdr; |
| 786 | struct nd_opt_prefix_info *pi_beg; /* multiple opts, start */ |
| 787 | struct nd_opt_rd_hdr *rh; |
| 788 | struct nd_opt_mtu *mtu; |
| 789 | struct nd_opt_hdr *__res6; |
| 790 | struct nd_opt_hdr *__res7; |
| 791 | struct nd_opt_hdr *__res8; |
| 792 | struct nd_opt_hdr *__res9; |
| 793 | struct nd_opt_hdr *__res10; |
| 794 | struct nd_opt_hdr *__res11; |
| 795 | struct nd_opt_hdr *__res12; |
| 796 | struct nd_opt_hdr *__res13; |
| 797 | struct nd_opt_nonce *nonce; |
| 798 | struct nd_opt_hdr *__res15; |
| 799 | struct nd_opt_hdr *search; /* multiple opts */ |
| 800 | struct nd_opt_hdr *last; /* multiple opts */ |
| 801 | int done; |
| 802 | struct nd_opt_prefix_info *pi_end; /* multiple opts, end */ |
| 803 | } nd_opt_each; |
| 804 | }; |
| 805 | #define nd_opts_src_lladdr nd_opt_each.src_lladdr |
| 806 | #define nd_opts_tgt_lladdr nd_opt_each.tgt_lladdr |
| 807 | #define nd_opts_pi nd_opt_each.pi_beg |
| 808 | #define nd_opts_pi_end nd_opt_each.pi_end |
| 809 | #define nd_opts_rh nd_opt_each.rh |
| 810 | #define nd_opts_mtu nd_opt_each.mtu |
| 811 | #define nd_opts_nonce nd_opt_each.nonce |
| 812 | #define nd_opts_search nd_opt_each.search |
| 813 | #define nd_opts_last nd_opt_each.last |
| 814 | #define nd_opts_done nd_opt_each.done |
| 815 | |
| 816 | /* XXX: need nd6_var.h?? */ |
| 817 | /* nd6.c */ |
| 818 | extern int nd6_sched_timeout_want; |
| 819 | extern void nd6_sched_timeout(struct timeval *, struct timeval *); |
| 820 | extern void nd6_init(void); |
| 821 | extern void nd6_ifreset(struct ifnet *ifp); |
| 822 | extern void nd6_ifattach(struct ifnet *); |
| 823 | extern int nd6_is_addr_neighbor(struct sockaddr_in6 *, struct ifnet *, int); |
| 824 | extern void nd6_option_init(void *, int, union nd_opts *); |
| 825 | extern struct nd_opt_hdr *nd6_option(union nd_opts *); |
| 826 | extern int nd6_options(union nd_opts *); |
| 827 | extern struct rtentry *nd6_lookup(struct in6_addr *, int, struct ifnet *, int); |
| 828 | extern void nd6_setmtu(struct ifnet *); |
| 829 | extern void nd6_purge(struct ifnet *); |
| 830 | extern void nd6_free(struct rtentry *); |
| 831 | extern void nd6_nud_hint(struct rtentry *, struct in6_addr *, int); |
| 832 | extern int nd6_resolve(struct ifnet *, struct rtentry *, |
| 833 | struct mbuf *, struct sockaddr *, u_char *); |
| 834 | extern void nd6_rtrequest(int, struct rtentry *, struct sockaddr *); |
| 835 | extern int nd6_ioctl(u_long, caddr_t, struct ifnet *); |
| 836 | extern void nd6_cache_lladdr(struct ifnet *, struct in6_addr *, |
| 837 | char *, int, int, int); |
| 838 | extern int nd6_output_list(struct ifnet *, struct ifnet *, struct mbuf *, |
| 839 | struct sockaddr_in6 *, struct rtentry *, struct flowadv *); |
| 840 | extern int nd6_output(struct ifnet *, struct ifnet *, struct mbuf *, |
| 841 | struct sockaddr_in6 *, struct rtentry *, struct flowadv *); |
| 842 | extern int nd6_storelladdr(struct ifnet *, struct rtentry *, struct mbuf *, |
| 843 | struct sockaddr *, u_char *); |
| 844 | extern int nd6_need_cache(struct ifnet *); |
| 845 | extern void nd6_drain(void *); |
| 846 | extern void nd6_post_msg(u_int32_t, struct nd_prefix_list *, u_int32_t, |
| 847 | u_int32_t); |
| 848 | extern int nd6_setifinfo(struct ifnet *, u_int32_t, u_int32_t); |
| 849 | extern const char *ndcache_state2str(short); |
| 850 | extern void ln_setexpire(struct llinfo_nd6 *, uint64_t); |
| 851 | |
| 852 | /* nd6_nbr.c */ |
| 853 | extern void nd6_nbr_init(void); |
| 854 | extern void nd6_na_input(struct mbuf *, int, int); |
| 855 | extern void nd6_na_output(struct ifnet *, const struct in6_addr *, |
| 856 | const struct in6_addr *, u_int32_t, int, struct sockaddr *); |
| 857 | extern void nd6_ns_input(struct mbuf *, int, int); |
| 858 | extern void nd6_ns_output(struct ifnet *, const struct in6_addr *, |
| 859 | const struct in6_addr *, struct llinfo_nd6 *, uint8_t *); |
| 860 | extern caddr_t nd6_ifptomac(struct ifnet *); |
| 861 | extern void nd6_dad_start(struct ifaddr *, int *); |
| 862 | extern void nd6_dad_stop(struct ifaddr *); |
| 863 | extern void nd6_dad_duplicated(struct ifaddr *); |
| 864 | extern void nd6_llreach_alloc(struct rtentry *, struct ifnet *, void *, |
| 865 | unsigned int, boolean_t); |
| 866 | extern void nd6_llreach_set_reachable(struct ifnet *, void *, unsigned int); |
| 867 | extern void nd6_llreach_use(struct llinfo_nd6 *); |
| 868 | extern void nd6_alt_node_addr_decompose(struct ifnet *, struct sockaddr *, |
| 869 | struct sockaddr_dl *, struct sockaddr_in6 *); |
| 870 | extern void nd6_alt_node_present(struct ifnet *, struct sockaddr_in6 *, |
| 871 | struct sockaddr_dl *, int32_t, int, int); |
| 872 | extern void nd6_alt_node_absent(struct ifnet *, struct sockaddr_in6 *); |
| 873 | |
| 874 | /* nd6_rtr.c */ |
| 875 | extern struct in6_ifaddr *in6_pfx_newpersistaddr(struct nd_prefix *, int, |
| 876 | int *, boolean_t); |
| 877 | extern void nd6_rtr_init(void); |
| 878 | extern void nd6_rs_input(struct mbuf *, int, int); |
| 879 | extern void nd6_ra_input(struct mbuf *, int, int); |
| 880 | extern void prelist_del(struct nd_prefix *); |
| 881 | extern void defrouter_select(struct ifnet *); |
| 882 | extern void defrouter_reset(void); |
| 883 | extern int defrtrlist_ioctl(u_long, caddr_t); |
| 884 | extern void defrtrlist_del(struct nd_defrouter *); |
| 885 | extern int defrtrlist_add_static(struct nd_defrouter *); |
| 886 | extern int defrtrlist_del_static(struct nd_defrouter *); |
| 887 | extern void prelist_remove(struct nd_prefix *); |
| 888 | extern int prelist_update(struct nd_prefix *, struct nd_defrouter *, |
| 889 | struct mbuf *, int); |
| 890 | extern int nd6_prelist_add(struct nd_prefix *, struct nd_defrouter *, |
| 891 | struct nd_prefix **, boolean_t); |
| 892 | extern int nd6_prefix_onlink(struct nd_prefix *); |
| 893 | extern int nd6_prefix_onlink_scoped(struct nd_prefix *, unsigned int); |
| 894 | extern int nd6_prefix_offlink(struct nd_prefix *); |
| 895 | extern void pfxlist_onlink_check(void); |
| 896 | extern struct nd_defrouter *defrouter_lookup(struct in6_addr *, struct ifnet *); |
| 897 | extern struct nd_prefix *nd6_prefix_lookup(struct nd_prefix *, int); |
| 898 | extern int in6_init_prefix_ltimes(struct nd_prefix *ndpr); |
| 899 | extern void rt6_flush(struct in6_addr *, struct ifnet *); |
| 900 | extern int nd6_setdefaultiface(int); |
| 901 | extern int in6_tmpifadd(const struct in6_ifaddr *, int); |
| 902 | extern void nddr_addref(struct nd_defrouter *, int); |
| 903 | extern struct nd_defrouter *nddr_remref(struct nd_defrouter *, int); |
| 904 | extern uint64_t nddr_getexpire(struct nd_defrouter *); |
| 905 | extern void ndpr_addref(struct nd_prefix *, int); |
| 906 | extern struct nd_prefix *ndpr_remref(struct nd_prefix *, int); |
| 907 | extern uint64_t ndpr_getexpire(struct nd_prefix *); |
| 908 | |
| 909 | /* nd6_prproxy.c */ |
| 910 | struct ip6_hdr; |
| 911 | extern u_int32_t nd6_prproxy; |
| 912 | extern void nd6_prproxy_init(void); |
| 913 | extern int nd6_if_prproxy(struct ifnet *, boolean_t); |
| 914 | extern void nd6_prproxy_prelist_update(struct nd_prefix *, struct nd_prefix *); |
| 915 | extern boolean_t nd6_prproxy_ifaddr(struct in6_ifaddr *); |
| 916 | extern void nd6_proxy_find_fwdroute(struct ifnet *, struct route_in6 *); |
| 917 | extern boolean_t nd6_prproxy_isours(struct mbuf *, struct ip6_hdr *, |
| 918 | struct route_in6 *, unsigned int); |
| 919 | extern void nd6_prproxy_ns_output(struct ifnet *, struct ifnet *, |
| 920 | struct in6_addr *, struct in6_addr *, struct llinfo_nd6 *); |
| 921 | extern void nd6_prproxy_ns_input(struct ifnet *, struct in6_addr *, |
| 922 | char *, int, struct in6_addr *, struct in6_addr *, uint8_t *nonce); |
| 923 | extern void nd6_prproxy_na_input(struct ifnet *, struct in6_addr *, |
| 924 | struct in6_addr *, struct in6_addr *, int); |
| 925 | extern void nd6_prproxy_sols_reap(struct nd_prefix *); |
| 926 | extern void nd6_prproxy_sols_prune(struct nd_prefix *, u_int32_t); |
| 927 | extern int nd6_if_disable(struct ifnet *, boolean_t); |
| 928 | void in6_ifaddr_set_dadprogress(struct in6_ifaddr *ia); |
| 929 | #endif /* BSD_KERNEL_PRIVATE */ |
| 930 | |
| 931 | #ifdef KERNEL |
| 932 | |
| 933 | /* |
| 934 | * @function nd6_lookup_ipv6 |
| 935 | * @discussion This function will check the routing table for a cached |
| 936 | * neighbor discovery entry or trigger an neighbor discovery query |
| 937 | * to resolve the IPv6 address to a link-layer address. |
| 938 | * nd entries are stored in the routing table. This function will |
| 939 | * lookup the IPv6 destination in the routing table. If the |
| 940 | * destination requires forwarding to a gateway, the route of the |
| 941 | * gateway will be looked up. The route entry is inspected to |
| 942 | * determine if the link layer destination address is known. If |
| 943 | * unknown, neighbor discovery will be used to resolve the entry. |
| 944 | * @param interface The interface the packet is being sent on. |
| 945 | * @param ip6_dest The IPv6 destination of the packet. |
| 946 | * @param ll_dest On output, the link-layer destination. |
| 947 | * @param ll_dest_len The length of the buffer for ll_dest. |
| 948 | * @param hint Any routing hint passed down from the protocol. |
| 949 | * @param packet The packet being transmitted. |
| 950 | * @result May return an error such as EHOSTDOWN or ENETUNREACH. If |
| 951 | * this function returns EJUSTRETURN, the packet has been queued |
| 952 | * and will be sent when the address is resolved. If any other |
| 953 | * value is returned, the caller is responsible for disposing of |
| 954 | * the packet. |
| 955 | */ |
| 956 | extern errno_t nd6_lookup_ipv6(ifnet_t interface, |
| 957 | const struct sockaddr_in6 *ip6_dest, struct sockaddr_dl *ll_dest, |
| 958 | size_t ll_dest_len, route_t hint, mbuf_t packet); |
| 959 | |
| 960 | #endif /* KERNEL */ |
| 961 | |
| 962 | /* nd6_send.c */ |
| 963 | #ifdef BSD_KERNEL_PRIVATE |
| 964 | /* |
| 965 | * nd6_send_opmode |
| 966 | * |
| 967 | * value using CGA tx SEND rx SEND |
| 968 | * -------- --------- ------- ------- |
| 969 | * DISABLED NO NO NO |
| 970 | * QUIET YES NO NO |
| 971 | */ |
| 972 | extern int nd6_send_opstate; |
| 973 | |
| 974 | #define ND6_SEND_OPMODE_DISABLED 0 |
| 975 | #define ND6_SEND_OPMODE_CGA_QUIET 1 |
| 976 | |
| 977 | #endif /* BSD_KERNEL_PRIVATE */ |
| 978 | #endif /* _NETINET6_ND6_H_ */ |
| 979 | |