From: Roy Marples Date: Fri, 17 Apr 2020 12:25:33 +0000 (+0100) Subject: DHCP6: don't log when things consitently fail X-Git-Tag: v9.0.2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aab713261e1ca792b4bf9228317c77ccc300f392;p=thirdparty%2Fdhcpcd.git DHCP6: don't log when things consitently fail For example, the RA says obtain more inforamtion via DHCPv6 but there is no DHCPv6 server to service the request. --- diff --git a/src/dhcp6.c b/src/dhcp6.c index e59a5aeb..3103e7e0 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -1585,6 +1585,7 @@ dhcp6_startdiscover(void *arg) { struct interface *ifp; struct dhcp6_state *state; + int llevel; ifp = arg; state = D6_STATE(ifp); @@ -1592,7 +1593,11 @@ dhcp6_startdiscover(void *arg) if (state->reason == NULL || strcmp(state->reason, "TIMEOUT6") != 0) dhcp6_delete_delegates(ifp); #endif - loginfox("%s: soliciting a DHCPv6 lease", ifp->name); + if (state->new == NULL && !state->failed) + llevel = LOG_INFO; + else + llevel = LOG_DEBUG; + logmessage(llevel, "%s: soliciting a DHCPv6 lease", ifp->name); state->state = DH6S_DISCOVER; state->RTC = 0; state->IMD = SOL_MAX_DELAY; @@ -1616,11 +1621,15 @@ dhcp6_startinform(void *arg) { struct interface *ifp; struct dhcp6_state *state; + int llevel; ifp = arg; state = D6_STATE(ifp); - if (state->new == NULL || ifp->options->options & DHCPCD_DEBUG) - loginfox("%s: requesting DHCPv6 information", ifp->name); + if (state->new == NULL && !state->failed) + llevel = LOG_INFO; + else + llevel = LOG_DEBUG; + logmessage(llevel, "%s: requesting DHCPv6 information", ifp->name); state->state = DH6S_INFORM; state->RTC = 0; state->IMD = INF_MAX_DELAY; @@ -1677,6 +1686,8 @@ dhcp6_fail(struct interface* ifp) { struct dhcp6_state *state = D6_STATE(ifp); + state->failed = true; + /* RFC3315 18.1.2 says that prior addresses SHOULD be used on failure. * RFC2131 3.2.3 says that MAY chose to use the prior address. * Because dhcpcd was written first for RFC2131, we have the LASTLEASE @@ -1711,33 +1722,43 @@ dhcp6_fail(struct interface* ifp) } } +static int +dhcp6_failloglevel(struct interface *ifp) +{ + const struct dhcp6_state *state = D6_CSTATE(ifp); + + return state->failed ? LOG_DEBUG : LOG_ERR; +} + static void dhcp6_failconfirm(void *arg) { - struct interface *ifp; + struct interface *ifp = arg; + int llevel = dhcp6_failloglevel(ifp); - ifp = arg; - logerrx("%s: failed to confirm prior address", ifp->name); + logmessage(llevel, "%s: failed to confirm prior DHCPv6 address", + ifp->name); dhcp6_fail(ifp); } static void dhcp6_failrequest(void *arg) { - struct interface *ifp; + struct interface *ifp = arg; + int llevel = dhcp6_failloglevel(ifp); - ifp = arg; - logerrx("%s: failed to request address", ifp->name); + logmessage(llevel, "%s: failed to request DHCPv6 address", ifp->name); dhcp6_fail(ifp); } static void dhcp6_failinform(void *arg) { - struct interface *ifp; + struct interface *ifp = arg; + int llevel = dhcp6_failloglevel(ifp); - ifp = arg; - logerrx("%s: failed to request information", ifp->name); + logmessage(llevel, "%s: failed to request DHCPv6 information", + ifp->name); dhcp6_fail(ifp); } @@ -1745,10 +1766,9 @@ dhcp6_failinform(void *arg) static void dhcp6_failrebind(void *arg) { - struct interface *ifp; + struct interface *ifp = arg; - ifp = arg; - logerrx("%s: failed to rebind prior delegation", ifp->name); + logerrx("%s: failed to rebind prior DHCPv6 delegation", ifp->name); dhcp6_fail(ifp); } @@ -3124,6 +3144,7 @@ dhcp6_bind(struct interface *ifp, const char *op, const char *sfrom) state->state = DH6S_INFORMED; else state->state = DH6S_BOUND; + state->failed = false; if (state->renew && state->renew != ND6_INFINITE_LIFETIME) eloop_timeout_add_sec(ifp->ctx->eloop, @@ -3857,6 +3878,7 @@ dhcp6_start(struct interface *ifp, enum DH6S init_state) gogogo: state->state = init_state; state->lerror = 0; + state->failed = false; dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile), AF_INET6, ifp); if (ipv6_linklocal(ifp) == NULL) { diff --git a/src/dhcp6.h b/src/dhcp6.h index c7d11889..73341cde 100644 --- a/src/dhcp6.h +++ b/src/dhcp6.h @@ -211,7 +211,10 @@ struct dhcp6_state { const char *reason; uint16_t lerror; /* Last error received from DHCPv6 reply. */ bool has_no_binding; + bool failed; /* Entered the failed state - used to rate limit log. */ +#ifdef AUTH struct authstate auth; +#endif }; #define D6_STATE(ifp) \