Provide TAILQ_FOREACH_REVERSE_SAFE if not defined.

When removing routes, do it in reverse order.
This commit is contained in:
Roy Marples 2012-10-31 20:14:08 +00:00
parent 7e5b6d033e
commit 6855bff4c4
2 changed files with 7 additions and 0 deletions

5
configure vendored
View File

@ -213,6 +213,7 @@ if [ -n "$DEBUG" -a "$DEBUG" != no -a "$DEBUG" != false ]; then
elif [ -z "$DEBUG" -a -d .git ]; then
printf "Found git ... "
DEBUG=yes
echo "CFLAGS+= -ggdb" >>$CONFIG_MK
else
DEBUG=no
fi
@ -404,6 +405,10 @@ if [ "$TAILQ_FOREACH_SAFE" = no ]; then
for ((var) = TAILQ_FIRST((head)); \
(var) && ((next) = TAILQ_NEXT((var), field), 1); \
(var) = (next))
#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, prev) \
for ((var) = TAILQ_LAST((head), headname); \
(var) && ((prev) = TAILQ_PREV((var), headname, field), 1);\
(var) = (prev))
EOF
fi

2
ipv6.c
View File

@ -437,6 +437,7 @@ ipv6_build_routes(void)
* If we own the default route, but not RA management itself
* then we need to preserve the last best default route we had */
TAILQ_FOREACH_REVERSE_SAFE(rt, routes, rt6head, next, rtn) {
TAILQ_REMOVE(routes, rt, next);
if (find_route6(nrs, rt) == NULL) {
if (!have_default &&
(options & DHCPCD_IPV6RA_OWN_DEFAULT) &&
@ -451,6 +452,7 @@ ipv6_build_routes(void)
}
free(rt);
}
free(routes);
routes = nrs;
}