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

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