summaryrefslogtreecommitdiff
path: root/sys/netinet6/nd6.c
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2013-03-22 00:59:26 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2013-03-22 00:59:26 +0000
commitb494bdf66d3502687b52a978a754bb6437fc727d (patch)
tree9c5ae1e711c26b0214521be0634ee0d1c40f6012 /sys/netinet6/nd6.c
parentda3133822455abb95cc346e6c265c8443876c624 (diff)
Replace hand-crafted nd_prefix loops with LIST_FOREACH macros.
OK mpi@
Diffstat (limited to 'sys/netinet6/nd6.c')
-rw-r--r--sys/netinet6/nd6.c37
1 files changed, 12 insertions, 25 deletions
diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c
index 00bc15d82f9..52394f0bd36 100644
--- a/sys/netinet6/nd6.c
+++ b/sys/netinet6/nd6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nd6.c,v 1.95 2013/03/11 14:08:04 mpi Exp $ */
+/* $OpenBSD: nd6.c,v 1.96 2013/03/22 00:59:25 bluhm Exp $ */
/* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */
/*
@@ -508,7 +508,7 @@ nd6_timer(void *ignored_arg)
{
int s;
struct nd_defrouter *dr, *ndr;
- struct nd_prefix *pr;
+ struct nd_prefix *pr, *npr;
struct in6_ifaddr *ia6, *nia6;
s = splsoftnet();
@@ -543,8 +543,7 @@ nd6_timer(void *ignored_arg)
}
/* expire prefix list */
- pr = LIST_FIRST(&nd_prefix);
- while (pr != NULL) {
+ LIST_FOREACH_SAFE(pr, &nd_prefix, ndpr_entry, npr) {
/*
* check prefix lifetime.
* since pltime is just for autoconf, pltime processing for
@@ -552,18 +551,13 @@ nd6_timer(void *ignored_arg)
*/
if (pr->ndpr_vltime != ND6_INFINITE_LIFETIME &&
time_second - pr->ndpr_lastupdate > pr->ndpr_vltime) {
- struct nd_prefix *t;
- t = LIST_NEXT(pr, ndpr_entry);
-
/*
* address expiration and prefix expiration are
* separate. NEVER perform in6_purgeaddr here.
*/
prelist_remove(pr);
- pr = t;
- } else
- pr = LIST_NEXT(pr, ndpr_entry);
+ }
}
splx(s);
}
@@ -601,8 +595,7 @@ nd6_purge(struct ifnet *ifp)
}
/* Nuke prefix list entries toward ifp */
- for (pr = LIST_FIRST(&nd_prefix); pr != NULL; pr = npr) {
- npr = LIST_NEXT(pr, ndpr_entry);
+ LIST_FOREACH_SAFE(pr, &nd_prefix, ndpr_entry, npr) {
if (pr->ndpr_ifp == ifp) {
/*
* Because if_detach() does *not* release prefixes
@@ -1302,11 +1295,12 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
*/
bzero(oprl, sizeof(*oprl));
s = splsoftnet();
- pr = LIST_FIRST(&nd_prefix);
- while (pr && i < PRLSTSIZ) {
+ LIST_FOREACH(pr, &nd_prefix, ndpr_entry) {
struct nd_pfxrouter *pfr;
int j;
+ if (i >= PRLSTSIZ)
+ break;
oprl->prefix[i].prefix = pr->ndpr_prefix.sin6_addr;
oprl->prefix[i].raflags = pr->ndpr_raf;
oprl->prefix[i].prefixlen = pr->ndpr_plen;
@@ -1315,9 +1309,8 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
oprl->prefix[i].if_index = pr->ndpr_ifp->if_index;
oprl->prefix[i].expire = pr->ndpr_expire;
- pfr = LIST_FIRST(&pr->ndpr_advrtrs);
j = 0;
- while(pfr) {
+ LIST_FOREACH(pfr, &pr->ndpr_advrtrs, pfr_entry) {
if (j < DRLSTSIZ) {
#define RTRADDR oprl->prefix[i].advrtr[j]
RTRADDR = pfr->router->rtaddr;
@@ -1333,13 +1326,11 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
#undef RTRADDR
}
j++;
- pfr = LIST_NEXT(pfr, pfr_entry);
}
oprl->prefix[i].advrtrs = j;
oprl->prefix[i].origin = PR_ORIG_RA;
i++;
- pr = LIST_NEXT(pr, ndpr_entry);
}
splx(s);
@@ -1370,15 +1361,13 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
case SIOCSPFXFLUSH_IN6:
{
/* flush all the prefix advertised by routers */
- struct nd_prefix *pr, *next;
+ struct nd_prefix *pr, *npr;
s = splsoftnet();
/* First purge the addresses referenced by a prefix. */
- for (pr = LIST_FIRST(&nd_prefix); pr; pr = next) {
+ LIST_FOREACH_SAFE(pr, &nd_prefix, ndpr_entry, npr) {
struct in6_ifaddr *ia, *ia_next;
- next = LIST_NEXT(pr, ndpr_entry);
-
if (IN6_IS_ADDR_LINKLOCAL(&pr->ndpr_prefix.sin6_addr))
continue; /* XXX */
@@ -1399,9 +1388,7 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
* So run the loop again to access only prefixes that have
* not been freed already.
*/
- for (pr = LIST_FIRST(&nd_prefix); pr; pr = next) {
- next = LIST_NEXT(pr, ndpr_entry);
-
+ LIST_FOREACH_SAFE(pr, &nd_prefix, ndpr_entry, npr) {
if (IN6_IS_ADDR_LINKLOCAL(&pr->ndpr_prefix.sin6_addr))
continue; /* XXX */