Blame SOURCES/dhcp-system_time_changed.patch

fad460
diff --git a/client/dhclient.c b/client/dhclient.c
fad460
index 1992467..364fd08 100644
fad460
--- a/client/dhclient.c
fad460
+++ b/client/dhclient.c
fad460
@@ -4463,6 +4463,10 @@ isc_result_t dhcp_set_control_state (control_object_state_t oldstate,
fad460
 		  case server_awaken:
fad460
 		    state_reboot (client);
fad460
 		    break;
fad460
+                  case server_time_changed:
fad460
+                    if (client->active)
fad460
+                      state_reboot (client);
fad460
+                    break;
fad460
 		}
fad460
 	    }
fad460
 	}
fad460
diff --git a/common/dispatch.c b/common/dispatch.c
fad460
index af8a5b5..c1d558f 100644
fad460
--- a/common/dispatch.c
fad460
+++ b/common/dispatch.c
fad460
@@ -110,10 +110,20 @@ dispatch(void)
fad460
 {
fad460
 	isc_result_t status;
fad460
 
fad460
-	status = isc_app_ctxrun(dhcp_gbl_ctx.actx);
fad460
-
fad460
-	log_fatal ("Dispatch routine failed: %s -- exiting",
fad460
-		   isc_result_totext (status));
fad460
+        do{
fad460
+          status = isc_app_ctxrun(dhcp_gbl_ctx.actx);
fad460
+
fad460
+          if (status == ISC_R_TIMESHIFTED){
fad460
+            status = dhcp_set_control_state(server_time_changed,
fad460
+                                            server_time_changed);
fad460
+            status = ISC_R_RELOAD;
fad460
+            log_info ("System time has been changed. Unable to use existing leases. Restarting");
fad460
+            // do nothing, restart context
fad460
+          };
fad460
+        } while (status == ISC_R_RELOAD);
fad460
+        
fad460
+        log_fatal ("Dispatch routine failed: %s -- exiting",
fad460
+                   isc_result_totext (status));
fad460
 }
fad460
 
fad460
 void
fad460
diff --git a/includes/dhcpd.h b/includes/dhcpd.h
fad460
index deea2a7..d60a03c 100644
fad460
--- a/includes/dhcpd.h
fad460
+++ b/includes/dhcpd.h
fad460
@@ -479,7 +479,8 @@ typedef enum {
fad460
 	server_running = 1,
fad460
 	server_shutdown = 2,
fad460
 	server_hibernate = 3,
fad460
-	server_awaken = 4
fad460
+	server_awaken = 4,
fad460
+        server_time_changed = 5
fad460
 } control_object_state_t;
fad460
 
fad460
 typedef struct {
fad460
diff --git a/server/dhcpd.c b/server/dhcpd.c
fad460
index 9617d75..9add7e4 100644
fad460
--- a/server/dhcpd.c
fad460
+++ b/server/dhcpd.c
fad460
@@ -1392,6 +1392,10 @@ static isc_result_t dhcp_io_shutdown_countdown (void *vlp)
fad460
 isc_result_t dhcp_set_control_state (control_object_state_t oldstate,
fad460
 				     control_object_state_t newstate)
fad460
 {
fad460
+        if (newstate == server_time_changed){
fad460
+          log_error ("System time has been changed. Leases information unreliable!");
fad460
+          return ISC_R_SUCCESS;
fad460
+        }
fad460
 	if (newstate == server_shutdown) {
fad460
 		shutdown_time = cur_time;
fad460
 		shutdown_state = shutdown_listeners;