From: Roy Marples Date: Wed, 20 Jan 2016 19:08:12 +0000 (+0000) Subject: Fix delegation activating interfaces. X-Git-Tag: v6.10.1^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4507db941053c5af9608b7884f6abe1150cc5fa2;p=thirdparty%2Fdhcpcd.git Fix delegation activating interfaces. --- diff --git a/dhcp6.c b/dhcp6.c index 5f8ced85..9abe78e7 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -2482,14 +2482,20 @@ dhcp6_delegate_prefix(struct interface *ifp) 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 --git a/dhcpcd.c b/dhcpcd.c index 5ca9f321..5255ec2e 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -670,6 +670,41 @@ dhcpcd_pollup(void *arg) 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,67 +982,44 @@ dhcpcd_prestartinterface(void *arg) } 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) +run_preinit(struct interface *ifp) { - struct if_options *ifo; - configure_interface(ifp, argc, argv, options); - ifo = ifp->options; + pre_start(ifp); + if (ifp->ctx->options & DHCPCD_TEST) + return; - 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; - } + script_runreason(ifp, "PREINIT"); - /* 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; - } + if (ifp->options->options & DHCPCD_LINK && ifp->carrier != LINK_UNKNOWN) + script_runreason(ifp, + ifp->carrier == LINK_UP ? "CARRIER" : "NOCARRIER"); } void -dhcpcd_initstate(struct interface *ifp, unsigned long long options) +dhcpcd_activateinterface(struct interface *ifp) { - dhcpcd_initstate1(ifp, ifp->ctx->argc, ifp->ctx->argv, options); + if (!ifp->active) { + ifp->active = 1; + dhcpcd_initstate(ifp, 0); + run_preinit(ifp); + dhcpcd_prestartinterface(ifp); + } } static void -run_preinit(struct interface *ifp) +handle_link(void *arg) { + struct dhcpcd_ctx *ctx; - pre_start(ifp); - if (ifp->ctx->options & DHCPCD_TEST) - return; - - script_runreason(ifp, "PREINIT"); - - if (ifp->options->options & DHCPCD_LINK && ifp->carrier != LINK_UNKNOWN) - script_runreason(ifp, - ifp->carrier == LINK_UP ? "CARRIER" : "NOCARRIER"); + 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 diff --git a/dhcpcd.h b/dhcpcd.h index 2de383f8..3ad73664 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -202,6 +202,6 @@ void dhcpcd_dropinterface(struct interface *, const char *); 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