| @@ -1,2381 +1,2381 @@ | | | @@ -1,2381 +1,2381 @@ |
1 | /* $NetBSD: nd6.c,v 1.143 2012/06/23 03:14:04 christos Exp $ */ | | 1 | /* $NetBSD: nd6.c,v 1.144 2013/01/24 14:23:09 joerg Exp $ */ |
2 | /* $KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $ */ | | 2 | /* $KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | | 15 | * documentation and/or other materials provided with the distribution. |
16 | * 3. Neither the name of the project nor the names of its contributors | | 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 | | 17 | * may be used to endorse or promote products derived from this software |
18 | * without specific prior written permission. | | 18 | * without specific prior written permission. |
19 | * | | 19 | * |
20 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | | 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 | | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 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 | | 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 | | 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 | | 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | * SUCH DAMAGE. | | 30 | * SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | __KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.143 2012/06/23 03:14:04 christos Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.144 2013/01/24 14:23:09 joerg Exp $"); |
35 | | | 35 | |
36 | #include "opt_ipsec.h" | | 36 | #include "opt_ipsec.h" |
37 | | | 37 | |
38 | #include <sys/param.h> | | 38 | #include <sys/param.h> |
39 | #include <sys/systm.h> | | 39 | #include <sys/systm.h> |
40 | #include <sys/callout.h> | | 40 | #include <sys/callout.h> |
41 | #include <sys/malloc.h> | | 41 | #include <sys/malloc.h> |
42 | #include <sys/mbuf.h> | | 42 | #include <sys/mbuf.h> |
43 | #include <sys/socket.h> | | 43 | #include <sys/socket.h> |
44 | #include <sys/socketvar.h> | | 44 | #include <sys/socketvar.h> |
45 | #include <sys/sockio.h> | | 45 | #include <sys/sockio.h> |
46 | #include <sys/time.h> | | 46 | #include <sys/time.h> |
47 | #include <sys/kernel.h> | | 47 | #include <sys/kernel.h> |
48 | #include <sys/protosw.h> | | 48 | #include <sys/protosw.h> |
49 | #include <sys/errno.h> | | 49 | #include <sys/errno.h> |
50 | #include <sys/ioctl.h> | | 50 | #include <sys/ioctl.h> |
51 | #include <sys/syslog.h> | | 51 | #include <sys/syslog.h> |
52 | #include <sys/queue.h> | | 52 | #include <sys/queue.h> |
53 | #include <sys/cprng.h> | | 53 | #include <sys/cprng.h> |
54 | | | 54 | |
55 | #include <net/if.h> | | 55 | #include <net/if.h> |
56 | #include <net/if_dl.h> | | 56 | #include <net/if_dl.h> |
57 | #include <net/if_types.h> | | 57 | #include <net/if_types.h> |
58 | #include <net/route.h> | | 58 | #include <net/route.h> |
59 | #include <net/if_ether.h> | | 59 | #include <net/if_ether.h> |
60 | #include <net/if_fddi.h> | | 60 | #include <net/if_fddi.h> |
61 | #include <net/if_arc.h> | | 61 | #include <net/if_arc.h> |
62 | | | 62 | |
63 | #include <netinet/in.h> | | 63 | #include <netinet/in.h> |
64 | #include <netinet6/in6_var.h> | | 64 | #include <netinet6/in6_var.h> |
65 | #include <netinet/ip6.h> | | 65 | #include <netinet/ip6.h> |
66 | #include <netinet6/ip6_var.h> | | 66 | #include <netinet6/ip6_var.h> |
67 | #include <netinet6/scope6_var.h> | | 67 | #include <netinet6/scope6_var.h> |
68 | #include <netinet6/nd6.h> | | 68 | #include <netinet6/nd6.h> |
69 | #include <netinet/icmp6.h> | | 69 | #include <netinet/icmp6.h> |
70 | #include <netinet6/icmp6_private.h> | | 70 | #include <netinet6/icmp6_private.h> |
71 | | | 71 | |
72 | #include <net/net_osdep.h> | | 72 | #include <net/net_osdep.h> |
73 | | | 73 | |
74 | #define ND6_SLOWTIMER_INTERVAL (60 * 60) /* 1 hour */ | | 74 | #define ND6_SLOWTIMER_INTERVAL (60 * 60) /* 1 hour */ |
75 | #define ND6_RECALC_REACHTM_INTERVAL (60 * 120) /* 2 hours */ | | 75 | #define ND6_RECALC_REACHTM_INTERVAL (60 * 120) /* 2 hours */ |
76 | | | 76 | |
77 | /* timer values */ | | 77 | /* timer values */ |
78 | int nd6_prune = 1; /* walk list every 1 seconds */ | | 78 | int nd6_prune = 1; /* walk list every 1 seconds */ |
79 | int nd6_delay = 5; /* delay first probe time 5 second */ | | 79 | int nd6_delay = 5; /* delay first probe time 5 second */ |
80 | int nd6_umaxtries = 3; /* maximum unicast query */ | | 80 | int nd6_umaxtries = 3; /* maximum unicast query */ |
81 | int nd6_mmaxtries = 3; /* maximum multicast query */ | | 81 | int nd6_mmaxtries = 3; /* maximum multicast query */ |
82 | int nd6_useloopback = 1; /* use loopback interface for local traffic */ | | 82 | int nd6_useloopback = 1; /* use loopback interface for local traffic */ |
83 | int nd6_gctimer = (60 * 60 * 24); /* 1 day: garbage collection timer */ | | 83 | int nd6_gctimer = (60 * 60 * 24); /* 1 day: garbage collection timer */ |
84 | | | 84 | |
85 | /* preventing too many loops in ND option parsing */ | | 85 | /* preventing too many loops in ND option parsing */ |
86 | int nd6_maxndopt = 10; /* max # of ND options allowed */ | | 86 | int nd6_maxndopt = 10; /* max # of ND options allowed */ |
87 | | | 87 | |
88 | int nd6_maxnudhint = 0; /* max # of subsequent upper layer hints */ | | 88 | int nd6_maxnudhint = 0; /* max # of subsequent upper layer hints */ |
89 | | | 89 | |
90 | int nd6_maxqueuelen = 1; /* max # of packets cached in unresolved ND entries */ | | 90 | int nd6_maxqueuelen = 1; /* max # of packets cached in unresolved ND entries */ |
91 | | | 91 | |
92 | #ifdef ND6_DEBUG | | 92 | #ifdef ND6_DEBUG |
93 | int nd6_debug = 1; | | 93 | int nd6_debug = 1; |
94 | #else | | 94 | #else |
95 | int nd6_debug = 0; | | 95 | int nd6_debug = 0; |
96 | #endif | | 96 | #endif |
97 | | | 97 | |
98 | /* for debugging? */ | | 98 | /* for debugging? */ |
99 | static int nd6_inuse, nd6_allocated; | | 99 | static int nd6_inuse, nd6_allocated; |
100 | | | 100 | |
101 | struct llinfo_nd6 llinfo_nd6 = { | | 101 | struct llinfo_nd6 llinfo_nd6 = { |
102 | .ln_prev = &llinfo_nd6, | | 102 | .ln_prev = &llinfo_nd6, |
103 | .ln_next = &llinfo_nd6, | | 103 | .ln_next = &llinfo_nd6, |
104 | }; | | 104 | }; |
105 | struct nd_drhead nd_defrouter; | | 105 | struct nd_drhead nd_defrouter; |
106 | struct nd_prhead nd_prefix = { 0 }; | | 106 | struct nd_prhead nd_prefix = { 0 }; |
107 | | | 107 | |
108 | int nd6_recalc_reachtm_interval = ND6_RECALC_REACHTM_INTERVAL; | | 108 | int nd6_recalc_reachtm_interval = ND6_RECALC_REACHTM_INTERVAL; |
109 | static const struct sockaddr_in6 all1_sa = { | | 109 | static const struct sockaddr_in6 all1_sa = { |
110 | .sin6_family = AF_INET6 | | 110 | .sin6_family = AF_INET6 |
111 | , .sin6_len = sizeof(struct sockaddr_in6) | | 111 | , .sin6_len = sizeof(struct sockaddr_in6) |
112 | , .sin6_addr = {.s6_addr = {0xff, 0xff, 0xff, 0xff, | | 112 | , .sin6_addr = {.s6_addr = {0xff, 0xff, 0xff, 0xff, |
113 | 0xff, 0xff, 0xff, 0xff, | | 113 | 0xff, 0xff, 0xff, 0xff, |
114 | 0xff, 0xff, 0xff, 0xff, | | 114 | 0xff, 0xff, 0xff, 0xff, |
115 | 0xff, 0xff, 0xff, 0xff}} | | 115 | 0xff, 0xff, 0xff, 0xff}} |
116 | }; | | 116 | }; |
117 | | | 117 | |
118 | static void nd6_setmtu0(struct ifnet *, struct nd_ifinfo *); | | 118 | static void nd6_setmtu0(struct ifnet *, struct nd_ifinfo *); |
119 | static void nd6_slowtimo(void *); | | 119 | static void nd6_slowtimo(void *); |
120 | static int regen_tmpaddr(struct in6_ifaddr *); | | 120 | static int regen_tmpaddr(struct in6_ifaddr *); |
121 | static struct llinfo_nd6 *nd6_free(struct rtentry *, int); | | 121 | static struct llinfo_nd6 *nd6_free(struct rtentry *, int); |
122 | static void nd6_llinfo_timer(void *); | | 122 | static void nd6_llinfo_timer(void *); |
123 | static void clear_llinfo_pqueue(struct llinfo_nd6 *); | | 123 | static void clear_llinfo_pqueue(struct llinfo_nd6 *); |
124 | | | 124 | |
125 | callout_t nd6_slowtimo_ch; | | 125 | callout_t nd6_slowtimo_ch; |
126 | callout_t nd6_timer_ch; | | 126 | callout_t nd6_timer_ch; |
127 | extern callout_t in6_tmpaddrtimer_ch; | | 127 | extern callout_t in6_tmpaddrtimer_ch; |
128 | | | 128 | |
129 | static int fill_drlist(void *, size_t *, size_t); | | 129 | static int fill_drlist(void *, size_t *, size_t); |
130 | static int fill_prlist(void *, size_t *, size_t); | | 130 | static int fill_prlist(void *, size_t *, size_t); |
131 | | | 131 | |
132 | MALLOC_DEFINE(M_IP6NDP, "NDP", "IPv6 Neighbour Discovery"); | | 132 | MALLOC_DEFINE(M_IP6NDP, "NDP", "IPv6 Neighbour Discovery"); |
133 | | | 133 | |
134 | #define LN_DEQUEUE(ln) do { \ | | 134 | #define LN_DEQUEUE(ln) do { \ |
135 | (ln)->ln_next->ln_prev = (ln)->ln_prev; \ | | 135 | (ln)->ln_next->ln_prev = (ln)->ln_prev; \ |
136 | (ln)->ln_prev->ln_next = (ln)->ln_next; \ | | 136 | (ln)->ln_prev->ln_next = (ln)->ln_next; \ |
137 | } while (/*CONSTCOND*/0) | | 137 | } while (/*CONSTCOND*/0) |
138 | #define LN_INSERTHEAD(ln) do { \ | | 138 | #define LN_INSERTHEAD(ln) do { \ |
139 | (ln)->ln_next = llinfo_nd6.ln_next; \ | | 139 | (ln)->ln_next = llinfo_nd6.ln_next; \ |
140 | llinfo_nd6.ln_next = (ln); \ | | 140 | llinfo_nd6.ln_next = (ln); \ |
141 | (ln)->ln_prev = &llinfo_nd6; \ | | 141 | (ln)->ln_prev = &llinfo_nd6; \ |
142 | (ln)->ln_next->ln_prev = (ln); \ | | 142 | (ln)->ln_next->ln_prev = (ln); \ |
143 | } while (/*CONSTCOND*/0) | | 143 | } while (/*CONSTCOND*/0) |
144 | void | | 144 | void |
145 | nd6_init(void) | | 145 | nd6_init(void) |
146 | { | | 146 | { |
147 | static int nd6_init_done = 0; | | 147 | static int nd6_init_done = 0; |
148 | | | 148 | |
149 | if (nd6_init_done) { | | 149 | if (nd6_init_done) { |
150 | log(LOG_NOTICE, "nd6_init called more than once(ignored)\n"); | | 150 | log(LOG_NOTICE, "nd6_init called more than once(ignored)\n"); |
151 | return; | | 151 | return; |
152 | } | | 152 | } |
153 | | | 153 | |
154 | /* initialization of the default router list */ | | 154 | /* initialization of the default router list */ |
155 | TAILQ_INIT(&nd_defrouter); | | 155 | TAILQ_INIT(&nd_defrouter); |
156 | | | 156 | |
157 | nd6_init_done = 1; | | 157 | nd6_init_done = 1; |
158 | | | 158 | |
159 | callout_init(&nd6_slowtimo_ch, CALLOUT_MPSAFE); | | 159 | callout_init(&nd6_slowtimo_ch, CALLOUT_MPSAFE); |
160 | callout_init(&nd6_timer_ch, CALLOUT_MPSAFE); | | 160 | callout_init(&nd6_timer_ch, CALLOUT_MPSAFE); |
161 | | | 161 | |
162 | /* start timer */ | | 162 | /* start timer */ |
163 | callout_reset(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz, | | 163 | callout_reset(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz, |
164 | nd6_slowtimo, NULL); | | 164 | nd6_slowtimo, NULL); |
165 | } | | 165 | } |
166 | | | 166 | |
167 | struct nd_ifinfo * | | 167 | struct nd_ifinfo * |
168 | nd6_ifattach(struct ifnet *ifp) | | 168 | nd6_ifattach(struct ifnet *ifp) |
169 | { | | 169 | { |
170 | struct nd_ifinfo *nd; | | 170 | struct nd_ifinfo *nd; |
171 | | | 171 | |
172 | nd = (struct nd_ifinfo *)malloc(sizeof(*nd), M_IP6NDP, M_WAITOK|M_ZERO); | | 172 | nd = (struct nd_ifinfo *)malloc(sizeof(*nd), M_IP6NDP, M_WAITOK|M_ZERO); |
173 | | | 173 | |
174 | nd->initialized = 1; | | 174 | nd->initialized = 1; |
175 | | | 175 | |
176 | nd->chlim = IPV6_DEFHLIM; | | 176 | nd->chlim = IPV6_DEFHLIM; |
177 | nd->basereachable = REACHABLE_TIME; | | 177 | nd->basereachable = REACHABLE_TIME; |
178 | nd->reachable = ND_COMPUTE_RTIME(nd->basereachable); | | 178 | nd->reachable = ND_COMPUTE_RTIME(nd->basereachable); |
179 | nd->retrans = RETRANS_TIMER; | | 179 | nd->retrans = RETRANS_TIMER; |
180 | /* | | 180 | /* |
181 | * Note that the default value of ip6_accept_rtadv is 0. | | 181 | * Note that the default value of ip6_accept_rtadv is 0. |
182 | * Because we do not set ND6_IFF_OVERRIDE_RTADV here, we won't | | 182 | * Because we do not set ND6_IFF_OVERRIDE_RTADV here, we won't |
183 | * accept RAs by default. | | 183 | * accept RAs by default. |
184 | */ | | 184 | */ |
185 | nd->flags = ND6_IFF_PERFORMNUD | ND6_IFF_ACCEPT_RTADV; | | 185 | nd->flags = ND6_IFF_PERFORMNUD | ND6_IFF_ACCEPT_RTADV; |
186 | | | 186 | |
187 | /* XXX: we cannot call nd6_setmtu since ifp is not fully initialized */ | | 187 | /* XXX: we cannot call nd6_setmtu since ifp is not fully initialized */ |
188 | nd6_setmtu0(ifp, nd); | | 188 | nd6_setmtu0(ifp, nd); |
189 | | | 189 | |
190 | return nd; | | 190 | return nd; |
191 | } | | 191 | } |
192 | | | 192 | |
193 | void | | 193 | void |
194 | nd6_ifdetach(struct nd_ifinfo *nd) | | 194 | nd6_ifdetach(struct nd_ifinfo *nd) |
195 | { | | 195 | { |
196 | | | 196 | |
197 | free(nd, M_IP6NDP); | | 197 | free(nd, M_IP6NDP); |
198 | } | | 198 | } |
199 | | | 199 | |
200 | void | | 200 | void |
201 | nd6_setmtu(struct ifnet *ifp) | | 201 | nd6_setmtu(struct ifnet *ifp) |
202 | { | | 202 | { |
203 | nd6_setmtu0(ifp, ND_IFINFO(ifp)); | | 203 | nd6_setmtu0(ifp, ND_IFINFO(ifp)); |
204 | } | | 204 | } |
205 | | | 205 | |
206 | void | | 206 | void |
207 | nd6_setmtu0(struct ifnet *ifp, struct nd_ifinfo *ndi) | | 207 | nd6_setmtu0(struct ifnet *ifp, struct nd_ifinfo *ndi) |
208 | { | | 208 | { |
209 | u_int32_t omaxmtu; | | 209 | u_int32_t omaxmtu; |
210 | | | 210 | |
211 | omaxmtu = ndi->maxmtu; | | 211 | omaxmtu = ndi->maxmtu; |
212 | | | 212 | |
213 | switch (ifp->if_type) { | | 213 | switch (ifp->if_type) { |
214 | case IFT_ARCNET: | | 214 | case IFT_ARCNET: |
215 | ndi->maxmtu = MIN(ARC_PHDS_MAXMTU, ifp->if_mtu); /* RFC2497 */ | | 215 | ndi->maxmtu = MIN(ARC_PHDS_MAXMTU, ifp->if_mtu); /* RFC2497 */ |
216 | break; | | 216 | break; |
217 | case IFT_FDDI: | | 217 | case IFT_FDDI: |
218 | ndi->maxmtu = MIN(FDDIIPMTU, ifp->if_mtu); | | 218 | ndi->maxmtu = MIN(FDDIIPMTU, ifp->if_mtu); |
219 | break; | | 219 | break; |
220 | default: | | 220 | default: |
221 | ndi->maxmtu = ifp->if_mtu; | | 221 | ndi->maxmtu = ifp->if_mtu; |
222 | break; | | 222 | break; |
223 | } | | 223 | } |
224 | | | 224 | |
225 | /* | | 225 | /* |
226 | * Decreasing the interface MTU under IPV6 minimum MTU may cause | | 226 | * Decreasing the interface MTU under IPV6 minimum MTU may cause |
227 | * undesirable situation. We thus notify the operator of the change | | 227 | * undesirable situation. We thus notify the operator of the change |
228 | * explicitly. The check for omaxmtu is necessary to restrict the | | 228 | * explicitly. The check for omaxmtu is necessary to restrict the |
229 | * log to the case of changing the MTU, not initializing it. | | 229 | * log to the case of changing the MTU, not initializing it. |
230 | */ | | 230 | */ |
231 | if (omaxmtu >= IPV6_MMTU && ndi->maxmtu < IPV6_MMTU) { | | 231 | if (omaxmtu >= IPV6_MMTU && ndi->maxmtu < IPV6_MMTU) { |
232 | log(LOG_NOTICE, "nd6_setmtu0: new link MTU on %s (%lu) is too" | | 232 | log(LOG_NOTICE, "nd6_setmtu0: new link MTU on %s (%lu) is too" |
233 | " small for IPv6 which needs %lu\n", | | 233 | " small for IPv6 which needs %lu\n", |
234 | if_name(ifp), (unsigned long)ndi->maxmtu, (unsigned long) | | 234 | if_name(ifp), (unsigned long)ndi->maxmtu, (unsigned long) |
235 | IPV6_MMTU); | | 235 | IPV6_MMTU); |
236 | } | | 236 | } |
237 | | | 237 | |
238 | if (ndi->maxmtu > in6_maxmtu) | | 238 | if (ndi->maxmtu > in6_maxmtu) |
239 | in6_setmaxmtu(); /* check all interfaces just in case */ | | 239 | in6_setmaxmtu(); /* check all interfaces just in case */ |
240 | } | | 240 | } |
241 | | | 241 | |
242 | void | | 242 | void |
243 | nd6_option_init(void *opt, int icmp6len, union nd_opts *ndopts) | | 243 | nd6_option_init(void *opt, int icmp6len, union nd_opts *ndopts) |
244 | { | | 244 | { |
245 | | | 245 | |
246 | memset(ndopts, 0, sizeof(*ndopts)); | | 246 | memset(ndopts, 0, sizeof(*ndopts)); |
247 | ndopts->nd_opts_search = (struct nd_opt_hdr *)opt; | | 247 | ndopts->nd_opts_search = (struct nd_opt_hdr *)opt; |
248 | ndopts->nd_opts_last | | 248 | ndopts->nd_opts_last |
249 | = (struct nd_opt_hdr *)(((u_char *)opt) + icmp6len); | | 249 | = (struct nd_opt_hdr *)(((u_char *)opt) + icmp6len); |
250 | | | 250 | |
251 | if (icmp6len == 0) { | | 251 | if (icmp6len == 0) { |
252 | ndopts->nd_opts_done = 1; | | 252 | ndopts->nd_opts_done = 1; |
253 | ndopts->nd_opts_search = NULL; | | 253 | ndopts->nd_opts_search = NULL; |
254 | } | | 254 | } |
255 | } | | 255 | } |
256 | | | 256 | |
257 | /* | | 257 | /* |
258 | * Take one ND option. | | 258 | * Take one ND option. |
259 | */ | | 259 | */ |
260 | struct nd_opt_hdr * | | 260 | struct nd_opt_hdr * |
261 | nd6_option(union nd_opts *ndopts) | | 261 | nd6_option(union nd_opts *ndopts) |
262 | { | | 262 | { |
263 | struct nd_opt_hdr *nd_opt; | | 263 | struct nd_opt_hdr *nd_opt; |
264 | int olen; | | 264 | int olen; |
265 | | | 265 | |
266 | if (ndopts == NULL) | | 266 | if (ndopts == NULL) |
267 | panic("ndopts == NULL in nd6_option"); | | 267 | panic("ndopts == NULL in nd6_option"); |
268 | if (ndopts->nd_opts_last == NULL) | | 268 | if (ndopts->nd_opts_last == NULL) |
269 | panic("uninitialized ndopts in nd6_option"); | | 269 | panic("uninitialized ndopts in nd6_option"); |
270 | if (ndopts->nd_opts_search == NULL) | | 270 | if (ndopts->nd_opts_search == NULL) |
271 | return NULL; | | 271 | return NULL; |
272 | if (ndopts->nd_opts_done) | | 272 | if (ndopts->nd_opts_done) |
273 | return NULL; | | 273 | return NULL; |
274 | | | 274 | |
275 | nd_opt = ndopts->nd_opts_search; | | 275 | nd_opt = ndopts->nd_opts_search; |
276 | | | 276 | |
277 | /* make sure nd_opt_len is inside the buffer */ | | 277 | /* make sure nd_opt_len is inside the buffer */ |
278 | if ((void *)&nd_opt->nd_opt_len >= (void *)ndopts->nd_opts_last) { | | 278 | if ((void *)&nd_opt->nd_opt_len >= (void *)ndopts->nd_opts_last) { |
279 | memset(ndopts, 0, sizeof(*ndopts)); | | 279 | memset(ndopts, 0, sizeof(*ndopts)); |
280 | return NULL; | | 280 | return NULL; |
281 | } | | 281 | } |
282 | | | 282 | |
283 | olen = nd_opt->nd_opt_len << 3; | | 283 | olen = nd_opt->nd_opt_len << 3; |
284 | if (olen == 0) { | | 284 | if (olen == 0) { |
285 | /* | | 285 | /* |
286 | * Message validation requires that all included | | 286 | * Message validation requires that all included |
287 | * options have a length that is greater than zero. | | 287 | * options have a length that is greater than zero. |
288 | */ | | 288 | */ |
289 | memset(ndopts, 0, sizeof(*ndopts)); | | 289 | memset(ndopts, 0, sizeof(*ndopts)); |
290 | return NULL; | | 290 | return NULL; |
291 | } | | 291 | } |
292 | | | 292 | |
293 | ndopts->nd_opts_search = (struct nd_opt_hdr *)((char *)nd_opt + olen); | | 293 | ndopts->nd_opts_search = (struct nd_opt_hdr *)((char *)nd_opt + olen); |
294 | if (ndopts->nd_opts_search > ndopts->nd_opts_last) { | | 294 | if (ndopts->nd_opts_search > ndopts->nd_opts_last) { |
295 | /* option overruns the end of buffer, invalid */ | | 295 | /* option overruns the end of buffer, invalid */ |
296 | memset(ndopts, 0, sizeof(*ndopts)); | | 296 | memset(ndopts, 0, sizeof(*ndopts)); |
297 | return NULL; | | 297 | return NULL; |
298 | } else if (ndopts->nd_opts_search == ndopts->nd_opts_last) { | | 298 | } else if (ndopts->nd_opts_search == ndopts->nd_opts_last) { |
299 | /* reached the end of options chain */ | | 299 | /* reached the end of options chain */ |
300 | ndopts->nd_opts_done = 1; | | 300 | ndopts->nd_opts_done = 1; |
301 | ndopts->nd_opts_search = NULL; | | 301 | ndopts->nd_opts_search = NULL; |
302 | } | | 302 | } |
303 | return nd_opt; | | 303 | return nd_opt; |
304 | } | | 304 | } |
305 | | | 305 | |
306 | /* | | 306 | /* |
307 | * Parse multiple ND options. | | 307 | * Parse multiple ND options. |
308 | * This function is much easier to use, for ND routines that do not need | | 308 | * This function is much easier to use, for ND routines that do not need |
309 | * multiple options of the same type. | | 309 | * multiple options of the same type. |
310 | */ | | 310 | */ |
311 | int | | 311 | int |
312 | nd6_options(union nd_opts *ndopts) | | 312 | nd6_options(union nd_opts *ndopts) |
313 | { | | 313 | { |
314 | struct nd_opt_hdr *nd_opt; | | 314 | struct nd_opt_hdr *nd_opt; |
315 | int i = 0; | | 315 | int i = 0; |
316 | | | 316 | |
317 | if (ndopts == NULL) | | 317 | if (ndopts == NULL) |
318 | panic("ndopts == NULL in nd6_options"); | | 318 | panic("ndopts == NULL in nd6_options"); |
319 | if (ndopts->nd_opts_last == NULL) | | 319 | if (ndopts->nd_opts_last == NULL) |
320 | panic("uninitialized ndopts in nd6_options"); | | 320 | panic("uninitialized ndopts in nd6_options"); |
321 | if (ndopts->nd_opts_search == NULL) | | 321 | if (ndopts->nd_opts_search == NULL) |
322 | return 0; | | 322 | return 0; |
323 | | | 323 | |
324 | while (1) { | | 324 | while (1) { |
325 | nd_opt = nd6_option(ndopts); | | 325 | nd_opt = nd6_option(ndopts); |
326 | if (nd_opt == NULL && ndopts->nd_opts_last == NULL) { | | 326 | if (nd_opt == NULL && ndopts->nd_opts_last == NULL) { |
327 | /* | | 327 | /* |
328 | * Message validation requires that all included | | 328 | * Message validation requires that all included |
329 | * options have a length that is greater than zero. | | 329 | * options have a length that is greater than zero. |
330 | */ | | 330 | */ |
331 | ICMP6_STATINC(ICMP6_STAT_ND_BADOPT); | | 331 | ICMP6_STATINC(ICMP6_STAT_ND_BADOPT); |
332 | memset(ndopts, 0, sizeof(*ndopts)); | | 332 | memset(ndopts, 0, sizeof(*ndopts)); |
333 | return -1; | | 333 | return -1; |
334 | } | | 334 | } |
335 | | | 335 | |
336 | if (nd_opt == NULL) | | 336 | if (nd_opt == NULL) |
337 | goto skip1; | | 337 | goto skip1; |
338 | | | 338 | |
339 | switch (nd_opt->nd_opt_type) { | | 339 | switch (nd_opt->nd_opt_type) { |
340 | case ND_OPT_SOURCE_LINKADDR: | | 340 | case ND_OPT_SOURCE_LINKADDR: |
341 | case ND_OPT_TARGET_LINKADDR: | | 341 | case ND_OPT_TARGET_LINKADDR: |
342 | case ND_OPT_MTU: | | 342 | case ND_OPT_MTU: |
343 | case ND_OPT_REDIRECTED_HEADER: | | 343 | case ND_OPT_REDIRECTED_HEADER: |
344 | if (ndopts->nd_opt_array[nd_opt->nd_opt_type]) { | | 344 | if (ndopts->nd_opt_array[nd_opt->nd_opt_type]) { |
345 | nd6log((LOG_INFO, | | 345 | nd6log((LOG_INFO, |
346 | "duplicated ND6 option found (type=%d)\n", | | 346 | "duplicated ND6 option found (type=%d)\n", |
347 | nd_opt->nd_opt_type)); | | 347 | nd_opt->nd_opt_type)); |
348 | /* XXX bark? */ | | 348 | /* XXX bark? */ |
349 | } else { | | 349 | } else { |
350 | ndopts->nd_opt_array[nd_opt->nd_opt_type] | | 350 | ndopts->nd_opt_array[nd_opt->nd_opt_type] |
351 | = nd_opt; | | 351 | = nd_opt; |
352 | } | | 352 | } |
353 | break; | | 353 | break; |
354 | case ND_OPT_PREFIX_INFORMATION: | | 354 | case ND_OPT_PREFIX_INFORMATION: |
355 | if (ndopts->nd_opt_array[nd_opt->nd_opt_type] == 0) { | | 355 | if (ndopts->nd_opt_array[nd_opt->nd_opt_type] == 0) { |
356 | ndopts->nd_opt_array[nd_opt->nd_opt_type] | | 356 | ndopts->nd_opt_array[nd_opt->nd_opt_type] |
357 | = nd_opt; | | 357 | = nd_opt; |
358 | } | | 358 | } |
359 | ndopts->nd_opts_pi_end = | | 359 | ndopts->nd_opts_pi_end = |
360 | (struct nd_opt_prefix_info *)nd_opt; | | 360 | (struct nd_opt_prefix_info *)nd_opt; |
361 | break; | | 361 | break; |
362 | default: | | 362 | default: |
363 | /* | | 363 | /* |
364 | * Unknown options must be silently ignored, | | 364 | * Unknown options must be silently ignored, |
365 | * to accommodate future extension to the protocol. | | 365 | * to accommodate future extension to the protocol. |
366 | */ | | 366 | */ |
367 | nd6log((LOG_DEBUG, | | 367 | nd6log((LOG_DEBUG, |
368 | "nd6_options: unsupported option %d - " | | 368 | "nd6_options: unsupported option %d - " |
369 | "option ignored\n", nd_opt->nd_opt_type)); | | 369 | "option ignored\n", nd_opt->nd_opt_type)); |
370 | } | | 370 | } |
371 | | | 371 | |
372 | skip1: | | 372 | skip1: |
373 | i++; | | 373 | i++; |
374 | if (i > nd6_maxndopt) { | | 374 | if (i > nd6_maxndopt) { |
375 | ICMP6_STATINC(ICMP6_STAT_ND_TOOMANYOPT); | | 375 | ICMP6_STATINC(ICMP6_STAT_ND_TOOMANYOPT); |
376 | nd6log((LOG_INFO, "too many loop in nd opt\n")); | | 376 | nd6log((LOG_INFO, "too many loop in nd opt\n")); |
377 | break; | | 377 | break; |
378 | } | | 378 | } |
379 | | | 379 | |
380 | if (ndopts->nd_opts_done) | | 380 | if (ndopts->nd_opts_done) |
381 | break; | | 381 | break; |
382 | } | | 382 | } |
383 | | | 383 | |
384 | return 0; | | 384 | return 0; |
385 | } | | 385 | } |
386 | | | 386 | |
387 | /* | | 387 | /* |
388 | * ND6 timer routine to handle ND6 entries | | 388 | * ND6 timer routine to handle ND6 entries |
389 | */ | | 389 | */ |
390 | void | | 390 | void |
391 | nd6_llinfo_settimer(struct llinfo_nd6 *ln, long xtick) | | 391 | nd6_llinfo_settimer(struct llinfo_nd6 *ln, long xtick) |
392 | { | | 392 | { |
393 | int s; | | 393 | int s; |
394 | | | 394 | |
395 | s = splsoftnet(); | | 395 | s = splsoftnet(); |
396 | | | 396 | |
397 | if (xtick < 0) { | | 397 | if (xtick < 0) { |
398 | ln->ln_expire = 0; | | 398 | ln->ln_expire = 0; |
399 | ln->ln_ntick = 0; | | 399 | ln->ln_ntick = 0; |
400 | callout_stop(&ln->ln_timer_ch); | | 400 | callout_stop(&ln->ln_timer_ch); |
401 | } else { | | 401 | } else { |
402 | ln->ln_expire = time_second + xtick / hz; | | 402 | ln->ln_expire = time_second + xtick / hz; |
403 | if (xtick > INT_MAX) { | | 403 | if (xtick > INT_MAX) { |
404 | ln->ln_ntick = xtick - INT_MAX; | | 404 | ln->ln_ntick = xtick - INT_MAX; |
405 | callout_reset(&ln->ln_timer_ch, INT_MAX, | | 405 | callout_reset(&ln->ln_timer_ch, INT_MAX, |
406 | nd6_llinfo_timer, ln); | | 406 | nd6_llinfo_timer, ln); |
407 | } else { | | 407 | } else { |
408 | ln->ln_ntick = 0; | | 408 | ln->ln_ntick = 0; |
409 | callout_reset(&ln->ln_timer_ch, xtick, | | 409 | callout_reset(&ln->ln_timer_ch, xtick, |
410 | nd6_llinfo_timer, ln); | | 410 | nd6_llinfo_timer, ln); |
411 | } | | 411 | } |
412 | } | | 412 | } |
413 | | | 413 | |
414 | splx(s); | | 414 | splx(s); |
415 | } | | 415 | } |
416 | | | 416 | |
417 | static void | | 417 | static void |
418 | nd6_llinfo_timer(void *arg) | | 418 | nd6_llinfo_timer(void *arg) |
419 | { | | 419 | { |
420 | struct llinfo_nd6 *ln; | | 420 | struct llinfo_nd6 *ln; |
421 | struct rtentry *rt; | | 421 | struct rtentry *rt; |
422 | const struct sockaddr_in6 *dst; | | 422 | const struct sockaddr_in6 *dst; |
423 | struct ifnet *ifp; | | 423 | struct ifnet *ifp; |
424 | struct nd_ifinfo *ndi = NULL; | | 424 | struct nd_ifinfo *ndi = NULL; |
425 | | | 425 | |
426 | mutex_enter(softnet_lock); | | 426 | mutex_enter(softnet_lock); |
427 | KERNEL_LOCK(1, NULL); | | 427 | KERNEL_LOCK(1, NULL); |
428 | | | 428 | |
429 | ln = (struct llinfo_nd6 *)arg; | | 429 | ln = (struct llinfo_nd6 *)arg; |
430 | | | 430 | |
431 | if (ln->ln_ntick > 0) { | | 431 | if (ln->ln_ntick > 0) { |
432 | nd6_llinfo_settimer(ln, ln->ln_ntick); | | 432 | nd6_llinfo_settimer(ln, ln->ln_ntick); |
433 | KERNEL_UNLOCK_ONE(NULL); | | 433 | KERNEL_UNLOCK_ONE(NULL); |
434 | mutex_exit(softnet_lock); | | 434 | mutex_exit(softnet_lock); |
435 | return; | | 435 | return; |
436 | } | | 436 | } |
437 | | | 437 | |
438 | if ((rt = ln->ln_rt) == NULL) | | 438 | if ((rt = ln->ln_rt) == NULL) |
439 | panic("ln->ln_rt == NULL"); | | 439 | panic("ln->ln_rt == NULL"); |
440 | if ((ifp = rt->rt_ifp) == NULL) | | 440 | if ((ifp = rt->rt_ifp) == NULL) |
441 | panic("ln->ln_rt->rt_ifp == NULL"); | | 441 | panic("ln->ln_rt->rt_ifp == NULL"); |
442 | ndi = ND_IFINFO(ifp); | | 442 | ndi = ND_IFINFO(ifp); |
443 | dst = satocsin6(rt_getkey(rt)); | | 443 | dst = satocsin6(rt_getkey(rt)); |
444 | | | 444 | |
445 | /* sanity check */ | | 445 | /* sanity check */ |
446 | if (rt->rt_llinfo && (struct llinfo_nd6 *)rt->rt_llinfo != ln) | | 446 | if (rt->rt_llinfo && (struct llinfo_nd6 *)rt->rt_llinfo != ln) |
447 | panic("rt_llinfo(%p) is not equal to ln(%p)", | | 447 | panic("rt_llinfo(%p) is not equal to ln(%p)", |
448 | rt->rt_llinfo, ln); | | 448 | rt->rt_llinfo, ln); |
449 | if (!dst) | | 449 | if (!dst) |
450 | panic("dst=0 in nd6_timer(ln=%p)", ln); | | 450 | panic("dst=0 in nd6_timer(ln=%p)", ln); |
451 | | | 451 | |
452 | switch (ln->ln_state) { | | 452 | switch (ln->ln_state) { |
453 | case ND6_LLINFO_INCOMPLETE: | | 453 | case ND6_LLINFO_INCOMPLETE: |
454 | if (ln->ln_asked < nd6_mmaxtries) { | | 454 | if (ln->ln_asked < nd6_mmaxtries) { |
455 | ln->ln_asked++; | | 455 | ln->ln_asked++; |
456 | nd6_llinfo_settimer(ln, (long)ndi->retrans * hz / 1000); | | 456 | nd6_llinfo_settimer(ln, (long)ndi->retrans * hz / 1000); |
457 | nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0); | | 457 | nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0); |
458 | } else { | | 458 | } else { |
459 | struct mbuf *m = ln->ln_hold; | | 459 | struct mbuf *m = ln->ln_hold; |
460 | if (m) { | | 460 | if (m) { |
461 | struct mbuf *m0; | | 461 | struct mbuf *m0; |
462 | | | 462 | |
463 | /* | | 463 | /* |
464 | * assuming every packet in ln_hold has | | 464 | * assuming every packet in ln_hold has |
465 | * the same IP header | | 465 | * the same IP header |
466 | */ | | 466 | */ |
467 | m0 = m->m_nextpkt; | | 467 | m0 = m->m_nextpkt; |
468 | m->m_nextpkt = NULL; | | 468 | m->m_nextpkt = NULL; |
469 | icmp6_error2(m, ICMP6_DST_UNREACH, | | 469 | icmp6_error2(m, ICMP6_DST_UNREACH, |
470 | ICMP6_DST_UNREACH_ADDR, 0, rt->rt_ifp); | | 470 | ICMP6_DST_UNREACH_ADDR, 0, rt->rt_ifp); |
471 | | | 471 | |
472 | ln->ln_hold = m0; | | 472 | ln->ln_hold = m0; |
473 | clear_llinfo_pqueue(ln); | | 473 | clear_llinfo_pqueue(ln); |
474 | } | | 474 | } |
475 | (void)nd6_free(rt, 0); | | 475 | (void)nd6_free(rt, 0); |
476 | ln = NULL; | | 476 | ln = NULL; |
477 | } | | 477 | } |
478 | break; | | 478 | break; |
479 | case ND6_LLINFO_REACHABLE: | | 479 | case ND6_LLINFO_REACHABLE: |
480 | if (!ND6_LLINFO_PERMANENT(ln)) { | | 480 | if (!ND6_LLINFO_PERMANENT(ln)) { |
481 | ln->ln_state = ND6_LLINFO_STALE; | | 481 | ln->ln_state = ND6_LLINFO_STALE; |
482 | nd6_llinfo_settimer(ln, (long)nd6_gctimer * hz); | | 482 | nd6_llinfo_settimer(ln, (long)nd6_gctimer * hz); |
483 | } | | 483 | } |
484 | break; | | 484 | break; |
485 | | | 485 | |
486 | case ND6_LLINFO_PURGE: | | 486 | case ND6_LLINFO_PURGE: |
487 | case ND6_LLINFO_STALE: | | 487 | case ND6_LLINFO_STALE: |
488 | /* Garbage Collection(RFC 2461 5.3) */ | | 488 | /* Garbage Collection(RFC 2461 5.3) */ |
489 | if (!ND6_LLINFO_PERMANENT(ln)) { | | 489 | if (!ND6_LLINFO_PERMANENT(ln)) { |
490 | (void)nd6_free(rt, 1); | | 490 | (void)nd6_free(rt, 1); |
491 | ln = NULL; | | 491 | ln = NULL; |
492 | } | | 492 | } |
493 | break; | | 493 | break; |
494 | | | 494 | |
495 | case ND6_LLINFO_DELAY: | | 495 | case ND6_LLINFO_DELAY: |
496 | if (ndi && (ndi->flags & ND6_IFF_PERFORMNUD) != 0) { | | 496 | if (ndi && (ndi->flags & ND6_IFF_PERFORMNUD) != 0) { |
497 | /* We need NUD */ | | 497 | /* We need NUD */ |
498 | ln->ln_asked = 1; | | 498 | ln->ln_asked = 1; |
499 | ln->ln_state = ND6_LLINFO_PROBE; | | 499 | ln->ln_state = ND6_LLINFO_PROBE; |
500 | nd6_llinfo_settimer(ln, (long)ndi->retrans * hz / 1000); | | 500 | nd6_llinfo_settimer(ln, (long)ndi->retrans * hz / 1000); |
501 | nd6_ns_output(ifp, &dst->sin6_addr, | | 501 | nd6_ns_output(ifp, &dst->sin6_addr, |
502 | &dst->sin6_addr, ln, 0); | | 502 | &dst->sin6_addr, ln, 0); |
503 | } else { | | 503 | } else { |
504 | ln->ln_state = ND6_LLINFO_STALE; /* XXX */ | | 504 | ln->ln_state = ND6_LLINFO_STALE; /* XXX */ |
505 | nd6_llinfo_settimer(ln, (long)nd6_gctimer * hz); | | 505 | nd6_llinfo_settimer(ln, (long)nd6_gctimer * hz); |
506 | } | | 506 | } |
507 | break; | | 507 | break; |
508 | case ND6_LLINFO_PROBE: | | 508 | case ND6_LLINFO_PROBE: |
509 | if (ln->ln_asked < nd6_umaxtries) { | | 509 | if (ln->ln_asked < nd6_umaxtries) { |
510 | ln->ln_asked++; | | 510 | ln->ln_asked++; |
511 | nd6_llinfo_settimer(ln, (long)ndi->retrans * hz / 1000); | | 511 | nd6_llinfo_settimer(ln, (long)ndi->retrans * hz / 1000); |
512 | nd6_ns_output(ifp, &dst->sin6_addr, | | 512 | nd6_ns_output(ifp, &dst->sin6_addr, |
513 | &dst->sin6_addr, ln, 0); | | 513 | &dst->sin6_addr, ln, 0); |
514 | } else { | | 514 | } else { |
515 | (void)nd6_free(rt, 0); | | 515 | (void)nd6_free(rt, 0); |
516 | ln = NULL; | | 516 | ln = NULL; |
517 | } | | 517 | } |
518 | break; | | 518 | break; |
519 | } | | 519 | } |
520 | | | 520 | |
521 | KERNEL_UNLOCK_ONE(NULL); | | 521 | KERNEL_UNLOCK_ONE(NULL); |
522 | mutex_exit(softnet_lock); | | 522 | mutex_exit(softnet_lock); |
523 | } | | 523 | } |
524 | | | 524 | |
525 | /* | | 525 | /* |
526 | * ND6 timer routine to expire default route list and prefix list | | 526 | * ND6 timer routine to expire default route list and prefix list |
527 | */ | | 527 | */ |
528 | void | | 528 | void |
529 | nd6_timer(void *ignored_arg) | | 529 | nd6_timer(void *ignored_arg) |
530 | { | | 530 | { |
531 | struct nd_defrouter *next_dr, *dr; | | 531 | struct nd_defrouter *next_dr, *dr; |
532 | struct nd_prefix *next_pr, *pr; | | 532 | struct nd_prefix *next_pr, *pr; |
533 | struct in6_ifaddr *ia6, *nia6; | | 533 | struct in6_ifaddr *ia6, *nia6; |
534 | | | 534 | |
535 | callout_reset(&nd6_timer_ch, nd6_prune * hz, | | 535 | callout_reset(&nd6_timer_ch, nd6_prune * hz, |
536 | nd6_timer, NULL); | | 536 | nd6_timer, NULL); |
537 | | | 537 | |
538 | mutex_enter(softnet_lock); | | 538 | mutex_enter(softnet_lock); |
539 | KERNEL_LOCK(1, NULL); | | 539 | KERNEL_LOCK(1, NULL); |
540 | | | 540 | |
541 | /* expire default router list */ | | 541 | /* expire default router list */ |
542 | | | 542 | |
543 | TAILQ_FOREACH_SAFE(dr, &nd_defrouter, dr_entry, next_dr) { | | 543 | TAILQ_FOREACH_SAFE(dr, &nd_defrouter, dr_entry, next_dr) { |
544 | if (dr->expire && dr->expire < time_second) { | | 544 | if (dr->expire && dr->expire < time_second) { |
545 | defrtrlist_del(dr); | | 545 | defrtrlist_del(dr); |
546 | } | | 546 | } |
547 | } | | 547 | } |
548 | | | 548 | |
549 | /* | | 549 | /* |
550 | * expire interface addresses. | | 550 | * expire interface addresses. |
551 | * in the past the loop was inside prefix expiry processing. | | 551 | * in the past the loop was inside prefix expiry processing. |
552 | * However, from a stricter speci-confrmance standpoint, we should | | 552 | * However, from a stricter speci-confrmance standpoint, we should |
553 | * rather separate address lifetimes and prefix lifetimes. | | 553 | * rather separate address lifetimes and prefix lifetimes. |
554 | */ | | 554 | */ |
555 | addrloop: | | 555 | addrloop: |
556 | for (ia6 = in6_ifaddr; ia6; ia6 = nia6) { | | 556 | for (ia6 = in6_ifaddr; ia6; ia6 = nia6) { |
557 | nia6 = ia6->ia_next; | | 557 | nia6 = ia6->ia_next; |
558 | /* check address lifetime */ | | 558 | /* check address lifetime */ |
559 | if (IFA6_IS_INVALID(ia6)) { | | 559 | if (IFA6_IS_INVALID(ia6)) { |
560 | int regen = 0; | | 560 | int regen = 0; |
561 | | | 561 | |
562 | /* | | 562 | /* |
563 | * If the expiring address is temporary, try | | 563 | * If the expiring address is temporary, try |
564 | * regenerating a new one. This would be useful when | | 564 | * regenerating a new one. This would be useful when |
565 | * we suspended a laptop PC, then turned it on after a | | 565 | * we suspended a laptop PC, then turned it on after a |
566 | * period that could invalidate all temporary | | 566 | * period that could invalidate all temporary |
567 | * addresses. Although we may have to restart the | | 567 | * addresses. Although we may have to restart the |
568 | * loop (see below), it must be after purging the | | 568 | * loop (see below), it must be after purging the |
569 | * address. Otherwise, we'd see an infinite loop of | | 569 | * address. Otherwise, we'd see an infinite loop of |
570 | * regeneration. | | 570 | * regeneration. |
571 | */ | | 571 | */ |
572 | if (ip6_use_tempaddr && | | 572 | if (ip6_use_tempaddr && |
573 | (ia6->ia6_flags & IN6_IFF_TEMPORARY) != 0) { | | 573 | (ia6->ia6_flags & IN6_IFF_TEMPORARY) != 0) { |
574 | if (regen_tmpaddr(ia6) == 0) | | 574 | if (regen_tmpaddr(ia6) == 0) |
575 | regen = 1; | | 575 | regen = 1; |
576 | } | | 576 | } |
577 | | | 577 | |
578 | in6_purgeaddr(&ia6->ia_ifa); | | 578 | in6_purgeaddr(&ia6->ia_ifa); |
579 | | | 579 | |
580 | if (regen) | | 580 | if (regen) |
581 | goto addrloop; /* XXX: see below */ | | 581 | goto addrloop; /* XXX: see below */ |
582 | } else if (IFA6_IS_DEPRECATED(ia6)) { | | 582 | } else if (IFA6_IS_DEPRECATED(ia6)) { |
583 | int oldflags = ia6->ia6_flags; | | 583 | int oldflags = ia6->ia6_flags; |
584 | | | 584 | |
585 | ia6->ia6_flags |= IN6_IFF_DEPRECATED; | | 585 | ia6->ia6_flags |= IN6_IFF_DEPRECATED; |
586 | | | 586 | |
587 | /* | | 587 | /* |
588 | * If a temporary address has just become deprecated, | | 588 | * If a temporary address has just become deprecated, |
589 | * regenerate a new one if possible. | | 589 | * regenerate a new one if possible. |
590 | */ | | 590 | */ |
591 | if (ip6_use_tempaddr && | | 591 | if (ip6_use_tempaddr && |
592 | (ia6->ia6_flags & IN6_IFF_TEMPORARY) != 0 && | | 592 | (ia6->ia6_flags & IN6_IFF_TEMPORARY) != 0 && |
593 | (oldflags & IN6_IFF_DEPRECATED) == 0) { | | 593 | (oldflags & IN6_IFF_DEPRECATED) == 0) { |
594 | | | 594 | |
595 | if (regen_tmpaddr(ia6) == 0) { | | 595 | if (regen_tmpaddr(ia6) == 0) { |
596 | /* | | 596 | /* |
597 | * A new temporary address is | | 597 | * A new temporary address is |
598 | * generated. | | 598 | * generated. |
599 | * XXX: this means the address chain | | 599 | * XXX: this means the address chain |
600 | * has changed while we are still in | | 600 | * has changed while we are still in |
601 | * the loop. Although the change | | 601 | * the loop. Although the change |
602 | * would not cause disaster (because | | 602 | * would not cause disaster (because |
603 | * it's not a deletion, but an | | 603 | * it's not a deletion, but an |
604 | * addition,) we'd rather restart the | | 604 | * addition,) we'd rather restart the |
605 | * loop just for safety. Or does this | | 605 | * loop just for safety. Or does this |
606 | * significantly reduce performance?? | | 606 | * significantly reduce performance?? |
607 | */ | | 607 | */ |
608 | goto addrloop; | | 608 | goto addrloop; |
609 | } | | 609 | } |
610 | } | | 610 | } |
611 | } else { | | 611 | } else { |
612 | /* | | 612 | /* |
613 | * A new RA might have made a deprecated address | | 613 | * A new RA might have made a deprecated address |
614 | * preferred. | | 614 | * preferred. |
615 | */ | | 615 | */ |
616 | ia6->ia6_flags &= ~IN6_IFF_DEPRECATED; | | 616 | ia6->ia6_flags &= ~IN6_IFF_DEPRECATED; |
617 | } | | 617 | } |
618 | } | | 618 | } |
619 | | | 619 | |
620 | /* expire prefix list */ | | 620 | /* expire prefix list */ |
621 | LIST_FOREACH_SAFE(pr, &nd_prefix, ndpr_entry, next_pr) { | | 621 | LIST_FOREACH_SAFE(pr, &nd_prefix, ndpr_entry, next_pr) { |
622 | /* | | 622 | /* |
623 | * check prefix lifetime. | | 623 | * check prefix lifetime. |
624 | * since pltime is just for autoconf, pltime processing for | | 624 | * since pltime is just for autoconf, pltime processing for |
625 | * prefix is not necessary. | | 625 | * prefix is not necessary. |
626 | */ | | 626 | */ |
627 | if (pr->ndpr_vltime != ND6_INFINITE_LIFETIME && | | 627 | if (pr->ndpr_vltime != ND6_INFINITE_LIFETIME && |
628 | time_second - pr->ndpr_lastupdate > pr->ndpr_vltime) { | | 628 | time_second - pr->ndpr_lastupdate > pr->ndpr_vltime) { |
629 | | | 629 | |
630 | /* | | 630 | /* |
631 | * address expiration and prefix expiration are | | 631 | * address expiration and prefix expiration are |
632 | * separate. NEVER perform in6_purgeaddr here. | | 632 | * separate. NEVER perform in6_purgeaddr here. |
633 | */ | | 633 | */ |
634 | | | 634 | |
635 | prelist_remove(pr); | | 635 | prelist_remove(pr); |
636 | } | | 636 | } |
637 | } | | 637 | } |
638 | | | 638 | |
639 | KERNEL_UNLOCK_ONE(NULL); | | 639 | KERNEL_UNLOCK_ONE(NULL); |
640 | mutex_exit(softnet_lock); | | 640 | mutex_exit(softnet_lock); |
641 | } | | 641 | } |
642 | | | 642 | |
643 | /* ia6: deprecated/invalidated temporary address */ | | 643 | /* ia6: deprecated/invalidated temporary address */ |
644 | static int | | 644 | static int |
645 | regen_tmpaddr(struct in6_ifaddr *ia6) | | 645 | regen_tmpaddr(struct in6_ifaddr *ia6) |
646 | { | | 646 | { |
647 | struct ifaddr *ifa; | | 647 | struct ifaddr *ifa; |
648 | struct ifnet *ifp; | | 648 | struct ifnet *ifp; |
649 | struct in6_ifaddr *public_ifa6 = NULL; | | 649 | struct in6_ifaddr *public_ifa6 = NULL; |
650 | | | 650 | |
651 | ifp = ia6->ia_ifa.ifa_ifp; | | 651 | ifp = ia6->ia_ifa.ifa_ifp; |
652 | IFADDR_FOREACH(ifa, ifp) { | | 652 | IFADDR_FOREACH(ifa, ifp) { |
653 | struct in6_ifaddr *it6; | | 653 | struct in6_ifaddr *it6; |
654 | | | 654 | |
655 | if (ifa->ifa_addr->sa_family != AF_INET6) | | 655 | if (ifa->ifa_addr->sa_family != AF_INET6) |
656 | continue; | | 656 | continue; |
657 | | | 657 | |
658 | it6 = (struct in6_ifaddr *)ifa; | | 658 | it6 = (struct in6_ifaddr *)ifa; |
659 | | | 659 | |
660 | /* ignore no autoconf addresses. */ | | 660 | /* ignore no autoconf addresses. */ |
661 | if ((it6->ia6_flags & IN6_IFF_AUTOCONF) == 0) | | 661 | if ((it6->ia6_flags & IN6_IFF_AUTOCONF) == 0) |
662 | continue; | | 662 | continue; |
663 | | | 663 | |
664 | /* ignore autoconf addresses with different prefixes. */ | | 664 | /* ignore autoconf addresses with different prefixes. */ |
665 | if (it6->ia6_ndpr == NULL || it6->ia6_ndpr != ia6->ia6_ndpr) | | 665 | if (it6->ia6_ndpr == NULL || it6->ia6_ndpr != ia6->ia6_ndpr) |
666 | continue; | | 666 | continue; |
667 | | | 667 | |
668 | /* | | 668 | /* |
669 | * Now we are looking at an autoconf address with the same | | 669 | * Now we are looking at an autoconf address with the same |
670 | * prefix as ours. If the address is temporary and is still | | 670 | * prefix as ours. If the address is temporary and is still |
671 | * preferred, do not create another one. It would be rare, but | | 671 | * preferred, do not create another one. It would be rare, but |
672 | * could happen, for example, when we resume a laptop PC after | | 672 | * could happen, for example, when we resume a laptop PC after |
673 | * a long period. | | 673 | * a long period. |
674 | */ | | 674 | */ |
675 | if ((it6->ia6_flags & IN6_IFF_TEMPORARY) != 0 && | | 675 | if ((it6->ia6_flags & IN6_IFF_TEMPORARY) != 0 && |
676 | !IFA6_IS_DEPRECATED(it6)) { | | 676 | !IFA6_IS_DEPRECATED(it6)) { |
677 | public_ifa6 = NULL; | | 677 | public_ifa6 = NULL; |
678 | break; | | 678 | break; |
679 | } | | 679 | } |
680 | | | 680 | |
681 | /* | | 681 | /* |
682 | * This is a public autoconf address that has the same prefix | | 682 | * This is a public autoconf address that has the same prefix |
683 | * as ours. If it is preferred, keep it. We can't break the | | 683 | * as ours. If it is preferred, keep it. We can't break the |
684 | * loop here, because there may be a still-preferred temporary | | 684 | * loop here, because there may be a still-preferred temporary |
685 | * address with the prefix. | | 685 | * address with the prefix. |
686 | */ | | 686 | */ |
687 | if (!IFA6_IS_DEPRECATED(it6)) | | 687 | if (!IFA6_IS_DEPRECATED(it6)) |
688 | public_ifa6 = it6; | | 688 | public_ifa6 = it6; |
689 | } | | 689 | } |
690 | | | 690 | |
691 | if (public_ifa6 != NULL) { | | 691 | if (public_ifa6 != NULL) { |
692 | int e; | | 692 | int e; |
693 | | | 693 | |
694 | /* | | 694 | /* |
695 | * Random factor is introduced in the preferred lifetime, so | | 695 | * Random factor is introduced in the preferred lifetime, so |
696 | * we do not need additional delay (3rd arg to in6_tmpifadd). | | 696 | * we do not need additional delay (3rd arg to in6_tmpifadd). |
697 | */ | | 697 | */ |
698 | if ((e = in6_tmpifadd(public_ifa6, 0, 0)) != 0) { | | 698 | if ((e = in6_tmpifadd(public_ifa6, 0, 0)) != 0) { |
699 | log(LOG_NOTICE, "regen_tmpaddr: failed to create a new" | | 699 | log(LOG_NOTICE, "regen_tmpaddr: failed to create a new" |
700 | " tmp addr, errno=%d\n", e); | | 700 | " tmp addr, errno=%d\n", e); |
701 | return -1; | | 701 | return -1; |
702 | } | | 702 | } |
703 | return 0; | | 703 | return 0; |
704 | } | | 704 | } |
705 | | | 705 | |
706 | return -1; | | 706 | return -1; |
707 | } | | 707 | } |
708 | | | 708 | |
709 | bool | | 709 | bool |
710 | nd6_accepts_rtadv(const struct nd_ifinfo *ndi) | | 710 | nd6_accepts_rtadv(const struct nd_ifinfo *ndi) |
711 | { | | 711 | { |
712 | switch (ndi->flags & (ND6_IFF_ACCEPT_RTADV|ND6_IFF_OVERRIDE_RTADV)) { | | 712 | switch (ndi->flags & (ND6_IFF_ACCEPT_RTADV|ND6_IFF_OVERRIDE_RTADV)) { |
713 | case ND6_IFF_OVERRIDE_RTADV|ND6_IFF_ACCEPT_RTADV: | | 713 | case ND6_IFF_OVERRIDE_RTADV|ND6_IFF_ACCEPT_RTADV: |
714 | return true; | | 714 | return true; |
715 | case ND6_IFF_ACCEPT_RTADV: | | 715 | case ND6_IFF_ACCEPT_RTADV: |
716 | return ip6_accept_rtadv != 0; | | 716 | return ip6_accept_rtadv != 0; |
717 | case ND6_IFF_OVERRIDE_RTADV: | | 717 | case ND6_IFF_OVERRIDE_RTADV: |
718 | case 0: | | 718 | case 0: |
719 | default: | | 719 | default: |
720 | return false; | | 720 | return false; |
721 | } | | 721 | } |
722 | } | | 722 | } |
723 | | | 723 | |
724 | /* | | 724 | /* |
725 | * Nuke neighbor cache/prefix/default router management table, right before | | 725 | * Nuke neighbor cache/prefix/default router management table, right before |
726 | * ifp goes away. | | 726 | * ifp goes away. |
727 | */ | | 727 | */ |
728 | void | | 728 | void |
729 | nd6_purge(struct ifnet *ifp) | | 729 | nd6_purge(struct ifnet *ifp) |
730 | { | | 730 | { |
731 | struct llinfo_nd6 *ln, *nln; | | 731 | struct llinfo_nd6 *ln, *nln; |
732 | struct nd_defrouter *dr, *ndr; | | 732 | struct nd_defrouter *dr, *ndr; |
733 | struct nd_prefix *pr, *npr; | | 733 | struct nd_prefix *pr, *npr; |
734 | | | 734 | |
735 | /* | | 735 | /* |
736 | * Nuke default router list entries toward ifp. | | 736 | * Nuke default router list entries toward ifp. |
737 | * We defer removal of default router list entries that is installed | | 737 | * We defer removal of default router list entries that is installed |
738 | * in the routing table, in order to keep additional side effects as | | 738 | * in the routing table, in order to keep additional side effects as |
739 | * small as possible. | | 739 | * small as possible. |
740 | */ | | 740 | */ |
741 | TAILQ_FOREACH_SAFE(dr, &nd_defrouter, dr_entry, ndr) { | | 741 | TAILQ_FOREACH_SAFE(dr, &nd_defrouter, dr_entry, ndr) { |
742 | if (dr->installed) | | 742 | if (dr->installed) |
743 | continue; | | 743 | continue; |
744 | | | 744 | |
745 | if (dr->ifp == ifp) | | 745 | if (dr->ifp == ifp) |
746 | defrtrlist_del(dr); | | 746 | defrtrlist_del(dr); |
747 | } | | 747 | } |
748 | | | 748 | |
749 | TAILQ_FOREACH_SAFE(dr, &nd_defrouter, dr_entry, ndr) { | | 749 | TAILQ_FOREACH_SAFE(dr, &nd_defrouter, dr_entry, ndr) { |
750 | if (!dr->installed) | | 750 | if (!dr->installed) |
751 | continue; | | 751 | continue; |
752 | | | 752 | |
753 | if (dr->ifp == ifp) | | 753 | if (dr->ifp == ifp) |
754 | defrtrlist_del(dr); | | 754 | defrtrlist_del(dr); |
755 | } | | 755 | } |
756 | | | 756 | |
757 | /* Nuke prefix list entries toward ifp */ | | 757 | /* Nuke prefix list entries toward ifp */ |
758 | LIST_FOREACH_SAFE(pr, &nd_prefix, ndpr_entry, npr) { | | 758 | LIST_FOREACH_SAFE(pr, &nd_prefix, ndpr_entry, npr) { |
759 | if (pr->ndpr_ifp == ifp) { | | 759 | if (pr->ndpr_ifp == ifp) { |
760 | /* | | 760 | /* |
761 | * Because if_detach() does *not* release prefixes | | 761 | * Because if_detach() does *not* release prefixes |
762 | * while purging addresses the reference count will | | 762 | * while purging addresses the reference count will |
763 | * still be above zero. We therefore reset it to | | 763 | * still be above zero. We therefore reset it to |
764 | * make sure that the prefix really gets purged. | | 764 | * make sure that the prefix really gets purged. |
765 | */ | | 765 | */ |
766 | pr->ndpr_refcnt = 0; | | 766 | pr->ndpr_refcnt = 0; |
767 | /* | | 767 | /* |
768 | * Previously, pr->ndpr_addr is removed as well, | | 768 | * Previously, pr->ndpr_addr is removed as well, |
769 | * but I strongly believe we don't have to do it. | | 769 | * but I strongly believe we don't have to do it. |
770 | * nd6_purge() is only called from in6_ifdetach(), | | 770 | * nd6_purge() is only called from in6_ifdetach(), |
771 | * which removes all the associated interface addresses | | 771 | * which removes all the associated interface addresses |
772 | * by itself. | | 772 | * by itself. |
773 | * (jinmei@kame.net 20010129) | | 773 | * (jinmei@kame.net 20010129) |
774 | */ | | 774 | */ |
775 | prelist_remove(pr); | | 775 | prelist_remove(pr); |
776 | } | | 776 | } |
777 | } | | 777 | } |
778 | | | 778 | |
779 | /* cancel default outgoing interface setting */ | | 779 | /* cancel default outgoing interface setting */ |
780 | if (nd6_defifindex == ifp->if_index) | | 780 | if (nd6_defifindex == ifp->if_index) |
781 | nd6_setdefaultiface(0); | | 781 | nd6_setdefaultiface(0); |
782 | | | 782 | |
783 | /* XXX: too restrictive? */ | | 783 | /* XXX: too restrictive? */ |
784 | if (!ip6_forwarding && ifp->if_afdata[AF_INET6]) { | | 784 | if (!ip6_forwarding && ifp->if_afdata[AF_INET6]) { |
785 | struct nd_ifinfo *ndi = ND_IFINFO(ifp); | | 785 | struct nd_ifinfo *ndi = ND_IFINFO(ifp); |
786 | if (ndi && nd6_accepts_rtadv(ndi)) { | | 786 | if (ndi && nd6_accepts_rtadv(ndi)) { |
787 | /* refresh default router list */ | | 787 | /* refresh default router list */ |
788 | defrouter_select(); | | 788 | defrouter_select(); |
789 | } | | 789 | } |
790 | } | | 790 | } |
791 | | | 791 | |
792 | /* | | 792 | /* |
793 | * Nuke neighbor cache entries for the ifp. | | 793 | * Nuke neighbor cache entries for the ifp. |
794 | * Note that rt->rt_ifp may not be the same as ifp, | | 794 | * Note that rt->rt_ifp may not be the same as ifp, |
795 | * due to KAME goto ours hack. See RTM_RESOLVE case in | | 795 | * due to KAME goto ours hack. See RTM_RESOLVE case in |
796 | * nd6_rtrequest(), and ip6_input(). | | 796 | * nd6_rtrequest(), and ip6_input(). |
797 | */ | | 797 | */ |
798 | ln = llinfo_nd6.ln_next; | | 798 | ln = llinfo_nd6.ln_next; |
799 | while (ln != NULL && ln != &llinfo_nd6) { | | 799 | while (ln != NULL && ln != &llinfo_nd6) { |
800 | struct rtentry *rt; | | 800 | struct rtentry *rt; |
801 | const struct sockaddr_dl *sdl; | | 801 | const struct sockaddr_dl *sdl; |
802 | | | 802 | |
803 | nln = ln->ln_next; | | 803 | nln = ln->ln_next; |
804 | rt = ln->ln_rt; | | 804 | rt = ln->ln_rt; |
805 | if (rt && rt->rt_gateway && | | 805 | if (rt && rt->rt_gateway && |
806 | rt->rt_gateway->sa_family == AF_LINK) { | | 806 | rt->rt_gateway->sa_family == AF_LINK) { |
807 | sdl = satocsdl(rt->rt_gateway); | | 807 | sdl = satocsdl(rt->rt_gateway); |
808 | if (sdl->sdl_index == ifp->if_index) | | 808 | if (sdl->sdl_index == ifp->if_index) |
809 | nln = nd6_free(rt, 0); | | 809 | nln = nd6_free(rt, 0); |
810 | } | | 810 | } |
811 | ln = nln; | | 811 | ln = nln; |
812 | } | | 812 | } |
813 | } | | 813 | } |
814 | | | 814 | |
815 | struct rtentry * | | 815 | struct rtentry * |
816 | nd6_lookup(const struct in6_addr *addr6, int create, struct ifnet *ifp) | | 816 | nd6_lookup(const struct in6_addr *addr6, int create, struct ifnet *ifp) |
817 | { | | 817 | { |
818 | struct rtentry *rt; | | 818 | struct rtentry *rt; |
819 | struct sockaddr_in6 sin6; | | 819 | struct sockaddr_in6 sin6; |
820 | | | 820 | |
821 | sockaddr_in6_init(&sin6, addr6, 0, 0, 0); | | 821 | sockaddr_in6_init(&sin6, addr6, 0, 0, 0); |
822 | rt = rtalloc1((struct sockaddr *)&sin6, create); | | 822 | rt = rtalloc1((struct sockaddr *)&sin6, create); |
823 | if (rt != NULL && (rt->rt_flags & RTF_LLINFO) == 0) { | | 823 | if (rt != NULL && (rt->rt_flags & RTF_LLINFO) == 0) { |
824 | /* | | 824 | /* |
825 | * This is the case for the default route. | | 825 | * This is the case for the default route. |
826 | * If we want to create a neighbor cache for the address, we | | 826 | * If we want to create a neighbor cache for the address, we |
827 | * should free the route for the destination and allocate an | | 827 | * should free the route for the destination and allocate an |
828 | * interface route. | | 828 | * interface route. |
829 | */ | | 829 | */ |
830 | if (create) { | | 830 | if (create) { |
831 | RTFREE(rt); | | 831 | RTFREE(rt); |
832 | rt = NULL; | | 832 | rt = NULL; |
833 | } | | 833 | } |
834 | } | | 834 | } |
835 | if (rt != NULL) | | 835 | if (rt != NULL) |
836 | ; | | 836 | ; |
837 | else if (create && ifp) { | | 837 | else if (create && ifp) { |
838 | int e; | | 838 | int e; |
839 | | | 839 | |
840 | /* | | 840 | /* |
841 | * If no route is available and create is set, | | 841 | * If no route is available and create is set, |
842 | * we allocate a host route for the destination | | 842 | * we allocate a host route for the destination |
843 | * and treat it like an interface route. | | 843 | * and treat it like an interface route. |
844 | * This hack is necessary for a neighbor which can't | | 844 | * This hack is necessary for a neighbor which can't |
845 | * be covered by our own prefix. | | 845 | * be covered by our own prefix. |
846 | */ | | 846 | */ |
847 | struct ifaddr *ifa = | | 847 | struct ifaddr *ifa = |
848 | ifaof_ifpforaddr((struct sockaddr *)&sin6, ifp); | | 848 | ifaof_ifpforaddr((struct sockaddr *)&sin6, ifp); |
849 | if (ifa == NULL) | | 849 | if (ifa == NULL) |
850 | return NULL; | | 850 | return NULL; |
851 | | | 851 | |
852 | /* | | 852 | /* |
853 | * Create a new route. RTF_LLINFO is necessary | | 853 | * Create a new route. RTF_LLINFO is necessary |
854 | * to create a Neighbor Cache entry for the | | 854 | * to create a Neighbor Cache entry for the |
855 | * destination in nd6_rtrequest which will be | | 855 | * destination in nd6_rtrequest which will be |
856 | * called in rtrequest via ifa->ifa_rtrequest. | | 856 | * called in rtrequest via ifa->ifa_rtrequest. |
857 | */ | | 857 | */ |
858 | if ((e = rtrequest(RTM_ADD, (const struct sockaddr *)&sin6, | | 858 | if ((e = rtrequest(RTM_ADD, (const struct sockaddr *)&sin6, |
859 | ifa->ifa_addr, (const struct sockaddr *)&all1_sa, | | 859 | ifa->ifa_addr, (const struct sockaddr *)&all1_sa, |
860 | (ifa->ifa_flags | RTF_HOST | RTF_LLINFO) & | | 860 | (ifa->ifa_flags | RTF_HOST | RTF_LLINFO) & |
861 | ~RTF_CLONING, &rt)) != 0) { | | 861 | ~RTF_CLONING, &rt)) != 0) { |
862 | #if 0 | | 862 | #if 0 |
863 | log(LOG_ERR, | | 863 | log(LOG_ERR, |
864 | "nd6_lookup: failed to add route for a " | | 864 | "nd6_lookup: failed to add route for a " |
865 | "neighbor(%s), errno=%d\n", | | 865 | "neighbor(%s), errno=%d\n", |
866 | ip6_sprintf(addr6), e); | | 866 | ip6_sprintf(addr6), e); |
867 | #endif | | 867 | #endif |
868 | return NULL; | | 868 | return NULL; |
869 | } | | 869 | } |
870 | if (rt == NULL) | | 870 | if (rt == NULL) |
871 | return NULL; | | 871 | return NULL; |
872 | if (rt->rt_llinfo) { | | 872 | if (rt->rt_llinfo) { |
873 | struct llinfo_nd6 *ln = | | 873 | struct llinfo_nd6 *ln = |
874 | (struct llinfo_nd6 *)rt->rt_llinfo; | | 874 | (struct llinfo_nd6 *)rt->rt_llinfo; |
875 | ln->ln_state = ND6_LLINFO_NOSTATE; | | 875 | ln->ln_state = ND6_LLINFO_NOSTATE; |
876 | } | | 876 | } |
877 | } else | | 877 | } else |
878 | return NULL; | | 878 | return NULL; |
879 | rt->rt_refcnt--; | | 879 | rt->rt_refcnt--; |
880 | /* | | 880 | /* |
881 | * Validation for the entry. | | 881 | * Validation for the entry. |
882 | * Note that the check for rt_llinfo is necessary because a cloned | | 882 | * Note that the check for rt_llinfo is necessary because a cloned |
883 | * route from a parent route that has the L flag (e.g. the default | | 883 | * route from a parent route that has the L flag (e.g. the default |
884 | * route to a p2p interface) may have the flag, too, while the | | 884 | * route to a p2p interface) may have the flag, too, while the |
885 | * destination is not actually a neighbor. | | 885 | * destination is not actually a neighbor. |
886 | * XXX: we can't use rt->rt_ifp to check for the interface, since | | 886 | * XXX: we can't use rt->rt_ifp to check for the interface, since |
887 | * it might be the loopback interface if the entry is for our | | 887 | * it might be the loopback interface if the entry is for our |
888 | * own address on a non-loopback interface. Instead, we should | | 888 | * own address on a non-loopback interface. Instead, we should |
889 | * use rt->rt_ifa->ifa_ifp, which would specify the REAL | | 889 | * use rt->rt_ifa->ifa_ifp, which would specify the REAL |
890 | * interface. | | 890 | * interface. |
891 | * Note also that ifa_ifp and ifp may differ when we connect two | | 891 | * Note also that ifa_ifp and ifp may differ when we connect two |
892 | * interfaces to a same link, install a link prefix to an interface, | | 892 | * interfaces to a same link, install a link prefix to an interface, |
893 | * and try to install a neighbor cache on an interface that does not | | 893 | * and try to install a neighbor cache on an interface that does not |
894 | * have a route to the prefix. | | 894 | * have a route to the prefix. |
895 | */ | | 895 | */ |
896 | if ((rt->rt_flags & RTF_GATEWAY) || (rt->rt_flags & RTF_LLINFO) == 0 || | | 896 | if ((rt->rt_flags & RTF_GATEWAY) || (rt->rt_flags & RTF_LLINFO) == 0 || |
897 | rt->rt_gateway->sa_family != AF_LINK || rt->rt_llinfo == NULL || | | 897 | rt->rt_gateway->sa_family != AF_LINK || rt->rt_llinfo == NULL || |
898 | (ifp && rt->rt_ifa->ifa_ifp != ifp)) { | | 898 | (ifp && rt->rt_ifa->ifa_ifp != ifp)) { |
899 | if (create) { | | 899 | if (create) { |
900 | nd6log((LOG_DEBUG, | | 900 | nd6log((LOG_DEBUG, |
901 | "nd6_lookup: failed to lookup %s (if = %s)\n", | | 901 | "nd6_lookup: failed to lookup %s (if = %s)\n", |
902 | ip6_sprintf(addr6), | | 902 | ip6_sprintf(addr6), |
903 | ifp ? if_name(ifp) : "unspec")); | | 903 | ifp ? if_name(ifp) : "unspec")); |
904 | } | | 904 | } |
905 | return NULL; | | 905 | return NULL; |
906 | } | | 906 | } |
907 | return rt; | | 907 | return rt; |
908 | } | | 908 | } |
909 | | | 909 | |
910 | /* | | 910 | /* |
911 | * Detect if a given IPv6 address identifies a neighbor on a given link. | | 911 | * Detect if a given IPv6 address identifies a neighbor on a given link. |
912 | * XXX: should take care of the destination of a p2p link? | | 912 | * XXX: should take care of the destination of a p2p link? |
913 | */ | | 913 | */ |
914 | int | | 914 | int |
915 | nd6_is_addr_neighbor(const struct sockaddr_in6 *addr, struct ifnet *ifp) | | 915 | nd6_is_addr_neighbor(const struct sockaddr_in6 *addr, struct ifnet *ifp) |
916 | { | | 916 | { |
917 | struct nd_prefix *pr; | | 917 | struct nd_prefix *pr; |
918 | | | 918 | |
919 | /* | | 919 | /* |
920 | * A link-local address is always a neighbor. | | 920 | * A link-local address is always a neighbor. |
921 | * XXX: a link does not necessarily specify a single interface. | | 921 | * XXX: a link does not necessarily specify a single interface. |
922 | */ | | 922 | */ |
923 | if (IN6_IS_ADDR_LINKLOCAL(&addr->sin6_addr)) { | | 923 | if (IN6_IS_ADDR_LINKLOCAL(&addr->sin6_addr)) { |
924 | struct sockaddr_in6 sin6_copy; | | 924 | struct sockaddr_in6 sin6_copy; |
925 | u_int32_t zone; | | 925 | u_int32_t zone; |
926 | | | 926 | |
927 | /* | | 927 | /* |
928 | * We need sin6_copy since sa6_recoverscope() may modify the | | 928 | * We need sin6_copy since sa6_recoverscope() may modify the |
929 | * content (XXX). | | 929 | * content (XXX). |
930 | */ | | 930 | */ |
931 | sin6_copy = *addr; | | 931 | sin6_copy = *addr; |
932 | if (sa6_recoverscope(&sin6_copy)) | | 932 | if (sa6_recoverscope(&sin6_copy)) |
933 | return 0; /* XXX: should be impossible */ | | 933 | return 0; /* XXX: should be impossible */ |
934 | if (in6_setscope(&sin6_copy.sin6_addr, ifp, &zone)) | | 934 | if (in6_setscope(&sin6_copy.sin6_addr, ifp, &zone)) |
935 | return 0; | | 935 | return 0; |
936 | if (sin6_copy.sin6_scope_id == zone) | | 936 | if (sin6_copy.sin6_scope_id == zone) |
937 | return 1; | | 937 | return 1; |
938 | else | | 938 | else |
939 | return 0; | | 939 | return 0; |
940 | } | | 940 | } |
941 | | | 941 | |
942 | /* | | 942 | /* |
943 | * If the address matches one of our on-link prefixes, it should be a | | 943 | * If the address matches one of our on-link prefixes, it should be a |
944 | * neighbor. | | 944 | * neighbor. |
945 | */ | | 945 | */ |
946 | LIST_FOREACH(pr, &nd_prefix, ndpr_entry) { | | 946 | LIST_FOREACH(pr, &nd_prefix, ndpr_entry) { |
947 | if (pr->ndpr_ifp != ifp) | | 947 | if (pr->ndpr_ifp != ifp) |
948 | continue; | | 948 | continue; |
949 | | | 949 | |
950 | if (!(pr->ndpr_stateflags & NDPRF_ONLINK)) | | 950 | if (!(pr->ndpr_stateflags & NDPRF_ONLINK)) |
951 | continue; | | 951 | continue; |
952 | | | 952 | |
953 | if (IN6_ARE_MASKED_ADDR_EQUAL(&pr->ndpr_prefix.sin6_addr, | | 953 | if (IN6_ARE_MASKED_ADDR_EQUAL(&pr->ndpr_prefix.sin6_addr, |
954 | &addr->sin6_addr, &pr->ndpr_mask)) | | 954 | &addr->sin6_addr, &pr->ndpr_mask)) |
955 | return 1; | | 955 | return 1; |
956 | } | | 956 | } |
957 | | | 957 | |
958 | /* | | 958 | /* |
959 | * If the default router list is empty, all addresses are regarded | | 959 | * If the default router list is empty, all addresses are regarded |
960 | * as on-link, and thus, as a neighbor. | | 960 | * as on-link, and thus, as a neighbor. |
961 | * XXX: we restrict the condition to hosts, because routers usually do | | 961 | * XXX: we restrict the condition to hosts, because routers usually do |
962 | * not have the "default router list". | | 962 | * not have the "default router list". |
963 | */ | | 963 | */ |
964 | if (!ip6_forwarding && TAILQ_FIRST(&nd_defrouter) == NULL && | | 964 | if (!ip6_forwarding && TAILQ_FIRST(&nd_defrouter) == NULL && |
965 | nd6_defifindex == ifp->if_index) { | | 965 | nd6_defifindex == ifp->if_index) { |
966 | return 1; | | 966 | return 1; |
967 | } | | 967 | } |
968 | | | 968 | |
969 | /* | | 969 | /* |
970 | * Even if the address matches none of our addresses, it might be | | 970 | * Even if the address matches none of our addresses, it might be |
971 | * in the neighbor cache. | | 971 | * in the neighbor cache. |
972 | */ | | 972 | */ |
973 | if (nd6_lookup(&addr->sin6_addr, 0, ifp) != NULL) | | 973 | if (nd6_lookup(&addr->sin6_addr, 0, ifp) != NULL) |
974 | return 1; | | 974 | return 1; |
975 | | | 975 | |
976 | return 0; | | 976 | return 0; |
977 | } | | 977 | } |
978 | | | 978 | |
979 | /* | | 979 | /* |
980 | * Free an nd6 llinfo entry. | | 980 | * Free an nd6 llinfo entry. |
981 | * Since the function would cause significant changes in the kernel, DO NOT | | 981 | * Since the function would cause significant changes in the kernel, DO NOT |
982 | * make it global, unless you have a strong reason for the change, and are sure | | 982 | * make it global, unless you have a strong reason for the change, and are sure |
983 | * that the change is safe. | | 983 | * that the change is safe. |
984 | */ | | 984 | */ |
985 | static struct llinfo_nd6 * | | 985 | static struct llinfo_nd6 * |
986 | nd6_free(struct rtentry *rt, int gc) | | 986 | nd6_free(struct rtentry *rt, int gc) |
987 | { | | 987 | { |
988 | struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo, *next; | | 988 | struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo, *next; |
989 | struct in6_addr in6 = satocsin6(rt_getkey(rt))->sin6_addr; | | 989 | struct in6_addr in6 = satocsin6(rt_getkey(rt))->sin6_addr; |
990 | struct nd_defrouter *dr; | | 990 | struct nd_defrouter *dr; |
991 | | | 991 | |
992 | /* | | 992 | /* |
993 | * we used to have pfctlinput(PRC_HOSTDEAD) here. | | 993 | * we used to have pfctlinput(PRC_HOSTDEAD) here. |
994 | * even though it is not harmful, it was not really necessary. | | 994 | * even though it is not harmful, it was not really necessary. |
995 | */ | | 995 | */ |
996 | | | 996 | |
997 | /* cancel timer */ | | 997 | /* cancel timer */ |
998 | nd6_llinfo_settimer(ln, -1); | | 998 | nd6_llinfo_settimer(ln, -1); |
999 | | | 999 | |
1000 | if (!ip6_forwarding) { | | 1000 | if (!ip6_forwarding) { |
1001 | int s; | | 1001 | int s; |
1002 | s = splsoftnet(); | | 1002 | s = splsoftnet(); |
1003 | dr = defrouter_lookup(&satocsin6(rt_getkey(rt))->sin6_addr, | | 1003 | dr = defrouter_lookup(&satocsin6(rt_getkey(rt))->sin6_addr, |
1004 | rt->rt_ifp); | | 1004 | rt->rt_ifp); |
1005 | | | 1005 | |
1006 | if (dr != NULL && dr->expire && | | 1006 | if (dr != NULL && dr->expire && |
1007 | ln->ln_state == ND6_LLINFO_STALE && gc) { | | 1007 | ln->ln_state == ND6_LLINFO_STALE && gc) { |
1008 | /* | | 1008 | /* |
1009 | * If the reason for the deletion is just garbage | | 1009 | * If the reason for the deletion is just garbage |
1010 | * collection, and the neighbor is an active default | | 1010 | * collection, and the neighbor is an active default |
1011 | * router, do not delete it. Instead, reset the GC | | 1011 | * router, do not delete it. Instead, reset the GC |
1012 | * timer using the router's lifetime. | | 1012 | * timer using the router's lifetime. |
1013 | * Simply deleting the entry would affect default | | 1013 | * Simply deleting the entry would affect default |
1014 | * router selection, which is not necessarily a good | | 1014 | * router selection, which is not necessarily a good |
1015 | * thing, especially when we're using router preference | | 1015 | * thing, especially when we're using router preference |
1016 | * values. | | 1016 | * values. |
1017 | * XXX: the check for ln_state would be redundant, | | 1017 | * XXX: the check for ln_state would be redundant, |
1018 | * but we intentionally keep it just in case. | | 1018 | * but we intentionally keep it just in case. |
1019 | */ | | 1019 | */ |
1020 | if (dr->expire > time_second) | | 1020 | if (dr->expire > time_second) |
1021 | nd6_llinfo_settimer(ln, | | 1021 | nd6_llinfo_settimer(ln, |
1022 | (dr->expire - time_second) * hz); | | 1022 | (dr->expire - time_second) * hz); |
1023 | else | | 1023 | else |
1024 | nd6_llinfo_settimer(ln, (long)nd6_gctimer * hz); | | 1024 | nd6_llinfo_settimer(ln, (long)nd6_gctimer * hz); |
1025 | splx(s); | | 1025 | splx(s); |
1026 | return ln->ln_next; | | 1026 | return ln->ln_next; |
1027 | } | | 1027 | } |
1028 | | | 1028 | |
1029 | if (ln->ln_router || dr) { | | 1029 | if (ln->ln_router || dr) { |
1030 | /* | | 1030 | /* |
1031 | * rt6_flush must be called whether or not the neighbor | | 1031 | * rt6_flush must be called whether or not the neighbor |
1032 | * is in the Default Router List. | | 1032 | * is in the Default Router List. |
1033 | * See a corresponding comment in nd6_na_input(). | | 1033 | * See a corresponding comment in nd6_na_input(). |
1034 | */ | | 1034 | */ |
1035 | rt6_flush(&in6, rt->rt_ifp); | | 1035 | rt6_flush(&in6, rt->rt_ifp); |
1036 | } | | 1036 | } |
1037 | | | 1037 | |
1038 | if (dr) { | | 1038 | if (dr) { |
1039 | /* | | 1039 | /* |
1040 | * Unreachablity of a router might affect the default | | 1040 | * Unreachablity of a router might affect the default |
1041 | * router selection and on-link detection of advertised | | 1041 | * router selection and on-link detection of advertised |
1042 | * prefixes. | | 1042 | * prefixes. |
1043 | */ | | 1043 | */ |
1044 | | | 1044 | |
1045 | /* | | 1045 | /* |
1046 | * Temporarily fake the state to choose a new default | | 1046 | * Temporarily fake the state to choose a new default |
1047 | * router and to perform on-link determination of | | 1047 | * router and to perform on-link determination of |
1048 | * prefixes correctly. | | 1048 | * prefixes correctly. |
1049 | * Below the state will be set correctly, | | 1049 | * Below the state will be set correctly, |
1050 | * or the entry itself will be deleted. | | 1050 | * or the entry itself will be deleted. |
1051 | */ | | 1051 | */ |
1052 | ln->ln_state = ND6_LLINFO_INCOMPLETE; | | 1052 | ln->ln_state = ND6_LLINFO_INCOMPLETE; |
1053 | | | 1053 | |
1054 | /* | | 1054 | /* |
1055 | * Since defrouter_select() does not affect the | | 1055 | * Since defrouter_select() does not affect the |
1056 | * on-link determination and MIP6 needs the check | | 1056 | * on-link determination and MIP6 needs the check |
1057 | * before the default router selection, we perform | | 1057 | * before the default router selection, we perform |
1058 | * the check now. | | 1058 | * the check now. |
1059 | */ | | 1059 | */ |
1060 | pfxlist_onlink_check(); | | 1060 | pfxlist_onlink_check(); |
1061 | | | 1061 | |
1062 | /* | | 1062 | /* |
1063 | * refresh default router list | | 1063 | * refresh default router list |
1064 | */ | | 1064 | */ |
1065 | defrouter_select(); | | 1065 | defrouter_select(); |
1066 | } | | 1066 | } |
1067 | splx(s); | | 1067 | splx(s); |
1068 | } | | 1068 | } |
1069 | | | 1069 | |
1070 | /* | | 1070 | /* |
1071 | * Before deleting the entry, remember the next entry as the | | 1071 | * Before deleting the entry, remember the next entry as the |
1072 | * return value. We need this because pfxlist_onlink_check() above | | 1072 | * return value. We need this because pfxlist_onlink_check() above |
1073 | * might have freed other entries (particularly the old next entry) as | | 1073 | * might have freed other entries (particularly the old next entry) as |
1074 | * a side effect (XXX). | | 1074 | * a side effect (XXX). |
1075 | */ | | 1075 | */ |
1076 | next = ln->ln_next; | | 1076 | next = ln->ln_next; |
1077 | | | 1077 | |
1078 | /* | | 1078 | /* |
1079 | * Detach the route from the routing tree and the list of neighbor | | 1079 | * Detach the route from the routing tree and the list of neighbor |
1080 | * caches, and disable the route entry not to be used in already | | 1080 | * caches, and disable the route entry not to be used in already |
1081 | * cached routes. | | 1081 | * cached routes. |
1082 | */ | | 1082 | */ |
1083 | rtrequest(RTM_DELETE, rt_getkey(rt), NULL, rt_mask(rt), 0, NULL); | | 1083 | rtrequest(RTM_DELETE, rt_getkey(rt), NULL, rt_mask(rt), 0, NULL); |
1084 | | | 1084 | |
1085 | return next; | | 1085 | return next; |
1086 | } | | 1086 | } |
1087 | | | 1087 | |
1088 | /* | | 1088 | /* |
1089 | * Upper-layer reachability hint for Neighbor Unreachability Detection. | | 1089 | * Upper-layer reachability hint for Neighbor Unreachability Detection. |
1090 | * | | 1090 | * |
1091 | * XXX cost-effective methods? | | 1091 | * XXX cost-effective methods? |
1092 | */ | | 1092 | */ |
1093 | void | | 1093 | void |
1094 | nd6_nud_hint(struct rtentry *rt, struct in6_addr *dst6, int force) | | 1094 | nd6_nud_hint(struct rtentry *rt, struct in6_addr *dst6, int force) |
1095 | { | | 1095 | { |
1096 | struct llinfo_nd6 *ln; | | 1096 | struct llinfo_nd6 *ln; |
1097 | | | 1097 | |
1098 | /* | | 1098 | /* |
1099 | * If the caller specified "rt", use that. Otherwise, resolve the | | 1099 | * If the caller specified "rt", use that. Otherwise, resolve the |
1100 | * routing table by supplied "dst6". | | 1100 | * routing table by supplied "dst6". |
1101 | */ | | 1101 | */ |
1102 | if (rt == NULL) { | | 1102 | if (rt == NULL) { |
1103 | if (dst6 == NULL) | | 1103 | if (dst6 == NULL) |
1104 | return; | | 1104 | return; |
1105 | if ((rt = nd6_lookup(dst6, 0, NULL)) == NULL) | | 1105 | if ((rt = nd6_lookup(dst6, 0, NULL)) == NULL) |
1106 | return; | | 1106 | return; |
1107 | } | | 1107 | } |
1108 | | | 1108 | |
1109 | if ((rt->rt_flags & RTF_GATEWAY) != 0 || | | 1109 | if ((rt->rt_flags & RTF_GATEWAY) != 0 || |
1110 | (rt->rt_flags & RTF_LLINFO) == 0 || | | 1110 | (rt->rt_flags & RTF_LLINFO) == 0 || |
1111 | !rt->rt_llinfo || !rt->rt_gateway || | | 1111 | !rt->rt_llinfo || !rt->rt_gateway || |
1112 | rt->rt_gateway->sa_family != AF_LINK) { | | 1112 | rt->rt_gateway->sa_family != AF_LINK) { |
1113 | /* This is not a host route. */ | | 1113 | /* This is not a host route. */ |
1114 | return; | | 1114 | return; |
1115 | } | | 1115 | } |
1116 | | | 1116 | |
1117 | ln = (struct llinfo_nd6 *)rt->rt_llinfo; | | 1117 | ln = (struct llinfo_nd6 *)rt->rt_llinfo; |
1118 | if (ln->ln_state < ND6_LLINFO_REACHABLE) | | 1118 | if (ln->ln_state < ND6_LLINFO_REACHABLE) |
1119 | return; | | 1119 | return; |
1120 | | | 1120 | |
1121 | /* | | 1121 | /* |
1122 | * if we get upper-layer reachability confirmation many times, | | 1122 | * if we get upper-layer reachability confirmation many times, |
1123 | * it is possible we have false information. | | 1123 | * it is possible we have false information. |
1124 | */ | | 1124 | */ |
1125 | if (!force) { | | 1125 | if (!force) { |
1126 | ln->ln_byhint++; | | 1126 | ln->ln_byhint++; |
1127 | if (ln->ln_byhint > nd6_maxnudhint) | | 1127 | if (ln->ln_byhint > nd6_maxnudhint) |
1128 | return; | | 1128 | return; |
1129 | } | | 1129 | } |
1130 | | | 1130 | |
1131 | ln->ln_state = ND6_LLINFO_REACHABLE; | | 1131 | ln->ln_state = ND6_LLINFO_REACHABLE; |
1132 | if (!ND6_LLINFO_PERMANENT(ln)) { | | 1132 | if (!ND6_LLINFO_PERMANENT(ln)) { |
1133 | nd6_llinfo_settimer(ln, | | 1133 | nd6_llinfo_settimer(ln, |
1134 | (long)ND_IFINFO(rt->rt_ifp)->reachable * hz); | | 1134 | (long)ND_IFINFO(rt->rt_ifp)->reachable * hz); |
1135 | } | | 1135 | } |
1136 | } | | 1136 | } |
1137 | | | 1137 | |
1138 | void | | 1138 | void |
1139 | nd6_rtrequest(int req, struct rtentry *rt, const struct rt_addrinfo *info) | | 1139 | nd6_rtrequest(int req, struct rtentry *rt, const struct rt_addrinfo *info) |
1140 | { | | 1140 | { |
1141 | struct sockaddr *gate = rt->rt_gateway; | | 1141 | struct sockaddr *gate = rt->rt_gateway; |
1142 | struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo; | | 1142 | struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo; |
1143 | struct ifnet *ifp = rt->rt_ifp; | | 1143 | struct ifnet *ifp = rt->rt_ifp; |
1144 | uint8_t namelen = strlen(ifp->if_xname), addrlen = ifp->if_addrlen; | | 1144 | uint8_t namelen = strlen(ifp->if_xname), addrlen = ifp->if_addrlen; |
1145 | struct ifaddr *ifa; | | 1145 | struct ifaddr *ifa; |
1146 | | | 1146 | |
1147 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1147 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1148 | | | 1148 | |
1149 | if (req == RTM_LLINFO_UPD) { | | 1149 | if (req == RTM_LLINFO_UPD) { |
1150 | int rc; | | 1150 | int rc; |
1151 | struct in6_addr *in6; | | 1151 | struct in6_addr *in6; |
1152 | struct in6_addr in6_all; | | 1152 | struct in6_addr in6_all; |
1153 | int anycast; | | 1153 | int anycast; |
1154 | | | 1154 | |
1155 | if ((ifa = info->rti_ifa) == NULL) | | 1155 | if ((ifa = info->rti_ifa) == NULL) |
1156 | return; | | 1156 | return; |
1157 | | | 1157 | |
1158 | in6 = &ifatoia6(ifa)->ia_addr.sin6_addr; | | 1158 | in6 = &ifatoia6(ifa)->ia_addr.sin6_addr; |
1159 | anycast = ifatoia6(ifa)->ia6_flags & IN6_IFF_ANYCAST; | | 1159 | anycast = ifatoia6(ifa)->ia6_flags & IN6_IFF_ANYCAST; |
1160 | | | 1160 | |
1161 | in6_all = in6addr_linklocal_allnodes; | | 1161 | in6_all = in6addr_linklocal_allnodes; |
1162 | if ((rc = in6_setscope(&in6_all, ifa->ifa_ifp, NULL)) != 0) { | | 1162 | if ((rc = in6_setscope(&in6_all, ifa->ifa_ifp, NULL)) != 0) { |
1163 | log(LOG_ERR, "%s: failed to set scope %s " | | 1163 | log(LOG_ERR, "%s: failed to set scope %s " |
1164 | "(errno=%d)\n", __func__, if_name(ifp), rc); | | 1164 | "(errno=%d)\n", __func__, if_name(ifp), rc); |
1165 | return; | | 1165 | return; |
1166 | } | | 1166 | } |
1167 | | | 1167 | |
1168 | /* XXX don't set Override for proxy addresses */ | | 1168 | /* XXX don't set Override for proxy addresses */ |
1169 | nd6_na_output(ifa->ifa_ifp, &in6_all, in6, | | 1169 | nd6_na_output(ifa->ifa_ifp, &in6_all, in6, |
1170 | (anycast ? 0 : ND_NA_FLAG_OVERRIDE) | | 1170 | (anycast ? 0 : ND_NA_FLAG_OVERRIDE) |
1171 | #if 0 | | 1171 | #if 0 |
1172 | | (ip6_forwarding ? ND_NA_FLAG_ROUTER : 0) | | 1172 | | (ip6_forwarding ? ND_NA_FLAG_ROUTER : 0) |
1173 | #endif | | 1173 | #endif |
1174 | , 1, NULL); | | 1174 | , 1, NULL); |
1175 | return; | | 1175 | return; |
1176 | } | | 1176 | } |
1177 | | | 1177 | |
1178 | if ((rt->rt_flags & RTF_GATEWAY) != 0) | | 1178 | if ((rt->rt_flags & RTF_GATEWAY) != 0) |
1179 | return; | | 1179 | return; |
1180 | | | 1180 | |
1181 | if (nd6_need_cache(ifp) == 0 && (rt->rt_flags & RTF_HOST) == 0) { | | 1181 | if (nd6_need_cache(ifp) == 0 && (rt->rt_flags & RTF_HOST) == 0) { |
1182 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1182 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1183 | /* | | 1183 | /* |
1184 | * This is probably an interface direct route for a link | | 1184 | * This is probably an interface direct route for a link |
1185 | * which does not need neighbor caches (e.g. fe80::%lo0/64). | | 1185 | * which does not need neighbor caches (e.g. fe80::%lo0/64). |
1186 | * We do not need special treatment below for such a route. | | 1186 | * We do not need special treatment below for such a route. |
1187 | * Moreover, the RTF_LLINFO flag which would be set below | | 1187 | * Moreover, the RTF_LLINFO flag which would be set below |
1188 | * would annoy the ndp(8) command. | | 1188 | * would annoy the ndp(8) command. |
1189 | */ | | 1189 | */ |
1190 | return; | | 1190 | return; |
1191 | } | | 1191 | } |
1192 | | | 1192 | |
1193 | if (req == RTM_RESOLVE && | | 1193 | if (req == RTM_RESOLVE && |
1194 | (nd6_need_cache(ifp) == 0 || /* stf case */ | | 1194 | (nd6_need_cache(ifp) == 0 || /* stf case */ |
1195 | !nd6_is_addr_neighbor(satocsin6(rt_getkey(rt)), ifp))) { | | 1195 | !nd6_is_addr_neighbor(satocsin6(rt_getkey(rt)), ifp))) { |
1196 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1196 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1197 | /* | | 1197 | /* |
1198 | * FreeBSD and BSD/OS often make a cloned host route based | | 1198 | * FreeBSD and BSD/OS often make a cloned host route based |
1199 | * on a less-specific route (e.g. the default route). | | 1199 | * on a less-specific route (e.g. the default route). |
1200 | * If the less specific route does not have a "gateway" | | 1200 | * If the less specific route does not have a "gateway" |
1201 | * (this is the case when the route just goes to a p2p or an | | 1201 | * (this is the case when the route just goes to a p2p or an |
1202 | * stf interface), we'll mistakenly make a neighbor cache for | | 1202 | * stf interface), we'll mistakenly make a neighbor cache for |
1203 | * the host route, and will see strange neighbor solicitation | | 1203 | * the host route, and will see strange neighbor solicitation |
1204 | * for the corresponding destination. In order to avoid the | | 1204 | * for the corresponding destination. In order to avoid the |
1205 | * confusion, we check if the destination of the route is | | 1205 | * confusion, we check if the destination of the route is |
1206 | * a neighbor in terms of neighbor discovery, and stop the | | 1206 | * a neighbor in terms of neighbor discovery, and stop the |
1207 | * process if not. Additionally, we remove the LLINFO flag | | 1207 | * process if not. Additionally, we remove the LLINFO flag |
1208 | * so that ndp(8) will not try to get the neighbor information | | 1208 | * so that ndp(8) will not try to get the neighbor information |
1209 | * of the destination. | | 1209 | * of the destination. |
1210 | */ | | 1210 | */ |
1211 | rt->rt_flags &= ~RTF_LLINFO; | | 1211 | rt->rt_flags &= ~RTF_LLINFO; |
1212 | return; | | 1212 | return; |
1213 | } | | 1213 | } |
1214 | | | 1214 | |
1215 | switch (req) { | | 1215 | switch (req) { |
1216 | case RTM_ADD: | | 1216 | case RTM_ADD: |
1217 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1217 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1218 | /* | | 1218 | /* |
1219 | * There is no backward compatibility :) | | 1219 | * There is no backward compatibility :) |
1220 | * | | 1220 | * |
1221 | * if ((rt->rt_flags & RTF_HOST) == 0 && | | 1221 | * if ((rt->rt_flags & RTF_HOST) == 0 && |
1222 | * SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff) | | 1222 | * SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff) |
1223 | * rt->rt_flags |= RTF_CLONING; | | 1223 | * rt->rt_flags |= RTF_CLONING; |
1224 | */ | | 1224 | */ |
1225 | if ((rt->rt_flags & RTF_CLONING) || | | 1225 | if ((rt->rt_flags & RTF_CLONING) || |
1226 | ((rt->rt_flags & RTF_LLINFO) && ln == NULL)) { | | 1226 | ((rt->rt_flags & RTF_LLINFO) && ln == NULL)) { |
1227 | union { | | 1227 | union { |
1228 | struct sockaddr sa; | | 1228 | struct sockaddr sa; |
1229 | struct sockaddr_dl sdl; | | 1229 | struct sockaddr_dl sdl; |
1230 | struct sockaddr_storage ss; | | 1230 | struct sockaddr_storage ss; |
1231 | } u; | | 1231 | } u; |
1232 | /* | | 1232 | /* |
1233 | * Case 1: This route should come from a route to | | 1233 | * Case 1: This route should come from a route to |
1234 | * interface (RTF_CLONING case) or the route should be | | 1234 | * interface (RTF_CLONING case) or the route should be |
1235 | * treated as on-link but is currently not | | 1235 | * treated as on-link but is currently not |
1236 | * (RTF_LLINFO && ln == NULL case). | | 1236 | * (RTF_LLINFO && ln == NULL case). |
1237 | */ | | 1237 | */ |
1238 | if (sockaddr_dl_init(&u.sdl, sizeof(u.ss), | | 1238 | if (sockaddr_dl_init(&u.sdl, sizeof(u.ss), |
1239 | ifp->if_index, ifp->if_type, | | 1239 | ifp->if_index, ifp->if_type, |
1240 | NULL, namelen, NULL, addrlen) == NULL) { | | 1240 | NULL, namelen, NULL, addrlen) == NULL) { |
1241 | printf("%s.%d: sockaddr_dl_init(, %zu, ) " | | 1241 | printf("%s.%d: sockaddr_dl_init(, %zu, ) " |
1242 | "failed on %s\n", __func__, __LINE__, | | 1242 | "failed on %s\n", __func__, __LINE__, |
1243 | sizeof(u.ss), if_name(ifp)); | | 1243 | sizeof(u.ss), if_name(ifp)); |
1244 | } | | 1244 | } |
1245 | rt_setgate(rt, &u.sa); | | 1245 | rt_setgate(rt, &u.sa); |
1246 | gate = rt->rt_gateway; | | 1246 | gate = rt->rt_gateway; |
1247 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1247 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1248 | if (ln != NULL) | | 1248 | if (ln != NULL) |
1249 | nd6_llinfo_settimer(ln, 0); | | 1249 | nd6_llinfo_settimer(ln, 0); |
1250 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1250 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1251 | if ((rt->rt_flags & RTF_CLONING) != 0) | | 1251 | if ((rt->rt_flags & RTF_CLONING) != 0) |
1252 | break; | | 1252 | break; |
1253 | } | | 1253 | } |
1254 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1254 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1255 | /* | | 1255 | /* |
1256 | * In IPv4 code, we try to annonuce new RTF_ANNOUNCE entry here. | | 1256 | * In IPv4 code, we try to annonuce new RTF_ANNOUNCE entry here. |
1257 | * We don't do that here since llinfo is not ready yet. | | 1257 | * We don't do that here since llinfo is not ready yet. |
1258 | * | | 1258 | * |
1259 | * There are also couple of other things to be discussed: | | 1259 | * There are also couple of other things to be discussed: |
1260 | * - unsolicited NA code needs improvement beforehand | | 1260 | * - unsolicited NA code needs improvement beforehand |
1261 | * - RFC2461 says we MAY send multicast unsolicited NA | | 1261 | * - RFC2461 says we MAY send multicast unsolicited NA |
1262 | * (7.2.6 paragraph 4), however, it also says that we | | 1262 | * (7.2.6 paragraph 4), however, it also says that we |
1263 | * SHOULD provide a mechanism to prevent multicast NA storm. | | 1263 | * SHOULD provide a mechanism to prevent multicast NA storm. |
1264 | * we don't have anything like it right now. | | 1264 | * we don't have anything like it right now. |
1265 | * note that the mechanism needs a mutual agreement | | 1265 | * note that the mechanism needs a mutual agreement |
1266 | * between proxies, which means that we need to implement | | 1266 | * between proxies, which means that we need to implement |
1267 | * a new protocol, or a new kludge. | | 1267 | * a new protocol, or a new kludge. |
1268 | * - from RFC2461 6.2.4, host MUST NOT send an unsolicited NA. | | 1268 | * - from RFC2461 6.2.4, host MUST NOT send an unsolicited NA. |
1269 | * we need to check ip6forwarding before sending it. | | 1269 | * we need to check ip6forwarding before sending it. |
1270 | * (or should we allow proxy ND configuration only for | | 1270 | * (or should we allow proxy ND configuration only for |
1271 | * routers? there's no mention about proxy ND from hosts) | | 1271 | * routers? there's no mention about proxy ND from hosts) |
1272 | */ | | 1272 | */ |
1273 | #if 0 | | 1273 | #if 0 |
1274 | /* XXX it does not work */ | | 1274 | /* XXX it does not work */ |
1275 | if (rt->rt_flags & RTF_ANNOUNCE) | | 1275 | if (rt->rt_flags & RTF_ANNOUNCE) |
1276 | nd6_na_output(ifp, | | 1276 | nd6_na_output(ifp, |
1277 | &satocsin6(rt_getkey(rt))->sin6_addr, | | 1277 | &satocsin6(rt_getkey(rt))->sin6_addr, |
1278 | &satocsin6(rt_getkey(rt))->sin6_addr, | | 1278 | &satocsin6(rt_getkey(rt))->sin6_addr, |
1279 | ip6_forwarding ? ND_NA_FLAG_ROUTER : 0, | | 1279 | ip6_forwarding ? ND_NA_FLAG_ROUTER : 0, |
1280 | 1, NULL); | | 1280 | 1, NULL); |
1281 | #endif | | 1281 | #endif |
1282 | /* FALLTHROUGH */ | | 1282 | /* FALLTHROUGH */ |
1283 | case RTM_RESOLVE: | | 1283 | case RTM_RESOLVE: |
1284 | if ((ifp->if_flags & (IFF_POINTOPOINT | IFF_LOOPBACK)) == 0) { | | 1284 | if ((ifp->if_flags & (IFF_POINTOPOINT | IFF_LOOPBACK)) == 0) { |
1285 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1285 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1286 | /* | | 1286 | /* |
1287 | * Address resolution isn't necessary for a point to | | 1287 | * Address resolution isn't necessary for a point to |
1288 | * point link, so we can skip this test for a p2p link. | | 1288 | * point link, so we can skip this test for a p2p link. |
1289 | */ | | 1289 | */ |
1290 | if (gate->sa_family != AF_LINK || | | 1290 | if (gate->sa_family != AF_LINK || |
1291 | gate->sa_len < | | 1291 | gate->sa_len < |
1292 | sockaddr_dl_measure(namelen, addrlen)) { | | 1292 | sockaddr_dl_measure(namelen, addrlen)) { |
1293 | log(LOG_DEBUG, | | 1293 | log(LOG_DEBUG, |
1294 | "nd6_rtrequest: bad gateway value: %s\n", | | 1294 | "nd6_rtrequest: bad gateway value: %s\n", |
1295 | if_name(ifp)); | | 1295 | if_name(ifp)); |
1296 | break; | | 1296 | break; |
1297 | } | | 1297 | } |
1298 | satosdl(gate)->sdl_type = ifp->if_type; | | 1298 | satosdl(gate)->sdl_type = ifp->if_type; |
1299 | satosdl(gate)->sdl_index = ifp->if_index; | | 1299 | satosdl(gate)->sdl_index = ifp->if_index; |
1300 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1300 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1301 | } | | 1301 | } |
1302 | if (ln != NULL) | | 1302 | if (ln != NULL) |
1303 | break; /* This happens on a route change */ | | 1303 | break; /* This happens on a route change */ |
1304 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1304 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1305 | /* | | 1305 | /* |
1306 | * Case 2: This route may come from cloning, or a manual route | | 1306 | * Case 2: This route may come from cloning, or a manual route |
1307 | * add with a LL address. | | 1307 | * add with a LL address. |
1308 | */ | | 1308 | */ |
1309 | R_Malloc(ln, struct llinfo_nd6 *, sizeof(*ln)); | | 1309 | R_Malloc(ln, struct llinfo_nd6 *, sizeof(*ln)); |
1310 | rt->rt_llinfo = ln; | | 1310 | rt->rt_llinfo = ln; |
1311 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1311 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1312 | if (ln == NULL) { | | 1312 | if (ln == NULL) { |
1313 | log(LOG_DEBUG, "nd6_rtrequest: malloc failed\n"); | | 1313 | log(LOG_DEBUG, "nd6_rtrequest: malloc failed\n"); |
1314 | break; | | 1314 | break; |
1315 | } | | 1315 | } |
1316 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1316 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1317 | nd6_inuse++; | | 1317 | nd6_inuse++; |
1318 | nd6_allocated++; | | 1318 | nd6_allocated++; |
1319 | memset(ln, 0, sizeof(*ln)); | | 1319 | memset(ln, 0, sizeof(*ln)); |
1320 | ln->ln_rt = rt; | | 1320 | ln->ln_rt = rt; |
1321 | callout_init(&ln->ln_timer_ch, CALLOUT_MPSAFE); | | 1321 | callout_init(&ln->ln_timer_ch, CALLOUT_MPSAFE); |
1322 | /* this is required for "ndp" command. - shin */ | | 1322 | /* this is required for "ndp" command. - shin */ |
1323 | if (req == RTM_ADD) { | | 1323 | if (req == RTM_ADD) { |
1324 | /* | | 1324 | /* |
1325 | * gate should have some valid AF_LINK entry, | | 1325 | * gate should have some valid AF_LINK entry, |
1326 | * and ln->ln_expire should have some lifetime | | 1326 | * and ln->ln_expire should have some lifetime |
1327 | * which is specified by ndp command. | | 1327 | * which is specified by ndp command. |
1328 | */ | | 1328 | */ |
1329 | ln->ln_state = ND6_LLINFO_REACHABLE; | | 1329 | ln->ln_state = ND6_LLINFO_REACHABLE; |
1330 | ln->ln_byhint = 0; | | 1330 | ln->ln_byhint = 0; |
1331 | } else { | | 1331 | } else { |
1332 | /* | | 1332 | /* |
1333 | * When req == RTM_RESOLVE, rt is created and | | 1333 | * When req == RTM_RESOLVE, rt is created and |
1334 | * initialized in rtrequest(), so rt_expire is 0. | | 1334 | * initialized in rtrequest(), so rt_expire is 0. |
1335 | */ | | 1335 | */ |
1336 | ln->ln_state = ND6_LLINFO_NOSTATE; | | 1336 | ln->ln_state = ND6_LLINFO_NOSTATE; |
1337 | nd6_llinfo_settimer(ln, 0); | | 1337 | nd6_llinfo_settimer(ln, 0); |
1338 | } | | 1338 | } |
1339 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1339 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1340 | rt->rt_flags |= RTF_LLINFO; | | 1340 | rt->rt_flags |= RTF_LLINFO; |
1341 | ln->ln_next = llinfo_nd6.ln_next; | | 1341 | ln->ln_next = llinfo_nd6.ln_next; |
1342 | llinfo_nd6.ln_next = ln; | | 1342 | llinfo_nd6.ln_next = ln; |
1343 | ln->ln_prev = &llinfo_nd6; | | 1343 | ln->ln_prev = &llinfo_nd6; |
1344 | ln->ln_next->ln_prev = ln; | | 1344 | ln->ln_next->ln_prev = ln; |
1345 | | | 1345 | |
1346 | /* | | 1346 | /* |
1347 | * If we have too many cache entries, initiate immediate | | 1347 | * If we have too many cache entries, initiate immediate |
1348 | * purging for some "less recently used" entries. Note that | | 1348 | * purging for some "less recently used" entries. Note that |
1349 | * we cannot directly call nd6_free() here because it would | | 1349 | * we cannot directly call nd6_free() here because it would |
1350 | * cause re-entering rtable related routines triggering an LOR | | 1350 | * cause re-entering rtable related routines triggering an LOR |
1351 | * problem for FreeBSD. | | 1351 | * problem for FreeBSD. |
1352 | */ | | 1352 | */ |
1353 | if (ip6_neighborgcthresh >= 0 && | | 1353 | if (ip6_neighborgcthresh >= 0 && |
1354 | nd6_inuse >= ip6_neighborgcthresh) { | | 1354 | nd6_inuse >= ip6_neighborgcthresh) { |
1355 | int i; | | 1355 | int i; |
1356 | | | 1356 | |
1357 | for (i = 0; i < 10 && llinfo_nd6.ln_prev != ln; i++) { | | 1357 | for (i = 0; i < 10 && llinfo_nd6.ln_prev != ln; i++) { |
1358 | struct llinfo_nd6 *ln_end = llinfo_nd6.ln_prev; | | 1358 | struct llinfo_nd6 *ln_end = llinfo_nd6.ln_prev; |
1359 | | | 1359 | |
1360 | /* Move this entry to the head */ | | 1360 | /* Move this entry to the head */ |
1361 | LN_DEQUEUE(ln_end); | | 1361 | LN_DEQUEUE(ln_end); |
1362 | LN_INSERTHEAD(ln_end); | | 1362 | LN_INSERTHEAD(ln_end); |
1363 | | | 1363 | |
1364 | if (ND6_LLINFO_PERMANENT(ln_end)) | | 1364 | if (ND6_LLINFO_PERMANENT(ln_end)) |
1365 | continue; | | 1365 | continue; |
1366 | | | 1366 | |
1367 | if (ln_end->ln_state > ND6_LLINFO_INCOMPLETE) | | 1367 | if (ln_end->ln_state > ND6_LLINFO_INCOMPLETE) |
1368 | ln_end->ln_state = ND6_LLINFO_STALE; | | 1368 | ln_end->ln_state = ND6_LLINFO_STALE; |
1369 | else | | 1369 | else |
1370 | ln_end->ln_state = ND6_LLINFO_PURGE; | | 1370 | ln_end->ln_state = ND6_LLINFO_PURGE; |
1371 | nd6_llinfo_settimer(ln_end, 0); | | 1371 | nd6_llinfo_settimer(ln_end, 0); |
1372 | } | | 1372 | } |
1373 | } | | 1373 | } |
1374 | | | 1374 | |
1375 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1375 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1376 | /* | | 1376 | /* |
1377 | * check if rt_getkey(rt) is an address assigned | | 1377 | * check if rt_getkey(rt) is an address assigned |
1378 | * to the interface. | | 1378 | * to the interface. |
1379 | */ | | 1379 | */ |
1380 | ifa = (struct ifaddr *)in6ifa_ifpwithaddr(ifp, | | 1380 | ifa = (struct ifaddr *)in6ifa_ifpwithaddr(ifp, |
1381 | &satocsin6(rt_getkey(rt))->sin6_addr); | | 1381 | &satocsin6(rt_getkey(rt))->sin6_addr); |
1382 | RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); | | 1382 | RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt)); |
1383 | if (ifa != NULL) { | | 1383 | if (ifa != NULL) { |
1384 | const void *mac; | | 1384 | const void *mac; |
1385 | nd6_llinfo_settimer(ln, -1); | | 1385 | nd6_llinfo_settimer(ln, -1); |
1386 | ln->ln_state = ND6_LLINFO_REACHABLE; | | 1386 | ln->ln_state = ND6_LLINFO_REACHABLE; |
1387 | ln->ln_byhint = 0; | | 1387 | ln->ln_byhint = 0; |
1388 | if ((mac = nd6_ifptomac(ifp)) != NULL) { | | 1388 | if ((mac = nd6_ifptomac(ifp)) != NULL) { |
1389 | /* XXX check for error */ | | 1389 | /* XXX check for error */ |
1390 | if (sockaddr_dl_setaddr(satosdl(gate), | | 1390 | if (sockaddr_dl_setaddr(satosdl(gate), |
1391 | gate->sa_len, mac, | | 1391 | gate->sa_len, mac, |
1392 | ifp->if_addrlen) == NULL) { | | 1392 | ifp->if_addrlen) == NULL) { |
1393 | printf("%s.%d: " | | 1393 | printf("%s.%d: " |
1394 | "sockaddr_dl_setaddr(, %d, ) " | | 1394 | "sockaddr_dl_setaddr(, %d, ) " |
1395 | "failed on %s\n", __func__, | | 1395 | "failed on %s\n", __func__, |
1396 | __LINE__, gate->sa_len, | | 1396 | __LINE__, gate->sa_len, |
1397 | if_name(ifp)); | | 1397 | if_name(ifp)); |
1398 | } | | 1398 | } |
1399 | } | | 1399 | } |
1400 | if (nd6_useloopback) { | | 1400 | if (nd6_useloopback) { |
1401 | ifp = rt->rt_ifp = lo0ifp; /* XXX */ | | 1401 | ifp = rt->rt_ifp = lo0ifp; /* XXX */ |
1402 | /* | | 1402 | /* |
1403 | * Make sure rt_ifa be equal to the ifaddr | | 1403 | * Make sure rt_ifa be equal to the ifaddr |
1404 | * corresponding to the address. | | 1404 | * corresponding to the address. |
1405 | * We need this because when we refer | | 1405 | * We need this because when we refer |
1406 | * rt_ifa->ia6_flags in ip6_input, we assume | | 1406 | * rt_ifa->ia6_flags in ip6_input, we assume |
1407 | * that the rt_ifa points to the address instead | | 1407 | * that the rt_ifa points to the address instead |
1408 | * of the loopback address. | | 1408 | * of the loopback address. |
1409 | */ | | 1409 | */ |
1410 | if (ifa != rt->rt_ifa) | | 1410 | if (ifa != rt->rt_ifa) |
1411 | rt_replace_ifa(rt, ifa); | | 1411 | rt_replace_ifa(rt, ifa); |
1412 | rt->rt_flags &= ~RTF_CLONED; | | 1412 | rt->rt_flags &= ~RTF_CLONED; |
1413 | } | | 1413 | } |
1414 | } else if (rt->rt_flags & RTF_ANNOUNCE) { | | 1414 | } else if (rt->rt_flags & RTF_ANNOUNCE) { |
1415 | nd6_llinfo_settimer(ln, -1); | | 1415 | nd6_llinfo_settimer(ln, -1); |
1416 | ln->ln_state = ND6_LLINFO_REACHABLE; | | 1416 | ln->ln_state = ND6_LLINFO_REACHABLE; |
1417 | ln->ln_byhint = 0; | | 1417 | ln->ln_byhint = 0; |
1418 | | | 1418 | |
1419 | /* join solicited node multicast for proxy ND */ | | 1419 | /* join solicited node multicast for proxy ND */ |
1420 | if (ifp->if_flags & IFF_MULTICAST) { | | 1420 | if (ifp->if_flags & IFF_MULTICAST) { |
1421 | struct in6_addr llsol; | | 1421 | struct in6_addr llsol; |
1422 | int error; | | 1422 | int error; |
1423 | | | 1423 | |
1424 | llsol = satocsin6(rt_getkey(rt))->sin6_addr; | | 1424 | llsol = satocsin6(rt_getkey(rt))->sin6_addr; |
1425 | llsol.s6_addr32[0] = htonl(0xff020000); | | 1425 | llsol.s6_addr32[0] = htonl(0xff020000); |
1426 | llsol.s6_addr32[1] = 0; | | 1426 | llsol.s6_addr32[1] = 0; |
1427 | llsol.s6_addr32[2] = htonl(1); | | 1427 | llsol.s6_addr32[2] = htonl(1); |
1428 | llsol.s6_addr8[12] = 0xff; | | 1428 | llsol.s6_addr8[12] = 0xff; |
1429 | if (in6_setscope(&llsol, ifp, NULL)) | | 1429 | if (in6_setscope(&llsol, ifp, NULL)) |
1430 | break; | | 1430 | break; |
1431 | if (!in6_addmulti(&llsol, ifp, &error, 0)) { | | 1431 | if (!in6_addmulti(&llsol, ifp, &error, 0)) { |
1432 | nd6log((LOG_ERR, "%s: failed to join " | | 1432 | nd6log((LOG_ERR, "%s: failed to join " |
1433 | "%s (errno=%d)\n", if_name(ifp), | | 1433 | "%s (errno=%d)\n", if_name(ifp), |
1434 | ip6_sprintf(&llsol), error)); | | 1434 | ip6_sprintf(&llsol), error)); |
1435 | } | | 1435 | } |
1436 | } | | 1436 | } |
1437 | } | | 1437 | } |
1438 | break; | | 1438 | break; |
1439 | | | 1439 | |
1440 | case RTM_DELETE: | | 1440 | case RTM_DELETE: |
1441 | if (ln == NULL) | | 1441 | if (ln == NULL) |
1442 | break; | | 1442 | break; |
1443 | /* leave from solicited node multicast for proxy ND */ | | 1443 | /* leave from solicited node multicast for proxy ND */ |
1444 | if ((rt->rt_flags & RTF_ANNOUNCE) != 0 && | | 1444 | if ((rt->rt_flags & RTF_ANNOUNCE) != 0 && |
1445 | (ifp->if_flags & IFF_MULTICAST) != 0) { | | 1445 | (ifp->if_flags & IFF_MULTICAST) != 0) { |
1446 | struct in6_addr llsol; | | 1446 | struct in6_addr llsol; |
1447 | struct in6_multi *in6m; | | 1447 | struct in6_multi *in6m; |
1448 | | | 1448 | |
1449 | llsol = satocsin6(rt_getkey(rt))->sin6_addr; | | 1449 | llsol = satocsin6(rt_getkey(rt))->sin6_addr; |
1450 | llsol.s6_addr32[0] = htonl(0xff020000); | | 1450 | llsol.s6_addr32[0] = htonl(0xff020000); |
1451 | llsol.s6_addr32[1] = 0; | | 1451 | llsol.s6_addr32[1] = 0; |
1452 | llsol.s6_addr32[2] = htonl(1); | | 1452 | llsol.s6_addr32[2] = htonl(1); |
1453 | llsol.s6_addr8[12] = 0xff; | | 1453 | llsol.s6_addr8[12] = 0xff; |
1454 | if (in6_setscope(&llsol, ifp, NULL) == 0) { | | 1454 | if (in6_setscope(&llsol, ifp, NULL) == 0) { |
1455 | IN6_LOOKUP_MULTI(llsol, ifp, in6m); | | 1455 | IN6_LOOKUP_MULTI(llsol, ifp, in6m); |
1456 | if (in6m) | | 1456 | if (in6m) |
1457 | in6_delmulti(in6m); | | 1457 | in6_delmulti(in6m); |
1458 | } | | 1458 | } |
1459 | } | | 1459 | } |
1460 | nd6_inuse--; | | 1460 | nd6_inuse--; |
1461 | ln->ln_next->ln_prev = ln->ln_prev; | | 1461 | ln->ln_next->ln_prev = ln->ln_prev; |
1462 | ln->ln_prev->ln_next = ln->ln_next; | | 1462 | ln->ln_prev->ln_next = ln->ln_next; |
1463 | ln->ln_prev = NULL; | | 1463 | ln->ln_prev = NULL; |
1464 | nd6_llinfo_settimer(ln, -1); | | 1464 | nd6_llinfo_settimer(ln, -1); |
1465 | rt->rt_llinfo = 0; | | 1465 | rt->rt_llinfo = 0; |
1466 | rt->rt_flags &= ~RTF_LLINFO; | | 1466 | rt->rt_flags &= ~RTF_LLINFO; |
1467 | clear_llinfo_pqueue(ln); | | 1467 | clear_llinfo_pqueue(ln); |
1468 | Free(ln); | | 1468 | Free(ln); |
1469 | } | | 1469 | } |
1470 | } | | 1470 | } |
1471 | | | 1471 | |
1472 | int | | 1472 | int |
1473 | nd6_ioctl(u_long cmd, void *data, struct ifnet *ifp) | | 1473 | nd6_ioctl(u_long cmd, void *data, struct ifnet *ifp) |
1474 | { | | 1474 | { |
1475 | struct in6_drlist *drl = (struct in6_drlist *)data; | | 1475 | struct in6_drlist *drl = (struct in6_drlist *)data; |
1476 | struct in6_oprlist *oprl = (struct in6_oprlist *)data; | | 1476 | struct in6_oprlist *oprl = (struct in6_oprlist *)data; |
1477 | struct in6_ndireq *ndi = (struct in6_ndireq *)data; | | 1477 | struct in6_ndireq *ndi = (struct in6_ndireq *)data; |
1478 | struct in6_nbrinfo *nbi = (struct in6_nbrinfo *)data; | | 1478 | struct in6_nbrinfo *nbi = (struct in6_nbrinfo *)data; |
1479 | struct in6_ndifreq *ndif = (struct in6_ndifreq *)data; | | 1479 | struct in6_ndifreq *ndif = (struct in6_ndifreq *)data; |
1480 | struct nd_defrouter *dr; | | 1480 | struct nd_defrouter *dr; |
1481 | struct nd_prefix *pr; | | 1481 | struct nd_prefix *pr; |
1482 | struct rtentry *rt; | | 1482 | struct rtentry *rt; |
1483 | int i = 0, error = 0; | | 1483 | int i = 0, error = 0; |
1484 | int s; | | 1484 | int s; |
1485 | | | 1485 | |
1486 | switch (cmd) { | | 1486 | switch (cmd) { |
1487 | case SIOCGDRLST_IN6: | | 1487 | case SIOCGDRLST_IN6: |
1488 | /* | | 1488 | /* |
1489 | * obsolete API, use sysctl under net.inet6.icmp6 | | 1489 | * obsolete API, use sysctl under net.inet6.icmp6 |
1490 | */ | | 1490 | */ |
1491 | memset(drl, 0, sizeof(*drl)); | | 1491 | memset(drl, 0, sizeof(*drl)); |
1492 | s = splsoftnet(); | | 1492 | s = splsoftnet(); |
1493 | TAILQ_FOREACH(dr, &nd_defrouter, dr_entry) { | | 1493 | TAILQ_FOREACH(dr, &nd_defrouter, dr_entry) { |
1494 | if (i >= DRLSTSIZ) | | 1494 | if (i >= DRLSTSIZ) |
1495 | break; | | 1495 | break; |
1496 | drl->defrouter[i].rtaddr = dr->rtaddr; | | 1496 | drl->defrouter[i].rtaddr = dr->rtaddr; |
1497 | in6_clearscope(&drl->defrouter[i].rtaddr); | | 1497 | in6_clearscope(&drl->defrouter[i].rtaddr); |
1498 | | | 1498 | |
1499 | drl->defrouter[i].flags = dr->flags; | | 1499 | drl->defrouter[i].flags = dr->flags; |
1500 | drl->defrouter[i].rtlifetime = dr->rtlifetime; | | 1500 | drl->defrouter[i].rtlifetime = dr->rtlifetime; |
1501 | drl->defrouter[i].expire = dr->expire; | | 1501 | drl->defrouter[i].expire = dr->expire; |
1502 | drl->defrouter[i].if_index = dr->ifp->if_index; | | 1502 | drl->defrouter[i].if_index = dr->ifp->if_index; |
1503 | i++; | | 1503 | i++; |
1504 | } | | 1504 | } |
1505 | splx(s); | | 1505 | splx(s); |
1506 | break; | | 1506 | break; |
1507 | case SIOCGPRLST_IN6: | | 1507 | case SIOCGPRLST_IN6: |
1508 | /* | | 1508 | /* |
1509 | * obsolete API, use sysctl under net.inet6.icmp6 | | 1509 | * obsolete API, use sysctl under net.inet6.icmp6 |
1510 | * | | 1510 | * |
1511 | * XXX the structure in6_prlist was changed in backward- | | 1511 | * XXX the structure in6_prlist was changed in backward- |
1512 | * incompatible manner. in6_oprlist is used for SIOCGPRLST_IN6, | | 1512 | * incompatible manner. in6_oprlist is used for SIOCGPRLST_IN6, |
1513 | * in6_prlist is used for nd6_sysctl() - fill_prlist(). | | 1513 | * in6_prlist is used for nd6_sysctl() - fill_prlist(). |
1514 | */ | | 1514 | */ |
1515 | /* | | 1515 | /* |
1516 | * XXX meaning of fields, especialy "raflags", is very | | 1516 | * XXX meaning of fields, especialy "raflags", is very |
1517 | * differnet between RA prefix list and RR/static prefix list. | | 1517 | * differnet between RA prefix list and RR/static prefix list. |
1518 | * how about separating ioctls into two? | | 1518 | * how about separating ioctls into two? |
1519 | */ | | 1519 | */ |
1520 | memset(oprl, 0, sizeof(*oprl)); | | 1520 | memset(oprl, 0, sizeof(*oprl)); |
1521 | s = splsoftnet(); | | 1521 | s = splsoftnet(); |
1522 | LIST_FOREACH(pr, &nd_prefix, ndpr_entry) { | | 1522 | LIST_FOREACH(pr, &nd_prefix, ndpr_entry) { |
1523 | struct nd_pfxrouter *pfr; | | 1523 | struct nd_pfxrouter *pfr; |
1524 | int j; | | 1524 | int j; |
1525 | | | 1525 | |
1526 | if (i >= PRLSTSIZ) | | 1526 | if (i >= PRLSTSIZ) |
1527 | break; | | 1527 | break; |
1528 | oprl->prefix[i].prefix = pr->ndpr_prefix.sin6_addr; | | 1528 | oprl->prefix[i].prefix = pr->ndpr_prefix.sin6_addr; |
1529 | oprl->prefix[i].raflags = pr->ndpr_raf; | | 1529 | oprl->prefix[i].raflags = pr->ndpr_raf; |
1530 | oprl->prefix[i].prefixlen = pr->ndpr_plen; | | 1530 | oprl->prefix[i].prefixlen = pr->ndpr_plen; |
1531 | oprl->prefix[i].vltime = pr->ndpr_vltime; | | 1531 | oprl->prefix[i].vltime = pr->ndpr_vltime; |
1532 | oprl->prefix[i].pltime = pr->ndpr_pltime; | | 1532 | oprl->prefix[i].pltime = pr->ndpr_pltime; |
1533 | oprl->prefix[i].if_index = pr->ndpr_ifp->if_index; | | 1533 | oprl->prefix[i].if_index = pr->ndpr_ifp->if_index; |
1534 | if (pr->ndpr_vltime == ND6_INFINITE_LIFETIME) | | 1534 | if (pr->ndpr_vltime == ND6_INFINITE_LIFETIME) |
1535 | oprl->prefix[i].expire = 0; | | 1535 | oprl->prefix[i].expire = 0; |
1536 | else { | | 1536 | else { |
1537 | time_t maxexpire; | | 1537 | time_t maxexpire; |
1538 | | | 1538 | |
1539 | /* XXX: we assume time_t is signed. */ | | 1539 | /* XXX: we assume time_t is signed. */ |
1540 | maxexpire = (-1) & | | 1540 | maxexpire = (-1) & |
1541 | ~((time_t)1 << | | 1541 | ~((time_t)1 << |
1542 | ((sizeof(maxexpire) * 8) - 1)); | | 1542 | ((sizeof(maxexpire) * 8) - 1)); |
1543 | if (pr->ndpr_vltime < | | 1543 | if (pr->ndpr_vltime < |
1544 | maxexpire - pr->ndpr_lastupdate) { | | 1544 | maxexpire - pr->ndpr_lastupdate) { |
1545 | oprl->prefix[i].expire = | | 1545 | oprl->prefix[i].expire = |
1546 | pr->ndpr_lastupdate + | | 1546 | pr->ndpr_lastupdate + |
1547 | pr->ndpr_vltime; | | 1547 | pr->ndpr_vltime; |
1548 | } else | | 1548 | } else |
1549 | oprl->prefix[i].expire = maxexpire; | | 1549 | oprl->prefix[i].expire = maxexpire; |
1550 | } | | 1550 | } |
1551 | | | 1551 | |
1552 | j = 0; | | 1552 | j = 0; |
1553 | LIST_FOREACH(pfr, &pr->ndpr_advrtrs, pfr_entry) { | | 1553 | LIST_FOREACH(pfr, &pr->ndpr_advrtrs, pfr_entry) { |
1554 | if (j < DRLSTSIZ) { | | 1554 | if (j < DRLSTSIZ) { |
1555 | #define RTRADDR oprl->prefix[i].advrtr[j] | | 1555 | #define RTRADDR oprl->prefix[i].advrtr[j] |
1556 | RTRADDR = pfr->router->rtaddr; | | 1556 | RTRADDR = pfr->router->rtaddr; |
1557 | in6_clearscope(&RTRADDR); | | 1557 | in6_clearscope(&RTRADDR); |
1558 | #undef RTRADDR | | 1558 | #undef RTRADDR |
1559 | } | | 1559 | } |
1560 | j++; | | 1560 | j++; |
1561 | } | | 1561 | } |
1562 | oprl->prefix[i].advrtrs = j; | | 1562 | oprl->prefix[i].advrtrs = j; |
1563 | oprl->prefix[i].origin = PR_ORIG_RA; | | 1563 | oprl->prefix[i].origin = PR_ORIG_RA; |
1564 | | | 1564 | |
1565 | i++; | | 1565 | i++; |
1566 | } | | 1566 | } |
1567 | splx(s); | | 1567 | splx(s); |
1568 | | | 1568 | |
1569 | break; | | 1569 | break; |
1570 | case OSIOCGIFINFO_IN6: | | 1570 | case OSIOCGIFINFO_IN6: |
1571 | #define ND ndi->ndi | | 1571 | #define ND ndi->ndi |
1572 | /* XXX: old ndp(8) assumes a positive value for linkmtu. */ | | 1572 | /* XXX: old ndp(8) assumes a positive value for linkmtu. */ |
1573 | memset(&ND, 0, sizeof(ND)); | | 1573 | memset(&ND, 0, sizeof(ND)); |
1574 | ND.linkmtu = IN6_LINKMTU(ifp); | | 1574 | ND.linkmtu = IN6_LINKMTU(ifp); |
1575 | ND.maxmtu = ND_IFINFO(ifp)->maxmtu; | | 1575 | ND.maxmtu = ND_IFINFO(ifp)->maxmtu; |
1576 | ND.basereachable = ND_IFINFO(ifp)->basereachable; | | 1576 | ND.basereachable = ND_IFINFO(ifp)->basereachable; |
1577 | ND.reachable = ND_IFINFO(ifp)->reachable; | | 1577 | ND.reachable = ND_IFINFO(ifp)->reachable; |
1578 | ND.retrans = ND_IFINFO(ifp)->retrans; | | 1578 | ND.retrans = ND_IFINFO(ifp)->retrans; |
1579 | ND.flags = ND_IFINFO(ifp)->flags; | | 1579 | ND.flags = ND_IFINFO(ifp)->flags; |
1580 | ND.recalctm = ND_IFINFO(ifp)->recalctm; | | 1580 | ND.recalctm = ND_IFINFO(ifp)->recalctm; |
1581 | ND.chlim = ND_IFINFO(ifp)->chlim; | | 1581 | ND.chlim = ND_IFINFO(ifp)->chlim; |
1582 | break; | | 1582 | break; |
1583 | case SIOCGIFINFO_IN6: | | 1583 | case SIOCGIFINFO_IN6: |
1584 | ND = *ND_IFINFO(ifp); | | 1584 | ND = *ND_IFINFO(ifp); |
1585 | break; | | 1585 | break; |
1586 | case SIOCSIFINFO_IN6: | | 1586 | case SIOCSIFINFO_IN6: |
1587 | /* | | 1587 | /* |
1588 | * used to change host variables from userland. | | 1588 | * used to change host variables from userland. |
1589 | * intented for a use on router to reflect RA configurations. | | 1589 | * intented for a use on router to reflect RA configurations. |
1590 | */ | | 1590 | */ |
1591 | /* 0 means 'unspecified' */ | | 1591 | /* 0 means 'unspecified' */ |
1592 | if (ND.linkmtu != 0) { | | 1592 | if (ND.linkmtu != 0) { |
1593 | if (ND.linkmtu < IPV6_MMTU || | | 1593 | if (ND.linkmtu < IPV6_MMTU || |
1594 | ND.linkmtu > IN6_LINKMTU(ifp)) { | | 1594 | ND.linkmtu > IN6_LINKMTU(ifp)) { |
1595 | error = EINVAL; | | 1595 | error = EINVAL; |
1596 | break; | | 1596 | break; |
1597 | } | | 1597 | } |
1598 | ND_IFINFO(ifp)->linkmtu = ND.linkmtu; | | 1598 | ND_IFINFO(ifp)->linkmtu = ND.linkmtu; |
1599 | } | | 1599 | } |
1600 | | | 1600 | |
1601 | if (ND.basereachable != 0) { | | 1601 | if (ND.basereachable != 0) { |
1602 | int obasereachable = ND_IFINFO(ifp)->basereachable; | | 1602 | int obasereachable = ND_IFINFO(ifp)->basereachable; |
1603 | | | 1603 | |
1604 | ND_IFINFO(ifp)->basereachable = ND.basereachable; | | 1604 | ND_IFINFO(ifp)->basereachable = ND.basereachable; |
1605 | if (ND.basereachable != obasereachable) | | 1605 | if (ND.basereachable != obasereachable) |
1606 | ND_IFINFO(ifp)->reachable = | | 1606 | ND_IFINFO(ifp)->reachable = |
1607 | ND_COMPUTE_RTIME(ND.basereachable); | | 1607 | ND_COMPUTE_RTIME(ND.basereachable); |
1608 | } | | 1608 | } |
1609 | if (ND.retrans != 0) | | 1609 | if (ND.retrans != 0) |
1610 | ND_IFINFO(ifp)->retrans = ND.retrans; | | 1610 | ND_IFINFO(ifp)->retrans = ND.retrans; |
1611 | if (ND.chlim != 0) | | 1611 | if (ND.chlim != 0) |
1612 | ND_IFINFO(ifp)->chlim = ND.chlim; | | 1612 | ND_IFINFO(ifp)->chlim = ND.chlim; |
1613 | /* FALLTHROUGH */ | | 1613 | /* FALLTHROUGH */ |
1614 | case SIOCSIFINFO_FLAGS: | | 1614 | case SIOCSIFINFO_FLAGS: |
1615 | ND_IFINFO(ifp)->flags = ND.flags; | | 1615 | ND_IFINFO(ifp)->flags = ND.flags; |
1616 | break; | | 1616 | break; |
1617 | #undef ND | | 1617 | #undef ND |
1618 | case SIOCSNDFLUSH_IN6: /* XXX: the ioctl name is confusing... */ | | 1618 | case SIOCSNDFLUSH_IN6: /* XXX: the ioctl name is confusing... */ |
1619 | /* sync kernel routing table with the default router list */ | | 1619 | /* sync kernel routing table with the default router list */ |
1620 | defrouter_reset(); | | 1620 | defrouter_reset(); |
1621 | defrouter_select(); | | 1621 | defrouter_select(); |
1622 | break; | | 1622 | break; |
1623 | case SIOCSPFXFLUSH_IN6: | | 1623 | case SIOCSPFXFLUSH_IN6: |
1624 | { | | 1624 | { |
1625 | /* flush all the prefix advertised by routers */ | | 1625 | /* flush all the prefix advertised by routers */ |
1626 | struct nd_prefix *pfx, *next; | | 1626 | struct nd_prefix *pfx, *next; |
1627 | | | 1627 | |
1628 | s = splsoftnet(); | | 1628 | s = splsoftnet(); |
1629 | LIST_FOREACH_SAFE(pfx, &nd_prefix, ndpr_entry, next) { | | 1629 | LIST_FOREACH_SAFE(pfx, &nd_prefix, ndpr_entry, next) { |
1630 | struct in6_ifaddr *ia, *ia_next; | | 1630 | struct in6_ifaddr *ia, *ia_next; |
1631 | | | 1631 | |
1632 | if (IN6_IS_ADDR_LINKLOCAL(&pfx->ndpr_prefix.sin6_addr)) | | 1632 | if (IN6_IS_ADDR_LINKLOCAL(&pfx->ndpr_prefix.sin6_addr)) |
1633 | continue; /* XXX */ | | 1633 | continue; /* XXX */ |
1634 | | | 1634 | |
1635 | /* do we really have to remove addresses as well? */ | | 1635 | /* do we really have to remove addresses as well? */ |
1636 | for (ia = in6_ifaddr; ia; ia = ia_next) { | | 1636 | for (ia = in6_ifaddr; ia; ia = ia_next) { |
1637 | /* ia might be removed. keep the next ptr. */ | | 1637 | /* ia might be removed. keep the next ptr. */ |
1638 | ia_next = ia->ia_next; | | 1638 | ia_next = ia->ia_next; |
1639 | | | 1639 | |
1640 | if ((ia->ia6_flags & IN6_IFF_AUTOCONF) == 0) | | 1640 | if ((ia->ia6_flags & IN6_IFF_AUTOCONF) == 0) |
1641 | continue; | | 1641 | continue; |
1642 | | | 1642 | |
1643 | if (ia->ia6_ndpr == pfx) | | 1643 | if (ia->ia6_ndpr == pfx) |
1644 | in6_purgeaddr(&ia->ia_ifa); | | 1644 | in6_purgeaddr(&ia->ia_ifa); |
1645 | } | | 1645 | } |
1646 | prelist_remove(pfx); | | 1646 | prelist_remove(pfx); |
1647 | } | | 1647 | } |
1648 | splx(s); | | 1648 | splx(s); |
1649 | break; | | 1649 | break; |
1650 | } | | 1650 | } |
1651 | case SIOCSRTRFLUSH_IN6: | | 1651 | case SIOCSRTRFLUSH_IN6: |
1652 | { | | 1652 | { |
1653 | /* flush all the default routers */ | | 1653 | /* flush all the default routers */ |
1654 | struct nd_defrouter *drtr, *next; | | 1654 | struct nd_defrouter *drtr, *next; |
1655 | | | 1655 | |
1656 | s = splsoftnet(); | | 1656 | s = splsoftnet(); |
1657 | defrouter_reset(); | | 1657 | defrouter_reset(); |
1658 | TAILQ_FOREACH_SAFE(drtr, &nd_defrouter, dr_entry, next) { | | 1658 | TAILQ_FOREACH_SAFE(drtr, &nd_defrouter, dr_entry, next) { |
1659 | defrtrlist_del(drtr); | | 1659 | defrtrlist_del(drtr); |
1660 | } | | 1660 | } |
1661 | defrouter_select(); | | 1661 | defrouter_select(); |
1662 | splx(s); | | 1662 | splx(s); |
1663 | break; | | 1663 | break; |
1664 | } | | 1664 | } |
1665 | case SIOCGNBRINFO_IN6: | | 1665 | case SIOCGNBRINFO_IN6: |
1666 | { | | 1666 | { |
1667 | struct llinfo_nd6 *ln; | | 1667 | struct llinfo_nd6 *ln; |
1668 | struct in6_addr nb_addr = nbi->addr; /* make local for safety */ | | 1668 | struct in6_addr nb_addr = nbi->addr; /* make local for safety */ |
1669 | | | 1669 | |
1670 | if ((error = in6_setscope(&nb_addr, ifp, NULL)) != 0) | | 1670 | if ((error = in6_setscope(&nb_addr, ifp, NULL)) != 0) |
1671 | return error; | | 1671 | return error; |
1672 | | | 1672 | |
1673 | s = splsoftnet(); | | 1673 | s = splsoftnet(); |
1674 | if ((rt = nd6_lookup(&nb_addr, 0, ifp)) == NULL || | | 1674 | if ((rt = nd6_lookup(&nb_addr, 0, ifp)) == NULL || |
1675 | (ln = (struct llinfo_nd6 *)rt->rt_llinfo) == NULL) { | | 1675 | (ln = (struct llinfo_nd6 *)rt->rt_llinfo) == NULL) { |
1676 | error = EINVAL; | | 1676 | error = EINVAL; |
1677 | splx(s); | | 1677 | splx(s); |
1678 | break; | | 1678 | break; |
1679 | } | | 1679 | } |
1680 | nbi->state = ln->ln_state; | | 1680 | nbi->state = ln->ln_state; |
1681 | nbi->asked = ln->ln_asked; | | 1681 | nbi->asked = ln->ln_asked; |
1682 | nbi->isrouter = ln->ln_router; | | 1682 | nbi->isrouter = ln->ln_router; |
1683 | nbi->expire = ln->ln_expire; | | 1683 | nbi->expire = ln->ln_expire; |
1684 | splx(s); | | 1684 | splx(s); |
1685 | | | 1685 | |
1686 | break; | | 1686 | break; |
1687 | } | | 1687 | } |
1688 | case SIOCGDEFIFACE_IN6: /* XXX: should be implemented as a sysctl? */ | | 1688 | case SIOCGDEFIFACE_IN6: /* XXX: should be implemented as a sysctl? */ |
1689 | ndif->ifindex = nd6_defifindex; | | 1689 | ndif->ifindex = nd6_defifindex; |
1690 | break; | | 1690 | break; |
1691 | case SIOCSDEFIFACE_IN6: /* XXX: should be implemented as a sysctl? */ | | 1691 | case SIOCSDEFIFACE_IN6: /* XXX: should be implemented as a sysctl? */ |
1692 | return nd6_setdefaultiface(ndif->ifindex); | | 1692 | return nd6_setdefaultiface(ndif->ifindex); |
1693 | } | | 1693 | } |
1694 | return error; | | 1694 | return error; |
1695 | } | | 1695 | } |
1696 | | | 1696 | |
1697 | void | | 1697 | void |
1698 | nd6_llinfo_release_pkts(struct llinfo_nd6 *ln, struct ifnet *ifp, | | 1698 | nd6_llinfo_release_pkts(struct llinfo_nd6 *ln, struct ifnet *ifp, |
1699 | struct rtentry *rt) | | 1699 | struct rtentry *rt) |
1700 | { | | 1700 | { |
1701 | struct mbuf *m_hold, *m_hold_next; | | 1701 | struct mbuf *m_hold, *m_hold_next; |
1702 | | | 1702 | |
1703 | for (m_hold = ln->ln_hold, ln->ln_hold = NULL; | | 1703 | for (m_hold = ln->ln_hold, ln->ln_hold = NULL; |
1704 | m_hold != NULL; | | 1704 | m_hold != NULL; |
1705 | m_hold = m_hold_next) { | | 1705 | m_hold = m_hold_next) { |
1706 | m_hold_next = m_hold->m_nextpkt; | | 1706 | m_hold_next = m_hold->m_nextpkt; |
1707 | m_hold->m_nextpkt = NULL; | | 1707 | m_hold->m_nextpkt = NULL; |
1708 | | | 1708 | |
1709 | /* | | 1709 | /* |
1710 | * we assume ifp is not a p2p here, so | | 1710 | * we assume ifp is not a p2p here, so |
1711 | * just set the 2nd argument as the | | 1711 | * just set the 2nd argument as the |
1712 | * 1st one. | | 1712 | * 1st one. |
1713 | */ | | 1713 | */ |
1714 | nd6_output(ifp, ifp, m_hold, satocsin6(rt_getkey(rt)), rt); | | 1714 | nd6_output(ifp, ifp, m_hold, satocsin6(rt_getkey(rt)), rt); |
1715 | } | | 1715 | } |
1716 | } | | 1716 | } |
1717 | | | 1717 | |
1718 | /* | | 1718 | /* |
1719 | * Create neighbor cache entry and cache link-layer address, | | 1719 | * Create neighbor cache entry and cache link-layer address, |
1720 | * on reception of inbound ND6 packets. (RS/RA/NS/redirect) | | 1720 | * on reception of inbound ND6 packets. (RS/RA/NS/redirect) |
1721 | */ | | 1721 | */ |
1722 | struct rtentry * | | 1722 | struct rtentry * |
1723 | nd6_cache_lladdr( | | 1723 | nd6_cache_lladdr( |
1724 | struct ifnet *ifp, | | 1724 | struct ifnet *ifp, |
1725 | struct in6_addr *from, | | 1725 | struct in6_addr *from, |
1726 | char *lladdr, | | 1726 | char *lladdr, |
1727 | int lladdrlen, | | 1727 | int lladdrlen, |
1728 | int type, /* ICMP6 type */ | | 1728 | int type, /* ICMP6 type */ |
1729 | int code /* type dependent information */ | | 1729 | int code /* type dependent information */ |
1730 | ) | | 1730 | ) |
1731 | { | | 1731 | { |
1732 | struct nd_ifinfo *ndi = ND_IFINFO(ifp); | | 1732 | struct nd_ifinfo *ndi = ND_IFINFO(ifp); |
1733 | struct rtentry *rt = NULL; | | 1733 | struct rtentry *rt = NULL; |
1734 | struct llinfo_nd6 *ln = NULL; | | 1734 | struct llinfo_nd6 *ln = NULL; |
1735 | int is_newentry; | | 1735 | int is_newentry; |
1736 | struct sockaddr_dl *sdl = NULL; | | 1736 | struct sockaddr_dl *sdl = NULL; |
1737 | int do_update; | | 1737 | int do_update; |
1738 | int olladdr; | | 1738 | int olladdr; |
1739 | int llchange; | | 1739 | int llchange; |
1740 | int newstate = 0; | | 1740 | int newstate = 0; |
1741 | | | 1741 | |
1742 | if (ifp == NULL) | | 1742 | if (ifp == NULL) |
1743 | panic("ifp == NULL in nd6_cache_lladdr"); | | 1743 | panic("ifp == NULL in nd6_cache_lladdr"); |
1744 | if (from == NULL) | | 1744 | if (from == NULL) |
1745 | panic("from == NULL in nd6_cache_lladdr"); | | 1745 | panic("from == NULL in nd6_cache_lladdr"); |
1746 | | | 1746 | |
1747 | /* nothing must be updated for unspecified address */ | | 1747 | /* nothing must be updated for unspecified address */ |
1748 | if (IN6_IS_ADDR_UNSPECIFIED(from)) | | 1748 | if (IN6_IS_ADDR_UNSPECIFIED(from)) |
1749 | return NULL; | | 1749 | return NULL; |
1750 | | | 1750 | |
1751 | /* | | 1751 | /* |
1752 | * Validation about ifp->if_addrlen and lladdrlen must be done in | | 1752 | * Validation about ifp->if_addrlen and lladdrlen must be done in |
1753 | * the caller. | | 1753 | * the caller. |
1754 | * | | 1754 | * |
1755 | * XXX If the link does not have link-layer adderss, what should | | 1755 | * XXX If the link does not have link-layer adderss, what should |
1756 | * we do? (ifp->if_addrlen == 0) | | 1756 | * we do? (ifp->if_addrlen == 0) |
1757 | * Spec says nothing in sections for RA, RS and NA. There's small | | 1757 | * Spec says nothing in sections for RA, RS and NA. There's small |
1758 | * description on it in NS section (RFC 2461 7.2.3). | | 1758 | * description on it in NS section (RFC 2461 7.2.3). |
1759 | */ | | 1759 | */ |
1760 | | | 1760 | |
1761 | rt = nd6_lookup(from, 0, ifp); | | 1761 | rt = nd6_lookup(from, 0, ifp); |
1762 | if (rt == NULL) { | | 1762 | if (rt == NULL) { |
1763 | #if 0 | | 1763 | #if 0 |
1764 | /* nothing must be done if there's no lladdr */ | | 1764 | /* nothing must be done if there's no lladdr */ |
1765 | if (!lladdr || !lladdrlen) | | 1765 | if (!lladdr || !lladdrlen) |
1766 | return NULL; | | 1766 | return NULL; |
1767 | #endif | | 1767 | #endif |
1768 | | | 1768 | |
1769 | rt = nd6_lookup(from, 1, ifp); | | 1769 | rt = nd6_lookup(from, 1, ifp); |
1770 | is_newentry = 1; | | 1770 | is_newentry = 1; |
1771 | } else { | | 1771 | } else { |
1772 | /* do nothing if static ndp is set */ | | 1772 | /* do nothing if static ndp is set */ |
1773 | if (rt->rt_flags & RTF_STATIC) | | 1773 | if (rt->rt_flags & RTF_STATIC) |
1774 | return NULL; | | 1774 | return NULL; |
1775 | is_newentry = 0; | | 1775 | is_newentry = 0; |
1776 | } | | 1776 | } |
1777 | | | 1777 | |
1778 | if (rt == NULL) | | 1778 | if (rt == NULL) |
1779 | return NULL; | | 1779 | return NULL; |
1780 | if ((rt->rt_flags & (RTF_GATEWAY | RTF_LLINFO)) != RTF_LLINFO) { | | 1780 | if ((rt->rt_flags & (RTF_GATEWAY | RTF_LLINFO)) != RTF_LLINFO) { |
1781 | fail: | | 1781 | fail: |
1782 | (void)nd6_free(rt, 0); | | 1782 | (void)nd6_free(rt, 0); |
1783 | return NULL; | | 1783 | return NULL; |
1784 | } | | 1784 | } |
1785 | ln = (struct llinfo_nd6 *)rt->rt_llinfo; | | 1785 | ln = (struct llinfo_nd6 *)rt->rt_llinfo; |
1786 | if (ln == NULL) | | 1786 | if (ln == NULL) |
1787 | goto fail; | | 1787 | goto fail; |
1788 | if (rt->rt_gateway == NULL) | | 1788 | if (rt->rt_gateway == NULL) |
1789 | goto fail; | | 1789 | goto fail; |
1790 | if (rt->rt_gateway->sa_family != AF_LINK) | | 1790 | if (rt->rt_gateway->sa_family != AF_LINK) |
1791 | goto fail; | | 1791 | goto fail; |
1792 | sdl = satosdl(rt->rt_gateway); | | 1792 | sdl = satosdl(rt->rt_gateway); |
1793 | | | 1793 | |
1794 | olladdr = (sdl->sdl_alen) ? 1 : 0; | | 1794 | olladdr = (sdl->sdl_alen) ? 1 : 0; |
1795 | if (olladdr && lladdr) { | | 1795 | if (olladdr && lladdr) { |
1796 | if (memcmp(lladdr, CLLADDR(sdl), ifp->if_addrlen)) | | 1796 | if (memcmp(lladdr, CLLADDR(sdl), ifp->if_addrlen)) |
1797 | llchange = 1; | | 1797 | llchange = 1; |
1798 | else | | 1798 | else |
1799 | llchange = 0; | | 1799 | llchange = 0; |
1800 | } else | | 1800 | } else |
1801 | llchange = 0; | | 1801 | llchange = 0; |
1802 | | | 1802 | |
1803 | /* | | 1803 | /* |
1804 | * newentry olladdr lladdr llchange (*=record) | | 1804 | * newentry olladdr lladdr llchange (*=record) |
1805 | * 0 n n -- (1) | | 1805 | * 0 n n -- (1) |
1806 | * 0 y n -- (2) | | 1806 | * 0 y n -- (2) |
1807 | * 0 n y -- (3) * STALE | | 1807 | * 0 n y -- (3) * STALE |
1808 | * 0 y y n (4) * | | 1808 | * 0 y y n (4) * |
1809 | * 0 y y y (5) * STALE | | 1809 | * 0 y y y (5) * STALE |
1810 | * 1 -- n -- (6) NOSTATE(= PASSIVE) | | 1810 | * 1 -- n -- (6) NOSTATE(= PASSIVE) |
1811 | * 1 -- y -- (7) * STALE | | 1811 | * 1 -- y -- (7) * STALE |
1812 | */ | | 1812 | */ |
1813 | | | 1813 | |
1814 | if (lladdr) { /* (3-5) and (7) */ | | 1814 | if (lladdr) { /* (3-5) and (7) */ |
1815 | /* | | 1815 | /* |
1816 | * Record source link-layer address | | 1816 | * Record source link-layer address |
1817 | * XXX is it dependent to ifp->if_type? | | 1817 | * XXX is it dependent to ifp->if_type? |
1818 | */ | | 1818 | */ |
1819 | /* XXX check for error */ | | 1819 | /* XXX check for error */ |
1820 | if (sockaddr_dl_setaddr(sdl, sdl->sdl_len, lladdr, | | 1820 | if (sockaddr_dl_setaddr(sdl, sdl->sdl_len, lladdr, |
1821 | ifp->if_addrlen) == NULL) { | | 1821 | ifp->if_addrlen) == NULL) { |
1822 | printf("%s.%d: sockaddr_dl_setaddr(, %d, ) " | | 1822 | printf("%s.%d: sockaddr_dl_setaddr(, %d, ) " |
1823 | "failed on %s\n", __func__, __LINE__, | | 1823 | "failed on %s\n", __func__, __LINE__, |
1824 | sdl->sdl_len, if_name(ifp)); | | 1824 | sdl->sdl_len, if_name(ifp)); |
1825 | } | | 1825 | } |
1826 | } | | 1826 | } |
1827 | | | 1827 | |
1828 | if (!is_newentry) { | | 1828 | if (!is_newentry) { |
1829 | if ((!olladdr && lladdr) || /* (3) */ | | 1829 | if ((!olladdr && lladdr) || /* (3) */ |
1830 | (olladdr && lladdr && llchange)) { /* (5) */ | | 1830 | (olladdr && lladdr && llchange)) { /* (5) */ |
1831 | do_update = 1; | | 1831 | do_update = 1; |
1832 | newstate = ND6_LLINFO_STALE; | | 1832 | newstate = ND6_LLINFO_STALE; |
1833 | } else /* (1-2,4) */ | | 1833 | } else /* (1-2,4) */ |
1834 | do_update = 0; | | 1834 | do_update = 0; |
1835 | } else { | | 1835 | } else { |
1836 | do_update = 1; | | 1836 | do_update = 1; |
1837 | if (lladdr == NULL) /* (6) */ | | 1837 | if (lladdr == NULL) /* (6) */ |
1838 | newstate = ND6_LLINFO_NOSTATE; | | 1838 | newstate = ND6_LLINFO_NOSTATE; |
1839 | else /* (7) */ | | 1839 | else /* (7) */ |
1840 | newstate = ND6_LLINFO_STALE; | | 1840 | newstate = ND6_LLINFO_STALE; |
1841 | } | | 1841 | } |
1842 | | | 1842 | |
1843 | if (do_update) { | | 1843 | if (do_update) { |
1844 | /* | | 1844 | /* |
1845 | * Update the state of the neighbor cache. | | 1845 | * Update the state of the neighbor cache. |
1846 | */ | | 1846 | */ |
1847 | ln->ln_state = newstate; | | 1847 | ln->ln_state = newstate; |
1848 | | | 1848 | |
1849 | if (ln->ln_state == ND6_LLINFO_STALE) { | | 1849 | if (ln->ln_state == ND6_LLINFO_STALE) { |
1850 | /* | | 1850 | /* |
1851 | * XXX: since nd6_output() below will cause | | 1851 | * XXX: since nd6_output() below will cause |
1852 | * state tansition to DELAY and reset the timer, | | 1852 | * state tansition to DELAY and reset the timer, |
1853 | * we must set the timer now, although it is actually | | 1853 | * we must set the timer now, although it is actually |
1854 | * meaningless. | | 1854 | * meaningless. |
1855 | */ | | 1855 | */ |
1856 | nd6_llinfo_settimer(ln, (long)nd6_gctimer * hz); | | 1856 | nd6_llinfo_settimer(ln, (long)nd6_gctimer * hz); |
1857 | | | 1857 | |
1858 | nd6_llinfo_release_pkts(ln, ifp, rt); | | 1858 | nd6_llinfo_release_pkts(ln, ifp, rt); |
1859 | } else if (ln->ln_state == ND6_LLINFO_INCOMPLETE) { | | 1859 | } else if (ln->ln_state == ND6_LLINFO_INCOMPLETE) { |
1860 | /* probe right away */ | | 1860 | /* probe right away */ |
1861 | nd6_llinfo_settimer((void *)ln, 0); | | 1861 | nd6_llinfo_settimer((void *)ln, 0); |
1862 | } | | 1862 | } |
1863 | } | | 1863 | } |
1864 | | | 1864 | |
1865 | /* | | 1865 | /* |
1866 | * ICMP6 type dependent behavior. | | 1866 | * ICMP6 type dependent behavior. |
1867 | * | | 1867 | * |
1868 | * NS: clear IsRouter if new entry | | 1868 | * NS: clear IsRouter if new entry |
1869 | * RS: clear IsRouter | | 1869 | * RS: clear IsRouter |
1870 | * RA: set IsRouter if there's lladdr | | 1870 | * RA: set IsRouter if there's lladdr |
1871 | * redir: clear IsRouter if new entry | | 1871 | * redir: clear IsRouter if new entry |
1872 | * | | 1872 | * |
1873 | * RA case, (1): | | 1873 | * RA case, (1): |
1874 | * The spec says that we must set IsRouter in the following cases: | | 1874 | * The spec says that we must set IsRouter in the following cases: |
1875 | * - If lladdr exist, set IsRouter. This means (1-5). | | 1875 | * - If lladdr exist, set IsRouter. This means (1-5). |
1876 | * - If it is old entry (!newentry), set IsRouter. This means (7). | | 1876 | * - If it is old entry (!newentry), set IsRouter. This means (7). |
1877 | * So, based on the spec, in (1-5) and (7) cases we must set IsRouter. | | 1877 | * So, based on the spec, in (1-5) and (7) cases we must set IsRouter. |
1878 | * A quetion arises for (1) case. (1) case has no lladdr in the | | 1878 | * A quetion arises for (1) case. (1) case has no lladdr in the |
1879 | * neighbor cache, this is similar to (6). | | 1879 | * neighbor cache, this is similar to (6). |
1880 | * This case is rare but we figured that we MUST NOT set IsRouter. | | 1880 | * This case is rare but we figured that we MUST NOT set IsRouter. |
1881 | * | | 1881 | * |
1882 | * newentry olladdr lladdr llchange NS RS RA redir | | 1882 | * newentry olladdr lladdr llchange NS RS RA redir |
1883 | * D R | | 1883 | * D R |
1884 | * 0 n n -- (1) c ? s | | 1884 | * 0 n n -- (1) c ? s |
1885 | * 0 y n -- (2) c s s | | 1885 | * 0 y n -- (2) c s s |
1886 | * 0 n y -- (3) c s s | | 1886 | * 0 n y -- (3) c s s |
1887 | * 0 y y n (4) c s s | | 1887 | * 0 y y n (4) c s s |
1888 | * 0 y y y (5) c s s | | 1888 | * 0 y y y (5) c s s |
1889 | * 1 -- n -- (6) c c c s | | 1889 | * 1 -- n -- (6) c c c s |
1890 | * 1 -- y -- (7) c c s c s | | 1890 | * 1 -- y -- (7) c c s c s |
1891 | * | | 1891 | * |
1892 | * (c=clear s=set) | | 1892 | * (c=clear s=set) |
1893 | */ | | 1893 | */ |
1894 | switch (type & 0xff) { | | 1894 | switch (type & 0xff) { |
1895 | case ND_NEIGHBOR_SOLICIT: | | 1895 | case ND_NEIGHBOR_SOLICIT: |
1896 | /* | | 1896 | /* |
1897 | * New entry must have is_router flag cleared. | | 1897 | * New entry must have is_router flag cleared. |
1898 | */ | | 1898 | */ |
1899 | if (is_newentry) /* (6-7) */ | | 1899 | if (is_newentry) /* (6-7) */ |
1900 | ln->ln_router = 0; | | 1900 | ln->ln_router = 0; |
1901 | break; | | 1901 | break; |
1902 | case ND_REDIRECT: | | 1902 | case ND_REDIRECT: |
1903 | /* | | 1903 | /* |
1904 | * If the icmp is a redirect to a better router, always set the | | 1904 | * If the icmp is a redirect to a better router, always set the |
1905 | * is_router flag. Otherwise, if the entry is newly created, | | 1905 | * is_router flag. Otherwise, if the entry is newly created, |
1906 | * clear the flag. [RFC 2461, sec 8.3] | | 1906 | * clear the flag. [RFC 2461, sec 8.3] |
1907 | */ | | 1907 | */ |
1908 | if (code == ND_REDIRECT_ROUTER) | | 1908 | if (code == ND_REDIRECT_ROUTER) |
1909 | ln->ln_router = 1; | | 1909 | ln->ln_router = 1; |
1910 | else if (is_newentry) /* (6-7) */ | | 1910 | else if (is_newentry) /* (6-7) */ |
1911 | ln->ln_router = 0; | | 1911 | ln->ln_router = 0; |
1912 | break; | | 1912 | break; |
1913 | case ND_ROUTER_SOLICIT: | | 1913 | case ND_ROUTER_SOLICIT: |
1914 | /* | | 1914 | /* |
1915 | * is_router flag must always be cleared. | | 1915 | * is_router flag must always be cleared. |
1916 | */ | | 1916 | */ |
1917 | ln->ln_router = 0; | | 1917 | ln->ln_router = 0; |
1918 | break; | | 1918 | break; |
1919 | case ND_ROUTER_ADVERT: | | 1919 | case ND_ROUTER_ADVERT: |
1920 | /* | | 1920 | /* |
1921 | * Mark an entry with lladdr as a router. | | 1921 | * Mark an entry with lladdr as a router. |
1922 | */ | | 1922 | */ |
1923 | if ((!is_newentry && (olladdr || lladdr)) || /* (2-5) */ | | 1923 | if ((!is_newentry && (olladdr || lladdr)) || /* (2-5) */ |
1924 | (is_newentry && lladdr)) { /* (7) */ | | 1924 | (is_newentry && lladdr)) { /* (7) */ |
1925 | ln->ln_router = 1; | | 1925 | ln->ln_router = 1; |
1926 | } | | 1926 | } |
1927 | break; | | 1927 | break; |
1928 | } | | 1928 | } |
1929 | | | 1929 | |
1930 | /* | | 1930 | /* |
1931 | * When the link-layer address of a router changes, select the | | 1931 | * When the link-layer address of a router changes, select the |
1932 | * best router again. In particular, when the neighbor entry is newly | | 1932 | * best router again. In particular, when the neighbor entry is newly |
1933 | * created, it might affect the selection policy. | | 1933 | * created, it might affect the selection policy. |
1934 | * Question: can we restrict the first condition to the "is_newentry" | | 1934 | * Question: can we restrict the first condition to the "is_newentry" |
1935 | * case? | | 1935 | * case? |
1936 | * XXX: when we hear an RA from a new router with the link-layer | | 1936 | * XXX: when we hear an RA from a new router with the link-layer |
1937 | * address option, defrouter_select() is called twice, since | | 1937 | * address option, defrouter_select() is called twice, since |
1938 | * defrtrlist_update called the function as well. However, I believe | | 1938 | * defrtrlist_update called the function as well. However, I believe |
1939 | * we can compromise the overhead, since it only happens the first | | 1939 | * we can compromise the overhead, since it only happens the first |
1940 | * time. | | 1940 | * time. |
1941 | * XXX: although defrouter_select() should not have a bad effect | | 1941 | * XXX: although defrouter_select() should not have a bad effect |
1942 | * for those are not autoconfigured hosts, we explicitly avoid such | | 1942 | * for those are not autoconfigured hosts, we explicitly avoid such |
1943 | * cases for safety. | | 1943 | * cases for safety. |
1944 | */ | | 1944 | */ |
1945 | if (do_update && ln->ln_router && !ip6_forwarding && | | 1945 | if (do_update && ln->ln_router && !ip6_forwarding && |
1946 | nd6_accepts_rtadv(ndi)) | | 1946 | nd6_accepts_rtadv(ndi)) |
1947 | defrouter_select(); | | 1947 | defrouter_select(); |
1948 | | | 1948 | |
1949 | return rt; | | 1949 | return rt; |
1950 | } | | 1950 | } |
1951 | | | 1951 | |
1952 | static void | | 1952 | static void |
1953 | nd6_slowtimo(void *ignored_arg) | | 1953 | nd6_slowtimo(void *ignored_arg) |
1954 | { | | 1954 | { |
1955 | struct nd_ifinfo *nd6if; | | 1955 | struct nd_ifinfo *nd6if; |
1956 | struct ifnet *ifp; | | 1956 | struct ifnet *ifp; |
1957 | | | 1957 | |
1958 | mutex_enter(softnet_lock); | | 1958 | mutex_enter(softnet_lock); |
1959 | KERNEL_LOCK(1, NULL); | | 1959 | KERNEL_LOCK(1, NULL); |
1960 | callout_reset(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz, | | 1960 | callout_reset(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz, |
1961 | nd6_slowtimo, NULL); | | 1961 | nd6_slowtimo, NULL); |
1962 | TAILQ_FOREACH(ifp, &ifnet, if_list) { | | 1962 | TAILQ_FOREACH(ifp, &ifnet, if_list) { |
1963 | nd6if = ND_IFINFO(ifp); | | 1963 | nd6if = ND_IFINFO(ifp); |
1964 | if (nd6if->basereachable && /* already initialized */ | | 1964 | if (nd6if->basereachable && /* already initialized */ |
1965 | (nd6if->recalctm -= ND6_SLOWTIMER_INTERVAL) <= 0) { | | 1965 | (nd6if->recalctm -= ND6_SLOWTIMER_INTERVAL) <= 0) { |
1966 | /* | | 1966 | /* |
1967 | * Since reachable time rarely changes by router | | 1967 | * Since reachable time rarely changes by router |
1968 | * advertisements, we SHOULD insure that a new random | | 1968 | * advertisements, we SHOULD insure that a new random |
1969 | * value gets recomputed at least once every few hours. | | 1969 | * value gets recomputed at least once every few hours. |
1970 | * (RFC 2461, 6.3.4) | | 1970 | * (RFC 2461, 6.3.4) |
1971 | */ | | 1971 | */ |
1972 | nd6if->recalctm = nd6_recalc_reachtm_interval; | | 1972 | nd6if->recalctm = nd6_recalc_reachtm_interval; |
1973 | nd6if->reachable = ND_COMPUTE_RTIME(nd6if->basereachable); | | 1973 | nd6if->reachable = ND_COMPUTE_RTIME(nd6if->basereachable); |
1974 | } | | 1974 | } |
1975 | } | | 1975 | } |
1976 | KERNEL_UNLOCK_ONE(NULL); | | 1976 | KERNEL_UNLOCK_ONE(NULL); |
1977 | mutex_exit(softnet_lock); | | 1977 | mutex_exit(softnet_lock); |
1978 | } | | 1978 | } |
1979 | | | 1979 | |
1980 | #define senderr(e) { error = (e); goto bad;} | | 1980 | #define senderr(e) { error = (e); goto bad;} |
1981 | int | | 1981 | int |
1982 | nd6_output(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m0, | | 1982 | nd6_output(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m0, |
1983 | const struct sockaddr_in6 *dst, struct rtentry *rt0) | | 1983 | const struct sockaddr_in6 *dst, struct rtentry *rt0) |
1984 | { | | 1984 | { |
1985 | struct mbuf *m = m0; | | 1985 | struct mbuf *m = m0; |
1986 | struct rtentry *rt = rt0; | | 1986 | struct rtentry *rt = rt0; |
1987 | struct sockaddr_in6 *gw6 = NULL; | | 1987 | struct sockaddr_in6 *gw6 = NULL; |
1988 | struct llinfo_nd6 *ln = NULL; | | 1988 | struct llinfo_nd6 *ln = NULL; |
1989 | int error = 0; | | 1989 | int error = 0; |
1990 | | | 1990 | |
1991 | if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr)) | | 1991 | if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr)) |
1992 | goto sendpkt; | | 1992 | goto sendpkt; |
1993 | | | 1993 | |
1994 | if (nd6_need_cache(ifp) == 0) | | 1994 | if (nd6_need_cache(ifp) == 0) |
1995 | goto sendpkt; | | 1995 | goto sendpkt; |
1996 | | | 1996 | |
1997 | /* | | 1997 | /* |
1998 | * next hop determination. This routine is derived from ether_output. | | 1998 | * next hop determination. This routine is derived from ether_output. |
1999 | */ | | 1999 | */ |
2000 | if (rt) { | | 2000 | if (rt) { |
2001 | if ((rt->rt_flags & RTF_UP) == 0) { | | 2001 | if ((rt->rt_flags & RTF_UP) == 0) { |
2002 | if ((rt0 = rt = rtalloc1(sin6tocsa(dst), 1)) != NULL) { | | 2002 | if ((rt0 = rt = rtalloc1(sin6tocsa(dst), 1)) != NULL) { |
2003 | rt->rt_refcnt--; | | 2003 | rt->rt_refcnt--; |
2004 | if (rt->rt_ifp != ifp) | | 2004 | if (rt->rt_ifp != ifp) |
2005 | senderr(EHOSTUNREACH); | | 2005 | senderr(EHOSTUNREACH); |
2006 | } else | | 2006 | } else |
2007 | senderr(EHOSTUNREACH); | | 2007 | senderr(EHOSTUNREACH); |
2008 | } | | 2008 | } |
2009 | | | 2009 | |
2010 | if (rt->rt_flags & RTF_GATEWAY) { | | 2010 | if (rt->rt_flags & RTF_GATEWAY) { |
2011 | gw6 = (struct sockaddr_in6 *)rt->rt_gateway; | | 2011 | gw6 = (struct sockaddr_in6 *)rt->rt_gateway; |
2012 | | | 2012 | |
2013 | /* | | 2013 | /* |
2014 | * We skip link-layer address resolution and NUD | | 2014 | * We skip link-layer address resolution and NUD |
2015 | * if the gateway is not a neighbor from ND point | | 2015 | * if the gateway is not a neighbor from ND point |
2016 | * of view, regardless of the value of nd_ifinfo.flags. | | 2016 | * of view, regardless of the value of nd_ifinfo.flags. |
2017 | * The second condition is a bit tricky; we skip | | 2017 | * The second condition is a bit tricky; we skip |
2018 | * if the gateway is our own address, which is | | 2018 | * if the gateway is our own address, which is |
2019 | * sometimes used to install a route to a p2p link. | | 2019 | * sometimes used to install a route to a p2p link. |
2020 | */ | | 2020 | */ |
2021 | if (!nd6_is_addr_neighbor(gw6, ifp) || | | 2021 | if (!nd6_is_addr_neighbor(gw6, ifp) || |
2022 | in6ifa_ifpwithaddr(ifp, &gw6->sin6_addr)) { | | 2022 | in6ifa_ifpwithaddr(ifp, &gw6->sin6_addr)) { |
2023 | /* | | 2023 | /* |
2024 | * We allow this kind of tricky route only | | 2024 | * We allow this kind of tricky route only |
2025 | * when the outgoing interface is p2p. | | 2025 | * when the outgoing interface is p2p. |
2026 | * XXX: we may need a more generic rule here. | | 2026 | * XXX: we may need a more generic rule here. |
2027 | */ | | 2027 | */ |
2028 | if ((ifp->if_flags & IFF_POINTOPOINT) == 0) | | 2028 | if ((ifp->if_flags & IFF_POINTOPOINT) == 0) |
2029 | senderr(EHOSTUNREACH); | | 2029 | senderr(EHOSTUNREACH); |
2030 | | | 2030 | |
2031 | goto sendpkt; | | 2031 | goto sendpkt; |
2032 | } | | 2032 | } |
2033 | | | 2033 | |
2034 | if (rt->rt_gwroute == NULL) | | 2034 | if (rt->rt_gwroute == NULL) |
2035 | goto lookup; | | 2035 | goto lookup; |
2036 | if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { | | 2036 | if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { |
2037 | rtfree(rt); rt = rt0; | | 2037 | rtfree(rt); rt = rt0; |
2038 | lookup: | | 2038 | lookup: |
2039 | rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1); | | 2039 | rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1); |
2040 | if ((rt = rt->rt_gwroute) == NULL) | | 2040 | if ((rt = rt->rt_gwroute) == NULL) |
2041 | senderr(EHOSTUNREACH); | | 2041 | senderr(EHOSTUNREACH); |
2042 | /* the "G" test below also prevents rt == rt0 */ | | 2042 | /* the "G" test below also prevents rt == rt0 */ |
2043 | if ((rt->rt_flags & RTF_GATEWAY) || | | 2043 | if ((rt->rt_flags & RTF_GATEWAY) || |
2044 | (rt->rt_ifp != ifp)) { | | 2044 | (rt->rt_ifp != ifp)) { |
2045 | rt->rt_refcnt--; | | 2045 | rt->rt_refcnt--; |
2046 | rt0->rt_gwroute = NULL; | | 2046 | rt0->rt_gwroute = NULL; |
2047 | senderr(EHOSTUNREACH); | | 2047 | senderr(EHOSTUNREACH); |
2048 | } | | 2048 | } |
2049 | } | | 2049 | } |
2050 | } | | 2050 | } |
2051 | } | | 2051 | } |
2052 | | | 2052 | |
2053 | /* | | 2053 | /* |
2054 | * Address resolution or Neighbor Unreachability Detection | | 2054 | * Address resolution or Neighbor Unreachability Detection |
2055 | * for the next hop. | | 2055 | * for the next hop. |
2056 | * At this point, the destination of the packet must be a unicast | | 2056 | * At this point, the destination of the packet must be a unicast |
2057 | * or an anycast address(i.e. not a multicast). | | 2057 | * or an anycast address(i.e. not a multicast). |
2058 | */ | | 2058 | */ |
2059 | | | 2059 | |
2060 | /* Look up the neighbor cache for the nexthop */ | | 2060 | /* Look up the neighbor cache for the nexthop */ |
2061 | if (rt != NULL && (rt->rt_flags & RTF_LLINFO) != 0) | | 2061 | if (rt != NULL && (rt->rt_flags & RTF_LLINFO) != 0) |
2062 | ln = (struct llinfo_nd6 *)rt->rt_llinfo; | | 2062 | ln = (struct llinfo_nd6 *)rt->rt_llinfo; |
2063 | else { | | 2063 | else { |
2064 | /* | | 2064 | /* |
2065 | * Since nd6_is_addr_neighbor() internally calls nd6_lookup(), | | 2065 | * Since nd6_is_addr_neighbor() internally calls nd6_lookup(), |
2066 | * the condition below is not very efficient. But we believe | | 2066 | * the condition below is not very efficient. But we believe |
2067 | * it is tolerable, because this should be a rare case. | | 2067 | * it is tolerable, because this should be a rare case. |
2068 | */ | | 2068 | */ |
2069 | if (nd6_is_addr_neighbor(dst, ifp) && | | 2069 | if (nd6_is_addr_neighbor(dst, ifp) && |
2070 | (rt = nd6_lookup(&dst->sin6_addr, 1, ifp)) != NULL) | | 2070 | (rt = nd6_lookup(&dst->sin6_addr, 1, ifp)) != NULL) |
2071 | ln = (struct llinfo_nd6 *)rt->rt_llinfo; | | 2071 | ln = (struct llinfo_nd6 *)rt->rt_llinfo; |
2072 | } | | 2072 | } |
2073 | if (ln == NULL || rt == NULL) { | | 2073 | if (ln == NULL || rt == NULL) { |
2074 | if ((ifp->if_flags & IFF_POINTOPOINT) == 0 && | | 2074 | if ((ifp->if_flags & IFF_POINTOPOINT) == 0 && |
2075 | !(ND_IFINFO(ifp)->flags & ND6_IFF_PERFORMNUD)) { | | 2075 | !(ND_IFINFO(ifp)->flags & ND6_IFF_PERFORMNUD)) { |
2076 | log(LOG_DEBUG, | | 2076 | log(LOG_DEBUG, |
2077 | "nd6_output: can't allocate llinfo for %s " | | 2077 | "nd6_output: can't allocate llinfo for %s " |
2078 | "(ln=%p, rt=%p)\n", | | 2078 | "(ln=%p, rt=%p)\n", |
2079 | ip6_sprintf(&dst->sin6_addr), ln, rt); | | 2079 | ip6_sprintf(&dst->sin6_addr), ln, rt); |
2080 | senderr(EIO); /* XXX: good error? */ | | 2080 | senderr(EIO); /* XXX: good error? */ |
2081 | } | | 2081 | } |
2082 | | | 2082 | |
2083 | goto sendpkt; /* send anyway */ | | 2083 | goto sendpkt; /* send anyway */ |
2084 | } | | 2084 | } |
2085 | | | 2085 | |
2086 | /* | | 2086 | /* |
2087 | * Move this entry to the head of the queue so that it is less likely | | 2087 | * Move this entry to the head of the queue so that it is less likely |
2088 | * for this entry to be a target of forced garbage collection (see | | 2088 | * for this entry to be a target of forced garbage collection (see |
2089 | * nd6_rtrequest()). | | 2089 | * nd6_rtrequest()). |
2090 | */ | | 2090 | */ |
2091 | LN_DEQUEUE(ln); | | 2091 | LN_DEQUEUE(ln); |
2092 | LN_INSERTHEAD(ln); | | 2092 | LN_INSERTHEAD(ln); |
2093 | | | 2093 | |
2094 | /* We don't have to do link-layer address resolution on a p2p link. */ | | 2094 | /* We don't have to do link-layer address resolution on a p2p link. */ |
2095 | if ((ifp->if_flags & IFF_POINTOPOINT) != 0 && | | 2095 | if ((ifp->if_flags & IFF_POINTOPOINT) != 0 && |
2096 | ln->ln_state < ND6_LLINFO_REACHABLE) { | | 2096 | ln->ln_state < ND6_LLINFO_REACHABLE) { |
2097 | ln->ln_state = ND6_LLINFO_STALE; | | 2097 | ln->ln_state = ND6_LLINFO_STALE; |
2098 | nd6_llinfo_settimer(ln, (long)nd6_gctimer * hz); | | 2098 | nd6_llinfo_settimer(ln, (long)nd6_gctimer * hz); |
2099 | } | | 2099 | } |
2100 | | | 2100 | |
2101 | /* | | 2101 | /* |
2102 | * The first time we send a packet to a neighbor whose entry is | | 2102 | * The first time we send a packet to a neighbor whose entry is |
2103 | * STALE, we have to change the state to DELAY and a sets a timer to | | 2103 | * STALE, we have to change the state to DELAY and a sets a timer to |
2104 | * expire in DELAY_FIRST_PROBE_TIME seconds to ensure do | | 2104 | * expire in DELAY_FIRST_PROBE_TIME seconds to ensure do |
2105 | * neighbor unreachability detection on expiration. | | 2105 | * neighbor unreachability detection on expiration. |
2106 | * (RFC 2461 7.3.3) | | 2106 | * (RFC 2461 7.3.3) |
2107 | */ | | 2107 | */ |
2108 | if (ln->ln_state == ND6_LLINFO_STALE) { | | 2108 | if (ln->ln_state == ND6_LLINFO_STALE) { |
2109 | ln->ln_asked = 0; | | 2109 | ln->ln_asked = 0; |
2110 | ln->ln_state = ND6_LLINFO_DELAY; | | 2110 | ln->ln_state = ND6_LLINFO_DELAY; |
2111 | nd6_llinfo_settimer(ln, (long)nd6_delay * hz); | | 2111 | nd6_llinfo_settimer(ln, (long)nd6_delay * hz); |
2112 | } | | 2112 | } |
2113 | | | 2113 | |
2114 | /* | | 2114 | /* |
2115 | * If the neighbor cache entry has a state other than INCOMPLETE | | 2115 | * If the neighbor cache entry has a state other than INCOMPLETE |
2116 | * (i.e. its link-layer address is already resolved), just | | 2116 | * (i.e. its link-layer address is already resolved), just |
2117 | * send the packet. | | 2117 | * send the packet. |
2118 | */ | | 2118 | */ |
2119 | if (ln->ln_state > ND6_LLINFO_INCOMPLETE) | | 2119 | if (ln->ln_state > ND6_LLINFO_INCOMPLETE) |
2120 | goto sendpkt; | | 2120 | goto sendpkt; |
2121 | | | 2121 | |
2122 | /* | | 2122 | /* |
2123 | * There is a neighbor cache entry, but no ethernet address | | 2123 | * There is a neighbor cache entry, but no ethernet address |
2124 | * response yet. Append this latest packet to the end of the | | 2124 | * response yet. Append this latest packet to the end of the |
2125 | * packet queue in the mbuf, unless the number of the packet | | 2125 | * packet queue in the mbuf, unless the number of the packet |
2126 | * does not exceed nd6_maxqueuelen. When it exceeds nd6_maxqueuelen, | | 2126 | * does not exceed nd6_maxqueuelen. When it exceeds nd6_maxqueuelen, |
2127 | * the oldest packet in the queue will be removed. | | 2127 | * the oldest packet in the queue will be removed. |
2128 | */ | | 2128 | */ |
2129 | if (ln->ln_state == ND6_LLINFO_NOSTATE) | | 2129 | if (ln->ln_state == ND6_LLINFO_NOSTATE) |
2130 | ln->ln_state = ND6_LLINFO_INCOMPLETE; | | 2130 | ln->ln_state = ND6_LLINFO_INCOMPLETE; |
2131 | if (ln->ln_hold) { | | 2131 | if (ln->ln_hold) { |
2132 | struct mbuf *m_hold; | | 2132 | struct mbuf *m_hold; |
2133 | int i; | | 2133 | int i; |
2134 | | | 2134 | |
2135 | i = 0; | | 2135 | i = 0; |
2136 | for (m_hold = ln->ln_hold; m_hold; m_hold = m_hold->m_nextpkt) { | | 2136 | for (m_hold = ln->ln_hold; m_hold; m_hold = m_hold->m_nextpkt) { |
2137 | i++; | | 2137 | i++; |
2138 | if (m_hold->m_nextpkt == NULL) { | | 2138 | if (m_hold->m_nextpkt == NULL) { |
2139 | m_hold->m_nextpkt = m; | | 2139 | m_hold->m_nextpkt = m; |
2140 | break; | | 2140 | break; |
2141 | } | | 2141 | } |
2142 | } | | 2142 | } |
2143 | while (i >= nd6_maxqueuelen) { | | 2143 | while (i >= nd6_maxqueuelen) { |
2144 | m_hold = ln->ln_hold; | | 2144 | m_hold = ln->ln_hold; |
2145 | ln->ln_hold = ln->ln_hold->m_nextpkt; | | 2145 | ln->ln_hold = ln->ln_hold->m_nextpkt; |
2146 | m_freem(m_hold); | | 2146 | m_freem(m_hold); |
2147 | i--; | | 2147 | i--; |
2148 | } | | 2148 | } |
2149 | } else { | | 2149 | } else { |
2150 | ln->ln_hold = m; | | 2150 | ln->ln_hold = m; |
2151 | } | | 2151 | } |
2152 | | | 2152 | |
2153 | /* | | 2153 | /* |
2154 | * If there has been no NS for the neighbor after entering the | | 2154 | * If there has been no NS for the neighbor after entering the |
2155 | * INCOMPLETE state, send the first solicitation. | | 2155 | * INCOMPLETE state, send the first solicitation. |
2156 | */ | | 2156 | */ |
2157 | if (!ND6_LLINFO_PERMANENT(ln) && ln->ln_asked == 0) { | | 2157 | if (!ND6_LLINFO_PERMANENT(ln) && ln->ln_asked == 0) { |
2158 | ln->ln_asked++; | | 2158 | ln->ln_asked++; |
2159 | nd6_llinfo_settimer(ln, | | 2159 | nd6_llinfo_settimer(ln, |
2160 | (long)ND_IFINFO(ifp)->retrans * hz / 1000); | | 2160 | (long)ND_IFINFO(ifp)->retrans * hz / 1000); |
2161 | nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0); | | 2161 | nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0); |
2162 | } | | 2162 | } |
2163 | return 0; | | 2163 | return 0; |
2164 | | | 2164 | |
2165 | sendpkt: | | 2165 | sendpkt: |
2166 | /* discard the packet if IPv6 operation is disabled on the interface */ | | 2166 | /* discard the packet if IPv6 operation is disabled on the interface */ |
2167 | if ((ND_IFINFO(ifp)->flags & ND6_IFF_IFDISABLED)) { | | 2167 | if ((ND_IFINFO(ifp)->flags & ND6_IFF_IFDISABLED)) { |
2168 | error = ENETDOWN; /* better error? */ | | 2168 | error = ENETDOWN; /* better error? */ |
2169 | goto bad; | | 2169 | goto bad; |
2170 | } | | 2170 | } |
2171 | | | 2171 | |
2172 | if ((ifp->if_flags & IFF_LOOPBACK) != 0) | | 2172 | if ((ifp->if_flags & IFF_LOOPBACK) != 0) |
2173 | return (*ifp->if_output)(origifp, m, sin6tocsa(dst), rt); | | 2173 | return (*ifp->if_output)(origifp, m, sin6tocsa(dst), rt); |
2174 | return (*ifp->if_output)(ifp, m, sin6tocsa(dst), rt); | | 2174 | return (*ifp->if_output)(ifp, m, sin6tocsa(dst), rt); |
2175 | | | 2175 | |
2176 | bad: | | 2176 | bad: |
2177 | if (m != NULL) | | 2177 | if (m != NULL) |
2178 | m_freem(m); | | 2178 | m_freem(m); |
2179 | return error; | | 2179 | return error; |
2180 | } | | 2180 | } |
2181 | #undef senderr | | 2181 | #undef senderr |
2182 | | | 2182 | |
2183 | int | | 2183 | int |
2184 | nd6_need_cache(struct ifnet *ifp) | | 2184 | nd6_need_cache(struct ifnet *ifp) |
2185 | { | | 2185 | { |
2186 | /* | | 2186 | /* |
2187 | * XXX: we currently do not make neighbor cache on any interface | | 2187 | * XXX: we currently do not make neighbor cache on any interface |
2188 | * other than ARCnet, Ethernet, FDDI and GIF. | | 2188 | * other than ARCnet, Ethernet, FDDI and GIF. |
2189 | * | | 2189 | * |
2190 | * RFC2893 says: | | 2190 | * RFC2893 says: |
2191 | * - unidirectional tunnels needs no ND | | 2191 | * - unidirectional tunnels needs no ND |
2192 | */ | | 2192 | */ |
2193 | switch (ifp->if_type) { | | 2193 | switch (ifp->if_type) { |
2194 | case IFT_ARCNET: | | 2194 | case IFT_ARCNET: |
2195 | case IFT_ETHER: | | 2195 | case IFT_ETHER: |
2196 | case IFT_FDDI: | | 2196 | case IFT_FDDI: |
2197 | case IFT_IEEE1394: | | 2197 | case IFT_IEEE1394: |
2198 | case IFT_CARP: | | 2198 | case IFT_CARP: |
2199 | case IFT_GIF: /* XXX need more cases? */ | | 2199 | case IFT_GIF: /* XXX need more cases? */ |
2200 | case IFT_PPP: | | 2200 | case IFT_PPP: |
2201 | case IFT_TUNNEL: | | 2201 | case IFT_TUNNEL: |
2202 | return 1; | | 2202 | return 1; |
2203 | default: | | 2203 | default: |
2204 | return 0; | | 2204 | return 0; |
2205 | } | | 2205 | } |
2206 | } | | 2206 | } |
2207 | | | 2207 | |
2208 | int | | 2208 | int |
2209 | nd6_storelladdr(const struct ifnet *ifp, const struct rtentry *rt, | | 2209 | nd6_storelladdr(const struct ifnet *ifp, const struct rtentry *rt, |
2210 | struct mbuf *m, const struct sockaddr *dst, uint8_t *lldst, | | 2210 | struct mbuf *m, const struct sockaddr *dst, uint8_t *lldst, |
2211 | size_t dstsize) | | 2211 | size_t dstsize) |
2212 | { | | 2212 | { |
2213 | const struct sockaddr_dl *sdl; | | 2213 | const struct sockaddr_dl *sdl; |
2214 | | | 2214 | |
2215 | if (m->m_flags & M_MCAST) { | | 2215 | if (m->m_flags & M_MCAST) { |
2216 | switch (ifp->if_type) { | | 2216 | switch (ifp->if_type) { |
2217 | case IFT_ETHER: | | 2217 | case IFT_ETHER: |
2218 | case IFT_FDDI: | | 2218 | case IFT_FDDI: |
2219 | ETHER_MAP_IPV6_MULTICAST(&satocsin6(dst)->sin6_addr, | | 2219 | ETHER_MAP_IPV6_MULTICAST(&satocsin6(dst)->sin6_addr, |
2220 | lldst); | | 2220 | lldst); |
2221 | return 1; | | 2221 | return 1; |
2222 | case IFT_IEEE1394: | | 2222 | case IFT_IEEE1394: |
2223 | memcpy(lldst, ifp->if_broadcastaddr, | | 2223 | memcpy(lldst, ifp->if_broadcastaddr, |
2224 | MIN(dstsize, ifp->if_addrlen)); | | 2224 | MIN(dstsize, ifp->if_addrlen)); |
2225 | return 1; | | 2225 | return 1; |
2226 | case IFT_ARCNET: | | 2226 | case IFT_ARCNET: |
2227 | *lldst = 0; | | 2227 | *lldst = 0; |
2228 | return 1; | | 2228 | return 1; |
2229 | default: | | 2229 | default: |
2230 | m_freem(m); | | 2230 | m_freem(m); |
2231 | return 0; | | 2231 | return 0; |
2232 | } | | 2232 | } |
2233 | } | | 2233 | } |
2234 | | | 2234 | |
2235 | if (rt == NULL) { | | 2235 | if (rt == NULL) { |
2236 | /* this could happen, if we could not allocate memory */ | | 2236 | /* this could happen, if we could not allocate memory */ |
2237 | m_freem(m); | | 2237 | m_freem(m); |
2238 | return 0; | | 2238 | return 0; |
2239 | } | | 2239 | } |
2240 | if (rt->rt_gateway->sa_family != AF_LINK) { | | 2240 | if (rt->rt_gateway->sa_family != AF_LINK) { |
2241 | printf("%s: something odd happens\n", __func__); | | 2241 | printf("%s: something odd happens\n", __func__); |
2242 | m_freem(m); | | 2242 | m_freem(m); |
2243 | return 0; | | 2243 | return 0; |
2244 | } | | 2244 | } |
2245 | sdl = satocsdl(rt->rt_gateway); | | 2245 | sdl = satocsdl(rt->rt_gateway); |
2246 | if (sdl->sdl_alen == 0 || sdl->sdl_alen > dstsize) { | | 2246 | if (sdl->sdl_alen == 0 || sdl->sdl_alen > dstsize) { |
2247 | /* this should be impossible, but we bark here for debugging */ | | 2247 | /* this should be impossible, but we bark here for debugging */ |
2248 | printf("%s: sdl_alen == %" PRIu8 ", dst=%s, if=%s\n", __func__, | | 2248 | printf("%s: sdl_alen == %" PRIu8 ", dst=%s, if=%s\n", __func__, |
2249 | sdl->sdl_alen, ip6_sprintf(&satocsin6(dst)->sin6_addr), | | 2249 | sdl->sdl_alen, ip6_sprintf(&satocsin6(dst)->sin6_addr), |
2250 | if_name(ifp)); | | 2250 | if_name(ifp)); |
2251 | m_freem(m); | | 2251 | m_freem(m); |
2252 | return 0; | | 2252 | return 0; |
2253 | } | | 2253 | } |
2254 | | | 2254 | |
2255 | memcpy(lldst, CLLADDR(sdl), MIN(dstsize, sdl->sdl_alen)); | | 2255 | memcpy(lldst, CLLADDR(sdl), MIN(dstsize, sdl->sdl_alen)); |
2256 | return 1; | | 2256 | return 1; |
2257 | } | | 2257 | } |
2258 | | | 2258 | |
2259 | static void | | 2259 | static void |
2260 | clear_llinfo_pqueue(struct llinfo_nd6 *ln) | | 2260 | clear_llinfo_pqueue(struct llinfo_nd6 *ln) |
2261 | { | | 2261 | { |
2262 | struct mbuf *m_hold, *m_hold_next; | | 2262 | struct mbuf *m_hold, *m_hold_next; |
2263 | | | 2263 | |
2264 | for (m_hold = ln->ln_hold; m_hold; m_hold = m_hold_next) { | | 2264 | for (m_hold = ln->ln_hold; m_hold; m_hold = m_hold_next) { |
2265 | m_hold_next = m_hold->m_nextpkt; | | 2265 | m_hold_next = m_hold->m_nextpkt; |
2266 | m_hold->m_nextpkt = NULL; | | 2266 | m_hold->m_nextpkt = NULL; |
2267 | m_freem(m_hold); | | 2267 | m_freem(m_hold); |
2268 | } | | 2268 | } |
2269 | | | 2269 | |
2270 | ln->ln_hold = NULL; | | 2270 | ln->ln_hold = NULL; |
2271 | return; | | 2271 | return; |
2272 | } | | 2272 | } |
2273 | | | 2273 | |
2274 | int | | 2274 | int |
2275 | nd6_sysctl( | | 2275 | nd6_sysctl( |
2276 | int name, | | 2276 | int name, |
2277 | void *oldp, /* syscall arg, need copyout */ | | 2277 | void *oldp, /* syscall arg, need copyout */ |
2278 | size_t *oldlenp, | | 2278 | size_t *oldlenp, |
2279 | void *newp, /* syscall arg, need copyin */ | | 2279 | void *newp, /* syscall arg, need copyin */ |
2280 | size_t newlen | | 2280 | size_t newlen |
2281 | ) | | 2281 | ) |
2282 | { | | 2282 | { |
2283 | void *p; | | 2283 | void *p; |
2284 | size_t ol; | | 2284 | size_t ol; |
2285 | int error; | | 2285 | int error; |
2286 | | | 2286 | |
2287 | error = 0; | | 2287 | error = 0; |
2288 | | | 2288 | |
2289 | if (newp) | | 2289 | if (newp) |
2290 | return EPERM; | | 2290 | return EPERM; |
2291 | if (oldp && !oldlenp) | | 2291 | if (oldp && !oldlenp) |
2292 | return EINVAL; | | 2292 | return EINVAL; |
2293 | ol = oldlenp ? *oldlenp : 0; | | 2293 | ol = oldlenp ? *oldlenp : 0; |
2294 | | | 2294 | |
2295 | if (oldp) { | | 2295 | if (oldp) { |
2296 | p = malloc(*oldlenp, M_TEMP, M_WAITOK); | | 2296 | p = malloc(*oldlenp, M_TEMP, M_WAITOK); |
2297 | if (p == NULL) | | 2297 | if (p == NULL) |
2298 | return ENOMEM; | | 2298 | return ENOMEM; |
2299 | } else | | 2299 | } else |
2300 | p = NULL; | | 2300 | p = NULL; |
2301 | switch (name) { | | 2301 | switch (name) { |
2302 | case ICMPV6CTL_ND6_DRLIST: | | 2302 | case ICMPV6CTL_ND6_DRLIST: |
2303 | error = fill_drlist(p, oldlenp, ol); | | 2303 | error = fill_drlist(p, oldlenp, ol); |
2304 | if (!error && p != NULL && oldp != NULL) | | 2304 | if (!error && p != NULL && oldp != NULL) |
2305 | error = copyout(p, oldp, *oldlenp); | | 2305 | error = copyout(p, oldp, *oldlenp); |
2306 | break; | | 2306 | break; |
2307 | | | 2307 | |
2308 | case ICMPV6CTL_ND6_PRLIST: | | 2308 | case ICMPV6CTL_ND6_PRLIST: |
2309 | error = fill_prlist(p, oldlenp, ol); | | 2309 | error = fill_prlist(p, oldlenp, ol); |
2310 | if (!error && p != NULL && oldp != NULL) | | 2310 | if (!error && p != NULL && oldp != NULL) |
2311 | error = copyout(p, oldp, *oldlenp); | | 2311 | error = copyout(p, oldp, *oldlenp); |
2312 | break; | | 2312 | break; |
2313 | | | 2313 | |
2314 | case ICMPV6CTL_ND6_MAXQLEN: | | 2314 | case ICMPV6CTL_ND6_MAXQLEN: |
2315 | break; | | 2315 | break; |
2316 | | | 2316 | |
2317 | default: | | 2317 | default: |
2318 | error = ENOPROTOOPT; | | 2318 | error = ENOPROTOOPT; |
2319 | break; | | 2319 | break; |
2320 | } | | 2320 | } |
2321 | if (p) | | 2321 | if (p) |
2322 | free(p, M_TEMP); | | 2322 | free(p, M_TEMP); |
2323 | | | 2323 | |
2324 | return error; | | 2324 | return error; |
2325 | } | | 2325 | } |
2326 | | | 2326 | |
2327 | static int | | 2327 | static int |
2328 | fill_drlist(void *oldp, size_t *oldlenp, size_t ol) | | 2328 | fill_drlist(void *oldp, size_t *oldlenp, size_t ol) |
2329 | { | | 2329 | { |
2330 | int error = 0, s; | | 2330 | int error = 0, s; |
2331 | struct in6_defrouter *d = NULL, *de = NULL; | | 2331 | struct in6_defrouter *d = NULL, *de = NULL; |
2332 | struct nd_defrouter *dr; | | 2332 | struct nd_defrouter *dr; |
2333 | size_t l; | | 2333 | size_t l; |
2334 | | | 2334 | |
2335 | s = splsoftnet(); | | 2335 | s = splsoftnet(); |
2336 | | | 2336 | |
2337 | if (oldp) { | | 2337 | if (oldp) { |
2338 | d = (struct in6_defrouter *)oldp; | | 2338 | d = (struct in6_defrouter *)oldp; |
2339 | de = (struct in6_defrouter *)((char *)oldp + *oldlenp); | | 2339 | de = (struct in6_defrouter *)((char *)oldp + *oldlenp); |
2340 | } | | 2340 | } |
2341 | l = 0; | | 2341 | l = 0; |
2342 | | | 2342 | |
2343 | TAILQ_FOREACH(dr, &nd_defrouter, dr_entry) { | | 2343 | TAILQ_FOREACH(dr, &nd_defrouter, dr_entry) { |
2344 | | | 2344 | |
2345 | if (oldp && d + 1 <= de) { | | 2345 | if (oldp && d + 1 <= de) { |
2346 | memset(d, 0, sizeof(*d)); | | 2346 | memset(d, 0, sizeof(*d)); |
2347 | sockaddr_in6_init(&d->rtaddr, &dr->rtaddr, 0, 0, 0); | | 2347 | sockaddr_in6_init(&d->rtaddr, &dr->rtaddr, 0, 0, 0); |
2348 | if (sa6_recoverscope(&d->rtaddr)) { | | 2348 | if (sa6_recoverscope(&d->rtaddr)) { |
2349 | log(LOG_ERR, | | 2349 | log(LOG_ERR, |
2350 | "scope error in router list (%s)\n", | | 2350 | "scope error in router list (%s)\n", |
2351 | ip6_sprintf(&d->rtaddr.sin6_addr)); | | 2351 | ip6_sprintf(&d->rtaddr.sin6_addr)); |
2352 | /* XXX: press on... */ | | 2352 | /* XXX: press on... */ |
2353 | } | | 2353 | } |
2354 | d->flags = dr->flags; | | 2354 | d->flags = dr->flags; |
2355 | d->rtlifetime = dr->rtlifetime; | | 2355 | d->rtlifetime = dr->rtlifetime; |
2356 | d->expire = dr->expire; | | 2356 | d->expire = dr->expire; |
2357 | d->if_index = dr->ifp->if_index; | | 2357 | d->if_index = dr->ifp->if_index; |
2358 | } | | 2358 | } |
2359 | | | 2359 | |
2360 | l += sizeof(*d); | | 2360 | l += sizeof(*d); |
2361 | if (d) | | 2361 | if (d) |
2362 | d++; | | 2362 | d++; |
2363 | } | | 2363 | } |
2364 | | | 2364 | |
2365 | if (oldp) { | | 2365 | if (oldp) { |
2366 | if (l > ol) | | 2366 | if (l > ol) |
2367 | error = ENOMEM; | | 2367 | error = ENOMEM; |
2368 | } | | 2368 | } |
2369 | if (oldlenp) | | 2369 | if (oldlenp) |
2370 | *oldlenp = l; /* (void *)d - (void *)oldp */ | | 2370 | *oldlenp = l; /* (void *)d - (void *)oldp */ |
2371 | | | 2371 | |
2372 | splx(s); | | 2372 | splx(s); |
2373 | | | 2373 | |
2374 | return error; | | 2374 | return error; |
2375 | } | | 2375 | } |
2376 | | | 2376 | |
2377 | static int | | 2377 | static int |
2378 | fill_prlist(void *oldp, size_t *oldlenp, size_t ol) | | 2378 | fill_prlist(void *oldp, size_t *oldlenp, size_t ol) |
2379 | { | | 2379 | { |
2380 | int error = 0, s; | | 2380 | int error = 0, s; |
2381 | struct nd_prefix *pr; | | 2381 | struct nd_prefix *pr; |