[Git][NTPsec/ntpsec][master] 3 commits: Fix for Issue #424, 32 bit overflow on counters

Hal Murray gitlab at mg.gitlab.com
Sat Dec 16 11:25:47 UTC 2017


Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
c1048d7e by Hal Murray at 2017-12-14T17:27:31-08:00
Fix for Issue #424, 32 bit overflow on counters

- - - - -
abde4b76 by Hal Murray at 2017-12-14T17:27:31-08:00
More uint64_t for counters

Also removed a few casts that didn't seem useful.
That may add some warnings, but not on any of my systmes.

- - - - -
6bd165b7 by Hal Murray at 2017-12-14T19:30:06-08:00
Add uptime_t for seconds since ntpd was started

- - - - -


16 changed files:

- include/ntp.h
- include/ntp_refclock.h
- include/ntp_types.h
- include/ntpd.h
- ntpd/ntp_control.c
- ntpd/ntp_io.c
- ntpd/ntp_loopfilter.c
- ntpd/ntp_monitor.c
- ntpd/ntp_peer.c
- ntpd/ntp_proto.c
- ntpd/ntp_refclock.c
- ntpd/ntp_signd.c
- ntpd/ntp_timer.c
- ntpd/ntp_util.c
- ntpd/refclock_generic.c
- tests/ntpd/restrict.c


Changes:

=====================================
include/ntp.h
=====================================
--- a/include/ntp.h
+++ b/include/ntp.h
@@ -267,14 +267,14 @@ struct peer {
 	uint8_t	new_status;	/* under-construction status */
 	uint8_t	reach;		/* reachability register */
 	int	flash;		/* protocol error test tally bits */
-	unsigned long	epoch;		/* reference epoch */
+	uptime_t	epoch;	/* reference epoch */
 	int	burst;		/* packets remaining in burst */
 	int	retry;		/* retry counter */
 	int	filter_nextpt;	/* index into filter shift register */
 	double	filter_delay[NTP_SHIFT]; /* delay shift register */
 	double	filter_offset[NTP_SHIFT]; /* offset shift register */
 	double	filter_disp[NTP_SHIFT]; /* dispersion shift register */
-	unsigned long	filter_epoch[NTP_SHIFT]; /* epoch shift register */
+	uptime_t	filter_epoch[NTP_SHIFT]; /* epoch shift register */
 	uint8_t	filter_order[NTP_SHIFT]; /* filter sort index */
 	l_fp	rec;		/* receive time stamp */
 	l_fp	xmt;		/* transmit time stamp */
@@ -304,8 +304,8 @@ struct peer {
 #define end_clear_to_zero update
 	int	unreach;	/* watchdog counter */
 	int	throttle;	/* rate control */
-	unsigned long	outdate;	/* send time last packet */
-	unsigned long	nextdate;	/* send time next packet */
+	uptime_t	outdate;	/* send time last packet */
+	uptime_t	nextdate;	/* send time next packet */
 
 	/*
 	 * Statistic counters


=====================================
include/ntp_refclock.h
=====================================
--- a/include/ntp_refclock.h
+++ b/include/ntp_refclock.h
@@ -143,7 +143,7 @@ struct refclockproc {
 	/*
 	 * Status tallies
  	 */
-	unsigned long	timestarted;	/* time we started this */
+	uptime_t		timestarted;	/* time we started this */
 	unsigned long	polls;		/* polls sent */
 	unsigned long	noreply;	/* no replies to polls */
 	unsigned long	badformat;	/* bad format reply */


=====================================
include/ntp_types.h
=====================================
--- a/include/ntp_types.h
+++ b/include/ntp_types.h
@@ -13,6 +13,8 @@
 #include <limits.h>
 #include "ntp_machine.h"
 
+typedef uint32_t uptime_t;	/* seconds since startup */
+
 
 /*
  * This is another naming conflict.


=====================================
include/ntpd.h
=====================================
--- a/include/ntpd.h
+++ b/include/ntpd.h
@@ -232,15 +232,15 @@ extern	void	reset_auth_stats(void);
 /*
  * Other statistics of possible interest
  */
-extern unsigned long packets_dropped;	/* # packets dropped on reception */
-extern unsigned long packets_ignored;	/* received on wild card interface */
-extern unsigned long packets_received;	/* total number of packets received */
-extern unsigned long packets_sent;	/* total number of packets sent */
-extern unsigned long packets_notsent; 	/* total number of packets which couldn't be sent */
+extern uint64_t packets_dropped;	/* # packets dropped on reception */
+extern uint64_t packets_ignored;	/* received on wild card interface */
+extern uint64_t packets_received;	/* total number of packets received */
+extern uint64_t packets_sent;		/* total number of packets sent */
+extern uint64_t packets_notsent; 	/* total number of packets which couldn't be sent */
 
-extern volatile unsigned long handler_calls;	/* number of calls to interrupt handler */
-extern volatile unsigned long handler_pkts;	/* number of pkts received by handler */
-extern unsigned long	io_timereset;		/* time counters were reset */
+extern volatile uint64_t handler_calls;	/* number of calls to interrupt handler */
+extern volatile uint64_t handler_pkts;	/* number of pkts received by handler */
+extern unsigned long io_timereset;	/* time counters were reset */
 
 /* ntp_io.c */
 extern bool	disable_dynamic_updates;
@@ -286,19 +286,19 @@ extern uint8_t	mon_hash_bits;		/* log2 size of hash table */
 extern mon_entry ** mon_hash;		/* MRU hash table */
 extern mon_entry mon_mru_list;		/* mru listhead */
 extern unsigned int	mon_enabled;		/* MON_OFF (0) or other MON_* */
-extern unsigned int	mru_entries;		/* mru list count */
-extern unsigned int	mru_peakentries;	/* highest mru_entries */
-extern unsigned int	mru_initalloc;		/* entries to preallocate */
-extern unsigned int	mru_incalloc;		/* allocation batch factor */
-extern unsigned int	mru_mindepth;		/* preempt above this */
+extern uint64_t	mru_entries;		/* mru list count */
+extern uint64_t	mru_peakentries;	/* highest mru_entries */
+extern uint64_t	mru_initalloc;		/* entries to preallocate */
+extern uint64_t	mru_incalloc;		/* allocation batch factor */
+extern uint64_t	mru_mindepth;		/* preempt above this */
 extern int	mru_maxage;		/* recycle if older than this */
 extern int	mru_minage;		/* recycle if older than this & full */
-extern unsigned int	mru_maxdepth; 		/* MRU size hard limit */
-extern unsigned long	mru_exists;		/* slot already exists */
-extern unsigned long	mru_new;		/* allocated new slot */
-extern unsigned long	mru_recycleold;		/* recycle: age > maxage */
-extern unsigned long	mru_recyclefull;	/* recycle: full and age > minage */
-extern unsigned long	mru_none;		/* couldn't allocate slot */
+extern uint64_t	mru_maxdepth; 		/* MRU size hard limit */
+extern uint64_t	mru_exists;		/* slot already exists */
+extern uint64_t	mru_new;		/* allocated new slot */
+extern uint64_t	mru_recycleold;		/* recycle: age > maxage */
+extern uint64_t	mru_recyclefull;	/* recycle: full and age > minage */
+extern uint64_t	mru_none;		/* couldn't allocate slot */
 extern int	mon_age;		/* preemption limit */
 
 /* ntp_peer.c */
@@ -333,18 +333,18 @@ extern int	sys_minsane;		/* minimum candidates */
 /*
  * Statistics counters
  */
-extern unsigned long	sys_stattime;		/* time since reset */
-extern unsigned long	sys_received;		/* packets received */
-extern unsigned long	sys_processed;		/* packets for this host */
-extern unsigned long	sys_restricted;	 	/* restricted packets */
-extern unsigned long	sys_newversion;		/* current version  */
-extern unsigned long	sys_oldversion;		/* old version */
-extern unsigned long	sys_badlength;		/* bad length or format */
-extern unsigned long	sys_badauth;		/* bad authentication */
-extern unsigned long	sys_declined;		/* declined */
-extern unsigned long	sys_limitrejected;	/* rate exceeded */
-extern unsigned long	sys_kodsent;		/* KoD sent */
-extern unsigned long	use_stattime;		/* time since reset */
+extern uptime_t	sys_stattime;		/* time since sysstats reset */
+extern uint64_t	sys_received;		/* packets received */
+extern uint64_t	sys_processed;		/* packets for this host */
+extern uint64_t	sys_restricted;	 	/* restricted packets */
+extern uint64_t	sys_newversion;		/* current version  */
+extern uint64_t	sys_oldversion;		/* old version */
+extern uint64_t	sys_badlength;		/* bad length or format */
+extern uint64_t	sys_badauth;		/* bad authentication */
+extern uint64_t	sys_declined;		/* declined */
+extern uint64_t	sys_limitrejected;	/* rate exceeded */
+extern uint64_t	sys_kodsent;		/* KoD sent */
+extern uptime_t	use_stattime;		/* time since usestats reset */
 
 /* Signalling */
 extern volatile bool sawALRM;
@@ -368,8 +368,8 @@ extern void send_via_ntp_signd(struct recvbuf *, int, keyid_t, int,
 
 /* ntp_timer.c */
 extern volatile unsigned long alarm_overflow;
-extern unsigned long	current_time;		/* seconds since startup */
-extern unsigned long	timer_timereset;
+extern uptime_t	current_time;		/* seconds since startup */
+extern uptime_t	timer_timereset;
 extern unsigned long	timer_xmtcalls;
 extern bool		leap_sec_in_progress;
 #ifdef ENABLE_LEAP_SMEAR


=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -59,8 +59,8 @@ static	void	ctl_putdblf	(const char *, int, int, double);
 #define	ctl_putdbl6(tag, d)	ctl_putdblf(tag, 1, 6, d)
 #define	ctl_putsfp(tag, sfp)	ctl_putdblf(tag, 0, -1, \
 					    FP_UNSCALE(sfp))
-static	void	ctl_putuint	(const char *, unsigned long);
-static	void	ctl_puthex	(const char *, unsigned long);
+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_putts	(const char *, l_fp *);
 static	void	ctl_putadr	(const char *, uint32_t,
@@ -620,20 +620,20 @@ static	uint8_t ctl_sys_num_events;
  * Statistic counters to keep track of requests and responses.
  */
 static unsigned long ctltimereset;	/* time stats reset */
-static unsigned long numctlreq;		/* # of requests we've received */
-static unsigned long numctlbadpkts;	/* # of bad control packets */
-static unsigned long numctlresponses;	/* # of resp packets sent with data */
-static unsigned long numctlfrags;	/* # of fragments sent */
-static unsigned long numctlerrors;	/* # of error responses sent */
-static unsigned long numctltooshort;	/* # of too short input packets */
-static unsigned long numctlinputresp;	/* # of responses on input */
-static unsigned long numctlinputfrag;	/* # of fragments on input */
-static unsigned long numctlinputerr;	/* # of input pkts with err bit set */
-static unsigned long numctlbadoffset;	/* # of input pkts with nonzero offset */
-static unsigned long numctlbadversion;	/* # of input pkts with unknown version */
-static unsigned long numctldatatooshort;    /* data too short for count */
-static unsigned long numctlbadop;	/* bad op code found in packet */
-static unsigned long numasyncmsgs;	/* # of async messages we've sent */
+static uint64_t numctlreq;		/* # of requests we've received */
+static uint64_t numctlbadpkts;		/* # of bad control packets */
+static uint64_t numctlresponses;	/* # of resp packets sent with data */
+static uint64_t numctlfrags;		/* # of fragments sent */
+static uint64_t numctlerrors;		/* # of error responses sent */
+static uint64_t numctltooshort;		/* # of too short input packets */
+static uint64_t numctlinputresp;	/* # of responses on input */
+static uint64_t numctlinputfrag;	/* # of fragments on input */
+static uint64_t numctlinputerr;		/* # of input pkts with err bit set */
+static uint64_t numctlbadoffset;	/* # of input pkts with nonzero offset */
+static uint64_t numctlbadversion;	/* # of input pkts with unknown version */
+static uint64_t numctldatatooshort;	/* data too short for count */
+static uint64_t numctlbadop;		/* bad op code found in packet */
+static uint64_t numasyncmsgs;		/* # of async messages we've sent */
 
 /*
  * Response packet used by these routines. Also some state information
@@ -1186,7 +1186,7 @@ ctl_putdblf(
 static void
 ctl_putuint(
 	const char *tag,
-	unsigned long uval
+	uint64_t uval
 	)
 {
 	char *cp;
@@ -1200,7 +1200,11 @@ ctl_putuint(
 
 	*cp++ = '=';
 	INSIST((cp - buffer) < (int)sizeof(buffer));
+#if (NTP_SIZEOF_LONG == 8)
 	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "%lu", uval);
+#else
+	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "%llu", uval);
+#endif
 	cp += strlen(cp);
 	ctl_putdata(buffer, (unsigned)( cp - buffer ), false);
 }
@@ -1245,7 +1249,7 @@ ctl_puttime(
 static void
 ctl_puthex(
 	const char *tag,
-	unsigned long uval
+	uint64_t uval
 	)
 {
 	char *cp;
@@ -1259,7 +1263,11 @@ ctl_puthex(
 
 	*cp++ = '=';
 	INSIST((cp - buffer) < (int)sizeof(buffer));
+#if (NTP_SIZEOF_LONG == 8)
 	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "0x%lx", uval);
+#else
+	snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer), "0x%llx", uval);
+#endif
 	cp += strlen(cp);
 	ctl_putdata(buffer,(unsigned)( cp - buffer ), false);
 }
@@ -1432,8 +1440,6 @@ ctl_putsys(
 {
 	l_fp tmp;
 	char str[256];
-	unsigned int u;
-	double kb;
 	double dtemp;
 	const char *ss;
 	static struct timex ntx;
@@ -1505,12 +1511,14 @@ ctl_putsys(
 		ctl_putunqstr(sys_var[CS_PEERADR].text, ss, strlen(ss));
 		break;
 
-	case CS_PEERMODE:
+	case CS_PEERMODE: {
+		uint64_t u;
 		u = (sys_peer != NULL)
 			? sys_peer->hmode
 			: MODE_UNSPEC;
 		ctl_putuint(sys_var[CS_PEERMODE].text, u);
 		break;
+		}
 
 	case CS_OFFSET:
 		ctl_putdbl6(sys_var[CS_OFFSET].text, last_offset * MS_PER_S);
@@ -1665,13 +1673,13 @@ ctl_putsys(
 		ctl_putuint(sys_var[varid].text, mru_entries);
 		break;
 
-	case CS_MRU_MEM:
-		kb = mru_entries * (sizeof(mon_entry) / 1024.);
-		u = (unsigned int)kb;
-		if (kb - u >= 0.5)
-			u++;
+	case CS_MRU_MEM: {
+		uint64_t u;
+		u = mru_entries * sizeof(mon_entry);
+		u = (u+512)/1024;
 		ctl_putuint(sys_var[varid].text, u);
 		break;
+		}
 
 	case CS_MRU_DEEPEST:
 		ctl_putuint(sys_var[varid].text, mru_peakentries);
@@ -1693,13 +1701,13 @@ ctl_putsys(
 		ctl_putuint(sys_var[varid].text, mru_maxdepth);
 		break;
 
-	case CS_MRU_MAXMEM:
-		kb = mru_maxdepth * (sizeof(mon_entry) / 1024.);
-		u = (unsigned int)kb;
-		if (kb - u >= 0.5)
-			u++;
+	case CS_MRU_MAXMEM: {
+		uint64_t u;
+		u = mru_maxdepth * sizeof(mon_entry);
+		u = (u+512)/1024;
 		ctl_putuint(sys_var[varid].text, u);
 		break;
+		}
 
 	case CS_MRU_EXISTS:
 		ctl_putuint(sys_var[varid].text, mru_exists);
@@ -1724,8 +1732,7 @@ ctl_putsys(
 	case CS_MRU_OLDEST_AGE: {
 		l_fp now;
 		get_systime(&now);
-		ctl_putuint(sys_var[varid].text,
-                            (unsigned long)mon_get_oldest_age(now));
+		ctl_putuint(sys_var[varid].text, mon_get_oldest_age(now));
 		break;
 		}
 
@@ -1734,8 +1741,7 @@ ctl_putsys(
 		break;
 
 	case CS_SS_RESET:
-		ctl_putuint(sys_var[varid].text,
-			    current_time - sys_stattime);
+		ctl_putuint(sys_var[varid].text, current_time - sys_stattime);
 		break;
 
 	case CS_SS_RECEIVED:
@@ -2090,7 +2096,7 @@ ctl_putpeer(
 		break;
 
 	case CP_RATE:
-		ctl_putuint(peer_var[id].text, (unsigned long)p->throttle);
+		ctl_putuint(peer_var[id].text, p->throttle);
 		break;
 
 	case CP_LEAP:
@@ -2161,7 +2167,7 @@ ctl_putpeer(
 		break;
 
 	case CP_FLASH:
-		ctl_puthex(peer_var[id].text, (unsigned long)p->flash);
+		ctl_puthex(peer_var[id].text, p->flash);
 		break;
 
 	case CP_TTL:
@@ -3675,7 +3681,7 @@ send_ifstats_entry(
 
 		case 4:
 			snprintf(tag, sizeof(tag), flags_fmt, ifnum);
-			ctl_puthex(tag, (unsigned int)la->flags);
+			ctl_puthex(tag, la->flags);
 			break;
 
 		case 5:
@@ -4180,7 +4186,7 @@ report_event(
 			msyslog(LOG_INFO, "MODE6: %s", statstr);
 	}
 	record_proto_stats(statstr);
-	DPRINT(1, ("event at %lu %s\n", current_time, statstr));
+	DPRINT(1, ("event at %u %s\n", current_time, statstr));
 
 }
 


=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -97,14 +97,14 @@ static nic_rule *nic_rule_list;
 /*
  * Other statistics of possible interest
  */
-unsigned long packets_dropped;	/* total # of packets dropped on reception */
-unsigned long packets_ignored;	/* packets received on wild card interface */
-unsigned long packets_received;	/* total # of packets received */
-unsigned long packets_sent;	/* total # of packets sent */
-unsigned long packets_notsent;	/* total # of packets which couldn't be sent */
-
-volatile unsigned long handler_calls;	/* # of calls to interrupt handler */
-volatile unsigned long handler_pkts;	/* number of pkts received by handler */
+uint64_t packets_dropped;	/* total # of packets dropped on reception */
+uint64_t packets_ignored;	/* packets received on wild card interface */
+uint64_t packets_received;	/* total # of packets received */
+uint64_t packets_sent;		/* total # of packets sent */
+uint64_t packets_notsent;	/* total # of packets which couldn't be sent */
+
+volatile uint64_t handler_calls;	/* # of calls to interrupt handler */
+volatile uint64_t handler_pkts;		/* number of pkts received by handler */
 unsigned long io_timereset;		/* time counters were reset */
 
 /*


=====================================
ntpd/ntp_loopfilter.c
=====================================
--- a/ntpd/ntp_loopfilter.c
+++ b/ntpd/ntp_loopfilter.c
@@ -114,7 +114,7 @@ uint8_t	allan_xpt = CLOCK_ALLAN; /* Allan intercept (log2 s) */
  */
 #ifndef ENABLE_LOCKCLOCK
 static double clock_offset;	/* offset */
-static unsigned long clock_epoch;	/* last update */
+static uptime_t clock_epoch;	/* last update */
 #endif /* ENABLE_LOCKCLOCK */
 double	clock_jitter;		/* offset jitter */
 double	drift_comp;		/* frequency (s/s) */


=====================================
ntpd/ntp_monitor.c
=====================================
--- a/ntpd/ntp_monitor.c
+++ b/ntpd/ntp_monitor.c
@@ -49,21 +49,24 @@ uint8_t	mon_hash_bits;
 /*
  * Pointers to the hash table and the MRU list.  Memory for the hash
  * table is allocated only if monitoring is enabled.
+ * Total size can easily exceed 32 bits (4 GB)
+ * Total count is unlikely to exceed 32 bits in 2017
+ *   but memories keep growing.
  */
 mon_entry **	mon_hash;	/* MRU hash table */
 mon_entry	mon_mru_list;	/* mru listhead */
-unsigned int	mru_entries;	/* mru list count */
+uint64_t	mru_entries;	/* mru list count */
 
-/*1
+/*
  * List of free structures, and counters of in-use and total
  * structures. The free structures are linked with the hash_next field.
  */
 static  mon_entry *mon_free;		/* free list or null if none */
-static	unsigned int mru_alloc;		/* mru list + free list count */
-	unsigned int mru_peakentries;		/* highest mru_entries seen */
-	unsigned int mru_initalloc = INIT_MONLIST;/* entries to preallocate */
-	unsigned int mru_incalloc = INC_MONLIST;/* allocation batch factor */
-static	unsigned int mon_mem_increments;	/* times called malloc() */
+static	uint64_t mru_alloc;		/* mru list + free list count */
+	uint64_t mru_peakentries;	/* highest mru_entries seen */
+	uint64_t mru_initalloc = INIT_MONLIST;/* entries to preallocate */
+	uint64_t mru_incalloc = INC_MONLIST;/* allocation batch factor */
+static	uint64_t mon_mem_increments;	/* times called malloc() */
 
 /*
  * Parameters of the RES_LIMITED restriction option. We define headway
@@ -79,10 +82,10 @@ uint8_t	ntp_minpoll = NTP_MINPOLL;	/* increment (log 2 s) */
  * we aren't, we may not even have allocated any memory yet.
  */
 unsigned int	mon_enabled;		/* enable switch */
-unsigned int	mru_mindepth = 600;	/* preempt above this */
+uint64_t	mru_mindepth = 600;	/* preempt above this */
 int		mru_maxage = 3600;	/* recycle if older than this */
 int		mru_minage = 64;	/* recycle if full and older than this */
-unsigned int	mru_maxdepth = MRU_MAXDEPTH_DEF;	/* MRU count hard limit */
+uint64_t	mru_maxdepth = MRU_MAXDEPTH_DEF;	/* MRU count hard limit */
 int	mon_age = 3000;		/* preemption limit */
 
 static	void		mon_getmoremem(void);
@@ -91,11 +94,11 @@ static	inline void	mon_free_entry(mon_entry *);
 static	inline void	mon_reclaim_entry(mon_entry *);
 
 /* MRU counters */
-unsigned long mru_exists = 0;		/* slot already exists */
-unsigned long mru_new = 0;		/* allocate a new slot (2 cases) */
-unsigned long mru_recycleold = 0;	/* recycle slot: age > mru_maxage */
-unsigned long mru_recyclefull = 0;	/* recycle slot: full and age > mru_minage */
-unsigned long mru_none = 0;		/* couldn't get one */
+uint64_t mru_exists = 0;	/* slot already exists */
+uint64_t mru_new = 0;		/* allocate a new slot (2 cases) */
+uint64_t mru_recycleold = 0;	/* recycle slot: age > mru_maxage */
+uint64_t mru_recyclefull = 0;	/* recycle slot: full and age > mru_minage */
+uint64_t mru_none = 0;		/* couldn't get one */
 
 
 /*


=====================================
ntpd/ntp_peer.c
=====================================
--- a/ntpd/ntp_peer.c
+++ b/ntpd/ntp_peer.c
@@ -357,7 +357,7 @@ clear_all(void)
 		if (!(MDF_TXONLY_MASK & p->cast_flags))
 		    peer_clear(p, "STEP", false);
 
-	DPRINT(1, ("clear_all: at %lu\n", current_time));
+	DPRINT(1, ("clear_all: at %u\n", current_time));
 }
 
 
@@ -386,7 +386,7 @@ score_all(
 			if (x < temp)
 				temp = x;
 		}
-	DPRINT(1, ("score_all: at %lu score %d min %d\n",
+	DPRINT(1, ("score_all: at %u score %d min %d\n",
 		   current_time, tamp, temp));
 
 	if (tamp != temp)


=====================================
ntpd/ntp_proto.c
=====================================
--- a/ntpd/ntp_proto.c
+++ b/ntpd/ntp_proto.c
@@ -63,7 +63,7 @@ static inline l_fp_w htonl_fp(l_fp lfp) {
 #define	NTP_MAXCLOCK	10	/* max candidates */
 #define MINDISPERSE	.001	/* min distance */
 #define CLOCK_SGATE	3.	/* popcorn spike gate */
-#define	NTP_ORPHWAIT	300	/* orphan wair (s) */
+#define	NTP_ORPHWAIT	300	/* orphan wait (s) */
 
 /*
  * pool soliciting restriction duration (s)
@@ -153,19 +153,20 @@ static int sys_orphwait = NTP_ORPHWAIT; /* orphan wait */
 
 /*
  * Statistics counters - first the good, then the bad
+ * These get reset every hour if sysstats is enabled.
  */
-unsigned long	sys_stattime;		/* elapsed time since reset */
-unsigned long	sys_received;		/* packets received */
-unsigned long	sys_processed;		/* packets for this host */
-unsigned long	sys_newversion;		/* current version */
-unsigned long	sys_oldversion;		/* old version */
-unsigned long	sys_restricted;		/* access denied */
-unsigned long	sys_badlength;		/* bad length or format */
-unsigned long	sys_badauth;		/* bad authentication */
-unsigned long	sys_declined;		/* declined */
-unsigned long	sys_limitrejected;	/* rate exceeded */
-unsigned long	sys_kodsent;		/* KoD sent */
-unsigned long	use_stattime;		/* elapsed time since reset */
+uptime_t	sys_stattime;		/* elapsed time since sysstats reset */
+uint64_t	sys_received;		/* packets received */
+uint64_t	sys_processed;		/* packets for this host */
+uint64_t	sys_newversion;		/* current version */
+uint64_t	sys_oldversion;		/* old version */
+uint64_t	sys_restricted;		/* access denied */
+uint64_t	sys_badlength;		/* bad length or format */
+uint64_t	sys_badauth;		/* bad authentication */
+uint64_t	sys_declined;		/* declined */
+uint64_t	sys_limitrejected;	/* rate exceeded */
+uint64_t	sys_kodsent;		/* KoD sent */
+uptime_t	use_stattime;		/* elapsed time since usestats reset */
 
 double	measured_tick;		/* non-overridable sys_tick (s) */
 
@@ -1115,7 +1116,7 @@ clock_update(
 	sys_rootdelay = peer->delay + peer->rootdelay;
 	sys_reftime = peer->dst;
 
-	DPRINT(1, ("clock_update: at %lu sample %lu associd %d\n",
+	DPRINT(1, ("clock_update: at %u sample %u associd %d\n",
 		   current_time, peer->epoch, peer->associd));
 
 	/*
@@ -1231,7 +1232,7 @@ poll_update(
 	uint8_t	mpoll
 	)
 {
-	unsigned long	next, utemp;
+	uptime_t	next, utemp;
 	uint8_t	hpoll;
 
 	/*
@@ -1306,7 +1307,7 @@ poll_update(
 		if (peer->throttle > (1 << peer->cfg.minpoll))
 			peer->nextdate += (unsigned long)ntp_minpkt;
 	}
-	DPRINT(2, ("poll_update: at %lu %s poll %d burst %d retry %d head %d early %lu next %lu\n",
+	DPRINT(2, ("poll_update: at %u %s poll %d burst %d retry %d head %d early %u next %u\n",
 		   current_time, socktoa(&peer->srcadr), peer->hpoll,
 		   peer->burst, peer->retry, peer->throttle,
 		   utemp - current_time, peer->nextdate -
@@ -1378,7 +1379,7 @@ peer_clear(
 	    int pseudorandom = peer->associd ^ sock_hash(&peer->srcadr);
 	    peer->nextdate += (unsigned long)(pseudorandom % (1 << peer->cfg.minpoll));
 	}
-	DPRINT(1, ("peer_clear: at %lu next %lu associd %d refid %s\n",
+	DPRINT(1, ("peer_clear: at %u next %u associd %d refid %s\n",
 		   current_time, peer->nextdate, peer->associd,
 		   ident));
 }
@@ -1544,7 +1545,7 @@ clock_filter(
 	 * packets.
 	 */
 	if (peer->filter_epoch[k] <= peer->epoch) {
-	  DPRINT(2, ("clock_filter: old sample %lu\n", current_time -
+	  DPRINT(2, ("clock_filter: old sample %u\n", current_time -
 		     peer->filter_epoch[k]));
 		return;
 	}
@@ -2216,7 +2217,7 @@ peer_xmit(
 		peer->outcount++;
 		peer->throttle += (1 << peer->cfg.minpoll) - 2;
 
-		DPRINT(1, ("transmit: at %lu %s->%s mode %d len %zu\n",
+		DPRINT(1, ("transmit: at %u %s->%s mode %d len %zu\n",
 			   current_time, peer->dstadr ?
 			   socktoa(&peer->dstadr->sin) : "-",
 			   socktoa(&peer->srcadr), peer->hmode, sendlen));
@@ -2252,7 +2253,7 @@ peer_xmit(
 	peer->sent++;
         peer->outcount++;
 	peer->throttle += (1 << peer->cfg.minpoll) - 2;
-	DPRINT(1, ("transmit: at %lu %s->%s mode %d keyid %08x len %zu\n",
+	DPRINT(1, ("transmit: at %u %s->%s mode %d keyid %08x len %zu\n",
 		   current_time, peer->dstadr ?
 		   socktoa(&peer->dstadr->sin) : "-",
 		   socktoa(&peer->srcadr), peer->hmode, xkeyid, sendlen));
@@ -2395,7 +2396,7 @@ fast_xmit(
 	sendlen = LEN_PKT_NOMAC;
 	if (rbufp->recv_length == sendlen) {
 		sendpkt(&rbufp->recv_srcadr, rbufp->dstadr, &xpkt, (int)sendlen);
-		DPRINT(1, ("transmit: at %lu %s->%s mode %d len %zu\n",
+		DPRINT(1, ("transmit: at %u %s->%s mode %d len %zu\n",
 			   current_time, socktoa(&rbufp->dstadr->sin),
 			   socktoa(&rbufp->recv_srcadr), xmode, sendlen));
 		return;
@@ -2413,7 +2414,7 @@ fast_xmit(
 	get_systime(&xmt_ty);
 	xmt_ty -= xmt_tx;
 	sys_authdelay = xmt_ty;
-	DPRINT(1, ("transmit: at %lu %s->%s mode %d keyid %08x len %zu\n",
+	DPRINT(1, ("transmit: at %u %s->%s mode %d keyid %08x len %zu\n",
 		   current_time, socktoa(&rbufp->dstadr->sin),
 		   socktoa(&rbufp->recv_srcadr), xmode, xkeyid, sendlen));
 }
@@ -2513,7 +2514,7 @@ dns_take_pool(
 				current_time + POOL_SOLICIT_WINDOW + 1);
 	}
 
-	DPRINT(1, ("transmit: at %lu %s->%s pool\n",
+	DPRINT(1, ("transmit: at %u %s->%s pool\n",
 		   current_time, latoa(lcladr), socktoa(rmtadr)));
 }
 


=====================================
ntpd/ntp_refclock.c
=====================================
--- a/ntpd/ntp_refclock.c
+++ b/ntpd/ntp_refclock.c
@@ -304,7 +304,7 @@ refclock_transmit(
 	 */
 	if (peer->burst == 0) {
 		uint8_t oreach;
-		DPRINT(1, ("refclock_transmit: at %lu %s\n",
+		DPRINT(1, ("refclock_transmit: at %u %s\n",
 			   current_time, socktoa(&(peer->srcadr))));
 
 		/*
@@ -518,7 +518,7 @@ refclock_receive(
 {
 	struct refclockproc *pp;
 
-	DPRINT(1, ("refclock_receive: at %lu %s\n",
+	DPRINT(1, ("refclock_receive: at %u %s\n",
 		   current_time, socktoa(&peer->srcadr)));
 
 	/*
@@ -1074,7 +1074,7 @@ refclock_catcher(
 	if (dtemp > .5)
 		dtemp -= 1.;
 	SAMPLE(-dtemp + pp->fudgetime1);
-	DPRINT(2, ("refclock_pps: %lu %f %f\n", current_time,
+	DPRINT(2, ("refclock_pps: %u %f %f\n", current_time,
 		   dtemp, pp->fudgetime1));
 	return PPS_OK;
 }


=====================================
ntpd/ntp_signd.c
=====================================
--- a/ntpd/ntp_signd.c
+++ b/ntpd/ntp_signd.c
@@ -212,7 +212,7 @@ send_via_ntp_signd(
 				sendlen = reply_len - offsetof(struct samba_key_out, pkt);
 				xpkt = &samba_reply.pkt;
 				sendpkt(&rbufp->recv_srcadr, rbufp->dstadr, xpkt, sendlen);
-				DPRINT(1, ("transmit ntp_signd packet: at %lu %s->%s mode %d keyid %08x len %d\n",
+				DPRINT(1, ("transmit ntp_signd packet: at %u %s->%s mode %d keyid %08x len %d\n",
 					   current_time, socktoa(&rbufp->dstadr->sin),
 					   socktoa(&rbufp->recv_srcadr), xmode, xkeyid, sendlen));
 			}


=====================================
ntpd/ntp_timer.c
=====================================
--- a/ntpd/ntp_timer.c
+++ b/ntpd/ntp_timer.c
@@ -54,12 +54,12 @@ unsigned long	orphwait; 	/* orphan wait time */
  */
 volatile unsigned long alarm_overflow;
 
-unsigned long current_time;		/* seconds since startup */
+uptime_t current_time;		/* seconds since startup */
 
 /*
  * Stats.  Time of last reset and number of calls to transmit().
  */
-unsigned long timer_timereset;
+uptime_t timer_timereset;
 unsigned long timer_xmtcalls;
 
 static	void catchALRM (int);


=====================================
ntpd/ntp_util.c
=====================================
--- a/ntpd/ntp_util.c
+++ b/ntpd/ntp_util.c
@@ -585,7 +585,11 @@ record_sys_stats(void)
 	filegen_setup(&sysstats, now.tv_sec);
 	if (sysstats.fp != NULL) {
 		fprintf(sysstats.fp,
-		    "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+#if (NTP_SIZEOF_LONG == 8)
+		    "%s %u %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+#else
+		    "%s %u %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
+#endif
 		    timespec_to_MJDtime(&now), current_time - sys_stattime,
 		    sys_received, sys_processed, sys_newversion,
 		    sys_oldversion, sys_restricted, sys_badlength,
@@ -629,7 +633,7 @@ void record_use_stats(void)
 		stimex /= 1E6;
 		stimex += usage.ru_stime.tv_sec -  oldusage.ru_stime.tv_sec;
 		fprintf(usestats.fp,
-		    "%s %lu %.3f %.3f %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
+		    "%s %u %.3f %.3f %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
 		    timespec_to_MJDtime(&now), current_time - use_stattime,
 		    utime, stimex,
 		    usage.ru_minflt -   oldusage.ru_minflt,


=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -291,8 +291,8 @@ err_tbl[] =
 
 struct errorinfo
 {
-	unsigned long err_started;	/* begin time (ntp) of error condition */
-	unsigned long err_last;		/* last time (ntp) error occurred */
+	uptime_t	err_started;	/* begin time (ntp) of error condition */
+	uptime_t	err_last;	/* last time (ntp) error occurred */
 	unsigned long err_cnt;		/* number of error repetitions */
 	unsigned long err_suppressed;	/* number of suppressed messages */
 	struct errorregression *err_stage; /* current error stage */
@@ -329,7 +329,7 @@ struct parseunit
 	 * clock state handling/reporting
 	 */
 	uint8_t	      	      flags;	        /* flags (leap_control) */
-	unsigned long	      lastchange;       /* time (ntp) when last state change accured */
+	uptime_t	      lastchange;       /* time (ntp) when last state change accured */
 	unsigned long	      statetime[CEVNT_MAX+1]; /* accumulated time of clock states */
 	unsigned long         pollneeddata; 	/* current_time(!=0) for receive sample expected in PPS mode */
 	unsigned short	      lastformat;       /* last format used */
@@ -347,8 +347,8 @@ struct parseunit
 	void         *localdata;        /* optional local, receiver-specific data */
         unsigned long localstate;       /* private local state */
 	struct errorinfo errors[ERR_CNT];  /* error state table for suppressing excessive error messages */
-	struct ctl_var *kv;	        /* additional pseudo variables */
-	unsigned long        laststatistic;    /* time when staticstics where output */
+	struct ctl_var *kv;		/* additional pseudo variables */
+	uptime_t	laststatistic;	/* time when staticstics where output */
 };
 
 


=====================================
tests/ntpd/restrict.c
=====================================
--- a/tests/ntpd/restrict.c
+++ b/tests/ntpd/restrict.c
@@ -27,7 +27,7 @@ TEST_SETUP(hackrestrict) {
 	init_restrict();
 }
 
-unsigned long	current_time;	/* not used - restruct code needs it */
+uptime_t	current_time;	/* not used - restruct code needs it */
 
 TEST_TEAR_DOWN(hackrestrict) {
 	restrict_u *empty_restrict = malloc(sizeof(restrict_u));



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/c1ba98f51ec17a0900f2320b3f7cca709767d03e...6bd165b75bf6cdbad8403f5ced02f7be9e6e965c

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/c1ba98f51ec17a0900f2320b3f7cca709767d03e...6bd165b75bf6cdbad8403f5ced02f7be9e6e965c
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20171216/0ab99489/attachment.html>


More information about the vc mailing list