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