Blame SOURCES/0024-Detect-system-time-changes.patch

f9ed25
From 41c6032ace65119e6a400365f7e90283c930afd4 Mon Sep 17 00:00:00 2001
f9ed25
From: Pavel Zhukov <pzhukov@redhat.com>
f9ed25
Date: Tue, 22 Oct 2019 16:23:01 +0200
f9ed25
Subject: [PATCH 24/26] Detect system time changes
f9ed25
Cc: pzhukov@redhat.com
f9ed25
f9ed25
---
f9ed25
 client/dhclient.c |  6 ++++++
f9ed25
 common/dispatch.c | 11 ++++++++++-
f9ed25
 includes/dhcpd.h  |  3 ++-
f9ed25
 server/dhcpd.c    |  6 ++++++
f9ed25
 4 files changed, 24 insertions(+), 2 deletions(-)
f9ed25
f9ed25
diff --git a/client/dhclient.c b/client/dhclient.c
f9ed25
index 9b65438..44d508a 100644
f9ed25
--- a/client/dhclient.c
f9ed25
+++ b/client/dhclient.c
f9ed25
@@ -5408,6 +5408,12 @@ isc_result_t dhcp_set_control_state (control_object_state_t oldstate,
f9ed25
 		  case server_awaken:
f9ed25
 		    state_reboot (client);
f9ed25
 		    break;
f9ed25
+
f9ed25
+                  case server_time_changed:
f9ed25
+                    if (client->active){
f9ed25
+                      state_reboot (client);
f9ed25
+                    }
f9ed25
+                    break;
f9ed25
 		}
f9ed25
 	    }
f9ed25
 	}
f9ed25
diff --git a/common/dispatch.c b/common/dispatch.c
f9ed25
index d7fe200..8a24499 100644
f9ed25
--- a/common/dispatch.c
f9ed25
+++ b/common/dispatch.c
f9ed25
@@ -118,7 +118,6 @@ dispatch(void)
f9ed25
 		 * signal. It will return ISC_R_RELOAD in that
f9ed25
 		 * case. That is a normal behavior.
f9ed25
 		 */
f9ed25
-
f9ed25
 		if (status == ISC_R_RELOAD) {
f9ed25
 			/*
f9ed25
 			 * dhcp_set_control_state() will do the job.
f9ed25
@@ -129,6 +128,16 @@ dispatch(void)
f9ed25
 			if (status == ISC_R_SUCCESS)
f9ed25
 				status = ISC_R_RELOAD;
f9ed25
 		}
f9ed25
+
f9ed25
+                
f9ed25
+                if (status == ISC_R_TIMESHIFTED){
f9ed25
+                  status = dhcp_set_control_state(server_time_changed,
f9ed25
+                                                  server_time_changed);
f9ed25
+                  status = ISC_R_RELOAD;
f9ed25
+                  log_info ("System time has been changed. Unable to use existing leases. Restarting");
f9ed25
+                  // do nothing, restart context
f9ed25
+                };
f9ed25
+
f9ed25
 	} while (status == ISC_R_RELOAD);
f9ed25
 
f9ed25
 	log_fatal ("Dispatch routine failed: %s -- exiting",
f9ed25
diff --git a/includes/dhcpd.h b/includes/dhcpd.h
f9ed25
index 635c510..ec6c227 100644
f9ed25
--- a/includes/dhcpd.h
f9ed25
+++ b/includes/dhcpd.h
f9ed25
@@ -524,7 +524,8 @@ typedef enum {
f9ed25
 	server_running = 1,
f9ed25
 	server_shutdown = 2,
f9ed25
 	server_hibernate = 3,
f9ed25
-	server_awaken = 4
f9ed25
+	server_awaken = 4,
f9ed25
+        server_time_changed = 5
f9ed25
 } control_object_state_t;
f9ed25
 
f9ed25
 typedef struct {
f9ed25
diff --git a/server/dhcpd.c b/server/dhcpd.c
f9ed25
index 530a923..4aef16b 100644
f9ed25
--- a/server/dhcpd.c
f9ed25
+++ b/server/dhcpd.c
f9ed25
@@ -1767,6 +1767,12 @@ isc_result_t dhcp_set_control_state (control_object_state_t oldstate,
f9ed25
 {
f9ed25
 	struct timeval tv;
f9ed25
 
f9ed25
+        if (newstate == server_time_changed){
f9ed25
+          log_error ("System time has been changed. Leases information unreliable!");
f9ed25
+          return ISC_R_SUCCESS;
f9ed25
+        }
f9ed25
+
f9ed25
+                
f9ed25
 	if (newstate != server_shutdown)
f9ed25
 		return DHCP_R_INVALIDARG;
f9ed25
 	/* Re-entry. */
f9ed25
-- 
f9ed25
2.14.5
f9ed25