1 /* $OpenBSD: nd6.c,v 1.39 2001/12/07 09:16:07 itojun Exp $ */ 2 /* $KAME: nd6.c,v 1.151 2001/06/19 14:24:41 sumikawa Exp $ */ 3 4 /* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 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 18 * without specific prior written permission. 19 * 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 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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 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 30 * SUCH DAMAGE. 31 */ 32 33 /* 34 * XXX 35 * KAME 970409 note: 36 * BSD/OS version heavily modifies this code, related to llinfo. 37 * Since we don't have BSD/OS version of net/route.c in our hand, 38 * I left the code mostly as it was in 970310. -- itojun 39 */ 40 41 #include <sys/param.h> 42 #include <sys/systm.h> 43 #include <sys/timeout.h> 44 #include <sys/malloc.h> 45 #include <sys/mbuf.h> 46 #include <sys/socket.h> 47 #include <sys/sockio.h> 48 #include <sys/time.h> 49 #include <sys/kernel.h> 50 #include <sys/protosw.h> 51 #include <sys/errno.h> 52 #include <sys/ioctl.h> 53 #include <sys/syslog.h> 54 #include <sys/queue.h> 55 #include <dev/rndvar.h> 56 57 #include <net/if.h> 58 #include <net/if_dl.h> 59 #include <net/if_types.h> 60 #include <net/if_atm.h> 61 #include <net/route.h> 62 63 #include <netinet/in.h> 64 #include <netinet/if_ether.h> 65 #include <netinet/ip_ipsp.h> 66 67 #include <netinet6/in6_var.h> 68 #include <netinet/ip6.h> 69 #include <netinet6/ip6_var.h> 70 #include <netinet6/nd6.h> 71 #include <netinet6/in6_prefix.h> 72 #include <netinet/icmp6.h> 73 74 #define ND6_SLOWTIMER_INTERVAL (60 * 60) /* 1 hour */ 75 #define ND6_RECALC_REACHTM_INTERVAL (60 * 120) /* 2 hours */ 76 77 #define SIN6(s) ((struct sockaddr_in6 *)s) 78 #define SDL(s) ((struct sockaddr_dl *)s) 79 80 /* timer values */ 81 int nd6_prune = 1; /* walk list every 1 seconds */ 82 int nd6_delay = 5; /* delay first probe time 5 second */ 83 int nd6_umaxtries = 3; /* maximum unicast query */ 84 int nd6_mmaxtries = 3; /* maximum multicast query */ 85 int nd6_useloopback = 1; /* use loopback interface for local traffic */ 86 int nd6_gctimer = (60 * 60 * 24); /* 1 day: garbage collection timer */ 87 88 /* preventing too many loops in ND option parsing */ 89 int nd6_maxndopt = 10; /* max # of ND options allowed */ 90 91 int nd6_maxnudhint = 0; /* max # of subsequent upper layer hints */ 92 93 #ifdef ND6_DEBUG 94 int nd6_debug = 1; 95 #else 96 int nd6_debug = 0; 97 #endif 98 99 /* for debugging? */ 100 static int nd6_inuse, nd6_allocated; 101 102 struct llinfo_nd6 llinfo_nd6 = {&llinfo_nd6, &llinfo_nd6}; 103 static size_t nd_ifinfo_indexlim = 8; 104 struct nd_ifinfo *nd_ifinfo = NULL; 105 struct nd_drhead nd_defrouter; 106 struct nd_prhead nd_prefix = { 0 }; 107 108 int nd6_recalc_reachtm_interval = ND6_RECALC_REACHTM_INTERVAL; 109 static struct sockaddr_in6 all1_sa; 110 111 static void nd6_slowtimo __P((void *)); 112 113 struct timeout nd6_slowtimo_ch; 114 struct timeout nd6_timer_ch; 115 extern struct timeout in6_tmpaddrtimer_ch; 116 117 void 118 nd6_init() 119 { 120 static int nd6_init_done = 0; 121 int i; 122 123 if (nd6_init_done) { 124 log(LOG_NOTICE, "nd6_init called more than once(ignored)\n"); 125 return; 126 } 127 128 all1_sa.sin6_family = AF_INET6; 129 all1_sa.sin6_len = sizeof(struct sockaddr_in6); 130 for (i = 0; i < sizeof(all1_sa.sin6_addr); i++) 131 all1_sa.sin6_addr.s6_addr[i] = 0xff; 132 133 /* initialization of the default router list */ 134 TAILQ_INIT(&nd_defrouter); 135 136 nd6_init_done = 1; 137 138 /* start timer */ 139 timeout_set(&nd6_slowtimo_ch, nd6_slowtimo, NULL); 140 timeout_add(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz); 141 } 142 143 void 144 nd6_ifattach(ifp) 145 struct ifnet *ifp; 146 { 147 148 /* 149 * We have some arrays that should be indexed by if_index. 150 * since if_index will grow dynamically, they should grow too. 151 */ 152 if (nd_ifinfo == NULL || if_index >= nd_ifinfo_indexlim) { 153 size_t n; 154 caddr_t q; 155 156 while (if_index >= nd_ifinfo_indexlim) 157 nd_ifinfo_indexlim <<= 1; 158 159 /* grow nd_ifinfo */ 160 n = nd_ifinfo_indexlim * sizeof(struct nd_ifinfo); 161 q = (caddr_t)malloc(n, M_IP6NDP, M_WAITOK); 162 bzero(q, n); 163 if (nd_ifinfo) { 164 bcopy((caddr_t)nd_ifinfo, q, n/2); 165 free((caddr_t)nd_ifinfo, M_IP6NDP); 166 } 167 nd_ifinfo = (struct nd_ifinfo *)q; 168 } 169 170 #define ND nd_ifinfo[ifp->if_index] 171 172 /* 173 * Don't initialize if called twice. 174 * XXX: to detect this, we should choose a member that is never set 175 * before initialization of the ND structure itself. We formaly used 176 * the linkmtu member, which was not suitable because it could be 177 * initialized via "ifconfig mtu". 178 */ 179 if (ND.basereachable) 180 return; 181 182 ND.linkmtu = ifindex2ifnet[ifp->if_index]->if_mtu; 183 ND.chlim = IPV6_DEFHLIM; 184 ND.basereachable = REACHABLE_TIME; 185 ND.reachable = ND_COMPUTE_RTIME(ND.basereachable); 186 ND.retrans = RETRANS_TIMER; 187 ND.receivedra = 0; 188 ND.flags = ND6_IFF_PERFORMNUD; 189 nd6_setmtu(ifp); 190 #undef ND 191 } 192 193 /* 194 * Reset ND level link MTU. This function is called when the physical MTU 195 * changes, which means we might have to adjust the ND level MTU. 196 */ 197 void 198 nd6_setmtu(ifp) 199 struct ifnet *ifp; 200 { 201 struct nd_ifinfo *ndi = &nd_ifinfo[ifp->if_index]; 202 u_long oldmaxmtu = ndi->maxmtu; 203 u_long oldlinkmtu = ndi->linkmtu; 204 205 switch (ifp->if_type) { 206 case IFT_ARCNET: /* XXX MTU handling needs more work */ 207 ndi->maxmtu = MIN(60480, ifp->if_mtu); 208 break; 209 case IFT_ETHER: 210 ndi->maxmtu = MIN(ETHERMTU, ifp->if_mtu); 211 break; 212 case IFT_ATM: 213 ndi->maxmtu = MIN(ATMMTU, ifp->if_mtu); 214 break; 215 default: 216 ndi->maxmtu = ifp->if_mtu; 217 break; 218 } 219 220 if (oldmaxmtu != ndi->maxmtu) { 221 /* 222 * If the ND level MTU is not set yet, or if the maxmtu 223 * is reset to a smaller value than the ND level MTU, 224 * also reset the ND level MTU. 225 */ 226 if (ndi->linkmtu == 0 || 227 ndi->maxmtu < ndi->linkmtu) { 228 ndi->linkmtu = ndi->maxmtu; 229 /* also adjust in6_maxmtu if necessary. */ 230 if (oldlinkmtu == 0) { 231 /* 232 * XXX: the case analysis is grotty, but 233 * it is not efficient to call in6_setmaxmtu() 234 * here when we are during the initialization 235 * procedure. 236 */ 237 if (in6_maxmtu < ndi->linkmtu) 238 in6_maxmtu = ndi->linkmtu; 239 } else 240 in6_setmaxmtu(); 241 } 242 } 243 #undef MIN 244 } 245 246 void 247 nd6_option_init(opt, icmp6len, ndopts) 248 void *opt; 249 int icmp6len; 250 union nd_opts *ndopts; 251 { 252 bzero(ndopts, sizeof(*ndopts)); 253 ndopts->nd_opts_search = (struct nd_opt_hdr *)opt; 254 ndopts->nd_opts_last 255 = (struct nd_opt_hdr *)(((u_char *)opt) + icmp6len); 256 257 if (icmp6len == 0) { 258 ndopts->nd_opts_done = 1; 259 ndopts->nd_opts_search = NULL; 260 } 261 } 262 263 /* 264 * Take one ND option. 265 */ 266 struct nd_opt_hdr * 267 nd6_option(ndopts) 268 union nd_opts *ndopts; 269 { 270 struct nd_opt_hdr *nd_opt; 271 int olen; 272 273 if (!ndopts) 274 panic("ndopts == NULL in nd6_option\n"); 275 if (!ndopts->nd_opts_last) 276 panic("uninitialized ndopts in nd6_option\n"); 277 if (!ndopts->nd_opts_search) 278 return NULL; 279 if (ndopts->nd_opts_done) 280 return NULL; 281 282 nd_opt = ndopts->nd_opts_search; 283 284 /* make sure nd_opt_len is inside the buffer */ 285 if ((caddr_t)&nd_opt->nd_opt_len >= (caddr_t)ndopts->nd_opts_last) { 286 bzero(ndopts, sizeof(*ndopts)); 287 return NULL; 288 } 289 290 olen = nd_opt->nd_opt_len << 3; 291 if (olen == 0) { 292 /* 293 * Message validation requires that all included 294 * options have a length that is greater than zero. 295 */ 296 bzero(ndopts, sizeof(*ndopts)); 297 return NULL; 298 } 299 300 ndopts->nd_opts_search = (struct nd_opt_hdr *)((caddr_t)nd_opt + olen); 301 if (ndopts->nd_opts_search > ndopts->nd_opts_last) { 302 /* option overruns the end of buffer, invalid */ 303 bzero(ndopts, sizeof(*ndopts)); 304 return NULL; 305 } else if (ndopts->nd_opts_search == ndopts->nd_opts_last) { 306 /* reached the end of options chain */ 307 ndopts->nd_opts_done = 1; 308 ndopts->nd_opts_search = NULL; 309 } 310 return nd_opt; 311 } 312 313 /* 314 * Parse multiple ND options. 315 * This function is much easier to use, for ND routines that do not need 316 * multiple options of the same type. 317 */ 318 int 319 nd6_options(ndopts) 320 union nd_opts *ndopts; 321 { 322 struct nd_opt_hdr *nd_opt; 323 int i = 0; 324 325 if (!ndopts) 326 panic("ndopts == NULL in nd6_options\n"); 327 if (!ndopts->nd_opts_last) 328 panic("uninitialized ndopts in nd6_options\n"); 329 if (!ndopts->nd_opts_search) 330 return 0; 331 332 while (1) { 333 nd_opt = nd6_option(ndopts); 334 if (!nd_opt && !ndopts->nd_opts_last) { 335 /* 336 * Message validation requires that all included 337 * options have a length that is greater than zero. 338 */ 339 icmp6stat.icp6s_nd_badopt++; 340 bzero(ndopts, sizeof(*ndopts)); 341 return -1; 342 } 343 344 if (!nd_opt) 345 goto skip1; 346 347 switch (nd_opt->nd_opt_type) { 348 case ND_OPT_SOURCE_LINKADDR: 349 case ND_OPT_TARGET_LINKADDR: 350 case ND_OPT_MTU: 351 case ND_OPT_REDIRECTED_HEADER: 352 if (ndopts->nd_opt_array[nd_opt->nd_opt_type]) { 353 nd6log((LOG_INFO, 354 "duplicated ND6 option found (type=%d)\n", 355 nd_opt->nd_opt_type)); 356 /* XXX bark? */ 357 } else { 358 ndopts->nd_opt_array[nd_opt->nd_opt_type] 359 = nd_opt; 360 } 361 break; 362 case ND_OPT_PREFIX_INFORMATION: 363 if (ndopts->nd_opt_array[nd_opt->nd_opt_type] == 0) { 364 ndopts->nd_opt_array[nd_opt->nd_opt_type] 365 = nd_opt; 366 } 367 ndopts->nd_opts_pi_end = 368 (struct nd_opt_prefix_info *)nd_opt; 369 break; 370 default: 371 /* 372 * Unknown options must be silently ignored, 373 * to accomodate future extension to the protocol. 374 */ 375 nd6log((LOG_DEBUG, 376 "nd6_options: unsupported option %d - " 377 "option ignored\n", nd_opt->nd_opt_type)); 378 } 379 380 skip1: 381 i++; 382 if (i > nd6_maxndopt) { 383 icmp6stat.icp6s_nd_toomanyopt++; 384 nd6log((LOG_INFO, "too many loop in nd opt\n")); 385 break; 386 } 387 388 if (ndopts->nd_opts_done) 389 break; 390 } 391 392 return 0; 393 } 394 395 /* 396 * ND6 timer routine to expire default route list and prefix list 397 */ 398 void 399 nd6_timer(ignored_arg) 400 void *ignored_arg; 401 { 402 int s; 403 struct llinfo_nd6 *ln; 404 struct nd_defrouter *dr; 405 struct nd_prefix *pr; 406 long time_second = time.tv_sec; 407 408 s = splnet(); 409 410 timeout_set(&nd6_timer_ch, nd6_timer, NULL); 411 timeout_add(&nd6_timer_ch, nd6_prune * hz); 412 413 ln = llinfo_nd6.ln_next; 414 /* XXX BSD/OS separates this code -- itojun */ 415 while (ln && ln != &llinfo_nd6) { 416 struct rtentry *rt; 417 struct ifnet *ifp; 418 struct sockaddr_in6 *dst; 419 struct llinfo_nd6 *next = ln->ln_next; 420 /* XXX: used for the DELAY case only: */ 421 struct nd_ifinfo *ndi = NULL; 422 423 if ((rt = ln->ln_rt) == NULL) { 424 ln = next; 425 continue; 426 } 427 if ((ifp = rt->rt_ifp) == NULL) { 428 ln = next; 429 continue; 430 } 431 ndi = &nd_ifinfo[ifp->if_index]; 432 dst = (struct sockaddr_in6 *)rt_key(rt); 433 434 if (ln->ln_expire > time_second) { 435 ln = next; 436 continue; 437 } 438 439 /* sanity check */ 440 if (!rt) 441 panic("rt=0 in nd6_timer(ln=%p)\n", ln); 442 if (rt->rt_llinfo && (struct llinfo_nd6 *)rt->rt_llinfo != ln) 443 panic("rt_llinfo(%p) is not equal to ln(%p)\n", 444 rt->rt_llinfo, ln); 445 if (!dst) 446 panic("dst=0 in nd6_timer(ln=%p)\n", ln); 447 448 switch (ln->ln_state) { 449 case ND6_LLINFO_INCOMPLETE: 450 if (ln->ln_asked < nd6_mmaxtries) { 451 ln->ln_asked++; 452 ln->ln_expire = time_second + 453 nd_ifinfo[ifp->if_index].retrans / 1000; 454 nd6_ns_output(ifp, NULL, &dst->sin6_addr, 455 ln, 0); 456 } else { 457 struct mbuf *m = ln->ln_hold; 458 if (m) { 459 if (rt->rt_ifp) { 460 /* 461 * Fake rcvif to make ICMP error 462 * more helpful in diagnosing 463 * for the receiver. 464 * XXX: should we consider 465 * older rcvif? 466 */ 467 m->m_pkthdr.rcvif = rt->rt_ifp; 468 } 469 icmp6_error(m, ICMP6_DST_UNREACH, 470 ICMP6_DST_UNREACH_ADDR, 0); 471 ln->ln_hold = NULL; 472 } 473 next = nd6_free(rt); 474 } 475 break; 476 case ND6_LLINFO_REACHABLE: 477 if (ln->ln_expire) { 478 ln->ln_state = ND6_LLINFO_STALE; 479 ln->ln_expire = time_second + nd6_gctimer; 480 } 481 break; 482 483 case ND6_LLINFO_STALE: 484 /* Garbage Collection(RFC 2461 5.3) */ 485 if (ln->ln_expire) 486 next = nd6_free(rt); 487 break; 488 489 case ND6_LLINFO_DELAY: 490 if (ndi && (ndi->flags & ND6_IFF_PERFORMNUD) != 0) { 491 /* We need NUD */ 492 ln->ln_asked = 1; 493 ln->ln_state = ND6_LLINFO_PROBE; 494 ln->ln_expire = time_second + 495 ndi->retrans / 1000; 496 nd6_ns_output(ifp, &dst->sin6_addr, 497 &dst->sin6_addr, 498 ln, 0); 499 } else { 500 ln->ln_state = ND6_LLINFO_STALE; /* XXX */ 501 ln->ln_expire = time_second + nd6_gctimer; 502 } 503 break; 504 case ND6_LLINFO_PROBE: 505 if (ln->ln_asked < nd6_umaxtries) { 506 ln->ln_asked++; 507 ln->ln_expire = time_second + 508 nd_ifinfo[ifp->if_index].retrans / 1000; 509 nd6_ns_output(ifp, &dst->sin6_addr, 510 &dst->sin6_addr, ln, 0); 511 } else 512 next = nd6_free(rt); 513 break; 514 } 515 ln = next; 516 } 517 518 /* expire default router list */ 519 dr = TAILQ_FIRST(&nd_defrouter); 520 while (dr) { 521 if (dr->expire && dr->expire < time_second) { 522 struct nd_defrouter *t; 523 t = TAILQ_NEXT(dr, dr_entry); 524 defrtrlist_del(dr); 525 dr = t; 526 } else 527 dr = TAILQ_NEXT(dr, dr_entry); 528 } 529 pr = nd_prefix.lh_first; 530 while (pr) { 531 struct in6_ifaddr *ia6; 532 struct in6_addrlifetime *lt6; 533 534 if (IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr)) 535 ia6 = NULL; 536 else 537 ia6 = in6ifa_ifpwithaddr(pr->ndpr_ifp, &pr->ndpr_addr); 538 539 if (ia6) { 540 /* check address lifetime */ 541 lt6 = &ia6->ia6_lifetime; 542 if (lt6->ia6t_preferred && lt6->ia6t_preferred < time_second) 543 ia6->ia6_flags |= IN6_IFF_DEPRECATED; 544 if (lt6->ia6t_expire && lt6->ia6t_expire < time_second) { 545 if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr)) 546 in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr); 547 /* xxx ND_OPT_PI_FLAG_ONLINK processing */ 548 } 549 } 550 551 /* 552 * check prefix lifetime. 553 * since pltime is just for autoconf, pltime processing for 554 * prefix is not necessary. 555 * 556 * we offset expire time by NDPR_KEEP_EXPIRE, so that we 557 * can use the old prefix information to validate the 558 * next prefix information to come. See prelist_update() 559 * for actual validation. 560 */ 561 if (pr->ndpr_expire 562 && pr->ndpr_expire + NDPR_KEEP_EXPIRED < time_second) { 563 struct nd_prefix *t; 564 t = pr->ndpr_next; 565 566 /* 567 * address expiration and prefix expiration are 568 * separate. NEVER perform in6_ifdel here. 569 */ 570 571 prelist_remove(pr); 572 pr = t; 573 } else 574 pr = pr->ndpr_next; 575 } 576 splx(s); 577 } 578 579 /* 580 * Nuke neighbor cache/prefix/default router management table, right before 581 * ifp goes away. 582 */ 583 void 584 nd6_purge(ifp) 585 struct ifnet *ifp; 586 { 587 struct llinfo_nd6 *ln, *nln; 588 struct nd_defrouter *dr, *ndr, drany; 589 struct nd_prefix *pr, *npr; 590 591 /* Nuke default router list entries toward ifp */ 592 if ((dr = TAILQ_FIRST(&nd_defrouter)) != NULL) { 593 /* 594 * The first entry of the list may be stored in 595 * the routing table, so we'll delete it later. 596 */ 597 for (dr = TAILQ_NEXT(dr, dr_entry); dr; dr = ndr) { 598 ndr = TAILQ_NEXT(dr, dr_entry); 599 if (dr->ifp == ifp) 600 defrtrlist_del(dr); 601 } 602 dr = TAILQ_FIRST(&nd_defrouter); 603 if (dr->ifp == ifp) 604 defrtrlist_del(dr); 605 } 606 607 /* Nuke prefix list entries toward ifp */ 608 for (pr = nd_prefix.lh_first; pr; pr = npr) { 609 npr = pr->ndpr_next; 610 if (pr->ndpr_ifp == ifp) { 611 if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr)) 612 in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr); 613 prelist_remove(pr); 614 } 615 } 616 617 /* cancel default outgoing interface setting */ 618 if (nd6_defifindex == ifp->if_index) 619 nd6_setdefaultiface(0); 620 621 if (!ip6_forwarding && ip6_accept_rtadv) { /* XXX: too restrictive? */ 622 /* refresh default router list */ 623 bzero(&drany, sizeof(drany)); 624 defrouter_delreq(&drany, 0); 625 defrouter_select(); 626 } 627 628 /* 629 * Nuke neighbor cache entries for the ifp. 630 * Note that rt->rt_ifp may not be the same as ifp, 631 * due to KAME goto ours hack. See RTM_RESOLVE case in 632 * nd6_rtrequest(), and ip6_input(). 633 */ 634 ln = llinfo_nd6.ln_next; 635 while (ln && ln != &llinfo_nd6) { 636 struct rtentry *rt; 637 struct sockaddr_dl *sdl; 638 639 nln = ln->ln_next; 640 rt = ln->ln_rt; 641 if (rt && rt->rt_gateway && 642 rt->rt_gateway->sa_family == AF_LINK) { 643 sdl = (struct sockaddr_dl *)rt->rt_gateway; 644 if (sdl->sdl_index == ifp->if_index) 645 nln = nd6_free(rt); 646 } 647 ln = nln; 648 } 649 } 650 651 struct rtentry * 652 nd6_lookup(addr6, create, ifp) 653 struct in6_addr *addr6; 654 int create; 655 struct ifnet *ifp; 656 { 657 struct rtentry *rt; 658 struct sockaddr_in6 sin6; 659 660 bzero(&sin6, sizeof(sin6)); 661 sin6.sin6_len = sizeof(struct sockaddr_in6); 662 sin6.sin6_family = AF_INET6; 663 sin6.sin6_addr = *addr6; 664 rt = rtalloc1((struct sockaddr *)&sin6, create); 665 if (rt && (rt->rt_flags & RTF_LLINFO) == 0) { 666 /* 667 * This is the case for the default route. 668 * If we want to create a neighbor cache for the address, we 669 * should free the route for the destination and allocate an 670 * interface route. 671 */ 672 if (create) { 673 RTFREE(rt); 674 rt = 0; 675 } 676 } 677 if (!rt) { 678 if (create && ifp) { 679 int e; 680 681 /* 682 * If no route is available and create is set, 683 * we allocate a host route for the destination 684 * and treat it like an interface route. 685 * This hack is necessary for a neighbor which can't 686 * be covered by our own prefix. 687 */ 688 struct ifaddr *ifa = 689 ifaof_ifpforaddr((struct sockaddr *)&sin6, ifp); 690 if (ifa == NULL) 691 return(NULL); 692 693 /* 694 * Create a new route. RTF_LLINFO is necessary 695 * to create a Neighbor Cache entry for the 696 * destination in nd6_rtrequest which will be 697 * called in rtrequest via ifa->ifa_rtrequest. 698 */ 699 if ((e = rtrequest(RTM_ADD, (struct sockaddr *)&sin6, 700 ifa->ifa_addr, 701 (struct sockaddr *)&all1_sa, 702 (ifa->ifa_flags | 703 RTF_HOST | RTF_LLINFO) & 704 ~RTF_CLONING, 705 &rt)) != 0) 706 log(LOG_ERR, 707 "nd6_lookup: failed to add route for a " 708 "neighbor(%s), errno=%d\n", 709 ip6_sprintf(addr6), e); 710 if (rt == NULL) 711 return(NULL); 712 if (rt->rt_llinfo) { 713 struct llinfo_nd6 *ln = 714 (struct llinfo_nd6 *)rt->rt_llinfo; 715 ln->ln_state = ND6_LLINFO_NOSTATE; 716 } 717 } else 718 return(NULL); 719 } 720 rt->rt_refcnt--; 721 /* 722 * Validation for the entry. 723 * XXX: we can't use rt->rt_ifp to check for the interface, since 724 * it might be the loopback interface if the entry is for our 725 * own address on a non-loopback interface. Instead, we should 726 * use rt->rt_ifa->ifa_ifp, which would specify the REAL interface. 727 */ 728 if ((rt->rt_flags & RTF_GATEWAY) || (rt->rt_flags & RTF_LLINFO) == 0 || 729 rt->rt_gateway->sa_family != AF_LINK || 730 (ifp && rt->rt_ifa->ifa_ifp != ifp)) { 731 if (create) { 732 log(LOG_DEBUG, "nd6_lookup: failed to lookup %s (if = %s)\n", 733 ip6_sprintf(addr6), ifp ? ifp->if_xname : "unspec"); 734 /* xxx more logs... kazu */ 735 } 736 return(0); 737 } 738 return(rt); 739 } 740 741 /* 742 * Detect if a given IPv6 address identifies a neighbor on a given link. 743 * XXX: should take care of the destination of a p2p link? 744 */ 745 int 746 nd6_is_addr_neighbor(addr, ifp) 747 struct sockaddr_in6 *addr; 748 struct ifnet *ifp; 749 { 750 struct ifaddr *ifa; 751 int i; 752 753 #define IFADDR6(a) ((((struct in6_ifaddr *)(a))->ia_addr).sin6_addr) 754 #define IFMASK6(a) ((((struct in6_ifaddr *)(a))->ia_prefixmask).sin6_addr) 755 756 /* 757 * A link-local address is always a neighbor. 758 * XXX: we should use the sin6_scope_id field rather than the embedded 759 * interface index. 760 */ 761 if (IN6_IS_ADDR_LINKLOCAL(&addr->sin6_addr) && 762 ntohs(*(u_int16_t *)&addr->sin6_addr.s6_addr[2]) == ifp->if_index) 763 return(1); 764 765 /* 766 * If the address matches one of our addresses, 767 * it should be a neighbor. 768 */ 769 for (ifa = ifp->if_addrlist.tqh_first; 770 ifa; 771 ifa = ifa->ifa_list.tqe_next) 772 { 773 if (ifa->ifa_addr->sa_family != AF_INET6) 774 next: continue; 775 776 for (i = 0; i < 4; i++) { 777 if ((IFADDR6(ifa).s6_addr32[i] ^ 778 addr->sin6_addr.s6_addr32[i]) & 779 IFMASK6(ifa).s6_addr32[i]) 780 goto next; 781 } 782 return(1); 783 } 784 785 /* 786 * Even if the address matches none of our addresses, it might be 787 * in the neighbor cache. 788 */ 789 if (nd6_lookup(&addr->sin6_addr, 0, ifp)) 790 return(1); 791 792 return(0); 793 #undef IFADDR6 794 #undef IFMASK6 795 } 796 797 /* 798 * Free an nd6 llinfo entry. 799 */ 800 struct llinfo_nd6 * 801 nd6_free(rt) 802 struct rtentry *rt; 803 { 804 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo, *next; 805 struct in6_addr in6 = ((struct sockaddr_in6 *)rt_key(rt))->sin6_addr; 806 struct nd_defrouter *dr; 807 808 /* 809 * Clear all destination cache entries for the neighbor. 810 * XXX: is it better to restrict this to hosts? 811 */ 812 pfctlinput(PRC_HOSTDEAD, rt_key(rt)); 813 814 if (!ip6_forwarding && ip6_accept_rtadv) { /* XXX: too restrictive? */ 815 int s; 816 s = splnet(); 817 dr = defrouter_lookup(&((struct sockaddr_in6 *)rt_key(rt))->sin6_addr, 818 rt->rt_ifp); 819 if (ln->ln_router || dr) { 820 /* 821 * rt6_flush must be called whether or not the neighbor 822 * is in the Default Router List. 823 * See a corresponding comment in nd6_na_input(). 824 */ 825 rt6_flush(&in6, rt->rt_ifp); 826 } 827 828 if (dr) { 829 /* 830 * Unreachablity of a router might affect the default 831 * router selection and on-link detection of advertised 832 * prefixes. 833 */ 834 835 /* 836 * Temporarily fake the state to choose a new default 837 * router and to perform on-link determination of 838 * prefixes correctly. 839 * Below the state will be set correctly, 840 * or the entry itself will be deleted. 841 */ 842 ln->ln_state = ND6_LLINFO_INCOMPLETE; 843 844 if (dr == TAILQ_FIRST(&nd_defrouter)) { 845 /* 846 * It is used as the current default router, 847 * so we have to move it to the end of the 848 * list and choose a new one. 849 * XXX: it is not very efficient if this is 850 * the only router. 851 */ 852 TAILQ_REMOVE(&nd_defrouter, dr, dr_entry); 853 TAILQ_INSERT_TAIL(&nd_defrouter, dr, dr_entry); 854 855 defrouter_select(); 856 } 857 pfxlist_onlink_check(); 858 } 859 splx(s); 860 } 861 862 /* 863 * Before deleting the entry, remember the next entry as the 864 * return value. We need this because pfxlist_onlink_check() above 865 * might have freed other entries (particularly the old next entry) as 866 * a side effect (XXX). 867 */ 868 next = ln->ln_next; 869 870 /* 871 * Detach the route from the routing tree and the list of neighbor 872 * caches, and disable the route entry not to be used in already 873 * cached routes. 874 */ 875 rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, 876 rt_mask(rt), 0, (struct rtentry **)0); 877 878 return(next); 879 } 880 881 /* 882 * Upper-layer reachability hint for Neighbor Unreachability Detection. 883 * 884 * XXX cost-effective metods? 885 */ 886 void 887 nd6_nud_hint(rt, dst6, force) 888 struct rtentry *rt; 889 struct in6_addr *dst6; 890 int force; 891 { 892 struct llinfo_nd6 *ln; 893 long time_second = time.tv_sec; 894 895 /* 896 * If the caller specified "rt", use that. Otherwise, resolve the 897 * routing table by supplied "dst6". 898 */ 899 if (!rt) { 900 if (!dst6) 901 return; 902 if (!(rt = nd6_lookup(dst6, 0, NULL))) 903 return; 904 } 905 906 if ((rt->rt_flags & RTF_GATEWAY) != 0 || 907 (rt->rt_flags & RTF_LLINFO) == 0 || 908 !rt->rt_llinfo || !rt->rt_gateway || 909 rt->rt_gateway->sa_family != AF_LINK) { 910 /* This is not a host route. */ 911 return; 912 } 913 914 ln = (struct llinfo_nd6 *)rt->rt_llinfo; 915 if (ln->ln_state < ND6_LLINFO_REACHABLE) 916 return; 917 918 /* 919 * if we get upper-layer reachability confirmation many times, 920 * it is possible we have false information. 921 */ 922 if (!force) { 923 ln->ln_byhint++; 924 if (ln->ln_byhint > nd6_maxnudhint) 925 return; 926 } 927 928 ln->ln_state = ND6_LLINFO_REACHABLE; 929 if (ln->ln_expire) 930 ln->ln_expire = time_second + 931 nd_ifinfo[rt->rt_ifp->if_index].reachable; 932 } 933 934 void 935 nd6_rtrequest(req, rt, info) 936 int req; 937 struct rtentry *rt; 938 struct rt_addrinfo *info; /* xxx unused */ 939 { 940 struct sockaddr *gate = rt->rt_gateway; 941 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo; 942 static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK}; 943 struct ifnet *ifp = rt->rt_ifp; 944 struct ifaddr *ifa; 945 long time_second = time.tv_sec; 946 947 if (rt->rt_flags & RTF_GATEWAY) 948 return; 949 950 switch (req) { 951 case RTM_ADD: 952 /* 953 * There is no backward compatibility :) 954 * 955 * if ((rt->rt_flags & RTF_HOST) == 0 && 956 * SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff) 957 * rt->rt_flags |= RTF_CLONING; 958 */ 959 if (rt->rt_flags & (RTF_CLONING | RTF_LLINFO)) { 960 /* 961 * Case 1: This route should come from 962 * a route to interface. RTF_LLINFO flag is set 963 * for a host route whose destination should be 964 * treated as on-link. 965 */ 966 rt_setgate(rt, rt_key(rt), 967 (struct sockaddr *)&null_sdl); 968 gate = rt->rt_gateway; 969 SDL(gate)->sdl_type = ifp->if_type; 970 SDL(gate)->sdl_index = ifp->if_index; 971 if (ln) 972 ln->ln_expire = time_second; 973 #if 1 974 if (ln && ln->ln_expire == 0) { 975 /* kludge for desktops */ 976 #if 0 977 printf("nd6_request: time.tv_sec is zero; " 978 "treat it as 1\n"); 979 #endif 980 ln->ln_expire = 1; 981 } 982 #endif 983 if (rt->rt_flags & RTF_CLONING) 984 break; 985 } 986 /* 987 * In IPv4 code, we try to annonuce new RTF_ANNOUNCE entry here. 988 * We don't do that here since llinfo is not ready yet. 989 * 990 * There are also couple of other things to be discussed: 991 * - unsolicited NA code needs improvement beforehand 992 * - RFC2461 says we MAY send multicast unsolicited NA 993 * (7.2.6 paragraph 4), however, it also says that we 994 * SHOULD provide a mechanism to prevent multicast NA storm. 995 * we don't have anything like it right now. 996 * note that the mechanism needs a mutual agreement 997 * between proxies, which means that we need to implement 998 * a new protocol, or a new kludge. 999 * - from RFC2461 6.2.4, host MUST NOT send an unsolicited NA. 1000 * we need to check ip6forwarding before sending it. 1001 * (or should we allow proxy ND configuration only for 1002 * routers? there's no mention about proxy ND from hosts) 1003 */ 1004 #if 0 1005 /* XXX it does not work */ 1006 if (rt->rt_flags & RTF_ANNOUNCE) 1007 nd6_na_output(ifp, 1008 &SIN6(rt_key(rt))->sin6_addr, 1009 &SIN6(rt_key(rt))->sin6_addr, 1010 ip6_forwarding ? ND_NA_FLAG_ROUTER : 0, 1011 1, NULL); 1012 #endif 1013 /* FALLTHROUGH */ 1014 case RTM_RESOLVE: 1015 if ((ifp->if_flags & IFF_POINTOPOINT) == 0) { 1016 /* 1017 * Address resolution isn't necessary for a point to 1018 * point link, so we can skip this test for a p2p link. 1019 */ 1020 if (gate->sa_family != AF_LINK || 1021 gate->sa_len < sizeof(null_sdl)) { 1022 log(LOG_DEBUG, 1023 "nd6_rtrequest: bad gateway value: %s\n", 1024 ifp->if_xname); 1025 break; 1026 } 1027 SDL(gate)->sdl_type = ifp->if_type; 1028 SDL(gate)->sdl_index = ifp->if_index; 1029 } 1030 if (ln != NULL) 1031 break; /* This happens on a route change */ 1032 /* 1033 * Case 2: This route may come from cloning, or a manual route 1034 * add with a LL address. 1035 */ 1036 R_Malloc(ln, struct llinfo_nd6 *, sizeof(*ln)); 1037 rt->rt_llinfo = (caddr_t)ln; 1038 if (!ln) { 1039 log(LOG_DEBUG, "nd6_rtrequest: malloc failed\n"); 1040 break; 1041 } 1042 nd6_inuse++; 1043 nd6_allocated++; 1044 Bzero(ln, sizeof(*ln)); 1045 ln->ln_rt = rt; 1046 /* this is required for "ndp" command. - shin */ 1047 if (req == RTM_ADD) { 1048 /* 1049 * gate should have some valid AF_LINK entry, 1050 * and ln->ln_expire should have some lifetime 1051 * which is specified by ndp command. 1052 */ 1053 ln->ln_state = ND6_LLINFO_REACHABLE; 1054 ln->ln_byhint = 0; 1055 } else { 1056 /* 1057 * When req == RTM_RESOLVE, rt is created and 1058 * initialized in rtrequest(), so rt_expire is 0. 1059 */ 1060 ln->ln_state = ND6_LLINFO_NOSTATE; 1061 ln->ln_expire = time_second; 1062 } 1063 rt->rt_flags |= RTF_LLINFO; 1064 ln->ln_next = llinfo_nd6.ln_next; 1065 llinfo_nd6.ln_next = ln; 1066 ln->ln_prev = &llinfo_nd6; 1067 ln->ln_next->ln_prev = ln; 1068 1069 /* 1070 * check if rt_key(rt) is one of my address assigned 1071 * to the interface. 1072 */ 1073 ifa = (struct ifaddr *)in6ifa_ifpwithaddr(rt->rt_ifp, 1074 &SIN6(rt_key(rt))->sin6_addr); 1075 if (ifa) { 1076 caddr_t macp = nd6_ifptomac(ifp); 1077 ln->ln_expire = 0; 1078 ln->ln_state = ND6_LLINFO_REACHABLE; 1079 ln->ln_byhint = 0; 1080 if (macp) { 1081 Bcopy(macp, LLADDR(SDL(gate)), ifp->if_addrlen); 1082 SDL(gate)->sdl_alen = ifp->if_addrlen; 1083 } 1084 if (nd6_useloopback) { 1085 rt->rt_ifp = lo0ifp; /*XXX*/ 1086 /* 1087 * Make sure rt_ifa be equal to the ifaddr 1088 * corresponding to the address. 1089 * We need this because when we refer 1090 * rt_ifa->ia6_flags in ip6_input, we assume 1091 * that the rt_ifa points to the address instead 1092 * of the loopback address. 1093 */ 1094 if (ifa != rt->rt_ifa) { 1095 IFAFREE(rt->rt_ifa); 1096 ifa->ifa_refcnt++; 1097 rt->rt_ifa = ifa; 1098 } 1099 } 1100 } else if (rt->rt_flags & RTF_ANNOUNCE) { 1101 ln->ln_expire = 0; 1102 ln->ln_state = ND6_LLINFO_REACHABLE; 1103 ln->ln_byhint = 0; 1104 1105 /* join solicited node multicast for proxy ND */ 1106 if (ifp->if_flags & IFF_MULTICAST) { 1107 struct in6_addr llsol; 1108 int error; 1109 1110 llsol = SIN6(rt_key(rt))->sin6_addr; 1111 llsol.s6_addr16[0] = htons(0xff02); 1112 llsol.s6_addr16[1] = htons(ifp->if_index); 1113 llsol.s6_addr32[1] = 0; 1114 llsol.s6_addr32[2] = htonl(1); 1115 llsol.s6_addr8[12] = 0xff; 1116 1117 (void)in6_addmulti(&llsol, ifp, &error); 1118 if (error) 1119 printf( 1120 "nd6_rtrequest: could not join solicited node multicast (errno=%d)\n", error); 1121 } 1122 } 1123 break; 1124 1125 case RTM_DELETE: 1126 if (!ln) 1127 break; 1128 /* leave from solicited node multicast for proxy ND */ 1129 if ((rt->rt_flags & RTF_ANNOUNCE) != 0 && 1130 (ifp->if_flags & IFF_MULTICAST) != 0) { 1131 struct in6_addr llsol; 1132 struct in6_multi *in6m; 1133 1134 llsol = SIN6(rt_key(rt))->sin6_addr; 1135 llsol.s6_addr16[0] = htons(0xff02); 1136 llsol.s6_addr16[1] = htons(ifp->if_index); 1137 llsol.s6_addr32[1] = 0; 1138 llsol.s6_addr32[2] = htonl(1); 1139 llsol.s6_addr8[12] = 0xff; 1140 1141 IN6_LOOKUP_MULTI(llsol, ifp, in6m); 1142 if (in6m) 1143 in6_delmulti(in6m); 1144 } 1145 nd6_inuse--; 1146 ln->ln_next->ln_prev = ln->ln_prev; 1147 ln->ln_prev->ln_next = ln->ln_next; 1148 ln->ln_prev = NULL; 1149 rt->rt_llinfo = 0; 1150 rt->rt_flags &= ~RTF_LLINFO; 1151 if (ln->ln_hold) 1152 m_freem(ln->ln_hold); 1153 Free((caddr_t)ln); 1154 } 1155 } 1156 1157 void 1158 nd6_p2p_rtrequest(req, rt, info) 1159 int req; 1160 struct rtentry *rt; 1161 struct rt_addrinfo *info; /* xxx unused */ 1162 { 1163 struct sockaddr *gate = rt->rt_gateway; 1164 static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK}; 1165 struct ifnet *ifp = rt->rt_ifp; 1166 struct ifaddr *ifa; 1167 1168 if (rt->rt_flags & RTF_GATEWAY) 1169 return; 1170 1171 switch (req) { 1172 case RTM_ADD: 1173 /* 1174 * There is no backward compatibility :) 1175 * 1176 * if ((rt->rt_flags & RTF_HOST) == 0 && 1177 * SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff) 1178 * rt->rt_flags |= RTF_CLONING; 1179 */ 1180 if (rt->rt_flags & RTF_CLONING) { 1181 /* 1182 * Case 1: This route should come from 1183 * a route to interface. 1184 */ 1185 rt_setgate(rt, rt_key(rt), 1186 (struct sockaddr *)&null_sdl); 1187 gate = rt->rt_gateway; 1188 SDL(gate)->sdl_type = ifp->if_type; 1189 SDL(gate)->sdl_index = ifp->if_index; 1190 break; 1191 } 1192 /* Announce a new entry if requested. */ 1193 if (rt->rt_flags & RTF_ANNOUNCE) 1194 nd6_na_output(ifp, 1195 &SIN6(rt_key(rt))->sin6_addr, 1196 &SIN6(rt_key(rt))->sin6_addr, 1197 ip6_forwarding ? ND_NA_FLAG_ROUTER : 0, 1198 1, NULL); 1199 /* FALLTHROUGH */ 1200 case RTM_RESOLVE: 1201 /* 1202 * check if rt_key(rt) is one of my address assigned 1203 * to the interface. 1204 */ 1205 ifa = (struct ifaddr *)in6ifa_ifpwithaddr(rt->rt_ifp, 1206 &SIN6(rt_key(rt))->sin6_addr); 1207 if (ifa) { 1208 if (nd6_useloopback) { 1209 rt->rt_ifp = lo0ifp; /*XXX*/ 1210 } 1211 } 1212 break; 1213 } 1214 } 1215 1216 int 1217 nd6_ioctl(cmd, data, ifp) 1218 u_long cmd; 1219 caddr_t data; 1220 struct ifnet *ifp; 1221 { 1222 struct in6_drlist *drl = (struct in6_drlist *)data; 1223 struct in6_prlist *prl = (struct in6_prlist *)data; 1224 struct in6_ndireq *ndi = (struct in6_ndireq *)data; 1225 struct in6_nbrinfo *nbi = (struct in6_nbrinfo *)data; 1226 struct in6_ndifreq *ndif = (struct in6_ndifreq *)data; 1227 struct nd_defrouter *dr, any; 1228 struct nd_prefix *pr; 1229 struct rtentry *rt; 1230 int i = 0, error = 0; 1231 int s; 1232 1233 switch (cmd) { 1234 case SIOCGDRLST_IN6: 1235 bzero(drl, sizeof(*drl)); 1236 s = splnet(); 1237 dr = TAILQ_FIRST(&nd_defrouter); 1238 while (dr && i < DRLSTSIZ) { 1239 drl->defrouter[i].rtaddr = dr->rtaddr; 1240 if (IN6_IS_ADDR_LINKLOCAL(&drl->defrouter[i].rtaddr)) { 1241 /* XXX: need to this hack for KAME stack */ 1242 drl->defrouter[i].rtaddr.s6_addr16[1] = 0; 1243 } else 1244 log(LOG_ERR, 1245 "default router list contains a " 1246 "non-linklocal address(%s)\n", 1247 ip6_sprintf(&drl->defrouter[i].rtaddr)); 1248 1249 drl->defrouter[i].flags = dr->flags; 1250 drl->defrouter[i].rtlifetime = dr->rtlifetime; 1251 drl->defrouter[i].expire = dr->expire; 1252 drl->defrouter[i].if_index = dr->ifp->if_index; 1253 i++; 1254 dr = TAILQ_NEXT(dr, dr_entry); 1255 } 1256 splx(s); 1257 break; 1258 case SIOCGPRLST_IN6: 1259 /* 1260 * XXX meaning of fields, especialy "raflags", is very 1261 * differnet between RA prefix list and RR/static prefix list. 1262 * how about separating ioctls into two? 1263 */ 1264 bzero(prl, sizeof(*prl)); 1265 s = splnet(); 1266 pr = nd_prefix.lh_first; 1267 while (pr && i < PRLSTSIZ) { 1268 struct nd_pfxrouter *pfr; 1269 int j; 1270 1271 prl->prefix[i].prefix = pr->ndpr_prefix.sin6_addr; 1272 prl->prefix[i].raflags = pr->ndpr_raf; 1273 prl->prefix[i].prefixlen = pr->ndpr_plen; 1274 prl->prefix[i].vltime = pr->ndpr_vltime; 1275 prl->prefix[i].pltime = pr->ndpr_pltime; 1276 prl->prefix[i].if_index = pr->ndpr_ifp->if_index; 1277 prl->prefix[i].expire = pr->ndpr_expire; 1278 1279 pfr = pr->ndpr_advrtrs.lh_first; 1280 j = 0; 1281 while(pfr) { 1282 if (j < DRLSTSIZ) { 1283 #define RTRADDR prl->prefix[i].advrtr[j] 1284 RTRADDR = pfr->router->rtaddr; 1285 if (IN6_IS_ADDR_LINKLOCAL(&RTRADDR)) { 1286 /* XXX: hack for KAME */ 1287 RTRADDR.s6_addr16[1] = 0; 1288 } else 1289 log(LOG_ERR, 1290 "a router(%s) advertises " 1291 "a prefix with " 1292 "non-link local address\n", 1293 ip6_sprintf(&RTRADDR)); 1294 #undef RTRADDR 1295 } 1296 j++; 1297 pfr = pfr->pfr_next; 1298 } 1299 prl->prefix[i].advrtrs = j; 1300 prl->prefix[i].origin = PR_ORIG_RA; 1301 1302 i++; 1303 pr = pr->ndpr_next; 1304 } 1305 { 1306 struct rr_prefix *rpp; 1307 1308 for (rpp = LIST_FIRST(&rr_prefix); rpp; 1309 rpp = LIST_NEXT(rpp, rp_entry)) { 1310 if (i >= PRLSTSIZ) 1311 break; 1312 prl->prefix[i].prefix = rpp->rp_prefix.sin6_addr; 1313 prl->prefix[i].raflags = rpp->rp_raf; 1314 prl->prefix[i].prefixlen = rpp->rp_plen; 1315 prl->prefix[i].vltime = rpp->rp_vltime; 1316 prl->prefix[i].pltime = rpp->rp_pltime; 1317 prl->prefix[i].if_index = rpp->rp_ifp->if_index; 1318 prl->prefix[i].expire = rpp->rp_expire; 1319 prl->prefix[i].advrtrs = 0; 1320 prl->prefix[i].origin = rpp->rp_origin; 1321 i++; 1322 } 1323 } 1324 splx(s); 1325 1326 break; 1327 case SIOCGIFINFO_IN6: 1328 if (!nd_ifinfo || i >= nd_ifinfo_indexlim) { 1329 error = EINVAL; 1330 break; 1331 } 1332 ndi->ndi = nd_ifinfo[ifp->if_index]; 1333 break; 1334 case SIOCSIFINFO_FLAGS: 1335 /* XXX: almost all other fields of ndi->ndi is unused */ 1336 if (!nd_ifinfo || i >= nd_ifinfo_indexlim) { 1337 error = EINVAL; 1338 break; 1339 } 1340 nd_ifinfo[ifp->if_index].flags = ndi->ndi.flags; 1341 break; 1342 case SIOCSNDFLUSH_IN6: /* XXX: the ioctl name is confusing... */ 1343 /* flush default router list */ 1344 /* 1345 * xxx sumikawa: should not delete route if default 1346 * route equals to the top of default router list 1347 */ 1348 bzero(&any, sizeof(any)); 1349 defrouter_delreq(&any, 0); 1350 defrouter_select(); 1351 /* xxx sumikawa: flush prefix list */ 1352 break; 1353 case SIOCSPFXFLUSH_IN6: 1354 { 1355 /* flush all the prefix advertised by routers */ 1356 struct nd_prefix *pr, *next; 1357 1358 s = splnet(); 1359 1360 for (pr = nd_prefix.lh_first; pr; pr = next) { 1361 next = pr->ndpr_next; 1362 if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr)) 1363 in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr); 1364 prelist_remove(pr); 1365 } 1366 splx(s); 1367 break; 1368 } 1369 case SIOCSRTRFLUSH_IN6: 1370 { 1371 /* flush all the default routers */ 1372 struct nd_defrouter *dr, *next; 1373 1374 s = splnet(); 1375 if ((dr = TAILQ_FIRST(&nd_defrouter)) != NULL) { 1376 /* 1377 * The first entry of the list may be stored in 1378 * the routing table, so we'll delete it later. 1379 */ 1380 for (dr = TAILQ_NEXT(dr, dr_entry); dr; dr = next) { 1381 next = TAILQ_NEXT(dr, dr_entry); 1382 defrtrlist_del(dr); 1383 } 1384 defrtrlist_del(TAILQ_FIRST(&nd_defrouter)); 1385 } 1386 splx(s); 1387 break; 1388 } 1389 case SIOCGNBRINFO_IN6: 1390 { 1391 struct llinfo_nd6 *ln; 1392 struct in6_addr nb_addr = nbi->addr; /* make local for safety */ 1393 1394 /* 1395 * XXX: KAME specific hack for scoped addresses 1396 * XXXX: for other scopes than link-local? 1397 */ 1398 if (IN6_IS_ADDR_LINKLOCAL(&nbi->addr) || 1399 IN6_IS_ADDR_MC_LINKLOCAL(&nbi->addr)) { 1400 u_int16_t *idp = (u_int16_t *)&nb_addr.s6_addr[2]; 1401 1402 if (*idp == 0) 1403 *idp = htons(ifp->if_index); 1404 } 1405 1406 s = splnet(); 1407 1408 if ((rt = nd6_lookup(&nb_addr, 0, ifp)) == NULL) { 1409 error = EINVAL; 1410 splx(s); 1411 break; 1412 } 1413 ln = (struct llinfo_nd6 *)rt->rt_llinfo; 1414 nbi->state = ln->ln_state; 1415 nbi->asked = ln->ln_asked; 1416 nbi->isrouter = ln->ln_router; 1417 nbi->expire = ln->ln_expire; 1418 splx(s); 1419 1420 break; 1421 } 1422 case SIOCGDEFIFACE_IN6: /* XXX: should be implemented as a sysctl? */ 1423 ndif->ifindex = nd6_defifindex; 1424 break; 1425 case SIOCSDEFIFACE_IN6: /* XXX: should be implemented as a sysctl? */ 1426 return(nd6_setdefaultiface(ndif->ifindex)); 1427 break; 1428 } 1429 return(error); 1430 } 1431 1432 /* 1433 * Create neighbor cache entry and cache link-layer address, 1434 * on reception of inbound ND6 packets. (RS/RA/NS/redirect) 1435 */ 1436 struct rtentry * 1437 nd6_cache_lladdr(ifp, from, lladdr, lladdrlen, type, code) 1438 struct ifnet *ifp; 1439 struct in6_addr *from; 1440 char *lladdr; 1441 int lladdrlen; 1442 int type; /* ICMP6 type */ 1443 int code; /* type dependent information */ 1444 { 1445 struct rtentry *rt = NULL; 1446 struct llinfo_nd6 *ln = NULL; 1447 int is_newentry; 1448 struct sockaddr_dl *sdl = NULL; 1449 int do_update; 1450 int olladdr; 1451 int llchange; 1452 int newstate = 0; 1453 long time_second = time.tv_sec; 1454 1455 if (!ifp) 1456 panic("ifp == NULL in nd6_cache_lladdr"); 1457 if (!from) 1458 panic("from == NULL in nd6_cache_lladdr"); 1459 1460 /* nothing must be updated for unspecified address */ 1461 if (IN6_IS_ADDR_UNSPECIFIED(from)) 1462 return NULL; 1463 1464 /* 1465 * Validation about ifp->if_addrlen and lladdrlen must be done in 1466 * the caller. 1467 * 1468 * XXX If the link does not have link-layer adderss, what should 1469 * we do? (ifp->if_addrlen == 0) 1470 * Spec says nothing in sections for RA, RS and NA. There's small 1471 * description on it in NS section (RFC 2461 7.2.3). 1472 */ 1473 1474 rt = nd6_lookup(from, 0, ifp); 1475 if (!rt) { 1476 #if 0 1477 /* nothing must be done if there's no lladdr */ 1478 if (!lladdr || !lladdrlen) 1479 return NULL; 1480 #endif 1481 1482 rt = nd6_lookup(from, 1, ifp); 1483 is_newentry = 1; 1484 } else { 1485 /* do nothing if static ndp is set */ 1486 if (rt->rt_flags & RTF_STATIC) 1487 return NULL; 1488 is_newentry = 0; 1489 } 1490 1491 if (!rt) 1492 return NULL; 1493 if ((rt->rt_flags & (RTF_GATEWAY | RTF_LLINFO)) != RTF_LLINFO) { 1494 fail: 1495 (void)nd6_free(rt); 1496 return NULL; 1497 } 1498 ln = (struct llinfo_nd6 *)rt->rt_llinfo; 1499 if (!ln) 1500 goto fail; 1501 if (!rt->rt_gateway) 1502 goto fail; 1503 if (rt->rt_gateway->sa_family != AF_LINK) 1504 goto fail; 1505 sdl = SDL(rt->rt_gateway); 1506 1507 olladdr = (sdl->sdl_alen) ? 1 : 0; 1508 if (olladdr && lladdr) { 1509 if (bcmp(lladdr, LLADDR(sdl), ifp->if_addrlen)) 1510 llchange = 1; 1511 else 1512 llchange = 0; 1513 } else 1514 llchange = 0; 1515 1516 /* 1517 * newentry olladdr lladdr llchange (*=record) 1518 * 0 n n -- (1) 1519 * 0 y n -- (2) 1520 * 0 n y -- (3) * STALE 1521 * 0 y y n (4) * 1522 * 0 y y y (5) * STALE 1523 * 1 -- n -- (6) NOSTATE(= PASSIVE) 1524 * 1 -- y -- (7) * STALE 1525 */ 1526 1527 if (lladdr) { /* (3-5) and (7) */ 1528 /* 1529 * Record source link-layer address 1530 * XXX is it dependent to ifp->if_type? 1531 */ 1532 sdl->sdl_alen = ifp->if_addrlen; 1533 bcopy(lladdr, LLADDR(sdl), ifp->if_addrlen); 1534 } 1535 1536 if (!is_newentry) { 1537 if ((!olladdr && lladdr) /* (3) */ 1538 || (olladdr && lladdr && llchange)) { /* (5) */ 1539 do_update = 1; 1540 newstate = ND6_LLINFO_STALE; 1541 } else /* (1-2,4) */ 1542 do_update = 0; 1543 } else { 1544 do_update = 1; 1545 if (!lladdr) /* (6) */ 1546 newstate = ND6_LLINFO_NOSTATE; 1547 else /* (7) */ 1548 newstate = ND6_LLINFO_STALE; 1549 } 1550 1551 if (do_update) { 1552 /* 1553 * Update the state of the neighbor cache. 1554 */ 1555 ln->ln_state = newstate; 1556 1557 if (ln->ln_state == ND6_LLINFO_STALE) { 1558 /* 1559 * XXX: since nd6_output() below will cause 1560 * state tansition to DELAY and reset the timer, 1561 * we must set the timer now, although it is actually 1562 * meaningless. 1563 */ 1564 ln->ln_expire = time_second + nd6_gctimer; 1565 1566 if (ln->ln_hold) { 1567 /* 1568 * we assume ifp is not a p2p here, so just 1569 * set the 2nd argument as the 1st one. 1570 */ 1571 nd6_output(ifp, ifp, ln->ln_hold, 1572 (struct sockaddr_in6 *)rt_key(rt), 1573 rt); 1574 ln->ln_hold = NULL; 1575 } 1576 } else if (ln->ln_state == ND6_LLINFO_INCOMPLETE) { 1577 /* probe right away */ 1578 ln->ln_expire = time_second; 1579 } 1580 } 1581 1582 /* 1583 * ICMP6 type dependent behavior. 1584 * 1585 * NS: clear IsRouter if new entry 1586 * RS: clear IsRouter 1587 * RA: set IsRouter if there's lladdr 1588 * redir: clear IsRouter if new entry 1589 * 1590 * RA case, (1): 1591 * The spec says that we must set IsRouter in the following cases: 1592 * - If lladdr exist, set IsRouter. This means (1-5). 1593 * - If it is old entry (!newentry), set IsRouter. This means (7). 1594 * So, based on the spec, in (1-5) and (7) cases we must set IsRouter. 1595 * A quetion arises for (1) case. (1) case has no lladdr in the 1596 * neighbor cache, this is similar to (6). 1597 * This case is rare but we figured that we MUST NOT set IsRouter. 1598 * 1599 * newentry olladdr lladdr llchange NS RS RA redir 1600 * D R 1601 * 0 n n -- (1) c ? s 1602 * 0 y n -- (2) c s s 1603 * 0 n y -- (3) c s s 1604 * 0 y y n (4) c s s 1605 * 0 y y y (5) c s s 1606 * 1 -- n -- (6) c c c s 1607 * 1 -- y -- (7) c c s c s 1608 * 1609 * (c=clear s=set) 1610 */ 1611 switch (type & 0xff) { 1612 case ND_NEIGHBOR_SOLICIT: 1613 /* 1614 * New entry must have is_router flag cleared. 1615 */ 1616 if (is_newentry) /* (6-7) */ 1617 ln->ln_router = 0; 1618 break; 1619 case ND_REDIRECT: 1620 /* 1621 * If the icmp is a redirect to a better router, always set the 1622 * is_router flag. Otherwise, if the entry is newly created, 1623 * clear the flag. [RFC 2461, sec 8.3] 1624 */ 1625 if (code == ND_REDIRECT_ROUTER) 1626 ln->ln_router = 1; 1627 else if (is_newentry) /* (6-7) */ 1628 ln->ln_router = 0; 1629 break; 1630 case ND_ROUTER_SOLICIT: 1631 /* 1632 * is_router flag must always be cleared. 1633 */ 1634 ln->ln_router = 0; 1635 break; 1636 case ND_ROUTER_ADVERT: 1637 /* 1638 * Mark an entry with lladdr as a router. 1639 */ 1640 if ((!is_newentry && (olladdr || lladdr)) /* (2-5) */ 1641 || (is_newentry && lladdr)) { /* (7) */ 1642 ln->ln_router = 1; 1643 } 1644 break; 1645 } 1646 1647 /* 1648 * When the link-layer address of a router changes, select the 1649 * best router again. In particular, when the neighbor entry is newly 1650 * created, it might affect the selection policy. 1651 * Question: can we restrict the first condition to the "is_newentry" 1652 * case? 1653 * XXX: when we hear an RA from a new router with the link-layer 1654 * address option, defrouter_select() is called twice, since 1655 * defrtrlist_update called the function as well. However, I believe 1656 * we can compromise the overhead, since it only happens the first 1657 * time. 1658 */ 1659 if (do_update && ln->ln_router && !ip6_forwarding && ip6_accept_rtadv) 1660 defrouter_select(); 1661 1662 return rt; 1663 } 1664 1665 static void 1666 nd6_slowtimo(ignored_arg) 1667 void *ignored_arg; 1668 { 1669 int s = splnet(); 1670 int i; 1671 struct nd_ifinfo *nd6if; 1672 1673 timeout_set(&nd6_slowtimo_ch, nd6_slowtimo, NULL); 1674 timeout_add(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz); 1675 for (i = 1; i < if_index + 1; i++) { 1676 if (!nd_ifinfo || i >= nd_ifinfo_indexlim) 1677 continue; 1678 nd6if = &nd_ifinfo[i]; 1679 if (nd6if->basereachable && /* already initialized */ 1680 (nd6if->recalctm -= ND6_SLOWTIMER_INTERVAL) <= 0) { 1681 /* 1682 * Since reachable time rarely changes by router 1683 * advertisements, we SHOULD insure that a new random 1684 * value gets recomputed at least once every few hours. 1685 * (RFC 2461, 6.3.4) 1686 */ 1687 nd6if->recalctm = nd6_recalc_reachtm_interval; 1688 nd6if->reachable = ND_COMPUTE_RTIME(nd6if->basereachable); 1689 } 1690 } 1691 splx(s); 1692 } 1693 1694 #define senderr(e) { error = (e); goto bad;} 1695 int 1696 nd6_output(ifp, origifp, m0, dst, rt0) 1697 struct ifnet *ifp; 1698 struct ifnet *origifp; 1699 struct mbuf *m0; 1700 struct sockaddr_in6 *dst; 1701 struct rtentry *rt0; 1702 { 1703 struct mbuf *m = m0; 1704 struct rtentry *rt = rt0; 1705 struct sockaddr_in6 *gw6 = NULL; 1706 struct llinfo_nd6 *ln = NULL; 1707 int error = 0; 1708 long time_second = time.tv_sec; 1709 #ifdef IPSEC 1710 struct m_tag *mtag; 1711 #endif /* IPSEC */ 1712 1713 if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr)) 1714 goto sendpkt; 1715 1716 /* 1717 * XXX: we currently do not make neighbor cache on any interface 1718 * other than ARCnet, Ethernet, FDDI and GIF. 1719 * 1720 * RFC2893 says: 1721 * - unidirectional tunnels needs no ND 1722 */ 1723 switch (ifp->if_type) { 1724 case IFT_ARCNET: 1725 case IFT_ETHER: 1726 case IFT_FDDI: 1727 case IFT_GIF: /* XXX need more cases? */ 1728 break; 1729 default: 1730 goto sendpkt; 1731 } 1732 1733 /* 1734 * next hop determination. This routine is derived from ether_outpout. 1735 */ 1736 if (rt) { 1737 if ((rt->rt_flags & RTF_UP) == 0) { 1738 if ((rt0 = rt = rtalloc1((struct sockaddr *)dst, 1)) != 1739 NULL) 1740 { 1741 rt->rt_refcnt--; 1742 if (rt->rt_ifp != ifp) { 1743 /* XXX: loop care? */ 1744 return nd6_output(ifp, origifp, m0, 1745 dst, rt); 1746 } 1747 } else 1748 senderr(EHOSTUNREACH); 1749 } 1750 1751 if (rt->rt_flags & RTF_GATEWAY) { 1752 gw6 = (struct sockaddr_in6 *)rt->rt_gateway; 1753 1754 /* 1755 * We skip link-layer address resolution and NUD 1756 * if the gateway is not a neighbor from ND point 1757 * of view, regardless the value of nd_ifinfo.flags. 1758 * The second condition is a bit tricky; we skip 1759 * if the gateway is our own address, which is 1760 * sometimes used to install a route to a p2p link. 1761 */ 1762 if (!nd6_is_addr_neighbor(gw6, ifp) || 1763 in6ifa_ifpwithaddr(ifp, &gw6->sin6_addr)) { 1764 /* 1765 * We allow this kind of tricky route only 1766 * when the outgoing interface is p2p. 1767 * XXX: we may need a more generic rule here. 1768 */ 1769 if ((ifp->if_flags & IFF_POINTOPOINT) == 0) 1770 senderr(EHOSTUNREACH); 1771 1772 goto sendpkt; 1773 } 1774 1775 if (rt->rt_gwroute == 0) 1776 goto lookup; 1777 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { 1778 rtfree(rt); rt = rt0; 1779 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1); 1780 if ((rt = rt->rt_gwroute) == 0) 1781 senderr(EHOSTUNREACH); 1782 } 1783 } 1784 } 1785 1786 /* 1787 * Address resolution or Neighbor Unreachability Detection 1788 * for the next hop. 1789 * At this point, the destination of the packet must be a unicast 1790 * or an anycast address(i.e. not a multicast). 1791 */ 1792 1793 /* Look up the neighbor cache for the nexthop */ 1794 if (rt && (rt->rt_flags & RTF_LLINFO) != 0) 1795 ln = (struct llinfo_nd6 *)rt->rt_llinfo; 1796 else { 1797 /* 1798 * Since nd6_is_addr_neighbor() internally calls nd6_lookup(), 1799 * the condition below is not very efficient. But we believe 1800 * it is tolerable, because this should be a rare case. 1801 */ 1802 if (nd6_is_addr_neighbor(dst, ifp) && 1803 (rt = nd6_lookup(&dst->sin6_addr, 1, ifp)) != NULL) 1804 ln = (struct llinfo_nd6 *)rt->rt_llinfo; 1805 } 1806 if (!ln || !rt) { 1807 if ((ifp->if_flags & IFF_POINTOPOINT) == 0 && 1808 !(nd_ifinfo[ifp->if_index].flags & ND6_IFF_PERFORMNUD)) { 1809 log(LOG_DEBUG, 1810 "nd6_output: can't allocate llinfo for %s " 1811 "(ln=%p, rt=%p)\n", 1812 ip6_sprintf(&dst->sin6_addr), ln, rt); 1813 senderr(EIO); /* XXX: good error? */ 1814 } 1815 1816 goto sendpkt; /* send anyway */ 1817 } 1818 1819 /* We don't have to do link-layer address resolution on a p2p link. */ 1820 if ((ifp->if_flags & IFF_POINTOPOINT) != 0 && 1821 ln->ln_state < ND6_LLINFO_REACHABLE) { 1822 ln->ln_state = ND6_LLINFO_STALE; 1823 ln->ln_expire = time_second + nd6_gctimer; 1824 } 1825 1826 /* 1827 * The first time we send a packet to a neighbor whose entry is 1828 * STALE, we have to change the state to DELAY and a sets a timer to 1829 * expire in DELAY_FIRST_PROBE_TIME seconds to ensure do 1830 * neighbor unreachability detection on expiration. 1831 * (RFC 2461 7.3.3) 1832 */ 1833 if (ln->ln_state == ND6_LLINFO_STALE) { 1834 ln->ln_asked = 0; 1835 ln->ln_state = ND6_LLINFO_DELAY; 1836 ln->ln_expire = time_second + nd6_delay; 1837 } 1838 1839 /* 1840 * If the neighbor cache entry has a state other than INCOMPLETE 1841 * (i.e. its link-layer address is already resolved), just 1842 * send the packet. 1843 */ 1844 if (ln->ln_state > ND6_LLINFO_INCOMPLETE) 1845 goto sendpkt; 1846 1847 /* 1848 * There is a neighbor cache entry, but no ethernet address 1849 * response yet. Replace the held mbuf (if any) with this 1850 * latest one. 1851 * 1852 * XXX Does the code conform to rate-limiting rule? 1853 * (RFC 2461 7.2.2) 1854 */ 1855 if (ln->ln_state == ND6_LLINFO_NOSTATE) 1856 ln->ln_state = ND6_LLINFO_INCOMPLETE; 1857 if (ln->ln_hold) 1858 m_freem(ln->ln_hold); 1859 ln->ln_hold = m; 1860 if (ln->ln_expire) { 1861 if (ln->ln_asked < nd6_mmaxtries && 1862 ln->ln_expire < time_second) { 1863 ln->ln_asked++; 1864 ln->ln_expire = time_second + 1865 nd_ifinfo[ifp->if_index].retrans / 1000; 1866 nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0); 1867 } 1868 } 1869 return(0); 1870 1871 sendpkt: 1872 #ifdef IPSEC 1873 /* 1874 * If the packet needs outgoing IPsec crypto processing and the 1875 * interface doesn't support it, drop it. 1876 */ 1877 mtag = m_tag_find(m, PACKET_TAG_IPSEC_OUT_CRYPTO_NEEDED, NULL); 1878 #endif /* IPSEC */ 1879 1880 if ((ifp->if_flags & IFF_LOOPBACK) != 0) { 1881 #ifdef IPSEC 1882 if (mtag != NULL && 1883 (origifp->if_capabilities & IFCAP_IPSEC) == 0) { 1884 /* Tell IPsec to do its own crypto. */ 1885 ipsp_skipcrypto_unmark((struct tdb_ident *)(mtag + 1)); 1886 error = EACCES; 1887 goto bad; 1888 } 1889 #endif /* IPSEC */ 1890 return((*ifp->if_output)(origifp, m, (struct sockaddr *)dst, 1891 rt)); 1892 } 1893 #ifdef IPSEC 1894 if (mtag != NULL && 1895 (ifp->if_capabilities & IFCAP_IPSEC) == 0) { 1896 /* Tell IPsec to do its own crypto. */ 1897 ipsp_skipcrypto_unmark((struct tdb_ident *)(mtag + 1)); 1898 error = EACCES; 1899 goto bad; 1900 } 1901 #endif /* IPSEC */ 1902 return((*ifp->if_output)(ifp, m, (struct sockaddr *)dst, rt)); 1903 1904 bad: 1905 if (m) 1906 m_freem(m); 1907 return (error); 1908 } 1909 #undef senderr 1910 1911 int 1912 nd6_storelladdr(ifp, rt, m, dst, desten) 1913 struct ifnet *ifp; 1914 struct rtentry *rt; 1915 struct mbuf *m; 1916 struct sockaddr *dst; 1917 u_char *desten; 1918 { 1919 struct sockaddr_dl *sdl; 1920 1921 if (m->m_flags & M_MCAST) { 1922 switch (ifp->if_type) { 1923 case IFT_ETHER: 1924 case IFT_FDDI: 1925 ETHER_MAP_IPV6_MULTICAST(&SIN6(dst)->sin6_addr, 1926 desten); 1927 return(1); 1928 break; 1929 case IFT_ARCNET: 1930 *desten = 0; 1931 return(1); 1932 default: 1933 m_freem(m); 1934 return(0); 1935 } 1936 } 1937 1938 if (rt == NULL) { 1939 /* this could happen, if we could not allocate memory */ 1940 m_freem(m); 1941 return(0); 1942 } 1943 if (rt->rt_gateway->sa_family != AF_LINK) { 1944 printf("nd6_storelladdr: something odd happens\n"); 1945 m_freem(m); 1946 return(0); 1947 } 1948 sdl = SDL(rt->rt_gateway); 1949 if (sdl->sdl_alen == 0) { 1950 /* this should be impossible, but we bark here for debugging */ 1951 printf("nd6_storelladdr: sdl_alen == 0\n"); 1952 m_freem(m); 1953 return(0); 1954 } 1955 1956 bcopy(LLADDR(sdl), desten, sdl->sdl_alen); 1957 return(1); 1958 } 1959