changeset 4423:22c551e08f53 draft

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.
author Roy Marples <roy@marples.name>
date Wed, 10 Apr 2019 14:10:42 +0100
parents 344851420e71
children 439a039862f7
files src/dhcp6.c src/dhcp6.h
diffstat 2 files changed, 30 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/dhcp6.c	Tue Apr 02 13:35:51 2019 +0100
+++ b/src/dhcp6.c	Wed Apr 10 14:10:42 2019 +0100
@@ -1913,13 +1913,16 @@
 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 @@
 		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 @@
 	}
 	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 @@
 		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 @@
 
 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 @@
 	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;
 	}
 }
 
--- a/src/dhcp6.h	Tue Apr 02 13:35:51 2019 +0100
+++ b/src/dhcp6.h	Wed Apr 10 14:10:42 2019 +0100
@@ -206,7 +206,7 @@
 	/* 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;
 };