summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Makefile.am15
-rw-r--r--include/Makefile.in181
-rw-r--r--include/autogen-version.def2
-rw-r--r--include/copyright.def24
-rw-r--r--include/debug-opt.def32
-rw-r--r--include/declcond.h21
-rw-r--r--include/homerc.def9
-rw-r--r--include/intreswork.h29
-rw-r--r--include/iosignal.h55
-rw-r--r--include/isc/Makefile.am2
-rw-r--r--include/isc/Makefile.in168
-rw-r--r--include/isc/mem.h6
-rw-r--r--include/l_stdlib.h22
-rw-r--r--include/lib_strbuf.h32
-rw-r--r--include/libntp.h16
-rw-r--r--include/mbg_gps166.h4
-rw-r--r--include/ntp.h195
-rw-r--r--include/ntp_assert.h21
-rw-r--r--include/ntp_calendar.h372
-rw-r--r--include/ntp_cmdargs.h5
-rw-r--r--include/ntp_config.h359
-rw-r--r--include/ntp_control.h145
-rw-r--r--include/ntp_crypto.h27
-rw-r--r--include/ntp_data_structures.h53
-rw-r--r--include/ntp_debug.h25
-rw-r--r--include/ntp_filegen.h32
-rw-r--r--include/ntp_fp.h375
-rw-r--r--include/ntp_intres.h47
-rw-r--r--include/ntp_io.h24
-rw-r--r--include/ntp_libopts.h1
-rw-r--r--include/ntp_machine.h255
-rw-r--r--include/ntp_md5.h37
-rw-r--r--include/ntp_net.h7
-rw-r--r--include/ntp_prio_q.h83
-rw-r--r--include/ntp_proto.h10
-rw-r--r--include/ntp_random.h3
-rw-r--r--include/ntp_refclock.h101
-rw-r--r--include/ntp_request.h77
-rw-r--r--include/ntp_rfc2553.h27
-rw-r--r--include/ntp_select.h37
-rw-r--r--include/ntp_sprintf.h13
-rw-r--r--include/ntp_stdlib.h146
-rw-r--r--include/ntp_string.h26
-rw-r--r--include/ntp_syscall.h56
-rw-r--r--include/ntp_syslog.h33
-rw-r--r--include/ntp_tty.h70
-rw-r--r--include/ntp_types.h208
-rw-r--r--include/ntp_unixtime.h113
-rw-r--r--include/ntp_worker.h162
-rw-r--r--include/ntp_workimpl.h30
-rw-r--r--include/ntpd.h318
-rw-r--r--include/ntpsim.h77
-rw-r--r--include/recvbuff.h83
-rw-r--r--include/refclock_atom.h2
-rw-r--r--include/timepps-SCO.h2
-rw-r--r--include/timepps-Solaris.h2
-rw-r--r--include/timepps-SunOS.h2
-rw-r--r--include/timespecops.h393
-rw-r--r--include/timetoa.h83
-rw-r--r--include/timevalops.h446
-rw-r--r--include/version.def1
-rw-r--r--include/version.texi3
-rw-r--r--include/vint64ops.h28
63 files changed, 3523 insertions, 1710 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 88727ddaf4e51..5ab3e6e9d0df1 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,7 +1,4 @@
NULL =
-AUTOMAKE_OPTIONS =
-ETAGS_ARGS = $(srcdir)/Makefile.am
-EXTRA_DIST = autogen-version.def copyright.def debug-opt.def homerc.def version.def version.texi
SUBDIRS = isc
@@ -11,13 +8,16 @@ noinst_HEADERS = \
ascii.h \
audio.h \
binio.h \
+ declcond.h \
gps.h \
hopf6039.h \
icom.h \
ieee754io.h \
+ intreswork.h \
iosignal.h \
l_stdlib.h \
lib_strbuf.h \
+ libntp.h \
mbg_gps166.h \
mx4200.h \
ntif.h \
@@ -28,7 +28,7 @@ noinst_HEADERS = \
ntp_config.h \
ntp_control.h \
ntp_crypto.h \
- ntp_data_structures.h \
+ ntp_prio_q.h \
ntp_datum.h \
ntp_debug.h \
ntp_filegen.h \
@@ -49,7 +49,6 @@ noinst_HEADERS = \
ntp_request.h \
ntp_rfc2553.h \
ntp_select.h \
- ntp_sprintf.h \
ntp_stdlib.h \
ntp_string.h \
ntp_syscall.h \
@@ -57,6 +56,8 @@ noinst_HEADERS = \
ntp_tty.h \
ntp_types.h \
ntp_unixtime.h \
+ ntp_worker.h \
+ ntp_workimpl.h \
ntpd.h \
ntpsim.h \
parse.h \
@@ -67,6 +68,10 @@ noinst_HEADERS = \
timepps-SCO.h \
timepps-Solaris.h \
timepps-SunOS.h \
+ timespecops.h \
+ timetoa.h \
+ timevalops.h \
trimble.h \
+ vint64ops.h \
$(NULL)
diff --git a/include/Makefile.in b/include/Makefile.in
index 2f285def317ba..0a6a65d4da3cf 100644
--- a/include/Makefile.in
+++ b/include/Makefile.in
@@ -39,22 +39,52 @@ DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \
- $(top_srcdir)/m4/define_dir.m4 $(top_srcdir)/m4/libtool.m4 \
- $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
- $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
- $(top_srcdir)/m4/ntp_cacheversion.m4 \
- $(top_srcdir)/m4/ntp_dir_sep.m4 \
- $(top_srcdir)/m4/ntp_lineeditlibs.m4 \
- $(top_srcdir)/m4/ntp_openssl.m4 \
- $(top_srcdir)/m4/ntp_vpathhack.m4 \
- $(top_srcdir)/m4/os_cflags.m4 $(top_srcdir)/version.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/sntp/libopts/m4/stdnoreturn.m4 \
+ $(top_srcdir)/sntp/libevent/m4/openldap-thread-check.m4 \
+ $(top_srcdir)/sntp/libevent/m4/openldap.m4 \
+ $(top_srcdir)/sntp/m4/define_dir.m4 \
+ $(top_srcdir)/sntp/m4/hms_search_lib.m4 \
+ $(top_srcdir)/sntp/m4/libtool.m4 \
+ $(top_srcdir)/sntp/m4/ltoptions.m4 \
+ $(top_srcdir)/sntp/m4/ltsugar.m4 \
+ $(top_srcdir)/sntp/m4/ltversion.m4 \
+ $(top_srcdir)/sntp/m4/lt~obsolete.m4 \
+ $(top_srcdir)/sntp/m4/ntp_cacheversion.m4 \
+ $(top_srcdir)/sntp/m4/ntp_compiler.m4 \
+ $(top_srcdir)/sntp/m4/ntp_crosscompile.m4 \
+ $(top_srcdir)/sntp/m4/ntp_crypto_rand.m4 \
+ $(top_srcdir)/sntp/m4/ntp_debug.m4 \
+ $(top_srcdir)/sntp/m4/ntp_dir_sep.m4 \
+ $(top_srcdir)/sntp/m4/ntp_facilitynames.m4 \
+ $(top_srcdir)/sntp/m4/ntp_googletest.m4 \
+ $(top_srcdir)/sntp/m4/ntp_ipv6.m4 \
+ $(top_srcdir)/sntp/m4/ntp_lib_m.m4 \
+ $(top_srcdir)/sntp/m4/ntp_libevent.m4 \
+ $(top_srcdir)/sntp/m4/ntp_libntp.m4 \
+ $(top_srcdir)/sntp/m4/ntp_lineeditlibs.m4 \
+ $(top_srcdir)/sntp/m4/ntp_locinfo.m4 \
+ $(top_srcdir)/sntp/m4/ntp_openssl.m4 \
+ $(top_srcdir)/sntp/m4/ntp_pkg_config.m4 \
+ $(top_srcdir)/sntp/m4/ntp_prog_cc.m4 \
+ $(top_srcdir)/sntp/m4/ntp_rlimit.m4 \
+ $(top_srcdir)/sntp/m4/ntp_sntp.m4 \
+ $(top_srcdir)/sntp/m4/ntp_ver_suffix.m4 \
+ $(top_srcdir)/sntp/m4/ntp_vpathhack.m4 \
+ $(top_srcdir)/sntp/m4/os_cflags.m4 \
+ $(top_srcdir)/sntp/m4/snprintf.m4 \
+ $(top_srcdir)/sntp/m4/version.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
+AM_V_GEN = $(am__v_GEN_$(V))
+am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+am__v_GEN_0 = @echo " GEN " $@;
+AM_V_at = $(am__v_at_$(V))
+am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+am__v_at_0 = @
SOURCES =
DIST_SOURCES =
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
@@ -100,20 +130,32 @@ am__relativize = \
done; \
reldir="$$dir2"
ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
-BINSUBDIR = @BINSUBDIR@
+CALC_TICKADJ_DB = @CALC_TICKADJ_DB@
+CALC_TICKADJ_DL = @CALC_TICKADJ_DL@
+CALC_TICKADJ_DS = @CALC_TICKADJ_DS@
+CALC_TICKADJ_MS = @CALC_TICKADJ_MS@
+CALC_TICKADJ_NI = @CALC_TICKADJ_NI@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
+CFLAGS_NTP = @CFLAGS_NTP@
CHUTEST = @CHUTEST@
-CLKTEST = @CLKTEST@
+CONFIG_SHELL = @CONFIG_SHELL@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
+CPPFLAGS_NTP = @CPPFLAGS_NTP@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DCFD = @DCFD@
DEFS = @DEFS@
@@ -125,21 +167,31 @@ ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EDITLINE_LIBS = @EDITLINE_LIBS@
-EF_LIBS = @EF_LIBS@
-EF_PROGS = @EF_PROGS@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
GREP = @GREP@
+GTEST_CONFIG = @GTEST_CONFIG@
+GTEST_CPPFLAGS = @GTEST_CPPFLAGS@
+GTEST_CXXFLAGS = @GTEST_CXXFLAGS@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
+GTEST_LIBS = @GTEST_LIBS@
HAVE_INLINE = @HAVE_INLINE@
+HAVE_RLIMIT_MEMLOCK = @HAVE_RLIMIT_MEMLOCK@
+HAVE_RLIMIT_STACK = @HAVE_RLIMIT_STACK@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-LCRYPTO = @LCRYPTO@
LD = @LD@
+LDADD_LIBNTP = @LDADD_LIBNTP@
+LDADD_NLIST = @LDADD_NLIST@
+LDADD_NTP = @LDADD_NTP@
LDFLAGS = @LDFLAGS@
+LDFLAGS_NTP = @LDFLAGS_NTP@
+LIBISC_PTHREADS_NOTHREADS = @LIBISC_PTHREADS_NOTHREADS@
+LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
LIBOPTS_CFLAGS = @LIBOPTS_CFLAGS@
LIBOPTS_DIR = @LIBOPTS_DIR@
@@ -147,6 +199,7 @@ LIBOPTS_LDADD = @LIBOPTS_LDADD@
LIBPARSE = @LIBPARSE@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
LIPO = @LIPO@
LN_S = @LN_S@
LSCF = @LSCF@
@@ -165,14 +218,68 @@ MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@
MAKE_TICKADJ = @MAKE_TICKADJ@
MAKE_TIMETRIM = @MAKE_TIMETRIM@
MANIFEST_TOOL = @MANIFEST_TOOL@
+MANTAGFMT = @MANTAGFMT@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
+NTPDATE_DB = @NTPDATE_DB@
+NTPDATE_DL = @NTPDATE_DL@
+NTPDATE_DS = @NTPDATE_DS@
+NTPDATE_MS = @NTPDATE_MS@
+NTPDATE_NI = @NTPDATE_NI@
+NTPDC_DB = @NTPDC_DB@
+NTPDC_DL = @NTPDC_DL@
+NTPDC_DS = @NTPDC_DS@
+NTPDC_MS = @NTPDC_MS@
+NTPDC_NI = @NTPDC_NI@
+NTPDSIM_DB = @NTPDSIM_DB@
+NTPDSIM_DL = @NTPDSIM_DL@
+NTPDSIM_DS = @NTPDSIM_DS@
+NTPDSIM_MS = @NTPDSIM_MS@
+NTPDSIM_NI = @NTPDSIM_NI@
+NTPD_DB = @NTPD_DB@
+NTPD_DL = @NTPD_DL@
+NTPD_DS = @NTPD_DS@
+NTPD_MS = @NTPD_MS@
+NTPD_NI = @NTPD_NI@
+NTPQ_DB = @NTPQ_DB@
+NTPQ_DL = @NTPQ_DL@
+NTPQ_DS = @NTPQ_DS@
+NTPQ_MS = @NTPQ_MS@
+NTPQ_NI = @NTPQ_NI@
+NTPSNMPD_DB = @NTPSNMPD_DB@
+NTPSNMPD_DL = @NTPSNMPD_DL@
+NTPSNMPD_DS = @NTPSNMPD_DS@
+NTPSNMPD_MS = @NTPSNMPD_MS@
+NTPSNMPD_NI = @NTPSNMPD_NI@
+NTPSWEEP_DB = @NTPSWEEP_DB@
+NTPSWEEP_DL = @NTPSWEEP_DL@
+NTPSWEEP_DS = @NTPSWEEP_DS@
+NTPSWEEP_MS = @NTPSWEEP_MS@
+NTPSWEEP_NI = @NTPSWEEP_NI@
+NTPTIME_DB = @NTPTIME_DB@
+NTPTIME_DL = @NTPTIME_DL@
+NTPTIME_DS = @NTPTIME_DS@
+NTPTIME_MS = @NTPTIME_MS@
+NTPTIME_NI = @NTPTIME_NI@
+NTPTRACE_DB = @NTPTRACE_DB@
+NTPTRACE_DL = @NTPTRACE_DL@
+NTPTRACE_DS = @NTPTRACE_DS@
+NTPTRACE_MS = @NTPTRACE_MS@
+NTPTRACE_NI = @NTPTRACE_NI@
+NTP_KEYGEN_DB = @NTP_KEYGEN_DB@
+NTP_KEYGEN_DL = @NTP_KEYGEN_DL@
+NTP_KEYGEN_DS = @NTP_KEYGEN_DS@
+NTP_KEYGEN_MS = @NTP_KEYGEN_MS@
+NTP_KEYGEN_NI = @NTP_KEYGEN_NI@
+NTP_KEYSDIR = @NTP_KEYSDIR@
+NTP_WAIT_DB = @NTP_WAIT_DB@
+NTP_WAIT_DL = @NTP_WAIT_DL@
+NTP_WAIT_DS = @NTP_WAIT_DS@
+NTP_WAIT_MS = @NTP_WAIT_MS@
+NTP_WAIT_NI = @NTP_WAIT_NI@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
-OPENSSL = @OPENSSL@
-OPENSSL_INC = @OPENSSL_INC@
-OPENSSL_LIB = @OPENSSL_LIB@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
@@ -185,10 +292,12 @@ PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_NET_SNMP_CONFIG = @PATH_NET_SNMP_CONFIG@
PATH_PERL = @PATH_PERL@
PATH_SEPARATOR = @PATH_SEPARATOR@
-PATH_SH = @PATH_SH@
PATH_TEST = @PATH_TEST@
+PERLLIBDIR = @PERLLIBDIR@
+PKG_CONFIG = @PKG_CONFIG@
POSIX_SHELL = @POSIX_SHELL@
PROPDELAY = @PROPDELAY@
+PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
@@ -196,9 +305,27 @@ SHELL = @SHELL@
SNMP_CFLAGS = @SNMP_CFLAGS@
SNMP_CPPFLAGS = @SNMP_CPPFLAGS@
SNMP_LIBS = @SNMP_LIBS@
+SNTP = @SNTP@
+SNTP_DB = @SNTP_DB@
+SNTP_DL = @SNTP_DL@
+SNTP_DS = @SNTP_DS@
+SNTP_MS = @SNTP_MS@
+SNTP_NI = @SNTP_NI@
+STDNORETURN_H = @STDNORETURN_H@
STRIP = @STRIP@
TESTDCF = @TESTDCF@
+TICKADJ_DB = @TICKADJ_DB@
+TICKADJ_DL = @TICKADJ_DL@
+TICKADJ_DS = @TICKADJ_DS@
+TICKADJ_MS = @TICKADJ_MS@
+TICKADJ_NI = @TICKADJ_NI@
+TIMETRIM_DB = @TIMETRIM_DB@
+TIMETRIM_DL = @TIMETRIM_DL@
+TIMETRIM_DS = @TIMETRIM_DS@
+TIMETRIM_MS = @TIMETRIM_MS@
+TIMETRIM_NI = @TIMETRIM_NI@
VERSION = @VERSION@
+VER_SUFFIX = @VER_SUFFIX@
YACC = @YACC@
YFLAGS = @YFLAGS@
abs_builddir = @abs_builddir@
@@ -207,6 +334,7 @@ abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
@@ -255,9 +383,6 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
NULL =
-AUTOMAKE_OPTIONS =
-ETAGS_ARGS = $(srcdir)/Makefile.am
-EXTRA_DIST = autogen-version.def copyright.def debug-opt.def homerc.def version.def version.texi
SUBDIRS = isc
noinst_HEADERS = \
adjtime.h \
@@ -265,13 +390,16 @@ noinst_HEADERS = \
ascii.h \
audio.h \
binio.h \
+ declcond.h \
gps.h \
hopf6039.h \
icom.h \
ieee754io.h \
+ intreswork.h \
iosignal.h \
l_stdlib.h \
lib_strbuf.h \
+ libntp.h \
mbg_gps166.h \
mx4200.h \
ntif.h \
@@ -282,7 +410,7 @@ noinst_HEADERS = \
ntp_config.h \
ntp_control.h \
ntp_crypto.h \
- ntp_data_structures.h \
+ ntp_prio_q.h \
ntp_datum.h \
ntp_debug.h \
ntp_filegen.h \
@@ -303,7 +431,6 @@ noinst_HEADERS = \
ntp_request.h \
ntp_rfc2553.h \
ntp_select.h \
- ntp_sprintf.h \
ntp_stdlib.h \
ntp_string.h \
ntp_syscall.h \
@@ -311,6 +438,8 @@ noinst_HEADERS = \
ntp_tty.h \
ntp_types.h \
ntp_unixtime.h \
+ ntp_worker.h \
+ ntp_workimpl.h \
ntpd.h \
ntpsim.h \
parse.h \
@@ -321,7 +450,11 @@ noinst_HEADERS = \
timepps-SCO.h \
timepps-Solaris.h \
timepps-SunOS.h \
+ timespecops.h \
+ timetoa.h \
+ timevalops.h \
trimble.h \
+ vint64ops.h \
$(NULL)
all: all-recursive
diff --git a/include/autogen-version.def b/include/autogen-version.def
deleted file mode 100644
index d69457ccf1e09..0000000000000
--- a/include/autogen-version.def
+++ /dev/null
@@ -1,2 +0,0 @@
-#assert (version-compare >= autogen-version "5.11.9")
-guard-option-names;
diff --git a/include/copyright.def b/include/copyright.def
deleted file mode 100644
index 0f1708c5d7c51..0000000000000
--- a/include/copyright.def
+++ /dev/null
@@ -1,24 +0,0 @@
-/* -*- Mode: Text -*- */
-
-copyright = {
- date = "1970-2011";
- owner = "David L. Mills and/or others";
- eaddr = "http://bugs.ntp.org, bugs@ntp.org";
- type = note;
- text = <<- _EndOfDoc_
- see html/copyright.html
-
- _EndOfDoc_;
-};
-
-long-opts;
-config-header = config.h;
-environrc;
-no-misuse-usage;
-
-version = `
-eval VERSION=\`sed -e 's/.*,\\[//' -e 's/\\].*//' < ../version.m4\`
-[ -z "${VERSION}" ] && echo "Cannot determine VERSION" && kill -TERM $AG_pid
-echo $VERSION`;
-
-version-value = ''; /* Don't use -v as a shortcut for --version */
diff --git a/include/debug-opt.def b/include/debug-opt.def
deleted file mode 100644
index 783e5b0b1ff06..0000000000000
--- a/include/debug-opt.def
+++ /dev/null
@@ -1,32 +0,0 @@
-
-include = <<- _EOF_
- #ifdef __windows
- extern int atoi(const char*);
- #else
- # include <stdlib.h>
- #endif
- _EOF_;
-
-flag = {
- name = debug-level;
- value = d;
- max = NOLIMIT;
- nopreset;
- descrip = "Increase output debug message level";
- doc = <<- _EndOfDoc_
- Increase the debugging message output level.
- _EndOfDoc_;
-};
-
-flag = {
- name = set-debug-level;
- value = D;
- max = NOLIMIT;
- descrip = "Set the output debug message level";
- arg-type = string;
- flag-code = 'DESC(DEBUG_LEVEL).optOccCt = atoi( pOptDesc->pzLastArg );';
- doc = <<- _EndOfDoc_
- Set the output debugging level. Can be supplied multiple times,
- but each overrides the previous value(s).
- _EndOfDoc_;
-};
diff --git a/include/declcond.h b/include/declcond.h
new file mode 100644
index 0000000000000..751eff9d167c7
--- /dev/null
+++ b/include/declcond.h
@@ -0,0 +1,21 @@
+/*
+ * declcond.h - declarations conditionalized for ntpd
+ *
+ * The NTP reference implementation distribution includes two distinct
+ * declcond.h files, one in ntpd/ used only by ntpd, and another in
+ * include/ used by libntp and utilities. This relies on the source
+ * file's directory being ahead of include/ in the include search.
+ *
+ * The ntpd variant of declcond.h declares "debug" only #ifdef DEBUG,
+ * as the --disable-debugging version of ntpd should not reference
+ * "debug". The libntp and utilities variant always declares debug,
+ * as it is used in those codebases even without DEBUG defined.
+ */
+#ifndef DECLCOND_H
+#define DECLCOND_H
+
+/* #ifdef DEBUG */ /* uncommented in ntpd/declcond.h */
+extern int debug;
+/* #endif */ /* uncommented in ntpd/declcond.h */
+
+#endif /* DECLCOND_H */
diff --git a/include/homerc.def b/include/homerc.def
deleted file mode 100644
index 18b4dcb74a98e..0000000000000
--- a/include/homerc.def
+++ /dev/null
@@ -1,9 +0,0 @@
-/* -*- Mode: Text -*- */
-
-#ifndef __windows__
-rcfile = ".ntprc";
-#else
-rcfile = "ntp.ini";
-#endif
-
-homerc = $HOME, ".";
diff --git a/include/intreswork.h b/include/intreswork.h
new file mode 100644
index 0000000000000..c343ac0135950
--- /dev/null
+++ b/include/intreswork.h
@@ -0,0 +1,29 @@
+/*
+ * intreswork.h -- declarations private to ntp_intres.c, ntp_worker.c.
+ */
+#ifndef INTRESWORK_H
+#define INTRESWORK_H
+
+#include "ntp_worker.h"
+
+#ifdef WORKER
+
+extern int blocking_getaddrinfo(blocking_child *,
+ blocking_pipe_header *);
+extern int blocking_getnameinfo(blocking_child *,
+ blocking_pipe_header *);
+
+#ifdef TEST_BLOCKING_WORKER
+extern void gai_test_callback(int rescode, int gai_errno,
+ void *context, const char *name,
+ const char *service,
+ const struct addrinfo *hints,
+ const struct addrinfo *ai_res);
+extern void gni_test_callback(int rescode, int gni_errno,
+ sockaddr_u *psau, int flags,
+ const char *host,
+ const char *service, void *context);
+#endif /* TEST_BLOCKING_WORKER */
+#endif /* WORKER */
+
+#endif /* INTRESWORK_H */
diff --git a/include/iosignal.h b/include/iosignal.h
index 6c4052b7f049e..406804e14c668 100644
--- a/include/iosignal.h
+++ b/include/iosignal.h
@@ -1,23 +1,58 @@
-#if !defined _ntp_iosignaled_h
-#define _ntp_iosignaled_h
+#ifndef IOSIGNAL_H
+#define IOSIGNAL_H
#include "ntp_refclock.h"
+ /*
+ * Some systems (MOST) define SIGPOLL == SIGIO, others SIGIO == SIGPOLL, and
+ * a few have separate SIGIO and SIGPOLL signals. This code checks for the
+ * SIGIO == SIGPOLL case at compile time.
+ * Do not define USE_SIGPOLL or USE_SIGIO.
+ * these are interal only to iosignal.c and ntpd/work_fork.c!
+ */
+#if defined(USE_SIGPOLL)
+# undef USE_SIGPOLL
+#endif
+#if defined(USE_SIGIO)
+# undef USE_SIGIO
+#endif
+
+/* type of input handler function - only shared between iosignal.c and ntp_io.c */
+typedef void (input_handler_t)(l_fp *);
+
#if defined(HAVE_SIGNALED_IO)
+# if defined(USE_TTY_SIGPOLL) || defined(USE_UDP_SIGPOLL)
+# define USE_SIGPOLL
+# endif
+
+# if !defined(USE_TTY_SIGPOLL) || !defined(USE_UDP_SIGPOLL)
+# define USE_SIGIO
+# endif
+
+# if defined(USE_SIGIO) && defined(USE_SIGPOLL)
+# if SIGIO == SIGPOLL
+# define USE_SIGIO
+# undef USE_SIGPOLL
+# endif /* SIGIO == SIGPOLL */
+# endif /* USE_SIGIO && USE_SIGPOLL */
+
+#define USING_SIGIO() using_sigio
+
+extern int using_sigio;
+
extern void block_sigio (void);
extern void unblock_sigio (void);
extern int init_clock_sig (struct refclockio *);
extern void init_socket_sig (int);
-extern void set_signal (void);
-RETSIGTYPE sigio_handler (int);
+extern void set_signal (input_handler_t *);
# define BLOCKIO() block_sigio()
# define UNBLOCKIO() unblock_sigio()
-#else
-
-# define BLOCKIO()
-# define UNBLOCKIO()
-#endif /* HAVE_SIGNALED_IO */
-
+#else /* !HAVE_SIGNALED_IO follows */
+# define BLOCKIO() do {} while (0)
+# define UNBLOCKIO() do {} while (0)
+# define USING_SIGIO() FALSE
#endif
+
+#endif /* IOSIGNAL_H */
diff --git a/include/isc/Makefile.am b/include/isc/Makefile.am
index 14aa70813e16e..160203b0cdadb 100644
--- a/include/isc/Makefile.am
+++ b/include/isc/Makefile.am
@@ -1,6 +1,4 @@
NULL =
-AUTOMAKE_OPTIONS =
-ETAGS_ARGS = $(srcdir)/Makefile.am
noinst_HEADERS = \
mem.h \
diff --git a/include/isc/Makefile.in b/include/isc/Makefile.in
index b792b24eb823e..cdb34ec0902bd 100644
--- a/include/isc/Makefile.in
+++ b/include/isc/Makefile.in
@@ -39,22 +39,52 @@ DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \
- $(top_srcdir)/m4/define_dir.m4 $(top_srcdir)/m4/libtool.m4 \
- $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
- $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
- $(top_srcdir)/m4/ntp_cacheversion.m4 \
- $(top_srcdir)/m4/ntp_dir_sep.m4 \
- $(top_srcdir)/m4/ntp_lineeditlibs.m4 \
- $(top_srcdir)/m4/ntp_openssl.m4 \
- $(top_srcdir)/m4/ntp_vpathhack.m4 \
- $(top_srcdir)/m4/os_cflags.m4 $(top_srcdir)/version.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/sntp/libopts/m4/stdnoreturn.m4 \
+ $(top_srcdir)/sntp/libevent/m4/openldap-thread-check.m4 \
+ $(top_srcdir)/sntp/libevent/m4/openldap.m4 \
+ $(top_srcdir)/sntp/m4/define_dir.m4 \
+ $(top_srcdir)/sntp/m4/hms_search_lib.m4 \
+ $(top_srcdir)/sntp/m4/libtool.m4 \
+ $(top_srcdir)/sntp/m4/ltoptions.m4 \
+ $(top_srcdir)/sntp/m4/ltsugar.m4 \
+ $(top_srcdir)/sntp/m4/ltversion.m4 \
+ $(top_srcdir)/sntp/m4/lt~obsolete.m4 \
+ $(top_srcdir)/sntp/m4/ntp_cacheversion.m4 \
+ $(top_srcdir)/sntp/m4/ntp_compiler.m4 \
+ $(top_srcdir)/sntp/m4/ntp_crosscompile.m4 \
+ $(top_srcdir)/sntp/m4/ntp_crypto_rand.m4 \
+ $(top_srcdir)/sntp/m4/ntp_debug.m4 \
+ $(top_srcdir)/sntp/m4/ntp_dir_sep.m4 \
+ $(top_srcdir)/sntp/m4/ntp_facilitynames.m4 \
+ $(top_srcdir)/sntp/m4/ntp_googletest.m4 \
+ $(top_srcdir)/sntp/m4/ntp_ipv6.m4 \
+ $(top_srcdir)/sntp/m4/ntp_lib_m.m4 \
+ $(top_srcdir)/sntp/m4/ntp_libevent.m4 \
+ $(top_srcdir)/sntp/m4/ntp_libntp.m4 \
+ $(top_srcdir)/sntp/m4/ntp_lineeditlibs.m4 \
+ $(top_srcdir)/sntp/m4/ntp_locinfo.m4 \
+ $(top_srcdir)/sntp/m4/ntp_openssl.m4 \
+ $(top_srcdir)/sntp/m4/ntp_pkg_config.m4 \
+ $(top_srcdir)/sntp/m4/ntp_prog_cc.m4 \
+ $(top_srcdir)/sntp/m4/ntp_rlimit.m4 \
+ $(top_srcdir)/sntp/m4/ntp_sntp.m4 \
+ $(top_srcdir)/sntp/m4/ntp_ver_suffix.m4 \
+ $(top_srcdir)/sntp/m4/ntp_vpathhack.m4 \
+ $(top_srcdir)/sntp/m4/os_cflags.m4 \
+ $(top_srcdir)/sntp/m4/snprintf.m4 \
+ $(top_srcdir)/sntp/m4/version.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
+AM_V_GEN = $(am__v_GEN_$(V))
+am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+am__v_GEN_0 = @echo " GEN " $@;
+AM_V_at = $(am__v_at_$(V))
+am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+am__v_at_0 = @
SOURCES =
DIST_SOURCES =
HEADERS = $(noinst_HEADERS)
@@ -62,20 +92,32 @@ ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
-BINSUBDIR = @BINSUBDIR@
+CALC_TICKADJ_DB = @CALC_TICKADJ_DB@
+CALC_TICKADJ_DL = @CALC_TICKADJ_DL@
+CALC_TICKADJ_DS = @CALC_TICKADJ_DS@
+CALC_TICKADJ_MS = @CALC_TICKADJ_MS@
+CALC_TICKADJ_NI = @CALC_TICKADJ_NI@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
+CFLAGS_NTP = @CFLAGS_NTP@
CHUTEST = @CHUTEST@
-CLKTEST = @CLKTEST@
+CONFIG_SHELL = @CONFIG_SHELL@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
+CPPFLAGS_NTP = @CPPFLAGS_NTP@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DCFD = @DCFD@
DEFS = @DEFS@
@@ -87,21 +129,31 @@ ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EDITLINE_LIBS = @EDITLINE_LIBS@
-EF_LIBS = @EF_LIBS@
-EF_PROGS = @EF_PROGS@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
GREP = @GREP@
+GTEST_CONFIG = @GTEST_CONFIG@
+GTEST_CPPFLAGS = @GTEST_CPPFLAGS@
+GTEST_CXXFLAGS = @GTEST_CXXFLAGS@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
+GTEST_LIBS = @GTEST_LIBS@
HAVE_INLINE = @HAVE_INLINE@
+HAVE_RLIMIT_MEMLOCK = @HAVE_RLIMIT_MEMLOCK@
+HAVE_RLIMIT_STACK = @HAVE_RLIMIT_STACK@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-LCRYPTO = @LCRYPTO@
LD = @LD@
+LDADD_LIBNTP = @LDADD_LIBNTP@
+LDADD_NLIST = @LDADD_NLIST@
+LDADD_NTP = @LDADD_NTP@
LDFLAGS = @LDFLAGS@
+LDFLAGS_NTP = @LDFLAGS_NTP@
+LIBISC_PTHREADS_NOTHREADS = @LIBISC_PTHREADS_NOTHREADS@
+LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
LIBOPTS_CFLAGS = @LIBOPTS_CFLAGS@
LIBOPTS_DIR = @LIBOPTS_DIR@
@@ -109,6 +161,7 @@ LIBOPTS_LDADD = @LIBOPTS_LDADD@
LIBPARSE = @LIBPARSE@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
LIPO = @LIPO@
LN_S = @LN_S@
LSCF = @LSCF@
@@ -127,14 +180,68 @@ MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@
MAKE_TICKADJ = @MAKE_TICKADJ@
MAKE_TIMETRIM = @MAKE_TIMETRIM@
MANIFEST_TOOL = @MANIFEST_TOOL@
+MANTAGFMT = @MANTAGFMT@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
+NTPDATE_DB = @NTPDATE_DB@
+NTPDATE_DL = @NTPDATE_DL@
+NTPDATE_DS = @NTPDATE_DS@
+NTPDATE_MS = @NTPDATE_MS@
+NTPDATE_NI = @NTPDATE_NI@
+NTPDC_DB = @NTPDC_DB@
+NTPDC_DL = @NTPDC_DL@
+NTPDC_DS = @NTPDC_DS@
+NTPDC_MS = @NTPDC_MS@
+NTPDC_NI = @NTPDC_NI@
+NTPDSIM_DB = @NTPDSIM_DB@
+NTPDSIM_DL = @NTPDSIM_DL@
+NTPDSIM_DS = @NTPDSIM_DS@
+NTPDSIM_MS = @NTPDSIM_MS@
+NTPDSIM_NI = @NTPDSIM_NI@
+NTPD_DB = @NTPD_DB@
+NTPD_DL = @NTPD_DL@
+NTPD_DS = @NTPD_DS@
+NTPD_MS = @NTPD_MS@
+NTPD_NI = @NTPD_NI@
+NTPQ_DB = @NTPQ_DB@
+NTPQ_DL = @NTPQ_DL@
+NTPQ_DS = @NTPQ_DS@
+NTPQ_MS = @NTPQ_MS@
+NTPQ_NI = @NTPQ_NI@
+NTPSNMPD_DB = @NTPSNMPD_DB@
+NTPSNMPD_DL = @NTPSNMPD_DL@
+NTPSNMPD_DS = @NTPSNMPD_DS@
+NTPSNMPD_MS = @NTPSNMPD_MS@
+NTPSNMPD_NI = @NTPSNMPD_NI@
+NTPSWEEP_DB = @NTPSWEEP_DB@
+NTPSWEEP_DL = @NTPSWEEP_DL@
+NTPSWEEP_DS = @NTPSWEEP_DS@
+NTPSWEEP_MS = @NTPSWEEP_MS@
+NTPSWEEP_NI = @NTPSWEEP_NI@
+NTPTIME_DB = @NTPTIME_DB@
+NTPTIME_DL = @NTPTIME_DL@
+NTPTIME_DS = @NTPTIME_DS@
+NTPTIME_MS = @NTPTIME_MS@
+NTPTIME_NI = @NTPTIME_NI@
+NTPTRACE_DB = @NTPTRACE_DB@
+NTPTRACE_DL = @NTPTRACE_DL@
+NTPTRACE_DS = @NTPTRACE_DS@
+NTPTRACE_MS = @NTPTRACE_MS@
+NTPTRACE_NI = @NTPTRACE_NI@
+NTP_KEYGEN_DB = @NTP_KEYGEN_DB@
+NTP_KEYGEN_DL = @NTP_KEYGEN_DL@
+NTP_KEYGEN_DS = @NTP_KEYGEN_DS@
+NTP_KEYGEN_MS = @NTP_KEYGEN_MS@
+NTP_KEYGEN_NI = @NTP_KEYGEN_NI@
+NTP_KEYSDIR = @NTP_KEYSDIR@
+NTP_WAIT_DB = @NTP_WAIT_DB@
+NTP_WAIT_DL = @NTP_WAIT_DL@
+NTP_WAIT_DS = @NTP_WAIT_DS@
+NTP_WAIT_MS = @NTP_WAIT_MS@
+NTP_WAIT_NI = @NTP_WAIT_NI@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
-OPENSSL = @OPENSSL@
-OPENSSL_INC = @OPENSSL_INC@
-OPENSSL_LIB = @OPENSSL_LIB@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
@@ -147,10 +254,12 @@ PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_NET_SNMP_CONFIG = @PATH_NET_SNMP_CONFIG@
PATH_PERL = @PATH_PERL@
PATH_SEPARATOR = @PATH_SEPARATOR@
-PATH_SH = @PATH_SH@
PATH_TEST = @PATH_TEST@
+PERLLIBDIR = @PERLLIBDIR@
+PKG_CONFIG = @PKG_CONFIG@
POSIX_SHELL = @POSIX_SHELL@
PROPDELAY = @PROPDELAY@
+PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
@@ -158,9 +267,27 @@ SHELL = @SHELL@
SNMP_CFLAGS = @SNMP_CFLAGS@
SNMP_CPPFLAGS = @SNMP_CPPFLAGS@
SNMP_LIBS = @SNMP_LIBS@
+SNTP = @SNTP@
+SNTP_DB = @SNTP_DB@
+SNTP_DL = @SNTP_DL@
+SNTP_DS = @SNTP_DS@
+SNTP_MS = @SNTP_MS@
+SNTP_NI = @SNTP_NI@
+STDNORETURN_H = @STDNORETURN_H@
STRIP = @STRIP@
TESTDCF = @TESTDCF@
+TICKADJ_DB = @TICKADJ_DB@
+TICKADJ_DL = @TICKADJ_DL@
+TICKADJ_DS = @TICKADJ_DS@
+TICKADJ_MS = @TICKADJ_MS@
+TICKADJ_NI = @TICKADJ_NI@
+TIMETRIM_DB = @TIMETRIM_DB@
+TIMETRIM_DL = @TIMETRIM_DL@
+TIMETRIM_DS = @TIMETRIM_DS@
+TIMETRIM_MS = @TIMETRIM_MS@
+TIMETRIM_NI = @TIMETRIM_NI@
VERSION = @VERSION@
+VER_SUFFIX = @VER_SUFFIX@
YACC = @YACC@
YFLAGS = @YFLAGS@
abs_builddir = @abs_builddir@
@@ -169,6 +296,7 @@ abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
@@ -217,8 +345,6 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
NULL =
-AUTOMAKE_OPTIONS =
-ETAGS_ARGS = $(srcdir)/Makefile.am
noinst_HEADERS = \
mem.h \
$(NULL)
diff --git a/include/isc/mem.h b/include/isc/mem.h
index f5cf9ec57fff5..ba1bfeb0e483e 100644
--- a/include/isc/mem.h
+++ b/include/isc/mem.h
@@ -60,9 +60,9 @@
#define isc_mem_strdup(c, str) \
( ISC_MEM_UNUSED_ARG(c), estrdup(str) )
-#define isc_mem_attach(src, ptgt) do { *(ptgt) = (src); } while (0)
-#define isc_mem_detach(c) ISC_MEM_UNUSED_ARG(c)
-#define isc_mem_printallactive(s) fprintf((s), \
+#define isc__mem_attach(src, ptgt) do { *(ptgt) = (src); } while (0)
+#define isc__mem_detach(c) ISC_MEM_UNUSED_ARG(c)
+#define isc__mem_printallactive(s) fprintf((s), \
"isc_mem_printallactive() stubbed.\n")
#endif /* ISC_MEM_H */
diff --git a/include/l_stdlib.h b/include/l_stdlib.h
index 0213d23c1c4f7..073ea46412368 100644
--- a/include/l_stdlib.h
+++ b/include/l_stdlib.h
@@ -3,12 +3,8 @@
* This is optional
*/
-#ifndef _l_stdlib_h
-#define _l_stdlib_h
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#ifndef L_STDLIB_H
+#define L_STDLIB_H
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
@@ -111,7 +107,7 @@ extern int rename (const char *, const char *);
#endif
#ifdef DECL_SELECT_0
-#ifdef _ntp_select_h
+#ifdef NTP_SELECT_H
extern int select (int, fd_set *, fd_set *, fd_set *, struct timeval *);
#endif
#endif
@@ -135,16 +131,6 @@ struct sigvec;
extern int sigvec (int, struct sigvec *, struct sigvec *);
#endif
-#ifndef HAVE_SNPRINTF
-/* PRINTFLIKE3 */
-extern int snprintf (char *, size_t, const char *, ...);
-#endif
-
-/* HMS: does this need further protection? */
-#ifndef HAVE_VSNPRINTF
-extern int vsnprintf (char *, size_t, const char *, va_list);
-#endif
-
#ifdef DECL_STDIO_0
#if defined(FILE) || defined(BUFSIZ)
extern int _flsbuf (int, FILE *);
@@ -235,4 +221,4 @@ extern int errno;
extern int h_errno;
#endif
-#endif /* l_stdlib_h */
+#endif /* L_STDLIB_H */
diff --git a/include/lib_strbuf.h b/include/lib_strbuf.h
index 5aa0eb0a6d72d..5ee92d6f83417 100644
--- a/include/lib_strbuf.h
+++ b/include/lib_strbuf.h
@@ -1,28 +1,32 @@
/*
* lib_strbuf.h - definitions for routines which use the common string buffers
*/
+#ifndef LIB_STRBUF_H
+#define LIB_STRBUF_H
#include <ntp_types.h>
+#include <ntp_malloc.h> /* for ZERO() */
/*
* Sizes of things
*/
-#define LIB_NUMBUFS 200
-#define LIB_BUFLENGTH 80
+#define LIB_NUMBUF 16
+#define LIB_BUFLENGTH 128
+
+typedef char libbufstr[LIB_BUFLENGTH];
+extern libbufstr lib_stringbuf[LIB_NUMBUF];
+extern int lib_nextbuf;
+extern int lib_inited;
+
/*
* Macro to get a pointer to the next buffer
*/
-#define LIB_GETBUF(buf) \
- do { \
- if (!lib_inited) \
- init_lib(); \
- buf = &lib_stringbuf[lib_nextbuf][0]; \
- if (++lib_nextbuf >= LIB_NUMBUFS) \
- lib_nextbuf = 0; \
- memset(buf, 0, LIB_BUFLENGTH); \
- } while (0)
+#define LIB_GETBUF(bufp) \
+ do { \
+ ZERO(lib_stringbuf[lib_nextbuf]); \
+ (bufp) = &lib_stringbuf[lib_nextbuf++][0]; \
+ lib_nextbuf %= COUNTOF(lib_stringbuf); \
+ } while (FALSE)
-extern char lib_stringbuf[LIB_NUMBUFS][LIB_BUFLENGTH];
-extern int lib_nextbuf;
-extern int lib_inited;
+#endif /* LIB_STRBUF_H */
diff --git a/include/libntp.h b/include/libntp.h
new file mode 100644
index 0000000000000..8d87c024f42ec
--- /dev/null
+++ b/include/libntp.h
@@ -0,0 +1,16 @@
+/* libntp.h */
+
+#if defined(HAVE_SYSCONF) && defined(_SC_OPEN_MAX)
+#define GETDTABLESIZE() ((int)sysconf(_SC_OPEN_MAX))
+#elif defined(HAVE_GETDTABLESIZE)
+#define GETDTABLESIZE getdtablesize
+#else
+/*
+ * if we have no idea about the max fd value set up things
+ * so we will start at FOPEN_MAX
+ */
+#define GETDTABLESIZE() (FOPEN_MAX + FD_CHUNK)
+#endif
+
+extern void make_socket_nonblocking( SOCKET fd );
+extern SOCKET move_fd( SOCKET fd );
diff --git a/include/mbg_gps166.h b/include/mbg_gps166.h
index f4b82381087ec..974debafae28c 100644
--- a/include/mbg_gps166.h
+++ b/include/mbg_gps166.h
@@ -197,7 +197,7 @@ typedef struct {
/* by the user. The status field can be checked to see which corrections */
/* have been applied. */
-#ifndef _TM_DEFINED
+#ifndef GPS166_TM_DEFINED
typedef struct {
short year; /* 0..9999 */
char month; /* 1..12 */
@@ -221,7 +221,7 @@ typedef struct {
# define TM_LS_ANN 0x10 /* leap second will be inserted */
# define TM_LS_ENB 0x20 /* current second is leap second */
-# define _TM_DEFINED
+# define GPS166_TM_DEFINED
#endif
diff --git a/include/ntp.h b/include/ntp.h
index d7e87582d708c..38343f23a705b 100644
--- a/include/ntp.h
+++ b/include/ntp.h
@@ -9,10 +9,9 @@
#include <ntp_fp.h>
#include <ntp_types.h>
+#include <ntp_lists.h>
#include <ntp_stdlib.h>
-#ifdef OPENSSL
#include <ntp_crypto.h>
-#endif /* OPENSSL */
#include <ntp_random.h>
#include <ntp_net.h>
@@ -90,12 +89,6 @@ typedef char s_char;
# undef SO_SNDBUF
# endif
#endif
-#ifndef TRUE
-# define TRUE 1
-#endif /* TRUE */
-#ifndef FALSE
-# define FALSE 0
-#endif /* FALSE */
/*
* NTP protocol parameters. See section 3.2.6 of the specification.
@@ -113,7 +106,7 @@ typedef char s_char;
#define NTP_MAXDPOLL 10 /* log2 default max poll (~17 m) */
#define NTP_MAXPOLL 17 /* log2 max poll interval (~36 h) */
#define NTP_RETRY 3 /* max packet retries */
-#define NTP_MINPKT 1 /* log2 min interburst interval (2 s) */
+#define NTP_MINPKT 2 /* guard time (s) */
/*
* Clock filter algorithm tuning parameters
@@ -127,7 +120,6 @@ typedef char s_char;
*/
#define NTP_MINCLOCK 3 /* min survivors */
#define NTP_MAXCLOCK 10 /* max candidates */
-#define NTP_MAXASSOC 50 /* max associations */
#define MINDISPERSE .001 /* min distance */
#define MAXDISTANCE 1.5 /* max root distance (select threshold) */
#define CLOCK_SGATE 3. /* popcorn spike gate */
@@ -136,6 +128,7 @@ typedef char s_char;
#define MAX_TTL 8 /* max ttl mapping vector size */
#define BEACON 7200 /* manycast beacon interval */
#define NTP_MAXEXTEN 2048 /* max extension field size */
+#define NTP_ORPHWAIT 300 /* orphan wair (s) */
/*
* Miscellaneous stuff
@@ -145,7 +138,7 @@ typedef char s_char;
/*
* Limits of things
*/
-#define MAXFILENAME 128 /* max length of file name */
+#define MAXFILENAME 256 /* max length of file name */
#define MAXHOSTNAME 512 /* max length of host/node name */
#define NTP_MAXSTRLEN 256 /* max string length */
@@ -163,10 +156,9 @@ typedef char s_char;
#define SQUARE(x) ((x) * (x))
#define SQRT(x) (sqrt(x))
#define DIFF(x, y) (SQUARE((x) - (y)))
-#define LOGTOD(a) ((a) < 0 ? 1. / (1L << -(a)) : \
- 1L << (int)(a)) /* log2 to double */
+#define LOGTOD(a) ldexp(1., (int)(a)) /* log2 to double */
#define UNIVAR(x) (SQUARE(.28867513 * LOGTOD(x))) /* std uniform distr */
-#define ULOGTOD(a) (1L << (int)(a)) /* ulog2 to double */
+#define ULOGTOD(a) ldexp(1., (int)(a)) /* ulog2 to double */
#define EVENT_TIMEOUT 0 /* one second, that is */
@@ -214,11 +206,12 @@ struct interface {
#define INT_LOOPBACK 0x004 /* the loopback interface */
#define INT_BROADCAST 0x008 /* can broadcast out this interface */
#define INT_MULTICAST 0x010 /* can multicast out this interface */
-#define INT_BCASTOPEN 0x020 /* broadcast socket is open */
+#define INT_BCASTOPEN 0x020 /* broadcast receive socket is open */
#define INT_MCASTOPEN 0x040 /* multicasting enabled */
#define INT_WILDCARD 0x080 /* wildcard interface - usually skipped */
#define INT_MCASTIF 0x100 /* bound directly to MCAST address */
#define INT_PRIVACY 0x200 /* RFC 4941 IPv6 privacy address */
+#define INT_BCASTXMIT 0x400 /* socket setup to allow broadcasts */
/*
* Define flasher bits (tests 1 through 11 in packet procedure)
@@ -254,10 +247,14 @@ struct interface {
* spec.
*/
struct peer {
- struct peer *next; /* link pointer in peer hash */
- struct peer *ass_next; /* link pointer in associd hash */
+ struct peer *p_link; /* link pointer in free & peer lists */
+ struct peer *adr_link; /* link pointer in address hash */
+ struct peer *aid_link; /* link pointer in associd hash */
struct peer *ilink; /* list of peers for interface */
sockaddr_u srcadr; /* address of remote host */
+ char * hostname; /* if non-NULL, remote name */
+ struct addrinfo *addrs; /* hostname query result */
+ struct addrinfo *ai; /* position within addrs */
endpt * dstadr; /* local address */
associd_t associd; /* association ID */
u_char version; /* version number */
@@ -269,7 +266,8 @@ struct peer {
u_char cast_flags; /* additional flags */
u_char last_event; /* last peer error code */
u_char num_events; /* number of error events */
- u_char ttl; /* ttl/refclock mode */
+ u_int32 ttl; /* ttl/refclock mode */
+ char *ident; /* group identifier name */
/*
* Variables used by reference clock support
@@ -298,7 +296,7 @@ struct peer {
* Variables used by authenticated client
*/
keyid_t keyid; /* current key ID */
-#ifdef OPENSSL
+#ifdef AUTOKEY
#define clear_to_zero opcode
u_int32 opcode; /* last request opcode */
associd_t assoc; /* peer association ID */
@@ -326,9 +324,9 @@ struct peer {
int keynumber; /* current key number */
struct value encrypt; /* send encrypt values */
struct value sndval; /* send autokey values */
-#else /* OPENSSL */
+#else /* !AUTOKEY follows */
#define clear_to_zero status
-#endif /* OPENSSL */
+#endif /* !AUTOKEY */
/*
* Ephemeral state variables
@@ -357,7 +355,7 @@ struct peer {
double jitter; /* peer jitter (squares) */
double disp; /* peer dispersion */
double xleave; /* interleave delay */
- double bias; /* bias for NIC asymmetry */
+ double bias; /* programmed offset bias */
/*
* Variables used to correct for packet length and asymmetry.
@@ -379,8 +377,6 @@ struct peer {
int throttle; /* rate control */
u_long outdate; /* send time last packet */
u_long nextdate; /* send time next packet */
- u_long nextaction; /* peer local activity timeout (refclocks) */
- void (*action) (struct peer *); /* action timeout function */
/*
* Statistic counters
@@ -413,7 +409,7 @@ struct peer {
* function. MODE_CONTROL and MODE_PRIVATE can appear in packets,
* but those never survive to the transition function.
* is a
- */
+/ */
#define MODE_UNSPEC 0 /* unspecified (old version) */
#define MODE_ACTIVE 1 /* symmetric active mode */
#define MODE_PASSIVE 2 /* symmetric passive mode */
@@ -467,19 +463,13 @@ struct peer {
*/
#define CLEAR_TO_ZERO(p) ((char *)&((p)->clear_to_zero))
#define END_CLEAR_TO_ZERO(p) ((char *)&((p)->end_clear_to_zero))
-#define LEN_CLEAR_TO_ZERO (END_CLEAR_TO_ZERO((struct peer *)0) \
- - CLEAR_TO_ZERO((struct peer *)0))
+#define LEN_CLEAR_TO_ZERO(p) (END_CLEAR_TO_ZERO(p) - CLEAR_TO_ZERO(p))
#define CRYPTO_TO_ZERO(p) ((char *)&((p)->clear_to_zero))
#define END_CRYPTO_TO_ZERO(p) ((char *)&((p)->end_clear_to_zero))
#define LEN_CRYPTO_TO_ZERO (END_CRYPTO_TO_ZERO((struct peer *)0) \
- CRYPTO_TO_ZERO((struct peer *)0))
/*
- * Reference clock identifiers (for pps signal)
- */
-#define PPSREFID (u_int32)"PPS " /* used when pps controls stratum>1 */
-
-/*
* Reference clock types. Added as necessary.
*/
#define REFCLK_NONE 0 /* unknown or missing */
@@ -526,7 +516,9 @@ struct peer {
#define REFCLK_ZYFER 42 /* Zyfer GPStarplus receiver */
#define REFCLK_RIPENCC 43 /* RIPE NCC Trimble driver */
#define REFCLK_NEOCLOCK4X 44 /* NeoClock4X DCF77 or TDF receiver */
-#define REFCLK_MAX 44 /* NeoClock4X DCF77 or TDF receiver */
+#define REFCLK_TSYNCPCI 45 /* Spectracom TSYNC PCI timing board */
+#define REFCLK_GPSDJSON 46
+#define REFCLK_MAX 46
/*
@@ -564,13 +556,19 @@ struct pkt {
* response, so the maximum total extension field length is 864
* octets. But, to handle humungus certificates, the bank must
* be broke.
+ *
+ * The different definitions of the 'exten' field are here for
+ * the benefit of applications that want to send a packet from
+ * an auto variable in the stack - not using the AUTOKEY version
+ * saves 2KB of stack space. The receive buffer should ALWAYS be
+ * big enough to hold a full extended packet if the extension
+ * fields have to be parsed or skipped.
*/
-#ifdef OPENSSL
- u_int32 exten[NTP_MAXEXTEN / 4]; /* max extension field */
-#else /* OPENSSL */
- u_int32 exten[1]; /* misused */
-#endif /* OPENSSL */
- u_char mac[MAX_MAC_LEN]; /* mac */
+#ifdef AUTOKEY
+ u_int32 exten[(NTP_MAXEXTEN + MAX_MAC_LEN) / sizeof(u_int32)];
+#else /* !AUTOKEY follows */
+ u_int32 exten[(MAX_MAC_LEN) / sizeof(u_int32)];
+#endif /* !AUTOKEY */
};
/*
@@ -581,10 +579,11 @@ struct pkt {
#define PKT_LEAP(li_vn_mode) ((u_char)(((li_vn_mode) >> 6) & 0x3))
/*
- * Stuff for putting things back into li_vn_mode
+ * Stuff for putting things back into li_vn_mode in packets and vn_mode
+ * in ntp_monitor.c's mon_entry.
*/
-#define PKT_LI_VN_MODE(li, vn, md) \
- ((u_char)((((li) << 6) & 0xc0) | (((vn) << 3) & 0x38) | ((md) & 0x7)))
+#define VN_MODE(v, m) ((((v) & 7) << 3) | ((m) & 0x7))
+#define PKT_LI_VN_MODE(l, v, m) ((((l) & 3) << 6) | VN_MODE((v), (m)))
/*
@@ -622,7 +621,6 @@ struct pkt {
#define EVNT_KERN 13 /* kernel event */
#define EVNT_TAI 14 /* TAI */
#define EVNT_LEAPVAL 15 /* stale leapsecond values */
-#define EVNT_CLKHOP 16 /* clockhop */
/*
* Peer event codes
@@ -642,7 +640,6 @@ struct pkt {
#define PEVNT_POPCORN (13 | PEER_EVENT) /* popcorn */
#define PEVNT_XLEAVE (14 | PEER_EVENT) /* interleave mode */
#define PEVNT_XERR (15 | PEER_EVENT) /* interleave error */
-#define PEVNT_TAI (16 | PEER_EVENT) /* TAI */
/*
* Clock event codes
@@ -666,9 +663,9 @@ struct pkt {
* To speed lookups, peers are hashed by the low order bits of the
* remote IP address. These definitions relate to that.
*/
-#define NTP_HASH_SIZE 128
-#define NTP_HASH_MASK (NTP_HASH_SIZE-1)
-#define NTP_HASH_ADDR(src) sock_hash(src)
+#define NTP_HASH_SIZE 128
+#define NTP_HASH_MASK (NTP_HASH_SIZE-1)
+#define NTP_HASH_ADDR(src) (sock_hash(src) & NTP_HASH_MASK)
/*
* min, min3 and max. Makes it easier to transliterate the spec without
@@ -704,16 +701,18 @@ struct pkt {
#define PROTO_CALLDELAY 20
#define PROTO_MINDISP 21
#define PROTO_MAXDIST 22
-#define PROTO_ADJ 23
+ /* available 23 */
#define PROTO_MAXHOP 24
#define PROTO_BEACON 25
#define PROTO_ORPHAN 26
+#define PROTO_ORPHWAIT 27
+#define PROTO_MODE7 28
/*
* Configuration items for the loop filter
*/
-#define LOOP_DRIFTINIT 1 /* set initial frequency offset */
-#define LOOP_DRIFTCOMP 2 /* set frequency offset */
+#define LOOP_DRIFTINIT 1 /* iniitialize frequency */
+#define LOOP_KERN_CLEAR 2 /* set initial frequency offset */
#define LOOP_MAX 3 /* set step offset */
#define LOOP_PANIC 4 /* set panic offseet */
#define LOOP_PHI 5 /* set dispersion rate */
@@ -722,9 +721,9 @@ struct pkt {
#define LOOP_ALLAN 8 /* set minimum Allan intercept */
#define LOOP_HUFFPUFF 9 /* set huff-n'-puff filter length */
#define LOOP_FREQ 10 /* set initial frequency */
-#define LOOP_KERN_CLEAR 11 /* reset kernel pll parameters */
-#define LOOP_CODEC 12 /* set audio codec frequency */
-#define LOOP_LEAP 13 /* insert leap after second 23:59 */
+#define LOOP_CODEC 11 /* set audio codec frequency */
+#define LOOP_LEAP 12 /* insert leap after second 23:59 */
+#define LOOP_TICK 13 /* sim. low precision clock */
/*
* Configuration items for the stats printer
@@ -744,40 +743,51 @@ struct pkt {
/*
* Structure used optionally for monitoring when this is turned on.
*/
+typedef struct mon_data mon_entry;
struct mon_data {
- struct mon_data *hash_next; /* next structure in hash list */
- struct mon_data *mru_next; /* next structure in MRU list */
- struct mon_data *mru_prev; /* previous structure in MRU list */
- int flags; /* restrict flags */
- int leak; /* leaky bucket accumulator */
- int count; /* total packet count */
- u_long firsttime; /* first time found */
- u_long lasttime; /* last time found */
- sockaddr_u rmtadr; /* address of remote host */
- struct interface *interface; /* interface on which this arrived */
- u_short rmtport; /* remote port last came from */
- u_char mode; /* packet mode */
- u_char version; /* packet version */
- u_char cast_flags; /* flags MDF_?CAST */
+ mon_entry * hash_next; /* next structure in hash list */
+ DECL_DLIST_LINK(mon_entry, mru);/* MRU list link pointers */
+ struct interface * lcladr; /* address on which this arrived */
+ l_fp first; /* first time seen */
+ l_fp last; /* last time seen */
+ int leak; /* leaky bucket accumulator */
+ int count; /* total packet count */
+ u_short flags; /* restrict flags */
+ u_char vn_mode; /* packet mode & version */
+ u_char cast_flags; /* flags MDF_?CAST */
+ sockaddr_u rmtadr; /* address of remote host */
};
/*
- * Values for cast_flags
+ * Values for cast_flags in mon_entry and struct peer. mon_entry uses
+ * only the first three, MDF_UCAST, MDF_MCAST, and MDF_BCAST.
*/
-#define MDF_UCAST 0x01 /* unicast */
-#define MDF_MCAST 0x02 /* multicast */
-#define MDF_BCAST 0x04 /* broadcast */
-#define MDF_LCAST 0x08 /* localcast */
-#define MDF_ACAST 0x10 /* manycast */
-#define MDF_BCLNT 0x20 /* broadcast client */
-#define MDF_ACLNT 0x40 /* manycast client */
-
+#define MDF_UCAST 0x01 /* unicast client */
+#define MDF_MCAST 0x02 /* multicast server */
+#define MDF_BCAST 0x04 /* broadcast server */
+#define MDF_POOL 0x08 /* pool client solicitor */
+#define MDF_ACAST 0x10 /* manycast client solicitor */
+#define MDF_BCLNT 0x20 /* eph. broadcast/multicast client */
+#define MDF_UCLNT 0x40 /* preemptible manycast or pool client */
+/*
+ * In the context of struct peer in ntpd, three of the cast_flags bits
+ * represent configured associations which never receive packets, and
+ * whose reach is always 0: MDF_BCAST, MDF_MCAST, and MDF_ACAST. The
+ * last can be argued as responses are received, but those responses do
+ * not affect the MDF_ACAST association's reach register, rather they
+ * (may) result in mobilizing ephemeral MDF_ACLNT associations.
+ */
+#define MDF_TXONLY_MASK (MDF_BCAST | MDF_MCAST | MDF_ACAST | MDF_POOL)
+/*
+ * manycastclient-like solicitor association cast_flags bits
+ */
+#define MDF_SOLICIT_MASK (MDF_ACAST | MDF_POOL)
/*
* Values used with mon_enabled to indicate reason for enabling monitoring
*/
-#define MON_OFF 0x00 /* no monitoring */
-#define MON_ON 0x01 /* monitoring explicitly enabled */
-#define MON_RES 0x02 /* implicit monitoring for RES_LIMITED */
+#define MON_OFF 0x00 /* no monitoring */
+#define MON_ON 0x01 /* monitoring explicitly enabled */
+#define MON_RES 0x02 /* implicit monitoring for RES_LIMITED */
/*
* Structure used for restrictlist entries
*/
@@ -797,6 +807,7 @@ struct restrict_u_tag {
u_int32 count; /* number of packets matched */
u_short flags; /* accesslist flags */
u_short mflags; /* match flags */
+ u_long expire; /* valid until time */
union { /* variant starting here */
res_addr4 v4;
res_addr6 v6;
@@ -807,7 +818,6 @@ struct restrict_u_tag {
#define V6_SIZEOF_RESTRICT_U (offsetof(restrict_u, u) \
+ sizeof(res_addr6))
-
/*
* Access flags
*/
@@ -826,20 +836,23 @@ struct restrict_u_tag {
#define RES_NOTRAP 0x0100 /* mode 6/7 set trap denied */
#define RES_LPTRAP 0x0200 /* mode 6/7 low priority trap */
-#define RES_KOD 0x0400 /* send kiss of death packet */
+#define RES_KOD 0x0400 /* send kiss of death packet */
#define RES_MSSNTP 0x0800 /* enable MS-SNTP authentication */
-#define RES_TIMEOUT 0x1000 /* timeout this entry */
+#define RES_FLAKE 0x1000 /* flakeway - drop 10% */
+#define RES_NOMRULIST 0x2000 /* mode 6 mrulist denied */
-#define RES_ALLFLAGS (RES_FLAGS | RES_NOQUERY |\
- RES_NOMODIFY | RES_NOTRAP |\
- RES_LPTRAP | RES_KOD |\
- RES_MSSNTP | RES_TIMEOUT)
+#define RES_ALLFLAGS (RES_FLAGS | RES_NOQUERY | \
+ RES_NOMODIFY | RES_NOTRAP | \
+ RES_LPTRAP | RES_KOD | \
+ RES_MSSNTP | RES_FLAKE | \
+ RES_NOMRULIST)
/*
* Match flags
*/
#define RESM_INTERFACE 0x1000 /* this is an interface */
-#define RESM_NTPONLY 0x2000 /* match ntp port only */
+#define RESM_NTPONLY 0x2000 /* match source port 123 */
+#define RESM_SOURCE 0x4000 /* from "restrict source" */
/*
* Restriction configuration ops
@@ -847,7 +860,7 @@ struct restrict_u_tag {
#define RESTRICT_FLAGS 1 /* add flags to restrict entry */
#define RESTRICT_UNFLAG 2 /* remove flags from restrict entry */
#define RESTRICT_REMOVE 3 /* remove a restrict entry */
-#define RESTRICT_REMOVEIF 4 /* remove an interface restrict entry */
+#define RESTRICT_REMOVEIF 4 /* remove an interface restrict entry */
/*
* Endpoint structure for the select algorithm
@@ -865,7 +878,7 @@ struct endpoint {
#define AM_PROCPKT 1 /* server/symmetric packet */
#define AM_BCST 2 /* broadcast packet */
#define AM_FXMIT 3 /* client packet */
-#define AM_MANYCAST 4 /* manycast packet */
+#define AM_MANYCAST 4 /* manycast or pool */
#define AM_NEWPASS 5 /* new passive */
#define AM_NEWBCL 6 /* new broadcast */
#define AM_POSSBCL 7 /* discard broadcast */
@@ -875,4 +888,8 @@ struct endpoint {
#define NETINFO_CONFIG_DIR "/config/ntp"
#endif
+/* ntpq -c mrulist rows per request limit in ntpd */
+#define MRU_ROW_LIMIT 256
+/* similar datagrams per response limit for ntpd */
+#define MRU_FRAGS_LIMIT 128
#endif /* NTP_H */
diff --git a/include/ntp_assert.h b/include/ntp_assert.h
index ab9b41981be68..2f3bbc8a0b9b5 100644
--- a/include/ntp_assert.h
+++ b/include/ntp_assert.h
@@ -28,6 +28,7 @@
#define NTP_ASSERT_H
# ifdef CALYSTO
+/* see: http://www.domagoj-babic.com/index.php/ResearchProjects/Calysto */
extern void calysto_assume(unsigned char cnd); /* assume this always holds */
extern void calysto_assert(unsigned char cnd); /* check whether this holds */
@@ -57,7 +58,17 @@ extern void calysto_assert(unsigned char cnd); /* check whether this holds */
#define ALWAYS_ENSURE(x) assert(x)
*/
-# else /* neither Coverity nor Calysto */
+
+#elif defined(__FLEXELINT__)
+
+#include <assert.h>
+
+#define ALWAYS_REQUIRE(x) assert(x)
+#define ALWAYS_INSIST(x) assert(x)
+#define ALWAYS_INVARIANT(x) assert(x)
+#define ALWAYS_ENSURE(x) assert(x)
+
+# else /* neither Calysto, Coverity or FlexeLint */
#include "isc/assertions.h"
@@ -88,10 +99,10 @@ extern void calysto_assert(unsigned char cnd); /* check whether this holds */
#define DEBUG_INVARIANT(x) INVARIANT(x)
#define DEBUG_ENSURE(x) ENSURE(x)
# else
-#define DEBUG_REQUIRE(x) (void)(x)
-#define DEBUG_INSIST(x) (void)(x)
-#define DEBUG_INVARIANT(x) (void)(x)
-#define DEBUG_ENSURE(x) (void)(x)
+#define DEBUG_REQUIRE(x) do {} while (FALSE)
+#define DEBUG_INSIST(x) do {} while (FALSE)
+#define DEBUG_INVARIANT(x) do {} while (FALSE)
+#define DEBUG_ENSURE(x) do {} while (FALSE)
# endif
#endif /* NTP_ASSERT_H */
diff --git a/include/ntp_calendar.h b/include/ntp_calendar.h
index fbdb27c7ab4f7..3ee1ff79c8060 100644
--- a/include/ntp_calendar.h
+++ b/include/ntp_calendar.h
@@ -4,20 +4,62 @@
#ifndef NTP_CALENDAR_H
#define NTP_CALENDAR_H
+#include <time.h>
+
#include "ntp_types.h"
+/* gregorian calendar date */
struct calendar {
- u_short year; /* year (A.D.) */
- u_short yearday; /* day of year, 1 = January 1 */
- u_char month; /* month, 1 = January */
- u_char monthday; /* day of month */
- u_char hour; /* hour of day, midnight = 0 */
- u_char minute; /* minute of hour */
- u_char second; /* second of minute */
+ uint16_t year; /* year (A.D.) */
+ uint16_t yearday; /* day of year, 1 = January 1 */
+ uint8_t month; /* month, 1 = January */
+ uint8_t monthday; /* day of month */
+ uint8_t hour; /* hour of day, midnight = 0 */
+ uint8_t minute; /* minute of hour */
+ uint8_t second; /* second of minute */
+ uint8_t weekday; /* 0..7, 0=Sunday */
+};
+
+/* ISO week calendar date */
+struct isodate {
+ uint16_t year; /* year (A.D.) */
+ uint8_t week; /* 1..53, week in year */
+ uint8_t weekday; /* 1..7, 1=Monday */
+ uint8_t hour; /* hour of day, midnight = 0 */
+ uint8_t minute; /* minute of hour */
+ uint8_t second; /* second of minute */
};
+/* general split representation */
+typedef struct {
+ int32_t hi;
+ int32_t lo;
+} ntpcal_split;
+
+typedef time_t (*systime_func_ptr)(time_t *);
+
+/*
+ * set the function for getting the system time. This is mostly used for
+ * unit testing to provide a fixed / shifted time stamp. Setting the
+ * value to NULL restores the original function, that is, 'time()',
+ * which is also the automatic default.
+ */
+extern systime_func_ptr ntpcal_set_timefunc(systime_func_ptr);
+
/*
- * Days in each month. 30 days hath September...
+ * days-of-week
+ */
+#define CAL_SUNDAY 0
+#define CAL_MONDAY 1
+#define CAL_TUESDAY 2
+#define CAL_WEDNESDAY 3
+#define CAL_THURSDAY 4
+#define CAL_FRIDAY 5
+#define CAL_SATURDAY 6
+#define CAL_SUNDAY7 7 /* also sunday */
+
+/*
+ * Days in each month. 30 days hath September...
*/
#define JAN 31
#define FEB 28
@@ -34,7 +76,7 @@ struct calendar {
#define DEC 31
/*
- * We deal in a 4 year cycle starting at March 1, 1900. We assume
+ * We deal in a 4 year cycle starting at March 1, 1900. We assume
* we will only want to deal with dates since then, and not to exceed
* the rollover day in 2036.
*/
@@ -43,17 +85,14 @@ struct calendar {
#define HRSPERDAY (24) /* hours per day */
#define DAYSPERYEAR (365) /* days per year */
-#define SECSPERDAY (SECSPERMIN*MINSPERHR*HRSPERDAY)
+#define SECSPERHR (SECSPERMIN * MINSPERHR)
+#define SECSPERDAY (SECSPERHR * HRSPERDAY)
#define SECSPERYEAR (365 * SECSPERDAY) /* regular year */
#define SECSPERLEAPYEAR (366 * SECSPERDAY) /* leap year */
-
-#define MAR1900 ((JAN+FEB) * SECSPERDAY) /* no leap year in 1900 */
-#define DAYSPERCYCLE (365+365+365+366) /* 3 normal years plus leap */
-#define SECSPERCYCLE (DAYSPERCYCLE*SECSPERDAY)
-#define YEARSPERCYCLE 4
+#define SECSPERAVGYEAR 31556952 /* mean year length over 400yrs */
/*
- * Gross hacks. I have illicit knowlege that there won't be overflows
+ * Gross hacks. I have illicit knowlege that there won't be overflows
* here, the compiler often can't tell this.
*/
#define TIMES60(val) ((((val)<<4) - (val))<<2) /* *(16 - 1) * 4 */
@@ -63,23 +102,270 @@ struct calendar {
+ ((val)<<7) + ((val)<<5) \
+ ((val)<<4) + ((val)<<2) + (val)) /* *big* hack */
+
+extern const char * const months[12];
+extern const char * const daynames[7];
+
+extern void caljulian (uint32_t, struct calendar *);
+extern uint32_t caltontp (const struct calendar *);
+
/*
- * Another big hack. Cycle 22 started on March 1, 1988. This is
- * STARTCYCLE22 seconds after the start of cycle 0.
+ * Convert between 'time_t' and 'vint64'
*/
-#define CYCLE22 (22)
-#define STARTCYCLE22 (u_long)(0xa586b500) /* 2777068800 */
-#define MAR1988 (u_long)(STARTCYCLE22 + (u_long)MAR1900)
+extern vint64 time_to_vint64(const time_t *);
+extern time_t vint64_to_time(const vint64 *);
/*
- * The length of January + February in leap and non-leap years.
+ * Get the build date & time. ATTENTION: The time zone is not specified!
+ * This depends entirely on the C compilers' capabilities to properly
+ * expand the '__TIME__' and '__DATE__' macros, as required by the C
+ * standard.
*/
-#define JANFEBNOLEAP ((JAN+FEB) * SECSPERDAY)
-#define JANFEBLEAP ((JAN+FEBLEAP) * SECSPERDAY)
+extern int
+ntpcal_get_build_date(struct calendar * /* jd */);
+/*
+ * Convert a timestamp in NTP scale to a time_t value in the UN*X
+ * scale with proper epoch unfolding around a given pivot or the
+ * current system time.
+ */
+extern vint64
+ntpcal_ntp_to_time(uint32_t /* ntp */, const time_t * /* pivot */);
+
+/*
+ * Convert a timestamp in NTP scale to a 64bit seconds value in the NTP
+ * scale with proper epoch unfolding around a given pivot or the current
+ * system time.
+ * Note: The pivot must be given in UN*X time scale!
+ */
+extern vint64
+ntpcal_ntp_to_ntp(uint32_t /* ntp */, const time_t * /* pivot */);
+
+/*
+ * Split a time stamp in seconds into elapsed days and elapsed seconds
+ * since midnight.
+ */
+extern ntpcal_split
+ntpcal_daysplit(const vint64 *);
-extern void caljulian (u_long, struct calendar *);
-extern u_long caltontp (const struct calendar *);
+/*
+ * 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 */);
+
+/*
+ * Convert elapsed years in Era into elapsed days in Era.
+ */
+extern int32_t
+ntpcal_days_in_years(int32_t /* years */);
+
+/*
+ * Convert a number of elapsed month in a year into elapsed days
+ * in year.
+ *
+ * The month will be normalized, and 'res.hi' will contain the
+ * excessive years that must be considered when converting the years,
+ * while 'res.lo' will contain the days since start of the
+ * year. (Expect the resulting days to be negative, with a positive
+ * excess! But then, we need no leap year flag, either...)
+ */
+extern ntpcal_split
+ntpcal_days_in_months(int32_t /* months */);
+
+/*
+ * Convert ELAPSED years/months/days of gregorian calendar to elapsed
+ * days in Gregorian epoch. No range checks done here!
+ */
+extern int32_t
+ntpcal_edate_to_eradays(int32_t /* years */, int32_t /* months */, int32_t /* mdays */);
+
+/*
+ * Convert a time spec to seconds. No range checks done here!
+ */
+extern int32_t
+ntpcal_etime_to_seconds(int32_t /* hours */, int32_t /* minutes */, int32_t /* seconds */);
+
+/*
+ * Convert ELAPSED years/months/days of gregorian calendar to elapsed
+ * days in year.
+ *
+ * Note: This will give the true difference to the start of the given year,
+ * even if months & days are off-scale.
+ */
+extern int32_t
+ntpcal_edate_to_yeardays(int32_t /* years */, int32_t /* months */, int32_t /* mdays */);
+
+/*
+ * Convert the date part of a 'struct tm' (that is, year, month,
+ * day-of-month) into the RataDie of that day.
+ */
+extern int32_t
+ntpcal_tm_to_rd(const struct tm * /* utm */);
+
+/*
+ * Convert the date part of a 'struct calendar' (that is, year, month,
+ * day-of-month) into the RataDie of that day.
+ */
+extern int32_t
+ntpcal_date_to_rd(const struct calendar * /* jt */);
+
+/*
+ * Given the number of elapsed days in the calendar era, split this
+ * number into the number of elapsed years in 'res.quot' and the
+ * number of elapsed days of that year in 'res.rem'.
+ *
+ * if 'isleapyear' is not NULL, it will receive an integer that is 0
+ * for regular years and a non-zero value for leap years.
+ */
+extern ntpcal_split
+ntpcal_split_eradays(int32_t /* days */, int/*BOOL*/ * /* isleapyear */);
+
+/*
+ * Given a number of elapsed days in a year and a leap year indicator,
+ * split the number of elapsed days into the number of elapsed months
+ * in 'res.quot' and the number of elapsed days of that month in
+ * 'res.rem'.
+ */
+extern ntpcal_split
+ntpcal_split_yeardays(int32_t /* eyd */, int/*BOOL*/ /* isleapyear */);
+
+/*
+ * Convert a RataDie number into the date part of a 'struct
+ * calendar'. Return 0 if the year is regular year, !0 if the year is
+ * a leap year.
+ */
+extern int/*BOOL*/
+ntpcal_rd_to_date(struct calendar * /* jt */, int32_t /* rd */);
+
+/*
+ * Convert a RataDie number into the date part of a 'struct
+ * tm'. Return 0 if the year is regular year, !0 if the year is a leap
+ * year.
+ */
+extern int/*BOOL*/
+ntpcal_rd_to_tm(struct tm * /* utm */, int32_t /* rd */);
+
+/*
+ * Take a value of seconds since midnight and split it into hhmmss in
+ * a 'struct calendar'. Return excessive days.
+ */
+extern int32_t
+ntpcal_daysec_to_date(struct calendar * /* jt */, int32_t /* secs */);
+
+/*
+ * Take the time part of a 'struct calendar' and return the seconds
+ * since midnight.
+ */
+extern int32_t
+ntpcal_date_to_daysec(const struct calendar *);
+
+/*
+ * Take a value of seconds since midnight and split it into hhmmss in
+ * a 'struct tm'. Return excessive days.
+ */
+extern int32_t
+ntpcal_daysec_to_tm(struct tm * /* utm */, int32_t /* secs */);
+
+extern int32_t
+ntpcal_tm_to_daysec(const struct tm * /* utm */);
+
+/*
+ * convert a year number to rata die of year start
+ */
+extern int32_t
+ntpcal_year_to_ystart(int32_t /* year */);
+
+/*
+ * For a given RataDie, get the RataDie of the associated year start,
+ * that is, the RataDie of the last January,1st on or before that day.
+ */
+extern int32_t
+ntpcal_rd_to_ystart(int32_t /* rd */);
+
+/*
+ * convert a RataDie to the RataDie of start of the calendar month.
+ */
+extern int32_t
+ntpcal_rd_to_mstart(int32_t /* year */);
+
+
+extern int
+ntpcal_daysplit_to_date(struct calendar * /* jt */,
+ const ntpcal_split * /* ds */, int32_t /* dof */);
+
+extern int
+ntpcal_daysplit_to_tm(struct tm * /* utm */, const ntpcal_split * /* ds */,
+ int32_t /* dof */);
+
+extern int
+ntpcal_time_to_date(struct calendar * /* jd */, const vint64 * /* ts */);
+
+extern int32_t
+ntpcal_periodic_extend(int32_t /* pivot */, int32_t /* value */,
+ int32_t /* cycle */);
+
+extern int
+ntpcal_ntp64_to_date(struct calendar * /* jd */, const vint64 * /* ntp */);
+
+extern int
+ntpcal_ntp_to_date(struct calendar * /* jd */, uint32_t /* ntp */,
+ const time_t * /* pivot */);
+
+extern vint64
+ntpcal_date_to_ntp64(const struct calendar * /* jd */);
+
+extern uint32_t
+ntpcal_date_to_ntp(const struct calendar * /* jd */);
+
+extern time_t
+ntpcal_date_to_time(const struct calendar * /* jd */);
+
+/*
+ * ISO week-calendar conversions
+ */
+extern int32_t
+isocal_weeks_in_years(int32_t /* years */);
+
+extern ntpcal_split
+isocal_split_eraweeks(int32_t /* weeks */);
+
+extern int
+isocal_ntp64_to_date(struct isodate * /* id */, const vint64 * /* ntp */);
+
+extern int
+isocal_ntp_to_date(struct isodate * /* id */, uint32_t /* ntp */,
+ const time_t * /* pivot */);
+
+extern vint64
+isocal_date_to_ntp64(const struct isodate * /* id */);
+
+extern uint32_t
+isocal_date_to_ntp(const struct isodate * /* id */);
+
+
+/*
+ * day-of-week calculations
+ *
+ * Given a RataDie and a day-of-week, calculate a RDN that is reater-than,
+ * greater-or equal, closest, less-or-equal or less-than the given RDN
+ * and denotes the given day-of-week
+ */
+extern int32_t
+ntpcal_weekday_gt(int32_t /* rdn */, int32_t /* dow */);
+
+extern int32_t
+ntpcal_weekday_ge(int32_t /* rdn */, int32_t /* dow */);
+
+extern int32_t
+ntpcal_weekday_close(int32_t /* rdn */, int32_t /* dow */);
+
+extern int32_t
+ntpcal_weekday_le(int32_t /* rdn */, int32_t /* dow */);
+
+extern int32_t
+ntpcal_weekday_lt(int32_t /* rdn */, int32_t /* dow */);
/*
* Additional support stuff for Ed Rheingold's calendrical calculations
@@ -90,22 +376,40 @@ extern u_long caltontp (const struct calendar *);
* (This is the beginning of the Christian Era, or BCE.)
*/
#define DAY_NTP_STARTS 693596
+
+/*
+ * Start day of the UNIX epoch. This is the Rata Die of 1970-01-01.
+ */
+#define DAY_UNIX_STARTS 719163
+
+/*
+ * Difference between UN*X and NTP epoch (25567).
+ */
+#define NTP_TO_UNIX_DAYS (DAY_UNIX_STARTS - DAY_NTP_STARTS)
+
+/*
+ * Days in a normal 4 year leap year calendar cycle (1461).
+ */
+#define GREGORIAN_NORMAL_LEAP_CYCLE_DAYS (3 * 365 + 366)
+
/*
- * The Gregorian calendar is based on a 400 year cycle. This is the number
- * of days in each cycle.
+ * Days in a normal 100 year leap year calendar (36524). We lose a
+ * leap day in years evenly divisible by 100 but not by 400.
*/
-#define GREGORIAN_CYCLE_DAYS 146097
+#define GREGORIAN_NORMAL_CENTURY_DAYS \
+ (25 * GREGORIAN_NORMAL_LEAP_CYCLE_DAYS - 1)
/*
- * Days in a normal 100 year leap year calendar. We lose a leap year day
- * in years evenly divisible by 100 but not by 400.
+ * The Gregorian calendar is based on a 400 year cycle. This is the
+ * number of days in each cycle (146097). We gain a leap day in years
+ * divisible by 400 relative to the "normal" century.
*/
-#define GREGORIAN_NORMAL_CENTURY_DAYS 36524
+#define GREGORIAN_CYCLE_DAYS (4 * GREGORIAN_NORMAL_CENTURY_DAYS + 1)
/*
- * Days in a normal 4 year leap year calendar cycle.
+ * Number of weeks in 400 years (20871).
*/
-#define GREGORIAN_NORMAL_LEAP_CYCLE_DAYS 1461
+#define GREGORIAN_CYCLE_WEEKS (GREGORIAN_CYCLE_DAYS / 7)
#define is_leapyear(y) (!((y) % 4) && !(!((y) % 100) && (y) % 400))
diff --git a/include/ntp_cmdargs.h b/include/ntp_cmdargs.h
index ee41b4a56c33c..de45d8d5e5fa6 100644
--- a/include/ntp_cmdargs.h
+++ b/include/ntp_cmdargs.h
@@ -1,4 +1 @@
-#include "ntp_types.h"
-
-extern void getstartup (int, char **);
-extern void getCmdOpts (int, char **);
+extern void getCmdOpts(int, char **);
diff --git a/include/ntp_config.h b/include/ntp_config.h
index 037ed0733c3ea..900688cef4eed 100644
--- a/include/ntp_config.h
+++ b/include/ntp_config.h
@@ -1,8 +1,11 @@
#ifndef NTP_CONFIG_H
#define NTP_CONFIG_H
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif /* HAVE_SYS_RESOURCE_H */
+
#include "ntp_machine.h"
-#include "ntp_data_structures.h"
#include "ntpsim.h"
@@ -19,28 +22,6 @@
# endif /* SYS_WINNT */
#endif /* not CONFIG_FILE */
-#ifdef HAVE_IPTOS_SUPPORT
-/*
- * "qos" modified keywords
- */
-#define CONF_QOS_LOWDELAY 1
-#define CONF_QOS_THROUGHPUT 2
-#define CONF_QOS_RELIABILITY 3
-#define CONF_QOS_MINCOST 4
-
-#ifdef IPTOS_PREC_INTERNETCONTROL
-#define CONF_QOS_CS0 5
-#define CONF_QOS_CS1 6
-#define CONF_QOS_CS2 7
-#define CONF_QOS_CS3 8
-#define CONF_QOS_CS4 9
-#define CONF_QOS_CS5 10
-#define CONF_QOS_CS6 11
-#define CONF_QOS_CS7 12
-#endif /* IPTOS_PREC_INTERNETCONTROL */
-
-#endif /* HAVE_IPTOS_SUPPORT */
-
/*
* We keep config trees around for possible saveconfig use. When
@@ -61,132 +42,203 @@
#define CONF_SOURCE_FILE 0
#define CONF_SOURCE_NTPQ 1
+/* list of servers from command line for config_peers() */
+extern int cmdline_server_count;
+extern char ** cmdline_servers;
+
+/* set to zero if admin doesn't want memory locked */
+extern int do_memlock;
+
+typedef struct int_range_tag {
+ int first;
+ int last;
+} int_range;
/* Structure for storing an attribute-value pair */
-struct attr_val {
- int attr;
- union val {
- double d;
- int i;
- u_int u;
- char * s;
- void * p;
- } value;
- int type;
+typedef struct attr_val_tag attr_val;
+struct attr_val_tag {
+ attr_val * link;
+ int attr;
+ int type; /* T_String, T_Integer, ... */
+ union val {
+ int i;
+ u_int u;
+ int_range r;
+ double d;
+ char * s;
+ } value;
};
+typedef DECL_FIFO_ANCHOR(attr_val) attr_val_fifo;
+
/* Structure for nodes on the syntax tree */
-struct address_node {
- char *address;
- int type;
+typedef struct address_node_tag address_node;
+struct address_node_tag {
+ address_node * link;
+ char * address;
+ u_short type; /* family, AF_UNSPEC (0), AF_INET[6] */
};
-struct restrict_node {
- struct address_node *addr;
- struct address_node *mask;
- queue *flags;
- int line_no;
+typedef DECL_FIFO_ANCHOR(address_node) address_fifo;
+
+typedef struct int_node_tag int_node;
+struct int_node_tag {
+ int_node * link;
+ int i;
+};
+
+typedef DECL_FIFO_ANCHOR(int_node) int_fifo;
+
+typedef struct string_node_tag string_node;
+struct string_node_tag {
+ string_node * link;
+ char * s;
};
-struct peer_node {
- int host_mode;
- struct address_node *addr;
- queue *peerflags;
- int minpoll;
- int maxpoll;
- int ttl;
- int peerversion;
- int peerkey;
- double bias;
+typedef DECL_FIFO_ANCHOR(string_node) string_fifo;
+
+typedef struct restrict_node_tag restrict_node;
+struct restrict_node_tag {
+ restrict_node * link;
+ address_node * addr;
+ address_node * mask;
+ int_fifo * flags;
+ int line_no;
};
-struct unpeer_node {
- u_int assocID;
- struct address_node * addr;
+typedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo;
+
+typedef struct peer_node_tag peer_node;
+struct peer_node_tag {
+ peer_node * link;
+ int host_mode;
+ address_node * addr;
+ attr_val_fifo * peerflags;
+ u_char minpoll;
+ u_char maxpoll;
+ u_int32 ttl;
+ u_char peerversion;
+ keyid_t peerkey;
+ char * group;
};
-struct auth_node {
- int control_key;
- int cryptosw;
- queue *crypto_cmd_list;
- char *keys;
- char *keysdir;
- int request_key;
- int revoke;
- queue *trusted_key_list;
- char *ntp_signd_socket;
+typedef DECL_FIFO_ANCHOR(peer_node) peer_fifo;
+
+typedef struct unpeer_node_tag unpeer_node;
+struct unpeer_node_tag {
+ unpeer_node * link;
+ associd_t assocID;
+ address_node * addr;
};
-struct filegen_node {
- int filegen_token;
- queue * options;
+typedef DECL_FIFO_ANCHOR(unpeer_node) unpeer_fifo;
+
+typedef struct auth_node_tag auth_node;
+struct auth_node_tag {
+ int control_key;
+ int cryptosw;
+ attr_val_fifo * crypto_cmd_list;
+ char * keys;
+ char * keysdir;
+ int request_key;
+ int revoke;
+ attr_val_fifo * trusted_key_list;
+ char * ntp_signd_socket;
};
-struct setvar_node {
- char * var;
- char * val;
- int isdefault;
+typedef struct filegen_node_tag filegen_node;
+struct filegen_node_tag {
+ filegen_node * link;
+ int filegen_token;
+ attr_val_fifo * options;
};
-typedef struct nic_rule_node_tag {
- int match_class;
- char *if_name; /* interface name or numeric address */
- int action;
-} nic_rule_node;
+typedef DECL_FIFO_ANCHOR(filegen_node) filegen_fifo;
-struct addr_opts_node {
- struct address_node *addr;
- queue *options;
+typedef struct setvar_node_tag setvar_node;
+struct setvar_node_tag {
+ setvar_node * link;
+ char * var;
+ char * val;
+ int isdefault;
};
-struct sim_node {
- queue *init_opts;
- queue *servers;
+typedef DECL_FIFO_ANCHOR(setvar_node) setvar_fifo;
+
+typedef struct nic_rule_node_tag nic_rule_node;
+struct nic_rule_node_tag {
+ nic_rule_node * link;
+ int match_class;
+ char * if_name; /* or numeric address */
+ int action;
+};
+
+typedef DECL_FIFO_ANCHOR(nic_rule_node) nic_rule_fifo;
+
+typedef struct addr_opts_node_tag addr_opts_node;
+struct addr_opts_node_tag {
+ addr_opts_node *link;
+ address_node * addr;
+ attr_val_fifo * options;
};
+typedef DECL_FIFO_ANCHOR(addr_opts_node) addr_opts_fifo;
+
+typedef struct sim_node_tag sim_node;
+struct sim_node_tag {
+ sim_node * link;
+ attr_val_fifo * init_opts;
+ server_info_fifo * servers;
+};
+
+typedef DECL_FIFO_ANCHOR(sim_node) sim_fifo;
/* The syntax tree */
-struct config_tree {
- struct config_tree *link;
+typedef struct config_tree_tag config_tree;
+struct config_tree_tag {
+ config_tree * link;
+
+ attr_val source;
+ time_t timestamp;
- struct attr_val source;
- time_t timestamp;
+ peer_fifo * peers;
+ unpeer_fifo * unpeers;
- queue *peers;
- queue *unpeers;
+ /* Other Modes */
+ int broadcastclient;
+ address_fifo * manycastserver;
+ address_fifo * multicastclient;
- /* Other Modes */
- int broadcastclient;
- queue *manycastserver;
- queue *multicastclient;
+ attr_val_fifo * orphan_cmds; /* s/b renamed tos_options */
- queue *orphan_cmds;
+ /* Monitoring Configuration */
+ int_fifo * stats_list;
+ char * stats_dir;
+ filegen_fifo * filegen_opts;
- /* Monitoring Configuration */
- queue *stats_list;
- char *stats_dir;
- queue *filegen_opts;
+ /* Access Control Configuration */
+ attr_val_fifo * discard_opts;
+ attr_val_fifo * mru_opts;
+ restrict_fifo * restrict_opts;
- /* Access Control Configuration */
- queue *discard_opts;
- queue *restrict_opts;
+ addr_opts_fifo *fudge;
+ attr_val_fifo * rlimit;
+ attr_val_fifo * tinker;
+ attr_val_fifo * enable_opts;
+ attr_val_fifo * disable_opts;
- queue *fudge;
- queue *tinker;
- queue *enable_opts;
- queue *disable_opts;
- struct auth_node auth;
+ auth_node auth;
- queue *logconfig;
- queue *qos;
- queue *phone;
- queue *setvar;
- queue *ttl;
- queue *trap;
- queue *vars;
- queue *nic_rules;
+ attr_val_fifo * logconfig;
+ string_fifo * phone;
+ setvar_fifo * setvar;
+ int_fifo * ttl;
+ addr_opts_fifo *trap;
+ attr_val_fifo * vars;
+ nic_rule_fifo * nic_rules;
+ int_fifo * reset_counters;
- struct sim_node *sim_details;
+ sim_fifo * sim_details;
};
@@ -199,47 +251,72 @@ struct REMOTE_CONFIG_INFO {
int no_errors;
};
+
+/*
+ * context for trap_name_resolved() to call ctlsettrap() once the
+ * name->address resolution completes.
+ */
+typedef struct settrap_parms_tag {
+ sockaddr_u ifaddr;
+ int ifaddr_nonnull;
+} settrap_parms;
+
+
/* get text from T_ tokens */
const char * token_name(int token);
-struct peer_node *create_peer_node(int hmode,
- struct address_node *addr,
- queue *options);
-struct unpeer_node *create_unpeer_node(struct address_node *addr);
-struct address_node *create_address_node(char *addr, int type);
-void destroy_address_node(struct address_node *my_node);
-queue *enqueue_in_new_queue(void *my_node);
-struct attr_val *create_attr_dval(int attr, double value);
-struct attr_val *create_attr_ival(int attr, int value);
-struct attr_val *create_attr_shorts(int, ntp_u_int16_t, ntp_u_int16_t);
-struct attr_val *create_attr_sval(int attr, char *s);
-struct attr_val *create_attr_pval(int attr, void *s);
-struct filegen_node *create_filegen_node(int filegen_token, queue *options);
-void **create_pval(void *val);
-struct restrict_node *create_restrict_node(struct address_node *addr,
- struct address_node *mask,
- queue *flags, int line_no);
-int *create_ival(int val);
-struct addr_opts_node *create_addr_opts_node(struct address_node *addr,
- queue *options);
-struct sim_node *create_sim_node(queue *init_opts, queue *servers);
-struct setvar_node *create_setvar_node(char *var, char *val,
- int isdefault);
+/* generic fifo routines for structs linked by 1st member */
+void* append_gen_fifo(void *fifo, void *entry);
+void * concat_gen_fifos(void *first, void *second);
+#define APPEND_G_FIFO(pf, pe) \
+ ((pf) = append_gen_fifo((pf), (pe)))
+#define CONCAT_G_FIFOS(first, second) \
+ ((first) = concat_gen_fifos((first), (second)))
+#define HEAD_PFIFO(pf) \
+ (((pf) != NULL) \
+ ? HEAD_FIFO(*(pf)) \
+ : NULL)
+
+peer_node *create_peer_node(int hmode, address_node *addr,
+ attr_val_fifo *options);
+unpeer_node *create_unpeer_node(address_node *addr);
+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_sval(int attr, char *s);
+filegen_node *create_filegen_node(int filegen_token,
+ attr_val_fifo *options);
+string_node *create_string_node(char *str);
+restrict_node *create_restrict_node(address_node *addr,
+ address_node *mask,
+ int_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);
+sim_node *create_sim_node(attr_val_fifo *init_opts,
+ server_info_fifo *servers);
+setvar_node *create_setvar_node(char *var, char *val, int isdefault);
nic_rule_node *create_nic_rule_node(int match_class, char *if_name,
int action);
script_info *create_sim_script_info(double duration,
- queue *script_queue);
-server_info *create_sim_server(struct address_node *addr,
- double server_offset, queue *script);
+ attr_val_fifo *script_queue);
+server_info *create_sim_server(address_node *addr, double server_offset,
+ script_info_fifo *script);
extern struct REMOTE_CONFIG_INFO remote_config;
void config_remotely(sockaddr_u *);
#ifdef SAVECONFIG
-int dump_config_tree(struct config_tree *ptree, FILE *df, int comment);
+int dump_config_tree(config_tree *ptree, FILE *df, int comment);
int dump_all_config_trees(FILE *df, int comment);
#endif
+#if defined(HAVE_SETRLIMIT)
+void ntp_rlimit(int, rlim_t, int, char *);
+#endif
#endif /* !defined(NTP_CONFIG_H) */
diff --git a/include/ntp_control.h b/include/ntp_control.h
index 3bca32b6e5b1c..be5b16d80eade 100644
--- a/include/ntp_control.h
+++ b/include/ntp_control.h
@@ -4,6 +4,11 @@
#include "ntp_types.h"
+typedef union ctl_pkt_u_tag {
+ u_char data[480 + MAX_MAC_LEN]; /* data + auth */
+ u_int32 u32[(480 + MAX_MAC_LEN) / sizeof(u_int32)];
+} ctl_pkt_u;
+
struct ntp_control {
u_char li_vn_mode; /* leap, version, mode */
u_char r_m_e_op; /* response, more, error, opcode */
@@ -12,13 +17,13 @@ struct ntp_control {
associd_t associd; /* association ID */
u_short offset; /* offset of this batch of data */
u_short count; /* count of data in this packet */
- u_char data[(480 + MAX_MAC_LEN)]; /* data + auth */
+ ctl_pkt_u u;
};
/*
* Length of the control header, in octets
*/
-#define CTL_HEADER_LEN (offsetof(struct ntp_control, data))
+#define CTL_HEADER_LEN (offsetof(struct ntp_control, u))
#define CTL_MAX_DATA_LEN 468
@@ -37,10 +42,10 @@ struct ntp_control {
#define CTL_MORE 0x20
#define CTL_OP_MASK 0x1f
-#define CTL_ISRESPONSE(r_m_e_op) (((r_m_e_op) & 0x80) != 0)
-#define CTL_ISMORE(r_m_e_op) (((r_m_e_op) & 0x20) != 0)
-#define CTL_ISERROR(r_m_e_op) (((r_m_e_op) & 0x40) != 0)
-#define CTL_OP(r_m_e_op) ((r_m_e_op) & CTL_OP_MASK)
+#define CTL_ISRESPONSE(r_m_e_op) ((CTL_RESPONSE & (r_m_e_op)) != 0)
+#define CTL_ISMORE(r_m_e_op) ((CTL_MORE & (r_m_e_op)) != 0)
+#define CTL_ISERROR(r_m_e_op) ((CTL_ERROR & (r_m_e_op)) != 0)
+#define CTL_OP(r_m_e_op) (CTL_OP_MASK & (r_m_e_op))
/*
* Opcodes
@@ -55,6 +60,9 @@ struct ntp_control {
#define CTL_OP_ASYNCMSG 7 /* asynchronous message */
#define CTL_OP_CONFIGURE 8 /* runtime configuration */
#define CTL_OP_SAVECONFIG 9 /* save config to file */
+#define CTL_OP_READ_MRU 10 /* retrieve MRU (mrulist) */
+#define CTL_OP_READ_ORDLIST_A 11 /* ordered list req. auth. */
+#define CTL_OP_REQ_NONCE 12 /* request a client nonce */
#define CTL_OP_UNSETTRAP 31 /* unset trap */
/*
@@ -144,121 +152,6 @@ struct ntp_control {
/*
- * System variables we understand
- */
-#define CS_LEAP 1
-#define CS_STRATUM 2
-#define CS_PRECISION 3
-#define CS_ROOTDELAY 4
-#define CS_ROOTDISPERSION 5
-#define CS_REFID 6
-#define CS_REFTIME 7
-#define CS_POLL 8
-#define CS_PEERID 9
-#define CS_OFFSET 10
-#define CS_DRIFT 11
-#define CS_JITTER 12
-#define CS_ERROR 13
-#define CS_CLOCK 14
-#define CS_PROCESSOR 15
-#define CS_SYSTEM 16
-#define CS_VERSION 17
-#define CS_STABIL 18
-#define CS_VARLIST 19
-#define CS_TAI 20
-#define CS_LEAPTAB 21
-#define CS_LEAPEND 22
-#define CS_RATE 23
-#ifdef OPENSSL
-#define CS_FLAGS 24
-#define CS_HOST 25
-#define CS_PUBLIC 26
-#define CS_CERTIF 27
-#define CS_SIGNATURE 28
-#define CS_REVTIME 29
-#define CS_GROUP 30
-#define CS_DIGEST 31
-#define CS_MAXCODE CS_DIGEST
-#else
-#define CS_MAXCODE CS_RATE
-#endif /* OPENSSL */
-
-/*
- * Peer variables we understand
- */
-#define CP_CONFIG 1
-#define CP_AUTHENABLE 2
-#define CP_AUTHENTIC 3
-#define CP_SRCADR 4
-#define CP_SRCPORT 5
-#define CP_DSTADR 6
-#define CP_DSTPORT 7
-#define CP_LEAP 8
-#define CP_HMODE 9
-#define CP_STRATUM 10
-#define CP_PPOLL 11
-#define CP_HPOLL 12
-#define CP_PRECISION 13
-#define CP_ROOTDELAY 14
-#define CP_ROOTDISPERSION 15
-#define CP_REFID 16
-#define CP_REFTIME 17
-#define CP_ORG 18
-#define CP_REC 19
-#define CP_XMT 20
-#define CP_REACH 21
-#define CP_UNREACH 22
-#define CP_TIMER 23
-#define CP_DELAY 24
-#define CP_OFFSET 25
-#define CP_JITTER 26
-#define CP_DISPERSION 27
-#define CP_KEYID 28
-#define CP_FILTDELAY 29
-#define CP_FILTOFFSET 30
-#define CP_PMODE 31
-#define CP_RECEIVED 32
-#define CP_SENT 33
-#define CP_FILTERROR 34
-#define CP_FLASH 35
-#define CP_TTL 36
-#define CP_VARLIST 37
-#define CP_IN 38
-#define CP_OUT 39
-#define CP_RATE 40
-#define CP_BIAS 41
-#ifdef OPENSSL
-#define CP_FLAGS 42
-#define CP_HOST 43
-#define CP_VALID 44
-#define CP_INITSEQ 45
-#define CP_INITKEY 46
-#define CP_INITTSP 47
-#define CP_SIGNATURE 48
-#define CP_MAXCODE CP_SIGNATURE
-#else
-#define CP_MAXCODE CP_BIAS
-#endif /* OPENSSL */
-
-/*
- * Clock variables we understand
- */
-#define CC_TYPE 1
-#define CC_TIMECODE 2
-#define CC_POLL 3
-#define CC_NOREPLY 4
-#define CC_BADFORMAT 5
-#define CC_BADDATA 6
-#define CC_FUDGETIME1 7
-#define CC_FUDGETIME2 8
-#define CC_FUDGEVAL1 9
-#define CC_FUDGEVAL2 10
-#define CC_FLAGS 11
-#define CC_DEVICE 12
-#define CC_VARLIST 13
-#define CC_MAXCODE CC_VARLIST
-
-/*
* Definition of the structure used internally to hold trap information.
* ntp_request.c wants to see this.
*/
@@ -273,7 +166,7 @@ struct ctl_trap {
u_char tr_flags; /* trap flags */
u_char tr_version; /* version number of trapper */
};
-extern struct ctl_trap ctl_trap[];
+extern struct ctl_trap ctl_traps[CTL_MAXTRAPS];
/*
* Flag bits
@@ -289,3 +182,11 @@ extern struct ctl_trap ctl_trap[];
#define TYPE_SYS 1
#define TYPE_PEER 2
#define TYPE_CLOCK 3
+
+/*
+ * IFSTATS_FIELDS is the number of fields ntpd supplies for each ifstats
+ * row. Similarly RESLIST_FIELDS for reslist.
+ */
+#define IFSTATS_FIELDS 12
+#define RESLIST_FIELDS 4
+
diff --git a/include/ntp_crypto.h b/include/ntp_crypto.h
index 80e3fb11a8f10..b801006144dcb 100644
--- a/include/ntp_crypto.h
+++ b/include/ntp_crypto.h
@@ -5,22 +5,28 @@
#define NTP_CRYPTO_H
/*
- * Configuration codes (also needed for parser without OPENSSL)
+ * Configuration codes (also needed for parser without AUTOKEY)
*/
#define CRYPTO_CONF_NONE 0 /* nothing doing */
-#define CRYPTO_CONF_PRIV 1 /* host keys file name */
-#define CRYPTO_CONF_SIGN 2 /* signature keys file name */
+#define CRYPTO_CONF_PRIV 1 /* host name */
+#define CRYPTO_CONF_IDENT 2 /* group name */
#define CRYPTO_CONF_CERT 3 /* certificate file name */
#define CRYPTO_CONF_RAND 4 /* random seed file name */
#define CRYPTO_CONF_IFFPAR 5 /* IFF parameters file name */
#define CRYPTO_CONF_GQPAR 6 /* GQ parameters file name */
#define CRYPTO_CONF_MVPAR 7 /* MV parameters file name */
#define CRYPTO_CONF_PW 8 /* private key password */
-#define CRYPTO_CONF_IDENT 9 /* specify identity scheme */
-#define CRYPTO_CONF_NID 10 /* specify digest name */
+#define CRYPTO_CONF_NID 9 /* specify digest name */
+
+#ifdef AUTOKEY
+#ifndef OPENSSL
+#error AUTOKEY should be defined only if OPENSSL is.
+invalidsyntax: AUTOKEY should be defined only if OPENSSL is.
+#endif
-#ifdef OPENSSL
#include "openssl/evp.h"
+#include "ntp_calendar.h" /* for fields in the cert_info structure */
+
/*
* The following bits are set by the CRYPTO_ASSOC message from
@@ -124,7 +130,7 @@ struct value { /* network byte order */
tstamp_t tstamp; /* timestamp */
tstamp_t fstamp; /* filestamp */
u_int32 vallen; /* value length */
- u_char *ptr; /* data pointer (various) */
+ void *ptr; /* data pointer (various) */
u_int32 siglen; /* signature length */
u_char *sig; /* signature */
};
@@ -142,6 +148,7 @@ struct exten {
u_int32 pkt[1]; /* start of value field */
};
+
/*
* The certificate info/value structure
*/
@@ -153,8 +160,8 @@ struct cert_info {
int nid; /* signature/digest ID */
const EVP_MD *digest; /* message digest algorithm */
u_long serial; /* serial number */
- tstamp_t first; /* not valid before */
- tstamp_t last; /* not valid after */
+ struct calendar first; /* not valid before */
+ struct calendar last; /* not valid after */
char *subject; /* subject common name */
char *issuer; /* issuer common name */
BIGNUM *grpkey; /* GQ group key */
@@ -179,5 +186,5 @@ extern int crypto_nid; /* digest nid */
extern struct value hostval; /* host name/value */
extern struct cert_info *cinfo; /* host certificate information */
extern struct value tai_leap; /* leapseconds table */
-#endif /* OPENSSL */
+#endif /* AUTOKEY */
#endif /* NTP_CRYPTO_H */
diff --git a/include/ntp_data_structures.h b/include/ntp_data_structures.h
deleted file mode 100644
index 363e0b47a4e9b..0000000000000
--- a/include/ntp_data_structures.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* ntp_data_structures.h
- *
- * This file contains the structures and function prototypes for the data
- * structures used by the ntp configuration code and the discrete event
- * simulator.
- *
- * Written By: Sachin Kamboj
- * University of Delaware
- * Newark, DE 19711
- * Copyright (c) 2006
- */
-
-#ifndef __NTP_DATA_STRUCTURES_H__
-#define __NTP_DATA_STRUCTURES_H__
-
-
-/* Structures for storing a priority queue
- * ---------------------------------------
- */
-
-typedef struct node {
- union {
- struct node *next;
- double d;
- } nodeu;
-} node;
-#define node_next nodeu.next
-
-typedef struct Queue {
- int (*get_order)(void *, void *);
- node *front;
- int no_of_elements;
-} queue;
-
-
-/* FUNCTION PROTOTYPES
- * -------------------
- */
-queue *create_priority_queue(int (*get_order)(void *, void *));
-void destroy_queue(queue *my_queue);
-void *get_node(size_t size);
-void free_node(void *my_node);
-void *next_node(void *my_node);
-int empty(queue *my_queue);
-void *queue_head(queue *my_queue);
-queue *enqueue(queue *my_queue, void *my_node);
-void *dequeue(queue *my_queue);
-int get_no_of_elements(queue *my_queue);
-void append_queue(queue *q1, queue *q2);
-int get_fifo_order(void *el1, void *el2);
-queue *create_queue(void);
-
-#endif
diff --git a/include/ntp_debug.h b/include/ntp_debug.h
index 55b2e1a76d8e6..b0e846e0b3757 100644
--- a/include/ntp_debug.h
+++ b/include/ntp_debug.h
@@ -9,20 +9,19 @@
#define NTP_DEBUG_H
/*
- * macros for debugging output - cut down on #ifdef pollution in the code
+ * macro for debugging output - cut down on #ifdef pollution.
+ *
+ * TRACE() is similar to ntpd's DPRINTF() for utilities and libntp.
+ * Uses mprintf() and so supports %m, replaced by strerror(errno).
+ *
+ * The calling convention is not attractive:
+ * TRACE(debuglevel, (fmt, ...));
+ * TRACE(2, ("this will appear on stdout if debug >= %d\n", 2));
*/
-
-#ifdef DEBUG
-#define DPRINTF(_lvl_, _arg_) \
+#define TRACE(lvl, arg) \
do { \
- if (debug >= (_lvl_)) \
- printf _arg_; \
+ if (debug >= (lvl)) \
+ mprintf arg; \
} while (0)
-#else
-#define DPRINTF(_lvl_, _arg_) do {} while (0)
-#endif
-#endif
-/*
- * $Log$
- */
+#endif /* NTP_DEBUG_H */
diff --git a/include/ntp_filegen.h b/include/ntp_filegen.h
index 2b90db29dde3f..f5ba8afe9ed8b 100644
--- a/include/ntp_filegen.h
+++ b/include/ntp_filegen.h
@@ -5,7 +5,7 @@
*
*
* Copyright (C) 1992, 1996 by Rainer Pruy
- * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
+ * Friedrich-Alexander Universitaet Erlangen-Nuernberg, Germany
*
* This code may be modified and used freely
* provided the credits remain intact.
@@ -23,7 +23,7 @@
#define FILEGEN_WEEK 3 /* one filegen per week */
#define FILEGEN_MONTH 4 /* one filegen per month */
#define FILEGEN_YEAR 5 /* one filegen per year */
-#define FILEGEN_AGE 6 /* change filegen each FG_AGE_SECS */
+#define FILEGEN_AGE 6 /* change filegen each FG_AGE_SECS */
/*
* supported file generation flags
@@ -31,22 +31,24 @@
#define FGEN_FLAG_LINK 0x01 /* make a link to base name */
-#define FGEN_FLAG_ENABLED 0x80 /* set this to really create files */
+#define FGEN_FLAG_ENABLED 0x80 /* set this to really create files */
/* without this, open is suppressed */
-typedef struct FILEGEN
-{
- FILE * fp; /* file referring to current generation */
- const char * prefix; /* filename prefix and basename to be used*/
- char * basename; /* for constructing filename of generation file */
- /* WARNING: must be malloced !!! will be fed to free()*/
- u_long id; /* id of current generation */
- u_char type; /* type of file generation */
- u_char flag; /* flags modifying processing of file generation */
-} FILEGEN;
+typedef struct filegen_tag {
+ FILE * fp; /* file referring to current generation */
+ char * dir; /* currently always statsdir */
+ char * fname; /* filename prefix of generation file */
+ /* must be malloced, will be fed to free() */
+ u_long id_lo; /* lower bound of ident value */
+ u_long id_hi; /* upper bound of ident value */
+ u_char type; /* type of file generation */
+ u_char flag; /* flags modifying processing of file generation */
+} FILEGEN;
-extern void filegen_setup (FILEGEN *, u_long);
-extern void filegen_config (FILEGEN *, const char *, u_int, u_int);
+extern void filegen_setup (FILEGEN *, u_int32);
+extern void filegen_config (FILEGEN *, const char *, const char *,
+ u_int, u_int);
+extern void filegen_statsdir(void);
extern FILEGEN *filegen_get (const char *);
extern void filegen_register (const char *, const char *, FILEGEN *);
#ifdef DEBUG
diff --git a/include/ntp_fp.h b/include/ntp_fp.h
index 99d4df37025fe..1b97e8b5cf72e 100644
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -32,16 +32,11 @@ typedef struct {
u_int32 Xl_ui;
int32 Xl_i;
} Ul_i;
- union {
- u_int32 Xl_uf;
- int32 Xl_f;
- } Ul_f;
+ u_int32 l_uf;
} l_fp;
#define l_ui Ul_i.Xl_ui /* unsigned integral part */
#define l_i Ul_i.Xl_i /* signed integral part */
-#define l_uf Ul_f.Xl_uf /* unsigned fractional part */
-#define l_f Ul_f.Xl_f /* signed fractional part */
/*
* Fractional precision (of an l_fp) is actually the number of
@@ -78,25 +73,32 @@ typedef u_int32 u_fp;
* Byte order conversions
*/
#define HTONS_FP(x) (htonl(x))
-#define HTONL_FP(h, n) do { (n)->l_ui = htonl((h)->l_ui); \
- (n)->l_uf = htonl((h)->l_uf); } while (0)
#define NTOHS_FP(x) (ntohl(x))
-#define NTOHL_FP(n, h) do { (h)->l_ui = ntohl((n)->l_ui); \
- (h)->l_uf = ntohl((n)->l_uf); } while (0)
-#define NTOHL_MFP(ni, nf, hi, hf) \
- do { (hi) = ntohl(ni); (hf) = ntohl(nf); } while (0)
-#define HTONL_MFP(hi, hf, ni, nf) \
- do { (ni) = htonl(hi); (nf) = htonl(hf); } while (0)
-/* funny ones. Converts ts fractions to net order ts */
-#define HTONL_UF(uf, nts) \
- do { (nts)->l_ui = 0; (nts)->l_uf = htonl(uf); } while (0)
-#define HTONL_F(f, nts) do { (nts)->l_uf = htonl(f); \
- if ((f) & 0x80000000) \
- (nts)->l_i = -1; \
- else \
- (nts)->l_i = 0; \
- } while (0)
+#define NTOHL_MFP(ni, nf, hi, hf) \
+ do { \
+ (hi) = ntohl(ni); \
+ (hf) = ntohl(nf); \
+ } while (FALSE)
+
+#define HTONL_MFP(hi, hf, ni, nf) \
+ do { \
+ (ni) = htonl(hi); \
+ (nf) = htonl(hf); \
+ } while (FALSE)
+
+#define HTONL_FP(h, n) \
+ HTONL_MFP((h)->l_ui, (h)->l_uf, (n)->l_ui, (n)->l_uf)
+
+#define NTOHL_FP(n, h) \
+ NTOHL_MFP((n)->l_ui, (n)->l_uf, (h)->l_ui, (h)->l_uf)
+
+/* Convert unsigned ts fraction to net order ts */
+#define HTONL_UF(uf, nts) \
+ do { \
+ (nts)->l_ui = 0; \
+ (nts)->l_uf = htonl(uf); \
+ } while (FALSE)
/*
* Conversions between the two fixed point types
@@ -104,13 +106,13 @@ typedef u_int32 u_fp;
#define MFPTOFP(x_i, x_f) (((x_i) >= 0x00010000) ? 0x7fffffff : \
(((x_i) <= -0x00010000) ? 0x80000000 : \
(((x_i)<<16) | (((x_f)>>16)&0xffff))))
-#define LFPTOFP(v) MFPTOFP((v)->l_i, (v)->l_f)
+#define LFPTOFP(v) MFPTOFP((v)->l_i, (v)->l_uf)
#define UFPTOLFP(x, v) ((v)->l_ui = (u_fp)(x)>>16, (v)->l_uf = (x)<<16)
#define FPTOLFP(x, v) (UFPTOLFP((x), (v)), (x) < 0 ? (v)->l_ui -= 0x10000 : 0)
-#define MAXLFP(v) ((v)->l_ui = 0x7fffffff, (v)->l_uf = 0xffffffff)
-#define MINLFP(v) ((v)->l_ui = 0x80000000, (v)->l_uf = 0)
+#define MAXLFP(v) ((v)->l_ui = 0x7fffffffu, (v)->l_uf = 0xffffffffu)
+#define MINLFP(v) ((v)->l_ui = 0x80000000u, (v)->l_uf = 0u)
/*
* Primitive operations on long fixed point values. If these are
@@ -120,123 +122,68 @@ typedef u_int32 u_fp;
*/
#define M_NEG(v_i, v_f) /* v = -v */ \
do { \
- if ((v_f) == 0) \
- (v_i) = -((s_fp)(v_i)); \
- else { \
- (v_f) = -((s_fp)(v_f)); \
- (v_i) = ~(v_i); \
- } \
- } while(0)
+ (v_f) = ~(v_f) + 1u; \
+ (v_i) = ~(v_i) + ((v_f) == 0); \
+ } while (FALSE)
#define M_NEGM(r_i, r_f, a_i, a_f) /* r = -a */ \
do { \
- if ((a_f) == 0) { \
- (r_f) = 0; \
- (r_i) = -(a_i); \
- } else { \
- (r_f) = -(a_f); \
- (r_i) = ~(a_i); \
- } \
- } while(0)
+ (r_f) = ~(a_f) + 1u; \
+ (r_i) = ~(a_i) + ((r_f) == 0); \
+ } while (FALSE)
#define M_ADD(r_i, r_f, a_i, a_f) /* r += a */ \
do { \
- register u_int32 lo_tmp; \
- register u_int32 hi_tmp; \
- \
- lo_tmp = ((r_f) & 0xffff) + ((a_f) & 0xffff); \
- hi_tmp = (((r_f) >> 16) & 0xffff) + (((a_f) >> 16) & 0xffff); \
- if (lo_tmp & 0x10000) \
- hi_tmp++; \
- (r_f) = ((hi_tmp & 0xffff) << 16) | (lo_tmp & 0xffff); \
- \
- (r_i) += (a_i); \
- if (hi_tmp & 0x10000) \
- (r_i)++; \
- } while (0)
+ u_int32 add_t = (r_f); \
+ (r_f) += (a_f); \
+ (r_i) += (a_i) + ((u_int32)(r_f) < add_t); \
+ } while (FALSE)
-#define M_ADD3(r_ovr, r_i, r_f, a_ovr, a_i, a_f) /* r += a, three word */ \
+#define M_ADD3(r_o, r_i, r_f, a_o, a_i, a_f) /* r += a, three word */ \
do { \
- register u_int32 lo_tmp; \
- register u_int32 hi_tmp; \
- \
- lo_tmp = ((r_f) & 0xffff) + ((a_f) & 0xffff); \
- hi_tmp = (((r_f) >> 16) & 0xffff) + (((a_f) >> 16) & 0xffff); \
- if (lo_tmp & 0x10000) \
- hi_tmp++; \
- (r_f) = ((hi_tmp & 0xffff) << 16) | (lo_tmp & 0xffff); \
- \
- lo_tmp = ((r_i) & 0xffff) + ((a_i) & 0xffff); \
- if (hi_tmp & 0x10000) \
- lo_tmp++; \
- hi_tmp = (((r_i) >> 16) & 0xffff) + (((a_i) >> 16) & 0xffff); \
- if (lo_tmp & 0x10000) \
- hi_tmp++; \
- (r_i) = ((hi_tmp & 0xffff) << 16) | (lo_tmp & 0xffff); \
- \
- (r_ovr) += (a_ovr); \
- if (hi_tmp & 0x10000) \
- (r_ovr)++; \
- } while (0)
+ u_int32 add_t, add_c; \
+ add_t = (r_f); \
+ (r_f) += (a_f); \
+ add_c = ((u_int32)(r_f) < add_t); \
+ (r_i) += add_c; \
+ add_c = ((u_int32)(r_i) < add_c); \
+ add_t = (r_i); \
+ (r_i) += (a_i); \
+ add_c |= ((u_int32)(r_i) < add_t); \
+ (r_o) += (a_o) + add_c; \
+ } while (FALSE)
#define M_SUB(r_i, r_f, a_i, a_f) /* r -= a */ \
do { \
- register u_int32 lo_tmp; \
- register u_int32 hi_tmp; \
- \
- if ((a_f) == 0) { \
- (r_i) -= (a_i); \
- } else { \
- lo_tmp = ((r_f) & 0xffff) + ((-((s_fp)(a_f))) & 0xffff); \
- hi_tmp = (((r_f) >> 16) & 0xffff) \
- + (((-((s_fp)(a_f))) >> 16) & 0xffff); \
- if (lo_tmp & 0x10000) \
- hi_tmp++; \
- (r_f) = ((hi_tmp & 0xffff) << 16) | (lo_tmp & 0xffff); \
- \
- (r_i) += ~(a_i); \
- if (hi_tmp & 0x10000) \
- (r_i)++; \
- } \
- } while (0)
+ u_int32 sub_t = (r_f); \
+ (r_f) -= (a_f); \
+ (r_i) -= (a_i) + ((u_int32)(r_f) > sub_t); \
+ } while (FALSE)
#define M_RSHIFTU(v_i, v_f) /* v >>= 1, v is unsigned */ \
do { \
- (v_f) = (u_int32)(v_f) >> 1; \
- if ((v_i) & 01) \
- (v_f) |= 0x80000000; \
- (v_i) = (u_int32)(v_i) >> 1; \
- } while (0)
+ (v_f) = ((u_int32)(v_f) >> 1) | ((u_int32)(v_i) << 31); \
+ (v_i) = ((u_int32)(v_i) >> 1); \
+ } while (FALSE)
#define M_RSHIFT(v_i, v_f) /* v >>= 1, v is signed */ \
do { \
- (v_f) = (u_int32)(v_f) >> 1; \
- if ((v_i) & 01) \
- (v_f) |= 0x80000000; \
- if ((v_i) & 0x80000000) \
- (v_i) = ((v_i) >> 1) | 0x80000000; \
- else \
- (v_i) = (v_i) >> 1; \
- } while (0)
+ (v_f) = ((u_int32)(v_f) >> 1) | ((u_int32)(v_i) << 31); \
+ (v_i) = ((u_int32)(v_i) >> 1) | ((u_int32)(v_i) & 0x80000000); \
+ } while (FALSE)
#define M_LSHIFT(v_i, v_f) /* v <<= 1 */ \
do { \
- (v_i) <<= 1; \
- if ((v_f) & 0x80000000) \
- (v_i) |= 0x1; \
- (v_f) <<= 1; \
- } while (0)
+ (v_i) = ((u_int32)(v_i) << 1) | ((u_int32)(v_f) >> 31); \
+ (v_f) = ((u_int32)(v_f) << 1); \
+ } while (FALSE)
-#define M_LSHIFT3(v_ovr, v_i, v_f) /* v <<= 1, with overflow */ \
+#define M_LSHIFT3(v_o, v_i, v_f) /* v <<= 1, with overflow */ \
do { \
- (v_ovr) <<= 1; \
- if ((v_i) & 0x80000000) \
- (v_ovr) |= 0x1; \
- (v_i) <<= 1; \
- if ((v_f) & 0x80000000) \
- (v_i) |= 0x1; \
- (v_f) <<= 1; \
- } while (0)
+ (v_o) = ((u_int32)(v_o) << 1) | ((u_int32)(v_i) >> 31); \
+ (v_i) = ((u_int32)(v_i) << 1) | ((u_int32)(v_f) >> 31); \
+ (v_f) = ((u_int32)(v_f) << 1); \
+ } while (FALSE)
#define M_ADDUF(r_i, r_f, uf) /* r += uf, uf is u_int32 fraction */ \
M_ADD((r_i), (r_f), 0, (uf)) /* let optimizer worry about it */
@@ -246,25 +193,34 @@ typedef u_int32 u_fp;
#define M_ADDF(r_i, r_f, f) /* r += f, f is a int32 fraction */ \
do { \
- if ((f) > 0) \
- M_ADD((r_i), (r_f), 0, (f)); \
- else if ((f) < 0) \
- M_ADD((r_i), (r_f), (-1), (f));\
+ int32 add_f = (int32)(f); \
+ if (add_f >= 0) \
+ M_ADD((r_i), (r_f), 0, (uint32)( add_f)); \
+ else \
+ M_SUB((r_i), (r_f), 0, (uint32)(-add_f)); \
} while(0)
-#define M_ISNEG(v_i, v_f) /* v < 0 */ \
+#define M_ISNEG(v_i) /* v < 0 */ \
(((v_i) & 0x80000000) != 0)
+#define M_ISGT(a_i, a_f, b_i, b_f) /* a > b signed */ \
+ (((u_int32)((a_i) ^ 0x80000000) > (u_int32)((b_i) ^ 0x80000000)) || \
+ ((a_i) == (b_i) && ((u_int32)(a_f)) > ((u_int32)(b_f))))
+
+#define M_ISGTU(a_i, a_f, b_i, b_f) /* a > b unsigned */ \
+ (((u_int32)(a_i)) > ((u_int32)(b_i)) || \
+ ((a_i) == (b_i) && ((u_int32)(a_f)) > ((u_int32)(b_f))))
+
#define M_ISHIS(a_i, a_f, b_i, b_f) /* a >= b unsigned */ \
(((u_int32)(a_i)) > ((u_int32)(b_i)) || \
((a_i) == (b_i) && ((u_int32)(a_f)) >= ((u_int32)(b_f))))
#define M_ISGEQ(a_i, a_f, b_i, b_f) /* a >= b signed */ \
- (((int32)(a_i)) > ((int32)(b_i)) || \
- ((a_i) == (b_i) && ((u_int32)(a_f)) >= ((u_int32)(b_f))))
+ (((u_int32)((a_i) ^ 0x80000000) > (u_int32)((b_i) ^ 0x80000000)) || \
+ ((a_i) == (b_i) && (u_int32)(a_f) >= (u_int32)(b_f)))
#define M_ISEQU(a_i, a_f, b_i, b_f) /* a == b unsigned */ \
- ((a_i) == (b_i) && (a_f) == (b_f))
+ ((u_int32)(a_i) == (u_int32)(b_i) && (u_int32)(a_f) == (u_int32)(b_f))
/*
* Operations on the long fp format
@@ -280,18 +236,18 @@ typedef u_int32 u_fp;
#define L_LSHIFT(v) M_LSHIFT((v)->l_ui, (v)->l_uf)
#define L_CLR(v) ((v)->l_ui = (v)->l_uf = 0)
-#define L_ISNEG(v) (((v)->l_ui & 0x80000000) != 0)
-#define L_ISZERO(v) ((v)->l_ui == 0 && (v)->l_uf == 0)
-#define L_ISHIS(a, b) ((a)->l_ui > (b)->l_ui || \
- ((a)->l_ui == (b)->l_ui && (a)->l_uf >= (b)->l_uf))
-#define L_ISGEQ(a, b) ((a)->l_i > (b)->l_i || \
- ((a)->l_i == (b)->l_i && (a)->l_uf >= (b)->l_uf))
+#define L_ISNEG(v) M_ISNEG((v)->l_ui)
+#define L_ISZERO(v) (((v)->l_ui | (v)->l_uf) == 0)
+#define L_ISGT(a, b) M_ISGT((a)->l_i, (a)->l_uf, (b)->l_i, (b)->l_uf)
+#define L_ISGTU(a, b) M_ISGTU((a)->l_ui, (a)->l_uf, (b)->l_ui, (b)->l_uf)
+#define L_ISHIS(a, b) M_ISHIS((a)->l_ui, (a)->l_uf, (b)->l_ui, (b)->l_uf)
+#define L_ISGEQ(a, b) M_ISGEQ((a)->l_ui, (a)->l_uf, (b)->l_ui, (b)->l_uf)
#define L_ISEQU(a, b) M_ISEQU((a)->l_ui, (a)->l_uf, (b)->l_ui, (b)->l_uf)
/*
* s_fp/double and u_fp/double conversions
*/
-#define FRIC 65536. /* 2^16 as a double */
+#define FRIC 65536.0 /* 2^16 as a double */
#define DTOFP(r) ((s_fp)((r) * FRIC))
#define DTOUFP(r) ((u_fp)((r) * FRIC))
#define FPTOD(r) ((double)(r) / FRIC)
@@ -299,67 +255,121 @@ typedef u_int32 u_fp;
/*
* l_fp/double conversions
*/
-#define FRAC 4294967296. /* 2^32 as a double */
-#define M_DTOLFP(d, r_i, r_uf) /* double to l_fp */ \
+#define FRAC 4294967296.0 /* 2^32 as a double */
+
+/*
+ * Use 64 bit integers if available. Solaris on SPARC has a problem
+ * compiling parsesolaris.c if ntp_fp.h includes math.h, due to
+ * archaic gets() and printf() prototypes used in Solaris kernel
+ * headers. So far the problem has only been seen with gcc, but it
+ * may also affect Sun compilers, in which case the defined(__GNUC__)
+ * term should be removed.
+ */
+#if defined(HAVE_U_INT64) && \
+ !(defined(__SVR4) && defined(__sun) && \
+ defined(sparc) && defined(__GNUC__))
+
+#include <math.h> /* ldexp() */
+
+#define M_DTOLFP(d, r_ui, r_uf) /* double to l_fp */ \
+ do { \
+ double d_tmp; \
+ u_int64 q_tmp; \
+ int M_isneg; \
+ \
+ d_tmp = (d); \
+ M_isneg = (d_tmp < 0.); \
+ if (M_isneg) { \
+ d_tmp = -d_tmp; \
+ } \
+ q_tmp = (u_int64)ldexp(d_tmp, 32); \
+ if (M_isneg) { \
+ q_tmp = ~q_tmp + 1; \
+ } \
+ (r_uf) = (u_int32)q_tmp; \
+ (r_ui) = (u_int32)(q_tmp >> 32); \
+ } while (FALSE)
+
+#define M_LFPTOD(r_ui, r_uf, d) /* l_fp to double */ \
+ do { \
+ double d_tmp; \
+ u_int64 q_tmp; \
+ int M_isneg; \
+ \
+ q_tmp = ((u_int64)(r_ui) << 32) + (r_uf); \
+ M_isneg = M_ISNEG(r_ui); \
+ if (M_isneg) { \
+ q_tmp = ~q_tmp + 1; \
+ } \
+ d_tmp = ldexp((double)q_tmp, -32); \
+ if (M_isneg) { \
+ d_tmp = -d_tmp; \
+ } \
+ (d) = d_tmp; \
+ } while (FALSE)
+
+#else /* use only 32 bit unsigned values */
+
+#define M_DTOLFP(d, r_ui, r_uf) /* double to l_fp */ \
do { \
- register double d_tmp; \
- \
- d_tmp = (d); \
- if (d_tmp < 0) { \
- d_tmp = -d_tmp; \
- (r_i) = (int32)(d_tmp); \
- (r_uf) = (u_int32)(((d_tmp) - (double)(r_i)) * FRAC); \
- M_NEG((r_i), (r_uf)); \
+ double d_tmp; \
+ if ((d_tmp = (d)) < 0) { \
+ (r_ui) = (u_int32)(-d_tmp); \
+ (r_uf) = (u_int32)(-(d_tmp + (double)(r_ui)) * FRAC); \
+ M_NEG((r_ui), (r_uf)); \
} else { \
- (r_i) = (int32)(d_tmp); \
- (r_uf) = (u_int32)(((d_tmp) - (double)(r_i)) * FRAC); \
+ (r_ui) = (u_int32)d_tmp; \
+ (r_uf) = (u_int32)((d_tmp - (double)(r_ui)) * FRAC); \
} \
} while (0)
-#define M_LFPTOD(r_i, r_uf, d) /* l_fp to double */ \
+#define M_LFPTOD(r_ui, r_uf, d) /* l_fp to double */ \
do { \
- register l_fp l_tmp; \
- \
- l_tmp.l_i = (r_i); \
- l_tmp.l_f = (r_uf); \
- if (l_tmp.l_i < 0) { \
- M_NEG(l_tmp.l_i, l_tmp.l_uf); \
- (d) = -((double)l_tmp.l_i + ((double)l_tmp.l_uf) / FRAC); \
+ u_int32 l_thi, l_tlo; \
+ l_thi = (r_ui); l_tlo = (r_uf); \
+ if (M_ISNEG(l_thi)) { \
+ M_NEG(l_thi, l_tlo); \
+ (d) = -((double)l_thi + (double)l_tlo / FRAC); \
} else { \
- (d) = (double)l_tmp.l_i + ((double)l_tmp.l_uf) / FRAC; \
+ (d) = (double)l_thi + (double)l_tlo / FRAC; \
} \
} while (0)
-#define DTOLFP(d, v) M_DTOLFP((d), (v)->l_ui, (v)->l_uf)
-#define LFPTOD(v, d) M_LFPTOD((v)->l_ui, (v)->l_uf, (d))
+#endif
+
+#define DTOLFP(d, v) M_DTOLFP((d), (v)->l_ui, (v)->l_uf)
+#define LFPTOD(v, d) M_LFPTOD((v)->l_ui, (v)->l_uf, (d))
/*
* Prototypes
*/
extern char * dofptoa (u_fp, int, short, int);
-extern char * dolfptoa (u_long, u_long, int, short, int);
+extern char * dolfptoa (u_int32, u_int32, int, short, int);
extern int atolfp (const char *, l_fp *);
extern int buftvtots (const char *, l_fp *);
extern char * fptoa (s_fp, short);
extern char * fptoms (s_fp, short);
extern int hextolfp (const char *, l_fp *);
-extern void gpstolfp (int, int, unsigned long, l_fp *);
+extern void gpstolfp (int, int, unsigned long, l_fp *);
extern int mstolfp (const char *, l_fp *);
extern char * prettydate (l_fp *);
extern char * gmprettydate (l_fp *);
extern char * uglydate (l_fp *);
-extern void mfp_mul (int32 *, u_int32 *, int32, u_int32, int32, u_int32);
+extern void mfp_mul (int32 *, u_int32 *, int32, u_int32, int32, u_int32);
+extern void set_sys_fuzz (double);
+extern void init_systime (void);
extern void get_systime (l_fp *);
extern int step_systime (double);
extern int adj_systime (double);
-extern struct tm * ntp2unix_tm (u_long ntp, int local);
+extern struct tm * ntp2unix_tm (u_int32 ntp, int local);
#define lfptoa(fpv, ndec) mfptoa((fpv)->l_ui, (fpv)->l_uf, (ndec))
#define lfptoms(fpv, ndec) mfptoms((fpv)->l_ui, (fpv)->l_uf, (ndec))
#define stoa(addr) socktoa(addr)
#define ntoa(addr) stoa(addr)
+#define sptoa(addr) sockporttoa(addr)
#define stohost(addr) socktohost(addr)
#define ufptoa(fpv, ndec) dofptoa((fpv), 0, (ndec), 0)
@@ -368,4 +378,43 @@ extern struct tm * ntp2unix_tm (u_long ntp, int local);
#define ulfptoms(fpv, ndec) dolfptoa((fpv)->l_ui, (fpv)->l_uf, 0, (ndec), 1)
#define umfptoa(fpi, fpf, ndec) dolfptoa((fpi), (fpf), 0, (ndec), 0)
+/*
+ * Optional callback from libntp step_systime() to ntpd. Optional
+* because other libntp clients like ntpdate don't use it.
+ */
+typedef void (*time_stepped_callback)(void);
+extern time_stepped_callback step_callback;
+
+/*
+ * Multi-thread locking for get_systime()
+ *
+ * On most systems, get_systime() is used solely by the main ntpd
+ * thread, but on Windows it's also used by the dedicated I/O thread.
+ * The [Bug 2037] changes to get_systime() have it keep state between
+ * calls to ensure time moves in only one direction, which means its
+ * use on Windows needs to be protected against simultaneous execution
+ * to avoid falsely detecting Lamport violations by ensuring only one
+ * thread at a time is in get_systime().
+ */
+#ifdef SYS_WINNT
+extern CRITICAL_SECTION get_systime_cs;
+# define INIT_GET_SYSTIME_CRITSEC() \
+ InitializeCriticalSection(&get_systime_cs)
+# define ENTER_GET_SYSTIME_CRITSEC() \
+ EnterCriticalSection(&get_systime_cs)
+# define LEAVE_GET_SYSTIME_CRITSEC() \
+ LeaveCriticalSection(&get_systime_cs)
+# define INIT_WIN_PRECISE_TIME() \
+ init_win_precise_time()
+#else /* !SYS_WINNT follows */
+# define INIT_GET_SYSTIME_CRITSEC() \
+ do {} while (FALSE)
+# define ENTER_GET_SYSTIME_CRITSEC() \
+ do {} while (FALSE)
+# define LEAVE_GET_SYSTIME_CRITSEC() \
+ do {} while (FALSE)
+# define INIT_WIN_PRECISE_TIME() \
+ do {} while (FALSE)
+#endif
+
#endif /* NTP_FP_H */
diff --git a/include/ntp_intres.h b/include/ntp_intres.h
index 53c8a63a40764..1b6bd66e0b117 100644
--- a/include/ntp_intres.h
+++ b/include/ntp_intres.h
@@ -1,14 +1,45 @@
+/*
+ * ntp_intres.h - client interface to blocking-worker name resolution.
+ */
#ifndef NTP_INTRES_H
#define NTP_INTRES_H
+#include <ntp_worker.h>
+
+#ifdef WORKER
+#define INITIAL_DNS_RETRY 2 /* seconds between queries */
+
+/*
+ * you call getaddrinfo_sometime(name, service, &hints, retry, callback_func, context);
+ * later (*callback_func)(rescode, gai_errno, context, name, service, hints, ai_result) is called.
+ */
+typedef void (*gai_sometime_callback)
+ (int, int, void *, const char *, const char *,
+ const struct addrinfo *, const struct addrinfo *);
+extern int getaddrinfo_sometime(const char *, const char *,
+ const struct addrinfo *, int,
+ gai_sometime_callback, void *);
/*
- * Some systems do not support fork() and don't have an alternate
- * threads implementation of ntp_intres. Such systems are limited
- * to using numeric IP addresses.
+ * In gai_sometime_callback routines, the resulting addrinfo list is
+ * only available until the callback returns. To hold on to the list
+ * of addresses after the callback returns, use copy_addrinfo_list():
+ *
+ * struct addrinfo *copy_addrinfo_list(const struct addrinfo *);
*/
-#if defined(VMS) || defined (SYS_VXWORKS) || \
- (!defined(HAVE_WORKING_FORK) && !defined(SYS_WINNT))
-#define NO_INTRES
-#endif
-#endif /* !defined(NTP_INTRES_H) */
+
+/*
+ * you call getnameinfo_sometime(sockaddr, namelen, servlen, flags, callback_func, context);
+ * later (*callback_func)(rescode, gni_errno, sockaddr, flags, name, service, context) is called.
+ */
+typedef void (*gni_sometime_callback)
+ (int, int, sockaddr_u *, int, const char *,
+ const char *, void *);
+extern int getnameinfo_sometime(sockaddr_u *, size_t, size_t, int,
+ gni_sometime_callback, void *);
+#endif /* WORKER */
+
+/* intres_timeout_req() is provided by the client, ntpd or sntp. */
+extern void intres_timeout_req(u_int);
+
+#endif /* NTP_INTRES_H */
diff --git a/include/ntp_io.h b/include/ntp_io.h
index 920fd0d36f708..2cdca71087370 100644
--- a/include/ntp_io.h
+++ b/include/ntp_io.h
@@ -1,13 +1,12 @@
#ifndef NTP_IO_H
#define NTP_IO_H
+
+#include "ntp_workimpl.h"
+
/*
* POSIX says use <fnct.h> to get O_* symbols and
* SEEK_SET symbol form <unistd.h>.
*/
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
@@ -39,6 +38,8 @@
# include <netinet/ip.h>
#endif
+#include "libntp.h" /* This needs Something above for GETDTABLESIZE */
+
/*
* Define FNDELAY and FASYNC using O_NONBLOCK and O_ASYNC if we need
* to (and can). This is here initially for QNX, but may help for
@@ -69,7 +70,6 @@ typedef enum {
MATCH_IFADDR
} nic_rule_match;
-
/*
* NIC rule actions
*/
@@ -80,10 +80,18 @@ typedef enum {
} nic_rule_action;
+SOCKET move_fd(SOCKET fd);
isc_boolean_t get_broadcastclient_flag(void);
-extern int is_ip_address(const char *, sockaddr_u *);
+extern int is_ip_address(const char *, u_short, sockaddr_u *);
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, nic_rule_action action);
+extern void add_nic_rule(nic_rule_match match_type,
+ const char *if_name, int prefixlen,
+ nic_rule_action action);
+#ifndef HAVE_IO_COMPLETION_PORT
+extern void maintain_activefds(int fd, int closing);
+#else
+#define maintain_activefds(f, c) do {} while (0)
+#endif
+
#endif /* NTP_IO_H */
diff --git a/include/ntp_libopts.h b/include/ntp_libopts.h
index c4d6e165f1493..b03b2f66c6129 100644
--- a/include/ntp_libopts.h
+++ b/include/ntp_libopts.h
@@ -10,4 +10,5 @@
extern int ntpOptionProcess(tOptions *pOpts, int argc,
char ** argv);
+extern void ntpOptionPrintVersion(tOptions *, tOptDesc *);
#endif
diff --git a/include/ntp_machine.h b/include/ntp_machine.h
index 69dca68170f22..c5e7248e41153 100644
--- a/include/ntp_machine.h
+++ b/include/ntp_machine.h
@@ -1,24 +1,19 @@
/*
+ * ntp_machine.h
+ *
* Collect all machine dependent idiosyncrasies in one place.
+ *
+ * The functionality formerly in this file is mostly handled by
+ * Autoconf these days.
*/
#ifndef NTP_MACHINE_H
#define NTP_MACHINE_H
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#ifdef TIME_WITH_SYS_TIME
+#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
-# include <time.h>
-#else
-# ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
#endif
+#include <time.h>
#include "ntp_proto.h"
@@ -26,9 +21,6 @@
HEY! CHECK THIS OUT!
- The first half of this file is obsolete, and is only there to help
- reconcile "what went before" with "current behavior".
-
The per-system SYS_* #defins ARE NO LONGER USED, with the temporary
exception of SYS_WINNT.
@@ -40,13 +32,6 @@
/*
-INFO ON NEW KERNEL PLL SYS CALLS
-
- NTP_SYSCALLS_STD - use the "normal" ones
- NTP_SYSCALL_GET - SYS_ntp_gettime id
- NTP_SYSCALL_ADJ - SYS_ntp_adjtime id
- NTP_SYSCALLS_LIBC - ntp_adjtime() and ntp_gettime() are in libc.
-
HOW TO GET IP INTERFACE INFORMATION
Some UNIX V.4 machines implement a sockets library on top of
@@ -80,169 +65,8 @@ MISC
LOCK_PROCESS - Have plock.
*/
-#if !defined(HAVE_NTP_ADJTIME) && defined(HAVE___ADJTIMEX)
-# define ntp_adjtime __adjtimex
-#endif
-
-#if 0
-
-/*
- * IRIX 4.X and IRIX 5.x
- */
-#if defined(SYS_IRIX4)||defined(SYS_IRIX5)
-# define ADJTIME_IS_ACCURATE
-# define LOCK_PROCESS
-#endif
-
-/*
- * Ultrix
- * Note: posix version has NTP_POSIX_SOURCE and HAVE_SIGNALED_IO
- */
-#if defined(SYS_ULTRIX)
-# define S_CHAR_DEFINED
-# define NTP_SYSCALLS_STD
-# define HAVE_MODEM_CONTROL
-#endif
-
-/*
- * AUX
- */
-#if defined(SYS_AUX2) || defined(SYS_AUX3)
-# define NO_SIGNED_CHAR_DECL
-# define LOCK_PROCESS
-# define NTP_POSIX_SOURCE
-/*
- * This requires that _POSIX_SOURCE be forced on the
- * compiler command flag. We can't do it here since this
- * file is included _after_ the system header files and we
- * need to let _them_ know we're POSIX. We do this in
- * compilers/aux3.gcc...
- */
-# define LOG_NTP LOG_LOCAL1
-#endif
-
-/*
- * HPUX
- */
-#if defined(SYS_HPUX)
-# define getdtablesize() sysconf(_SC_OPEN_MAX)
-# define setlinebuf(f) setvbuf(f, NULL, _IOLBF, 0)
-# define NO_SIGNED_CHAR_DECL
-# define LOCK_PROCESS
-#endif
-
-/*
- * BSD/OS 2.0 and above
- */
-#if defined(SYS_BSDI)
-# define USE_FSETOWNCTTY /* this funny system demands a CTTY for FSETOWN */
-#endif
-
-/*
- * FreeBSD 2.0 and above
- */
-#ifdef SYS_FREEBSD
-# define KERNEL_PLL
-#endif
-
-/*
- * Linux
- */
-#if defined(SYS_LINUX)
-# define ntp_adjtime __adjtimex
-#endif
-
-/*
- * PTX
- */
-#if defined(SYS_PTX)
-# define LOCK_PROCESS
-struct timezone { int __0; }; /* unused placebo */
-/*
- * no comment !@!
- */
-typedef unsigned int u_int;
-# ifndef _NETINET_IN_SYSTM_INCLUDED /* i am about to comment... */
-typedef unsigned char u_char;
-typedef unsigned short u_short;
-typedef unsigned long u_long;
-# endif
-#endif
-
-/*
- * UNIX V.4 on and NCR 3000
- */
-#if defined(SYS_SVR4)
-# define STREAM
-# define LOCK_PROCESS
-# define SIZE_RETURNED_IN_BUFFER
-#endif
-
-/*
- * (Univel/Novell) Unixware1 SVR4 on intel x86 processor
- */
-#if defined(SYS_UNIXWARE1)
-/* #define _POSIX_SOURCE */
-# define STREAM
-# define STREAMS
-# undef STEP_SLEW /* TWO step */
-# define LOCK_PROCESS
-# define SIZE_RETURNED_IN_BUFFER
-# include <sys/sockio.h>
-# include <sys/types.h>
-# include <netinet/in_systm.h>
-#endif
-
-/*
- * DomainOS
- */
-#if defined(SYS_DOMAINOS)
-# define NTP_SYSCALLS_STD
-/* older versions of domain/os don't have class D */
-# ifndef IN_CLASSD
-# define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
-# define IN_CLASSD_NET 0xf0000000
-# define IN_CLASSD_NSHIFT 28
-# define IN_CLASSD_HOST 0xfffffff
-# define IN_MULTICAST(i) IN_CLASSD(i)
-# endif
-#endif
-
-/*
- * Fujitsu UXP/V
- */
-#if defined(SYS_UXPV)
-# define LOCK_PROCESS
-# define SIZE_RETURNED_IN_BUFFER
-#endif
-
-
-#endif /* 0 */
-
-/*
- * Define these here for non-Windows NT systems
- * SOCKET and INVALID_SOCKET are native macros
- * on Windows NT and since they have different
- * requirements we use them in the code and
- * make them macros for everyone else
- */
-#ifndef SYS_WINNT
-typedef int SOCKET;
-# define INVALID_SOCKET -1
-# define SOCKET_ERROR -1
-# define socket_errno() (errno)
-# define closesocket(fd) close(fd)
-#else /* SYS_WINNT follows */
-# define socket_errno() (errno = WSAGetLastError())
-#endif
-
int ntp_set_tod (struct timeval *tvp, void *tzp);
-#if defined (SYS_CYGWIN32)
-#include <windows.h>
-#define __int64 long long
-#endif
-
/*casey Tue May 27 15:45:25 SAT 1997*/
#ifdef SYS_VXWORKS
@@ -264,8 +88,6 @@ int ntp_set_tod (struct timeval *tvp, void *tzp);
#define HAVE_RANDOM 1 /* configure does not set this ... */
#define HAVE_SRANDOM 1 /* configure does not set this ... */
-#define NODETACH 1
-
/* vxWorks specific additions to take care of its
* unix (non)complicance
*/
@@ -428,7 +250,6 @@ struct servent *getservbyname (char *name, char *type);
# define IN_CLASSD(i) ((((long)(i))&0xf0000000)==0xe0000000)
# define IN_MULTICAST IN_CLASSD
# define ITIMER_REAL 0
-# define MAXHOSTNAMELEN 64
/* standard structures missing from MPE include files */
@@ -468,71 +289,9 @@ extern char *strdup(const char *);
#include "ERROR: You must define one of the HAVE_xx_NICE defines!"
#endif
-/*
- * use only one tty model - no use in initialising
- * a tty in three ways
- * HAVE_TERMIOS is preferred over HAVE_SYSV_TTYS over HAVE_BSD_TTYS
- */
-
-#ifdef HAVE_TERMIOS_H
-# define HAVE_TERMIOS
-#else
-# ifdef HAVE_TERMIO_H
-# define HAVE_SYSV_TTYS
-# else
-# ifdef HAVE_SGTTY_H
-# define HAVE_BSD_TTYS
-# endif
-# endif
-#endif
-
-#ifdef HAVE_TERMIOS
-# undef HAVE_BSD_TTYS
-# undef HAVE_SYSV_TTYS
-#endif
-
#ifndef HAVE_TIMEGM
extern time_t timegm (struct tm *);
#endif
-#ifdef HAVE_SYSV_TTYS
-# undef HAVE_BSD_TTYS
-#endif
-
-#if !defined(SYS_WINNT) && !defined(VMS) && !defined(SYS_VXWORKS)
-# if !defined(HAVE_SYSV_TTYS) \
- && !defined(HAVE_BSD_TTYS) \
- && !defined(HAVE_TERMIOS)
-#include "ERROR: no tty type defined!"
-# endif
-#endif /* SYS_WINNT || VMS || SYS_VXWORKS*/
-
-#ifdef WORDS_BIGENDIAN
-# define XNTP_BIG_ENDIAN 1
-#else
-# define XNTP_LITTLE_ENDIAN 1
-#endif
-
-/*
- * Byte order woes.
- * This used to be resolved by calling ntohl() and htonl() to swap things
- * around, but this turned out to be quite costly on Vaxes where those
- * things are actual functions. The code now straightens out byte
- * order troubles on its own, with no performance penalty for little
- * end first machines, but at great expense to cleanliness.
- */
-#if !defined(XNTP_BIG_ENDIAN) && !defined(XNTP_LITTLE_ENDIAN)
- /*
- * Pick one or the other.
- */
- BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
-#endif
-
-#if defined(XNTP_BIG_ENDIAN) && defined(XNTP_LITTLE_ENDIAN)
- /*
- * Pick one or the other.
- */
- BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
-#endif
#endif /* NTP_MACHINE_H */
diff --git a/include/ntp_md5.h b/include/ntp_md5.h
index 458962fdab6f5..9f43378f81c58 100644
--- a/include/ntp_md5.h
+++ b/include/ntp_md5.h
@@ -3,27 +3,38 @@
*
* Use the system MD5 if available, otherwise libisc's.
*/
-#if defined HAVE_MD5_H && defined HAVE_MD5INIT
-# include <md5.h>
-#else
-# include "isc/md5.h"
- typedef isc_md5_t MD5_CTX;
-# define MD5Init(c) isc_md5_init(c)
-# define MD5Update(c, p, s) isc_md5_update(c, p, s)
-# define MD5Final(d, c) isc_md5_final((c), (d)) /* swapped */
-#endif
+#ifndef NTP_MD5_H
+#define NTP_MD5_H
+#ifdef OPENSSL
+# include "openssl/evp.h"
+#else /* !OPENSSL follows */
/*
* Provide OpenSSL-alike MD5 API if we're not using OpenSSL
*/
-#ifndef OPENSSL
+# if defined HAVE_MD5_H && defined HAVE_MD5INIT
+# include <md5.h>
+# else
+# include "isc/md5.h"
+ typedef isc_md5_t MD5_CTX;
+# define MD5Init(c) isc_md5_init(c)
+# define MD5Update(c, p, s) isc_md5_update(c, p, s)
+# define MD5Final(d, c) isc_md5_final((c), (d)) /* swapped */
+# endif
+
typedef MD5_CTX EVP_MD_CTX;
# define EVP_get_digestbynid(t) NULL
-# define EVP_DigestInit(c, dt) MD5Init(c)
-# define EVP_DigestUpdate(c, p, s) MD5Update(c, p, s)
+# define EVP_md5(v) NULL
+# define EVP_MD_CTX_init(c)
+# define EVP_MD_CTX_set_flags(c, f)
+# define EVP_DigestInit(c, dt) (MD5Init(c), 1)
+# define EVP_DigestInit_ex(c, dt, i) (MD5Init(c), 1)
+# define EVP_DigestUpdate(c, p, s) MD5Update(c, (const void *)(p), \
+ s)
# define EVP_DigestFinal(c, d, pdl) \
do { \
MD5Final((d), (c)); \
*(pdl) = 16; \
} while (0)
-#endif
+# endif /* !OPENSSL */
+#endif /* NTP_MD5_H */
diff --git a/include/ntp_net.h b/include/ntp_net.h
index d417cea4d3d7a..0577402bfb2ce 100644
--- a/include/ntp_net.h
+++ b/include/ntp_net.h
@@ -23,6 +23,7 @@
#endif
#include "ntp_rfc2553.h"
+#include "ntp_malloc.h"
typedef union {
struct sockaddr sa;
@@ -123,7 +124,7 @@ typedef union {
: sizeof((psau)->sa6))
#define ZERO_SOCK(psau) \
- memset((psau), 0, sizeof(*(psau)))
+ ZERO(*(psau))
/* blast a byte value across sockaddr_u v6 address */
#define MEMSET_ADDR6(psau, v) \
@@ -215,13 +216,9 @@ typedef union {
#define REFCLOCK_ADDR 0x7f7f0000 /* 127.127.0.0 */
#define REFCLOCK_MASK 0xffff0000 /* 255.255.0.0 */
-#ifdef REFCLOCK
#define ISREFCLOCKADR(srcadr) \
(IS_IPV4(srcadr) && \
(SRCADR(srcadr) & REFCLOCK_MASK) == REFCLOCK_ADDR)
-#else
-#define ISREFCLOCKADR(srcadr) (0)
-#endif
/*
* Macro for checking for invalid addresses. This is really, really
diff --git a/include/ntp_prio_q.h b/include/ntp_prio_q.h
new file mode 100644
index 0000000000000..4b5ffca528120
--- /dev/null
+++ b/include/ntp_prio_q.h
@@ -0,0 +1,83 @@
+/* ntp_prio_q.h
+ *
+ * This file contains the structures and function prototypes for the
+ * priority queue implementation used by the discrete event simulator.
+ *
+ * Written By: Sachin Kamboj
+ * University of Delaware
+ * Newark, DE 19711
+ * Copyright (c) 2006
+ */
+
+#ifndef NTP_PRIO_Q_H
+#define NTP_PRIO_Q_H
+
+#include <stddef.h> /* size_t */
+
+/* Structures for storing a priority queue
+ * ---------------------------------------
+ */
+
+typedef struct node {
+ union {
+ struct node *next;
+ double d;
+ } nodeu;
+} node;
+#define node_next nodeu.next
+
+typedef int (*q_order_func)(const void *, const void *);
+
+typedef struct Queue {
+ q_order_func get_order;
+ node * front;
+ int no_of_elements;
+} queue;
+
+
+/* FUNCTION PROTOTYPES
+ * -------------------
+ */
+/* Define a function to create a FIFO queue */
+#define create_queue() create_priority_queue(&get_fifo_order)
+
+void destroy_queue(queue *my_queue);
+void free_node(void *my_node);
+void *next_node(void *my_node);
+int empty(queue *my_queue);
+void *queue_head(queue *my_queue);
+queue *enqueue(queue *my_queue, void *my_node);
+void append_queue(queue *q1, queue *q2);
+void *dequeue(queue *my_queue);
+int get_no_of_elements(queue *my_queue);
+int get_fifo_order(const void *el1, const void *el2);
+
+/*
+ * Preserve original callsite __FILE__ and __LINE__ for these
+ * malloc-like funcs when using MS C runtime debug heap.
+ */
+#ifdef _CRTDBG_MAP_ALLOC
+# define create_priority_queue(order) debug_create_priority_queue(order, __FILE__, __LINE__)
+# define get_node(size) debug_get_node(size, __FILE__, __LINE__)
+#else
+# define create_priority_queue(order) debug_create_priority_queue(order)
+# define get_node(size) debug_get_node(size)
+#endif
+
+queue *debug_create_priority_queue(
+ q_order_func get_order
+#ifdef _CRTDBG_MAP_ALLOC
+ , const char * sourcefile
+ , int line_num
+#endif
+ );
+
+void *debug_get_node(
+ size_t size
+#ifdef _CRTDBG_MAP_ALLOC
+ , const char * sourcefile
+ , int line_num
+#endif
+ );
+
+#endif /* NTP_PRIO_Q_H */
diff --git a/include/ntp_proto.h b/include/ntp_proto.h
index e6e78553305be..1d04b78ab4b23 100644
--- a/include/ntp_proto.h
+++ b/include/ntp_proto.h
@@ -1,10 +1,6 @@
-#ifndef __ntp_proto_h
-#define __ntp_proto_h
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#ifndef NTP_PROTO_H
+#define NTP_PROTO_H
#define NTP_MAXFREQ 500e-6
-#endif /* __ntp_proto_h */
+#endif /* NTP_PROTO_H */
diff --git a/include/ntp_random.h b/include/ntp_random.h
index 3f898312d77e8..fa77f6553ec65 100644
--- a/include/ntp_random.h
+++ b/include/ntp_random.h
@@ -1,6 +1,9 @@
#include <ntp_types.h>
+void ntp_crypto_srandom(void);
+int ntp_crypto_random_buf(void *buf, size_t nbytes);
+
long ntp_random (void);
void ntp_srandom (unsigned long);
void ntp_srandomdev (void);
diff --git a/include/ntp_refclock.h b/include/ntp_refclock.h
index 9d803e4cc4d5b..f92d14cdb890c 100644
--- a/include/ntp_refclock.h
+++ b/include/ntp_refclock.h
@@ -5,44 +5,14 @@
#ifndef NTP_REFCLOCK_H
#define NTP_REFCLOCK_H
-#include "ntp_types.h"
-
-#if defined(HAVE_BSD_TTYS)
-#include <sgtty.h>
-#endif /* HAVE_BSD_TTYS */
-
-#if defined(HAVE_SYSV_TTYS)
-#include <termio.h>
-#endif /* HAVE_SYSV_TTYS */
-
-#if defined(HAVE_TERMIOS)
-# ifdef TERMIOS_NEEDS__SVID3
-# define _SVID3
-# endif
-# include <termios.h>
-# ifdef TERMIOS_NEEDS__SVID3
-# undef _SVID3
-# endif
-#endif
-
#if defined(HAVE_SYS_MODEM_H)
#include <sys/modem.h>
#endif
-#if 0 /* If you need that, include ntp_io.h instead */
-#if defined(STREAM)
-#include <stropts.h>
-#if defined(CLK) /* This is never defined, except perhaps by a system header file */
-#include <sys/clkdefs.h>
-#endif /* CLK */
-#endif /* STREAM */
-#endif
-
+#include "ntp_types.h"
+#include "ntp_tty.h"
#include "recvbuff.h"
-#if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS)
-#define BSD_TTYS
-#endif /* SYSV_TTYS STREAM BSD_TTYS */
#define SAMPLE(x) pp->coderecv = (pp->coderecv + 1) % MAXSTAGE; \
pp->filter[pp->coderecv] = (x); \
@@ -128,10 +98,15 @@ struct refclockio {
to avoid excessive buffer use
due to small bursts
of refclock input data */
- caddr_t srcclock; /* pointer to clock structure */
- int datalen; /* lenth of data */
+ struct peer *srcclock; /* refclock peer */
+ int datalen; /* length of data */
int fd; /* file descriptor */
u_long recvcount; /* count of receive completions */
+ int active; /* nonzero when in use */
+
+#ifdef HAVE_IO_COMPLETION_PORT
+ void * device_context; /* device-related data for i/o subsystem */
+#endif
};
/*
@@ -149,6 +124,10 @@ struct refclockbug {
l_fp times[NCLKBUGTIMES]; /* real times */
};
+#ifdef HAVE_IO_COMPLETION_PORT
+extern HANDLE WaitableIoEventHandle;
+#endif
+
/*
* Structure interface between the reference clock support
* ntp_refclock.c and the driver utility routines
@@ -159,30 +138,18 @@ struct refclockbug {
#define GMT 0 /* I hope nobody sees this */
#define MAXDIAL 60 /* max length of modem dial strings */
-/*
- * Line discipline flags. These require line discipline or streams
- * modules to be installed/loaded in the kernel. If specified, but not
- * installed, the code runs as if unspecified.
- */
-#define LDISC_STD 0x00 /* standard */
-#define LDISC_CLK 0x01 /* tty_clk \n intercept */
-#define LDISC_CLKPPS 0x02 /* tty_clk \377 intercept */
-#define LDISC_ACTS 0x04 /* tty_clk #* intercept */
-#define LDISC_CHU 0x08 /* depredated */
-#define LDISC_PPS 0x10 /* ppsclock, ppsapi */
-#define LDISC_RAW 0x20 /* raw binary */
-#define LDISC_ECHO 0x40 /* enable echo */
-#define LDISC_REMOTE 0x80 /* remote mode */
-#define LDISC_7O1 0x100 /* 7-bit, odd parity for Z3801A */
struct refclockproc {
- struct refclockio io; /* I/O handler structure */
void * unitptr; /* pointer to unit structure */
+ struct refclock * conf; /* refclock_conf[type] */
+ struct refclockio io; /* I/O handler structure */
u_char leap; /* leap/synchronization code */
u_char currentstatus; /* clock status */
u_char lastevent; /* last exception event */
u_char type; /* clock type */
const char *clockdesc; /* clock description */
+ u_long nextaction; /* local activity timeout */
+ void (*action)(struct peer *); /* timeout callback */
char a_lastcode[BMAX]; /* last timecode received */
int lencode; /* length of last timecode */
@@ -234,8 +201,8 @@ struct refclock {
int (*clock_start) (int, struct peer *);
void (*clock_shutdown) (int, struct peer *);
void (*clock_poll) (int, struct peer *);
- void (*clock_control) (int, struct refclockstat *,
- struct refclockstat *, struct peer *);
+ void (*clock_control) (int, const struct refclockstat *,
+ struct refclockstat *, struct peer *);
void (*clock_init) (void);
void (*clock_buginfo) (int, struct refclockbug *, struct peer *);
void (*clock_timer) (int, struct peer *);
@@ -244,31 +211,29 @@ struct refclock {
/*
* Function prototypes
*/
-/*
- * auxiliary PPS interface (implemented by refclock_atom())
- */
-extern int pps_sample (l_fp *);
-extern int io_addclock_simple (struct refclockio *);
extern int io_addclock (struct refclockio *);
extern void io_closeclock (struct refclockio *);
#ifdef REFCLOCK
-extern void refclock_buginfo (sockaddr_u *,
- struct refclockbug *);
-extern void refclock_control (sockaddr_u *,
- struct refclockstat *,
- struct refclockstat *);
+extern void refclock_buginfo(sockaddr_u *,
+ struct refclockbug *);
+extern void refclock_control(sockaddr_u *,
+ const struct refclockstat *,
+ struct refclockstat *);
extern int refclock_open (char *, u_int, u_int);
extern int refclock_setup (int, u_int, u_int);
extern void refclock_timer (struct peer *);
-extern void refclock_transmit (struct peer *);
-extern int refclock_ioctl (int, u_int);
-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 void refclock_transmit(struct peer *);
+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 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 refclock_gtraw (struct recvbuf *, char *, int, l_fp *);
+extern int indicate_refclock_packet(struct refclockio *,
+ struct recvbuf *);
+extern void process_refclock_packet(struct recvbuf *);
#endif /* REFCLOCK */
#endif /* NTP_REFCLOCK_H */
diff --git a/include/ntp_request.h b/include/ntp_request.h
index 7f68894479dd7..c750b7750a7a7 100644
--- a/include/ntp_request.h
+++ b/include/ntp_request.h
@@ -69,7 +69,7 @@
* requested wasn't performed.
*
* 0 - no error
- * 1 - incompatable implementation number
+ * 1 - incompatible implementation number
* 2 - unimplemented request code
* 3 - format error (wrong data items, data size, packet size etc.)
* 4 - no data available (e.g. request for details on unknown peer)
@@ -116,12 +116,18 @@
/*
* union of raw addresses to save space
*/
-union addrun
-{
+union addrun {
struct in6_addr addr6;
struct in_addr addr;
};
+#define MODE7_PAYLOAD_LIM 176
+
+typedef union req_data_u_tag {
+ u_int32 u32[MODE7_PAYLOAD_LIM / sizeof(u_int32)];
+ char data[MODE7_PAYLOAD_LIM]; /* data area (176 byte max) */
+} req_data_u; /* struct conf_peer must fit */
+
/*
* A request packet. These are almost a fixed length.
*/
@@ -132,8 +138,7 @@ struct req_pkt {
u_char request; /* request number */
u_short err_nitems; /* error code/number of data items */
u_short mbz_itemsize; /* item size */
- char data[MAXFILENAME + 48]; /* data area [32 prev](176 byte max) */
- /* struct conf_peer must fit */
+ req_data_u u; /* data area */
l_fp tstamp; /* time stamp, for authentication */
keyid_t keyid; /* (optional) encryption key */
char mac[MAX_MAC_LEN-sizeof(keyid_t)]; /* (optional) auth code */
@@ -150,7 +155,7 @@ struct req_pkt_tail {
};
/* MODE_PRIVATE request packet header length before optional items. */
-#define REQ_LEN_HDR (offsetof(struct req_pkt, data))
+#define REQ_LEN_HDR (offsetof(struct req_pkt, u))
/* MODE_PRIVATE request packet fixed length without MAC. */
#define REQ_LEN_NOMAC (offsetof(struct req_pkt, keyid))
/* MODE_PRIVATE req_pkt_tail minimum size (16 octet digest) */
@@ -162,8 +167,13 @@ struct req_pkt_tail {
* is a maximally sized one. Note that this implementation doesn't
* authenticate responses.
*/
-#define RESP_HEADER_SIZE (offsetof(struct resp_pkt, data))
-#define RESP_DATA_SIZE (500)
+#define RESP_HEADER_SIZE (offsetof(struct resp_pkt, u))
+#define RESP_DATA_SIZE 500
+
+typedef union resp_pkt_u_tag {
+ char data[RESP_DATA_SIZE];
+ u_int32 u32[RESP_DATA_SIZE / sizeof(u_int32)];
+} resp_pkt_u;
struct resp_pkt {
u_char rm_vn_mode; /* response, more, version, mode */
@@ -172,7 +182,7 @@ struct resp_pkt {
u_char request; /* request number */
u_short err_nitems; /* error code/number of data items */
u_short mbz_itemsize; /* item size */
- char data[RESP_DATA_SIZE]; /* data area */
+ resp_pkt_u u; /* data area */
};
@@ -180,11 +190,12 @@ struct resp_pkt {
* Information error codes
*/
#define INFO_OKAY 0
-#define INFO_ERR_IMPL 1 /* incompatable implementation */
+#define INFO_ERR_IMPL 1 /* incompatible implementation */
#define INFO_ERR_REQ 2 /* unknown request code */
#define INFO_ERR_FMT 3 /* format error */
#define INFO_ERR_NODATA 4 /* no data for this request */
#define INFO_ERR_AUTH 7 /* authentication failure */
+#define MAX_INFO_ERR INFO_ERR_AUTH
/*
* Maximum sequence number.
@@ -242,7 +253,7 @@ struct resp_pkt {
*/
/*
- * NTPD request codes go here.
+ * ntpdc -> ntpd request codes go here.
*/
#define REQ_PEER_LIST 0 /* return list of peers */
#define REQ_PEER_LIST_SUM 1 /* return summary info for all peers */
@@ -591,7 +602,7 @@ struct conf_peer {
u_char ttl; /* time to live (multicast) or refclock mode */
u_short unused1; /* unused */
keyid_t keyid; /* key to use for this association */
- char keystr[MAXFILENAME]; /* public key file name*/
+ char keystr[128]; /* public key file name */
u_int v6_flag; /* is this v6 or not */
u_int unused2; /* unused, padding for peeraddr6 */
struct in6_addr peeraddr6; /* ipv6 address to poll */
@@ -668,8 +679,8 @@ struct conf_restrict {
* Structure used for returning monitor data
*/
struct info_monitor_1 {
- u_int32 lasttime; /* last packet from this host */
- u_int32 firsttime; /* first time we received a packet */
+ u_int32 avg_int; /* avg s between packets from this host */
+ u_int32 last_int; /* s since we last received a packet */
u_int32 restr; /* restrict bits (was named lastdrop) */
u_int32 count; /* count of packets received */
u_int32 addr; /* host address V4 style */
@@ -689,8 +700,8 @@ struct info_monitor_1 {
* Structure used for returning monitor data
*/
struct info_monitor {
- u_int32 lasttime; /* last packet from this host */
- u_int32 firsttime; /* first time we received a packet */
+ u_int32 avg_int; /* avg s between packets from this host */
+ u_int32 last_int; /* s since we last received a packet */
u_int32 restr; /* restrict bits (was named lastdrop) */
u_int32 count; /* count of packets received */
u_int32 addr; /* host address */
@@ -732,9 +743,15 @@ struct reset_flags {
#define RESET_FLAG_AUTH 0x20
#define RESET_FLAG_CTL 0x40
-#define RESET_ALLFLAGS \
- (RESET_FLAG_ALLPEERS|RESET_FLAG_IO|RESET_FLAG_SYS \
- |RESET_FLAG_MEM|RESET_FLAG_TIMER|RESET_FLAG_AUTH|RESET_FLAG_CTL)
+#define RESET_ALLFLAGS ( \
+ RESET_FLAG_ALLPEERS | \
+ RESET_FLAG_IO | \
+ RESET_FLAG_SYS | \
+ RESET_FLAG_MEM | \
+ RESET_FLAG_TIMER | \
+ RESET_FLAG_AUTH | \
+ RESET_FLAG_CTL \
+)
/*
* Structure used to return information concerning the authentication
@@ -890,26 +907,26 @@ struct info_kernel {
* interface statistics
*/
struct info_if_stats {
- union addrun unaddr; /* address */
- union addrun unbcast; /* broadcast */
- union addrun unmask; /* mask */
- u_int32 v6_flag; /* is this v6 */
+ union addrun unaddr; /* address */
+ union addrun unbcast; /* broadcast */
+ union addrun unmask; /* mask */
+ u_int32 v6_flag; /* is this v6 */
char name[32]; /* name of interface */
int32 flags; /* interface flags */
int32 last_ttl; /* last TTL specified */
int32 num_mcast; /* No. of IP addresses in multicast socket */
- int32 received; /* number of incoming packets */
+ int32 received; /* number of incoming packets */
int32 sent; /* number of outgoing packets */
int32 notsent; /* number of send failures */
- int32 uptime; /* number of seconds this interface was active */
+ int32 uptime; /* number of seconds this interface was active */
u_int32 scopeid; /* Scope used for Multicasting */
u_int32 ifindex; /* interface index - from system */
- u_int32 ifnum; /* sequential interface number */
- u_int32 peercnt; /* number of peers referencinf this interface - informational only */
+ u_int32 ifnum; /* sequential interface number */
+ u_int32 peercnt; /* number of peers referencinf this interface - informational only */
u_short family; /* Address family */
- u_char ignore_packets; /* Specify whether the packet should be ignored */
- u_char action; /* reason the item is listed */
- int32 _filler0; /* pad to a 64 bit size boundary */
+ u_char ignore_packets; /* Specify whether the packet should be ignored */
+ u_char action; /* reason the item is listed */
+ int32 _filler0; /* pad to a 64 bit size boundary */
};
#define IFS_EXISTS 1 /* just exists */
diff --git a/include/ntp_rfc2553.h b/include/ntp_rfc2553.h
index 8e824f4a240b1..08ccbc415b217 100644
--- a/include/ntp_rfc2553.h
+++ b/include/ntp_rfc2553.h
@@ -68,16 +68,33 @@
#ifndef NTP_RFC2553_H
#define NTP_RFC2553_H
-/*
- * Ensure that we include the configuration file before we check
- * for IPV6
- */
-#include <config.h>
#include <netdb.h>
#include <isc/net.h>
#include "ntp_types.h"
+#include "ntp_malloc.h"
+struct addrinfo *copy_addrinfo_impl(const struct addrinfo *
+#ifdef EREALLOC_CALLSITE /* from ntp_malloc.h */
+ ,
+ const char *, int
+#endif
+ );
+struct addrinfo *copy_addrinfo_list_impl(const struct addrinfo *
+#ifdef EREALLOC_CALLSITE /* from ntp_malloc.h */
+ ,
+ const char *, int
+#endif
+ );
+#ifdef EREALLOC_CALLSITE
+# define copy_addrinfo(l) \
+ copy_addrinfo_impl((l), __FILE__, __LINE__)
+# define copy_addrinfo_list(l) \
+ copy_addrinfo_list_impl((l), __FILE__, __LINE__)
+#else
+# define copy_addrinfo(l) copy_addrinfo_impl(l)
+# define copy_addrinfo_list(l) copy_addrinfo_list_impl(l)
+#endif
/*
* If various macros are not defined we need to define them
diff --git a/include/ntp_select.h b/include/ntp_select.h
index dc60f70b3ae0e..2c0fbeec980f7 100644
--- a/include/ntp_select.h
+++ b/include/ntp_select.h
@@ -2,39 +2,34 @@
* Not all machines define FD_SET in sys/types.h
*/
#ifndef NTP_SELECT_H
-#define NTP_SELECT_H
+#define NTP_SELECT_H /* note: tested by include/l_stdlib.h */
/* Was: (defined(RS6000)||defined(SYS_PTX))&&!defined(_BSD) */
/* Could say: !defined(FD_SET) && defined(HAVE_SYS_SELECT_H) */
+/* except FD_SET can legitimately be a typedef... */
#if defined(HAVE_SYS_SELECT_H) && !defined(_BSD)
-#ifndef SYS_VXWORKS
-#include <sys/select.h>
-#else
-#include <sockLib.h>
-extern int select (int width, fd_set *pReadFds, fd_set *pWriteFds,
- fd_set *pExceptFds, struct timeval *pTimeOut);
-
-#endif
+# ifndef SYS_VXWORKS
+# include <sys/select.h>
+# else
+# include <sockLib.h>
+extern int select(int width, fd_set *pReadFds, fd_set *pWriteFds,
+ fd_set *pExceptFds, struct timeval *pTimeOut);
+# endif
#endif
#if !defined(FD_SET)
-#define NFDBITS 32
-#define FD_SETSIZE 32
-#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
-#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
-#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
-#define FD_ZERO(p) memset((char *)(p), 0, sizeof(*(p)))
+# define NFDBITS 32
+# define FD_SETSIZE 32
+# define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
+# define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
+# define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
+# define FD_ZERO(p) memset((p), 0, sizeof(*(p)))
#endif
#if defined(VMS)
typedef struct {
- unsigned int fds_bits[1];
+ unsigned int fds_bits[1];
} fd_set;
#endif
-#ifdef SYS_WINNT
-/* ports/winnt/libntp/setpriority.c */
-extern void InitSockets(void);
-#endif
-
#endif /* NTP_SELECT_H */
diff --git a/include/ntp_sprintf.h b/include/ntp_sprintf.h
deleted file mode 100644
index a456a89259497..0000000000000
--- a/include/ntp_sprintf.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * Handle ancient char* *s*printf*() systems
- */
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-# define SNPRINTF(x) strlen(snprintf/**/x)
-# define VSNPRINTF(x) strlen(vsnprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-# define SNPRINTF(x) ((size_t)snprintf x)
-# define VSNPRINTF(x) ((size_t)vsnprintf x)
-#endif
diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h
index 8fc237ae03515..7c884fc3274c3 100644
--- a/include/ntp_stdlib.h
+++ b/include/ntp_stdlib.h
@@ -9,43 +9,34 @@
#include <sys/socket.h>
#endif
+#include "declcond.h" /* ntpd uses ntpd/declcond.h, others include/ */
#include "l_stdlib.h"
-#include "ntp_rfc2553.h"
-#include "ntp_types.h"
+#include "ntp_net.h"
+#include "ntp_debug.h"
#include "ntp_malloc.h"
#include "ntp_string.h"
-#include "ntp_net.h"
#include "ntp_syslog.h"
-
-/*
- * Handle gcc __attribute__ if available.
- */
-#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || (defined(__STRICT_ANSI__))
-# define __attribute__(Spec) /* empty */
-# endif
-/* The __-protected variants of `format' and `printf' attributes
- are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __format__ format
-# define __printf__ printf
-# endif
+#ifdef __GNUC__
+#define NTP_PRINTF(fmt, args) __attribute__((__format__(__printf__, fmt, args)))
+#else
+#define NTP_PRINTF(fmt, args)
#endif
-extern int mprintf(const char *, ...)
- __attribute__((__format__(__printf__, 1, 2)));
-extern int mfprintf(FILE *, const char *, ...)
- __attribute__((__format__(__printf__, 2, 3)));
-extern int mvfprintf(FILE *, const char *, va_list)
- __attribute__((__format__(__printf__, 2, 0)));
+extern int mprintf(const char *, ...) NTP_PRINTF(1, 2);
+extern int mfprintf(FILE *, const char *, ...) NTP_PRINTF(2, 3);
+extern int mvfprintf(FILE *, const char *, va_list) NTP_PRINTF(2, 0);
extern int mvsnprintf(char *, size_t, const char *, va_list)
- __attribute__((__format__(__printf__, 3, 0)));
+ NTP_PRINTF(3, 0);
extern int msnprintf(char *, size_t, const char *, ...)
- __attribute__((__format__(__printf__, 3, 4)));
-extern void msyslog(int, const char *, ...)
- __attribute__((__format__(__printf__, 2, 3)));
+ NTP_PRINTF(3, 4);
+extern void msyslog(int, const char *, ...) NTP_PRINTF(2, 3);
+extern void init_logging (const char *, u_int32, int);
+extern int change_logfile (const char *, int);
+extern void setup_logfile (const char *);
+#ifndef errno_to_str
+extern void errno_to_str(int, char *, size_t);
+#endif
/*
* When building without OpenSSL, use a few macros of theirs to
@@ -57,6 +48,19 @@ extern void msyslog(int, const char *, ...)
#define EVP_MAX_MD_SIZE 64 /* longest known is SHA512 */
#endif
+#define SAVE_ERRNO(stmt) \
+ { \
+ int preserved_errno; \
+ \
+ preserved_errno = socket_errno(); \
+ { \
+ stmt \
+ } \
+ errno = preserved_errno; \
+ }
+
+typedef void (*ctrl_c_fn)(void);
+
/* authkeys.c */
extern void auth_delkeys (void);
extern int auth_havekey (keyid_t);
@@ -68,20 +72,31 @@ extern int authreadkeys (const char *);
extern void authtrust (keyid_t, u_long);
extern int authusekey (keyid_t, int, const u_char *);
-extern u_long calyearstart (u_long);
+/*
+ * Based on the NTP timestamp, calculate the NTP timestamp of
+ * the corresponding calendar unit. Use the pivot time to unfold
+ * the NTP timestamp properly, or the current system time if the
+ * pivot pointer is NULL.
+ */
+extern u_int32 calyearstart (u_int32 ntptime, const time_t *pivot);
+extern u_int32 calmonthstart (u_int32 ntptime, const time_t *pivot);
+extern u_int32 calweekstart (u_int32 ntptime, const time_t *pivot);
+extern u_int32 caldaystart (u_int32 ntptime, const time_t *pivot);
+
extern const char *clockname (int);
-extern int clocktime (int, int, int, int, int, u_long, u_long *, u_int32 *);
+extern int clocktime (int, int, int, int, int, u_int32, u_long *, u_int32 *);
extern int ntp_getopt (int, char **, const char *);
extern void init_auth (void);
extern void init_lib (void);
extern struct savekey *auth_findkey (keyid_t);
-extern int auth_moremem (void);
+extern void auth_moremem (int);
+extern void auth_prealloc_symkeys(int);
extern int ymd2yd (int, int, int);
/* a_md5encrypt.c */
extern int MD5authdecrypt (int, u_char *, u_int32 *, int, int);
extern int MD5authencrypt (int, u_char *, u_int32 *, int);
-extern void MD5auth_setkey (keyid_t, int, const u_char *, const int);
+extern void MD5auth_setkey (keyid_t, int, const u_char *, int);
extern u_int32 addr2refid (sockaddr_u *);
/* emalloc.c */
@@ -115,32 +130,37 @@ extern int atoint (const char *, long *);
extern int atouint (const char *, u_long *);
extern int hextoint (const char *, u_long *);
extern char * humanlogtime (void);
-extern char * inttoa (long);
-extern char * mfptoa (u_long, u_long, short);
-extern char * mfptoms (u_long, u_long, short);
+extern char * humantime (time_t);
+extern char * mfptoa (u_int32, u_int32, short);
+extern char * mfptoms (u_int32, u_int32, short);
extern const char * modetoa (int);
-extern const char * eventstr (int);
-extern const char * ceventstr (int);
+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);
+#ifdef KERNEL_PLL
+extern const char * k_st_flags (u_int32);
+#endif
extern char * statustoa (int, int);
-extern const char * sysstatstr (int);
-extern const char * peerstatstr (int);
-extern const char * clockstatstr (int);
extern sockaddr_u * netof (sockaddr_u *);
extern char * numtoa (u_int32);
extern char * numtohost (u_int32);
-extern char * socktoa (const sockaddr_u *);
-extern char * socktohost (const sockaddr_u *);
+extern const char * socktoa (const sockaddr_u *);
+extern const char * sockporttoa(const sockaddr_u *);
+extern u_short sock_hash (const sockaddr_u *);
+extern int sockaddr_masktoprefixlen(const sockaddr_u *);
+extern const char * socktohost (const sockaddr_u *);
extern int octtoint (const char *, u_long *);
extern u_long ranp2 (int);
-extern char * refnumtoa (sockaddr_u *);
-extern int tsftomsu (u_long, int);
-extern char * uinttoa (u_long);
+extern const char *refnumtoa (sockaddr_u *);
+extern const char *refid_str (u_int32, int);
extern int decodenetnum (const char *, sockaddr_u *);
extern const char * FindConfig (const char *);
extern void signal_no_reset (int, RETSIGTYPE (*func)(int));
+extern void set_ctrl_c_hook (ctrl_c_fn);
extern void getauthkeys (const char *);
extern void auth_agekeys (void);
@@ -150,11 +170,6 @@ extern void rereadkeys (void);
* Variable declarations for libntp.
*/
-/*
- * Defined by any program.
- */
-extern volatile int debug; /* debugging flag */
-
/* authkeys.c */
extern u_long authkeynotfound; /* keys not found */
extern u_long authkeylookups; /* calls to lookup keys */
@@ -170,9 +185,10 @@ extern int authnumfreekeys;
* The key cache. We cache the last key we looked at here.
*/
extern keyid_t cache_keyid; /* key identifier */
-extern u_char * cache_key; /* key pointer */
extern int cache_type; /* key type */
-extern u_int cache_keylen; /* key length */
+extern u_char * cache_secret; /* secret */
+extern u_short cache_secretsize; /* secret octets */
+extern u_short cache_flags; /* KEY_ bit flags */
/* getopt.c */
extern char * ntp_optarg; /* global argument pointer */
@@ -203,6 +219,27 @@ extern int keytype_from_text (const char *, size_t *);
extern const char *keytype_name (int);
extern char * getpass_keytype (int);
+/* strl-obsd.c */
+#ifndef HAVE_STRLCPY /* + */
+/*
+ * Copy src to string dst of size siz. At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz == 0).
+ * Returns strlen(src); if retval >= siz, truncation occurred.
+ */
+extern size_t strlcpy(char *dst, const char *src, size_t siz);
+#endif
+#ifndef HAVE_STRLCAT /* + */
+/*
+ * Appends src to string dst of size siz (unlike strncat, siz is the
+ * full size of dst, not space left). At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
+ * If retval >= siz, truncation occurred.
+ */
+extern size_t strlcat(char *dst, const char *src, size_t siz);
+#endif
+
+
/* lib/isc/win32/strerror.c
*
@@ -219,7 +256,10 @@ extern char * ntp_strerror (int e);
#endif
/* systime.c */
-extern double sys_tick; /* adjtime() resolution */
+extern double sys_tick; /* tick size or time to read */
+extern double measured_tick; /* non-overridable sys_tick */
+extern double sys_fuzz; /* min clock read latency */
+extern int trunc_os_clock; /* sys_tick > measured_tick */
/* version.c */
extern const char *Version; /* version declaration */
diff --git a/include/ntp_string.h b/include/ntp_string.h
index aab7084b0536e..9b62ec2d97e11 100644
--- a/include/ntp_string.h
+++ b/include/ntp_string.h
@@ -1,13 +1,9 @@
/*
- * Define string ops: strchr strrchr memcmp memmove memset
+ * Define string ops: strchr strrchr memcmp memmove memset
*/
-#ifndef _ntp_string_h
-#define _ntp_string_h
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#ifndef NTP_STRING_H
+#define NTP_STRING_H
#ifdef HAVE_MEMORY_H
# include <memory.h>
@@ -21,20 +17,6 @@
# include <bstring.h>
#endif
-#ifndef STDC_HEADERS
-# ifndef HAVE_STRCHR
-# include <strings.h>
-# define strchr index
-# define strrchr rindex
-# endif
-# ifndef __GNUC__
-char *strchr(), *strrchr();
-# endif
-# ifndef HAVE_MEMCPY
-# define NTP_NEED_BOPS
-# endif
-#endif /* STDC_HEADERS */
-
#ifdef NTP_NEED_BOPS
#ifdef HAVE_STRINGS_H
@@ -52,4 +34,4 @@ void ntp_memset (char *, int, int);
ntp_memset((char *)(a), x, c)
#endif /* NTP_NEED_BOPS */
-#endif /* _ntp_string_h */
+#endif /* NTP_STRING_H */
diff --git a/include/ntp_syscall.h b/include/ntp_syscall.h
index c255cee46b5fc..d1ce03ea90a25 100644
--- a/include/ntp_syscall.h
+++ b/include/ntp_syscall.h
@@ -6,33 +6,28 @@
#ifndef NTP_SYSCALL_H
#define NTP_SYSCALL_H
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#ifdef HAVE_SYS_TIMEX_H
# include <sys/timex.h>
#endif
#ifndef NTP_SYSCALLS_LIBC
-#ifdef NTP_SYSCALLS_STD
-# define ntp_adjtime(t) syscall(SYS_ntp_adjtime, (t))
-# define ntp_gettime(t) syscall(SYS_ntp_gettime, (t))
-#else /* !NTP_SYSCALLS_STD */
-# ifdef HAVE___ADJTIMEX
-extern int __adjtimex (struct timex *);
-
-# define ntp_adjtime(t) __adjtimex((t))
+# ifdef NTP_SYSCALLS_STD
+# define ntp_adjtime(t) syscall(SYS_ntp_adjtime, (t))
+# define ntp_gettime(t) syscall(SYS_ntp_gettime, (t))
+# else /* !NTP_SYSCALLS_STD */
+# ifdef HAVE_NTP_ADJTIME
+extern int ntp_adjtime (struct timex *);
-#ifndef HAVE_STRUCT_NTPTIMEVAL
+# ifndef HAVE_STRUCT_NTPTIMEVAL
struct ntptimeval
{
- struct timeval time; /* current time (ro) */
- long int maxerror; /* maximum error (us) (ro) */
- long int esterror; /* estimated error (us) (ro) */
+ struct timeval time; /* current time (ro) */
+ long int maxerror; /* maximum error (us) (ro) */
+ long int esterror; /* estimated error (us) (ro) */
};
-#endif
+# endif
+# ifndef HAVE_NTP_GETTIME
static inline int
ntp_gettime(
struct ntptimeval *ntv
@@ -41,24 +36,21 @@ ntp_gettime(
struct timex tntx;
int result;
- tntx.modes = 0;
- result = __adjtimex (&tntx);
+ ZERO(tntx);
+ result = ntp_adjtime(&tntx);
ntv->time = tntx.time;
ntv->maxerror = tntx.maxerror;
ntv->esterror = tntx.esterror;
-#ifdef NTP_API
-# if NTP_API > 3
+# ifdef NTP_API
+# if NTP_API > 3
ntv->tai = tntx.tai;
-# endif
-#endif
- return(result);
+# endif
+# endif
+ return result;
}
-# else /* !HAVE__ADJTIMEX */
-# ifdef HAVE___NTP_GETTIME
-# define ntp_gettime(t) __ntp_gettime((t))
-# endif
-# endif /* !HAVE_ADJTIMEX */
-#endif /* !NTP_SYSCALLS_STD */
-#endif /* !NTP_SYSCALLS_LIBC */
+# endif /* !HAVE_NTP_GETTIME */
+# endif /* !HAVE_NTP_ADJTIME */
+# endif /* !NTP_SYSCALLS_STD */
+#endif /* !NTP_SYSCALLS_LIBC */
-#endif /* NTP_SYSCALL_H */
+#endif /* NTP_SYSCALL_H */
diff --git a/include/ntp_syslog.h b/include/ntp_syslog.h
index 12f78292b1eab..a0152b53d9ca3 100644
--- a/include/ntp_syslog.h
+++ b/include/ntp_syslog.h
@@ -7,19 +7,23 @@
#include <ntp_types.h> /* u_int32 type */
-# ifdef VMS
+#ifdef VMS
extern void msyslog();
-# else
-# ifndef SYS_VXWORKS
-# include <syslog.h>
-# endif
-# endif /* VMS */
-# include <stdio.h>
+#else
+# ifndef SYS_VXWORKS
+# include <syslog.h>
+# endif
+#endif /* VMS */
+#include <stdio.h>
-extern int syslogit;
-extern int msyslog_term; /* duplicate to stdout/err */
-extern FILE *syslog_file; /* if syslogit is FALSE, log to
+extern int syslogit;
+extern int msyslog_term; /* duplicate to stdout/err */
+extern int msyslog_term_pid;
+extern int msyslog_include_timestamp;
+extern FILE * syslog_file; /* if syslogit is FALSE, log to
this file and not syslog */
+extern char * syslog_fname;
+extern char * syslog_abs_fname;
#if defined(VMS) || defined (SYS_VXWORKS)
#define LOG_EMERG 0 /* system is unusable */
@@ -69,6 +73,13 @@ extern FILE *syslog_file; /* if syslogit is FALSE, log to
#define NLOG_SYNCSTATIST 0x00008000 /* sync statistics output */
extern u_int32 ntp_syslogmask;
-#define NLOG(_X_) if (ntp_syslogmask & (_X_))
+
+#define NLOG(bits) if (ntp_syslogmask & (bits))
+
+#define LOGIF(nlog_suffix, msl_args) \
+do { \
+ NLOG(NLOG_##nlog_suffix) /* like "if (...) */ \
+ msyslog msl_args; \
+} while (FALSE)
#endif /* NTP_SYSLOG_H */
diff --git a/include/ntp_tty.h b/include/ntp_tty.h
index 9833119238f4e..6dc48b6c71f19 100644
--- a/include/ntp_tty.h
+++ b/include/ntp_tty.h
@@ -1,10 +1,31 @@
/*
* ntp_tty.h - header file for serial lines handling
*/
-
#ifndef NTP_TTY_H
#define NTP_TTY_H
+/*
+ * use only one tty model - no use in initialising
+ * a tty in three ways
+ * HAVE_TERMIOS is preferred over HAVE_SYSV_TTYS over HAVE_BSD_TTYS
+ */
+
+#if defined(HAVE_TERMIOS_H) || defined(HAVE_SYS_TERMIOS_H)
+# define HAVE_TERMIOS
+#elif defined(HAVE_TERMIO_H)
+# define HAVE_SYSV_TTYS
+#elif defined(HAVE_SGTTY_H)
+# define HAVE_BSD_TTYS
+#endif
+
+#if !defined(VMS) && !defined(SYS_VXWORKS)
+# if !defined(HAVE_SYSV_TTYS) \
+ && !defined(HAVE_BSD_TTYS) \
+ && !defined(HAVE_TERMIOS)
+#include "ERROR: no tty type defined!"
+# endif
+#endif /* !VMS && !SYS_VXWORKS*/
+
#if defined(HAVE_BSD_TTYS)
#include <sgtty.h>
#define TTY struct sgttyb
@@ -34,22 +55,49 @@
#endif /* HAVE_SYSV_TTYS */
#if defined(HAVE_TERMIOS)
-# ifdef TERMIOS_NEEDS__SVID3
-# define _SVID3
-# endif
-# include <termios.h>
-# ifdef TERMIOS_NEEDS__SVID3
-# undef _SVID3
+# if defined(HAVE_TERMIOS_H)
+# ifdef TERMIOS_NEEDS__SVID3
+# define _SVID3
+# endif
+# include <termios.h>
+# ifdef TERMIOS_NEEDS__SVID3
+# undef _SVID3
+# endif
+# elif defined(HAVE_SYS_TERMIOS_H)
+# include <sys/termios.h>
# endif
-#define TTY struct termios
+# define TTY struct termios
#endif
#if defined(HAVE_SYS_MODEM_H)
#include <sys/modem.h>
#endif
-#if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS)
-#define BSD_TTYS
-#endif /* SYSV_TTYS STREAM BSD_TTYS */
+/*
+ * Line discipline flags. The depredated ones required line discipline
+ * or streams modules to be installed/loaded in the kernel and are now
+ * ignored. Leave the LDISC_CLK and other deprecated symbols defined
+ * until 2013 or 2014 to avoid complicating the use of newer drivers on
+ * older ntpd, which is often as easy as dropping in the refclock *.c.
+ */
+#define LDISC_STD 0x000 /* standard */
+#define LDISC_CLK 0x001 /* depredated tty_clk \n */
+#define LDISC_CLKPPS 0x002 /* depredated tty_clk \377 */
+#define LDISC_ACTS 0x004 /* depredated tty_clk #* */
+#define LDISC_CHU 0x008 /* depredated */
+#define LDISC_PPS 0x010 /* depredated */
+#define LDISC_RAW 0x020 /* raw binary */
+#define LDISC_ECHO 0x040 /* enable echo */
+#define LDISC_REMOTE 0x080 /* remote mode */
+#define LDISC_7O1 0x100 /* 7-bit, odd parity for Z3801A */
+
+/* function prototypes for ntp_tty.c */
+#if !defined(SYS_VXWORKS) && !defined(SYS_WINNT)
+# if defined(HAVE_TERMIOS) || defined(HAVE_SYSV_TTYS) || \
+ defined(HAVE_BSD_TTYS)
+extern int ntp_tty_setup(int, u_int, u_int);
+extern int ntp_tty_ioctl(int, u_int);
+# endif
+#endif
#endif /* NTP_TTY_H */
diff --git a/include/ntp_types.h b/include/ntp_types.h
index c975a08163cce..1beb16647a660 100644
--- a/include/ntp_types.h
+++ b/include/ntp_types.h
@@ -1,5 +1,10 @@
/*
* ntp_types.h - defines how int32 and u_int32 are treated.
+ *
+ * New style: Make sure C99 fixed width integer types are available:
+ * intN_t and uintN_t
+
+ * Old style: defines how int32 and u_int32 are treated.
* For 64 bit systems like the DEC Alpha, they have to be defined
* as int and u_int.
* For 32 bit systems, define them as long and u_long
@@ -8,8 +13,15 @@
#define NTP_TYPES_H
#include <sys/types.h>
+#if defined(HAVE_INTTYPES_H)
+# include <inttypes.h>
+#elif defined(HAVE_STDINT_H)
+# include <stdint.h>
+#endif
+
#include "ntp_machine.h"
+
#ifndef TRUE
# define TRUE 1
#endif
@@ -33,7 +45,10 @@
* used to quiet compiler warnings
*/
#ifndef UNUSED_ARG
-#define UNUSED_ARG(arg) ((void)(arg))
+#define UNUSED_ARG(arg) ((void)(arg))
+#endif
+#ifndef UNUSED_LOCAL
+#define UNUSED_LOCAL(arg) ((void)(arg))
#endif
/*
@@ -48,15 +63,21 @@
#if defined(VMS)
#include <socket.h>
typedef unsigned int u_int;
-/*
- * Note: VMS DECC has long == int (even on __alpha),
- * so the distinction below doesn't matter
- */
#endif /* VMS */
-#if (SIZEOF_INT == 4)
-# ifndef int32
-# define int32 int
+#ifdef HAVE_UINT32_T
+# ifndef HAVE_INT32
+ typedef int32_t int32;
+# endif
+# ifndef HAVE_U_INT32
+ typedef uint32_t u_int32;
+# if defined(UINT32_MAX) && !defined(U_INT32_MAX)
+# define U_INT32_MAX UINT32_MAX
+# endif
+# endif
+#elif (SIZEOF_INT == 4)
+# if !defined(HAVE_INT32) && !defined(int32)
+ typedef int int32;
# ifndef INT32_MIN
# define INT32_MIN INT_MIN
# endif
@@ -64,16 +85,16 @@ typedef unsigned int u_int;
# define INT32_MAX INT_MAX
# endif
# endif
-# ifndef u_int32
-# define u_int32 unsigned int
-# ifndef U_INT32_MAX
+# if !defined(HAVE_U_INT32) && !defined(u_int32)
+ typedef unsigned u_int32;
+# if defined(UINT_MAX) && !defined(U_INT32_MAX)
# define U_INT32_MAX UINT_MAX
# endif
# endif
-#else /* not sizeof(int) == 4 */
+#else /* SIZEOF_INT != 4 */
# if (SIZEOF_LONG == 4)
-# ifndef int32
-# define int32 long
+# if !defined(HAVE_INT32) && !defined(int32)
+ typedef long int32;
# ifndef INT32_MIN
# define INT32_MIN LONG_MIN
# endif
@@ -81,28 +102,154 @@ typedef unsigned int u_int;
# define INT32_MAX LONG_MAX
# endif
# endif
-# ifndef u_int32
-# define u_int32 unsigned long
-# ifndef U_INT32_MAX
+# if !defined(HAVE_U_INT32) && !defined(u_int32)
+ typedef unsigned long u_int32;
+# if defined(ULONG_MAX) && !defined(U_INT32_MAX)
# define U_INT32_MAX ULONG_MAX
# endif
# endif
-# else /* not sizeof(long) == 4 */
+# else /* SIZEOF_LONG != 4 */
# include "Bletch: what's 32 bits on this machine?"
-# endif /* not sizeof(long) == 4 */
-#endif /* not sizeof(int) == 4 */
+# endif
+#endif /* !HAVE_UINT32_T && SIZEOF_INT != 4 */
+
+#ifndef U_INT32_MAX
+# define U_INT32_MAX 0xffffffff
+#endif
+
+
+/*
+ * Ugly dance to find out if we have 64bit integer type.
+ */
+#if !defined(HAVE_INT64)
+
+/* assume best for now, fix if frustrated later. */
+# define HAVE_INT64
+# define HAVE_U_INT64
+
+/* now check the cascade. Feel free to add things. */
+# ifdef INT64_MAX
+
+typedef int64_t int64;
+typedef uint64_t u_int64;
+
+# elif SIZEOF_LONG == 8
+
+typedef long int64;
+typedef unsigned long u_int64;
+
+# elif SIZEOF_LONG_LONG == 8
+
+typedef long long int64;
+typedef unsigned long long u_int64;
+
+# else
-typedef u_char ntp_u_int8_t;
-typedef u_short ntp_u_int16_t;
-typedef u_int32 ntp_u_int32_t;
+/* no 64bit scalar, give it up. */
+# undef HAVE_INT64
+# undef HAVE_U_INT64
+
+# endif
+
+#endif
+
+/*
+ * and here the trouble starts: We need a representation with more than
+ * 64 bits. If a scalar of that size is not available, we need a struct
+ * that holds the value in split representation.
+ *
+ * To ease the usage a bit, we alwys use a union that is in processor
+ * byte order and might or might not contain a 64bit scalar.
+ */
+
+#if SIZEOF_SHORT != 2
+# error short is not 2 bytes -- what is 16 bit integer on this target?
+#endif
+
+typedef union {
+# ifdef WORDS_BIGENDIAN
+ struct {
+ int16_t hh; uint16_t hl; uint16_t lh; uint16_t ll;
+ } w_s;
+ struct {
+ uint16_t hh; uint16_t hl; uint16_t lh; uint16_t ll;
+ } W_s;
+ struct {
+ int32 hi; u_int32 lo;
+ } d_s;
+ struct {
+ u_int32 hi; u_int32 lo;
+ } D_s;
+# else
+ struct {
+ uint16_t ll; uint16_t lh; uint16_t hl; int16_t hh;
+ } w_s;
+ struct {
+ uint16_t ll; uint16_t lh; uint16_t hl; uint16_t hh;
+ } W_s;
+ struct {
+ u_int32 lo; int32 hi;
+ } d_s;
+ struct {
+ u_int32 lo; u_int32 hi;
+ } D_s;
+# endif
+
+# ifdef HAVE_INT64
+ int64 q_s; /* signed quad scalar */
+ u_int64 Q_s; /* unsigned quad scalar */
+# endif
+} vint64; /* variant int 64 */
+
+
+typedef uint8_t ntp_u_int8_t;
+typedef uint16_t ntp_u_int16_t;
+typedef uint32_t ntp_u_int32_t;
typedef struct ntp_uint64_t { u_int32 val[2]; } ntp_uint64_t;
-typedef unsigned short associd_t; /* association ID */
+typedef uint16_t associd_t; /* association ID */
+#define ASSOCID_MAX USHRT_MAX
typedef u_int32 keyid_t; /* cryptographic key ID */
+#define KEYID_T_MAX (0xffffffff)
typedef u_int32 tstamp_t; /* NTP seconds timestamp */
/*
+ * Cloning malloc()'s behavior of always returning pointers suitably
+ * aligned for the strictest alignment requirement of any type is not
+ * easy to do portably, as the maximum alignment required is not
+ * exposed. Use the size of a union of the types known to represent the
+ * strictest alignment on some platform.
+ */
+typedef union max_alignment_tag {
+ double d;
+} max_alignment;
+
+#define MAXALIGN sizeof(max_alignment)
+#define ALIGN_UNITS(sz) (((sz) + MAXALIGN - 1) / MAXALIGN)
+#define ALIGNED_SIZE(sz) (MAXALIGN * ALIGN_UNITS(sz))
+#define INC_ALIGNED_PTR(b, m) ((void *)aligned_ptr((void *)(b), m))
+
+static inline
+max_alignment *
+aligned_ptr(
+ max_alignment * base,
+ size_t minsize
+ )
+{
+ return base + ALIGN_UNITS((minsize < 1) ? 1 : minsize);
+}
+
+/*
+ * Macro to use in otherwise-empty source files to comply with ANSI C
+ * requirement that each translation unit (source file) contain some
+ * declaration. This has commonly been done by declaring an unused
+ * global variable of type int or char. An extern reference to exit()
+ * serves the same purpose without bloat.
+ */
+#define NONEMPTY_TRANSLATION_UNIT extern void exit(int);
+
+/*
* On Unix struct sock_timeval is equivalent to struct timeval.
* On Windows built with 64-bit time_t, sock_timeval.tv_sec is a long
* as required by Windows' socket() interface timeout argument, while
@@ -121,10 +268,21 @@ typedef u_int32 tstamp_t; /* NTP seconds timestamp */
* instead of refclock_open(), tty_open() is equivalent to open() on
* Unix and implemented in the Windows port similarly to
* refclock_open().
+ * Similarly, the termios emulation in the Windows code needs to know
+ * about serial ports being closed, while the Posix systems do not.
*/
#ifndef SYS_WINNT
-#define tty_open(f, a, m) open(f, a, m)
+# define tty_open(f, a, m) open(f, a, m)
+# define closeserial(fd) close(fd)
+# define closesocket(fd) close(fd)
+typedef int SOCKET;
+# define INVALID_SOCKET (-1)
+# define SOCKET_ERROR (-1)
+# define socket_errno() (errno)
+#else /* SYS_WINNT follows */
+# define socket_errno() (errno = WSAGetLastError())
#endif
+
#endif /* NTP_TYPES_H */
diff --git a/include/ntp_unixtime.h b/include/ntp_unixtime.h
index 8c43f1cea0372..eaa8b1ed4545f 100644
--- a/include/ntp_unixtime.h
+++ b/include/ntp_unixtime.h
@@ -1,13 +1,12 @@
/*
- * ntp_unixtime.h - contains constants and macros for converting between
- * NTP time stamps (l_fp) and Unix times (struct timeval)
+ * ntp_unixtime.h - much of what was here is now in timevalops.h
*/
-#include "ntp_types.h"
+#ifndef NTP_UNIXTIME_H
+#define NTP_UNIXTIME_H
-#ifdef SIM
-#include "ntpsim.h"
-#endif
+#include "ntp_types.h" /* picks up time.h via ntp_machine.h */
+#include "ntp_calendar.h"
#ifdef SIM
# define GETTIMEOFDAY(a, b) (node_gettime(&ntp_node, a))
@@ -19,7 +18,7 @@
# if defined(HAVE_SYS_TIMERS_H) && defined(HAVE_GETCLOCK)
# include <sys/timers.h>
int getclock (int clock_type, struct timespec *tp);
-/* Don't #define GETTIMEOFDAY because we shouldn't be using it in this case. */
+# define GETTIMEOFDAY(a, b) (gettimeofday(a, b))
# define SETTIMEOFDAY(a, b) (settimeofday(a, b))
# else /* not (HAVE_SYS_TIMERS_H && HAVE_GETCLOCK) */
# ifdef SYSV_TIMEOFDAY
@@ -39,100 +38,10 @@ int getclock (int clock_type, struct timespec *tp);
/*
* Time of day conversion constant. Ntp's time scale starts in 1900,
- * Unix in 1970.
- */
-#define JAN_1970 0x83aa7e80 /* 2208988800 1970 - 1900 in seconds */
-
-/*
- * These constants are used to round the time stamps computed from
- * a struct timeval to the microsecond (more or less). This keeps
- * things neat.
- */
-#define TS_MASK 0xfffff000 /* mask to usec, for time stamps */
-#define TS_ROUNDBIT 0x00000800 /* round at this bit */
-
-
-/*
- * Convert usec to a time stamp fraction. If you use this the program
- * must include the following declarations:
- */
-extern u_long ustotslo[];
-extern u_long ustotsmid[];
-extern u_long ustotshi[];
-
-#define TVUTOTSF(tvu, tsf) \
- (tsf) = ustotslo[(tvu) & 0xff] \
- + ustotsmid[((tvu) >> 8) & 0xff] \
- + ustotshi[((tvu) >> 16) & 0xf]
-
-/*
- * Convert a struct timeval to a time stamp.
- */
-#define TVTOTS(tv, ts) \
- do { \
- (ts)->l_ui = (u_long)(tv)->tv_sec; \
- TVUTOTSF((tv)->tv_usec, (ts)->l_uf); \
- } while(0)
-
-#define sTVTOTS(tv, ts) \
- do { \
- int isneg = 0; \
- long usec; \
- (ts)->l_ui = (tv)->tv_sec; \
- usec = (tv)->tv_usec; \
- if (((tv)->tv_sec < 0) || ((tv)->tv_usec < 0)) { \
- usec = -usec; \
- (ts)->l_ui = -(ts)->l_ui; \
- isneg = 1; \
- } \
- TVUTOTSF(usec, (ts)->l_uf); \
- if (isneg) { \
- L_NEG((ts)); \
- } \
- } while(0)
-
-/*
- * TV_SHIFT is used to turn the table result into a usec value. To round,
- * add in TV_ROUNDBIT before shifting
- */
-#define TV_SHIFT 3
-#define TV_ROUNDBIT 0x4
-
-
-/*
- * Convert a time stamp fraction to microseconds. The time stamp
- * fraction is assumed to be unsigned. To use this in a program, declare:
- */
-extern long tstouslo[];
-extern long tstousmid[];
-extern long tstoushi[];
-
-#define TSFTOTVU(tsf, tvu) \
- (tvu) = (tstoushi[((tsf) >> 24) & 0xff] \
- + tstousmid[((tsf) >> 16) & 0xff] \
- + tstouslo[((tsf) >> 9) & 0x7f] \
- + TV_ROUNDBIT) >> TV_SHIFT
-/*
- * Convert a time stamp to a struct timeval. The time stamp
- * has to be positive.
- */
-#define TSTOTV(ts, tv) \
- do { \
- (tv)->tv_sec = (ts)->l_ui; \
- TSFTOTVU((ts)->l_uf, (tv)->tv_usec); \
- if ((tv)->tv_usec == 1000000) { \
- (tv)->tv_sec++; \
- (tv)->tv_usec = 0; \
- } \
- } while (0)
-
-/*
- * Convert milliseconds to a time stamp fraction. This shouldn't be
- * here, but it is convenient since the guys who use the definition will
- * often be including this file anyway.
+ * Unix in 1970. The value is 1970 - 1900 in seconds, 0x83aa7e80 or
+ * 2208988800. This is larger than 32-bit INT_MAX, so unsigned
+ * type is forced.
*/
-extern u_long msutotsflo[];
-extern u_long msutotsfhi[];
+#define JAN_1970 ((u_int)NTP_TO_UNIX_DAYS * (u_int)SECSPERDAY)
-#define MSUTOTSF(msu, tsf) \
- (tsf) = msutotsfhi[((msu) >> 5) & 0x1f] + msutotsflo[(msu) & 0x1f]
+#endif /* !defined(NTP_UNIXTIME_H) */
diff --git a/include/ntp_worker.h b/include/ntp_worker.h
new file mode 100644
index 0000000000000..f7e8d5be70865
--- /dev/null
+++ b/include/ntp_worker.h
@@ -0,0 +1,162 @@
+/*
+ * ntp_worker.h
+ */
+
+#ifndef NTP_WORKER_H
+#define NTP_WORKER_H
+
+#include "ntp_workimpl.h"
+
+#ifdef WORKER
+# if defined(WORK_THREAD) && defined(WORK_PIPE)
+# ifdef HAVE_SEMAPHORE_H
+# include <semaphore.h>
+# endif
+# endif
+#include "ntp_stdlib.h"
+
+/* #define TEST_BLOCKING_WORKER */ /* ntp_config.c ntp_intres.c */
+
+typedef enum blocking_work_req_tag {
+ BLOCKING_GETNAMEINFO,
+ BLOCKING_GETADDRINFO,
+} blocking_work_req;
+
+typedef void (*blocking_work_callback)(blocking_work_req, void *, size_t, void *);
+
+typedef enum blocking_magic_sig_e {
+ BLOCKING_REQ_MAGIC = 0x510c7ecf,
+ BLOCKING_RESP_MAGIC = 0x510c7e54,
+} blocking_magic_sig;
+
+/*
+ * The same header is used for both requests to and responses from
+ * the child. In the child, done_func and context are opaque.
+ */
+typedef struct blocking_pipe_header_tag {
+ size_t octets;
+ blocking_magic_sig magic_sig;
+ blocking_work_req rtype;
+ u_int child_idx;
+ blocking_work_callback done_func;
+ void * context;
+} blocking_pipe_header;
+
+# ifdef WORK_THREAD
+# ifdef WORK_PIPE
+typedef pthread_t * thr_ref;
+typedef sem_t * sem_ref;
+# else
+typedef HANDLE thr_ref;
+typedef HANDLE sem_ref;
+# endif
+# endif
+
+/*
+ *
+ */
+#ifdef WORK_FORK
+typedef struct blocking_child_tag {
+ int reusable;
+ int pid;
+ int req_write_pipe; /* parent */
+ int resp_read_pipe;
+ void * resp_read_ctx;
+ int req_read_pipe; /* child */
+ int resp_write_pipe;
+ int ispipe;
+} blocking_child;
+#elif defined(WORK_THREAD)
+typedef struct blocking_child_tag {
+/*
+ * blocking workitems and blocking_responses are dynamically-sized
+ * one-dimensional arrays of pointers to blocking worker requests and
+ * responses.
+ */
+ int reusable;
+ thr_ref thread_ref;
+ u_int thread_id;
+ blocking_pipe_header * volatile * volatile
+ workitems;
+ volatile size_t workitems_alloc;
+ size_t next_workitem; /* parent */
+ size_t next_workeritem; /* child */
+ blocking_pipe_header * volatile * volatile
+ responses;
+ volatile size_t responses_alloc;
+ size_t next_response; /* child */
+ size_t next_workresp; /* parent */
+ /* event handles / sem_t pointers */
+ /* sem_ref child_is_blocking; */
+ sem_ref blocking_req_ready;
+ sem_ref wake_scheduled_sleep;
+#ifdef WORK_PIPE
+ int resp_read_pipe; /* parent */
+ int resp_write_pipe;/* child */
+ int ispipe;
+ void * resp_read_ctx; /* child */
+#else
+ sem_ref blocking_response_ready;
+#endif
+} blocking_child;
+
+#endif /* WORK_THREAD */
+
+extern blocking_child ** blocking_children;
+extern size_t blocking_children_alloc;
+extern int worker_per_query; /* boolean */
+extern int intres_req_pending;
+
+extern u_int available_blocking_child_slot(void);
+extern int queue_blocking_request(blocking_work_req, void *,
+ size_t, blocking_work_callback,
+ void *);
+extern int queue_blocking_response(blocking_child *,
+ blocking_pipe_header *, size_t,
+ const blocking_pipe_header *);
+extern void process_blocking_resp(blocking_child *);
+extern int send_blocking_req_internal(blocking_child *,
+ blocking_pipe_header *,
+ void *);
+extern int send_blocking_resp_internal(blocking_child *,
+ blocking_pipe_header *);
+extern blocking_pipe_header *
+ receive_blocking_req_internal(blocking_child *);
+extern blocking_pipe_header *
+ receive_blocking_resp_internal(blocking_child *);
+extern int blocking_child_common(blocking_child *);
+extern void exit_worker(int)
+ __attribute__ ((__noreturn__));
+extern int worker_sleep(blocking_child *, time_t);
+extern void worker_idle_timer_fired(void);
+extern void interrupt_worker_sleep(void);
+extern int req_child_exit(blocking_child *);
+#ifndef HAVE_IO_COMPLETION_PORT
+extern int pipe_socketpair(int fds[2], int *is_pipe);
+extern void close_all_beyond(int);
+extern void close_all_except(int);
+extern void kill_asyncio (int);
+#endif
+
+# ifdef WORK_PIPE
+typedef void (*addremove_io_fd_func)(int, int, int);
+extern addremove_io_fd_func addremove_io_fd;
+# else
+extern void handle_blocking_resp_sem(void *);
+typedef void (*addremove_io_semaphore_func)(sem_ref, int);
+extern addremove_io_semaphore_func addremove_io_semaphore;
+# endif
+
+# ifdef WORK_FORK
+extern int worker_process;
+# endif
+
+#endif /* WORKER */
+
+#if defined(HAVE_DROPROOT) && defined(WORK_FORK)
+extern void fork_deferred_worker(void);
+#else
+# define fork_deferred_worker() do {} while (0)
+#endif
+
+#endif /* !NTP_WORKER_H */
diff --git a/include/ntp_workimpl.h b/include/ntp_workimpl.h
new file mode 100644
index 0000000000000..a86c2cd0bff0e
--- /dev/null
+++ b/include/ntp_workimpl.h
@@ -0,0 +1,30 @@
+/*
+ * ntp_workimpl.h - selects worker child implementation
+ */
+#ifndef NTP_WORKIMPL_H
+#define NTP_WORKIMPL_H
+
+/*
+ * Some systems do not support fork() and don't have an alternate
+ * threads implementation of ntp_intres. Such systems are limited
+ * to using numeric IP addresses.
+ */
+#if defined(SYS_WINNT)
+# define WORK_THREAD
+#elif defined(ISC_PLATFORM_USETHREADS) && \
+ defined(HAVE_SEM_TIMEDWAIT) && \
+ (defined(HAVE_GETCLOCK) || defined(HAVE_CLOCK_GETTIME))
+# define WORK_THREAD
+# define WORK_PIPE
+#elif defined(VMS) || defined(SYS_VXWORKS)
+ /* empty */
+#elif defined(HAVE_WORKING_FORK)
+# define WORK_FORK
+# define WORK_PIPE
+#endif
+
+#if defined(WORK_FORK) || defined(WORK_THREAD)
+# define WORKER
+#endif
+
+#endif /* !NTP_WORKIMPL_H */
diff --git a/include/ntpd.h b/include/ntpd.h
index 75e87de97a416..51d8f2accd3e6 100644
--- a/include/ntpd.h
+++ b/include/ntpd.h
@@ -1,17 +1,59 @@
/*
- * ntpd.h - Prototypes for ntpd.
+ * ntpd.h - Prototypes and external variables for ntpd.
+ *
+ * Note the first half is primarily function prototypes, type
+ * declarations, and preprocessor macros, with variables declared
+ * primarily in the second half.
+ *
+ * Each half is further divided into sections for each source file.
*/
#include "ntp.h"
+#include "ntp_stdlib.h"
+#include "ntp_syslog.h"
#include "ntp_debug.h"
#include "ntp_syslog.h"
#include "ntp_select.h"
#include "ntp_malloc.h"
#include "ntp_refclock.h"
+#include "ntp_intres.h"
#include "recvbuff.h"
-/* ntp_config.c */
+/*
+ * First half: ntpd types, functions, macros
+ * -----------------------------------------
+ */
+
+/*
+ * macro for debugging output - cut down on #ifdef pollution.
+ *
+ * DPRINTF() is for use by ntpd only, and compiles away to nothing
+ * without DEBUG (configure --disable-debugging).
+ *
+ * TRACE() is similar for libntp and utilities, which retain full
+ * debug capability even when compiled without DEBUG.
+ *
+ * The calling convention is not attractive:
+ * DPRINTF(debuglevel, (fmt, ...));
+ * DPRINTF(2, ("shows #ifdef DEBUG and if debug >= %d\n", 2));
+ */
+#ifdef DEBUG
+# define DPRINTF(lvl, arg) \
+ do { \
+ if (debug >= (lvl)) \
+ mprintf arg; \
+ } while (0)
+#else
+# define DPRINTF(lvl, arg) do {} while (0)
+#endif
+
+
+/* nt_clockstuff.c */
+#ifdef SYS_WINNT
+extern void win_time_stepped(void);
+#endif
+/* ntp_config.c */
#define TAI_1972 10 /* initial TAI offset (s) */
extern char *keysdir; /* crypto keys and leaptable directory */
extern char * saveconfigdir; /* ntpq saveconfig output directory */
@@ -23,10 +65,10 @@ extern u_short ctlpeerstatus (struct peer *);
extern int ctlsettrap (sockaddr_u *, struct interface *, int, int);
extern u_short ctlsysstatus (void);
extern void init_control (void);
-extern void init_logging (char const *, int);
-extern void setup_logfile (void);
extern void process_control (struct recvbuf *, int);
extern void report_event (int, struct peer *, const char *);
+extern int mprintf_event (int, struct peer *, const char *, ...)
+ NTP_PRINTF(3, 4);
/* ntp_control.c */
/*
@@ -52,18 +94,11 @@ struct ctl_var {
#define WO (CAN_WRITE)
#define RW (CAN_READ|CAN_WRITE)
-extern char * add_var (struct ctl_var **, u_long, u_short);
-extern void free_varlist (struct ctl_var *);
-extern void set_var (struct ctl_var **, const char *, u_long, u_short);
-extern void set_sys_var (const char *, u_long, u_short);
-
-/* ntp_intres.c */
-extern void ntp_res_name (sockaddr_u, u_short);
-extern void ntp_res_recv (void);
-extern void ntp_intres (void);
-#ifdef SYS_WINNT
-extern unsigned WINAPI ntp_intres_thread (void *);
-#endif
+extern char * add_var (struct ctl_var **, u_long, u_short);
+extern void free_varlist (struct ctl_var *);
+extern void set_var (struct ctl_var **, const char *, u_long, u_short);
+extern void set_sys_var (const char *, u_long, u_short);
+extern const char * get_ext_sys_var(const char *tag);
/* ntp_io.c */
typedef struct interface_info {
@@ -73,27 +108,26 @@ typedef struct interface_info {
typedef void (*interface_receiver_t) (void *, interface_info_t *);
-extern int disable_dynamic_updates;
-
extern void interface_enumerate (interface_receiver_t, void *);
+extern endpt * getinterface (sockaddr_u *, u_int32);
+extern endpt * select_peerinterface (struct peer *, sockaddr_u *,
+ endpt *);
extern endpt * findinterface (sockaddr_u *);
extern endpt * findbcastinter (sockaddr_u *);
extern void enable_broadcast (endpt *, sockaddr_u *);
extern void enable_multicast_if (endpt *, sockaddr_u *);
extern void interface_update (interface_receiver_t, void *);
-
+#ifndef HAVE_IO_COMPLETION_PORT
+extern void io_handler (void);
+#endif
extern void init_io (void);
extern void io_open_sockets (void);
-extern void input_handler (l_fp *);
extern void io_clr_stats (void);
extern void io_setbclient (void);
extern void io_unsetbclient (void);
extern void io_multicast_add(sockaddr_u *);
extern void io_multicast_del(sockaddr_u *);
extern void sendpkt (sockaddr_u *, struct interface *, int, struct pkt *, int);
-#ifndef SYS_WINNT
-extern void kill_asyncio (int);
-#endif
#ifdef DEBUG
extern void collect_timing (struct recvbuf *, const char *, int, l_fp *);
#endif
@@ -101,11 +135,11 @@ extern void collect_timing (struct recvbuf *, const char *, int, l_fp *);
extern void wait_for_signal (void);
extern void unblock_io_and_alarm (void);
extern void block_io_and_alarm (void);
-#define UNBLOCK_IO_AND_ALARM() unblock_io_and_alarm()
-#define BLOCK_IO_AND_ALARM() block_io_and_alarm()
+# define UNBLOCK_IO_AND_ALARM() unblock_io_and_alarm()
+# define BLOCK_IO_AND_ALARM() block_io_and_alarm()
#else
-#define UNBLOCK_IO_AND_ALARM()
-#define BLOCK_IO_AND_ALARM()
+# define UNBLOCK_IO_AND_ALARM() do {} while (0)
+# define BLOCK_IO_AND_ALARM() do {} while (0)
#endif
#define latoa(pif) localaddrtoa(pif)
extern const char * localaddrtoa(endpt *);
@@ -115,36 +149,48 @@ extern void init_loopfilter(void);
extern int local_clock(struct peer *, double);
extern void adj_host_clock(void);
extern void loop_config(int, double);
+extern void select_loop(int);
extern void huffpuff(void);
extern u_long sys_clocktime;
extern u_int sys_tai;
+extern int freq_cnt;
/* ntp_monitor.c */
+#define MON_HASH_SIZE (1U << mon_hash_bits)
+#define MON_HASH_MASK (MON_HASH_SIZE - 1)
+#define MON_HASH(addr) (sock_hash(addr) & MON_HASH_MASK)
extern void init_mon (void);
extern void mon_start (int);
extern void mon_stop (int);
-extern int ntp_monitor (struct recvbuf *, int);
-extern void ntp_monclearinterface (struct interface *interface);
+extern u_short ntp_monitor (struct recvbuf *, u_short);
+extern void mon_clearinterface(endpt *interface);
/* ntp_peer.c */
extern void init_peer (void);
-extern struct peer *findexistingpeer (sockaddr_u *, struct peer *, int, u_char);
+extern struct peer *findexistingpeer(sockaddr_u *, const char *,
+ struct peer *, int, u_char);
extern struct peer *findpeer (struct recvbuf *, int, int *);
-extern struct peer *findpeerbyassoc (u_int);
-extern void set_peerdstadr (struct peer *peer, struct interface *interface);
-extern struct peer *newpeer (sockaddr_u *, struct interface *, int, int, int, int, u_int, u_char, int, keyid_t);
+extern struct peer *findpeerbyassoc(associd_t);
+extern void set_peerdstadr (struct peer *, endpt *);
+extern struct peer *newpeer (sockaddr_u *, const char *,
+ endpt *, u_char, u_char,
+ u_char, u_char, u_int, u_char, u_int32,
+ keyid_t, const char *);
extern void peer_all_reset (void);
extern void peer_clr_stats (void);
-extern struct peer *peer_config (sockaddr_u *, struct interface *, int, int, int, int, u_int, int, keyid_t, u_char *);
+extern struct peer *peer_config(sockaddr_u *, const char *,
+ endpt *, u_char, u_char,
+ u_char, u_char, u_int, u_int32,
+ keyid_t, const char *);
extern void peer_reset (struct peer *);
-extern void refresh_all_peerinterfaces (void);
+extern void refresh_all_peerinterfaces(void);
extern void unpeer (struct peer *);
extern void clear_all (void);
extern int score_all (struct peer *);
-extern struct peer *findmanycastpeer (struct recvbuf *);
+extern struct peer *findmanycastpeer(struct recvbuf *);
/* ntp_crypto.c */
-#ifdef OPENSSL
+#ifdef AUTOKEY
extern int crypto_recv (struct peer *, struct recvbuf *);
extern int crypto_xmit (struct peer *, struct pkt *,
struct recvbuf *, int,
@@ -167,7 +213,7 @@ extern EVP_PKEY *gqpar_pkey;
extern char *mvpar_file;
extern EVP_PKEY *mvpar_pkey;
extern struct value tai_leap;
-#endif /* OPENSSL */
+#endif /* AUTOKEY */
/* ntp_proto.c */
extern void transmit (struct peer *);
@@ -176,31 +222,24 @@ extern void peer_clear (struct peer *, char *);
extern void process_packet (struct peer *, struct pkt *, u_int);
extern void clock_select (void);
-extern int leap_tai; /* TAI at next leap */
-extern u_long leap_sec; /* next scheduled leap from file */
-extern u_long leap_peers; /* next scheduled leap from peers */
-extern u_long leapsec; /* seconds to next leap */
-extern u_long leap_expire; /* leap information expiration */
+extern u_long leapsec; /* seconds to next leap (proximity class) */
+extern int leapdif; /* TAI difference step at next leap second*/
extern int sys_orphan;
extern double sys_mindisp;
extern double sys_maxdist;
-/*
- * there seems to be a bug in the IRIX 4 compiler which prevents
- * u_char from beeing used in prototyped functions.
- * This is also true AIX compiler.
- * So give up and define it to be int. WLJ
- */
-extern void poll_update (struct peer *, int);
+extern char *sys_ident; /* identity scheme */
+extern void poll_update (struct peer *, u_char);
extern void clear (struct peer *);
extern void clock_filter (struct peer *, double, double, double);
extern void init_proto (void);
+extern void set_sys_tick_precision(double);
extern void proto_config (int, u_long, double, sockaddr_u *);
extern void proto_clr_stats (void);
-#ifdef REFCLOCK
/* ntp_refclock.c */
+#ifdef REFCLOCK
extern int refclock_newpeer (struct peer *);
extern void refclock_unpeer (struct peer *);
extern void refclock_receive (struct peer *);
@@ -211,26 +250,30 @@ extern void init_refclock (void);
/* ntp_request.c */
extern void init_request (void);
extern void process_private (struct recvbuf *, int);
+extern void reset_auth_stats(void);
/* ntp_restrict.c */
extern void init_restrict (void);
extern u_short restrictions (sockaddr_u *);
-extern void hack_restrict (int, sockaddr_u *, sockaddr_u *, u_short, u_short);
+extern void hack_restrict (int, sockaddr_u *, sockaddr_u *,
+ u_short, u_short, u_long);
+extern void restrict_source (sockaddr_u *, int, u_long);
/* ntp_timer.c */
extern void init_timer (void);
extern void reinit_timer (void);
extern void timer (void);
extern void timer_clr_stats (void);
-extern void timer_interfacetimeout (u_long);
-extern volatile int interface_interval;
-#ifdef OPENSSL
+extern void timer_interfacetimeout (u_long);
+extern volatile int interface_interval;
+extern u_long orphwait; /* orphan wait time */
+#ifdef AUTOKEY
extern char *sys_hostname; /* host name */
extern char *sys_groupname; /* group name */
extern char *group_name; /* group name */
-extern u_long sys_revoke; /* keys revoke timeout */
-extern u_long sys_automax; /* session key timeout */
-#endif /* OPENSSL */
+extern u_long sys_revoke; /* keys revoke timeout */
+extern u_long sys_automax; /* session key timeout */
+#endif /* AUTOKEY */
/* ntp_util.c */
extern void init_util (void);
@@ -240,22 +283,39 @@ 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);
extern void record_clock_stats (sockaddr_u *, const char *);
-extern void record_raw_stats (sockaddr_u *, sockaddr_u *, l_fp *, l_fp *, l_fp *, l_fp *);
-extern u_long leap_month(u_long);
+extern int mprintf_clock_stats(sockaddr_u *, const char *, ...)
+ NTP_PRINTF(2, 3);
+extern void record_raw_stats (sockaddr_u *srcadr, sockaddr_u *dstadr, l_fp *t1, l_fp *t2, l_fp *t3, l_fp *t4, int leap, int version, int mode, int stratum, int poll, int precision, double root_delay, double root_dispersion, u_int32 refid);
+extern void check_leap_file (int is_daily_check, u_int32 ntptime, const time_t * systime);
extern void record_crypto_stats (sockaddr_u *, const char *);
#ifdef DEBUG
extern void record_timing_stats (const char *);
#endif
-extern u_short sock_hash (sockaddr_u *);
extern char * fstostr(time_t); /* NTP timescale seconds */
-extern double old_drift;
-extern int drift_file_sw;
-extern double wander_threshold;
-extern double wander_resid;
+
+/* ntpd.c */
+extern void parse_cmdline_opts(int *, char ***);
+/*
+ * Signals we catch for debugging.
+ */
+#define MOREDEBUGSIG SIGUSR1
+#define LESSDEBUGSIG SIGUSR2
+/*
+ * Signals which terminate us gracefully.
+ */
+#ifndef SYS_WINNT
+# define SIGDIE1 SIGHUP
+# define SIGDIE2 SIGINT
+# define SIGDIE3 SIGQUIT
+# define SIGDIE4 SIGTERM
+#endif /* SYS_WINNT */
+
/*
- * Variable declarations for ntpd.
+ * Last half: ntpd variables
+ * -------------------------
*/
+
/* ntp_config.c */
extern char const * progname;
extern char *sys_phone[]; /* ACTS phone numbers */
@@ -264,7 +324,7 @@ extern int config_priority_override;
extern int config_priority;
#endif
extern char *ntp_signd_socket;
-extern struct config_tree *cfg_tree_history;
+extern struct config_tree_tag *cfg_tree_history;
#ifdef BC_LIST_FRAMEWORK_NOT_YET_USED
/*
@@ -301,17 +361,6 @@ extern u_long numctldatatooshort; /* data too short for count */
extern u_long numctlbadop; /* bad op code found in packet */
extern u_long numasyncmsgs; /* number of async messages we've sent */
-/* ntp_intres.c */
-extern keyid_t req_keyid; /* request keyid */
-extern int req_keytype; /* OpenSSL NID such as NID_md5 */
-extern size_t req_hashlen; /* digest size for req_keytype */
-extern char * req_file; /* name of the file with configuration info */
-#ifdef SYS_WINNT
-extern HANDLE ResolverEventHandle;
-#else
-extern int resolver_pipe_fd[2]; /* used to let the resolver process alert the parent process */
-#endif /* SYS_WINNT */
-
/*
* Other statistics of possible interest
*/
@@ -325,18 +374,13 @@ extern volatile u_long handler_calls; /* number of calls to interrupt handler */
extern volatile u_long handler_pkts; /* number of pkts received by handler */
extern u_long io_timereset; /* time counters were reset */
-/*
- * Interface stuff
- */
+/* ntp_io.c */
+extern int disable_dynamic_updates;
+extern u_int sys_ifnum; /* next .ifnum to assign */
extern endpt * any_interface; /* IPv4 wildcard */
extern endpt * any6_interface; /* IPv6 wildcard */
extern endpt * loopback_interface; /* IPv4 loopback for refclocks */
-
-/*
- * File descriptor masks etc. for call to select
- */
-extern fd_set activefds;
-extern int maxactivefd;
+extern endpt * ep_list; /* linked list */
/* ntp_loopfilter.c */
extern double drift_comp; /* clock frequency (s/s) */
@@ -356,7 +400,7 @@ extern int pll_status; /* status bits for kernel pll */
extern int ntp_enable; /* clock discipline enabled */
extern int pll_control; /* kernel support available */
extern int kern_enable; /* kernel support enabled */
-extern int pps_enable; /* kernel PPS discipline enabled */
+extern int hardpps_enable; /* kernel PPS discipline enabled */
extern int ext_enable; /* external clock enabled */
extern int cal_enable; /* refclock calibrate enable */
extern int allow_panic; /* allow panic correction */
@@ -377,16 +421,28 @@ extern double sys_offset; /* system offset (s) */
extern double sys_jitter; /* system jitter (s) */
/* ntp_monitor.c */
-extern struct mon_data mon_mru_list;
-extern struct mon_data mon_fifo_list;
-extern int mon_enabled;
+extern u_char 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 u_int mon_enabled; /* MON_OFF (0) or other MON_* */
+extern u_int mru_alloc; /* mru list + free list count */
+extern u_int mru_entries; /* mru list count */
+extern u_int mru_peakentries; /* highest mru_entries */
+extern u_int mru_initalloc; /* entries to preallocate */
+extern u_int mru_incalloc; /* allocation batch factor */
+extern u_int mru_mindepth; /* preempt above this */
+extern int mru_maxage; /* for entries older than */
+extern u_int mru_maxdepth; /* MRU size hard limit */
+extern int mon_age; /* preemption limit */
/* ntp_peer.c */
-extern struct peer *peer_hash[]; /* peer hash table */
-extern int peer_hash_count[]; /* count of peers in each bucket */
-extern struct peer *assoc_hash[]; /* association ID hash table */
-extern int assoc_hash_count[];
-extern int peer_free_count;
+extern struct peer *peer_hash[NTP_HASH_SIZE]; /* peer hash table */
+extern int peer_hash_count[NTP_HASH_SIZE]; /* count of in each bucket */
+extern struct peer *assoc_hash[NTP_HASH_SIZE]; /* association ID hash table */
+extern int assoc_hash_count[NTP_HASH_SIZE];/* count of in each bucket */
+extern struct peer *peer_list; /* peer structures list */
+extern int peer_count; /* count in peer_list */
+extern int peer_free_count; /* count in peer_free */
/*
* Miscellaneous statistic counters which may be queried.
@@ -399,6 +455,7 @@ extern u_long peer_demobilizations; /* number of structs freed to free list */
extern int total_peer_structs; /* number of peer structs in circulation */
extern int peer_associations; /* mobilized associations */
extern int peer_preempt; /* preemptable associations */
+
/* ntp_proto.c */
/*
* System variables are declared here. See Section 3.2 of the
@@ -420,6 +477,7 @@ extern int sys_bclient; /* we set our time to broadcasts */
extern double sys_bdelay; /* broadcast client default delay */
extern int sys_authenticate; /* requre authentication for config */
extern l_fp sys_authdelay; /* authentication delay */
+extern u_long sys_epoch; /* last clock update time */
extern keyid_t sys_private; /* private value for session seed */
extern int sys_manycastserver; /* respond to manycast client pkts */
extern int sys_minclock; /* minimum survivors */
@@ -445,45 +503,60 @@ extern u_long sys_declined; /* declined */
extern u_long sys_limitrejected; /* rate exceeded */
extern u_long sys_kodsent; /* KoD sent */
-/* ntp_refclock.c */
-#ifdef REFCLOCK
-#ifdef PPS
-extern int fdpps; /* pps file descriptor */
-#endif /* PPS */
-#endif
-
/* ntp_request.c */
extern keyid_t info_auth_keyid; /* keyid used to authenticate requests */
+extern u_long auth_timereset;
/* ntp_restrict.c */
extern restrict_u * restrictlist4; /* IPv4 restriction list */
extern restrict_u * restrictlist6; /* IPv6 restriction list */
-extern int ntp_minpkt;
-extern int ntp_minpoll;
-extern int mon_age; /* monitor preempt age */
+extern int ntp_minpkt;
+extern u_char ntp_minpoll;
+
+/* ntp_scanner.c */
+extern u_int32 conf_file_sum; /* Simple sum of characters */
+
+/* ntp_signd.c */
+#ifdef HAVE_NTP_SIGND
+extern void send_via_ntp_signd(struct recvbuf *, int, keyid_t, int,
+ struct pkt *);
+#endif
/* ntp_timer.c */
extern volatile int alarm_flag; /* alarm flag */
extern volatile u_long alarm_overflow;
-extern u_long current_time; /* current time (s) */
+extern u_long current_time; /* seconds since startup */
extern u_long timer_timereset;
extern u_long timer_overflows;
extern u_long timer_xmtcalls;
+#ifdef SYS_WINNT
+HANDLE WaitableTimerHandle;
+#endif
/* ntp_util.c */
-extern int stats_control; /* write stats to fileset? */
-extern int stats_write_period; /* # of seconds between writes. */
-extern double stats_write_tolerance;
+extern char statsdir[MAXFILENAME];
+extern int stats_control; /* write stats to fileset? */
+extern int stats_write_period; /* # of seconds between writes. */
+extern double stats_write_tolerance;
+extern double wander_threshold;
/* ntpd.c */
-extern volatile int debug; /* debugging flag */
-extern int nofork; /* no-fork flag */
-extern int initializing; /* initializing flag */
+extern int nofork; /* no-fork flag */
+extern int initializing; /* initializing flag */
#ifdef HAVE_DROPROOT
-extern int droproot; /* flag: try to drop root privileges after startup */
-extern char *user; /* user to switch to */
-extern char *group; /* group to switch to */
-extern const char *chrootdir; /* directory to chroot to */
+extern int droproot; /* flag: try to drop root privileges after startup */
+extern int root_dropped; /* root has been dropped */
+extern char *user; /* user to switch to */
+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 */
+#endif
+
+/* ntservice.c */
+#ifdef SYS_WINNT
+extern int accept_wildcard_if_for_winnt;
#endif
/* refclock_conf.c */
@@ -493,14 +566,3 @@ extern struct refclock * const refclock_conf[];
extern u_char num_refclock_conf;
#endif
-/* ntp_signd.c */
-#ifdef HAVE_NTP_SIGND
-extern void
-send_via_ntp_signd(
- struct recvbuf *rbufp, /* receive packet pointer */
- int xmode,
- keyid_t xkeyid,
- int flags,
- struct pkt *xpkt
- );
-#endif
diff --git a/include/ntpsim.h b/include/ntpsim.h
index 971c7f16340c5..b270ce640b18d 100644
--- a/include/ntpsim.h
+++ b/include/ntpsim.h
@@ -26,8 +26,7 @@
#include "recvbuff.h"
#include "ntp_io.h"
#include "ntp_stdlib.h"
-
-#include "ntp_data_structures.h"
+#include "ntp_prio_q.h"
/* CONSTANTS */
@@ -77,26 +76,32 @@ typedef struct {
/* Server Script Information */
+typedef struct script_info_tag script_info;
+struct script_info_tag {
+ script_info * link;
+ double duration;
+ double freq_offset;
+ double wander;
+ double jitter;
+ double prop_delay;
+ double proc_delay;
+};
-typedef struct {
- double duration;
- double freq_offset;
- double wander;
- double jitter;
- double prop_delay;
- double proc_delay;
-} script_info;
-
+typedef DECL_FIFO_ANCHOR(script_info) script_info_fifo;
/* Server Structures */
-typedef struct {
- double server_time; /* Server time */
- sockaddr_u *addr; /* Server Address */
- queue *script; /* Server Script */
- script_info *curr_script; /* Current Script */
-} server_info;
+typedef struct server_info_tag server_info;
+struct server_info_tag {
+ server_info * link;
+ double server_time;
+ sockaddr_u * addr;
+ script_info_fifo * script;
+ script_info * curr_script;
+};
+
+typedef DECL_FIFO_ANCHOR(server_info) server_info_fifo;
/* Simulation control information */
@@ -114,30 +119,28 @@ typedef struct Sim_Info {
/* Local Clock (Client) Variables */
typedef struct Local_Clock_Info {
- double local_time; /* Client disciplined time */
- double adj; /* Remaining time correction */
- double slew; /* Correction Slew Rate */
- double last_read_time; /* Last time the clock was read */
+ double local_time; /* Client disciplined time */
+ double adj; /* Remaining time correction */
+ double slew; /* Correction Slew Rate */
+ double last_read_time; /* Last time the clock was read */
} local_clock_info;
-extern local_clock_info simclock; /* Local Clock Variables */
-extern sim_info simulation; /* Simulation Control Variables */
+extern local_clock_info simclock; /* Local Clock Variables */
+extern sim_info simulation; /* Simulation Control Variables */
/* Function Prototypes */
-int ntpsim (int argc, char *argv[]);
-Event *event (double t, funcTkn f);
-void sim_event_timer (Event *e);
-int simulate_server (sockaddr_u *serv_addr,
- struct interface *inter,
- struct pkt *rpkt);
-void sim_update_clocks (Event *e);
-void sim_event_recv_packet (Event *e);
-void sim_event_beep (Event *e);
-void abortsim (char *errmsg);
-double gauss (double, double);
-double poisson (double, double);
-int yyparse (void);
-void create_server_associations (void);
+int ntpsim (int argc, char *argv[]);
+Event *event (double t, funcTkn f);
+void sim_event_timer (Event *e);
+int simulate_server (sockaddr_u *serv_addr, endpt *inter,
+ struct pkt *rpkt);
+void sim_update_clocks (Event *e);
+void sim_event_recv_packet (Event *e);
+void sim_event_beep (Event *e);
+void abortsim (char *errmsg);
+double gauss (double, double);
+double poisson (double, double);
+void create_server_associations(void);
#endif /* NTPSIM_H */
diff --git a/include/recvbuff.h b/include/recvbuff.h
index 3b205452e2064..92188f5990cd2 100644
--- a/include/recvbuff.h
+++ b/include/recvbuff.h
@@ -1,12 +1,8 @@
#ifndef RECVBUFF_H
#define RECVBUFF_H
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
#include "ntp.h"
-#include "ntp_fp.h"
+#include "ntp_net.h"
#include "ntp_lists.h"
#include <isc/result.h>
@@ -21,14 +17,14 @@
#if defined HAVE_IO_COMPLETION_PORT
# include "ntp_iocompletionport.h"
-#include "ntp_timer.h"
+# include "ntp_timer.h"
# define RECV_BLOCK_IO() EnterCriticalSection(&RecvCritSection)
# define RECV_UNBLOCK_IO() LeaveCriticalSection(&RecvCritSection)
/* Return the event which is set when items are added to the full list
*/
-extern HANDLE get_recv_buff_event (void);
+extern HANDLE get_recv_buff_event(void);
#else
# define RECV_BLOCK_IO()
# define RECV_UNBLOCK_IO()
@@ -51,40 +47,40 @@ extern HANDLE get_recv_buff_event (void);
typedef struct recvbuf recvbuf_t;
struct recvbuf {
- ISC_LINK(recvbuf_t) link; /* next in list */
+ recvbuf_t * link; /* next in list */
union {
- sockaddr_u X_recv_srcadr;
- caddr_t X_recv_srcclock;
- struct peer *X_recv_peer;
+ sockaddr_u X_recv_srcadr;
+ caddr_t X_recv_srcclock;
+ struct peer * X_recv_peer;
} X_from_where;
-#define recv_srcadr X_from_where.X_recv_srcadr
-#define recv_srcclock X_from_where.X_recv_srcclock
-#define recv_peer X_from_where.X_recv_peer
+#define recv_srcadr X_from_where.X_recv_srcadr
+#define recv_srcclock X_from_where.X_recv_srcclock
+#define recv_peer X_from_where.X_recv_peer
#ifndef HAVE_IO_COMPLETION_PORT
- sockaddr_u srcadr; /* where packet came from */
+ sockaddr_u srcadr; /* where packet came from */
#else
- int recv_srcadr_len; /* filled in on completion */
+ int recv_srcadr_len;/* filled in on completion */
#endif
- endpt * dstadr; /* address pkt arrived on */
- SOCKET fd; /* fd on which it was received */
- int msg_flags; /* Flags received about the packet */
- l_fp recv_time; /* time of arrival */
- void (*receiver) (struct recvbuf *); /* routine to receive buffer */
- int recv_length; /* number of octets received */
+ endpt * dstadr; /* address pkt arrived on */
+ SOCKET fd; /* fd on which it was received */
+ int msg_flags; /* Flags received about the packet */
+ l_fp recv_time; /* time of arrival */
+ void (*receiver)(struct recvbuf *); /* callback */
+ int recv_length; /* number of octets received */
union {
- struct pkt X_recv_pkt;
- u_char X_recv_buffer[RX_BUFF_SIZE];
+ struct pkt X_recv_pkt;
+ u_char X_recv_buffer[RX_BUFF_SIZE];
} recv_space;
-#define recv_pkt recv_space.X_recv_pkt
-#define recv_buffer recv_space.X_recv_buffer
- int used; /* reference count */
+#define recv_pkt recv_space.X_recv_pkt
+#define recv_buffer recv_space.X_recv_buffer
+ int used; /* reference count */
};
-extern void init_recvbuff (int);
+extern void init_recvbuff(int);
/* freerecvbuf - make a single recvbuf available for reuse
*/
-extern void freerecvbuf (struct recvbuf *);
+extern void freerecvbuf(struct recvbuf *);
/* Get a free buffer (typically used so an async
* read can directly place data into the buffer
@@ -92,29 +88,36 @@ extern void freerecvbuf (struct recvbuf *);
* The buffer is removed from the free list. Make sure
* you put it back with freerecvbuf() or
*/
-extern struct recvbuf *get_free_recv_buffer (void); /* signal safe - no malloc */
-extern struct recvbuf *get_free_recv_buffer_alloc (void); /* signal unsafe - may malloc */
+
+/* signal safe - no malloc */
+extern struct recvbuf *get_free_recv_buffer(void);
+/* signal unsafe - may malloc */
+extern struct recvbuf *get_free_recv_buffer_alloc(void);
/* Add a buffer to the full list
*/
-extern void add_full_recv_buffer (struct recvbuf *);
-
-/*extern void process_recv_buffers (void); */
+extern void add_full_recv_buffer(struct recvbuf *);
/* number of recvbufs on freelist */
-extern u_long free_recvbuffs (void);
-extern u_long full_recvbuffs (void);
-extern u_long total_recvbuffs (void);
-extern u_long lowater_additions (void);
+extern u_long free_recvbuffs(void);
+extern u_long full_recvbuffs(void);
+extern u_long total_recvbuffs(void);
+extern u_long lowater_additions(void);
/* Returns the next buffer in the full list.
*
*/
-extern struct recvbuf *get_full_recv_buffer (void);
+extern struct recvbuf *get_full_recv_buffer(void);
+
+/*
+ * purge_recv_buffers_for_fd() - purges any previously-received input
+ * from a given file descriptor.
+ */
+extern void purge_recv_buffers_for_fd(SOCKET);
/*
* Checks to see if there are buffers to process
*/
-extern isc_boolean_t has_full_recv_buffer (void);
+extern isc_boolean_t has_full_recv_buffer(void);
#endif /* RECVBUFF_H */
diff --git a/include/refclock_atom.h b/include/refclock_atom.h
index 9afce0207ff82..452e933a8d8d3 100644
--- a/include/refclock_atom.h
+++ b/include/refclock_atom.h
@@ -1,8 +1,8 @@
/*
* Definitions for the atom driver and its friends
*/
+#undef NANOSECOND /* some systems define it differently */
#define NANOSECOND 1000000000 /* one second (ns) */
-#define RANGEGATE 500000 /* range gate (ns) */
struct refclock_atom {
pps_handle_t handle;
diff --git a/include/timepps-SCO.h b/include/timepps-SCO.h
index 130a153c69f0b..ce9052e2461ea 100644
--- a/include/timepps-SCO.h
+++ b/include/timepps-SCO.h
@@ -3,7 +3,7 @@
* Copyright (c) David L. Mills 1999-2000 *
* *
* Permission to use, copy, modify, and distribute this software and *
- * its documentation for any purpose and without fee is hereby *
+ * its documentation for any purpose and with or without fee is hereby *
* granted, provided that the above copyright notice appears in all *
* copies and that both the copyright notice and this permission *
* notice appear in supporting documentation, and that the name *
diff --git a/include/timepps-Solaris.h b/include/timepps-Solaris.h
index 73faa5e087457..a2b1fbe3b677b 100644
--- a/include/timepps-Solaris.h
+++ b/include/timepps-Solaris.h
@@ -3,7 +3,7 @@
* Copyright (c) David L. Mills 1999-2009 *
* *
* Permission to use, copy, modify, and distribute this software and *
- * its documentation for any purpose and without fee is hereby *
+ * its documentation for any purpose and with or without fee is hereby *
* granted, provided that the above copyright notice appears in all *
* copies and that both the copyright notice and this permission *
* notice appear in supporting documentation, and that the name *
diff --git a/include/timepps-SunOS.h b/include/timepps-SunOS.h
index 6cd166e69c540..4e4c05e0fee41 100644
--- a/include/timepps-SunOS.h
+++ b/include/timepps-SunOS.h
@@ -3,7 +3,7 @@
* Copyright (c) David L. Mills 1999-2000 *
* *
* Permission to use, copy, modify, and distribute this software and *
- * its documentation for any purpose and without fee is hereby *
+ * its documentation for any purpose and with or without fee is hereby *
* granted, provided that the above copyright notice appears in all *
* copies and that both the copyright notice and this permission *
* notice appear in supporting documentation, and that the name *
diff --git a/include/timespecops.h b/include/timespecops.h
new file mode 100644
index 0000000000000..fa32e42a60008
--- /dev/null
+++ b/include/timespecops.h
@@ -0,0 +1,393 @@
+/*
+ * timespecops.h -- calculations on 'struct timespec' values
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ *
+ * Rationale
+ * ---------
+ *
+ * Doing basic arithmetic on a 'struct timespec' is not exceedingly
+ * hard, but it requires tedious and repetitive code to keep the result
+ * normalised. We consider a timespec normalised when the nanosecond
+ * fraction is in the interval [0 .. 10^9[ ; there are multiple value
+ * pairs of seconds and nanoseconds that denote the same time interval,
+ * but the normalised representation is unique. No two different
+ * intervals can have the same normalised representation.
+ *
+ * Another topic is the representation of negative time intervals.
+ * There's more than one way to this, since both the seconds and the
+ * nanoseconds of a timespec are signed values. IMHO, the easiest way is
+ * to use a complement representation where the nanoseconds are still
+ * normalised, no matter what the sign of the seconds value. This makes
+ * normalisation easier, since the sign of the integer part is
+ * irrelevant, and it removes several sign decision cases during the
+ * calculations.
+ *
+ * As long as no signed integer overflow can occur with the nanosecond
+ * part of the operands, all operations work as expected and produce a
+ * normalised result.
+ *
+ * The exception to this are functions fix a '_fast' suffix, which do no
+ * normalisation on input data and therefore expect the input data to be
+ * normalised.
+ *
+ * Input and output operands may overlap; all input is consumed before
+ * the output is written to.
+ */
+#ifndef TIMESPECOPS_H
+#define TIMESPECOPS_H
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "ntp.h"
+#include "timetoa.h"
+
+
+/* nanoseconds per second */
+#define NANOSECONDS 1000000000
+
+/* predicate: returns TRUE if the nanoseconds are in nominal range */
+#define timespec_isnormal(x) \
+ ((x)->tv_nsec >= 0 && (x)->tv_nsec < NANOSECONDS)
+
+/* 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;
+}
+
+/* x = a + b */
+static inline struct timespec
+add_tspec(
+ struct timespec a,
+ struct timespec b
+ )
+{
+ struct timespec x;
+
+ x = a;
+ x.tv_sec += b.tv_sec;
+ x.tv_nsec += b.tv_nsec;
+
+ return normalize_tspec(x);
+}
+
+/* x = a + b, b is fraction only */
+static inline struct timespec
+add_tspec_ns(
+ struct timespec a,
+ long b
+ )
+{
+ struct timespec x;
+
+ x = a;
+ x.tv_nsec += b;
+
+ return normalize_tspec(x);
+}
+
+/* x = a - b */
+static inline struct timespec
+sub_tspec(
+ struct timespec a,
+ struct timespec b
+ )
+{
+ struct timespec x;
+
+ x = a;
+ x.tv_sec -= b.tv_sec;
+ x.tv_nsec -= b.tv_nsec;
+
+ return normalize_tspec(x);
+}
+
+/* x = a - b, b is fraction only */
+static inline struct timespec
+sub_tspec_ns(
+ struct timespec a,
+ long b
+ )
+{
+ struct timespec x;
+
+ x = a;
+ x.tv_nsec -= b;
+
+ return normalize_tspec(x);
+}
+
+/* x = -a */
+static inline struct timespec
+neg_tspec(
+ struct timespec a
+ )
+{
+ struct timespec x;
+
+ x.tv_sec = -a.tv_sec;
+ x.tv_nsec = -a.tv_nsec;
+
+ return normalize_tspec(x);
+}
+
+/* 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;
+}
+
+/*
+ * 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;
+}
+
+/*
+ * compare possibly-denormal a and b
+ * return 1 / 0 / -1 if a < / == / > b
+ */
+static inline int
+cmp_tspec_denorm(
+ struct timespec a,
+ struct timespec b
+ )
+{
+ return cmp_tspec(normalize_tspec(a), normalize_tspec(b));
+}
+
+/*
+ * 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;
+}
+
+/*
+ * test possibly-denormal a
+ * return 1 / 0 / -1 if a < / == / > 0
+ */
+static inline int
+test_tspec_denorm(
+ struct timespec a
+ )
+{
+ return test_tspec(normalize_tspec(a));
+}
+
+/* return LIB buffer ptr to string rep */
+static inline const char *
+tspectoa(
+ struct timespec x
+ )
+{
+ return format_time_fraction(x.tv_sec, x.tv_nsec, 9);
+}
+
+/*
+ * convert to l_fp type, relative and absolute
+ */
+
+/* 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;
+}
+
+/* x must be UN*X epoch, output will be in NTP epoch */
+static inline l_fp
+tspec_stamp_to_lfp(
+ struct timespec x
+ )
+{
+ l_fp y;
+
+ y = tspec_intv_to_lfp(x);
+ y.l_ui += JAN_1970;
+
+ return y;
+}
+
+/* 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;
+}
+
+/*
+ * 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;
+}
+
+#endif /* TIMESPECOPS_H */
diff --git a/include/timetoa.h b/include/timetoa.h
new file mode 100644
index 0000000000000..259944907741c
--- /dev/null
+++ b/include/timetoa.h
@@ -0,0 +1,83 @@
+/*
+ * timetoa.h -- time_t related string formatting
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ *
+ * Printing a 'time_t' has some portability pitfalls, due to it's opaque
+ * base type. The only requirement imposed by the standard is that it
+ * must be a numeric type. For all practical purposes it's a signed int,
+ * and 32 bits are common.
+ *
+ * Since the UN*X time epoch will cause a signed integer overflow for
+ * 32-bit signed int values in the year 2038, implementations slowly
+ * move to 64bit base types for time_t, even in 32-bit environments. In
+ * such an environment sizeof(time_t) could be bigger than sizeof(long)
+ * and the commonly used idiom of casting to long leads to truncation.
+ *
+ * As the printf() family has no standardised type specifier for time_t,
+ * guessing the right output format specifier is a bit troublesome and
+ * best done with the help of the preprocessor and "config.h".
+ */
+#ifndef TIMETOA_H
+#define TIMETOA_H
+
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+#include "ntp_unixtime.h"
+
+/*
+ * Given the size of time_t, guess what can be used as an unsigned value
+ * to hold a time_t and the printf() format specifcation.
+ *
+ * These should be used with the string constant concatenation feature
+ * of the compiler like this:
+ *
+ * printf("a time stamp: %" TIME_FORMAT " and more\n", a_time_t_value);
+ *
+ * It's not exactly nice, but there's not much leeway once we want to
+ * use the printf() family on time_t values.
+ */
+
+#if SIZEOF_TIME_T <= SIZEOF_INT
+
+typedef unsigned int u_time;
+#define TIME_FORMAT "d"
+#define UTIME_FORMAT "u"
+
+#elif SIZEOF_TIME_T <= SIZEOF_LONG
+
+typedef unsigned long u_time;
+#define TIME_FORMAT "ld"
+#define UTIME_FORMAT "lu"
+
+#elif defined(SIZEOF_LONG_LONG) && SIZEOF_TIME_T <= SIZEOF_LONG_LONG
+
+typedef unsigned long long u_time;
+#define TIME_FORMAT "lld"
+#define UTIME_FORMAT "llu"
+
+#else
+#include "GRONK: what size has a time_t here?"
+#endif
+
+/*
+ * general fractional time stamp formatting.
+ *
+ * secs - integral seconds of time stamp
+ * frac - fractional units
+ * prec - log10 of units per second (3=milliseconds, 6=microseconds,..)
+ * or in other words: the count of decimal digits required.
+ * If prec is < 0, abs(prec) is taken for the precision and secs
+ * is treated as an unsigned value.
+ *
+ * The function will eventually normalise the fraction and adjust the
+ * seconds accordingly.
+ *
+ * This function uses the string buffer library for the return value,
+ * so do not keep the resulting pointers around.
+ */
+extern const char *
+format_time_fraction(time_t secs, long frac, int prec);
+
+#endif /* !defined(TIMETOA_H) */
diff --git a/include/timevalops.h b/include/timevalops.h
new file mode 100644
index 0000000000000..e873b8b8006ea
--- /dev/null
+++ b/include/timevalops.h
@@ -0,0 +1,446 @@
+/*
+ * timevalops.h -- calculations on 'struct timeval' values
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ *
+ * For a rationale look at 'timespecops.h'; we do the same here, but the
+ * normalisation keeps the microseconds in [0 .. 10^6[, of course.
+ */
+#ifndef TIMEVALOPS_H
+#define TIMEVALOPS_H
+
+#include <sys/types.h>
+#include <stdio.h>
+
+#include "ntp.h"
+#include "timetoa.h"
+
+
+/* microseconds per second */
+#define MICROSECONDS 1000000
+
+#ifndef HAVE_U_INT64
+# define USE_TSF_USEC_TABLES
+#endif
+
+/*
+ * Convert usec to a time stamp fraction.
+ */
+#ifdef USE_TSF_USEC_TABLES
+extern const u_int32 ustotslo[];
+extern const u_int32 ustotsmid[];
+extern const u_int32 ustotshi[];
+
+# define TVUTOTSF(tvu, tsf) \
+ ((tsf) = ustotslo[(tvu) & 0xff] \
+ + ustotsmid[((tvu) >> 8) & 0xff] \
+ + ustotshi[((tvu) >> 16) & 0xf])
+#else
+# define TVUTOTSF(tvu, tsf) \
+ ((tsf) = (u_int32) \
+ ((((u_int64)(tvu) << 32) + MICROSECONDS / 2) / \
+ MICROSECONDS))
+#endif
+
+/*
+ * Convert a time stamp fraction to microseconds. The time stamp
+ * fraction is assumed to be unsigned.
+ */
+#ifdef USE_TSF_USEC_TABLES
+extern const u_int32 tstouslo[256];
+extern const u_int32 tstousmid[256];
+extern const u_int32 tstoushi[128];
+
+/*
+ * TV_SHIFT is used to turn the table result into a usec value. To
+ * round, add in TV_ROUNDBIT before shifting.
+ */
+#define TV_SHIFT 3
+#define TV_ROUNDBIT 0x4
+
+# define TSFTOTVU(tsf, tvu) \
+ ((tvu) = (tstoushi[((tsf) >> 24) & 0xff] \
+ + tstousmid[((tsf) >> 16) & 0xff] \
+ + tstouslo[((tsf) >> 9) & 0x7f] \
+ + TV_ROUNDBIT) >> TV_SHIFT)
+#else
+# define TSFTOTVU(tsf, tvu) \
+ ((tvu) = (int32) \
+ (((u_int64)(tsf) * MICROSECONDS + 0x80000000) >> 32))
+#endif
+
+/*
+ * Convert a struct timeval to a time stamp.
+ */
+#define TVTOTS(tv, ts) \
+ do { \
+ (ts)->l_ui = (u_long)(tv)->tv_sec; \
+ TVUTOTSF((tv)->tv_usec, (ts)->l_uf); \
+ } while (FALSE)
+
+#define sTVTOTS(tv, ts) \
+ do { \
+ int isneg = 0; \
+ long usec; \
+ (ts)->l_ui = (tv)->tv_sec; \
+ usec = (tv)->tv_usec; \
+ if (((tv)->tv_sec < 0) || ((tv)->tv_usec < 0)) { \
+ usec = -usec; \
+ (ts)->l_ui = -(ts)->l_ui; \
+ isneg = 1; \
+ } \
+ TVUTOTSF(usec, (ts)->l_uf); \
+ if (isneg) { \
+ L_NEG((ts)); \
+ } \
+ } while (FALSE)
+
+/*
+ * Convert a time stamp to a struct timeval. The time stamp
+ * has to be positive.
+ */
+#define TSTOTV(ts, tv) \
+ do { \
+ (tv)->tv_sec = (ts)->l_ui; \
+ TSFTOTVU((ts)->l_uf, (tv)->tv_usec); \
+ if ((tv)->tv_usec == 1000000) { \
+ (tv)->tv_sec++; \
+ (tv)->tv_usec = 0; \
+ } \
+ } while (FALSE)
+
+
+/*
+ * predicate: returns TRUE if the microseconds are in nominal range
+ * use like: int timeval_isnormal(const struct timeval *x)
+ */
+#define timeval_isnormal(x) \
+ ((x)->tv_usec >= 0 && (x)->tv_usec < MICROSECONDS)
+
+/*
+ * Convert milliseconds to a time stamp fraction. Unused except for
+ * refclock_leitch.c, so accompanying lookup tables were removed in
+ * favor of reusing the microseconds conversion tables.
+ */
+#define MSUTOTSF(msu, tsf) TVUTOTSF((msu) * 1000, tsf)
+
+/*
+ * predicate: returns TRUE if the microseconds are out-of-bounds
+ * use like: int timeval_isdenormal(const struct timeval *x)
+ */
+#define timeval_isdenormal(x) (!timeval_isnormal(x))
+
+/* make sure microseconds are in nominal range */
+static inline struct timeval
+normalize_tval(
+ struct timeval x
+ )
+{
+ long z;
+
+ /*
+ * If the fraction becomes excessive denormal, we use division
+ * to do first partial normalisation. The normalisation loops
+ * following will do the remaining cleanup. Since the size of
+ * tv_usec has a peculiar definition by the standard the range
+ * check is coded manually. And labs() is intentionally not used
+ * here: it has implementation-defined behaviour when applied
+ * to LONG_MIN.
+ */
+ if (x.tv_usec < -3l * MICROSECONDS ||
+ x.tv_usec > 3l * MICROSECONDS ) {
+ z = x.tv_usec / MICROSECONDS;
+ x.tv_usec -= z * MICROSECONDS;
+ x.tv_sec += z;
+ }
+
+ /*
+ * Do any remaining normalisation steps in loops. This takes 3
+ * steps max, and should outperform a division even if the
+ * mul-by-inverse trick is employed. (It also does the floor
+ * division adjustment if the above division was executed.)
+ */
+ if (x.tv_usec < 0)
+ do {
+ x.tv_usec += MICROSECONDS;
+ x.tv_sec--;
+ } while (x.tv_usec < 0);
+ else if (x.tv_usec >= MICROSECONDS)
+ do {
+ x.tv_usec -= MICROSECONDS;
+ x.tv_sec++;
+ } while (x.tv_usec >= MICROSECONDS);
+
+ return x;
+}
+
+/* x = a + b */
+static inline struct timeval
+add_tval(
+ struct timeval a,
+ struct timeval b
+ )
+{
+ struct timeval x;
+
+ x = a;
+ x.tv_sec += b.tv_sec;
+ x.tv_usec += b.tv_usec;
+
+ return normalize_tval(x);
+}
+
+/* x = a + b, b is fraction only */
+static inline struct timeval
+add_tval_us(
+ struct timeval a,
+ long b
+ )
+{
+ struct timeval x;
+
+ x = a;
+ x.tv_usec += b;
+
+ return normalize_tval(x);
+}
+
+/* x = a - b */
+static inline struct timeval
+sub_tval(
+ struct timeval a,
+ struct timeval b
+ )
+{
+ struct timeval x;
+
+ x = a;
+ x.tv_sec -= b.tv_sec;
+ x.tv_usec -= b.tv_usec;
+
+ return normalize_tval(x);
+}
+
+/* x = a - b, b is fraction only */
+static inline struct timeval
+sub_tval_us(
+ struct timeval a,
+ long b
+ )
+{
+ struct timeval x;
+
+ x = a;
+ x.tv_usec -= b;
+
+ return normalize_tval(x);
+}
+
+/* x = -a */
+static inline struct timeval
+neg_tval(
+ struct timeval a
+ )
+{
+ struct timeval x;
+
+ x.tv_sec = -a.tv_sec;
+ x.tv_usec = -a.tv_usec;
+
+ return normalize_tval(x);
+}
+
+/* x = abs(a) */
+static inline struct timeval
+abs_tval(
+ struct timeval a
+ )
+{
+ struct timeval c;
+
+ c = normalize_tval(a);
+ if (c.tv_sec < 0) {
+ if (c.tv_usec != 0) {
+ c.tv_sec = -c.tv_sec - 1;
+ c.tv_usec = MICROSECONDS - c.tv_usec;
+ } else {
+ c.tv_sec = -c.tv_sec;
+ }
+ }
+
+ return c;
+}
+
+/*
+ * compare previously-normalised a and b
+ * return 1 / 0 / -1 if a < / == / > b
+ */
+static inline int
+cmp_tval(
+ struct timeval a,
+ struct timeval b
+ )
+{
+ int r;
+
+ r = (a.tv_sec > b.tv_sec) - (a.tv_sec < b.tv_sec);
+ if (0 == r)
+ r = (a.tv_usec > b.tv_usec) -
+ (a.tv_usec < b.tv_usec);
+
+ return r;
+}
+
+/*
+ * compare possibly-denormal a and b
+ * return 1 / 0 / -1 if a < / == / > b
+ */
+static inline int
+cmp_tval_denorm(
+ struct timeval a,
+ struct timeval b
+ )
+{
+ return cmp_tval(normalize_tval(a), normalize_tval(b));
+}
+
+/*
+ * test previously-normalised a
+ * return 1 / 0 / -1 if a < / == / > 0
+ */
+static inline int
+test_tval(
+ struct timeval a
+ )
+{
+ int r;
+
+ r = (a.tv_sec > 0) - (a.tv_sec < 0);
+ if (r == 0)
+ r = (a.tv_usec > 0);
+
+ return r;
+}
+
+/*
+ * test possibly-denormal a
+ * return 1 / 0 / -1 if a < / == / > 0
+ */
+static inline int
+test_tval_denorm(
+ struct timeval a
+ )
+{
+ return test_tval(normalize_tval(a));
+}
+
+/* return LIB buffer ptr to string rep */
+static inline const char *
+tvaltoa(
+ struct timeval x
+ )
+{
+ return format_time_fraction(x.tv_sec, x.tv_usec, 6);
+}
+
+/* convert from timeval duration to l_fp duration */
+static inline l_fp
+tval_intv_to_lfp(
+ struct timeval x
+ )
+{
+ struct timeval v;
+ l_fp y;
+
+ v = normalize_tval(x);
+ TVUTOTSF(v.tv_usec, y.l_uf);
+ y.l_i = (int32)v.tv_sec;
+
+ return y;
+}
+
+/* x must be UN*X epoch, output *y will be in NTP epoch */
+static inline l_fp
+tval_stamp_to_lfp(
+ struct timeval x
+ )
+{
+ l_fp y;
+
+ y = tval_intv_to_lfp(x);
+ y.l_ui += JAN_1970;
+
+ return y;
+}
+
+/* convert to l_fp type, relative signed/unsigned and absolute */
+static inline struct timeval
+lfp_intv_to_tval(
+ l_fp x
+ )
+{
+ struct timeval out;
+ l_fp absx;
+ int neg;
+
+ neg = L_ISNEG(&x);
+ absx = x;
+ if (neg) {
+ L_NEG(&absx);
+ }
+ TSFTOTVU(absx.l_uf, out.tv_usec);
+ out.tv_sec = absx.l_i;
+ if (neg) {
+ out.tv_sec = -out.tv_sec;
+ out.tv_usec = -out.tv_usec;
+ out = normalize_tval(out);
+ }
+
+ return out;
+}
+
+static inline struct timeval
+lfp_uintv_to_tval(
+ l_fp x
+ )
+{
+ struct timeval out;
+
+ TSFTOTVU(x.l_uf, out.tv_usec);
+ out.tv_sec = x.l_ui;
+
+ return out;
+}
+
+/*
+ * 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 timeval
+lfp_stamp_to_tval(
+ l_fp x,
+ const time_t * p
+ )
+{
+ struct timeval out;
+ vint64 sec;
+
+ sec = ntpcal_ntp_to_time(x.l_ui, p);
+ TSFTOTVU(x.l_uf, out.tv_usec);
+
+ /* 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
+ out = normalize_tval(out);
+
+ return out;
+}
+
+#endif /* TIMEVALOPS_H */
diff --git a/include/version.def b/include/version.def
deleted file mode 100644
index 706bf967cac2a..0000000000000
--- a/include/version.def
+++ /dev/null
@@ -1 +0,0 @@
-version = '4.2.6p5';
diff --git a/include/version.texi b/include/version.texi
deleted file mode 100644
index 1d549577f4066..0000000000000
--- a/include/version.texi
+++ /dev/null
@@ -1,3 +0,0 @@
-@set UPDATED 24 December 2011
-@set EDITION 4.2.6p5
-@set VERSION 4.2.6p5
diff --git a/include/vint64ops.h b/include/vint64ops.h
new file mode 100644
index 0000000000000..2c3deffb38132
--- /dev/null
+++ b/include/vint64ops.h
@@ -0,0 +1,28 @@
+/*
+ * vint64ops.h - operations on 'vint64' values
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ * ----------------------------------------------------------------------
+ * This is an attempt to get the vint64 calculations stuff centralised.
+ */
+#ifndef VINT64OPS_H
+#define VINT64OPS_H
+
+/* signed/unsigned compare. returns 1/0/-1 if lhs >/=/< rhs */
+extern int icmpv64(const vint64 * lhs, const vint64 * rhs);
+extern int ucmpv64(const vint64 * lhs, const vint64 * rhs);
+
+/* add / subtract */
+extern vint64 addv64(const vint64 *lhs, const vint64 *rhs);
+extern vint64 addv64i32(const vint64 * lhs, int32_t rhs);
+extern vint64 addv64u32(const vint64 * lhs, uint32_t rhs);
+
+extern vint64 subv64(const vint64 *lhs, const vint64 *rhs);
+extern vint64 subv64i32(const vint64 * lhs, int32_t rhs);
+extern vint64 subv64u32(const vint64 * lhs, uint32_t rhs);
+
+/* parsing. works like strtoul() or strtoull() */
+extern vint64 strtouv64(const char * begp, char ** endp, int base);
+
+#endif /*!defined(VINT64OPS_H)*/