diff options
Diffstat (limited to 'include')
82 files changed, 11723 insertions, 0 deletions
diff --git a/include/Makefile.am b/include/Makefile.am new file mode 100644 index 000000000000..8f8b934afeb4 --- /dev/null +++ b/include/Makefile.am @@ -0,0 +1,58 @@ +#AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies +AUTOMAKE_OPTIONS = ../util/ansi2knr +ETAGS_ARGS = $(srcdir)/Makefile.am +#EXTRA_DIST = TAGS + +SUBDIRS = isc + +noinst_HEADERS = \ + adjtime.h \ + audio.h \ + ascii.h \ + audio.h \ + binio.h \ + global.h \ + gps.h \ + hopf6039.h \ + icom.h \ + ieee754io.h \ + iosignal.h \ + l_stdlib.h \ + mbg_gps166.h \ + mx4200.h \ + ntif.h \ + ntp.h \ + ntp_calendar.h \ + ntp_cmdargs.h \ + ntp_config.h \ + ntp_control.h \ + ntp_crypto.h \ + ntp_datum.h \ + ntp_filegen.h \ + ntp_fp.h \ + ntp_if.h \ + ntp_io.h \ + ntp_machine.h \ + ntp_malloc.h \ + ntp_md5.h \ + ntp_proto.h \ + ntp_refclock.h \ + ntp_request.h \ + ntp_rfc2553.h \ + ntp_select.h \ + ntp_sprintf.h \ + ntp_stdlib.h \ + ntp_string.h \ + ntp_syscall.h \ + ntp_syslog.h \ + ntp_tty.h \ + ntp_types.h \ + ntp_unixtime.h \ + ntpd.h \ + ntpsim.h \ + parse.h \ + parse_conf.h \ + recvbuff.h \ + rsa_md5.h \ + trimble.h + diff --git a/include/Makefile.in b/include/Makefile.in new file mode 100644 index 000000000000..d0a688243ec3 --- /dev/null +++ b/include/Makefile.in @@ -0,0 +1,501 @@ +# Makefile.in generated by automake 1.7.7 from Makefile.am. +# @configure_input@ + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 +# Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. + +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +ARLIB_DIR = @ARLIB_DIR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CHUTEST = @CHUTEST@ +CLKTEST = @CLKTEST@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DCFD = @DCFD@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EF_LIBS = @EF_LIBS@ +EF_PROGS = @EF_PROGS@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LCRYPTO = @LCRYPTO@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBPARSE = @LIBPARSE@ +LIBS = @LIBS@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAKE_ADJTIMED = @MAKE_ADJTIMED@ +MAKE_CHECK_Y2K = @MAKE_CHECK_Y2K@ +MAKE_LIBNTPSIM = @MAKE_LIBNTPSIM@ +MAKE_LIBPARSE = @MAKE_LIBPARSE@ +MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@ +MAKE_NTPDSIM = @MAKE_NTPDSIM@ +MAKE_NTPTIME = @MAKE_NTPTIME@ +MAKE_NTP_KEYGEN = @MAKE_NTP_KEYGEN@ +MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@ +MAKE_SNTP = @MAKE_SNTP@ +MAKE_TICKADJ = @MAKE_TICKADJ@ +MAKE_TIMETRIM = @MAKE_TIMETRIM@ +OBJEXT = @OBJEXT@ +OPENSSL = @OPENSSL@ +OPENSSL_INC = @OPENSSL_INC@ +OPENSSL_LIB = @OPENSSL_LIB@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_PERL = @PATH_PERL@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_SH = @PATH_SH@ +PROPDELAY = @PROPDELAY@ +RANLIB = @RANLIB@ +READLINE_LIBS = @READLINE_LIBS@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TESTDCF = @TESTDCF@ +U = @U@ +VERSION = @VERSION@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +subdirs = @subdirs@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ + +#AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies +AUTOMAKE_OPTIONS = ../util/ansi2knr +ETAGS_ARGS = $(srcdir)/Makefile.am + +#EXTRA_DIST = TAGS +SUBDIRS = isc + +noinst_HEADERS = \ + adjtime.h \ + audio.h \ + ascii.h \ + audio.h \ + binio.h \ + global.h \ + gps.h \ + hopf6039.h \ + icom.h \ + ieee754io.h \ + iosignal.h \ + l_stdlib.h \ + mbg_gps166.h \ + mx4200.h \ + ntif.h \ + ntp.h \ + ntp_calendar.h \ + ntp_cmdargs.h \ + ntp_config.h \ + ntp_control.h \ + ntp_crypto.h \ + ntp_datum.h \ + ntp_filegen.h \ + ntp_fp.h \ + ntp_if.h \ + ntp_io.h \ + ntp_machine.h \ + ntp_malloc.h \ + ntp_md5.h \ + ntp_proto.h \ + ntp_refclock.h \ + ntp_request.h \ + ntp_rfc2553.h \ + ntp_select.h \ + ntp_sprintf.h \ + ntp_stdlib.h \ + ntp_string.h \ + ntp_syscall.h \ + ntp_syslog.h \ + ntp_tty.h \ + ntp_types.h \ + ntp_unixtime.h \ + ntpd.h \ + ntpsim.h \ + parse.h \ + parse_conf.h \ + recvbuff.h \ + rsa_md5.h \ + trimble.h + +subdir = include +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +DIST_SOURCES = +HEADERS = $(noinst_HEADERS) + + +RECURSIVE_TARGETS = info-recursive dvi-recursive pdf-recursive \ + ps-recursive install-info-recursive uninstall-info-recursive \ + all-recursive install-data-recursive install-exec-recursive \ + installdirs-recursive install-recursive uninstall-recursive \ + check-recursive installcheck-recursive +DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/Makefile.in \ + Makefile.am +DIST_SUBDIRS = $(SUBDIRS) +all: all-recursive + +.SUFFIXES: +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu include/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) +uninstall-info-am: + +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @set fnord $$MAKEFLAGS; amf=$$2; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +mostlyclean-recursive clean-recursive distclean-recursive \ +maintainer-clean-recursive: + @set fnord $$MAKEFLAGS; amf=$$2; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + +ETAGS = etags +ETAGSFLAGS = + +CTAGS = ctags +CTAGSFLAGS = + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique + +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + if (etags --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + else \ + include_option=--include; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -f $$subdir/TAGS && \ + tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique + +ctags: CTAGS +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + +top_distdir = .. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkinstalldirs) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -d $(distdir)/$$subdir \ + || mkdir $(distdir)/$$subdir \ + || exit 1; \ + (cd $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$(top_distdir)" \ + distdir=../$(distdir)/$$subdir \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-recursive +all-am: Makefile $(HEADERS) +installdirs: installdirs-recursive +installdirs-am: + +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-recursive + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-recursive + +dvi-am: + +info: info-recursive + +info-am: + +install-data-am: + +install-exec-am: + +install-info: install-info-recursive + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: uninstall-info-am + +uninstall-info: uninstall-info-recursive + +.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am clean \ + clean-generic clean-recursive ctags ctags-recursive distclean \ + distclean-generic distclean-recursive distclean-tags distdir \ + dvi dvi-am dvi-recursive info info-am info-recursive install \ + install-am install-data install-data-am install-data-recursive \ + install-exec install-exec-am install-exec-recursive \ + install-info install-info-am install-info-recursive install-man \ + install-recursive install-strip installcheck installcheck-am \ + installdirs installdirs-am installdirs-recursive \ + maintainer-clean maintainer-clean-generic \ + maintainer-clean-recursive mostlyclean mostlyclean-generic \ + mostlyclean-recursive pdf pdf-am pdf-recursive ps ps-am \ + ps-recursive tags tags-recursive uninstall uninstall-am \ + uninstall-info-am uninstall-info-recursive uninstall-recursive + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/include/README b/include/README new file mode 100644 index 000000000000..5d818dc002f8 --- /dev/null +++ b/include/README @@ -0,0 +1,4 @@ +README file for directory ./include of the NTP Version 4 distribution + +This directory contains the include files used by most programs in this +distribution. diff --git a/include/adjtime.h b/include/adjtime.h new file mode 100644 index 000000000000..b6e2a3e99541 --- /dev/null +++ b/include/adjtime.h @@ -0,0 +1,69 @@ +/*************************************************************************/ +/* (c) Copyright Tai Jin, 1988. All Rights Reserved. */ +/* Hewlett-Packard Laboratories. */ +/* */ +/* Permission is hereby granted for unlimited modification, use, and */ +/* distribution. This software is made available with no warranty of */ +/* any kind, express or implied. This copyright notice must remain */ +/* intact in all versions of this software. */ +/* */ +/* The author would appreciate it if any bug fixes and enhancements were */ +/* to be sent back to him for incorporation into future versions of this */ +/* software. Please send changes to tai@iag.hp.com or ken@sdd.hp.com. */ +/*************************************************************************/ + +/* "adjtime.h,v 3.1 1993/07/06 01:04:43 jbj Exp" */ +/* adjtime.h,v + * Revision 3.1 1993/07/06 01:04:43 jbj + * NTP release 3.1 + * + * + * Revision 1.5 90/02/07 15:34:18 15:34:18 src (Source Hacker) + * CHANGED KEY !!! + * + * Revision 1.4 89/02/09 12:26:35 12:26:35 tai (Tai Jin (Guest)) + * *** empty log message *** + * + * Revision 1.4 89/02/09 12:26:35 12:26:35 tai (Tai Jin) + * added comment + * + * Revision 1.3 88/08/30 01:08:29 01:08:29 tai (Tai Jin) + * fix copyright notice again + * + * Revision 1.2 88/08/30 00:51:55 00:51:55 tai (Tai Jin) + * fix copyright notice + * + * Revision 1.1 88/04/02 14:56:54 14:56:54 tai (Tai Jin) + * Initial revision + * */ + +#include "ntp_types.h" + +#ifdef __QNXNTO__ +int adjtime( const struct timeval * oldtime, struct timeval * newtime ); +#else /* not __QNXNTO__ */ + +#define KEY 659847L + +typedef union { + struct msgbuf msgp; + struct { + long mtype; + int code; + struct timeval tv; + } msgb; +} MsgBuf; + +#define MSGSIZE (sizeof(int) + sizeof(struct timeval)) +/* + * mtype values + */ +#define CLIENT 1L +#define SERVER 2L +/* + * code values + */ +#define DELTA1 0 +#define DELTA2 1 + +#endif /* not __QNXNTO__ */ diff --git a/include/ascii.h b/include/ascii.h new file mode 100644 index 000000000000..c679362c1226 --- /dev/null +++ b/include/ascii.h @@ -0,0 +1,61 @@ +/* + * /src/NTP/ntp-4/include/ascii.h,v 4.1 1998/07/11 10:05:22 kardel RELEASE_19990228_A + * + * $Created: Sun Jul 20 11:42:53 1997 $ + * + * Copyright (C) 1997 by Frank Kardel + */ +#ifndef ASCII_H +#define ASCII_H + +/* + * just name the common ASCII control codes + */ +#define NUL 0 +#define SOH 1 +#define STX 2 +#define ETX 3 +#define EOT 4 +#define ENQ 5 +#define ACK 6 +#define BEL 7 +#define BS 8 +#define HT 9 +#define NL 10 +#define VT 11 +#define NP 12 +#define CR 13 +#define SO 14 +#define SI 15 +#define DLE 16 +#define DC1 17 +#define DC2 18 +#define DC3 19 +#define DC4 20 +#define NAK 21 +#define SYN 22 +#define ETB 23 +#define CAN 24 +#define EM 25 +#define SUB 26 +#define ESC 27 +#define FS 28 +#define GS 29 +#define RS 30 +#define US 31 +#define SP 32 +#define DEL 127 + +#endif +/* + * ascii.h,v + * Revision 4.1 1998/07/11 10:05:22 kardel + * Release 4.0.73d reconcilation + * + * Revision 4.0 1998/04/10 19:50:38 kardel + * Start 4.0 release version numbering + * + * Revision 4.0 1998/04/10 19:50:38 kardel + * Start 4.0 release version numbering + * + */ diff --git a/include/audio.h b/include/audio.h new file mode 100644 index 000000000000..6d16347ec80d --- /dev/null +++ b/include/audio.h @@ -0,0 +1,14 @@ +/* + * Header file for audio drivers + */ +#include "ntp_types.h" + +#define MAXGAIN 255 /* max codec gain */ +#define MONGAIN 127 /* codec monitor gain */ + +/* + * Function prototypes + */ +int audio_init P((char *, int, int)); +int audio_gain P((int, int, int)); +void audio_show P((void)); diff --git a/include/binio.h b/include/binio.h new file mode 100644 index 000000000000..49feee9a21c9 --- /dev/null +++ b/include/binio.h @@ -0,0 +1,41 @@ +/* + * /src/NTP/ntp-4/include/binio.h,v 4.2 1998/06/28 16:52:15 kardel RELEASE_19990228_A + * + * $Created: Sun Jul 20 13:03:05 1997 $ + * + * Copyright (C) 1997-1998 by Frank Kardel + */ +#ifndef BINIO_H +#define BINIO_H + +#include "ntp_stdlib.h" + +long get_lsb_short P((unsigned char **)); +void put_lsb_short P((unsigned char **, long)); +long get_lsb_long P((unsigned char **)); +void put_lsb_long P((unsigned char **, long)); + +long get_msb_short P((unsigned char **)); +void put_msb_short P((unsigned char **, long)); +long get_msb_long P((unsigned char **)); +void put_msb_long P((unsigned char **, long)); + +#endif +/* + * binio.h,v + * Revision 4.2 1998/06/28 16:52:15 kardel + * added binio MSB prototypes for {get,put}_msb_{short,long} + * + * Revision 4.1 1998/06/12 15:07:40 kardel + * fixed prototyping + * + * Revision 4.0 1998/04/10 19:50:38 kardel + * Start 4.0 release version numbering + * + * Revision 1.1 1998/04/10 19:27:32 kardel + * initial NTP VERSION 4 integration of PARSE with GPS166 binary support + * + * Revision 1.1 1997/10/06 20:55:37 kardel + * new parse structure + * + */ diff --git a/include/global.h b/include/global.h new file mode 100644 index 000000000000..742f84cd9433 --- /dev/null +++ b/include/global.h @@ -0,0 +1,54 @@ +/* GLOBAL.H - RSAREF types and constants */ + +/* Copyright (C) RSA Laboratories, a division of RSA Data Security, + Inc., created 1991. All rights reserved. + */ + +/* + * Note: the modifications are necessary for little-endian machines + */ +#include "ntp_types.h" /* local modification */ + +#ifndef _GLOBAL_H_ +#define _GLOBAL_H_ 1 + +/* PROTOTYPES should be set to one if and only if the compiler supports + function argument prototyping. + The following makes PROTOTYPES default to 1 if it has not already been + defined as 0 with C compiler flags. + */ +#ifdef HAVE_PROTOTYPES +#define PROTOTYPES 1 +#endif + +/* POINTER defines a generic pointer type */ +typedef unsigned char *POINTER; + +/* UINT2 defines a two byte word */ +typedef unsigned short int UINT2; + +/* UINT4 defines a four byte word */ +typedef u_int32 UINT4; /* local modification */ + +/* BYTE defines a unsigned character */ +typedef unsigned char BYTE; /* local modification for RSAEuro */ + +#ifndef NULL_PTR +#define NULL_PTR ((POINTER)0) +#endif + +#ifndef UNUSED_ARG +#define UNUSED_ARG(x) x = *(&x); +#endif + +/* PROTO_LIST is defined depending on how PROTOTYPES is defined above. + If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it + returns an empty list. + */ +#if PROTOTYPES +#define PROTO_LIST(list) list +#else +#define PROTO_LIST(list) () +#endif + +#endif /* end _GLOBAL_H_ */ diff --git a/include/gps.h b/include/gps.h new file mode 100644 index 000000000000..d4f2dbc672ae --- /dev/null +++ b/include/gps.h @@ -0,0 +1,53 @@ +/****************************************************************************/ +/* gps.h */ +/* TrueTime GPS-VME and VME-SG */ +/* VME controller hardware commands and parameters. */ +/* created 010694 res */ +/* History: revised for 747i 3/94 */ +/****************************************************************************/ + + +#define GPS_VME "/dev/vme2" /* the device file for the GPS board */ + /* change it to whatever yours is */ +#define PRIO 120 /* set the realtime priority */ +#define NREGS 7 /* number of registers we will use */ + +#define GFRZ1 0x0020 /* freeze cmd addr gen reg. 1 */ +#define GREG1A 0x0021 /* Gen reg. 1 Word A (units microsec to 0.001 sec) */ +#define GREG1B 0x0040 /* Gen reg. 1 Word B (units 0.01 sec to tens sec ) */ +#define GREG1C 0x0041 /* Gen reg 1 Word C (units mins and hours) */ +#define GREG1D 0x0042 /* Gen reg. 1 Word D (units days and status) */ +#define GREG1E 0x0043 /* Gen reg. 1 Word E (units Years ) */ +#define GUFRZ1 0x0022 /* unfreeze cmd addr gen reg 1 */ + +#define MASKDAY 0x0FFF /* mask for units days */ +#define MASKHI 0xFF00 +#define MASKLO 0x00FF +/* Use the following ASCII hex values: N(0x004e),S(0x0053),E(0x0045), + W(0x0057), +(0x002B), - (0x002D) */ + +#define LAT1 0x0048 /* Lat (degrees) */ +#define LAT2 0x0049 /* Lat (min, sec) */ +#define LAT3 0x004A /* Lat (N/S, tenths sec) */ +#define LON1 0x004B /* Lon (degrees) */ +#define LON2 0x004C /* Lon (min, sec) */ +#define LON3 0x004D /* Lon (E/W, tenths sec) */ +#define ELV1 0x004E /* Elev. (sign, 10,000 and 1000 ) */ +#define ELV2 0x004F /* Elev. (100, 10s, units, and .1) */ + +#define CFREG1 0x0050 /* config. register 1 */ +#define CFREG2 0x00A0 /* config. register 2 */ +#define PMODE 0x00A4 /* Position mode */ +#define LOCAL 0x0051 /* Local hours offset */ +#define RATE 0x0054 /* Pulse rate output select */ +#define DAC 0x0055 /* OSC Control (DAC) select */ + +#define PUMS 0x0056 /* Gen. preset register unit millisec */ +#define PMS 0x0057 /* Gen. preset register units hundreds and tens ms */ +#define PSEC 0x0058 /* Gen. preset register units tens and unit seconds */ +#define PMIN 0x0059 /* Gen. preset register units tens and unit minutes */ +#define PHRS 0x005A /* Gen. preset register units tens and unit hours */ +#define PDYS1 0x005B /* Gen. preset register units tens and unit days */ +#define PDYS2 0x005C /* Gen. preset register units hundreds days */ +#define PYRS1 0x005D /* Gen. preset register units tens and unit years */ +#define PYRS2 0x005E /* Gen. preset reg. units thousands and hundreds yrs */ diff --git a/include/hopf6039.h b/include/hopf6039.h new file mode 100644 index 000000000000..853209937b99 --- /dev/null +++ b/include/hopf6039.h @@ -0,0 +1,144 @@ +/****************************************************************************/ +/* hopf6039.h */ +/* hopf Elektronik 6039 PCI radio clock header */ +/* (c) 1999, 2000 Bernd Altmeier <altmeier@ATLSoft.de> */ +/* Rev. 1.00 Date 25.03.2000 */ +/* History: */ +/****************************************************************************/ + +#ifndef _hopf6039_H_ +#define _hopf6039_H_ + +#define HOPF_MAXVERSION 8 +#define HOPF_CNTR_MEM_LEN 0x7f +#define HOPF_DATA_MEM_LEN 0x3ff /* this is our memory size */ + +/* macros and definition for 32 to 16 to 8 bit conversion */ + +typedef unsigned long DWORD; +typedef unsigned char BYTE; +typedef unsigned short WORD; + +#define LOWORD(l) ((WORD)(l)) +#define HIWORD(l) ((WORD)(((DWORD)(l) >> 16) & 0xFFFF)) +#define LOBYTE(w) ((BYTE)(w)) +#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF)) + +/* iocntl codes for driver access */ + +#define HOPF_CLOCK_CMD_MASK 0xff000 + +#define HOPF_CLOCK_GET_LOCAL 0x10000 +#define HOPF_CLOCK_GET_UTC 0x20000 +#define HOPF_CLOCK_GET_ANTENNA 0x30000 +#define HOPF_CLOCK_GET_DIFFERENCE 0x40000 +#define HOPF_CLOCK_GET_VERSION 0x50000 +#define HOPF_CLOCK_GET_POSITION 0x60000 +#define HOPF_CLOCK_GET_SATDATA 0x70000 +#define HOPF_CLOCK_GET_SYSTEMBYTE 0x80000 +#define HOPF_CLOCK_GET_IRIG 0x90000 + +#define HOPF_CLOCK_SET_DIFFERENCE 0x01000 +#define HOPF_CLOCK_SET_ANTENNA 0x02000 +#define HOPF_CLOCK_SET_TIME 0x03000 +#define HOPF_CLOCK_SET_POSITION 0x04000 +#define HOPF_CLOCK_SET_SATMODE 0x05000 +#define HOPF_CLOCK_SET_SYSTEMBYTE 0x06000 +#define HOPF_CLOCK_SET_RESET 0x07000 +#define HOPF_CLOCK_SET_IRIG 0x08000 + +/* clock command codes */ + +#define HOPF_CLOCK_HARDRESET 0x00008000 +#define HOPF_CLOCK_SOFTRESET 0x00004000 + +/* sat-information */ + +typedef struct SatStat{ + BYTE wVisible; + BYTE wMode; + BYTE wSat0; + BYTE wRat0; + BYTE wSat1; + BYTE wRat1; + BYTE wSat2; + BYTE wRat2; + BYTE wSat3; + BYTE wRat3; + BYTE wSat4; + BYTE wRat4; + BYTE wSat5; + BYTE wRat5; + BYTE wSat6; + BYTE wRat6; + BYTE wSat7; + BYTE wRat7; +} SatStat; + +/* GPS position */ + +typedef struct GPSPos { /* Position */ + long wAltitude; + long wLongitude; + long wLatitude; +} GPSPos; + +/* clock hardware version */ + +typedef struct ClockVersion { + char cVersion[255]; /* Hardware Version like " DCF-RECEIVER, VERSION 01.01, DAT: 23.NOV.1999" */ + char dVersion[255]; /* Driver Version */ +} ClockVersion; + +/* hopftime what you think */ + +typedef struct HOPFTIME { + unsigned int wYear; + unsigned int wMonth; + unsigned int wDayOfWeek; + unsigned int wDay; + unsigned int wHour; + unsigned int wMinute; + unsigned int wSecond; + unsigned int wMilliseconds; + unsigned int wStatus; +} HOPFTIME; + +/* DCF77 antenna alignment */ + +typedef struct DcfAntenne { + BYTE bStatus; + BYTE bStatus1; + WORD wAntValue; +} DcfAntenne; + +/* hopf PCI clock */ + +typedef struct hopfCard { + char name[32]; + unsigned irq; + unsigned long membase; /* without mmap */ + unsigned int port; + + int versionlen; + char versionbuf[1024]; + char *version[HOPF_MAXVERSION]; + char cardname[32]; + int interrupt; + void *mbase; /* this will be our memory base address */ + +} hopfCard; + +typedef struct cardparams { + unsigned int port; + unsigned irq; + int cardtype; + int cardnr; + unsigned int membase; +} cardparams; + + +#define WRITE_REGISTER 0x00 +#define READ_REGISTER 0x01 + +#endif /* _hopf6039_H_ */ diff --git a/include/icom.h b/include/icom.h new file mode 100755 index 000000000000..aac62c8d3de4 --- /dev/null +++ b/include/icom.h @@ -0,0 +1,87 @@ +/* + * Header file for ICOM radios + */ +#include "ntp_types.h" + +/* + * Common definitions + */ +#define P_ERMSG 0x1 /* trace bus error messages */ +#define P_TRACE 0x2 /* trace CI-V messges */ +#define RETRY 3 /* max packet retries */ +#define IBAUD B1200 /* autotune port speed */ + +/* + * Radio identifier codes + */ +#define IC1271 0x24 +#define IC1275 0x18 +#define IC271 0x20 +#define IC275 0x10 +#define IC375 0x12 +#define IC471 0x22 +#define IC475 0x14 +#define IC575 0x16 +#define IC725 0x28 +#define IC726 0x30 +#define IC735 0x04 +#define IC751 0x1c +#define IC761 0x1e +#define IC765 0x2c +#define IC775 0x46 +#define IC781 0x26 +#define IC970 0x2e +#define R7000 0x08 +#define R71 0x1a +#define R7100 0x34 +#define R72 0x32 +#define R8500 0x4a +#define R9000 0x2a + +/* + * CI-V frame codes + */ +#define PR 0xfe /* preamble */ +#define TX 0xe0 /* controller address */ +#define FI 0xfd /* end of message */ +#define ACK 0xfb /* controller normal reply */ +#define NAK 0xfa /* controller error reply */ +#define PAD 0xff /* transmit padding */ + +/* + * CI-V controller commands + */ +#define V_FREQT 0x00 /* freq set (transceive) */ +#define V_MODET 0x01 /* set mode (transceive) */ +#define V_RBAND 0x02 /* read band edge */ +#define V_RFREQ 0x03 /* read frequency */ +#define V_RMODE 0x04 /* read mode */ +#define V_SFREQ 0x05 /* set frequency */ +#define V_SMODE 0x06 /* set mode */ +#define V_SVFO 0x07 /* select vfo */ +#define V_SMEM 0x08 /* select channel/bank */ +#define V_WRITE 0x09 /* write channel */ +#define V_VFOM 0x0a /* memory -> vfo */ +#define V_CLEAR 0x0b /* clear channel */ +#define V_ROFFS 0x0c /* read tx offset */ +#define V_SOFFS 0x0d /* write tx offset */ +#define V_SCAN 0x0e /* scan control */ +#define V_SPLIT 0x0f /* split control */ +#define V_DIAL 0x10 /* set dial tuning step */ +#define V_ATTEN 0x11 /* set attenuator */ +#define V_SANT 0x12 /* select antenna */ +#define V_ANNC 0x13 /* announce control */ +#define V_WRCTL 0x14 /* write controls */ +#define V_RDCTL 0x15 /* read controls */ +#define V_TOGL 0x16 /* set switches */ +#define V_ASCII 0x17 /* send CW message */ +#define V_POWER 0x18 /* power control */ +#define V_RDID 0x19 /* read model ID */ +#define V_SETW 0x1a /* read/write channel/bank data */ +#define V_CTRL 0x7f /* miscellaneous control */ + +/* + * Function prototypes + */ +int icom_init P((char *, int, int)); +int icom_freq P((int, int, double)); diff --git a/include/ieee754io.h b/include/ieee754io.h new file mode 100644 index 000000000000..f691acc3c2ae --- /dev/null +++ b/include/ieee754io.h @@ -0,0 +1,43 @@ +/* + * /src/NTP/ntp-4/include/ieee754io.h,v 4.0 1998/04/10 19:50:40 kardel RELEASE_19990228_A + * + * $Created: Sun Jul 13 12:22:11 1997 $ + * + * Copyright (C) 1997 by Frank Kardel + */ +#ifndef IEEE754IO_H +#define IEEE754IO_H + +#define IEEE_SINGLE 1 +#define IEEE_DOUBLE 2 + +#define IEEE_MSB 1 +#define IEEE_LSB 2 + +#define IEEE_OK 0 /* conversion ok */ +#define IEEE_BADCALL 1 /* bad call parameters */ +#define IEEE_NAN 2 /* found an NaN */ +#define IEEE_POSINFINITY 3 /* positive infinity */ +#define IEEE_NEGINFINITY 4 /* negative infinity */ +#define IEEE_POSOVERFLOW 5 /* positive overflow */ +#define IEEE_NEGOVERFLOW 6 /* negative overflow */ + +#define IEEE_OFFSETS 8 /* number of byte positions */ +typedef unsigned char offsets_t[IEEE_OFFSETS]; + +int fetch_ieee754 P((unsigned char **bufp, int size, l_fp *lfpp, offsets_t offsets)); +int put_ieee754 P((unsigned char **bufpp, int size, l_fp *lfpp, offsets_t offsets)); + +#endif +/* + * ieee754io.h,v + * Revision 4.0 1998/04/10 19:50:40 kardel + * Start 4.0 release version numbering + * + * Revision 1.1 1998/04/10 19:27:33 kardel + * initial NTP VERSION 4 integration of PARSE with GPS166 binary support + * + * Revision 1.1 1997/10/06 20:55:37 kardel + * new parse structure + * + */ diff --git a/include/iosignal.h b/include/iosignal.h new file mode 100644 index 000000000000..bd74e096d00b --- /dev/null +++ b/include/iosignal.h @@ -0,0 +1,23 @@ +#if !defined _ntp_iosignaled_h +#define _ntp_iosignaled_h + +#include "ntp_refclock.h" + +#if defined(HAVE_SIGNALED_IO) +extern void block_sigio P((void)); +extern void unblock_sigio P((void)); +extern int init_clock_sig P((struct refclockio *)); +extern void init_socket_sig P((int)); +extern void set_signal P((void)); +RETSIGTYPE sigio_handler P((int)); + +# define BLOCKIO() ((void) block_sigio()) +# define UNBLOCKIO() ((void) unblock_sigio()) + +#else + +# define BLOCKIO() +# define UNBLOCKIO() +#endif /* HAVE_SIGNALED_IO */ + +#endif diff --git a/include/isc/Makefile.am b/include/isc/Makefile.am new file mode 100644 index 000000000000..a5b253c9ddc6 --- /dev/null +++ b/include/isc/Makefile.am @@ -0,0 +1,34 @@ +#AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies +AUTOMAKE_OPTIONS = ../util/ansi2knr +ETAGS_ARGS = $(srcdir)/Makefile.am +#EXTRA_DIST = TAGS + +noinst_HEADERS = \ + app.h \ + assertions.h \ + boolean.h \ + error.h \ + formatcheck.h \ + int.h \ + interfaceiter.h \ + ipv6.h \ + lang.h \ + lib.h \ + list.h \ + magic.h \ + mem.h \ + msgcat.h \ + msgs.h \ + mutex.h \ + net.h \ + netaddr.h \ + offset.h \ + once.h \ + platform.h \ + print.h \ + result.h \ + sockaddr.h \ + strerror.h \ + string.h \ + types.h \ + util.h diff --git a/include/isc/Makefile.in b/include/isc/Makefile.in new file mode 100644 index 000000000000..3270f4a9f726 --- /dev/null +++ b/include/isc/Makefile.in @@ -0,0 +1,380 @@ +# Makefile.in generated by automake 1.7.7 from Makefile.am. +# @configure_input@ + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 +# Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. + +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +ARLIB_DIR = @ARLIB_DIR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CHUTEST = @CHUTEST@ +CLKTEST = @CLKTEST@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DCFD = @DCFD@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EF_LIBS = @EF_LIBS@ +EF_PROGS = @EF_PROGS@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LCRYPTO = @LCRYPTO@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBPARSE = @LIBPARSE@ +LIBS = @LIBS@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAKE_ADJTIMED = @MAKE_ADJTIMED@ +MAKE_CHECK_Y2K = @MAKE_CHECK_Y2K@ +MAKE_LIBNTPSIM = @MAKE_LIBNTPSIM@ +MAKE_LIBPARSE = @MAKE_LIBPARSE@ +MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@ +MAKE_NTPDSIM = @MAKE_NTPDSIM@ +MAKE_NTPTIME = @MAKE_NTPTIME@ +MAKE_NTP_KEYGEN = @MAKE_NTP_KEYGEN@ +MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@ +MAKE_SNTP = @MAKE_SNTP@ +MAKE_TICKADJ = @MAKE_TICKADJ@ +MAKE_TIMETRIM = @MAKE_TIMETRIM@ +OBJEXT = @OBJEXT@ +OPENSSL = @OPENSSL@ +OPENSSL_INC = @OPENSSL_INC@ +OPENSSL_LIB = @OPENSSL_LIB@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_PERL = @PATH_PERL@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_SH = @PATH_SH@ +PROPDELAY = @PROPDELAY@ +RANLIB = @RANLIB@ +READLINE_LIBS = @READLINE_LIBS@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TESTDCF = @TESTDCF@ +U = @U@ +VERSION = @VERSION@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +subdirs = @subdirs@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ + +#AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies +AUTOMAKE_OPTIONS = ../util/ansi2knr +ETAGS_ARGS = $(srcdir)/Makefile.am + +#EXTRA_DIST = TAGS +noinst_HEADERS = \ + app.h \ + assertions.h \ + boolean.h \ + error.h \ + formatcheck.h \ + int.h \ + interfaceiter.h \ + ipv6.h \ + lang.h \ + lib.h \ + list.h \ + magic.h \ + mem.h \ + msgcat.h \ + msgs.h \ + mutex.h \ + net.h \ + netaddr.h \ + offset.h \ + once.h \ + platform.h \ + print.h \ + result.h \ + sockaddr.h \ + strerror.h \ + string.h \ + types.h \ + util.h + +subdir = include/isc +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +DIST_SOURCES = +HEADERS = $(noinst_HEADERS) + +DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.in Makefile.am +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu include/isc/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) +uninstall-info-am: + +ETAGS = etags +ETAGSFLAGS = + +CTAGS = ctags +CTAGSFLAGS = + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique + +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + +top_distdir = ../.. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkinstalldirs) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(HEADERS) + +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f Makefile + +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-am + +dvi-am: + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile + +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic ctags \ + distclean distclean-generic distclean-tags distdir dvi dvi-am \ + info info-am install install-am install-data install-data-am \ + install-exec install-exec-am install-info install-info-am \ + install-man install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags \ + uninstall uninstall-am uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/include/isc/app.h b/include/isc/app.h new file mode 100644 index 000000000000..5aa3d23acaca --- /dev/null +++ b/include/isc/app.h @@ -0,0 +1,212 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: app.h,v 1.1 2001/07/06 19:50:03 gson Exp $ */ + +#ifndef ISC_APP_H +#define ISC_APP_H 1 + +/***** + ***** Module Info + *****/ + +/* + * ISC Application Support + * + * Dealing with program termination can be difficult, especially in a + * multithreaded program. The routines in this module help coordinate + * the shutdown process. They are used as follows by the initial (main) + * thread of the application: + * + * isc_app_start(); Call very early in main(), before + * any other threads have been created. + * + * isc_app_run(); This will post any on-run events, + * and then block until application + * shutdown is requested. A shutdown + * request is made by calling + * isc_app_shutdown(), or by sending + * SIGINT or SIGTERM to the process. + * After isc_app_run() returns, the + * application should shutdown itself. + * + * isc_app_finish(); Call very late in main(). + * + * Applications that want to use SIGHUP/isc_app_reload() to trigger reloading + * should check the result of isc_app_run() and call the reload routine if + * the result is ISC_R_RELOAD. They should then call isc_app_run() again + * to resume waiting for reload or termination. + * + * Use of this module is not required. In particular, isc_app_start() is + * NOT an ISC library initialization routine. + * + * MP: + * Clients must ensure that isc_app_start(), isc_app_run(), and + * isc_app_finish() are called at most once. isc_app_shutdown() + * is safe to use by any thread (provided isc_app_start() has been + * called previously). + * + * Reliability: + * No anticipated impact. + * + * Resources: + * None. + * + * Security: + * No anticipated impact. + * + * Standards: + * None. + */ + +#include <isc/eventclass.h> +#include <isc/lang.h> +#include <isc/result.h> + +typedef isc_event_t isc_appevent_t; + +#define ISC_APPEVENT_FIRSTEVENT (ISC_EVENTCLASS_APP + 0) +#define ISC_APPEVENT_SHUTDOWN (ISC_EVENTCLASS_APP + 1) +#define ISC_APPEVENT_LASTEVENT (ISC_EVENTCLASS_APP + 65535) + +ISC_LANG_BEGINDECLS + +isc_result_t +isc_app_start(void); +/* + * Start an ISC library application. + * + * Notes: + * This call should be made before any other ISC library call, and as + * close to the beginning of the application as possible. + */ + +isc_result_t +isc_app_onrun(isc_mem_t *mctx, isc_task_t *task, isc_taskaction_t action, + void *arg); +/* + * Request delivery of an event when the application is run. + * + * Requires: + * isc_app_start() has been called. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_NOMEMORY + */ + +isc_result_t +isc_app_run(void); +/* + * Run an ISC library application. + * + * Notes: + * The caller (typically the initial thread of an application) will + * block until shutdown is requested. When the call returns, the + * caller should start shutting down the application. + * + * Requires: + * isc_app_start() has been called. + * + * Ensures: + * Any events requested via isc_app_onrun() will have been posted (in + * FIFO order) before isc_app_run() blocks. + * + * Returns: + * ISC_R_SUCCESS Shutdown has been requested. + * ISC_R_RELOAD Reload has been requested. + */ + +isc_result_t +isc_app_shutdown(void); +/* + * Request application shutdown. + * + * Notes: + * It is safe to call isc_app_shutdown() multiple times. Shutdown will + * only be triggered once. + * + * Requires: + * isc_app_run() has been called. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_UNEXPECTED + */ + +isc_result_t +isc_app_reload(void); +/* + * Request application reload. + * + * Requires: + * isc_app_run() has been called. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_UNEXPECTED + */ + +void +isc_app_finish(void); +/* + * Finish an ISC library application. + * + * Notes: + * This call should be made at or near the end of main(). + * + * Requires: + * isc_app_start() has been called. + * + * Ensures: + * Any resources allocated by isc_app_start() have been released. + */ + +void +isc_app_block(void); +/* + * Indicate that a blocking operation will be performed. + * + * Notes: + * If a blocking operation is in process, a call to isc_app_shutdown() + * or an external signal will abort the program, rather than allowing + * clean shutdown. This is primarily useful for reading user input. + * + * Requires: + * isc_app_start() has been called. + * No other blocking operations are in progress. + */ + +void +isc_app_unblock(void); +/* + * Indicate that a blocking operation is complete. + * + * Notes: + * When a blocking operation has completed, return the program to a + * state where a call to isc_app_shutdown() or an external signal will + * shutdown normally. + * + * Requires: + * isc_app_start() has been called. + * isc_app_block() has been called by the same thread. + */ + + +ISC_LANG_ENDDECLS + +#endif /* ISC_APP_H */ diff --git a/include/isc/assertions.h b/include/isc/assertions.h new file mode 100644 index 000000000000..45855c663180 --- /dev/null +++ b/include/isc/assertions.h @@ -0,0 +1,120 @@ +/* + * Copyright (C) 1997-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * $Id: assertions.h,v 1.17 2001/07/12 05:58:21 mayer Exp $ + */ + +#ifndef ISC_ASSERTIONS_H +#define ISC_ASSERTIONS_H 1 + +#include <isc/lang.h> +#include <isc/platform.h> + +ISC_LANG_BEGINDECLS + +typedef enum { + isc_assertiontype_require, + isc_assertiontype_ensure, + isc_assertiontype_insist, + isc_assertiontype_invariant +} isc_assertiontype_t; + +typedef void (*isc_assertioncallback_t)(const char *, int, isc_assertiontype_t, + const char *); + +LIBISC_EXTERNAL_DATA extern isc_assertioncallback_t isc_assertion_failed; + +void +isc_assertion_setcallback(isc_assertioncallback_t); + +const char * +isc_assertion_typetotext(isc_assertiontype_t type); + +#ifdef ISC_CHECK_ALL +#define ISC_CHECK_REQUIRE 1 +#define ISC_CHECK_ENSURE 1 +#define ISC_CHECK_INSIST 1 +#define ISC_CHECK_INVARIANT 1 +#endif + +#ifdef ISC_CHECK_NONE +#define ISC_CHECK_REQUIRE 0 +#define ISC_CHECK_ENSURE 0 +#define ISC_CHECK_INSIST 0 +#define ISC_CHECK_INVARIANT 0 +#endif + +#ifndef ISC_CHECK_REQUIRE +#define ISC_CHECK_REQUIRE 1 +#endif + +#ifndef ISC_CHECK_ENSURE +#define ISC_CHECK_ENSURE 1 +#endif + +#ifndef ISC_CHECK_INSIST +#define ISC_CHECK_INSIST 1 +#endif + +#ifndef ISC_CHECK_INVARIANT +#define ISC_CHECK_INVARIANT 1 +#endif + +#if ISC_CHECK_REQUIRE != 0 +#define ISC_REQUIRE(cond) \ + ((void) ((cond) || \ + ((isc_assertion_failed)(__FILE__, __LINE__, \ + isc_assertiontype_require, \ + #cond), 0))) +#else +#define ISC_REQUIRE(cond) ((void) 0) +#endif /* ISC_CHECK_REQUIRE */ + +#if ISC_CHECK_ENSURE != 0 +#define ISC_ENSURE(cond) \ + ((void) ((cond) || \ + ((isc_assertion_failed)(__FILE__, __LINE__, \ + isc_assertiontype_ensure, \ + #cond), 0))) +#else +#define ISC_ENSURE(cond) ((void) 0) +#endif /* ISC_CHECK_ENSURE */ + +#if ISC_CHECK_INSIST != 0 +#define ISC_INSIST(cond) \ + ((void) ((cond) || \ + ((isc_assertion_failed)(__FILE__, __LINE__, \ + isc_assertiontype_insist, \ + #cond), 0))) +#else +#define ISC_INSIST(cond) ((void) 0) +#endif /* ISC_CHECK_INSIST */ + +#if ISC_CHECK_INVARIANT != 0 +#define ISC_INVARIANT(cond) \ + ((void) ((cond) || \ + ((isc_assertion_failed)(__FILE__, __LINE__, \ + isc_assertiontype_invariant, \ + #cond), 0))) +#else +#define ISC_INVARIANT(cond) ((void) 0) +#endif /* ISC_CHECK_INVARIANT */ + +ISC_LANG_ENDDECLS + +#endif /* ISC_ASSERTIONS_H */ diff --git a/include/isc/boolean.h b/include/isc/boolean.h new file mode 100644 index 000000000000..d10007b5802a --- /dev/null +++ b/include/isc/boolean.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 1998-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: boolean.h,v 1.12 2001/01/09 21:56:45 bwelling Exp $ */ + +#ifndef ISC_BOOLEAN_H +#define ISC_BOOLEAN_H 1 + +typedef enum { isc_boolean_false = 0, isc_boolean_true = 1 } isc_boolean_t; + +#define ISC_FALSE isc_boolean_false +#define ISC_TRUE isc_boolean_true +#define ISC_TF(x) ((x) ? ISC_TRUE : ISC_FALSE) + +#endif /* ISC_BOOLEAN_H */ diff --git a/include/isc/error.h b/include/isc/error.h new file mode 100644 index 000000000000..1dc07748c21d --- /dev/null +++ b/include/isc/error.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 1998-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: error.h,v 1.13 2001/01/09 21:56:51 bwelling Exp $ */ + +#ifndef ISC_ERROR_H +#define ISC_ERROR_H 1 + +#include <stdarg.h> + +#include <isc/formatcheck.h> +#include <isc/lang.h> + +ISC_LANG_BEGINDECLS + +typedef void (*isc_errorcallback_t)(const char *, int, const char *, va_list); + +void +isc_error_setunexpected(isc_errorcallback_t); + +void +isc_error_setfatal(isc_errorcallback_t); + +void +isc_error_unexpected(const char *, int, const char *, ...) + ISC_FORMAT_PRINTF(3, 4); + +void +isc_error_fatal(const char *, int, const char *, ...) + ISC_FORMAT_PRINTF(3, 4); + +void +isc_error_runtimecheck(const char *, int, const char *); + +#define ISC_ERROR_RUNTIMECHECK(cond) \ + ((void) ((cond) || \ + ((isc_error_runtimecheck)(__FILE__, __LINE__, #cond), 0))) + +ISC_LANG_ENDDECLS + +#endif /* ISC_ERROR_H */ diff --git a/include/isc/formatcheck.h b/include/isc/formatcheck.h new file mode 100644 index 000000000000..e9b91698e979 --- /dev/null +++ b/include/isc/formatcheck.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: formatcheck.h,v 1.6 2001/01/09 21:56:55 bwelling Exp $ */ + +#ifndef ISC_FORMATCHECK_H +#define ISC_FORMATCHECK_H 1 + +/* + * fmt is the location of the format string parameter. + * args is the location of the first argument (or 0 for no argument checking). + * Note: the first parameter is 1, not 0. + */ +#ifdef __GNUC__ +#define ISC_FORMAT_PRINTF(fmt, args) __attribute__((__format__(__printf__, fmt, args))) +#else +#define ISC_FORMAT_PRINTF(fmt, args) +#endif + +#endif /* ISC_FORMATCHECK_H */ diff --git a/include/isc/int.h b/include/isc/int.h new file mode 100644 index 000000000000..d30e6dcc6290 --- /dev/null +++ b/include/isc/int.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: int.h,v 1.11 2001/01/09 21:58:39 bwelling Exp $ */ + +#ifndef ISC_INT_H +#define ISC_INT_H 1 + +typedef char isc_int8_t; +typedef unsigned char isc_uint8_t; +typedef short isc_int16_t; +typedef unsigned short isc_uint16_t; +typedef int isc_int32_t; +typedef unsigned int isc_uint32_t; +typedef long long isc_int64_t; +typedef unsigned long long isc_uint64_t; + +#define ISC_INT8_MIN -128 +#define ISC_INT8_MAX 127 +#define ISC_UINT8_MAX 255 + +#define ISC_INT16_MIN -32768 +#define ISC_INT16_MAX 32767 +#define ISC_UINT16_MAX 65535 + +/* + * Note that "int" is 32 bits on all currently supported Unix-like operating + * systems, but "long" can be either 32 bits or 64 bits, thus the 32 bit + * constants are not qualified with "L". + */ +#define ISC_INT32_MIN -2147483648 +#define ISC_INT32_MAX 2147483647 +#define ISC_UINT32_MAX 4294967295U + +#define ISC_INT64_MIN -9223372036854775808LL +#define ISC_INT64_MAX 9223372036854775807LL +#define ISC_UINT64_MAX 18446744073709551615ULL + +#endif /* ISC_INT_H */ diff --git a/include/isc/interfaceiter.h b/include/isc/interfaceiter.h new file mode 100644 index 000000000000..fbd1b8224615 --- /dev/null +++ b/include/isc/interfaceiter.h @@ -0,0 +1,137 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: interfaceiter.h,v 1.10 2001/01/09 21:57:01 bwelling Exp $ */ + +#ifndef ISC_INTERFACEITER_H +#define ISC_INTERFACEITER_H 1 + +/***** + ***** Module Info + *****/ + +/* + * Interface iterator + * + * Iterate over the list of network interfaces. + * + * Interfaces whose address family is not supported are ignored and never + * returned by the iterator. Interfaces whose netmask, interface flags, + * or similar cannot be obtained are also ignored, and the failure is logged. + * + * Standards: + * The API for scanning varies greatly among operating systems. + * This module attempts to hide the differences. + */ + +/*** + *** Imports + ***/ + +#include <isc/lang.h> +#include <isc/netaddr.h> +#include <isc/types.h> + +/* + * Public structure describing a network interface. + */ + +struct isc_interface { + char name[32]; /* Interface name, null-terminated. */ + unsigned int af; /* Address family. */ + isc_netaddr_t address; /* Local address. */ + isc_netaddr_t netmask; /* Network mask. */ + isc_netaddr_t broadcast; /* Broadcast address. */ + isc_netaddr_t dstaddress; /* Destination address + (point-to-point only). */ + isc_uint32_t flags; /* Flags; see below. */ +}; + +/* Interface flags. */ + +#define INTERFACE_F_UP 0x00000001U /* Interface is up */ +#define INTERFACE_F_POINTTOPOINT 0x00000002U /*this is point-to-point interface*/ +#define INTERFACE_F_LOOPBACK 0x00000004U /* this is loopback interface */ +#define INTERFACE_F_BROADCAST 0x00000008U /* Broadcast is supported */ +#define INTERFACE_F_MULTICAST 0x00000010U /* multicast is supported */ + +/*** + *** Functions + ***/ + +ISC_LANG_BEGINDECLS + +isc_result_t +isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp); +/* + * Create an iterator for traversing the operating system's list + * of network interfaces. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_NOMEMORY + * Various network-related errors + */ + +isc_result_t +isc_interfaceiter_first(isc_interfaceiter_t *iter); +/* + * Position the iterator on the first interface. + * + * Returns: + * ISC_R_SUCCESS Success. + * ISC_R_NOMORE There are no interfaces. + */ + +isc_result_t +isc_interfaceiter_current(isc_interfaceiter_t *iter, + isc_interface_t *ifdata); +/* + * Get information about the interface the iterator is currently + * positioned at and store it at *ifdata. + * + * Requires: + * The iterator has been successfully positioned using + * isc_interface_iter_first() / isc_interface_iter_next(). + * + * Returns: + * ISC_R_SUCCESS Success. + */ + +isc_result_t +isc_interfaceiter_next(isc_interfaceiter_t *iter); +/* + * Position the iterator on the next interface. + * + * Requires: + * The iterator has been successfully positioned using + * isc_interface_iter_first() / isc_interface_iter_next(). + * + * Returns: + * ISC_R_SUCCESS Success. + * ISC_R_NOMORE There are no more interfaces. + */ + +void +isc_interfaceiter_destroy(isc_interfaceiter_t **iterp); +/* + * Destroy the iterator. + */ + +ISC_LANG_ENDDECLS + +#endif /* ISC_INTERFACEITER_H */ diff --git a/include/isc/ipv6.h b/include/isc/ipv6.h new file mode 100644 index 000000000000..18893b7003ce --- /dev/null +++ b/include/isc/ipv6.h @@ -0,0 +1,153 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: ipv6.h,v 1.19 2002/04/03 06:38:33 marka Exp $ */ + +#ifndef ISC_IPV6_H +#define ISC_IPV6_H 1 + +/* + * Also define LWRES_IPV6_H to keep it from being included if liblwres is + * being used, or redefinition errors will occur. + */ +#define LWRES_IPV6_H 1 + +/***** + ***** Module Info + *****/ + +/* + * IPv6 definitions for systems which do not support IPv6. + * + * MP: + * No impact. + * + * Reliability: + * No anticipated impact. + * + * Resources: + * N/A. + * + * Security: + * No anticipated impact. + * + * Standards: + * RFC 2553. + */ + +/*** + *** Imports. + ***/ + +#include <isc/int.h> +#include <isc/platform.h> + +/* + * We probably don't need this on NTP + */ +#ifdef ISC_ONLY_IPV6 +/*** + *** Types. + ***/ + +struct in6_addr { + union { + isc_uint8_t _S6_u8[16]; + isc_uint16_t _S6_u16[8]; + isc_uint32_t _S6_u32[4]; + } _S6_un; +}; +#define s6_addr _S6_un._S6_u8 +#define s6_addr8 _S6_un._S6_u8 +#define s6_addr16 _S6_un._S6_u16 +#define s6_addr32 _S6_un._S6_u32 + +#define IN6ADDR_ANY_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}} +#define IN6ADDR_LOOPBACK_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}} + +LIBISC_EXTERNAL_DATA extern const struct in6_addr in6addr_any; +LIBISC_EXTERNAL_DATA extern const struct in6_addr in6addr_loopback; + +struct sockaddr_in6 { +#ifdef ISC_PLATFORM_HAVESALEN + isc_uint8_t sin6_len; + isc_uint8_t sin6_family; +#else + isc_uint16_t sin6_family; +#endif + isc_uint16_t sin6_port; + isc_uint32_t sin6_flowinfo; + struct in6_addr sin6_addr; + isc_uint32_t sin6_scope_id; +}; + +#ifdef ISC_PLATFORM_HAVESALEN +#define SIN6_LEN 1 +#endif + +/* + * Unspecified + */ +#define IN6_IS_ADDR_UNSPECIFIED(a) \ + (((a)->s6_addr32[0] == 0) && \ + ((a)->s6_addr32[1] == 0) && \ + ((a)->s6_addr32[2] == 0) && \ + ((a)->s6_addr32[3] == 0)) + +/* + * Loopback + */ +#define IN6_IS_ADDR_LOOPBACK(a) \ + (((a)->s6_addr32[0] == 0) && \ + ((a)->s6_addr32[1] == 0) && \ + ((a)->s6_addr32[2] == 0) && \ + ((a)->s6_addr32[3] == htonl(1))) + +/* + * IPv4 compatible + */ +#define IN6_IS_ADDR_V4COMPAT(a) \ + (((a)->s6_addr32[0] == 0) && \ + ((a)->s6_addr32[1] == 0) && \ + ((a)->s6_addr32[2] == 0) && \ + ((a)->s6_addr32[3] != 0) && \ + ((a)->s6_addr32[3] != htonl(1))) + +/* + * Mapped + */ +#define IN6_IS_ADDR_V4MAPPED(a) \ + (((a)->s6_addr32[0] == 0) && \ + ((a)->s6_addr32[1] == 0) && \ + ((a)->s6_addr32[2] == htonl(0x0000ffff))) + +/* + * Multicast + */ +#define IN6_IS_ADDR_MULTICAST(a) \ + ((a)->s6_addr8[0] == 0xffU) + +/* + * Unicast link / site local. + */ +#define IN6_IS_ADDR_LINKLOCAL(a) \ + (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) +#define IN6_IS_ADDR_SITELOCAL(a) \ + (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) + +#endif /* ISC_ONLY_IPV6 */ +#endif /* ISC_IPV6_H */ diff --git a/include/isc/lang.h b/include/isc/lang.h new file mode 100644 index 000000000000..b3ba5908fe14 --- /dev/null +++ b/include/isc/lang.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: lang.h,v 1.6 2001/01/09 21:57:03 bwelling Exp $ */ + +#ifndef ISC_LANG_H +#define ISC_LANG_H 1 + +#ifdef __cplusplus +#define ISC_LANG_BEGINDECLS extern "C" { +#define ISC_LANG_ENDDECLS } +#else +#define ISC_LANG_BEGINDECLS +#define ISC_LANG_ENDDECLS +#endif + +#endif /* ISC_LANG_H */ diff --git a/include/isc/lib.h b/include/isc/lib.h new file mode 100644 index 000000000000..7feef43c5ebe --- /dev/null +++ b/include/isc/lib.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: lib.h,v 1.7 2001/11/19 03:08:25 mayer Exp $ */ + +#ifndef ISC_LIB_H +#define ISC_LIB_H 1 + +#include <isc/types.h> +#include <isc/lang.h> + +ISC_LANG_BEGINDECLS + +LIBISC_EXTERNAL_DATA extern isc_msgcat_t *isc_msgcat; + +void +isc_lib_initmsgcat(void); +/* + * Initialize the ISC library's message catalog, isc_msgcat, if it + * has not already been initialized. + */ + +ISC_LANG_ENDDECLS + +#endif /* ISC_LIB_H */ diff --git a/include/isc/list.h b/include/isc/list.h new file mode 100644 index 000000000000..d0ae7a91a6f3 --- /dev/null +++ b/include/isc/list.h @@ -0,0 +1,180 @@ +/* + * Copyright (C) 1997-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: list.h,v 1.19 2002/05/09 07:09:30 marka Exp $ */ + +#ifndef ISC_LIST_H +#define ISC_LIST_H 1 +#include <isc/boolean.h> +#include <isc/assertions.h> + +#ifdef ISC_LIST_CHECKINIT +#define ISC_LINK_INSIST(x) ISC_INSIST(x) +#else +#define ISC_LINK_INSIST(x) +#endif + +#define ISC_LIST(type) struct { type *head, *tail; } +#define ISC_LIST_INIT(list) \ + do { (list).head = NULL; (list).tail = NULL; } while (0) + +#define ISC_LINK(type) struct { type *prev, *next; } +#define ISC_LINK_INIT_TYPE(elt, link, type) \ + do { \ + (elt)->link.prev = (type *)(-1); \ + (elt)->link.next = (type *)(-1); \ + } while (0) +#define ISC_LINK_INIT(elt, link) \ + ISC_LINK_INIT_TYPE(elt, link, void) +#define ISC_LINK_LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1)) + +#define ISC_LIST_HEAD(list) ((list).head) +#define ISC_LIST_TAIL(list) ((list).tail) +#define ISC_LIST_EMPTY(list) ISC_TF((list).head == NULL) + +#define __ISC_LIST_PREPENDUNSAFE(list, elt, link) \ + do { \ + if ((list).head != NULL) \ + (list).head->link.prev = (elt); \ + else \ + (list).tail = (elt); \ + (elt)->link.prev = NULL; \ + (elt)->link.next = (list).head; \ + (list).head = (elt); \ + } while (0) + +#define ISC_LIST_PREPEND(list, elt, link) \ + do { \ + ISC_LINK_INSIST(!ISC_LINK_LINKED(elt, link)); \ + __ISC_LIST_PREPENDUNSAFE(list, elt, link); \ + } while (0) + +#define ISC_LIST_INITANDPREPEND(list, elt, link) \ + __ISC_LIST_PREPENDUNSAFE(list, elt, link) + +#define __ISC_LIST_APPENDUNSAFE(list, elt, link) \ + do { \ + if ((list).tail != NULL) \ + (list).tail->link.next = (elt); \ + else \ + (list).head = (elt); \ + (elt)->link.prev = (list).tail; \ + (elt)->link.next = NULL; \ + (list).tail = (elt); \ + } while (0) + +#define ISC_LIST_APPEND(list, elt, link) \ + do { \ + ISC_LINK_INSIST(!ISC_LINK_LINKED(elt, link)); \ + __ISC_LIST_APPENDUNSAFE(list, elt, link); \ + } while (0) + +#define ISC_LIST_INITANDAPPEND(list, elt, link) \ + __ISC_LIST_APPENDUNSAFE(list, elt, link) + +#define __ISC_LIST_UNLINKUNSAFE_TYPE(list, elt, link, type) \ + do { \ + if ((elt)->link.next != NULL) \ + (elt)->link.next->link.prev = (elt)->link.prev; \ + else \ + (list).tail = (elt)->link.prev; \ + if ((elt)->link.prev != NULL) \ + (elt)->link.prev->link.next = (elt)->link.next; \ + else \ + (list).head = (elt)->link.next; \ + (elt)->link.prev = (type *)(-1); \ + (elt)->link.next = (type *)(-1); \ + } while (0) + +#define __ISC_LIST_UNLINKUNSAFE(list, elt, link) \ + __ISC_LIST_UNLINKUNSAFE_TYPE(list, elt, link, void) + +#define ISC_LIST_UNLINK_TYPE(list, elt, link, type) \ + do { \ + ISC_LINK_INSIST(ISC_LINK_LINKED(elt, link)); \ + __ISC_LIST_UNLINKUNSAFE_TYPE(list, elt, link, type); \ + } while (0) +#define ISC_LIST_UNLINK(list, elt, link) \ + ISC_LIST_UNLINK_TYPE(list, elt, link, void) + +#define ISC_LIST_PREV(elt, link) ((elt)->link.prev) +#define ISC_LIST_NEXT(elt, link) ((elt)->link.next) + +#define __ISC_LIST_INSERTBEFOREUNSAFE(list, before, elt, link) \ + do { \ + if ((before)->link.prev == NULL) \ + ISC_LIST_PREPEND(list, elt, link); \ + else { \ + (elt)->link.prev = (before)->link.prev; \ + (before)->link.prev = (elt); \ + (elt)->link.prev->link.next = (elt); \ + (elt)->link.next = (before); \ + } \ + } while (0) + +#define ISC_LIST_INSERTBEFORE(list, before, elt, link) \ + do { \ + ISC_LINK_INSIST(ISC_LINK_LINKED(before, link)); \ + ISC_LINK_INSIST(!ISC_LINK_LINKED(elt, link)); \ + __ISC_LIST_INSERTBEFOREUNSAFE(list, before, elt, link); \ + } while (0) + +#define __ISC_LIST_INSERTAFTERUNSAFE(list, after, elt, link) \ + do { \ + if ((after)->link.next == NULL) \ + ISC_LIST_APPEND(list, elt, link); \ + else { \ + (elt)->link.next = (after)->link.next; \ + (after)->link.next = (elt); \ + (elt)->link.next->link.prev = (elt); \ + (elt)->link.prev = (after); \ + } \ + } while (0) + +#define ISC_LIST_INSERTAFTER(list, after, elt, link) \ + do { \ + ISC_LINK_INSIST(ISC_LINK_LINKED(after, link)); \ + ISC_LINK_INSIST(!ISC_LINK_LINKED(elt, link)); \ + __ISC_LIST_INSERTAFTERUNSAFE(list, after, elt, link); \ + } while (0) + +#define ISC_LIST_APPENDLIST(list1, list2, link) \ + do { \ + if (ISC_LIST_EMPTY(list1)) \ + (list1) = (list2); \ + else if (!ISC_LIST_EMPTY(list2)) { \ + (list1).tail->link.next = (list2).head; \ + (list2).head->link.prev = (list1).tail; \ + (list1).tail = (list2).tail; \ + } \ + (list2).head = NULL; \ + (list2).tail = NULL; \ + } while (0) + +#define ISC_LIST_ENQUEUE(list, elt, link) ISC_LIST_APPEND(list, elt, link) +#define __ISC_LIST_ENQUEUEUNSAFE(list, elt, link) \ + __ISC_LIST_APPENDUNSAFE(list, elt, link) +#define ISC_LIST_DEQUEUE(list, elt, link) \ + ISC_LIST_UNLINK_TYPE(list, elt, link, void) +#define ISC_LIST_DEQUEUE_TYPE(list, elt, link, type) \ + ISC_LIST_UNLINK_TYPE(list, elt, link, type) +#define __ISC_LIST_DEQUEUEUNSAFE(list, elt, link) \ + __ISC_LIST_UNLINKUNSAFE_TYPE(list, elt, link, void) +#define __ISC_LIST_DEQUEUEUNSAFE_TYPE(list, elt, link, type) \ + __ISC_LIST_UNLINKUNSAFE_TYPE(list, elt, link, type) + +#endif /* ISC_LIST_H */ diff --git a/include/isc/magic.h b/include/isc/magic.h new file mode 100644 index 000000000000..ff3df24bdfc8 --- /dev/null +++ b/include/isc/magic.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: magic.h,v 1.11 2001/01/09 21:57:10 bwelling Exp $ */ + +#ifndef ISC_MAGIC_H +#define ISC_MAGIC_H 1 + +typedef struct { + unsigned int magic; +} isc__magic_t; + + +/* + * To use this macro the magic number MUST be the first thing in the + * structure, and MUST be of type "unsigned int". + * + * The intent of this is to allow magic numbers to be checked even though + * the object is otherwise opaque. + */ +#define ISC_MAGIC_VALID(a,b) (((a) != NULL) && \ + (((const isc__magic_t *)(a))->magic == (b))) + +#define ISC_MAGIC(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d)) + +#endif /* ISC_MAGIC_H */ diff --git a/include/isc/mem.h b/include/isc/mem.h new file mode 100644 index 000000000000..f8e73d0e73d8 --- /dev/null +++ b/include/isc/mem.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 1997-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: mem.h,v 1.58 2001/09/07 00:51:51 marka Exp $ */ + +#ifndef ISC_MEM_H +#define ISC_MEM_H 1 + +#include <stdio.h> +#include <isc/types.h> + +void * +isc_mem_get(isc_mem_t *, size_t); +void +isc_mem_put(isc_mem_t *, void *, size_t); + +#endif /* ISC_MEM_H */ diff --git a/include/isc/msgcat.h b/include/isc/msgcat.h new file mode 100644 index 000000000000..d2bf1e1622d9 --- /dev/null +++ b/include/isc/msgcat.h @@ -0,0 +1,132 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: msgcat.h,v 1.8 2001/01/09 21:57:13 bwelling Exp $ */ + +#ifndef ISC_MSGCAT_H +#define ISC_MSGCAT_H 1 + +/***** + ***** Module Info + *****/ + +/* + * ISC Message Catalog + * + * Message catalogs aid internationalization of applications by allowing + * messages to be retrieved from locale-specific files instead of + * hardwiring them into the application. This allows translations of + * messages appropriate to the locale to be supplied without recompiling + * the application. + * + * Notes: + * It's very important that message catalogs work, even if only the + * default_text can be used. + * + * MP: + * The caller must ensure appropriate synchronization of + * isc_msgcat_open() and isc_msgcat_close(). isc_msgcat_get() + * ensures appropriate synchronization. + * + * Reliability: + * No anticipated impact. + * + * Resources: + * <TBS> + * + * Security: + * No anticipated impact. + * + * Standards: + * None. + */ + +/***** + ***** Imports + *****/ + +#include <isc/lang.h> +#include <isc/types.h> + +ISC_LANG_BEGINDECLS + +/***** + ***** Methods + *****/ + +void +isc_msgcat_open(const char *name, isc_msgcat_t **msgcatp); +/* + * Open a message catalog. + * + * Notes: + * + * If memory cannot be allocated or other failures occur, *msgcatp + * will be set to NULL. If a NULL msgcat is given to isc_msgcat_get(), + * the default_text will be returned, ensuring that some message text + * will be available, no matter what's going wrong. + * + * Requires: + * + * 'name' is a valid string. + * + * msgcatp != NULL && *msgcatp == NULL + */ + +void +isc_msgcat_close(isc_msgcat_t **msgcatp); +/* + * Close a message catalog. + * + * Notes: + * + * Any string pointers returned by prior calls to isc_msgcat_get() are + * invalid after isc_msgcat_close() has been called and must not be + * used. + * + * Requires: + * + * *msgcatp is a valid message catalog or is NULL. + * + * Ensures: + * + * All resources associated with the message catalog are released. + * + * *msgcatp == NULL + */ + +const char * +isc_msgcat_get(isc_msgcat_t *msgcat, int set, int message, + const char *default_text); +/* + * Get message 'message' from message set 'set' in 'msgcat'. If it + * is not available, use 'default_text'. + * + * Requires: + * + * 'msgcat' is a valid message catalog or is NULL. + * + * set > 0 + * + * message > 0 + * + * 'default_text' is a valid string. + */ + +ISC_LANG_ENDDECLS + +#endif /* ISC_MSGCAT_H */ diff --git a/include/isc/msgs.h b/include/isc/msgs.h new file mode 100644 index 000000000000..b166199e8f0d --- /dev/null +++ b/include/isc/msgs.h @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: msgs.h,v 1.7 2002/05/27 00:40:18 marka Exp $ */ + +#ifndef ISC_MSGS_H +#define ISC_MSGS_H 1 + +#include <isc/lib.h> /* Provide isc_msgcat global variable. */ +#include <isc/msgcat.h> /* Provide isc_msgcat_*() functions. */ + +/* + * Message sets, named per source file, excepting "GENERAL". + * IMPORTANT: The original list is alphabetical, but any new sets must + * be added to the end. + */ +#define ISC_MSGSET_GENERAL 1 +/* ISC_RESULT_RESULTSET 2 */ /* XXX */ +/* ISC_RESULT_UNAVAILABLESET 3 */ /* XXX */ +#define ISC_MSGSET_APP 4 +#define ISC_MSGSET_COMMANDLINE 5 +#define ISC_MSGSET_ENTROPY 6 +#define ISC_MSGSET_IFITERIOCTL 7 +#define ISC_MSGSET_IFITERSYSCTL 8 +#define ISC_MSGSET_LEX 9 +#define ISC_MSGSET_LOG 10 +#define ISC_MSGSET_MEM 11 +#define ISC_MSGSET_NETADDR 12 +#define ISC_MSGSET_PRINT 13 +#define ISC_MSGSET_RESULT 14 +#define ISC_MSGSET_RWLOCK 15 +#define ISC_MSGSET_SOCKADDR 16 +#define ISC_MSGSET_SOCKET 17 +#define ISC_MSGSET_TASK 18 +#define ISC_MSGSET_TIMER 19 +#define ISC_MSGSET_UTIL 20 + +/* + * Message numbers. They are only required to be unique per message set, + * but are unique throughout the entire catalog to not be as confusing when + * debugging. + * + * The initial numbering was done by multiply by 100 the set number the + * message appears in then adding the incremental message number. + */ +#define ISC_MSG_FAILED 101 /* "failed" */ +#define ISC_MSG_SUCCEEDED 102 /* Compatible with "failed" */ +#define ISC_MSG_SUCCESS 103 /* More usual way to say "success" */ +#define ISC_MSG_STARTING 104 /* As in "daemon: starting" */ +#define ISC_MSG_STOPING 105 /* As in "daemon: stopping" */ +#define ISC_MSG_ENTERING 106 /* As in "some_subr: entering" */ +#define ISC_MSG_EXITING 107 /* As in "some_subr: exiting" */ +#define ISC_MSG_CALLING 108 /* As in "calling some_subr()" */ +#define ISC_MSG_RETURNED 109 /* As in "some_subr: returned <foo>" */ +#define ISC_MSG_FATALERROR 110 /* "fatal error" */ +#define ISC_MSG_SHUTTINGDOWN 111 /* "shutting down" */ +#define ISC_MSG_RUNNING 112 /* "running" */ +#define ISC_MSG_WAIT 113 /* "wait" */ +#define ISC_MSG_WAITUNTIL 114 /* "waituntil" */ + +#define ISC_MSG_SIGNALSETUP 201 /* "handle_signal() %d setup: %s" */ + +#define ISC_MSG_ILLEGALOPT 301 /* "illegal option" */ +#define ISC_MSG_OPTNEEDARG 302 /* "option requires an argument" */ + +#define ISC_MSG_ENTROPYSTATS 401 /* "Entropy pool %p: refcnt %u ..." */ + +#define ISC_MSG_MAKESCANSOCKET 501 /* "making interface scan socket: %s" */ +#define ISC_MSG_GETIFCONFIG 502 /* "get interface configuration: %s" */ +#define ISC_MSG_BUFFERMAX 503 /* "... maximum buffer size exceeded" */ +#define ISC_MSG_GETDESTADDR 504 /* "%s: getting destination address: %s" */ +#define ISC_MSG_GETNETMASK 505 /* "%s: getting netmask: %s" */ + +#define ISC_MSG_GETIFLISTSIZE 601 /* "getting interface list size: ..." */ +#define ISC_MSG_GETIFLIST 602 /* "getting interface list: ..." */ +#define ISC_MSG_UNEXPECTEDTYPE 603 /* "... unexpected ... message type" */ + +#define ISC_MSG_UNEXPECTEDSTATE 701 /* "Unexpected state %d" */ + +#define ISC_MSG_BADTIME 801 /* "Bad 00 99:99:99.999 " */ +#define ISC_MSG_LEVEL 802 /* "level %d: " */ + +#define ISC_MSG_ADDTRACE 901 /* "add %p size %u " */ +#define ISC_MSG_DELTRACE 902 /* "del %p size %u " */ +#define ISC_MSG_POOLSTATS 903 /* "[Pool statistics]\n" */ +#define ISC_MSG_POOLNAME 904 /* "name" */ +#define ISC_MSG_POOLSIZE 905 /* "size" */ +#define ISC_MSG_POOLMAXALLOC 906 /* "maxalloc" */ +#define ISC_MSG_POOLALLOCATED 907 /* "allocated" */ +#define ISC_MSG_POOLFREECOUNT 908 /* "freecount" */ +#define ISC_MSG_POOLFREEMAX 909 /* "freemax" */ +#define ISC_MSG_POOLFILLCOUNT 910 /* "fillcount" */ +#define ISC_MSG_POOLGETS 911 /* "gets" */ +#define ISC_MSG_DUMPALLOC 912 /* "DUMP OF ALL OUTSTANDING MEMORY ..." */ +#define ISC_MSG_NONE 913 /* "\tNone.\n" */ +#define ISC_MSG_PTRFILELINE 914 /* "\tptr %p file %s line %u\n" */ + +#define ISC_MSG_UNKNOWNADDR 1001 /* "<unknown address, family %u>" */ + +#define ISC_MSG_NOLONGDBL 1104 /* "long doubles are not supported" */ + +#define ISC_MSG_PRINTLOCK 1201 /* "rwlock %p thread %lu ..." */ +#define ISC_MSG_READ 1202 /* "read" */ +#define ISC_MSG_WRITE 1203 /* "write" */ +#define ISC_MSG_READING 1204 /* "reading" */ +#define ISC_MSG_WRITING 1205 /* "writing" */ +#define ISC_MSG_PRELOCK 1206 /* "prelock" */ +#define ISC_MSG_POSTLOCK 1207 /* "postlock" */ +#define ISC_MSG_PREUNLOCK 1208 /* "preunlock" */ +#define ISC_MSG_POSTUNLOCK 1209 /* "postunlock" */ + +#define ISC_MSG_UNKNOWNFAMILY 1301 /* "unknown address family: %d" */ + +#define ISC_MSG_WRITEFAILED 1401 /* "write() failed during watcher ..." */ +#define ISC_MSG_READFAILED 1402 /* "read() failed during watcher ... " */ +#define ISC_MSG_PROCESSCMSG 1403 /* "processing cmsg %p" */ +#define ISC_MSG_IFRECEIVED 1404 /* "interface received on ifindex %u" */ +#define ISC_MSG_SENDTODATA 1405 /* "sendto pktinfo data, ifindex %u" */ +#define ISC_MSG_DOIORECV 1406 /* "doio_recv: recvmsg(%d) %d bytes ..." */ +#define ISC_MSG_PKTRECV 1407 /* "packet received correctly" */ +#define ISC_MSG_DESTROYING 1408 /* "destroying" */ +#define ISC_MSG_CREATED 1409 /* "created" */ +#define ISC_MSG_ACCEPTLOCK 1410 /* "internal_accept called, locked ..." */ +#define ISC_MSG_ACCEPTEDCXN 1411 /* "accepted connection, new socket %p" */ +#define ISC_MSG_INTERNALRECV 1412 /* "internal_recv: task %p got event %p" */ +#define ISC_MSG_INTERNALSEND 1413 /* "internal_send: task %p got event %p" */ +#define ISC_MSG_WATCHERMSG 1414 /* "watcher got message %d" */ +#define ISC_MSG_SOCKETSREMAIN 1415 /* "sockets exist" */ +#define ISC_MSG_PKTINFOPROVIDED 1416 /* "pktinfo structure provided, ..." */ +#define ISC_MSG_BOUND 1417 /* "bound" */ +#define ISC_MSG_ACCEPTRETURNED 1418 /* accept() returned %d/%s */ +#define ISC_MSG_TOOMANYFDS 1419 /* %s: too many open file descriptors */ +#define ISC_MSG_ZEROPORT 1420 /* dropping source port zero packet */ +#define ISC_MSG_FILTER 1420 /* setsockopt(SO_ACCEPTFILTER): %s */ + +#define ISC_MSG_AWAKE 1502 /* "awake" */ +#define ISC_MSG_WORKING 1503 /* "working" */ +#define ISC_MSG_EXECUTE 1504 /* "execute action" */ +#define ISC_MSG_EMPTY 1505 /* "empty" */ +#define ISC_MSG_DONE 1506 /* "done" */ +#define ISC_MSG_QUANTUM 1507 /* "quantum" */ + +#define ISC_MSG_SCHEDULE 1601 /* "schedule" */ +#define ISC_MSG_SIGNALSCHED 1602 /* "signal (schedule)" */ +#define ISC_MSG_SIGNALDESCHED 1603 /* "signal (deschedule)" */ +#define ISC_MSG_SIGNALDESTROY 1604 /* "signal (destroy)" */ +#define ISC_MSG_IDLERESCHED 1605 /* "idle reschedule" */ +#define ISC_MSG_EVENTNOTALLOC 1606 /* "couldn't allocate event" */ +#define ISC_MSG_SCHEDFAIL 1607 /* "couldn't schedule timer: %u" */ +#define ISC_MSG_POSTING 1608 /* "posting" */ +#define ISC_MSG_WAKEUP 1609 /* "wakeup" */ + +#define ISC_MSG_LOCK 1701 /* "LOCK" */ +#define ISC_MSG_LOCKING 1702 /* "LOCKING" */ +#define ISC_MSG_LOCKED 1703 /* "LOCKED" */ +#define ISC_MSG_UNLOCKED 1704 /* "UNLOCKED" */ +#define ISC_MSG_RWLOCK 1705 /* "RWLOCK" */ +#define ISC_MSG_RWLOCKED 1706 /* "RWLOCKED" */ +#define ISC_MSG_RWUNLOCK 1707 /* "RWUNLOCK" */ +#define ISC_MSG_BROADCAST 1708 /* "BROADCAST" */ +#define ISC_MSG_SIGNAL 1709 /* "SIGNAL" */ +#define ISC_MSG_UTILWAIT 1710 /* "WAIT" */ +#define ISC_MSG_WAITED 1711 /* "WAITED" */ + + + +#endif /* ISC_MSGS_H */ diff --git a/include/isc/mutex.h b/include/isc/mutex.h new file mode 100644 index 000000000000..fd6f3ec5ea1a --- /dev/null +++ b/include/isc/mutex.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: mutex.h,v 1.3 2001/01/09 21:57:55 bwelling Exp $ */ + +#ifndef ISC_MUTEX_H +#define ISC_MUTEX_H 1 + +#include <isc/result.h> /* for ISC_R_ codes */ + +typedef int isc_mutex_t; + +#define isc_mutex_init(mp) \ + (*(mp) = 0, ISC_R_SUCCESS) +#define isc_mutex_lock(mp) \ + ((*(mp))++ == 0 ? ISC_R_SUCCESS : ISC_R_UNEXPECTED) +#define isc_mutex_unlock(mp) \ + (--(*(mp)) == 0 ? ISC_R_SUCCESS : ISC_R_UNEXPECTED) +#define isc_mutex_trylock(mp) \ + (*(mp) == 0 ? ((*(mp))++, ISC_R_SUCCESS) : ISC_R_LOCKBUSY) +#define isc_mutex_destroy(mp) \ + (*(mp) == 0 ? (*(mp) = -1, ISC_R_SUCCESS) : ISC_R_UNEXPECTED) +#define isc_mutex_stats(fp) + +#endif /* ISC_MUTEX_H */ diff --git a/include/isc/net.h b/include/isc/net.h new file mode 100644 index 000000000000..25924febca38 --- /dev/null +++ b/include/isc/net.h @@ -0,0 +1,284 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: net.h,v 1.34 2002/04/03 06:38:38 marka Exp $ */ + +#ifndef ISC_NET_H +#define ISC_NET_H 1 + +/***** + ***** Module Info + *****/ + +/* + * Basic Networking Types + * + * This module is responsible for defining the following basic networking + * types: + * + * struct in_addr + * struct in6_addr + * struct in6_pktinfo + * struct sockaddr + * struct sockaddr_in + * struct sockaddr_in6 + * in_port_t + * + * It ensures that the AF_ and PF_ macros are defined. + * + * It declares ntoh[sl]() and hton[sl](). + * + * It declares inet_aton(), inet_ntop(), and inet_pton(). + * + * It ensures that INADDR_LOOPBACK, INADDR_ANY, IN6ADDR_ANY_INIT, + * in6addr_any, and in6addr_loopback are available. + * + * It ensures that IN_MULTICAST() is available to check for multicast + * addresses. + * + * MP: + * No impact. + * + * Reliability: + * No anticipated impact. + * + * Resources: + * N/A. + * + * Security: + * No anticipated impact. + * + * Standards: + * BSD Socket API + * RFC 2553 + */ + +/*** + *** Imports. + ***/ +#include <isc/platform.h> + +#include <sys/types.h> +#include <sys/socket.h> /* Contractual promise. */ + +#include <netinet/in.h> /* Contractual promise. */ +#include <arpa/inet.h> /* Contractual promise. */ +#ifdef ISC_PLATFORM_NEEDNETINETIN6H +#include <netinet/in6.h> /* Required on UnixWare. */ +#endif +#ifdef ISC_PLATFORM_NEEDNETINET6IN6H +#include <netinet6/in6.h> /* Required on BSD/OS for in6_pktinfo. */ +#endif + +#ifndef ISC_PLATFORM_HAVEIPV6 +#include <isc/ipv6.h> /* Contractual promise. */ +#endif + +#include <isc/lang.h> +#include <isc/types.h> + +#ifdef ISC_PLATFORM_HAVEINADDR6 +#define in6_addr in_addr6 /* Required for pre RFC2133 implementations. */ +#endif + +#ifdef ISC_PLATFORM_HAVEIPV6 +/* + * Required for some pre RFC2133 implementations. + * IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT were added in + * draft-ietf-ipngwg-bsd-api-04.txt or draft-ietf-ipngwg-bsd-api-05.txt. + * If 's6_addr' is defined then assume that there is a union and three + * levels otherwise assume two levels required. + */ +#ifndef IN6ADDR_ANY_INIT +#ifdef s6_addr +#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } +#else +#define IN6ADDR_ANY_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } +#endif +#endif + +#ifndef IN6ADDR_LOOPBACK_INIT +#ifdef s6_addr +#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } +#else +#define IN6ADDR_LOOPBACK_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } +#endif +#endif + +#ifndef IN6_IS_ADDR_V4MAPPED +#define IN6_IS_ADDR_V4MAPPED(x) \ + (memcmp((x)->s6_addr, in6addr_any.s6_addr, 10) == 0 && \ + (x)->s6_addr[10] == 0xff && (x)->s6_addr[11] == 0xff) +#endif + +#ifndef IN6_IS_ADDR_V4COMPAT +#define IN6_IS_ADDR_V4COMPAT(x) \ + (memcmp((x)->s6_addr, in6addr_any.s6_addr, 12) == 0 && \ + ((x)->s6_addr[12] != 0 || (x)->s6_addr[13] != 0 || \ + (x)->s6_addr[14] != 0 || \ + ((x)->s6_addr[15] != 0 && (x)->s6_addr[15] != 1))) +#endif + +#ifndef IN6_IS_ADDR_MULTICAST +#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) +#endif + +#ifndef IN6_IS_ADDR_LINKLOCAL +#define IN6_IS_ADDR_LINKLOCAL(a) \ + (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) +#endif + +#ifndef IN6_IS_ADDR_SITELOCAL +#define IN6_IS_ADDR_SITELOCAL(a) \ + (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) +#endif + + +#ifndef IN6_IS_ADDR_LOOPBACK +#define IN6_IS_ADDR_LOOPBACK(x) \ + (memcmp((x)->s6_addr, in6addr_loopback.s6_addr, 16) == 0) +#endif +#endif + +#ifndef AF_INET6 +#define AF_INET6 99 +#endif + +#ifndef PF_INET6 +#define PF_INET6 AF_INET6 +#endif + +#ifndef INADDR_LOOPBACK +#define INADDR_LOOPBACK 0x7f000001UL +#endif + +#if 0 +#ifndef ISC_PLATFORM_HAVEIN6PKTINFO +struct in6_pktinfo { + struct in6_addr ipi6_addr; /* src/dst IPv6 address */ + unsigned int ipi6_ifindex; /* send/recv interface index */ +}; +#endif +#endif + +/* + * Cope with a missing in6addr_any and in6addr_loopback. + */ +#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY) +extern const struct in6_addr isc_net_in6addrany; +#define in6addr_any isc_net_in6addrany +#endif + +#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRLOOPBACK) +extern const struct in6_addr isc_net_in6addrloop; +#define in6addr_loopback isc_net_in6addrloop +#endif + +/* + * Fix UnixWare 7.1.1's broken IN6_IS_ADDR_* definitions. + */ +#ifdef ISC_PLATFORM_FIXIN6ISADDR +#undef IN6_IS_ADDR_GEOGRAPHIC +#define IN6_IS_ADDR_GEOGRAPHIC(a) (((a)->S6_un.S6_l[0] & 0xE0) == 0x80) +#undef IN6_IS_ADDR_IPX +#define IN6_IS_ADDR_IPX(a) (((a)->S6_un.S6_l[0] & 0xFE) == 0x04) +#undef IN6_IS_ADDR_LINKLOCAL +#define IN6_IS_ADDR_LINKLOCAL(a) (((a)->S6_un.S6_l[0] & 0xC0FF) == 0x80FE) +#undef IN6_IS_ADDR_MULTICAST +#define IN6_IS_ADDR_MULTICAST(a) (((a)->S6_un.S6_l[0] & 0xFF) == 0xFF) +#undef IN6_IS_ADDR_NSAP +#define IN6_IS_ADDR_NSAP(a) (((a)->S6_un.S6_l[0] & 0xFE) == 0x02) +#undef IN6_IS_ADDR_PROVIDER +#define IN6_IS_ADDR_PROVIDER(a) (((a)->S6_un.S6_l[0] & 0xE0) == 0x40) +#undef IN6_IS_ADDR_SITELOCAL +#define IN6_IS_ADDR_SITELOCAL(a) (((a)->S6_un.S6_l[0] & 0xC0FF) == 0xC0FE) +#endif /* ISC_PLATFORM_FIXIN6ISADDR */ + +/* + * Ensure type in_port_t is defined. + */ +#ifdef ISC_PLATFORM_NEEDPORTT +typedef isc_uint16_t in_port_t; +#endif + +/* + * If this system does not have MSG_TRUNC (as returned from recvmsg()) + * ISC_PLATFORM_RECVOVERFLOW will be defined. This will enable the MSG_TRUNC + * faking code in socket.c. + */ +#ifndef MSG_TRUNC +#define ISC_PLATFORM_RECVOVERFLOW +#endif + +#define ISC__IPADDR(x) ((isc_uint32_t)htonl((isc_uint32_t)(x))) + +#define ISC_IPADDR_ISMULTICAST(i) \ + (((isc_uint32_t)(i) & ISC__IPADDR(0xf0000000)) \ + == ISC__IPADDR(0xe0000000)) + +/*** + *** Functions. + ***/ + +ISC_LANG_BEGINDECLS + +isc_result_t +isc_net_probeipv4(void); +/* + * Check if the system's kernel supports IPv4. + * + * Returns: + * + * ISC_R_SUCCESS IPv4 is supported. + * ISC_R_NOTFOUND IPv4 is not supported. + * ISC_R_UNEXPECTED + */ + +isc_result_t +isc_net_probeipv6(void); +/* + * Check if the system's kernel supports IPv6. + * + * Returns: + * + * ISC_R_SUCCESS IPv6 is supported. + * ISC_R_NOTFOUND IPv6 is not supported. + * ISC_R_UNEXPECTED + */ + +const char * +isc_net_ntop(int af, const void *src, char *dst, size_t size); +#ifdef ISC_PLATFORM_NEEDNTOP +#define inet_ntop isc_net_ntop +#endif + +int +isc_net_pton(int af, const char *src, void *dst); +#ifdef ISC_PLATFORM_NEEDPTON +#undef inet_pton +#define inet_pton isc_net_pton +#endif + +int +isc_net_aton(const char *cp, struct in_addr *addr); +#ifdef ISC_PLATFORM_NEEDATON +#define inet_aton isc_net_aton +#endif + +ISC_LANG_ENDDECLS + +#endif /* ISC_NET_H */ diff --git a/include/isc/netaddr.h b/include/isc/netaddr.h new file mode 100644 index 000000000000..811e8dd48e0c --- /dev/null +++ b/include/isc/netaddr.h @@ -0,0 +1,139 @@ +/* + * Copyright (C) 1998-2002 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: netaddr.h,v 1.21 2002/04/03 06:38:35 marka Exp $ */ + +#ifndef ISC_NETADDR_H +#define ISC_NETADDR_H 1 + +#include <isc/lang.h> +#include <isc/net.h> +#include <isc/types.h> +#include "ntp_rfc2553.h" + + + +ISC_LANG_BEGINDECLS + +struct isc_netaddr { + unsigned int family; + union { + struct in_addr in; + struct in6_addr in6; + } type; +}; + +isc_boolean_t +isc_netaddr_equal(const isc_netaddr_t *a, const isc_netaddr_t *b); + +isc_boolean_t +isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b, + unsigned int prefixlen); +/* + * Compare the 'prefixlen' most significant bits of the network + * addresses 'a' and 'b'. Return ISC_TRUE if they are equal, + * ISC_FALSE if not. + */ + +isc_result_t +isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp); +/* + * Convert a netmask in 's' into a prefix length in '*lenp'. + * The mask should consist of zero or more '1' bits in the most + * most significant part of the address, followed by '0' bits. + * If this is not the case, ISC_R_MASKNONCONTIG is returned. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_MASKNONCONTIG + */ + +isc_result_t +isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target); +/* + * Append a text representation of 'sockaddr' to the buffer 'target'. + * The text is NOT null terminated. Handles IPv4 and IPv6 addresses. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_NOSPACE The text or the null termination did not fit. + * ISC_R_FAILURE Unspecified failure + */ + +void +isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size); +/* + * Format a human-readable representation of the network address '*na' + * into the character array 'array', which is of size 'size'. + * The resulting string is guaranteed to be null-terminated. + */ + +#define ISC_NETADDR_FORMATSIZE \ + sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX") +/* + * Minimum size of array to pass to isc_netaddr_format(). + */ + +void +isc_netaddr_fromsockaddr(isc_netaddr_t *netaddr, const isc_sockaddr_t *source); + +void +isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina); + +void +isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6); + +void +isc_netaddr_any(isc_netaddr_t *netaddr); +/* + * Return the IPv4 wildcard address. + */ + +void +isc_netaddr_any6(isc_netaddr_t *netaddr); +/* + * Return the IPv6 wildcard address. + */ + +isc_boolean_t +isc_netaddr_ismulticast(isc_netaddr_t *na); +/* + * Returns ISC_TRUE if the address is a multicast address. + */ + +isc_boolean_t +isc_netaddr_islinklocal(isc_netaddr_t *na); +/* + * Returns ISC_TRUE if the address is a link local address. + */ + +isc_boolean_t +isc_netaddr_issitelocal(isc_netaddr_t *na); +/* + * Returns ISC_TRUE if the address is a site local address. + */ + +void +isc_netaddr_fromv4mapped(isc_netaddr_t *t, const isc_netaddr_t *s); +/* + * Convert an IPv6 v4mapped address into an IPv4 address. + */ + + +ISC_LANG_ENDDECLS + +#endif /* ISC_NETADDR_H */ diff --git a/include/isc/offset.h b/include/isc/offset.h new file mode 100644 index 000000000000..709bde4e07be --- /dev/null +++ b/include/isc/offset.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: offset.h,v 1.10 2001/01/09 21:58:43 bwelling Exp $ */ + +#ifndef ISC_OFFSET_H +#define ISC_OFFSET_H 1 + +/* + * File offsets are operating-system dependent. + */ +#include <limits.h> /* Required for CHAR_BIT. */ +#include <sys/types.h> + +typedef off_t isc_offset_t; + +/* + * POSIX says "Additionally, blkcnt_t and off_t are extended signed integral + * types", so the maximum value is all 1s except for the high bit. + * This definition is more complex than it really needs to be because it was + * crafted to keep both the SunOS 5.6 and the HP/UX 11 compilers quiet about + * integer overflow. For example, though this is equivalent to just left + * shifting 1 to the high bit and then inverting the bits, the SunOS compiler + * is unhappy about shifting a positive "1" to negative in a signed integer. + */ +#define ISC_OFFSET_MAXIMUM \ + (~(((off_t)-1 >> (sizeof(off_t) * CHAR_BIT - 1)) \ + << (sizeof(off_t) * CHAR_BIT - 1))) + +#endif /* ISC_OFFSET_H */ diff --git a/include/isc/once.h b/include/isc/once.h new file mode 100644 index 000000000000..f57d6215fe3e --- /dev/null +++ b/include/isc/once.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: once.h,v 1.3 2001/01/09 21:57:56 bwelling Exp $ */ + +#ifndef ISC_ONCE_H +#define ISC_ONCE_H 1 + +#include <isc/result.h> + +typedef isc_boolean_t isc_once_t; + +#define ISC_ONCE_INIT ISC_FALSE + +#define isc_once_do(op, f) \ + (!*(op) ? (f(), *(op) = ISC_TRUE, ISC_R_SUCCESS) : ISC_R_SUCCESS) + +#endif /* ISC_ONCE_H */ diff --git a/include/isc/platform.h b/include/isc/platform.h new file mode 100644 index 000000000000..bd11a25503a5 --- /dev/null +++ b/include/isc/platform.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: platform.h.in,v 1.28 2001/11/19 03:08:26 mayer Exp $ */ + +#ifndef ISC_PLATFORM_H +#define ISC_PLATFORM_H 1 + + +#ifndef ISC_PLATFORM_USEDECLSPEC +#define LIBISC_EXTERNAL_DATA +#define LIBDNS_EXTERNAL_DATA +#define LIBISCCC_EXTERNAL_DATA +#define LIBISCCFG_EXTERNAL_DATA +#define LIBBIND9_EXTERNAL_DATA +#endif /* ISC_PLATFORM_USEDECLSPEC */ + +/* + * Tell emacs to use C mode for this file. + * + * Local Variables: + * mode: c + * End: + */ + +#endif /* ISC_PLATFORM_H */ diff --git a/include/isc/print.h b/include/isc/print.h new file mode 100644 index 000000000000..7a1bc83b6741 --- /dev/null +++ b/include/isc/print.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: print.h,v 1.17 2001/02/27 02:19:33 gson Exp $ */ + +#ifndef ISC_PRINT_H +#define ISC_PRINT_H 1 + +/*** + *** Imports + ***/ + +#include <isc/formatcheck.h> /* Required for ISC_FORMAT_PRINTF() macro. */ +#include <isc/lang.h> +#include <isc/platform.h> + +/* + * This block allows lib/isc/print.c to be cleanly compiled even if + * the platform does not need it. The standard Makefile will still + * not compile print.c or archive print.o, so this is just to make test + * compilation ("make print.o") easier. + */ +#if !defined(ISC_PLATFORM_NEEDVSNPRINTF) && defined(ISC__PRINT_SOURCE) +#define ISC_PLATFORM_NEEDVSNPRINTF +#endif + +/*** + *** Macros + ***/ +#define ISC_PRINT_QUADFORMAT ISC_PLATFORM_QUADFORMAT + +/*** + *** Functions + ***/ + +#ifdef ISC_PLATFORM_NEEDVSNPRINTF +#include <stdarg.h> +#include <stddef.h> + +ISC_LANG_BEGINDECLS + +int +isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) + ISC_FORMAT_PRINTF(3, 0); +#define vsnprintf isc_print_vsnprintf + +int +isc_print_snprintf(char *str, size_t size, const char *format, ...) + ISC_FORMAT_PRINTF(3, 4); +#define snprintf isc_print_snprintf + +ISC_LANG_ENDDECLS +#endif /* ISC_PLATFORM_NEEDVSNPRINTF */ + +#endif /* ISC_PRINT_H */ diff --git a/include/isc/result.h b/include/isc/result.h new file mode 100644 index 000000000000..bf6b99258732 --- /dev/null +++ b/include/isc/result.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 1998-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: result.h,v 1.59 2001/11/30 01:02:17 gson Exp $ */ + +#ifndef ISC_RESULT_H +#define ISC_RESULT_H 1 + +#include <isc/lang.h> +#include <isc/types.h> + +#define ISC_R_SUCCESS 0 /* success */ +#define ISC_R_NOMEMORY 1 /* out of memory */ +#define ISC_R_TIMEDOUT 2 /* timed out */ +#define ISC_R_NOTHREADS 3 /* no available threads */ +#define ISC_R_ADDRNOTAVAIL 4 /* address not available */ +#define ISC_R_ADDRINUSE 5 /* address in use */ +#define ISC_R_NOPERM 6 /* permission denied */ +#define ISC_R_NOCONN 7 /* no pending connections */ +#define ISC_R_NETUNREACH 8 /* network unreachable */ +#define ISC_R_HOSTUNREACH 9 /* host unreachable */ +#define ISC_R_NETDOWN 10 /* network down */ +#define ISC_R_HOSTDOWN 11 /* host down */ +#define ISC_R_CONNREFUSED 12 /* connection refused */ +#define ISC_R_NORESOURCES 13 /* not enough free resources */ +#define ISC_R_EOF 14 /* end of file */ +#define ISC_R_BOUND 15 /* socket already bound */ +#define ISC_R_RELOAD 16 /* reload */ +#define ISC_R_LOCKBUSY 17 /* lock busy */ +#define ISC_R_EXISTS 18 /* already exists */ +#define ISC_R_NOSPACE 19 /* ran out of space */ +#define ISC_R_CANCELED 20 /* operation canceled */ +#define ISC_R_NOTBOUND 21 /* socket is not bound */ +#define ISC_R_SHUTTINGDOWN 22 /* shutting down */ +#define ISC_R_NOTFOUND 23 /* not found */ +#define ISC_R_UNEXPECTEDEND 24 /* unexpected end of input */ +#define ISC_R_FAILURE 25 /* generic failure */ +#define ISC_R_IOERROR 26 /* I/O error */ +#define ISC_R_NOTIMPLEMENTED 27 /* not implemented */ +#define ISC_R_UNBALANCED 28 /* unbalanced parentheses */ +#define ISC_R_NOMORE 29 /* no more */ +#define ISC_R_INVALIDFILE 30 /* invalid file */ +#define ISC_R_BADBASE64 31 /* bad base64 encoding */ +#define ISC_R_UNEXPECTEDTOKEN 32 /* unexpected token */ +#define ISC_R_QUOTA 33 /* quota reached */ +#define ISC_R_UNEXPECTED 34 /* unexpected error */ +#define ISC_R_ALREADYRUNNING 35 /* already running */ +#define ISC_R_IGNORE 36 /* ignore */ +#define ISC_R_MASKNONCONTIG 37 /* addr mask not contiguous */ +#define ISC_R_FILENOTFOUND 38 /* file not found */ +#define ISC_R_FILEEXISTS 39 /* file already exists */ +#define ISC_R_NOTCONNECTED 40 /* socket is not connected */ +#define ISC_R_RANGE 41 /* out of range */ +#define ISC_R_NOENTROPY 42 /* out of entropy */ +#define ISC_R_MULTICAST 43 /* invalid use of multicast */ +#define ISC_R_NOTFILE 44 /* not a file */ +#define ISC_R_NOTDIRECTORY 45 /* not a directory */ +#define ISC_R_QUEUEFULL 46 /* queue is full */ +#define ISC_R_FAMILYMISMATCH 47 /* address family mismatch */ +#define ISC_R_FAMILYNOSUPPORT 48 /* AF not supported */ +#define ISC_R_BADHEX 49 /* bad hex encoding */ +#define ISC_R_TOOMANYOPENFILES 50 /* too many open files */ +#define ISC_R_NOTBLOCKING 51 /* not blocking */ +#define ISC_R_UNBALANCEDQUOTES 52 /* unbalanced quotes */ +#define ISC_R_INPROGRESS 53 /* operation in progress */ +#define ISC_R_CONNECTIONRESET 54 /* connection reset */ +#define ISC_R_SOFTQUOTA 55 /* soft quota reached */ +#define ISC_R_BADNUMBER 56 /* not a valid number */ + +/* + * Not a result code: the number of results. + */ +#define ISC_R_NRESULTS 57 + +ISC_LANG_BEGINDECLS + +const char * +isc_result_totext(isc_result_t); +/* + * Convert an isc_result_t into a string message describing the result. + */ + +isc_result_t +isc_result_register(unsigned int base, unsigned int nresults, + const char **text, isc_msgcat_t *msgcat, int set); + +ISC_LANG_ENDDECLS + +#endif /* ISC_RESULT_H */ diff --git a/include/isc/sockaddr.h b/include/isc/sockaddr.h new file mode 100644 index 000000000000..5257b059de01 --- /dev/null +++ b/include/isc/sockaddr.h @@ -0,0 +1,196 @@ +/* + * Copyright (C) 1998-2002 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: sockaddr.h,v 1.39 2002/04/03 06:38:36 marka Exp $ */ + +#ifndef ISC_SOCKADDR_H +#define ISC_SOCKADDR_H 1 + +#include <isc/lang.h> +#include <isc/net.h> +#include <isc/types.h> + +struct isc_sockaddr { + union { + struct sockaddr sa; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + } type; + unsigned int length; /* XXXRTH beginning? */ + ISC_LINK(struct isc_sockaddr) link; +}; + +typedef ISC_LIST(struct isc_sockaddr) isc_sockaddrlist_t; + +ISC_LANG_BEGINDECLS + +isc_boolean_t +isc_sockaddr_equal(const isc_sockaddr_t *a, const isc_sockaddr_t *b); +/* + * Return ISC_TRUE iff the socket addresses 'a' and 'b' are equal. + */ + +isc_boolean_t +isc_sockaddr_eqaddr(const isc_sockaddr_t *a, const isc_sockaddr_t *b); +/* + * Return ISC_TRUE iff the address parts of the socket addresses + * 'a' and 'b' are equal, ignoring the ports. + */ + +isc_boolean_t +isc_sockaddr_eqaddrprefix(const isc_sockaddr_t *a, const isc_sockaddr_t *b, + unsigned int prefixlen); +/* + * Return ISC_TRUE iff the most significant 'prefixlen' bits of the + * socket addresses 'a' and 'b' are equal, ignoring the ports. + */ + +unsigned int +isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, isc_boolean_t address_only); +/* + * Return a hash value for the socket address 'sockaddr'. If 'address_only' + * is ISC_TRUE, the hash value will not depend on the port. + * + * IPv6 addresses containing mapped IPv4 addresses generate the same hash + * value as the equivalent IPv4 address. + */ + +void +isc_sockaddr_any(isc_sockaddr_t *sockaddr); +/* + * Return the IPv4 wildcard address. + */ + +void +isc_sockaddr_any6(isc_sockaddr_t *sockaddr); +/* + * Return the IPv6 wildcard address. + */ + +void +isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int family); +/* + * Set '*sockaddr' to the wildcard address of protocol family + * 'family'. + * + * Requires: + * 'family' is AF_INET or AF_INET6. + */ + +void +isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina, + in_port_t port); +/* + * Construct an isc_sockaddr_t from an IPv4 address and port. + */ + +void +isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, const struct in6_addr *ina6, + in_port_t port); +/* + * Construct an isc_sockaddr_t from an IPv6 address and port. + */ + +void +isc_sockaddr_v6fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina, + in_port_t port); +/* + * Construct an IPv6 isc_sockaddr_t representing a mapped IPv4 address. + */ + +void +isc_sockaddr_fromnetaddr(isc_sockaddr_t *sockaddr, const isc_netaddr_t *na, + in_port_t port); +/* + * Construct an isc_sockaddr_t from an isc_netaddr_t and port. + */ + +int +isc_sockaddr_pf(const isc_sockaddr_t *sockaddr); +/* + * Get the protocol family of 'sockaddr'. + * + * Requires: + * + * 'sockaddr' is a valid sockaddr with an address family of AF_INET + * or AF_INET6. + * + * Returns: + * + * The protocol family of 'sockaddr', e.g. PF_INET or PF_INET6. + */ + +void +isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port); +/* + * Set the port of 'sockaddr' to 'port'. + */ + +in_port_t +isc_sockaddr_getport(isc_sockaddr_t *sockaddr); +/* + * Get the port stored in 'sockaddr'. + */ + +isc_result_t +isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target); +/* + * Append a text representation of 'sockaddr' to the buffer 'target'. + * The text will include both the IP address (v4 or v6) and the port. + * The text is null terminated, but the terminating null is not + * part of the buffer's used region. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_NOSPACE The text or the null termination did not fit. + */ + +void +isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size); +/* + * Format a human-readable representation of the socket address '*sa' + * into the character array 'array', which is of size 'size'. + * The resulting string is guaranteed to be null-terminated. + */ + +isc_boolean_t +isc_sockaddr_ismulticast(isc_sockaddr_t *sa); +/* + * Returns ISC_TRUE if the address is a multicast address. + */ + +isc_boolean_t +isc_sockaddr_islinklocal(isc_sockaddr_t *sa); +/* + * Returns ISC_TRUE if the address is a link local addresss. + */ + +isc_boolean_t +isc_sockaddr_issitelocal(isc_sockaddr_t *sa); +/* + * Returns ISC_TRUE if the address is a sitelocal address. + */ + +#define ISC_SOCKADDR_FORMATSIZE \ + sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX#YYYYY") +/* + * Minimum size of array to pass to isc_sockaddr_format(). + */ + +ISC_LANG_ENDDECLS + +#endif /* ISC_SOCKADDR_H */ diff --git a/include/isc/strerror.h b/include/isc/strerror.h new file mode 100644 index 000000000000..ca428af9553f --- /dev/null +++ b/include/isc/strerror.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: strerror.h,v 1.3 2001/11/20 01:45:47 gson Exp $ */ + +#ifndef ISC_STRERROR_H +#define ISC_STRERROR_H + +#include <sys/types.h> + +#include <isc/lang.h> + +ISC_LANG_BEGINDECLS + +#define ISC_STRERRORSIZE 128 + +/* + * Provide a thread safe wrapper to strerrror(). + * + * Requires: + * 'buf' to be non NULL. + */ +void +isc__strerror(int num, char *buf, size_t bufsize); + +ISC_LANG_ENDDECLS + +#endif /* ISC_STRERROR_H */ diff --git a/include/isc/string.h b/include/isc/string.h new file mode 100644 index 000000000000..e16219fdaad0 --- /dev/null +++ b/include/isc/string.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: string.h,v 1.9 2001/01/09 21:57:37 bwelling Exp $ */ + +#ifndef ISC_STRING_H +#define ISC_STRING_H 1 + +#include <string.h> + +#include <isc/int.h> +#include <isc/lang.h> +#include <isc/platform.h> + +ISC_LANG_BEGINDECLS + +isc_uint64_t +isc_string_touint64(char *source, char **endp, int base); +/* + * Convert the string pointed to by 'source' to isc_uint64_t. + * + * On successful conversion 'endp' points to the first character + * after conversion is complete. + * + * 'base': 0 or 2..36 + * + * If base is 0 the base is computed from the string type. + * + * On error 'endp' points to 'source'. + */ + + +char * +isc_string_separate(char **stringp, const char *delim); + +#ifdef ISC_PLATFORM_NEEDSTRSEP +#define strsep isc_string_separate +#endif + +ISC_LANG_ENDDECLS + +#endif /* ISC_STRING_H */ diff --git a/include/isc/types.h b/include/isc/types.h new file mode 100644 index 000000000000..b30f55ee7fe9 --- /dev/null +++ b/include/isc/types.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: types.h,v 1.33 2002/07/19 03:39:44 marka Exp $ */ + +#ifndef ISC_TYPES_H +#define ISC_TYPES_H 1 + +/* + * OS-specific types, from the OS-specific include directories. + */ +#include <isc/int.h> +#include <isc/offset.h> + +/* + * XXXDCL should isc_boolean_t be moved here, requiring an explicit include + * of <isc/boolean.h> when ISC_TRUE/ISC_FALSE/ISC_TF() are desired? + */ +#include <isc/boolean.h> +/* + * XXXDCL This is just for ISC_LIST and ISC_LINK, but gets all of the other + * list macros too. + */ +#include <isc/list.h> + +/*** + *** Core Types. Alphabetized by defined type. + ***/ + +typedef struct isc_bitstring isc_bitstring_t; +typedef struct isc_buffer isc_buffer_t; +typedef ISC_LIST(isc_buffer_t) isc_bufferlist_t; +typedef struct isc_constregion isc_constregion_t; +typedef struct isc_consttextregion isc_consttextregion_t; +typedef struct isc_entropy isc_entropy_t; +typedef struct isc_entropysource isc_entropysource_t; +typedef struct isc_event isc_event_t; +typedef ISC_LIST(isc_event_t) isc_eventlist_t; +typedef unsigned int isc_eventtype_t; +typedef isc_uint32_t isc_fsaccess_t; +typedef struct isc_interface isc_interface_t; +typedef struct isc_interfaceiter isc_interfaceiter_t; +typedef struct isc_interval isc_interval_t; +typedef struct isc_lex isc_lex_t; +typedef struct isc_log isc_log_t; +typedef struct isc_logcategory isc_logcategory_t; +typedef struct isc_logconfig isc_logconfig_t; +typedef struct isc_logmodule isc_logmodule_t; +typedef struct isc_mem isc_mem_t; +typedef struct isc_mempool isc_mempool_t; +typedef struct isc_msgcat isc_msgcat_t; +typedef struct isc_ondestroy isc_ondestroy_t; +typedef struct isc_netaddr isc_netaddr_t; +typedef struct isc_quota isc_quota_t; +typedef struct isc_random isc_random_t; +typedef struct isc_ratelimiter isc_ratelimiter_t; +typedef struct isc_region isc_region_t; +typedef isc_uint64_t isc_resourcevalue_t; +typedef unsigned int isc_result_t; +typedef struct isc_rwlock isc_rwlock_t; +typedef struct isc_sockaddr isc_sockaddr_t; +typedef struct isc_socket isc_socket_t; +typedef struct isc_socketevent isc_socketevent_t; +typedef struct isc_socketmgr isc_socketmgr_t; +typedef struct isc_symtab isc_symtab_t; +typedef struct isc_task isc_task_t; +typedef ISC_LIST(isc_task_t) isc_tasklist_t; +typedef struct isc_taskmgr isc_taskmgr_t; +typedef struct isc_textregion isc_textregion_t; +typedef struct isc_time isc_time_t; +typedef struct isc_timer isc_timer_t; +typedef struct isc_timermgr isc_timermgr_t; + +typedef void (*isc_taskaction_t)(isc_task_t *, isc_event_t *); + +typedef enum { + isc_resource_coresize = 1, + isc_resource_cputime, + isc_resource_datasize, + isc_resource_filesize, + isc_resource_lockedmemory, + isc_resource_openfiles, + isc_resource_processes, + isc_resource_residentsize, + isc_resource_stacksize +} isc_resource_t; + +#endif /* ISC_TYPES_H */ diff --git a/include/isc/util.h b/include/isc/util.h new file mode 100644 index 000000000000..6144e11ba863 --- /dev/null +++ b/include/isc/util.h @@ -0,0 +1,225 @@ +/* + * Copyright (C) 1998-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: util.h,v 1.23 2001/11/30 01:59:38 gson Exp $ */ + +#ifndef ISC_UTIL_H +#define ISC_UTIL_H 1 + +/* + * NOTE: + * + * This file is not to be included from any <isc/???.h> (or other) library + * files. + * + * Including this file puts several macros in your name space that are + * not protected (as all the other ISC functions/macros do) by prepending + * ISC_ or isc_ to the name. + */ + +/*** + *** General Macros. + ***/ + +/* + * Use this to hide unused function arguments. + * + * int + * foo(char *bar) + * { + * UNUSED(bar); + * } + */ +#define UNUSED(x) (void)(x) + +#define ISC_MAX(a, b) ((a) > (b) ? (a) : (b)) +#define ISC_MIN(a, b) ((a) < (b) ? (a) : (b)) + +/* + * Use this to remove the const qualifier of a variable to assign it to + * a non-const variable or pass it as a non-const function argument ... + * but only when you are sure it won't then be changed! + * This is necessary to sometimes shut up some compilers + * (as with gcc -Wcast-qual) when there is just no other good way to avoid the + * situation. + */ +#define DE_CONST(konst, var) \ + do { \ + union { const void *k; void *v; } _u; \ + _u.k = konst; \ + var = _u.v; \ + } while (0) + +/* + * Use this in translation units that would otherwise be empty, to + * suppress compiler warnings. + */ +#define EMPTY_TRANSLATION_UNIT static void isc__empty(void) { isc__empty(); } + +/* + * We use macros instead of calling the routines directly because + * the capital letters make the locking stand out. + * + * We RUNTIME_CHECK for success since in general there's no way + * for us to continue if they fail. + */ + +#ifdef ISC_UTIL_TRACEON +#define ISC_UTIL_TRACE(a) a +#include <stdio.h> /* Required for fprintf/stderr when tracing. */ +#include <isc/msgs.h> /* Required for isc_msgcat when tracing. */ +#else +#define ISC_UTIL_TRACE(a) +#endif + +#include <isc/result.h> /* Contractual promise. */ + +#define LOCK(lp) do { \ + ISC_UTIL_TRACE(fprintf(stderr, "%s %p %s %d\n", \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_LOCKING, "LOCKING"), \ + (lp), __FILE__, __LINE__)); \ + RUNTIME_CHECK(isc_mutex_lock((lp)) == ISC_R_SUCCESS); \ + ISC_UTIL_TRACE(fprintf(stderr, "%s %p %s %d\n", \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_LOCKED, "LOCKED"), \ + (lp), __FILE__, __LINE__)); \ + } while (0) +#define UNLOCK(lp) do { \ + RUNTIME_CHECK(isc_mutex_unlock((lp)) == ISC_R_SUCCESS); \ + ISC_UTIL_TRACE(fprintf(stderr, "%s %p %s %d\n", \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_UNLOCKED, "UNLOCKED"), \ + (lp), __FILE__, __LINE__)); \ + } while (0) +#define ISLOCKED(lp) (1) +#define DESTROYLOCK(lp) \ + RUNTIME_CHECK(isc_mutex_destroy((lp)) == ISC_R_SUCCESS) + + +#define BROADCAST(cvp) do { \ + ISC_UTIL_TRACE(fprintf(stderr, "%s %p %s %d\n", \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_BROADCAST, "BROADCAST"),\ + (cvp), __FILE__, __LINE__)); \ + RUNTIME_CHECK(isc_condition_broadcast((cvp)) == ISC_R_SUCCESS); \ + } while (0) +#define SIGNAL(cvp) do { \ + ISC_UTIL_TRACE(fprintf(stderr, "%s %p %s %d\n", \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_SIGNAL, "SIGNAL"), \ + (cvp), __FILE__, __LINE__)); \ + RUNTIME_CHECK(isc_condition_signal((cvp)) == ISC_R_SUCCESS); \ + } while (0) +#define WAIT(cvp, lp) do { \ + ISC_UTIL_TRACE(fprintf(stderr, "%s %p %s %p %s %d\n", \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_UTILWAIT, "WAIT"), \ + (cvp), \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_LOCK, "LOCK"), \ + (lp), __FILE__, __LINE__)); \ + RUNTIME_CHECK(isc_condition_wait((cvp), (lp)) == ISC_R_SUCCESS); \ + ISC_UTIL_TRACE(fprintf(stderr, "%s %p %s %p %s %d\n", \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_WAITED, "WAITED"), \ + (cvp), \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_LOCKED, "LOCKED"), \ + (lp), __FILE__, __LINE__)); \ + } while (0) + +/* + * isc_condition_waituntil can return ISC_R_TIMEDOUT, so we + * don't RUNTIME_CHECK the result. + * + * XXX Also, can't really debug this then... + */ + +#define WAITUNTIL(cvp, lp, tp) \ + isc_condition_waituntil((cvp), (lp), (tp)) + +#define RWLOCK(lp, t) do { \ + ISC_UTIL_TRACE(fprintf(stderr, "%s %p, %d %s %d\n", \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_RWLOCK, "RWLOCK"), \ + (lp), (t), __FILE__, __LINE__)); \ + RUNTIME_CHECK(isc_rwlock_lock((lp), (t)) == ISC_R_SUCCESS); \ + ISC_UTIL_TRACE(fprintf(stderr, "%s %p, %d %s %d\n", \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_RWLOCKED, "RWLOCKED"), \ + (lp), (t), __FILE__, __LINE__)); \ + } while (0) +#define RWUNLOCK(lp, t) do { \ + ISC_UTIL_TRACE(fprintf(stderr, "%s %p, %d %s %d\n", \ + isc_msgcat_get(isc_msgcat, ISC_MSGSET_UTIL, \ + ISC_MSG_RWUNLOCK, "RWUNLOCK"), \ + (lp), (t), __FILE__, __LINE__)); \ + RUNTIME_CHECK(isc_rwlock_unlock((lp), (t)) == ISC_R_SUCCESS); \ + } while (0) + +#define DESTROYMUTEXBLOCK(bp, n) \ + RUNTIME_CHECK(isc_mutexblock_destroy((bp), (n)) == ISC_R_SUCCESS) + +/* + * List Macros. + */ +#include <isc/list.h> /* Contractual promise. */ + +#define LIST(type) ISC_LIST(type) +#define INIT_LIST(type) ISC_LIST_INIT(type) +#define LINK(type) ISC_LINK(type) +#define INIT_LINK(elt, link) ISC_LINK_INIT(elt, link) +#define HEAD(list) ISC_LIST_HEAD(list) +#define TAIL(list) ISC_LIST_TAIL(list) +#define EMPTY(list) ISC_LIST_EMPTY(list) +#define PREV(elt, link) ISC_LIST_PREV(elt, link) +#define NEXT(elt, link) ISC_LIST_NEXT(elt, link) +#define APPEND(list, elt, link) ISC_LIST_APPEND(list, elt, link) +#define PREPEND(list, elt, link) ISC_LIST_PREPEND(list, elt, link) +#define UNLINK(list, elt, link) ISC_LIST_UNLINK(list, elt, link) +#define ENQUEUE(list, elt, link) ISC_LIST_APPEND(list, elt, link) +#define DEQUEUE(list, elt, link) ISC_LIST_UNLINK(list, elt, link) +#define INSERTBEFORE(li, b, e, ln) ISC_LIST_INSERTBEFORE(li, b, e, ln) +#define INSERTAFTER(li, a, e, ln) ISC_LIST_INSERTAFTER(li, a, e, ln) +#define APPENDLIST(list1, list2, link) ISC_LIST_APPENDLIST(list1, list2, link) + +/* + * Assertions + */ +#include <isc/assertions.h> /* Contractual promise. */ + +#define REQUIRE(e) ISC_REQUIRE(e) +#define ENSURE(e) ISC_ENSURE(e) +#define INSIST(e) ISC_INSIST(e) +#define INVARIANT(e) ISC_INVARIANT(e) + +/* + * Errors + */ +#include <isc/error.h> /* Contractual promise. */ + +#define UNEXPECTED_ERROR isc_error_unexpected +#define FATAL_ERROR isc_error_fatal +#define RUNTIME_CHECK(cond) ISC_ERROR_RUNTIMECHECK(cond) + +/* + * Time + */ +#define TIME_NOW(tp) RUNTIME_CHECK(isc_time_now((tp)) == ISC_R_SUCCESS) + +#endif /* ISC_UTIL_H */ diff --git a/include/l_stdlib.h b/include/l_stdlib.h new file mode 100644 index 000000000000..3f242b7994a0 --- /dev/null +++ b/include/l_stdlib.h @@ -0,0 +1,519 @@ +/* + * Proto types for machines that are not ANSI and POSIX compliant. + * This is optional + */ + +#ifndef _l_stdlib_h +#define _l_stdlib_h + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#ifdef HAVE_STDLIB_H +# include <stdlib.h> +#endif + +#if defined(__STDC__) || defined(HAVE_STDARG_H) +# include <stdarg.h> +#else +# include <varargs.h> +#endif + +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif + +/* Needed for speed_t. */ +#ifdef HAVE_TERMIOS_H +# include <termios.h> +#endif + +#ifdef HAVE_ERRNO_H +# include <errno.h> +#endif + +#include "ntp_types.h" +#include "ntp_proto.h" + +/* Let's try to keep this more or less alphabetized... */ + +#ifdef DECL_ADJTIME_0 +struct timeval; +extern int adjtime P((struct timeval *, struct timeval *)); +#endif + +#ifdef DECL_BCOPY_0 +#ifndef bcopy +extern void bcopy P((const char *, char *, int)); +#endif +#endif + +#ifdef DECL_BZERO_0 +#ifndef bzero +extern void bzero P((char *, int)); +#endif +#endif + +#ifdef DECL_CFSETISPEED_0 +struct termios; +extern int cfsetispeed P((struct termios *, speed_t)); +extern int cfsetospeed P((struct termios *, speed_t)); +#endif + +extern char * getpass P((const char *)); + +#ifdef DECL_HSTRERROR_0 +extern const char * hstrerror P((int)); +#endif + +#ifdef DECL_INET_NTOA_0 +struct in_addr; +extern char * inet_ntoa P((struct in_addr)); +#endif + +#ifdef DECL_IOCTL_0 +extern int ioctl P((int, u_long, char *)); +#endif + +#ifdef DECL_IPC_0 +struct sockaddr; +extern int bind P((int, struct sockaddr *, int)); +extern int connect P((int, struct sockaddr *, int)); +extern int recv P((int, char *, int, int)); +extern int recvfrom P((int, char *, int, int, struct sockaddr *, int *)); +extern int send P((int, char *, int, int)); +extern int sendto P((int, char *, int, int, struct sockaddr *, int)); +extern int setsockopt P((int, int, int, char *, int)); +extern int socket P((int, int, int)); +#endif + +#ifdef DECL_MEMMOVE_0 +extern void * memmove P((void *, const void *, size_t)); +#endif + +#ifdef DECL_MEMSET_0 +extern char * memset P((char *, int, int)); +#endif + +#ifdef DECL_MKSTEMP_0 +extern int mkstemp P((char *)); +#endif + +#ifdef DECL_MKTEMP_0 +extern char *mktemp P((char *)); +#endif + +#ifdef DECL_MRAND48_0 +extern long mrand48 P((void)); +#endif + +#ifdef DECL_NLIST_0 +struct nlist; +extern int nlist P((const char *, struct nlist *)); +#endif + +#ifdef DECL_PLOCK_0 +extern int plock P((int)); +#endif + +#ifdef DECL_RENAME_0 +extern int rename P((const char *, const char *)); +#endif + +#ifdef DECL_SELECT_0 +#ifdef _ntp_select_h +extern int select P((int, fd_set *, fd_set *, fd_set *, struct timeval *)); +#endif +#endif + +#ifdef DECL_SETITIMER_0 +struct itimerval; +extern int setitimer P((int , struct itimerval *, struct itimerval *)); +#endif + +#ifdef PRIO_PROCESS +#ifdef DECL_SETPRIORITY_0 +extern int setpriority P((int, int, int)); +#endif +#ifdef DECL_SETPRIORITY_1 +extern int setpriority P((int, id_t, int)); +#endif +#endif + +#ifdef DECL_SIGVEC_0 +struct sigvec; +extern int sigvec P((int, struct sigvec *, struct sigvec *)); +#endif + +#ifndef HAVE_SNPRINTF +/* PRINTFLIKE3 */ +extern int snprintf P((char *, size_t, const char *, ...)); +#endif + +/* HMS: does this need further protection? */ +#ifndef HAVE_VSNPRINTF +extern int vsnprintf P((char *, size_t, const char *, va_list)); +#endif + +#ifdef DECL_SRAND48_0 +extern void srand48 P((long)); +#endif + +#ifdef DECL_STDIO_0 +#if defined(FILE) || defined(BUFSIZ) +extern int _flsbuf P((int, FILE *)); +extern int _filbuf P((FILE *)); +extern int fclose P((FILE *)); +extern int fflush P((FILE *)); +extern int fprintf P((FILE *, const char *, ...)); +extern int fscanf P((FILE *, const char *, ...)); +extern int fputs P((const char *, FILE *)); +extern int fputc P((int, FILE *)); +extern int fread P((char *, int, int, FILE *)); +extern void perror P((const char *)); +extern int printf P((const char *, ...)); +extern int setbuf P((FILE *, char *)); +# ifdef HAVE_SETLINEBUF +extern int setlinebuf P((FILE *)); +# endif +extern int setvbuf P((FILE *, char *, int, int)); +extern int scanf P((const char *, ...)); +extern int sscanf P((const char *, const char *, ...)); +extern int vfprintf P((FILE *, const char *, ...)); +extern int vsprintf P((char *, const char *, ...)); +#endif +#endif + +#ifdef DECL_STIME_0 +extern int stime P((const time_t *)); +#endif + +#ifdef DECL_STIME_1 +extern int stime P((long *)); +#endif + +#ifdef DECL_STRERROR_0 +extern char * strerror P((int errnum)); +#endif + +#ifdef DECL_STRTOL_0 +extern long strtol P((const char *, char **, int)); +#endif + +#ifdef DECL_SYSCALL +extern int syscall P((int, ...)); +#endif + +#ifdef DECL_SYSLOG_0 +extern void closelog P((void)); +#ifndef LOG_DAEMON +extern void openlog P((const char *, int)); +#else +extern void openlog P((const char *, int, int)); +#endif +extern int setlogmask P((int)); +extern void syslog P((int, const char *, ...)); +#endif + +#ifdef DECL_TIME_0 +extern time_t time P((time_t *)); +#endif + +#ifdef DECL_TIMEOFDAY_0 +#ifdef SYSV_TIMEOFDAY +extern int gettimeofday P((struct timeval *)); +extern int settimeofday P((struct timeval *)); +#else /* not SYSV_TIMEOFDAY */ +struct timezone; +extern int gettimeofday P((struct timeval *, struct timezone *)); +extern int settimeofday P((struct timeval *, void *)); +#endif /* not SYSV_TIMEOFDAY */ +#endif + +#ifdef DECL_TOLOWER_0 +extern int tolower P((int)); +#endif + +#ifdef DECL_TOUPPER_0 +extern int toupper P((int)); +#endif + +/* + * Necessary variable declarations. + */ +#ifdef DECL_ERRNO +extern int errno; +#endif + +#if defined(DECL_H_ERRNO) && !defined(h_errno) +extern int h_errno; +#endif + +/*******************************************************/ + +#if 0 +/* + * Unprotoyped library functions for SunOS 4.x.x + */ +#ifdef SYS_SUNOS4 +extern void closelog P((void)); +extern void openlog P((char *, int, int)); +extern void syslog P((int, char *, ...)); +extern int setlogmask P((int)); + +extern char * getpass P((char *)); + +extern int setpriority P((int ,int ,int)); + +extern long strtol P((char *, char **, int)); + +#if !defined(NTP_POSIX_SOURCE) +extern int atoi P((char *)); +extern int dup2 P((int, int)); +extern int execve P((char *, char **,char **)); +extern int fork P((void)); +extern int getdtablesize P((void)); +extern int qsort (void *, int , int, + int P((*compar)(void *, void *))); +extern long random P((void)); +extern long mrand48 P((void)); +extern int setpgrp P((int, int)); +extern void srandom P((unsigned int)); +extern void bcopy P((const char *, char *, int)); +#endif + +#ifndef bzero /* XXX macro prototyping clash */ +extern void bzero P((char *, int)); +extern int bcmp P((char *, char *, int)); +extern void bcopy P((const char *, char *, int)); +#endif +extern char *mktemp P((char *)); + +extern int tolower P((int)); + +extern int isatty P((int)); + +extern unsigned sleep P((unsigned )); +extern unsigned int alarm P((unsigned int)); +extern int pause P((void)); + +extern int getpid P((void)); +extern int getppid P((void)); + +extern int close P((int)); +extern int ioctl P((int, int, char *)); +extern int rename P((char *, char *)); +#if 0 +extern int read P((int, void *, size_t)); +extern int write P((int, const void *, size_t)); +#endif +extern int unlink P((const char *)); +extern int link P((const char *, const char *)); + +#ifdef FILE +extern int fclose P((FILE *)); +extern int fflush P((FILE *)); +extern int fprintf P((FILE *, char *, ...)); +extern int fscanf P((FILE *, char *, ...)); +extern int fputs P((char *, FILE *)); +extern int fputc P((char, FILE *)); +extern int fread P((char *, int, int, FILE *)); +extern int printf P((char *, ...)); +extern int setbuf P((FILE *, char *)); +extern int setvbuf P((FILE *, char *, int, int)); +extern int scanf P((char *, ...)); +extern int sscanf P((char *, char *, ...)); +extern int vsprintf P((char *, char *, ...)); +extern int _flsbuf P((int, FILE *)); +extern int _filbuf P((FILE *)); +extern void perror P((char *)); +#ifdef HAVE_SETLINEBUF +extern int setlinebuf P((FILE *)); +#endif +#endif + +#ifdef _ntp_string_h +#ifdef NTP_POSIX_SOURCE /* these are builtins */ +#ifndef NTP_NEED_BOPS /* but may be emulated by bops */ +extern char *memcpy P(()); +extern char *memset P(()); +extern int memcmp P(()); +#endif +#endif +#endif + +#ifdef _sys_socket_h +extern int bind P((int, struct sockaddr *, int)); +extern int connect P((int, struct sockaddr *, int)); +extern int sendto P((int, char *, int, int, struct sockaddr *, int)); +extern int setsockopt P((int, int, int, char *, int)); +extern int socket P((int, int, int)); +extern int recvfrom P((int, char *, int, int, struct sockaddr *, int *)); +#endif /* _sys_socket_h */ + +#ifdef _ntp_select_h +extern int select P((int, fd_set *, fd_set *, fd_set *, struct timeval *)); +#endif + +#ifdef _sys_time_h +extern int adjtime P((struct timeval *, struct timeval *)); +extern int setitimer P((int , struct itimerval *, struct itimerval *)); +#ifdef SYSV_TIMEOFDAY +extern int gettimeofday P((struct timeval *)); +extern int settimeofday P((struct timeval *)); +#else /* ! SYSV_TIMEOFDAY */ +extern int gettimeofday P((struct timeval *, struct timezone *)); +extern int settimeofday P((struct timeval *, struct timezone *)); +#endif /* SYSV_TIMEOFDAY */ +#endif /* _sys_time_h */ + +#ifdef __time_h +extern time_t time P((time_t *)); +#endif + +#ifdef __setjmp_h +extern int setjmp P((jmp_buf)); +extern void longjmp P((jmp_buf, int)); +#endif + +#ifdef _sys_resource_h +extern int getrusage P((int, struct rusage *)); +#endif + +#ifdef _nlist_h +extern int nlist P((char *, struct nlist *)); +#endif + +#endif /* SYS_SUNOS4 */ + +/* + * Unprototyped library functions for DEC OSF/1 + */ +#ifdef SYS_DECOSF1 +#ifndef _MACHINE_ENDIAN_H_ +#define _MACHINE_ENDIAN_H_ +extern u_short htons P((u_short)); +extern u_short ntohs P((u_short)); +extern u_int32 htonl P((u_int32)); +extern u_int32 ntohl P((u_int32)); +#endif /* _MACHINE_ENDIAN_H_ */ + +/* +extern char * getpass P((char *)); +*/ +extern char * mktemp P((char *)); +#ifndef SYS_IX86OSF1 +extern int ioctl P((int, u_long, char *)); +extern void bzero P((char *, int)); +#endif + +#ifdef SOCK_DGRAM +extern int bind P((int, const struct sockaddr *, int)); +extern int connect P((int, const struct sockaddr *, int)); +extern int socket P((int, int, int)); +extern int sendto P((int, const void *, int, int, const struct sockaddr *, int)); +extern int setsockopt P((int, int, int, const void *, int)); +extern int recvfrom P((int, void *, int, int, struct sockaddr *, int *)); +#endif /* SOCK_STREAM */ + +#ifdef _ntp_select_h +extern int select P((int, fd_set *, fd_set *, fd_set *, struct timeval *)); +#endif + +#endif /* DECOSF1 */ + +/* + * Unprototyped library functions for Ultrix + */ +#ifdef SYS_ULTRIX +extern int close P((int)); +extern char * getpass P((char *)); +extern int getpid P((void)); +extern int ioctl P((int, int, char *)); +extern char *mktemp P((char *)); +extern int unlink P((const char *)); +extern int link P((const char *, const char *)); + +extern void closelog P((void)); +extern void syslog P((int, char *, ...)); +#ifndef LOG_DAEMON +extern void openlog P((char *, int)); +#else +extern void openlog P((char *, int, int)); +#endif + +extern int setpriority P((int ,int ,int )); + +#ifdef SOCK_DGRAM +extern int bind P((int, struct sockaddr *, int)); +extern int connect P((int, struct sockaddr *, int)); +extern int socket P((int, int, int)); +extern int sendto P((int, char *, int, int, struct sockaddr *, int)); +extern int setsockopt P((int, int, int, char *, int)); +extern int recvfrom P((int, char *, int, int, struct sockaddr *, int *)); +#endif /* SOCK_STREAM */ + +#ifdef _TIME_H_ +extern int gettimeofday P((struct timeval *, struct timezone *)); +extern int settimeofday P((struct timeval *, struct timezone *)); +extern int adjtime P((struct timeval *, struct timeval *)); +extern int select P((int, fd_set *, fd_set *, fd_set *, struct timeval *)); +extern int setitimer P((int , struct itimerval *, struct itimerval *)); +#endif /* _TIME_H_ */ + +#ifdef N_UNDF +extern int nlist P((char *, struct nlist *)); +#endif + +#ifndef bzero /* XXX macro prototyping clash */ +extern void bzero P((char *, int)); +extern int bcmp P((char *, char *, int)); +extern void bcopy P((const char *, char *, int)); +#endif + +#ifndef NTP_POSIX_SOURCE +extern int atoi P((char *)); +extern void bzero P((char *, int)); +extern int bcmp P((char *, char *, int)); +extern void bcopy P((const char *, char *, int)); +extern int execve P((char *, char **,char **)); +extern int fork P((void)); +extern int getdtablesize P((void)); +extern int ran P((void)); +extern int rand P((void)); +extern void srand P((unsigned int)); +#ifdef _TIME_H_ +extern int gettimeofday P((struct timeval *, struct timezone *)); +extern int settimeofday P((struct timeval *, struct timezone *)); +#endif +#endif + +#ifdef _RESOURCE_H_ +extern int getrusage P((int, struct rusage *)); +#endif + +#endif /* SYS_ULTRIX */ + +#if defined(__convex__) +extern char * getpass P((char *)); +#endif + +#ifdef SYS_IRIX4 +extern char * getpass P((char *)); +#endif /* IRIX4 */ + +#ifdef SYS_VAX +extern char * getpass P((char *)); +#endif /* VAX */ + +#ifdef SYS_DOMAINOS +extern char * getpass P((char *)); +#endif /* SYS_DOMAINOS */ + +#ifdef SYS_BSD +#define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) +#endif + +#endif /* 0 */ +#endif /* l_stdlib_h */ diff --git a/include/mbg_gps166.h b/include/mbg_gps166.h new file mode 100644 index 000000000000..71107517e9d2 --- /dev/null +++ b/include/mbg_gps166.h @@ -0,0 +1,538 @@ +/* + * /src/NTP/ntp-4/include/mbg_gps166.h,v 4.1 1998/06/12 15:07:30 kardel RELEASE_19990228_A + * + * $Created: Sun Jul 20 09:20:50 1997 $ + * + * Copyright (C) 1997, 1998 by Frank Kardel + */ +#ifndef MBG_GPS166_H +#define MBG_GPS166_H + + +/***************************************************************************/ +/* */ +/* File: GPSSERIO.H 4.1 */ +/* */ +/* Project: Common C Library */ +/* */ +/* Compiler: Borland C++ */ +/* */ +/* Author: M. Burnicki, Meinberg Funkuhren */ +/* */ +/* */ +/* Description: */ +/* This file defines structures and codes to be used to access GPS166 */ +/* via its serial interface COM0. COM0 should be set to a high baud */ +/* rate, default is 19200. */ +/* */ +/* Standard GPS166 serial operation is to send a time string that is */ +/* compatible with Meinberg UA31 or PZF535 DCF77 radio remote clocks. */ +/* That string can be transmitted automatically once per second, once */ +/* per minute or on request per ASCII '?'. */ +/* */ +/* Parameter setup or parameter readout works using blocks of binary */ +/* data which have to be isolated from the standard string. A block of */ +/* data starts with a SOH code (ASCII Start Of Header, 0x01) followed */ +/* by a message header with constant length and a data portion with */ +/* variable length. The first field (cmd) of the message header holds */ +/* the command code rsp. the type of data to be transmitted. The next */ +/* field (len) gives the number of data bytes that are transmitted */ +/* after the header. This number ranges from 0 to sizeof( MSG_DATA ). */ +/* The third field (data_csum) holds a checksum of all data bytes and */ +/* the last field of the header finally holds the checksum of the. */ +/* header. */ +/* */ +/***************************************************************************/ + +/* the control codes defined below are to be or'ed with a command/type code */ + +#define GPS_REQACK 0x8000 /* to GPS166: request acknowledge */ +#define GPS_ACK 0x4000 /* from GPS166: acknowledge a command */ +#define GPS_NACK 0x2000 /* from GPS166: error receiving command */ + +#define GPS_CTRL_MSK 0xF000 /* masks control code from command */ + + +/* The codes below specify commands/types of data to be supplied to GPS166: */ + +/* GPS166 auto-message to host */ +/* þ host request, GPS166 response */ +/* þ þ host download to GPS166 */ +/* þ þ þ */ +enum { /* þ þ þ */ + /* system data */ + GPS_AUTO_ON = 0x000, /* þ þ þ X þ enable auto-messages from GPS166 */ + GPS_AUTO_OFF, /* þ þ þ X þ disable auto-messages from GPS166 */ + GPS_SW_REV, /* þ þ X þ þ request software revision */ + GPS_STAT, /* þ þ X þ þ request status of buffered variables */ + GPS_TIME, /* þ X þ þ X þ current time or capture or init board time */ + GPS_POS_XYZ, /* þ þ X þ X þ current position in ECEF coords */ + GPS_POS_LLA, /* þ þ X þ X þ current position in geographic coords */ + GPS_TZDL, /* þ þ X þ X þ time zone / daylight saving */ + GPS_PORT_PARM, /* þ þ X þ X þ parameters of the serial ports */ + GPS_SYNTH, /* þ þ X þ X þ synthesizer's frequency and phase */ + GPS_ANT_INFO, /* þ X þ X þ þ time diff after antenna disconnect */ + GPS_UCAP, /* þ X þ X þ þ user capture */ + + /* GPS data */ + GPS_CFGH = 0x100, /* þ þ X þ X þ SVs' configuration and health codes */ + GPS_ALM, /* þ þ X þ X þ one SV's almanac */ + GPS_EPH, /* þ þ X þ X þ one SV's ephemeris */ + GPS_UTC, /* þ þ X þ X þ UTC correction parameters */ + GPS_IONO, /* þ þ X þ X þ ionospheric correction parameters */ + GPS_ASCII_MSG /* þ þ X þ þ the GPS ASCII message */ +}; + +/* + * modelled after GPSDEFS.H Revision 1.5 + */ +/***************************************************************************/ +/* */ +/* File: GPSDEFS.H 4.1 */ +/* */ +/* Project: Common C Library */ +/* */ +/* Compiler: Borland C++ */ +/* */ +/* Author: M. Burnicki, Meinberg Funkuhren */ +/* */ +/* */ +/* Description: */ +/* General definitions to be used with GPS166 */ +/* GPS166 Rev. 1.23 or above */ +/* */ +/* Modifications: see file GPSLIB.TXT */ +/* */ +/***************************************************************************/ +#define _GPSDEFS_H +/* the type of various checksums */ + +#ifndef _CSUM_DEFINED + typedef unsigned short CSUM; +# define _CSUM_DEFINED +#endif + +/* the message header */ + +typedef struct { + unsigned short gps_cmd; + unsigned short gps_len; + unsigned short gps_data_csum; + unsigned short gps_hdr_csum; +} GPS_MSG_HDR; + +/* a struct used to hold the software revision information */ + +typedef struct { + unsigned short code; /* e.g. 0x0120 means rev. 1.20 */ + unsigned char name[17]; /* used to identify customized versions */ +} SW_REV; + +/* GPS ASCII message */ + +typedef struct { + CSUM csum; /* checksum of the remaining bytes */ + short valid; /* flag data are valid */ + char s[23]; /* 22 chars GPS ASCII message plus trailing zero */ +} ASCII_MSG; + +#define MIN_SVNO 1 /* min. SV number */ +#define MAX_SVNO 32 /* max. SV number */ +#define N_SVNO ( MAX_SVNO - MIN_SVNO + 1) /* number of possibly active SVs */ + + +typedef short SVNO; /* the number of a SV */ +typedef unsigned short HEALTH; /* a SV's health code */ +typedef unsigned short CFG; /* a SV's configuration code */ +typedef unsigned short IOD; /* Issue-Of-Data code */ + +/* Date and time referred to the linear time scale defined by GPS. */ +/* GPS time is defined by the number of weeks since midnight from */ +/* January 5, 1980 to January 6, 1980 plus the number of seconds of */ +/* the current week plus fractions of a second. GPS time differs from */ +/* UTC because UTC is corrected with leap seconds while GPS time scale */ +/* is continuous. */ + +typedef struct { + unsigned short wn; /* the week number since GPS has been installed */ + unsigned long sec; /* the second of that week */ + unsigned long tick; /* fractions of a second; scale: 1E-7 */ +} T_GPS; + + +/* Local date and time computed from GPS time. The current number */ +/* of leap seconds have to be added to get UTC from GPS time. */ +/* Additional corrections could have been made according to the */ +/* time zone/daylight saving parameters (TZDL, see below) defined */ +/* by the user. The status field can be checked to see which corrections */ +/* have been applied. */ + +#ifndef _TM_DEFINED + typedef struct { + short year; /* 0..9999 */ + char month; /* 1..12 */ + char mday; /* 1..31 */ + short yday; /* 1..366 */ + char wday; /* 0..6 == Sun..Sat */ + char hour; /* 0..23 */ + char minute; /* 0..59 */ + char second; /* 0..59 */ + long frac; /* fractions of a second, scale 1E-7 */ + long offs_from_utc; /* local time's offset from UTC */ + unsigned short status; /* flags */ + } TM; + + /* status flags used with conversion from GPS time to local time */ + +# define TM_UTC 0x01 /* UTC correction has been made */ +# define TM_LOCAL 0x02 /* UTC has been converted to local time */ +# define TM_DL_ANN 0x04 /* state of daylight saving is going to change */ +# define TM_DL_ENB 0x08 /* daylight saving is enabled */ +# define TM_LS_ANN 0x10 /* leap second will be inserted */ +# define TM_LS_ENB 0x20 /* current second is leap second */ + +# define _TM_DEFINED +#endif + + +/* the status flags below are defined starting with rev. 1.32 */ + +#define TM_ANT_DISCONN 0x1000 /* antenna currently disconnected */ +#define TM_SYN_FLAG 0x2000 /* TIME_SYN output is low */ +#define TM_NO_SYNC 0x4000 /* not sync'ed after reset */ +#define TM_NO_POS 0x8000 /* position not computed after reset, */ + /* LOCK LED off */ + +/* a struct used to transmit information on date and time */ + +typedef struct { + short channel; /* -1: the current time; 0, 1: capture 0, 1 */ + T_GPS t; /* time in GPS format */ + TM tm; /* that time converted to local time */ +} TTM; + + + +/* Two types of variables used to store a position. Type XYZ is */ +/* used with a position in earth centered, earth fixed (ECEF) */ +/* coordinates whereas type LLA holds such a position converted */ +/* to geographic coordinates as defined by WGS84 (World Geodetic */ +/* System from 1984). */ + +#ifndef _XYZ_DEFINED + /* sequence and number of components of a cartesian position */ + enum { XP, YP, ZP, N_XYZ }; + + /* a type of array holding a cartesian position */ + typedef l_fp XYZ[N_XYZ]; /* values are in [m] */ + +# define _XYZ_DEFINED +#endif + + +#ifndef _LLA_DEFINED + /* sequence and number of components of a geographic position */ + enum { LAT, LON, ALT, N_LLA }; /* latitude, longitude, altitude */ + + /* a type of array holding a geographic position */ + typedef l_fp LLA[N_LLA]; /* lon, lat in [rad], alt in [m] */ + +# define _LLA_DEFINED +#endif + +/* Synthesizer parameters. Synthesizer frequency is expressed as a */ +/* four digit decimal number (freq) to be multiplied by 0.1 Hz and an */ +/* base 10 exponent (range). If the effective frequency is less than */ +/* 10 kHz its phase is synchronized corresponding to the variable phase. */ +/* Phase may be in a range from -360° to +360° with a resolution of 0.1°, */ +/* so the resulting numbers to be stored are in a range of -3600 to +3600. */ + +/* Example: */ +/* Assume the value of freq is 2345 (decimal) and the value of phase is 900. */ +/* If range == 0 the effective frequency is 234.5 Hz with a phase of +90°. */ +/* If range == 1 the synthesizer will generate a 2345 Hz output frequency */ +/* and so on. */ + +/* Limitations: */ +/* If freq == 0 the synthesizer is disabled. If range == 0 the least */ +/* significant digit of freq is limited to 0, 3, 5 or 6. The resulting */ +/* frequency is shown in the examples below: */ +/* freq == 1230 --> 123.0 Hz */ +/* freq == 1233 --> 123 1/3 Hz (real 1/3 Hz, NOT 123.3 Hz) */ +/* freq == 1235 --> 123.5 Hz */ +/* freq == 1236 --> 123 2/3 Hz (real 2/3 Hz, NOT 123.6 Hz) */ + +/* If range == MAX_RANGE the value of freq must not exceed 1200, so the */ +/* output frequency is limited to 12 MHz. */ + +/* Phase will be ignored if the resulting frequency is greater or equal */ +/* to 10 kHz. */ + +#define MAX_SYNTH_FREQ 1200 /* if range == MAX_SYNTH_RANGE */ +#define MIN_SYNTH_RANGE 0 +#define MAX_SYNTH_RANGE 5 +#define MAX_SYNTH_PHASE 3600 + +typedef struct { + short freq; /* four digits used; scale: 0.1; e.g. 1234 -> 123.4 Hz */ + short range; /* scale factor for freq; 0..MAX_SYNTH_RANGE */ + short phase; /* -MAX_SYNTH_PHASE..+MAX_SYNTH_PHASE; >0 -> pulses later */ +} SYNTH; + + + +/* Time zone/daylight saving parameters. */ + +/* the name of a time zone, 5 characters plus trailing zero */ +typedef char TZ_NAME[6]; + +typedef struct { + long offs; /* offset from UTC to local time [sec] */ + long offs_dl; /* additional offset if daylight saving enabled [sec] */ + TM tm_on; /* date/time when daylight saving starts */ + TM tm_off; /* date/time when daylight saving ends */ + TZ_NAME name[2]; /* names without and with daylight saving enabled */ +} TZDL; + +/* The constant below is defined beginning with software rev. 1.29. */ +/* If the year in tzdl.tmon and tzdl.tm_off is or'ed with that constant, */ +/* the receiver automatically generates daylight saving year by year. */ +/* See GPSLIB.TXT for more information. */ + +#define DL_AUTO_FLAG 0x8000 + +/* Example: */ +/* for automatic daylight saving enable/disable in Central Europe, */ +/* the variables are to be set as shown below: */ +/* offs = 3600L one hour from UTC */ +/* offs_dl = 3600L one additional hour if daylight saving enabled */ +/* tm_on = first Sunday from March 25, 02:00:00h ( year |= DL_AUTO_FLAG ) */ +/* tm_off = first Sunday from Sept 24, 03:00:00h ( year |= DL_AUTO_FLAG ) */ +/* name[0] == "MEZ " name if daylight saving not enabled */ +/* name[1] == "MESZ " name if daylight saving is enabled */ + + + + +/* the structure below was defined in rev. 1.31. It reflects the status */ +/* of the antenna, the times of last disconnect/reconnect and the boards */ +/* clock offset after the phase of disconnection. */ + +typedef struct { + short status; /* current status of antenna */ + TM tm_disconn; /* time of antenna disconnect */ + TM tm_reconn; /* time of antenna reconnect */ + long delta_t; /* clock offset at reconnect time, units: TICKS_PER_SEC */ +} ANT_INFO; + + +/* the status field may be set to one of the values below: */ + +enum { + ANT_INVALID, /* struct not set yet because ant. has not been disconn. */ + ANT_DISCONN, /* ant. now disconn., tm_reconn and delta_t not set */ + ANT_RECONN /* ant. has been disconn. and reconn., all fields valid */ +}; + + +/* Summary of configuration and health data of all SVs. */ + +typedef struct { + CSUM csum; /* checksum of the remaining bytes */ + short valid; /* flag data are valid */ + + T_GPS tot_51; /* time of transmission, page 51 */ + T_GPS tot_63; /* time of transmission, page 63 */ + T_GPS t0a; /* complete reference time almanac */ + + CFG cfg[N_SVNO]; /* SV configuration from page 63 */ + HEALTH health[N_SVNO]; /* SV health from pages 51, 63 */ +} CFGH; + + + +/* UTC correction parameters */ + +typedef struct { + CSUM csum; /* checksum of the remaining bytes */ + short valid; /* flag data are valid */ + + T_GPS t0t; /* Reference Time UTC Parameters [sec] */ + l_fp A0; /* ± Clock Correction Coefficient 0 [sec] */ + l_fp A1; /* ± Clock Correction Coefficient 1 [sec/sec] */ + + ushort WNlsf; /* week number of nearest leap second */ + short DNt; /* the day number at the end of which LS is inserted */ + char delta_tls; /* */ + char delta_tlsf; /* */ + +} UTC; + +/* a struct used to hold the settings of a serial port */ + +#ifndef _COM_PARM_DEFINED + typedef long BAUD_RATE; + + /* indices used to identify a parameter in the framing string */ + enum { F_DBITS, F_PRTY, F_STBITS }; + + /* types of handshake */ + enum { HS_NONE, HS_XONXOFF, HS_RTSCTS }; + + typedef struct { + BAUD_RATE baud_rate; /* e.g. 19200L */ + char framing[4]; /* e.g. "8N1" */ + short handshake; /* a numeric value, only HS_NONE supported yet */ + } COM_PARM; + +#define _COM_PARM_DEFINED +#endif + + + +/* the codes below define what has to comes out of the serial ports */ + +enum { STR_ON_REQ, STR_PER_SEC, + STR_PER_MIN, N_STR_MODE_0, /* COM0 and COM1 */ + STR_UCAP = N_STR_MODE_0, + STR_UCAP_REQ, N_STR_MODE_1 /* COM1 only */ + }; + + +#define N_COM 2 /* the number of serial ports */ + +/* the structure used to store the modes of both serial ports */ + +typedef struct { + COM_PARM com[N_COM]; /* COM0 and COM1 settings */ + u_char mode[N_COM]; /* COM0 and COM1 output mode */ +} PORT_PARM; + +/* Ephemeris parameters of one specific SV. Needed to compute the position */ +/* of a satellite at a given time with high precision. Valid for an */ +/* interval of 4 to 6 hours from start of transmission. */ + +typedef struct { + CSUM csum; /* checksum of the remaining bytes */ + short valid; /* flag data are valid */ + + HEALTH health; /* health indication of transmitting SV [---] */ + IOD IODC; /* Issue Of Data, Clock */ + IOD IODE2; /* Issue of Data, Ephemeris (Subframe 2) */ + IOD IODE3; /* Issue of Data, Ephemeris (Subframe 3) */ + T_GPS tt; /* time of transmission */ + T_GPS t0c; /* Reference Time Clock [---] */ + T_GPS t0e; /* Reference Time Ephemeris [---] */ + + l_fp sqrt_A; /* Square Root of semi-major Axis [sqrt(m)] */ + l_fp e; /* Eccentricity [---] */ + l_fp M0; /* ± Mean Anomaly at Ref. Time [rad] */ + l_fp omega; /* ± Argument of Perigee [rad] */ + l_fp OMEGA0; /* ± Longit. of Asc. Node of orbit plane [rad] */ + l_fp OMEGADOT; /* ± Rate of Right Ascension [rad/sec] */ + l_fp deltan; /* ± Mean Motion Diff. from computed value [rad/sec] */ + l_fp i0; /* ± Inclination Angle [rad] */ + l_fp idot; /* ± Rate of Inclination Angle [rad/sec] */ + l_fp crc; /* ± Cosine Corr. Term to Orbit Radius [m] */ + l_fp crs; /* ± Sine Corr. Term to Orbit Radius [m] */ + l_fp cuc; /* ± Cosine Corr. Term to Arg. of Latitude [rad] */ + l_fp cus; /* ± Sine Corr. Term to Arg. of Latitude [rad] */ + l_fp cic; /* ± Cosine Corr. Term to Inclination Angle [rad] */ + l_fp cis; /* ± Sine Corr. Term to Inclination Angle [rad] */ + + l_fp af0; /* ± Clock Correction Coefficient 0 [sec] */ + l_fp af1; /* ± Clock Correction Coefficient 1 [sec/sec] */ + l_fp af2; /* ± Clock Correction Coefficient 2 [sec/sec²] */ + l_fp tgd; /* ± estimated group delay differential [sec] */ + + u_short URA; /* predicted User Range Accuracy */ + + u_char L2code; /* code on L2 channel [---] */ + u_char L2flag; /* L2 P data flag [---] */ + +} EPH; + +/* Almanac parameters of one specific SV. A reduced precision set of */ +/* parameters used to check if a satellite is in view at a given time. */ +/* Valid for an interval of more than 7 days from start of transmission. */ + +typedef struct { + CSUM csum; /* checksum of the remaining bytes */ + short valid; /* flag data are valid */ + + HEALTH health; /* [---] */ + T_GPS t0a; /* Reference Time Almanac [sec] */ + + l_fp sqrt_A; /* Square Root of semi-major Axis [sqrt(m)] */ + l_fp e; /* Eccentricity [---] */ + + l_fp M0; /* ± Mean Anomaly at Ref. Time [rad] */ + l_fp omega; /* ± Argument of Perigee [rad] */ + l_fp OMEGA0; /* ± Longit. of Asc. Node of orbit plane [rad] */ + l_fp OMEGADOT; /* ± Rate of Right Ascension [rad/sec] */ + l_fp deltai; /* ± [rad] */ + l_fp af0; /* ± Clock Correction Coefficient 0 [sec] */ + l_fp af1; /* ± Clock Correction Coefficient 1 [sec/sec] */ +} ALM; + + +/* ionospheric correction parameters */ + +typedef struct { + CSUM csum; /* checksum of the remaining bytes */ + short valid; /* flag data are valid */ + + l_fp alpha_0; /* Ionosph. Corr. Coeff. Alpha 0 [sec] */ + l_fp alpha_1; /* Ionosph. Corr. Coeff. Alpha 1 [sec/deg] */ + l_fp alpha_2; /* Ionosph. Corr. Coeff. Alpha 2 [sec/deg^2] */ + l_fp alpha_3; /* Ionosph. Corr. Coeff. Alpha 3 [sec/deg^3] */ + + l_fp beta_0; /* Ionosph. Corr. Coeff. Beta 0 [sec] */ + l_fp beta_1; /* Ionosph. Corr. Coeff. Beta 1 [sec/deg] */ + l_fp beta_2; /* Ionosph. Corr. Coeff. Beta 2 [sec/deg^2] */ + l_fp beta_3; /* Ionosph. Corr. Coeff. Beta 3 [sec/deg^3] */ + +} IONO; + +void mbg_tm_str P((unsigned char **, TM *)); +void mbg_tgps_str P((unsigned char **, T_GPS *)); +void get_mbg_header P((unsigned char **, GPS_MSG_HDR *)); +void put_mbg_header P((unsigned char **, GPS_MSG_HDR *)); +void get_mbg_sw_rev P((unsigned char **, SW_REV *)); +void get_mbg_ascii_msg P((unsigned char **, ASCII_MSG *)); +void get_mbg_svno P((unsigned char **, SVNO *)); +void get_mbg_health P((unsigned char **, HEALTH *)); +void get_mbg_cfg P((unsigned char **, CFG *)); +void get_mbg_tgps P((unsigned char **, T_GPS *)); +void get_mbg_tm P((unsigned char **, TM *)); +void get_mbg_ttm P((unsigned char **, TTM *)); +void get_mbg_synth P((unsigned char **, SYNTH *)); +void get_mbg_tzdl P((unsigned char **, TZDL *)); +void get_mbg_antinfo P((unsigned char **, ANT_INFO *)); +void get_mbg_cfgh P((unsigned char **, CFGH *)); +void get_mbg_utc P((unsigned char **, UTC *)); +void get_mbg_lla P((unsigned char **, LLA)); +void get_mbg_xyz P((unsigned char **, XYZ)); +void get_mbg_portparam P((unsigned char **, PORT_PARM *)); +void get_mbg_eph P((unsigned char **, EPH *)); +void get_mbg_alm P((unsigned char **, ALM *)); +void get_mbg_iono P((unsigned char **, IONO *)); + +unsigned long mbg_csum P((unsigned char *, unsigned int)); + +#endif +/* + * mbg_gps166.h,v + * Revision 4.1 1998/06/12 15:07:30 kardel + * fixed prototyping + * + * Revision 4.0 1998/04/10 19:50:42 kardel + * Start 4.0 release version numbering + * + * Revision 1.1 1998/04/10 19:27:34 kardel + * initial NTP VERSION 4 integration of PARSE with GPS166 binary support + * + * Revision 1.1 1997/10/06 20:55:38 kardel + * new parse structure + * + */ diff --git a/include/md5.h b/include/md5.h new file mode 100644 index 000000000000..8241647601b3 --- /dev/null +++ b/include/md5.h @@ -0,0 +1,51 @@ +/* MD5.H - header file for MD5C.C + */ + +/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All + rights reserved. + + License to copy and use this software is granted provided that it + is identified as the "RSA Data Security, Inc. MD5 Message-Digest + Algorithm" in all material mentioning or referencing this software + or this function. + + License is also granted to make and use derivative works provided + that such works are identified as "derived from the RSA Data + Security, Inc. MD5 Message-Digest Algorithm" in all material + mentioning or referencing the derived work. + + RSA Data Security, Inc. makes no representations concerning either + the merchantability of this software or the suitability of this + software for any particular purpose. It is provided "as is" + without express or implied warranty of any kind. + + These notices must be retained in any copies of any part of this + documentation and/or software. + */ + +#ifndef _MD5_H_ +#define _MD5_H_ 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/*#include "global.h" */ + +/* MD5 context. */ +typedef struct { + UINT4 state[4]; /* state (ABCD) */ + UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD5_CTX; + +void MD5Init PROTO_LIST ((MD5_CTX *)); +void MD5Update PROTO_LIST + ((MD5_CTX *, unsigned char *, unsigned int)); +void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *)); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mx4200.h b/include/mx4200.h new file mode 100644 index 000000000000..6ea2c6039cf6 --- /dev/null +++ b/include/mx4200.h @@ -0,0 +1,40 @@ + +/* records transmitted from extern CDU to MX 4200 */ +#define PMVXG_S_INITMODEA 0 /* initialization/mode part A */ +#define PMVXG_S_INITMODEB 1 /* initialization/mode part B*/ +#define PMVXG_S_SATHEALTH 2 /* satellite health control */ +#define PMVXG_S_DIFFNAV 3 /* differential navigation control */ +#define PMVXG_S_PORTCONF 7 /* control port configuration */ +#define PMVXG_S_GETSELFTEST 13 /* self test (request results) */ +#define PMVXG_S_RTCMCONF 16 /* RTCM port configuration */ +#define PMVXG_S_PASSTHRU 17 /* equipment port pass-thru config */ +#define PMVXG_S_RESTART 18 /* restart control */ +#define PMVXG_S_OSCPARAM 19 /* oscillator parameter */ +#define PMVXG_S_DOSELFTEST 20 /* self test (activate a test) */ +#define PMVXG_S_TRECOVCONF 23 /* time recovery configuration */ +#define PMVXG_S_RAWDATASEL 24 /* raw data port data selection */ +#define PMVXG_S_EQUIPCONF 26 /* equipment port configuration */ +#define PMVXG_S_RAWDATACONF 27 /* raw data port configuration */ + +/* records transmitted from MX 4200 to external CDU */ +#define PMVXG_D_STATUS 0 /* status */ +#define PMVXG_D_POSITION 1 /* position */ +#define PMVXG_D_OPDOPS 3 /* (optimum) DOPs */ +#define PMVXG_D_MODEDATA 4 /* mode data */ +#define PMVXG_D_SATPRED 5 /* satellite predictions */ +#define PMVXG_D_SATHEALTH 6 /* satellite health status */ +#define PMVXG_D_UNRECOG 7 /* unrecognized request response */ +#define PMVXG_D_SIGSTRLOC 8 /* sig strength & location (sats 1-4) */ +#define PMVXG_D_SPEEDHEAD 11 /* speed/heading data */ +#define PMVXG_D_OSELFTEST 12 /* (old) self-test results */ +#define PMVXG_D_SIGSTRLOC2 18 /* sig strength & location (sats 5-8) */ +#define PMVXG_D_OSCPARAM 19 /* oscillator parameter */ +#define PMVXG_D_SELFTEST 20 /* self test results */ +#define PMVXG_D_PHV 21 /* position, height & velocity */ +#define PMVXG_D_DOPS 22 /* DOPs */ +#define PMVXG_D_SOFTCONF 30 /* software configuration */ +#define PMVXG_D_DIFFGPSMODE 503 /* differential gps moding */ +#define PMVXG_D_TRECOVUSEAGE 523 /* time recovery usage */ +#define PMVXG_D_RAWDATAOUT 524 /* raw data port data output */ +#define PMVXG_D_TRECOVRESULT 828 /* time recovery results */ +#define PMVXG_D_TRECOVOUT 830 /* time recovery output message */ diff --git a/include/ntif.h b/include/ntif.h new file mode 100644 index 000000000000..837785272d24 --- /dev/null +++ b/include/ntif.h @@ -0,0 +1,98 @@ +/* this is a hacked version of if.h from unix to contain the stuff we need only to build named (bind) with + the minimal amount of changes... by l. kahn */ + + /* + * Copyright (c) 1982, 1986 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#ifndef _NET_IF_H +#define _NET_IF_H + + +/* #pragma ident "@(#)if.h 1.3 93/06/30 SMI" +/* if.h 1.26 90/05/29 SMI; from UCB 7.1 6/4/86 */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Structures defining a network interface, providing a packet + * transport mechanism (ala level 0 of the PUP protocols). + * + * Each interface accepts output datagrams of a specified maximum + * length, and provides higher level routines with input datagrams + * received from its medium. + * + * Output occurs when the routine if_output is called, with three parameters: + * (*ifp->if_output)(ifp, m, dst) + * Here m is the mbuf chain to be sent and dst is the destination address. + * The output routine encapsulates the supplied datagram if necessary, + * and then transmits it on its medium. + * + * On input, each interface unwraps the data received by it, and either + * places it on the input queue of a internetwork datagram routine + * and posts the associated software interrupt, or passes the datagram to a raw + * packet input routine. + * + * Routines exist for locating interfaces by their addresses + * or for locating a interface on a certain network, as well as more general + * routing and gateway routines maintaining information used to locate + * interfaces. These routines live in the files if.c and route.c + */ + +/* + * Structure defining a queue for a network interface. + * + * (Would like to call this struct ``if'', but C isn't PL/1.) + */ +/* + * Interface request structure used for socket + * ioctl's. All interface ioctl's must have parameter + * definitions which begin with ifr_name. The + * remainder may be interface specific. + */ +#ifdef FD_SETSIZE +#undef FD_SETSIZE +#endif +#define FD_SETSIZE 512 +#include <winsock.h> +typedef char *caddr_t; + +int get_winnt_interfaces(); + +struct ifreq { +#define IFNAMSIZ 16 + char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + struct sockaddr ifru_addr; + char nt_mask[IFNAMSIZ]; /* new field to store mask returned from nt lookup l. kahn */ + +#define ifr_addr ifru_addr /* address */ +#define ifr_mask nt_mask /* nt mask in character form */ + +}; + +/* + * Structure used in SIOCGIFCONF request. + * Used to retrieve interface configuration + * for machine (useful for programs which + * must know all networks accessible). + */ +struct ifconf { + int ifc_len; /* size of associated buffer */ + union { + caddr_t ifcu_buf; + struct ifreq *ifcu_req; + } ifc_ifcu; +#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ +#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _NET_IF_H */ + diff --git a/include/ntp.h b/include/ntp.h new file mode 100644 index 000000000000..1ce302b7be98 --- /dev/null +++ b/include/ntp.h @@ -0,0 +1,874 @@ +/* + * ntp.h - NTP definitions for the masses + */ +#ifndef NTP_H +#define NTP_H + +#include "ntp_types.h" +#include <math.h> +#ifdef OPENSSL +#include "ntp_crypto.h" +#endif /* OPENSSL */ + +/* + * Calendar arithmetic - contributed by G. Healton + */ +#define YEAR_BREAK 500 /* years < this are tm_year values: + * Break < AnyFourDigitYear && Break > + * Anytm_yearYear */ + +#define YEAR_PIVOT 98 /* 97/98: years < this are year 2000+ + * FYI: official UNIX pivot year is + * 68/69 */ + +/* + * Number of Days since 1 BC Gregorian to 1 January of given year + */ +#define julian0(year) (((year) * 365 ) + ((year) > 0 ? (((year) + 3) \ + / 4 - ((year - 1) / 100) + ((year - 1) / \ + 400)) : 0)) + +/* + * Number of days since start of NTP time to 1 January of given year + */ +#define ntp0(year) (julian0(year) - julian0(1900)) + +/* + * Number of days since start of UNIX time to 1 January of given year + */ +#define unix0(year) (julian0(year) - julian0(1970)) + +/* + * LEAP YEAR test for full 4-digit years (e.g, 1999, 2010) + */ +#define isleap_4(y) ((y) % 4 == 0 && !((y) % 100 == 0 && !(y % \ + 400 == 0))) + +/* + * LEAP YEAR test for tm_year (struct tm) years (e.g, 99, 110) + */ +#define isleap_tm(y) ((y) % 4 == 0 && !((y) % 100 == 0 && !(((y) \ + + 1900) % 400 == 0))) + +/* + * to convert simple two-digit years to tm_year style years: + * + * if (year < YEAR_PIVOT) + * year += 100; + * + * to convert either two-digit OR tm_year years to four-digit years: + * + * if (year < YEAR_PIVOT) + * year += 100; + * + * if (year < YEAR_BREAK) + * year += 1900; + */ + +/* + * How to get signed characters. On machines where signed char works, + * use it. On machines where signed char doesn't work, char had better + * be signed. + */ +#ifdef NEED_S_CHAR_TYPEDEF +# if SIZEOF_SIGNED_CHAR +typedef signed char s_char; +# else +typedef char s_char; +# endif + /* XXX: Why is this sequent bit INSIDE this test? */ +# ifdef sequent +# undef SO_RCVBUF +# 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. + */ +#define NTP_VERSION ((u_char)4) /* current version number */ +#define NTP_OLDVERSION ((u_char)1) /* oldest credible version */ +#define NTP_PORT 123 /* included for non-unix machines */ + +/* + * Poll interval parameters + */ +#define NTP_UNREACH 16 /* poll interval backoff count */ +#define NTP_MINPOLL 4 /* log2 min poll interval (16 s) */ +#define NTP_MINDPOLL 6 /* log2 default min poll (64 s) */ +#define NTP_MAXDPOLL 10 /* log2 default max poll (~17 m) */ +#define NTP_MAXPOLL 17 /* log2 max poll interval (~36 h) */ +#define NTP_BURST 8 /* packets in burst */ +#define BURST_DELAY 2 /* interburst delay (s) */ +#define RESP_DELAY 1 /* crypto response delay (s) */ + +/* + * Clock filter algorithm tuning parameters + */ +#define MINDISPERSE .01 /* min dispersion */ +#define MAXDISPERSE 16. /* max dispersion */ +#define NTP_SHIFT 8 /* clock filter stages */ +#define NTP_FWEIGHT .5 /* clock filter weight */ + +/* + * Selection algorithm tuning parameters + */ +#define NTP_MINCLOCK 4 /* minimum survivors */ +#define NTP_MAXCLOCK 50 /* maximum candidates */ +#define MAXDISTANCE 1. /* max root distance */ +#define CLOCK_SGATE 3. /* popcorn spike gate */ +#define HUFFPUFF 900 /* huff-n'-puff sample interval (s) */ +#define HYST .5 /* anti-clockhop hysteresis */ +#define HYST_TC .875 /* anti-clockhop hysteresis decay */ +#define MAX_TTL 8 /* max ttl mapping vector size */ +#define NTP_MAXEXTEN 1024 /* maximum extension field size */ + +/* + * Miscellaneous stuff + */ +#define NTP_MAXKEY 65535 /* maximum authentication key number */ + +/* + * Limits of things + */ +#define MAXFILENAME 128 /* max length of file name */ +#define MAXHOSTNAME 512 /* max length of host/node name */ +#define NTP_MAXSTRLEN 256 /* maximum string length */ +#define MAXINTERFACES 512 /* max number of interfaces */ + +/* + * Operations for jitter calculations (these use doubles). + * + * Note that we carefully separate the jitter component from the + * dispersion component (frequency error plus precision). The frequency + * error component is computed as CLOCK_PHI times the difference between + * the epoch of the time measurement and the reference time. The + * precision componen is computed as the square root of the mean of the + * squares of a zero-mean, uniform distribution of unit maximum + * amplitude. Whether this makes statistical sense may be arguable. + */ +#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 UNIVAR(x) (SQUARE(.28867513 * LOGTOD(x))) /* std uniform distr */ +#define ULOGTOD(a) (1L << (int)(a)) /* ulog2 to double */ + +#define EVENT_TIMEOUT 0 /* one second, that is */ + +/* + * The interface structure is used to hold the addresses and socket + * numbers of each of the interfaces we are using. + */ +struct interface { + SOCKET fd; /* socket this is opened on */ + SOCKET bfd; /* socket for receiving broadcasts */ + struct sockaddr_storage sin; /* interface address */ + struct sockaddr_storage bcast; /* broadcast address */ + struct sockaddr_storage mask; /* interface mask */ + char name[32]; /* name of interface */ + int flags; /* interface flags */ + int last_ttl; /* last TTL specified */ + u_int addr_refid; /* IPv4 addr or IPv6 hash */ + int num_mcast; /* No. of IP addresses in multicast socket */ + volatile long received; /* number of incoming packets */ + long sent; /* number of outgoing packets */ + long notsent; /* number of send failures */ +}; + +/* + * Flags for interfaces + */ +#define INT_UP 1 /* Interface is up */ +#define INT_PPP 2 /* Point-to-point interface */ +#define INT_LOOPBACK 4 /* the loopback interface */ +#define INT_BROADCAST 8 /* can broadcast out this interface */ +#define INT_MULTICAST 16 /* multicasting enabled */ +#define INT_BCASTOPEN 32 /* broadcast socket is open */ + +/* + * Define flasher bits (tests 1 through 11 in packet procedure) + * These reveal the state at the last grumble from the peer and are + * most handy for diagnosing problems, even if not strictly a state + * variable in the spec. These are recorded in the peer structure. + */ +#define TEST1 0x0001 /* duplicate packet received */ +#define TEST2 0x0002 /* bogus packet received */ +#define TEST3 0x0004 /* protocol unsynchronized */ +#define TEST4 0x0008 /* access denied */ +#define TEST5 0x0010 /* authentication failed */ +#define TEST6 0x0020 /* peer clock unsynchronized */ +#define TEST7 0x0040 /* peer stratum out of bounds */ +#define TEST8 0x0080 /* root delay/dispersion bounds check */ +#define TEST9 0x0100 /* peer delay/dispersion bounds check */ +#define TEST10 0x0200 /* autokey failed */ +#define TEST11 0x0400 /* proventic not confirmed */ + +/* + * The peer structure. Holds state information relating to the guys + * we are peering with. Most of this stuff is from section 3.2 of the + * spec. + */ +struct peer { + struct peer *next; /* pointer to next association */ + struct peer *ass_next; /* link pointer in associd hash */ + struct sockaddr_storage srcadr; /* address of remote host */ + struct interface *dstadr; /* pointer to address on local host */ + associd_t associd; /* association ID */ + u_char version; /* version number */ + u_char hmode; /* local association mode */ + u_char hpoll; /* local poll interval */ + u_char kpoll; /* last poll interval */ + u_char minpoll; /* min poll interval */ + u_char maxpoll; /* max poll interval */ + u_char burst; /* packets remaining in burst */ + u_int flags; /* association flags */ + u_char cast_flags; /* additional flags */ + u_int flash; /* protocol error test tally bits */ + u_char last_event; /* last peer error code */ + u_char num_events; /* number of error events */ + u_char ttl; /* ttl/refclock mode */ + + /* + * Variables used by reference clock support + */ + struct refclockproc *procptr; /* refclock structure pointer */ + u_char refclktype; /* reference clock type */ + u_char refclkunit; /* reference clock unit number */ + u_char sstclktype; /* clock type for system status word */ + + /* + * Variables set by received packet + */ + u_char leap; /* local leap indicator */ + u_char pmode; /* remote association mode */ + u_char stratum; /* remote stratum */ + s_char precision; /* remote clock precision */ + u_char ppoll; /* remote poll interval */ + u_int32 refid; /* remote reference ID */ + l_fp reftime; /* update epoch */ + + /* + * Variables used by authenticated client + */ + keyid_t keyid; /* current key ID */ +#ifdef OPENSSL +#define clear_to_zero assoc + associd_t assoc; /* peer association ID */ + u_int32 crypto; /* peer status word */ + EVP_PKEY *pkey; /* public key */ + const EVP_MD *digest; /* message digest algorithm */ + char *subject; /* certificate subject name */ + char *issuer; /* certificate issuer name */ + keyid_t pkeyid; /* previous key ID */ + keyid_t pcookie; /* peer cookie */ + EVP_PKEY *ident_pkey; /* identity key */ + tstamp_t fstamp; /* identity filestamp */ + BIGNUM *iffval; /* IFF/GQ challenge */ + BIGNUM *grpkey; /* GQ group key */ + struct value cookval; /* cookie values */ + struct value recval; /* receive autokey values */ + struct value tai_leap; /* leapseconds values */ + struct exten *cmmd; /* extension pointer */ + + /* + * Variables used by authenticated server + */ + keyid_t *keylist; /* session key ID list */ + int keynumber; /* current key number */ + struct value encrypt; /* send encrypt values */ + struct value sndval; /* send autokey values */ +#else /* OPENSSL */ +#define clear_to_zero status +#endif /* OPENSSL */ + + /* + * Ephemeral state variables + */ + u_char status; /* peer status */ + u_char reach; /* reachability register */ + u_long epoch; /* reference epoch */ + u_short filter_nextpt; /* index into filter shift register */ + double filter_delay[NTP_SHIFT]; /* delay shift register */ + double filter_offset[NTP_SHIFT]; /* offset shift register */ + double filter_disp[NTP_SHIFT]; /* dispersion shift register */ + u_long filter_epoch[NTP_SHIFT]; /* epoch shift register */ + u_char filter_order[NTP_SHIFT]; /* filter sort index */ + l_fp org; /* originate time stamp */ + l_fp rec; /* receive time stamp */ + l_fp xmt; /* transmit time stamp */ + double offset; /* peer clock offset */ + double delay; /* peer roundtrip delay */ + double jitter; /* peer jitter (squares) */ + double disp; /* peer dispersion */ + double estbdelay; /* clock offset to broadcast server */ + double hyst; /* anti-clockhop hysteresis */ + + /* + * Variables set by received packet + */ + double rootdelay; /* roundtrip delay to primary clock */ + double rootdispersion; /* dispersion to primary clock */ + + /* + * End of clear-to-zero area + */ + u_long update; /* receive epoch */ +#define end_clear_to_zero update + u_int unreach; /* unreachable count */ + u_long outdate; /* send time last packet */ + u_long nextdate; /* send time next packet */ + u_long nextaction; /* peer local activity timeout (refclocks mainly) */ + void (*action) P((struct peer *)); /* action timeout function */ + /* + * Statistic counters + */ + u_long timereset; /* time stat counters were reset */ + u_long timereceived; /* last packet received time */ + u_long timereachable; /* last reachable/unreachable time */ + + u_long sent; /* packets sent */ + u_long received; /* packets received */ + u_long processed; /* packets processed by the protocol */ + u_long badauth; /* packets cryptosum failed */ + u_long bogusorg; /* packets bogus origin */ + u_long oldpkt; /* packets duplicate packet */ + u_long seldisptoolarge; /* packets dispersion to large*/ + u_long selbroken; /* not used */ + u_long rank; /* number of times selected or in cluster */ +}; + +/* + * Values for peer.leap, sys_leap + */ +#define LEAP_NOWARNING 0x0 /* normal, no leap second warning */ +#define LEAP_ADDSECOND 0x1 /* last minute of day has 61 seconds */ +#define LEAP_DELSECOND 0x2 /* last minute of day has 59 seconds */ +#define LEAP_NOTINSYNC 0x3 /* overload, clock is free running */ + +/* + * Values for peer.mode + */ +#define MODE_UNSPEC 0 /* unspecified (old version) */ +#define MODE_ACTIVE 1 /* symmetric active */ +#define MODE_PASSIVE 2 /* symmetric passive */ +#define MODE_CLIENT 3 /* client mode */ +#define MODE_SERVER 4 /* server mode */ +#define MODE_BROADCAST 5 /* broadcast mode */ +#define MODE_CONTROL 6 /* control mode packet */ +#define MODE_PRIVATE 7 /* implementation defined function */ +#define MODE_BCLIENT 8 /* broadcast client mode */ + +/* + * Values for peer.stratum, sys_stratum + */ +#define STRATUM_REFCLOCK ((u_char)0) /* default stratum */ +/* A stratum of 0 in the packet is mapped to 16 internally */ +#define STRATUM_PKT_UNSPEC ((u_char)0) /* unspecified in packet */ +#define STRATUM_UNSPEC ((u_char)16) /* unspecified */ + +/* + * Values for peer.flags + */ +#define FLAG_CONFIG 0x0001 /* association was configured */ +#define FLAG_AUTHENABLE 0x0002 /* authentication required */ +#define FLAG_AUTHENTIC 0x0004 /* last message was authentic */ +#define FLAG_SKEY 0x0008 /* autokey authentication */ +#define FLAG_MCAST 0x0010 /* multicast client mode */ +#define FLAG_REFCLOCK 0x0020 /* this is actually a reference clock */ +#define FLAG_SYSPEER 0x0040 /* this is one of the selected peers */ +#define FLAG_PREFER 0x0080 /* this is the preferred peer */ +#define FLAG_BURST 0x0100 /* burst mode */ +#define FLAG_IBURST 0x0200 /* initial burst mode */ +#define FLAG_NOSELECT 0x0400 /* this is a "noselect" peer */ +#define FLAG_ASSOC 0x0800 /* autokey request */ + +/* + * Definitions for the clear() routine. We use memset() to clear + * the parts of the peer structure which go to zero. These are + * used to calculate the start address and length of the area. + */ +#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 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 */ +#define REFCLK_LOCALCLOCK 1 /* external (e.g., lockclock) */ +#define REFCLK_GPS_TRAK 2 /* TRAK 8810 GPS Receiver */ +#define REFCLK_WWV_PST 3 /* PST/Traconex 1020 WWV/H */ +#define REFCLK_SPECTRACOM 4 /* Spectracom (generic) Receivers */ +#define REFCLK_TRUETIME 5 /* TrueTime (generic) Receivers */ +#define REFCLK_IRIG_AUDIO 6 /* IRIG-B/W audio decoder */ +#define REFCLK_CHU_AUDIO 7 /* CHU audio demodulator/decoder */ +#define REFCLK_PARSE 8 /* generic driver (usually DCF77,GPS,MSF) */ +#define REFCLK_GPS_MX4200 9 /* Magnavox MX4200 GPS */ +#define REFCLK_GPS_AS2201 10 /* Austron 2201A GPS */ +#define REFCLK_GPS_ARBITER 11 /* Arbiter 1088A/B/ GPS */ +#define REFCLK_IRIG_TPRO 12 /* KSI/Odetics TPRO-S IRIG */ +#define REFCLK_ATOM_LEITCH 13 /* Leitch CSD 5300 Master Clock */ +#define REFCLK_MSF_EES 14 /* EES M201 MSF Receiver */ +#define REFCLK_GPSTM_TRUE 15 /* OLD TrueTime GPS/TM-TMD Receiver */ +#define REFCLK_IRIG_BANCOMM 16 /* Bancomm GPS/IRIG Interface */ +#define REFCLK_GPS_DATUM 17 /* Datum Programmable Time System */ +#define REFCLK_NIST_ACTS 18 /* NIST Auto Computer Time Service */ +#define REFCLK_WWV_HEATH 19 /* Heath GC1000 WWV/WWVH Receiver */ +#define REFCLK_GPS_NMEA 20 /* NMEA based GPS clock */ +#define REFCLK_GPS_VME 21 /* TrueTime GPS-VME Interface */ +#define REFCLK_ATOM_PPS 22 /* 1-PPS Clock Discipline */ +#define REFCLK_PTB_ACTS 23 /* PTB Auto Computer Time Service */ +#define REFCLK_USNO 24 /* Naval Observatory dialup */ +#define REFCLK_GPS_HP 26 /* HP 58503A Time/Frequency Receiver */ +#define REFCLK_ARCRON_MSF 27 /* ARCRON MSF radio clock. */ +#define REFCLK_SHM 28 /* clock attached thru shared memory */ +#define REFCLK_PALISADE 29 /* Trimble Navigation Palisade GPS */ +#define REFCLK_ONCORE 30 /* Motorola UT Oncore GPS */ +#define REFCLK_GPS_JUPITER 31 /* Rockwell Jupiter GPS receiver */ +#define REFCLK_CHRONOLOG 32 /* Chrono-log K WWVB receiver */ +#define REFCLK_DUMBCLOCK 33 /* Dumb localtime clock */ +#define REFCLK_ULINK 34 /* Ultralink M320 WWVB receiver */ +#define REFCLK_PCF 35 /* Conrad parallel port radio clock */ +#define REFCLK_WWV_AUDIO 36 /* WWV/H audio demodulator/decoder */ +#define REFCLK_FG 37 /* Forum Graphic GPS */ +#define REFCLK_HOPF_SERIAL 38 /* hopf DCF77/GPS serial receiver */ +#define REFCLK_HOPF_PCI 39 /* hopf DCF77/GPS PCI receiver */ +#define REFCLK_JJY 40 /* JJY receiver */ +#define REFCLK_TT560 41 /* TrueTime 560 IRIG-B decoder */ +#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 */ + + /* + * Macro for sockaddr_storage structures operations + */ +#define SOCKCMP(sock1, sock2) \ + (((struct sockaddr_storage *)sock1)->ss_family \ + == ((struct sockaddr_storage *)sock2)->ss_family ? \ + ((struct sockaddr_storage *)sock1)->ss_family == AF_INET ? \ + memcmp(&((struct sockaddr_in *)sock1)->sin_addr, \ + &((struct sockaddr_in *)sock2)->sin_addr, \ + sizeof(struct in_addr)) == 0 : \ + memcmp(&((struct sockaddr_in6 *)sock1)->sin6_addr, \ + &((struct sockaddr_in6 *)sock2)->sin6_addr, \ + sizeof(struct in6_addr)) == 0 : \ + 0) + +#define SOCKNUL(sock1) \ + (((struct sockaddr_storage *)sock1)->ss_family == AF_INET ? \ + (((struct sockaddr_in *)sock1)->sin_addr.s_addr == 0) : \ + (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)sock1)->sin6_addr))) + +#define SOCKLEN(sock) \ + (((struct sockaddr_storage *)sock)->ss_family == AF_INET ? \ + (sizeof(struct sockaddr_in)) : (sizeof(struct sockaddr_in6))) + +#define ANYSOCK(sock) \ + memset(((struct sockaddr_in *)sock), 0, \ + sizeof(struct sockaddr_storage)) + +#define ANY_INTERFACE_CHOOSE(sock) \ + (((struct sockaddr_storage *)sock)->ss_family == AF_INET ? \ + any_interface : any6_interface) + +/* + * We tell reference clocks from real peers by giving the reference + * clocks an address of the form 127.127.t.u, where t is the type and + * u is the unit number. We define some of this here since we will need + * some sanity checks to make sure this address isn't interpretted as + * that of a normal peer. + */ +#define REFCLOCK_ADDR 0x7f7f0000 /* 127.127.0.0 */ +#define REFCLOCK_MASK 0xffff0000 /* 255.255.0.0 */ + +#define ISREFCLOCKADR(srcadr) ((SRCADR(srcadr) & REFCLOCK_MASK) \ + == REFCLOCK_ADDR) + +/* + * Macro for checking for invalid addresses. This is really, really + * gross, but is needed so no one configures a host on net 127 now that + * we're encouraging it the the configuration file. + */ +#define LOOPBACKADR 0x7f000001 +#define LOOPNETMASK 0xff000000 + +#define ISBADADR(srcadr) (((SRCADR(srcadr) & LOOPNETMASK) \ + == (LOOPBACKADR & LOOPNETMASK)) \ + && (SRCADR(srcadr) != LOOPBACKADR)) + +/* + * Utilities for manipulating addresses and port numbers + */ +#define NSRCADR(src) (((struct sockaddr_in *)src)->sin_addr.s_addr) /* address in net byte order */ +#define NSRCPORT(src) (((struct sockaddr_in *)src)->sin_port) /* port in net byte order */ +#define SRCADR(src) (ntohl(NSRCADR((src)))) /* address in host byte order */ +#define SRCPORT(src) (ntohs(NSRCPORT((src)))) /* host port */ + +#define CAST_V4(src) ((struct sockaddr_in *)&(src)) +#define CAST_V6(src) ((struct sockaddr_in6 *)&(src)) +#define GET_INADDR(src) (CAST_V4(src)->sin_addr.s_addr) +#define GET_INADDR6(src) (CAST_V6(src)->sin6_addr) + +#define SET_HOSTMASK(addr, family) \ + do { \ + memset((char *)(addr), 0, sizeof(struct sockaddr_storage)); \ + (addr)->ss_family = (family); \ + if ((family) == AF_INET) \ + GET_INADDR(*(addr)) = 0xffffffff; \ + else \ + memset(&GET_INADDR6(*(addr)), 0xff, \ + sizeof(struct in6_addr)); \ + } while(0) + +/* + * NTP packet format. The mac field is optional. It isn't really + * an l_fp either, but for now declaring it that way is convenient. + * See Appendix A in the specification. + * + * Note that all u_fp and l_fp values arrive in network byte order + * and must be converted (except the mac, which isn't, really). + */ +struct pkt { + u_char li_vn_mode; /* leap indicator, version and mode */ + u_char stratum; /* peer stratum */ + u_char ppoll; /* peer poll interval */ + s_char precision; /* peer clock precision */ + u_fp rootdelay; /* distance to primary clock */ + u_fp rootdispersion; /* clock dispersion */ + u_int32 refid; /* reference clock ID */ + l_fp reftime; /* time peer clock was last updated */ + l_fp org; /* originate time stamp */ + l_fp rec; /* receive time stamp */ + l_fp xmt; /* transmit time stamp */ + +#define LEN_PKT_NOMAC 12 * sizeof(u_int32) /* min header length */ +#define LEN_PKT_MAC LEN_PKT_NOMAC + sizeof(u_int32) +#define MIN_MAC_LEN 3 * sizeof(u_int32) /* DES */ +#define MAX_MAC_LEN 5 * sizeof(u_int32) /* MD5 */ + + /* + * The length of the packet less MAC must be a multiple of 64 + * with an RSA modulus and Diffie-Hellman prime of 64 octets + * and maximum host name of 128 octets, the maximum autokey + * command is 152 octets and maximum autokey response is 460 + * octets. A packet can contain no more than one command and one + * response, so the maximum total extension field length is 672 + * octets. But, to handle humungus certificates, the bank must + * be broke. + */ +#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 */ +}; + +/* + * Stuff for extracting things from li_vn_mode + */ +#define PKT_MODE(li_vn_mode) ((u_char)((li_vn_mode) & 0x7)) +#define PKT_VERSION(li_vn_mode) ((u_char)(((li_vn_mode) >> 3) & 0x7)) +#define PKT_LEAP(li_vn_mode) ((u_char)(((li_vn_mode) >> 6) & 0x3)) + +/* + * Stuff for putting things back into li_vn_mode + */ +#define PKT_LI_VN_MODE(li, vn, md) \ + ((u_char)((((li) << 6) & 0xc0) | (((vn) << 3) & 0x38) | ((md) & 0x7))) + + +/* + * Dealing with stratum. 0 gets mapped to 16 incoming, and back to 0 + * on output. + */ +#define PKT_TO_STRATUM(s) ((u_char)(((s) == (STRATUM_PKT_UNSPEC)) ?\ + (STRATUM_UNSPEC) : (s))) + +#define STRATUM_TO_PKT(s) ((u_char)(((s) == (STRATUM_UNSPEC)) ?\ + (STRATUM_PKT_UNSPEC) : (s))) + +/* + * Event codes. Used for reporting errors/events to the control module + */ +#define PEER_EVENT 0x080 /* this is a peer event */ +#define CRPT_EVENT 0x100 /* this is a crypto event */ + +/* + * System event codes + */ +#define EVNT_UNSPEC 0 /* unspecified */ +#define EVNT_SYSRESTART 1 /* system restart */ +#define EVNT_SYSFAULT 2 /* wsystem or hardware fault */ +#define EVNT_SYNCCHG 3 /* new leap or synch change */ +#define EVNT_PEERSTCHG 4 /* new source or stratum */ +#define EVNT_CLOCKRESET 5 /* clock reset */ +#define EVNT_BADDATETIM 6 /* invalid time or date */ +#define EVNT_CLOCKEXCPT 7 /* reference clock exception */ + +/* + * Peer event codes + */ +#define EVNT_PEERIPERR (1 | PEER_EVENT) /* IP error */ +#define EVNT_PEERAUTH (2 | PEER_EVENT) /* authentication failure */ +#define EVNT_UNREACH (3 | PEER_EVENT) /* change to unreachable */ +#define EVNT_REACH (4 | PEER_EVENT) /* change to reachable */ +#define EVNT_PEERCLOCK (5 | PEER_EVENT) /* clock exception */ + +/* + * Clock event codes + */ +#define CEVNT_NOMINAL 0 /* unspecified */ +#define CEVNT_TIMEOUT 1 /* poll timeout */ +#define CEVNT_BADREPLY 2 /* bad reply format */ +#define CEVNT_FAULT 3 /* hardware or software fault */ +#define CEVNT_PROP 4 /* propagation failure */ +#define CEVNT_BADDATE 5 /* bad date format or value */ +#define CEVNT_BADTIME 6 /* bad time format or value */ +#define CEVNT_MAX CEVNT_BADTIME + +/* + * Very misplaced value. Default port through which we send traps. + */ +#define TRAPPORT 18447 + + +/* + * To speed lookups, peers are hashed by the low order bits of the + * remote IP address. These definitions relate to that. + */ +#define HASH_SIZE 128 +#define HASH_MASK (HASH_SIZE-1) +#define HASH_ADDR(src) sock_hash(src) + +/* + * How we randomize polls. The poll interval is a power of two. + * We chose a random value which is between 1/4 and 3/4 of the + * poll interval we would normally use and which is an even multiple + * of the EVENT_TIMEOUT. The random number routine, given an argument + * spread value of n, returns an integer between 0 and (1<<n)-1. This + * is shifted by EVENT_TIMEOUT and added to the base value. + */ +#if defined(HAVE_MRAND48) +# define RANDOM (mrand48()) +# define SRANDOM(x) (srand48(x)) +#else +# define RANDOM (random()) +# define SRANDOM(x) (srandom(x)) +#endif + +#define RANDPOLL(x) ((1 << (x)) - 1 + (RANDOM & 0x3)) +#define RANDOM_SPREAD(poll) ((poll) - (EVENT_TIMEOUT+1)) +#define RANDOM_POLL(poll, rval) ((((rval)+1)<<EVENT_TIMEOUT) + (1<<((poll)-2))) + +/* + * min, min3 and max. Makes it easier to transliterate the spec without + * thinking about it. + */ +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#define min3(a,b,c) min(min((a),(b)), (c)) + + +/* + * Configuration items. These are for the protocol module (proto_config()) + */ +#define PROTO_BROADCLIENT 1 +#define PROTO_PRECISION 2 /* (not used) */ +#define PROTO_AUTHENTICATE 3 +#define PROTO_BROADDELAY 4 +#define PROTO_AUTHDELAY 5 /* (not used) */ +#define PROTO_MULTICAST_ADD 6 +#define PROTO_MULTICAST_DEL 7 +#define PROTO_NTP 8 +#define PROTO_KERNEL 9 +#define PROTO_MONITOR 10 +#define PROTO_FILEGEN 11 +#define PROTO_PPS 12 +#define PROTO_CAL 13 +#define PROTO_MINCLOCK 14 +#define PROTO_MINSANE 15 +#define PROTO_FLOOR 16 +#define PROTO_CEILING 17 +#define PROTO_COHORT 18 +#define PROTO_CALLDELAY 19 +#define PROTO_ADJ 20 + +/* + * Configuration items for the loop filter + */ +#define LOOP_DRIFTINIT 1 /* set initial frequency offset */ +#define LOOP_DRIFTCOMP 2 /* set frequency offset */ +#define LOOP_MAX 3 /* set step offset */ +#define LOOP_PANIC 4 /* set panic offseet */ +#define LOOP_PHI 5 /* set dispersion rate */ +#define LOOP_MINSTEP 6 /* set step timeout */ +#define LOOP_MINPOLL 7 /* set min poll interval (log2 s) */ +#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 */ + +/* + * Configuration items for the stats printer + */ +#define STATS_FREQ_FILE 1 /* configure drift file */ +#define STATS_STATSDIR 2 /* directory prefix for stats files */ +#define STATS_PID_FILE 3 /* configure ntpd PID file */ + +#define MJD_1900 15020 /* MJD for 1 Jan 1900 */ + +/* + * Default parameters. We use these in the absence of something better. + */ +#define DEFBROADDELAY 4e-3 /* default broadcast offset */ +#define INADDR_NTP 0xe0000101 /* NTP multicast address 224.0.1.1 */ + +/* + * Structure used optionally for monitoring when this is turned on. + */ +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 */ + u_long drop_count; /* dropped due RESLIMIT*/ + double avg_interval; /* average interpacket interval */ + u_long lasttime; /* interval since last packet */ + u_long count; /* total packet count */ + struct sockaddr_storage rmtadr; /* address of remote host */ + struct interface *interface; /* interface on which this arrived */ + u_short rmtport; /* remote port last came from */ + u_char mode; /* mode of incoming packet */ + u_char version; /* version of incoming packet */ + u_char cast_flags; /* flags MDF_?CAST */ +}; + +/* + * Values for cast_flags + */ +#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 */ + +/* + * 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 */ +/* + * Structure used for restrictlist entries + */ +struct restrictlist { + struct restrictlist *next; /* link to next entry */ + u_int32 addr; /* Ipv4 host address (host byte order) */ + u_int32 mask; /* Ipv4 mask for address (host byte order) */ + u_long count; /* number of packets matched */ + u_short flags; /* accesslist flags */ + u_short mflags; /* match flags */ +}; + +struct restrictlist6 { + struct restrictlist6 *next; /* link to next entry */ + struct in6_addr addr6; /* Ipv6 host address */ + struct in6_addr mask6; /* Ipv6 mask address */ + u_long count; /* number of packets matched */ + u_short flags; /* accesslist flags */ + u_short mflags; /* match flags */ +}; + + +/* + * Access flags + */ +#define RES_IGNORE 0x001 /* ignore packet */ +#define RES_DONTSERVE 0x002 /* access denied */ +#define RES_DONTTRUST 0x004 /* authentication required */ +#define RES_VERSION 0x008 /* version mismatch */ +#define RES_NOPEER 0x010 /* new association denied */ +#define RES_LIMITED 0x020 /* packet rate exceeded */ + +#define RES_FLAGS (RES_IGNORE | RES_DONTSERVE |\ + RES_DONTTRUST | RES_VERSION |\ + RES_NOPEER | RES_LIMITED) + +#define RES_NOQUERY 0x040 /* mode 6/7 packet denied */ +#define RES_NOMODIFY 0x080 /* mode 6/7 modify denied */ +#define RES_NOTRAP 0x100 /* mode 6/7 set trap denied */ +#define RES_LPTRAP 0x200 /* mode 6/7 low priority trap */ + +#define RES_DEMOBILIZE 0x400 /* send kiss of death packet */ +#define RES_TIMEOUT 0x800 /* timeout this entry */ + +#define RES_ALLFLAGS (RES_FLAGS | RES_NOQUERY |\ + RES_NOMODIFY | RES_NOTRAP |\ + RES_LPTRAP | RES_DEMOBILIZE |\ + RES_TIMEOUT) + +/* + * Match flags + */ +#define RESM_INTERFACE 0x1 /* this is an interface */ +#define RESM_NTPONLY 0x2 /* match ntp port only */ + +/* + * Restriction configuration ops + */ +#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 */ + +/* + * Endpoint structure for the select algorithm + */ +struct endpoint { + double val; /* offset of endpoint */ + int type; /* interval entry/exit */ +}; + +/* + * Defines for association matching + */ +#define AM_MODES 10 /* total number of modes */ +#define NO_PEER 0 /* action when no peer is found */ + +/* + * Association matching AM[] return codes + */ +#define AM_ERR -1 +#define AM_NOMATCH 0 +#define AM_PROCPKT 1 +#define AM_FXMIT 2 +#define AM_MANYCAST 3 +#define AM_NEWPASS 4 +#define AM_NEWBCL 5 +#define AM_POSSBCL 6 + +/* NetInfo configuration locations */ +#ifdef HAVE_NETINFO +#define NETINFO_CONFIG_DIR "/config/ntp" +#endif + +#endif /* NTP_H */ diff --git a/include/ntp_calendar.h b/include/ntp_calendar.h new file mode 100644 index 000000000000..95e2c12974ba --- /dev/null +++ b/include/ntp_calendar.h @@ -0,0 +1,112 @@ +/* + * ntp_calendar.h - definitions for the calendar time-of-day routine + */ +#ifndef NTP_CALENDAR_H +#define NTP_CALENDAR_H + +#include "ntp_types.h" + +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 */ +}; + +/* + * Days in each month. 30 days hath September... + */ +#define JAN 31 +#define FEB 28 +#define FEBLEAP 29 +#define MAR 31 +#define APR 30 +#define MAY 31 +#define JUN 30 +#define JUL 31 +#define AUG 31 +#define SEP 30 +#define OCT 31 +#define NOV 30 +#define DEC 31 + +/* + * 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. + */ +#define SECSPERMIN (60) /* seconds per minute */ +#define MINSPERHR (60) /* minutes per hour */ +#define HRSPERDAY (24) /* hours per day */ +#define DAYSPERYEAR (365) /* days per year */ + +#define SECSPERDAY (SECSPERMIN*MINSPERHR*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 + +/* + * 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 */ +#define TIMES24(val) (((val)<<4) + ((val)<<3)) /* *16 + *8 */ +#define TIMES7(val) (((val)<<3) - (val)) /* *8 - *1 */ +#define TIMESDPERC(val) (((val)<<10) + ((val)<<8) \ + + ((val)<<7) + ((val)<<5) \ + + ((val)<<4) + ((val)<<2) + (val)) /* *big* hack */ + +/* + * Another big hack. Cycle 22 started on March 1, 1988. This is + * STARTCYCLE22 seconds after the start of cycle 0. + */ +#define CYCLE22 (22) +#define STARTCYCLE22 (u_long)(0xa586b500) /* 2777068800 */ +#define MAR1988 (u_long)(STARTCYCLE22 + (u_long)MAR1900) + +/* + * The length of January + February in leap and non-leap years. + */ +#define JANFEBNOLEAP ((JAN+FEB) * SECSPERDAY) +#define JANFEBLEAP ((JAN+FEBLEAP) * SECSPERDAY) + + +extern void caljulian P((u_long, struct calendar *)); +extern u_long caltontp P((const struct calendar *)); + +/* + * Additional support stuff for Ed Rheingold's calendrical calculations + */ + +/* + * Start day of NTP time as days past the imaginary date 12/1/1 BC. + * P((This is the beginning of the Christian Era, or BCE.)) + */ +#define DAY_NTP_STARTS 693596 +/* + * The Gregorian calendar is based on a 400 year cycle. This is the number + * of days in each cycle. + */ +#define GREGORIAN_CYCLE_DAYS 146097 + +/* + * 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. + */ +#define GREGORIAN_NORMAL_CENTURY_DAYS 36524 + +/* + * Days in a normal 4 year leap year calendar cycle. + */ +#define GREGORIAN_NORMAL_LEAP_CYCLE_DAYS 1461 + +#define is_leapyear(y) (y%4 == 0 && !(y%100 == 0 && !(y%400 == 0))) + +#endif diff --git a/include/ntp_cmdargs.h b/include/ntp_cmdargs.h new file mode 100644 index 000000000000..e9ab9b1c29cc --- /dev/null +++ b/include/ntp_cmdargs.h @@ -0,0 +1,4 @@ +#include "ntp_types.h" + +extern void getstartup P((int, char **)); +extern void getCmdOpts P((int, char **)); diff --git a/include/ntp_config.h b/include/ntp_config.h new file mode 100644 index 000000000000..01478d2b6b07 --- /dev/null +++ b/include/ntp_config.h @@ -0,0 +1,178 @@ +/* + * Configuration file name + */ +#ifndef CONFIG_FILE +# ifndef SYS_WINNT +# define CONFIG_FILE "/etc/ntp.conf" +# else /* SYS_WINNT */ +# define CONFIG_FILE "%windir%\\system32\\drivers\\etc\\ntp.conf" +# define ALT_CONFIG_FILE "%windir%\\ntp.conf" +# define NTP_KEYSDIR "%windir%\\system32\\drivers\\etc" +# endif /* SYS_WINNT */ +#endif /* not CONFIG_FILE */ + +/* + * Types of entries we understand. + */ +#define CONFIG_UNKNOWN 0 + +/* + * Command keywords + */ +#define CONFIG_PEER 1 +#define CONFIG_SERVER 2 +#define CONFIG_AUTOMAX 3 +#define CONFIG_DRIFTFILE 4 +#define CONFIG_BROADCAST 5 +#define CONFIG_BROADCASTCLIENT 6 +#define CONFIG_AUTHENTICATE 7 +#define CONFIG_KEYS 8 +#define CONFIG_REVOKE 9 +#define CONFIG_PPS 10 +#define CONFIG_RESTRICT 11 +#define CONFIG_BDELAY 12 +#define CONFIG_TRUSTEDKEY 13 +#define CONFIG_REQUESTKEY 14 +#define CONFIG_CONTROLKEY 15 +#define CONFIG_TRAP 16 +#define CONFIG_FUDGE 17 +#define CONFIG_TINKER 18 +#define CONFIG_STATSDIR 19 +#define CONFIG_FILEGEN 20 +#define CONFIG_STATISTICS 21 +#define CONFIG_PIDFILE 22 +#define CONFIG_SETVAR 23 +#define CONFIG_DISCARD 24 +#define CONFIG_ADJ 25 +#define CONFIG_MULTICASTCLIENT 26 +#define CONFIG_ENABLE 27 +#define CONFIG_DISABLE 28 +#define CONFIG_PHONE 29 +#define CONFIG_LOGFILE 30 +#define CONFIG_LOGCONFIG 31 +#define CONFIG_MANYCASTCLIENT 32 +#define CONFIG_MANYCASTSERVER 33 +#define CONFIG_TOS 34 +#define CONFIG_TTL 35 +#define CONFIG_INCLUDEFILE 36 +#define CONFIG_KEYSDIR 37 +#define CONFIG_CDELAY 38 +#ifdef OPENSSL +#define CONFIG_CRYPTO 39 +#endif /* OPENSSL */ + +/* + * "peer", "server", "broadcast" modifier keywords + */ +#define CONF_MOD_VERSION 1 +#define CONF_MOD_KEY 2 +#define CONF_MOD_MINPOLL 3 +#define CONF_MOD_MAXPOLL 4 +#define CONF_MOD_PREFER 5 +#define CONF_MOD_BURST 6 +#define CONF_MOD_IBURST 7 +#define CONF_MOD_SKEY 8 +#define CONF_MOD_TTL 9 +#define CONF_MOD_MODE 10 +#define CONF_MOD_NOSELECT 11 + +/* + * "restrict" modifier keywords + */ +#define CONF_RES_MASK 1 +#define CONF_RES_IGNORE 2 +#define CONF_RES_NOSERVE 3 +#define CONF_RES_NOTRUST 4 +#define CONF_RES_NOQUERY 5 +#define CONF_RES_NOMODIFY 6 +#define CONF_RES_NOPEER 7 +#define CONF_RES_NOTRAP 8 +#define CONF_RES_LPTRAP 9 +#define CONF_RES_NTPPORT 10 +#define CONF_RES_LIMITED 11 +#define CONF_RES_VERSION 12 +#define CONF_RES_DEMOBILIZE 13 + +/* + * "trap" modifier keywords + */ +#define CONF_TRAP_PORT 1 +#define CONF_TRAP_INTERFACE 2 + +/* + * "fudge" modifier keywords + */ +#define CONF_FDG_TIME1 1 +#define CONF_FDG_TIME2 2 +#define CONF_FDG_STRATUM 3 +#define CONF_FDG_REFID 4 +#define CONF_FDG_FLAG1 5 +#define CONF_FDG_FLAG2 6 +#define CONF_FDG_FLAG3 7 +#define CONF_FDG_FLAG4 8 + +/* + * "filegen" modifier keywords + */ +#define CONF_FGEN_FILE 1 +#define CONF_FGEN_TYPE 2 +#define CONF_FGEN_FLAG_LINK 3 +#define CONF_FGEN_FLAG_NOLINK 4 +#define CONF_FGEN_FLAG_ENABLE 5 +#define CONF_FGEN_FLAG_DISABLE 6 + +/* + * "pps" modifier keywords + */ +#define CONF_PPS_ASSERT 1 +#define CONF_PPS_CLEAR 2 +#define CONF_PPS_HARDPPS 3 + +/* + * "discard" modifier keywords + */ +#define CONF_DISCARD_AVERAGE 1 +#define CONF_DISCARD_MINIMUM 2 +#define CONF_DISCARD_MONITOR 3 + +/* + * "tinker" modifier keywords + */ +#define CONF_CLOCK_MAX 1 +#define CONF_CLOCK_PANIC 2 +#define CONF_CLOCK_PHI 3 +#define CONF_CLOCK_MINSTEP 4 +#define CONF_CLOCK_ALLAN 5 +#define CONF_CLOCK_HUFFPUFF 6 +#define CONF_CLOCK_FREQ 7 + +/* + * "tos" modifier keywords + */ +#define CONF_TOS_MINCLOCK 1 +#define CONF_TOS_MINSANE 2 +#define CONF_TOS_FLOOR 3 +#define CONF_TOS_CEILING 4 +#define CONF_TOS_COHORT 5 + +#ifdef OPENSSL +/* + * "crypto" modifier keywords + */ +#define CONF_CRYPTO_RSA 1 +#define CONF_CRYPTO_SIGN 2 +#define CONF_CRYPTO_LEAP 3 +#define CONF_CRYPTO_CERT 4 +#define CONF_CRYPTO_RAND 5 +#define CONF_CRYPTO_KEYS 6 +#define CONF_CRYPTO_IFFPAR 7 +#define CONF_CRYPTO_GQPAR 8 +#define CONF_CRYPTO_MVPAR 9 +#define CONF_CRYPTO_PW 10 +#endif /* OPENSSL */ + +/* + * Address selection, IPv4 or IPv6 + */ +#define CONF_ADDR_IPV4 1 +#define CONF_ADDR_IPV6 2 diff --git a/include/ntp_control.h b/include/ntp_control.h new file mode 100644 index 000000000000..c75d38b31ad6 --- /dev/null +++ b/include/ntp_control.h @@ -0,0 +1,283 @@ +/* + * ntp_control.h - definitions related to NTP mode 6 control messages + */ + +#include "ntp_types.h" + +struct ntp_control { + u_char li_vn_mode; /* leap, version, mode */ + u_char r_m_e_op; /* response, more, error, opcode */ + u_short sequence; /* sequence number of request */ + u_short status; /* status word for association */ + 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 */ +}; + +/* + * Length of the control header, in octets + */ +#define CTL_HEADER_LEN 12 +#define CTL_MAX_DATA_LEN 468 + + +/* + * Limits and things + */ +#define CTL_MAXTRAPS 3 /* maximum number of traps we allow */ +#define CTL_TRAPTIME (60*60) /* time out traps in 1 hour */ +#define CTL_MAXAUTHSIZE 64 /* maximum size of an authen'ed req */ + +/* + * Decoding for the r_m_e_op field + */ +#define CTL_RESPONSE 0x80 +#define CTL_ERROR 0x40 +#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) + +/* + * Opcodes + */ +#define CTL_OP_UNSPEC 0 +#define CTL_OP_READSTAT 1 +#define CTL_OP_READVAR 2 +#define CTL_OP_WRITEVAR 3 +#define CTL_OP_READCLOCK 4 +#define CTL_OP_WRITECLOCK 5 +#define CTL_OP_SETTRAP 6 +#define CTL_OP_ASYNCMSG 7 +#define CTL_OP_UNSETTRAP 31 + +/* + * {En,De}coding of the system status word + */ +#define CTL_SST_TS_UNSPEC 0 /* time source unspecified */ +#define CTL_SST_TS_ATOM 1 /* time source calibrated atomic */ +#define CTL_SST_TS_LF 2 /* time source VLF or LF radio */ +#define CTL_SST_TS_HF 3 /* time source HF radio */ +#define CTL_SST_TS_UHF 4 /* time source UHF radio */ +#define CTL_SST_TS_LOCAL 5 /* time source LOCAL */ +#define CTL_SST_TS_NTP 6 /* time source NTP */ +#define CTL_SST_TS_UDPTIME 7 /* time source UDP/TIME */ +#define CTL_SST_TS_WRSTWTCH 8 /* time source is wristwatch */ +#define CTL_SST_TS_TELEPHONE 9 /* time source is telephone modem */ +#define CTL_SST_TS_PPS 0x20 /* time source is PPS signal */ + +#define CTL_SYS_MAXEVENTS 15 + +#define CTL_SYS_STATUS(li, source, nevnt, evnt) \ + (((((unsigned short)(li))<< 14)&0xc000) | \ + (((source)<<8)&0x3f00) | \ + (((nevnt)<<4)&0x00f0) | \ + ((evnt)&0x000f)) + +#define CTL_SYS_LI(status) (((status)>>14) & 0x3) +#define CTL_SYS_SOURCE(status) (((status)>>8) & 0x3f) +#define CTL_SYS_NEVNT(status) (((status)>>4) & 0xf) +#define CTL_SYS_EVENT(status) ((status) & 0xf) + +/* + * {En,De}coding of the peer status word + */ +#define CTL_PST_CONFIG 0x80 +#define CTL_PST_AUTHENABLE 0x40 +#define CTL_PST_AUTHENTIC 0x20 +#define CTL_PST_REACH 0x10 +#define CTL_PST_UNSPEC 0x08 + +#define CTL_PST_SEL_REJECT 0 /* reject */ +#define CTL_PST_SEL_SANE 1 /* x falsetick */ +#define CTL_PST_SEL_CORRECT 2 /* . excess */ +#define CTL_PST_SEL_SELCAND 3 /* - outlyer */ +#define CTL_PST_SEL_SYNCCAND 4 /* + candidat */ +#define CTL_PST_SEL_DISTSYSPEER 5 /* # selected */ +#define CTL_PST_SEL_SYSPEER 6 /* * sys.peer */ +#define CTL_PST_SEL_PPS 7 /* o pps.peer */ + +#define CTL_PEER_MAXEVENTS 15 + +#define CTL_PEER_STATUS(status, nevnt, evnt) \ + ((((status)<<8) & 0xff00) | \ + (((nevnt)<<4) & 0x00f0) | \ + ((evnt) & 0x000f)) + +#define CTL_PEER_STATVAL(status)(((status)>>8) & 0xff) +#define CTL_PEER_NEVNT(status) (((status)>>4) & 0xf) +#define CTL_PEER_EVENT(status) ((status) & 0xf) + +/* + * {En,De}coding of the clock status word + */ +#define CTL_CLK_OKAY 0 +#define CTL_CLK_NOREPLY 1 +#define CTL_CLK_BADFORMAT 2 +#define CTL_CLK_FAULT 3 +#define CTL_CLK_PROPAGATION 4 +#define CTL_CLK_BADDATE 5 +#define CTL_CLK_BADTIME 6 + +#define CTL_CLK_STATUS(status, event) \ + ((((status)<<8) & 0xff00) | \ + ((event) & 0x00ff)) + +/* + * Error code responses returned when the E bit is set. + */ +#define CERR_UNSPEC 0 +#define CERR_PERMISSION 1 +#define CERR_BADFMT 2 +#define CERR_BADOP 3 +#define CERR_BADASSOC 4 +#define CERR_UNKNOWNVAR 5 +#define CERR_BADVALUE 6 +#define CERR_RESTRICT 7 + +#define CERR_NORESOURCE CERR_PERMISSION /* wish there was a different code */ + + +/* + * 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_STATE 10 +#define CS_OFFSET 11 +#define CS_DRIFT 12 +#define CS_JITTER 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 +#ifdef OPENSSL +#define CS_FLAGS 20 +#define CS_HOST 21 +#define CS_PUBLIC 22 +#define CS_CERTIF 23 +#define CS_REVTIME 24 +#define CS_LEAPTAB 25 +#define CS_TAI 26 +#define CS_DIGEST 27 +#define CS_MAXCODE CS_DIGEST +#else +#define CS_MAXCODE CS_VARLIST +#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_VALID 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_RANK 37 +#define CP_VARLIST 38 +#ifdef OPENSSL +#define CP_FLAGS 39 +#define CP_HOST 40 +#define CP_INITSEQ 41 +#define CP_INITKEY 42 +#define CP_INITTSP 43 +#define CP_DIGEST 44 +#define CP_IDENT 45 +#define CP_MAXCODE CP_IDENT +#else +#define CP_MAXCODE CP_VARLIST +#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. + */ +struct ctl_trap { + struct sockaddr_storage tr_addr;/* address of trap recipient */ + struct interface *tr_localaddr; /* interface to send this through */ + u_long tr_settime; /* time trap was set */ + u_long tr_count; /* async messages sent to this guy */ + u_long tr_origtime; /* time trap was originally set */ + u_long tr_resets; /* count of resets for this trap */ + u_short tr_sequence; /* trap sequence id */ + u_char tr_flags; /* trap flags */ + u_char tr_version; /* version number of trapper */ +}; + +/* + * Flag bits + */ +#define TRAP_INUSE 0x1 /* this trap is active */ +#define TRAP_NONPRIO 0x2 /* this trap is non-priority */ +#define TRAP_CONFIGURED 0x4 /* this trap was configured */ + +/* + * Types of things we may deal with + * shared between ntpq and library + */ +#define TYPE_SYS 1 +#define TYPE_PEER 2 +#define TYPE_CLOCK 3 diff --git a/include/ntp_crypto.h b/include/ntp_crypto.h new file mode 100644 index 000000000000..fb1955ce4064 --- /dev/null +++ b/include/ntp_crypto.h @@ -0,0 +1,166 @@ +/* + * ntp_crypto.h - definitions for cryptographic operations + */ +#ifdef OPENSSL +#include "openssl/evp.h" +/* + * The following bits are set by the CRYPTO_ASSOC message from + * the server and are not modified by the client. + */ +#define CRYPTO_FLAG_ENAB 0x0001 /* crypto enable */ +#define CRYPTO_FLAG_TAI 0x0002 /* leapseconds table */ + +#define CRYPTO_FLAG_PRIV 0x0010 /* PC identity scheme */ +#define CRYPTO_FLAG_IFF 0x0020 /* IFF identity scheme */ +#define CRYPTO_FLAG_GQ 0x0040 /* GQ identity scheme */ +#define CRYPTO_FLAG_MV 0x0080 /* MV identity scheme */ +#define CRYPTO_FLAG_MASK 0x00f0 /* identity scheme mask */ + +/* + * The following bits are used by the client during the protocol + * exchange. + */ +#define CRYPTO_FLAG_VALID 0x0100 /* public key verified */ +#define CRYPTO_FLAG_VRFY 0x0200 /* identity verified */ +#define CRYPTO_FLAG_PROV 0x0400 /* signature verified */ +#define CRYPTO_FLAG_AGREE 0x0800 /* cookie verifed */ +#define CRYPTO_FLAG_AUTO 0x1000 /* autokey verified */ +#define CRYPTO_FLAG_SIGN 0x2000 /* certificate signed */ +#define CRYPTO_FLAG_LEAP 0x4000 /* leapseconds table verified */ + +/* + * Flags used for certificate management + */ +#define CERT_SIGN 0x01 /* certificate is signed */ +#define CERT_TRUST 0x02 /* certificate is trusted */ +#define CERT_PRIV 0x04 /* certificate is private */ +#define CERT_ERROR 0x80 /* certificate has errors */ + +/* + * Extension field definitions + */ +#define CRYPTO_MAXLEN 1024 /* max extension field length */ +#define CRYPTO_VN 2 /* current protocol version number */ +#define CRYPTO_CMD(x) (((CRYPTO_VN << 8) | (x)) << 16) +#define CRYPTO_NULL CRYPTO_CMD(0) /* no operation */ +#define CRYPTO_ASSOC CRYPTO_CMD(1) /* association */ +#define CRYPTO_CERT CRYPTO_CMD(2) /* certificate */ +#define CRYPTO_COOK CRYPTO_CMD(3) /* cookie value */ +#define CRYPTO_AUTO CRYPTO_CMD(4) /* autokey values */ +#define CRYPTO_TAI CRYPTO_CMD(5) /* leapseconds table */ +#define CRYPTO_SIGN CRYPTO_CMD(6) /* certificate sign */ +#define CRYPTO_IFF CRYPTO_CMD(7) /* IFF identity scheme */ +#define CRYPTO_GQ CRYPTO_CMD(8) /* GQ identity scheme */ +#define CRYPTO_MV CRYPTO_CMD(9) /* MV identity scheme */ +#define CRYPTO_RESP 0x80000000 /* response */ +#define CRYPTO_ERROR 0x40000000 /* error */ + +/* + * Autokey event codes + */ +#define XEVNT_CMD(x) (CRPT_EVENT | (x)) +#define XEVNT_OK XEVNT_CMD(0) /* success */ +#define XEVNT_LEN XEVNT_CMD(1) /* bad field format or length */ +#define XEVNT_TSP XEVNT_CMD(2) /* bad timestamp */ +#define XEVNT_FSP XEVNT_CMD(3) /* bad filestamp */ +#define XEVNT_PUB XEVNT_CMD(4) /* bad procedure or data */ +#define XEVNT_MD XEVNT_CMD(5) /* unsupported digest type */ +#define XEVNT_KEY XEVNT_CMD(6) /* unsupported identity type */ +#define XEVNT_SGL XEVNT_CMD(7) /* bad signature length */ +#define XEVNT_SIG XEVNT_CMD(8) /* signature not verified */ +#define XEVNT_VFY XEVNT_CMD(9) /* certificate not verified */ +#define XEVNT_PER XEVNT_CMD(10) /* certificate expired */ +#define XEVNT_CKY XEVNT_CMD(11) /* bad or missing cookie */ +#define XEVNT_DAT XEVNT_CMD(12) /* bad or missing leapseconds table */ +#define XEVNT_CRT XEVNT_CMD(13) /* bad or missing certificate */ +#define XEVNT_ID XEVNT_CMD(14) /* bad or missing identification */ + +/* + * Configuration codes + */ +#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_LEAP 3 /* leapseconds table file name */ +#define CRYPTO_CONF_KEYS 4 /* keys directory path */ +#define CRYPTO_CONF_CERT 5 /* certificate file name */ +#define CRYPTO_CONF_RAND 6 /* random seed file name */ +#define CRYPTO_CONF_TRST 7 /* specify trust */ +#define CRYPTO_CONF_IFFPAR 8 /* IFF parameters file name */ +#define CRYPTO_CONF_GQPAR 9 /* GQ parameters file name */ +#define CRYPTO_CONF_MVPAR 10 /* GQ parameters file name */ +#define CRYPTO_CONF_PW 11 /* private key password */ + +/* + * Miscellaneous crypto stuff + */ +#define NTP_MAXSESSION 100 /* maximum session key list entries */ +#define NTP_AUTOMAX 13 /* log2 default max session key life */ +#define KEY_REVOKE 16 /* log2 default key revoke timeout */ +#define NTP_MAXEXTEN 1024 /* maximum extension field size */ + +/* + * The autokey structure holds the values used to authenticate key IDs. + */ +struct autokey { /* network byte order */ + keyid_t key; /* key ID */ + int32 seq; /* key number */ +}; + +/* + * The value structure holds variable length data such as public + * key, agreement parameters, public valule and leapsecond table. + * They are in network byte order. + */ +struct value { /* network byte order */ + tstamp_t tstamp; /* timestamp */ + tstamp_t fstamp; /* filestamp */ + u_int32 vallen; /* value length */ + u_char *ptr; /* data pointer (various) */ + u_int32 siglen; /* signature length */ + u_char *sig; /* signature */ +}; + +/* + * The packet extension field structures are used to hold values + * and signatures in network byte order. + */ +struct exten { + u_int32 opcode; /* opcode */ + u_int32 associd; /* association ID */ + u_int32 tstamp; /* timestamp */ + u_int32 fstamp; /* filestamp */ + u_int32 vallen; /* value length */ + u_int32 pkt[1]; /* start of value field */ +}; + +/* + * The certificate info/value structure + */ +struct cert_info { + struct cert_info *link; /* forward link */ + u_int flags; /* flags that wave */ + EVP_PKEY *pkey; /* generic key */ + long version; /* X509 version */ + int nid; /* signature/digest ID */ + const EVP_MD *digest; /* message digest algorithm */ + u_long serial; /* serial number */ + tstamp_t first; /* valid not before */ + tstamp_t last; /* valid not after */ + char *subject; /* subject common name */ + char *issuer; /* issuer common name */ + u_char *grpkey; /* GQ group key */ + u_int grplen; /* GQ group key length */ + struct value cert; /* certificate/value */ +}; + +/* + * Cryptographic values + */ +extern char *keysdir; /* crypto keys directory */ +extern u_int crypto_flags; /* status word */ +extern struct value hostval; /* host name/value */ +extern struct cert_info *cinfo; /* host certificate information */ +extern struct value tai_leap; /* leapseconds table */ +extern u_int sys_tai; /* current UTC offset from TAI */ +#endif /* OPENSSL */ diff --git a/include/ntp_datum.h b/include/ntp_datum.h new file mode 100644 index 000000000000..2aa2cb742d01 --- /dev/null +++ b/include/ntp_datum.h @@ -0,0 +1,30 @@ +struct btfp_time /* Structure for reading 5 time words */ + /* in one ioctl(2) operation. */ +{ + unsigned short btfp_time[5]; /* Time words 0,1,2,3, and 4. (16bit)*/ +}; + +/***** Simple ioctl commands *****/ + +#define RUNLOCK _IO('X',19) /* Release Capture Lockout */ +#define RCR0 _IOR('X',22,unsigned int) /* Read control register */ +#define WCR0 _IOW('X',23,unsigned int) /* Write control register */ + +/***** Compound ioctl commands *****/ + +/* Read all 5 time words in one call. */ +#define READTIME _IOR('X',32,struct btfp_time) +#define VMEFD "/dev/btfp0" + + struct vmedate { /* structure returned by get_vmetime.c */ + unsigned short year; + unsigned short doy; + unsigned short hr; + unsigned short mn; + unsigned short sec; + unsigned long frac; + unsigned short status; + }; + +#define PRIO 120 /* set the realtime priority */ +#define NREGS 7 /* number of registers we will use */ diff --git a/include/ntp_filegen.h b/include/ntp_filegen.h new file mode 100644 index 000000000000..8217dbc11670 --- /dev/null +++ b/include/ntp_filegen.h @@ -0,0 +1,51 @@ +/* + * ntp_filegen.h,v 3.9 1996/12/01 16:02:45 kardel Exp + * + * definitions for NTP file generations support + * + * + * Copyright (C) 1992, 1996 by Rainer Pruy + * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany + * + * This code may be modified and used freely + * provided the credits remain intact. + */ + +#include "ntp_types.h" + +/* + * supported file generation types + */ + +#define FILEGEN_NONE 255 /* no generations - use plain file name */ +#define FILEGEN_PID 1 /* one filegen per process incarnation */ +#define FILEGEN_DAY 2 /* one filegen per day */ +#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 */ + +/* + * supported file generation flags + */ + +#define FGEN_FLAG_LINK 0x01 /* make a link to base name */ + +#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 */ + 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; + +extern void filegen_setup P((FILEGEN *, u_long)); +extern void filegen_config P((FILEGEN *, char *, u_int, u_int)); +extern FILEGEN *filegen_get P((char *)); +extern void filegen_register P((const char *, FILEGEN *)); diff --git a/include/ntp_fp.h b/include/ntp_fp.h new file mode 100644 index 000000000000..256bab830a04 --- /dev/null +++ b/include/ntp_fp.h @@ -0,0 +1,376 @@ +/* + * ntp_fp.h - definitions for NTP fixed/floating-point arithmetic + */ + +#ifndef NTP_FP_H +#define NTP_FP_H + +#include <sys/types.h> +#include <sys/socket.h> +#include "ntp_rfc2553.h" +#include <netinet/in.h> + +#include "ntp_types.h" + +/* + * NTP uses two fixed point formats. The first (l_fp) is the "long" + * format and is 64 bits long with the decimal between bits 31 and 32. + * This is used for time stamps in the NTP packet header (in network + * byte order) and for internal computations of offsets (in local host + * byte order). We use the same structure for both signed and unsigned + * values, which is a big hack but saves rewriting all the operators + * twice. Just to confuse this, we also sometimes just carry the + * fractional part in calculations, in both signed and unsigned forms. + * Anyway, an l_fp looks like: + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Integral Part | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Fractional Part | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + */ +typedef struct { + union { + u_int32 Xl_ui; + int32 Xl_i; + } Ul_i; + union { + u_int32 Xl_uf; + int32 Xl_f; + } Ul_f; +} 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 + * bits in a long. + */ +#define FRACTION_PREC (32) + + +/* + * The second fixed point format is 32 bits, with the decimal between + * bits 15 and 16. There is a signed version (s_fp) and an unsigned + * version (u_fp). This is used to represent synchronizing distance + * and synchronizing dispersion in the NTP packet header (again, in + * network byte order) and internally to hold both distance and + * dispersion values (in local byte order). In network byte order + * it looks like: + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Integer Part | Fraction Part | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + */ +typedef int32 s_fp; +typedef u_int32 u_fp; + +/* + * A unit second in fp format. Actually 2**(half_the_bits_in_a_long) + */ +#define FP_SECOND (0x10000) + +/* + * 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) = ntohl(hi); (nf) = ntohl(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) + +/* + * Conversions between the two fixed point types + */ +#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 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) + +/* + * Primitive operations on long fixed point values. If these are + * reminiscent of assembler op codes it's only because some may + * be replaced by inline assembler for particular machines someday. + * These are the (kind of inefficient) run-anywhere versions. + */ +#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) + +#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) + +#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) + +#define M_ADD3(r_ovr, r_i, r_f, a_ovr, 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) + +#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) + +#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) + +#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) + +#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) + +#define M_LSHIFT3(v_ovr, 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) + +#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 */ + +#define M_SUBUF(r_i, r_f, uf) /* r -= uf, uf is u_int32 fraction */ \ + M_SUB((r_i), (r_f), 0, (uf)) /* let optimizer worry about it */ + +#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));\ + } while(0) + +#define M_ISNEG(v_i, v_f) /* v < 0 */ \ + (((v_i) & 0x80000000) != 0) + +#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)))) + +#define M_ISEQU(a_i, a_f, b_i, b_f) /* a == b unsigned */ \ + ((a_i) == (b_i) && (a_f) == (b_f)) + +/* + * Operations on the long fp format + */ +#define L_ADD(r, a) M_ADD((r)->l_ui, (r)->l_uf, (a)->l_ui, (a)->l_uf) +#define L_SUB(r, a) M_SUB((r)->l_ui, (r)->l_uf, (a)->l_ui, (a)->l_uf) +#define L_NEG(v) M_NEG((v)->l_ui, (v)->l_uf) +#define L_ADDUF(r, uf) M_ADDUF((r)->l_ui, (r)->l_uf, (uf)) +#define L_SUBUF(r, uf) M_SUBUF((r)->l_ui, (r)->l_uf, (uf)) +#define L_ADDF(r, f) M_ADDF((r)->l_ui, (r)->l_uf, (f)) +#define L_RSHIFT(v) M_RSHIFT((v)->l_i, (v)->l_uf) +#define L_RSHIFTU(v) M_RSHIFT((v)->l_ui, (v)->l_uf) +#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_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 DTOFP(r) ((s_fp)((r) * FRIC)) +#define DTOUFP(r) ((u_fp)((r) * FRIC)) +#define FPTOD(r) ((double)(r) / FRIC) + +/* + * l_fp/double conversions + */ +#define FRAC 4294967296. /* 2^32 as a double */ +#define M_DTOLFP(d, r_i, 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)); \ + } else { \ + (r_i) = (int32)(d_tmp); \ + (r_uf) = (u_int32)(((d_tmp) - (double)(r_i)) * FRAC); \ + } \ + } while (0) +#define M_LFPTOD(r_i, 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); \ + } else { \ + (d) = (double)l_tmp.l_i + ((double)l_tmp.l_uf) / 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)) + +/* + * Prototypes + */ +extern char * dofptoa P((u_fp, int, short, int)); +extern char * dolfptoa P((u_long, u_long, int, short, int)); + +extern int atolfp P((const char *, l_fp *)); +extern int buftvtots P((const char *, l_fp *)); +extern char * fptoa P((s_fp, short)); +extern char * fptoms P((s_fp, short)); +extern int hextolfp P((const char *, l_fp *)); +extern void gpstolfp P((int, int, unsigned long, l_fp *)); +extern int mstolfp P((const char *, l_fp *)); +extern char * prettydate P((l_fp *)); +extern char * gmprettydate P((l_fp *)); +extern char * uglydate P((l_fp *)); +extern void mfp_mul P((int32 *, u_int32 *, int32, u_int32, int32, u_int32)); + +extern void get_systime P((l_fp *)); +extern int step_systime P((double)); +extern int adj_systime P((double)); + +#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(_sin) socktoa((_sin)) +#define stohost(_sin) socktohost((_sin)) + +#define ntoa(_sin) stoa(_sin) +#define ntohost(_sin) stohost(_sin) + +#define ufptoa(_fpv, _ndec) dofptoa((_fpv), 0, (_ndec), 0) +#define ufptoms(_fpv, _ndec) dofptoa((_fpv), 0, (_ndec), 1) +#define ulfptoa(_fpv, _ndec) dolfptoa((_fpv)->l_ui, (_fpv)->l_uf, 0, (_ndec), 0) +#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) + +#endif /* NTP_FP_H */ diff --git a/include/ntp_if.h b/include/ntp_if.h new file mode 100644 index 000000000000..3af5865ffae2 --- /dev/null +++ b/include/ntp_if.h @@ -0,0 +1,27 @@ +/* + * Sockets are not standard. + * So hide uglyness in include file. + */ +/* was: defined(SYS_CONVEXOS9) */ +#if defined(HAVE__SYS_SYNC_QUEUE_H) && defined(HAVE__SYS_SYNC_SEMA_H) +# include "/sys/sync/queue.h" +# include "/sys/sync/sema.h" +#endif + +/* was: (defined(SYS_SOLARIS) && !defined(bsd)) || defined(SYS_SUNOS4) */ +/* was: defined(SYS_UNIXWARE1) */ +#ifdef HAVE_SYS_SOCKIO_H +# include <sys/sockio.h> +#endif + +/* was: #if defined(SYS_PTX) || defined(SYS_SINIXM) */ +#ifdef HAVE_SYS_STREAM_H +# include <sys/stream.h> +#endif +#ifdef HAVE_SYS_STROPTS_H +# include <sys/stropts.h> +#endif + +#ifdef HAVE_NET_IF_H +# include <net/if.h> +#endif /* HAVE_NET_IF_H */ diff --git a/include/ntp_io.h b/include/ntp_io.h new file mode 100644 index 000000000000..983c6c7dce85 --- /dev/null +++ b/include/ntp_io.h @@ -0,0 +1,50 @@ +#if !defined _NTP_IO_H +#define _NTP_IO_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 + +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif +#include <stdio.h> +#ifdef HAVE_SYS_FILE_H +# include <sys/file.h> +#endif +#ifdef HAVE_FCNTL_H +# include <fcntl.h> +#endif +#if !defined(SEEK_SET) && defined(L_SET) +# define SEEK_SET L_SET +#endif + +#ifdef SYS_WINNT +# include <io.h> +# include "win32_io.h" +#endif + +/* + * 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 + * others as well... + */ +#ifndef FNDELAY +# ifdef O_NONBLOCK +# define FNDELAY O_NONBLOCK +# endif +#endif + +#ifndef FASYNC +# ifdef O_ASYNC +# define FASYNC O_ASYNC +# endif +#endif + +#endif diff --git a/include/ntp_machine.h b/include/ntp_machine.h new file mode 100644 index 000000000000..65ef5be88e3d --- /dev/null +++ b/include/ntp_machine.h @@ -0,0 +1,596 @@ +/* + * Collect all machine dependent idiosyncrasies in one place. + */ + +#ifndef __ntp_machine +#define __ntp_machine + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#ifdef TIME_WITH_SYS_TIME +# include <sys/time.h> +# include <time.h> +#else +# ifdef HAVE_SYS_TIME_H +# include <sys/time.h> +# else +# include <time.h> +# endif +#endif + +#include "ntp_proto.h" + +/* + + 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. + + If you find a hunk of code that is bracketed by a SYS_* macro and you + *know* that it is still needed, please let us know. In many cases the + code fragment is now handled somewhere else by autoconf choices. + +*/ + +/* + +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 + streams. For these systems, you must use send the SIOCGIFCONF down + the stream in an I_STR ioctl. This ususally also implies + USE_STREAMS_DEVICE FOR IF_CONFIG. Dell UNIX is a notable exception. + + STREAMS_TLI - use ioctl(I_STR) to implement ioctl(SIOCGIFCONF) + +WHAT DOES IOCTL(SIOCGIFCONF) RETURN IN THE BUFFER + + UNIX V.4 machines implement a sockets library on top of streams. + When requesting the IP interface configuration with an ioctl(2) calll, + an array of ifreq structures are placed in the provided buffer. Some + implementations also place the length of the buffer information in + the first integer position of the buffer. + + SIZE_RETURNED_IN_BUFFER - size integer is in the buffer + +WILL IOCTL(SIOCGIFCONF) WORK ON A SOCKET + + Some UNIX V.4 machines do not appear to support ioctl() requests for the + IP interface configuration on a socket. They appear to require the use + of the streams device instead. + + USE_STREAMS_DEVICE_FOR_IF_CONFIG - use the /dev/ip device for configuration + +MISC + + HAVE_PROTOTYPES - Prototype functions + DOSYNCTODR - Resync TODR clock every hour. + RETSIGTYPE - Define signal function type. + NO_SIGNED_CHAR_DECL - No "signed char" see include/ntp.h + LOCK_PROCESS - Have plock. + UDP_WILDCARD_DELIVERY + - these systems deliver broadcast packets to the wildcard + port instead to a port bound to the interface bound + to the correct broadcast address - are these + implementations broken or did the spec change ? +*/ + +/* + * Set up for prototyping (duplicated from ntp_types.h) + */ +#ifndef P +#if defined(__STDC__) || defined(HAVE_PROTOTYPES) +#define P(x) x +#else /* not __STDC__ and not HAVE_PROTOTYPES */ +#define P(x) () +#endif /* not __STDC__ and not HAVE_PROTOTYPES */ +#endif /* P */ + +#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 +# define SOCKET int +# define INVALID_SOCKET -1 +# define closesocket close +#endif +/* + * Windows NT + */ +#if defined(SYS_WINNT) +# if !defined(HAVE_CONFIG_H) || !defined(__config) +# include <config.h> +# endif /* HAVE_CONFIG_H) */ +# include <windows.h> +# include <ws2tcpip.h> +# include <winsock2.h> + +# define ifreq _INTERFACE_INFO +# define ifr_flags iiFlags +# define ifr_addr iiAddress.AddressIn +# define ifr_broadaddr iiBroadcastAddress.AddressIn +# define ifr_mask iiNetmask.AddressIn +# define zz_family sin_family + +# define S_IFREG _S_IFREG +# define stat _stat +# define isascii __isascii +# define isatty _isatty +# define mktemp _mktemp +# define unlink _unlink +# define fileno _fileno +# define write _write +# define vsnprintf _vsnprintf +# define snprintf _snprintf +#ifndef close +# define close _close +#endif +# undef interface +# include <process.h> +#define getpid _getpid +/* + * Defining registers are not a good idea on Windows + * This gets rid of the usage + */ +#ifndef register +# define register +#endif + typedef char *caddr_t; +# define vsnprintf _vsnprintf +#endif /* SYS_WINNT */ + +int ntp_set_tod P((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 + +/* casey's new defines */ +#define NO_MAIN_ALLOWED 1 +#define NO_NETDB 1 +#define NO_RENAME 1 + +/* in vxWorks we use FIONBIO, but the others are defined for old systems, so + * all hell breaks loose if we leave them defined we define USE_FIONBIO to + * undefine O_NONBLOCK FNDELAY O_NDELAY where necessary. + */ +#define USE_FIONBIO 1 +/* end my new defines */ + +#define TIMEOFDAY 0x0 /* system wide realtime clock */ +#define HAVE_GETCLOCK 1 /* configure does not set this ... */ +#define HAVE_NO_NICE 1 /* configure does not set this ... */ +#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 + */ + +#include "vxWorks.h" +#include "ioLib.h" +#include "taskLib.h" +#include "time.h" + +extern int sysClkRateGet P(()); + +/* usrtime.h + * Bob Herlien's excellent time code find it at: + * ftp://ftp.atd.ucar.edu/pub/vxworks/vx/usrTime.shar + * I would recommend this instead of clock_[g|s]ettime() plus you get + * adjtime() too ... casey + */ +/* +extern int gettimeofday P(( struct timeval *tp, struct timezone *tzp )); +extern int settimeofday P((struct timeval *, struct timezone *)); +extern int adjtime P(( struct timeval *delta, struct timeval *olddelta )); + */ + +/* in machines.c */ +extern void sleep P((int seconds)); +extern void alarm P((int seconds)); +/* machines.c */ + + +/* this is really this */ +#define getpid taskIdSelf +#define getclock clock_gettime +#define fcntl ioctl +#define _getch getchar +#define random rand +#define srandom srand + +/* define this away for vxWorks */ +#define openlog(x,y) +/* use local defines for these */ +#undef min +#undef max + +#endif /* SYS_VXWORKS */ + +#ifdef NO_NETDB +/* These structures are needed for gethostbyname() etc... */ +/* structures used by netdb.h */ +struct hostent { + char *h_name; /* official name of host */ + char **h_aliases; /* alias list */ + int h_addrtype; /* host address type */ + int h_length; /* length of address */ + char **h_addr_list; /* list of addresses from name server */ +#define h_addr h_addr_list[0] /* address, for backward compatibility */ +}; + +struct servent { + char *s_name; /* official service name */ + char **s_aliases; /* alias list */ + int s_port; /* port # */ + char *s_proto; /* protocol to use */ +}; +extern int h_errno; + +#define TRY_AGAIN 2 + +struct hostent *gethostbyname P((char * netnum)); +struct hostent *gethostbyaddr P((char * netnum, int size, int addr_type)); +/* type is the protocol */ +struct servent *getservbyname P((char *name, char *type)); +#endif /* NO_NETDB */ + +#ifdef NO_MAIN_ALLOWED +/* we have no main routines so lets make a plan */ +#define CALL(callname, progname, callmain) \ + extern int callmain (int,char**); \ + void callname (a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \ + char *a0; \ + char *a1; \ + char *a2; \ + char *a3; \ + char *a4; \ + char *a5; \ + char *a6; \ + char *a7; \ + char *a8; \ + char *a9; \ + char *a10; \ + { \ + char *x[11]; \ + int argc; \ + char *argv[] = {progname,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; \ + int i; \ + for (i=0;i<11;i++) \ + x[i] = NULL; \ + x[0] = a0; \ + x[1] = a1; \ + x[2] = a2; \ + x[3] = a3; \ + x[4] = a4; \ + x[5] = a5; \ + x[6] = a6; \ + x[7] = a7; \ + x[8] = a8; \ + x[9] = a9; \ + x[10] = a10; \ + argc=1; \ + for (i=0; i<11;i++) \ + if (x[i]) \ + { \ + argv[argc++] = x[i]; \ + } \ + callmain(argc,argv); \ + } +#endif /* NO_MAIN_ALLOWED */ +/*casey Tue May 27 15:45:25 SAT 1997*/ + +/* + * Here's where autoconfig starts to take over + */ +#ifdef HAVE_SYS_STROPTS_H +# ifdef HAVE_SYS_STREAM_H +# define STREAM +# endif +#endif + +#ifndef RETSIGTYPE +# if defined(NTP_POSIX_SOURCE) +# define RETSIGTYPE void +# else +# define RETSIGTYPE int +# endif +#endif + +#ifdef NTP_SYSCALLS_STD +# ifndef NTP_SYSCALL_GET +# define NTP_SYSCALL_GET 235 +# endif +# ifndef NTP_SYSCALL_ADJ +# define NTP_SYSCALL_ADJ 236 +# endif +#endif /* NTP_SYSCALLS_STD */ + +#ifdef MPE +# include <sys/types.h> +# include <netinet/in.h> +# include <stdio.h> +# include <time.h> + +/* missing functions that are easily renamed */ + +# define _getch getchar + +/* special functions that require MPE-specific wrappers */ + +# define bind __ntp_mpe_bind +# define fcntl __ntp_mpe_fcntl + +/* standard macros missing from MPE include files */ + +# 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 */ + +struct itimerval { + struct timeval it_interval; /* timer interval */ + struct timeval it_value; /* current value */ +}; + +/* various declarations to make gcc stop complaining */ + +extern int __filbuf(FILE *); +extern int __flsbuf(int, FILE *); +extern int gethostname(char *, int); +extern unsigned long inet_addr(char *); +extern char *strdup(const char *); + +/* miscellaneous NTP macros */ + +# define HAVE_NO_NICE +#endif /* MPE */ + +#ifdef HAVE_RTPRIO +# define HAVE_NO_NICE +#else +# ifdef HAVE_SETPRIORITY +# define HAVE_BSD_NICE +# else +# ifdef HAVE_NICE +# define HAVE_ATT_NICE +# endif +# endif +#endif + +#if !defined(HAVE_ATT_NICE) \ + && !defined(HAVE_BSD_NICE) \ + && !defined(HAVE_NO_NICE) \ + && !defined(SYS_WINNT) +#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 P((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 */ diff --git a/include/ntp_malloc.h b/include/ntp_malloc.h new file mode 100644 index 000000000000..099c83effe90 --- /dev/null +++ b/include/ntp_malloc.h @@ -0,0 +1,19 @@ +/* + * Define malloc and friends. + */ +#ifndef _ntp_malloc_h +#define _ntp_malloc_h + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#ifdef HAVE_STDLIB_H +# include <stdlib.h> +#else /* HAVE_STDLIB_H */ +# ifdef HAVE_MALLOC_H +# include <malloc.h> +# endif +#endif /* HAVE_STDLIB_H */ + +#endif /* _ntp_malloc_h */ diff --git a/include/ntp_md5.h b/include/ntp_md5.h new file mode 100644 index 000000000000..bb6985a2f367 --- /dev/null +++ b/include/ntp_md5.h @@ -0,0 +1,9 @@ +/* + * ntp_md5.h: deal with md5.h headers + */ + +#ifdef HAVE_MD5_H +# include <md5.h> +#else +# include "rsa_md5.h" +#endif diff --git a/include/ntp_proto.h b/include/ntp_proto.h new file mode 100644 index 000000000000..e6e78553305b --- /dev/null +++ b/include/ntp_proto.h @@ -0,0 +1,10 @@ +#ifndef __ntp_proto_h +#define __ntp_proto_h + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#define NTP_MAXFREQ 500e-6 + +#endif /* __ntp_proto_h */ diff --git a/include/ntp_refclock.h b/include/ntp_refclock.h new file mode 100644 index 000000000000..5e33a8ce25a1 --- /dev/null +++ b/include/ntp_refclock.h @@ -0,0 +1,267 @@ +/* + * ntp_refclock.h - definitions for reference clock support + */ + +#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 "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); \ + if (pp->coderecv == pp->codeproc) \ + pp->codeproc = (pp->codeproc + 1) % MAXSTAGE; + +/* + * Macros to determine the clock type and unit numbers from a + * 127.127.t.u address + */ +#define REFCLOCKTYPE(srcadr) ((SRCADR(srcadr) >> 8) & 0xff) +#define REFCLOCKUNIT(srcadr) (SRCADR(srcadr) & 0xff) + +/* + * List of reference clock names and descriptions. These must agree with + * lib/clocktypes.c and ntpd/refclock_conf.c. + */ +struct clktype { + int code; /* driver "major" number */ + const char *clocktype; /* long description */ + const char *abbrev; /* short description */ +}; + +/* + * Configuration flag values + */ +#define CLK_HAVETIME1 0x1 +#define CLK_HAVETIME2 0x2 +#define CLK_HAVEVAL1 0x4 +#define CLK_HAVEVAL2 0x8 + +#define CLK_FLAG1 0x1 +#define CLK_FLAG2 0x2 +#define CLK_FLAG3 0x4 +#define CLK_FLAG4 0x8 + +#define CLK_HAVEFLAG1 0x10 +#define CLK_HAVEFLAG2 0x20 +#define CLK_HAVEFLAG3 0x40 +#define CLK_HAVEFLAG4 0x80 + +/* + * Constant for disabling event reporting in + * refclock_receive. ORed in leap + * parameter + */ +#define REFCLOCK_OWN_STATES 0x80 + +/* + * Structure for returning clock status + */ +struct refclockstat { + u_char type; /* clock type */ + u_char flags; /* clock flags */ + u_char haveflags; /* bit array of valid flags */ + u_short lencode; /* length of last timecode */ + const char *p_lastcode; /* last timecode received */ + u_int32 polls; /* transmit polls */ + u_int32 noresponse; /* no response to poll */ + u_int32 badformat; /* bad format timecode received */ + u_int32 baddata; /* invalid data timecode received */ + u_int32 timereset; /* driver resets */ + const char *clockdesc; /* ASCII description */ + double fudgetime1; /* configure fudge time1 */ + double fudgetime2; /* configure fudge time2 */ + int32 fudgeval1; /* configure fudge value1 */ + int32 fudgeval2; /* configure fudge value2 */ + u_char currentstatus; /* clock status */ + u_char lastevent; /* last exception event */ + u_char leap; /* leap bits */ + struct ctl_var *kv_list; /* additional variables */ +}; + +/* + * Reference clock I/O structure. Used to provide an interface between + * the reference clock drivers and the I/O module. + */ +struct refclockio { + struct refclockio *next; /* link to next structure */ + void (*clock_recv) P((struct recvbuf *)); /* completion routine */ + int (*io_input) P((struct recvbuf *)); /* input routine - + 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 */ + SOCKET fd; /* file descriptor */ + u_long recvcount; /* count of receive completions */ +}; + +/* + * Structure for returning debugging info + */ +#define NCLKBUGVALUES 16 +#define NCLKBUGTIMES 32 + +struct refclockbug { + u_char nvalues; /* values following */ + u_char ntimes; /* times following */ + u_short svalues; /* values format sign array */ + u_int32 stimes; /* times format sign array */ + u_int32 values[NCLKBUGVALUES]; /* real values */ + l_fp times[NCLKBUGTIMES]; /* real times */ +}; + +/* + * Structure interface between the reference clock support + * ntp_refclock.c and the driver utility routines + */ +#define MAXSTAGE 60 /* max median filter stages */ +#define NSTAGE 5 /* default median filter stages */ +#define BMAX 128 /* max timecode length */ +#define GMT 0 /* I hope nobody sees this */ +#define MAXDIAL 60 /* max length of modem dial strings */ + +/* + * 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 0x0 /* standard */ +#define LDISC_CLK 0x1 /* tty_clk \n intercept */ +#define LDISC_CLKPPS 0x2 /* tty_clk \377 intercept */ +#define LDISC_ACTS 0x4 /* tty_clk #* intercept */ +#define LDISC_CHU 0x8 /* depredated */ +#define LDISC_PPS 0x10 /* ppsclock, ppsapi */ +#define LDISC_RAW 0x20 /* raw binary */ + +struct refclockproc { + struct refclockio io; /* I/O handler structure */ + caddr_t unitptr; /* pointer to unit 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 */ + + char a_lastcode[BMAX]; /* last timecode received */ + u_short lencode; /* length of last timecode */ + + int year; /* year of eternity */ + int day; /* day of year */ + int hour; /* hour of day */ + int minute; /* minute of hour */ + int second; /* second of minute */ + long nsec; /* nanosecond of second */ + u_long yearstart; /* beginning of year */ + int coderecv; /* put pointer */ + int codeproc; /* get pointer */ + l_fp lastref; /* reference timestamp */ + l_fp lastrec; /* receive timestamp */ + double offset; /* mean offset */ + double disp; /* sample dispersion */ + double jitter; /* jitter (mean squares) */ + double filter[MAXSTAGE]; /* median filter */ + + /* + * Configuration data + */ + double fudgetime1; /* fudge time1 */ + double fudgetime2; /* fudge time2 */ + u_char stratum; /* server stratum */ + u_int32 refid; /* reference identifier */ + u_char sloppyclockflag; /* fudge flags */ + + /* + * Status tallies + */ + u_long timestarted; /* time we started this */ + u_long polls; /* polls sent */ + u_long noreply; /* no replies to polls */ + u_long badformat; /* bad format reply */ + u_long baddata; /* bad data reply */ +}; + +/* + * Structure interface between the reference clock support + * ntp_refclock.c and particular clock drivers. This must agree with the + * structure defined in the driver. + */ +#define noentry 0 /* flag for null routine */ +#define NOFLAGS 0 /* flag for null flags */ + +struct refclock { + int (*clock_start) P((int, struct peer *)); + void (*clock_shutdown) P((int, struct peer *)); + void (*clock_poll) P((int, struct peer *)); + void (*clock_control) P((int, struct refclockstat *, + struct refclockstat *, struct peer *)); + void (*clock_init) P((void)); + void (*clock_buginfo) P((int, struct refclockbug *, struct peer *)); + u_long clock_flags; +}; + +/* + * Function prototypes + */ +/* + * auxiliary PPS interface (implemented by refclock_atom()) + */ +extern int pps_sample P((l_fp *)); +extern int io_addclock_simple P((struct refclockio *)); +extern int io_addclock P((struct refclockio *)); +extern void io_closeclock P((struct refclockio *)); + +#ifdef REFCLOCK +extern void refclock_buginfo P((struct sockaddr_storage *, + struct refclockbug *)); +extern void refclock_control P((struct sockaddr_storage *, + struct refclockstat *, + struct refclockstat *)); +extern int refclock_open P((char *, int, int)); +extern void refclock_transmit P((struct peer *)); +extern int refclock_ioctl P((int, int)); +extern int refclock_process P((struct refclockproc *)); +extern void refclock_process_offset P((struct refclockproc *, l_fp, l_fp, double)); +extern void refclock_report P((struct peer *, int)); +extern int refclock_gtlin P((struct recvbuf *, char *, int, + l_fp *)); +#endif /* REFCLOCK */ + +#endif /* NTP_REFCLOCK_H */ diff --git a/include/ntp_request.h b/include/ntp_request.h new file mode 100644 index 000000000000..8166a4df2c5f --- /dev/null +++ b/include/ntp_request.h @@ -0,0 +1,884 @@ +/* + * ntp_request.h - definitions for the ntpd remote query facility + */ + +#ifndef _NTP_REQUEST_H +#define _NTP_REQUEST_H + +#include "ntp_types.h" + +/* + * A mode 7 packet is used exchanging data between an NTP server + * and a client for purposes other than time synchronization, e.g. + * monitoring, statistics gathering and configuration. A mode 7 + * packet has the following format: + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |R|M| VN | Mode|A| Sequence | Implementation| Req Code | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Err | Number of data items | MBZ | Size of data item | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | + * | Data (Minimum 0 octets, maximum 500 octets) | + * | | + * [...] + * | | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Encryption Keyid (when A bit set) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | + * | Message Authentication Code (when A bit set) | + * | | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * where the fields are (note that the client sends requests, the server + * responses): + * + * Response Bit: This packet is a response (if clear, packet is a request). + * + * More Bit: Set for all packets but the last in a response which + * requires more than one packet. + * + * Version Number: 2 for current version + * + * Mode: Always 7 + * + * Authenticated bit: If set, this packet is authenticated. + * + * Sequence number: For a multipacket response, contains the sequence + * number of this packet. 0 is the first in the sequence, + * 127 (or less) is the last. The More Bit must be set in + * all packets but the last. + * + * Implementation number: The number of the implementation this request code + * is defined by. An implementation number of zero is used + * for requst codes/data formats which all implementations + * agree on. Implementation number 255 is reserved (for + * extensions, in case we run out). + * + * Request code: An implementation-specific code which specifies the + * operation to be (which has been) performed and/or the + * format and semantics of the data included in the packet. + * + * Err: Must be 0 for a request. For a response, holds an error + * code relating to the request. If nonzero, the operation + * requested wasn't performed. + * + * 0 - no error + * 1 - incompatable 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) + * 5-6 I don't know + * 7 - authentication failure (i.e. permission denied) + * + * Number of data items: number of data items in packet. 0 to 500 + * + * MBZ: A reserved data field, must be zero in requests and responses. + * + * Size of data item: size of each data item in packet. 0 to 500 + * + * Data: Variable sized area containing request/response data. For + * requests and responses the size in octets must be greater + * than or equal to the product of the number of data items + * and the size of a data item. For requests the data area + * must be exactly 40 octets in length. For responses the + * data area may be any length between 0 and 500 octets + * inclusive. + * + * Message Authentication Code: Same as NTP spec, in definition and function. + * May optionally be included in requests which require + * authentication, is never included in responses. + * + * The version number, mode and keyid have the same function and are + * in the same location as a standard NTP packet. The request packet + * is the same size as a standard NTP packet to ease receive buffer + * management, and to allow the same encryption procedure to be used + * both on mode 7 and standard NTP packets. The mac is included when + * it is required that a request be authenticated, the keyid should be + * zero in requests in which the mac is not included. + * + * The data format depends on the implementation number/request code pair + * and whether the packet is a request or a response. The only requirement + * is that data items start in the octet immediately following the size + * word and that data items be concatenated without padding between (i.e. + * if the data area is larger than data_items*size, all padding is at + * the end). Padding is ignored, other than for encryption purposes. + * Implementations using encryption might want to include a time stamp + * or other data in the request packet padding. The key used for requests + * is implementation defined, but key 15 is suggested as a default. + */ + +/* + * A request packet. These are almost a fixed length. + */ +struct req_pkt { + u_char rm_vn_mode; /* response, more, version, mode */ + u_char auth_seq; /* key, sequence number */ + u_char implementation; /* implementation number */ + 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 */ + l_fp tstamp; /* time stamp, for authentication */ + keyid_t keyid; /* encryption key */ + char mac[MAX_MAC_LEN-sizeof(u_int32)]; /* (optional) 8 byte auth code */ +}; + +/* + * The req_pkt_tail structure is used by ntpd to adjust for different + * packet sizes that may arrive. + */ +struct req_pkt_tail { + l_fp tstamp; /* time stamp, for authentication */ + keyid_t keyid; /* encryption key */ + char mac[MAX_MAC_LEN-sizeof(u_int32)]; /* (optional) 8 byte auth code */ +}; + +/* + * Input packet lengths. One with the mac, one without. + */ +#define REQ_LEN_HDR 8 /* 4 * u_char + 2 * u_short */ +#define REQ_LEN_MAC (sizeof(struct req_pkt)) +#define REQ_LEN_NOMAC (sizeof(struct req_pkt) - MAX_MAC_LEN) + +/* + * A response packet. The length here is variable, this is a + * maximally sized one. Note that this implementation doesn't + * authenticate responses. + */ +#define RESP_HEADER_SIZE (8) +#define RESP_DATA_SIZE (500) + +struct resp_pkt { + u_char rm_vn_mode; /* response, more, version, mode */ + u_char auth_seq; /* key, sequence number */ + u_char implementation; /* implementation number */ + 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 */ +}; + + +/* + * Information error codes + */ +#define INFO_OKAY 0 +#define INFO_ERR_IMPL 1 /* incompatable 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 */ + +/* + * Maximum sequence number. + */ +#define MAXSEQ 127 + + +/* + * Bit setting macros for multifield items. + */ +#define RESP_BIT 0x80 +#define MORE_BIT 0x40 + +#define ISRESPONSE(rm_vn_mode) (((rm_vn_mode)&RESP_BIT)!=0) +#define ISMORE(rm_vn_mode) (((rm_vn_mode)&MORE_BIT)!=0) +#define INFO_VERSION(rm_vn_mode) ((u_char)(((rm_vn_mode)>>3)&0x7)) +#define INFO_MODE(rm_vn_mode) ((rm_vn_mode)&0x7) + +#define RM_VN_MODE(resp, more, version) \ + ((u_char)(((resp)?RESP_BIT:0)\ + |((more)?MORE_BIT:0)\ + |((version?version:(NTP_OLDVERSION+1))<<3)\ + |(MODE_PRIVATE))) + +#define INFO_IS_AUTH(auth_seq) (((auth_seq) & 0x80) != 0) +#define INFO_SEQ(auth_seq) ((auth_seq)&0x7f) +#define AUTH_SEQ(auth, seq) ((u_char)((((auth)!=0)?0x80:0)|((seq)&0x7f))) + +#define INFO_ERR(err_nitems) ((u_short)((ntohs(err_nitems)>>12)&0xf)) +#define INFO_NITEMS(err_nitems) ((u_short)(ntohs(err_nitems)&0xfff)) +#define ERR_NITEMS(err, nitems) (htons((u_short)((((u_short)(err)<<12)&0xf000)\ + |((u_short)(nitems)&0xfff)))) + +#define INFO_MBZ(mbz_itemsize) ((ntohs(mbz_itemsize)>>12)&0xf) +#define INFO_ITEMSIZE(mbz_itemsize) ((u_short)(ntohs(mbz_itemsize)&0xfff)) +#define MBZ_ITEMSIZE(itemsize) (htons((u_short)(itemsize))) + + +/* + * Implementation numbers. One for universal use and one for ntpd. + */ +#define IMPL_UNIV 0 +#define IMPL_XNTPD_OLD 2 /* Used by pre ipv6 ntpdc */ +#define IMPL_XNTPD 3 /* Used by post ipv6 ntpdc */ + +/* + * Some limits related to authentication. Frames which are + * authenticated must include a time stamp which differs from + * the receive time stamp by no more than 10 seconds. + */ +#define INFO_TS_MAXSKEW 10. + +/* + * Universal request codes go here. There aren't any. + */ + +/* + * 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 */ +#define REQ_PEER_INFO 2 /* get standard information on peer */ +#define REQ_PEER_STATS 3 /* get statistics for peer */ +#define REQ_SYS_INFO 4 /* get system information */ +#define REQ_SYS_STATS 5 /* get system stats */ +#define REQ_IO_STATS 6 /* get I/O stats */ +#define REQ_MEM_STATS 7 /* stats related to peer list maint */ +#define REQ_LOOP_INFO 8 /* info from the loop filter */ +#define REQ_TIMER_STATS 9 /* get timer stats */ +#define REQ_CONFIG 10 /* configure a new peer */ +#define REQ_UNCONFIG 11 /* unconfigure an existing peer */ +#define REQ_SET_SYS_FLAG 12 /* set system flags */ +#define REQ_CLR_SYS_FLAG 13 /* clear system flags */ +#define REQ_MONITOR 14 /* (not used) */ +#define REQ_NOMONITOR 15 /* (not used) */ +#define REQ_GET_RESTRICT 16 /* return restrict list */ +#define REQ_RESADDFLAGS 17 /* add flags to restrict list */ +#define REQ_RESSUBFLAGS 18 /* remove flags from restrict list */ +#define REQ_UNRESTRICT 19 /* remove entry from restrict list */ +#define REQ_MON_GETLIST 20 /* return data collected by monitor */ +#define REQ_RESET_STATS 21 /* reset stat counters */ +#define REQ_RESET_PEER 22 /* reset peer stat counters */ +#define REQ_REREAD_KEYS 23 /* reread the encryption key file */ +#define REQ_DO_DIRTY_HACK 24 /* (not used) */ +#define REQ_DONT_DIRTY_HACK 25 /* (not used) */ +#define REQ_TRUSTKEY 26 /* add a trusted key */ +#define REQ_UNTRUSTKEY 27 /* remove a trusted key */ +#define REQ_AUTHINFO 28 /* return authentication info */ +#define REQ_TRAPS 29 /* return currently set traps */ +#define REQ_ADD_TRAP 30 /* add a trap */ +#define REQ_CLR_TRAP 31 /* clear a trap */ +#define REQ_REQUEST_KEY 32 /* define a new request keyid */ +#define REQ_CONTROL_KEY 33 /* define a new control keyid */ +#define REQ_GET_CTLSTATS 34 /* get stats from the control module */ +#define REQ_GET_LEAPINFO 35 /* (not used) */ +#define REQ_GET_CLOCKINFO 36 /* get clock information */ +#define REQ_SET_CLKFUDGE 37 /* set clock fudge factors */ +#define REQ_GET_KERNEL 38 /* get kernel pll/pps information */ +#define REQ_GET_CLKBUGINFO 39 /* get clock debugging info */ +#define REQ_SET_PRECISION 41 /* (not used) */ +#define REQ_MON_GETLIST_1 42 /* return collected v1 monitor data */ +#define REQ_HOSTNAME_ASSOCID 43 /* Here is a hostname + assoc_id */ + +/* Determine size of pre-v6 version of structures */ +#define v4sizeof(type) offsetof(type, v6_flag) + +/* + * Flags in the peer information returns + */ +#define INFO_FLAG_CONFIG 0x1 +#define INFO_FLAG_SYSPEER 0x2 +#define INFO_FLAG_BURST 0x4 +#define INFO_FLAG_REFCLOCK 0x8 +#define INFO_FLAG_PREFER 0x10 +#define INFO_FLAG_AUTHENABLE 0x20 +#define INFO_FLAG_SEL_CANDIDATE 0x40 +#define INFO_FLAG_SHORTLIST 0x80 + +/* + * Flags in the system information returns + */ +#define INFO_FLAG_BCLIENT 0x1 +#define INFO_FLAG_AUTHENTICATE 0x2 +#define INFO_FLAG_NTP 0x4 +#define INFO_FLAG_KERNEL 0x8 +#define INFO_FLAG_MONITOR 0x40 +#define INFO_FLAG_FILEGEN 0x80 +#define INFO_FLAG_CAL 0x10 +#define INFO_FLAG_PPS_SYNC 0x20 + +/* + * Peer list structure. Used to return raw lists of peers. It goes + * without saying that everything returned is in network byte order. + * Well, it *would* have gone without saying, but somebody said it. + */ +struct info_peer_list { + u_int32 addr; /* address of peer */ + u_short port; /* port number of peer */ + u_char hmode; /* mode for this peer */ + u_char flags; /* flags (from above) */ + u_int v6_flag; /* is this v6 or not */ + u_int unused1; /* (unused) padding for addr6 */ + struct in6_addr addr6; /* v6 address of peer */ +}; + + +/* + * Peer summary structure. Sort of the info that ntpdc returns by default. + */ +struct info_peer_summary { + u_int32 dstadr; /* local address (zero for undetermined) */ + u_int32 srcadr; /* source address */ + u_short srcport; /* source port */ + u_char stratum; /* stratum of peer */ + s_char hpoll; /* host polling interval */ + s_char ppoll; /* peer polling interval */ + u_char reach; /* reachability register */ + u_char flags; /* flags, from above */ + u_char hmode; /* peer mode */ + s_fp delay; /* peer.estdelay */ + l_fp offset; /* peer.estoffset */ + u_fp dispersion; /* peer.estdisp */ + u_int v6_flag; /* is this v6 or not */ + u_int unused1; /* (unused) padding for dstadr6 */ + struct in6_addr dstadr6; /* local address (v6) */ + struct in6_addr srcadr6; /* source address (v6) */ +}; + + +/* + * Peer information structure. + */ +struct info_peer { + u_int32 dstadr; /* local address */ + u_int32 srcadr; /* source address */ + u_short srcport; /* remote port */ + u_char flags; /* peer flags */ + u_char leap; /* peer.leap */ + u_char hmode; /* peer.hmode */ + u_char pmode; /* peer.pmode */ + u_char stratum; /* peer.stratum */ + u_char ppoll; /* peer.ppoll */ + u_char hpoll; /* peer.hpoll */ + s_char precision; /* peer.precision */ + u_char version; /* peer.version */ + u_char unused8; + u_char reach; /* peer.reach */ + u_char unreach; /* peer.unreach */ + u_char flash; /* old peer.flash */ + u_char ttl; /* peer.ttl */ + u_short flash2; /* new peer.flash */ + associd_t associd; /* association ID */ + keyid_t keyid; /* peer.keyid */ + u_int32 pkeyid; /* unused */ + u_int32 refid; /* peer.refid */ + u_int32 timer; /* peer.timer */ + s_fp rootdelay; /* peer.distance */ + u_fp rootdispersion; /* peer.dispersion */ + l_fp reftime; /* peer.reftime */ + l_fp org; /* peer.org */ + l_fp rec; /* peer.rec */ + l_fp xmt; /* peer.xmt */ + s_fp filtdelay[NTP_SHIFT]; /* delay shift register */ + l_fp filtoffset[NTP_SHIFT]; /* offset shift register */ + u_char order[NTP_SHIFT]; /* order of peers from last filter */ + s_fp delay; /* peer.estdelay */ + u_fp dispersion; /* peer.estdisp */ + l_fp offset; /* peer.estoffset */ + u_fp selectdisp; /* peer select dispersion */ + int32 unused1; /* (obsolete) */ + int32 unused2; + int32 unused3; + int32 unused4; + int32 unused5; + int32 unused6; + int32 unused7; + s_fp estbdelay; /* broadcast offset */ + u_int v6_flag; /* is this v6 or not */ + u_int unused9; /* (unused) padding for dstadr6 */ + struct in6_addr dstadr6; /* local address (v6-like) */ + struct in6_addr srcadr6; /* sources address (v6-like) */ +}; + + +/* + * Peer statistics structure + */ +struct info_peer_stats { + u_int32 dstadr; /* local address */ + u_int32 srcadr; /* remote address */ + u_short srcport; /* remote port */ + u_short flags; /* peer flags */ + u_int32 timereset; /* time counters were reset */ + u_int32 timereceived; /* time since a packet received */ + u_int32 timetosend; /* time until a packet sent */ + u_int32 timereachable; /* time peer has been reachable */ + u_int32 sent; /* number sent */ + u_int32 unused1; /* (unused) */ + u_int32 processed; /* number processed */ + u_int32 unused2; /* (unused) */ + u_int32 badauth; /* bad authentication */ + u_int32 bogusorg; /* bogus origin */ + u_int32 oldpkt; /* duplicate */ + u_int32 unused3; /* (unused) */ + u_int32 unused4; /* (unused) */ + u_int32 seldisp; /* bad dispersion */ + u_int32 selbroken; /* bad reference time */ + u_int32 unused5; /* (unused) */ + u_char candidate; /* select order */ + u_char unused6; /* (unused) */ + u_char unused7; /* (unused) */ + u_char unused8; /* (unused) */ + u_int v6_flag; /* is this v6 or not */ + u_int unused9; /* (unused) padding for dstadr6 */ + struct in6_addr dstadr6; /* local address */ + struct in6_addr srcadr6; /* remote address */ +}; + + +/* + * Loop filter variables + */ +struct info_loop { + l_fp last_offset; + l_fp drift_comp; + u_int32 compliance; + u_int32 watchdog_timer; +}; + + +/* + * System info. Mostly the sys.* variables, plus a few unique to + * the implementation. + */ +struct info_sys { + u_int32 peer; /* system peer address (v4) */ + u_char peer_mode; /* mode we are syncing to peer in */ + u_char leap; /* system leap bits */ + u_char stratum; /* our stratum */ + s_char precision; /* local clock precision */ + s_fp rootdelay; /* distance from sync source */ + u_fp rootdispersion; /* dispersion from sync source */ + u_int32 refid; /* reference ID of sync source */ + l_fp reftime; /* system reference time */ + u_int32 poll; /* system poll interval */ + u_char flags; /* system flags */ + u_char unused1; /* unused */ + u_char unused2; /* unused */ + u_char unused3; /* unused */ + s_fp bdelay; /* default broadcast offset */ + s_fp frequency; /* frequency residual (scaled ppm) */ + l_fp authdelay; /* default authentication delay */ + u_fp stability; /* clock stability (scaled ppm) */ + u_int v6_flag; /* is this v6 or not */ + u_int unused4; /* unused, padding for peer6 */ + struct in6_addr peer6; /* system peer address (v6) */ +}; + + +/* + * System stats. These are collected in the protocol module + */ +struct info_sys_stats { + u_int32 timeup; /* time since restart */ + u_int32 timereset; /* time since reset */ + u_int32 denied; /* access denied */ + u_int32 oldversionpkt; /* recent version */ + u_int32 newversionpkt; /* current version */ + u_int32 unknownversion; /* bad version */ + u_int32 badlength; /* bad length or format */ + u_int32 processed; /* packets processed */ + u_int32 badauth; /* bad authentication */ + u_int32 received; /* packets received */ + u_int32 limitrejected; /* rate exceeded */ +}; + + +/* + * System stats - old version + */ +struct old_info_sys_stats { + u_int32 timeup; /* time since restart */ + u_int32 timereset; /* time since reset */ + u_int32 denied; /* access denied */ + u_int32 oldversionpkt; /* recent version */ + u_int32 newversionpkt; /* current version */ + u_int32 unknownversion; /* bad version */ + u_int32 badlength; /* bad length or format */ + u_int32 processed; /* packets processed */ + u_int32 badauth; /* bad authentication */ + u_int32 wanderhold; /* (not used) */ +}; + + +/* + * Peer memory statistics. Collected in the peer module. + */ +struct info_mem_stats { + u_int32 timereset; /* time since reset */ + u_short totalpeermem; + u_short freepeermem; + u_int32 findpeer_calls; + u_int32 allocations; + u_int32 demobilizations; + u_char hashcount[HASH_SIZE]; +}; + + +/* + * I/O statistics. Collected in the I/O module + */ +struct info_io_stats { + u_int32 timereset; /* time since reset */ + u_short totalrecvbufs; /* total receive bufs */ + u_short freerecvbufs; /* free buffers */ + u_short fullrecvbufs; /* full buffers */ + u_short lowwater; /* number of times we've added buffers */ + u_int32 dropped; /* dropped packets */ + u_int32 ignored; /* ignored packets */ + u_int32 received; /* received packets */ + u_int32 sent; /* packets sent */ + u_int32 notsent; /* packets not sent */ + u_int32 interrupts; /* interrupts we've handled */ + u_int32 int_received; /* received by interrupt handler */ +}; + + +/* + * Timer stats. Guess where from. + */ +struct info_timer_stats { + u_int32 timereset; /* time since reset */ + u_int32 alarms; /* alarms we've handled */ + u_int32 overflows; /* timer overflows */ + u_int32 xmtcalls; /* calls to xmit */ +}; + + +/* + * Structure for passing peer configuration information + */ +struct old_conf_peer { + u_int32 peeraddr; /* address to poll */ + u_char hmode; /* mode, either broadcast, active or client */ + u_char version; /* version number to poll with */ + u_char minpoll; /* min host poll interval */ + u_char maxpoll; /* max host poll interval */ + u_char flags; /* flags for this request */ + u_char ttl; /* time to live (multicast) or refclock mode */ + u_short unused; /* unused */ + keyid_t keyid; /* key to use for this association */ +}; + +struct conf_peer { + u_int32 peeraddr; /* address to poll */ + u_char hmode; /* mode, either broadcast, active or client */ + u_char version; /* version number to poll with */ + u_char minpoll; /* min host poll interval */ + u_char maxpoll; /* max host poll interval */ + u_char flags; /* flags for this request */ + 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*/ + u_int v6_flag; /* is this v6 or not */ + u_int unused2; /* unused, padding for peeraddr6 */ + struct in6_addr peeraddr6; /* ipv6 address to poll */ +}; + +#define CONF_FLAG_AUTHENABLE 0x01 +#define CONF_FLAG_PREFER 0x02 +#define CONF_FLAG_BURST 0x04 +#define CONF_FLAG_IBURST 0x08 +#define CONF_FLAG_NOSELECT 0x10 +#define CONF_FLAG_SKEY 0x20 + +/* + * Structure for passing peer deletion information. Currently + * we only pass the address and delete all configured peers with + * this addess. + */ +struct conf_unpeer { + u_int32 peeraddr; /* address of peer */ + u_int v6_flag; /* is this v6 or not */ + struct in6_addr peeraddr6; /* address of peer (v6) */ +}; + +/* + * Structure for carrying system flags. + */ +struct conf_sys_flags { + u_int32 flags; +}; + +/* + * System flags we can set/clear + */ +#define SYS_FLAG_BCLIENT 0x01 +#define SYS_FLAG_PPS 0x02 +#define SYS_FLAG_NTP 0x04 +#define SYS_FLAG_KERNEL 0x08 +#define SYS_FLAG_MONITOR 0x10 +#define SYS_FLAG_FILEGEN 0x20 +#define SYS_FLAG_AUTH 0x40 +#define SYS_FLAG_CAL 0x80 + +/* + * Structure used for returning restrict entries + */ +struct info_restrict { + u_int32 addr; /* match address */ + u_int32 mask; /* match mask */ + u_int32 count; /* number of packets matched */ + u_short flags; /* restrict flags */ + u_short mflags; /* match flags */ + u_int v6_flag; /* is this v6 or not */ + u_int unused1; /* unused, padding for addr6 */ + struct in6_addr addr6; /* match address (v6) */ + struct in6_addr mask6; /* match mask (v6) */ +}; + + +/* + * Structure used for specifying restrict entries + */ +struct conf_restrict { + u_int32 addr; /* match address */ + u_int32 mask; /* match mask */ + u_short flags; /* restrict flags */ + u_short mflags; /* match flags */ + u_int v6_flag; /* is this v6 or not */ + struct in6_addr addr6; /* match address (v6) */ + struct in6_addr mask6; /* match mask (v6) */ +}; + + +/* + * 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 lastdrop; /* last time we rejected a packet due to client limitation policy */ + u_int32 count; /* count of packets received */ + u_int32 addr; /* host address V4 style */ + u_int32 daddr; /* destination host address */ + u_int32 flags; /* flags about destination */ + u_short port; /* port number of last reception */ + u_char mode; /* mode of last packet */ + u_char version; /* version number of last packet */ + u_int v6_flag; /* is this v6 or not */ + u_int unused1; /* unused, padding for addr6 */ + struct in6_addr addr6; /* host address V6 style */ + struct in6_addr daddr6; /* host address V6 style */ +}; + + +/* + * 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 lastdrop; /* last time we rejected a packet due to client limitation policy */ + u_int32 count; /* count of packets received */ + u_int32 addr; /* host address */ + u_short port; /* port number of last reception */ + u_char mode; /* mode of last packet */ + u_char version; /* version number of last packet */ + u_int v6_flag; /* is this v6 or not */ + u_int unused1; /* unused, padding for addr6 */ + struct in6_addr addr6; /* host v6 address */ +}; + +/* + * Structure used for returning monitor data (old format + */ +struct old_info_monitor { + u_int32 lasttime; /* last packet from this host */ + u_int32 firsttime; /* first time we received a packet */ + u_int32 count; /* count of packets received */ + u_int32 addr; /* host address */ + u_short port; /* port number of last reception */ + u_char mode; /* mode of last packet */ + u_char version; /* version number of last packet */ + u_int v6_flag; /* is this v6 or not */ + struct in6_addr addr6; /* host address (v6)*/ +}; + +/* + * Structure used for passing indication of flags to clear + */ +struct reset_flags { + u_int32 flags; +}; + +#define RESET_FLAG_ALLPEERS 0x01 +#define RESET_FLAG_IO 0x02 +#define RESET_FLAG_SYS 0x04 +#define RESET_FLAG_MEM 0x08 +#define RESET_FLAG_TIMER 0x10 +#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) + +/* + * Structure used to return information concerning the authentication + * module. + */ +struct info_auth { + u_int32 timereset; /* time counters were reset */ + u_int32 numkeys; /* number of keys we know */ + u_int32 numfreekeys; /* number of free keys */ + u_int32 keylookups; /* calls to authhavekey() */ + u_int32 keynotfound; /* requested key unknown */ + u_int32 encryptions; /* number of encryptions */ + u_int32 decryptions; /* number of decryptions */ + u_int32 expired; /* number of expired keys */ + u_int32 keyuncached; /* calls to encrypt/decrypt with uncached key */ +}; + + +/* + * Structure used to pass trap information to the client + */ +struct info_trap { + u_int32 local_address; /* local interface addres (v4) */ + u_int32 trap_address; /* remote client's addres (v4) */ + u_short trap_port; /* remote port number */ + u_short sequence; /* sequence number */ + u_int32 settime; /* time trap last set */ + u_int32 origtime; /* time trap originally set */ + u_int32 resets; /* number of resets on this trap */ + u_int32 flags; /* trap flags, as defined in ntp_control.h */ + u_int v6_flag; /* is this v6 or not */ + struct in6_addr local_address6; /* local interface address (v6) */ + struct in6_addr trap_address6; /* remote client's address (v6) */ +}; + +/* + * Structure used to pass add/clear trap information to the client + */ +struct conf_trap { + u_int32 local_address; /* remote client's address */ + u_int32 trap_address; /* local interface address */ + u_short trap_port; /* remote client's port */ + u_short unused; /* (unused) */ + u_int v6_flag; /* is this v6 or not */ + struct in6_addr local_address6; /* local interface address (v6) */ + struct in6_addr trap_address6; /* remote client's address (v6) */ +}; + + +/* + * Structure used to return statistics from the control module + */ +struct info_control { + u_int32 ctltimereset; + u_int32 numctlreq; /* number of requests we've received */ + u_int32 numctlbadpkts; /* number of bad control packets */ + u_int32 numctlresponses; /* # resp packets sent */ + u_int32 numctlfrags; /* # of fragments sent */ + u_int32 numctlerrors; /* number of error responses sent */ + u_int32 numctltooshort; /* number of too short input packets */ + u_int32 numctlinputresp; /* number of responses on input */ + u_int32 numctlinputfrag; /* number of fragments on input */ + u_int32 numctlinputerr; /* # input pkts with err bit set */ + u_int32 numctlbadoffset; /* # input pkts with nonzero offset */ + u_int32 numctlbadversion; /* # input pkts with unknown version */ + u_int32 numctldatatooshort; /* data too short for count */ + u_int32 numctlbadop; /* bad op code found in packet */ + u_int32 numasyncmsgs; /* # async messages we've sent */ +}; + + +/* + * Structure used to return clock information + */ +struct info_clock { + u_int32 clockadr; + u_char type; + u_char flags; + u_char lastevent; + u_char currentstatus; + u_int32 polls; + u_int32 noresponse; + u_int32 badformat; + u_int32 baddata; + u_int32 timestarted; + l_fp fudgetime1; + l_fp fudgetime2; + int32 fudgeval1; + int32 fudgeval2; +}; + + +/* + * Structure used for setting clock fudge factors + */ +struct conf_fudge { + u_int32 clockadr; + u_int32 which; + l_fp fudgetime; + int32 fudgeval_flags; +}; + +#define FUDGE_TIME1 1 +#define FUDGE_TIME2 2 +#define FUDGE_VAL1 3 +#define FUDGE_VAL2 4 +#define FUDGE_FLAGS 5 + + +/* + * Structure used for returning clock debugging info + */ +#define NUMCBUGVALUES 16 +#define NUMCBUGTIMES 32 + +struct info_clkbug { + u_int32 clockadr; + u_char nvalues; + u_char ntimes; + u_short svalues; + u_int32 stimes; + u_int32 values[NUMCBUGVALUES]; + l_fp times[NUMCBUGTIMES]; +}; + +/* + * Structure used for returning kernel pll/PPS information + */ +struct info_kernel { + int32 offset; + int32 freq; + int32 maxerror; + int32 esterror; + u_short status; + u_short shift; + int32 constant; + int32 precision; + int32 tolerance; + +/* + * Variables used only if PPS signal discipline is implemented + */ + int32 ppsfreq; + int32 jitter; + int32 stabil; + int32 jitcnt; + int32 calcnt; + int32 errcnt; + int32 stbcnt; +}; + +/* + * Info returned with IP -> hostname lookup + */ +/* 144 might need to become 32, matching data[] member of req_pkt */ +#define NTP_MAXHOSTNAME (32 - sizeof(u_int32) - sizeof(u_short)) +struct info_dns_assoc { + u_int32 peeraddr; /* peer address (HMS: being careful...) */ + associd_t associd; /* association ID */ + char hostname[NTP_MAXHOSTNAME]; /* hostname */ +}; +#endif /* NTP_REQUEST_H */ diff --git a/include/ntp_rfc2553.h b/include/ntp_rfc2553.h new file mode 100644 index 000000000000..28ff004b8808 --- /dev/null +++ b/include/ntp_rfc2553.h @@ -0,0 +1,254 @@ +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)in.h 8.3 (Berkeley) 1/3/94 + */ + +/* + * Compatability shims with the rfc2553 API to simplify ntp. + */ +#ifndef _NTP_RFC2553_H_ +#define _NTP_RFC2553_H_ + +#if defined(_SS_MAXSIZE) || defined(_SS_SIZE) +#define HAVE_IPV6 +#else + +#include <sys/types.h> +#include "ntp_types.h" + +#ifndef AF_INET6 +#define AF_INET6 AF_MAX +#define PF_INET6 AF_INET6 +#endif + +#ifndef HAVE_TYPE_U_INT8_T +typedef u_char u_int8_t; +typedef u_short u_int16_t; +typedef u_int32 u_int32_t; +#endif /* HAVE_TYPE_U_INT8_T */ + +#ifndef HAVE_TYPE_U_INT64_T +typedef struct u_int64_t { u_int32 val[2]; } u_int64_t; +#endif /* HAVE_TYPE_U_INT64_T */ + +/* + * IPv6 address + */ +#ifdef SYS_WINNT +#define in6_addr in_addr6 +#else +/* + * Don't include any additional IPv6 definitions + * We are defining our own here. + */ +#define ISC_IPV6_H 1 + +struct in6_addr { + union { + u_int8_t __u6_addr8[16]; + u_int16_t __u6_addr16[8]; + u_int32_t __u6_addr32[4]; + } __u6_addr; /* 128-bit IP6 address */ +}; + +#define s6_addr __u6_addr.__u6_addr8 +#endif + +/* + * Definition of some useful macros to handle IP6 addresses + */ +#ifdef SYS_WINNT +#define IN6ADDR_ANY_INIT {{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }} +#else +#define IN6ADDR_ANY_INIT \ + {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} +#endif + +extern const struct in6_addr in6addr_any; + +#define SIN6_LEN +#ifndef HAVE_SOCKADDR_IN6 +struct sockaddr_in6 { +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + u_int8_t sin6_len; /* length of this struct(sa_family_t)*/ + u_int8_t sin6_family; /* AF_INET6 (sa_family_t) */ +#else + short sin6_family; /* AF_INET6 (sa_family_t) */ +#endif + u_int16_t sin6_port; /* Transport layer port # (in_port_t)*/ + u_int32_t sin6_flowinfo; /* IP6 flow information */ + struct in6_addr sin6_addr; /* IP6 address */ + u_int32_t sin6_scope_id; /* scope zone index */ +}; +#endif + +/* + * Unspecified + */ +#ifndef IN6_IS_ADDR_UNSPECIFIED +#define IN6_IS_ADDR_UNSPECIFIED(a) \ + ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0)) +#endif +/* + * Multicast + */ +#ifndef IN6_IS_ADDR_MULTICAST +#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) +#endif + +/* + * RFC 2553: protocol-independent placeholder for socket addresses + */ +#define _SS_MAXSIZE 128 +#define _SS_ALIGNSIZE (sizeof(u_int64_t)) +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR +#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) - sizeof(u_int8_t)) +#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) - sizeof(u_int8_t) - \ + _SS_PAD1SIZE - _SS_ALIGNSIZE) +#else +#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(short)) +#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(short) - \ + _SS_PAD1SIZE - _SS_ALIGNSIZE) +#endif /* HAVE_SA_LEN_IN_STRUCT_SOCKADDR */ + +struct sockaddr_storage { +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + u_int8_t ss_len; /* address length */ + u_int8_t ss_family; /* address family */ +#else + short ss_family; /* address family */ +#endif + char __ss_pad1[_SS_PAD1SIZE]; + u_int64_t __ss_align; /* force desired structure storage alignment */ + char __ss_pad2[_SS_PAD2SIZE]; +}; + +struct addrinfo { + int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ + int ai_family; /* PF_xxx */ + int ai_socktype; /* SOCK_xxx */ + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ + size_t ai_addrlen; /* length of ai_addr */ + char *ai_canonname; /* canonical name for hostname */ + struct sockaddr *ai_addr; /* binary address */ + struct addrinfo *ai_next; /* next structure in linked list */ +}; + +/* + * Error return codes from getaddrinfo() + */ +#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ +#define EAI_AGAIN 2 /* temporary failure in name resolution */ +#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ +#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ +#define EAI_FAMILY 5 /* ai_family not supported */ +#define EAI_MEMORY 6 /* memory allocation failure */ +#define EAI_NODATA 7 /* no address associated with hostname */ +#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ +#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ +#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ +#define EAI_SYSTEM 11 /* system error returned in errno */ +#define EAI_BADHINTS 12 +#define EAI_PROTOCOL 13 +#define EAI_MAX 14 + +/* + * Flag values for getaddrinfo() + */ +#define AI_PASSIVE 0x00000001 /* get address to use bind() */ +#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ +#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ +/* valid flags for addrinfo */ +#define AI_MASK \ + (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG) + +#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ + +/* + * Constants for getnameinfo() + */ +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 + +/* + * Flag values for getnameinfo() + */ +#define NI_NOFQDN 0x00000001 +#define NI_NUMERICHOST 0x00000002 +#define NI_NAMEREQD 0x00000004 +#define NI_NUMERICSERV 0x00000008 +#define NI_DGRAM 0x00000010 +#define NI_WITHSCOPEID 0x00000020 + +int getaddrinfo P((const char *, const char *, + const struct addrinfo *, struct addrinfo **)); +int getnameinfo P((const struct sockaddr *, u_int, char *, + size_t, char *, size_t, int)); +void freeaddrinfo P((struct addrinfo *)); +char *gai_strerror P((int)); + +#endif /* _SS_MAXSIZE */ +#endif /* !_NTP_RFC2553_H_ */ diff --git a/include/ntp_select.h b/include/ntp_select.h new file mode 100644 index 000000000000..79c0fc0a56bf --- /dev/null +++ b/include/ntp_select.h @@ -0,0 +1,35 @@ +/* + * Not all machines define FD_SET in sys/types.h + */ +#ifndef _ntp_select_h +#define _ntp_select_h + +/* Was: (defined(RS6000)||defined(SYS_PTX))&&!defined(_BSD) */ +/* Could say: !defined(FD_SET) && defined(HAVE_SYS_SELECT_H) */ +#if defined(HAVE_SYS_SELECT_H) && !defined(_BSD) +#ifndef SYS_VXWORKS +#include <sys/select.h> +#else +#include <sockLib.h> +extern int select P((int width, fd_set *pReadFds, fd_set *pWriteFds, + fd_set *pExceptFds, struct timeval *pTimeOut)); + +#endif +#endif + +#if !defined(FD_SET) && !defined(SYS_WINNT) +#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))) +#endif + +#if defined(VMS) +typedef struct { + unsigned int fds_bits[1]; +} fd_set; +#endif + +#endif /* _ntp_select_h */ diff --git a/include/ntp_sprintf.h b/include/ntp_sprintf.h new file mode 100644 index 000000000000..a456a8925949 --- /dev/null +++ b/include/ntp_sprintf.h @@ -0,0 +1,13 @@ +/* + * 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 new file mode 100644 index 000000000000..3dc6fe041857 --- /dev/null +++ b/include/ntp_stdlib.h @@ -0,0 +1,158 @@ +/* + * ntp_stdlib.h - Prototypes for NTP lib. + */ +#include <sys/types.h> +#include <sys/socket.h> +#include "ntp_rfc2553.h" + +#include "ntp_types.h" +#include "ntp_string.h" +#include "l_stdlib.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 +#endif + +#if defined(__STDC__) || defined(HAVE_STDARG_H) +# include <stdarg.h> +extern void msyslog P((int, const char *, ...)) + __attribute__((__format__(__printf__, 2, 3))); +extern void netsyslog P((int, const char *, ...)) + __attribute__((__format__(__printf__, 2, 3))); +#else +# include <varargs.h> +extern void msyslog P(()); +extern void netsyslog P(()); +#endif + +extern void auth_delkeys P((void)); +extern int auth_havekey P((keyid_t)); +extern int authdecrypt P((keyid_t, u_int32 *, int, int)); +extern int authencrypt P((keyid_t, u_int32 *, int)); +extern int authhavekey P((keyid_t)); +extern int authistrusted P((keyid_t)); +extern int authreadkeys P((const char *)); +extern void authtrust P((keyid_t, u_long)); +extern int authusekey P((keyid_t, int, const u_char *)); + +extern u_long calleapwhen P((u_long)); +extern u_long calyearstart P((u_long)); +extern const char *clockname P((int)); +extern int clocktime P((int, int, int, int, int, u_long, u_long *, u_int32 *)); +#if defined SYS_WINNT && defined DEBUG +# define emalloc(_c) debug_emalloc(_c, __FILE__, __LINE__) +extern void * debug_emalloc P((u_int, char *, int)); +#else +extern void * emalloc P((u_int)); +#endif +extern int ntp_getopt P((int, char **, const char *)); +extern void init_auth P((void)); +extern void init_lib P((void)); +extern void init_random P((void)); +extern struct savekey *auth_findkey P((keyid_t)); +extern int auth_moremem P((void)); +extern int ymd2yd P((int, int, int)); + +extern int MD5authdecrypt P((u_char *, u_int32 *, int, int)); +extern int MD5authencrypt P((u_char *, u_int32 *, int)); +extern void MD5auth_setkey P((keyid_t, const u_char *, const int)); +extern u_int32 addr2refid P((struct sockaddr_storage *)); + +extern int atoint P((const char *, long *)); +extern int atouint P((const char *, u_long *)); +extern int hextoint P((const char *, u_long *)); +extern char * humandate P((u_long)); +extern char * humanlogtime P((void)); +extern char * inttoa P((long)); +extern char * mfptoa P((u_long, u_long, short)); +extern char * mfptoms P((u_long, u_long, short)); +extern const char * modetoa P((int)); +extern const char * eventstr P((int)); +extern const char * ceventstr P((int)); +extern char * statustoa P((int, int)); +extern const char * sysstatstr P((int)); +extern const char * peerstatstr P((int)); +extern const char * clockstatstr P((int)); +extern struct sockaddr_storage* netof P((struct sockaddr_storage*)); +extern char * numtoa P((u_int32)); +extern char * numtohost P((u_int32)); +extern char * socktoa P((struct sockaddr_storage *)); +extern char * socktohost P((struct sockaddr_storage *)); +extern int octtoint P((const char *, u_long *)); +extern u_long ranp2 P((int)); +extern char * refnumtoa P((struct sockaddr_storage *)); +extern int tsftomsu P((u_long, int)); +extern char * uinttoa P((u_long)); + +extern int decodenetnum P((const char *, struct sockaddr_storage *)); + +extern const char * FindConfig P((const char *)); + +extern void signal_no_reset P((int, RETSIGTYPE (*func)(int))); + +extern void getauthkeys P((char *)); +extern void auth_agekeys P((void)); +extern void rereadkeys P((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 */ +extern u_long authnumkeys; /* number of active keys */ +extern u_long authkeyexpired; /* key lifetime expirations */ +extern u_long authkeyuncached; /* cache misses */ +extern u_long authencryptions; /* calls to encrypt */ +extern u_long authdecryptions; /* calls to decrypt */ + +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 u_int cache_keylen; /* key length */ + +/* clocktypes.c */ +#ifdef NTP_REFCLOCK_H +struct clktype; +extern struct clktype clktypes[]; +#endif + +/* getopt.c */ +extern char * ntp_optarg; /* global argument pointer */ +extern int ntp_optind; /* global argv index */ + +/* machines.c */ +extern const char *set_tod_using; + +/* mexit.c */ +#if defined SYS_WINNT || defined SYS_CYGWIN32 +extern HANDLE hServDoneEvent; +#endif + +/* systime.c */ +extern double sys_tick; /* adjtime() resolution */ + +/* version.c */ +extern const char *Version; /* version declaration */ diff --git a/include/ntp_string.h b/include/ntp_string.h new file mode 100644 index 000000000000..f7f0092ae493 --- /dev/null +++ b/include/ntp_string.h @@ -0,0 +1,48 @@ +/* + * Define string ops: strchr strrchr memcmp memmove memset + */ + +#ifndef _ntp_string_h +#define _ntp_string_h + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#ifdef HAVE_MEMORY_H +# include <memory.h> +#endif + +#ifdef HAVE_STRING_H +# include <string.h> +#endif + +#ifdef HAVE_BSTRING_H +# 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 +# define memcmp(a,b,c) bcmp(a,b,(int)c) +# define memmove(t,f,c) bcopy(f,t,(int)c) +# define memcpy(t,f,c) bcopy(f,t,(int)c) +# define memset(a,x,c) if (x == 0x00) bzero(a,(int)c); else ntp_memset((char*)a,x,c) + +void ntp_memset P((char *, int, int)); + +#endif /* NTP_NEED_BOPS */ + +#endif /* _ntp_string_h */ diff --git a/include/ntp_syscall.h b/include/ntp_syscall.h new file mode 100644 index 000000000000..521e753f6791 --- /dev/null +++ b/include/ntp_syscall.h @@ -0,0 +1,55 @@ +/* + * ntp_syscall.h - various ways to perform the ntp_adjtime() and ntp_gettime() + * system calls. + */ + +#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 P((struct timex *)); + +# define ntp_adjtime(t) __adjtimex((t)) + +static inline int +ntp_gettime( + struct ntptimeval *ntv + ) +{ + struct timex tntx; + int result; + + tntx.modes = 0; + result = __adjtimex (&tntx); + ntv->time = tntx.time; + ntv->maxerror = tntx.maxerror; + ntv->esterror = tntx.esterror; +#ifdef NTP_API +# if NTP_API > 3 + ntv->tai = tntx.tai; +# 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 /* NTP_SYSCALL_H */ diff --git a/include/ntp_syslog.h b/include/ntp_syslog.h new file mode 100644 index 000000000000..38021e251682 --- /dev/null +++ b/include/ntp_syslog.h @@ -0,0 +1,70 @@ +/* + * A hack for platforms which require specially built syslog facilities + */ + +#ifndef NTP_SYSLOG_H +#define NTP_SYSLOG_H + +# ifdef VMS +extern void msyslog(); +# else +# ifndef SYS_VXWORKS +# include <syslog.h> +# endif +# endif /* VMS */ +# include <stdio.h> + +extern int syslogit; +extern FILE *syslog_file; + +#if defined(VMS) || defined (SYS_VXWORKS) +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but signification condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ +#endif /* VMS || VXWORKS */ + +/* + * syslog output control + */ +#define NLOG_INFO 0x00000001 +#define NLOG_EVENT 0x00000002 +#define NLOG_STATUS 0x00000004 +#define NLOG_STATIST 0x00000008 + +#define NLOG_OSYS 0 /* offset for system flags */ +#define NLOG_SYSMASK 0x0000000F /* system log events */ +#define NLOG_SYSINFO 0x00000001 /* system info log events */ +#define NLOG_SYSEVENT 0x00000002 /* system events */ +#define NLOG_SYSSTATUS 0x00000004 /* system status (sync/unsync) */ +#define NLOG_SYSSTATIST 0x00000008 /* system statistics output */ + +#define NLOG_OPEER 4 /* offset for peer flags */ +#define NLOG_PEERMASK 0x000000F0 /* peer log events */ +#define NLOG_PEERINFO 0x00000010 /* peer info log events */ +#define NLOG_PEEREVENT 0x00000020 /* peer events */ +#define NLOG_PEERSTATUS 0x00000040 /* peer status (sync/unsync) */ +#define NLOG_PEERSTATIST 0x00000080 /* peer statistics output */ + +#define NLOG_OCLOCK 8 /* offset for clock flags */ +#define NLOG_CLOCKMASK 0x00000F00 /* clock log events */ +#define NLOG_CLOCKINFO 0x00000100 /* clock info log events */ +#define NLOG_CLOCKEVENT 0x00000200 /* clock events */ +#define NLOG_CLOCKSTATUS 0x00000400 /* clock status (sync/unsync) */ +#define NLOG_CLOCKSTATIST 0x00000800 /* clock statistics output */ + +#define NLOG_OSYNC 12 /* offset for sync flags */ +#define NLOG_SYNCMASK 0x0000F000 /* sync log events */ +#define NLOG_SYNCINFO 0x00001000 /* sync info log events */ +#define NLOG_SYNCEVENT 0x00002000 /* sync events */ +#define NLOG_SYNCSTATUS 0x00004000 /* sync status (sync/unsync) */ +#define NLOG_SYNCSTATIST 0x00008000 /* sync statistics output */ + +extern unsigned long ntp_syslogmask; +#define NLOG(_X_) if (ntp_syslogmask & (_X_)) + +#endif /* NTP_SYSLOG_H */ diff --git a/include/ntp_tty.h b/include/ntp_tty.h new file mode 100644 index 000000000000..3e12c8d3ea7f --- /dev/null +++ b/include/ntp_tty.h @@ -0,0 +1,68 @@ +/* + * ntp_tty.h - header file for serial lines handling + */ + +#ifndef NTP_TTY_H +#define NTP_TTY_H + +#if defined(HAVE_BSD_TTYS) +#include <sgtty.h> +#define TTY struct sgttyb +#endif /* HAVE_BSD_TTYS */ + +#if defined(HAVE_SYSV_TTYS) +#include <termio.h> +#define TTY struct termio +#ifndef tcsetattr +#define tcsetattr(fd, cmd, arg) ioctl(fd, cmd, arg) +#endif +#ifndef TCSANOW +#define TCSANOW TCSETA +#endif +#ifndef TCIFLUSH +#define TCIFLUSH 0 +#endif +#ifndef TCOFLUSH +#define TCOFLUSH 1 +#endif +#ifndef TCIOFLUSH +#define TCIOFLUSH 2 +#endif +#ifndef tcflush +#define tcflush(fd, arg) ioctl(fd, TCFLSH, arg) +#endif +#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 +#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. 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 0x0 /* standard */ +#define LDISC_CLK 0x1 /* tty_clk \n intercept */ +#define LDISC_CLKPPS 0x2 /* tty_clk \377 intercept */ +#define LDISC_ACTS 0x4 /* tty_clk #* intercept */ +#define LDISC_CHU 0x8 /* depredated */ +#define LDISC_PPS 0x10 /* ppsclock, ppsapi */ +#define LDISC_RAW 0x20 /* raw binary */ + +#endif /* NTP_TTY_H */ diff --git a/include/ntp_types.h b/include/ntp_types.h new file mode 100644 index 000000000000..348e95ec162d --- /dev/null +++ b/include/ntp_types.h @@ -0,0 +1,73 @@ +/* + * ntp_types.h - 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 + */ +#include "ntp_machine.h" + +#ifndef _NTP_TYPES_ +#define _NTP_TYPES_ + +/* + * This is another naming conflict. + * On NetBSD for MAC the macro "mac" is defined as 1 + * this is fun for us as a packet structure contains an + * optional "mac" member - severe confusion results 8-) + * As we hopefully do not have to rely on that macro we + * just undefine that. + */ +#ifdef mac +#undef mac +#endif + +/* + * Set up for prototyping + */ +#ifndef P +#if defined(__STDC__) || defined(HAVE_PROTOTYPES) +#define P(x) x +#else /* not __STDC__ and not HAVE_PROTOTYPES */ +#define P(x) () +#endif /* not __STDC__ and HAVE_PROTOTYPES */ +#endif /* P */ + +/* + * VMS DECC (v4.1), {u_char,u_short,u_long} are only in SOCKET.H, + * and u_int isn't defined anywhere + */ +#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 +# endif +# ifndef u_int32 +# define u_int32 unsigned int +# endif +#else /* not sizeof(int) == 4 */ +# if (SIZEOF_LONG == 4) +# else /* not sizeof(long) == 4 */ +# ifndef int32 +# define int32 long +# endif +# ifndef u_int32 +# define u_int32 unsigned long +# endif +# endif /* not sizeof(long) == 4 */ +# include "Bletch: what's 32 bits on this machine?" +#endif /* not sizeof(int) == 4 */ + +typedef unsigned short associd_t; /* association ID */ +typedef u_int32 keyid_t; /* cryptographic key ID */ +typedef u_int32 tstamp_t; /* NTP seconds timestamp */ + +#endif /* _NTP_TYPES_ */ + diff --git a/include/ntp_unixtime.h b/include/ntp_unixtime.h new file mode 100644 index 000000000000..ce96980209e9 --- /dev/null +++ b/include/ntp_unixtime.h @@ -0,0 +1,141 @@ +/* + * ntp_unixtime.h - contains constants and macros for converting between + * NTP time stamps (l_fp) and Unix times (struct timeval) + */ + +#include "ntp_types.h" + +#ifdef SIM +#include "ntpsim.h" +#endif + +#ifdef SIM +# define GETTIMEOFDAY(a, b) (node_gettime(&ntp_node, a)) +# define SETTIMEOFDAY(a, b) (node_settime(&ntp_node, a)) +# define ADJTIMEOFDAY(a, b) (node_adjtime(&ntp_node, a, b)) +#else +# define ADJTIMEOFDAY(a, b) (adjtime(a, b)) +/* gettimeofday() takes two args in BSD and only one in SYSV */ +# 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 SETTIMEOFDAY(a, b) (settimeofday(a, b)) +# else /* not (HAVE_SYS_TIMERS_H && HAVE_GETCLOCK) */ +# ifdef SYSV_TIMEOFDAY +# define GETTIMEOFDAY(a, b) (gettimeofday(a)) +# define SETTIMEOFDAY(a, b) (settimeofday(a)) +# else /* ! SYSV_TIMEOFDAY */ +#if defined SYS_CYGWIN32 +# define GETTIMEOFDAY(a, b) (gettimeofday(a, b)) +# define SETTIMEOFDAY(a, b) (settimeofday_NT(a)) +#else +# define GETTIMEOFDAY(a, b) (gettimeofday(a, b)) +# define SETTIMEOFDAY(a, b) (settimeofday(a, b)) +#endif +# endif /* SYSV_TIMEOFDAY */ +# endif /* not (HAVE_SYS_TIMERS_H && HAVE_GETCLOCK) */ +#endif /* SIM */ + +/* + * 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. + */ +extern u_long msutotsflo[]; +extern u_long msutotsfhi[]; + +#define MSUTOTSF(msu, tsf) \ + (tsf) = msutotsfhi[((msu) >> 5) & 0x1f] + msutotsflo[(msu) & 0x1f] + +extern char * tvtoa P((const struct timeval *)); +extern char * utvtoa P((const struct timeval *)); diff --git a/include/ntpd.h b/include/ntpd.h new file mode 100644 index 000000000000..54d3e13c24ee --- /dev/null +++ b/include/ntpd.h @@ -0,0 +1,435 @@ +/* + * ntpd.h - Prototypes for ntpd. + */ + +#include "ntp_syslog.h" +#include "ntp_fp.h" +#include "ntp.h" +#include "ntp_select.h" +#include "ntp_malloc.h" +#include "ntp_refclock.h" +#include "recvbuff.h" + +#ifdef SYS_WINNT +#define exit service_exit +extern void service_exit (int); +/* declare the service threads */ +void service_main (DWORD, LPTSTR *); +void service_ctrl (DWORD); +void worker_thread (void *); +#define sleep(x) Sleep((DWORD) x * 1000 /* milliseconds */ ); +#endif /* SYS_WINNT */ + +/* ntp_config.c */ +extern void getconfig P((int, char **)); + +/* ntp_config.c */ +extern void ctl_clr_stats P((void)); +extern int ctlclrtrap P((struct sockaddr_storage *, struct interface *, int)); +extern u_short ctlpeerstatus P((struct peer *)); +extern int ctlsettrap P((struct sockaddr_storage *, struct interface *, int, int)); +extern u_short ctlsysstatus P((void)); +extern void init_control P((void)); +extern void process_control P((struct recvbuf *, int)); +extern void report_event P((int, struct peer *)); + +extern double fabs P((double)); +extern double sqrt P((double)); + +/* ntp_control.c */ +/* + * Structure for translation tables between internal system + * variable indices and text format. + */ +struct ctl_var { + u_short code; + u_short flags; + char *text; +}; +/* + * Flag values + */ +#define CAN_READ 0x01 +#define CAN_WRITE 0x02 + +#define DEF 0x20 +#define PADDING 0x40 +#define EOV 0x80 + +#define RO (CAN_READ) +#define WO (CAN_WRITE) +#define RW (CAN_READ|CAN_WRITE) + +extern char * add_var P((struct ctl_var **, u_long, u_short)); +extern void free_varlist P((struct ctl_var *)); +extern void set_var P((struct ctl_var **, const char *, u_long, u_short)); +extern void set_sys_var P((char *, u_long, u_short)); + +/* ntp_intres.c */ +extern void ntp_res_name P((struct sockaddr_storage, u_short)); +extern void ntp_res_recv P((void)); +extern void ntp_intres P((void)); + +/* ntp_io.c */ +extern struct interface *findinterface P((struct sockaddr_storage *)); +extern struct interface *findbcastinter P((struct sockaddr_storage *)); + +extern void init_io P((void)); +extern void input_handler P((l_fp *)); +extern void io_clr_stats P((void)); +extern void io_setbclient P((void)); +extern void io_unsetbclient P((void)); +extern void io_multicast_add P((struct sockaddr_storage)); +extern void io_multicast_del P((struct sockaddr_storage)); +extern void kill_asyncio P((int)); + +extern void sendpkt P((struct sockaddr_storage *, struct interface *, int, struct pkt *, int)); +#ifdef HAVE_SIGNALED_IO +extern void wait_for_signal P((void)); +extern void unblock_io_and_alarm P((void)); +extern void block_io_and_alarm P((void)); +#endif + +/* ntp_leap.c */ +extern void init_leap P((void)); +extern void leap_process P((void)); +extern int leap_setleap P((int, int)); +/* + * 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 int leap_actual P((int)); + +/* ntp_loopfilter.c */ +extern void init_loopfilter P((void)); +extern int local_clock P((struct peer *, double, double)); +extern void adj_host_clock P((void)); +extern void loop_config P((int, double)); +extern void huffpuff P((void)); + +/* ntp_monitor.c */ +extern void init_mon P((void)); +extern void mon_start P((int)); +extern void mon_stop P((int)); +extern void ntp_monitor P((struct recvbuf *)); + +/* ntp_peer.c */ +extern void init_peer P((void)); +extern struct peer *findexistingpeer P((struct sockaddr_storage *, struct peer *, int)); +extern struct peer *findpeer P((struct sockaddr_storage *, struct interface *, int, int, int *)); +extern struct peer *findpeerbyassoc P((u_int)); +extern struct peer *newpeer P((struct sockaddr_storage *, struct interface *, int, int, int, int, u_int, u_char, int, keyid_t)); +extern void peer_all_reset P((void)); +extern void peer_clr_stats P((void)); +extern struct peer *peer_config P((struct sockaddr_storage *, struct interface *, int, int, int, int, u_int, int, keyid_t, u_char *)); +extern void peer_reset P((struct peer *)); +extern int peer_unconfig P((struct sockaddr_storage *, struct interface *, int)); +extern void unpeer P((struct peer *)); +extern void clear_all P((void)); +#ifdef OPENSSL +extern void expire_all P((void)); +#endif /* OPENSSL */ +extern struct peer *findmanycastpeer P((struct recvbuf *)); +extern void resetmanycast P((void)); + +/* ntp_crypto.c */ +#ifdef OPENSSL +extern int crypto_recv P((struct peer *, struct recvbuf *)); +extern int crypto_xmit P((struct pkt *, struct sockaddr_storage *, int, struct exten *, keyid_t)); +extern keyid_t session_key P((struct sockaddr_storage *, struct sockaddr_storage *, keyid_t, keyid_t, u_long)); +extern void make_keylist P((struct peer *, struct interface *)); +extern void key_expire P((struct peer *)); +extern void crypto_update P((void)); +extern void crypto_config P((int, char *)); +extern void crypto_setup P((void)); +extern u_int crypto_ident P((struct peer *)); +extern struct exten *crypto_args P((struct peer *, u_int, char *)); +extern int crypto_public P((struct peer *, u_char *, u_int)); +extern void value_free P((struct value *)); +#endif /* OPENSSL */ + +/* ntp_proto.c */ +extern void transmit P((struct peer *)); +extern void receive P((struct recvbuf *)); +extern void peer_clear P((struct peer *, char *)); +extern void process_packet P((struct peer *, struct pkt *, l_fp *)); +extern void clock_select P((void)); +extern void kod_proto P((void)); + +/* + * 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 P((struct peer *, int)); + +extern void clear P((struct peer *)); +extern void clock_filter P((struct peer *, double, double, double)); +extern void init_proto P((void)); +extern void proto_config P((int, u_long, double, struct sockaddr_storage*)); +extern void proto_clr_stats P((void)); + +#ifdef REFCLOCK +/* ntp_refclock.c */ +extern int refclock_newpeer P((struct peer *)); +extern void refclock_unpeer P((struct peer *)); +extern void refclock_receive P((struct peer *)); +extern void refclock_transmit P((struct peer *)); +extern void init_refclock P((void)); +#endif /* REFCLOCK */ + +/* ntp_request.c */ +extern void init_request P((void)); +extern void process_private P((struct recvbuf *, int)); + +/* ntp_restrict.c */ +extern void init_restrict P((void)); +extern int restrictions P((struct sockaddr_storage *)); +extern void hack_restrict P((int, struct sockaddr_storage *, struct sockaddr_storage *, int, int)); + +/* ntp_timer.c */ +extern void init_timer P((void)); +extern void reinit_timer P((void)); +extern void timer P((void)); +extern void timer_clr_stats P((void)); +#ifdef OPENSSL +extern char *sys_hostname; +extern l_fp sys_revoketime; +#endif /* OPENSSL */ + +/* ntp_util.c */ +extern void init_util P((void)); +extern void hourly_stats P((void)); +extern void stats_config P((int, char *)); +extern void record_peer_stats P((struct sockaddr_storage *, int, double, double, double, double)); +extern void record_loop_stats P((double, double, double, double, int)); +extern void record_clock_stats P((struct sockaddr_storage *, const char *)); +extern void record_raw_stats P((struct sockaddr_storage *, struct sockaddr_storage *, l_fp *, l_fp *, l_fp *, l_fp *)); +extern void record_sys_stats P((void)); +extern void record_crypto_stats P((struct sockaddr_storage *, const char *)); +extern int sock_hash P((struct sockaddr_storage *)); + +/* + * Variable declarations for ntpd. + */ + +/* ntp_config.c */ +extern char const * progname; +extern char sys_phone[][MAXDIAL]; /* ACTS phone numbers */ +extern char pps_device[]; /* PPS device name */ +#if defined(HAVE_SCHED_SETSCHEDULER) +extern int config_priority_override; +extern int config_priority; +#endif + +/* ntp_control.c */ +#if 0 +struct ctl_trap; +extern struct ctl_trap ctl_trap[]; +#endif +extern int num_ctl_traps; +extern keyid_t ctl_auth_keyid; /* keyid used for authenticating write requests */ + +/* + * Statistic counters to keep track of requests and responses. + */ +extern u_long ctltimereset; /* time stats reset */ +extern u_long numctlreq; /* number of requests we've received */ +extern u_long numctlbadpkts; /* number of bad control packets */ +extern u_long numctlresponses; /* number of resp packets sent with data */ +extern u_long numctlfrags; /* number of fragments sent */ +extern u_long numctlerrors; /* number of error responses sent */ +extern u_long numctltooshort; /* number of too short input packets */ +extern u_long numctlinputresp; /* number of responses on input */ +extern u_long numctlinputfrag; /* number of fragments on input */ +extern u_long numctlinputerr; /* number of input pkts with err bit set */ +extern u_long numctlbadoffset; /* number of input pkts with nonzero offset */ +extern u_long numctlbadversion; /* number of input pkts with unknown version */ +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 char * req_file; /* name of the file with configuration info */ + +/* + * Other statistics of possible interest + */ +extern volatile u_long packets_dropped; /* total number of packets dropped on reception */ +extern volatile u_long packets_ignored; /* packets received on wild card interface */ +extern volatile u_long packets_received;/* total number of packets received */ +extern u_long packets_sent; /* total number of packets sent */ +extern u_long packets_notsent; /* total number of packets which couldn't be sent */ + +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 + */ +extern struct interface *any_interface; /* default ipv4 interface */ +extern struct interface *any6_interface;/* default ipv6 interface */ +extern struct interface *loopback_interface; /* loopback interface */ + +/* + * File descriptor masks etc. for call to select + */ +extern fd_set activefds; +extern int maxactivefd; + +/* ntp_loopfilter.c */ +extern double drift_comp; /* clock frequency (s/s) */ +extern double clock_stability; /* clock stability (s/s) */ +extern double clock_max; /* max offset before step (s) */ +extern double clock_panic; /* max offset before panic (s) */ +extern double clock_phi; /* dispersion rate (s/s) */ +extern double clock_minstep; /* step timeout (s) */ +extern u_long pps_control; /* last pps sample time */ +#ifdef KERNEL_PLL +extern int pll_status; /* status bits for kernel pll */ +#endif /* KERNEL_PLL */ + +/* + * Clock state machine control flags + */ +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 ext_enable; /* external clock enabled */ +extern int cal_enable; /* refclock calibrate enable */ +extern int allow_panic; /* allow panic correction */ +extern int mode_ntpdate; /* exit on first clock set */ +extern int peer_ntpdate; /* count of ntpdate peers */ +extern int forground_process; /* run the process in the forground */ + +/* + * Clock state machine variables + */ +extern u_char sys_poll; /* system poll interval (log2 s) */ +extern int state; /* clock discipline state */ +extern int tc_counter; /* poll-adjust counter */ +extern u_long last_time; /* time of last clock update (s) */ +extern double last_offset; /* last clock offset (s) */ +extern double allan_xpt; /* Allan intercept (s) */ +extern double sys_error; /* system RMS error (s) */ +extern double sys_jitter; /* system RMS jitter (s) */ + +/* ntp_monitor.c */ +extern struct mon_data mon_mru_list; +extern struct mon_data mon_fifo_list; +extern int mon_enabled; + +/* 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; + +/* + * Miscellaneous statistic counters which may be queried. + */ +extern u_long peer_timereset; /* time stat counters were zeroed */ +extern u_long findpeer_calls; /* number of calls to findpeer */ +extern u_long assocpeer_calls; /* number of calls to findpeerbyassoc */ +extern u_long peer_allocations; /* number of allocations from the free list */ +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; /* number of active associations */ + +/* ntp_proto.c */ +/* + * System variables are declared here. See Section 3.2 of the + * specification. + */ +extern u_char sys_leap; /* system leap indicator */ +extern u_char sys_stratum; /* stratum of system */ +extern s_char sys_precision; /* local clock precision */ +extern double sys_rootdelay; /* distance to current sync source */ +extern double sys_rootdispersion; /* dispersion of system clock */ +extern u_int32 sys_refid; /* reference source for local clock */ +extern l_fp sys_reftime; /* time we were last updated */ +extern struct peer *sys_peer; /* our current peer */ +extern struct peer *sys_prefer; /* our cherished peer */ +extern u_long sys_automax; /* maximum session key lifetime */ + +/* + * Nonspecified system state variables. + */ +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 keyid_t sys_private; /* private value for session seed */ +extern int sys_manycastserver; /* respond to manycast client pkts */ +extern int sys_minclock; /* minimum survivors */ +extern int sys_minsane; /* minimum candidates */ +extern int sys_floor; /* cluster stratum floor */ +extern int sys_ceiling; /* cluster stratum ceiling */ +extern u_char sys_ttl[]; /* ttl mapping vector */ +extern int sys_ttlmax; /* max ttl mapping vector index */ + +/* + * Statistics counters + */ +extern u_long sys_stattime; /* time when we started recording */ +extern u_long sys_restricted; /* restricted packets */ +extern u_long sys_oldversionpkt; /* old version packets */ +extern u_long sys_newversionpkt; /* new version packets */ +extern u_long sys_unknownversion; /* don't know version packets */ +extern u_long sys_badlength; /* bad length or format */ +extern u_long sys_processed; /* packets processed */ +extern u_long sys_badauth; /* bad authentication */ +extern u_long sys_limitrejected; /* rate limit exceeded */ +extern u_long sys_received; /* packets received */ + +/* ntp_refclock.c */ +#ifdef REFCLOCK +#if defined(PPS) || defined(HAVE_PPSAPI) +extern int fdpps; /* pps file descriptor */ +#endif /* PPS */ +#endif + +/* ntp_request.c */ +extern keyid_t info_auth_keyid; /* keyid used to authenticate requests */ + +/* ntp_restrict.c */ +extern struct restrictlist *restrictlist; /* the ipv4 restriction list */ +extern struct restrictlist6 *restrictlist6; /* the ipv6 restriction list */ +extern u_long res_min_interval; +extern u_long res_avg_interval; +extern u_long mon_age; /* monitor preempt age */ + +/* ntp_timer.c */ +extern volatile int alarm_flag; /* alarm flag */ +extern u_char sys_revoke; /* keys revoke timeout (log2 s) */ +extern volatile u_long alarm_overflow; +extern u_long current_time; /* current time (s) */ +extern u_long timer_timereset; +extern u_long timer_overflows; +extern u_long timer_xmtcalls; + +/* ntp_util.c */ +extern int stats_control; /* write stats to fileset? */ + +/* ntpd.c */ +extern volatile int debug; /* debugging flag */ +extern int nofork; /* no-fork flag */ +extern int initializing; /* initializing flag */ +#ifdef HAVE_CLOCKCTL +extern char *user; /* user to switch to */ +extern char *group; /* group to switch to */ +extern char *chrootdir; /* directory to chroot to */ +#endif + +/* refclock_conf.c */ +#ifdef REFCLOCK +extern struct refclock *refclock_conf[]; /* refclock configuration table */ +extern u_char num_refclock_conf; +#endif diff --git a/include/ntpsim.h b/include/ntpsim.h new file mode 100644 index 000000000000..c48dc59542be --- /dev/null +++ b/include/ntpsim.h @@ -0,0 +1,93 @@ +/* + * ntpsim.h - Prototypes for ntpsim + */ + +#ifndef __ntpsim_h +#define __ntpsim_h + +#include <stdio.h> +#include <math.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include "ntp_syslog.h" +#include "ntp_fp.h" +#include "ntp.h" +#include "ntp_select.h" +#include "ntp_malloc.h" +#include "ntp_refclock.h" +#include "recvbuff.h" +#include "ntp_io.h" +#include "ntp_stdlib.h" + +#define PI 3.1415926535 + +/* + * ntpsim declarations + */ +typedef enum { + BEEP, CLOCK, TIMER, PACKET +} funcTkn; + +typedef struct { + double time; + union { + struct pkt evnt_pkt; + struct recvbuf evnt_buf; + } buffer; +#define ntp_pkt buffer.evnt_pkt +#define rcv_buf buffer.evnt_buf + funcTkn function; +} Event; + +typedef struct List { + Event event; + struct List *next; +} *Queue; + +typedef struct nde { + double time; /* simulation time */ + double sim_time; /* end simulation time */ + double ntp_time; /* client disciplined time */ + double adj; /* remaining time correction */ + double slew; /* correction slew rate */ + + double clk_time; /* server time */ + double ferr; /* frequency errort */ + double fnse; /* random walk noise */ + double ndly; /* network delay */ + double snse; /* phase noise */ + double pdly; /* processing delay */ + double bdly; /* beep interval */ + + double last_time; /* last clock read time */ + Queue events; /* Node Event Queue */ + struct recvbuf *rbuflist; /* Node Receive Buffer */ +} Node; + +/* + * Function prototypes + */ +int ntpsim P((int argc, char *argv[])); +Event event P((double, funcTkn)); +Queue queue P((Event, Queue )); +Node node P((void)); +void push P((Event, Queue *)); +Event pop P((Queue *)); +void ndbeep P((Node *, Event)); +void ndeclk P((Node *, Event)); +void ntptmr P((Node *, Event)); +void netpkt P((Node *, Event)); +int srvr_rply P((Node *, struct sockaddr_storage *, + struct interface *, struct pkt *)); +double gauss P((double, double)); +double poisson P((double, double)); +int node_clock P((Node *, double)); +void abortsim P((char *)); + +/* + * The global Node + */ +Node ntp_node; + +#endif + diff --git a/include/parse.h b/include/parse.h new file mode 100644 index 000000000000..56a92e95d15a --- /dev/null +++ b/include/parse.h @@ -0,0 +1,391 @@ +/* + * /src/NTP/ntp-4/include/parse.h,v 4.5 1998/08/09 22:23:32 kardel RELEASE_19990228_A + * + * parse.h,v 4.5 1998/08/09 22:23:32 kardel RELEASE_19990228_A + * + * Copyright (C) 1989-1998 by Frank Kardel + * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + */ + +#ifndef __PARSE_H__ +#define __PARSE_H__ +#if !(defined(lint) || defined(__GNUC__)) + static char parsehrcsid[]="parse.h,v 4.5 1998/08/09 22:23:32 kardel RELEASE_19990228_A"; +#endif + +#include "ntp_types.h" + +#include "parse_conf.h" + +/* + * we use the following datastructures in two modes + * either in the NTP itself where we use NTP time stamps at some places + * or in the kernel, where only struct timeval will be used. + */ +#undef PARSEKERNEL +#if defined(KERNEL) || defined(_KERNEL) +#ifndef PARSESTREAM +#define PARSESTREAM +#endif +#endif +#if defined(PARSESTREAM) && defined(HAVE_SYS_STREAM_H) +#define PARSEKERNEL +#endif +#ifdef PARSEKERNEL +#ifndef _KERNEL +extern caddr_t kmem_alloc P((unsigned int)); +extern caddr_t kmem_free P((caddr_t, unsigned int)); +extern unsigned int splx P((unsigned int)); +extern unsigned int splhigh P((void)); +extern unsigned int splclock P((void)); +#define MALLOC(_X_) (char *)kmem_alloc(_X_) +#define FREE(_X_, _Y_) kmem_free((caddr_t)_X_, _Y_) +#else +#include <sys/kmem.h> +#define MALLOC(_X_) (char *)kmem_alloc(_X_, KM_SLEEP) +#define FREE(_X_, _Y_) kmem_free((caddr_t)_X_, _Y_) +#endif +#else +#define MALLOC(_X_) malloc(_X_) +#define FREE(_X_, _Y_) free(_X_) +#endif + +#if defined(PARSESTREAM) && defined(HAVE_SYS_STREAM_H) +#include <sys/stream.h> +#include <sys/stropts.h> +#else /* STREAM */ +#include <stdio.h> +#include "ntp_syslog.h" +#ifdef DEBUG +#define DD_PARSE 5 +#define DD_RAWDCF 4 +#define parseprintf(LEVEL, ARGS) if (debug > LEVEL) printf ARGS +#else /* DEBUG */ +#define parseprintf(LEVEL, ARGS) +#endif /* DEBUG */ +#endif /* PARSESTREAM */ + +#if defined(timercmp) && defined(__GNUC__) +#undef timercmp +#endif + +#if !defined(timercmp) +#define timercmp(tvp, uvp, cmp) \ + ((tvp)->tv_sec cmp (uvp)->tv_sec || \ + ((tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)) +#endif + +#ifndef TIMES10 +#define TIMES10(_X_) (((_X_) << 3) + ((_X_) << 1)) +#endif + +/* + * state flags + */ +#define PARSEB_POWERUP 0x00000001 /* no synchronisation */ +#define PARSEB_NOSYNC 0x00000002 /* timecode currently not confirmed */ + +/* + * time zone information + */ +#define PARSEB_ANNOUNCE 0x00000010 /* switch time zone warning (DST switch) */ +#define PARSEB_DST 0x00000020 /* DST in effect */ +#define PARSEB_UTC 0x00000040 /* UTC time */ + +/* + * leap information + */ +#define PARSEB_LEAPDEL 0x00000100 /* LEAP deletion warning */ +#define PARSEB_LEAPADD 0x00000200 /* LEAP addition warning */ +#define PARSEB_LEAPS 0x00000300 /* LEAP warnings */ +#define PARSEB_LEAPSECOND 0x00000400 /* actual leap second */ +/* + * optional status information + */ +#define PARSEB_ALTERNATE 0x00001000 /* alternate antenna used */ +#define PARSEB_POSITION 0x00002000 /* position available */ +#define PARSEB_MESSAGE 0x00004000 /* addtitional message data */ +/* + * feature information + */ +#define PARSEB_S_LEAP 0x00010000 /* supports LEAP */ +#define PARSEB_S_ANTENNA 0x00020000 /* supports antenna information */ +#define PARSEB_S_PPS 0x00040000 /* supports PPS time stamping */ +#define PARSEB_S_POSITION 0x00080000 /* supports position information (GPS) */ + +/* + * time stamp availability + */ +#define PARSEB_TIMECODE 0x10000000 /* valid time code sample */ +#define PARSEB_PPS 0x20000000 /* valid PPS sample */ + +#define PARSE_TCINFO (PARSEB_ANNOUNCE|PARSEB_POWERUP|PARSEB_NOSYNC|PARSEB_DST|\ + PARSEB_UTC|PARSEB_LEAPS|PARSEB_ALTERNATE|PARSEB_S_LEAP|\ + PARSEB_S_LOCATION|PARSEB_TIMECODE|PARSEB_MESSAGE) + +#define PARSE_POWERUP(x) ((x) & PARSEB_POWERUP) +#define PARSE_NOSYNC(x) (((x) & (PARSEB_POWERUP|PARSEB_NOSYNC)) == PARSEB_NOSYNC) +#define PARSE_SYNC(x) (((x) & (PARSEB_POWERUP|PARSEB_NOSYNC)) == 0) +#define PARSE_ANNOUNCE(x) ((x) & PARSEB_ANNOUNCE) +#define PARSE_DST(x) ((x) & PARSEB_DST) +#define PARSE_UTC(x) ((x) & PARSEB_UTC) +#define PARSE_LEAPADD(x) (PARSE_SYNC(x) && (((x) & PARSEB_LEAPS) == PARSEB_LEAPADD)) +#define PARSE_LEAPDEL(x) (PARSE_SYNC(x) && (((x) & PARSEB_LEAPS) == PARSEB_LEAPDEL)) +#define PARSE_ALTERNATE(x) ((x) & PARSEB_ALTERNATE) +#define PARSE_LEAPSECOND(x) (PARSE_SYNC(x) && ((x) & PARSEB_LEAP_SECOND)) + +#define PARSE_S_LEAP(x) ((x) & PARSEB_S_LEAP) +#define PARSE_S_ANTENNA(x) ((x) & PARSEB_S_ANTENNA) +#define PARSE_S_PPS(x) ((x) & PARSEB_S_PPS) +#define PARSE_S_POSITION(x) ((x) & PARSEB_S_POSITION) + +#define PARSE_TIMECODE(x) ((x) & PARSEB_TIMECODE) +#define PARSE_PPS(x) ((x) & PARSEB_PPS) +#define PARSE_POSITION(x) ((x) & PARSEB_POSITION) +#define PARSE_MESSAGE(x) ((x) & PARSEB_MESSAGE) + +/* + * operation flags - lower nibble contains fudge flags + */ +#define PARSE_STATISTICS 0x08 /* enable statistics */ +#define PARSE_LEAP_DELETE 0x04 /* delete leap */ +#define PARSE_FIXED_FMT 0x10 /* fixed format */ +#define PARSE_PPSCLOCK 0x20 /* try to get PPS time stamp via ppsclock ioctl */ + +/* + * size of buffers + */ +#define PARSE_TCMAX 400 /* maximum addition data size */ + +typedef union timestamp +{ + struct timeval tv; /* timeval - kernel view */ + l_fp fp; /* fixed point - ntp view */ +} timestamp_t; + +/* + * standard time stamp structure + */ +struct parsetime +{ + u_long parse_status; /* data status - CVT_OK, CVT_NONE, CVT_FAIL ... */ + timestamp_t parse_time; /* PARSE timestamp */ + timestamp_t parse_stime; /* telegram sample timestamp */ + timestamp_t parse_ptime; /* PPS time stamp */ + long parse_usecerror; /* sampled usec error */ + u_long parse_state; /* current receiver state */ + unsigned short parse_format; /* format code */ + unsigned short parse_msglen; /* length of message */ + unsigned char parse_msg[PARSE_TCMAX]; /* original messages */ +}; + +typedef struct parsetime parsetime_t; + +/*---------- STREAMS interface ----------*/ + +#ifdef HAVE_SYS_STREAM_H +/* + * ioctls + */ +#define PARSEIOC_ENABLE (('D'<<8) + 'E') +#define PARSEIOC_DISABLE (('D'<<8) + 'D') +#define PARSEIOC_SETFMT (('D'<<8) + 'f') +#define PARSEIOC_GETFMT (('D'<<8) + 'F') +#define PARSEIOC_SETCS (('D'<<8) + 'C') +#define PARSEIOC_TIMECODE (('D'<<8) + 'T') + +#endif + +/*------ IO handling flags (sorry) ------*/ + +#define PARSE_IO_CSIZE 0x00000003 +#define PARSE_IO_CS5 0x00000000 +#define PARSE_IO_CS6 0x00000001 +#define PARSE_IO_CS7 0x00000002 +#define PARSE_IO_CS8 0x00000003 + +/* + * ioctl structure + */ +union parsectl +{ + struct parsegettc + { + u_long parse_state; /* last state */ + u_long parse_badformat; /* number of bad packets since last query */ + unsigned short parse_format;/* last decoded format */ + unsigned short parse_count; /* count of valid time code bytes */ + char parse_buffer[PARSE_TCMAX+1]; /* timecode buffer */ + } parsegettc; + + struct parseformat + { + unsigned short parse_format;/* number of examined format */ + unsigned short parse_count; /* count of valid string bytes */ + char parse_buffer[PARSE_TCMAX+1]; /* format code string */ + } parseformat; + + struct parsesetcs + { + u_long parse_cs; /* character size (needed for stripping) */ + } parsesetcs; +}; + +typedef union parsectl parsectl_t; + +/*------ for conversion routines --------*/ + +struct parse /* parse module local data */ +{ + int parse_flags; /* operation and current status flags */ + + int parse_ioflags; /* io handling flags (5-8 Bit control currently) */ + + /* + * private data - fixed format only + */ + unsigned short parse_plen; /* length of private data */ + void *parse_pdata; /* private data pointer */ + + /* + * time code input buffer (from RS232 or PPS) + */ + unsigned short parse_index; /* current buffer index */ + char *parse_data; /* data buffer */ + unsigned short parse_dsize; /* size of data buffer */ + unsigned short parse_lformat; /* last format used */ + u_long parse_lstate; /* last state code */ + char *parse_ldata; /* last data buffer */ + unsigned short parse_ldsize; /* last data buffer length */ + u_long parse_badformat; /* number of unparsable pakets */ + + timestamp_t parse_lastchar; /* last time a character was received */ + parsetime_t parse_dtime; /* external data prototype */ +}; + +typedef struct parse parse_t; + +struct clocktime /* clock time broken up from time code */ +{ + long day; + long month; + long year; + long hour; + long minute; + long second; + long usecond; + long utcoffset; /* in seconds */ + time_t utctime; /* the actual time - alternative to date/time */ + u_long flags; /* current clock status */ +}; + +typedef struct clocktime clocktime_t; + +/* + * parser related return/error codes + */ +#define CVT_MASK (unsigned)0x0000000F /* conversion exit code */ +#define CVT_NONE (unsigned)0x00000001 /* format not applicable */ +#define CVT_FAIL (unsigned)0x00000002 /* conversion failed - error code returned */ +#define CVT_OK (unsigned)0x00000004 /* conversion succeeded */ +#define CVT_SKIP (unsigned)0x00000008 /* conversion succeeded */ +#define CVT_ADDITIONAL (unsigned)0x00000010 /* additional data is available */ +#define CVT_BADFMT (unsigned)0x00000100 /* general format error - (unparsable) */ +#define CVT_BADDATE (unsigned)0x00000200 /* date field incorrect */ +#define CVT_BADTIME (unsigned)0x00000400 /* time field incorrect */ + +/* + * return codes used by special input parsers + */ +#define PARSE_INP_SKIP 0x00 /* discard data - may have been consumed */ +#define PARSE_INP_TIME 0x01 /* time code assembled */ +#define PARSE_INP_PARSE 0x02 /* parse data using normal algorithm */ +#define PARSE_INP_DATA 0x04 /* additional data to pass up */ +#define PARSE_INP_SYNTH 0x08 /* just pass up synthesized time */ + +/* + * PPS edge info + */ +#define SYNC_ZERO 0x00 +#define SYNC_ONE 0x01 + +struct clockformat +{ + /* special input protocol - implies fixed format */ + u_long (*input) P((parse_t *, unsigned int, timestamp_t *)); + /* conversion routine */ + u_long (*convert) P((unsigned char *, int, struct format *, clocktime_t *, void *)); + /* routine for handling RS232 sync events (time stamps) */ + /* PPS input routine */ + u_long (*syncpps) P((parse_t *, int, timestamp_t *)); + /* time code synthesizer */ + + void *data; /* local parameters */ + const char *name; /* clock format name */ + unsigned short length; /* maximum length of data packet */ + unsigned short plen; /* length of private data - implies fixed format */ +}; + +typedef struct clockformat clockformat_t; + +/* + * parse interface + */ +extern int parse_ioinit P((parse_t *)); +extern void parse_ioend P((parse_t *)); +extern int parse_ioread P((parse_t *, unsigned int, timestamp_t *)); +extern int parse_iopps P((parse_t *, int, timestamp_t *)); +extern void parse_iodone P((parse_t *)); +extern int parse_timecode P((parsectl_t *, parse_t *)); +extern int parse_getfmt P((parsectl_t *, parse_t *)); +extern int parse_setfmt P((parsectl_t *, parse_t *)); +extern int parse_setcs P((parsectl_t *, parse_t *)); + +extern unsigned int parse_restart P((parse_t *, unsigned int)); +extern unsigned int parse_addchar P((parse_t *, unsigned int)); +extern unsigned int parse_end P((parse_t *)); + +extern int Strok P((const unsigned char *, const unsigned char *)); +extern int Stoi P((const unsigned char *, long *, int)); + +extern time_t parse_to_unixtime P((clocktime_t *, u_long *)); +extern u_long updatetimeinfo P((parse_t *, u_long)); +extern void syn_simple P((parse_t *, timestamp_t *, struct format *, u_long)); +extern u_long pps_simple P((parse_t *, int, timestamp_t *)); +extern u_long pps_one P((parse_t *, int, timestamp_t *)); +extern u_long pps_zero P((parse_t *, int, timestamp_t *)); +extern int parse_timedout P((parse_t *, timestamp_t *, struct timeval *)); + +#endif + +/* + * History: + * + * parse.h,v + * Revision 4.5 1998/08/09 22:23:32 kardel + * 4.0.73e2 adjustments + * + * Revision 4.4 1998/06/14 21:09:27 kardel + * Sun acc cleanup + * + * Revision 4.3 1998/06/13 11:49:25 kardel + * STREAM macro gone in favor of HAVE_SYS_STREAM_H + * + * Revision 4.2 1998/06/12 15:14:25 kardel + * fixed prototypes + * + * Revision 4.1 1998/05/24 10:07:59 kardel + * removed old data structure cruft (new input model) + * new PARSE_INP* macros for input handling + * removed old SYNC_* macros from old input model + * (struct clockformat): removed old parse functions in favor of the + * new input model + * updated prototypes + * + * form V3 3.31 - log info deleted 1998/04/11 kardel + */ diff --git a/include/parse_conf.h b/include/parse_conf.h new file mode 100644 index 000000000000..0a30eb635203 --- /dev/null +++ b/include/parse_conf.h @@ -0,0 +1,54 @@ +/* + * /src/NTP/ntp-4/include/parse_conf.h,v 4.2 1998/06/14 21:09:28 kardel RELEASE_19990228_A + * + * parse_conf.h,v 4.2 1998/06/14 21:09:28 kardel RELEASE_19990228_A + * + * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998 by Frank Kardel + * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + */ + +#ifndef __PARSE_CONF_H__ +#define __PARSE_CONF_H__ +#if !(defined(lint) || defined(__GNUC__)) + static char prshrcsid[] = "parse_conf.h,v 4.2 1998/06/14 21:09:28 kardel RELEASE_19990228_A"; +#endif + +/* + * field location structure + */ +#define O_DAY 0 +#define O_MONTH 1 +#define O_YEAR 2 +#define O_HOUR 3 +#define O_MIN 4 +#define O_SEC 5 +#define O_WDAY 6 +#define O_FLAGS 7 +#define O_ZONE 8 +#define O_UTCHOFFSET 9 +#define O_UTCMOFFSET 10 +#define O_UTCSOFFSET 11 +#define O_COUNT (O_UTCSOFFSET+1) + +#define MBG_EXTENDED 0x00000001 + +/* + * see below for field offsets + */ + +struct format +{ + struct foff + { + unsigned short offset; /* offset into buffer */ + unsigned short length; /* length of field */ + } field_offsets[O_COUNT]; + const unsigned char *fixed_string; /* string with must be chars (blanks = wildcards) */ + u_long flags; +}; +#endif diff --git a/include/recvbuff.h b/include/recvbuff.h new file mode 100644 index 000000000000..4fde7f19250a --- /dev/null +++ b/include/recvbuff.h @@ -0,0 +1,113 @@ +#if !defined __recvbuff_h +#define __recvbuff_h + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include "ntp.h" +#include "ntp_fp.h" +#include "ntp_types.h" + +/* + * recvbuf memory management + */ +#define RECV_INIT 10 /* 10 buffers initially */ +#define RECV_LOWAT 3 /* when we're down to three buffers get more */ +#define RECV_INC 5 /* get 5 more at a time */ +#define RECV_TOOMANY 40 /* this is way too many buffers */ + +#if defined HAVE_IO_COMPLETION_PORT +# include "ntp_iocompletionport.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 P((void)); +#else +# define RECV_BLOCK_IO() +# define RECV_UNBLOCK_IO() +#endif + + +/* + * Format of a recvbuf. These are used by the asynchronous receive + * routine to store incoming packets and related information. + */ + +/* + * the maximum length NTP packet contains the NTP header, one Autokey + * request, one Autokey response and the MAC. Assuming certificates don't + * get too big, the maximum packet length is set arbitrarily at 1000. + */ +#define RX_BUFF_SIZE 1000 /* hail Mary */ + +struct recvbuf { + struct recvbuf *next; /* next buffer in chain */ + union { + struct sockaddr_storage 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 +#if defined HAVE_IO_COMPLETION_PORT + IoCompletionInfo iocompletioninfo; + WSABUF wsabuff; + DWORD AddressLength; +#else + struct sockaddr_storage srcadr; /* where packet came from */ +#endif + struct interface *dstadr; /* interface datagram arrived thru */ + SOCKET fd; /* fd on which it was received */ + l_fp recv_time; /* time of arrival */ + void (*receiver) P((struct recvbuf *)); /* routine to receive buffer */ + int recv_length; /* number of octets received */ + union { + 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 +}; + +extern void init_recvbuff P((int)); + +/* freerecvbuf - make a single recvbuf available for reuse + */ +extern void freerecvbuf P((struct recvbuf *)); + + +extern struct recvbuf * getrecvbufs P((void)); + +/* Get a free buffer (typically used so an async + * read can directly place data into the buffer + * + * The buffer is removed from the free list. Make sure + * you put it back with freerecvbuf() or + */ +extern struct recvbuf *get_free_recv_buffer P((void)); + +/* Add a buffer to the full list + */ +extern void add_full_recv_buffer P((struct recvbuf *)); + +/*extern void process_recv_buffers P((void)); */ + +/* number of recvbufs on freelist */ +extern u_long free_recvbuffs P((void)); +extern u_long full_recvbuffs P((void)); +extern u_long total_recvbuffs P((void)); +extern u_long lowater_additions P((void)); + +/* Returns the next buffer in the full list. + * + */ +extern struct recvbuf *get_full_recv_buffer P((void)); + +#endif /* defined __recvbuff_h */ + diff --git a/include/rsa_md5.h b/include/rsa_md5.h new file mode 100644 index 000000000000..8241647601b3 --- /dev/null +++ b/include/rsa_md5.h @@ -0,0 +1,51 @@ +/* MD5.H - header file for MD5C.C + */ + +/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All + rights reserved. + + License to copy and use this software is granted provided that it + is identified as the "RSA Data Security, Inc. MD5 Message-Digest + Algorithm" in all material mentioning or referencing this software + or this function. + + License is also granted to make and use derivative works provided + that such works are identified as "derived from the RSA Data + Security, Inc. MD5 Message-Digest Algorithm" in all material + mentioning or referencing the derived work. + + RSA Data Security, Inc. makes no representations concerning either + the merchantability of this software or the suitability of this + software for any particular purpose. It is provided "as is" + without express or implied warranty of any kind. + + These notices must be retained in any copies of any part of this + documentation and/or software. + */ + +#ifndef _MD5_H_ +#define _MD5_H_ 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/*#include "global.h" */ + +/* MD5 context. */ +typedef struct { + UINT4 state[4]; /* state (ABCD) */ + UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD5_CTX; + +void MD5Init PROTO_LIST ((MD5_CTX *)); +void MD5Update PROTO_LIST + ((MD5_CTX *, unsigned char *, unsigned int)); +void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *)); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/trimble.h b/include/trimble.h new file mode 100644 index 000000000000..58a1a3aa8cf9 --- /dev/null +++ b/include/trimble.h @@ -0,0 +1,125 @@ +/* + * /src/NTP/ntp-4/include/trimble.h,v 4.4 1999/02/28 11:41:11 kardel RELEASE_19990228_A + * + * $Created: Sun Aug 2 16:16:49 1998 $ + * + * Copyright (C) 1998 by Frank Kardel + */ +#ifndef TRIMBLE_H +#define TRIMBLE_H + +/* + * Trimble packet command codes - commands being sent/received + * keep comments formatted as shown - they are used to generate + * translation tables + */ +#define CMD_CCLROSC 0x1D /* clear oscillator offset */ +#define CMD_CCLRRST 0x1E /* clear battery backup and RESET */ +#define CMD_CVERSION 0x1F /* return software version */ +#define CMD_CALMANAC 0x20 /* almanac */ +#define CMD_CCURTIME 0x21 /* current time */ +#define CMD_CMODESEL 0x22 /* mode select (2-d, 3-D, auto) */ +#define CMD_CINITPOS 0x23 /* initial position */ +#define CMD_CRECVPOS 0x24 /* receiver position fix mode */ +#define CMD_CRESET 0x25 /* soft reset & selftest */ +#define CMD_CRECVHEALTH 0x26 /* receiver health */ +#define CMD_CSIGNALLV 0x27 /* signal levels */ +#define CMD_CMESSAGE 0x28 /* GPS system message */ +#define CMD_CALMAHEALTH 0x29 /* almanac healt page */ +#define CMD_C2DALTITUDE 0x2A /* altitude for 2-D mode */ +#define CMD_CINITPOSLLA 0x2B /* initial position LLA */ +#define CMD_COPERPARAM 0x2C /* operating parameters */ +#define CMD_COSCOFFSET 0x2D /* oscillator offset */ +#define CMD_CSETGPSTIME 0x2E /* set GPS time */ +#define CMD_CUTCPARAM 0x2F /* UTC parameters */ +#define CMD_CACCPOSXYZ 0x31 /* accurate initial position (XYZ/ECEF) */ +#define CMD_CACCPOS 0x32 /* accurate initial position */ +#define CMD_CANALOGDIG 0x33 /* analog to digital */ +#define CMD_CSAT1SAT 0x34 /* satellite for 1-Sat mode */ +#define CMD_CIOOPTIONS 0x35 /* I/O options */ +#define CMD_CVELOCAID 0x36 /* velocity aiding of acquisition */ +#define CMD_CSTATLSTPOS 0x37 /* status and values of last pos. and vel. */ +#define CMD_CLOADSSATDT 0x38 /* load satellite system data */ +#define CMD_CSATDISABLE 0x39 /* satellite disable */ +#define CMD_CLASTRAW 0x3A /* last raw measurement */ +#define CMD_CSTATSATEPH 0x3B /* satellite ephemeris status */ +#define CMD_CSTATTRACK 0x3C /* tracking status */ +#define CMD_CCHANADGPS 0x3D /* configure channel A for differential GPS */ +#define CMD_CADDITFIX 0x3E /* additional fix data */ +#define CMD_CDGPSFIXMD 0x62 /* set/request differential GPS position fix mode */ +#define CMD_CDGPSCORR 0x65 /* differential correction status */ +#define CMD_CPOSFILT 0x71 /* position filter parameters */ +#define CMD_CHEIGHTFILT 0x73 /* height filter control */ +#define CMD_CHIGH8CNT 0x75 /* high-8 (best 4) / high-6 (overdetermined) control */ +#define CMD_CMAXDGPSCOR 0x77 /* maximum rate of DGPS corrections */ +#define CMD_CSUPER 0x8E /* super paket */ + +#define CMD_RDATAA 0x3D /* data channel A configuration:trimble_channelA:RO */ +#define CMD_RALMANAC 0x40 /* almanac data for sat:gps_almanac:RO */ +#define CMD_RCURTIME 0x41 /* GPS time:gps_time:RO */ +#define CMD_RSPOSXYZ 0x42 /* single precision XYZ position:gps_position(XYZ):RO|DEF */ +#define CMD_RVELOXYZ 0x43 /* velocity fix (XYZ ECEF):gps_velocity(XYZ):RO|DEF */ +#define CMD_RBEST4 0x44 /* best 4 satellite selection:trimble_best4:RO|DEF */ +#define CMD_RVERSION 0x45 /* software version:trimble_version:RO|DEF */ +#define CMD_RRECVHEALTH 0x46 /* receiver health:trimble_receiver_health:RO|DEF */ +#define CMD_RSIGNALLV 0x47 /* signal levels of all satellites:trimble_signal_levels:RO */ +#define CMD_RMESSAGE 0x48 /* GPS system message:gps-message:RO|DEF */ +#define CMD_RALMAHEALTH 0x49 /* almanac health page for all satellites:gps_almanac_health:RO */ +#define CMD_RSLLAPOS 0x4A /* single LLA position:gps_position(LLA):RO|DEF */ +#define CMD_RMACHSTAT 0x4B /* machine code / status:trimble_status:RO|DEF */ +#define CMD_ROPERPARAM 0x4C /* operating parameters:trimble_opparam:RO */ +#define CMD_ROSCOFFSET 0x4D /* oscillator offset:trimble_oscoffset:RO */ +#define CMD_RSETGPSTIME 0x4E /* response to set GPS time:trimble_setgpstime:RO */ +#define CMD_RUTCPARAM 0x4F /* UTC parameters:gps_utc_correction:RO|DEF */ +#define CMD_RANALOGDIG 0x53 /* analog to digital:trimble_analogdigital:RO */ +#define CMD_RSAT1BIAS 0x54 /* one-satellite bias & bias rate:trimble_sat1bias:RO */ +#define CMD_RIOOPTIONS 0x55 /* I/O options:trimble_iooptions:RO */ +#define CMD_RVELOCFIX 0x56 /* velocity fix (ENU):trimble_velocfix */ +#define CMD_RSTATLSTFIX 0x57 /* status and values of last pos. and vel.:trimble_status_lastpos:RO */ +#define CMD_RLOADSSATDT 0x58 /* response to load satellite system data:trimble_loaddata:RO */ +#define CMD_RSATDISABLE 0x59 /* satellite disable:trimble_satdisble:RO */ +#define CMD_RLASTRAW 0x5A /* last raw measurement:trimble_lastraw:RO */ +#define CMD_RSTATSATEPH 0x5B /* satellite ephemeris status:trimble_ephstatus:RO */ +#define CMD_RSTATTRACK 0x5C /* tracking status:trimble_tracking_status:RO|DEF */ +#define CMD_RADDITFIX 0x5E /* additional fix data:trimble_addfix:RO */ +#define CMD_RALLINVIEW 0x6D /* all in view satellite selection:trimble_satview:RO|DEF */ +#define CMD_RPOSFILT 0x72 /* position filter parameters:trimble_posfilt:RO */ +#define CMD_RHEIGHTFILT 0x74 /* height filter control:trimble_heightfilt:RO */ +#define CMD_RHIGH8CNT 0x76 /* high-8 (best 4) / high-6 (overdetermined) control:trimble_high8control:RO */ +#define CMD_RMAXAGE 0x78 /* DC MaxAge:trimble_dgpsmaxage:RO */ +#define CMD_RDGPSFIX 0x82 /* differential position fix mode:trimble_dgpsfixmode:RO */ +#define CMD_RDOUBLEXYZ 0x83 /* double precision XYZ:gps_position_ext(XYZ):RO|DEF */ +#define CMD_RDOUBLELLA 0x84 /* double precision LLA:gps_position_ext(LLA):RO|DEF */ +#define CMD_RDGPSSTAT 0x85 /* differential correction status:trimble_dgpsstatus:RO */ +#define CMD_RSUPER 0x8F /* super paket::0 */ + +typedef struct cmd_info +{ + unsigned char cmd; /* command code */ + const char *cmdname; /* command name */ + const char *cmddesc; /* command description */ + const char *varname; /* name of variable */ + int varmode; /* mode of variable */ +} cmd_info_t; + +extern cmd_info_t trimble_rcmds[]; +extern cmd_info_t trimble_scmds[]; + +extern cmd_info_t *trimble_convert P((unsigned int cmd, cmd_info_t *tbl)); + +#endif +/* + * trimble.h,v + * Revision 4.4 1999/02/28 11:41:11 kardel + * (CMD_RUTCPARAM): control variable name unification + * + * Revision 4.3 1998/12/20 23:45:25 kardel + * fix types and warnings + * + * Revision 4.2 1998/08/16 18:45:05 kardel + * (CMD_RSTATTRACK): renamed mode 6 variable name + * + * Revision 4.1 1998/08/09 22:24:35 kardel + * Trimble TSIP support + * + */ |