From: Roy Marples Date: Wed, 10 Apr 2019 13:10:42 +0000 (+0100) Subject: DHCP6: Don't spam syslog if we get the same error over and over X-Git-Tag: v7.2.0~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4772fd28fd6564ffe6d39677a8214e4591b7a29;p=thirdparty%2Fdhcpcd.git DHCP6: Don't spam syslog if we get the same error over and over It will still be spammy if we ask for more than one IA and one of them has an error, but that's for another day. --- diff --git a/src/dhcp6.c b/src/dhcp6.c index cc226787..99a452bb 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -1913,13 +1913,16 @@ static int dhcp6_checkstatusok(const struct interface *ifp, struct dhcp6_message *m, uint8_t *p, size_t len) { + struct dhcp6_state *state; uint8_t *opt; uint16_t opt_len, code; size_t mlen; void * (*f)(void *, size_t, uint16_t, uint16_t *), *farg; char buf[32], *sbuf; const char *status; + logfunc_t *logfunc; + state = D6_STATE(ifp); f = p ? dhcp6_findoption : dhcp6_findmoption; if (p) farg = p; @@ -1927,6 +1930,7 @@ dhcp6_checkstatusok(const struct interface *ifp, farg = m; if ((opt = f(farg, len, D6_OPTION_STATUS_CODE, &opt_len)) == NULL) { //logdebugx("%s: no status", ifp->name); + state->lerror = 0; return 0; } @@ -1936,8 +1940,10 @@ dhcp6_checkstatusok(const struct interface *ifp, } memcpy(&code, opt, sizeof(code)); code = ntohs(code); - if (code == D6_STATUS_OK) + if (code == D6_STATUS_OK) { + state->lerror = 0; return 1; + } /* Anything after the code is a message. */ opt += sizeof(code); @@ -1960,8 +1966,13 @@ dhcp6_checkstatusok(const struct interface *ifp, status = sbuf; } - logerrx("%s: DHCPv6 REPLY: %s", ifp->name, status); + if (state->lerror == code || state->state == DH6S_INIT) + logfunc = logdebugx; + else + logfunc = logerrx; + logfunc("%s: DHCPv6 REPLY: %s", ifp->name, status); free(sbuf); + state->lerror = code; return -1; } @@ -3794,6 +3805,7 @@ dhcp6_start(struct interface *ifp, enum DH6S init_state) gogogo: state->state = init_state; + state->lerror = 0; dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile), AF_INET6, ifp); if (ipv6_linklocal(ifp) == NULL) { @@ -3813,18 +3825,20 @@ dhcp6_reboot(struct interface *ifp) struct dhcp6_state *state; state = D6_STATE(ifp); - if (state) { - switch (state->state) { - case DH6S_BOUND: - dhcp6_startrebind(ifp); - break; - case DH6S_INFORMED: - dhcp6_startinform(ifp); - break; - default: - dhcp6_startdiscover(ifp); - break; - } + if (state == NULL) + return; + + state->lerror = 0; + switch (state->state) { + case DH6S_BOUND: + dhcp6_startrebind(ifp); + break; + case DH6S_INFORMED: + dhcp6_startinform(ifp); + break; + default: + dhcp6_startdiscover(ifp); + break; } } diff --git a/src/dhcp6.h b/src/dhcp6.h index e1a0a374..a670566d 100644 --- a/src/dhcp6.h +++ b/src/dhcp6.h @@ -206,7 +206,7 @@ struct dhcp6_state { /* The +3 is for the possible .pd extension for prefix delegation */ char leasefile[sizeof(LEASEFILE6) + IF_NAMESIZE + (IF_SSIDLEN * 4) +3]; const char *reason; - + uint16_t lerror; /* Last error received from DHCPv6 reply. */ struct authstate auth; };