in6_ifattach.c revision 1.2
1/* $OpenBSD: in6_ifattach.c,v 1.2 1999/12/10 10:04:27 angelos 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/md5k.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#include <netinet/if_ether.h> 48 49#include <netinet6/ip6.h> 50#include <netinet6/ip6_var.h> 51#include <netinet6/in6_ifattach.h> 52#include <netinet6/ip6.h> 53#include <netinet6/ip6_var.h> 54#include <netinet6/nd6.h> 55 56#include <net/net_osdep.h> 57 58static struct in6_addr llsol; 59 60struct in6_ifstat **in6_ifstat = NULL; 61struct icmp6_ifstat **icmp6_ifstat = NULL; 62size_t in6_ifstatmax = 0; 63size_t icmp6_ifstatmax = 0; 64unsigned long in6_maxmtu = 0; 65 66int found_first_ifid = 0; 67#define IFID_LEN 8 68static char first_ifid[IFID_LEN]; 69 70static int laddr_to_eui64 __P((u_int8_t *, u_int8_t *, size_t)); 71static int gen_rand_eui64 __P((u_int8_t *)); 72 73static int 74laddr_to_eui64(dst, src, len) 75 u_int8_t *dst; 76 u_int8_t *src; 77 size_t len; 78{ 79 static u_int8_t zero[8]; 80 81 bzero(zero, sizeof(zero)); 82 83 switch (len) { 84 case 6: 85 if (bcmp(zero, src, 6) == 0) 86 return EINVAL; 87 dst[0] = src[0]; 88 dst[1] = src[1]; 89 dst[2] = src[2]; 90 dst[3] = 0xff; 91 dst[4] = 0xfe; 92 dst[5] = src[3]; 93 dst[6] = src[4]; 94 dst[7] = src[5]; 95 break; 96 case 8: 97 if (bcmp(zero, src, 8) == 0) 98 return EINVAL; 99 bcopy(src, dst, len); 100 break; 101 default: 102 return EINVAL; 103 } 104 105 return 0; 106} 107 108/* 109 * Generate a last-resort interface identifier, when the machine has no 110 * IEEE802/EUI64 address sources. 111 * The address should be random, and should not change across reboot. 112 */ 113static int 114gen_rand_eui64(dst) 115 u_int8_t *dst; 116{ 117 MD5_CTX ctxt; 118 u_int8_t digest[16]; 119 120 /* generate 8bytes of pseudo-random value. */ 121 bzero(&ctxt, sizeof(ctxt)); 122 MD5Init(&ctxt); 123 MD5Update(&ctxt, hostname, hostnamelen); 124 MD5Final(digest, &ctxt); 125 126 /* assumes sizeof(digest) > sizeof(first_ifid) */ 127 bcopy(digest, dst, 8); 128 129 /* make sure to set "u" bit to local, and "g" bit to individual. */ 130 dst[0] &= 0xfe; 131 dst[0] |= 0x02; /* EUI64 "local" */ 132 133 return 0; 134} 135 136/* 137 * Find first ifid on list of interfaces. 138 * This is assumed that ifp0's interface token (for example, IEEE802 MAC) 139 * is globally unique. We may need to have a flag parameter in the future. 140 */ 141int 142in6_ifattach_getifid(ifp0) 143 struct ifnet *ifp0; 144{ 145 struct ifnet *ifp; 146 struct ifaddr *ifa; 147 u_int8_t *addr = NULL; 148 int addrlen = 0; 149 struct sockaddr_dl *sdl; 150 151 if (found_first_ifid) 152 return 0; 153 154 for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_list.tqe_next) 155 { 156 if (ifp0 != NULL && ifp0 != ifp) 157 continue; 158 for (ifa = ifp->if_addrlist.tqh_first; 159 ifa; 160 ifa = ifa->ifa_list.tqe_next) 161 { 162 if (ifa->ifa_addr->sa_family != AF_LINK) 163 continue; 164 sdl = (struct sockaddr_dl *)ifa->ifa_addr; 165 if (sdl == NULL) 166 continue; 167 if (sdl->sdl_alen == 0) 168 continue; 169 switch (ifp->if_type) { 170 case IFT_ETHER: 171 case IFT_FDDI: 172 case IFT_ATM: 173 /* IEEE802/EUI64 cases - what others? */ 174 addr = LLADDR(sdl); 175 addrlen = sdl->sdl_alen; 176 /* 177 * to copy ifid from IEEE802/EUI64 interface, 178 * u bit of the source needs to be 0. 179 */ 180 if ((addr[0] & 0x02) != 0) 181 break; 182 goto found; 183 case IFT_ARCNET: 184 /* 185 * ARCnet interface token cannot be used as 186 * globally unique identifier due to its 187 * small bitwidth. 188 */ 189 break; 190 default: 191 break; 192 } 193 } 194 } 195#ifdef DEBUG 196 printf("in6_ifattach_getifid: failed to get EUI64"); 197#endif 198 return EADDRNOTAVAIL; 199 200found: 201 if (laddr_to_eui64(first_ifid, addr, addrlen) == 0) 202 found_first_ifid = 1; 203 204 if (found_first_ifid) { 205 printf("%s: supplying EUI64: " 206 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", 207 if_name(ifp), 208 first_ifid[0] & 0xff, first_ifid[1] & 0xff, 209 first_ifid[2] & 0xff, first_ifid[3] & 0xff, 210 first_ifid[4] & 0xff, first_ifid[5] & 0xff, 211 first_ifid[6] & 0xff, first_ifid[7] & 0xff); 212 213 /* invert u bit to convert EUI64 to RFC2373 interface ID. */ 214 first_ifid[0] ^= 0x02; 215 216 return 0; 217 } else { 218#ifdef DEBUG 219 printf("in6_ifattach_getifid: failed to get EUI64"); 220#endif 221 return EADDRNOTAVAIL; 222 } 223} 224 225void 226in6_ifattach(ifp, type, laddr, noloop) 227 struct ifnet *ifp; 228 u_int type; 229 caddr_t laddr; 230 /* size_t laddrlen; */ 231 int noloop; 232{ 233 static size_t if_indexlim = 8; 234 struct sockaddr_in6 mltaddr; 235 struct sockaddr_in6 mltmask; 236 struct sockaddr_in6 gate; 237 struct sockaddr_in6 mask; 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] & 0xff, first_ifid[1] & 0xff, 254 first_ifid[2] & 0xff, first_ifid[3] & 0xff, 255 first_ifid[4] & 0xff, first_ifid[5] & 0xff, 256 first_ifid[6] & 0xff, first_ifid[7] & 0xff); 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 342 TAILQ_INSERT_TAIL(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list); 343 344 /* 345 * Also link into the IPv6 address chain beginning with in6_ifaddr. 346 * kazu opposed it, but itojun & jinmei wanted. 347 */ 348 if ((oia = in6_ifaddr) != NULL) { 349 for (; oia->ia_next; oia = oia->ia_next) 350 continue; 351 oia->ia_next = ia; 352 } else 353 in6_ifaddr = ia; 354 355 ia->ia_prefixmask.sin6_len = sizeof(struct sockaddr_in6); 356 ia->ia_prefixmask.sin6_family = AF_INET6; 357 ia->ia_prefixmask.sin6_addr = in6mask64; 358 359 bzero(&ia->ia_addr, sizeof(struct sockaddr_in6)); 360 ia->ia_addr.sin6_len = sizeof(struct sockaddr_in6); 361 ia->ia_addr.sin6_family = AF_INET6; 362 ia->ia_addr.sin6_addr.s6_addr16[0] = htons(0xfe80); 363 ia->ia_addr.sin6_addr.s6_addr16[1] = htons(ifp->if_index); 364 ia->ia_addr.sin6_addr.s6_addr32[1] = 0; 365 366 switch (type) { 367 case IN6_IFT_LOOP: 368 ia->ia_addr.sin6_addr.s6_addr32[2] = 0; 369 ia->ia_addr.sin6_addr.s6_addr32[3] = htonl(1); 370 break; 371 case IN6_IFT_802: 372 ia->ia_ifa.ifa_rtrequest = nd6_rtrequest; 373 ia->ia_ifa.ifa_flags |= RTF_CLONING; 374 rtflag = RTF_CLONING; 375 /* fall through */ 376 case IN6_IFT_P2P802: 377 if (laddr == NULL) 378 break; 379 /* XXX use laddrlen */ 380 if (laddr_to_eui64(&ia->ia_addr.sin6_addr.s6_addr8[8], 381 laddr, 6) != 0) { 382 break; 383 } 384 /* invert u bit to convert EUI64 to RFC2373 interface ID. */ 385 ia->ia_addr.sin6_addr.s6_addr8[8] ^= 0x02; 386 if (found_first_ifid == 0) 387 in6_ifattach_getifid(ifp); 388 bzero(&ia->ia_dstaddr, sizeof(struct sockaddr_in6)); 389 ia->ia_dstaddr.sin6_len = sizeof(struct sockaddr_in6); 390 ia->ia_dstaddr.sin6_family = AF_INET6; 391 break; 392 case IN6_IFT_P2P: 393 bcopy((caddr_t)first_ifid, 394 (caddr_t)&ia->ia_addr.sin6_addr.s6_addr8[8], 395 IFID_LEN); 396 bzero(&ia->ia_dstaddr, sizeof(struct sockaddr_in6)); 397 ia->ia_dstaddr.sin6_len = sizeof(struct sockaddr_in6); 398 ia->ia_dstaddr.sin6_family = AF_INET6; 399 break; 400 case IN6_IFT_ARCNET: 401 ia->ia_ifa.ifa_rtrequest = nd6_rtrequest; 402 ia->ia_ifa.ifa_flags |= RTF_CLONING; 403 rtflag = RTF_CLONING; 404 if (laddr == NULL) 405 break; 406 407 /* make non-global IF id out of link-level address */ 408 bzero(&ia->ia_addr.sin6_addr.s6_addr8[8], 7); 409 ia->ia_addr.sin6_addr.s6_addr8[15] = *laddr; 410 } 411 412 ia->ia_ifa.ifa_metric = ifp->if_metric; 413 414 if (ifp->if_ioctl != NULL) { 415 int s; 416 int error; 417 418 /* 419 * give the interface a chance to initialize, in case this 420 * is the first address to be added. 421 */ 422 s = splimp(); 423 error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia); 424 splx(s); 425 426 if (error) { 427 switch (error) { 428 case EAFNOSUPPORT: 429 printf("%s: IPv6 not supported\n", 430 if_name(ifp)); 431 break; 432 default: 433 printf("%s: SIOCSIFADDR error %d\n", 434 if_name(ifp), error); 435 break; 436 } 437 438 /* undo changes */ 439 TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list); 440 if (oia) 441 oia->ia_next = ia->ia_next; 442 else 443 in6_ifaddr = ia->ia_next; 444 free(ia, M_IFADDR); 445 return; 446 } 447 } 448 449 /* add route to the interface. */ 450 rtrequest(RTM_ADD, 451 (struct sockaddr *)&ia->ia_addr, 452 (struct sockaddr *)&ia->ia_addr, 453 (struct sockaddr *)&ia->ia_prefixmask, 454 RTF_UP|rtflag, 455 (struct rtentry **)0); 456 ia->ia_flags |= IFA_ROUTE; 457 458 if (type == IN6_IFT_P2P || type == IN6_IFT_P2P802) { 459 /* 460 * route local address to loopback 461 */ 462 bzero(&gate, sizeof(gate)); 463 gate.sin6_len = sizeof(struct sockaddr_in6); 464 gate.sin6_family = AF_INET6; 465 gate.sin6_addr = in6addr_loopback; 466 bzero(&mask, sizeof(mask)); 467 mask.sin6_len = sizeof(struct sockaddr_in6); 468 mask.sin6_family = AF_INET6; 469 mask.sin6_addr = in6mask64; 470 rtrequest(RTM_ADD, 471 (struct sockaddr *)&ia->ia_addr, 472 (struct sockaddr *)&gate, 473 (struct sockaddr *)&mask, 474 RTF_UP|RTF_HOST, 475 (struct rtentry **)0); 476 } 477 478 /* 479 * loopback address 480 */ 481 ib = (struct in6_ifaddr *)NULL; 482 if (type == IN6_IFT_LOOP) { 483 ib = (struct in6_ifaddr *) 484 malloc(sizeof(*ib), M_IFADDR, M_WAITOK); 485 bzero((caddr_t)ib, sizeof(*ib)); 486 ib->ia_ifa.ifa_addr = (struct sockaddr *)&ib->ia_addr; 487 ib->ia_ifa.ifa_dstaddr = (struct sockaddr *)&ib->ia_dstaddr; 488 ib->ia_ifa.ifa_netmask = (struct sockaddr *)&ib->ia_prefixmask; 489 ib->ia_ifp = ifp; 490 491 ia->ia_next = ib; 492 TAILQ_INSERT_TAIL(&ifp->if_addrlist, (struct ifaddr *)ib, 493 ifa_list); 494 495 ib->ia_prefixmask.sin6_len = sizeof(struct sockaddr_in6); 496 ib->ia_prefixmask.sin6_family = AF_INET6; 497 ib->ia_prefixmask.sin6_addr = in6mask128; 498 ib->ia_addr.sin6_len = sizeof(struct sockaddr_in6); 499 ib->ia_addr.sin6_family = AF_INET6; 500 ib->ia_addr.sin6_addr = in6addr_loopback; 501 ib->ia_ifa.ifa_metric = ifp->if_metric; 502 503 rtrequest(RTM_ADD, 504 (struct sockaddr *)&ib->ia_addr, 505 (struct sockaddr *)&ib->ia_addr, 506 (struct sockaddr *)&ib->ia_prefixmask, 507 RTF_UP|RTF_HOST, 508 (struct rtentry **)0); 509 510 ib->ia_flags |= IFA_ROUTE; 511 } 512 513 /* 514 * join multicast 515 */ 516 if (ifp->if_flags & IFF_MULTICAST) { 517 int error; /* not used */ 518 519 /* Restore saved multicast addresses(if any). */ 520 in6_restoremkludge(ia, ifp); 521 522 bzero(&mltmask, sizeof(mltmask)); 523 mltmask.sin6_len = sizeof(struct sockaddr_in6); 524 mltmask.sin6_family = AF_INET6; 525 mltmask.sin6_addr = in6mask32; 526 527 /* 528 * join link-local all-nodes address 529 */ 530 bzero(&mltaddr, sizeof(mltaddr)); 531 mltaddr.sin6_len = sizeof(struct sockaddr_in6); 532 mltaddr.sin6_family = AF_INET6; 533 mltaddr.sin6_addr = in6addr_linklocal_allnodes; 534 mltaddr.sin6_addr.s6_addr16[1] = htons(ifp->if_index); 535 rtrequest(RTM_ADD, 536 (struct sockaddr *)&mltaddr, 537 (struct sockaddr *)&ia->ia_addr, 538 (struct sockaddr *)&mltmask, 539 RTF_UP|RTF_CLONING, /* xxx */ 540 (struct rtentry **)0); 541 (void)in6_addmulti(&mltaddr.sin6_addr, ifp, &error); 542 543 if (type == IN6_IFT_LOOP) { 544 /* 545 * join node-local all-nodes address 546 */ 547 mltaddr.sin6_addr = in6addr_nodelocal_allnodes; 548 rtrequest(RTM_ADD, 549 (struct sockaddr *)&mltaddr, 550 (struct sockaddr *)&ib->ia_addr, 551 (struct sockaddr *)&mltmask, 552 RTF_UP, 553 (struct rtentry **)0); 554 (void)in6_addmulti(&mltaddr.sin6_addr, ifp, &error); 555 } else { 556 /* 557 * join solicited multicast address 558 */ 559 bzero(&llsol, sizeof(llsol)); 560 llsol.s6_addr16[0] = htons(0xff02); 561 llsol.s6_addr16[1] = htons(ifp->if_index); 562 llsol.s6_addr32[1] = 0; 563 llsol.s6_addr32[2] = htonl(1); 564 llsol.s6_addr32[3] = ia->ia_addr.sin6_addr.s6_addr32[3]; 565 llsol.s6_addr8[12] = 0xff; 566 (void)in6_addmulti(&llsol, ifp, &error); 567 } 568 } 569 570 /* update dynamically. */ 571 if (in6_maxmtu < ifp->if_mtu) 572 in6_maxmtu = ifp->if_mtu; 573 574 if (in6_ifstat[ifp->if_index] == NULL) { 575 in6_ifstat[ifp->if_index] = (struct in6_ifstat *) 576 malloc(sizeof(struct in6_ifstat), M_IFADDR, M_WAITOK); 577 bzero(in6_ifstat[ifp->if_index], sizeof(struct in6_ifstat)); 578 } 579 if (icmp6_ifstat[ifp->if_index] == NULL) { 580 icmp6_ifstat[ifp->if_index] = (struct icmp6_ifstat *) 581 malloc(sizeof(struct icmp6_ifstat), M_IFADDR, M_WAITOK); 582 bzero(icmp6_ifstat[ifp->if_index], sizeof(struct icmp6_ifstat)); 583 } 584 585 /* initialize NDP variables */ 586 nd6_ifattach(ifp); 587 588 /* mark the address TENTATIVE, if needed. */ 589 switch (ifp->if_type) { 590 case IFT_ARCNET: 591 case IFT_ETHER: 592 case IFT_FDDI: 593#if 0 594 case IFT_ATM: 595 case IFT_SLIP: 596 case IFT_PPP: 597#endif 598 ia->ia6_flags |= IN6_IFF_TENTATIVE; 599 /* nd6_dad_start() will be called in in6_if_up */ 600 break; 601 case IFT_DUMMY: 602 case IFT_GIF: /*XXX*/ 603 case IFT_LOOP: 604 case IFT_FAITH: 605 default: 606 break; 607 } 608 609 return; 610} 611 612void 613in6_ifdetach(ifp) 614 struct ifnet *ifp; 615{ 616 struct in6_ifaddr *ia, *oia; 617 struct ifaddr *ifa; 618 struct rtentry *rt; 619 short rtflags; 620 621 for (ifa = ifp->if_addrlist.tqh_first; ifa; ifa = ifa->ifa_list.tqe_next) 622 { 623 if (ifa->ifa_addr->sa_family != AF_INET6 624 || !IN6_IS_ADDR_LINKLOCAL(&satosin6(&ifa->ifa_addr)->sin6_addr)) { 625 continue; 626 } 627 628 ia = (struct in6_ifaddr *)ifa; 629 630 /* remove from the routing table */ 631 if ((ia->ia_flags & IFA_ROUTE) 632 && (rt = rtalloc1((struct sockaddr *)&ia->ia_addr, 0))) { 633 rtflags = rt->rt_flags; 634 rtfree(rt); 635 rtrequest(RTM_DELETE, 636 (struct sockaddr *)&ia->ia_addr, 637 (struct sockaddr *)&ia->ia_addr, 638 (struct sockaddr *)&ia->ia_prefixmask, 639 rtflags, (struct rtentry **)0); 640 } 641 642 /* remove from the linked list */ 643 TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list); 644 645 /* also remove from the IPv6 address chain(itojun&jinmei) */ 646 oia = ia; 647 if (oia == (ia = in6_ifaddr)) 648 in6_ifaddr = ia->ia_next; 649 else { 650 while (ia->ia_next && (ia->ia_next != oia)) 651 ia = ia->ia_next; 652 if (ia->ia_next) 653 ia->ia_next = oia->ia_next; 654#ifdef DEBUG 655 else 656 printf("%s: didn't unlink in6ifaddr from " 657 "list\n", if_name(ifp)); 658#endif 659 } 660 661 free(ia, M_IFADDR); 662 } 663} 664