1 /* $NetBSD: nd6.h,v 1.90 2020/08/20 11:01:02 roy Exp $ */ 2 /* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */ 3 4 /* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the project nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #ifndef _NETINET6_ND6_H_ 34 #define _NETINET6_ND6_H_ 35 36 #include <sys/queue.h> 37 #include <sys/callout.h> 38 39 #define ND6_LLINFO_PURGE -3 40 #define ND6_LLINFO_NOSTATE -2 41 #define ND6_LLINFO_WAITDELETE -1 42 #define ND6_LLINFO_INCOMPLETE 0 43 #define ND6_LLINFO_REACHABLE 1 44 #define ND6_LLINFO_STALE 2 45 #define ND6_LLINFO_DELAY 3 46 #define ND6_LLINFO_PROBE 4 47 48 #define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE) 49 #define ND6_LLINFO_PERMANENT(n) (((n)->ln_expire == 0) && ((n)->ln_state > ND6_LLINFO_INCOMPLETE)) 50 51 struct nd_ifinfo { 52 uint8_t chlim; /* CurHopLimit */ 53 uint32_t basereachable; /* BaseReachableTime */ 54 uint32_t retrans; /* Retrans Timer */ 55 uint32_t flags; /* Flags */ 56 }; 57 #ifdef _KERNEL 58 struct nd_kifinfo { 59 uint8_t chlim; /* CurHopLimit */ 60 uint32_t basereachable; /* BaseReachableTime */ 61 uint32_t retrans; /* Retrans Timer */ 62 uint32_t flags; /* Flags */ 63 int recalctm; /* BaseReacable re-calculation timer */ 64 uint32_t reachable; /* Reachable Time */ 65 }; 66 #endif 67 68 #define ND6_IFF_PERFORMNUD 0x01 69 /* 0x02 was ND6_IFF_ACCEPT_RTADV */ 70 #define ND6_IFF_PREFER_SOURCE 0x04 /* XXX: not related to ND. */ 71 #define ND6_IFF_IFDISABLED 0x08 /* IPv6 operation is disabled due to 72 * DAD failure. (XXX: not ND-specific) 73 */ 74 /* 0x10 was ND6_IFF_OVERRIDE_RTADV */ 75 #define ND6_IFF_AUTO_LINKLOCAL 0x20 76 77 #ifdef _KERNEL 78 #define ND_IFINFO(ifp) \ 79 (((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->nd_ifinfo) 80 #endif 81 82 struct in6_nbrinfo { 83 char ifname[IFNAMSIZ]; /* if name, e.g. "en0" */ 84 struct in6_addr addr; /* IPv6 address of the neighbor */ 85 long asked; /* number of queries already sent for this addr */ 86 int isrouter; /* if it acts as a router */ 87 int state; /* reachability state */ 88 int expire; /* lifetime for NDP state transition */ 89 }; 90 91 struct in6_ndireq { 92 char ifname[IFNAMSIZ]; 93 struct nd_ifinfo ndi; 94 }; 95 96 /* protocol constants */ 97 #define MAX_RTR_SOLICITATION_DELAY 1 /* 1sec */ 98 #define ND6_INFINITE_LIFETIME ((u_int32_t)~0) 99 100 #ifdef _KERNEL 101 /* node constants */ 102 #define MAX_REACHABLE_TIME 3600000 /* msec */ 103 #define REACHABLE_TIME 30000 /* msec */ 104 #define RETRANS_TIMER 1000 /* msec */ 105 #define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */ 106 #define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */ 107 #define ND_COMPUTE_RTIME(x) \ 108 (((MIN_RANDOM_FACTOR * (x >> 10)) + (cprng_fast32() & \ 109 ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000) 110 111 #include <sys/mallocvar.h> 112 MALLOC_DECLARE(M_IP6NDP); 113 114 /* nd6.c */ 115 extern int nd6_prune; 116 extern int nd6_delay; 117 extern int nd6_umaxtries; 118 extern int nd6_mmaxtries; 119 extern int nd6_useloopback; 120 extern int nd6_maxnudhint; 121 extern int nd6_gctimer; 122 extern int nd6_debug; 123 124 #define nd6log(level, fmt, args...) \ 125 do { if (nd6_debug) log(level, "%s: " fmt, __func__, ##args);} while (0) 126 127 extern krwlock_t nd6_lock; 128 129 #define ND6_RLOCK() rw_enter(&nd6_lock, RW_READER) 130 #define ND6_WLOCK() rw_enter(&nd6_lock, RW_WRITER) 131 #define ND6_UNLOCK() rw_exit(&nd6_lock) 132 #define ND6_ASSERT_WLOCK() KASSERT(rw_write_held(&nd6_lock)) 133 #define ND6_ASSERT_LOCK() KASSERT(rw_lock_held(&nd6_lock)) 134 135 union nd_opts { 136 struct nd_opt_hdr *nd_opt_array[16]; /* max = ND_OPT_NONCE */ 137 struct { 138 struct nd_opt_hdr *zero; 139 struct nd_opt_hdr *src_lladdr; 140 struct nd_opt_hdr *tgt_lladdr; 141 struct nd_opt_prefix_info *pi_beg; /* multiple opts, start */ 142 struct nd_opt_rd_hdr *rh; 143 struct nd_opt_mtu *mtu; 144 struct nd_opt_hdr *__res6; 145 struct nd_opt_hdr *__res7; 146 struct nd_opt_hdr *__res8; 147 struct nd_opt_hdr *__res9; 148 struct nd_opt_hdr *__res10; 149 struct nd_opt_hdr *__res11; 150 struct nd_opt_hdr *__res12; 151 struct nd_opt_hdr *__res13; 152 struct nd_opt_nonce *nonce; 153 struct nd_opt_hdr *__res15; 154 struct nd_opt_hdr *search; /* multiple opts */ 155 struct nd_opt_hdr *last; /* multiple opts */ 156 int done; 157 struct nd_opt_prefix_info *pi_end;/* multiple opts, end */ 158 } nd_opt_each; 159 }; 160 #define nd_opts_src_lladdr nd_opt_each.src_lladdr 161 #define nd_opts_tgt_lladdr nd_opt_each.tgt_lladdr 162 #define nd_opts_pi nd_opt_each.pi_beg 163 #define nd_opts_pi_end nd_opt_each.pi_end 164 #define nd_opts_rh nd_opt_each.rh 165 #define nd_opts_mtu nd_opt_each.mtu 166 #define nd_opts_nonce nd_opt_each.nonce 167 #define nd_opts_search nd_opt_each.search 168 #define nd_opts_last nd_opt_each.last 169 #define nd_opts_done nd_opt_each.done 170 171 #include <net/if_llatbl.h> 172 173 /* XXX: need nd6_var.h?? */ 174 /* nd6.c */ 175 void nd6_init(void); 176 void nd6_nbr_init(void); 177 struct nd_kifinfo *nd6_ifattach(struct ifnet *); 178 void nd6_ifdetach(struct ifnet *, struct in6_ifextra *); 179 int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *); 180 void nd6_option_init(void *, int, union nd_opts *); 181 int nd6_options(union nd_opts *); 182 struct llentry *nd6_lookup(const struct in6_addr *, const struct ifnet *, bool); 183 struct llentry *nd6_create(const struct in6_addr *, const struct ifnet *); 184 void nd6_llinfo_settimer(struct llentry *, time_t); 185 void nd6_purge(struct ifnet *, struct in6_ifextra *); 186 void nd6_nud_hint(struct rtentry *); 187 int nd6_resolve(struct ifnet *, const struct rtentry *, struct mbuf *, 188 const struct sockaddr *, uint8_t *, size_t); 189 void nd6_rtrequest(int, struct rtentry *, const struct rt_addrinfo *); 190 int nd6_ioctl(u_long, void *, struct ifnet *); 191 void nd6_cache_lladdr(struct ifnet *, struct in6_addr *, 192 char *, int, int, int); 193 int nd6_sysctl(int, void *, size_t *, void *, size_t); 194 int nd6_need_cache(struct ifnet *); 195 void nd6_llinfo_release_pkts(struct llentry *, struct ifnet *); 196 197 /* nd6_nbr.c */ 198 void nd6_na_input(struct mbuf *, int, int); 199 void nd6_na_output(struct ifnet *, const struct in6_addr *, 200 const struct in6_addr *, u_long, int, const struct sockaddr *); 201 void nd6_ns_input(struct mbuf *, int, int); 202 void nd6_ns_output(struct ifnet *, const struct in6_addr *, 203 const struct in6_addr *, const struct in6_addr *, const uint8_t *); 204 const void *nd6_ifptomac(const struct ifnet *); 205 void nd6_dad_start(struct ifaddr *, int); 206 void nd6_dad_stop(struct ifaddr *); 207 208 /* nd6_rtr.c */ 209 void nd6_rtr_cache(struct mbuf *, int, int, int); 210 211 #endif /* _KERNEL */ 212 213 #endif /* !_NETINET6_ND6_H_ */ 214