[icinga-checkins] icinga.org: icinga-nsca/mfriedrich/fixes: allow packets arriving with a future time stamp (Daniel Wittenberg) #2101

git at icinga.org git at icinga.org
Wed Nov 23 18:34:29 CET 2011


Module: icinga-nsca
Branch: mfriedrich/fixes
Commit: 83f5f7ff8ab5f75bc639df7851999d646a2f7a54
URL:    https://git.icinga.org/?p=icinga-nsca.git;a=commit;h=83f5f7ff8ab5f75bc639df7851999d646a2f7a54

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Wed Nov 23 18:34:16 2011 +0100

allow packets arriving with a future time stamp (Daniel Wittenberg) #2101

refs #2101

---

 Changelog  |    3 ++-
 THANKS     |    1 +
 src/nsca.c |   33 +++++++++++++--------------------
 3 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/Changelog b/Changelog
index 16c6a46..112cf7f 100644
--- a/Changelog
+++ b/Changelog
@@ -8,9 +8,10 @@ ENHANCEMENTS
 * add IPv6 support
 * add config directive to submit directly to checkresults directory (Mike Lindsey) #2100
 	** --with-checkresult-dir=<path> for configure
-* Support multi-line check output with 4000 character limit (Mike Lindsey) #2101
+* Support multi-line check output with 4000 character limit (Mike Lindsey) #2100
 
 FIXES
+* allow packets arriving with a future time stamp (Daniel Wittenberg) #2101
 
 CHANGES
 
diff --git a/THANKS b/THANKS
index 5e6893f..d7e07ff 100644
--- a/THANKS
+++ b/THANKS
@@ -20,4 +20,5 @@ If we missed your name, let us know.
 * Ton Voon
 * Holger Weiss
 * Chris Wilson
+* Daniel Wittenberg
 * Daniel ?
diff --git a/src/nsca.c b/src/nsca.c
index 4712dbf..731c496 100644
--- a/src/nsca.c
+++ b/src/nsca.c
@@ -1131,39 +1131,32 @@ static void handle_connection_read(int sock, void *data) {
 			do_exit(STATE_OK);
 	}
 
+	/* host name */
+	strncpy(host_name, receive_packet.host_name, sizeof(host_name) - 1);
+	host_name[sizeof(host_name) - 1] = '\0';
+
 	/* check the timestamp in the packet */
-	packet_time = (time_t)ntohl(receive_packet.timestamp);
-	time(&current_time);
-	if (packet_time > current_time) {
-		syslog(LOG_ERR, "Dropping packet with future timestamp.");
-		/*return;*/
-		close(sock);
-		if (mode == SINGLE_PROCESS_DAEMON)
-			return;
-		else
-			do_exit(STATE_OK);
-	} else {
-		packet_age = (unsigned long)(current_time - packet_time);
-		if (max_packet_age > 0 && (packet_age > max_packet_age)) {
-			syslog(LOG_ERR, "Dropping packet with stale timestamp - packet was %lu seconds old.", packet_age);
-			/*return;*/
+	packet_age = (unsigned long)(current_time - packet_time);
+	if (debug == TRUE)
+		syslog(LOG_ERR, "Time difference in packet: %lu seconds for host %s", packet_age, host_name);
+
+	if ((max_packet_age > 0 && (packet_age > max_packet_age) && (packet_age >= 0)) ||
+	        ((max_packet_age > 0) && (packet_age < (0 - max_packet_age)) && (packet_age < 0))
+	   ) {
+			syslog(LOG_ERR, "Dropping packet with stale timestamp for %s - packet was %lu seconds old.", host_name, packet_age);
+
 			close(sock);
 			if (mode == SINGLE_PROCESS_DAEMON)
 				return;
 			else
 				do_exit(STATE_OK);
 		}
-	}
 
 	/**** GET THE SERVICE CHECK INFORMATION ****/
 
 	/* plugin return code */
 	return_code = ntohs(receive_packet.return_code);
 
-	/* host name */
-	strncpy(host_name, receive_packet.host_name, sizeof(host_name) - 1);
-	host_name[sizeof(host_name) - 1] = '\0';
-
 	/* service description */
 	strncpy(svc_description, receive_packet.svc_description, sizeof(svc_description) - 1);
 	svc_description[sizeof(svc_description) - 1] = '\0';





More information about the icinga-checkins mailing list