# HG changeset patch # User Roy Marples # Date 1453316892 0 # Node ID df62940aacb7b4bf99f10ae7125caf5671699b4b # Parent e07f5afe803868d6a0e26c289f232fc4b39bc2cd Fix delegation activating interfaces. diff -r e07f5afe8038 -r df62940aacb7 dhcp6.c --- a/dhcp6.c Wed Jan 20 17:41:12 2016 +0000 +++ b/dhcp6.c Wed Jan 20 19:08:12 2016 +0000 @@ -2482,14 +2482,20 @@ for (k = 0; k < i; j++) if (strcmp(sla->ifname, ia->sla[j].ifname) == 0) break; - if (j >= i && - ((ifd = if_find(ifp->ctx->ifaces, - sla->ifname)) == NULL || - !ifd->active)) - logger(ifp->ctx, LOG_ERR, - "%s: interface does not exist" - " for delegation", - sla->ifname); + if (j >= i) { + ifd = if_find(ifp->ctx->ifaces, sla->ifname); + if (ifd == NULL) + logger(ifp->ctx, LOG_ERR, + "%s: interface does not exist" + " for delegation", + sla->ifname); + else if (!ifd->active) { + logger(ifp->ctx, LOG_INFO, + "%s: activating for delegation", + sla->ifname); + dhcpcd_activateinterface(ifd); + } + } } } diff -r e07f5afe8038 -r df62940aacb7 dhcpcd.c --- a/dhcpcd.c Wed Jan 20 17:41:12 2016 +0000 +++ b/dhcpcd.c Wed Jan 20 19:08:12 2016 +0000 @@ -670,6 +670,41 @@ dhcpcd_handlecarrier(ifp->ctx, carrier, ifp->flags, ifp->name); } +static void +dhcpcd_initstate1(struct interface *ifp, int argc, char **argv, + unsigned long long options) +{ + struct if_options *ifo; + + configure_interface(ifp, argc, argv, options); + ifo = ifp->options; + + if (ifo->options & DHCPCD_IPV4 && ipv4_init(ifp->ctx) == -1) { + logger(ifp->ctx, LOG_ERR, "ipv4_init: %m"); + ifo->options &= ~DHCPCD_IPV4; + } + if (ifo->options & DHCPCD_IPV6 && ipv6_init(ifp->ctx) == NULL) { + logger(ifp->ctx, LOG_ERR, "ipv6_init: %m"); + ifo->options &= ~DHCPCD_IPV6RS; + } + + /* Add our link-local address before upping the interface + * so our RFC7217 address beats the hwaddr based one. + * This needs to happen before PREINIT incase a hook script + * inadvertently ups the interface. */ + if (ifo->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) { + logger(ifp->ctx, LOG_ERR, "%s: ipv6_start: %m", ifp->name); + ifo->options &= ~DHCPCD_IPV6; + } +} + +static void +dhcpcd_initstate(struct interface *ifp, unsigned long long options) +{ + + dhcpcd_initstate1(ifp, ifp->ctx->argc, ifp->ctx->argv, options); +} + void dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags, const char *ifname) @@ -947,55 +982,6 @@ } static void -handle_link(void *arg) -{ - struct dhcpcd_ctx *ctx; - - ctx = arg; - if (if_managelink(ctx) == -1) { - logger(ctx, LOG_ERR, "if_managelink: %m"); - eloop_event_delete(ctx->eloop, ctx->link_fd); - close(ctx->link_fd); - ctx->link_fd = -1; - } -} - -static void -dhcpcd_initstate1(struct interface *ifp, int argc, char **argv, - unsigned long long options) -{ - struct if_options *ifo; - - configure_interface(ifp, argc, argv, options); - ifo = ifp->options; - - if (ifo->options & DHCPCD_IPV4 && ipv4_init(ifp->ctx) == -1) { - logger(ifp->ctx, LOG_ERR, "ipv4_init: %m"); - ifo->options &= ~DHCPCD_IPV4; - } - if (ifo->options & DHCPCD_IPV6 && ipv6_init(ifp->ctx) == NULL) { - logger(ifp->ctx, LOG_ERR, "ipv6_init: %m"); - ifo->options &= ~DHCPCD_IPV6RS; - } - - /* Add our link-local address before upping the interface - * so our RFC7217 address beats the hwaddr based one. - * This needs to happen before PREINIT incase a hook script - * inadvertently ups the interface. */ - if (ifo->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) { - logger(ifp->ctx, LOG_ERR, "%s: ipv6_start: %m", ifp->name); - ifo->options &= ~DHCPCD_IPV6; - } -} - -void -dhcpcd_initstate(struct interface *ifp, unsigned long long options) -{ - - dhcpcd_initstate1(ifp, ifp->ctx->argc, ifp->ctx->argv, options); -} - -static void run_preinit(struct interface *ifp) { @@ -1010,6 +996,32 @@ ifp->carrier == LINK_UP ? "CARRIER" : "NOCARRIER"); } +void +dhcpcd_activateinterface(struct interface *ifp) +{ + + if (!ifp->active) { + ifp->active = 1; + dhcpcd_initstate(ifp, 0); + run_preinit(ifp); + dhcpcd_prestartinterface(ifp); + } +} + +static void +handle_link(void *arg) +{ + struct dhcpcd_ctx *ctx; + + ctx = arg; + if (if_managelink(ctx) == -1) { + logger(ctx, LOG_ERR, "if_managelink: %m"); + eloop_event_delete(ctx->eloop, ctx->link_fd); + close(ctx->link_fd); + ctx->link_fd = -1; + } +} + int dhcpcd_handleinterface(void *arg, int action, const char *ifname) { diff -r e07f5afe8038 -r df62940aacb7 dhcpcd.h --- a/dhcpcd.h Wed Jan 20 17:41:12 2016 +0000 +++ b/dhcpcd.h Wed Jan 20 19:08:12 2016 +0000 @@ -202,6 +202,6 @@ int dhcpcd_selectprofile(struct interface *, const char *); void dhcpcd_startinterface(void *); -void dhcpcd_initstate(struct interface *, unsigned long long); +void dhcpcd_activateinterface(struct interface *); #endif