in6_ifattach.c revision 1.30.4.2 1 1.30.4.2 msaitoh /* $NetBSD: in6_ifattach.c,v 1.30.4.2 2003/08/05 12:50:09 msaitoh Exp $ */
2 1.30 itojun /* $KAME: in6_ifattach.c,v 1.56 2000/05/05 06:54:33 itojun Exp $ */
3 1.3 thorpej
4 1.2 itojun /*
5 1.2 itojun * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 1.2 itojun * All rights reserved.
7 1.24 itojun *
8 1.2 itojun * Redistribution and use in source and binary forms, with or without
9 1.2 itojun * modification, are permitted provided that the following conditions
10 1.2 itojun * are met:
11 1.2 itojun * 1. Redistributions of source code must retain the above copyright
12 1.2 itojun * notice, this list of conditions and the following disclaimer.
13 1.2 itojun * 2. Redistributions in binary form must reproduce the above copyright
14 1.2 itojun * notice, this list of conditions and the following disclaimer in the
15 1.2 itojun * documentation and/or other materials provided with the distribution.
16 1.2 itojun * 3. Neither the name of the project nor the names of its contributors
17 1.2 itojun * may be used to endorse or promote products derived from this software
18 1.2 itojun * without specific prior written permission.
19 1.24 itojun *
20 1.2 itojun * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 1.2 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.2 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.2 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 1.2 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.2 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.2 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.2 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.2 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.2 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.2 itojun * SUCH DAMAGE.
31 1.2 itojun */
32 1.2 itojun
33 1.2 itojun #include <sys/param.h>
34 1.2 itojun #include <sys/systm.h>
35 1.2 itojun #include <sys/malloc.h>
36 1.2 itojun #include <sys/socket.h>
37 1.2 itojun #include <sys/sockio.h>
38 1.13 itojun #include <sys/kernel.h>
39 1.13 itojun #include <sys/md5.h>
40 1.2 itojun
41 1.2 itojun #include <net/if.h>
42 1.2 itojun #include <net/if_dl.h>
43 1.2 itojun #include <net/if_types.h>
44 1.2 itojun #include <net/route.h>
45 1.2 itojun
46 1.2 itojun #include <netinet/in.h>
47 1.2 itojun #include <netinet/in_var.h>
48 1.2 itojun
49 1.19 itojun #include <netinet/ip6.h>
50 1.2 itojun #include <netinet6/ip6_var.h>
51 1.2 itojun #include <netinet6/in6_ifattach.h>
52 1.2 itojun #include <netinet6/ip6_var.h>
53 1.2 itojun #include <netinet6/nd6.h>
54 1.30.4.2 msaitoh #include <netinet6/ip6_mroute.h>
55 1.2 itojun
56 1.13 itojun #include <net/net_osdep.h>
57 1.13 itojun
58 1.13 itojun struct in6_ifstat **in6_ifstat = NULL;
59 1.13 itojun struct icmp6_ifstat **icmp6_ifstat = NULL;
60 1.13 itojun size_t in6_ifstatmax = 0;
61 1.13 itojun size_t icmp6_ifstatmax = 0;
62 1.2 itojun unsigned long in6_maxmtu = 0;
63 1.2 itojun
64 1.25 itojun static int get_rand_ifid __P((struct ifnet *, struct in6_addr *));
65 1.25 itojun static int get_hw_ifid __P((struct ifnet *, struct in6_addr *));
66 1.25 itojun static int get_ifid __P((struct ifnet *, struct ifnet *, struct in6_addr *));
67 1.25 itojun static int in6_ifattach_addaddr __P((struct ifnet *, struct in6_ifaddr *));
68 1.25 itojun static int in6_ifattach_linklocal __P((struct ifnet *, struct ifnet *));
69 1.25 itojun static int in6_ifattach_loopback __P((struct ifnet *));
70 1.25 itojun
71 1.25 itojun #define EUI64_GBIT 0x01
72 1.25 itojun #define EUI64_UBIT 0x02
73 1.25 itojun #define EUI64_TO_IFID(in6) do {(in6)->s6_addr[8] ^= EUI64_UBIT; } while (0)
74 1.25 itojun #define EUI64_GROUP(in6) ((in6)->s6_addr[8] & EUI64_GBIT)
75 1.25 itojun #define EUI64_INDIVIDUAL(in6) (!EUI64_GROUP(in6))
76 1.25 itojun #define EUI64_LOCAL(in6) ((in6)->s6_addr[8] & EUI64_UBIT)
77 1.25 itojun #define EUI64_UNIVERSAL(in6) (!EUI64_LOCAL(in6))
78 1.25 itojun
79 1.25 itojun #define IFID_LOCAL(in6) (!EUI64_LOCAL(in6))
80 1.25 itojun #define IFID_UNIVERSAL(in6) (!EUI64_UNIVERSAL(in6))
81 1.25 itojun
82 1.25 itojun /*
83 1.25 itojun * Generate a last-resort interface identifier, when the machine has no
84 1.25 itojun * IEEE802/EUI64 address sources.
85 1.25 itojun * The goal here is to get an interface identifier that is
86 1.25 itojun * (1) random enough and (2) does not change across reboot.
87 1.25 itojun * We currently use MD5(hostname) for it.
88 1.25 itojun */
89 1.25 itojun static int
90 1.25 itojun get_rand_ifid(ifp, in6)
91 1.25 itojun struct ifnet *ifp;
92 1.25 itojun struct in6_addr *in6; /*upper 64bits are preserved */
93 1.25 itojun {
94 1.25 itojun MD5_CTX ctxt;
95 1.25 itojun u_int8_t digest[16];
96 1.25 itojun
97 1.25 itojun #if 0
98 1.25 itojun /* we need at least several letters as seed for ifid */
99 1.25 itojun if (hostnamelen < 3)
100 1.25 itojun return -1;
101 1.25 itojun #endif
102 1.25 itojun
103 1.25 itojun /* generate 8 bytes of pseudo-random value. */
104 1.25 itojun bzero(&ctxt, sizeof(ctxt));
105 1.25 itojun MD5Init(&ctxt);
106 1.25 itojun MD5Update(&ctxt, hostname, hostnamelen);
107 1.25 itojun MD5Final(digest, &ctxt);
108 1.25 itojun
109 1.25 itojun /* assumes sizeof(digest) > sizeof(ifid) */
110 1.25 itojun bcopy(digest, &in6->s6_addr[8], 8);
111 1.2 itojun
112 1.25 itojun /* make sure to set "u" bit to local, and "g" bit to individual. */
113 1.25 itojun in6->s6_addr[8] &= ~EUI64_GBIT; /* g bit to "individual" */
114 1.25 itojun in6->s6_addr[8] |= EUI64_UBIT; /* u bit to "local" */
115 1.25 itojun
116 1.25 itojun /* convert EUI64 into IPv6 interface identifier */
117 1.25 itojun EUI64_TO_IFID(in6);
118 1.25 itojun
119 1.25 itojun return 0;
120 1.25 itojun }
121 1.2 itojun
122 1.25 itojun /*
123 1.25 itojun * Get interface identifier for the specified interface.
124 1.25 itojun * XXX assumes single sockaddr_dl (AF_LINK address) per an interface
125 1.25 itojun */
126 1.7 itojun static int
127 1.25 itojun get_hw_ifid(ifp, in6)
128 1.25 itojun struct ifnet *ifp;
129 1.25 itojun struct in6_addr *in6; /*upper 64bits are preserved */
130 1.2 itojun {
131 1.25 itojun struct ifaddr *ifa;
132 1.25 itojun struct sockaddr_dl *sdl;
133 1.25 itojun u_int8_t *addr;
134 1.25 itojun size_t addrlen;
135 1.25 itojun static u_int8_t allzero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
136 1.25 itojun static u_int8_t allone[8] =
137 1.25 itojun { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
138 1.25 itojun
139 1.25 itojun for (ifa = ifp->if_addrlist.tqh_first;
140 1.25 itojun ifa;
141 1.25 itojun ifa = ifa->ifa_list.tqe_next)
142 1.25 itojun {
143 1.25 itojun if (ifa->ifa_addr->sa_family != AF_LINK)
144 1.25 itojun continue;
145 1.25 itojun sdl = (struct sockaddr_dl *)ifa->ifa_addr;
146 1.25 itojun if (sdl == NULL)
147 1.25 itojun continue;
148 1.25 itojun if (sdl->sdl_alen == 0)
149 1.25 itojun continue;
150 1.25 itojun
151 1.25 itojun goto found;
152 1.25 itojun }
153 1.25 itojun
154 1.25 itojun return -1;
155 1.25 itojun
156 1.25 itojun found:
157 1.25 itojun addr = LLADDR(sdl);
158 1.25 itojun addrlen = sdl->sdl_alen;
159 1.25 itojun
160 1.25 itojun /* get EUI64 */
161 1.25 itojun switch (ifp->if_type) {
162 1.25 itojun case IFT_ETHER:
163 1.25 itojun case IFT_FDDI:
164 1.25 itojun case IFT_ATM:
165 1.25 itojun /* IEEE802/EUI64 cases - what others? */
166 1.13 itojun
167 1.25 itojun /* look at IEEE802/EUI64 only */
168 1.25 itojun if (addrlen != 8 && addrlen != 6)
169 1.25 itojun return -1;
170 1.13 itojun
171 1.25 itojun /*
172 1.25 itojun * check for invalid MAC address - on bsdi, we see it a lot
173 1.25 itojun * since wildboar configures all-zero MAC on pccard before
174 1.25 itojun * card insertion.
175 1.25 itojun */
176 1.25 itojun if (bcmp(addr, allzero, addrlen) == 0)
177 1.25 itojun return -1;
178 1.25 itojun if (bcmp(addr, allone, addrlen) == 0)
179 1.25 itojun return -1;
180 1.25 itojun
181 1.25 itojun /* make EUI64 address */
182 1.25 itojun if (addrlen == 8)
183 1.25 itojun bcopy(addr, &in6->s6_addr[8], 8);
184 1.25 itojun else if (addrlen == 6) {
185 1.25 itojun in6->s6_addr[8] = addr[0];
186 1.25 itojun in6->s6_addr[9] = addr[1];
187 1.25 itojun in6->s6_addr[10] = addr[2];
188 1.25 itojun in6->s6_addr[11] = 0xff;
189 1.26 itojun in6->s6_addr[12] = 0xfe;
190 1.25 itojun in6->s6_addr[13] = addr[3];
191 1.25 itojun in6->s6_addr[14] = addr[4];
192 1.25 itojun in6->s6_addr[15] = addr[5];
193 1.25 itojun }
194 1.7 itojun break;
195 1.25 itojun
196 1.25 itojun case IFT_ARCNET:
197 1.25 itojun if (addrlen != 1)
198 1.25 itojun return -1;
199 1.25 itojun if (!addr[0])
200 1.25 itojun return -1;
201 1.25 itojun
202 1.25 itojun bzero(&in6->s6_addr[8], 8);
203 1.25 itojun in6->s6_addr[15] = addr[0];
204 1.25 itojun
205 1.27 itojun /*
206 1.27 itojun * due to insufficient bitwidth, we mark it local.
207 1.27 itojun */
208 1.25 itojun in6->s6_addr[8] &= ~EUI64_GBIT; /* g bit to "individual" */
209 1.25 itojun in6->s6_addr[8] |= EUI64_UBIT; /* u bit to "local" */
210 1.7 itojun break;
211 1.25 itojun
212 1.25 itojun case IFT_GIF:
213 1.25 itojun #ifdef IFT_STF
214 1.25 itojun case IFT_STF:
215 1.25 itojun #endif
216 1.25 itojun /*
217 1.27 itojun * mech-06 says: "SHOULD use IPv4 address as ifid source".
218 1.27 itojun * however, IPv4 address is not very suitable as unique
219 1.27 itojun * identifier source (can be renumbered).
220 1.27 itojun * we don't do this.
221 1.25 itojun */
222 1.25 itojun return -1;
223 1.25 itojun
224 1.7 itojun default:
225 1.25 itojun return -1;
226 1.25 itojun }
227 1.25 itojun
228 1.25 itojun /* sanity check: g bit must not indicate "group" */
229 1.25 itojun if (EUI64_GROUP(in6))
230 1.25 itojun return -1;
231 1.25 itojun
232 1.25 itojun /* convert EUI64 into IPv6 interface identifier */
233 1.25 itojun EUI64_TO_IFID(in6);
234 1.25 itojun
235 1.25 itojun /*
236 1.25 itojun * sanity check: ifid must not be all zero, avoid conflict with
237 1.25 itojun * subnet router anycast
238 1.25 itojun */
239 1.25 itojun if ((in6->s6_addr[8] & ~(EUI64_GBIT | EUI64_UBIT)) == 0x00 &&
240 1.25 itojun bcmp(&in6->s6_addr[9], allzero, 7) == 0) {
241 1.25 itojun return -1;
242 1.7 itojun }
243 1.7 itojun
244 1.7 itojun return 0;
245 1.2 itojun }
246 1.2 itojun
247 1.2 itojun /*
248 1.25 itojun * Get interface identifier for the specified interface. If it is not
249 1.25 itojun * available on ifp0, borrow interface identifier from other information
250 1.25 itojun * sources.
251 1.13 itojun */
252 1.13 itojun static int
253 1.25 itojun get_ifid(ifp0, altifp, in6)
254 1.25 itojun struct ifnet *ifp0;
255 1.25 itojun struct ifnet *altifp; /*secondary EUI64 source*/
256 1.25 itojun struct in6_addr *in6;
257 1.13 itojun {
258 1.25 itojun struct ifnet *ifp;
259 1.25 itojun
260 1.25 itojun /* first, try to get it from the interface itself */
261 1.25 itojun if (get_hw_ifid(ifp0, in6) == 0) {
262 1.25 itojun #ifdef ND6_DEBUG
263 1.25 itojun printf("%s: got interface identifier from itself\n",
264 1.25 itojun if_name(ifp0));
265 1.25 itojun #endif
266 1.25 itojun goto success;
267 1.25 itojun }
268 1.25 itojun
269 1.25 itojun /* try secondary EUI64 source. this basically is for ATM PVC */
270 1.25 itojun if (altifp && get_hw_ifid(altifp, in6) == 0) {
271 1.25 itojun #ifdef ND6_DEBUG
272 1.25 itojun printf("%s: got interface identifier from %s\n",
273 1.25 itojun if_name(ifp0), ifname(altifp));
274 1.25 itojun #endif
275 1.25 itojun goto success;
276 1.25 itojun }
277 1.25 itojun
278 1.25 itojun /* next, try to get it from some other hardware interface */
279 1.25 itojun for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_list.tqe_next)
280 1.25 itojun {
281 1.25 itojun if (ifp == ifp0)
282 1.25 itojun continue;
283 1.25 itojun if (get_hw_ifid(ifp, in6) != 0)
284 1.25 itojun continue;
285 1.27 itojun
286 1.25 itojun /*
287 1.25 itojun * to borrow ifid from other interface, ifid needs to be
288 1.25 itojun * globally unique
289 1.25 itojun */
290 1.25 itojun if (IFID_UNIVERSAL(in6)) {
291 1.13 itojun
292 1.25 itojun #ifdef ND6_DEBUG
293 1.25 itojun printf("%s: borrow interface identifier from %s\n",
294 1.25 itojun if_name(ifp0), if_name(ifp));
295 1.25 itojun #endif
296 1.25 itojun goto success;
297 1.25 itojun }
298 1.25 itojun }
299 1.13 itojun
300 1.25 itojun /* last resort: get from random number source */
301 1.25 itojun if (get_rand_ifid(ifp, in6) == 0) {
302 1.25 itojun #ifdef ND6_DEBUG
303 1.25 itojun printf("%s: interface identifier generated by random number\n",
304 1.25 itojun if_name(ifp0));
305 1.25 itojun #endif
306 1.25 itojun goto success;
307 1.25 itojun }
308 1.13 itojun
309 1.25 itojun printf("%s: failed to get interface identifier", if_name(ifp0));
310 1.25 itojun return -1;
311 1.13 itojun
312 1.25 itojun success:
313 1.25 itojun #ifdef ND6_DEBUG
314 1.25 itojun printf("%s: ifid: "
315 1.25 itojun "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
316 1.25 itojun if_name(ifp0),
317 1.25 itojun in6->s6_addr[8], in6->s6_addr[9],
318 1.25 itojun in6->s6_addr[10], in6->s6_addr[11],
319 1.25 itojun in6->s6_addr[12], in6->s6_addr[13],
320 1.25 itojun in6->s6_addr[14], in6->s6_addr[15]);
321 1.25 itojun #endif
322 1.13 itojun return 0;
323 1.13 itojun }
324 1.13 itojun
325 1.13 itojun /*
326 1.25 itojun * configure IPv6 interface address. XXX code duplicated with in.c
327 1.2 itojun */
328 1.25 itojun static int
329 1.25 itojun in6_ifattach_addaddr(ifp, ia)
330 1.25 itojun struct ifnet *ifp;
331 1.25 itojun struct in6_ifaddr *ia;
332 1.2 itojun {
333 1.25 itojun struct in6_ifaddr *oia;
334 1.2 itojun struct ifaddr *ifa;
335 1.25 itojun int error;
336 1.25 itojun int rtflag;
337 1.25 itojun struct in6_addr llsol;
338 1.25 itojun
339 1.25 itojun /*
340 1.25 itojun * initialize if_addrlist, if we are the very first one
341 1.25 itojun */
342 1.25 itojun ifa = TAILQ_FIRST(&ifp->if_addrlist);
343 1.25 itojun if (ifa == NULL) {
344 1.25 itojun TAILQ_INIT(&ifp->if_addrlist);
345 1.25 itojun }
346 1.2 itojun
347 1.25 itojun /*
348 1.25 itojun * link the interface address to global list
349 1.25 itojun */
350 1.25 itojun TAILQ_INSERT_TAIL(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
351 1.27 itojun IFAREF(&ia->ia_ifa);
352 1.2 itojun
353 1.25 itojun /*
354 1.25 itojun * Also link into the IPv6 address chain beginning with in6_ifaddr.
355 1.25 itojun * kazu opposed it, but itojun & jinmei wanted.
356 1.25 itojun */
357 1.25 itojun if ((oia = in6_ifaddr) != NULL) {
358 1.25 itojun for (; oia->ia_next; oia = oia->ia_next)
359 1.2 itojun continue;
360 1.25 itojun oia->ia_next = ia;
361 1.25 itojun } else
362 1.25 itojun in6_ifaddr = ia;
363 1.27 itojun IFAREF(&ia->ia_ifa);
364 1.25 itojun
365 1.25 itojun /*
366 1.25 itojun * give the interface a chance to initialize, in case this
367 1.25 itojun * is the first address to be added.
368 1.25 itojun */
369 1.25 itojun if (ifp->if_ioctl != NULL) {
370 1.25 itojun int s;
371 1.25 itojun s = splimp();
372 1.25 itojun error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia);
373 1.25 itojun splx(s);
374 1.25 itojun } else
375 1.25 itojun error = 0;
376 1.25 itojun if (error) {
377 1.25 itojun switch (error) {
378 1.25 itojun case EAFNOSUPPORT:
379 1.25 itojun printf("%s: IPv6 not supported\n", if_name(ifp));
380 1.25 itojun break;
381 1.25 itojun default:
382 1.25 itojun printf("%s: SIOCSIFADDR error %d\n", if_name(ifp),
383 1.25 itojun error);
384 1.25 itojun break;
385 1.25 itojun }
386 1.25 itojun
387 1.25 itojun /* undo changes */
388 1.25 itojun TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
389 1.25 itojun IFAFREE(&ia->ia_ifa);
390 1.25 itojun if (oia)
391 1.25 itojun oia->ia_next = ia->ia_next;
392 1.25 itojun else
393 1.25 itojun in6_ifaddr = ia->ia_next;
394 1.25 itojun IFAFREE(&ia->ia_ifa);
395 1.25 itojun return -1;
396 1.25 itojun }
397 1.25 itojun
398 1.25 itojun /* configure link-layer address resolution */
399 1.27 itojun rtflag = 0;
400 1.25 itojun if (IN6_ARE_ADDR_EQUAL(&ia->ia_prefixmask.sin6_addr, &in6mask128))
401 1.25 itojun rtflag = RTF_HOST;
402 1.25 itojun else {
403 1.25 itojun switch (ifp->if_type) {
404 1.25 itojun case IFT_LOOP:
405 1.25 itojun #ifdef IFT_STF
406 1.25 itojun case IFT_STF:
407 1.25 itojun #endif
408 1.25 itojun rtflag = 0;
409 1.25 itojun break;
410 1.25 itojun default:
411 1.25 itojun ia->ia_ifa.ifa_rtrequest = nd6_rtrequest;
412 1.25 itojun ia->ia_ifa.ifa_flags |= RTF_CLONING;
413 1.25 itojun rtflag = RTF_CLONING;
414 1.25 itojun break;
415 1.2 itojun }
416 1.2 itojun }
417 1.25 itojun
418 1.25 itojun /* add route to the interface. */
419 1.25 itojun rtrequest(RTM_ADD,
420 1.25 itojun (struct sockaddr *)&ia->ia_addr,
421 1.25 itojun (struct sockaddr *)&ia->ia_addr,
422 1.25 itojun (struct sockaddr *)&ia->ia_prefixmask,
423 1.25 itojun RTF_UP | rtflag,
424 1.25 itojun (struct rtentry **)0);
425 1.25 itojun ia->ia_flags |= IFA_ROUTE;
426 1.25 itojun
427 1.25 itojun if ((rtflag & RTF_CLONING) != 0 &&
428 1.25 itojun (ifp->if_flags & IFF_MULTICAST) != 0) {
429 1.25 itojun /* Restore saved multicast addresses (if any). */
430 1.25 itojun in6_restoremkludge(ia, ifp);
431 1.25 itojun
432 1.25 itojun /*
433 1.25 itojun * join solicited multicast address
434 1.25 itojun */
435 1.25 itojun bzero(&llsol, sizeof(llsol));
436 1.25 itojun llsol.s6_addr16[0] = htons(0xff02);
437 1.25 itojun llsol.s6_addr16[1] = htons(ifp->if_index);
438 1.25 itojun llsol.s6_addr32[1] = 0;
439 1.25 itojun llsol.s6_addr32[2] = htonl(1);
440 1.25 itojun llsol.s6_addr32[3] = ia->ia_addr.sin6_addr.s6_addr32[3];
441 1.25 itojun llsol.s6_addr8[12] = 0xff;
442 1.25 itojun (void)in6_addmulti(&llsol, ifp, &error);
443 1.25 itojun
444 1.25 itojun /* XXX should we run DAD on other interface types? */
445 1.25 itojun switch (ifp->if_type) {
446 1.25 itojun #if 1
447 1.25 itojun case IFT_ARCNET:
448 1.25 itojun case IFT_ETHER:
449 1.25 itojun case IFT_FDDI:
450 1.25 itojun #else
451 1.25 itojun default:
452 1.4 thorpej #endif
453 1.25 itojun /* mark the address TENTATIVE, if needed. */
454 1.25 itojun ia->ia6_flags |= IN6_IFF_TENTATIVE;
455 1.25 itojun /* nd6_dad_start() will be called in in6_if_up */
456 1.25 itojun }
457 1.25 itojun }
458 1.25 itojun
459 1.25 itojun return 0;
460 1.25 itojun }
461 1.25 itojun
462 1.25 itojun static int
463 1.25 itojun in6_ifattach_linklocal(ifp, altifp)
464 1.25 itojun struct ifnet *ifp;
465 1.25 itojun struct ifnet *altifp; /*secondary EUI64 source*/
466 1.25 itojun {
467 1.25 itojun struct in6_ifaddr *ia;
468 1.2 itojun
469 1.25 itojun /*
470 1.25 itojun * configure link-local address
471 1.25 itojun */
472 1.25 itojun ia = (struct in6_ifaddr *)malloc(sizeof(*ia), M_IFADDR, M_WAITOK);
473 1.25 itojun bzero((caddr_t)ia, sizeof(*ia));
474 1.25 itojun ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
475 1.25 itojun if (ifp->if_flags & IFF_POINTOPOINT)
476 1.25 itojun ia->ia_ifa.ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr;
477 1.25 itojun else
478 1.25 itojun ia->ia_ifa.ifa_dstaddr = NULL;
479 1.25 itojun ia->ia_ifa.ifa_netmask = (struct sockaddr *)&ia->ia_prefixmask;
480 1.25 itojun ia->ia_ifp = ifp;
481 1.2 itojun
482 1.25 itojun bzero(&ia->ia_prefixmask, sizeof(ia->ia_prefixmask));
483 1.25 itojun ia->ia_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
484 1.25 itojun ia->ia_prefixmask.sin6_family = AF_INET6;
485 1.25 itojun ia->ia_prefixmask.sin6_addr = in6mask64;
486 1.5 itojun
487 1.25 itojun /* just in case */
488 1.25 itojun bzero(&ia->ia_dstaddr, sizeof(ia->ia_dstaddr));
489 1.25 itojun ia->ia_dstaddr.sin6_len = sizeof(struct sockaddr_in6);
490 1.25 itojun ia->ia_dstaddr.sin6_family = AF_INET6;
491 1.5 itojun
492 1.25 itojun bzero(&ia->ia_addr, sizeof(ia->ia_addr));
493 1.25 itojun ia->ia_addr.sin6_len = sizeof(struct sockaddr_in6);
494 1.25 itojun ia->ia_addr.sin6_family = AF_INET6;
495 1.25 itojun ia->ia_addr.sin6_addr.s6_addr16[0] = htons(0xfe80);
496 1.25 itojun ia->ia_addr.sin6_addr.s6_addr16[1] = htons(ifp->if_index);
497 1.25 itojun ia->ia_addr.sin6_addr.s6_addr32[1] = 0;
498 1.25 itojun if (ifp->if_flags & IFF_LOOPBACK) {
499 1.25 itojun ia->ia_addr.sin6_addr.s6_addr32[2] = 0;
500 1.25 itojun ia->ia_addr.sin6_addr.s6_addr32[3] = htonl(1);
501 1.2 itojun } else {
502 1.25 itojun if (get_ifid(ifp, altifp, &ia->ia_addr.sin6_addr) != 0) {
503 1.25 itojun #ifdef ND6_DEBUG
504 1.25 itojun printf("%s: no ifid available\n", if_name(ifp));
505 1.4 thorpej #endif
506 1.25 itojun free(ia, M_IFADDR);
507 1.25 itojun return -1;
508 1.25 itojun }
509 1.25 itojun }
510 1.25 itojun
511 1.25 itojun ia->ia_ifa.ifa_metric = ifp->if_metric;
512 1.25 itojun
513 1.25 itojun if (in6_ifattach_addaddr(ifp, ia) != 0) {
514 1.25 itojun /* ia will be freed on failure */
515 1.25 itojun return -1;
516 1.25 itojun }
517 1.25 itojun
518 1.25 itojun return 0;
519 1.25 itojun }
520 1.25 itojun
521 1.25 itojun static int
522 1.25 itojun in6_ifattach_loopback(ifp)
523 1.25 itojun struct ifnet *ifp; /* must be IFT_LOOP */
524 1.25 itojun {
525 1.25 itojun struct in6_ifaddr *ia;
526 1.25 itojun
527 1.25 itojun /*
528 1.25 itojun * configure link-local address
529 1.25 itojun */
530 1.25 itojun ia = (struct in6_ifaddr *)malloc(sizeof(*ia), M_IFADDR, M_WAITOK);
531 1.25 itojun bzero((caddr_t)ia, sizeof(*ia));
532 1.25 itojun ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
533 1.25 itojun ia->ia_ifa.ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr;
534 1.25 itojun ia->ia_ifa.ifa_netmask = (struct sockaddr *)&ia->ia_prefixmask;
535 1.25 itojun ia->ia_ifp = ifp;
536 1.25 itojun
537 1.25 itojun bzero(&ia->ia_prefixmask, sizeof(ia->ia_prefixmask));
538 1.25 itojun ia->ia_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
539 1.25 itojun ia->ia_prefixmask.sin6_family = AF_INET6;
540 1.25 itojun ia->ia_prefixmask.sin6_addr = in6mask128;
541 1.25 itojun
542 1.25 itojun /*
543 1.25 itojun * Always initialize ia_dstaddr (= broadcast address) to loopback
544 1.25 itojun * address, to make getifaddr happier.
545 1.25 itojun *
546 1.25 itojun * For BSDI, it is mandatory. The BSDI version of
547 1.25 itojun * ifa_ifwithroute() rejects to add a route to the loopback
548 1.25 itojun * interface. Even for other systems, loopback looks somewhat
549 1.25 itojun * special.
550 1.25 itojun */
551 1.25 itojun bzero(&ia->ia_dstaddr, sizeof(ia->ia_dstaddr));
552 1.25 itojun ia->ia_dstaddr.sin6_len = sizeof(struct sockaddr_in6);
553 1.25 itojun ia->ia_dstaddr.sin6_family = AF_INET6;
554 1.25 itojun ia->ia_dstaddr.sin6_addr = in6addr_loopback;
555 1.25 itojun
556 1.25 itojun bzero(&ia->ia_addr, sizeof(ia->ia_addr));
557 1.25 itojun ia->ia_addr.sin6_len = sizeof(struct sockaddr_in6);
558 1.25 itojun ia->ia_addr.sin6_family = AF_INET6;
559 1.25 itojun ia->ia_addr.sin6_addr = in6addr_loopback;
560 1.25 itojun
561 1.25 itojun ia->ia_ifa.ifa_metric = ifp->if_metric;
562 1.25 itojun
563 1.25 itojun if (in6_ifattach_addaddr(ifp, ia) != 0) {
564 1.25 itojun /* ia will be freed on failure */
565 1.25 itojun return -1;
566 1.2 itojun }
567 1.25 itojun
568 1.25 itojun return 0;
569 1.2 itojun }
570 1.2 itojun
571 1.17 itojun /*
572 1.17 itojun * XXX multiple loopback interface needs more care. for instance,
573 1.17 itojun * nodelocal address needs to be configured onto only one of them.
574 1.25 itojun * XXX multiple link-local address case
575 1.17 itojun */
576 1.2 itojun void
577 1.25 itojun in6_ifattach(ifp, altifp)
578 1.2 itojun struct ifnet *ifp;
579 1.25 itojun struct ifnet *altifp; /* secondary EUI64 source */
580 1.2 itojun {
581 1.2 itojun static size_t if_indexlim = 8;
582 1.2 itojun struct sockaddr_in6 mltaddr;
583 1.2 itojun struct sockaddr_in6 mltmask;
584 1.2 itojun struct sockaddr_in6 gate;
585 1.2 itojun struct sockaddr_in6 mask;
586 1.25 itojun struct in6_ifaddr *ia;
587 1.25 itojun struct in6_addr in6;
588 1.13 itojun
589 1.2 itojun /*
590 1.2 itojun * We have some arrays that should be indexed by if_index.
591 1.2 itojun * since if_index will grow dynamically, they should grow too.
592 1.13 itojun * struct in6_ifstat **in6_ifstat
593 1.13 itojun * struct icmp6_ifstat **icmp6_ifstat
594 1.2 itojun */
595 1.25 itojun if (in6_ifstat == NULL || icmp6_ifstat == NULL ||
596 1.25 itojun if_index >= if_indexlim) {
597 1.2 itojun size_t n;
598 1.2 itojun caddr_t q;
599 1.7 itojun size_t olim;
600 1.2 itojun
601 1.7 itojun olim = if_indexlim;
602 1.7 itojun while (if_index >= if_indexlim)
603 1.2 itojun if_indexlim <<= 1;
604 1.2 itojun
605 1.13 itojun /* grow in6_ifstat */
606 1.13 itojun n = if_indexlim * sizeof(struct in6_ifstat *);
607 1.13 itojun q = (caddr_t)malloc(n, M_IFADDR, M_WAITOK);
608 1.13 itojun bzero(q, n);
609 1.13 itojun if (in6_ifstat) {
610 1.13 itojun bcopy((caddr_t)in6_ifstat, q,
611 1.13 itojun olim * sizeof(struct in6_ifstat *));
612 1.13 itojun free((caddr_t)in6_ifstat, M_IFADDR);
613 1.13 itojun }
614 1.13 itojun in6_ifstat = (struct in6_ifstat **)q;
615 1.13 itojun in6_ifstatmax = if_indexlim;
616 1.13 itojun
617 1.13 itojun /* grow icmp6_ifstat */
618 1.13 itojun n = if_indexlim * sizeof(struct icmp6_ifstat *);
619 1.2 itojun q = (caddr_t)malloc(n, M_IFADDR, M_WAITOK);
620 1.2 itojun bzero(q, n);
621 1.13 itojun if (icmp6_ifstat) {
622 1.13 itojun bcopy((caddr_t)icmp6_ifstat, q,
623 1.13 itojun olim * sizeof(struct icmp6_ifstat *));
624 1.13 itojun free((caddr_t)icmp6_ifstat, M_IFADDR);
625 1.2 itojun }
626 1.13 itojun icmp6_ifstat = (struct icmp6_ifstat **)q;
627 1.13 itojun icmp6_ifstatmax = if_indexlim;
628 1.2 itojun }
629 1.2 itojun
630 1.2 itojun /*
631 1.25 itojun * quirks based on interface type
632 1.2 itojun */
633 1.25 itojun switch (ifp->if_type) {
634 1.25 itojun #ifdef IFT_STF
635 1.25 itojun case IFT_STF:
636 1.25 itojun /*
637 1.25 itojun * 6to4 interface is a very speical kind of beast.
638 1.25 itojun * no multicast, no linklocal (based on 03 draft).
639 1.25 itojun */
640 1.25 itojun goto statinit;
641 1.25 itojun #endif
642 1.25 itojun default:
643 1.25 itojun break;
644 1.7 itojun }
645 1.2 itojun
646 1.2 itojun /*
647 1.25 itojun * usually, we require multicast capability to the interface
648 1.2 itojun */
649 1.25 itojun if ((ifp->if_flags & IFF_MULTICAST) == 0) {
650 1.25 itojun printf("%s: not multicast capable, IPv6 not enabled\n",
651 1.25 itojun if_name(ifp));
652 1.25 itojun return;
653 1.25 itojun }
654 1.15 thorpej
655 1.2 itojun /*
656 1.25 itojun * assign link-local address, if there's none
657 1.2 itojun */
658 1.25 itojun ia = in6ifa_ifpforlinklocal(ifp, 0);
659 1.25 itojun if (ia == NULL) {
660 1.25 itojun if (in6_ifattach_linklocal(ifp, altifp) != 0)
661 1.25 itojun return;
662 1.25 itojun ia = in6ifa_ifpforlinklocal(ifp, 0);
663 1.2 itojun
664 1.25 itojun if (ia == NULL) {
665 1.25 itojun printf("%s: failed to add link-local address",
666 1.25 itojun if_name(ifp));
667 1.2 itojun
668 1.25 itojun /* we can't initialize multicasts without link-local */
669 1.25 itojun goto statinit;
670 1.2 itojun }
671 1.2 itojun }
672 1.2 itojun
673 1.25 itojun if (ifp->if_flags & IFF_POINTOPOINT) {
674 1.2 itojun /*
675 1.2 itojun * route local address to loopback
676 1.2 itojun */
677 1.2 itojun bzero(&gate, sizeof(gate));
678 1.2 itojun gate.sin6_len = sizeof(struct sockaddr_in6);
679 1.2 itojun gate.sin6_family = AF_INET6;
680 1.2 itojun gate.sin6_addr = in6addr_loopback;
681 1.2 itojun bzero(&mask, sizeof(mask));
682 1.2 itojun mask.sin6_len = sizeof(struct sockaddr_in6);
683 1.2 itojun mask.sin6_family = AF_INET6;
684 1.2 itojun mask.sin6_addr = in6mask64;
685 1.2 itojun rtrequest(RTM_ADD,
686 1.2 itojun (struct sockaddr *)&ia->ia_addr,
687 1.2 itojun (struct sockaddr *)&gate,
688 1.2 itojun (struct sockaddr *)&mask,
689 1.2 itojun RTF_UP|RTF_HOST,
690 1.2 itojun (struct rtentry **)0);
691 1.2 itojun }
692 1.2 itojun
693 1.2 itojun /*
694 1.25 itojun * assign loopback address for loopback interface
695 1.25 itojun * XXX multiple loopback interface case
696 1.2 itojun */
697 1.25 itojun in6 = in6addr_loopback;
698 1.25 itojun if (ifp->if_flags & IFF_LOOPBACK) {
699 1.25 itojun if (in6ifa_ifpwithaddr(ifp, &in6) == NULL) {
700 1.25 itojun if (in6_ifattach_loopback(ifp) != 0)
701 1.25 itojun return;
702 1.25 itojun }
703 1.25 itojun }
704 1.2 itojun
705 1.25 itojun #ifdef DIAGNOSTIC
706 1.25 itojun if (!ia) {
707 1.25 itojun panic("ia == NULL in in6_ifattach");
708 1.25 itojun /*NOTREACHED*/
709 1.2 itojun }
710 1.25 itojun #endif
711 1.2 itojun
712 1.2 itojun /*
713 1.2 itojun * join multicast
714 1.2 itojun */
715 1.2 itojun if (ifp->if_flags & IFF_MULTICAST) {
716 1.2 itojun int error; /* not used */
717 1.25 itojun struct in6_multi *in6m;
718 1.2 itojun
719 1.25 itojun /* Restore saved multicast addresses (if any). */
720 1.2 itojun in6_restoremkludge(ia, ifp);
721 1.2 itojun
722 1.2 itojun bzero(&mltmask, sizeof(mltmask));
723 1.2 itojun mltmask.sin6_len = sizeof(struct sockaddr_in6);
724 1.2 itojun mltmask.sin6_family = AF_INET6;
725 1.2 itojun mltmask.sin6_addr = in6mask32;
726 1.2 itojun
727 1.2 itojun /*
728 1.2 itojun * join link-local all-nodes address
729 1.2 itojun */
730 1.2 itojun bzero(&mltaddr, sizeof(mltaddr));
731 1.2 itojun mltaddr.sin6_len = sizeof(struct sockaddr_in6);
732 1.2 itojun mltaddr.sin6_family = AF_INET6;
733 1.2 itojun mltaddr.sin6_addr = in6addr_linklocal_allnodes;
734 1.2 itojun mltaddr.sin6_addr.s6_addr16[1] = htons(ifp->if_index);
735 1.2 itojun
736 1.25 itojun IN6_LOOKUP_MULTI(mltaddr.sin6_addr, ifp, in6m);
737 1.25 itojun if (in6m == NULL) {
738 1.2 itojun rtrequest(RTM_ADD,
739 1.2 itojun (struct sockaddr *)&mltaddr,
740 1.25 itojun (struct sockaddr *)&ia->ia_addr,
741 1.2 itojun (struct sockaddr *)&mltmask,
742 1.25 itojun RTF_UP|RTF_CLONING, /* xxx */
743 1.2 itojun (struct rtentry **)0);
744 1.2 itojun (void)in6_addmulti(&mltaddr.sin6_addr, ifp, &error);
745 1.25 itojun }
746 1.25 itojun
747 1.25 itojun if (ifp->if_flags & IFF_LOOPBACK) {
748 1.25 itojun in6 = in6addr_loopback;
749 1.25 itojun ia = in6ifa_ifpwithaddr(ifp, &in6);
750 1.2 itojun /*
751 1.25 itojun * join node-local all-nodes address, on loopback
752 1.2 itojun */
753 1.25 itojun mltaddr.sin6_addr = in6addr_nodelocal_allnodes;
754 1.25 itojun
755 1.25 itojun IN6_LOOKUP_MULTI(mltaddr.sin6_addr, ifp, in6m);
756 1.25 itojun if (in6m == NULL && ia != NULL) {
757 1.25 itojun rtrequest(RTM_ADD,
758 1.25 itojun (struct sockaddr *)&mltaddr,
759 1.25 itojun (struct sockaddr *)&ia->ia_addr,
760 1.25 itojun (struct sockaddr *)&mltmask,
761 1.25 itojun RTF_UP,
762 1.25 itojun (struct rtentry **)0);
763 1.25 itojun (void)in6_addmulti(&mltaddr.sin6_addr, ifp, &error);
764 1.25 itojun }
765 1.2 itojun }
766 1.2 itojun }
767 1.2 itojun
768 1.25 itojun statinit:;
769 1.25 itojun
770 1.2 itojun /* update dynamically. */
771 1.2 itojun if (in6_maxmtu < ifp->if_mtu)
772 1.2 itojun in6_maxmtu = ifp->if_mtu;
773 1.2 itojun
774 1.13 itojun if (in6_ifstat[ifp->if_index] == NULL) {
775 1.13 itojun in6_ifstat[ifp->if_index] = (struct in6_ifstat *)
776 1.13 itojun malloc(sizeof(struct in6_ifstat), M_IFADDR, M_WAITOK);
777 1.13 itojun bzero(in6_ifstat[ifp->if_index], sizeof(struct in6_ifstat));
778 1.13 itojun }
779 1.13 itojun if (icmp6_ifstat[ifp->if_index] == NULL) {
780 1.13 itojun icmp6_ifstat[ifp->if_index] = (struct icmp6_ifstat *)
781 1.13 itojun malloc(sizeof(struct icmp6_ifstat), M_IFADDR, M_WAITOK);
782 1.13 itojun bzero(icmp6_ifstat[ifp->if_index], sizeof(struct icmp6_ifstat));
783 1.13 itojun }
784 1.13 itojun
785 1.2 itojun /* initialize NDP variables */
786 1.2 itojun nd6_ifattach(ifp);
787 1.2 itojun }
788 1.2 itojun
789 1.17 itojun /*
790 1.17 itojun * NOTE: in6_ifdetach() does not support loopback if at this moment.
791 1.17 itojun */
792 1.2 itojun void
793 1.2 itojun in6_ifdetach(ifp)
794 1.2 itojun struct ifnet *ifp;
795 1.2 itojun {
796 1.2 itojun struct in6_ifaddr *ia, *oia;
797 1.30 itojun struct ifaddr *ifa, *next;
798 1.2 itojun struct rtentry *rt;
799 1.2 itojun short rtflags;
800 1.16 itojun struct sockaddr_in6 sin6;
801 1.2 itojun
802 1.18 itojun /* nuke prefix list. this may try to remove some of ifaddrs as well */
803 1.18 itojun in6_purgeprefix(ifp);
804 1.30.4.2 msaitoh
805 1.30.4.2 msaitoh /* remove ip6_mrouter stuff */
806 1.30.4.2 msaitoh ip6_mrouter_detach(ifp);
807 1.18 itojun
808 1.18 itojun /* remove neighbor management table */
809 1.18 itojun nd6_purge(ifp);
810 1.18 itojun
811 1.30 itojun /* nuke any of IPv6 addresses we have */
812 1.30 itojun for (ifa = ifp->if_addrlist.tqh_first; ifa; ifa = next)
813 1.30 itojun {
814 1.30 itojun next = ifa->ifa_list.tqe_next;
815 1.30 itojun if (ifa->ifa_addr->sa_family != AF_INET6)
816 1.30 itojun continue;
817 1.30 itojun in6_purgeaddr(ifa, ifp);
818 1.30 itojun }
819 1.30 itojun
820 1.30 itojun /* undo everything done by in6_ifattach(), just in case */
821 1.30 itojun for (ifa = ifp->if_addrlist.tqh_first; ifa; ifa = next)
822 1.13 itojun {
823 1.30 itojun next = ifa->ifa_list.tqe_next;
824 1.30 itojun
825 1.30 itojun
826 1.2 itojun if (ifa->ifa_addr->sa_family != AF_INET6
827 1.2 itojun || !IN6_IS_ADDR_LINKLOCAL(&satosin6(&ifa->ifa_addr)->sin6_addr)) {
828 1.2 itojun continue;
829 1.2 itojun }
830 1.2 itojun
831 1.2 itojun ia = (struct in6_ifaddr *)ifa;
832 1.2 itojun
833 1.2 itojun /* remove from the routing table */
834 1.2 itojun if ((ia->ia_flags & IFA_ROUTE)
835 1.14 itojun && (rt = rtalloc1((struct sockaddr *)&ia->ia_addr, 0))) {
836 1.2 itojun rtflags = rt->rt_flags;
837 1.2 itojun rtfree(rt);
838 1.2 itojun rtrequest(RTM_DELETE,
839 1.2 itojun (struct sockaddr *)&ia->ia_addr,
840 1.24 itojun (struct sockaddr *)&ia->ia_addr,
841 1.2 itojun (struct sockaddr *)&ia->ia_prefixmask,
842 1.2 itojun rtflags, (struct rtentry **)0);
843 1.2 itojun }
844 1.2 itojun
845 1.2 itojun /* remove from the linked list */
846 1.2 itojun TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
847 1.30 itojun IFAFREE(&ia->ia_ifa);
848 1.2 itojun
849 1.2 itojun /* also remove from the IPv6 address chain(itojun&jinmei) */
850 1.2 itojun oia = ia;
851 1.2 itojun if (oia == (ia = in6_ifaddr))
852 1.2 itojun in6_ifaddr = ia->ia_next;
853 1.2 itojun else {
854 1.2 itojun while (ia->ia_next && (ia->ia_next != oia))
855 1.2 itojun ia = ia->ia_next;
856 1.2 itojun if (ia->ia_next)
857 1.2 itojun ia->ia_next = oia->ia_next;
858 1.25 itojun #ifdef ND6_DEBUG
859 1.2 itojun else
860 1.4 thorpej printf("%s: didn't unlink in6ifaddr from "
861 1.13 itojun "list\n", if_name(ifp));
862 1.4 thorpej #endif
863 1.2 itojun }
864 1.2 itojun
865 1.30 itojun IFAFREE(&oia->ia_ifa);
866 1.16 itojun }
867 1.16 itojun
868 1.17 itojun /* cleanup multicast address kludge table, if there is any */
869 1.17 itojun in6_purgemkludge(ifp);
870 1.30 itojun
871 1.30 itojun /* remove neighbor management table */
872 1.30 itojun nd6_purge(ifp);
873 1.18 itojun
874 1.16 itojun /* remove route to link-local allnodes multicast (ff02::1) */
875 1.16 itojun bzero(&sin6, sizeof(sin6));
876 1.16 itojun sin6.sin6_len = sizeof(struct sockaddr_in6);
877 1.16 itojun sin6.sin6_family = AF_INET6;
878 1.16 itojun sin6.sin6_addr = in6addr_linklocal_allnodes;
879 1.16 itojun sin6.sin6_addr.s6_addr16[1] = htons(ifp->if_index);
880 1.30.4.1 he rt = rtalloc1((struct sockaddr *)&sin6, 0);
881 1.30.4.1 he if (rt && rt->rt_ifp == ifp) {
882 1.16 itojun rtrequest(RTM_DELETE, (struct sockaddr *)rt_key(rt),
883 1.16 itojun rt->rt_gateway, rt_mask(rt), rt->rt_flags, 0);
884 1.16 itojun rtfree(rt);
885 1.2 itojun }
886 1.2 itojun }
887