diff options
| author | Roy Marples <roy@marples.name> | 2015-12-17 02:34:36 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2015-12-17 02:34:36 +0000 |
| commit | 80e9033d457ea1522a19c605d921d39f35c6b6b5 (patch) | |
| tree | f3172c636847f692201b5b9a2676db22d108c1d5 /dhcpcd.c | |
| parent | 363c200a57af680f43327706f70c2297ea85303c (diff) | |
| download | dhcpcd-80e9033d457ea1522a19c605d921d39f35c6b6b5.tar.xz | |
Instead of maintaining a seperate list, instead mark each interface as active
dhcpcd will actively work on.
This will allow dhcpcd to move addresses around interfaces much more easily
as well.
Diffstat (limited to 'dhcpcd.c')
| -rw-r--r-- | dhcpcd.c | 84 |
1 files changed, 56 insertions, 28 deletions
@@ -228,6 +228,9 @@ dhcpcd_ifafwaiting(const struct interface *ifp) { unsigned long long opts; + if (!ifp->active) + return AF_MAX; + opts = ifp->options->options; if (opts & DHCPCD_WAITIP4 && !ipv4_hasaddr(ifp)) return AF_INET; @@ -392,6 +395,9 @@ stop_interface(struct interface *ifp) struct dhcpcd_ctx *ctx; ctx = ifp->ctx; + if (!ifp->active) + goto stop; + logger(ctx, LOG_INFO, "%s: removing interface", ifp->name); ifp->options->options |= DHCPCD_STOPPING; @@ -401,6 +407,7 @@ stop_interface(struct interface *ifp) else script_runreason(ifp, "STOPPED"); +stop: /* Delete all timeouts for the interfaces */ eloop_q_timeout_delete(ctx->eloop, 0, NULL, ifp); @@ -658,7 +665,9 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags, struct interface *ifp; ifp = if_find(ctx->ifaces, ifname); - if (ifp == NULL || !(ifp->options->options & DHCPCD_LINK)) + if (ifp == NULL || + ifp->options == NULL || !(ifp->options->options & DHCPCD_LINK) || + !ifp->active) return; switch(carrier) { @@ -754,7 +763,7 @@ warn_iaid_conflict(struct interface *ifp, uint8_t *iaid) size_t i; TAILQ_FOREACH(ifn, ifp->ctx->ifaces, next) { - if (ifn == ifp) + if (ifn == ifp || !ifn->active) continue; if (memcmp(ifn->options->iaid, iaid, sizeof(ifn->options->iaid)) == 0) @@ -1005,7 +1014,9 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname) errno = ESRCH; return -1; } - logger(ctx, LOG_DEBUG, "%s: interface departed", ifp->name); + if (ifp->active) + logger(ctx, LOG_DEBUG, "%s: interface departed", + ifp->name); ifp->options->options |= DHCPCD_DEPARTED; stop_interface(ifp); return 0; @@ -1027,7 +1038,7 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname) return -1; } TAILQ_FOREACH_SAFE(ifp, ifs, next, ifn) { - if (strcmp(ifp->name, ifname) != 0) + if (!ifp->active || strcmp(ifp->name, ifname) != 0) continue; i = 0; /* Check if we already have the interface */ @@ -1133,6 +1144,10 @@ reconf_reboot(struct dhcpcd_ctx *ctx, int action, int argc, char **argv, int oi) while ((ifp = TAILQ_FIRST(ifs))) { TAILQ_REMOVE(ifs, ifp, next); + if (!(ifp->active)) { + if_free(ifp); + continue; + } ifn = if_find(ctx->ifaces, ifp->name); if (ifn) { if (action) @@ -1157,10 +1172,12 @@ stop_all_interfaces(struct dhcpcd_ctx *ctx, unsigned long long opts) /* Drop the last interface first */ while ((ifp = TAILQ_LAST(ctx->ifaces, if_head)) != NULL) { - ifp->options->options |= opts; - if (ifp->options->options & DHCPCD_RELEASE) - ifp->options->options &= ~DHCPCD_PERSISTENT; - ifp->options->options |= DHCPCD_EXITING; + if (ifp->options) { + ifp->options->options |= opts; + if (ifp->options->options & DHCPCD_RELEASE) + ifp->options->options &= ~DHCPCD_PERSISTENT; + ifp->options->options |= DHCPCD_EXITING; + } stop_interface(ifp); } } @@ -1257,6 +1274,8 @@ dhcpcd_getinterfaces(void *arg) len = 0; TAILQ_FOREACH(ifp, fd->ctx->ifaces, next) { + if (!ifp->active) + continue; len++; if (D_STATE_RUNNING(ifp)) len++; @@ -1271,6 +1290,8 @@ dhcpcd_getinterfaces(void *arg) return; eloop_event_remove_writecb(fd->ctx->eloop, fd->fd); TAILQ_FOREACH(ifp, fd->ctx->ifaces, next) { + if (!ifp->active) + continue; if (send_interface(fd, ifp) == -1) logger(ifp->ctx, LOG_ERR, "send_interface %d: %m", fd->fd); @@ -1641,7 +1662,7 @@ main(int argc, char **argv) logger(&ctx, LOG_ERR, "if_discover: %m"); goto exit_failure; } - ifp = TAILQ_FIRST(ctx.ifaces); + ifp = if_find(ctx.ifaces, argv[optind]); if (ifp == NULL) { ifp = calloc(1, sizeof(*ifp)); if (ifp == NULL) { @@ -1845,12 +1866,17 @@ main(int argc, char **argv) goto exit_failure; } for (i = 0; i < ctx.ifc; i++) { - if (if_find(ctx.ifaces, ctx.ifv[i]) == NULL) + if ((ifp = if_find(ctx.ifaces, ctx.ifv[i])) == NULL || + !ifp->active) logger(&ctx, LOG_ERR, "%s: interface not found or invalid", ctx.ifv[i]); } - if (TAILQ_FIRST(ctx.ifaces) == NULL) { + TAILQ_FOREACH(ifp, ctx.ifaces, next) { + if (ifp->active) + break; + } + if (ifp == NULL) { if (ctx.ifc == 0) logger(&ctx, LOG_ERR, "no valid interfaces found"); else @@ -1863,7 +1889,8 @@ main(int argc, char **argv) } TAILQ_FOREACH(ifp, ctx.ifaces, next) { - dhcpcd_initstate1(ifp, argc, argv, 0); + if (ifp->active) + dhcpcd_initstate1(ifp, argc, argv, 0); } if (ctx.options & DHCPCD_BACKGROUND && dhcpcd_daemonise(&ctx)) @@ -1871,19 +1898,26 @@ main(int argc, char **argv) opt = 0; TAILQ_FOREACH(ifp, ctx.ifaces, next) { - run_preinit(ifp); - if (!(ifp->options->options & DHCPCD_LINK) || - ifp->carrier != LINK_DOWN) - opt = 1; + if (ifp->active) { + run_preinit(ifp); + if (!(ifp->options->options & DHCPCD_LINK) || + ifp->carrier != LINK_DOWN) + opt = 1; + } } if (!(ctx.options & DHCPCD_BACKGROUND)) { if (ctx.options & DHCPCD_MASTER) t = ifo->timeout; - else if ((ifp = TAILQ_FIRST(ctx.ifaces))) - t = ifp->options->timeout; - else + else { t = 0; + TAILQ_FOREACH(ifp, ctx.ifaces, next) { + if (ifp->active) { + t = ifp->options->timeout; + break; + } + } + } if (opt == 0 && ctx.options & DHCPCD_LINK && !(ctx.options & DHCPCD_WAITIP)) @@ -1905,8 +1939,9 @@ main(int argc, char **argv) if_sortinterfaces(&ctx); TAILQ_FOREACH(ifp, ctx.ifaces, next) { - eloop_timeout_add_sec(ctx.eloop, 0, - dhcpcd_prestartinterface, ifp); + if (ifp->active) + eloop_timeout_add_sec(ctx.eloop, 0, + dhcpcd_prestartinterface, ifp); } i = eloop_start(ctx.eloop, &ctx.sigset); @@ -1932,13 +1967,6 @@ exit1: } free(ctx.ifaces); } - if (ctx.oifaces) { - while ((ifp = TAILQ_FIRST(ctx.oifaces))) { - TAILQ_REMOVE(ctx.oifaces, ifp, next); - if_free(ifp); - } - free(ctx.oifaces); - } free(ctx.duid); if (ctx.link_fd != -1) { eloop_event_delete(ctx.eloop, ctx.link_fd); |
