From: Roy Marples Date: Mon, 4 Mar 2019 11:48:04 +0000 (+0000) Subject: if: No more need for interface sorting X-Git-Tag: v8.0.0~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=769ff1adf7e596879fe33b84447cf95d1aaa0904;p=thirdparty%2Fdhcpcd.git if: No more need for interface sorting --- diff --git a/src/dhcp6.c b/src/dhcp6.c index 6e83a70f..da5242fd 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -2825,20 +2825,6 @@ dhcp6_delegate_prefix(struct interface *ifp) struct dhcp6_state *s = D6_STATE(ifd); ipv6_addaddrs(&s->addrs); - - /* - * Can't add routes here because that will trigger - * interface sorting which may break the current - * enumeration. - * This doesn't really matter thanks to DaD because - * calling the script will be delayed and routes - * will get re-built if needed first. - * This only cause minor confusion when dhcpcd is - * restarted and confirms a lease where prior delegation - * has already been assigned, because it will log it - * added routes after the script has run. - * The routes should still be there and fine though. - */ dhcp6_script_try_run(ifd, 1); } } diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 384107a8..f7927140 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -2092,7 +2092,6 @@ printpidfile: free_options(&ctx, ifo); ifo = NULL; - if_sortinterfaces(&ctx); TAILQ_FOREACH(ifp, ctx.ifaces, next) { if (ifp->active) eloop_timeout_add_sec(ctx.eloop, 0, diff --git a/src/if.c b/src/if.c index 95067c77..d58ecb8a 100644 --- a/src/if.c +++ b/src/if.c @@ -720,87 +720,6 @@ if_domtu(const struct interface *ifp, short int mtu) return ifr.ifr_mtu; } -/* Interface comparer for working out ordering. */ -static int -if_cmp(const struct interface *si, const struct interface *ti) -{ -#ifdef INET - int r; -#endif - - /* Check active first */ - if (si->active > ti->active) - return -1; - if (si->active < ti->active) - return 1; - - /* Check carrier status next */ - if (si->carrier > ti->carrier) - return -1; - if (si->carrier < ti->carrier) - return 1; -#ifdef INET - if (D_STATE_RUNNING(si) && !D_STATE_RUNNING(ti)) - return -1; - if (!D_STATE_RUNNING(si) && D_STATE_RUNNING(ti)) - return 1; -#endif -#ifdef INET6 - if (RS_STATE_RUNNING(si) && !RS_STATE_RUNNING(ti)) - return -1; - if (!RS_STATE_RUNNING(si) && RS_STATE_RUNNING(ti)) - return 1; -#endif -#ifdef DHCP6 - if (D6_STATE_RUNNING(si) && !D6_STATE_RUNNING(ti)) - return -1; - if (!D6_STATE_RUNNING(si) && D6_STATE_RUNNING(ti)) - return 1; -#endif - -#ifdef INET - /* Special attention needed here due to states and IPv4LL. */ - if ((r = ipv4_ifcmp(si, ti)) != 0) - return r; -#endif - - /* Finally, metric */ - if (si->metric < ti->metric) - return -1; - if (si->metric > ti->metric) - return 1; - return 0; -} - -/* Sort the interfaces into a preferred order - best first, worst last. */ -void -if_sortinterfaces(struct dhcpcd_ctx *ctx) -{ - struct if_head sorted; - struct interface *ifp, *ift; - - if (ctx->ifaces == NULL || - (ifp = TAILQ_FIRST(ctx->ifaces)) == NULL || - TAILQ_NEXT(ifp, next) == NULL) - return; - - TAILQ_INIT(&sorted); - TAILQ_REMOVE(ctx->ifaces, ifp, next); - TAILQ_INSERT_HEAD(&sorted, ifp, next); - while ((ifp = TAILQ_FIRST(ctx->ifaces))) { - TAILQ_REMOVE(ctx->ifaces, ifp, next); - TAILQ_FOREACH(ift, &sorted, next) { - if (if_cmp(ifp, ift) == -1) { - TAILQ_INSERT_BEFORE(ift, ifp, next); - break; - } - } - if (ift == NULL) - TAILQ_INSERT_TAIL(&sorted, ifp, next); - } - TAILQ_CONCAT(ctx->ifaces, &sorted, next); -} - struct interface * if_findifpfromcmsg(struct dhcpcd_ctx *ctx, struct msghdr *msg, int *hoplimit) { diff --git a/src/if.h b/src/if.h index 2f20764c..1aac439b 100644 --- a/src/if.h +++ b/src/if.h @@ -122,7 +122,6 @@ void if_deletestaleaddrs(struct if_head *); struct interface *if_find(struct if_head *, const char *); struct interface *if_findindex(struct if_head *, unsigned int); struct interface *if_loopback(struct dhcpcd_ctx *); -void if_sortinterfaces(struct dhcpcd_ctx *); void if_free(struct interface *); int if_domtu(const struct interface *, short int); #define if_getmtu(ifp) if_domtu((ifp), 0)