Deleted Added
sdiff udiff text old ( 74093 ) new ( 78064 )
full compact
1/* $FreeBSD: head/sys/netinet6/nd6.c 78064 2001-06-11 12:39:29Z ume $ */
2/* $KAME: nd6.c,v 1.144 2001/05/24 07:44:00 itojun 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:

--- 27 unchanged lines hidden (view full) ---

38 * I left the code mostly as it was in 970310. -- itojun
39 */
40
41#include "opt_inet.h"
42#include "opt_inet6.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/callout.h>
47#include <sys/malloc.h>
48#include <sys/mbuf.h>
49#include <sys/socket.h>
50#include <sys/sockio.h>
51#include <sys/time.h>
52#include <sys/kernel.h>
53#include <sys/protosw.h>
54#include <sys/errno.h>
55#include <sys/syslog.h>
56#include <sys/queue.h>
57#include <sys/sysctl.h>
58
59#include <net/if.h>
60#include <net/if_dl.h>
61#include <net/if_types.h>
62#include <net/if_atm.h>
63#include <net/route.h>
64
65#include <netinet/in.h>

--- 15 unchanged lines hidden (view full) ---

81#define SDL(s) ((struct sockaddr_dl *)s)
82
83/* timer values */
84int nd6_prune = 1; /* walk list every 1 seconds */
85int nd6_delay = 5; /* delay first probe time 5 second */
86int nd6_umaxtries = 3; /* maximum unicast query */
87int nd6_mmaxtries = 3; /* maximum multicast query */
88int nd6_useloopback = 1; /* use loopback interface for local traffic */
89int nd6_gctimer = (60 * 60 * 24); /* 1 day: garbage collection timer */
90
91/* preventing too many loops in ND option parsing */
92int nd6_maxndopt = 10; /* max # of ND options allowed */
93
94int nd6_maxnudhint = 0; /* max # of subsequent upper layer hints */
95
96#ifdef ND6_DEBUG
97int nd6_debug = 1;
98#else
99int nd6_debug = 0;
100#endif
101
102/* for debugging? */
103static int nd6_inuse, nd6_allocated;
104
105struct llinfo_nd6 llinfo_nd6 = {&llinfo_nd6, &llinfo_nd6};
106static size_t nd_ifinfo_indexlim = 8;
107struct nd_ifinfo *nd_ifinfo = NULL;
108struct nd_drhead nd_defrouter;
109struct nd_prhead nd_prefix = { 0 };
110
111int nd6_recalc_reachtm_interval = ND6_RECALC_REACHTM_INTERVAL;
112static struct sockaddr_in6 all1_sa;
113
114static void nd6_slowtimo __P((void *));
115static int regen_tmpaddr __P((struct in6_ifaddr *));
116
117struct callout nd6_slowtimo_ch;
118struct callout nd6_timer_ch;
119extern struct callout in6_tmpaddrtimer_ch;
120
121void
122nd6_init()
123{
124 static int nd6_init_done = 0;
125 int i;
126
127 if (nd6_init_done) {
128 log(LOG_NOTICE, "nd6_init called more than once(ignored)\n");

--- 6 unchanged lines hidden (view full) ---

135 all1_sa.sin6_addr.s6_addr[i] = 0xff;
136
137 /* initialization of the default router list */
138 TAILQ_INIT(&nd_defrouter);
139
140 nd6_init_done = 1;
141
142 /* start timer */
143 callout_reset(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz,
144 nd6_slowtimo, NULL);
145}
146
147void
148nd6_ifattach(ifp)
149 struct ifnet *ifp;
150{
151
152 /*

--- 49 unchanged lines hidden (view full) ---

202nd6_setmtu(ifp)
203 struct ifnet *ifp;
204{
205#define MIN(a,b) ((a) < (b) ? (a) : (b))
206 struct nd_ifinfo *ndi = &nd_ifinfo[ifp->if_index];
207 u_long oldmaxmtu = ndi->maxmtu;
208 u_long oldlinkmtu = ndi->linkmtu;
209
210 switch (ifp->if_type) {
211 case IFT_ARCNET: /* XXX MTU handling needs more work */
212 ndi->maxmtu = MIN(60480, ifp->if_mtu);
213 break;
214 case IFT_ETHER:
215 ndi->maxmtu = MIN(ETHERMTU, ifp->if_mtu);
216 break;
217 case IFT_FDDI:
218 ndi->maxmtu = MIN(FDDIIPMTU, ifp->if_mtu);
219 break;
220 case IFT_ATM:
221 ndi->maxmtu = MIN(ATMMTU, ifp->if_mtu);
222 break;
223 case IFT_IEEE1394: /* XXX should be IEEE1394MTU(1500) */
224 ndi->maxmtu = MIN(ETHERMTU, ifp->if_mtu);
225 break;
226#ifdef IFT_IEEE80211
227 case IFT_IEEE80211: /* XXX should be IEEE80211MTU(1500) */
228 ndi->maxmtu = MIN(ETHERMTU, ifp->if_mtu);
229 break;
230#endif
231 default:
232 ndi->maxmtu = ifp->if_mtu;
233 break;
234 }
235
236 if (oldmaxmtu != ndi->maxmtu) {
237 /*
238 * If the ND level MTU is not set yet, or if the maxmtu
239 * is reset to a smaller value than the ND level MTU,
240 * also reset the ND level MTU.
241 */

--- 105 unchanged lines hidden (view full) ---

347
348 while (1) {
349 nd_opt = nd6_option(ndopts);
350 if (!nd_opt && !ndopts->nd_opts_last) {
351 /*
352 * Message validation requires that all included
353 * options have a length that is greater than zero.
354 */
355 icmp6stat.icp6s_nd_badopt++;
356 bzero(ndopts, sizeof(*ndopts));
357 return -1;
358 }
359
360 if (!nd_opt)
361 goto skip1;
362
363 switch (nd_opt->nd_opt_type) {
364 case ND_OPT_SOURCE_LINKADDR:
365 case ND_OPT_TARGET_LINKADDR:
366 case ND_OPT_MTU:
367 case ND_OPT_REDIRECTED_HEADER:
368 if (ndopts->nd_opt_array[nd_opt->nd_opt_type]) {
369 nd6log((LOG_INFO,
370 "duplicated ND6 option found (type=%d)\n",
371 nd_opt->nd_opt_type));
372 /* XXX bark? */
373 } else {
374 ndopts->nd_opt_array[nd_opt->nd_opt_type]
375 = nd_opt;
376 }
377 break;
378 case ND_OPT_PREFIX_INFORMATION:
379 if (ndopts->nd_opt_array[nd_opt->nd_opt_type] == 0) {
380 ndopts->nd_opt_array[nd_opt->nd_opt_type]
381 = nd_opt;
382 }
383 ndopts->nd_opts_pi_end =
384 (struct nd_opt_prefix_info *)nd_opt;
385 break;
386 default:
387 /*
388 * Unknown options must be silently ignored,
389 * to accomodate future extension to the protocol.
390 */
391 nd6log((LOG_DEBUG,
392 "nd6_options: unsupported option %d - "
393 "option ignored\n", nd_opt->nd_opt_type));
394 }
395
396skip1:
397 i++;
398 if (i > nd6_maxndopt) {
399 icmp6stat.icp6s_nd_toomanyopt++;
400 nd6log((LOG_INFO, "too many loop in nd opt\n"));
401 break;
402 }
403
404 if (ndopts->nd_opts_done)
405 break;
406 }
407
408 return 0;
409}
410
411/*
412 * ND6 timer routine to expire default route list and prefix list
413 */
414void
415nd6_timer(ignored_arg)
416 void *ignored_arg;
417{
418 int s;
419 struct llinfo_nd6 *ln;
420 struct nd_defrouter *dr;
421 struct nd_prefix *pr;
422 struct ifnet *ifp;
423 struct in6_ifaddr *ia6, *nia6;
424 struct in6_addrlifetime *lt6;
425
426 s = splnet();
427 callout_reset(&nd6_timer_ch, nd6_prune * hz,
428 nd6_timer, NULL);
429
430 ln = llinfo_nd6.ln_next;
431 /* XXX BSD/OS separates this code -- itojun */
432 while (ln && ln != &llinfo_nd6) {
433 struct rtentry *rt;
434 struct sockaddr_in6 *dst;
435 struct llinfo_nd6 *next = ln->ln_next;
436 /* XXX: used for the DELAY case only: */
437 struct nd_ifinfo *ndi = NULL;
438
439 if ((rt = ln->ln_rt) == NULL) {
440 ln = next;
441 continue;

--- 39 unchanged lines hidden (view full) ---

481 * older rcvif?
482 */
483 m->m_pkthdr.rcvif = rt->rt_ifp;
484 }
485 icmp6_error(m, ICMP6_DST_UNREACH,
486 ICMP6_DST_UNREACH_ADDR, 0);
487 ln->ln_hold = NULL;
488 }
489 next = nd6_free(rt);
490 }
491 break;
492 case ND6_LLINFO_REACHABLE:
493 if (ln->ln_expire) {
494 ln->ln_state = ND6_LLINFO_STALE;
495 ln->ln_expire = time_second + nd6_gctimer;
496 }
497 break;
498
499 case ND6_LLINFO_STALE:
500 /* Garbage Collection(RFC 2461 5.3) */
501 if (ln->ln_expire)
502 next = nd6_free(rt);
503 break;
504
505 case ND6_LLINFO_DELAY:
506 if (ndi && (ndi->flags & ND6_IFF_PERFORMNUD) != 0) {
507 /* We need NUD */
508 ln->ln_asked = 1;
509 ln->ln_state = ND6_LLINFO_PROBE;
510 ln->ln_expire = time_second +
511 ndi->retrans / 1000;
512 nd6_ns_output(ifp, &dst->sin6_addr,
513 &dst->sin6_addr,
514 ln, 0);
515 } else {
516 ln->ln_state = ND6_LLINFO_STALE; /* XXX */
517 ln->ln_expire = time_second + nd6_gctimer;
518 }
519 break;
520 case ND6_LLINFO_PROBE:
521 if (ln->ln_asked < nd6_umaxtries) {
522 ln->ln_asked++;
523 ln->ln_expire = time_second +
524 nd_ifinfo[ifp->if_index].retrans / 1000;
525 nd6_ns_output(ifp, &dst->sin6_addr,
526 &dst->sin6_addr, ln, 0);
527 } else {
528 next = nd6_free(rt);
529 }
530 break;
531 }
532 ln = next;
533 }
534
535 /* expire default router list */
536 dr = TAILQ_FIRST(&nd_defrouter);
537 while (dr) {
538 if (dr->expire && dr->expire < time_second) {
539 struct nd_defrouter *t;
540 t = TAILQ_NEXT(dr, dr_entry);
541 defrtrlist_del(dr);
542 dr = t;
543 } else {
544 dr = TAILQ_NEXT(dr, dr_entry);
545 }
546 }
547
548 /*
549 * expire interface addresses.
550 * in the past the loop was inside prefix expiry processing.
551 * However, from a stricter speci-confrmance standpoint, we should
552 * rather separate address lifetimes and prefix lifetimes.
553 */
554 addrloop:
555 for (ia6 = in6_ifaddr; ia6; ia6 = nia6) {
556 nia6 = ia6->ia_next;
557 /* check address lifetime */
558 lt6 = &ia6->ia6_lifetime;
559 if (IFA6_IS_INVALID(ia6)) {
560 int regen = 0;
561
562 /*
563 * If the expiring address is temporary, try
564 * regenerating a new one. This would be useful when
565 * we suspended a laptop PC, then turned on after a
566 * period that could invalidate all temporary
567 * addresses. Although we may have to restart the
568 * loop (see below), it must be after purging the
569 * address. Otherwise, we'd see an infinite loop of
570 * regeneration.
571 */
572 if (ip6_use_tempaddr &&
573 (ia6->ia6_flags & IN6_IFF_TEMPORARY) != 0) {
574 if (regen_tmpaddr(ia6) == 0)
575 regen = 1;
576 }
577
578 in6_purgeaddr(&ia6->ia_ifa);
579
580 if (regen)
581 goto addrloop; /* XXX: see below */
582 } else if (IFA6_IS_DEPRECATED(ia6)) {
583 int oldflags = ia6->ia6_flags;
584
585 ia6->ia6_flags |= IN6_IFF_DEPRECATED;
586
587 /*
588 * If a temporary address has just become deprecated,
589 * regenerate a new one if possible.
590 */
591 if (ip6_use_tempaddr &&
592 (ia6->ia6_flags & IN6_IFF_TEMPORARY) != 0 &&
593 (oldflags & IN6_IFF_DEPRECATED) == 0) {
594
595 if (regen_tmpaddr(ia6) == 0) {
596 /*
597 * A new temporary address is
598 * generated.
599 * XXX: this means the address chain
600 * has changed while we are still in
601 * the loop. Although the change
602 * would not cause disaster (because
603 * it's not an addition, but a
604 * deletion,) we'd rather restart the
605 * loop just for safety. Or does this
606 * significantly reduce performance??
607 */
608 goto addrloop;
609 }
610 }
611 } else if (IFA6_IS_DEPRECATED(ia6)) {
612 /*
613 * A new RA might have made a deprecated address
614 * preferred.
615 */
616 ia6->ia6_flags &= ~IN6_IFF_DEPRECATED;
617 }
618 }
619
620 /* expire prefix list */
621 pr = nd_prefix.lh_first;
622 while (pr) {
623 /*
624 * check prefix lifetime.
625 * since pltime is just for autoconf, pltime processing for
626 * prefix is not necessary.
627 *
628 * we offset expire time by NDPR_KEEP_EXPIRE, so that we
629 * can use the old prefix information to validate the
630 * next prefix information to come. See prelist_update()
631 * for actual validation.
632 *
633 * I don't think such an offset is necessary.
634 * (jinmei@kame.net, 20010130).
635 */
636 if (pr->ndpr_expire && pr->ndpr_expire < time_second) {
637 struct nd_prefix *t;
638 t = pr->ndpr_next;
639
640 /*
641 * address expiration and prefix expiration are
642 * separate. NEVER perform in6_purgeaddr here.
643 */
644
645 prelist_remove(pr);
646 pr = t;
647 } else
648 pr = pr->ndpr_next;
649 }
650 splx(s);
651}
652
653static int
654regen_tmpaddr(ia6)
655 struct in6_ifaddr *ia6; /* deprecated/invalidated temporary address */
656{
657 struct ifaddr *ifa;
658 struct ifnet *ifp;
659 struct in6_ifaddr *public_ifa6 = NULL;
660
661 ifp = ia6->ia_ifa.ifa_ifp;
662 for (ifa = ifp->if_addrlist.tqh_first; ifa;
663 ifa = ifa->ifa_list.tqe_next)
664 {
665 struct in6_ifaddr *it6;
666
667 if (ifa->ifa_addr->sa_family != AF_INET6)
668 continue;
669
670 it6 = (struct in6_ifaddr *)ifa;
671
672 /* ignore no autoconf addresses. */
673 if ((it6->ia6_flags & IN6_IFF_AUTOCONF) == 0)
674 continue;
675
676 /* ignore autoconf addresses with different prefixes. */
677 if (it6->ia6_ndpr == NULL || it6->ia6_ndpr != ia6->ia6_ndpr)
678 continue;
679
680 /*
681 * Now we are looking at an autoconf address with the same
682 * prefix as ours. If the address is temporary and is still
683 * preferred, do not create another one. It would be rare, but
684 * could happen, for example, when we resume a laptop PC after
685 * a long period.
686 */
687 if ((it6->ia6_flags & IN6_IFF_TEMPORARY) != 0 &&
688 !IFA6_IS_DEPRECATED(it6)) {
689 public_ifa6 = NULL;
690 break;
691 }
692
693 /*
694 * This is a public autoconf address that has the same prefix
695 * as ours. If it is preferred, keep it. We can't break the
696 * loop here, because there may be a still-preferred temporary
697 * address with the prefix.
698 */
699 if (!IFA6_IS_DEPRECATED(it6))
700 public_ifa6 = it6;
701 }
702
703 if (public_ifa6 != NULL) {
704 int e;
705
706 if ((e = in6_tmpifadd(public_ifa6, 0)) != 0) {
707 log(LOG_NOTICE, "regen_tmpaddr: failed to create a new"
708 " tmp addr,errno=%d\n", e);
709 return(-1);
710 }
711 return(0);
712 }
713
714 return(-1);
715}
716
717/*
718 * Nuke neighbor cache/prefix/default router management table, right before
719 * ifp goes away.
720 */
721void
722nd6_purge(ifp)
723 struct ifnet *ifp;
724{

--- 16 unchanged lines hidden (view full) ---

741 if (dr->ifp == ifp)
742 defrtrlist_del(dr);
743 }
744
745 /* Nuke prefix list entries toward ifp */
746 for (pr = nd_prefix.lh_first; pr; pr = npr) {
747 npr = pr->ndpr_next;
748 if (pr->ndpr_ifp == ifp) {
749 /*
750 * Previously, pr->ndpr_addr is removed as well,
751 * but I strongly believe we don't have to do it.
752 * nd6_purge() is only called from in6_ifdetach(),
753 * which removes all the associated interface addresses
754 * by itself.
755 * (jinmei@kame.net 20010129)
756 */
757 prelist_remove(pr);
758 }
759 }
760
761 /* cancel default outgoing interface setting */
762 if (nd6_defifindex == ifp->if_index)
763 nd6_setdefaultiface(0);
764

--- 14 unchanged lines hidden (view full) ---

779 struct sockaddr_dl *sdl;
780
781 nln = ln->ln_next;
782 rt = ln->ln_rt;
783 if (rt && rt->rt_gateway &&
784 rt->rt_gateway->sa_family == AF_LINK) {
785 sdl = (struct sockaddr_dl *)rt->rt_gateway;
786 if (sdl->sdl_index == ifp->if_index)
787 nln = nd6_free(rt);
788 }
789 ln = nln;
790 }
791}
792
793struct rtentry *
794nd6_lookup(addr6, create, ifp)
795 struct in6_addr *addr6;
796 int create;
797 struct ifnet *ifp;
798{

--- 88 unchanged lines hidden (view full) ---

887 * Detect if a given IPv6 address identifies a neighbor on a given link.
888 * XXX: should take care of the destination of a p2p link?
889 */
890int
891nd6_is_addr_neighbor(addr, ifp)
892 struct sockaddr_in6 *addr;
893 struct ifnet *ifp;
894{
895 struct ifaddr *ifa;
896 int i;
897
898#define IFADDR6(a) ((((struct in6_ifaddr *)(a))->ia_addr).sin6_addr)
899#define IFMASK6(a) ((((struct in6_ifaddr *)(a))->ia_prefixmask).sin6_addr)
900
901 /*
902 * A link-local address is always a neighbor.
903 * XXX: we should use the sin6_scope_id field rather than the embedded

--- 33 unchanged lines hidden (view full) ---

937 return(0);
938#undef IFADDR6
939#undef IFMASK6
940}
941
942/*
943 * Free an nd6 llinfo entry.
944 */
945struct llinfo_nd6 *
946nd6_free(rt)
947 struct rtentry *rt;
948{
949 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo, *next;
950 struct in6_addr in6 = ((struct sockaddr_in6 *)rt_key(rt))->sin6_addr;
951 struct nd_defrouter *dr;
952
953 /*
954 * we used to have pfctlinput(PRC_HOSTDEAD) here.
955 * even though it is not harmful, it was not really necessary.
956 */
957
958 if (!ip6_forwarding && ip6_accept_rtadv) { /* XXX: too restrictive? */
959 int s;
960 s = splnet();
961 dr = defrouter_lookup(&((struct sockaddr_in6 *)rt_key(rt))->sin6_addr,
962 rt->rt_ifp);
963
964 if (ln->ln_router || dr) {
965 /*
966 * rt6_flush must be called whether or not the neighbor
967 * is in the Default Router List.
968 * See a corresponding comment in nd6_na_input().
969 */
970 rt6_flush(&in6, rt->rt_ifp);
971 }

--- 9 unchanged lines hidden (view full) ---

981 * Temporarily fake the state to choose a new default
982 * router and to perform on-link determination of
983 * prefixes coreectly.
984 * Below the state will be set correctly,
985 * or the entry itself will be deleted.
986 */
987 ln->ln_state = ND6_LLINFO_INCOMPLETE;
988
989 /*
990 * Since defrouter_select() does not affect the
991 * on-link determination and MIP6 needs the check
992 * before the default router selection, we perform
993 * the check now.
994 */
995 pfxlist_onlink_check();
996
997 if (dr == TAILQ_FIRST(&nd_defrouter)) {
998 /*
999 * It is used as the current default router,
1000 * so we have to move it to the end of the
1001 * list and choose a new one.
1002 * XXX: it is not very efficient if this is
1003 * the only router.
1004 */
1005 TAILQ_REMOVE(&nd_defrouter, dr, dr_entry);
1006 TAILQ_INSERT_TAIL(&nd_defrouter, dr, dr_entry);
1007
1008 defrouter_select();
1009 }
1010 }
1011 splx(s);
1012 }
1013
1014 /*
1015 * Before deleting the entry, remember the next entry as the
1016 * return value. We need this because pfxlist_onlink_check() above
1017 * might have freed other entries (particularly the old next entry) as
1018 * a side effect (XXX).
1019 */
1020 next = ln->ln_next;
1021
1022 /*
1023 * Detach the route from the routing tree and the list of neighbor
1024 * caches, and disable the route entry not to be used in already
1025 * cached routes.
1026 */
1027 rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0,
1028 rt_mask(rt), 0, (struct rtentry **)0);
1029
1030 return(next);
1031}
1032
1033/*
1034 * Upper-layer reachability hint for Neighbor Unreachability Detection.
1035 *
1036 * XXX cost-effective metods?
1037 */
1038void

--- 38 unchanged lines hidden (view full) ---

1077 }
1078
1079 ln->ln_state = ND6_LLINFO_REACHABLE;
1080 if (ln->ln_expire)
1081 ln->ln_expire = time_second +
1082 nd_ifinfo[rt->rt_ifp->if_index].reachable;
1083}
1084
1085void
1086nd6_rtrequest(req, rt, sa)
1087 int req;
1088 struct rtentry *rt;
1089 struct sockaddr *sa; /* xxx unused */
1090{
1091 struct sockaddr *gate = rt->rt_gateway;
1092 struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1093 static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
1094 struct ifnet *ifp = rt->rt_ifp;
1095 struct ifaddr *ifa;
1096
1097 if (rt->rt_flags & RTF_GATEWAY)
1098 return;
1099
1100 if (nd6_need_cache(ifp) == 0 && (rt->rt_flags & RTF_HOST) == 0) {
1101 /*
1102 * This is probably an interface direct route for a link
1103 * which does not need neighbor caches (e.g. fe80::%lo0/64).
1104 * We do not need special treatment below for such a route.
1105 * Moreover, the RTF_LLINFO flag which would be set below
1106 * would annoy the ndp(8) command.
1107 */
1108 return;
1109 }
1110
1111 switch (req) {
1112 case RTM_ADD:
1113 /*
1114 * There is no backward compatibility :)
1115 *
1116 * if ((rt->rt_flags & RTF_HOST) == 0 &&
1117 * SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
1118 * rt->rt_flags |= RTF_CLONING;

--- 9 unchanged lines hidden (view full) ---

1128 (struct sockaddr *)&null_sdl);
1129 gate = rt->rt_gateway;
1130 SDL(gate)->sdl_type = ifp->if_type;
1131 SDL(gate)->sdl_index = ifp->if_index;
1132 if (ln)
1133 ln->ln_expire = time_second;
1134#if 1
1135 if (ln && ln->ln_expire == 0) {
1136 /* kludge for desktops */
1137#if 0
1138 printf("nd6_request: time.tv_sec is zero; "
1139 "treat it as 1\n");
1140#endif
1141 ln->ln_expire = 1;
1142 }
1143#endif
1144 if (rt->rt_flags & RTF_CLONING)

--- 4 unchanged lines hidden (view full) ---

1149 * We don't do that here since llinfo is not ready yet.
1150 *
1151 * There are also couple of other things to be discussed:
1152 * - unsolicited NA code needs improvement beforehand
1153 * - RFC2461 says we MAY send multicast unsolicited NA
1154 * (7.2.6 paragraph 4), however, it also says that we
1155 * SHOULD provide a mechanism to prevent multicast NA storm.
1156 * we don't have anything like it right now.
1157 * note that the mechanism needs a mutual agreement
1158 * between proxies, which means that we need to implement
1159 * a new protocol, or a new kludge.
1160 * - from RFC2461 6.2.4, host MUST NOT send an unsolicited NA.
1161 * we need to check ip6forwarding before sending it.
1162 * (or should we allow proxy ND configuration only for
1163 * routers? there's no mention about proxy ND from hosts)
1164 */
1165#if 0
1166 /* XXX it does not work */
1167 if (rt->rt_flags & RTF_ANNOUNCE)
1168 nd6_na_output(ifp,
1169 &SIN6(rt_key(rt))->sin6_addr,
1170 &SIN6(rt_key(rt))->sin6_addr,
1171 ip6_forwarding ? ND_NA_FLAG_ROUTER : 0,
1172 1, NULL);
1173#endif
1174 /* FALLTHROUGH */
1175 case RTM_RESOLVE:
1176 if ((ifp->if_flags & (IFF_POINTOPOINT | IFF_LOOPBACK)) == 0) {
1177 /*
1178 * Address resolution isn't necessary for a point to
1179 * point link, so we can skip this test for a p2p link.
1180 */
1181 if (gate->sa_family != AF_LINK ||
1182 gate->sa_len < sizeof(null_sdl)) {
1183 log(LOG_DEBUG,
1184 "nd6_rtrequest: bad gateway value: %s\n",
1185 if_name(ifp));
1186 break;
1187 }
1188 SDL(gate)->sdl_type = ifp->if_type;
1189 SDL(gate)->sdl_index = ifp->if_index;
1190 }
1191 if (ln != NULL)
1192 break; /* This happens on a route change */
1193 /*

--- 55 unchanged lines hidden (view full) ---

1249 * corresponding to the address.
1250 * We need this because when we refer
1251 * rt_ifa->ia6_flags in ip6_input, we assume
1252 * that the rt_ifa points to the address instead
1253 * of the loopback address.
1254 */
1255 if (ifa != rt->rt_ifa) {
1256 IFAFREE(rt->rt_ifa);
1257 IFAREF(ifa);
1258 rt->rt_ifa = ifa;
1259 }
1260 }
1261 } else if (rt->rt_flags & RTF_ANNOUNCE) {
1262 ln->ln_expire = 0;
1263 ln->ln_state = ND6_LLINFO_REACHABLE;
1264 ln->ln_byhint = 0;
1265

--- 4 unchanged lines hidden (view full) ---

1270
1271 llsol = SIN6(rt_key(rt))->sin6_addr;
1272 llsol.s6_addr16[0] = htons(0xff02);
1273 llsol.s6_addr16[1] = htons(ifp->if_index);
1274 llsol.s6_addr32[1] = 0;
1275 llsol.s6_addr32[2] = htonl(1);
1276 llsol.s6_addr8[12] = 0xff;
1277
1278 if (!in6_addmulti(&llsol, ifp, &error)) {
1279 nd6log((LOG_ERR, "%s: failed to join "
1280 "%s (errno=%d)\n", if_name(ifp),
1281 ip6_sprintf(&llsol), error));
1282 }
1283 }
1284 }
1285 break;
1286
1287 case RTM_DELETE:
1288 if (!ln)
1289 break;
1290 /* leave from solicited node multicast for proxy ND */

--- 20 unchanged lines hidden (view full) ---

1311 rt->rt_llinfo = 0;
1312 rt->rt_flags &= ~RTF_LLINFO;
1313 if (ln->ln_hold)
1314 m_freem(ln->ln_hold);
1315 Free((caddr_t)ln);
1316 }
1317}
1318
1319int
1320nd6_ioctl(cmd, data, ifp)
1321 u_long cmd;
1322 caddr_t data;
1323 struct ifnet *ifp;
1324{
1325 struct in6_drlist *drl = (struct in6_drlist *)data;
1326 struct in6_prlist *prl = (struct in6_prlist *)data;
1327 struct in6_ndireq *ndi = (struct in6_ndireq *)data;
1328 struct in6_nbrinfo *nbi = (struct in6_nbrinfo *)data;
1329 struct in6_ndifreq *ndif = (struct in6_ndifreq *)data;
1330 struct nd_defrouter *dr, any;
1331 struct nd_prefix *pr;
1332 struct rtentry *rt;
1333 int i = 0, error = 0;
1334 int s;
1335
1336 switch (cmd) {
1337 case SIOCGDRLST_IN6:
1338 /*
1339 * obsolete API, use sysctl under net.inet6.icmp6
1340 */
1341 bzero(drl, sizeof(*drl));
1342 s = splnet();
1343 dr = TAILQ_FIRST(&nd_defrouter);
1344 while (dr && i < DRLSTSIZ) {
1345 drl->defrouter[i].rtaddr = dr->rtaddr;
1346 if (IN6_IS_ADDR_LINKLOCAL(&drl->defrouter[i].rtaddr)) {
1347 /* XXX: need to this hack for KAME stack */
1348 drl->defrouter[i].rtaddr.s6_addr16[1] = 0;

--- 9 unchanged lines hidden (view full) ---

1358 drl->defrouter[i].if_index = dr->ifp->if_index;
1359 i++;
1360 dr = TAILQ_NEXT(dr, dr_entry);
1361 }
1362 splx(s);
1363 break;
1364 case SIOCGPRLST_IN6:
1365 /*
1366 * obsolete API, use sysctl under net.inet6.icmp6
1367 */
1368 /*
1369 * XXX meaning of fields, especialy "raflags", is very
1370 * differnet between RA prefix list and RR/static prefix list.
1371 * how about separating ioctls into two?
1372 */
1373 bzero(prl, sizeof(*prl));
1374 s = splnet();
1375 pr = nd_prefix.lh_first;
1376 while (pr && i < PRLSTSIZ) {
1377 struct nd_pfxrouter *pfr;
1378 int j;
1379
1380 (void)in6_embedscope(&prl->prefix[i].prefix,
1381 &pr->ndpr_prefix, NULL, NULL);
1382 prl->prefix[i].raflags = pr->ndpr_raf;
1383 prl->prefix[i].prefixlen = pr->ndpr_plen;
1384 prl->prefix[i].vltime = pr->ndpr_vltime;
1385 prl->prefix[i].pltime = pr->ndpr_pltime;
1386 prl->prefix[i].if_index = pr->ndpr_ifp->if_index;
1387 prl->prefix[i].expire = pr->ndpr_expire;
1388
1389 pfr = pr->ndpr_advrtrs.lh_first;
1390 j = 0;
1391 while (pfr) {
1392 if (j < DRLSTSIZ) {
1393#define RTRADDR prl->prefix[i].advrtr[j]
1394 RTRADDR = pfr->router->rtaddr;
1395 if (IN6_IS_ADDR_LINKLOCAL(&RTRADDR)) {
1396 /* XXX: hack for KAME */
1397 RTRADDR.s6_addr16[1] = 0;
1398 } else
1399 log(LOG_ERR,

--- 14 unchanged lines hidden (view full) ---

1414 }
1415 {
1416 struct rr_prefix *rpp;
1417
1418 for (rpp = LIST_FIRST(&rr_prefix); rpp;
1419 rpp = LIST_NEXT(rpp, rp_entry)) {
1420 if (i >= PRLSTSIZ)
1421 break;
1422 (void)in6_embedscope(&prl->prefix[i].prefix,
1423 &pr->ndpr_prefix, NULL, NULL);
1424 prl->prefix[i].raflags = rpp->rp_raf;
1425 prl->prefix[i].prefixlen = rpp->rp_plen;
1426 prl->prefix[i].vltime = rpp->rp_vltime;
1427 prl->prefix[i].pltime = rpp->rp_pltime;
1428 prl->prefix[i].if_index = rpp->rp_ifp->if_index;
1429 prl->prefix[i].expire = rpp->rp_expire;
1430 prl->prefix[i].advrtrs = 0;
1431 prl->prefix[i].origin = rpp->rp_origin;
1432 i++;
1433 }
1434 }
1435 splx(s);
1436
1437 break;
1438 case OSIOCGIFINFO_IN6:
1439 if (!nd_ifinfo || i >= nd_ifinfo_indexlim) {
1440 error = EINVAL;
1441 break;
1442 }
1443 ndi->ndi.linkmtu = nd_ifinfo[ifp->if_index].linkmtu;
1444 ndi->ndi.maxmtu = nd_ifinfo[ifp->if_index].maxmtu;
1445 ndi->ndi.basereachable =
1446 nd_ifinfo[ifp->if_index].basereachable;
1447 ndi->ndi.reachable = nd_ifinfo[ifp->if_index].reachable;
1448 ndi->ndi.retrans = nd_ifinfo[ifp->if_index].retrans;
1449 ndi->ndi.flags = nd_ifinfo[ifp->if_index].flags;
1450 ndi->ndi.recalctm = nd_ifinfo[ifp->if_index].recalctm;
1451 ndi->ndi.chlim = nd_ifinfo[ifp->if_index].chlim;
1452 ndi->ndi.receivedra = nd_ifinfo[ifp->if_index].receivedra;
1453 break;
1454 case SIOCGIFINFO_IN6:
1455 if (!nd_ifinfo || i >= nd_ifinfo_indexlim) {
1456 error = EINVAL;
1457 break;
1458 }
1459 ndi->ndi = nd_ifinfo[ifp->if_index];
1460 break;
1461 case SIOCSIFINFO_FLAGS:

--- 17 unchanged lines hidden (view full) ---

1479 break;
1480 case SIOCSPFXFLUSH_IN6:
1481 {
1482 /* flush all the prefix advertised by routers */
1483 struct nd_prefix *pr, *next;
1484
1485 s = splnet();
1486 for (pr = nd_prefix.lh_first; pr; pr = next) {
1487 struct in6_ifaddr *ia, *ia_next;
1488
1489 next = pr->ndpr_next;
1490
1491 if (IN6_IS_ADDR_LINKLOCAL(&pr->ndpr_prefix.sin6_addr))
1492 continue; /* XXX */
1493
1494 /* do we really have to remove addresses as well? */
1495 for (ia = in6_ifaddr; ia; ia = ia_next) {
1496 /* ia might be removed. keep the next ptr. */
1497 ia_next = ia->ia_next;
1498
1499 if ((ia->ia6_flags & IN6_IFF_AUTOCONF) == 0)
1500 continue;
1501
1502 if (ia->ia6_ndpr == pr)
1503 in6_purgeaddr(&ia->ia_ifa);
1504 }
1505 prelist_remove(pr);
1506 }
1507 splx(s);
1508 break;
1509 }
1510 case SIOCSRTRFLUSH_IN6:
1511 {
1512 /* flush all the default routers */

--- 102 unchanged lines hidden (view full) ---

1615#if 0
1616 /* nothing must be done if there's no lladdr */
1617 if (!lladdr || !lladdrlen)
1618 return NULL;
1619#endif
1620
1621 rt = nd6_lookup(from, 1, ifp);
1622 is_newentry = 1;
1623 } else {
1624 /* do nothing if static ndp is set */
1625 if (rt->rt_flags & RTF_STATIC)
1626 return NULL;
1627 is_newentry = 0;
1628 }
1629
1630 if (!rt)
1631 return NULL;
1632 if ((rt->rt_flags & (RTF_GATEWAY | RTF_LLINFO)) != RTF_LLINFO) {
1633fail:
1634 (void)nd6_free(rt);
1635 return NULL;
1636 }
1637 ln = (struct llinfo_nd6 *)rt->rt_llinfo;
1638 if (!ln)
1639 goto fail;
1640 if (!rt->rt_gateway)
1641 goto fail;
1642 if (rt->rt_gateway->sa_family != AF_LINK)

--- 46 unchanged lines hidden (view full) ---

1689
1690 if (do_update) {
1691 /*
1692 * Update the state of the neighbor cache.
1693 */
1694 ln->ln_state = newstate;
1695
1696 if (ln->ln_state == ND6_LLINFO_STALE) {
1697 /*
1698 * XXX: since nd6_output() below will cause
1699 * state tansition to DELAY and reset the timer,
1700 * we must set the timer now, although it is actually
1701 * meaningless.
1702 */
1703 ln->ln_expire = time_second + nd6_gctimer;
1704
1705 if (ln->ln_hold) {
1706 /*
1707 * we assume ifp is not a p2p here, so just
1708 * set the 2nd argument as the 1st one.
1709 */
1710 nd6_output(ifp, ifp, ln->ln_hold,
1711 (struct sockaddr_in6 *)rt_key(rt),
1712 rt);
1713 ln->ln_hold = NULL;
1714 }
1715 } else if (ln->ln_state == ND6_LLINFO_INCOMPLETE) {
1716 /* probe right away */
1717 ln->ln_expire = time_second;
1718 }
1719 }
1720
1721 /*

--- 64 unchanged lines hidden (view full) ---

1786 return rt;
1787}
1788
1789static void
1790nd6_slowtimo(ignored_arg)
1791 void *ignored_arg;
1792{
1793 int s = splnet();
1794 int i;
1795 struct nd_ifinfo *nd6if;
1796
1797 callout_reset(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz,
1798 nd6_slowtimo, NULL);
1799 for (i = 1; i < if_index + 1; i++) {
1800 if (!nd_ifinfo || i >= nd_ifinfo_indexlim)
1801 continue;
1802 nd6if = &nd_ifinfo[i];
1803 if (nd6if->basereachable && /* already initialized */
1804 (nd6if->recalctm -= ND6_SLOWTIMER_INTERVAL) <= 0) {
1805 /*
1806 * Since reachable time rarely changes by router

--- 6 unchanged lines hidden (view full) ---

1813 }
1814 }
1815 splx(s);
1816}
1817
1818#define senderr(e) { error = (e); goto bad;}
1819int
1820nd6_output(ifp, origifp, m0, dst, rt0)
1821 struct ifnet *ifp;
1822 struct ifnet *origifp;
1823 struct mbuf *m0;
1824 struct sockaddr_in6 *dst;
1825 struct rtentry *rt0;
1826{
1827 struct mbuf *m = m0;
1828 struct rtentry *rt = rt0;
1829 struct sockaddr_in6 *gw6 = NULL;
1830 struct llinfo_nd6 *ln = NULL;
1831 int error = 0;
1832
1833 if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr))
1834 goto sendpkt;
1835
1836 if (nd6_need_cache(ifp) == 0)
1837 goto sendpkt;
1838
1839 /*
1840 * next hop determination. This routine is derived from ether_outpout.
1841 */
1842 if (rt) {
1843 if ((rt->rt_flags & RTF_UP) == 0) {
1844 if ((rt0 = rt = rtalloc1((struct sockaddr *)dst, 1, 0UL)) !=
1845 NULL)

--- 9 unchanged lines hidden (view full) ---

1855 }
1856
1857 if (rt->rt_flags & RTF_GATEWAY) {
1858 gw6 = (struct sockaddr_in6 *)rt->rt_gateway;
1859
1860 /*
1861 * We skip link-layer address resolution and NUD
1862 * if the gateway is not a neighbor from ND point
1863 * of view, regardless the value of the
1864 * nd_ifinfo.flags.
1865 * The second condition is a bit tricky: we skip
1866 * if the gateway is our own address, which is
1867 * sometimes used to install a route to a p2p link.
1868 */
1869 if (!nd6_is_addr_neighbor(gw6, ifp) ||
1870 in6ifa_ifpwithaddr(ifp, &gw6->sin6_addr)) {
1871 /*
1872 * We allow this kind of tricky route only
1873 * when the outgoing interface is p2p.
1874 * XXX: we may need a more generic rule here.
1875 */
1876 if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
1877 senderr(EHOSTUNREACH);
1878

--- 4 unchanged lines hidden (view full) ---

1883 goto lookup;
1884 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
1885 rtfree(rt); rt = rt0;
1886 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 0UL);
1887 if ((rt = rt->rt_gwroute) == 0)
1888 senderr(EHOSTUNREACH);
1889 }
1890 }
1891 }
1892
1893 /*
1894 * Address resolution or Neighbor Unreachability Detection
1895 * for the next hop.
1896 * At this point, the destination of the packet must be a unicast
1897 * or an anycast address(i.e. not a multicast).
1898 */

--- 21 unchanged lines hidden (view full) ---

1920 senderr(EIO); /* XXX: good error? */
1921 }
1922
1923 goto sendpkt; /* send anyway */
1924 }
1925
1926 /* We don't have to do link-layer address resolution on a p2p link. */
1927 if ((ifp->if_flags & IFF_POINTOPOINT) != 0 &&
1928 ln->ln_state < ND6_LLINFO_REACHABLE) {
1929 ln->ln_state = ND6_LLINFO_STALE;
1930 ln->ln_expire = time_second + nd6_gctimer;
1931 }
1932
1933 /*
1934 * The first time we send a packet to a neighbor whose entry is
1935 * STALE, we have to change the state to DELAY and a sets a timer to
1936 * expire in DELAY_FIRST_PROBE_TIME seconds to ensure do
1937 * neighbor unreachability detection on expiration.
1938 * (RFC 2461 7.3.3)
1939 */

--- 14 unchanged lines hidden (view full) ---

1954 /*
1955 * There is a neighbor cache entry, but no ethernet address
1956 * response yet. Replace the held mbuf (if any) with this
1957 * latest one.
1958 *
1959 * XXX Does the code conform to rate-limiting rule?
1960 * (RFC 2461 7.2.2)
1961 */
1962 if (ln->ln_state == ND6_LLINFO_NOSTATE)
1963 ln->ln_state = ND6_LLINFO_INCOMPLETE;
1964 if (ln->ln_hold)
1965 m_freem(ln->ln_hold);
1966 ln->ln_hold = m;
1967 if (ln->ln_expire) {
1968 if (ln->ln_asked < nd6_mmaxtries &&
1969 ln->ln_expire < time_second) {
1970 ln->ln_asked++;
1971 ln->ln_expire = time_second +
1972 nd_ifinfo[ifp->if_index].retrans / 1000;
1973 nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0);
1974 }
1975 }
1976 return(0);
1977
1978 sendpkt:
1979
1980 if ((ifp->if_flags & IFF_LOOPBACK) != 0) {
1981 return((*ifp->if_output)(origifp, m, (struct sockaddr *)dst,
1982 rt));
1983 }
1984 return((*ifp->if_output)(ifp, m, (struct sockaddr *)dst, rt));
1985
1986 bad:
1987 if (m)
1988 m_freem(m);
1989 return (error);
1990}
1991#undef senderr
1992
1993int
1994nd6_need_cache(ifp)
1995 struct ifnet *ifp;
1996{
1997 /*
1998 * XXX: we currently do not make neighbor cache on any interface
1999 * other than ARCnet, Ethernet, FDDI and GIF.
2000 *
2001 * RFC2893 says:
2002 * - unidirectional tunnels needs no ND
2003 */
2004 switch (ifp->if_type) {
2005 case IFT_ARCNET:
2006 case IFT_ETHER:
2007 case IFT_FDDI:
2008 case IFT_IEEE1394:
2009#ifdef IFT_IEEE80211
2010 case IFT_IEEE80211:
2011#endif
2012 case IFT_GIF: /* XXX need more cases? */
2013 return(1);
2014 default:
2015 return(0);
2016 }
2017}
2018
2019int
2020nd6_storelladdr(ifp, rt, m, dst, desten)
2021 struct ifnet *ifp;
2022 struct rtentry *rt;
2023 struct mbuf *m;
2024 struct sockaddr *dst;
2025 u_char *desten;
2026{
2027 int i;
2028 struct sockaddr_dl *sdl;
2029
2030 if (m->m_flags & M_MCAST) {
2031 switch (ifp->if_type) {
2032 case IFT_ETHER:
2033 case IFT_FDDI:
2034#ifdef IFT_IEEE80211
2035 case IFT_IEEE80211:
2036#endif
2037 ETHER_MAP_IPV6_MULTICAST(&SIN6(dst)->sin6_addr,
2038 desten);
2039 return(1);
2040 case IFT_IEEE1394:
2041 for (i = 0; i < ifp->if_addrlen; i++)
2042 desten[i] = ~0;
2043 return(1);
2044 case IFT_ARCNET:
2045 *desten = 0;
2046 return(1);
2047 default:
2048 m_freem(m);
2049 return(0);
2050 }
2051 }
2052
2053 if (rt == NULL) {
2054 /* this could happen, if we could not allocate memory */
2055 m_freem(m);
2056 return(0);
2057 }
2058 if (rt->rt_gateway->sa_family != AF_LINK) {
2059 printf("nd6_storelladdr: something odd happens\n");
2060 m_freem(m);
2061 return(0);
2062 }
2063 sdl = SDL(rt->rt_gateway);
2064 if (sdl->sdl_alen == 0) {
2065 /* this should be impossible, but we bark here for debugging */
2066 printf("nd6_storelladdr: sdl_alen == 0\n");
2067 m_freem(m);
2068 return(0);
2069 }
2070
2071 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
2072 return(1);
2073}
2074
2075static int nd6_sysctl_drlist(SYSCTL_HANDLER_ARGS);
2076static int nd6_sysctl_prlist(SYSCTL_HANDLER_ARGS);
2077#ifdef SYSCTL_DECL
2078SYSCTL_DECL(_net_inet6_icmp6);
2079#endif
2080SYSCTL_NODE(_net_inet6_icmp6, ICMPV6CTL_ND6_DRLIST, nd6_drlist,
2081 CTLFLAG_RD, nd6_sysctl_drlist, "");
2082SYSCTL_NODE(_net_inet6_icmp6, ICMPV6CTL_ND6_PRLIST, nd6_prlist,
2083 CTLFLAG_RD, nd6_sysctl_prlist, "");
2084
2085static int
2086nd6_sysctl_drlist(SYSCTL_HANDLER_ARGS)
2087{
2088 int error;
2089 char buf[1024];
2090 struct in6_defrouter *d, *de;
2091 struct nd_defrouter *dr;
2092
2093 if (req->newptr)
2094 return EPERM;
2095 error = 0;
2096
2097 for (dr = TAILQ_FIRST(&nd_defrouter);
2098 dr;
2099 dr = TAILQ_NEXT(dr, dr_entry)) {
2100 d = (struct in6_defrouter *)buf;
2101 de = (struct in6_defrouter *)(buf + sizeof(buf));
2102
2103 if (d + 1 <= de) {
2104 bzero(d, sizeof(*d));
2105 d->rtaddr.sin6_family = AF_INET6;
2106 d->rtaddr.sin6_len = sizeof(d->rtaddr);
2107 if (in6_recoverscope(&d->rtaddr, &dr->rtaddr,
2108 dr->ifp) != 0)
2109 log(LOG_ERR,
2110 "scope error in "
2111 "default router list (%s)\n",
2112 ip6_sprintf(&dr->rtaddr));
2113 d->flags = dr->flags;
2114 d->rtlifetime = dr->rtlifetime;
2115 d->expire = dr->expire;
2116 d->if_index = dr->ifp->if_index;
2117 } else
2118 panic("buffer too short");
2119
2120 error = SYSCTL_OUT(req, buf, sizeof(*d));
2121 if (error)
2122 break;
2123 }
2124 return error;
2125}
2126
2127static int
2128nd6_sysctl_prlist(SYSCTL_HANDLER_ARGS)
2129{
2130 int error;
2131 char buf[1024];
2132 struct in6_prefix *p, *pe;
2133 struct nd_prefix *pr;
2134
2135 if (req->newptr)
2136 return EPERM;
2137 error = 0;
2138
2139 for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
2140 u_short advrtrs;
2141 size_t advance;
2142 struct sockaddr_in6 *sin6, *s6;
2143 struct nd_pfxrouter *pfr;
2144
2145 p = (struct in6_prefix *)buf;
2146 pe = (struct in6_prefix *)(buf + sizeof(buf));
2147
2148 if (p + 1 <= pe) {
2149 bzero(p, sizeof(*p));
2150 sin6 = (struct sockaddr_in6 *)(p + 1);
2151
2152 p->prefix = pr->ndpr_prefix;
2153 if (in6_recoverscope(&p->prefix,
2154 &p->prefix.sin6_addr, pr->ndpr_ifp) != 0)
2155 log(LOG_ERR,
2156 "scope error in prefix list (%s)\n",
2157 ip6_sprintf(&p->prefix.sin6_addr));
2158 p->raflags = pr->ndpr_raf;
2159 p->prefixlen = pr->ndpr_plen;
2160 p->vltime = pr->ndpr_vltime;
2161 p->pltime = pr->ndpr_pltime;
2162 p->if_index = pr->ndpr_ifp->if_index;
2163 p->expire = pr->ndpr_expire;
2164 p->refcnt = pr->ndpr_refcnt;
2165 p->flags = pr->ndpr_stateflags;
2166 p->origin = PR_ORIG_RA;
2167 advrtrs = 0;
2168 for (pfr = pr->ndpr_advrtrs.lh_first;
2169 pfr;
2170 pfr = pfr->pfr_next) {
2171 if ((void *)&sin6[advrtrs + 1] >
2172 (void *)pe) {
2173 advrtrs++;
2174 continue;
2175 }
2176 s6 = &sin6[advrtrs];
2177 bzero(s6, sizeof(*s6));
2178 s6->sin6_family = AF_INET6;
2179 s6->sin6_len = sizeof(*sin6);
2180 if (in6_recoverscope(s6,
2181 &pfr->router->rtaddr,
2182 pfr->router->ifp) != 0)
2183 log(LOG_ERR,
2184 "scope error in "
2185 "prefix list (%s)\n",
2186 ip6_sprintf(&pfr->router->rtaddr));
2187 advrtrs++;
2188 }
2189 p->advrtrs = advrtrs;
2190 } else
2191 panic("buffer too short");
2192
2193 advance = sizeof(*p) + sizeof(*sin6) * advrtrs;
2194 error = SYSCTL_OUT(req, buf, advance);
2195 if (error)
2196 break;
2197 }
2198 return error;
2199}