2022-03-10 17:06:31 +00:00
|
|
|
From 8e49f4b460ad20890c63a385c17d3e5decd45a82 Mon Sep 17 00:00:00 2001
|
2019-10-22 14:58:01 +00:00
|
|
|
From: Pavel Zhukov <pzhukov@redhat.com>
|
|
|
|
Date: Tue, 22 Oct 2019 16:23:24 +0200
|
2022-03-10 17:06:31 +00:00
|
|
|
Subject: [PATCH 25/28] bind: Detect system time changes
|
2019-10-22 14:58:01 +00:00
|
|
|
|
|
|
|
---
|
2022-03-10 17:06:31 +00:00
|
|
|
.../bind-9.11.36/lib/isc/include/isc/result.h | 4 +-
|
|
|
|
bind/bind-9.11.36/lib/isc/include/isc/util.h | 4 ++
|
|
|
|
bind/bind-9.11.36/lib/isc/result.c | 2 +
|
|
|
|
bind/bind-9.11.36/lib/isc/unix/app.c | 41 +++++++++++++++++--
|
|
|
|
.../lib/isc/unix/include/isc/time.h | 20 +++++++++
|
|
|
|
bind/bind-9.11.36/lib/isc/unix/time.c | 22 ++++++++++
|
2019-10-22 14:58:01 +00:00
|
|
|
6 files changed, 89 insertions(+), 4 deletions(-)
|
|
|
|
|
2022-03-10 17:06:31 +00:00
|
|
|
diff --git a/bind/bind-9.11.36/lib/isc/include/isc/result.h b/bind/bind-9.11.36/lib/isc/include/isc/result.h
|
|
|
|
index 916641f..51c2468 100644
|
|
|
|
--- a/bind/bind-9.11.36/lib/isc/include/isc/result.h
|
|
|
|
+++ b/bind/bind-9.11.36/lib/isc/include/isc/result.h
|
2020-01-06 13:52:18 +00:00
|
|
|
@@ -89,7 +89,9 @@
|
|
|
|
#define ISC_R_DISCFULL 67 /*%< disc full */
|
|
|
|
#define ISC_R_DEFAULT 68 /*%< default */
|
|
|
|
#define ISC_R_IPV4PREFIX 69 /*%< IPv4 prefix */
|
|
|
|
-#define ISC_R_NRESULTS 70
|
|
|
|
+#define ISC_R_TIMESHIFTED 70 /*%< system time changed */
|
|
|
|
+/*% Not a result code: the number of results. */
|
|
|
|
+#define ISC_R_NRESULTS 71
|
2019-07-25 10:54:23 +00:00
|
|
|
|
|
|
|
ISC_LANG_BEGINDECLS
|
|
|
|
|
2022-03-10 17:06:31 +00:00
|
|
|
diff --git a/bind/bind-9.11.36/lib/isc/include/isc/util.h b/bind/bind-9.11.36/lib/isc/include/isc/util.h
|
|
|
|
index 9111c2a..20a05b4 100644
|
|
|
|
--- a/bind/bind-9.11.36/lib/isc/include/isc/util.h
|
|
|
|
+++ b/bind/bind-9.11.36/lib/isc/include/isc/util.h
|
|
|
|
@@ -325,6 +325,10 @@ extern void mock_assert(const int result, const char* const expression,
|
2019-07-25 10:54:23 +00:00
|
|
|
* Time
|
|
|
|
*/
|
|
|
|
#define TIME_NOW(tp) RUNTIME_CHECK(isc_time_now((tp)) == ISC_R_SUCCESS)
|
|
|
|
+#ifdef CLOCK_BOOTTIME
|
|
|
|
+#define TIME_MONOTONIC(tp) RUNTIME_CHECK(isc_time_boottime((tp)) == ISC_R_SUCCESS)
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
|
|
|
|
/*%
|
2020-01-06 13:52:18 +00:00
|
|
|
* Alignment
|
2022-03-10 17:06:31 +00:00
|
|
|
diff --git a/bind/bind-9.11.36/lib/isc/result.c b/bind/bind-9.11.36/lib/isc/result.c
|
|
|
|
index 887b08c..2106a3a 100644
|
|
|
|
--- a/bind/bind-9.11.36/lib/isc/result.c
|
|
|
|
+++ b/bind/bind-9.11.36/lib/isc/result.c
|
2020-01-06 13:52:18 +00:00
|
|
|
@@ -105,6 +105,7 @@ static const char *description[ISC_R_NRESULTS] = {
|
|
|
|
"disc full", /*%< 67 */
|
|
|
|
"default", /*%< 68 */
|
|
|
|
"IPv4 prefix", /*%< 69 */
|
|
|
|
+ "time changed", /*%< 70 */
|
2019-07-25 10:54:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *identifier[ISC_R_NRESULTS] = {
|
2020-01-06 13:52:18 +00:00
|
|
|
@@ -178,6 +179,7 @@ static const char *identifier[ISC_R_NRESULTS] = {
|
|
|
|
"ISC_R_DISCFULL",
|
|
|
|
"ISC_R_DEFAULT",
|
|
|
|
"ISC_R_IPV4PREFIX",
|
2019-07-25 10:54:23 +00:00
|
|
|
+ "ISC_R_TIMESHIFTED",
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ISC_RESULT_RESULTSET 2
|
2022-03-10 17:06:31 +00:00
|
|
|
diff --git a/bind/bind-9.11.36/lib/isc/unix/app.c b/bind/bind-9.11.36/lib/isc/unix/app.c
|
|
|
|
index 8189c63..4aabaa4 100644
|
|
|
|
--- a/bind/bind-9.11.36/lib/isc/unix/app.c
|
|
|
|
+++ b/bind/bind-9.11.36/lib/isc/unix/app.c
|
2020-01-06 13:52:18 +00:00
|
|
|
@@ -442,15 +442,51 @@ isc__app_ctxonrun(isc_appctx_t *ctx0, isc_mem_t *mctx, isc_task_t *task,
|
2019-07-25 10:54:23 +00:00
|
|
|
static isc_result_t
|
|
|
|
evloop(isc__appctx_t *ctx) {
|
|
|
|
isc_result_t result;
|
|
|
|
+ isc_time_t now;
|
|
|
|
+#ifdef CLOCK_BOOTTIME
|
|
|
|
+ isc_time_t monotonic;
|
2020-01-06 13:52:18 +00:00
|
|
|
+ uint64_t diff = 0;
|
2019-07-25 10:54:23 +00:00
|
|
|
+#else
|
|
|
|
+ isc_time_t prev;
|
|
|
|
+ TIME_NOW(&prev);
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
while (!ctx->want_shutdown) {
|
|
|
|
int n;
|
|
|
|
- isc_time_t when, now;
|
|
|
|
+ isc_time_t when;
|
|
|
|
+
|
|
|
|
struct timeval tv, *tvp;
|
|
|
|
isc_socketwait_t *swait;
|
2020-01-06 13:52:18 +00:00
|
|
|
bool readytasks;
|
|
|
|
bool call_timer_dispatch = false;
|
2019-07-25 10:54:23 +00:00
|
|
|
|
2020-01-06 13:52:18 +00:00
|
|
|
+ uint64_t us;
|
2019-07-25 10:54:23 +00:00
|
|
|
+
|
|
|
|
+#ifdef CLOCK_BOOTTIME
|
|
|
|
+ // TBD macros for following three lines
|
|
|
|
+ TIME_NOW(&now);
|
|
|
|
+ TIME_MONOTONIC(&monotonic);
|
|
|
|
+ INSIST(now.seconds > monotonic.seconds)
|
|
|
|
+ us = isc_time_microdiff (&now, &monotonic);
|
|
|
|
+ if (us < diff){
|
|
|
|
+ us = diff - us;
|
|
|
|
+ if (us > 1000000){ // ignoring shifts less than one second
|
|
|
|
+ return ISC_R_TIMESHIFTED;
|
|
|
|
+ };
|
|
|
|
+ diff = isc_time_microdiff (&now, &monotonic);
|
|
|
|
+ } else {
|
|
|
|
+ diff = isc_time_microdiff (&now, &monotonic);
|
|
|
|
+ // not implemented
|
|
|
|
+ }
|
|
|
|
+#else
|
|
|
|
+ TIME_NOW(&now);
|
|
|
|
+ if (isc_time_compare (&now, &prev) < 0)
|
|
|
|
+ return ISC_R_TIMESHIFTED;
|
|
|
|
+ TIME_NOW(&prev);
|
|
|
|
+#endif
|
|
|
|
/*
|
|
|
|
* Check the reload (or suspend) case first for exiting the
|
|
|
|
* loop as fast as possible in case:
|
2020-01-06 13:52:18 +00:00
|
|
|
@@ -475,9 +511,8 @@ evloop(isc__appctx_t *ctx) {
|
2019-07-25 10:54:23 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
tvp = NULL;
|
|
|
|
else {
|
2020-01-06 13:52:18 +00:00
|
|
|
- uint64_t us;
|
|
|
|
-
|
2019-07-25 10:54:23 +00:00
|
|
|
TIME_NOW(&now);
|
|
|
|
+
|
|
|
|
us = isc_time_microdiff(&when, &now);
|
|
|
|
if (us == 0)
|
2020-01-06 13:52:18 +00:00
|
|
|
call_timer_dispatch = true;
|
2022-03-10 17:06:31 +00:00
|
|
|
diff --git a/bind/bind-9.11.36/lib/isc/unix/include/isc/time.h b/bind/bind-9.11.36/lib/isc/unix/include/isc/time.h
|
|
|
|
index 03512c1..99e0dfa 100644
|
|
|
|
--- a/bind/bind-9.11.36/lib/isc/unix/include/isc/time.h
|
|
|
|
+++ b/bind/bind-9.11.36/lib/isc/unix/include/isc/time.h
|
2020-01-06 13:52:18 +00:00
|
|
|
@@ -132,6 +132,26 @@ isc_time_isepoch(const isc_time_t *t);
|
2019-07-25 10:54:23 +00:00
|
|
|
*\li 't' is a valid pointer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
+#ifdef CLOCK_BOOTTIME
|
|
|
|
+isc_result_t
|
|
|
|
+isc_time_boottime(isc_time_t *t);
|
|
|
|
+/*%<
|
|
|
|
+ * Set 't' to monotonic time from previous boot
|
|
|
|
+ * it's not affected by system time change. It also
|
|
|
|
+ * includes the time system was suspended
|
|
|
|
+ *
|
|
|
|
+ * Requires:
|
|
|
|
+ *\li 't' is a valid pointer.
|
|
|
|
+ *
|
|
|
|
+ * Returns:
|
|
|
|
+ *
|
|
|
|
+ *\li Success
|
|
|
|
+ *\li Unexpected error
|
|
|
|
+ * Getting the time from the system failed.
|
|
|
|
+ */
|
|
|
|
+#endif /* CLOCK_BOOTTIME */
|
|
|
|
+
|
|
|
|
+
|
|
|
|
isc_result_t
|
|
|
|
isc_time_now(isc_time_t *t);
|
|
|
|
/*%<
|
2022-03-10 17:06:31 +00:00
|
|
|
diff --git a/bind/bind-9.11.36/lib/isc/unix/time.c b/bind/bind-9.11.36/lib/isc/unix/time.c
|
|
|
|
index bcca41b..af6ea7f 100644
|
|
|
|
--- a/bind/bind-9.11.36/lib/isc/unix/time.c
|
|
|
|
+++ b/bind/bind-9.11.36/lib/isc/unix/time.c
|
2020-01-06 13:52:18 +00:00
|
|
|
@@ -498,3 +498,25 @@ isc_time_formatISO8601ms(const isc_time_t *t, char *buf, unsigned int len) {
|
2019-07-25 10:54:23 +00:00
|
|
|
t->nanoseconds / NS_PER_MS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#ifdef CLOCK_BOOTTIME
|
|
|
|
+isc_result_t
|
|
|
|
+isc_time_boottime(isc_time_t *t) {
|
|
|
|
+ struct timespec ts;
|
|
|
|
+
|
|
|
|
+ char strbuf[ISC_STRERRORSIZE];
|
|
|
|
+
|
|
|
|
+ if (clock_gettime (CLOCK_BOOTTIME, &ts) != 0){
|
|
|
|
+ isc__strerror(errno, strbuf, sizeof(strbuf));
|
|
|
|
+ UNEXPECTED_ERROR(__FILE__, __LINE__, "%s", strbuf);
|
|
|
|
+ return (ISC_R_UNEXPECTED);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ t->seconds = ts.tv_sec;
|
|
|
|
+ t->nanoseconds = ts.tv_nsec;
|
|
|
|
+
|
|
|
|
+ return (ISC_R_SUCCESS);
|
|
|
|
+
|
|
|
|
+};
|
|
|
|
+#endif
|
2019-10-22 14:58:01 +00:00
|
|
|
--
|
2022-03-10 17:06:31 +00:00
|
|
|
2.35.1
|
2019-10-22 14:58:01 +00:00
|
|
|
|