From 047235d751f655120613923724587abc36921b84 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 19 May 2014 00:49:14 +0000 Subject: [PATCH] If a DHCPv6 lease expires as well as all IPv6 routers who want DHCPv6, don't restart discover. --- dhcp6.c | 7 ++++++- dhcpcd.c | 4 ++-- ipv6nd.c | 20 ++++++++++++++++++-- ipv6nd.h | 3 ++- script.c | 6 +++--- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/dhcp6.c b/dhcp6.c index 8c27bcc4..d18da6ed 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -1142,7 +1142,12 @@ dhcp6_startexpire(void *arg) dhcp6_freedrop_addrs(ifp, 1, NULL); dhcp6_delete_delegates(ifp); script_runreason(ifp, "EXPIRE6"); - dhcp6_startdiscover(ifp); + if (ipv6nd_hasradhcp(ifp)) + dhcp6_startdiscover(ifp); + else + syslog(LOG_WARNING, + "%s: no advertising IPv6 router wants DHCP", + ifp->name); } static void diff --git a/dhcpcd.c b/dhcpcd.c index fe869c11..5e142009 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1001,7 +1001,7 @@ dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd, len++; if (D6_STATE_RUNNING(ifp)) len++; - if (ipv6nd_has_ra(ifp)) + if (ipv6nd_hasra(ifp)) len++; } if (write(fd->fd, &len, sizeof(len)) != @@ -1024,7 +1024,7 @@ dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd, len++; if (D6_STATE_RUNNING(ifp)) len++; - if (ipv6nd_has_ra(ifp)) + if (ipv6nd_hasra(ifp)) len++; } } diff --git a/ipv6nd.c b/ipv6nd.c index da3817b6..9977fd06 100644 --- a/ipv6nd.c +++ b/ipv6nd.c @@ -1022,18 +1022,34 @@ handle_flag: } int -ipv6nd_has_ra(const struct interface *ifp) +ipv6nd_hasra(const struct interface *ifp) { const struct ra *rap; if (ifp->ctx->ipv6) { TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) - if (rap->iface == ifp) + if (rap->iface == ifp && !rap->expired) return 1; } return 0; } +int +ipv6nd_hasradhcp(const struct interface *ifp) +{ + const struct ra *rap; + + if (ifp->ctx->ipv6) { + TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) { + if (rap->iface == ifp && + !rap->expired && + (rap->flags & (ND_RA_FLAG_MANAGED | ND_RA_FLAG_OTHER))) + return 1; + } + } + return 0; +} + ssize_t ipv6nd_env(char **env, const char *prefix, const struct interface *ifp) { diff --git a/ipv6nd.h b/ipv6nd.h index 9dbbdf63..6c52c1fd 100644 --- a/ipv6nd.h +++ b/ipv6nd.h @@ -90,7 +90,8 @@ void ipv6nd_freedrop_ra(struct ra *, int); #define ipv6nd_drop_ra(ra) ipv6nd_freedrop_ra((ra), 1) ssize_t ipv6nd_free(struct interface *); void ipv6nd_expirera(void *arg); -int ipv6nd_has_ra(const struct interface *); +int ipv6nd_hasra(const struct interface *); +int ipv6nd_hasradhcp(const struct interface *); void ipv6nd_handleifa(struct dhcpcd_ctx *, int, const char *, const struct in6_addr *, int); void ipv6nd_drop(struct interface *); diff --git a/script.c b/script.c index bbc9006a..e3f34050 100644 --- a/script.c +++ b/script.c @@ -249,7 +249,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) #ifdef INET6 else if (d6_state && d6_state->new) dhcp6 = 1; - else if (ipv6nd_has_ra(ifp)) + else if (ipv6nd_hasra(ifp)) ra = 1; #endif #ifdef INET @@ -336,7 +336,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv) #endif #ifdef INET6 || (dhcp6 && d6_state && d6_state->new) - || (ra && ipv6nd_has_ra(ifp)) + || (ra && ipv6nd_hasra(ifp)) #endif ) { @@ -557,7 +557,7 @@ send_interface(int fd, const struct interface *ifp) #endif #ifdef INET6 - if (ipv6nd_has_ra(ifp)) { + if (ipv6nd_hasra(ifp)) { if (send_interface1(fd, ifp, "ROUTERADVERT") == -1) retval = -1; } -- 2.47.3