diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/Makefile.am | 3 | ||||
| -rw-r--r-- | include/Makefile.in | 3 | ||||
| -rw-r--r-- | include/ntp.h | 10 | ||||
| -rw-r--r-- | include/ntp_calendar.h | 73 | ||||
| -rw-r--r-- | include/ntp_calgps.h | 151 | ||||
| -rw-r--r-- | include/ntp_config.h | 39 | ||||
| -rw-r--r-- | include/ntp_control.h | 4 | ||||
| -rw-r--r-- | include/ntp_fp.h | 4 | ||||
| -rw-r--r-- | include/ntp_io.h | 2 | ||||
| -rw-r--r-- | include/ntp_psl.h | 17 | ||||
| -rw-r--r-- | include/ntp_refclock.h | 35 | ||||
| -rw-r--r-- | include/ntp_request.h | 4 | ||||
| -rw-r--r-- | include/ntp_stdlib.h | 2 | ||||
| -rw-r--r-- | include/ntp_syslog.h | 3 | ||||
| -rw-r--r-- | include/ntpd.h | 6 | ||||
| -rw-r--r-- | include/timespecops.h | 187 | ||||
| -rw-r--r-- | include/timexsup.h | 42 |
17 files changed, 375 insertions, 210 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index 749a0c839050..dd739ebbcdbd 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -25,6 +25,7 @@ noinst_HEADERS = \ ntp.h \ ntp_assert.h \ ntp_calendar.h \ + ntp_calgps.h \ ntp_cmdargs.h \ ntp_config.h \ ntp_control.h \ @@ -46,6 +47,7 @@ noinst_HEADERS = \ ntp_md5.h \ ntp_net.h \ ntp_proto.h \ + ntp_psl.h \ ntp_random.h \ ntp_refclock.h \ ntp_request.h \ @@ -76,6 +78,7 @@ noinst_HEADERS = \ timespecops.h \ timetoa.h \ timevalops.h \ + timexsup.h \ trimble.h \ vint64ops.h \ $(NULL) diff --git a/include/Makefile.in b/include/Makefile.in index 2e1ed92c8899..9e75bb3df245 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -511,6 +511,7 @@ noinst_HEADERS = \ ntp.h \ ntp_assert.h \ ntp_calendar.h \ + ntp_calgps.h \ ntp_cmdargs.h \ ntp_config.h \ ntp_control.h \ @@ -532,6 +533,7 @@ noinst_HEADERS = \ ntp_md5.h \ ntp_net.h \ ntp_proto.h \ + ntp_psl.h \ ntp_random.h \ ntp_refclock.h \ ntp_request.h \ @@ -562,6 +564,7 @@ noinst_HEADERS = \ timespecops.h \ timetoa.h \ timevalops.h \ + timexsup.h \ trimble.h \ vint64ops.h \ $(NULL) diff --git a/include/ntp.h b/include/ntp.h index cfbb7d2e7a47..97f0d5f9e2de 100644 --- a/include/ntp.h +++ b/include/ntp.h @@ -359,6 +359,7 @@ struct peer { l_fp aorg; /* origin timestamp */ l_fp borg; /* alternate origin timestamp */ l_fp bxmt; /* most recent broadcast transmit timestamp */ + l_fp nonce; /* Value of nonce we sent as the xmt stamp */ double offset; /* peer clock offset */ double delay; /* peer roundtrip delay */ double jitter; /* peer jitter (squares) */ @@ -466,6 +467,7 @@ struct peer { # define FLAG_ASSOC 0x8000 /* autokey request */ #endif /* OPENSSL */ #define FLAG_TSTAMP_PPS 0x10000 /* PPS source provides absolute timestamp */ +#define FLAG_LOOPNONCE 0x20000 /* Use a nonce for the loopback test */ /* * Definitions for the clear() routine. We use memset() to clear @@ -841,6 +843,7 @@ struct restrict_u_tag { u_short rflags; /* restrict (accesslist) flags */ u_short mflags; /* match flags */ short ippeerlimit; /* IP peer limit */ + int srvfuzrftpoll; /* server response: fuzz reftime */ u_long expire; /* valid until time */ union { /* variant starting here */ res_addr4 v4; @@ -885,13 +888,16 @@ char *build_rflags(u_short rflags); #define RES_MSSNTP 0x1000 /* enable MS-SNTP authentication */ #define RES_FLAKE 0x2000 /* flakeway - drop 10% */ #define RES_NOMRULIST 0x4000 /* mode 6 mrulist denied */ -#define RES_UNUSED 0x8000 /* Unused flag bits */ + +#define RES_SRVRSPFUZ 0x8000 /* Server response: fuzz */ + +#define RES_UNUSED 0x0000 /* Unused flag bits (none left) */ #define RES_ALLFLAGS (RES_FLAGS | RES_NOQUERY | \ RES_NOMODIFY | RES_NOTRAP | \ RES_LPTRAP | RES_KOD | \ RES_MSSNTP | RES_FLAKE | \ - RES_NOMRULIST) + RES_NOMRULIST | RES_SRVRSPFUZ ) /* * Match flags (mflags) diff --git a/include/ntp_calendar.h b/include/ntp_calendar.h index 0b1f20d6bd7b..cc7977aff481 100644 --- a/include/ntp_calendar.h +++ b/include/ntp_calendar.h @@ -19,6 +19,8 @@ struct calendar { uint8_t second; /* second of minute */ uint8_t weekday; /* 0..7, 0=Sunday */ }; +typedef struct calendar TCivilDate; +typedef struct calendar const TcCivilDate; /* ISO week calendar date */ struct isodate { @@ -29,6 +31,8 @@ struct isodate { uint8_t minute; /* minute of hour */ uint8_t second; /* second of minute */ }; +typedef struct isodate TIsoDate; +typedef struct isodate const TcIsoDate; /* general split representation */ typedef struct { @@ -109,6 +113,7 @@ extern systime_func_ptr ntpcal_set_timefunc(systime_func_ptr); extern const char * const months[12]; extern const char * const daynames[7]; +extern char * ntpcal_iso8601std(char*, size_t, struct calendar const*); extern void caljulian (uint32_t, struct calendar *); extern uint32_t caltontp (const struct calendar *); @@ -152,12 +157,26 @@ extern ntpcal_split ntpcal_daysplit(const vint64 *); /* + * Split a time stamp in seconds into elapsed weeks and elapsed seconds + * since start of week. + */ +extern ntpcal_split +ntpcal_weeksplit(const vint64 *); + +/* * Merge a number of days and a number of seconds into seconds, * expressed in 64 bits to avoid overflow. */ extern vint64 ntpcal_dayjoin(int32_t /* days */, int32_t /* seconds */); +/* + * Merge a number of weeks and a number of seconds into seconds, + * expressed in 64 bits to avoid overflow. + */ +extern vint64 +ntpcal_weekjoin(int32_t /* weeks */, int32_t /* seconds */); + /* Get the number of leap years since epoch for the number of elapsed * full years */ @@ -431,7 +450,7 @@ basedate_expand_gpsweek(unsigned short weekno); /* * Start day of the GPS epoch. This is the Rata Die of 1980-01-06 */ -#define DAY_GPS_STARTS 722819 +#define DAY_GPS_STARTS 722820 /* * Difference between UN*X and NTP epoch (25567). @@ -467,6 +486,56 @@ basedate_expand_gpsweek(unsigned short weekno); */ #define GREGORIAN_CYCLE_WEEKS (GREGORIAN_CYCLE_DAYS / 7) -#define is_leapyear(y) (!((y) % 4) && !(!((y) % 100) && (y) % 400)) +/* + * Is a Greogorian calendar year a leap year? The obvious solution is to + * test the expression + * + * (y % 4 == 0) && ((y % 100 != 0) || (y % 400 == 0)) + * + * This needs (in theory) 2 true divisions -- most compilers check the + * (mod 4) condition by doing a bit test. Some compilers have been + * even observed to partially fuse the (mod 100) and (mod 400) test, + * but there is an alternative formula that gives the compiler even + * better chances: + * + * (y % 4 == 0) && ((y % 16 == 0) || (y % 25 != 0)) + * + * The order of checks is chosen so that the shorcut evaluation can fix + * the result as soon as possible. And the compiler has to do only one + * true division here -- the (mod 4) and (mod 16) can be done with + * direct bit tests. *If* the compiler chooses to do so. + * + * The deduction is as follows: rewrite the standard formula as + * (y % 4 == 0) && ((y % 4*25 != 0) || (y % 16*25 == 0)) + * + * then split the congruences: + * (y % 4 == 0) && ((y % 4 != 0 || y % 25 != 0) || (y % 16 == 0 && y % 25 == 0)) + * + * eliminate the 1st inner term, as it is provably false: + * (y % 4 == 0) && (y % 25 != 0 || (y % 16 == 0 && y % 25 == 0)) + * + * Use the distributive laws on the second major group: + * (y % 4 == 0) && ((y % 25 != 0 || y % 16 == 0) && (y % 25 != 0 || y % 25 == 0)) + * + * Eliminate the constant term, reorder, and voila: + */ + +static inline int +is_leapyear(int32_t y) { + return !(y % 4) && (!(y % 16) || (y % 25)); +} +/* The (mod 4) test eliminates 3/4 (or 12/16) of all values. + * The (mod 16) test eliminates another 1/16 of all values. + * 3/16 of all values reach the final division. + * Assuming that the true division is the most costly operation, this + * sequence should give most bang for the buck. + */ + +/* misc */ +extern int u32mod7(uint32_t x); +extern int i32mod7(int32_t x); +extern uint32_t i32fmod(int32_t x, uint32_t d); + +extern int32_t ntpcal_expand_century(uint32_t y, uint32_t m, uint32_t d, uint32_t wd); #endif diff --git a/include/ntp_calgps.h b/include/ntp_calgps.h new file mode 100644 index 000000000000..7b5d83d1305c --- /dev/null +++ b/include/ntp_calgps.h @@ -0,0 +1,151 @@ +/* + * ntp_calgps.h - calendar for GPS/GNSS based clocks + * + * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. + * The contents of 'html/copyright.html' apply. + * + * -------------------------------------------------------------------- + * + * This module implements stuff often used with GPS/GNSS receivers + */ +#ifndef NTP_CALGPS_H +#define NTP_CALGPS_H + +#include <time.h> + +#include "ntp_types.h" +#include "ntp_fp.h" +#include "ntp_calendar.h" + +/* GPS week calendar (extended weeks) + * We use weeks based on 1899-31-12, which was the last Sunday before + * the begin of the NTP epoch. (Which is equivalent to saying 1900-01-01 + * was a Monday...) + * + * We simply pre-calculate the offsets and cycle shifts for the real GPS + * calendar, which starts at 1980-01-06, to simplyfy some expressions. + * + * This has a fringe benefit that should not be overlooked: Since week zero + * is around 1900, and we should never have to deal with dates before + * 1970 or 1980, a week number of zero can be easily used to indicate + * an invalid week time stamp. + */ +#define GPSNTP_WSHIFT 4175 /* weeks 1899-31-12 --> 1980-01-06 */ +#define GPSNTP_WCYCLE 79 /* above, modulo 1024 */ +#define GPSNTP_DSHIFT 1 /* day number of 1900-01-01 in week */ + +struct gpsdatum { + uint32_t weeks; /* weeks since GPS epoch */ + int32_t wsecs; /* seconds since week start */ + uint32_t frac; /* fractional seconds */ +}; +typedef struct gpsdatum TGpsDatum; +typedef struct gpsdatum const TcGpsDatum; + +/* NTP date/time in split representation */ +struct ntpdatum { + uint32_t days; /* since NTP epoch */ + int32_t secs; /* since midnight, denorm is ok */ + uint32_t frac; /* fractional seconds */ +}; +typedef struct ntpdatum TNtpDatum; +typedef struct ntpdatum const TcNtpDatum; + +/* + * GPS week/sec calendar functions + * + * see the implementation for details, especially the + * 'gpscal_from_weektime{1,2}()' + */ + +extern TGpsDatum +gpscal_fix_gps_era(TcGpsDatum *); + +extern void +gpscal_add_offset(TGpsDatum *datum, l_fp offset); + +extern TGpsDatum +gpscal_from_calendar_ex(TcCivilDate*, l_fp fofs, int/*BOOL*/ warp); + +static inline TGpsDatum +gpscal_from_calendar(TcCivilDate *pCiv, l_fp fofs) { + return gpscal_from_calendar_ex(pCiv, fofs, TRUE); +} + +extern TGpsDatum /* see source for semantic of the 'fofs' value! */ +gpscal_from_gpsweek(uint16_t w, int32_t s, l_fp fofs); + +extern TGpsDatum +gpscal_from_weektime1(int32_t wsecs, l_fp fofs, l_fp pivot); + +extern TGpsDatum +gpscal_from_weektime2(int32_t wsecs, l_fp fofs, TcGpsDatum *pivot); + +extern void +gpscal_to_calendar(TCivilDate*, TcGpsDatum*); + +extern TGpsDatum +gpscal_from_gpsntp(TcNtpDatum*); + +extern l_fp +ntpfp_from_gpsdatum(TcGpsDatum *); + +/* + * NTP day/sec calendar functions + * + * see the implementation for details, especially the + * 'gpscal_from_daytime{1,2}()' + */ +extern TNtpDatum +gpsntp_fix_gps_era(TcNtpDatum *); + +extern void +gpsntp_add_offset(TNtpDatum *datum, l_fp offset); + +extern TNtpDatum +gpsntp_from_calendar_ex(TcCivilDate*, l_fp fofs, int/*BOOL*/ warp); + +static inline TNtpDatum +gpsntp_from_calendar(TcCivilDate * pCiv, l_fp fofs) { + return gpsntp_from_calendar_ex(pCiv, fofs, TRUE); +} + +extern TNtpDatum +gpsntp_from_daytime1_ex(TcCivilDate *dt, l_fp fofs, l_fp pivot, int/*BOOL*/ warp); + +static inline TNtpDatum +gpsntp_from_daytime1(TcCivilDate *dt, l_fp fofs, l_fp pivot) { + return gpsntp_from_daytime1_ex(dt, fofs, pivot, TRUE); +} + +extern TNtpDatum +gpsntp_from_daytime2_ex(TcCivilDate *dt, l_fp fofs, TcNtpDatum *pivot, int/*BOOL*/ warp); + +static inline TNtpDatum +gpsntp_from_daytime2(TcCivilDate *dt, l_fp fofs, TcNtpDatum *pivot) { + return gpsntp_from_daytime2_ex(dt, fofs, pivot, TRUE); +} + +extern TNtpDatum +gpsntp_from_gpscal_ex(TcGpsDatum*, int/*BOOL*/ warp); + +static inline TNtpDatum +gpsntp_from_gpscal(TcGpsDatum *wd) { + return gpsntp_from_gpscal_ex(wd, FALSE); +} + +extern void +gpsntp_to_calendar(TCivilDate*, TcNtpDatum*); + +extern l_fp +ntpfp_from_ntpdatum(TcNtpDatum*); + +/* + * Some helpers + */ + +/* apply fudge to time stamp: *SUBTRACT* the given offset from an l_fp*/ +extern l_fp +ntpfp_with_fudge(l_fp lfp, double ofs); + +#endif /*!defined(NTP_CALGPS_H)*/ diff --git a/include/ntp_config.h b/include/ntp_config.h index dac933a17764..b414466930ad 100644 --- a/include/ntp_config.h +++ b/include/ntp_config.h @@ -6,6 +6,7 @@ #endif /* HAVE_SYS_RESOURCE_H */ #include "ntp_machine.h" +#include "ntp_psl.h" #include "ntpsim.h" @@ -68,12 +69,13 @@ struct attr_val_tag { attr_val * link; int attr; int type; /* T_String, T_Integer, ... */ + int flag; /* auxiliary flags */ union val { - int i; - u_int u; - int_range r; - double d; - char * s; + double d; /* T_Double */ + int i; /* T_Integer */ + int_range r; /* T_Intrange */ + char * s; /* T_String */ + u_int u; /* T_U_int */ } value; }; @@ -110,9 +112,10 @@ struct restrict_node_tag { restrict_node * link; address_node * addr; address_node * mask; - int_fifo * flag_tok_fifo; + attr_val_fifo * flag_tok_fifo; int line_no; short ippeerlimit; + short srvfuzrft; }; typedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo; @@ -246,6 +249,7 @@ struct config_tree_tag { attr_val_fifo * vars; nic_rule_fifo * nic_rules; int_fifo * reset_counters; + attr_val_fifo * pollskewlist; sim_fifo * sim_details; int mdnstries; @@ -272,6 +276,23 @@ typedef struct settrap_parms_tag { } settrap_parms; +/* + * Poll Skew List + */ + +psl_item psl[17-3+1]; /* values for polls 3-17 */ + /* To simplify the runtime code we */ + /* don't want to have to special-case */ + /* dealing with a default */ + + +/* +** Data Minimization Items +*/ + +/* Serverresponse fuzz reftime: stored in 'restrict' fifos */ + + /* get text from T_ tokens */ const char * token_name(int token); @@ -298,9 +319,9 @@ address_node *create_address_node(char *addr, int type); void destroy_address_node(address_node *my_node); attr_val *create_attr_dval(int attr, double value); attr_val *create_attr_ival(int attr, int value); -attr_val *create_attr_uval(int attr, u_int value); -attr_val *create_attr_rangeval(int attr, int first, int last); +attr_val *create_attr_rval(int attr, int first, int last); attr_val *create_attr_sval(int attr, const char *s); +attr_val *create_attr_uval(int attr, u_int value); void destroy_attr_val(attr_val *node); filegen_node *create_filegen_node(int filegen_token, attr_val_fifo *options); @@ -308,7 +329,7 @@ string_node *create_string_node(char *str); restrict_node *create_restrict_node(address_node *addr, address_node *mask, short ippeerlimit, - int_fifo *flags, int line_no); + attr_val_fifo *flags, int line_no); int_node *create_int_node(int val); addr_opts_node *create_addr_opts_node(address_node *addr, attr_val_fifo *options); diff --git a/include/ntp_control.h b/include/ntp_control.h index 85f41056c7b1..2fe0f30bbd78 100644 --- a/include/ntp_control.h +++ b/include/ntp_control.h @@ -1,3 +1,5 @@ +#ifndef NTP_CONTROL_H +#define NTP_CONTROL_H /* * ntp_control.h - definitions related to NTP mode 6 control messages */ @@ -190,3 +192,5 @@ extern struct ctl_trap ctl_traps[CTL_MAXTRAPS]; #define IFSTATS_FIELDS 12 #define RESLIST_FIELDS 4 +#endif /* NTP_CONTROL_H */ + diff --git a/include/ntp_fp.h b/include/ntp_fp.h index 2782ebfe921a..afd1f827459e 100644 --- a/include/ntp_fp.h +++ b/include/ntp_fp.h @@ -344,8 +344,8 @@ typedef u_int32 u_fp; /* * Prototypes */ -extern char * dofptoa (u_fp, int, short, int); -extern char * dolfptoa (u_int32, u_int32, int, short, int); +extern char * dofptoa (u_fp, char, short, int); +extern char * dolfptoa (u_int32, u_int32, char, short, int); extern int atolfp (const char *, l_fp *); extern int buftvtots (const char *, l_fp *); diff --git a/include/ntp_io.h b/include/ntp_io.h index d34d60a80b98..9d63c9da06b2 100644 --- a/include/ntp_io.h +++ b/include/ntp_io.h @@ -84,7 +84,7 @@ typedef enum { extern int qos; SOCKET move_fd(SOCKET fd); -isc_boolean_t get_broadcastclient_flag(void); +/*isc_boolean_t get_broadcastclient_flag(void);*/ extern void sau_from_netaddr(sockaddr_u *, const isc_netaddr_t *); extern void add_nic_rule(nic_rule_match match_type, const char *if_name, int prefixlen, diff --git a/include/ntp_psl.h b/include/ntp_psl.h new file mode 100644 index 000000000000..a0c2662d44c7 --- /dev/null +++ b/include/ntp_psl.h @@ -0,0 +1,17 @@ +#ifndef NTP_PSL_H +#define NTP_PSL_H + + +/* + * Poll Skew List Item + */ + +typedef struct psl_item_tag { + int sub; /* int or short? unsigned is OK, but why? */ + int qty; /* int or short? unsigned is OK, but why? */ + int msk; /* int or short? unsigned is OK */ +} psl_item; + +int get_pollskew(int, psl_item *); + +#endif /* !defined(NTP_PSL_H) */ diff --git a/include/ntp_refclock.h b/include/ntp_refclock.h index 4b807e5f369e..e74e77aa791a 100644 --- a/include/ntp_refclock.h +++ b/include/ntp_refclock.h @@ -14,11 +14,6 @@ #include "recvbuff.h" -#define SAMPLE(x) pp->coderecv = (pp->coderecv + 1) % MAXSTAGE; \ - pp->filter[pp->coderecv] = (x); \ - if (pp->coderecv == pp->codeproc) \ - pp->codeproc = (pp->codeproc + 1) % MAXSTAGE; - /* * Macros to determine the clock type and unit numbers from a * 127.127.t.u address @@ -54,6 +49,7 @@ extern struct clktype clktypes[]; #define CLK_HAVEFLAG2 0x20 #define CLK_HAVEFLAG3 0x40 #define CLK_HAVEFLAG4 0x80 +#define CLK_HAVEMINJIT 0x100 /* * Constant for disabling event reporting in @@ -68,7 +64,7 @@ extern struct clktype clktypes[]; struct refclockstat { u_char type; /* clock type */ u_char flags; /* clock flags */ - u_char haveflags; /* bit array of valid flags */ + u_short haveflags; /* bit array of valid flags */ u_short lencode; /* length of last timecode */ const char *p_lastcode; /* last timecode received */ u_int32 polls; /* transmit polls */ @@ -77,6 +73,7 @@ struct refclockstat { u_int32 baddata; /* invalid data timecode received */ u_int32 timereset; /* driver resets */ const char *clockdesc; /* ASCII description */ + double fudgeminjitter; /* configure fudge minjitter */ double fudgetime1; /* configure fudge time1 */ double fudgetime2; /* configure fudge time2 */ int32 fudgeval1; /* configure fudge value1 */ @@ -133,13 +130,12 @@ extern HANDLE WaitableIoEventHandle; * Structure interface between the reference clock support * ntp_refclock.c and the driver utility routines */ -#define MAXSTAGE 60 /* max median filter stages */ +#define MAXSTAGE 64 /* max median filter stages */ #define NSTAGE 5 /* default median filter stages */ #define BMAX 128 /* max timecode length */ #define GMT 0 /* I hope nobody sees this */ #define MAXDIAL 60 /* max length of modem dial strings */ - struct refclockproc { void * unitptr; /* pointer to unit structure */ struct refclock * conf; /* refclock_conf[type] */ @@ -148,6 +144,7 @@ struct refclockproc { u_char currentstatus; /* clock status */ u_char lastevent; /* last exception event */ u_char type; /* clock type */ + u_char inpoll; /* waiting for 'refclock_receive()' */ const char *clockdesc; /* clock description */ u_long nextaction; /* local activity timeout */ void (*action)(struct peer *); /* timeout callback */ @@ -162,8 +159,8 @@ struct refclockproc { int second; /* second of minute */ long nsec; /* nanosecond of second */ u_long yearstart; /* beginning of year */ - int coderecv; /* put pointer */ - int codeproc; /* get pointer */ + u_int coderecv; /* put pointer */ + u_int codeproc; /* get pointer */ l_fp lastref; /* reference timestamp */ l_fp lastrec; /* receive timestamp */ double offset; /* mean offset */ @@ -176,6 +173,7 @@ struct refclockproc { */ double fudgetime1; /* fudge time1 */ double fudgetime2; /* fudge time2 */ + double fudgeminjitter; /* manually set lower bound for jitter */ u_char stratum; /* server stratum */ u_int32 refid; /* reference identifier */ u_char sloppyclockflag; /* fudge flags */ @@ -229,12 +227,29 @@ extern int refclock_process(struct refclockproc *); extern int refclock_process_f(struct refclockproc *, double); extern void refclock_process_offset(struct refclockproc *, l_fp, l_fp, double); +extern int refclock_samples_avail(struct refclockproc const *); +extern int refclock_samples_expire(struct refclockproc *, int); extern void refclock_report (struct peer *, int); extern int refclock_gtlin (struct recvbuf *, char *, int, l_fp *); extern int refclock_gtraw (struct recvbuf *, char *, int, l_fp *); extern int indicate_refclock_packet(struct refclockio *, struct recvbuf *); extern void process_refclock_packet(struct recvbuf *); + +/* save string as la_code, size==(size_t)-1 ==> ASCIIZ string */ +extern void refclock_save_lcode( + struct refclockproc *, char const *, size_t); +/* format data into la_code */ +extern void refclock_format_lcode( + struct refclockproc *, char const *, ...); +extern void refclock_vformat_lcode( + struct refclockproc *, char const *, va_list); + +struct refclock_atom; +extern int refclock_ppsaugment( + const struct refclock_atom*, l_fp *rcvtime , + double rcvfudge, double ppsfudge); + #endif /* REFCLOCK */ #endif /* NTP_REFCLOCK_H */ diff --git a/include/ntp_request.h b/include/ntp_request.h index d05a67f75382..db9cbcfb96e4 100644 --- a/include/ntp_request.h +++ b/include/ntp_request.h @@ -670,8 +670,10 @@ struct conf_restrict { u_int32 addr; /* match address */ u_int32 mask; /* match mask */ short ippeerlimit; /* ip peer limit */ - u_short flags; /* restrict flags */ + int srvfuzrft; /* server response fuzz reftime: poll */ + u_short flags; /* restrict flags XXX: OLD size and name */ u_short mflags; /* match flags */ + short unused1; /* (unused) padding for v6_flag */ u_int v6_flag; /* is this v6 or not */ struct in6_addr addr6; /* match address (v6) */ struct in6_addr mask6; /* match mask (v6) */ diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h index c0bc71b09f5b..265aafa73ebc 100644 --- a/include/ntp_stdlib.h +++ b/include/ntp_stdlib.h @@ -159,7 +159,7 @@ extern const char * modetoa (size_t); extern const char * eventstr (int); extern const char * ceventstr (int); extern const char * res_match_flags(u_short); -extern const char * res_access_flags(u_short); +extern const char * res_access_flags(u_int32); #ifdef KERNEL_PLL extern const char * k_st_flags (u_int32); #endif diff --git a/include/ntp_syslog.h b/include/ntp_syslog.h index ecc6346796e8..76c638682055 100644 --- a/include/ntp_syslog.h +++ b/include/ntp_syslog.h @@ -83,4 +83,7 @@ do { \ msyslog msl_args; \ } while (FALSE) +extern int change_iobufs(int how); +/* how: 0->unbuffered, 1->linebuffer, 2->full */ + #endif /* NTP_SYSLOG_H */ diff --git a/include/ntpd.h b/include/ntpd.h index ead0c2cf8171..de9283360a46 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -232,7 +232,7 @@ extern double sys_mindisp; extern double sys_maxdist; extern char *sys_ident; /* identity scheme */ -extern void poll_update (struct peer *, u_char); +extern void poll_update (struct peer *, u_char, u_char); extern void clear (struct peer *); extern void clock_filter (struct peer *, double, double, double); @@ -282,7 +282,7 @@ extern u_char sys_automax; /* session key timeout */ /* ntp_util.c */ extern void init_util (void); extern void write_stats (void); -extern void stats_config (int, const char *); +extern void stats_config (int, const char *, int optflag); extern void record_peer_stats (sockaddr_u *, int, double, double, double, double); extern void record_proto_stats (char *); extern void record_loop_stats (double, double, double, double, int); @@ -568,7 +568,7 @@ extern char *group; /* group to switch to */ extern const char *chrootdir; /* directory to chroot() to */ #endif #ifdef HAVE_WORKING_FORK -extern int waitsync_fd_to_close; /* -w/--wait-sync */ +extern int daemon_pipe[2]; /* startup monitoring */ #endif /* ntservice.c */ diff --git a/include/timespecops.h b/include/timespecops.h index fa32e42a6000..17a9b680681e 100644 --- a/include/timespecops.h +++ b/include/timespecops.h @@ -56,68 +56,11 @@ /* predicate: returns TRUE if the nanoseconds are out-of-bounds */ #define timespec_isdenormal(x) (!timespec_isnormal(x)) -/* conversion between l_fp fractions and nanoseconds */ -#ifdef HAVE_U_INT64 -# define FTOTVN(tsf) \ - ((int32) \ - (((u_int64)(tsf) * NANOSECONDS + 0x80000000) >> 32)) -# define TVNTOF(tvu) \ - ((u_int32) \ - ((((u_int64)(tvu) << 32) + NANOSECONDS / 2) / \ - NANOSECONDS)) -#else -# define NSECFRAC (FRAC / NANOSECONDS) -# define FTOTVN(tsf) \ - ((int32)((tsf) / NSECFRAC + 0.5)) -# define TVNTOF(tvu) \ - ((u_int32)((tvu) * NSECFRAC + 0.5)) -#endif /* make sure nanoseconds are in nominal range */ -static inline struct timespec -normalize_tspec( - struct timespec x - ) -{ -#if SIZEOF_LONG > 4 - long z; - - /* - * tv_nsec is of type 'long', and on a 64-bit machine using only - * loops becomes prohibitive once the upper 32 bits get - * involved. On the other hand, division by constant should be - * fast enough; so we do a division of the nanoseconds in that - * case. The floor adjustment step follows with the standard - * normalisation loops. And labs() is intentionally not used - * here: it has implementation-defined behaviour when applied - * to LONG_MIN. - */ - if (x.tv_nsec < -3l * NANOSECONDS || - x.tv_nsec > 3l * NANOSECONDS) { - z = x.tv_nsec / NANOSECONDS; - x.tv_nsec -= z * NANOSECONDS; - x.tv_sec += z; - } -#endif - /* since 10**9 is close to 2**32, we don't divide but do a - * normalisation in a loop; this takes 3 steps max, and should - * outperform a division even if the mul-by-inverse trick is - * employed. */ - if (x.tv_nsec < 0) - do { - x.tv_nsec += NANOSECONDS; - x.tv_sec--; - } while (x.tv_nsec < 0); - else if (x.tv_nsec >= NANOSECONDS) - do { - x.tv_nsec -= NANOSECONDS; - x.tv_sec++; - } while (x.tv_nsec >= NANOSECONDS); - - return x; -} +extern struct timespec normalize_tspec(struct timespec x); /* x = a + b */ static inline struct timespec @@ -196,45 +139,13 @@ neg_tspec( } /* x = abs(a) */ -static inline struct timespec -abs_tspec( - struct timespec a - ) -{ - struct timespec c; - - c = normalize_tspec(a); - if (c.tv_sec < 0) { - if (c.tv_nsec != 0) { - c.tv_sec = -c.tv_sec - 1; - c.tv_nsec = NANOSECONDS - c.tv_nsec; - } else { - c.tv_sec = -c.tv_sec; - } - } - - return c; -} +struct timespec abs_tspec(struct timespec a); /* * compare previously-normalised a and b * return 1 / 0 / -1 if a < / == / > b */ -static inline int -cmp_tspec( - struct timespec a, - struct timespec b - ) -{ - int r; - - r = (a.tv_sec > b.tv_sec) - (a.tv_sec < b.tv_sec); - if (0 == r) - r = (a.tv_nsec > b.tv_nsec) - - (a.tv_nsec < b.tv_nsec); - - return r; -} +extern int cmp_tspec(struct timespec a, struct timespec b); /* * compare possibly-denormal a and b @@ -253,19 +164,7 @@ cmp_tspec_denorm( * test previously-normalised a * return 1 / 0 / -1 if a < / == / > 0 */ -static inline int -test_tspec( - struct timespec a - ) -{ - int r; - - r = (a.tv_sec > 0) - (a.tv_sec < 0); - if (r == 0) - r = (a.tv_nsec > 0); - - return r; -} +extern int test_tspec(struct timespec a); /* * test possibly-denormal a @@ -293,20 +192,7 @@ tspectoa( */ /* convert from timespec duration to l_fp duration */ -static inline l_fp -tspec_intv_to_lfp( - struct timespec x - ) -{ - struct timespec v; - l_fp y; - - v = normalize_tspec(x); - y.l_uf = TVNTOF(v.tv_nsec); - y.l_i = (int32)v.tv_sec; - - return y; -} +extern l_fp tspec_intv_to_lfp(struct timespec x); /* x must be UN*X epoch, output will be in NTP epoch */ static inline l_fp @@ -323,71 +209,14 @@ tspec_stamp_to_lfp( } /* convert from l_fp type, relative signed/unsigned and absolute */ -static inline struct timespec -lfp_intv_to_tspec( - l_fp x - ) -{ - struct timespec out; - l_fp absx; - int neg; - - neg = L_ISNEG(&x); - absx = x; - if (neg) { - L_NEG(&absx); - } - out.tv_nsec = FTOTVN(absx.l_uf); - out.tv_sec = absx.l_i; - if (neg) { - out.tv_sec = -out.tv_sec; - out.tv_nsec = -out.tv_nsec; - out = normalize_tspec(out); - } - - return out; -} - -static inline struct timespec -lfp_uintv_to_tspec( - l_fp x - ) -{ - struct timespec out; - - out.tv_nsec = FTOTVN(x.l_uf); - out.tv_sec = x.l_ui; - - return out; -} +extern struct timespec lfp_intv_to_tspec(l_fp x); +extern struct timespec lfp_uintv_to_tspec(l_fp x); /* * absolute (timestamp) conversion. Input is time in NTP epoch, output * is in UN*X epoch. The NTP time stamp will be expanded around the * pivot time *p or the current time, if p is NULL. */ -static inline struct timespec -lfp_stamp_to_tspec( - l_fp x, - const time_t * p - ) -{ - struct timespec out; - vint64 sec; - - sec = ntpcal_ntp_to_time(x.l_ui, p); - out.tv_nsec = FTOTVN(x.l_uf); - - /* copying a vint64 to a time_t needs some care... */ -#if SIZEOF_TIME_T <= 4 - out.tv_sec = (time_t)sec.d_s.lo; -#elif defined(HAVE_INT64) - out.tv_sec = (time_t)sec.q_s; -#else - out.tv_sec = ((time_t)sec.d_s.hi << 32) | sec.d_s.lo; -#endif - - return out; -} +extern struct timespec lfp_stamp_to_tspec(l_fp x, const time_t *pivot); #endif /* TIMESPECOPS_H */ diff --git a/include/timexsup.h b/include/timexsup.h new file mode 100644 index 000000000000..81afe41e267c --- /dev/null +++ b/include/timexsup.h @@ -0,0 +1,42 @@ +/* + * timexsup.h - 'struct timex' support functions + * + * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. + * The contents of 'html/copyright.html' apply. + */ +#ifndef TIMEXSUP_H +#define TIMEXSUP_H + + +/* convert a 'long' time value (in usec or nsec) into seconds, expressed + * as a 'double'. If 'STA_NANO' is not defined, this will always convert + * from usec. ('STA_NANO' is Linux specific at the time of this + * writing.) + * + * If 'STA_NANO' is defined, it will be checked in 'status' to decide + * which time base (usec or nsec) applies for this conversion. + */ +extern double dbl_from_var_long(long lval, int status); + +/* convert a 'long' time value in usec into seconds, expressed as + * 'double'. This function is there for pure symmetry right now -- it + * just casts and scales without any additional bells and whistles. + */ +extern double dbl_from_usec_long(long lval); + +/* If MOD_NANO is defined, set the MOD_NANO bit in '*modes' and + * calculate the time stamp in nsec; otherwise, calculate the result in + * usec. + * + * Applies proper bounds checks and saturation on LONG_MAX/LONG_MIN to + * avoid undefined behaviour. + */ +extern long var_long_from_dbl(double dval, unsigned int *modes); + +/* convert a 'double' time value (in seconds) into usec with proper + * bounds check and range clamp. + */ +extern long usec_long_from_dbl(double dval); + +#endif +/* -*- that's all folks -*- */ |
