From: Dave Hart Date: Mon, 27 Dec 2010 21:29:19 +0000 (+0000) Subject: Add ntpq kerninfo command similar to ntpdc's. X-Git-Tag: NTP_4_2_7P104~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56797b732d602fed3f44bc9b6f331cba60b111fd;p=thirdparty%2Fntp.git Add ntpq kerninfo command similar to ntpdc's. bk: 4d19052fgIId6PtZU5xvKsTI7pWQeQ --- diff --git a/ChangeLog b/ChangeLog index 6abbfac03..77c653dc8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,4 @@ -* Add ntpq authinfo command, similar to ntpdc's authinfo. -* Add ntpq sysinfo command, similar to ntpdc's sysinfo. +* Add ntpq kerninfo, authinfo, and sysinfo commands similar to ntpdc's. (4.2.7p103) 2010/12/24 Released by Harlan Stenn * Add ntpq pstats command similar to ntpdc's. * Remove ntpq pstatus command, rv/readvar does the same and more. diff --git a/include/ntp_control.h b/include/ntp_control.h index cecfa5c65..52de472b4 100644 --- a/include/ntp_control.h +++ b/include/ntp_control.h @@ -205,7 +205,25 @@ struct ntp_control { #define CS_AUTHENCRYPTS 54 #define CS_AUTHDECRYPTS 55 #define CS_AUTHRESET 56 -#define CS_MAX_NOAUTOKEY CS_AUTHRESET +#define CS_K_OFFSET 57 +#define CS_K_FREQ 58 +#define CS_K_MAXERR 59 +#define CS_K_ESTERR 60 +#define CS_K_STFLAGS 61 +#define CS_K_TIMECONST 62 +#define CS_K_PRECISION 63 +#define CS_K_FREQTOL 64 +#define CS_K_PPS_FREQ 65 +#define CS_K_PPS_STABIL 66 +#define CS_K_PPS_JITTER 67 +#define CS_K_PPS_CALIBDUR 68 +#define CS_K_PPS_CALIBS 69 +#define CS_K_PPS_CALIBERRS 70 +#define CS_K_PPS_JITEXC 71 +#define CS_K_PPS_STBEXC 72 +#define CS_KERN_FIRST CS_K_OFFSET +#define CS_KERN_LAST CS_K_PPS_STBEXC +#define CS_MAX_NOAUTOKEY CS_KERN_LAST #ifdef AUTOKEY #define CS_FLAGS (1 + CS_MAX_NOAUTOKEY) #define CS_HOST (2 + CS_MAX_NOAUTOKEY) diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h index 11b869179..6a489a379 100644 --- a/include/ntp_stdlib.h +++ b/include/ntp_stdlib.h @@ -120,7 +120,7 @@ extern char * numtohost (u_int32); extern const char * socktoa (const sockaddr_u *); extern const char * sockporttoa(const sockaddr_u *); extern u_short sock_hash (const sockaddr_u *); -extern char * socktohost (const sockaddr_u *); +extern const char * socktohost (const sockaddr_u *); extern int octtoint (const char *, u_long *); extern u_long ranp2 (int); extern const char *refnumtoa (sockaddr_u *); diff --git a/include/ntpd.h b/include/ntpd.h index d58e59130..d92a7f10b 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -151,8 +151,8 @@ extern void block_io_and_alarm (void); # define UNBLOCK_IO_AND_ALARM() do {} while (0) # define BLOCK_IO_AND_ALARM() do {} while (0) #endif -extern char * localaddrtoa(struct interface *); #define latoa(pif) localaddrtoa(pif) +extern const char * localaddrtoa(endpt *); /* ntp_loopfilter.c */ extern void init_loopfilter(void); diff --git a/libntp/socktohost.c b/libntp/socktohost.c index cab1ed756..492521190 100644 --- a/libntp/socktohost.c +++ b/libntp/socktohost.c @@ -21,7 +21,7 @@ #include "ntp_debug.h" -char * +const char * socktohost( const sockaddr_u *sock ) diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index 3f3997fb6..e1301d982 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -1,11 +1,21 @@ /* - * ntp_control.c - respond to control messages and send async traps + * ntp_control.c - respond to mode 6 control messages and send async + * traps. Provides service to ntpq and others. */ #ifdef HAVE_CONFIG_H # include #endif +#include +#include +#include +#include +#ifdef HAVE_NETINET_IN_H +# include +#endif +#include + #include "ntpd.h" #include "ntp_io.h" #include "ntp_refclock.h" @@ -16,16 +26,9 @@ #include "ntp_crypto.h" #include "ntp_assert.h" #include "ntp_md5.h" /* provides OpenSSL digest API */ - -#include -#include -#include -#include - -#ifdef HAVE_NETINET_IN_H -#include +#ifdef KERNEL_PLL +# include "ntp_syscall.h" #endif -#include /* @@ -53,7 +56,12 @@ static u_short ctlclkstatus (struct refclockstat *); static void ctl_flushpkt (u_char); static void ctl_putdata (const char *, unsigned int, int); static void ctl_putstr (const char *, const char *, size_t); -static void ctl_putdbl (const char *, double); +static void ctl_putdblf (const char *, const char *, double); +const char ctl_def_dbl_fmt[] = "%.3f"; +#define ctl_putdbl(tag, d) ctl_putdblf(tag, ctl_def_dbl_fmt, d) +const char ctl_def_sfp_fmt[] = "%g"; +#define ctl_putsfp(tag, sfp) ctl_putdblf(tag, ctl_def_sfp_fmt, \ + FPTOD(sfp)) static void ctl_putuint (const char *, u_long); static void ctl_puthex (const char *, u_long); static void ctl_putint (const char *, long); @@ -62,14 +70,18 @@ static void ctl_putadr (const char *, u_int32, sockaddr_u *); static void ctl_putid (const char *, char *); static void ctl_putarray (const char *, double *, int); +#ifdef KERNEL_PLL +static void kstatus_to_text (u_int32, char *, size_t); +#endif static void ctl_putsys (int); static void ctl_putpeer (int, struct peer *); static void ctl_putfs (const char *, tstamp_t); #ifdef REFCLOCK static void ctl_putclock (int, struct refclockstat *, int); #endif /* REFCLOCK */ -static struct ctl_var *ctl_getitem(struct ctl_var *, char **); -static u_short count_var (struct ctl_var *); +static const struct ctl_var *ctl_getitem(const struct ctl_var *, + char **); +static u_short count_var (const struct ctl_var *); static void control_unspec (struct recvbuf *, int); static void read_status (struct recvbuf *, int); static void read_sysvars (void); @@ -94,7 +106,7 @@ static void unset_trap (struct recvbuf *, int); static struct ctl_trap *ctlfindtrap(sockaddr_u *, struct interface *); -static struct ctl_proc control_codes[] = { +static const struct ctl_proc control_codes[] = { { CTL_OP_UNSPEC, NOAUTH, control_unspec }, { CTL_OP_READSTAT, NOAUTH, read_status }, { CTL_OP_READVAR, NOAUTH, read_variables }, @@ -115,7 +127,7 @@ static struct ctl_proc control_codes[] = { * System variable values. The array can be indexed by the variable * index to find the textual name. */ -static struct ctl_var sys_var[] = { +static const struct ctl_var sys_var[] = { { 0, PADDING, "" }, /* 0 */ { CS_LEAP, RW, "leap" }, /* 1 */ { CS_STRATUM, RO, "stratum" }, /* 2 */ @@ -173,6 +185,22 @@ static struct ctl_var sys_var[] = { { CS_AUTHENCRYPTS, RO, "authencrypts" }, /* 54 */ { CS_AUTHDECRYPTS, RO, "authdecrypts" }, /* 55 */ { CS_AUTHRESET, RO, "authreset" }, /* 56 */ + { CS_K_OFFSET, RO, "koffset" }, /* 57 */ + { CS_K_FREQ, RO, "kfreq" }, /* 58 */ + { CS_K_MAXERR, RO, "kmaxerr" }, /* 59 */ + { CS_K_ESTERR, RO, "kesterr" }, /* 60 */ + { CS_K_STFLAGS, RO, "kstflags" }, /* 61 */ + { CS_K_TIMECONST, RO, "ktimeconst" }, /* 62 */ + { CS_K_PRECISION, RO, "kprecis" }, /* 63 */ + { CS_K_FREQTOL, RO, "kfreqtol" }, /* 64 */ + { CS_K_PPS_FREQ, RO, "kppsfreq" }, /* 65 */ + { CS_K_PPS_STABIL, RO, "kppsstab" }, /* 66 */ + { CS_K_PPS_JITTER, RO, "kppsjitter" }, /* 67 */ + { CS_K_PPS_CALIBDUR, RO, "kppscalibdur" }, /* 68 */ + { CS_K_PPS_CALIBS, RO, "kppscalibs" }, /* 69 */ + { CS_K_PPS_CALIBERRS, RO, "kppscaliberrs" }, /* 70 */ + { CS_K_PPS_JITEXC, RO, "kppsjitexc" }, /* 71 */ + { CS_K_PPS_STBEXC, RO, "kppsstbexc" }, /* 72 */ #ifdef AUTOKEY { CS_FLAGS, RO, "flags" }, /* 1 + CS_MAX_NOAUTOKEY */ { CS_HOST, RO, "host" }, /* 2 + CS_MAX_NOAUTOKEY */ @@ -192,7 +220,7 @@ static struct ctl_var *ext_sys_var = NULL; * System variables we print by default (in fuzzball order, * more-or-less) */ -static u_char def_sys_var[] = { +static const u_char def_sys_var[] = { CS_VERSION, CS_PROCESSOR, CS_SYSTEM, @@ -231,7 +259,7 @@ static u_char def_sys_var[] = { /* * Peer variable list */ -static struct ctl_var peer_var[] = { +static const struct ctl_var peer_var[] = { { 0, PADDING, "" }, /* 0 */ { CP_CONFIG, RO, "config" }, /* 1 */ { CP_AUTHENABLE, RO, "authenable" }, /* 2 */ @@ -300,7 +328,7 @@ static struct ctl_var peer_var[] = { /* * Peer variables we print by default */ -static u_char def_peer_var[] = { +static const u_char def_peer_var[] = { CP_SRCADR, CP_SRCPORT, CP_SRCHOST, @@ -351,7 +379,7 @@ static u_char def_peer_var[] = { /* * Clock variable list */ -static struct ctl_var clock_var[] = { +static const struct ctl_var clock_var[] = { { 0, PADDING, "" }, /* 0 */ { CC_TYPE, RO, "type" }, /* 1 */ { CC_TIMECODE, RO, "timecode" }, /* 2 */ @@ -373,7 +401,7 @@ static struct ctl_var clock_var[] = { /* * Clock variables printed by default */ -static u_char def_clock_var[] = { +static const u_char def_clock_var[] = { CC_DEVICE, CC_TYPE, /* won't be output if device = known */ CC_TIMECODE, @@ -407,8 +435,8 @@ static const char last_fmt[] = "last.%d"; # define STR_PROCESSOR "unknown" # endif -static char str_system[] = STR_SYSTEM; -static char str_processor[] = STR_PROCESSOR; +static const char str_system[] = STR_SYSTEM; +static const char str_processor[] = STR_PROCESSOR; #else # include static struct utsname utsnamebuf; @@ -740,10 +768,10 @@ process_control( int restrict_mask ) { - register struct ntp_control *pkt; - register int req_count; - register int req_data; - register struct ctl_proc *cc; + struct ntp_control *pkt; + int req_count; + int req_data; + const struct ctl_proc *cc; keyid_t *pkid; int properlen; int maclen; @@ -1165,16 +1193,17 @@ ctl_putunqstr( /* - * ctl_putdbl - write a tagged, signed double into the response packet + * ctl_putdblf - write a tagged, signed double into the response packet */ static void -ctl_putdbl( - const char *tag, - double ts +ctl_putdblf( + const char * tag, + const char * fmt, + double d ) { - register char *cp; - register const char *cq; + char *cp; + const char *cq; char buffer[200]; cp = buffer; @@ -1183,7 +1212,7 @@ ctl_putdbl( *cp++ = *cq++; *cp++ = '='; NTP_INSIST((cp - buffer) < sizeof(buffer)); - snprintf(cp, sizeof(buffer) - (cp - buffer), "%.3f", ts); + snprintf(cp, sizeof(buffer) - (cp - buffer), fmt, d); cp += strlen(cp); ctl_putdata(buffer, (unsigned)(cp - buffer), 0); } @@ -1415,6 +1444,132 @@ ctl_putarray( ctl_putdata(buffer, (unsigned)(cp - buffer), 0); } +/* + * kstatus_to_text - convert ntp_adjtime() status bits to text + */ +#ifdef KERNEL_PLL +void +kstatus_to_text( + u_int32 status, + char * str, + size_t str_sz + ) +{ + char * pch; + const char *lim; + + pch = str; + lim = pch + str_sz; + +# define XLATE_KST_BIT(bitval, text) \ +do { \ + if (((bitval) & status) && pch + sizeof(text) <= lim) { \ + memcpy(pch, (text), sizeof(text)); \ + pch += sizeof(text) - 1; \ + } \ +} while (0) + +# ifdef STA_PLL + { + const char spll[] = "pll "; + XLATE_KST_BIT(STA_PLL, spll); + } +# endif +# ifdef STA_PPSFREQ + { + const char sppsfreq[] = "ppsfreq "; + XLATE_KST_BIT(STA_PPSFREQ, sppsfreq); + } +# endif +# ifdef STA_PPSTIME + { + const char sppstime[] = "ppstime "; + XLATE_KST_BIT(STA_PPSTIME, sppstime); + } +# endif +# ifdef STA_FLL + { + const char sfll[] = "fll "; + XLATE_KST_BIT(STA_FLL, sfll); + } +# endif +# ifdef STA_INS + { + const char sins[] = "ins "; + XLATE_KST_BIT(STA_INS, sins); + } +# endif +# ifdef STA_DEL + { + const char sdel[] = "del "; + XLATE_KST_BIT(STA_DEL, sdel); + } +# endif +# ifdef STA_UNSYNC + { + const char sunsync[] = "unsync "; + XLATE_KST_BIT(STA_UNSYNC, sunsync); + } +# endif +# ifdef STA_FREQHOLD + { + const char sfreqhold[] = "freqhold "; + XLATE_KST_BIT(STA_FREQHOLD, sfreqhold); + } +# endif +# ifdef STA_PPSSIGNAL + { + const char sppssignal[] = "ppssignal "; + XLATE_KST_BIT(STA_PPSSIGNAL, sppssignal); + } +# endif +# ifdef STA_PPSJITTER + { + const char sppsjitter[] = "ppsjitter "; + XLATE_KST_BIT(STA_PPSJITTER, sppsjitter); + } +# endif +# ifdef STA_PPSWANDER + { + const char sppswander[] = "ppswander "; + XLATE_KST_BIT(STA_PPSWANDER, sppswander); + } +# endif +# ifdef STA_PPSERROR + { + const char sppserror[] = "ppserror "; + XLATE_KST_BIT(STA_PPSERROR, sppserror); + } +# endif +# ifdef STA_CLOCKERR + { + const char sclockerr[] = "clockerr "; + XLATE_KST_BIT(STA_CLOCKERR, sclockerr); + } +# endif +# ifdef STA_NANO + { + const char snano[] = "nano "; + XLATE_KST_BIT(STA_NANO, snano); + } +# endif +# ifdef STA_MODE + { + const char smodefll[] = "mode=fll "; + XLATE_KST_BIT(STA_MODE, smodefll); + } +# endif +# ifdef STA_CLK + { + const char ssrcb[] = "src=B "; + XLATE_KST_BIT(STA_CLK, ssrcb); + } +# endif + if (pch > str && ' ' == pch[-1]) + pch[-1] = '\0'; +} +#endif /* KERNEL_PLL */ + /* * ctl_putsys - output a system variable @@ -1433,12 +1588,34 @@ ctl_putsys( char *s, *t, *be; const char *ss; int i; - struct ctl_var *k; - sockaddr_u sau; + const struct ctl_var *k; #ifdef AUTOKEY struct cert_info *cp; char cbuf[256]; #endif /* AUTOKEY */ +#ifdef KERNEL_PLL + static struct timex ntx; + static u_long ntp_adjtime_time; + const double tscale = +# ifdef STA_NANO + 1e-9; +# else + 1e-6; +# endif + const double to_ms = 1e3 * tscale; + + /* + * CS_K_* variables depend on up-to-date output of ntp_adjtime() + */ + if (CS_KERN_FIRST <= varid && varid <= CS_KERN_LAST && + current_time != ntp_adjtime_time) { + memset(&ntx, 0, sizeof(ntx)); + if (ntp_adjtime(&ntx) < 0) + msyslog(LOG_ERR, "ntp_adjtime() for mode 6 query failed: %m"); + else + ntp_adjtime_time = current_time; + } +#endif /* KERNEL_PLL */ switch (varid) { @@ -1761,6 +1938,150 @@ ctl_putsys( ctl_putuint(sys_var[varid].text, current_time - auth_timereset); break; + + /* + * CTL_IF_KERNLOOP() puts a zero if the kernel loop is + * unavailable, otherwise calls putfunc with args. + */ +#ifndef KERNEL_PLL +# define CTL_IF_KERNLOOP(putfunc, args) \ + ctl_putint(sys_var[varid].text, 0) +#else +# define CTL_IF_KERNLOOP(putfunc, args) \ + putfunc args +#endif + + /* + * CTL_IF_KERNPPS() puts a zero if either the kernel + * loop is unavailable, or kernel hard PPS is not + * active, otherwise calls putfunc with args. + */ +#ifndef KERNEL_PLL +# define CTL_IF_KERNPPS(putfunc, args) \ + ctl_putint(sys_var[varid].text, 0) +#else +# define CTL_IF_KERNPPS(putfunc, args) \ + if (0 == ntx.shift) \ + ctl_putint(sys_var[varid].text, 0); \ + else \ + putfunc args /* no trailing ; */ +#endif + + case CS_K_OFFSET: + CTL_IF_KERNLOOP( + ctl_putdblf, + (sys_var[varid].text, "%g", to_ms * ntx.offset) + ); + break; + + case CS_K_FREQ: + CTL_IF_KERNLOOP( + ctl_putsfp, + (sys_var[varid].text, ntx.freq) + ); + break; + + case CS_K_MAXERR: + CTL_IF_KERNLOOP( + ctl_putdblf, + (sys_var[varid].text, "%.6g", + to_ms * ntx.maxerror) + ); + break; + + case CS_K_ESTERR: + CTL_IF_KERNLOOP( + ctl_putdblf, + (sys_var[varid].text, "%.6g", + to_ms * ntx.esterror) + ); + break; + + case CS_K_STFLAGS: +#ifndef KERNEL_PLL + str[0] = '\0'; +#else + kstatus_to_text(ntx.status, str, sizeof(str)); +#endif + ctl_putstr(sys_var[varid].text, str, strlen(str)); + break; + + case CS_K_TIMECONST: + CTL_IF_KERNLOOP( + ctl_putint, + (sys_var[varid].text, ntx.constant) + ); + break; + + case CS_K_PRECISION: + CTL_IF_KERNLOOP( + ctl_putdblf, + (sys_var[varid].text, "%.6g", + to_ms * ntx.precision) + ); + break; + + case CS_K_FREQTOL: + CTL_IF_KERNLOOP( + ctl_putsfp, + (sys_var[varid].text, ntx.tolerance) + ); + break; + + case CS_K_PPS_FREQ: + CTL_IF_KERNPPS( + ctl_putsfp, + (sys_var[varid].text, ntx.ppsfreq) + ); + break; + + case CS_K_PPS_STABIL: + CTL_IF_KERNPPS( + ctl_putsfp, + (sys_var[varid].text, ntx.stabil) + ); + break; + + case CS_K_PPS_JITTER: + CTL_IF_KERNPPS( + ctl_putdbl, + (sys_var[varid].text, to_ms * ntx.jitter) + ); + break; + + case CS_K_PPS_CALIBDUR: + CTL_IF_KERNPPS( + ctl_putint, + (sys_var[varid].text, 1 << ntx.shift) + ); + break; + + case CS_K_PPS_CALIBS: + CTL_IF_KERNPPS( + ctl_putint, + (sys_var[varid].text, ntx.calcnt) + ); + break; + + case CS_K_PPS_CALIBERRS: + CTL_IF_KERNPPS( + ctl_putint, + (sys_var[varid].text, ntx.errcnt) + ); + + case CS_K_PPS_JITEXC: + CTL_IF_KERNPPS( + ctl_putint, + (sys_var[varid].text, ntx.jitcnt) + ); + break; + + case CS_K_PPS_STBEXC: + CTL_IF_KERNPPS( + ctl_putint, + (sys_var[varid].text, ntx.stbcnt) + ); + break; #ifdef AUTOKEY case CS_FLAGS: if (crypto_flags) @@ -1837,7 +2158,7 @@ ctl_putpeer( char *t; char *be; int i; - struct ctl_var *k; + const struct ctl_var *k; #ifdef AUTOKEY struct autokey *ap; const EVP_MD *dp; @@ -2154,6 +2475,12 @@ ctl_putclock( int mustput ) { + char buf[CTL_MAX_DATA_LEN]; + char *s, *t, *be; + const char *ss; + int i; + const struct ctl_var *k; + switch (id) { case CC_TYPE: @@ -2238,11 +2565,6 @@ ctl_putclock( case CC_VARLIST: { - char buf[CTL_MAX_DATA_LEN]; - register char *s, *t, *be; - register const char *ss; - register int i; - register struct ctl_var *k; s = buf; be = buf + sizeof(buf); @@ -2306,18 +2628,19 @@ ctl_putclock( /* * ctl_getitem - get the next data item from the incoming packet */ -static struct ctl_var * +static const struct ctl_var * ctl_getitem( - struct ctl_var *var_list, + const struct ctl_var *var_list, char **data ) { - static struct ctl_var eol = { 0, EOV, NULL }; + static const struct ctl_var eol = { 0, EOV, NULL }; static char buf[128]; static u_long quiet_until; - register struct ctl_var *v; - register char *cp; - register char *tp; + const struct ctl_var *v; + const char *pch; + char *cp; + char *tp; /* * Delete leading commas and white space @@ -2339,13 +2662,13 @@ ctl_getitem( cp = reqpt; for (v = var_list; !(EOV & v->flags); v++) { if (!(PADDING & v->flags) && *cp == *(v->text)) { - tp = v->text; - while ('\0' != *tp && '=' != *tp && cp < reqend - && *cp == *tp) { + pch = v->text; + while ('\0' != *pch && '=' != *pch && cp < reqend + && *cp == *pch) { cp++; - tp++; + pch++; } - if ('\0' == *tp || '=' == *tp) { + if ('\0' == *pch || '=' == *pch) { while (cp < reqend && isspace((u_char)*cp)) cp++; if (cp == reqend || ',' == *cp) { @@ -2433,9 +2756,9 @@ read_status( int restrict_mask ) { - register struct peer *peer; - register u_char *cp; - register int n; + struct peer *peer; + const u_char *cp; + int n; /* a_st holds association ID, status pairs alternating */ u_short a_st[CTL_MAX_DATA_LEN / sizeof(u_short)]; @@ -2490,10 +2813,10 @@ read_status( static void read_peervars(void) { - register struct ctl_var *v; - register struct peer *peer; - register u_char *cp; - register int i; + const struct ctl_var *v; + struct peer *peer; + const u_char *cp; + int i; char * valuep; u_char wants[CP_MAXCODE + 1]; u_int gotvar; @@ -2538,13 +2861,13 @@ read_peervars(void) static void read_sysvars(void) { - register struct ctl_var *v; - register struct ctl_var *kv; + const struct ctl_var *v; + struct ctl_var *kv; u_int n; u_int gotvar; - u_char *cs; + const u_char *cs; char * valuep; - char * pch; + const char * pch; u_char *wants; size_t wants_count; @@ -2628,8 +2951,8 @@ write_variables( int restrict_mask ) { - register struct ctl_var *v; - register int ext_var; + const struct ctl_var *v; + int ext_var; char *valuep; long val = 0; @@ -3142,7 +3465,7 @@ static void read_mru_list( sockaddr_u addr[COUNTOF(last)]; char buf[128]; struct ctl_var * in_parms; - struct ctl_var * v; + const struct ctl_var * v; char * val; const char * pch; char * pnonce; @@ -3510,14 +3833,14 @@ read_clockstatus( */ ctl_error(CERR_BADASSOC); #else - register struct ctl_var *v; - register int i; - register struct peer *peer; + const struct ctl_var *v; + int i; + struct peer *peer; char *valuep; u_char *wants; unsigned int gotvar; - register u_char *cc; - register struct ctl_var *kv; + const u_char *cc; + struct ctl_var *kv; struct refclockstat cs; if (res_associd) @@ -4037,10 +4360,10 @@ ctl_clr_stats(void) static u_short count_var( - struct ctl_var *k + const struct ctl_var *k ) { - register u_int c; + u_int c; if (NULL == k) return 0; @@ -4061,20 +4384,22 @@ add_var( u_short def ) { - register u_short c; + u_short c; struct ctl_var *k; + char * buf; c = count_var(*kv); *kv = erealloc(*kv, (c + 2) * sizeof(**kv)); k = *kv; + buf = emalloc(size); k[c].code = c; - k[c].text = emalloc(size); + k[c].text = buf; k[c].flags = def; k[c + 1].code = 0; k[c + 1].text = NULL; k[c + 1].flags = EOV; - return k[c].text; + return buf; } @@ -4086,9 +4411,9 @@ set_var( u_short def ) { - register struct ctl_var *k; - register const char *s; - register const char *t; + struct ctl_var *k; + const char *s; + const char *t; char *td; if (NULL == data || !size) @@ -4098,8 +4423,9 @@ set_var( if (k != NULL) { while (!(EOV & k->flags)) { if (NULL == k->text) { - k->text = emalloc(size); - memcpy(k->text, data, size); + td = emalloc(size); + memcpy(td, data, size); + k->text = td; k->flags = def; return; } else { @@ -4110,9 +4436,9 @@ set_var( t++; } if (*s == *t && ((*t == '=') || !*t)) { - k->text = erealloc(k->text, - size); - memcpy(k->text, data, size); + td = erealloc(k->text, size); + memcpy(td, data, size); + k->text = td; k->flags = def; return; } diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 31a566e2c..548b93ed3 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -4409,9 +4409,9 @@ find_flagged_addr_in_list( } -char * +const char * localaddrtoa( - struct interface *la + endpt *la ) { return (NULL == la) diff --git a/ntpd/ntp_request.c b/ntpd/ntp_request.c index 05537e9db..75e98d0ee 100644 --- a/ntpd/ntp_request.c +++ b/ntpd/ntp_request.c @@ -57,7 +57,7 @@ struct req_proc { /* * Universal request codes */ -static struct req_proc univ_codes[] = { +static const struct req_proc univ_codes[] = { { NO_REQUEST, NOAUTH, 0, 0 } }; @@ -120,7 +120,7 @@ static void get_clkbug_info (sockaddr_u *, struct interface *, struct req_pkt *) /* * ntpd request codes */ -static struct req_proc ntp_codes[] = { +static const struct req_proc ntp_codes[] = { { REQ_PEER_LIST, NOAUTH, 0, 0, list_peers }, { REQ_PEER_LIST_SUM, NOAUTH, 0, 0, list_peers_sum }, { REQ_PEER_INFO, NOAUTH, v4sizeof(struct info_peer_list), @@ -179,7 +179,7 @@ static struct req_proc ntp_codes[] = { get_clkbug_info }, #endif { REQ_IF_STATS, AUTH, 0, 0, get_if_stats }, - { REQ_IF_RELOAD, AUTH, 0, 0, do_if_reload }, + { REQ_IF_RELOAD, AUTH, 0, 0, do_if_reload }, { NO_REQUEST, NOAUTH, 0, 0, 0 } }; @@ -415,7 +415,7 @@ process_private( struct req_pkt_tail *tailinpkt; sockaddr_u *srcadr; struct interface *inter; - struct req_proc *proc; + const struct req_proc *proc; int ec; short temp_size; l_fp ftmp; diff --git a/ntpdate/ntpdate.c b/ntpdate/ntpdate.c index 907c0cc5a..bd7d4869b 100644 --- a/ntpdate/ntpdate.c +++ b/ntpdate/ntpdate.c @@ -2127,7 +2127,7 @@ printserver( { register int i; char junk[5]; - char *str; + const char *str; if (!debug) { (void) fprintf(fp, "server %s, stratum %d, offset %s, delay %s\n", diff --git a/ntpdc/ntpdc.c b/ntpdc/ntpdc.c index b5369e459..e7d449b79 100644 --- a/ntpdc/ntpdc.c +++ b/ntpdc/ntpdc.c @@ -1469,7 +1469,7 @@ getnetnum( * nntohost - convert network number to host name. This routine enforces * the showhostnames setting. */ -char * +const char * nntohost( sockaddr_u *netnum ) diff --git a/ntpdc/ntpdc.h b/ntpdc/ntpdc.h index 9d41a70cc..bfc222863 100644 --- a/ntpdc/ntpdc.h +++ b/ntpdc/ntpdc.h @@ -64,4 +64,4 @@ extern int showhostnames; extern int s_port; extern int doquery (int, int, int, int, int, char *, int *, int *, char **, int, int); -extern char * nntohost (sockaddr_u *); +extern const char * nntohost (sockaddr_u *); diff --git a/ntpdc/ntpdc_ops.c b/ntpdc/ntpdc_ops.c index 3b7f0447c..4d4b3704e 100644 --- a/ntpdc/ntpdc_ops.c +++ b/ntpdc/ntpdc_ops.c @@ -86,8 +86,8 @@ static void clockstat (struct parse *, FILE *); static void fudge (struct parse *, FILE *); static void clkbug (struct parse *, FILE *); static void kerninfo (struct parse *, FILE *); -static void get_if_stats (struct parse *, FILE *); -static void do_if_reload (struct parse *, FILE *); +static void get_if_stats (struct parse *, FILE *); +static void do_if_reload (struct parse *, FILE *); /* * Commands we understand. Ntpdc imports this. @@ -2971,9 +2971,9 @@ again: (void)fprintf(fp, "pll frequency: %s ppm\n", fptoa((s_fp)ntohl(ik->freq), 3)); (void)fprintf(fp, "maximum error: %g s\n", - (u_long)ntohl(ik->maxerror) * 1e-6); + (u_long)ntohl(ik->maxerror) * tscale); (void)fprintf(fp, "estimated error: %g s\n", - (u_long)ntohl(ik->esterror) * 1e-6); + (u_long)ntohl(ik->esterror) * tscale); (void)fprintf(fp, "status: %04x ", status); #ifdef STA_PLL if (status & STA_PLL) (void)fprintf(fp, " pll"); diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index cb4a065cd..a1b862b35 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -70,6 +70,7 @@ static void mrulist (struct parse *, FILE *); static void ifstats (struct parse *, FILE *); static void sysstats (struct parse *, FILE *); static void sysinfo (struct parse *, FILE *); +static void kerninfo (struct parse *, FILE *); static void monstats (struct parse *, FILE *); /* @@ -175,6 +176,9 @@ struct xcmd opcmds[] = { { "sysinfo", sysinfo, { NO, NO, NO, NO }, { "", "", "", "" }, "display system summary" }, + { "kerninfo", kerninfo, { NO, NO, NO, NO }, + { "", "", "", "" }, + "display kernel loop and PPS statistics" }, { "sysstats", sysstats, { NO, NO, NO, NO }, { "", "", "", "" }, "display system uptime and packet counts" }, @@ -3227,7 +3231,7 @@ collect_display_vdc( char *tag; char *val; u_int n; - size_t taglen; + size_t len; int match; u_long ul; int vtype; @@ -3257,17 +3261,17 @@ collect_display_vdc( */ while (nextvar(&rsize, &rdata, &tag, &val)) { for (pvdc = table; pvdc->tag != NULL; pvdc++) { - taglen = strlen(pvdc->tag); - if (strncmp(tag, pvdc->tag, taglen)) + len = strlen(pvdc->tag); + if (strncmp(tag, pvdc->tag, len)) continue; if (NTP_ADD != pvdc->type) { - if ('\0' != tag[taglen]) + if ('\0' != tag[len]) continue; break; } match = FALSE; for (n = 0; n < COUNTOF(suf); n++) { - if (strcmp(tag + taglen, suf[n])) + if (strcmp(tag + len, suf[n])) continue; match = TRUE; break; @@ -3279,7 +3283,16 @@ collect_display_vdc( continue; switch (pvdc->type) { - case NTP_STR: /* fallthru */ + case NTP_STR: + /* strip surrounding double quotes */ + if ('"' == val[0]) { + len = strlen(val); + if (len > 0 && '"' == val[len - 1]) { + val[len - 1] = '\0'; + val++; + } + } + /* fallthru */ case NTP_MODE: /* fallthru */ case NTP_2BIT: pvdc->v.str = estrdup(val); @@ -3386,7 +3399,7 @@ sysstats( collect_display_vdc(0, sysstats_vdc, FALSE, fp); } - + /* * sysinfo - modeled on ntpdc's sysinfo */ @@ -3418,6 +3431,39 @@ sysinfo( } +/* + * kerninfo - modeled on ntpdc's kerninfo + */ +static void +kerninfo( + struct parse *pcmd, + FILE *fp + ) +{ + static vdc kerninfo_vdc[] = { + { "koffset", "pll offset: ", NTP_STR }, + { "kfreq", "pll frequency: ", NTP_STR }, + { "kmaxerr", "maximum error: ", NTP_STR }, + { "kesterr", "estimated error: ", NTP_STR }, + { "kstflags", "kernel status: ", NTP_STR }, + { "ktimeconst", "pll time constant: ", NTP_STR }, + { "kprecis", "precision: ", NTP_STR }, + { "kfreqtol", "frequency tolerance: ", NTP_STR }, + { "kppsfreq", "pps frequency: ", NTP_STR }, + { "kppsstab", "pps stability: ", NTP_STR }, + { "kppsjitter", "pps jitter: ", NTP_STR }, + { "kppscalibdur", "calibration interval ", NTP_STR }, + { "kppscalibs", "calibration cycles: ", NTP_STR }, + { "kppsjitexc", "jitter exceeded: ", NTP_STR }, + { "kppsstbexc", "stability exceeded: ", NTP_STR }, + { "kppscaliberrs", "calibration errors: ", NTP_STR }, + { NULL, NULL, 0 } + }; + + collect_display_vdc(0, kerninfo_vdc, TRUE, fp); +} + + /* * monstats - implements ntpq -c monstats */ diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 6c1eebfaa..0f7ffd029 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -294,7 +294,7 @@ static void atoascii (const char *, size_t, char *, size_t); static void cookedprint (int, int, const char *, int, int, FILE *); static void rawprint (int, int, const char *, int, int, FILE *); static void startoutput (void); -static void output (FILE *, char *, char *); +static void output (FILE *, const char *, const char *); static void endoutput (FILE *); static void outputarr (FILE *, char *, int, l_fp *); static int assoccmp (const void *, const void *); @@ -1827,7 +1827,7 @@ getnetnum( * nntohost - convert network number to host name. This routine enforces * the showhostnames setting. */ -char * +const char * nntohost( sockaddr_u *netnum ) @@ -1844,7 +1844,7 @@ nntohost( /* * nntohostp() is the same as nntohost() plus a :port suffix */ -char * +const char * nntohostp( sockaddr_u *netnum ) @@ -3010,8 +3010,8 @@ startoutput(void) static void output( FILE *fp, - char *name, - char *value + const char *name, + const char *value ) { size_t len; diff --git a/ntpq/ntpq.h b/ntpq/ntpq.h index bf653b08e..5aa001106 100644 --- a/ntpq/ntpq.h +++ b/ntpq/ntpq.h @@ -128,8 +128,8 @@ extern int doquery (int, associd_t, int, int, const char *, u_short *, int *, const char **); extern int doqueryex (int, associd_t, int, int, const char *, u_short *, int *, const char **, int); -extern char * nntohost (sockaddr_u *); -extern char * nntohostp (sockaddr_u *); +extern const char * nntohost (sockaddr_u *); +extern const char * nntohostp (sockaddr_u *); extern int decodets (char *, l_fp *); extern int decodeuint (char *, u_long *); extern int nextvar (int *, const char **, char **, char **); diff --git a/sntp/kod_management.c b/sntp/kod_management.c index a0cd23c48..33ea031fc 100644 --- a/sntp/kod_management.c +++ b/sntp/kod_management.c @@ -7,7 +7,6 @@ #include "log.h" #include "sntp-opts.h" #include "ntp_stdlib.h" -//#define DEBUG int kod_init = 0, kod_db_cnt = 0; const char *kod_db_file; @@ -19,9 +18,9 @@ struct kod_entry **kod_db; /* array of pointers to kod_entry */ */ int search_entry ( - char *hostname, - struct kod_entry **dst - ) + const char *hostname, + struct kod_entry **dst + ) { register int a, b, resc = 0; @@ -49,8 +48,8 @@ search_entry ( void add_entry( - char *hostname, - char *type /* 4 bytes not \0 terminated */ + const char * hostname, + const char * type /* 4 bytes not \0 terminated */ ) { int n; @@ -89,11 +88,11 @@ add_entry( void delete_entry( - char *hostname, - char *type + const char * hostname, + const char * type ) { - register int a; + int a; for (a = 0; a < kod_db_cnt; a++) if (!strcmp(kod_db[a]->hostname, hostname) diff --git a/sntp/kod_management.h b/sntp/kod_management.h index 70903a52a..63e68ab57 100644 --- a/sntp/kod_management.h +++ b/sntp/kod_management.h @@ -9,10 +9,9 @@ struct kod_entry { char type[5]; }; -int search_entry(char *hostname, struct kod_entry **dst); - -void add_entry(char *hostname, char *type); -void delete_entry(char *hostname, char *type); +int search_entry(const char *hostname, struct kod_entry **dst); +void add_entry(const char *hostname, const char *type); +void delete_entry(const char *hostname, const char *type); void kod_init_kod_db(const char *db_file); void write_kod_db(void);