Deleted Added
full compact
42,44c42,44
< * in here is the hourly stats printer and some code to support rereading
< * the keys file, but I may eventually put other things in here such as
< * code to do something with the leap bits.
---
> * in here is the hourly stats printer and some code to support
> * rereading the keys file, but I may eventually put other things in
> * here such as code to do something with the leap bits.
46d45
<
78a78,81
> static FILEGEN sysstats;
> #ifdef OPENSSL
> static FILEGEN cryptostats;
> #endif /* OPENSSL */
99a103,107
> #define STANAME "systats"
> #ifdef OPENSSL
> #define CRYPTONAME "cryptostats"
> #endif /* OPENSSL */
>
135a144,163
> sysstats.fp = NULL;
> sysstats.prefix = &statsdir[0];
> sysstats.basename = (char*)emalloc(strlen(STANAME)+1);
> strcpy(sysstats.basename, STANAME);
> sysstats.id = 0;
> sysstats.type = FILEGEN_DAY;
> sysstats.flag = FGEN_FLAG_LINK; /* not yet enabled !!*/
> filegen_register("sysstats", &sysstats);
>
> #ifdef OPENSSL
> cryptostats.fp = NULL;
> cryptostats.prefix = &statsdir[0];
> cryptostats.basename = (char*)emalloc(strlen(CRYPTONAME)+1);
> strcpy(cryptostats.basename, CRYPTONAME);
> cryptostats.id = 0;
> cryptostats.type = FILEGEN_DAY;
> cryptostats.flag = FGEN_FLAG_LINK; /* not yet enabled !!*/
> filegen_register("cryptostats", &cryptostats);
> #endif /* OPENSSL */
>
140c168,171
<
---
> #undef STANAME
> #ifdef OPENSSL
> #undef CRYPTONAME
> #endif /* OPENSSL */
186,187c217,218
< * return value (!), so instead we have to zero errno before the call
< * and check it for non-zero afterwards.
---
> * return value (!), so instead we have to zero errno before the
> * call and check it for non-zero afterwards.
189d219
<
194c224,225
< /* (prr) if getpriority succeeded, call setpriority to raise
---
> /*
> * (prr) if getpriority succeeded, call setpriority to raise
197,202c228,234
< * priority to its previous value below. Note that on Solaris 2.6
< * (and beyond?), both getpriority and setpriority will fail with
< * ESRCH, because sched_setscheduler (called from main) put us in
< * the real-time scheduling class which setpriority doesn't know about.
< * Being in the real-time class is better than anything setpriority
< * can do, anyhow, so this error is silently ignored.
---
> * priority to its previous value below. Note that on Solaris
> * 2.6 (and beyond?), both getpriority and setpriority will fail
> * with ESRCH, because sched_setscheduler (called from main) put
> * us in the real-time scheduling class which setpriority
> * doesn't know about. Being in the real-time class is better
> * than anything setpriority can do, anyhow, so this error is
> * silently ignored.
204d235
<
206c237
< prio_set = 1; /* overdrive */
---
> prio_set = 1; /* overdrive */
215,216c246
< if (ntp_set_tod(&tv,(struct timezone *)NULL) != 0)
< {
---
> if (ntp_set_tod(&tv,(struct timezone *)NULL) != 0) {
221c251
< setpriority(PRIO_PROCESS, 0, o_prio); /* downshift */
---
> setpriority(PRIO_PROCESS, 0, o_prio); /* downshift */
228c258,259
< last_offset, drift_comp * 1e6, sys_jitter, sys_poll);
---
> last_offset, drift_comp * 1e6, sys_jitter,
> sys_poll);
230a262
> record_sys_stats();
241c273
< (void) unlink(stats_drift_file); /* rename semantics differ under NT */
---
> (void) _unlink(stats_drift_file); /* rename semantics differ under NT */
284,285c316,318
< /* Expand environment strings under Windows NT, since the command
< * interpreter doesn't do this, the program must.
---
> /*
> * Expand environment strings under Windows NT, since the
> * command interpreter doesn't do this, the program must.
290,291c323
< if (!ExpandEnvironmentStrings(invalue, newvalue, MAX_PATH))
< {
---
> if (!ExpandEnvironmentStrings(invalue, newvalue, MAX_PATH)) {
310,311c342
< }
< else
---
> } else {
312a344
> }
317,318d348
<
<
333c363,364
< stats_temp_file = (char*)emalloc((u_int)(len + sizeof(".TEMP")));
---
> stats_temp_file = (char*)emalloc((u_int)(len +
> sizeof(".TEMP")));
335c366,367
< stats_temp_file = (char*)emalloc((u_int)(len + sizeof("-TEMP")));
---
> stats_temp_file = (char*)emalloc((u_int)(len +
> sizeof("-TEMP")));
340c372,373
< memmove(stats_temp_file + len, ".TEMP", sizeof(".TEMP"));
---
> memmove(stats_temp_file + len, ".TEMP",
> sizeof(".TEMP"));
342c375,376
< memmove(stats_temp_file + len, "-TEMP", sizeof("-TEMP"));
---
> memmove(stats_temp_file + len, "-TEMP",
> sizeof("-TEMP"));
346c380,381
< * Open drift file and read frequency
---
> * Open drift file and read frequency. If the file is
> * missing or contains errors, tell the loop to reset.
348a384
> loop_config(LOOP_DRIFTCOMP, 1e9);
352c388
< msyslog(LOG_ERR, "Un-parsable frequency in %s",
---
> msyslog(LOG_ERR, "Frequency format error in %s",
354c390,391
< (void) fclose(fp);
---
> loop_config(LOOP_DRIFTCOMP, 1e9);
> fclose(fp);
357,374c394,397
< (void) fclose(fp);
< if (
< #ifdef HAVE_FINITE
< !finite(old_drift)
< #else /* not HAVE_FINITE */
< # ifdef HAVE_ISFINITE
< !isfinite(old_drift)
< # else /* not HAVE_ISFINITE */
< 0
< # endif /* not HAVE_ISFINITE */
< #endif /* not HAVE_FINITE */
< || (fabs(old_drift) > (NTP_MAXFREQ * 1e6))) {
< msyslog(LOG_ERR, "invalid frequency (%f) in %s",
< old_drift, stats_drift_file);
< old_drift = 0.0;
< }
< msyslog(LOG_INFO, "frequency initialized %.3f from %s",
< old_drift, stats_drift_file);
---
> fclose(fp);
> msyslog(LOG_INFO,
> "frequency initialized %.3f PPM from %s",
> old_drift, stats_drift_file);
411a435,448
> if(sysstats.prefix == &statsdir[0] &&
> sysstats.fp != NULL) {
> fclose(sysstats.fp);
> sysstats.fp = NULL;
> filegen_setup(&sysstats, now.l_ui);
> }
> #ifdef OPENSSL
> if(cryptostats.prefix == &statsdir[0] &&
> cryptostats.fp != NULL) {
> fclose(cryptostats.fp);
> cryptostats.fp = NULL;
> filegen_setup(&cryptostats, now.l_ui);
> }
> #endif /* OPENSSL */
445,450c482,487
< struct sockaddr_in *addr,
< int status,
< double offset,
< double delay,
< double dispersion,
< double skew
---
> struct sockaddr_storage *addr,
> int status,
> double offset,
> double delay,
> double dispersion,
> double skew
453,457c490,491
< struct timeval tv;
< #ifdef HAVE_GETCLOCK
< struct timespec ts;
< #endif
< u_long day, sec, msec;
---
> l_fp now;
> u_long day;
461,470d494
< #ifdef HAVE_GETCLOCK
< (void) getclock(TIMEOFDAY, &ts);
< tv.tv_sec = ts.tv_sec;
< tv.tv_usec = ts.tv_nsec / 1000;
< #else /* not HAVE_GETCLOCK */
< GETTIMEOFDAY(&tv, (struct timezone *)NULL);
< #endif /* not HAVE_GETCLOCK */
< day = tv.tv_sec / 86400 + MJD_1970;
< sec = tv.tv_sec % 86400;
< msec = tv.tv_usec / 1000;
472c496,499
< filegen_setup(&peerstats, (u_long)(tv.tv_sec + JAN_1970));
---
> get_systime(&now);
> filegen_setup(&peerstats, now.l_ui);
> day = now.l_ui / 86400 + MJD_1900;
> now.l_ui %= 86400;
475,476c502,503
< "%lu %lu.%03lu %s %x %.9f %.9f %.9f %.9f\n",
< day, sec, msec, ntoa(addr), status, offset,
---
> "%lu %s %s %x %.9f %.9f %.9f %.9f\n",
> day, ulfptoa(&now, 3), stoa(addr), status, offset,
493,497c520,524
< double offset,
< double freq,
< double jitter,
< double stability,
< int poll
---
> double offset,
> double freq,
> double jitter,
> double stability,
> int spoll
500,504c527,528
< struct timeval tv;
< #ifdef HAVE_GETCLOCK
< struct timespec ts;
< #endif
< u_long day, sec, msec;
---
> l_fp now;
> u_long day;
508,517d531
< #ifdef HAVE_GETCLOCK
< (void) getclock(TIMEOFDAY, &ts);
< tv.tv_sec = ts.tv_sec;
< tv.tv_usec = ts.tv_nsec / 1000;
< #else /* not HAVE_GETCLOCK */
< GETTIMEOFDAY(&tv, (struct timezone *)NULL);
< #endif /* not HAVE_GETCLOCK */
< day = tv.tv_sec / 86400 + MJD_1970;
< sec = tv.tv_sec % 86400;
< msec = tv.tv_usec / 1000;
519c533,536
< filegen_setup(&loopstats, (u_long)(tv.tv_sec + JAN_1970));
---
> get_systime(&now);
> filegen_setup(&loopstats, now.l_ui);
> day = now.l_ui / 86400 + MJD_1900;
> now.l_ui %= 86400;
521,523c538,540
< fprintf(loopstats.fp, "%lu %lu.%03lu %.9f %.6f %.9f %.6f %d\n",
< day, sec, msec, offset, freq * 1e6, jitter,
< stability * 1e6, poll);
---
> fprintf(loopstats.fp, "%lu %s %.9f %.6f %.9f %.6f %d\n",
> day, ulfptoa(&now, 3), offset, freq * 1e6, jitter,
> stability * 1e6, spoll);
539c556
< struct sockaddr_in *addr,
---
> struct sockaddr_storage *addr,
543,547c560,561
< struct timeval tv;
< #ifdef HAVE_GETCLOCK
< struct timespec ts;
< #endif
< u_long day, sec, msec;
---
> l_fp now;
> u_long day;
551,560d564
< #ifdef HAVE_GETCLOCK
< (void) getclock(TIMEOFDAY, &ts);
< tv.tv_sec = ts.tv_sec;
< tv.tv_usec = ts.tv_nsec / 1000;
< #else /* not HAVE_GETCLOCK */
< GETTIMEOFDAY(&tv, (struct timezone *)NULL);
< #endif /* not HAVE_GETCLOCK */
< day = tv.tv_sec / 86400 + MJD_1970;
< sec = tv.tv_sec % 86400;
< msec = tv.tv_usec / 1000;
562c566,569
< filegen_setup(&clockstats, (u_long)(tv.tv_sec + JAN_1970));
---
> get_systime(&now);
> filegen_setup(&clockstats, now.l_ui);
> day = now.l_ui / 86400 + MJD_1900;
> now.l_ui %= 86400;
564,565c571,572
< fprintf(clockstats.fp, "%lu %lu.%03lu %s %s\n",
< day, sec, msec, ntoa(addr), text);
---
> fprintf(clockstats.fp, "%lu %s %s %s\n",
> day, ulfptoa(&now, 3), stoa(addr), text);
582,587c589,594
< struct sockaddr_in *srcadr,
< struct sockaddr_in *dstadr,
< l_fp *t1,
< l_fp *t2,
< l_fp *t3,
< l_fp *t4
---
> struct sockaddr_storage *srcadr,
> struct sockaddr_storage *dstadr,
> l_fp *t1,
> l_fp *t2,
> l_fp *t3,
> l_fp *t4
590,594c597,598
< struct timeval tv;
< #ifdef HAVE_GETCLOCK
< struct timespec ts;
< #endif
< u_long day, sec, msec;
---
> l_fp now;
> u_long day;
598,607d601
< #ifdef HAVE_GETCLOCK
< (void) getclock(TIMEOFDAY, &ts);
< tv.tv_sec = ts.tv_sec;
< tv.tv_usec = ts.tv_nsec / 1000;
< #else /* not HAVE_GETCLOCK */
< GETTIMEOFDAY(&tv, (struct timezone *)NULL);
< #endif /* not HAVE_GETCLOCK */
< day = tv.tv_sec / 86400 + MJD_1970;
< sec = tv.tv_sec % 86400;
< msec = tv.tv_usec / 1000;
609c603,606
< filegen_setup(&rawstats, (u_long)(tv.tv_sec + JAN_1970));
---
> get_systime(&now);
> filegen_setup(&rawstats, now.l_ui);
> day = now.l_ui / 86400 + MJD_1900;
> now.l_ui %= 86400;
611,612c608,609
< fprintf(rawstats.fp, "%lu %lu.%03lu %s %s %s %s %s %s\n",
< day, sec, msec, ntoa(srcadr), ntoa(dstadr),
---
> fprintf(rawstats.fp, "%lu %s %s %s %s %s %s %s\n",
> day, ulfptoa(&now, 3), stoa(srcadr), stoa(dstadr),
618a616
>
619a618,699
> * record_sys_stats - write system statistics to file
> *
> * file format
> * time (s past midnight)
> * time since startup (hr)
> * packets recieved
> * packets processed
> * current version
> * previous version
> * bad version
> * access denied
> * bad length or format
> * bad authentication
> * rate exceeded
> */
> void
> record_sys_stats(void)
> {
> l_fp now;
> u_long day;
>
> if (!stats_control)
> return;
>
> get_systime(&now);
> filegen_setup(&sysstats, now.l_ui);
> day = now.l_ui / 86400 + MJD_1900;
> now.l_ui %= 86400;
> if (sysstats.fp != NULL) {
> fprintf(sysstats.fp,
> "%lu %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
> day, ulfptoa(&now, 3), sys_stattime / 3600,
> sys_received, sys_processed, sys_newversionpkt,
> sys_oldversionpkt, sys_unknownversion,
> sys_restricted, sys_badlength, sys_badauth,
> sys_limitrejected);
> fflush(sysstats.fp);
> proto_clr_stats();
> }
> }
>
>
> #ifdef OPENSSL
> /*
> * record_crypto_stats - write crypto statistics to file
> *
> * file format:
> * day (mjd)
> * time (s past midnight)
> * peer (ip address)
> * text message
> */
> void
> record_crypto_stats(
> struct sockaddr_storage *addr,
> const char *text
> )
> {
> l_fp now;
> u_long day;
>
> if (!stats_control)
> return;
>
> get_systime(&now);
> filegen_setup(&cryptostats, now.l_ui);
> day = now.l_ui / 86400 + MJD_1900;
> now.l_ui %= 86400;
> if (cryptostats.fp != NULL) {
> if (addr == NULL)
> fprintf(cryptostats.fp, "%lu %s %s\n",
> day, ulfptoa(&now, 3), text);
> else
> fprintf(cryptostats.fp, "%lu %s %s %s\n",
> day, ulfptoa(&now, 3), stoa(addr), text);
> fflush(cryptostats.fp);
> }
> }
> #endif /* OPENSSL */
>
>
> /*
669a750,797
>
> /*
> * sock_hash - hash an sockaddr_storage structure
> */
> int
> sock_hash(
> struct sockaddr_storage *addr
> )
> {
> int hashVal;
> int i;
> int len;
> char *ch;
>
> hashVal = 0;
> len = 0;
> /*
> * We can't just hash the whole thing because there are hidden
> * fields in sockaddr_in6 that might be filled in by recvfrom(),
> * so just use the family, port and address.
> */
> ch = (char *)&addr->ss_family;
> hashVal = 37 * hashVal + (int)*ch;
> if (sizeof(addr->ss_family) > 1) {
> ch++;
> hashVal = 37 * hashVal + (int)*ch;
> }
> switch(addr->ss_family) {
> case AF_INET:
> ch = (char *)&((struct sockaddr_in *)addr)->sin_addr;
> len = sizeof(struct in_addr);
> break;
> case AF_INET6:
> ch = (char *)&((struct sockaddr_in6 *)addr)->sin6_addr;
> len = sizeof(struct in6_addr);
> break;
> }
>
> for (i = 0; i < len ; i++)
> hashVal = 37 * hashVal + (int)*(ch + i);
>
> hashVal = hashVal % 128; /* % MON_HASH_SIZE hardcoded */
>
> if (hashVal < 0)
> hashVal += 128;
>
> return hashVal;
> }