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

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