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