in6_ifattach.c revision 1.14 1 /* $NetBSD: in6_ifattach.c,v 1.14 2000/01/06 15:46:09 itojun Exp $ */
2
3 /*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/malloc.h>
35 #include <sys/socket.h>
36 #include <sys/sockio.h>
37 #include <sys/kernel.h>
38 #include <sys/md5.h>
39
40 #include <net/if.h>
41 #include <net/if_dl.h>
42 #include <net/if_types.h>
43 #include <net/route.h>
44
45 #include <netinet/in.h>
46 #include <netinet/in_var.h>
47
48 #include <netinet6/ip6.h>
49 #include <netinet6/ip6_var.h>
50 #include <netinet6/in6_ifattach.h>
51 #include <netinet6/ip6.h>
52 #include <netinet6/ip6_var.h>
53 #include <netinet6/nd6.h>
54
55 #include <net/net_osdep.h>
56
57 static struct in6_addr llsol;
58
59 struct in6_ifstat **in6_ifstat = NULL;
60 struct icmp6_ifstat **icmp6_ifstat = NULL;
61 size_t in6_ifstatmax = 0;
62 size_t icmp6_ifstatmax = 0;
63 unsigned long in6_maxmtu = 0;
64
65 int found_first_ifid = 0;
66 #define IFID_LEN 8
67 static u_int8_t first_ifid[IFID_LEN];
68
69 static int laddr_to_eui64 __P((u_int8_t *, u_int8_t *, size_t));
70 static int gen_rand_eui64 __P((u_int8_t *));
71
72 static int
73 laddr_to_eui64(dst, src, len)
74 u_int8_t *dst;
75 u_int8_t *src;
76 size_t len;
77 {
78 static u_int8_t zero[8];
79
80 bzero(zero, sizeof(zero));
81
82 switch (len) {
83 case 6:
84 if (bcmp(zero, src, 6) == 0)
85 return EINVAL;
86 dst[0] = src[0];
87 dst[1] = src[1];
88 dst[2] = src[2];
89 dst[3] = 0xff;
90 dst[4] = 0xfe;
91 dst[5] = src[3];
92 dst[6] = src[4];
93 dst[7] = src[5];
94 break;
95 case 8:
96 if (bcmp(zero, src, 8) == 0)
97 return EINVAL;
98 bcopy(src, dst, len);
99 break;
100 default:
101 return EINVAL;
102 }
103
104 return 0;
105 }
106
107 /*
108 * Generate a last-resort interface identifier, when the machine has no
109 * IEEE802/EUI64 address sources.
110 * The address should be random, and should not change across reboot.
111 */
112 static int
113 gen_rand_eui64(dst)
114 u_int8_t *dst;
115 {
116 MD5_CTX ctxt;
117 u_int8_t digest[16];
118
119 /* generate 8bytes of pseudo-random value. */
120 bzero(&ctxt, sizeof(ctxt));
121 MD5Init(&ctxt);
122 MD5Update(&ctxt, hostname, hostnamelen);
123 MD5Final(digest, &ctxt);
124
125 /* assumes sizeof(digest) > sizeof(first_ifid) */
126 bcopy(digest, dst, 8);
127
128 /* make sure to set "u" bit to local, and "g" bit to individual. */
129 dst[0] &= 0xfe;
130 dst[0] |= 0x02; /* EUI64 "local" */
131
132 return 0;
133 }
134
135 /*
136 * Find first ifid on list of interfaces.
137 * This is assumed that ifp0's interface token (for example, IEEE802 MAC)
138 * is globally unique. We may need to have a flag parameter in the future.
139 */
140 int
141 in6_ifattach_getifid(ifp0)
142 struct ifnet *ifp0;
143 {
144 struct ifnet *ifp;
145 struct ifaddr *ifa;
146 u_int8_t *addr = NULL;
147 int addrlen = 0;
148 struct sockaddr_dl *sdl;
149
150 if (found_first_ifid)
151 return 0;
152
153 for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_list.tqe_next)
154 {
155 if (ifp0 != NULL && ifp0 != ifp)
156 continue;
157 for (ifa = ifp->if_addrlist.tqh_first;
158 ifa;
159 ifa = ifa->ifa_list.tqe_next)
160 {
161 if (ifa->ifa_addr->sa_family != AF_LINK)
162 continue;
163 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
164 if (sdl == NULL)
165 continue;
166 if (sdl->sdl_alen == 0)
167 continue;
168 switch (ifp->if_type) {
169 case IFT_ETHER:
170 case IFT_FDDI:
171 case IFT_ATM:
172 /* IEEE802/EUI64 cases - what others? */
173 addr = LLADDR(sdl);
174 addrlen = sdl->sdl_alen;
175 /*
176 * to copy ifid from IEEE802/EUI64 interface,
177 * u bit of the source needs to be 0.
178 */
179 if ((addr[0] & 0x02) != 0)
180 break;
181 goto found;
182 case IFT_ARCNET:
183 /*
184 * ARCnet interface token cannot be used as
185 * globally unique identifier due to its
186 * small bitwidth.
187 */
188 break;
189 default:
190 break;
191 }
192 }
193 }
194 #ifdef DEBUG
195 printf("in6_ifattach_getifid: failed to get EUI64");
196 #endif
197 return EADDRNOTAVAIL;
198
199 found:
200 if (laddr_to_eui64(first_ifid, addr, addrlen) == 0)
201 found_first_ifid = 1;
202
203 if (found_first_ifid) {
204 printf("%s: supplying EUI64: "
205 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
206 if_name(ifp),
207 first_ifid[0], first_ifid[1],
208 first_ifid[2], first_ifid[3],
209 first_ifid[4], first_ifid[5],
210 first_ifid[6], first_ifid[7]);
211
212 /* invert u bit to convert EUI64 to RFC2373 interface ID. */
213 first_ifid[0] ^= 0x02;
214
215 return 0;
216 } else {
217 #ifdef DEBUG
218 printf("in6_ifattach_getifid: failed to get EUI64");
219 #endif
220 return EADDRNOTAVAIL;
221 }
222 }
223
224 void
225 in6_ifattach(ifp, type, laddr, noloop)
226 struct ifnet *ifp;
227 u_int type;
228 caddr_t laddr;
229 /* size_t laddrlen; */
230 int noloop;
231 {
232 static size_t if_indexlim = 8;
233 struct sockaddr_in6 mltaddr;
234 struct sockaddr_in6 mltmask;
235 struct sockaddr_in6 gate;
236 struct sockaddr_in6 mask;
237
238 struct in6_ifaddr *ia, *ib, *oia;
239 struct ifaddr *ifa;
240 int rtflag = 0;
241
242 if (type == IN6_IFT_P2P && found_first_ifid == 0) {
243 printf("%s: no ifid available for IPv6 link-local address\n",
244 if_name(ifp));
245 #if 0
246 return;
247 #else
248 /* last resort */
249 if (gen_rand_eui64(first_ifid) == 0) {
250 printf("%s: using random value as EUI64: "
251 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
252 if_name(ifp),
253 first_ifid[0], first_ifid[1],
254 first_ifid[2], first_ifid[3],
255 first_ifid[4], first_ifid[5],
256 first_ifid[6], first_ifid[7]);
257 /*
258 * invert u bit to convert EUI64 to RFC2373 interface
259 * ID.
260 */
261 first_ifid[0] ^= 0x02;
262
263 found_first_ifid = 1;
264 }
265 #endif
266 }
267
268 if ((ifp->if_flags & IFF_MULTICAST) == 0) {
269 printf("%s: not multicast capable, IPv6 not enabled\n",
270 if_name(ifp));
271 return;
272 }
273
274 /*
275 * We have some arrays that should be indexed by if_index.
276 * since if_index will grow dynamically, they should grow too.
277 * struct in6_ifstat **in6_ifstat
278 * struct icmp6_ifstat **icmp6_ifstat
279 */
280 if (in6_ifstat == NULL || icmp6_ifstat == NULL
281 || if_index >= if_indexlim) {
282 size_t n;
283 caddr_t q;
284 size_t olim;
285
286 olim = if_indexlim;
287 while (if_index >= if_indexlim)
288 if_indexlim <<= 1;
289
290 /* grow in6_ifstat */
291 n = if_indexlim * sizeof(struct in6_ifstat *);
292 q = (caddr_t)malloc(n, M_IFADDR, M_WAITOK);
293 bzero(q, n);
294 if (in6_ifstat) {
295 bcopy((caddr_t)in6_ifstat, q,
296 olim * sizeof(struct in6_ifstat *));
297 free((caddr_t)in6_ifstat, M_IFADDR);
298 }
299 in6_ifstat = (struct in6_ifstat **)q;
300 in6_ifstatmax = if_indexlim;
301
302 /* grow icmp6_ifstat */
303 n = if_indexlim * sizeof(struct icmp6_ifstat *);
304 q = (caddr_t)malloc(n, M_IFADDR, M_WAITOK);
305 bzero(q, n);
306 if (icmp6_ifstat) {
307 bcopy((caddr_t)icmp6_ifstat, q,
308 olim * sizeof(struct icmp6_ifstat *));
309 free((caddr_t)icmp6_ifstat, M_IFADDR);
310 }
311 icmp6_ifstat = (struct icmp6_ifstat **)q;
312 icmp6_ifstatmax = if_indexlim;
313 }
314
315 /*
316 * To prevent to assign link-local address to PnP network
317 * cards multiple times.
318 * This is lengthy for P2P and LOOP but works.
319 */
320 ifa = TAILQ_FIRST(&ifp->if_addrlist);
321 if (ifa != NULL) {
322 for ( ; ifa; ifa = TAILQ_NEXT(ifa, ifa_list)) {
323 if (ifa->ifa_addr->sa_family != AF_INET6)
324 continue;
325 if (IN6_IS_ADDR_LINKLOCAL(&satosin6(ifa->ifa_addr)->sin6_addr))
326 return;
327 }
328 } else {
329 TAILQ_INIT(&ifp->if_addrlist);
330 }
331
332 /*
333 * link-local address
334 */
335 ia = (struct in6_ifaddr *)malloc(sizeof(*ia), M_IFADDR, M_WAITOK);
336 bzero((caddr_t)ia, sizeof(*ia));
337 ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
338 ia->ia_ifa.ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr;
339 ia->ia_ifa.ifa_netmask = (struct sockaddr *)&ia->ia_prefixmask;
340 ia->ia_ifp = ifp;
341 TAILQ_INSERT_TAIL(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
342 /*
343 * Also link into the IPv6 address chain beginning with in6_ifaddr.
344 * kazu opposed it, but itojun & jinmei wanted.
345 */
346 if ((oia = in6_ifaddr) != NULL) {
347 for (; oia->ia_next; oia = oia->ia_next)
348 continue;
349 oia->ia_next = ia;
350 } else
351 in6_ifaddr = ia;
352
353 ia->ia_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
354 ia->ia_prefixmask.sin6_family = AF_INET6;
355 ia->ia_prefixmask.sin6_addr = in6mask64;
356
357 bzero(&ia->ia_addr, sizeof(struct sockaddr_in6));
358 ia->ia_addr.sin6_len = sizeof(struct sockaddr_in6);
359 ia->ia_addr.sin6_family = AF_INET6;
360 ia->ia_addr.sin6_addr.s6_addr16[0] = htons(0xfe80);
361 ia->ia_addr.sin6_addr.s6_addr16[1] = htons(ifp->if_index);
362 ia->ia_addr.sin6_addr.s6_addr32[1] = 0;
363
364 switch (type) {
365 case IN6_IFT_LOOP:
366 ia->ia_addr.sin6_addr.s6_addr32[2] = 0;
367 ia->ia_addr.sin6_addr.s6_addr32[3] = htonl(1);
368 break;
369 case IN6_IFT_802:
370 ia->ia_ifa.ifa_rtrequest = nd6_rtrequest;
371 ia->ia_ifa.ifa_flags |= RTF_CLONING;
372 rtflag = RTF_CLONING;
373 /* fall through */
374 case IN6_IFT_P2P802:
375 if (laddr == NULL)
376 break;
377 /* XXX use laddrlen */
378 if (laddr_to_eui64(&ia->ia_addr.sin6_addr.s6_addr8[8],
379 laddr, 6) != 0) {
380 break;
381 }
382 /* invert u bit to convert EUI64 to RFC2373 interface ID. */
383 ia->ia_addr.sin6_addr.s6_addr8[8] ^= 0x02;
384 if (found_first_ifid == 0)
385 in6_ifattach_getifid(ifp);
386 bzero(&ia->ia_dstaddr, sizeof(struct sockaddr_in6));
387 ia->ia_dstaddr.sin6_len = sizeof(struct sockaddr_in6);
388 ia->ia_dstaddr.sin6_family = AF_INET6;
389 break;
390 case IN6_IFT_P2P:
391 bcopy((caddr_t)first_ifid,
392 (caddr_t)&ia->ia_addr.sin6_addr.s6_addr8[8],
393 IFID_LEN);
394 bzero(&ia->ia_dstaddr, sizeof(struct sockaddr_in6));
395 ia->ia_dstaddr.sin6_len = sizeof(struct sockaddr_in6);
396 ia->ia_dstaddr.sin6_family = AF_INET6;
397 break;
398 case IN6_IFT_ARCNET:
399 ia->ia_ifa.ifa_rtrequest = nd6_rtrequest;
400 ia->ia_ifa.ifa_flags |= RTF_CLONING;
401 rtflag = RTF_CLONING;
402 if (laddr == NULL)
403 break;
404
405 /* make non-global IF id out of link-level address */
406 bzero(&ia->ia_addr.sin6_addr.s6_addr8[8], 7);
407 ia->ia_addr.sin6_addr.s6_addr8[15] = *laddr;
408 }
409
410 ia->ia_ifa.ifa_metric = ifp->if_metric;
411
412 if (ifp->if_ioctl != NULL) {
413 int s;
414 int error;
415
416 /*
417 * give the interface a chance to initialize, in case this
418 * is the first address to be added.
419 */
420 s = splimp();
421 error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia);
422 splx(s);
423
424 if (error) {
425 switch (error) {
426 case EAFNOSUPPORT:
427 printf("%s: IPv6 not supported\n",
428 if_name(ifp));
429 break;
430 default:
431 printf("%s: SIOCSIFADDR error %d\n",
432 if_name(ifp), error);
433 break;
434 }
435
436 /* undo changes */
437 TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
438 if (oia)
439 oia->ia_next = ia->ia_next;
440 else
441 in6_ifaddr = ia->ia_next;
442 free(ia, M_IFADDR);
443 return;
444 }
445 }
446
447 /* add route to the interface. */
448 rtrequest(RTM_ADD,
449 (struct sockaddr *)&ia->ia_addr,
450 (struct sockaddr *)&ia->ia_addr,
451 (struct sockaddr *)&ia->ia_prefixmask,
452 RTF_UP|rtflag,
453 (struct rtentry **)0);
454 ia->ia_flags |= IFA_ROUTE;
455
456 if (type == IN6_IFT_P2P || type == IN6_IFT_P2P802) {
457 /*
458 * route local address to loopback
459 */
460 bzero(&gate, sizeof(gate));
461 gate.sin6_len = sizeof(struct sockaddr_in6);
462 gate.sin6_family = AF_INET6;
463 gate.sin6_addr = in6addr_loopback;
464 bzero(&mask, sizeof(mask));
465 mask.sin6_len = sizeof(struct sockaddr_in6);
466 mask.sin6_family = AF_INET6;
467 mask.sin6_addr = in6mask64;
468 rtrequest(RTM_ADD,
469 (struct sockaddr *)&ia->ia_addr,
470 (struct sockaddr *)&gate,
471 (struct sockaddr *)&mask,
472 RTF_UP|RTF_HOST,
473 (struct rtentry **)0);
474 }
475
476 /*
477 * loopback address
478 */
479 ib = (struct in6_ifaddr *)NULL;
480 if (type == IN6_IFT_LOOP) {
481 ib = (struct in6_ifaddr *)
482 malloc(sizeof(*ib), M_IFADDR, M_WAITOK);
483 bzero((caddr_t)ib, sizeof(*ib));
484 ib->ia_ifa.ifa_addr = (struct sockaddr *)&ib->ia_addr;
485 ib->ia_ifa.ifa_dstaddr = (struct sockaddr *)&ib->ia_dstaddr;
486 ib->ia_ifa.ifa_netmask = (struct sockaddr *)&ib->ia_prefixmask;
487 ib->ia_ifp = ifp;
488
489 ia->ia_next = ib;
490 TAILQ_INSERT_TAIL(&ifp->if_addrlist, (struct ifaddr *)ib,
491 ifa_list);
492
493 ib->ia_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
494 ib->ia_prefixmask.sin6_family = AF_INET6;
495 ib->ia_prefixmask.sin6_addr = in6mask128;
496 ib->ia_addr.sin6_len = sizeof(struct sockaddr_in6);
497 ib->ia_addr.sin6_family = AF_INET6;
498 ib->ia_addr.sin6_addr = in6addr_loopback;
499
500 ib->ia_ifa.ifa_metric = ifp->if_metric;
501
502 rtrequest(RTM_ADD,
503 (struct sockaddr *)&ib->ia_addr,
504 (struct sockaddr *)&ib->ia_addr,
505 (struct sockaddr *)&ib->ia_prefixmask,
506 RTF_UP|RTF_HOST,
507 (struct rtentry **)0);
508
509 ib->ia_flags |= IFA_ROUTE;
510 }
511
512 /*
513 * join multicast
514 */
515 if (ifp->if_flags & IFF_MULTICAST) {
516 int error; /* not used */
517
518 /* Restore saved multicast addresses(if any). */
519 in6_restoremkludge(ia, ifp);
520
521 bzero(&mltmask, sizeof(mltmask));
522 mltmask.sin6_len = sizeof(struct sockaddr_in6);
523 mltmask.sin6_family = AF_INET6;
524 mltmask.sin6_addr = in6mask32;
525
526 /*
527 * join link-local all-nodes address
528 */
529 bzero(&mltaddr, sizeof(mltaddr));
530 mltaddr.sin6_len = sizeof(struct sockaddr_in6);
531 mltaddr.sin6_family = AF_INET6;
532 mltaddr.sin6_addr = in6addr_linklocal_allnodes;
533 mltaddr.sin6_addr.s6_addr16[1] = htons(ifp->if_index);
534 rtrequest(RTM_ADD,
535 (struct sockaddr *)&mltaddr,
536 (struct sockaddr *)&ia->ia_addr,
537 (struct sockaddr *)&mltmask,
538 RTF_UP|RTF_CLONING, /* xxx */
539 (struct rtentry **)0);
540 (void)in6_addmulti(&mltaddr.sin6_addr, ifp, &error);
541
542 if (type == IN6_IFT_LOOP) {
543 /*
544 * join node-local all-nodes address
545 */
546 mltaddr.sin6_addr = in6addr_nodelocal_allnodes;
547 rtrequest(RTM_ADD,
548 (struct sockaddr *)&mltaddr,
549 (struct sockaddr *)&ib->ia_addr,
550 (struct sockaddr *)&mltmask,
551 RTF_UP,
552 (struct rtentry **)0);
553 (void)in6_addmulti(&mltaddr.sin6_addr, ifp, &error);
554 } else {
555 /*
556 * join solicited multicast address
557 */
558 bzero(&llsol, sizeof(llsol));
559 llsol.s6_addr16[0] = htons(0xff02);
560 llsol.s6_addr16[1] = htons(ifp->if_index);
561 llsol.s6_addr32[1] = 0;
562 llsol.s6_addr32[2] = htonl(1);
563 llsol.s6_addr32[3] = ia->ia_addr.sin6_addr.s6_addr32[3];
564 llsol.s6_addr8[12] = 0xff;
565 (void)in6_addmulti(&llsol, ifp, &error);
566 }
567 }
568
569 /* update dynamically. */
570 if (in6_maxmtu < ifp->if_mtu)
571 in6_maxmtu = ifp->if_mtu;
572
573 if (in6_ifstat[ifp->if_index] == NULL) {
574 in6_ifstat[ifp->if_index] = (struct in6_ifstat *)
575 malloc(sizeof(struct in6_ifstat), M_IFADDR, M_WAITOK);
576 bzero(in6_ifstat[ifp->if_index], sizeof(struct in6_ifstat));
577 }
578 if (icmp6_ifstat[ifp->if_index] == NULL) {
579 icmp6_ifstat[ifp->if_index] = (struct icmp6_ifstat *)
580 malloc(sizeof(struct icmp6_ifstat), M_IFADDR, M_WAITOK);
581 bzero(icmp6_ifstat[ifp->if_index], sizeof(struct icmp6_ifstat));
582 }
583
584 /* initialize NDP variables */
585 nd6_ifattach(ifp);
586
587 /* mark the address TENTATIVE, if needed. */
588 switch (ifp->if_type) {
589 case IFT_ARCNET:
590 case IFT_ETHER:
591 case IFT_FDDI:
592 #if 0
593 case IFT_ATM:
594 case IFT_SLIP:
595 case IFT_PPP:
596 #endif
597 ia->ia6_flags |= IN6_IFF_TENTATIVE;
598 /* nd6_dad_start() will be called in in6_if_up */
599 break;
600 case IFT_GIF: /*XXX*/
601 case IFT_LOOP:
602 case IFT_FAITH:
603 default:
604 break;
605 }
606
607 return;
608 }
609
610 void
611 in6_ifdetach(ifp)
612 struct ifnet *ifp;
613 {
614 struct in6_ifaddr *ia, *oia;
615 struct ifaddr *ifa;
616 struct rtentry *rt;
617 short rtflags;
618
619 for (ifa = ifp->if_addrlist.tqh_first; ifa; ifa = ifa->ifa_list.tqe_next)
620 {
621 if (ifa->ifa_addr->sa_family != AF_INET6
622 || !IN6_IS_ADDR_LINKLOCAL(&satosin6(&ifa->ifa_addr)->sin6_addr)) {
623 continue;
624 }
625
626 ia = (struct in6_ifaddr *)ifa;
627
628 /* remove from the routing table */
629 if ((ia->ia_flags & IFA_ROUTE)
630 && (rt = rtalloc1((struct sockaddr *)&ia->ia_addr, 0))) {
631 rtflags = rt->rt_flags;
632 rtfree(rt);
633 rtrequest(RTM_DELETE,
634 (struct sockaddr *)&ia->ia_addr,
635 (struct sockaddr *)&ia->ia_addr,
636 (struct sockaddr *)&ia->ia_prefixmask,
637 rtflags, (struct rtentry **)0);
638 }
639
640 /* remove from the linked list */
641 TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
642
643 /* also remove from the IPv6 address chain(itojun&jinmei) */
644 oia = ia;
645 if (oia == (ia = in6_ifaddr))
646 in6_ifaddr = ia->ia_next;
647 else {
648 while (ia->ia_next && (ia->ia_next != oia))
649 ia = ia->ia_next;
650 if (ia->ia_next)
651 ia->ia_next = oia->ia_next;
652 #ifdef DEBUG
653 else
654 printf("%s: didn't unlink in6ifaddr from "
655 "list\n", if_name(ifp));
656 #endif
657 }
658
659 free(ia, M_IFADDR);
660 }
661 }
662