OpenNTPD daemon with OpenSSL implementation & flexible configurability
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.4 KiB

  1. From: Pekka Helenius <fincer89@hotmail.com>
  2. Date: Wed, 20 Jan 2021 23:20:31 +0300
  3. Subject: Assume system clock is synced when time offset is in specific range limits (quick hotfix).
  4. --- a/src/ntpd.c 2020-08-03 23:48:23.609231373 +0300
  5. +++ b/src/ntpd.c 2021-01-20 23:00:53.946365898 +0200
  6. @@ -566,9 +566,12 @@ ntpd_adjtime(double d)
  7. log_warn("main process: time adjustment failed due to time error");
  8. } else if (rc < 0) {
  9. log_warn("main process: time adjustment failed");
  10. - } else if (!firstadj && tx.offset == offset) {
  11. + }
  12. + if (tx.offset > -(conf->synced_offset) || tx.offset < conf->synced_offset) {
  13. synced = 1;
  14. - }
  15. + } else {
  16. + synced = 0;
  17. + }
  18. #else
  19. struct timeval tv, olddelta;
  20. d_to_tv(d, &tv);
  21. --- a/src/ntpd.h 2020-08-03 23:25:02.978705101 +0300
  22. +++ b/src/ntpd.h 2021-01-20 23:09:58.945735647 +0200
  23. @@ -76,6 +76,7 @@
  24. #define SETTIME_TIMEOUT 100 /* max seconds to wait when settime == 1 */
  25. #define LOG_NEGLIGIBLE_ADJTIME 32 /* negligible drift to not log (ms) */
  26. #define LOG_NEGLIGIBLE_ADJFREQ 0.05 /* negligible rate to not log (ppm) */
  27. +#define SYNCED_OFFSET 100 /* Synced time offset (μs) */
  28. #define FREQUENCY_SAMPLES 8 /* samples for est. of permanent drift */
  29. #define MAX_FREQUENCY_ADJUST 128e-5 /* max correction per iteration */
  30. #define MAX_SEND_ERRORS 3 /* max send errors before reconnect */
  31. @@ -313,6 +314,7 @@ struct ntpd_conf {
  32. int settime_timeout;
  33. int log_negligible_adjtime;
  34. + int synced_offset;
  35. double log_negligible_adjfreq;
  36. int frequency_samples;
  37. --- a/src/parse.y 2020-08-03 23:22:43.401482642 +0300
  38. +++ b/src/parse.y 2021-01-20 23:08:20.789182596 +0200
  39. @@ -119,6 +119,8 @@ typedef struct {
  40. %token _LOG_NEGLIGIBLE_ADJTIME
  41. %token _LOG_NEGLIGIBLE_ADJFREQ
  42. +%token _SYNCED_OFFSET
  43. +
  44. %token _FREQUENCY_SAMPLES
  45. %token _MAX_FREQUENCY_ADJUST
  46. @@ -515,6 +517,10 @@ main : LISTEN ON address listen_opts {
  47. conf->log_negligible_adjfreq = $2.pos_decimal;
  48. }
  49. + | _SYNCED_OFFSET pos_num {
  50. + conf->synced_offset = $2.pos_num;
  51. + }
  52. +
  53. | _FREQUENCY_SAMPLES pos_num {
  54. conf->frequency_samples = $2.pos_num;
  55. }
  56. @@ -918,6 +924,7 @@ lookup(char *s)
  57. { "servers", SERVERS, "multiple" },
  58. { "settime_timeout", _SETTIME_TIMEOUT, "single" },
  59. { "stratum", STRATUM, "multiple" },
  60. + { "synced_offset", _SYNCED_OFFSET, "single" },
  61. { "tries_auto_dnsfail", _TRIES_AUTO_DNSFAIL, "single" },
  62. { "trusted", TRUSTED, "multiple" },
  63. { "trustlevel_aggressive", _TRUSTLEVEL_AGGRESSIVE, "single" },
  64. @@ -1293,6 +1300,9 @@ init_conf(struct ntpd_conf *conf)
  65. /* negligible rate to not log (ppm) */
  66. conf->log_negligible_adjfreq = LOG_NEGLIGIBLE_ADJFREQ; // 0.05;
  67. + /* negligible drift to not log (ms) */
  68. + conf->synced_offset = SYNCED_OFFSET; // 100;
  69. +
  70. /* samples for est. of permanent drift */
  71. conf->frequency_samples = FREQUENCY_SAMPLES; // 8;
  72. @@ -1372,6 +1382,8 @@ print_conf(struct ntpd_conf *lconf)
  73. fprintf(stdout, "Neglible drift time to not log: %d milliseconds\n", conf->log_negligible_adjtime);
  74. fprintf(stdout, "Neglible frequency rate to not log: %f ppm\n", conf->log_negligible_adjfreq);
  75. fprintf(stdout, "\n");
  76. + fprintf(stdout, "Synced time offset threshold: %d microseconds\n", conf->synced_offset);
  77. + fprintf(stdout, "\n");
  78. fprintf(stdout, "Frequency samples for estimation of permanent drift: %d\n", conf->frequency_samples);
  79. fprintf(stdout, "Maximum frequency correction per iteration: %f\n", conf->max_frequency_adjust);
  80. fprintf(stdout, "\n");
  81. --- a/src/ntpd.conf.5 2020-08-03 23:21:11.124672226 +0300
  82. +++ b/src/ntpd.conf.5 2021-01-20 23:12:45.628871438 +0200
  83. @@ -676,6 +676,14 @@ Negligible drift time to not log in mill
  84. 32
  85. .El
  86. .Ed
  87. +.It Ic synced_offset Ar microseconds
  88. +Synced time offset threshold in microseconds.
  89. +.Bd -literal -offset indent
  90. +.Bl -tag -width "Default:" -compact
  91. +.It Default:
  92. +100
  93. +.El
  94. +.Ed
  95. .It Ic max_frequency_adjust Ar decimal
  96. Maximum allowed frequency correction per iteration.
  97. .Bd -literal -offset indent
  98. --- a/ntpd.conf 2020-08-03 23:19:18.951338773 +0300
  99. +++ b/ntpd.conf 2021-01-20 23:14:56.802048541 +0200
  100. @@ -246,6 +246,12 @@ constraints from "https://www.duckduckgo
  101. #
  102. # log_negligible_adjtime 32
  103. +# Synced time offset threshold in microseconds.
  104. +# If our time adjustment value exceeds the threshold
  105. +# we assume the clock is not synced anymore.
  106. +#
  107. +# synced_offset 100
  108. +
  109. # Maximum allowed frequency correction per iteration.
  110. #
  111. # max_frequency_adjust 0.0128