Deleted Added
full compact
nd6_rtr.c (53541) nd6_rtr.c (54263)
1/*
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
1/*
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: head/sys/netinet6/nd6_rtr.c 53541 1999-11-22 02:45:11Z shin $
29 * $FreeBSD: head/sys/netinet6/nd6_rtr.c 54263 1999-12-07 17:39:16Z shin $
30 */
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/malloc.h>
35#include <sys/mbuf.h>
36#include <sys/socket.h>
37#include <sys/sockio.h>

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

369
370struct nd_defrouter *
371defrouter_lookup(addr, ifp)
372 struct in6_addr *addr;
373 struct ifnet *ifp;
374{
375 struct nd_defrouter *dr;
376
30 */
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/malloc.h>
35#include <sys/mbuf.h>
36#include <sys/socket.h>
37#include <sys/sockio.h>

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

369
370struct nd_defrouter *
371defrouter_lookup(addr, ifp)
372 struct in6_addr *addr;
373 struct ifnet *ifp;
374{
375 struct nd_defrouter *dr;
376
377 for(dr = nd_defrouter.lh_first; dr; dr = dr->dr_next)
377 LIST_FOREACH(dr, &nd_defrouter, dr_entry)
378 if (dr->ifp == ifp && IN6_ARE_ADDR_EQUAL(addr, &dr->rtaddr))
379 return(dr);
380
381 return(NULL); /* search failed */
382}
383
384void
385defrouter_delreq(dr, dofree)

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

400 rtrequest(RTM_DELETE, (struct sockaddr *)&def,
401 (struct sockaddr *)&gate,
402 (struct sockaddr *)&mask,
403 RTF_GATEWAY, (struct rtentry **)0);
404
405 if (dofree)
406 free(dr, M_IP6NDP);
407
378 if (dr->ifp == ifp && IN6_ARE_ADDR_EQUAL(addr, &dr->rtaddr))
379 return(dr);
380
381 return(NULL); /* search failed */
382}
383
384void
385defrouter_delreq(dr, dofree)

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

400 rtrequest(RTM_DELETE, (struct sockaddr *)&def,
401 (struct sockaddr *)&gate,
402 (struct sockaddr *)&mask,
403 RTF_GATEWAY, (struct rtentry **)0);
404
405 if (dofree)
406 free(dr, M_IP6NDP);
407
408 if (nd_defrouter.lh_first)
409 defrouter_addreq(nd_defrouter.lh_first);
408 if (!LIST_EMPTY(&nd_defrouter))
409 defrouter_addreq(LIST_FIRST(&nd_defrouter));
410
411 /*
412 * xxx update the Destination Cache entries for all
413 * destinations using that neighbor as a router (7.2.5)
414 */
415}
416
417void

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

425 * Flush all the routing table entries that use the router
426 * as a next hop.
427 */
428 if (!ip6_forwarding && ip6_accept_rtadv) {
429 /* above is a good condition? */
430 rt6_flush(&dr->rtaddr, dr->ifp);
431 }
432
410
411 /*
412 * xxx update the Destination Cache entries for all
413 * destinations using that neighbor as a router (7.2.5)
414 */
415}
416
417void

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

425 * Flush all the routing table entries that use the router
426 * as a next hop.
427 */
428 if (!ip6_forwarding && ip6_accept_rtadv) {
429 /* above is a good condition? */
430 rt6_flush(&dr->rtaddr, dr->ifp);
431 }
432
433 if (dr == nd_defrouter.lh_first)
433 if (dr == LIST_FIRST(&nd_defrouter))
434 deldr = dr; /* The router is primary. */
435
436 LIST_REMOVE(dr, dr_entry);
437
438 /*
439 * Also delete all the pointers to the router in each prefix lists.
440 */
434 deldr = dr; /* The router is primary. */
435
436 LIST_REMOVE(dr, dr_entry);
437
438 /*
439 * Also delete all the pointers to the router in each prefix lists.
440 */
441 for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
441 LIST_FOREACH(pr, &nd_prefix, ndpr_entry) {
442 struct nd_pfxrouter *pfxrtr;
443 if ((pfxrtr = pfxrtr_lookup(pr, dr)) != NULL)
444 pfxrtr_del(pfxrtr);
445 }
446 pfxlist_onlink_check();
447
448 /*
449 * If the router is the primary one, delete the default route

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

484
485 n = (struct nd_defrouter *)malloc(sizeof(*n), M_IP6NDP, M_NOWAIT);
486 if (n == NULL) {
487 splx(s);
488 return(NULL);
489 }
490 bzero(n, sizeof(*n));
491 *n = *new;
442 struct nd_pfxrouter *pfxrtr;
443 if ((pfxrtr = pfxrtr_lookup(pr, dr)) != NULL)
444 pfxrtr_del(pfxrtr);
445 }
446 pfxlist_onlink_check();
447
448 /*
449 * If the router is the primary one, delete the default route

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

484
485 n = (struct nd_defrouter *)malloc(sizeof(*n), M_IP6NDP, M_NOWAIT);
486 if (n == NULL) {
487 splx(s);
488 return(NULL);
489 }
490 bzero(n, sizeof(*n));
491 *n = *new;
492 if (nd_defrouter.lh_first == NULL) {
492 if (LIST_EMPTY(&nd_defrouter)) {
493 LIST_INSERT_HEAD(&nd_defrouter, n, dr_entry);
494 defrouter_addreq(n);
495 } else {
493 LIST_INSERT_HEAD(&nd_defrouter, n, dr_entry);
494 defrouter_addreq(n);
495 } else {
496 LIST_INSERT_AFTER(nd_defrouter.lh_first, n, dr_entry);
496 LIST_INSERT_AFTER(LIST_FIRST(&nd_defrouter), n, dr_entry);
497 defrouter_addreq(n);
498 }
499 splx(s);
500
501 return(n);
502}
503
504static struct nd_pfxrouter *
505pfxrtr_lookup(pr, dr)
506 struct nd_prefix *pr;
507 struct nd_defrouter *dr;
508{
509 struct nd_pfxrouter *search;
497 defrouter_addreq(n);
498 }
499 splx(s);
500
501 return(n);
502}
503
504static struct nd_pfxrouter *
505pfxrtr_lookup(pr, dr)
506 struct nd_prefix *pr;
507 struct nd_defrouter *dr;
508{
509 struct nd_pfxrouter *search;
510
511 for (search = pr->ndpr_advrtrs.lh_first; search; search = search->pfr_next) {
510
511 LIST_FOREACH(search, &pr->ndpr_advrtrs, pfr_entry) {
512 if (search->router == dr)
513 break;
514 }
515
516 return(search);
517}
518
519static void

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

543}
544
545static struct nd_prefix *
546prefix_lookup(pr)
547 struct nd_prefix *pr;
548{
549 struct nd_prefix *search;
550
512 if (search->router == dr)
513 break;
514 }
515
516 return(search);
517}
518
519static void

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

543}
544
545static struct nd_prefix *
546prefix_lookup(pr)
547 struct nd_prefix *pr;
548{
549 struct nd_prefix *search;
550
551 for (search = nd_prefix.lh_first; search; search = search->ndpr_next) {
551 LIST_FOREACH(search, &nd_prefix, ndpr_entry) {
552 if (pr->ndpr_ifp == search->ndpr_ifp &&
553 pr->ndpr_plen == search->ndpr_plen &&
554 in6_are_prefix_equal(&pr->ndpr_prefix.sin6_addr,
555 &search->ndpr_prefix.sin6_addr,
556 pr->ndpr_plen)
557 ) {
558 break;
559 }

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

606 int s;
607
608 s = splnet();
609 /* unlink ndpr_entry from nd_prefix list */
610 LIST_REMOVE(pr, ndpr_entry);
611 splx(s);
612
613 /* free list of routers that adversed the prefix */
552 if (pr->ndpr_ifp == search->ndpr_ifp &&
553 pr->ndpr_plen == search->ndpr_plen &&
554 in6_are_prefix_equal(&pr->ndpr_prefix.sin6_addr,
555 &search->ndpr_prefix.sin6_addr,
556 pr->ndpr_plen)
557 ) {
558 break;
559 }

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

606 int s;
607
608 s = splnet();
609 /* unlink ndpr_entry from nd_prefix list */
610 LIST_REMOVE(pr, ndpr_entry);
611 splx(s);
612
613 /* free list of routers that adversed the prefix */
614 for (pfr = pr->ndpr_advrtrs.lh_first; pfr; pfr = next) {
615 next = pfr->pfr_next;
614 for (pfr = LIST_FIRST(&pr->ndpr_advrtrs); pfr; pfr = next) {
615 next = LIST_NEXT(pfr, pfr_entry);
616
617 free(pfr, M_IP6NDP);
618 }
619 free(pr, M_IP6NDP);
620
621 pfxlist_onlink_check();
622}
623

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

804 * routers are simply dead or if we really moved from the network and there
805 * is no router around us.
806 */
807static void
808pfxlist_onlink_check()
809{
810 struct nd_prefix *pr;
811
616
617 free(pfr, M_IP6NDP);
618 }
619 free(pr, M_IP6NDP);
620
621 pfxlist_onlink_check();
622}
623

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

804 * routers are simply dead or if we really moved from the network and there
805 * is no router around us.
806 */
807static void
808pfxlist_onlink_check()
809{
810 struct nd_prefix *pr;
811
812 for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next)
813 if (pr->ndpr_advrtrs.lh_first) /* pr has an available router */
812 LIST_FOREACH(pr, &nd_prefix, ndpr_entry)
813 if (!LIST_EMPTY(&pr->ndpr_advrtrs)) /* pr has an available router */
814 break;
815
816 if (pr) {
817 /*
818 * There is at least one prefix that has a router. First,
819 * detach prefixes which has no advertising router and then
820 * attach other prefixes. The order is important since an
821 * attached prefix and a detached prefix may have a same
822 * interface route.
823 */
814 break;
815
816 if (pr) {
817 /*
818 * There is at least one prefix that has a router. First,
819 * detach prefixes which has no advertising router and then
820 * attach other prefixes. The order is important since an
821 * attached prefix and a detached prefix may have a same
822 * interface route.
823 */
824 for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
825 if (pr->ndpr_advrtrs.lh_first == NULL &&
824 LIST_FOREACH(pr, &nd_prefix, ndpr_entry) {
825 if (LIST_EMPTY(&pr->ndpr_advrtrs) &&
826 pr->ndpr_statef_onlink) {
827 pr->ndpr_statef_onlink = 0;
828 nd6_detach_prefix(pr);
829 }
830 }
826 pr->ndpr_statef_onlink) {
827 pr->ndpr_statef_onlink = 0;
828 nd6_detach_prefix(pr);
829 }
830 }
831 for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
832 if (pr->ndpr_advrtrs.lh_first &&
831 LIST_FOREACH(pr, &nd_prefix, ndpr_entry) {
832 if (!LIST_EMPTY(&pr->ndpr_advrtrs) &&
833 pr->ndpr_statef_onlink == 0)
834 nd6_attach_prefix(pr);
835 }
836 } else {
837 /* there is no prefix that has a router */
833 pr->ndpr_statef_onlink == 0)
834 nd6_attach_prefix(pr);
835 }
836 } else {
837 /* there is no prefix that has a router */
838 for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next)
838 LIST_FOREACH(pr, &nd_prefix, ndpr_entry)
839 if (pr->ndpr_statef_onlink == 0)
840 nd6_attach_prefix(pr);
841 }
842}
843
844static void
845nd6_detach_prefix(pr)
846 struct nd_prefix *pr;

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

988 if ((oia = in6_ifaddr) != NULL) {
989 for( ; oia->ia_next; oia = oia->ia_next)
990 continue;
991 oia->ia_next = ia;
992 } else
993 in6_ifaddr = ia;
994
995 /* link to if_addrlist */
839 if (pr->ndpr_statef_onlink == 0)
840 nd6_attach_prefix(pr);
841 }
842}
843
844static void
845nd6_detach_prefix(pr)
846 struct nd_prefix *pr;

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

988 if ((oia = in6_ifaddr) != NULL) {
989 for( ; oia->ia_next; oia = oia->ia_next)
990 continue;
991 oia->ia_next = ia;
992 } else
993 in6_ifaddr = ia;
994
995 /* link to if_addrlist */
996 if (ifp->if_addrlist.tqh_first != NULL) {
996 if (!TAILQ_EMPTY(&ifp->if_addrlist)) {
997 TAILQ_INSERT_TAIL(&ifp->if_addrlist, (struct ifaddr *)ia,
998 ifa_list);
999 }
1000
1001 /* new address */
1002 ia->ia_addr.sin6_len = sizeof(struct sockaddr_in6);
1003 ia->ia_addr.sin6_family = AF_INET6;
1004 /* prefix */

--- 239 unchanged lines hidden ---
997 TAILQ_INSERT_TAIL(&ifp->if_addrlist, (struct ifaddr *)ia,
998 ifa_list);
999 }
1000
1001 /* new address */
1002 ia->ia_addr.sin6_len = sizeof(struct sockaddr_in6);
1003 ia->ia_addr.sin6_family = AF_INET6;
1004 /* prefix */

--- 239 unchanged lines hidden ---