Blame SOURCES/dhcp-detect-system-time-jumps.patch

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