1 From a2fb8759ab48c88e3f8df94ae6e156c357d932a2 Mon Sep 17 00:00:00 2001
2 From: Pavel Zhukov <pzhukov@redhat.com>
3 Date: Tue, 22 Oct 2019 16:23:01 +0200
4 Subject: [PATCH 24/28] Detect system time changes
7 client/dhclient.c | 6 ++++++
8 common/dispatch.c | 11 ++++++++++-
9 includes/dhcpd.h | 3 ++-
10 server/dhcpd.c | 6 ++++++
11 4 files changed, 24 insertions(+), 2 deletions(-)
13 diff --git a/client/dhclient.c b/client/dhclient.c
14 index 60836b4..fd18813 100644
15 --- a/client/dhclient.c
16 +++ b/client/dhclient.c
17 @@ -5665,6 +5665,12 @@ isc_result_t dhcp_set_control_state (control_object_state_t oldstate,
19 state_reboot (client);
22 + case server_time_changed:
23 + if (client->active){
24 + state_reboot (client);
30 diff --git a/common/dispatch.c b/common/dispatch.c
31 index 9741ff5..11c1787 100644
32 --- a/common/dispatch.c
33 +++ b/common/dispatch.c
34 @@ -118,7 +118,6 @@ dispatch(void)
35 * signal. It will return ISC_R_RELOAD in that
36 * case. That is a normal behavior.
39 if (status == ISC_R_RELOAD) {
41 * dhcp_set_control_state() will do the job.
42 @@ -129,6 +128,16 @@ dispatch(void)
43 if (status == ISC_R_SUCCESS)
44 status = ISC_R_RELOAD;
48 + if (status == ISC_R_TIMESHIFTED){
49 + status = dhcp_set_control_state(server_time_changed,
50 + server_time_changed);
51 + status = ISC_R_RELOAD;
52 + log_info ("System time has been changed. Unable to use existing leases. Restarting");
53 + // do nothing, restart context
56 } while (status == ISC_R_RELOAD);
58 log_fatal ("Dispatch routine failed: %s -- exiting",
59 diff --git a/includes/dhcpd.h b/includes/dhcpd.h
60 index fabad01..9663508 100644
61 --- a/includes/dhcpd.h
62 +++ b/includes/dhcpd.h
63 @@ -524,7 +524,8 @@ typedef enum {
69 + server_time_changed = 5
70 } control_object_state_t;
73 diff --git a/server/dhcpd.c b/server/dhcpd.c
74 index 845d0cc..3b3bd3b 100644
77 @@ -1767,6 +1767,12 @@ isc_result_t dhcp_set_control_state (control_object_state_t oldstate,
81 + if (newstate == server_time_changed){
82 + log_error ("System time has been changed. Leases information unreliable!");
83 + return ISC_R_SUCCESS;
87 if (newstate != server_shutdown)
88 return DHCP_R_INVALIDARG;