changeset 4927:f2d637554e89 draft

arp: use eloop_timespec_diff to handle wrapped times
author Roy Marples <roy@marples.name>
date Tue, 07 Jan 2020 22:28:55 +0000
parents 5aae8c49e9f3
children 3cb7e75517a7
files src/arp.c
diffstat 1 files changed, 3 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/arp.c	Tue Jan 07 22:28:25 2020 +0000
+++ b/src/arp.c	Tue Jan 07 22:28:55 2020 +0000
@@ -140,7 +140,7 @@
 	struct interface *ifp;
 	struct ipv4_addr *ia;
 #ifndef KERNEL_RFC5227
-	struct timespec now, defend;
+	struct timespec now;
 #endif
 
 	arp_report_conflicted(astate, amsg);
@@ -163,10 +163,9 @@
 	 * messages.
 	 * If another conflict happens within DEFEND_INTERVAL
 	 * then we must drop our address and negotiate a new one. */
-	defend.tv_sec = astate->defend.tv_sec + DEFEND_INTERVAL;
-	defend.tv_nsec = astate->defend.tv_nsec;
 	clock_gettime(CLOCK_MONOTONIC, &now);
-	if (timespeccmp(&defend, &now, >))
+	if (timespecisset(&astate->defend) &&
+	    eloop_timespec_diff(&astate->defend, &now, NULL) < DEFEND_INTERVAL)
 		logwarnx("%s: %d second defence failed for %s",
 		    ifp->name, DEFEND_INTERVAL, inet_ntoa(astate->addr));
 	else if (arp_request(ifp, &astate->addr, &astate->addr) == -1)