summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2011-12-27 17:20:05 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2011-12-27 17:20:05 +0000
commite0891b4ca3efb31863ea5a1987c25d1c6976b25f (patch)
treec152cd161a038de02ee3d33f138e0d156f40b533
parentbe4bbf253b62bd86f1110a865e92fd732f70199d (diff)
Instead of hand crafted code, use the macros TAILQ_FOREACH(_SAFE)
and TAILQ_EMPTY for accessing the nd_defrouter list. No funtional change. ok stsp@
-rw-r--r--sys/netinet6/nd6.c40
-rw-r--r--sys/netinet6/nd6_rtr.c23
2 files changed, 21 insertions, 42 deletions
diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c
index 9068f6fe21c..28cf0fa6f92 100644
--- a/sys/netinet6/nd6.c
+++ b/sys/netinet6/nd6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nd6.c,v 1.89 2011/12/02 03:15:31 haesbaert Exp $ */
+/* $OpenBSD: nd6.c,v 1.90 2011/12/27 17:20:04 bluhm Exp $ */
/* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */
/*
@@ -507,7 +507,7 @@ void
nd6_timer(void *ignored_arg)
{
int s;
- struct nd_defrouter *dr;
+ struct nd_defrouter *dr, *ndr;
struct nd_prefix *pr;
struct in6_ifaddr *ia6, *nia6;
@@ -516,17 +516,9 @@ nd6_timer(void *ignored_arg)
timeout_add_sec(&nd6_timer_ch, nd6_prune);
/* expire default router list */
- dr = TAILQ_FIRST(&nd_defrouter);
- while (dr) {
- if (dr->expire && dr->expire < time_second) {
- struct nd_defrouter *t;
- t = TAILQ_NEXT(dr, dr_entry);
+ TAILQ_FOREACH_SAFE(dr, &nd_defrouter, dr_entry, ndr)
+ if (dr->expire && dr->expire < time_second)
defrtrlist_del(dr);
- dr = t;
- } else {
- dr = TAILQ_NEXT(dr, dr_entry);
- }
- }
/*
* expire interface addresses.
@@ -593,16 +585,14 @@ nd6_purge(struct ifnet *ifp)
* in the routing table, in order to keep additional side effects as
* small as possible.
*/
- for (dr = TAILQ_FIRST(&nd_defrouter); dr; dr = ndr) {
- ndr = TAILQ_NEXT(dr, dr_entry);
+ TAILQ_FOREACH_SAFE(dr, &nd_defrouter, dr_entry, ndr) {
if (dr->installed)
continue;
if (dr->ifp == ifp)
defrtrlist_del(dr);
}
- for (dr = TAILQ_FIRST(&nd_defrouter); dr; dr = ndr) {
- ndr = TAILQ_NEXT(dr, dr_entry);
+ TAILQ_FOREACH_SAFE(dr, &nd_defrouter, dr_entry, ndr) {
if (!dr->installed)
continue;
@@ -808,7 +798,7 @@ nd6_is_addr_neighbor(struct sockaddr_in6 *addr, struct ifnet *ifp)
* XXX: we restrict the condition to hosts, because routers usually do
* not have the "default router list".
*/
- if (!ip6_forwarding && TAILQ_FIRST(&nd_defrouter) == NULL &&
+ if (!ip6_forwarding && TAILQ_EMPTY(&nd_defrouter) &&
nd6_defifindex == ifp->if_index) {
return (1);
}
@@ -1292,8 +1282,9 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
*/
bzero(drl, sizeof(*drl));
s = splsoftnet();
- dr = TAILQ_FIRST(&nd_defrouter);
- while (dr && i < DRLSTSIZ) {
+ TAILQ_FOREACH(dr, &nd_defrouter, dr_entry) {
+ if (i >= DRLSTSIZ)
+ break;
drl->defrouter[i].rtaddr = dr->rtaddr;
if (IN6_IS_ADDR_LINKLOCAL(&drl->defrouter[i].rtaddr)) {
/* XXX: need to this hack for KAME stack */
@@ -1309,7 +1300,6 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
drl->defrouter[i].expire = dr->expire;
drl->defrouter[i].if_index = dr->ifp->if_index;
i++;
- dr = TAILQ_NEXT(dr, dr_entry);
}
splx(s);
break;
@@ -1426,14 +1416,12 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
case SIOCSRTRFLUSH_IN6:
{
/* flush all the default routers */
- struct nd_defrouter *dr, *next;
+ struct nd_defrouter *dr, *ndr;
s = splsoftnet();
defrouter_reset();
- for (dr = TAILQ_FIRST(&nd_defrouter); dr; dr = next) {
- next = TAILQ_NEXT(dr, dr_entry);
+ TAILQ_FOREACH_SAFE(dr, &nd_defrouter, dr_entry, ndr)
defrtrlist_del(dr);
- }
defrouter_select();
splx(s);
break;
@@ -2082,9 +2070,7 @@ fill_drlist(void *oldp, size_t *oldlenp, size_t ol)
}
l = 0;
- for (dr = TAILQ_FIRST(&nd_defrouter); dr;
- dr = TAILQ_NEXT(dr, dr_entry)) {
-
+ TAILQ_FOREACH(dr, &nd_defrouter, dr_entry) {
if (oldp && d + 1 <= de) {
bzero(d, sizeof(*d));
d->rtaddr.sin6_family = AF_INET6;
diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c
index 3c890e30ead..16591e8be83 100644
--- a/sys/netinet6/nd6_rtr.c
+++ b/sys/netinet6/nd6_rtr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nd6_rtr.c,v 1.56 2011/11/24 17:39:55 sperreault Exp $ */
+/* $OpenBSD: nd6_rtr.c,v 1.57 2011/12/27 17:20:04 bluhm Exp $ */
/* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */
/*
@@ -476,12 +476,9 @@ defrouter_lookup(struct in6_addr *addr, struct ifnet *ifp)
{
struct nd_defrouter *dr;
- for (dr = TAILQ_FIRST(&nd_defrouter); dr;
- dr = TAILQ_NEXT(dr, dr_entry)) {
- if (dr->ifp == ifp && IN6_ARE_ADDR_EQUAL(addr, &dr->rtaddr)) {
+ TAILQ_FOREACH(dr, &nd_defrouter, dr_entry)
+ if (dr->ifp == ifp && IN6_ARE_ADDR_EQUAL(addr, &dr->rtaddr))
return (dr);
- }
- }
return (NULL); /* search failed */
}
@@ -591,8 +588,7 @@ defrouter_reset(void)
{
struct nd_defrouter *dr;
- for (dr = TAILQ_FIRST(&nd_defrouter); dr;
- dr = TAILQ_NEXT(dr, dr_entry))
+ TAILQ_FOREACH(dr, &nd_defrouter, dr_entry)
defrouter_delreq(dr);
/*
@@ -648,7 +644,7 @@ defrouter_select(void)
* Let's handle easy case (3) first:
* If default router list is empty, there's nothing to be done.
*/
- if (!TAILQ_FIRST(&nd_defrouter)) {
+ if (TAILQ_EMPTY(&nd_defrouter)) {
splx(s);
return;
}
@@ -658,8 +654,7 @@ defrouter_select(void)
* We just pick up the first reachable one (if any), assuming that
* the ordering rule of the list described in defrtrlist_update().
*/
- for (dr = TAILQ_FIRST(&nd_defrouter); dr;
- dr = TAILQ_NEXT(dr, dr_entry)) {
+ TAILQ_FOREACH(dr, &nd_defrouter, dr_entry) {
if (!selected_dr &&
(rt = nd6_lookup(&dr->rtaddr, 0, dr->ifp)) &&
(ln = (struct llinfo_nd6 *)rt->rt_llinfo) &&
@@ -819,11 +814,9 @@ insert:
*/
/* insert at the end of the group */
- for (dr = TAILQ_FIRST(&nd_defrouter); dr;
- dr = TAILQ_NEXT(dr, dr_entry)) {
+ TAILQ_FOREACH(dr, &nd_defrouter, dr_entry)
if (rtpref(n) > rtpref(dr))
break;
- }
if (dr)
TAILQ_INSERT_BEFORE(dr, n, dr_entry);
else
@@ -1400,7 +1393,7 @@ pfxlist_onlink_check(void)
if (pr->ndpr_raf_onlink && find_pfxlist_reachable_router(pr))
break;
}
- if (pr != NULL || TAILQ_FIRST(&nd_defrouter) != NULL) {
+ if (pr != NULL || !TAILQ_EMPTY(&nd_defrouter)) {
/*
* There is at least one prefix that has a reachable router,
* or at least a router which probably does not advertise