From: Roy Marples Date: Mon, 15 Jul 2019 16:13:43 +0000 (+0100) Subject: route: Compare AF_UNSPEC family when cleaning old routes X-Git-Tag: v8.0.0~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57abb730681c1f357d30ea0db618a81147be7398;p=thirdparty%2Fdhcpcd.git route: Compare AF_UNSPEC family when cleaning old routes --- diff --git a/src/route.c b/src/route.c index 5e79fb6b..a0bb2a1c 100644 --- a/src/route.c +++ b/src/route.c @@ -685,8 +685,10 @@ rt_build(struct dhcpcd_ctx *ctx, int af) } RB_TREE_FOREACH_SAFE(rt, &routes, rtn) { - if (rt->rt_dest.sa_family != af && - rt->rt_gateway.sa_family != af) + if ((rt->rt_dest.sa_family != af && + rt->rt_dest.sa_family != AF_UNSPEC) || + (rt->rt_gateway.sa_family != af && + rt->rt_gateway.sa_family != AF_UNSPEC)) continue; /* Is this route already in our table? */ if (rb_tree_find_node(&added, rt) != NULL) @@ -702,12 +704,14 @@ rt_build(struct dhcpcd_ctx *ctx, int af) } /* Remove old routes we used to manage. */ - while ((rt = RB_TREE_MAX(&ctx->routes)) != NULL) { + RB_TREE_FOREACH_REVERSE_SAFE(rt, &ctx->routes, rtn) { + if ((rt->rt_dest.sa_family != af && + rt->rt_dest.sa_family != AF_UNSPEC) || + (rt->rt_gateway.sa_family != af && + rt->rt_gateway.sa_family != AF_UNSPEC)) + continue; rb_tree_remove_node(&ctx->routes, rt); - if (rt->rt_dest.sa_family == af && - rt->rt_gateway.sa_family == af && - rb_tree_find_node(&added, rt) == NULL) - { + if (rb_tree_find_node(&added, rt) == NULL) { o = rt->rt_ifp->options ? rt->rt_ifp->options->options : ctx->options;