1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
From 37d223bd43b1b1f9084dcb9c01642064537b389f Mon Sep 17 00:00:00 2001
From: Hal Murray <halmurray@sonic.net>
Date: Mon, 30 Sep 2024 19:49:11 -0700
Subject: [PATCH 1/4] Fix ntpd/ntp_control.c to handle crazy timex slots
The man page says "long", but the actual implementation
on Linux uses something else.
This fixes compiler errors on a few systems.
---
ntpd/ntp_control.c | 44 +++++++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 11 deletions(-)
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -37,6 +37,19 @@
static leap_signature_t lsig;
static struct timex ntx;
+/* Ugh. timex slots are tough. The man page says "long"
+ * But the actual implementation on Linux uses something else.
+ * On some 32 bit systems, that may not match the size of a long.
+ * The below kludge of using a special slot for each of the 5 places
+ * where that type would get used is simpler than setting up a
+ * #define for SIZEOF_TIMEX_XX that could be used to setup the
+ * correct type of the pointer in the table.
+ *
+ * See the discussion at:
+ * https://gitlab.com/NTPsec/ntpsec/-/merge_requests/1403
+ * https://lists.ntpsec.org/pipermail/devel/2024-September/010492.html
+ */
+
/*
* Statistic counters to keep track of requests and responses.
*/
@@ -97,7 +110,7 @@
#define ctl_putsfp(tag, sfp) ctl_putdblf(tag, false, -1, FP_UNSCALE(sfp))
static void ctl_putuint (const char *, uint64_t);
static void ctl_puthex (const char *, uint64_t);
-static void ctl_putint (const char *, long);
+static void ctl_putint (const char *, int64_t);
static void ctl_putts (const char *, l_fp);
static void ctl_putadr (const char *, refid_t, sockaddr_u *);
static void ctl_putrefid (const char *, refid_t);
@@ -172,7 +185,9 @@
enum var_type_special {
vs_peer, vs_peeradr, vs_peermode,
vs_systime,
- vs_refid, vs_mruoldest, vs_varlist};
+ vs_refid, vs_mruoldest, vs_varlist,
+ /* for slots in struct timex -- see comment above */
+ vs_tx_con, vs_tx_cal, vs_tx_err, vs_tx_jit, vs_tx_stb};
struct var {
const char* name;
const int flags;
@@ -183,6 +198,7 @@
const double* dbl;
const unsigned long int* uli;
const long int* li;
+ const int64_t* timex_li;
const unsigned int* uinnt;
const int* innt;
const uint64_t* u64;
@@ -269,9 +285,10 @@
.name = xname, .flags = xflags, .type = v_kli, .p.li = &xlocation }
#define Var_special(xname, xflags, xspecial) { \
.name = xname, .flags = xflags, .type = v_special, .p.special = xspecial }
+#define Var_timex(xname, xflags, xspecial) { \
+ .name = xname, .flags = xflags, .type = v_special, .p.special = xspecial }
static const struct var sys_var[] = {
- Var_u32("ss_uptime", RO, current_time),
Var_u8("leap", RO|DEF, sys_vars.sys_leap), // Was RW
Var_u8("stratum", RO|DEF, sys_vars.sys_stratum),
Var_i8("precision", RO|DEF, sys_vars.sys_precision),
@@ -370,17 +387,17 @@
Var_kli("kmaxerr", RO|N_CLOCK|KUToMS, ntx.maxerror),
Var_kli("kesterr", RO|N_CLOCK|KUToMS, ntx.esterror),
Var_int("kstflags", RO|N_CLOCK, ntx.status), // turn to text
- Var_li("ktimeconst", RO|N_CLOCK, ntx.constant),
+ Var_timex("ktimeconst", RO|N_CLOCK, vs_tx_con),
Var_kli("kprecis", RO|N_CLOCK|KUToMS, ntx.precision),
Var_kli("kfreqtol", RO|N_CLOCK|K_16, ntx.tolerance), // Not in man page
Var_kli("kppsfreq", RO|N_CLOCK|K_16, ntx.ppsfreq),
Var_kli("kppsstab", RO|N_CLOCK|K_16, ntx.stabil),
Var_kli("kppsjitter", RO|N_CLOCK|KNUToMS, ntx.jitter),
Var_int("kppscalibdur", RO|N_CLOCK, ntx.shift), // 1<<shift
- Var_li("kppscalibs", RO|N_CLOCK, ntx.calcnt),
- Var_li("kppscaliberrs", RO|N_CLOCK, ntx.errcnt),
- Var_li("kppsjitexc", RO|N_CLOCK, ntx.jitcnt),
- Var_li("kppsstbexc", RO|N_CLOCK, ntx.stbcnt),
+ Var_timex("kppscalibs", RO|N_CLOCK, vs_tx_cal),
+ Var_timex("kppscaliberrs", RO|N_CLOCK, vs_tx_err),
+ Var_timex("kppsjitexc", RO|N_CLOCK, vs_tx_jit),
+ Var_timex("kppsstbexc", RO|N_CLOCK, vs_tx_stb),
/* refclock stuff in ntp_io */
@@ -1291,11 +1308,11 @@
static void
ctl_putint(
const char *tag,
- long ival
+ int64_t ival
)
{
- char buf[50];
- snprintf(buf, sizeof(buf), "%ld", ival);
+ char buf[50];
+ snprintf(buf, sizeof(buf), "%" PRId64, ival);
ctl_putunqstr(tag, buf, strlen(buf));
}
@@ -1578,6 +1595,11 @@
ctl_putdata(cv->text, strlen(cv->text), false);
}
break;
+ case vs_tx_con: ctl_putint(v->name, ntx.constant); break;
+ case vs_tx_cal: ctl_putint(v->name, ntx.calcnt); break;
+ case vs_tx_err: ctl_putint(v->name, ntx.errcnt); break;
+ case vs_tx_jit: ctl_putint(v->name, ntx.jitcnt); break;
+ case vs_tx_stb: ctl_putint(v->name, ntx.stbcnt); break;
default:
/* -Wswitch-enum will warn if this is possible */
if (log_limit++ > 10) return; /* Avoid log file clutter/DDoS */
|