1caf43b02SWarner Losh /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 482cd038dSYoshinobu Inoue * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 582cd038dSYoshinobu Inoue * All rights reserved. 682cd038dSYoshinobu Inoue * 782cd038dSYoshinobu Inoue * Redistribution and use in source and binary forms, with or without 882cd038dSYoshinobu Inoue * modification, are permitted provided that the following conditions 982cd038dSYoshinobu Inoue * are met: 1082cd038dSYoshinobu Inoue * 1. Redistributions of source code must retain the above copyright 1182cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer. 1282cd038dSYoshinobu Inoue * 2. Redistributions in binary form must reproduce the above copyright 1382cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer in the 1482cd038dSYoshinobu Inoue * documentation and/or other materials provided with the distribution. 1582cd038dSYoshinobu Inoue * 3. Neither the name of the project nor the names of its contributors 1682cd038dSYoshinobu Inoue * may be used to endorse or promote products derived from this software 1782cd038dSYoshinobu Inoue * without specific prior written permission. 1882cd038dSYoshinobu Inoue * 1982cd038dSYoshinobu Inoue * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2082cd038dSYoshinobu Inoue * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2182cd038dSYoshinobu Inoue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2282cd038dSYoshinobu Inoue * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2382cd038dSYoshinobu Inoue * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2482cd038dSYoshinobu Inoue * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2582cd038dSYoshinobu Inoue * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2682cd038dSYoshinobu Inoue * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2782cd038dSYoshinobu Inoue * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2882cd038dSYoshinobu Inoue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2982cd038dSYoshinobu Inoue * SUCH DAMAGE. 30b48287a3SDavid E. O'Brien * 31b48287a3SDavid E. O'Brien * $KAME: nd6.h,v 1.76 2001/12/18 02:10:31 itojun Exp $ 3282cd038dSYoshinobu Inoue */ 3382cd038dSYoshinobu Inoue 3482cd038dSYoshinobu Inoue #ifndef _NETINET6_ND6_H_ 3582cd038dSYoshinobu Inoue #define _NETINET6_ND6_H_ 3682cd038dSYoshinobu Inoue 37686cdd19SJun-ichiro itojun Hagino /* see net/route.h, or net/if_inarp.h */ 38686cdd19SJun-ichiro itojun Hagino #ifndef RTF_ANNOUNCE 39686cdd19SJun-ichiro itojun Hagino #define RTF_ANNOUNCE RTF_PROTO2 40686cdd19SJun-ichiro itojun Hagino #endif 41686cdd19SJun-ichiro itojun Hagino 4282cd038dSYoshinobu Inoue #include <sys/queue.h> 4333841545SHajimu UMEMOTO #include <sys/callout.h> 4482cd038dSYoshinobu Inoue 456e6b3f7cSQing Li struct llentry; 4682cd038dSYoshinobu Inoue 4782cd038dSYoshinobu Inoue #define ND6_LLINFO_NOSTATE -2 4833841545SHajimu UMEMOTO /* 4933841545SHajimu UMEMOTO * We don't need the WAITDELETE state any more, but we keep the definition 5033841545SHajimu UMEMOTO * in a comment line instead of removing it. This is necessary to avoid 5133841545SHajimu UMEMOTO * unintentionally reusing the value for another purpose, which might 5233841545SHajimu UMEMOTO * affect backward compatibility with old applications. 5333841545SHajimu UMEMOTO * (20000711 jinmei@kame.net) 5433841545SHajimu UMEMOTO */ 5533841545SHajimu UMEMOTO /* #define ND6_LLINFO_WAITDELETE -1 */ 5682cd038dSYoshinobu Inoue #define ND6_LLINFO_INCOMPLETE 0 5782cd038dSYoshinobu Inoue #define ND6_LLINFO_REACHABLE 1 5882cd038dSYoshinobu Inoue #define ND6_LLINFO_STALE 2 5982cd038dSYoshinobu Inoue #define ND6_LLINFO_DELAY 3 6082cd038dSYoshinobu Inoue #define ND6_LLINFO_PROBE 4 6182cd038dSYoshinobu Inoue 62686cdd19SJun-ichiro itojun Hagino #define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE) 636e6b3f7cSQing Li #define ND6_LLINFO_PERMANENT(n) (((n)->la_expire == 0) && ((n)->ln_state > ND6_LLINFO_INCOMPLETE)) 64686cdd19SJun-ichiro itojun Hagino 6582cd038dSYoshinobu Inoue struct nd_ifinfo { 6682cd038dSYoshinobu Inoue u_int32_t linkmtu; /* LinkMTU */ 6782cd038dSYoshinobu Inoue u_int32_t maxmtu; /* Upper bound of LinkMTU */ 6882cd038dSYoshinobu Inoue u_int32_t basereachable; /* BaseReachableTime */ 6982cd038dSYoshinobu Inoue u_int32_t reachable; /* Reachable Time */ 7082cd038dSYoshinobu Inoue u_int32_t retrans; /* Retrans Timer */ 71686cdd19SJun-ichiro itojun Hagino u_int32_t flags; /* Flags */ 7282cd038dSYoshinobu Inoue int recalctm; /* BaseReacable re-calculation timer */ 7382cd038dSYoshinobu Inoue u_int8_t chlim; /* CurHopLimit */ 7431b1bfe1SHajimu UMEMOTO u_int8_t initialized; /* Flag to see the entry is initialized */ 7588ff5695SSUZUKI Shinsuke /* the following 3 members are for privacy extension for addrconf */ 7633841545SHajimu UMEMOTO u_int8_t randomseed0[8]; /* upper 64 bits of MD5 digest */ 7733841545SHajimu UMEMOTO u_int8_t randomseed1[8]; /* lower 64 bits (usually the EUI64 IFID) */ 7833841545SHajimu UMEMOTO u_int8_t randomid[8]; /* current random ID */ 7982cd038dSYoshinobu Inoue }; 8082cd038dSYoshinobu Inoue 81686cdd19SJun-ichiro itojun Hagino #define ND6_IFF_PERFORMNUD 0x1 8207cf047dSHajimu UMEMOTO #define ND6_IFF_ACCEPT_RTADV 0x2 83f6c336feSHiroki Sato #define ND6_IFF_PREFER_SOURCE 0x4 /* Not used in FreeBSD. */ 845b27b045SSUZUKI Shinsuke #define ND6_IFF_IFDISABLED 0x8 /* IPv6 operation is disabled due to 855b27b045SSUZUKI Shinsuke * DAD failure. (XXX: not ND-specific) 865b27b045SSUZUKI Shinsuke */ 87743eee66SSUZUKI Shinsuke #define ND6_IFF_DONT_SET_IFROUTE 0x10 88a283298cSHiroki Sato #define ND6_IFF_AUTO_LINKLOCAL 0x20 89e7fa8d0aSHiroki Sato #define ND6_IFF_NO_RADR 0x40 90164051ceSHajimu UMEMOTO #define ND6_IFF_NO_PREFER_IFACE 0x80 /* XXX: not related to ND. */ 9159333867SHiroki Sato #define ND6_IFF_NO_DAD 0x100 92201100c5SBjoern A. Zeeb #ifdef EXPERIMENTAL 9321231a7aSBjoern A. Zeeb /* XXX: not related to ND. */ 94201100c5SBjoern A. Zeeb #define ND6_IFF_IPV6_ONLY 0x200 /* draft-ietf-6man-ipv6only-flag */ 9521231a7aSBjoern A. Zeeb #define ND6_IFF_IPV6_ONLY_MANUAL 0x400 9621231a7aSBjoern A. Zeeb #define ND6_IFF_IPV6_ONLY_MASK (ND6_IFF_IPV6_ONLY|ND6_IFF_IPV6_ONLY_MANUAL) 97201100c5SBjoern A. Zeeb #endif 98686cdd19SJun-ichiro itojun Hagino 9931b1bfe1SHajimu UMEMOTO #ifdef _KERNEL 10031b1bfe1SHajimu UMEMOTO #define ND_IFINFO(ifp) \ 101*3d0d5b21SJustin Hibbits (((struct in6_ifextra *)if_getafdata(ifp, AF_INET6))->nd_ifinfo) 10231b1bfe1SHajimu UMEMOTO #define IN6_LINKMTU(ifp) \ 10331b1bfe1SHajimu UMEMOTO ((ND_IFINFO(ifp)->linkmtu && ND_IFINFO(ifp)->linkmtu < (ifp)->if_mtu) \ 10431b1bfe1SHajimu UMEMOTO ? ND_IFINFO(ifp)->linkmtu \ 10531b1bfe1SHajimu UMEMOTO : ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < (ifp)->if_mtu) \ 10631b1bfe1SHajimu UMEMOTO ? ND_IFINFO(ifp)->maxmtu : (ifp)->if_mtu)) 10731b1bfe1SHajimu UMEMOTO #endif 10831b1bfe1SHajimu UMEMOTO 10982cd038dSYoshinobu Inoue struct in6_nbrinfo { 11082cd038dSYoshinobu Inoue char ifname[IFNAMSIZ]; /* if name, e.g. "en0" */ 11182cd038dSYoshinobu Inoue struct in6_addr addr; /* IPv6 address of the neighbor */ 11282cd038dSYoshinobu Inoue long asked; /* number of queries already sent for this addr */ 11382cd038dSYoshinobu Inoue int isrouter; /* if it acts as a router */ 11482cd038dSYoshinobu Inoue int state; /* reachability state */ 11582cd038dSYoshinobu Inoue int expire; /* lifetime for NDP state transition */ 11682cd038dSYoshinobu Inoue }; 11782cd038dSYoshinobu Inoue 118b3a25d29SBjoern A. Zeeb /* Sysctls, shared with user space. */ 11933841545SHajimu UMEMOTO struct in6_defrouter { 12033841545SHajimu UMEMOTO struct sockaddr_in6 rtaddr; 12133841545SHajimu UMEMOTO u_char flags; 12233841545SHajimu UMEMOTO u_short rtlifetime; 12333841545SHajimu UMEMOTO u_long expire; 12433841545SHajimu UMEMOTO u_short if_index; 12523cd8d58SHidetoshi Shimokawa }; 12633841545SHajimu UMEMOTO 12733841545SHajimu UMEMOTO struct in6_prefix { 12833841545SHajimu UMEMOTO struct sockaddr_in6 prefix; 12933841545SHajimu UMEMOTO struct prf_ra raflags; 13033841545SHajimu UMEMOTO u_char prefixlen; 13133841545SHajimu UMEMOTO u_char origin; 132f95d4633SHajimu UMEMOTO u_int32_t vltime; 133f95d4633SHajimu UMEMOTO u_int32_t pltime; 134f95d4633SHajimu UMEMOTO time_t expire; 13533841545SHajimu UMEMOTO u_int32_t flags; 13633841545SHajimu UMEMOTO int refcnt; 13733841545SHajimu UMEMOTO u_short if_index; 13833841545SHajimu UMEMOTO u_short advrtrs; /* number of advertisement routers */ 13933841545SHajimu UMEMOTO /* struct sockaddr_in6 advrtr[] */ 14023cd8d58SHidetoshi Shimokawa }; 14133841545SHajimu UMEMOTO 14233841545SHajimu UMEMOTO #ifdef _KERNEL 14333841545SHajimu UMEMOTO struct in6_ondireq { 14433841545SHajimu UMEMOTO char ifname[IFNAMSIZ]; 14533841545SHajimu UMEMOTO struct { 14633841545SHajimu UMEMOTO u_int32_t linkmtu; /* LinkMTU */ 14733841545SHajimu UMEMOTO u_int32_t maxmtu; /* Upper bound of LinkMTU */ 14833841545SHajimu UMEMOTO u_int32_t basereachable; /* BaseReachableTime */ 14933841545SHajimu UMEMOTO u_int32_t reachable; /* Reachable Time */ 15033841545SHajimu UMEMOTO u_int32_t retrans; /* Retrans Timer */ 15133841545SHajimu UMEMOTO u_int32_t flags; /* Flags */ 15233841545SHajimu UMEMOTO int recalctm; /* BaseReacable re-calculation timer */ 15333841545SHajimu UMEMOTO u_int8_t chlim; /* CurHopLimit */ 15433841545SHajimu UMEMOTO u_int8_t receivedra; 15533841545SHajimu UMEMOTO } ndi; 15633841545SHajimu UMEMOTO }; 15733841545SHajimu UMEMOTO #endif 15833841545SHajimu UMEMOTO 15982cd038dSYoshinobu Inoue struct in6_ndireq { 16082cd038dSYoshinobu Inoue char ifname[IFNAMSIZ]; 16182cd038dSYoshinobu Inoue struct nd_ifinfo ndi; 16282cd038dSYoshinobu Inoue }; 16382cd038dSYoshinobu Inoue 164686cdd19SJun-ichiro itojun Hagino struct in6_ndifreq { 165686cdd19SJun-ichiro itojun Hagino char ifname[IFNAMSIZ]; 166686cdd19SJun-ichiro itojun Hagino u_long ifindex; 167686cdd19SJun-ichiro itojun Hagino }; 168686cdd19SJun-ichiro itojun Hagino 16933841545SHajimu UMEMOTO /* Prefix status */ 17033841545SHajimu UMEMOTO #define NDPRF_ONLINK 0x1 17133841545SHajimu UMEMOTO #define NDPRF_DETACHED 0x2 172686cdd19SJun-ichiro itojun Hagino 17382cd038dSYoshinobu Inoue /* protocol constants */ 17482cd038dSYoshinobu Inoue #define MAX_RTR_SOLICITATION_DELAY 1 /* 1sec */ 17582cd038dSYoshinobu Inoue #define RTR_SOLICITATION_INTERVAL 4 /* 4sec */ 17682cd038dSYoshinobu Inoue #define MAX_RTR_SOLICITATIONS 3 17782cd038dSYoshinobu Inoue 17882cd038dSYoshinobu Inoue #define ND6_INFINITE_LIFETIME 0xffffffff 17982cd038dSYoshinobu Inoue 18082cd038dSYoshinobu Inoue #ifdef _KERNEL 18182cd038dSYoshinobu Inoue /* node constants */ 18282cd038dSYoshinobu Inoue #define MAX_REACHABLE_TIME 3600000 /* msec */ 18382cd038dSYoshinobu Inoue #define REACHABLE_TIME 30000 /* msec */ 18482cd038dSYoshinobu Inoue #define RETRANS_TIMER 1000 /* msec */ 18582cd038dSYoshinobu Inoue #define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */ 18682cd038dSYoshinobu Inoue #define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */ 18733841545SHajimu UMEMOTO #define DEF_TEMP_VALID_LIFETIME 604800 /* 1 week */ 18833841545SHajimu UMEMOTO #define DEF_TEMP_PREFERRED_LIFETIME 86400 /* 1 day */ 18933841545SHajimu UMEMOTO #define TEMPADDR_REGEN_ADVANCE 5 /* sec */ 19033841545SHajimu UMEMOTO #define MAX_TEMP_DESYNC_FACTOR 600 /* 10 min */ 19182cd038dSYoshinobu Inoue #define ND_COMPUTE_RTIME(x) \ 192a02e1e2bSHajimu UMEMOTO (((MIN_RANDOM_FACTOR * (x >> 10)) + (arc4random() & \ 19382cd038dSYoshinobu Inoue ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000) 19482cd038dSYoshinobu Inoue 19582cd038dSYoshinobu Inoue struct nd_defrouter { 196686cdd19SJun-ichiro itojun Hagino TAILQ_ENTRY(nd_defrouter) dr_entry; 19782cd038dSYoshinobu Inoue struct in6_addr rtaddr; 19801869be5SMark Johnston u_char raflags; /* flags on RA message */ 19982cd038dSYoshinobu Inoue u_short rtlifetime; 20082cd038dSYoshinobu Inoue u_long expire; 20182cd038dSYoshinobu Inoue struct ifnet *ifp; 202743eee66SSUZUKI Shinsuke int installed; /* is installed into kernel routing table */ 2034de485feSMark Johnston u_int refcnt; 20482cd038dSYoshinobu Inoue }; 20582cd038dSYoshinobu Inoue 206743eee66SSUZUKI Shinsuke struct nd_prefixctl { 207743eee66SSUZUKI Shinsuke struct ifnet *ndpr_ifp; 208743eee66SSUZUKI Shinsuke 209743eee66SSUZUKI Shinsuke /* prefix */ 210743eee66SSUZUKI Shinsuke struct sockaddr_in6 ndpr_prefix; 211743eee66SSUZUKI Shinsuke u_char ndpr_plen; 212743eee66SSUZUKI Shinsuke 213743eee66SSUZUKI Shinsuke u_int32_t ndpr_vltime; /* advertised valid lifetime */ 214743eee66SSUZUKI Shinsuke u_int32_t ndpr_pltime; /* advertised preferred lifetime */ 215743eee66SSUZUKI Shinsuke 216743eee66SSUZUKI Shinsuke struct prf_ra ndpr_flags; 217743eee66SSUZUKI Shinsuke }; 218743eee66SSUZUKI Shinsuke 219d748f7efSMark Johnston LIST_HEAD(nd_prhead, nd_prefix); 22082cd038dSYoshinobu Inoue struct nd_prefix { 22182cd038dSYoshinobu Inoue struct ifnet *ndpr_ifp; 222e3975643SJake Burkholder LIST_ENTRY(nd_prefix) ndpr_entry; 22382cd038dSYoshinobu Inoue struct sockaddr_in6 ndpr_prefix; /* prefix */ 22482cd038dSYoshinobu Inoue struct in6_addr ndpr_mask; /* netmask derived from the prefix */ 225743eee66SSUZUKI Shinsuke 22682cd038dSYoshinobu Inoue u_int32_t ndpr_vltime; /* advertised valid lifetime */ 22782cd038dSYoshinobu Inoue u_int32_t ndpr_pltime; /* advertised preferred lifetime */ 228743eee66SSUZUKI Shinsuke 22982cd038dSYoshinobu Inoue time_t ndpr_expire; /* expiration time of the prefix */ 23082cd038dSYoshinobu Inoue time_t ndpr_preferred; /* preferred time of the prefix */ 231743eee66SSUZUKI Shinsuke time_t ndpr_lastupdate; /* reception time of last advertisement */ 232743eee66SSUZUKI Shinsuke 23382cd038dSYoshinobu Inoue struct prf_ra ndpr_flags; 23433841545SHajimu UMEMOTO u_int32_t ndpr_stateflags; /* actual state flags */ 23582cd038dSYoshinobu Inoue /* list of routers that advertise the prefix: */ 236e3975643SJake Burkholder LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs; 23782cd038dSYoshinobu Inoue u_char ndpr_plen; 2380bbf244eSMark Johnston int ndpr_addrcnt; /* count of derived addresses */ 239d748f7efSMark Johnston volatile u_int ndpr_refcnt; 24082cd038dSYoshinobu Inoue }; 24182cd038dSYoshinobu Inoue 24282cd038dSYoshinobu Inoue #define ndpr_raf ndpr_flags 24382cd038dSYoshinobu Inoue #define ndpr_raf_onlink ndpr_flags.onlink 24482cd038dSYoshinobu Inoue #define ndpr_raf_auto ndpr_flags.autonomous 2458036234cSAlexander V. Chernikov #define ndpr_raf_ra_derived ndpr_flags.ra_derived 246743eee66SSUZUKI Shinsuke #define ndpr_raf_router ndpr_flags.router 24782cd038dSYoshinobu Inoue 24882cd038dSYoshinobu Inoue struct nd_pfxrouter { 249e3975643SJake Burkholder LIST_ENTRY(nd_pfxrouter) pfr_entry; 25082cd038dSYoshinobu Inoue struct nd_defrouter *router; 25182cd038dSYoshinobu Inoue }; 25282cd038dSYoshinobu Inoue 2535e0a6f31SMark Johnston #ifdef MALLOC_DECLARE 2545e0a6f31SMark Johnston MALLOC_DECLARE(M_IP6NDP); 2555e0a6f31SMark Johnston #endif 2565e0a6f31SMark Johnston 25782cd038dSYoshinobu Inoue /* nd6.c */ 258eddfbb76SRobert Watson VNET_DECLARE(int, nd6_mmaxtries); 259eddfbb76SRobert Watson VNET_DECLARE(struct nd_prhead, nd_prefix); 260eddfbb76SRobert Watson VNET_DECLARE(int, nd6_debug); 2611e77c105SRobert Watson #define V_nd6_mmaxtries VNET(nd6_mmaxtries) 2621e77c105SRobert Watson #define V_nd_prefix VNET(nd_prefix) 2631e77c105SRobert Watson #define V_nd6_debug VNET(nd6_debug) 26482cea7e6SBjoern A. Zeeb 2654de485feSMark Johnston /* Lock for the prefix and default router lists. */ 2664de485feSMark Johnston VNET_DECLARE(struct rwlock, nd6_lock); 267d748f7efSMark Johnston VNET_DECLARE(uint64_t, nd6_list_genid); 2684de485feSMark Johnston #define V_nd6_lock VNET(nd6_lock) 269d748f7efSMark Johnston #define V_nd6_list_genid VNET(nd6_list_genid) 2704de485feSMark Johnston 2714de485feSMark Johnston #define ND6_RLOCK() rw_rlock(&V_nd6_lock) 2724de485feSMark Johnston #define ND6_RUNLOCK() rw_runlock(&V_nd6_lock) 2734de485feSMark Johnston #define ND6_WLOCK() rw_wlock(&V_nd6_lock) 2744de485feSMark Johnston #define ND6_WUNLOCK() rw_wunlock(&V_nd6_lock) 275d748f7efSMark Johnston #define ND6_TRY_UPGRADE() rw_try_upgrade(&V_nd6_lock) 2764de485feSMark Johnston #define ND6_WLOCK_ASSERT() rw_assert(&V_nd6_lock, RA_WLOCKED) 2774de485feSMark Johnston #define ND6_RLOCK_ASSERT() rw_assert(&V_nd6_lock, RA_RLOCKED) 2784de485feSMark Johnston #define ND6_LOCK_ASSERT() rw_assert(&V_nd6_lock, RA_LOCKED) 2794de485feSMark Johnston #define ND6_UNLOCK_ASSERT() rw_assert(&V_nd6_lock, RA_UNLOCKED) 2804de485feSMark Johnston 281d748f7efSMark Johnston /* Mutex for prefix onlink/offlink transitions. */ 282d748f7efSMark Johnston VNET_DECLARE(struct mtx, nd6_onlink_mtx); 283d748f7efSMark Johnston #define V_nd6_onlink_mtx VNET(nd6_onlink_mtx) 284d748f7efSMark Johnston 285d748f7efSMark Johnston #define ND6_ONLINK_LOCK() mtx_lock(&V_nd6_onlink_mtx) 286d748f7efSMark Johnston #define ND6_ONLINK_TRYLOCK() mtx_trylock(&V_nd6_onlink_mtx) 287d748f7efSMark Johnston #define ND6_ONLINK_UNLOCK() mtx_unlock(&V_nd6_onlink_mtx) 288d748f7efSMark Johnston #define ND6_ONLINK_LOCK_ASSERT() mtx_assert(&V_nd6_onlink_mtx, MA_OWNED) 289d748f7efSMark Johnston #define ND6_ONLINK_UNLOCK_ASSERT() mtx_assert(&V_nd6_onlink_mtx, MA_NOTOWNED) 290d748f7efSMark Johnston 29182cea7e6SBjoern A. Zeeb #define nd6log(x) do { if (V_nd6_debug) log x; } while (/*CONSTCOND*/ 0) 29282cea7e6SBjoern A. Zeeb 293686cdd19SJun-ichiro itojun Hagino /* nd6_rtr.c */ 294eddfbb76SRobert Watson VNET_DECLARE(int, nd6_defifindex); 295eddfbb76SRobert Watson VNET_DECLARE(int, ip6_desync_factor); /* seconds */ 296eddfbb76SRobert Watson VNET_DECLARE(u_int32_t, ip6_temp_preferred_lifetime); /* seconds */ 297eddfbb76SRobert Watson VNET_DECLARE(u_int32_t, ip6_temp_valid_lifetime); /* seconds */ 298eddfbb76SRobert Watson VNET_DECLARE(int, ip6_temp_regen_advance); /* seconds */ 2991e77c105SRobert Watson #define V_nd6_defifindex VNET(nd6_defifindex) 3001e77c105SRobert Watson #define V_ip6_desync_factor VNET(ip6_desync_factor) 3011e77c105SRobert Watson #define V_ip6_temp_preferred_lifetime VNET(ip6_temp_preferred_lifetime) 3021e77c105SRobert Watson #define V_ip6_temp_valid_lifetime VNET(ip6_temp_valid_lifetime) 3031e77c105SRobert Watson #define V_ip6_temp_regen_advance VNET(ip6_temp_regen_advance) 30486413abfSBjoern A. Zeeb 30582cd038dSYoshinobu Inoue union nd_opts { 30611d8451dSHiroki Sato struct nd_opt_hdr *nd_opt_array[16]; /* max = ND_OPT_NONCE */ 30782cd038dSYoshinobu Inoue struct { 30882cd038dSYoshinobu Inoue struct nd_opt_hdr *zero; 30982cd038dSYoshinobu Inoue struct nd_opt_hdr *src_lladdr; 31082cd038dSYoshinobu Inoue struct nd_opt_hdr *tgt_lladdr; 31182cd038dSYoshinobu Inoue struct nd_opt_prefix_info *pi_beg; /* multiple opts, start */ 31282cd038dSYoshinobu Inoue struct nd_opt_rd_hdr *rh; 31382cd038dSYoshinobu Inoue struct nd_opt_mtu *mtu; 31411d8451dSHiroki Sato struct nd_opt_hdr *__res6; 31511d8451dSHiroki Sato struct nd_opt_hdr *__res7; 31611d8451dSHiroki Sato struct nd_opt_hdr *__res8; 31711d8451dSHiroki Sato struct nd_opt_hdr *__res9; 31811d8451dSHiroki Sato struct nd_opt_hdr *__res10; 31911d8451dSHiroki Sato struct nd_opt_hdr *__res11; 32011d8451dSHiroki Sato struct nd_opt_hdr *__res12; 32111d8451dSHiroki Sato struct nd_opt_hdr *__res13; 32211d8451dSHiroki Sato struct nd_opt_nonce *nonce; 32311d8451dSHiroki Sato struct nd_opt_hdr *__res15; 32482cd038dSYoshinobu Inoue struct nd_opt_hdr *search; /* multiple opts */ 32582cd038dSYoshinobu Inoue struct nd_opt_hdr *last; /* multiple opts */ 32682cd038dSYoshinobu Inoue int done; 32782cd038dSYoshinobu Inoue struct nd_opt_prefix_info *pi_end;/* multiple opts, end */ 32882cd038dSYoshinobu Inoue } nd_opt_each; 32982cd038dSYoshinobu Inoue }; 33082cd038dSYoshinobu Inoue #define nd_opts_src_lladdr nd_opt_each.src_lladdr 33182cd038dSYoshinobu Inoue #define nd_opts_tgt_lladdr nd_opt_each.tgt_lladdr 33282cd038dSYoshinobu Inoue #define nd_opts_pi nd_opt_each.pi_beg 33382cd038dSYoshinobu Inoue #define nd_opts_pi_end nd_opt_each.pi_end 33482cd038dSYoshinobu Inoue #define nd_opts_rh nd_opt_each.rh 33582cd038dSYoshinobu Inoue #define nd_opts_mtu nd_opt_each.mtu 33611d8451dSHiroki Sato #define nd_opts_nonce nd_opt_each.nonce 33782cd038dSYoshinobu Inoue #define nd_opts_search nd_opt_each.search 33882cd038dSYoshinobu Inoue #define nd_opts_last nd_opt_each.last 33982cd038dSYoshinobu Inoue #define nd_opts_done nd_opt_each.done 34082cd038dSYoshinobu Inoue 34182cd038dSYoshinobu Inoue /* XXX: need nd6_var.h?? */ 34282cd038dSYoshinobu Inoue /* nd6.c */ 3436f56329aSXin LI void nd6_init(void); 344bc29160dSMarko Zec #ifdef VIMAGE 3456f56329aSXin LI void nd6_destroy(void); 346bc29160dSMarko Zec #endif 3476f56329aSXin LI struct nd_ifinfo *nd6_ifattach(struct ifnet *); 34889856f7eSBjoern A. Zeeb void nd6_ifdetach(struct ifnet *, struct nd_ifinfo *); 349f0316e1aSAlexander V. Chernikov int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *); 3506f56329aSXin LI void nd6_option_init(void *, int, union nd_opts *); 3516f56329aSXin LI struct nd_opt_hdr *nd6_option(union nd_opts *); 3526f56329aSXin LI int nd6_options(union nd_opts *); 353f0316e1aSAlexander V. Chernikov struct llentry *nd6_lookup(const struct in6_addr *, int, struct ifnet *); 3546f56329aSXin LI void nd6_setmtu(struct ifnet *); 355aa5f023eSAlexander V. Chernikov void nd6_llinfo_setstate(struct llentry *lle, int newstate); 3566f56329aSXin LI void nd6_timer(void *); 3576f56329aSXin LI void nd6_purge(struct ifnet *); 3584fb3a820SAlexander V. Chernikov int nd6_resolve_addr(struct ifnet *ifp, int flags, const struct sockaddr *dst, 3594fb3a820SAlexander V. Chernikov char *desten, uint32_t *pflags); 3601fe201c3SAlexander V. Chernikov int nd6_resolve(struct ifnet *, int, struct mbuf *, 3616d768226SGeorge V. Neville-Neil const struct sockaddr *, u_char *, uint32_t *, struct llentry **); 3626f56329aSXin LI int nd6_ioctl(u_long, caddr_t, struct ifnet *); 3630e2dcee6SAlexander V. Chernikov void nd6_cache_lladdr(struct ifnet *, struct in6_addr *, 3646f56329aSXin LI char *, int, int, int); 3650b79b007SAlexander V. Chernikov bool nd6_try_set_entry_addr(struct ifnet *ifp, struct llentry *lle, char *lladdr); 3668482aa77SAlexander V. Chernikov struct mbuf *nd6_grab_holdchain(struct llentry *); 3678482aa77SAlexander V. Chernikov int nd6_flush_holdchain(struct ifnet *, struct llentry *, struct mbuf *); 368c541bd36SAlexander V. Chernikov void nd6_flush_children_holdchain(struct ifnet *, struct llentry *); 369f6b84910SAlexander V. Chernikov int nd6_add_ifa_lle(struct in6_ifaddr *); 3703e7a2321SAlexander V. Chernikov void nd6_rem_ifa_lle(struct in6_ifaddr *, int); 3711fe201c3SAlexander V. Chernikov int nd6_output_ifp(struct ifnet *, struct ifnet *, struct mbuf *, 372637670e7SAlexander V. Chernikov struct sockaddr_in6 *, struct route *); 37382cd038dSYoshinobu Inoue 3744c7ba83fSAlexander V. Chernikov struct rib_head; 3754c7ba83fSAlexander V. Chernikov struct rib_cmd_info; 3764c7ba83fSAlexander V. Chernikov void nd6_subscription_cb(struct rib_head *rnh, struct rib_cmd_info *rc, 3774c7ba83fSAlexander V. Chernikov void *arg); 3784c7ba83fSAlexander V. Chernikov 37982cd038dSYoshinobu Inoue /* nd6_nbr.c */ 3806f56329aSXin LI void nd6_na_input(struct mbuf *, int, int); 3816f56329aSXin LI void nd6_na_output(struct ifnet *, const struct in6_addr *, 3826f56329aSXin LI const struct in6_addr *, u_long, int, struct sockaddr *); 3836f56329aSXin LI void nd6_ns_input(struct mbuf *, int, int); 3846f56329aSXin LI void nd6_ns_output(struct ifnet *, const struct in6_addr *, 38526deb882SAlexander V. Chernikov const struct in6_addr *, const struct in6_addr *, uint8_t *); 3866f56329aSXin LI caddr_t nd6_ifptomac(struct ifnet *); 387d6ad6a86SMark Johnston void nd6_dad_init(void); 3886f56329aSXin LI void nd6_dad_start(struct ifaddr *, int); 3896f56329aSXin LI void nd6_dad_stop(struct ifaddr *); 39082cd038dSYoshinobu Inoue 39182cd038dSYoshinobu Inoue /* nd6_rtr.c */ 3926f56329aSXin LI void nd6_rs_input(struct mbuf *, int, int); 3936f56329aSXin LI void nd6_ra_input(struct mbuf *, int, int); 39430b45077SBjoern A. Zeeb void nd6_ifnet_link_event(void *, struct ifnet *, int); 395aaad3c4fSAlexander V. Chernikov struct nd_defrouter *defrouter_lookup(const struct in6_addr *, struct ifnet *); 396aaad3c4fSAlexander V. Chernikov struct nd_defrouter *defrouter_lookup_locked(const struct in6_addr *, 397aaad3c4fSAlexander V. Chernikov struct ifnet *); 3986f56329aSXin LI void defrouter_reset(void); 399559b4296SAlan Somers void defrouter_select_fib(int fibnum); 4004de485feSMark Johnston void defrouter_rele(struct nd_defrouter *); 401ff63037dSMark Johnston bool defrouter_remove(struct in6_addr *, struct ifnet *); 402ad675b32SBjoern A. Zeeb bool nd6_defrouter_list_empty(void); 403ad675b32SBjoern A. Zeeb void nd6_defrouter_flush_all(void); 404ad675b32SBjoern A. Zeeb void nd6_defrouter_purge(struct ifnet *); 405ad675b32SBjoern A. Zeeb void nd6_defrouter_timer(void); 406ad675b32SBjoern A. Zeeb void nd6_defrouter_init(void); 4076f56329aSXin LI int nd6_prelist_add(struct nd_prefixctl *, struct nd_defrouter *, 4086f56329aSXin LI struct nd_prefix **); 409d748f7efSMark Johnston void nd6_prefix_unlink(struct nd_prefix *, struct nd_prhead *); 410d748f7efSMark Johnston void nd6_prefix_del(struct nd_prefix *); 411d748f7efSMark Johnston void nd6_prefix_ref(struct nd_prefix *); 412d748f7efSMark Johnston void nd6_prefix_rele(struct nd_prefix *); 413d748f7efSMark Johnston int nd6_prefix_offlink(struct nd_prefix *); 4146f56329aSXin LI void pfxlist_onlink_check(void); 4156f56329aSXin LI struct nd_prefix *nd6_prefix_lookup(struct nd_prefixctl *); 4166f56329aSXin LI void rt6_flush(struct in6_addr *, struct ifnet *); 4176f56329aSXin LI int nd6_setdefaultiface(int); 4186f56329aSXin LI int in6_tmpifadd(const struct in6_ifaddr *, int, int); 41982cd038dSYoshinobu Inoue 42082cd038dSYoshinobu Inoue #endif /* _KERNEL */ 42182cd038dSYoshinobu Inoue 42282cd038dSYoshinobu Inoue #endif /* _NETINET6_ND6_H_ */ 423