nd6.h revision 1.91 1 1.91 roy /* $NetBSD: nd6.h,v 1.91 2020/09/11 15:03:33 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.91 roy #ifndef _KERNEL
40 1.91 roy /* Backwards compat */
41 1.91 roy #include <net/nd.h>
42 1.91 roy #define ND6_LLINFO_PURGE ND_LLINFO_PURGE
43 1.91 roy #define ND6_LLINFO_NOSTATE ND_LLINFO_NOSTATE
44 1.91 roy #define ND6_LLINFO_WAITDELETE ND_LLINFO_WAITDELETE
45 1.91 roy #define ND6_LLINFO_INCOMPLETE ND_LLINFO_INCOMPLETE
46 1.91 roy #define ND6_LLINFO_REACHABLE ND_LLINFO_REACHABLE
47 1.91 roy #define ND6_LLINFO_STALE ND_LLINFO_STALE
48 1.91 roy #define ND6_LLINFO_DELAY ND_LLINFO_DELAY
49 1.91 roy #define ND6_LLINFO_PROBE ND_LLINFO_PROBE
50 1.91 roy #endif
51 1.26 itojun
52 1.2 itojun struct nd_ifinfo {
53 1.89 roy uint8_t chlim; /* CurHopLimit */
54 1.89 roy uint32_t basereachable; /* BaseReachableTime */
55 1.89 roy uint32_t retrans; /* Retrans Timer */
56 1.89 roy uint32_t flags; /* Flags */
57 1.89 roy };
58 1.89 roy #ifdef _KERNEL
59 1.89 roy struct nd_kifinfo {
60 1.89 roy uint8_t chlim; /* CurHopLimit */
61 1.89 roy uint32_t basereachable; /* BaseReachableTime */
62 1.89 roy uint32_t retrans; /* Retrans Timer */
63 1.89 roy uint32_t flags; /* Flags */
64 1.6 itojun int recalctm; /* BaseReacable re-calculation timer */
65 1.89 roy uint32_t reachable; /* Reachable Time */
66 1.2 itojun };
67 1.89 roy #endif
68 1.12 itojun
69 1.53 dyoung #define ND6_IFF_PERFORMNUD 0x01
70 1.89 roy /* 0x02 was ND6_IFF_ACCEPT_RTADV */
71 1.53 dyoung #define ND6_IFF_PREFER_SOURCE 0x04 /* XXX: not related to ND. */
72 1.53 dyoung #define ND6_IFF_IFDISABLED 0x08 /* IPv6 operation is disabled due to
73 1.53 dyoung * DAD failure. (XXX: not ND-specific)
74 1.53 dyoung */
75 1.89 roy /* 0x10 was ND6_IFF_OVERRIDE_RTADV */
76 1.59 roy #define ND6_IFF_AUTO_LINKLOCAL 0x20
77 1.53 dyoung
78 1.26 itojun #ifdef _KERNEL
79 1.26 itojun #define ND_IFINFO(ifp) \
80 1.26 itojun (((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->nd_ifinfo)
81 1.26 itojun #endif
82 1.26 itojun
83 1.2 itojun struct in6_nbrinfo {
84 1.2 itojun char ifname[IFNAMSIZ]; /* if name, e.g. "en0" */
85 1.2 itojun struct in6_addr addr; /* IPv6 address of the neighbor */
86 1.2 itojun long asked; /* number of queries already sent for this addr */
87 1.2 itojun int isrouter; /* if it acts as a router */
88 1.2 itojun int state; /* reachability state */
89 1.2 itojun int expire; /* lifetime for NDP state transition */
90 1.2 itojun };
91 1.2 itojun
92 1.2 itojun struct in6_ndireq {
93 1.2 itojun char ifname[IFNAMSIZ];
94 1.2 itojun struct nd_ifinfo ndi;
95 1.2 itojun };
96 1.2 itojun
97 1.2 itojun /* protocol constants */
98 1.24 itojun #define MAX_RTR_SOLICITATION_DELAY 1 /* 1sec */
99 1.52 christos #define ND6_INFINITE_LIFETIME ((u_int32_t)~0)
100 1.2 itojun
101 1.2 itojun #ifdef _KERNEL
102 1.34 thorpej #include <sys/mallocvar.h>
103 1.34 thorpej MALLOC_DECLARE(M_IP6NDP);
104 1.2 itojun
105 1.2 itojun /* nd6.c */
106 1.2 itojun extern int nd6_prune;
107 1.2 itojun extern int nd6_useloopback;
108 1.17 itojun extern int nd6_debug;
109 1.17 itojun
110 1.91 roy extern struct nd_domain nd6_nd_domain;
111 1.91 roy
112 1.71 ozaki #define nd6log(level, fmt, args...) \
113 1.71 ozaki do { if (nd6_debug) log(level, "%s: " fmt, __func__, ##args);} while (0)
114 1.10 thorpej
115 1.81 ozaki extern krwlock_t nd6_lock;
116 1.81 ozaki
117 1.81 ozaki #define ND6_RLOCK() rw_enter(&nd6_lock, RW_READER)
118 1.81 ozaki #define ND6_WLOCK() rw_enter(&nd6_lock, RW_WRITER)
119 1.81 ozaki #define ND6_UNLOCK() rw_exit(&nd6_lock)
120 1.81 ozaki #define ND6_ASSERT_WLOCK() KASSERT(rw_write_held(&nd6_lock))
121 1.81 ozaki #define ND6_ASSERT_LOCK() KASSERT(rw_lock_held(&nd6_lock))
122 1.81 ozaki
123 1.2 itojun union nd_opts {
124 1.86 roy struct nd_opt_hdr *nd_opt_array[16]; /* max = ND_OPT_NONCE */
125 1.2 itojun struct {
126 1.2 itojun struct nd_opt_hdr *zero;
127 1.2 itojun struct nd_opt_hdr *src_lladdr;
128 1.2 itojun struct nd_opt_hdr *tgt_lladdr;
129 1.26 itojun struct nd_opt_prefix_info *pi_beg; /* multiple opts, start */
130 1.2 itojun struct nd_opt_rd_hdr *rh;
131 1.2 itojun struct nd_opt_mtu *mtu;
132 1.86 roy struct nd_opt_hdr *__res6;
133 1.86 roy struct nd_opt_hdr *__res7;
134 1.86 roy struct nd_opt_hdr *__res8;
135 1.86 roy struct nd_opt_hdr *__res9;
136 1.86 roy struct nd_opt_hdr *__res10;
137 1.86 roy struct nd_opt_hdr *__res11;
138 1.86 roy struct nd_opt_hdr *__res12;
139 1.86 roy struct nd_opt_hdr *__res13;
140 1.86 roy struct nd_opt_nonce *nonce;
141 1.86 roy struct nd_opt_hdr *__res15;
142 1.2 itojun struct nd_opt_hdr *search; /* multiple opts */
143 1.2 itojun struct nd_opt_hdr *last; /* multiple opts */
144 1.2 itojun int done;
145 1.2 itojun struct nd_opt_prefix_info *pi_end;/* multiple opts, end */
146 1.2 itojun } nd_opt_each;
147 1.2 itojun };
148 1.2 itojun #define nd_opts_src_lladdr nd_opt_each.src_lladdr
149 1.2 itojun #define nd_opts_tgt_lladdr nd_opt_each.tgt_lladdr
150 1.2 itojun #define nd_opts_pi nd_opt_each.pi_beg
151 1.2 itojun #define nd_opts_pi_end nd_opt_each.pi_end
152 1.2 itojun #define nd_opts_rh nd_opt_each.rh
153 1.2 itojun #define nd_opts_mtu nd_opt_each.mtu
154 1.86 roy #define nd_opts_nonce nd_opt_each.nonce
155 1.2 itojun #define nd_opts_search nd_opt_each.search
156 1.2 itojun #define nd_opts_last nd_opt_each.last
157 1.2 itojun #define nd_opts_done nd_opt_each.done
158 1.2 itojun
159 1.68 ozaki #include <net/if_llatbl.h>
160 1.68 ozaki
161 1.2 itojun /* XXX: need nd6_var.h?? */
162 1.2 itojun /* nd6.c */
163 1.45 dyoung void nd6_init(void);
164 1.88 ozaki void nd6_nbr_init(void);
165 1.89 roy struct nd_kifinfo *nd6_ifattach(struct ifnet *);
166 1.62 martin void nd6_ifdetach(struct ifnet *, struct in6_ifextra *);
167 1.43 dyoung int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *);
168 1.45 dyoung void nd6_option_init(void *, int, union nd_opts *);
169 1.45 dyoung int nd6_options(union nd_opts *);
170 1.72 ozaki struct llentry *nd6_lookup(const struct in6_addr *, const struct ifnet *, bool);
171 1.72 ozaki struct llentry *nd6_create(const struct in6_addr *, const struct ifnet *);
172 1.62 martin void nd6_purge(struct ifnet *, struct in6_ifextra *);
173 1.65 ozaki void nd6_nud_hint(struct rtentry *);
174 1.82 ozaki int nd6_resolve(struct ifnet *, const struct rtentry *, struct mbuf *,
175 1.82 ozaki const struct sockaddr *, uint8_t *, size_t);
176 1.51 dyoung void nd6_rtrequest(int, struct rtentry *, const struct rt_addrinfo *);
177 1.45 dyoung int nd6_ioctl(u_long, void *, struct ifnet *);
178 1.66 ozaki void nd6_cache_lladdr(struct ifnet *, struct in6_addr *,
179 1.45 dyoung char *, int, int, int);
180 1.45 dyoung int nd6_sysctl(int, void *, size_t *, void *, size_t);
181 1.45 dyoung int nd6_need_cache(struct ifnet *);
182 1.72 ozaki void nd6_llinfo_release_pkts(struct llentry *, struct ifnet *);
183 1.2 itojun
184 1.2 itojun /* nd6_nbr.c */
185 1.45 dyoung void nd6_na_input(struct mbuf *, int, int);
186 1.45 dyoung void nd6_na_output(struct ifnet *, const struct in6_addr *,
187 1.49 dyoung const struct in6_addr *, u_long, int, const struct sockaddr *);
188 1.45 dyoung void nd6_ns_input(struct mbuf *, int, int);
189 1.45 dyoung void nd6_ns_output(struct ifnet *, const struct in6_addr *,
190 1.90 roy const struct in6_addr *, const struct in6_addr *, const uint8_t *);
191 1.50 dyoung const void *nd6_ifptomac(const struct ifnet *);
192 1.45 dyoung void nd6_dad_start(struct ifaddr *, int);
193 1.45 dyoung void nd6_dad_stop(struct ifaddr *);
194 1.2 itojun
195 1.2 itojun /* nd6_rtr.c */
196 1.89 roy void nd6_rtr_cache(struct mbuf *, int, int, int);
197 1.2 itojun
198 1.2 itojun #endif /* _KERNEL */
199 1.2 itojun
200 1.40 elad #endif /* !_NETINET6_ND6_H_ */
201