diff options
Diffstat (limited to 'includes')
34 files changed, 10145 insertions, 0 deletions
diff --git a/includes/Makefile.am b/includes/Makefile.am new file mode 100644 index 0000000..4a462d5 --- /dev/null +++ b/includes/Makefile.am @@ -0,0 +1,11 @@ +nobase_include_HEADERS = omapip/alloc.h omapip/buffer.h omapip/convert.h \ + omapip/hash.h omapip/isclib.h omapip/omapip.h \ + omapip/omapip_p.h omapip/result.h omapip/trace.h \ + isc-dhcp/dst.h + +EXTRA_DIST = cdefs.h ctrace.h dhcp.h dhcp6.h dhcpd.h dhctoken.h failover.h \ + heap.h inet.h minires.h osdep.h site.h statement.h tree.h \ + t_api.h \ + arpa/nameser.h arpa/nameser_compat.h \ + netinet/if_ether.h netinet/ip.h netinet/ip_icmp.h netinet/udp.h + diff --git a/includes/Makefile.in b/includes/Makefile.in new file mode 100644 index 0000000..b453cdd --- /dev/null +++ b/includes/Makefile.in @@ -0,0 +1,552 @@ +# Makefile.in generated by automake 1.14 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2013 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@ + +VPATH = @srcdir@ +am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +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@ +subdir = includes +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ + $(srcdir)/config.h.in $(nobase_include_HEADERS) +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(includedir)" +HEADERS = $(nobase_include_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \ + $(LISP)config.h.in +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +ATF_BIN = @ATF_BIN@ +ATF_CFLAGS = @ATF_CFLAGS@ +ATF_LDFLAGS = @ATF_LDFLAGS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDAP_CFLAGS = @LDAP_CFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_prefix_program = @ac_prefix_program@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +byte_order = @byte_order@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +nobase_include_HEADERS = omapip/alloc.h omapip/buffer.h omapip/convert.h \ + omapip/hash.h omapip/isclib.h omapip/omapip.h \ + omapip/omapip_p.h omapip/result.h omapip/trace.h \ + isc-dhcp/dst.h + +EXTRA_DIST = cdefs.h ctrace.h dhcp.h dhcp6.h dhcpd.h dhctoken.h failover.h \ + heap.h inet.h minires.h osdep.h site.h statement.h tree.h \ + t_api.h \ + arpa/nameser.h arpa/nameser_compat.h \ + netinet/if_ether.h netinet/ip.h netinet/ip_icmp.h netinet/udp.h + +all: config.h + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign includes/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign includes/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +config.h: stamp-h1 + @test -f $@ || rm -f stamp-h1 + @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1 + +stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status + @rm -f stamp-h1 + cd $(top_builddir) && $(SHELL) ./config.status includes/config.h +$(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) + rm -f stamp-h1 + touch $@ + +distclean-hdr: + -rm -f config.h stamp-h1 +install-nobase_includeHEADERS: $(nobase_include_HEADERS) + @$(NORMAL_INSTALL) + @list='$(nobase_include_HEADERS)'; test -n "$(includedir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(includedir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(includedir)" || exit 1; \ + fi; \ + $(am__nobase_list) | while read dir files; do \ + xfiles=; for file in $$files; do \ + if test -f "$$file"; then xfiles="$$xfiles $$file"; \ + else xfiles="$$xfiles $(srcdir)/$$file"; fi; done; \ + test -z "$$xfiles" || { \ + test "x$$dir" = x. || { \ + echo " $(MKDIR_P) '$(DESTDIR)$(includedir)/$$dir'"; \ + $(MKDIR_P) "$(DESTDIR)$(includedir)/$$dir"; }; \ + echo " $(INSTALL_HEADER) $$xfiles '$(DESTDIR)$(includedir)/$$dir'"; \ + $(INSTALL_HEADER) $$xfiles "$(DESTDIR)$(includedir)/$$dir" || exit $$?; }; \ + done + +uninstall-nobase_includeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(nobase_include_HEADERS)'; test -n "$(includedir)" || list=; \ + $(am__nobase_strip_setup); files=`$(am__nobase_strip)`; \ + dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir) + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$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) config.h +installdirs: + for dir in "$(DESTDIR)$(includedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +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: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_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-hdr distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-nobase_includeHEADERS + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +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-nobase_includeHEADERS + +.MAKE: all install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + cscopelist-am ctags ctags-am distclean distclean-generic \ + distclean-hdr distclean-tags distdir dvi dvi-am html html-am \ + info info-am install install-am install-data install-data-am \ + install-dvi install-dvi-am install-exec install-exec-am \ + install-html install-html-am install-info install-info-am \ + install-man install-nobase_includeHEADERS install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ + pdf-am ps ps-am tags tags-am uninstall uninstall-am \ + uninstall-nobase_includeHEADERS + + +# 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/includes/arpa/nameser.h b/includes/arpa/nameser.h new file mode 100644 index 0000000..ef9ac05 --- /dev/null +++ b/includes/arpa/nameser.h @@ -0,0 +1,463 @@ +/* + * Copyright (c) 1983, 1989, 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. 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. + */ + +/* + * Copyright (c) 2004,2009 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + */ + +/* + * $Id: nameser.h,v 1.6.24.1 2009/11/20 01:49:01 sar Exp $ + */ + +#ifndef _ARPA_NAMESER_H_ +#define _ARPA_NAMESER_H_ + +/* + * Revision information. This is the release date in YYYYMMDD format. + * It can change every day so the right thing to do with it is use it + * in preprocessor commands such as "#if (__NAMESER > 19931104)". Do not + * compare for equality; rather, use it to determine whether your libbind.a + * contains a new enough lib/nameser/ to support the feature you need. + */ + +#define __NAMESER 19991006 /* New interface version stamp. */ + +/* + * Define constants based on RFC 883, RFC 1034, RFC 1035 + */ +#define NS_PACKETSZ 512 /* maximum packet size */ +#define NS_MAXDNAME 1025 /* maximum domain name */ +#define NS_MAXCDNAME 255 /* maximum compressed domain name */ +#define NS_MAXLABEL 63 /* maximum length of domain label */ +#define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */ +#define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */ +#define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ +#define NS_INT32SZ 4 /* #/bytes of data in a u_int32_t */ +#define NS_INT16SZ 2 /* #/bytes of data in a u_int16_t */ +#define NS_INT8SZ 1 /* #/bytes of data in a u_int8_t */ +#define NS_INADDRSZ 4 /* IPv4 T_A */ +#define NS_IN6ADDRSZ 16 /* IPv6 T_AAAA */ +#define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */ +#define NS_DEFAULTPORT 53 /* For both TCP and UDP. */ + +/* + * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord() + * in synch with it. + */ +typedef enum __ns_sect { + ns_s_qd = 0, /* Query: Question. */ + ns_s_zn = 0, /* Update: Zone. */ + ns_s_an = 1, /* Query: Answer. */ + ns_s_pr = 1, /* Update: Prerequisites. */ + ns_s_ns = 2, /* Query: Name servers. */ + ns_s_ud = 2, /* Update: Update. */ + ns_s_ar = 3, /* Query|Update: Additional records. */ + ns_s_max = 4 +} ns_sect; + +/* + * This is a message handle. It is caller allocated and has no dynamic data. + * This structure is intended to be opaque to all but ns_parse.c, thus the + * leading _'s on the member names. Use the accessor functions, not the _'s. + */ +typedef struct __ns_msg { + const u_int8_t *_msg, *_eom; + u_int16_t _id, _flags, _counts[ns_s_max]; + const u_int8_t *_sections[ns_s_max]; + ns_sect _sect; + int _rrnum; + const u_int8_t *_ptr; +} ns_msg; + +/* Private data structure - do not use from outside library. */ +struct _ns_flagdata { int mask, shift; }; +extern struct _ns_flagdata _ns_flagdata[]; + +/* Accessor macros - this is part of the public interface. */ +#define ns_msg_getflag(handle, flag) ( \ + ((handle)._flags & _ns_flagdata[flag].mask) \ + >> _ns_flagdata[flag].shift \ + ) +#define ns_msg_id(handle) ((handle)._id + 0) +#define ns_msg_base(handle) ((handle)._msg + 0) +#define ns_msg_end(handle) ((handle)._eom + 0) +#define ns_msg_size(handle) ((handle)._eom - (handle)._msg) +#define ns_msg_count(handle, section) ((handle)._counts[section] + 0) + +/* + * This is a parsed record. It is caller allocated and has no dynamic data. + */ +typedef struct __ns_rr { + char name[NS_MAXDNAME]; + u_int16_t type; + u_int16_t rr_class; + u_int32_t ttl; + u_int16_t rdlength; + const u_int8_t *rdata; +} ns_rr; + +/* Accessor macros - this is part of the public interface. */ +#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") +#define ns_rr_type(rr) ((ns_type)((rr).type + 0)) +#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) +#define ns_rr_ttl(rr) ((rr).ttl + 0) +#define ns_rr_rdlen(rr) ((rr).rdlength + 0) +#define ns_rr_rdata(rr) ((rr).rdata + 0) + +/* + * These don't have to be in the same order as in the packet flags word, + * and they can even overlap in some cases, but they will need to be kept + * in synch with ns_parse.c:ns_flagdata[]. + */ +typedef enum __ns_flag { + ns_f_qr, /* Question/Response. */ + ns_f_opcode, /* Operation code. */ + ns_f_aa, /* Authoritative Answer. */ + ns_f_tc, /* Truncation occurred. */ + ns_f_rd, /* Recursion Desired. */ + ns_f_ra, /* Recursion Available. */ + ns_f_z, /* MBZ. */ + ns_f_ad, /* Authentic Data (DNSSEC). */ + ns_f_cd, /* Checking Disabled (DNSSEC). */ + ns_f_rcode, /* Response code. */ + ns_f_max +} ns_flag; + +/* + * Currently defined opcodes. + */ +typedef enum __ns_opcode { + ns_o_query = 0, /* Standard query. */ + ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */ + ns_o_status = 2, /* Name server status query (unsupported). */ + /* Opcode 3 is undefined/reserved. */ + ns_o_notify = 4, /* Zone change notification. */ + ns_o_update = 5, /* Zone update message. */ + ns_o_max = 6 +} ns_opcode; + +/* + * Currently defined response codes. + */ +typedef enum __ns_rcode { + ns_r_noerror = 0, /* No error occurred. */ + ns_r_formerr = 1, /* Format error. */ + ns_r_servfail = 2, /* Server failure. */ + ns_r_nxdomain = 3, /* Name error. */ + ns_r_notimpl = 4, /* Unimplemented. */ + ns_r_refused = 5, /* Operation refused. */ + /* these are for BIND_UPDATE */ + ns_r_yxdomain = 6, /* Name exists */ + ns_r_yxrrset = 7, /* RRset exists */ + ns_r_nxrrset = 8, /* RRset does not exist */ + ns_r_notauth = 9, /* Not authoritative for zone */ + ns_r_notzone = 10, /* Zone of record different from zone section */ + ns_r_max = 11, + /* The following are TSIG extended errors */ + ns_r_badsig = 16, + ns_r_badkey = 17, + ns_r_badtime = 18 +} ns_rcode; + +/* BIND_UPDATE */ +typedef enum __ns_update_operation { + ns_uop_delete = 0, + ns_uop_add = 1, + ns_uop_max = 2 +} ns_update_operation; + +/* + * This structure is used for TSIG authenticated messages + */ +struct ns_tsig_key { + char name[NS_MAXDNAME], alg[NS_MAXDNAME]; + unsigned char *data; + unsigned len; +}; +typedef struct ns_tsig_key ns_tsig_key; + +/* + * This structure is used for TSIG authenticated TCP messages + */ +struct ns_tcp_tsig_state { + int counter; + struct dst_key *key; + void *ctx; + unsigned char sig[NS_PACKETSZ]; + unsigned siglen; +}; +typedef struct ns_tcp_tsig_state ns_tcp_tsig_state; + +#define NS_TSIG_FUDGE 300 +#define NS_TSIG_TCP_COUNT 100 +#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT" + +#define NS_TSIG_ERROR_NO_TSIG -10 +#define NS_TSIG_ERROR_NO_SPACE -11 +#define NS_TSIG_ERROR_FORMERR -12 + +/* + * Currently defined type values for resources and queries. + */ +typedef enum __ns_type { + ns_t_invalid = 0, /* Cookie. */ + ns_t_a = 1, /* Host address. */ + ns_t_ns = 2, /* Authoritative server. */ + ns_t_md = 3, /* Mail destination. */ + ns_t_mf = 4, /* Mail forwarder. */ + ns_t_cname = 5, /* Canonical name. */ + ns_t_soa = 6, /* Start of authority zone. */ + ns_t_mb = 7, /* Mailbox domain name. */ + ns_t_mg = 8, /* Mail group member. */ + ns_t_mr = 9, /* Mail rename name. */ + ns_t_null = 10, /* Null resource record. */ + ns_t_wks = 11, /* Well known service. */ + ns_t_ptr = 12, /* Domain name pointer. */ + ns_t_hinfo = 13, /* Host information. */ + ns_t_minfo = 14, /* Mailbox information. */ + ns_t_mx = 15, /* Mail routing information. */ + ns_t_txt = 16, /* Text strings. */ + ns_t_rp = 17, /* Responsible person. */ + ns_t_afsdb = 18, /* AFS cell database. */ + ns_t_x25 = 19, /* X_25 calling address. */ + ns_t_isdn = 20, /* ISDN calling address. */ + ns_t_rt = 21, /* Router. */ + ns_t_nsap = 22, /* NSAP address. */ + ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */ + ns_t_sig = 24, /* Security signature. */ + ns_t_key = 25, /* Security key. */ + ns_t_px = 26, /* X.400 mail mapping. */ + ns_t_gpos = 27, /* Geographical position (withdrawn). */ + ns_t_aaaa = 28, /* Ip6 Address. */ + ns_t_loc = 29, /* Location Information. */ + ns_t_nxt = 30, /* Next domain (security). */ + ns_t_eid = 31, /* Endpoint identifier. */ + ns_t_nimloc = 32, /* Nimrod Locator. */ + ns_t_srv = 33, /* Server Selection. */ + ns_t_atma = 34, /* ATM Address */ + ns_t_naptr = 35, /* Naming Authority PoinTeR */ + ns_t_kx = 36, /* Key Exchange */ + ns_t_cert = 37, /* Certification record */ + ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */ + ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */ + ns_t_sink = 40, /* Kitchen sink (experimentatl) */ + ns_t_opt = 41, /* EDNS0 option (meta-RR) */ + ns_t_tsig = 250, /* Transaction signature. */ + ns_t_ixfr = 251, /* Incremental zone transfer. */ + ns_t_axfr = 252, /* Transfer zone of authority. */ + ns_t_mailb = 253, /* Transfer mailbox records. */ + ns_t_maila = 254, /* Transfer mail agent records. */ + ns_t_any = 255, /* Wildcard match. */ + ns_t_zxfr = 256, /* BIND-specific, nonstandard. */ + ns_t_max = 65536 +} ns_type; + +/* Exclusively a QTYPE? (not also an RTYPE) */ +#define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \ + (t) == ns_t_mailb || (t) == ns_t_maila) +/* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */ +#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) +/* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */ +#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) +#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) +#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ + (t) == ns_t_zxfr) + +/* + * Values for class field + */ +typedef enum __ns_class { + ns_c_invalid = 0, /* Cookie. */ + ns_c_in = 1, /* Internet. */ + ns_c_2 = 2, /* unallocated/unsupported. */ + ns_c_chaos = 3, /* MIT Chaos-net. */ + ns_c_hs = 4, /* MIT Hesiod. */ + /* Query class values which do not appear in resource records */ + ns_c_none = 254, /* for prereq. sections in update requests */ + ns_c_any = 255, /* Wildcard match. */ + ns_c_max = 65536 +} ns_class; + +/* DNSSEC constants. */ + +typedef enum __ns_key_types { + ns_kt_rsa = 1, /* key type RSA/MD5 */ + ns_kt_dh = 2, /* Diffie Hellman */ + ns_kt_dsa = 3, /* Digital Signature Standard (MANDATORY) */ + ns_kt_private = 254 /* Private key type starts with OID */ +} ns_key_types; + +typedef enum __ns_cert_types { + cert_t_pkix = 1, /* PKIX (X.509v3) */ + cert_t_spki = 2, /* SPKI */ + cert_t_pgp = 3, /* PGP */ + cert_t_url = 253, /* URL private type */ + cert_t_oid = 254 /* OID private type */ +} ns_cert_types; + +/* Flags field of the KEY RR rdata. */ +#define NS_KEY_TYPEMASK 0xC000 /* Mask for "type" bits */ +#define NS_KEY_TYPE_AUTH_CONF 0x0000 /* Key usable for both */ +#define NS_KEY_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */ +#define NS_KEY_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */ +#define NS_KEY_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */ +/* The type bits can also be interpreted independently, as single bits: */ +#define NS_KEY_NO_AUTH 0x8000 /* Key unusable for authentication */ +#define NS_KEY_NO_CONF 0x4000 /* Key unusable for confidentiality */ +#define NS_KEY_RESERVED2 0x2000 /* Security is *mandatory* if bit=0 */ +#define NS_KEY_EXTENDED_FLAGS 0x1000 /* reserved - must be zero */ +#define NS_KEY_RESERVED4 0x0800 /* reserved - must be zero */ +#define NS_KEY_RESERVED5 0x0400 /* reserved - must be zero */ +#define NS_KEY_NAME_TYPE 0x0300 /* these bits determine the type */ +#define NS_KEY_NAME_USER 0x0000 /* key is assoc. with user */ +#define NS_KEY_NAME_ENTITY 0x0200 /* key is assoc. with entity eg host */ +#define NS_KEY_NAME_ZONE 0x0100 /* key is zone key */ +#define NS_KEY_NAME_RESERVED 0x0300 /* reserved meaning */ +#define NS_KEY_RESERVED8 0x0080 /* reserved - must be zero */ +#define NS_KEY_RESERVED9 0x0040 /* reserved - must be zero */ +#define NS_KEY_RESERVED10 0x0020 /* reserved - must be zero */ +#define NS_KEY_RESERVED11 0x0010 /* reserved - must be zero */ +#define NS_KEY_SIGNATORYMASK 0x000F /* key can sign RR's of same name */ +#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \ + NS_KEY_RESERVED4 | \ + NS_KEY_RESERVED5 | \ + NS_KEY_RESERVED8 | \ + NS_KEY_RESERVED9 | \ + NS_KEY_RESERVED10 | \ + NS_KEY_RESERVED11 ) +#define NS_KEY_RESERVED_BITMASK2 0xFFFF /* no bits defined here */ + +/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */ +#define NS_ALG_MD5RSA 1 /* MD5 with RSA */ +#define NS_ALG_DH 2 /* Diffie Hellman KEY */ +#define NS_ALG_DSA 3 /* DSA KEY */ +#define NS_ALG_DSS NS_ALG_DSA +#define NS_ALG_EXPIRE_ONLY 253 /* No alg, no security */ +#define NS_ALG_PRIVATE_OID 254 /* Key begins with OID giving alg */ + +/* Protocol values */ +/* value 0 is reserved */ +#define NS_KEY_PROT_TLS 1 +#define NS_KEY_PROT_EMAIL 2 +#define NS_KEY_PROT_DNSSEC 3 +#define NS_KEY_PROT_IPSEC 4 +#define NS_KEY_PROT_ANY 255 + +/* Signatures */ +#define NS_MD5RSA_MIN_BITS 512 /* Size of a mod or exp in bits */ +#define NS_MD5RSA_MAX_BITS 2552 + /* Total of binary mod and exp */ +#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3) + /* Max length of text sig block */ +#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4) +#define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8) +#define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8) + +#define NS_DSA_SIG_SIZE 41 +#define NS_DSA_MIN_SIZE 213 +#define NS_DSA_MAX_BYTES 405 + +/* Offsets into SIG record rdata to find various values */ +#define NS_SIG_TYPE 0 /* Type flags */ +#define NS_SIG_ALG 2 /* Algorithm */ +#define NS_SIG_LABELS 3 /* How many labels in name */ +#define NS_SIG_OTTL 4 /* Original TTL */ +#define NS_SIG_EXPIR 8 /* Expiration time */ +#define NS_SIG_SIGNED 12 /* Signature time */ +#define NS_SIG_FOOT 16 /* Key footprint */ +#define NS_SIG_SIGNER 18 /* Domain name of who signed it */ + +/* How RR types are represented as bit-flags in NXT records */ +#define NS_NXT_BITS 8 +#define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_MAX 127 + +/* + * Inline versions of get/put short/long. Pointer is advanced. + */ +#define NS_GET16(s, cp) do { \ + register u_int8_t *t_cp = (u_int8_t *)(cp); \ + (s) = ((u_int16_t)t_cp[0] << 8) \ + | ((u_int16_t)t_cp[1]) \ + ; \ + (cp) += NS_INT16SZ; \ +} while (0) + +#define NS_GET32(l, cp) do { \ + register u_int8_t *t_cp = (u_int8_t *)(cp); \ + (l) = ((u_int32_t)t_cp[0] << 24) \ + | ((u_int32_t)t_cp[1] << 16) \ + | ((u_int32_t)t_cp[2] << 8) \ + | ((u_int32_t)t_cp[3]) \ + ; \ + (cp) += NS_INT32SZ; \ +} while (0) + +#define NS_PUT16(s, cp) do { \ + register u_int16_t t_s = (u_int16_t)(s); \ + register u_int8_t *t_cp = (u_int8_t *)(cp); \ + *t_cp++ = t_s >> 8; \ + *t_cp = t_s; \ + (cp) += NS_INT16SZ; \ +} while (0) + +#define NS_PUT32(l, cp) do { \ + register u_int32_t t_l = (u_int32_t)(l); \ + register u_int8_t *t_cp = (u_int8_t *)(cp); \ + *t_cp++ = t_l >> 24; \ + *t_cp++ = t_l >> 16; \ + *t_cp++ = t_l >> 8; \ + *t_cp = t_l; \ + (cp) += NS_INT32SZ; \ +} while (0) + +#include <arpa/nameser_compat.h> + +#endif /* !_ARPA_NAMESER_H_ */ diff --git a/includes/arpa/nameser_compat.h b/includes/arpa/nameser_compat.h new file mode 100644 index 0000000..fa30d99 --- /dev/null +++ b/includes/arpa/nameser_compat.h @@ -0,0 +1,179 @@ +/* Copyright (c) 1983, 1989 + * 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. 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. + */ + +/* + * from nameser.h 8.1 (Berkeley) 6/2/93 + * $Id: nameser_compat.h,v 1.2 2000/01/27 23:28:08 mellon Exp $ + */ + +#ifndef _ARPA_NAMESER_COMPAT_ +#define _ARPA_NAMESER_COMPAT_ + +/* + * Structure for query header. The order of the fields is machine- and + * compiler-dependent, depending on the byte/bit order and the layout + * of bit fields. We use bit fields only in int variables, as this + * is all ANSI requires. This requires a somewhat confusing rearrangement. + */ + +typedef struct { + unsigned id :16; /* query identification number */ +#if BYTE_ORDER == BIG_ENDIAN + /* fields in third byte */ + unsigned qr: 1; /* response flag */ + unsigned opcode: 4; /* purpose of message */ + unsigned aa: 1; /* authoritive answer */ + unsigned tc: 1; /* truncated message */ + unsigned rd: 1; /* recursion desired */ + /* fields in fourth byte */ + unsigned ra: 1; /* recursion available */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ad: 1; /* authentic data from named */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned rcode :4; /* response code */ +#endif +#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN + /* fields in third byte */ + unsigned rd :1; /* recursion desired */ + unsigned tc :1; /* truncated message */ + unsigned aa :1; /* authoritive answer */ + unsigned opcode :4; /* purpose of message */ + unsigned qr :1; /* response flag */ + /* fields in fourth byte */ + unsigned rcode :4; /* response code */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned ad: 1; /* authentic data from named */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ra :1; /* recursion available */ +#endif + /* remaining bytes */ + unsigned qdcount :16; /* number of question entries */ + unsigned ancount :16; /* number of answer entries */ + unsigned nscount :16; /* number of authority entries */ + unsigned arcount :16; /* number of resource entries */ +} HEADER; + +#define PACKETSZ NS_PACKETSZ +#define MAXDNAME NS_MAXDNAME +#define MAXCDNAME NS_MAXCDNAME +#define MAXLABEL NS_MAXLABEL +#define HFIXEDSZ NS_HFIXEDSZ +#define QFIXEDSZ NS_QFIXEDSZ +#define RRFIXEDSZ NS_RRFIXEDSZ +#define INT32SZ NS_INT32SZ +#define INT16SZ NS_INT16SZ +#define INADDRSZ NS_INADDRSZ +#define IN6ADDRSZ NS_IN6ADDRSZ +#define INDIR_MASK NS_CMPRSFLGS +#define NAMESERVER_PORT NS_DEFAULTPORT + +#define S_ZONE ns_s_zn +#define S_PREREQ ns_s_pr +#define S_UPDATE ns_s_ud +#define S_ADDT ns_s_ar + +#define QUERY ns_o_query +#define IQUERY ns_o_iquery +#define STATUS ns_o_status +#define NS_NOTIFY_OP ns_o_notify +#define NS_UPDATE_OP ns_o_update + +#define NOERROR ns_r_noerror +#define FORMERR ns_r_formerr +#define SERVFAIL ns_r_servfail +#define NXDOMAIN ns_r_nxdomain +#define NOTIMP ns_r_notimpl +#define REFUSED ns_r_refused +#define YXDOMAIN ns_r_yxdomain +#define YXRRSET ns_r_yxrrset +#define NXRRSET ns_r_nxrrset +#define NOTAUTH ns_r_notauth +#define NOTZONE ns_r_notzone +/*#define BADSIG ns_r_badsig*/ +/*#define BADKEY ns_r_badkey*/ +/*#define BADTIME ns_r_badtime*/ + + +#define DELETE ns_uop_delete +#define ADD ns_uop_add + +#define T_A ns_t_a +#define T_NS ns_t_ns +#define T_MD ns_t_md +#define T_MF ns_t_mf +#define T_CNAME ns_t_cname +#define T_SOA ns_t_soa +#define T_MB ns_t_mb +#define T_MG ns_t_mg +#define T_MR ns_t_mr +#define T_NULL ns_t_null +#define T_WKS ns_t_wks +#define T_PTR ns_t_ptr +#define T_HINFO ns_t_hinfo +#define T_MINFO ns_t_minfo +#define T_MX ns_t_mx +#define T_TXT ns_t_txt +#define T_RP ns_t_rp +#define T_AFSDB ns_t_afsdb +#define T_X25 ns_t_x25 +#define T_ISDN ns_t_isdn +#define T_RT ns_t_rt +#define T_NSAP ns_t_nsap +#define T_NSAP_PTR ns_t_nsap_ptr +#define T_SIG ns_t_sig +#define T_KEY ns_t_key +#define T_PX ns_t_px +#define T_GPOS ns_t_gpos +#define T_AAAA ns_t_aaaa +#define T_LOC ns_t_loc +#define T_NXT ns_t_nxt +#define T_EID ns_t_eid +#define T_NIMLOC ns_t_nimloc +#define T_SRV ns_t_srv +#define T_ATMA ns_t_atma +#define T_NAPTR ns_t_naptr +#define T_TSIG ns_t_tsig +#define T_IXFR ns_t_ixfr +#define T_AXFR ns_t_axfr +#define T_MAILB ns_t_mailb +#define T_MAILA ns_t_maila +#define T_ANY ns_t_any + +#define C_IN ns_c_in +#define C_CHAOS ns_c_chaos +#define C_HS ns_c_hs +/* BIND_UPDATE */ +#define C_NONE ns_c_none +#define C_ANY ns_c_any + +#define GETSHORT NS_GET16 +#define GETLONG NS_GET32 +#define PUTSHORT NS_PUT16 +#define PUTLONG NS_PUT32 + +#endif /* _ARPA_NAMESER_COMPAT_ */ diff --git a/includes/cdefs.h b/includes/cdefs.h new file mode 100644 index 0000000..eab1c4b --- /dev/null +++ b/includes/cdefs.h @@ -0,0 +1,70 @@ +/* cdefs.h + + Standard C definitions... */ + +/* + * Copyright (c) 2012 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004,2009,2011 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by Internet Software Consortium + * Copyright (c) 1995 RadioMail Corporation. All rights reserved. + * + * 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + * This software was written for RadioMail Corporation by Ted Lemon + * under a contract with Vixie Enterprises. Further modifications have + * been made for Internet Systems Consortium under a contract + * with Vixie Laboratories. + */ + +#if !defined (__ISC_DHCP_CDEFS_H__) +#define __ISC_DHCP_CDEFS_H__ +/* Delete attributes if not gcc or not the right version of gcc. */ +#if !defined(__GNUC__) || __GNUC__ < 2 || \ + (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || defined (darwin) +#define __attribute__(x) +#endif + +/* The following macro handles the case of unwanted return values. In + * GCC one can specify an attribute for a function to generate a warning + * if the return value of the function is ignored and one can't dispose of + * the warning by the use of void. In conjunction with the use of -Werror + * these warnings prohibit the compilation of the package. This macro + * allows us to assign the return value to a variable and then ignore it. + * + * __attribute__((unused)) is added for avoiding another warning about set, + * but unused variable. This is produced by unused-but-set-variable switch + * that is enabled by default in gcc 4.6. + */ +#if !defined(__GNUC__) || (__GNUC__ < 4) +#define IGNORE_RET(x) (void) x +#else +#define IGNORE_RET(x) \ + do { \ + int __attribute__((unused)) ignore_return ;\ + ignore_return = x; \ + } while (0) +#endif + +/* This macro is defined to avoid unused-but-set-variable warning + * that is enabled in gcc 4.6 + */ + +#define IGNORE_UNUSED(x) { x = x; } + +#endif /* __ISC_DHCP_CDEFS_H__ */ diff --git a/includes/config.h.in b/includes/config.h.in new file mode 100644 index 0000000..8c17338 --- /dev/null +++ b/includes/config.h.in @@ -0,0 +1,300 @@ +/* includes/config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +#undef AC_APPLE_UNIVERSAL_BUILD + +/* Define to compile debug-only DHCP software. */ +#undef DEBUG + +/* Define to queue multiple DHCPACK replies per fsync. */ +#undef DELAYED_ACK + +/* Define to BIG_ENDIAN for MSB (Motorola or SPARC CPUs) or LITTLE_ENDIAN for + LSB (Intel CPUs). */ +#undef DHCP_BYTE_ORDER + +/* Define to 1 to include DHCPv6 support. */ +#undef DHCPv6 + +/* Define to any value to chroot() prior to loading config. */ +#undef EARLY_CHROOT + +/* Define to include execute() config language support. */ +#undef ENABLE_EXECUTE + +/* Define to include Failover Protocol support. */ +#undef FAILOVER_PROTOCOL + +/* Define to nothing if C supports flexible array members, and to 1 if it does + not. That way, with a declaration like `struct s { int n; double + d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99 + compilers. When computing the size of such an object, don't use 'sizeof + (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)' + instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with + MSVC and with C++ compilers. */ +#undef FLEXIBLE_ARRAY_MEMBER + +/* ATF framework specified? */ +#undef HAVE_ATF + +/* Define to 1 to use the Berkeley Packet Filter interface code. */ +#undef HAVE_BPF + +/* Define to 1 if you have the /dev/random file. */ +#undef HAVE_DEV_RANDOM + +/* Define to 1 to use DLPI interface code. */ +#undef HAVE_DLPI + +/* Define to 1 if you have the <ifaddrs.h> header file. */ +#undef HAVE_IFADDRS_H + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the <linux/types.h> header file. */ +#undef HAVE_LINUX_TYPES_H + +/* Define to 1 to use the Linux Packet Filter interface code. */ +#undef HAVE_LPF + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the <net/if6.h> header file. */ +#undef HAVE_NET_IF6_H + +/* Define to 1 if you have the <net/if_dl.h> header file. */ +#undef HAVE_NET_IF_DL_H + +/* Define to 1 if you have the <regex.h> header file. */ +#undef HAVE_REGEX_H + +/* Define to 1 if the sockaddr structure has a length field. */ +#undef HAVE_SA_LEN + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strlcat' function. */ +#undef HAVE_STRLCAT + +/* Define to 1 if you have the <sys/socket.h> header file. */ +#undef HAVE_SYS_SOCKET_H + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* Define to the string for a noreturn attribute. */ +#undef ISC_DHCP_NORETURN + +/* Define to 1 if the system has 'struct if_laddrconf'. */ +#undef ISC_PLATFORM_HAVEIF_LADDRCONF + +/* Define to 1 if the system has 'struct if_laddrreq'. */ +#undef ISC_PLATFORM_HAVEIF_LADDRREQ + +/* Define to 1 if the system has 'struct lifnum'. */ +#undef ISC_PLATFORM_HAVELIFNUM + +/* Define to 1 if the inet_aton() function is missing. */ +#undef NEED_INET_ATON + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to any value to include Ari's PARANOIA patch. */ +#undef PARANOIA + +/* Define to correct bad byteorders in secs field. */ +#undef SECS_BYTEORDER + +/* The size of `struct iaddr *', as computed by sizeof. */ +#undef SIZEOF_STRUCT_IADDR_P + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to include server activity tracing support. */ +#undef TRACING + +/* Define to include PIDs in syslog messages. */ +#undef USE_LOG_PID + +/* Define to 1 to use the standard BSD socket API. */ +#undef USE_SOCKETS + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# undef _ALL_SOURCE +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# undef _GNU_SOURCE +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# undef _POSIX_PTHREAD_SEMANTICS +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# undef _TANDEM_SOURCE +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# undef __EXTENSIONS__ +#endif + + +/* Define to 1 to enable IPv4 packet info support. */ +#undef USE_V4_PKTINFO + +/* Version number of package */ +#undef VERSION + +/* tpacket_auxdata.tp_vlan_tci present */ +#undef VLAN_TCI_PRESENT + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# undef WORDS_BIGENDIAN +# endif +#endif + +/* Define to 1 if on MINIX. */ +#undef _MINIX + +/* File for dhclient6 leases. */ +#undef _PATH_DHCLIENT6_DB + +/* File for dhclient6 process information. */ +#undef _PATH_DHCLIENT6_PID + +/* File for dhclient leases. */ +#undef _PATH_DHCLIENT_DB + +/* File for dhclient process information. */ +#undef _PATH_DHCLIENT_PID + +/* File for dhcpd6 leases. */ +#undef _PATH_DHCPD6_DB + +/* File for dhcpd6 process information. */ +#undef _PATH_DHCPD6_PID + +/* File for dhcpd leases. */ +#undef _PATH_DHCPD_DB + +/* File for dhcpd process information. */ +#undef _PATH_DHCPD_PID + +/* File for dhcrelay6 process information. */ +#undef _PATH_DHCRELAY6_PID + +/* File for dhcrelay process information. */ +#undef _PATH_DHCRELAY_PID + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +#undef _POSIX_1_SOURCE + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +#undef _POSIX_SOURCE + +/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>, + <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the + #define below would cause a syntax error. */ +#undef _UINT32_T + +/* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>, + <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the + #define below would cause a syntax error. */ +#undef _UINT64_T + +/* Define for Solaris 2.5.1 so the uint8_t typedef from <sys/synch.h>, + <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the + #define below would cause a syntax error. */ +#undef _UINT8_T + +/* Define to the type of a signed integer type of width exactly 16 bits if + such a type exists and the standard includes do not define it. */ +#undef int16_t + +/* Define to the type of a signed integer type of width exactly 32 bits if + such a type exists and the standard includes do not define it. */ +#undef int32_t + +/* Define to the type of a signed integer type of width exactly 64 bits if + such a type exists and the standard includes do not define it. */ +#undef int64_t + +/* Define to the type of a signed integer type of width exactly 8 bits if such + a type exists and the standard includes do not define it. */ +#undef int8_t + +/* Define a type for 16-bit unsigned integers. */ +#undef u_int16_t + +/* Define a type for 32-bit unsigned integers. */ +#undef u_int32_t + +/* Define a type for 64-bit unsigned integers. */ +#undef u_int64_t + +/* Define a type for 8-bit unsigned integers. */ +#undef u_int8_t + +/* Define to the type of an unsigned integer type of width exactly 16 bits if + such a type exists and the standard includes do not define it. */ +#undef uint16_t + +/* Define to the type of an unsigned integer type of width exactly 32 bits if + such a type exists and the standard includes do not define it. */ +#undef uint32_t + +/* Define to the type of an unsigned integer type of width exactly 64 bits if + such a type exists and the standard includes do not define it. */ +#undef uint64_t + +/* Define to the type of an unsigned integer type of width exactly 8 bits if + such a type exists and the standard includes do not define it. */ +#undef uint8_t diff --git a/includes/ctrace.h b/includes/ctrace.h new file mode 100644 index 0000000..306e689 --- /dev/null +++ b/includes/ctrace.h @@ -0,0 +1,73 @@ +/* trace.h + + Definitions for dhcp tracing facility... */ + +/* + * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2001-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +typedef struct { + struct in_addr primary_address; + u_int32_t index; + struct hardware hw_address; + char name [IFNAMSIZ]; +} trace_interface_packet_t; + +typedef struct { + u_int32_t index; + struct iaddr from; + u_int16_t from_port; + struct hardware hfrom; + u_int8_t havehfrom; +} trace_inpacket_t; + +typedef struct { + u_int32_t index; + struct iaddr from; + struct iaddr to; + u_int16_t to_port; + struct hardware hto; + u_int8_t havehto; +} trace_outpacket_t; + +void trace_interface_register (trace_type_t *, struct interface_info *); +void trace_interface_input (trace_type_t *, unsigned, char *); +void trace_interface_stop (trace_type_t *); +void trace_inpacket_stash (struct interface_info *, + struct dhcp_packet *, unsigned, unsigned int, + struct iaddr, struct hardware *); +void trace_inpacket_input (trace_type_t *, unsigned, char *); +void trace_inpacket_stop (trace_type_t *); +void trace_outpacket_input (trace_type_t *, unsigned, char *); +void trace_outpacket_stop (trace_type_t *); +ssize_t trace_packet_send (struct interface_info *, + struct packet *, struct dhcp_packet *, size_t, + struct in_addr, + struct sockaddr_in *, struct hardware *); +void trace_icmp_input_input (trace_type_t *, unsigned, char *); +void trace_icmp_input_stop (trace_type_t *); +void trace_icmp_output_input (trace_type_t *, unsigned, char *); +void trace_icmp_output_stop (trace_type_t *); +void trace_seed_stash (trace_type_t *, unsigned); +void trace_seed_input (trace_type_t *, unsigned, char *); +void trace_seed_stop (trace_type_t *); diff --git a/includes/dhcp.h b/includes/dhcp.h new file mode 100644 index 0000000..f916468 --- /dev/null +++ b/includes/dhcp.h @@ -0,0 +1,203 @@ +/* dhcp.h + + Protocol structures... */ + +/* + * Copyright (c) 2011-2012,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004-2009 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1995-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#ifndef DHCP_H +#define DHCP_H + +#define DHCP_UDP_OVERHEAD (20 + /* IP header */ \ + 8) /* UDP header */ +#define DHCP_SNAME_LEN 64 +#define DHCP_FILE_LEN 128 +#define DHCP_FIXED_NON_UDP 236 +#define DHCP_FIXED_LEN (DHCP_FIXED_NON_UDP + DHCP_UDP_OVERHEAD) + /* Everything but options. */ +#define BOOTP_MIN_LEN 300 + +#define DHCP_MTU_MAX 1500 +#define DHCP_MTU_MIN 576 + +#define DHCP_MAX_OPTION_LEN (DHCP_MTU_MAX - DHCP_FIXED_LEN) +#define DHCP_MIN_OPTION_LEN (DHCP_MTU_MIN - DHCP_FIXED_LEN) + +struct dhcp_packet { + u_int8_t op; /* 0: Message opcode/type */ + u_int8_t htype; /* 1: Hardware addr type (net/if_types.h) */ + u_int8_t hlen; /* 2: Hardware addr length */ + u_int8_t hops; /* 3: Number of relay agent hops from client */ + u_int32_t xid; /* 4: Transaction ID */ + u_int16_t secs; /* 8: Seconds since client started looking */ + u_int16_t flags; /* 10: Flag bits */ + struct in_addr ciaddr; /* 12: Client IP address (if already in use) */ + struct in_addr yiaddr; /* 16: Client IP address */ + struct in_addr siaddr; /* 18: IP address of next server to talk to */ + struct in_addr giaddr; /* 20: DHCP relay agent IP address */ + unsigned char chaddr [16]; /* 24: Client hardware address */ + char sname [DHCP_SNAME_LEN]; /* 40: Server name */ + char file [DHCP_FILE_LEN]; /* 104: Boot filename */ + unsigned char options [DHCP_MAX_OPTION_LEN]; + /* 212: Optional parameters + (actual length dependent on MTU). */ +}; + +/* BOOTP (rfc951) message types */ +#define BOOTREQUEST 1 +#define BOOTREPLY 2 + +/* Possible values for flags field... */ +#define BOOTP_BROADCAST 32768L + +/* Possible values for hardware type (htype) field... */ +#define HTYPE_ETHER 1 /* Ethernet 10Mbps */ +#define HTYPE_IEEE802 6 /* IEEE 802.2 Token Ring... */ +#define HTYPE_FDDI 8 /* FDDI... */ +#define HTYPE_INFINIBAND 32 /* IP over Infiniband */ +#define HTYPE_IPMP 255 /* IPMP - random hw address - there + * is no standard for this so we + * just steal a type */ + +/* Magic cookie validating dhcp options field (and bootp vendor + extensions field). */ +#define DHCP_OPTIONS_COOKIE "\143\202\123\143" + +/* DHCP Option codes: */ + +#define DHO_PAD 0 +#define DHO_SUBNET_MASK 1 +#define DHO_TIME_OFFSET 2 +#define DHO_ROUTERS 3 +#define DHO_TIME_SERVERS 4 +#define DHO_NAME_SERVERS 5 +#define DHO_DOMAIN_NAME_SERVERS 6 +#define DHO_LOG_SERVERS 7 +#define DHO_COOKIE_SERVERS 8 +#define DHO_LPR_SERVERS 9 +#define DHO_IMPRESS_SERVERS 10 +#define DHO_RESOURCE_LOCATION_SERVERS 11 +#define DHO_HOST_NAME 12 +#define DHO_BOOT_SIZE 13 +#define DHO_MERIT_DUMP 14 +#define DHO_DOMAIN_NAME 15 +#define DHO_SWAP_SERVER 16 +#define DHO_ROOT_PATH 17 +#define DHO_EXTENSIONS_PATH 18 +#define DHO_IP_FORWARDING 19 +#define DHO_NON_LOCAL_SOURCE_ROUTING 20 +#define DHO_POLICY_FILTER 21 +#define DHO_MAX_DGRAM_REASSEMBLY 22 +#define DHO_DEFAULT_IP_TTL 23 +#define DHO_PATH_MTU_AGING_TIMEOUT 24 +#define DHO_PATH_MTU_PLATEAU_TABLE 25 +#define DHO_INTERFACE_MTU 26 +#define DHO_ALL_SUBNETS_LOCAL 27 +#define DHO_BROADCAST_ADDRESS 28 +#define DHO_PERFORM_MASK_DISCOVERY 29 +#define DHO_MASK_SUPPLIER 30 +#define DHO_ROUTER_DISCOVERY 31 +#define DHO_ROUTER_SOLICITATION_ADDRESS 32 +#define DHO_STATIC_ROUTES 33 +#define DHO_TRAILER_ENCAPSULATION 34 +#define DHO_ARP_CACHE_TIMEOUT 35 +#define DHO_IEEE802_3_ENCAPSULATION 36 +#define DHO_DEFAULT_TCP_TTL 37 +#define DHO_TCP_KEEPALIVE_INTERVAL 38 +#define DHO_TCP_KEEPALIVE_GARBAGE 39 +#define DHO_NIS_DOMAIN 40 +#define DHO_NIS_SERVERS 41 +#define DHO_NTP_SERVERS 42 +#define DHO_VENDOR_ENCAPSULATED_OPTIONS 43 +#define DHO_NETBIOS_NAME_SERVERS 44 +#define DHO_NETBIOS_DD_SERVER 45 +#define DHO_NETBIOS_NODE_TYPE 46 +#define DHO_NETBIOS_SCOPE 47 +#define DHO_FONT_SERVERS 48 +#define DHO_X_DISPLAY_MANAGER 49 +#define DHO_DHCP_REQUESTED_ADDRESS 50 +#define DHO_DHCP_LEASE_TIME 51 +#define DHO_DHCP_OPTION_OVERLOAD 52 +#define DHO_DHCP_MESSAGE_TYPE 53 +#define DHO_DHCP_SERVER_IDENTIFIER 54 +#define DHO_DHCP_PARAMETER_REQUEST_LIST 55 +#define DHO_DHCP_MESSAGE 56 +#define DHO_DHCP_MAX_MESSAGE_SIZE 57 +#define DHO_DHCP_RENEWAL_TIME 58 +#define DHO_DHCP_REBINDING_TIME 59 +#define DHO_VENDOR_CLASS_IDENTIFIER 60 +#define DHO_DHCP_CLIENT_IDENTIFIER 61 +#define DHO_NWIP_DOMAIN_NAME 62 +#define DHO_NWIP_SUBOPTIONS 63 +#define DHO_USER_CLASS 77 +#define DHO_FQDN 81 +#define DHO_DHCP_AGENT_OPTIONS 82 +#define DHO_AUTHENTICATE 90 /* RFC3118, was 210 */ +#define DHO_CLIENT_LAST_TRANSACTION_TIME 91 +#define DHO_ASSOCIATED_IP 92 +#define DHO_SUBNET_SELECTION 118 /* RFC3011! */ +#define DHO_DOMAIN_SEARCH 119 /* RFC3397 */ +#define DHO_VIVCO_SUBOPTIONS 124 +#define DHO_VIVSO_SUBOPTIONS 125 + +#define DHO_END 255 + +/* DHCP message types. */ +#define DHCPDISCOVER 1 +#define DHCPOFFER 2 +#define DHCPREQUEST 3 +#define DHCPDECLINE 4 +#define DHCPACK 5 +#define DHCPNAK 6 +#define DHCPRELEASE 7 +#define DHCPINFORM 8 +#define DHCPLEASEQUERY 10 +#define DHCPLEASEUNASSIGNED 11 +#define DHCPLEASEUNKNOWN 12 +#define DHCPLEASEACTIVE 13 + + +/* Relay Agent Information option subtypes: */ +#define RAI_CIRCUIT_ID 1 +#define RAI_REMOTE_ID 2 +#define RAI_AGENT_ID 3 +#define RAI_LINK_SELECT 5 + +/* FQDN suboptions: */ +#define FQDN_NO_CLIENT_UPDATE 1 +#define FQDN_SERVER_UPDATE 2 +#define FQDN_ENCODED 3 +#define FQDN_RCODE1 4 +#define FQDN_RCODE2 5 +#define FQDN_HOSTNAME 6 +#define FQDN_DOMAINNAME 7 +#define FQDN_FQDN 8 +#define FQDN_SUBOPTION_COUNT 8 + +/* Enterprise Suboptions: */ +#define VENDOR_ISC_SUBOPTIONS 2495 + +#endif /* DHCP_H */ + diff --git a/includes/dhcp6.h b/includes/dhcp6.h new file mode 100644 index 0000000..920be80 --- /dev/null +++ b/includes/dhcp6.h @@ -0,0 +1,213 @@ +/* dhcp6.h + + DHCPv6 Protocol structures... */ + +/* + * Copyright (c) 2006-2010 by Internet Systems Consortium, Inc. ("ISC") + * + * 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + */ + + +/* DHCPv6 Option codes: */ + +#define D6O_CLIENTID 1 /* RFC3315 */ +#define D6O_SERVERID 2 +#define D6O_IA_NA 3 +#define D6O_IA_TA 4 +#define D6O_IAADDR 5 +#define D6O_ORO 6 +#define D6O_PREFERENCE 7 +#define D6O_ELAPSED_TIME 8 +#define D6O_RELAY_MSG 9 +/* Option code 10 unassigned. */ +#define D6O_AUTH 11 +#define D6O_UNICAST 12 +#define D6O_STATUS_CODE 13 +#define D6O_RAPID_COMMIT 14 +#define D6O_USER_CLASS 15 +#define D6O_VENDOR_CLASS 16 +#define D6O_VENDOR_OPTS 17 +#define D6O_INTERFACE_ID 18 +#define D6O_RECONF_MSG 19 +#define D6O_RECONF_ACCEPT 20 +#define D6O_SIP_SERVERS_DNS 21 /* RFC3319 */ +#define D6O_SIP_SERVERS_ADDR 22 /* RFC3319 */ +#define D6O_NAME_SERVERS 23 /* RFC3646 */ +#define D6O_DOMAIN_SEARCH 24 /* RFC3646 */ +#define D6O_IA_PD 25 /* RFC3633 */ +#define D6O_IAPREFIX 26 /* RFC3633 */ +#define D6O_NIS_SERVERS 27 /* RFC3898 */ +#define D6O_NISP_SERVERS 28 /* RFC3898 */ +#define D6O_NIS_DOMAIN_NAME 29 /* RFC3898 */ +#define D6O_NISP_DOMAIN_NAME 30 /* RFC3898 */ +#define D6O_SNTP_SERVERS 31 /* RFC4075 */ +#define D6O_INFORMATION_REFRESH_TIME 32 /* RFC4242 */ +#define D6O_BCMCS_SERVER_D 33 /* RFC4280 */ +#define D6O_BCMCS_SERVER_A 34 /* RFC4280 */ +/* 35 is unassigned */ +#define D6O_GEOCONF_CIVIC 36 /* RFC4776 */ +#define D6O_REMOTE_ID 37 /* RFC4649 */ +#define D6O_SUBSCRIBER_ID 38 /* RFC4580 */ +#define D6O_CLIENT_FQDN 39 /* RFC4704 */ +#define D6O_PANA_AGENT 40 /* paa-option */ +#define D6O_NEW_POSIX_TIMEZONE 41 /* RFC4833 */ +#define D6O_NEW_TZDB_TIMEZONE 42 /* RFC4833 */ +#define D6O_ERO 43 /* RFC4994 */ +#define D6O_LQ_QUERY 44 /* RFC5007 */ +#define D6O_CLIENT_DATA 45 /* RFC5007 */ +#define D6O_CLT_TIME 46 /* RFC5007 */ +#define D6O_LQ_RELAY_DATA 47 /* RFC5007 */ +#define D6O_LQ_CLIENT_LINK 48 /* RFC5007 */ + +/* + * Status Codes, from RFC 3315 section 24.4, and RFC 3633, 5007. + */ +#define STATUS_Success 0 +#define STATUS_UnspecFail 1 +#define STATUS_NoAddrsAvail 2 +#define STATUS_NoBinding 3 +#define STATUS_NotOnLink 4 +#define STATUS_UseMulticast 5 +#define STATUS_NoPrefixAvail 6 +#define STATUS_UnknownQueryType 7 +#define STATUS_MalformedQuery 8 +#define STATUS_NotConfigured 9 +#define STATUS_NotAllowed 10 + +/* + * DHCPv6 message types, defined in section 5.3 of RFC 3315 + */ +#define DHCPV6_SOLICIT 1 +#define DHCPV6_ADVERTISE 2 +#define DHCPV6_REQUEST 3 +#define DHCPV6_CONFIRM 4 +#define DHCPV6_RENEW 5 +#define DHCPV6_REBIND 6 +#define DHCPV6_REPLY 7 +#define DHCPV6_RELEASE 8 +#define DHCPV6_DECLINE 9 +#define DHCPV6_RECONFIGURE 10 +#define DHCPV6_INFORMATION_REQUEST 11 +#define DHCPV6_RELAY_FORW 12 +#define DHCPV6_RELAY_REPL 13 +#define DHCPV6_LEASEQUERY 14 +#define DHCPV6_LEASEQUERY_REPLY 15 + +extern const char *dhcpv6_type_names[]; +extern const int dhcpv6_type_name_max; + +/* DUID type definitions (RFC3315 section 9). + */ +#define DUID_LLT 1 +#define DUID_EN 2 +#define DUID_LL 3 + +/* Offsets into IA_*'s where Option spaces commence. */ +#define IA_NA_OFFSET 12 /* IAID, T1, T2, all 4 octets each */ +#define IA_TA_OFFSET 4 /* IAID only, 4 octets */ +#define IA_PD_OFFSET 12 /* IAID, T1, T2, all 4 octets each */ + +/* Offset into IAADDR's where Option spaces commence. */ +#define IAADDR_OFFSET 24 + +/* Offset into IAPREFIX's where Option spaces commence. */ +#define IAPREFIX_OFFSET 25 + +/* Offset into LQ_QUERY's where Option spaces commence. */ +#define LQ_QUERY_OFFSET 17 + +/* + * DHCPv6 well-known multicast addressess, from section 5.1 of RFC 3315 + */ +#define All_DHCP_Relay_Agents_and_Servers "FF02::1:2" +#define All_DHCP_Servers "FF05::1:3" + +/* + * DHCPv6 Retransmission Constants (RFC3315 section 5.5, RFC 5007) + */ + +#define SOL_MAX_DELAY 1 +#define SOL_TIMEOUT 1 +#define SOL_MAX_RT 120 +#define REQ_TIMEOUT 1 +#define REQ_MAX_RT 30 +#define REQ_MAX_RC 10 +#define CNF_MAX_DELAY 1 +#define CNF_TIMEOUT 1 +#define CNF_MAX_RT 4 +#define CNF_MAX_RD 10 +#define REN_TIMEOUT 10 +#define REN_MAX_RT 600 +#define REB_TIMEOUT 10 +#define REB_MAX_RT 600 +#define INF_MAX_DELAY 1 +#define INF_TIMEOUT 1 +#define INF_MAX_RT 120 +#define REL_TIMEOUT 1 +#define REL_MAX_RC 5 +#define DEC_TIMEOUT 1 +#define DEC_MAX_RC 5 +#define REC_TIMEOUT 2 +#define REC_MAX_RC 8 +#define HOP_COUNT_LIMIT 32 +#define LQ6_TIMEOUT 1 +#define LQ6_MAX_RT 10 +#define LQ6_MAX_RC 5 + +/* + * Normal packet format, defined in section 6 of RFC 3315 + */ +struct dhcpv6_packet { + unsigned char msg_type; + unsigned char transaction_id[3]; + unsigned char options[FLEXIBLE_ARRAY_MEMBER]; +}; + +/* Offset into DHCPV6 Reply packets where Options spaces commence. */ +#define REPLY_OPTIONS_INDEX 4 + +/* + * Relay packet format, defined in section 7 of RFC 3315 + */ +struct dhcpv6_relay_packet { + unsigned char msg_type; + unsigned char hop_count; + unsigned char link_address[16]; + unsigned char peer_address[16]; + unsigned char options[FLEXIBLE_ARRAY_MEMBER]; +}; + +/* Leasequery query-types (RFC 5007) */ + +#define LQ6QT_BY_ADDRESS 1 +#define LQ6QT_BY_CLIENTID 2 + +/* + * DUID time starts 2000-01-01. + * This constant is the number of seconds since 1970-01-01, + * when the Unix epoch began. + */ +#define DUID_TIME_EPOCH 946684800 + +/* Information-Request Time option (RFC 4242) */ + +#define IRT_DEFAULT 86400 +#define IRT_MINIMUM 600 + diff --git a/includes/dhcpd.h b/includes/dhcpd.h new file mode 100644 index 0000000..bd11b48 --- /dev/null +++ b/includes/dhcpd.h @@ -0,0 +1,3592 @@ +/* dhcpd.h + + Definitions for dhcpd... */ + +/* + * Copyright (c) 2004-2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#include "config.h" + +#ifndef __CYGWIN32__ +#include <sys/types.h> +#include <netinet/in.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <arpa/inet.h> +#include <errno.h> + +#include <netdb.h> +#else +#define fd_set cygwin_fd_set +#include <sys/types.h> +#endif +#include <stddef.h> +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <ctype.h> +#include <time.h> + +#include <net/if.h> +#undef FDDI +#include <net/route.h> +#include <net/if_arp.h> +#if HAVE_NET_IF_DL_H +# include <net/if_dl.h> +#endif + +#include <setjmp.h> + +#include "cdefs.h" +#include "osdep.h" + +#include "arpa/nameser.h" + +#include "minires.h" + +struct hash_table; +typedef struct hash_table group_hash_t; +typedef struct hash_table universe_hash_t; +typedef struct hash_table option_name_hash_t; +typedef struct hash_table option_code_hash_t; +typedef struct hash_table dns_zone_hash_t; +typedef struct hash_table lease_ip_hash_t; +typedef struct hash_table lease_id_hash_t; +typedef struct hash_table host_hash_t; +typedef struct hash_table class_hash_t; + +typedef time_t TIME; + +#ifndef EOL +#define EOL '\n' +#endif + +#include <omapip/isclib.h> +#include <omapip/result.h> + +#include "dhcp.h" +#include "dhcp6.h" +#include "statement.h" +#include "tree.h" +#include "inet.h" +#include "dhctoken.h" + +#include <omapip/omapip_p.h> + +#if defined(LDAP_CONFIGURATION) +# include <ldap.h> +# include <sys/utsname.h> /* for uname() */ +#endif + +#if !defined (BYTE_NAME_HASH_SIZE) +# define BYTE_NAME_HASH_SIZE 401 /* Default would be ridiculous. */ +#endif +#if !defined (BYTE_CODE_HASH_SIZE) +# define BYTE_CODE_HASH_SIZE 254 /* Default would be ridiculous. */ +#endif + +/* Although it is highly improbable that a 16-bit option space might + * actually use 2^16 actual defined options, it is the worst case + * scenario we must prepare for. Having 4 options per bucket in this + * case is pretty reasonable. + */ +#if !defined (WORD_NAME_HASH_SIZE) +# define WORD_NAME_HASH_SIZE 20479 +#endif +#if !defined (WORD_CODE_HASH_SIZE) +# define WORD_CODE_HASH_SIZE 16384 +#endif + +/* Not only is it improbable that the 32-bit spaces might actually use 2^32 + * defined options, it is infeasible. It would be best for this kind of + * space to be dynamically sized. Instead we size it at the word hash's + * level. + */ +#if !defined (QUAD_NAME_HASH_SIZE) +# define QUAD_NAME_HASH_SIZE WORD_NAME_HASH_SIZE +#endif +#if !defined (QUAD_CODE_HASH_SIZE) +# define QUAD_CODE_HASH_SIZE WORD_CODE_HASH_SIZE +#endif + +#if !defined (DNS_HASH_SIZE) +# define DNS_HASH_SIZE 0 /* Default. */ +#endif + +/* Default size to use for name/code hashes on user-defined option spaces. */ +#if !defined (DEFAULT_SPACE_HASH_SIZE) +# define DEFAULT_SPACE_HASH_SIZE 11 +#endif + +#if !defined (NWIP_HASH_SIZE) +# define NWIP_HASH_SIZE 17 /* A really small table. */ +#endif + +#if !defined (FQDN_HASH_SIZE) +# define FQDN_HASH_SIZE 13 /* A ridiculously small table. */ +#endif + +/* I really doubt a given installation is going to have more than a few + * hundred vendors involved. + */ +#if !defined (VIVCO_HASH_SIZE) +# define VIVCO_HASH_SIZE 127 +#endif + +#if !defined (VIVSO_HASH_SIZE) +# define VIVSO_HASH_SIZE VIVCO_HASH_SIZE +#endif + +#if !defined (VSIO_HASH_SIZE) +# define VSIO_HASH_SIZE VIVCO_HASH_SIZE +#endif + +#if !defined (VIV_ISC_HASH_SIZE) +# define VIV_ISC_HASH_SIZE 3 /* An incredulously small table. */ +#endif + +#if !defined (UNIVERSE_HASH_SIZE) +# define UNIVERSE_HASH_SIZE 13 /* A really small table. */ +#endif + +#if !defined (GROUP_HASH_SIZE) +# define GROUP_HASH_SIZE 0 /* Default. */ +#endif + +/* At least one person has indicated they use ~20k host records. + */ +#if !defined (HOST_HASH_SIZE) +# define HOST_HASH_SIZE 22501 +#endif + +/* We have user reports of use of ISC DHCP numbering leases in the 200k's. + * + * We also have reports of folks using 10.0/8 as a dynamic range. The + * following is something of a compromise between the two. At the ~2-3 + * hundred thousand leases, there's ~2-3 leases to search in each bucket. + */ +#if !defined (LEASE_HASH_SIZE) +# define LEASE_HASH_SIZE 100003 +#endif + +/* It is not known what the worst case subclass hash size is. We estimate + * high, I think. + */ +#if !defined (SCLASS_HASH_SIZE) +# define SCLASS_HASH_SIZE 12007 +#endif + +#if !defined (AGENT_HASH_SIZE) +# define AGENT_HASH_SIZE 11 /* A really small table. */ +#endif + +/* The server hash size is used for both names and codes. There aren't + * many (roughly 50 at the moment), so we use a smaller table. If we + * use a 1:1 table size, then we get name collisions due to poor name + * hashing. So we use double the space we need, which drastically + * reduces collisions. + */ +#if !defined (SERVER_HASH_SIZE) +# define SERVER_HASH_SIZE (2*(sizeof(server_options) / sizeof(struct option))) +#endif + + +/* How many options are likely to appear in a single packet? */ +#if !defined (OPTION_HASH_SIZE) +# define OPTION_HASH_SIZE 17 +# define OPTION_HASH_PTWO 32 /* Next power of two above option hash. */ +# define OPTION_HASH_EXP 5 /* The exponent for that power of two. */ +#endif + +#define compute_option_hash(x) \ + (((x) & (OPTION_HASH_PTWO - 1)) + \ + (((x) >> OPTION_HASH_EXP) & \ + (OPTION_HASH_PTWO - 1))) % OPTION_HASH_SIZE; + +enum dhcp_shutdown_state { + shutdown_listeners, + shutdown_omapi_connections, + shutdown_drop_omapi_connections, + shutdown_dhcp, + shutdown_done +}; + +/* Client FQDN option, failover FQDN option, etc. */ +typedef struct { + u_int8_t codes [2]; + unsigned length; + u_int8_t *data; +} ddns_fqdn_t; + +#include "failover.h" + +/* A parsing context. */ + +struct parse { + int lexline; + int lexchar; + char *token_line; + char *prev_line; + char *cur_line; + const char *tlname; + int eol_token; + + /* + * In order to give nice output when we have a parsing error + * in our file, we keep track of where we are in the line so + * that we can show the user. + * + * We need to keep track of two lines, because we can look + * ahead, via the "peek" function, to the next line sometimes. + * + * The "line1" and "line2" variables act as buffers for this + * information. The "lpos" variable tells us where we are in the + * line. + * + * When we "put back" a character from the parsing context, we + * do not want to have the character appear twice in the error + * output. So, we set a flag, the "ugflag", which the + * get_char() function uses to check for this condition. + */ + char line1 [81]; + char line2 [81]; + int lpos; + int line; + int tlpos; + int tline; + enum dhcp_token token; + int ugflag; + char *tval; + int tlen; + char tokbuf [1500]; + + int warnings_occurred; + int file; + char *inbuf; + size_t bufix, buflen; + size_t bufsiz; + + struct parse *saved_state; + +#if defined(LDAP_CONFIGURATION) + /* + * LDAP configuration uses a call-back to iteratively read config + * off of the LDAP repository. + * XXX: The token stream can not be rewound reliably, so this must + * be addressed for DHCPv6 support. + */ + int (*read_function)(struct parse *); +#endif +}; + +/* Variable-length array of data. */ + +struct string_list { + struct string_list *next; + char string [1]; +}; + +/* A name server, from /etc/resolv.conf. */ +struct name_server { + struct name_server *next; + struct sockaddr_in addr; + TIME rcdate; +}; + +/* A domain search list element. */ +struct domain_search_list { + struct domain_search_list *next; + char *domain; + TIME rcdate; +}; + +/* Option tag structures are used to build chains of option tags, for + when we're sure we're not going to have enough of them to justify + maintaining an array. */ + +struct option_tag { + struct option_tag *next; + u_int8_t data [1]; +}; + +/* An agent option structure. We need a special structure for the + Relay Agent Information option because if more than one appears in + a message, we have to keep them separate. */ + +struct agent_options { + struct agent_options *next; + int length; + struct option_tag *first; +}; + +struct option_cache { + int refcnt; + struct option_cache *next; + struct expression *expression; + struct option *option; + struct data_string data; + + #define OPTION_HAD_NULLS 0x00000001 + u_int32_t flags; +}; + +struct option_state { + int refcnt; + int universe_count; + int site_universe; + int site_code_min; + void *universes [1]; +}; + +/* A dhcp packet and the pointers to its option values. */ +struct packet { + struct dhcp_packet *raw; + int refcnt; + unsigned packet_length; + int packet_type; + + unsigned char dhcpv6_msg_type; /* DHCPv6 message type */ + + /* DHCPv6 transaction ID */ + unsigned char dhcpv6_transaction_id[3]; + + /* DHCPv6 relay information */ + unsigned char dhcpv6_hop_count; + struct in6_addr dhcpv6_link_address; + struct in6_addr dhcpv6_peer_address; + + /* DHCPv6 packet containing this one, or NULL if none */ + struct packet *dhcpv6_container_packet; + + int options_valid; + int client_port; + struct iaddr client_addr; + struct interface_info *interface; /* Interface on which packet + was received. */ + struct hardware *haddr; /* Physical link address + of local sender (maybe gateway). */ + + /* Information for relay agent options (see + draft-ietf-dhc-agent-options-xx.txt). */ + u_int8_t *circuit_id; /* Circuit ID of client connection. */ + int circuit_id_len; + u_int8_t *remote_id; /* Remote ID of client. */ + int remote_id_len; + + int got_requested_address; /* True if client sent the + dhcp-requested-address option. */ + + struct shared_network *shared_network; + struct option_state *options; + +#if !defined (PACKET_MAX_CLASSES) +# define PACKET_MAX_CLASSES 5 +#endif + int class_count; + struct class *classes [PACKET_MAX_CLASSES]; + + int known; + int authenticated; + + /* If we stash agent options onto the packet option state, to pretend + * options we got in a previous exchange were still there, we need + * to signal this in a reliable way. + */ + isc_boolean_t agent_options_stashed; + + /* + * ISC_TRUE if packet received unicast (as opposed to multicast). + * Only used in DHCPv6. + */ + isc_boolean_t unicast; +}; + +/* + * A network interface's MAC address. + * 20 bytes for the hardware address + * and 1 byte for the type tag + */ + +#define HARDWARE_ADDR_LEN 20 + +struct hardware { + u_int8_t hlen; + u_int8_t hbuf[HARDWARE_ADDR_LEN + 1]; +}; + +#if defined(LDAP_CONFIGURATION) +# define LDAP_BUFFER_SIZE 8192 +# define LDAP_METHOD_STATIC 0 +# define LDAP_METHOD_DYNAMIC 1 +#if defined (LDAP_USE_SSL) +# define LDAP_SSL_OFF 0 +# define LDAP_SSL_ON 1 +# define LDAP_SSL_TLS 2 +# define LDAP_SSL_LDAPS 3 +#endif + +/* This is a tree of the current configuration we are building from LDAP */ +struct ldap_config_stack { + LDAPMessage * res; /* Pointer returned from ldap_search */ + LDAPMessage * ldent; /* Current item in LDAP that we're processing. + in res */ + int close_brace; /* Put a closing } after we're through with + this item */ + int processed; /* We set this flag if this base item has been + processed. After this base item is processed, + we can start processing the children */ + struct ldap_config_stack *children; + struct ldap_config_stack *next; +}; +#endif + +typedef enum { + server_startup = 0, + server_running = 1, + server_shutdown = 2, + server_hibernate = 3, + server_awaken = 4 +} control_object_state_t; + +typedef struct { + OMAPI_OBJECT_PREAMBLE; + control_object_state_t state; +} dhcp_control_object_t; + +/* Lease states: */ +#define FTS_FREE 1 +#define FTS_ACTIVE 2 +#define FTS_EXPIRED 3 +#define FTS_RELEASED 4 +#define FTS_ABANDONED 5 +#define FTS_RESET 6 +#define FTS_BACKUP 7 +typedef u_int8_t binding_state_t; + +/* FTS_LAST is the highest value that is valid for a lease binding state. */ +#define FTS_LAST FTS_BACKUP + +/* A dhcp lease declaration structure. */ +struct lease { + OMAPI_OBJECT_PREAMBLE; + struct lease *next; + struct lease *n_uid, *n_hw; + + struct iaddr ip_addr; + TIME starts, ends, sort_time; + char *client_hostname; + struct binding_scope *scope; + struct host_decl *host; + struct subnet *subnet; + struct pool *pool; + struct class *billing_class; + struct option_chain_head *agent_options; + + struct executable_statement *on_expiry; + struct executable_statement *on_commit; + struct executable_statement *on_release; + + unsigned char *uid; + unsigned short uid_len; + unsigned short uid_max; + unsigned char uid_buf [7]; + struct hardware hardware_addr; + + u_int8_t flags; +# define STATIC_LEASE 1 +# define BOOTP_LEASE 2 +# define RESERVED_LEASE 4 +# define MS_NULL_TERMINATION 8 +# define ON_UPDATE_QUEUE 16 +# define ON_ACK_QUEUE 32 +# define ON_QUEUE (ON_UPDATE_QUEUE | ON_ACK_QUEUE) +# define UNICAST_BROADCAST_HACK 64 +# define ON_DEFERRED_QUEUE 128 + +/* Persistent flags are to be preserved on a given lease structure. */ +# define PERSISTENT_FLAGS (ON_ACK_QUEUE | ON_UPDATE_QUEUE) +/* Ephemeral flags are to be preserved on a given lease (copied etc). */ +# define EPHEMERAL_FLAGS (MS_NULL_TERMINATION | \ + UNICAST_BROADCAST_HACK | \ + RESERVED_LEASE | \ + BOOTP_LEASE) + + /* + * The lease's binding state is its current state. The next binding + * state is the next state this lease will move into by expiration, + * or timers in general. The desired binding state is used on lease + * updates; the caller is attempting to move the lease to the desired + * binding state (and this may either succeed or fail, so the binding + * state must be preserved). + * + * The 'rewind' binding state is used in failover processing. It + * is used for an optimization when out of communications; it allows + * the server to "rewind" a lease to the previous state acknowledged + * by the peer, and progress forward from that point. + */ + binding_state_t binding_state; + binding_state_t next_binding_state; + binding_state_t desired_binding_state; + binding_state_t rewind_binding_state; + + struct lease_state *state; + + /* + * 'tsfp' is more of an 'effective' tsfp. It may be calculated from + * stos+mclt for example if it's an expired lease and the server is + * in partner-down state. 'atsfp' is zeroed whenever a lease is + * updated - and only set when the peer acknowledges it. This + * ensures every state change is transmitted. + */ + TIME tstp; /* Time sent to partner. */ + TIME tsfp; /* Time sent from partner. */ + TIME atsfp; /* Actual time sent from partner. */ + TIME cltt; /* Client last transaction time. */ + u_int32_t last_xid; /* XID we sent in this lease's BNDUPD */ + struct lease *next_pending; + + /* + * A pointer to the state of the ddns update for this lease. + * It should be set while the update is in progress and cleared + * when the update finishes. It can be used to cancel the + * update if we want to do a different update. + */ + struct dhcp_ddns_cb *ddns_cb; +}; + +struct lease_state { + struct lease_state *next; + + struct interface_info *ip; + + struct packet *packet; /* The incoming packet. */ + + TIME offered_expiry; + + struct option_state *options; + struct data_string parameter_request_list; + int max_message_size; + unsigned char expiry[4], renewal[4], rebind[4]; + struct data_string filename, server_name; + int got_requested_address; + int got_server_identifier; + struct shared_network *shared_network; /* Shared network of interface + on which request arrived. */ + + u_int32_t xid; + u_int16_t secs; + u_int16_t bootp_flags; + struct in_addr ciaddr; + struct in_addr siaddr; + struct in_addr giaddr; + u_int8_t hops; + u_int8_t offer; + struct iaddr from; +}; + +#define ROOT_GROUP 0 +#define HOST_DECL 1 +#define SHARED_NET_DECL 2 +#define SUBNET_DECL 3 +#define CLASS_DECL 4 +#define GROUP_DECL 5 +#define POOL_DECL 6 + +/* Possible modes in which discover_interfaces can run. */ + +#define DISCOVER_RUNNING 0 +#define DISCOVER_SERVER 1 +#define DISCOVER_UNCONFIGURED 2 +#define DISCOVER_RELAY 3 +#define DISCOVER_REQUESTED 4 + +/* DDNS_UPDATE_STYLE enumerations. */ +#define DDNS_UPDATE_STYLE_NONE 0 +#define DDNS_UPDATE_STYLE_AD_HOC 1 +#define DDNS_UPDATE_STYLE_INTERIM 2 + +/* Server option names. */ + +#define SV_DEFAULT_LEASE_TIME 1 +#define SV_MAX_LEASE_TIME 2 +#define SV_MIN_LEASE_TIME 3 +#define SV_BOOTP_LEASE_CUTOFF 4 +#define SV_BOOTP_LEASE_LENGTH 5 +#define SV_BOOT_UNKNOWN_CLIENTS 6 +#define SV_DYNAMIC_BOOTP 7 +#define SV_ALLOW_BOOTP 8 +#define SV_ALLOW_BOOTING 9 +#define SV_ONE_LEASE_PER_CLIENT 10 +#define SV_GET_LEASE_HOSTNAMES 11 +#define SV_USE_HOST_DECL_NAMES 12 +#define SV_USE_LEASE_ADDR_FOR_DEFAULT_ROUTE 13 +#define SV_MIN_SECS 14 +#define SV_FILENAME 15 +#define SV_SERVER_NAME 16 +#define SV_NEXT_SERVER 17 +#define SV_AUTHORITATIVE 18 +#define SV_VENDOR_OPTION_SPACE 19 +#define SV_ALWAYS_REPLY_RFC1048 20 +#define SV_SITE_OPTION_SPACE 21 +#define SV_ALWAYS_BROADCAST 22 +#define SV_DDNS_DOMAIN_NAME 23 +#define SV_DDNS_HOST_NAME 24 +#define SV_DDNS_REV_DOMAIN_NAME 25 +#define SV_LEASE_FILE_NAME 26 +#define SV_PID_FILE_NAME 27 +#define SV_DUPLICATES 28 +#define SV_DECLINES 29 +#define SV_DDNS_UPDATES 30 +#define SV_OMAPI_PORT 31 +#define SV_LOCAL_PORT 32 +#define SV_LIMITED_BROADCAST_ADDRESS 33 +#define SV_REMOTE_PORT 34 +#define SV_LOCAL_ADDRESS 35 +#define SV_OMAPI_KEY 36 +#define SV_STASH_AGENT_OPTIONS 37 +#define SV_DDNS_TTL 38 +#define SV_DDNS_UPDATE_STYLE 39 +#define SV_CLIENT_UPDATES 40 +#define SV_UPDATE_OPTIMIZATION 41 +#define SV_PING_CHECKS 42 +#define SV_UPDATE_STATIC_LEASES 43 +#define SV_LOG_FACILITY 44 +#define SV_DO_FORWARD_UPDATES 45 +#define SV_PING_TIMEOUT 46 +#define SV_RESERVE_INFINITE 47 +#define SV_DDNS_CONFLICT_DETECT 48 +#define SV_LEASEQUERY 49 +#define SV_ADAPTIVE_LEASE_TIME_THRESHOLD 50 +#define SV_DO_REVERSE_UPDATES 51 +#define SV_FQDN_REPLY 52 +#define SV_PREFER_LIFETIME 53 +#define SV_DHCPV6_LEASE_FILE_NAME 54 +#define SV_DHCPV6_PID_FILE_NAME 55 +#define SV_LIMIT_ADDRS_PER_IA 56 +#define SV_LIMIT_PREFS_PER_IA 57 +#define SV_DELAYED_ACK 58 +#define SV_MAX_ACK_DELAY 59 +#if defined(LDAP_CONFIGURATION) +# define SV_LDAP_SERVER 60 +# define SV_LDAP_PORT 61 +# define SV_LDAP_USERNAME 62 +# define SV_LDAP_PASSWORD 63 +# define SV_LDAP_BASE_DN 64 +# define SV_LDAP_METHOD 65 +# define SV_LDAP_DEBUG_FILE 66 +# define SV_LDAP_DHCP_SERVER_CN 67 +# define SV_LDAP_REFERRALS 68 +#if defined (LDAP_USE_SSL) +# define SV_LDAP_SSL 69 +# define SV_LDAP_TLS_REQCERT 70 +# define SV_LDAP_TLS_CA_FILE 71 +# define SV_LDAP_TLS_CA_DIR 72 +# define SV_LDAP_TLS_CERT 73 +# define SV_LDAP_TLS_KEY 74 +# define SV_LDAP_TLS_CRLCHECK 75 +# define SV_LDAP_TLS_CIPHERS 76 +# define SV_LDAP_TLS_RANDFILE 77 +#endif +#endif + +#if !defined (DEFAULT_PING_TIMEOUT) +# define DEFAULT_PING_TIMEOUT 1 +#endif + +#if !defined (DEFAULT_DELAYED_ACK) +# define DEFAULT_DELAYED_ACK 28 /* default SO_SNDBUF size / 576 bytes */ +#endif + +#if !defined (DEFAULT_ACK_DELAY_SECS) +# define DEFAULT_ACK_DELAY_SECS 0 +#endif + +#if !defined (DEFAULT_ACK_DELAY_USECS) +# define DEFAULT_ACK_DELAY_USECS 250000 /* 1/4 of a second */ +#endif + +#if !defined (DEFAULT_MIN_ACK_DELAY_USECS) +# define DEFAULT_MIN_ACK_DELAY_USECS 10000 /* 1/100 second */ +#endif + +#if defined(LDAP_CONFIGURATION) +# define SV_LDAP_SERVER 60 +# define SV_LDAP_PORT 61 +# define SV_LDAP_USERNAME 62 +# define SV_LDAP_PASSWORD 63 +# define SV_LDAP_BASE_DN 64 +# define SV_LDAP_METHOD 65 +# define SV_LDAP_DEBUG_FILE 66 +# define SV_LDAP_DHCP_SERVER_CN 67 +# define SV_LDAP_REFERRALS 68 +#if defined (LDAP_USE_SSL) +# define SV_LDAP_SSL 69 +# define SV_LDAP_TLS_REQCERT 70 +# define SV_LDAP_TLS_CA_FILE 71 +# define SV_LDAP_TLS_CA_DIR 72 +# define SV_LDAP_TLS_CERT 73 +# define SV_LDAP_TLS_KEY 74 +# define SV_LDAP_TLS_CRLCHECK 75 +# define SV_LDAP_TLS_CIPHERS 76 +# define SV_LDAP_TLS_RANDFILE 77 +#endif +#endif + +#if !defined (DEFAULT_DEFAULT_LEASE_TIME) +# define DEFAULT_DEFAULT_LEASE_TIME 43200 +#endif + +#if !defined (DEFAULT_MIN_LEASE_TIME) +# define DEFAULT_MIN_LEASE_TIME 300 +#endif + +#if !defined (DEFAULT_MAX_LEASE_TIME) +# define DEFAULT_MAX_LEASE_TIME 86400 +#endif + +#if !defined (DEFAULT_DDNS_TTL) +# define DEFAULT_DDNS_TTL 3600 +#endif +#if !defined (MAX_DEFAULT_DDNS_TTL) +# define MAX_DEFAULT_DDNS_TTL 3600 +#endif + +#if !defined (MIN_LEASE_WRITE) +# define MIN_LEASE_WRITE 15 +#endif + +/* Client option names */ + +#define CL_TIMEOUT 1 +#define CL_SELECT_INTERVAL 2 +#define CL_REBOOT_TIMEOUT 3 +#define CL_RETRY_INTERVAL 4 +#define CL_BACKOFF_CUTOFF 5 +#define CL_INITIAL_INTERVAL 6 +#define CL_BOOTP_POLICY 7 +#define CL_SCRIPT_NAME 8 +#define CL_REQUESTED_OPTIONS 9 +#define CL_REQUESTED_LEASE_TIME 10 +#define CL_SEND_OPTIONS 11 +#define CL_MEDIA 12 +#define CL_REJECT_LIST 13 + +#ifndef CL_DEFAULT_TIMEOUT +# define CL_DEFAULT_TIMEOUT 60 +#endif + +#ifndef CL_DEFAULT_SELECT_INTERVAL +# define CL_DEFAULT_SELECT_INTERVAL 0 +#endif + +#ifndef CL_DEFAULT_REBOOT_TIMEOUT +# define CL_DEFAULT_REBOOT_TIMEOUT 10 +#endif + +#ifndef CL_DEFAULT_RETRY_INTERVAL +# define CL_DEFAULT_RETRY_INTERVAL 300 +#endif + +#ifndef CL_DEFAULT_BACKOFF_CUTOFF +# define CL_DEFAULT_BACKOFF_CUTOFF 120 +#endif + +#ifndef CL_DEFAULT_INITIAL_INTERVAL +# define CL_DEFAULT_INITIAL_INTERVAL 10 +#endif + +#ifndef CL_DEFAULT_BOOTP_POLICY +# define CL_DEFAULT_BOOTP_POLICY P_ACCEPT +#endif + +#ifndef CL_DEFAULT_REQUESTED_OPTIONS +# define CL_DEFAULT_REQUESTED_OPTIONS \ + { DHO_SUBNET_MASK, \ + DHO_BROADCAST_ADDRESS, \ + DHO_TIME_OFFSET, \ + DHO_ROUTERS, \ + DHO_DOMAIN_NAME, \ + DHO_DOMAIN_NAME_SERVERS, \ + DHO_HOST_NAME } +#endif + +struct group_object { + OMAPI_OBJECT_PREAMBLE; + + struct group_object *n_dynamic; + struct group *group; + char *name; + int flags; +#define GROUP_OBJECT_DELETED 1 +#define GROUP_OBJECT_DYNAMIC 2 +#define GROUP_OBJECT_STATIC 4 +}; + +/* Group of declarations that share common parameters. */ +struct group { + struct group *next; + + int refcnt; + struct group_object *object; + struct subnet *subnet; + struct shared_network *shared_network; + int authoritative; + struct executable_statement *statements; +}; + +/* A dhcp host declaration structure. */ +struct host_decl { + OMAPI_OBJECT_PREAMBLE; + struct host_decl *n_ipaddr; + struct host_decl *n_dynamic; + char *name; + struct hardware interface; + struct data_string client_identifier; + struct option *host_id_option; + struct data_string host_id; + /* XXXSK: fixed_addr should be an array of iaddr values, + not an option_cache, but it's referenced in a lot of + places, so we'll leave it for now. */ + struct option_cache *fixed_addr; + struct iaddrcidrnetlist *fixed_prefix; + struct group *group; + struct group_object *named_group; + struct data_string auth_key_id; + int flags; +#define HOST_DECL_DELETED 1 +#define HOST_DECL_DYNAMIC 2 +#define HOST_DECL_STATIC 4 +}; + +struct permit { + struct permit *next; + enum { + permit_unknown_clients, + permit_known_clients, + permit_authenticated_clients, + permit_unauthenticated_clients, + permit_all_clients, + permit_dynamic_bootp_clients, + permit_class, + permit_after + } type; + struct class *class; + TIME after; /* date after which this clause applies */ +}; + +struct pool { + OMAPI_OBJECT_PREAMBLE; + struct pool *next; + struct group *group; + struct shared_network *shared_network; + struct permit *permit_list; + struct permit *prohibit_list; + struct lease *active; + struct lease *expired; + struct lease *free; + struct lease *backup; + struct lease *abandoned; + struct lease *reserved; + TIME next_event_time; + int lease_count; + int free_leases; + int backup_leases; + int index; + TIME valid_from; /* deny pool use before this date */ + TIME valid_until; /* deny pool use after this date */ + +#if defined (FAILOVER_PROTOCOL) + dhcp_failover_state_t *failover_peer; +#endif +}; + +struct shared_network { + OMAPI_OBJECT_PREAMBLE; + struct shared_network *next; + char *name; + +#define SHARED_IMPLICIT 1 /* This network was synthesized. */ + int flags; + + struct subnet *subnets; + struct interface_info *interface; + struct pool *pools; + struct ipv6_pool **ipv6_pools; /* NULL-terminated array */ + int last_ipv6_pool; /* offset of last IPv6 pool + used to issue a lease */ + struct group *group; +#if defined (FAILOVER_PROTOCOL) + dhcp_failover_state_t *failover_peer; +#endif +}; + +struct subnet { + OMAPI_OBJECT_PREAMBLE; + struct subnet *next_subnet; + struct subnet *next_sibling; + struct shared_network *shared_network; + struct interface_info *interface; + struct iaddr interface_address; + struct iaddr net; + struct iaddr netmask; + int prefix_len; /* XXX: currently for IPv6 only */ + struct group *group; +}; + +struct collection { + struct collection *next; + + const char *name; + struct class *classes; +}; + +/* Used as an argument to parse_clasS_decl() */ +#define CLASS_TYPE_VENDOR 0 +#define CLASS_TYPE_USER 1 +#define CLASS_TYPE_CLASS 2 +#define CLASS_TYPE_SUBCLASS 3 + +/* XXX classes must be reference-counted. */ +struct class { + OMAPI_OBJECT_PREAMBLE; + struct class *nic; /* Next in collection. */ + struct class *superclass; /* Set for spawned classes only. */ + char *name; /* Not set for spawned classes. */ + + /* A class may be configured to permit a limited number of leases. */ + int lease_limit; + int leases_consumed; + struct lease **billed_leases; + + /* If nonzero, class has not been saved since it was last + modified. */ + int dirty; + + /* Hash table containing subclasses. */ + class_hash_t *hash; + struct data_string hash_string; + + /* Expression used to match class. */ + struct expression *expr; + + /* Expression used to compute subclass identifiers for spawning + and to do subclass matching. */ + struct expression *submatch; + int spawning; + + struct group *group; + + /* Statements to execute if class matches. */ + struct executable_statement *statements; + +#define CLASS_DECL_DELETED 1 +#define CLASS_DECL_DYNAMIC 2 +#define CLASS_DECL_STATIC 4 +#define CLASS_DECL_SUBCLASS 8 + + int flags; +}; + +/* DHCP client lease structure... */ +struct client_lease { + struct client_lease *next; /* Next lease in list. */ + TIME expiry, renewal, rebind; /* Lease timeouts. */ + struct iaddr address; /* Address being leased. */ + char *server_name; /* Name of boot server. */ + char *filename; /* Name of file we're supposed to boot. */ + struct string_list *medium; /* Network medium. */ + struct auth_key *key; /* Key used in basic DHCP authentication. */ + + unsigned int is_static : 1; /* If set, lease is from config file. */ + unsigned int is_bootp: 1; /* If set, lease was acquired with BOOTP. */ + + struct option_state *options; /* Options supplied with lease. */ + struct iaddr next_srv_addr; /* Address of the next server to use */ +}; + +/* DHCPv6 lease structures */ +struct dhc6_addr { + struct dhc6_addr *next; + struct iaddr address; + u_int8_t plen; + + /* Address state flags. */ + #define DHC6_ADDR_DEPREFFED 0x01 + #define DHC6_ADDR_EXPIRED 0x02 + u_int8_t flags; + + TIME starts; + u_int32_t preferred_life; + u_int32_t max_life; + + struct option_state *options; +}; + +struct dhc6_ia { + struct dhc6_ia *next; + unsigned char iaid[4]; + u_int16_t ia_type; + + TIME starts; + u_int32_t renew; + u_int32_t rebind; + struct dhc6_addr *addrs; + + struct option_state *options; +}; + +struct dhc6_lease { + struct dhc6_lease *next; + struct data_string server_id; + + isc_boolean_t released; + int score; + u_int8_t pref; + + unsigned char dhcpv6_transaction_id[3]; + struct dhc6_ia *bindings; + + struct option_state *options; +}; + +/* Possible states in which the client can be. */ +enum dhcp_state { + S_REBOOTING = 1, + S_INIT = 2, + S_SELECTING = 3, + S_REQUESTING = 4, + S_BOUND = 5, + S_RENEWING = 6, + S_REBINDING = 7, + S_STOPPED = 8 +}; + +/* Authentication and BOOTP policy possibilities (not all values work + for each). */ +enum policy { P_IGNORE, P_ACCEPT, P_PREFER, P_REQUIRE, P_DONT }; + +/* Configuration information from the config file... */ +struct client_config { + /* + * When a message has been received, run these statements + * over it. + */ + struct group *on_receipt; + + /* + * When a message is sent, run these statements. + */ + struct group *on_transmission; + + struct option **required_options; /* Options that MUST be present. */ + struct option **requested_options; /* Options to request (ORO/PRL). */ + + TIME timeout; /* Start to panic if we don't get a + lease in this time period when + SELECTING. */ + TIME initial_delay; /* Set initial delay before first + transmission. */ + TIME initial_interval; /* All exponential backoff intervals + start here. */ + TIME retry_interval; /* If the protocol failed to produce + an address before the timeout, + try the protocol again after this + many seconds. */ + TIME select_interval; /* Wait this many seconds from the + first DHCPDISCOVER before + picking an offered lease. */ + TIME reboot_timeout; /* When in INIT-REBOOT, wait this + long before giving up and going + to INIT. */ + TIME backoff_cutoff; /* When doing exponential backoff, + never back off to an interval + longer than this amount. */ + u_int32_t requested_lease; /* Requested lease time, if user + doesn't configure one. */ + struct string_list *media; /* Possible network media values. */ + char *script_name; /* Name of config script. */ + char *vendor_space_name; /* Name of config script. */ + enum policy bootp_policy; + /* Ignore, accept or prefer BOOTP + responses. */ + enum policy auth_policy; + /* Require authentication, prefer + authentication, or don't try to + authenticate. */ + struct string_list *medium; /* Current network medium. */ + + struct iaddrmatchlist *reject_list; /* Servers to reject. */ + + int omapi_port; /* port on which to accept OMAPI + connections, or -1 for no + listener. */ + int do_forward_update; /* If nonzero, and if we have the + information we need, update the + A record for the address we get. */ +}; + +/* Per-interface state used in the dhcp client... */ +/* XXX: consider union {}'ing this for v4/v6. */ +struct client_state { + struct client_state *next; + struct interface_info *interface; + char *name; + + /* Common values. */ + struct client_config *config; /* Client configuration. */ + struct string_list *env; /* Client script environment. */ + int envc; /* Number of entries in environment. */ + struct option_state *sent_options; /* Options we sent. */ + enum dhcp_state state; /* Current state for this interface. */ + TIME last_write; /* Last time this state was written. */ + + /* DHCPv4 values. */ + struct client_lease *active; /* Currently active lease. */ + struct client_lease *new; /* New lease. */ + struct client_lease *offered_leases; /* Leases offered to us. */ + struct client_lease *leases; /* Leases we currently hold. */ + struct client_lease *alias; /* Alias lease. */ + + struct iaddr destination; /* Where to send packet. */ + u_int32_t xid; /* Transaction ID. */ + u_int16_t secs; /* secs value from DHCPDISCOVER. */ + TIME first_sending; /* When was first copy sent? */ + TIME interval; /* What's the current resend interval? */ + struct string_list *medium; /* Last media type tried. */ + struct dhcp_packet packet; /* Outgoing DHCP packet. */ + unsigned packet_length; /* Actual length of generated packet. */ + + struct iaddr requested_address; /* Address we would like to get. */ + + /* DHCPv6 values. */ + unsigned char dhcpv6_transaction_id[3]; + u_int8_t refresh_type; + + struct dhc6_lease *active_lease; + struct dhc6_lease *old_lease; + struct dhc6_lease *advertised_leases; + struct dhc6_lease *selected_lease; + struct dhc6_lease *held_leases; + + struct timeval start_time; + u_int16_t elapsed; + int txcount; + + /* See RFC3315 section 14. */ + TIME RT; /* In hundredths of seconds. */ + TIME IRT; /* In hundredths of seconds. */ + TIME MRC; /* Count. */ + TIME MRT; /* In hundredths of seconds. */ + TIME MRD; /* In seconds, relative. */ + TIME next_MRD; /* In seconds, absolute. */ + + /* Rather than a state, we use a function that shifts around + * depending what stage of life the v6 state machine is in. + * This is where incoming packets are dispatched to (sometimes + * a no-op). + */ + void (*v6_handler)(struct packet *, struct client_state *); + + /* + * A pointer to the state of the ddns update for this lease. + * It should be set while the update is in progress and cleared + * when the update finishes. It can be used to cancel the + * update if we want to do a different update. + */ + struct dhcp_ddns_cb *ddns_cb; +}; + +struct envadd_state { + struct client_state *client; + const char *prefix; +}; + +struct dns_update_state { + struct client_state *client; + struct iaddr address; + int dns_update_timeout; +}; + +/* Information about each network interface. */ + +struct interface_info { + OMAPI_OBJECT_PREAMBLE; + struct interface_info *next; /* Next interface in list... */ + struct shared_network *shared_network; + /* Networks connected to this interface. */ + struct hardware hw_address; /* Its physical address. */ + struct in_addr *addresses; /* Addresses associated with this + * interface. + */ + int address_count; /* Number of addresses stored. */ + int address_max; /* Size of addresses buffer. */ + struct in6_addr *v6addresses; /* IPv6 addresses associated with + this interface. */ + int v6address_count; /* Number of IPv6 addresses associated + with this interface. */ + int v6address_max; /* Maximum number of IPv6 addresses + we can store in current buffer. */ + + u_int8_t *circuit_id; /* Circuit ID associated with this + interface. */ + unsigned circuit_id_len; /* Length of Circuit ID, if there + is one. */ + u_int8_t *remote_id; /* Remote ID associated with this + interface (if any). */ + unsigned remote_id_len; /* Length of Remote ID. */ + + char name [IFNAMSIZ]; /* Its name... */ + int index; /* Its if_nametoindex(). */ + int rfdesc; /* Its read file descriptor. */ + int wfdesc; /* Its write file descriptor, if + different. */ + unsigned char *rbuf; /* Read buffer, if required. */ + unsigned int rbuf_max; /* Size of read buffer. */ + size_t rbuf_offset; /* Current offset into buffer. */ + size_t rbuf_len; /* Length of data in buffer. */ + + struct ifreq *ifp; /* Pointer to ifreq struct. */ + int configured; /* If set to 1, interface has at least + * one valid IP address. + */ + u_int32_t flags; /* Control flags... */ +#define INTERFACE_REQUESTED 1 +#define INTERFACE_AUTOMATIC 2 +#define INTERFACE_RUNNING 4 +#define INTERFACE_DOWNSTREAM 8 +#define INTERFACE_UPSTREAM 16 +#define INTERFACE_STREAMS (INTERFACE_DOWNSTREAM | INTERFACE_UPSTREAM) + + /* Only used by DHCP client code. */ + struct client_state *client; +# if defined(USE_DLPI_SEND) || defined(USE_DLPI_RECEIVE) || \ + defined(USE_DLPI_HWADDR) + int dlpi_sap_length; + struct hardware dlpi_broadcast_addr; +# endif /* DLPI_SEND || DLPI_RECEIVE */ + struct hardware anycast_mac_addr; +}; + +struct hardware_link { + struct hardware_link *next; + char name [IFNAMSIZ]; + struct hardware address; +}; + +struct leasequeue { + struct leasequeue *prev; + struct leasequeue *next; + struct lease *lease; +}; + +typedef void (*tvref_t)(void *, void *, const char *, int); +typedef void (*tvunref_t)(void *, const char *, int); +struct timeout { + struct timeout *next; + struct timeval when; + void (*func) (void *); + void *what; + tvref_t ref; + tvunref_t unref; + isc_timer_t *isc_timeout; +}; + +struct eventqueue { + struct eventqueue *next; + void (*handler)(void *); +}; + +struct protocol { + struct protocol *next; + int fd; + void (*handler) (struct protocol *); + void *local; +}; + +struct dns_query; /* forward */ + +struct dns_wakeup { + struct dns_wakeup *next; /* Next wakeup in chain. */ + void (*func) (struct dns_query *); +}; + +struct dns_question { + u_int16_t type; /* Type of query. */ + u_int16_t class; /* Class of query. */ + unsigned char data [1]; /* Query data. */ +}; + +struct dns_answer { + u_int16_t type; /* Type of answer. */ + u_int16_t class; /* Class of answer. */ + int count; /* Number of answers. */ + unsigned char *answers[1]; /* Pointers to answers. */ +}; + +struct dns_query { + struct dns_query *next; /* Next query in hash bucket. */ + u_int32_t hash; /* Hash bucket index. */ + TIME expiry; /* Query expiry time (zero if not yet + answered. */ + u_int16_t id; /* Query ID (also hash table index) */ + caddr_t waiters; /* Pointer to list of things waiting + on this query. */ + + struct dns_question *question; /* Question, internal format. */ + struct dns_answer *answer; /* Answer, internal format. */ + + unsigned char *query; /* Query formatted for DNS server. */ + unsigned len; /* Length of entire query. */ + int sent; /* The query has been sent. */ + struct dns_wakeup *wakeups; /* Wakeups to call if this query is + answered. */ + struct name_server *next_server; /* Next server to try. */ + int backoff; /* Current backoff, in seconds. */ +}; + +struct dns_zone { + int refcnt; + TIME timeout; + char *name; + struct option_cache *primary; + struct option_cache *secondary; + struct option_cache *primary6; + struct option_cache *secondary6; + struct auth_key *key; +}; + +struct icmp_state { + OMAPI_OBJECT_PREAMBLE; + int socket; + void (*icmp_handler) (struct iaddr, u_int8_t *, int); +}; + +#include "ctrace.h" + +/* Bitmask of dhcp option codes. */ +typedef unsigned char option_mask [16]; + +/* DHCP Option mask manipulation macros... */ +#define OPTION_ZERO(mask) (memset (mask, 0, 16)) +#define OPTION_SET(mask, bit) (mask [bit >> 8] |= (1 << (bit & 7))) +#define OPTION_CLR(mask, bit) (mask [bit >> 8] &= ~(1 << (bit & 7))) +#define OPTION_ISSET(mask, bit) (mask [bit >> 8] & (1 << (bit & 7))) +#define OPTION_ISCLR(mask, bit) (!OPTION_ISSET (mask, bit)) + +/* An option occupies its length plus two header bytes (code and + length) for every 255 bytes that must be stored. */ +#define OPTION_SPACE(x) ((x) + 2 * ((x) / 255 + 1)) + +/* Default path to dhcpd config file. */ +#ifdef DEBUG +#undef _PATH_DHCPD_CONF +#define _PATH_DHCPD_CONF "dhcpd.conf" +#undef _PATH_DHCPD_DB +#define _PATH_DHCPD_DB "dhcpd.leases" +#undef _PATH_DHCPD6_DB +#define _PATH_DHCPD6_DB "dhcpd6.leases" +#undef _PATH_DHCPD_PID +#define _PATH_DHCPD_PID "dhcpd.pid" +#undef _PATH_DHCPD6_PID +#define _PATH_DHCPD6_PID "dhcpd6.pid" +#else /* !DEBUG */ + +#ifndef _PATH_DHCPD_CONF +#define _PATH_DHCPD_CONF "/etc/dhcpd.conf" +#endif /* DEBUG */ + +#ifndef _PATH_DHCPD_DB +#define _PATH_DHCPD_DB LOCALSTATEDIR"/db/dhcpd.leases" +#endif + +#ifndef _PATH_DHCPD6_DB +#define _PATH_DHCPD6_DB LOCALSTATEDIR"/db/dhcpd6.leases" +#endif + +#ifndef _PATH_DHCPD_PID +#define _PATH_DHCPD_PID LOCALSTATEDIR"/run/dhcpd.pid" +#endif + +#ifndef _PATH_DHCPD6_PID +#define _PATH_DHCPD6_PID LOCALSTATEDIR"/run/dhcpd6.pid" +#endif + +#endif /* DEBUG */ + +#ifndef _PATH_DHCLIENT_CONF +#define _PATH_DHCLIENT_CONF "/etc/dhclient.conf" +#endif + +#ifndef _PATH_DHCLIENT_SCRIPT +#define _PATH_DHCLIENT_SCRIPT "/sbin/dhclient-script" +#endif + +#ifndef _PATH_DHCLIENT_PID +#define _PATH_DHCLIENT_PID LOCALSTATEDIR"/run/dhclient.pid" +#endif + +#ifndef _PATH_DHCLIENT6_PID +#define _PATH_DHCLIENT6_PID LOCALSTATEDIR"/run/dhclient6.pid" +#endif + +#ifndef _PATH_DHCLIENT_DB +#define _PATH_DHCLIENT_DB LOCALSTATEDIR"/db/dhclient.leases" +#endif + +#ifndef _PATH_DHCLIENT6_DB +#define _PATH_DHCLIENT6_DB LOCALSTATEDIR"/db/dhclient6.leases" +#endif + +#ifndef _PATH_RESOLV_CONF +#define _PATH_RESOLV_CONF "/etc/resolv.conf" +#endif + +#ifndef _PATH_DHCRELAY_PID +#define _PATH_DHCRELAY_PID LOCALSTATEDIR"/run/dhcrelay.pid" +#endif + +#ifndef _PATH_DHCRELAY6_PID +#define _PATH_DHCRELAY6_PID LOCALSTATEDIR"/run/dhcrelay6.pid" +#endif + +#ifndef DHCPD_LOG_FACILITY +#define DHCPD_LOG_FACILITY LOG_DAEMON +#endif + +#define MAX_TIME 0x7fffffff +#define MIN_TIME 0 + +#ifdef USE_LOG_PID +/* include the pid in the syslog messages */ +#define DHCP_LOG_OPTIONS LOG_NDELAY | LOG_PID +#else +#define DHCP_LOG_OPTIONS LOG_NDELAY +#endif + /* these are referenced */ +typedef struct hash_table ia_hash_t; +typedef struct hash_table iasubopt_hash_t; + + /* IAADDR/IAPREFIX lease */ + +struct iasubopt { + int refcnt; /* reference count */ + struct in6_addr addr; /* IPv6 address/prefix */ + u_int8_t plen; /* iaprefix prefix length */ + binding_state_t state; /* state */ + struct binding_scope *scope; /* "set var = value;" */ + time_t hard_lifetime_end_time; /* time address expires */ + time_t soft_lifetime_end_time; /* time ephemeral expires */ + u_int32_t prefer; /* cached preferred lifetime */ + u_int32_t valid; /* cached valid lifetime */ + struct ia_xx *ia; /* IA for this lease */ + struct ipv6_pool *ipv6_pool; /* pool for this lease */ +/* + * For now, just pick an arbitrary time to keep old hard leases + * around (value in seconds). + */ +#define EXPIRED_IPV6_CLEANUP_TIME (60*60) + + int heap_index; /* index into heap, or -1 + (internal use only) */ + + /* + * A pointer to the state of the ddns update for this lease. + * It should be set while the update is in progress and cleared + * when the update finishes. It can be used to cancel the + * update if we want to do a different update. + */ + struct dhcp_ddns_cb *ddns_cb; + +}; + +struct ia_xx { + int refcnt; /* reference count */ + struct data_string iaid_duid; /* from the client */ + u_int16_t ia_type; /* IA_XX */ + int num_iasubopt; /* number of IAADDR/PREFIX */ + int max_iasubopt; /* space available for IAADDR/PREFIX */ + time_t cltt; /* client last transaction time */ + struct iasubopt **iasubopt; /* pointers to the IAADDR/IAPREFIXs */ +}; + +extern ia_hash_t *ia_na_active; +extern ia_hash_t *ia_ta_active; +extern ia_hash_t *ia_pd_active; + +struct ipv6_pool { + int refcnt; /* reference count */ + u_int16_t pool_type; /* IA_xx */ + struct in6_addr start_addr; /* first IPv6 address */ + int bits; /* number of bits, CIDR style */ + int units; /* allocation unit in bits */ + iasubopt_hash_t *leases; /* non-free leases */ + int num_active; /* count of active leases */ + isc_heap_t *active_timeouts; /* timeouts for active leases */ + int num_inactive; /* count of inactive leases */ + isc_heap_t *inactive_timeouts; /* timeouts for expired or + released leases */ + struct shared_network *shared_network; /* shared_network for + this pool */ + struct subnet *subnet; /* subnet for this pool */ +}; + +/* Flags and state for dhcp_ddns_cb_t */ +#define DDNS_UPDATE_ADDR 0x01 +#define DDNS_UPDATE_PTR 0x02 +#define DDNS_INCLUDE_RRSET 0x04 +#define DDNS_CONFLICT_OVERRIDE 0x08 +#define DDNS_CLIENT_DID_UPDATE 0x10 +#define DDNS_EXECUTE_NEXT 0x20 +#define DDNS_ABORT 0x40 +#define DDNS_STATIC_LEASE 0x80 +#define DDNS_ACTIVE_LEASE 0x100 +/* + * The following two groups are separate and we could reuse + * values but not reusing them may be useful in the future. + */ +#define DDNS_STATE_CLEANUP 0 // The previous step failed, cleanup + +#define DDNS_STATE_ADD_FW_NXDOMAIN 1 +#define DDNS_STATE_ADD_FW_YXDHCID 2 +#define DDNS_STATE_ADD_PTR 3 + +#define DDNS_STATE_REM_FW_YXDHCID 17 +#define DDNS_STATE_REM_FW_NXRR 18 +#define DDNS_STATE_REM_PTR 19 + +/* + * Flags for the dns print function + */ +#define DDNS_PRINT_INBOUND 1 +#define DDNS_PRINT_OUTBOUND 0 + +struct dhcp_ddns_cb; + +typedef void (*ddns_action_t)(struct dhcp_ddns_cb *ddns_cb, + isc_result_t result); + +typedef struct dhcp_ddns_cb { + struct data_string fwd_name; + struct data_string rev_name; + struct data_string dhcid; + struct iaddr address; + int address_type; + + unsigned long ttl; + + unsigned char zone_name[DHCP_MAXDNS_WIRE]; + isc_sockaddrlist_t zone_server_list; + isc_sockaddr_t zone_addrs[DHCP_MAXNS]; + int zone_addr_count; + struct dns_zone *zone; + + u_int16_t flags; + TIME timeout; + int state; + ddns_action_t cur_func; + + struct dhcp_ddns_cb * next_op; + + /* Lease or client state that triggered the ddns operation */ + void *lease; + struct binding_scope **scope; + + void *transaction; + void *dataspace; +} dhcp_ddns_cb_t; + +extern struct ipv6_pool **pools; +extern int num_pools; + +/* External definitions... */ + +HASH_FUNCTIONS_DECL (group, const char *, struct group_object, group_hash_t) +HASH_FUNCTIONS_DECL (universe, const char *, struct universe, universe_hash_t) +HASH_FUNCTIONS_DECL (option_name, const char *, struct option, + option_name_hash_t) +HASH_FUNCTIONS_DECL (option_code, const unsigned *, struct option, + option_code_hash_t) +HASH_FUNCTIONS_DECL (dns_zone, const char *, struct dns_zone, dns_zone_hash_t) +HASH_FUNCTIONS_DECL(lease_ip, const unsigned char *, struct lease, + lease_ip_hash_t) +HASH_FUNCTIONS_DECL(lease_id, const unsigned char *, struct lease, + lease_id_hash_t) +HASH_FUNCTIONS_DECL (host, const unsigned char *, struct host_decl, host_hash_t) +HASH_FUNCTIONS_DECL (class, const char *, struct class, class_hash_t) + +/* options.c */ + +extern struct option *vendor_cfg_option; +int parse_options (struct packet *); +int parse_option_buffer (struct option_state *, const unsigned char *, + unsigned, struct universe *); +struct universe *find_option_universe (struct option *, const char *); +int parse_encapsulated_suboptions (struct option_state *, struct option *, + const unsigned char *, unsigned, + struct universe *, const char *); +int cons_options (struct packet *, struct dhcp_packet *, struct lease *, + struct client_state *, + int, struct option_state *, struct option_state *, + struct binding_scope **, + int, int, int, struct data_string *, const char *); +int fqdn_universe_decode (struct option_state *, + const unsigned char *, unsigned, struct universe *); +struct option_cache * +lookup_fqdn6_option(struct universe *universe, struct option_state *options, + unsigned code); +void +save_fqdn6_option(struct universe *universe, struct option_state *options, + struct option_cache *oc, isc_boolean_t appendp); +void +delete_fqdn6_option(struct universe *universe, struct option_state *options, + int code); +void +fqdn6_option_space_foreach(struct packet *packet, struct lease *lease, + struct client_state *client_state, + struct option_state *in_options, + struct option_state *cfg_options, + struct binding_scope **scope, + struct universe *u, void *stuff, + void (*func)(struct option_cache *, + struct packet *, + struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *, void *)); +int +fqdn6_option_space_encapsulate(struct data_string *result, + struct packet *packet, struct lease *lease, + struct client_state *client_state, + struct option_state *in_options, + struct option_state *cfg_options, + struct binding_scope **scope, + struct universe *universe); +int +fqdn6_universe_decode(struct option_state *options, + const unsigned char *buffer, unsigned length, + struct universe *u); +int append_option(struct data_string *dst, struct universe *universe, + struct option *option, struct data_string *src); +int +store_options(int *ocount, + unsigned char *buffer, unsigned buflen, unsigned index, + struct packet *packet, struct lease *lease, + struct client_state *client_state, + struct option_state *in_options, + struct option_state *cfg_options, + struct binding_scope **scope, + unsigned *priority_list, int priority_len, + unsigned first_cutoff, int second_cutoff, int terminate, + const char *vuname); +int store_options6(char *, int, struct option_state *, struct packet *, + const int *, struct data_string *); +int format_has_text(const char *); +int format_min_length(const char *, struct option_cache *); +const char *pretty_print_option (struct option *, const unsigned char *, + unsigned, int, int); +int pretty_escape(char **, char *, const unsigned char **, + const unsigned char *); +int get_option (struct data_string *, struct universe *, + struct packet *, struct lease *, struct client_state *, + struct option_state *, struct option_state *, + struct option_state *, struct binding_scope **, unsigned, + const char *, int); +void set_option (struct universe *, struct option_state *, + struct option_cache *, enum statement_op); +struct option_cache *lookup_option (struct universe *, + struct option_state *, unsigned); +struct option_cache *lookup_hashed_option (struct universe *, + struct option_state *, + unsigned); +struct option_cache *next_hashed_option(struct universe *, + struct option_state *, + struct option_cache *); +int save_option_buffer (struct universe *, struct option_state *, + struct buffer *, unsigned char *, unsigned, + unsigned, int); +int append_option_buffer(struct universe *, struct option_state *, + struct buffer *, unsigned char *, unsigned, + unsigned, int); +void build_server_oro(struct data_string *, struct option_state *, + const char *, int); +void save_option(struct universe *, struct option_state *, + struct option_cache *); +void also_save_option(struct universe *, struct option_state *, + struct option_cache *); +void save_hashed_option(struct universe *, struct option_state *, + struct option_cache *, isc_boolean_t appendp); +void delete_option (struct universe *, struct option_state *, int); +void delete_hashed_option (struct universe *, + struct option_state *, int); +int option_cache_dereference (struct option_cache **, + const char *, int); +int hashed_option_state_dereference (struct universe *, + struct option_state *, + const char *, int); +int store_option (struct data_string *, + struct universe *, struct packet *, struct lease *, + struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, struct option_cache *); +int option_space_encapsulate (struct data_string *, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct data_string *); +int hashed_option_space_encapsulate (struct data_string *, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *); +int nwip_option_space_encapsulate (struct data_string *, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *); +int fqdn_option_space_encapsulate (struct data_string *, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *); +void suboption_foreach (struct packet *, struct lease *, struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, struct universe *, void *, + void (*) (struct option_cache *, struct packet *, + struct lease *, struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, + struct universe *, void *), + struct option_cache *, const char *); +void option_space_foreach (struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *, void *, + void (*) (struct option_cache *, + struct packet *, + struct lease *, struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *, void *)); +void hashed_option_space_foreach (struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *, void *, + void (*) (struct option_cache *, + struct packet *, + struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *, void *)); +int linked_option_get (struct data_string *, struct universe *, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, struct option_state *, + struct option_state *, struct binding_scope **, + unsigned); +int linked_option_state_dereference (struct universe *, + struct option_state *, + const char *, int); +void save_linked_option(struct universe *, struct option_state *, + struct option_cache *, isc_boolean_t appendp); +void linked_option_space_foreach (struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *, void *, + void (*) (struct option_cache *, + struct packet *, + struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *, void *)); +int linked_option_space_encapsulate (struct data_string *, struct packet *, + struct lease *, struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *); +void delete_linked_option (struct universe *, struct option_state *, int); +struct option_cache *lookup_linked_option (struct universe *, + struct option_state *, unsigned); +void do_packet (struct interface_info *, + struct dhcp_packet *, unsigned, + unsigned int, struct iaddr, struct hardware *); +void do_packet6(struct interface_info *, const char *, + int, int, const struct iaddr *, isc_boolean_t); +int packet6_len_okay(const char *, int); + +int validate_packet(struct packet *); + +int add_option(struct option_state *options, + unsigned int option_num, + void *data, + unsigned int data_len); + +/* dhcpd.c */ +extern struct timeval cur_tv; +#define cur_time cur_tv.tv_sec + +extern int ddns_update_style; + +extern const char *path_dhcpd_conf; +extern const char *path_dhcpd_db; +extern const char *path_dhcpd_pid; + +extern int dhcp_max_agent_option_packet_length; +extern struct eventqueue *rw_queue_empty; + +int main(int, char **); +void postconf_initialization(int); +void postdb_startup(void); +void cleanup (void); +void lease_pinged (struct iaddr, u_int8_t *, int); +void lease_ping_timeout (void *); +int dhcpd_interface_setup_hook (struct interface_info *ip, struct iaddr *ia); +extern enum dhcp_shutdown_state shutdown_state; +isc_result_t dhcp_io_shutdown (omapi_object_t *, void *); +isc_result_t dhcp_set_control_state (control_object_state_t oldstate, + control_object_state_t newstate); +#if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) +void relinquish_ackqueue(void); +#endif + +/* conflex.c */ +isc_result_t new_parse (struct parse **, int, + char *, unsigned, const char *, int); +isc_result_t end_parse (struct parse **); +isc_result_t save_parse_state(struct parse *cfile); +isc_result_t restore_parse_state(struct parse *cfile); +enum dhcp_token next_token (const char **, unsigned *, struct parse *); +enum dhcp_token peek_token (const char **, unsigned *, struct parse *); +enum dhcp_token next_raw_token(const char **rval, unsigned *rlen, + struct parse *cfile); +enum dhcp_token peek_raw_token(const char **rval, unsigned *rlen, + struct parse *cfile); +/* + * Use skip_token when we are skipping a token we have previously + * used peek_token on as we know what the result will be in this case. + */ +#define skip_token(a,b,c) ((void) next_token((a),(b),(c))) + + +/* confpars.c */ +void parse_trace_setup (void); +isc_result_t readconf (void); +isc_result_t read_conf_file (const char *, struct group *, int, int); +#if defined (TRACING) +void trace_conf_input (trace_type_t *, unsigned, char *); +void trace_conf_stop (trace_type_t *ttype); +#endif +isc_result_t conf_file_subparse (struct parse *, struct group *, int); +isc_result_t lease_file_subparse (struct parse *); +int parse_statement (struct parse *, struct group *, int, + struct host_decl *, int); +#if defined (FAILOVER_PROTOCOL) +void parse_failover_peer (struct parse *, struct group *, int); +void parse_failover_state_declaration (struct parse *, + dhcp_failover_state_t *); +void parse_failover_state (struct parse *, + enum failover_state *, TIME *); +#endif +int permit_list_match (struct permit *, struct permit *); +void parse_pool_statement (struct parse *, struct group *, int); +int parse_lbrace (struct parse *); +void parse_host_declaration (struct parse *, struct group *); +int parse_class_declaration (struct class **, struct parse *, + struct group *, int); +void parse_shared_net_declaration (struct parse *, struct group *); +void parse_subnet_declaration (struct parse *, + struct shared_network *); +void parse_subnet6_declaration (struct parse *, + struct shared_network *); +void parse_group_declaration (struct parse *, struct group *); +int parse_fixed_addr_param (struct option_cache **, + struct parse *, enum dhcp_token); +int parse_lease_declaration (struct lease **, struct parse *); +int parse_ip6_addr(struct parse *, struct iaddr *); +int parse_ip6_addr_expr(struct expression **, struct parse *); +int parse_ip6_prefix(struct parse *, struct iaddr *, u_int8_t *); +void parse_address_range (struct parse *, struct group *, int, + struct pool *, struct lease **); +void parse_address_range6(struct parse *cfile, struct group *group); +void parse_prefix6(struct parse *cfile, struct group *group); +void parse_fixed_prefix6(struct parse *cfile, struct host_decl *host_decl); +void parse_ia_na_declaration(struct parse *); +void parse_ia_ta_declaration(struct parse *); +void parse_ia_pd_declaration(struct parse *); +void parse_server_duid(struct parse *cfile); +void parse_server_duid_conf(struct parse *cfile); + +/* ddns.c */ +int ddns_updates(struct packet *, struct lease *, struct lease *, + struct iasubopt *, struct iasubopt *, struct option_state *); +isc_result_t ddns_removals(struct lease *, struct iasubopt *, + struct dhcp_ddns_cb *, isc_boolean_t); +#if defined (TRACING) +void trace_ddns_init(void); +#endif + +/* parse.c */ +void add_enumeration (struct enumeration *); +struct enumeration *find_enumeration (const char *, int); +struct enumeration_value *find_enumeration_value (const char *, int, + unsigned *, + const char *); +void skip_to_semi (struct parse *); +void skip_to_rbrace (struct parse *, int); +int parse_semi (struct parse *); +int parse_string (struct parse *, char **, unsigned *); +char *parse_host_name (struct parse *); +int parse_ip_addr_or_hostname (struct expression **, + struct parse *, int); +void parse_hardware_param (struct parse *, struct hardware *); +void parse_lease_time (struct parse *, TIME *); +unsigned char *parse_numeric_aggregate (struct parse *, + unsigned char *, unsigned *, + int, int, unsigned); +void convert_num (struct parse *, unsigned char *, const char *, + int, unsigned); +TIME parse_date (struct parse *); +TIME parse_date_core(struct parse *); +isc_result_t parse_option_name (struct parse *, int, int *, + struct option **); +void parse_option_space_decl (struct parse *); +int parse_option_code_definition (struct parse *, struct option *); +int parse_base64 (struct data_string *, struct parse *); +int parse_cshl (struct data_string *, struct parse *); +int parse_executable_statement (struct executable_statement **, + struct parse *, int *, + enum expression_context); +int parse_executable_statements (struct executable_statement **, + struct parse *, int *, + enum expression_context); +int parse_zone (struct dns_zone *, struct parse *); +int parse_key (struct parse *); +int parse_on_statement (struct executable_statement **, + struct parse *, int *); +int parse_switch_statement (struct executable_statement **, + struct parse *, int *); +int parse_case_statement (struct executable_statement **, + struct parse *, int *, + enum expression_context); +int parse_if_statement (struct executable_statement **, + struct parse *, int *); +int parse_boolean_expression (struct expression **, + struct parse *, int *); +int parse_boolean (struct parse *); +int parse_data_expression (struct expression **, + struct parse *, int *); +int parse_numeric_expression (struct expression **, + struct parse *, int *); +int parse_dns_expression (struct expression **, struct parse *, int *); +int parse_non_binary (struct expression **, struct parse *, int *, + enum expression_context); +int parse_expression (struct expression **, struct parse *, int *, + enum expression_context, + struct expression **, enum expr_op); +int parse_option_data(struct expression **expr, struct parse *cfile, + int lookups, struct option *option); +int parse_option_statement (struct executable_statement **, + struct parse *, int, + struct option *, enum statement_op); +int parse_option_token (struct expression **, struct parse *, + const char **, struct expression *, int, int); +int parse_allow_deny (struct option_cache **, struct parse *, int); +int parse_auth_key (struct data_string *, struct parse *); +int parse_warn (struct parse *, const char *, ...) + __attribute__((__format__(__printf__,2,3))); +struct expression *parse_domain_list(struct parse *cfile, int); + + +/* tree.c */ +#if defined (NSUPDATE) +extern struct __res_state resolver_state; +extern int resolver_inited; +#endif + +extern struct binding_scope *global_scope; +pair cons (caddr_t, pair); +int make_const_option_cache (struct option_cache **, struct buffer **, + u_int8_t *, unsigned, struct option *, + const char *, int); +int make_host_lookup (struct expression **, const char *); +int enter_dns_host (struct dns_host_entry **, const char *); +int make_const_data (struct expression **, + const unsigned char *, unsigned, int, int, + const char *, int); +int make_const_int (struct expression **, unsigned long); +int make_concat (struct expression **, + struct expression *, struct expression *); +int make_encapsulation (struct expression **, struct data_string *); +int make_substring (struct expression **, struct expression *, + struct expression *, struct expression *); +int make_limit (struct expression **, struct expression *, int); +int make_let (struct executable_statement **, const char *); +int option_cache (struct option_cache **, struct data_string *, + struct expression *, struct option *, + const char *, int); +int evaluate_expression (struct binding_value **, struct packet *, + struct lease *, struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, struct expression *, + const char *, int); +int binding_value_dereference (struct binding_value **, const char *, int); +#if defined (NSUPDATE_OLD) +int evaluate_dns_expression (ns_updrec **, struct packet *, + struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct expression *); +#endif +int evaluate_boolean_expression (int *, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct expression *); +int evaluate_data_expression (struct data_string *, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct expression *, const char *, int); +int evaluate_numeric_expression (unsigned long *, struct packet *, + struct lease *, struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, + struct expression *); +int evaluate_option_cache (struct data_string *, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, + struct option_cache *, + const char *, int); +int evaluate_boolean_option_cache (int *, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct option_cache *, + const char *, int); +int evaluate_boolean_expression_result (int *, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct expression *); +void expression_dereference (struct expression **, const char *, int); +int is_dns_expression (struct expression *); +int is_boolean_expression (struct expression *); +int is_data_expression (struct expression *); +int is_numeric_expression (struct expression *); +int is_compound_expression (struct expression *); +int op_precedence (enum expr_op, enum expr_op); +enum expression_context expression_context (struct expression *); +enum expression_context op_context (enum expr_op); +int write_expression (FILE *, struct expression *, int, int, int); +struct binding *find_binding (struct binding_scope *, const char *); +int free_bindings (struct binding_scope *, const char *, int); +int binding_scope_dereference (struct binding_scope **, + const char *, int); +int fundef_dereference (struct fundef **, const char *, int); +int data_subexpression_length (int *, struct expression *); +int expr_valid_for_context (struct expression *, enum expression_context); +struct binding *create_binding (struct binding_scope **, const char *); +int bind_ds_value (struct binding_scope **, + const char *, struct data_string *); +int find_bound_string (struct data_string *, + struct binding_scope *, const char *); +int unset (struct binding_scope *, const char *); +int data_string_sprintfa(struct data_string *ds, const char *fmt, ...); +int concat_dclists (struct data_string *, struct data_string *, + struct data_string *); + +/* dhcp.c */ +extern int outstanding_pings; +extern int max_outstanding_acks; +extern int max_ack_delay_secs; +extern int max_ack_delay_usecs; + +void dhcp (struct packet *); +void dhcpdiscover (struct packet *, int); +void dhcprequest (struct packet *, int, struct lease *); +void dhcprelease (struct packet *, int); +void dhcpdecline (struct packet *, int); +void dhcpinform (struct packet *, int); +void nak_lease (struct packet *, struct iaddr *cip); +void ack_lease (struct packet *, struct lease *, + unsigned int, TIME, char *, int, struct host_decl *); +void delayed_ack_enqueue(struct lease *); +void commit_leases_readerdry(void *); +void flush_ackqueue(void *); +void dhcp_reply (struct lease *); +int find_lease (struct lease **, struct packet *, + struct shared_network *, int *, int *, struct lease *, + const char *, int); +int mockup_lease (struct lease **, struct packet *, + struct shared_network *, + struct host_decl *); +void static_lease_dereference (struct lease *, const char *, int); + +int allocate_lease (struct lease **, struct packet *, + struct pool *, int *); +int permitted (struct packet *, struct permit *); +int locate_network (struct packet *); +int parse_agent_information_option (struct packet *, int, u_int8_t *); +unsigned cons_agent_information_options (struct option_state *, + struct dhcp_packet *, + unsigned, unsigned); +void get_server_source_address(struct in_addr *from, + struct option_state *options, + struct option_state *out_options, + struct packet *packet); +void setup_server_source_address(struct in_addr *from, + struct option_state *options, + struct packet *packet); + +/* dhcpleasequery.c */ +void dhcpleasequery (struct packet *, int); +void dhcpv6_leasequery (struct data_string *, struct packet *); + +/* dhcpv6.c */ +isc_boolean_t server_duid_isset(void); +void copy_server_duid(struct data_string *ds, const char *file, int line); +void set_server_duid(struct data_string *new_duid); +isc_result_t set_server_duid_from_option(void); +void set_server_duid_type(int type); +isc_result_t generate_new_server_duid(void); +isc_result_t get_client_id(struct packet *, struct data_string *); +void dhcpv6(struct packet *); + +/* bootp.c */ +void bootp(struct packet *); +void use_host_decl_name(struct packet *, struct lease* , struct option_state *); + +/* memory.c */ +extern int (*group_write_hook) (struct group_object *); +extern struct group *root_group; +extern group_hash_t *group_name_hash; +isc_result_t delete_group (struct group_object *, int); +isc_result_t supersede_group (struct group_object *, int); +int clone_group (struct group **, struct group *, const char *, int); +int write_group (struct group_object *); + +/* salloc.c */ +void relinquish_lease_hunks (void); +struct lease *new_leases (unsigned, const char *, int); +#if defined (DEBUG_MEMORY_LEAKAGE) || \ + defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) +void relinquish_free_lease_states (void); +#endif +OMAPI_OBJECT_ALLOC_DECL (lease, struct lease, dhcp_type_lease) +OMAPI_OBJECT_ALLOC_DECL (class, struct class, dhcp_type_class) +OMAPI_OBJECT_ALLOC_DECL (subclass, struct class, dhcp_type_subclass) +OMAPI_OBJECT_ALLOC_DECL (pool, struct pool, dhcp_type_pool) +OMAPI_OBJECT_ALLOC_DECL (host, struct host_decl, dhcp_type_host) + +/* alloc.c */ +OMAPI_OBJECT_ALLOC_DECL (subnet, struct subnet, dhcp_type_subnet) +OMAPI_OBJECT_ALLOC_DECL (shared_network, struct shared_network, + dhcp_type_shared_network) +OMAPI_OBJECT_ALLOC_DECL (group_object, struct group_object, dhcp_type_group) +OMAPI_OBJECT_ALLOC_DECL (dhcp_control, + dhcp_control_object_t, dhcp_type_control) + +#if defined (DEBUG_MEMORY_LEAKAGE) || \ + defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) +void relinquish_free_pairs (void); +void relinquish_free_expressions (void); +void relinquish_free_binding_values (void); +void relinquish_free_option_caches (void); +void relinquish_free_packets (void); +#endif + +int option_chain_head_allocate (struct option_chain_head **, + const char *, int); +int option_chain_head_reference (struct option_chain_head **, + struct option_chain_head *, + const char *, int); +int option_chain_head_dereference (struct option_chain_head **, + const char *, int); +int group_allocate (struct group **, const char *, int); +int group_reference (struct group **, struct group *, const char *, int); +int group_dereference (struct group **, const char *, int); +struct dhcp_packet *new_dhcp_packet (const char *, int); +struct protocol *new_protocol (const char *, int); +struct lease_state *new_lease_state (const char *, int); +struct domain_search_list *new_domain_search_list (const char *, int); +struct name_server *new_name_server (const char *, int); +void free_name_server (struct name_server *, const char *, int); +struct option *new_option (const char *, const char *, int); +int option_reference(struct option **dest, struct option *src, + const char * file, int line); +int option_dereference(struct option **dest, const char *file, int line); +struct universe *new_universe (const char *, int); +void free_universe (struct universe *, const char *, int); +void free_domain_search_list (struct domain_search_list *, + const char *, int); +void free_lease_state (struct lease_state *, const char *, int); +void free_protocol (struct protocol *, const char *, int); +void free_dhcp_packet (struct dhcp_packet *, const char *, int); +struct client_lease *new_client_lease (const char *, int); +void free_client_lease (struct client_lease *, const char *, int); +struct permit *new_permit (const char *, int); +void free_permit (struct permit *, const char *, int); +pair new_pair (const char *, int); +void free_pair (pair, const char *, int); +int expression_allocate (struct expression **, const char *, int); +int expression_reference (struct expression **, + struct expression *, const char *, int); +void free_expression (struct expression *, const char *, int); +int binding_value_allocate (struct binding_value **, + const char *, int); +int binding_value_reference (struct binding_value **, + struct binding_value *, + const char *, int); +void free_binding_value (struct binding_value *, const char *, int); +int fundef_allocate (struct fundef **, const char *, int); +int fundef_reference (struct fundef **, + struct fundef *, const char *, int); +int option_cache_allocate (struct option_cache **, const char *, int); +int option_cache_reference (struct option_cache **, + struct option_cache *, const char *, int); +int buffer_allocate (struct buffer **, unsigned, const char *, int); +int buffer_reference (struct buffer **, struct buffer *, + const char *, int); +int buffer_dereference (struct buffer **, const char *, int); +int dns_host_entry_allocate (struct dns_host_entry **, + const char *, const char *, int); +int dns_host_entry_reference (struct dns_host_entry **, + struct dns_host_entry *, + const char *, int); +int dns_host_entry_dereference (struct dns_host_entry **, + const char *, int); +int option_state_allocate (struct option_state **, const char *, int); +int option_state_reference (struct option_state **, + struct option_state *, const char *, int); +int option_state_dereference (struct option_state **, + const char *, int); +int data_string_new(struct data_string *, const char *, unsigned int, + const char *, int); +void data_string_copy(struct data_string *, const struct data_string *, + const char *, int); +void data_string_forget (struct data_string *, const char *, int); +void data_string_truncate (struct data_string *, int); +int executable_statement_allocate (struct executable_statement **, + const char *, int); +int executable_statement_reference (struct executable_statement **, + struct executable_statement *, + const char *, int); +int packet_allocate (struct packet **, const char *, int); +int packet_reference (struct packet **, + struct packet *, const char *, int); +int packet_dereference (struct packet **, const char *, int); +int binding_scope_allocate (struct binding_scope **, + const char *, int); +int binding_scope_reference (struct binding_scope **, + struct binding_scope *, + const char *, int); +int dns_zone_allocate (struct dns_zone **, const char *, int); +int dns_zone_reference (struct dns_zone **, + struct dns_zone *, const char *, int); + +/* print.c */ +#define DEFAULT_TIME_FORMAT 0 +#define LOCAL_TIME_FORMAT 1 +extern int db_time_format; +char *quotify_string (const char *, const char *, int); +char *quotify_buf (const unsigned char *, unsigned, const char *, int); +char *print_base64 (const unsigned char *, unsigned, const char *, int); +char *print_hw_addr (const int, const int, const unsigned char *); +void print_lease (struct lease *); +void dump_raw (const unsigned char *, unsigned); +void dump_packet_option (struct option_cache *, struct packet *, + struct lease *, struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, struct universe *, void *); +void dump_packet (struct packet *); +void hash_dump (struct hash_table *); +char *print_hex (unsigned, const u_int8_t *, unsigned, unsigned); +void print_hex_only (unsigned, const u_int8_t *, unsigned, char *); +void print_hex_or_string (unsigned, const u_int8_t *, unsigned, char *); +#define print_hex_1(len, data, limit) print_hex(len, data, limit, 0) +#define print_hex_2(len, data, limit) print_hex(len, data, limit, 1) +#define print_hex_3(len, data, limit) print_hex(len, data, limit, 2) +char *print_dotted_quads (unsigned, const u_int8_t *); +char *print_dec_1 (unsigned long); +char *print_dec_2 (unsigned long); +void print_expression (const char *, struct expression *); +int token_print_indent_concat (FILE *, int, int, + const char *, const char *, ...); +int token_indent_data_string (FILE *, int, int, const char *, const char *, + struct data_string *); +int token_print_indent (FILE *, int, int, + const char *, const char *, const char *); +void indent_spaces (FILE *, int); +#if defined (NSUPDATE) +void print_dns_status (int, struct dhcp_ddns_cb *, isc_result_t); +#endif +const char *print_time(TIME); + +void get_hw_addr(const char *name, struct hardware *hw); + +/* socket.c */ +#if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \ + || defined (USE_SOCKET_FALLBACK) +int if_register_socket(struct interface_info *, int, int *, struct in6_addr *); + +void set_multicast_hop_limit(struct interface_info* info, int hop_limit); +#endif + +#if defined (USE_SOCKET_FALLBACK) && !defined (USE_SOCKET_SEND) +void if_reinitialize_fallback (struct interface_info *); +void if_register_fallback (struct interface_info *); +ssize_t send_fallback (struct interface_info *, + struct packet *, struct dhcp_packet *, size_t, + struct in_addr, + struct sockaddr_in *, struct hardware *); +ssize_t send_fallback6(struct interface_info *, struct packet *, + struct dhcp_packet *, size_t, struct in6_addr *, + struct sockaddr_in6 *, struct hardware *); +#endif + +#ifdef USE_SOCKET_SEND +void if_reinitialize_send (struct interface_info *); +void if_register_send (struct interface_info *); +void if_deregister_send (struct interface_info *); +ssize_t send_packet (struct interface_info *, + struct packet *, struct dhcp_packet *, size_t, + struct in_addr, + struct sockaddr_in *, struct hardware *); +#endif +ssize_t send_packet6(struct interface_info *, const unsigned char *, size_t, + struct sockaddr_in6 *); +#ifdef USE_SOCKET_RECEIVE +void if_reinitialize_receive (struct interface_info *); +void if_register_receive (struct interface_info *); +void if_deregister_receive (struct interface_info *); +ssize_t receive_packet (struct interface_info *, + unsigned char *, size_t, + struct sockaddr_in *, struct hardware *); +#endif + +#if defined (USE_SOCKET_FALLBACK) +isc_result_t fallback_discard (omapi_object_t *); +#endif + +#if defined (USE_SOCKET_SEND) +int can_unicast_without_arp (struct interface_info *); +int can_receive_unicast_unconfigured (struct interface_info *); +int supports_multiple_interfaces (struct interface_info *); +void maybe_setup_fallback (void); +#endif + +void if_register6(struct interface_info *info, int do_multicast); +void if_register_linklocal6(struct interface_info *info); +ssize_t receive_packet6(struct interface_info *interface, + unsigned char *buf, size_t len, + struct sockaddr_in6 *from, struct in6_addr *to_addr, + unsigned int *if_index); +void if_deregister6(struct interface_info *info); + + +/* bpf.c */ +#if defined (USE_BPF_SEND) || defined (USE_BPF_RECEIVE) +int if_register_bpf (struct interface_info *); +#endif +#ifdef USE_BPF_SEND +void if_reinitialize_send (struct interface_info *); +void if_register_send (struct interface_info *); +void if_deregister_send (struct interface_info *); +ssize_t send_packet (struct interface_info *, + struct packet *, struct dhcp_packet *, size_t, + struct in_addr, + struct sockaddr_in *, struct hardware *); +#endif +#ifdef USE_BPF_RECEIVE +void if_reinitialize_receive (struct interface_info *); +void if_register_receive (struct interface_info *); +void if_deregister_receive (struct interface_info *); +ssize_t receive_packet (struct interface_info *, + unsigned char *, size_t, + struct sockaddr_in *, struct hardware *); +#endif +#if defined (USE_BPF_SEND) +int can_unicast_without_arp (struct interface_info *); +int can_receive_unicast_unconfigured (struct interface_info *); +int supports_multiple_interfaces (struct interface_info *); +void maybe_setup_fallback (void); +#endif + +/* lpf.c */ +#if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE) +int if_register_lpf (struct interface_info *); +#endif +#ifdef USE_LPF_SEND +void if_reinitialize_send (struct interface_info *); +void if_register_send (struct interface_info *); +void if_deregister_send (struct interface_info *); +ssize_t send_packet (struct interface_info *, + struct packet *, struct dhcp_packet *, size_t, + struct in_addr, + struct sockaddr_in *, struct hardware *); +#endif +#ifdef USE_LPF_RECEIVE +void if_reinitialize_receive (struct interface_info *); +void if_register_receive (struct interface_info *); +void if_deregister_receive (struct interface_info *); +ssize_t receive_packet (struct interface_info *, + unsigned char *, size_t, + struct sockaddr_in *, struct hardware *); +#endif +#if defined (USE_LPF_SEND) +int can_unicast_without_arp (struct interface_info *); +int can_receive_unicast_unconfigured (struct interface_info *); +int supports_multiple_interfaces (struct interface_info *); +void maybe_setup_fallback (void); +#endif + +/* nit.c */ +#if defined (USE_NIT_SEND) || defined (USE_NIT_RECEIVE) +int if_register_nit (struct interface_info *); +#endif + +#ifdef USE_NIT_SEND +void if_reinitialize_send (struct interface_info *); +void if_register_send (struct interface_info *); +void if_deregister_send (struct interface_info *); +ssize_t send_packet (struct interface_info *, + struct packet *, struct dhcp_packet *, size_t, + struct in_addr, + struct sockaddr_in *, struct hardware *); +#endif +#ifdef USE_NIT_RECEIVE +void if_reinitialize_receive (struct interface_info *); +void if_register_receive (struct interface_info *); +void if_deregister_receive (struct interface_info *); +ssize_t receive_packet (struct interface_info *, + unsigned char *, size_t, + struct sockaddr_in *, struct hardware *); +#endif +#if defined (USE_NIT_SEND) +int can_unicast_without_arp (struct interface_info *); +int can_receive_unicast_unconfigured (struct interface_info *); +int supports_multiple_interfaces (struct interface_info *); +void maybe_setup_fallback (void); +#endif + +/* dlpi.c */ +#if defined (USE_DLPI_SEND) || defined (USE_DLPI_RECEIVE) +int if_register_dlpi (struct interface_info *); +#endif + +#ifdef USE_DLPI_SEND +int can_unicast_without_arp (struct interface_info *); +int can_receive_unicast_unconfigured (struct interface_info *); +void if_reinitialize_send (struct interface_info *); +void if_register_send (struct interface_info *); +void if_deregister_send (struct interface_info *); +ssize_t send_packet (struct interface_info *, + struct packet *, struct dhcp_packet *, size_t, + struct in_addr, + struct sockaddr_in *, struct hardware *); +int supports_multiple_interfaces (struct interface_info *); +void maybe_setup_fallback (void); +#endif +#ifdef USE_DLPI_RECEIVE +void if_reinitialize_receive (struct interface_info *); +void if_register_receive (struct interface_info *); +void if_deregister_receive (struct interface_info *); +ssize_t receive_packet (struct interface_info *, + unsigned char *, size_t, + struct sockaddr_in *, struct hardware *); +#endif + + +/* raw.c */ +#ifdef USE_RAW_SEND +void if_reinitialize_send (struct interface_info *); +void if_register_send (struct interface_info *); +void if_deregister_send (struct interface_info *); +ssize_t send_packet (struct interface_info *, struct packet *, + struct dhcp_packet *, size_t, struct in_addr, + struct sockaddr_in *, struct hardware *); +int can_unicast_without_arp (struct interface_info *); +int can_receive_unicast_unconfigured (struct interface_info *); +int supports_multiple_interfaces (struct interface_info *); +void maybe_setup_fallback (void); +#endif + +/* discover.c */ +extern struct interface_info *interfaces, + *dummy_interfaces, *fallback_interface; +extern struct protocol *protocols; +extern int quiet_interface_discovery; +isc_result_t interface_setup (void); +void interface_trace_setup (void); + +extern struct in_addr limited_broadcast; +extern int local_family; +extern struct in_addr local_address; + +extern u_int16_t local_port; +extern u_int16_t remote_port; +extern int (*dhcp_interface_setup_hook) (struct interface_info *, + struct iaddr *); +extern int (*dhcp_interface_discovery_hook) (struct interface_info *); +extern isc_result_t (*dhcp_interface_startup_hook) (struct interface_info *); + +extern void (*bootp_packet_handler) (struct interface_info *, + struct dhcp_packet *, unsigned, + unsigned int, + struct iaddr, struct hardware *); +extern void (*dhcpv6_packet_handler)(struct interface_info *, + const char *, int, + int, const struct iaddr *, isc_boolean_t); +extern struct timeout *timeouts; +extern omapi_object_type_t *dhcp_type_interface; +#if defined (TRACING) +extern trace_type_t *interface_trace; +extern trace_type_t *inpacket_trace; +extern trace_type_t *outpacket_trace; +#endif +extern struct interface_info **interface_vector; +extern int interface_count; +extern int interface_max; +isc_result_t interface_initialize(omapi_object_t *, const char *, int); +void discover_interfaces(int); +int setup_fallback (struct interface_info **, const char *, int); +int if_readsocket (omapi_object_t *); +void reinitialize_interfaces (void); + +/* dispatch.c */ +void set_time(TIME); +struct timeval *process_outstanding_timeouts (struct timeval *); +void dispatch (void); +isc_result_t got_one(omapi_object_t *); +isc_result_t got_one_v6(omapi_object_t *); +isc_result_t interface_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, omapi_typed_data_t *); +isc_result_t interface_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, omapi_value_t **); +isc_result_t interface_destroy (omapi_object_t *, const char *, int); +isc_result_t interface_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t interface_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); + +void add_timeout (struct timeval *, void (*) (void *), void *, + tvref_t, tvunref_t); +void cancel_timeout (void (*) (void *), void *); +void cancel_all_timeouts (void); +void relinquish_timeouts (void); + +OMAPI_OBJECT_ALLOC_DECL (interface, + struct interface_info, dhcp_type_interface) + +/* tables.c */ +extern char *default_option_format; +extern struct universe dhcp_universe; +extern struct universe dhcpv6_universe; +extern struct universe nwip_universe; +extern struct universe fqdn_universe; +extern struct universe vsio_universe; +extern int dhcp_option_default_priority_list []; +extern int dhcp_option_default_priority_list_count; +extern const char *hardware_types [256]; +extern int universe_count, universe_max; +extern struct universe **universes; +extern universe_hash_t *universe_hash; +void initialize_common_option_spaces (void); +extern struct universe *config_universe; + +/* stables.c */ +#if defined (FAILOVER_PROTOCOL) +extern failover_option_t null_failover_option; +extern failover_option_t skip_failover_option; +extern struct failover_option_info ft_options []; +extern u_int32_t fto_allowed []; +extern int ft_sizes []; +extern const char *dhcp_flink_state_names []; +#endif +extern const char *binding_state_names []; + +extern struct universe agent_universe; +extern struct universe server_universe; + +extern struct enumeration ddns_styles; +extern struct enumeration syslog_enum; +void initialize_server_option_spaces (void); + +/* inet.c */ +struct iaddr subnet_number (struct iaddr, struct iaddr); +struct iaddr ip_addr (struct iaddr, struct iaddr, u_int32_t); +struct iaddr broadcast_addr (struct iaddr, struct iaddr); +u_int32_t host_addr (struct iaddr, struct iaddr); +int addr_eq (struct iaddr, struct iaddr); +int addr_match(struct iaddr *, struct iaddrmatch *); +int addr_cmp(const struct iaddr *a1, const struct iaddr *a2); +int addr_or(struct iaddr *result, + const struct iaddr *a1, const struct iaddr *a2); +int addr_and(struct iaddr *result, + const struct iaddr *a1, const struct iaddr *a2); +isc_boolean_t is_cidr_mask_valid(const struct iaddr *addr, int bits); +isc_result_t range2cidr(struct iaddrcidrnetlist **result, + const struct iaddr *lo, const struct iaddr *hi); +isc_result_t free_iaddrcidrnetlist(struct iaddrcidrnetlist **result); +const char *piaddr (struct iaddr); +char *piaddrmask(struct iaddr *, struct iaddr *); +char *piaddrcidr(const struct iaddr *, unsigned int); +u_int16_t validate_port(char *); + +/* dhclient.c */ +extern int nowait; + +extern int wanted_ia_na; +extern int wanted_ia_ta; +extern int wanted_ia_pd; + +extern const char *path_dhclient_conf; +extern const char *path_dhclient_db; +extern const char *path_dhclient_pid; +extern char *path_dhclient_script; +extern int interfaces_requested; +extern struct data_string default_duid; +extern int duid_type; + +extern struct client_config top_level_config; + +void dhcpoffer (struct packet *); +void dhcpack (struct packet *); +void dhcpnak (struct packet *); + +void send_discover (void *); +void send_request (void *); +void send_release (void *); +void send_decline (void *); + +void state_reboot (void *); +void state_init (void *); +void state_selecting (void *); +void state_requesting (void *); +void state_bound (void *); +void state_stop (void *); +void state_panic (void *); + +void bind_lease (struct client_state *); + +void make_client_options (struct client_state *, + struct client_lease *, u_int8_t *, + struct option_cache *, struct iaddr *, + struct option **, struct option_state **); +void make_discover (struct client_state *, struct client_lease *); +void make_request (struct client_state *, struct client_lease *); +void make_decline (struct client_state *, struct client_lease *); +void make_release (struct client_state *, struct client_lease *); + +void destroy_client_lease (struct client_lease *); +void rewrite_client_leases (void); +void write_lease_option (struct option_cache *, struct packet *, + struct lease *, struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, struct universe *, void *); +int write_client_lease (struct client_state *, struct client_lease *, int, int); +isc_result_t write_client6_lease(struct client_state *client, + struct dhc6_lease *lease, + int rewrite, int sync); +int dhcp_option_ev_name (char *, size_t, struct option *); + +void script_init (struct client_state *, const char *, + struct string_list *); +void client_option_envadd (struct option_cache *, struct packet *, + struct lease *, struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, struct universe *, void *); +void script_write_params (struct client_state *, const char *, + struct client_lease *); +void script_write_requested (struct client_state *); +int script_go (struct client_state *); +void client_envadd (struct client_state *, + const char *, const char *, const char *, ...) + __attribute__((__format__(__printf__,4,5))); + +struct client_lease *packet_to_lease (struct packet *, struct client_state *); +void go_daemon (void); +void write_client_pid_file (void); +void client_location_changed (void); +void do_release (struct client_state *); +int dhclient_interface_shutdown_hook (struct interface_info *); +int dhclient_interface_discovery_hook (struct interface_info *); +isc_result_t dhclient_interface_startup_hook (struct interface_info *); +void dhclient_schedule_updates(struct client_state *client, + struct iaddr *addr, int offset); +void client_dns_update_timeout (void *cp); +isc_result_t client_dns_update(struct client_state *client, + dhcp_ddns_cb_t *ddns_cb); +void client_dns_remove(struct client_state *client, struct iaddr *addr); + +void dhcpv4_client_assignments(void); +void dhcpv6_client_assignments(void); + +/* dhc6.c */ +void form_duid(struct data_string *duid, const char *file, int line); +void dhc6_lease_destroy(struct dhc6_lease **src, const char *file, int line); +void start_init6(struct client_state *client); +void start_info_request6(struct client_state *client); +void start_confirm6(struct client_state *client); +void start_release6(struct client_state *client); +void start_selecting6(struct client_state *client); +void unconfigure6(struct client_state *client, const char *reason); + +/* db.c */ +int write_lease (struct lease *); +int write_host (struct host_decl *); +int write_server_duid(void); +#if defined (FAILOVER_PROTOCOL) +int write_failover_state (dhcp_failover_state_t *); +#endif +int db_printable (const unsigned char *); +int db_printable_len (const unsigned char *, unsigned); +isc_result_t write_named_billing_class(const void *, unsigned, void *); +void write_billing_classes (void); +int write_billing_class (struct class *); +void commit_leases_timeout (void *); +void commit_leases_readerdry(void *); +int commit_leases (void); +int commit_leases_timed (void); +void db_startup (int); +int new_lease_file (void); +int group_writer (struct group_object *); +int write_ia(const struct ia_xx *); + +/* packet.c */ +u_int32_t checksum (unsigned char *, unsigned, u_int32_t); +u_int32_t wrapsum (u_int32_t); +void assemble_hw_header (struct interface_info *, unsigned char *, + unsigned *, struct hardware *); +void assemble_udp_ip_header (struct interface_info *, unsigned char *, + unsigned *, u_int32_t, u_int32_t, + u_int32_t, unsigned char *, unsigned); +ssize_t decode_hw_header (struct interface_info *, unsigned char *, + unsigned, struct hardware *); +ssize_t decode_udp_ip_header (struct interface_info *, unsigned char *, + unsigned, struct sockaddr_in *, + unsigned, unsigned *, int); + +/* ethernet.c */ +void assemble_ethernet_header (struct interface_info *, unsigned char *, + unsigned *, struct hardware *); +ssize_t decode_ethernet_header (struct interface_info *, + unsigned char *, + unsigned, struct hardware *); + +/* tr.c */ +void assemble_tr_header (struct interface_info *, unsigned char *, + unsigned *, struct hardware *); +ssize_t decode_tr_header (struct interface_info *, + unsigned char *, + unsigned, struct hardware *); + +/* dhxpxlt.c */ +void convert_statement (struct parse *); +void convert_host_statement (struct parse *, jrefproto); +void convert_host_name (struct parse *, jrefproto); +void convert_class_statement (struct parse *, jrefproto, int); +void convert_class_decl (struct parse *, jrefproto); +void convert_lease_time (struct parse *, jrefproto, char *); +void convert_shared_net_statement (struct parse *, jrefproto); +void convert_subnet_statement (struct parse *, jrefproto); +void convert_subnet_decl (struct parse *, jrefproto); +void convert_host_decl (struct parse *, jrefproto); +void convert_hardware_decl (struct parse *, jrefproto); +void convert_hardware_addr (struct parse *, jrefproto); +void convert_filename_decl (struct parse *, jrefproto); +void convert_servername_decl (struct parse *, jrefproto); +void convert_ip_addr_or_hostname (struct parse *, jrefproto, int); +void convert_fixed_addr_decl (struct parse *, jrefproto); +void convert_option_decl (struct parse *, jrefproto); +void convert_lease_statement (struct parse *, jrefproto); +void convert_address_range (struct parse *, jrefproto); +void convert_date (struct parse *, jrefproto, char *); +void convert_numeric_aggregate (struct parse *, jrefproto, int, int, int, int); +void indent (int); + +/* route.c */ +void add_route_direct (struct interface_info *, struct in_addr); +void add_route_net (struct interface_info *, struct in_addr, struct in_addr); +void add_route_default_gateway (struct interface_info *, struct in_addr); +void remove_routes (struct in_addr); +void remove_if_route (struct interface_info *, struct in_addr); +void remove_all_if_routes (struct interface_info *); +void set_netmask (struct interface_info *, struct in_addr); +void set_broadcast_addr (struct interface_info *, struct in_addr); +void set_ip_address (struct interface_info *, struct in_addr); + +/* clparse.c */ +isc_result_t read_client_conf (void); +int read_client_conf_file (const char *, + struct interface_info *, struct client_config *); +void read_client_leases (void); +void parse_client_statement (struct parse *, struct interface_info *, + struct client_config *); +int parse_X (struct parse *, u_int8_t *, unsigned); +int parse_option_list (struct parse *, struct option ***); +void parse_interface_declaration (struct parse *, + struct client_config *, char *); +int interface_or_dummy (struct interface_info **, const char *); +void make_client_state (struct client_state **); +void make_client_config (struct client_state *, struct client_config *); +void parse_client_lease_statement (struct parse *, int); +void parse_client_lease_declaration (struct parse *, + struct client_lease *, + struct interface_info **, + struct client_state **); +int parse_option_decl (struct option_cache **, struct parse *); +void parse_string_list (struct parse *, struct string_list **, int); +int parse_ip_addr (struct parse *, struct iaddr *); +int parse_ip_addr_with_subnet(struct parse *, struct iaddrmatch *); +void parse_reject_statement (struct parse *, struct client_config *); + +/* icmp.c */ +OMAPI_OBJECT_ALLOC_DECL (icmp_state, struct icmp_state, dhcp_type_icmp) +extern struct icmp_state *icmp_state; +void icmp_startup (int, void (*) (struct iaddr, u_int8_t *, int)); +int icmp_readsocket (omapi_object_t *); +int icmp_echorequest (struct iaddr *); +isc_result_t icmp_echoreply (omapi_object_t *); + +/* dns.c */ +#if defined (NSUPDATE) +isc_result_t find_tsig_key (ns_tsig_key **, const char *, struct dns_zone *); +void tkey_free (ns_tsig_key **); +#endif +isc_result_t enter_dns_zone (struct dns_zone *); +isc_result_t dns_zone_lookup (struct dns_zone **, const char *); +int dns_zone_dereference (struct dns_zone **, const char *, int); +#if defined (NSUPDATE) +#define FIND_FORWARD 0 +#define FIND_REVERSE 1 +isc_result_t find_cached_zone (dhcp_ddns_cb_t *, int); +void forget_zone (struct dns_zone **); +void repudiate_zone (struct dns_zone **); +//void cache_found_zone (ns_class, char *, struct in_addr *, int); +int get_dhcid (struct data_string *, int, const u_int8_t *, unsigned); +void dhcid_tolease (struct data_string *, struct data_string *); +isc_result_t dhcid_fromlease (struct data_string *, struct data_string *); +isc_result_t ddns_update_fwd(struct data_string *, struct iaddr, + struct data_string *, unsigned long, unsigned, + unsigned); +isc_result_t ddns_remove_fwd(struct data_string *, + struct iaddr, struct data_string *); +#endif /* NSUPDATE */ + +/* resolv.c */ +extern char path_resolv_conf []; +extern struct name_server *name_servers; +extern struct domain_search_list *domains; + +void read_resolv_conf (TIME); +struct name_server *first_name_server (void); + +/* inet_addr.c */ +#ifdef NEED_INET_ATON +int inet_aton (const char *, struct in_addr *); +#endif + +/* class.c */ +extern int have_billing_classes; +struct class unknown_class; +struct class known_class; +struct collection default_collection; +struct collection *collections; +extern struct executable_statement *default_classification_rules; + +void classification_setup (void); +void classify_client (struct packet *); +int check_collection (struct packet *, struct lease *, struct collection *); +void classify (struct packet *, struct class *); +isc_result_t unlink_class (struct class **class); +isc_result_t find_class (struct class **, const char *, + const char *, int); +int unbill_class (struct lease *, struct class *); +int bill_class (struct lease *, struct class *); + +/* execute.c */ +int execute_statements (struct binding_value **result, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, + struct executable_statement *); +void execute_statements_in_scope (struct binding_value **result, + struct packet *, struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct group *, struct group *); +int executable_statement_dereference (struct executable_statement **, + const char *, int); +void write_statements (FILE *, struct executable_statement *, int); +int find_matching_case (struct executable_statement **, + struct packet *, struct lease *, struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, + struct expression *, struct executable_statement *); +int executable_statement_foreach (struct executable_statement *, + int (*) (struct executable_statement *, + void *, int), void *, int); + +/* comapi.c */ +extern omapi_object_type_t *dhcp_type_group; +extern omapi_object_type_t *dhcp_type_shared_network; +extern omapi_object_type_t *dhcp_type_subnet; +extern omapi_object_type_t *dhcp_type_control; +extern dhcp_control_object_t *dhcp_control_object; + +void dhcp_common_objects_setup (void); + +isc_result_t dhcp_group_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_group_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_group_destroy (omapi_object_t *, const char *, int); +isc_result_t dhcp_group_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t dhcp_group_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_group_lookup (omapi_object_t **, + omapi_object_t *, omapi_object_t *); +isc_result_t dhcp_group_create (omapi_object_t **, + omapi_object_t *); +isc_result_t dhcp_group_remove (omapi_object_t *, + omapi_object_t *); + +isc_result_t dhcp_control_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_control_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_control_destroy (omapi_object_t *, const char *, int); +isc_result_t dhcp_control_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t dhcp_control_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_control_lookup (omapi_object_t **, + omapi_object_t *, omapi_object_t *); +isc_result_t dhcp_control_create (omapi_object_t **, + omapi_object_t *); +isc_result_t dhcp_control_remove (omapi_object_t *, + omapi_object_t *); + +isc_result_t dhcp_subnet_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_subnet_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_subnet_destroy (omapi_object_t *, const char *, int); +isc_result_t dhcp_subnet_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t dhcp_subnet_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_subnet_lookup (omapi_object_t **, + omapi_object_t *, omapi_object_t *); +isc_result_t dhcp_subnet_create (omapi_object_t **, + omapi_object_t *); +isc_result_t dhcp_subnet_remove (omapi_object_t *, + omapi_object_t *); + +isc_result_t dhcp_shared_network_set_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_shared_network_get_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_shared_network_destroy (omapi_object_t *, const char *, int); +isc_result_t dhcp_shared_network_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t dhcp_shared_network_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_shared_network_lookup (omapi_object_t **, + omapi_object_t *, omapi_object_t *); +isc_result_t dhcp_shared_network_create (omapi_object_t **, + omapi_object_t *); +isc_result_t dhcp_shared_network_remove (omapi_object_t *, + omapi_object_t *); + +/* omapi.c */ +extern int (*dhcp_interface_shutdown_hook) (struct interface_info *); + +extern omapi_object_type_t *dhcp_type_lease; +extern omapi_object_type_t *dhcp_type_pool; +extern omapi_object_type_t *dhcp_type_class; +extern omapi_object_type_t *dhcp_type_subclass; + +#if defined (FAILOVER_PROTOCOL) +extern omapi_object_type_t *dhcp_type_failover_state; +extern omapi_object_type_t *dhcp_type_failover_link; +extern omapi_object_type_t *dhcp_type_failover_listener; +#endif + +void dhcp_db_objects_setup (void); + +isc_result_t dhcp_lease_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_lease_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_lease_destroy (omapi_object_t *, const char *, int); +isc_result_t dhcp_lease_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t dhcp_lease_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_lease_lookup (omapi_object_t **, + omapi_object_t *, omapi_object_t *); +isc_result_t dhcp_lease_create (omapi_object_t **, + omapi_object_t *); +isc_result_t dhcp_lease_remove (omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_host_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_host_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_host_destroy (omapi_object_t *, const char *, int); +isc_result_t dhcp_host_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t dhcp_host_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_host_lookup (omapi_object_t **, + omapi_object_t *, omapi_object_t *); +isc_result_t dhcp_host_create (omapi_object_t **, + omapi_object_t *); +isc_result_t dhcp_host_remove (omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_pool_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_pool_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_pool_destroy (omapi_object_t *, const char *, int); +isc_result_t dhcp_pool_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t dhcp_pool_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_pool_lookup (omapi_object_t **, + omapi_object_t *, omapi_object_t *); +isc_result_t dhcp_pool_create (omapi_object_t **, + omapi_object_t *); +isc_result_t dhcp_pool_remove (omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_class_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_class_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_class_destroy (omapi_object_t *, const char *, int); +isc_result_t dhcp_class_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t dhcp_class_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_class_lookup (omapi_object_t **, + omapi_object_t *, omapi_object_t *); +isc_result_t dhcp_class_create (omapi_object_t **, + omapi_object_t *); +isc_result_t dhcp_class_remove (omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_subclass_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_subclass_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_subclass_destroy (omapi_object_t *, const char *, int); +isc_result_t dhcp_subclass_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t dhcp_subclass_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_subclass_lookup (omapi_object_t **, + omapi_object_t *, omapi_object_t *); +isc_result_t dhcp_subclass_create (omapi_object_t **, + omapi_object_t *); +isc_result_t dhcp_subclass_remove (omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_interface_set_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_interface_get_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_interface_destroy (omapi_object_t *, + const char *, int); +isc_result_t dhcp_interface_signal_handler (omapi_object_t *, + const char *, + va_list ap); +isc_result_t dhcp_interface_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_interface_lookup (omapi_object_t **, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_interface_create (omapi_object_t **, + omapi_object_t *); +isc_result_t dhcp_interface_remove (omapi_object_t *, + omapi_object_t *); +void interface_stash (struct interface_info *); +void interface_snorf (struct interface_info *, int); + +isc_result_t binding_scope_set_value (struct binding_scope *, int, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t binding_scope_get_value (omapi_value_t **, + struct binding_scope *, + omapi_data_string_t *); +isc_result_t binding_scope_stuff_values (omapi_object_t *, + struct binding_scope *); + +void register_eventhandler(struct eventqueue **, void (*handler)(void *)); +void unregister_eventhandler(struct eventqueue **, void (*handler)(void *)); +void trigger_event(struct eventqueue **); + +/* mdb.c */ + +extern struct subnet *subnets; +extern struct shared_network *shared_networks; +extern host_hash_t *host_hw_addr_hash; +extern host_hash_t *host_uid_hash; +extern host_hash_t *host_name_hash; +extern lease_id_hash_t *lease_uid_hash; +extern lease_ip_hash_t *lease_ip_addr_hash; +extern lease_id_hash_t *lease_hw_addr_hash; + +extern omapi_object_type_t *dhcp_type_host; + +extern int numclasseswritten; + + +isc_result_t enter_class (struct class *, int, int); +isc_result_t delete_class (struct class *, int); +isc_result_t enter_host (struct host_decl *, int, int); +isc_result_t delete_host (struct host_decl *, int); +void change_host_uid(struct host_decl *host, const char *data, int len); +int find_hosts_by_haddr (struct host_decl **, int, + const unsigned char *, unsigned, + const char *, int); +int find_hosts_by_uid (struct host_decl **, const unsigned char *, + unsigned, const char *, int); +int find_hosts_by_option(struct host_decl **, struct packet *, + struct option_state *, const char *, int); +int find_host_for_network (struct subnet **, struct host_decl **, + struct iaddr *, struct shared_network *); +void new_address_range (struct parse *, struct iaddr, struct iaddr, + struct subnet *, struct pool *, + struct lease **); +isc_result_t dhcp_lease_free (omapi_object_t *, const char *, int); +isc_result_t dhcp_lease_get (omapi_object_t **, const char *, int); +int find_grouped_subnet (struct subnet **, struct shared_network *, + struct iaddr, const char *, int); +int find_subnet(struct subnet **, struct iaddr, const char *, int); +void enter_shared_network (struct shared_network *); +void new_shared_network_interface (struct parse *, + struct shared_network *, + const char *); +int subnet_inner_than(const struct subnet *, const struct subnet *, int); +void enter_subnet (struct subnet *); +void enter_lease (struct lease *); +int supersede_lease (struct lease *, struct lease *, int, int, int, int); +void make_binding_state_transition (struct lease *); +int lease_copy (struct lease **, struct lease *, const char *, int); +void release_lease (struct lease *, struct packet *); +void abandon_lease (struct lease *, const char *); +#if 0 +/* this appears to be unused and I plan to remove it SAR */ +void dissociate_lease (struct lease *); +#endif +void pool_timer (void *); +int find_lease_by_uid (struct lease **, const unsigned char *, + unsigned, const char *, int); +int find_lease_by_hw_addr (struct lease **, const unsigned char *, + unsigned, const char *, int); +int find_lease_by_ip_addr (struct lease **, struct iaddr, + const char *, int); +void uid_hash_add (struct lease *); +void uid_hash_delete (struct lease *); +void hw_hash_add (struct lease *); +void hw_hash_delete (struct lease *); +int write_leases (void); +int write_leases6(void); +int lease_enqueue (struct lease *); +isc_result_t lease_instantiate(const void *, unsigned, void *); +void expire_all_pools (void); +void dump_subnets (void); +#if defined (DEBUG_MEMORY_LEAKAGE) || \ + defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) +void free_everything (void); +#endif + +/* nsupdate.c */ +char *ddns_rev_name (struct lease *, struct lease_state *, struct packet *); +char *ddns_fwd_name (struct lease *, struct lease_state *, struct packet *); +int nsupdateA (const char *, const unsigned char *, u_int32_t, int); +int nsupdatePTR (const char *, const unsigned char *, u_int32_t, int); +void nsupdate (struct lease *, struct lease_state *, struct packet *, int); +int updateA (const struct data_string *, const struct data_string *, + unsigned int, struct lease *); +int updatePTR (const struct data_string *, const struct data_string *, + unsigned int, struct lease *); +int deleteA (const struct data_string *, const struct data_string *, + struct lease *); +int deletePTR (const struct data_string *, const struct data_string *, + struct lease *); + +/* failover.c */ +#if defined (FAILOVER_PROTOCOL) +extern dhcp_failover_state_t *failover_states; +void dhcp_failover_startup (void); +int dhcp_failover_write_all_states (void); +isc_result_t enter_failover_peer (dhcp_failover_state_t *); +isc_result_t find_failover_peer (dhcp_failover_state_t **, + const char *, const char *, int); +isc_result_t dhcp_failover_link_initiate (omapi_object_t *); +isc_result_t dhcp_failover_link_signal (omapi_object_t *, + const char *, va_list); +isc_result_t dhcp_failover_link_set_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_failover_link_get_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_failover_link_destroy (omapi_object_t *, + const char *, int); +isc_result_t dhcp_failover_link_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_failover_listen (omapi_object_t *); + +isc_result_t dhcp_failover_listener_signal (omapi_object_t *, + const char *, + va_list); +isc_result_t dhcp_failover_listener_set_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t dhcp_failover_listener_get_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_failover_listener_destroy (omapi_object_t *, + const char *, int); +isc_result_t dhcp_failover_listener_stuff (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_failover_register (omapi_object_t *); +isc_result_t dhcp_failover_state_signal (omapi_object_t *, + const char *, va_list); +isc_result_t dhcp_failover_state_transition (dhcp_failover_state_t *, + const char *); +isc_result_t dhcp_failover_set_service_state (dhcp_failover_state_t *state); +void dhcp_failover_rescind_updates (dhcp_failover_state_t *); +isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *, + enum failover_state); +isc_result_t dhcp_failover_peer_state_changed (dhcp_failover_state_t *, + failover_message_t *); +void dhcp_failover_pool_rebalance (void *); +void dhcp_failover_pool_check (struct pool *); +int dhcp_failover_state_pool_check (dhcp_failover_state_t *); +void dhcp_failover_timeout (void *); +void dhcp_failover_send_contact (void *); +isc_result_t dhcp_failover_send_state (dhcp_failover_state_t *); +isc_result_t dhcp_failover_send_updates (dhcp_failover_state_t *); +int dhcp_failover_queue_update (struct lease *, int); +int dhcp_failover_send_acks (dhcp_failover_state_t *); +void dhcp_failover_toack_queue_timeout (void *); +int dhcp_failover_queue_ack (dhcp_failover_state_t *, failover_message_t *msg); +void dhcp_failover_ack_queue_remove (dhcp_failover_state_t *, struct lease *); +isc_result_t dhcp_failover_state_set_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +void dhcp_failover_keepalive (void *); +void dhcp_failover_reconnect (void *); +void dhcp_failover_startup_timeout (void *); +void dhcp_failover_link_startup_timeout (void *); +void dhcp_failover_listener_restart (void *); +void dhcp_failover_auto_partner_down(void *vs); +isc_result_t dhcp_failover_state_get_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t dhcp_failover_state_destroy (omapi_object_t *, + const char *, int); +isc_result_t dhcp_failover_state_stuff (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_failover_state_lookup (omapi_object_t **, + omapi_object_t *, + omapi_object_t *); +isc_result_t dhcp_failover_state_create (omapi_object_t **, + omapi_object_t *); +isc_result_t dhcp_failover_state_remove (omapi_object_t *, + omapi_object_t *); +int dhcp_failover_state_match (dhcp_failover_state_t *, u_int8_t *, unsigned); +int dhcp_failover_state_match_by_name(dhcp_failover_state_t *, + failover_option_t *); +const char *dhcp_failover_reject_reason_print (int); +const char *dhcp_failover_state_name_print (enum failover_state); +const char *dhcp_failover_message_name (unsigned); +const char *dhcp_failover_option_name (unsigned); +failover_option_t *dhcp_failover_option_printf (unsigned, char *, + unsigned *, + unsigned, + const char *, ...) + __attribute__((__format__(__printf__,5,6))); +failover_option_t *dhcp_failover_make_option (unsigned, char *, + unsigned *, unsigned, ...); +isc_result_t dhcp_failover_put_message (dhcp_failover_link_t *, + omapi_object_t *, int, u_int32_t, ...); +isc_result_t dhcp_failover_send_connect (omapi_object_t *); +isc_result_t dhcp_failover_send_connectack (omapi_object_t *, + dhcp_failover_state_t *, + int, const char *); +isc_result_t dhcp_failover_send_disconnect (omapi_object_t *, + int, const char *); +isc_result_t dhcp_failover_send_bind_update (dhcp_failover_state_t *, + struct lease *); +isc_result_t dhcp_failover_send_bind_ack (dhcp_failover_state_t *, + failover_message_t *, + int, const char *); +isc_result_t dhcp_failover_send_poolreq (dhcp_failover_state_t *); +isc_result_t dhcp_failover_send_poolresp (dhcp_failover_state_t *, int); +isc_result_t dhcp_failover_send_update_request (dhcp_failover_state_t *); +isc_result_t dhcp_failover_send_update_request_all (dhcp_failover_state_t *); +isc_result_t dhcp_failover_send_update_done (dhcp_failover_state_t *); +isc_result_t dhcp_failover_process_bind_update (dhcp_failover_state_t *, + failover_message_t *); +isc_result_t dhcp_failover_process_bind_ack (dhcp_failover_state_t *, + failover_message_t *); +isc_result_t dhcp_failover_generate_update_queue (dhcp_failover_state_t *, + int); +isc_result_t dhcp_failover_process_update_request (dhcp_failover_state_t *, + failover_message_t *); +isc_result_t dhcp_failover_process_update_request_all (dhcp_failover_state_t *, + failover_message_t *); +isc_result_t dhcp_failover_process_update_done (dhcp_failover_state_t *, + failover_message_t *); +void ia_remove_all_lease(struct ia_xx *ia, const char *file, int line); +void dhcp_failover_recover_done (void *); +void failover_print (char *, unsigned *, unsigned, const char *); +void update_partner (struct lease *); +int load_balance_mine (struct packet *, dhcp_failover_state_t *); +int peer_wants_lease (struct lease *); +binding_state_t normal_binding_state_transition_check (struct lease *, + dhcp_failover_state_t *, + binding_state_t, + u_int32_t); +binding_state_t +conflict_binding_state_transition_check (struct lease *, + dhcp_failover_state_t *, + binding_state_t, u_int32_t); +int lease_mine_to_reallocate (struct lease *); + +OMAPI_OBJECT_ALLOC_DECL (dhcp_failover_state, dhcp_failover_state_t, + dhcp_type_failover_state) +OMAPI_OBJECT_ALLOC_DECL (dhcp_failover_listener, dhcp_failover_listener_t, + dhcp_type_failover_listener) +OMAPI_OBJECT_ALLOC_DECL (dhcp_failover_link, dhcp_failover_link_t, + dhcp_type_failover_link) +#endif /* FAILOVER_PROTOCOL */ + +const char *binding_state_print (enum failover_state); + +/* ldap.c */ +#if defined(LDAP_CONFIGURATION) +extern struct enumeration ldap_methods; +#if defined (LDAP_USE_SSL) +extern struct enumeration ldap_ssl_usage_enum; +extern struct enumeration ldap_tls_reqcert_enum; +extern struct enumeration ldap_tls_crlcheck_enum; +#endif +isc_result_t ldap_read_config (void); +int find_haddr_in_ldap (struct host_decl **, int, unsigned, + const unsigned char *, const char *, int); +int find_subclass_in_ldap (struct class *, struct class **, + struct data_string *); +#endif + +/* mdb6.c */ +HASH_FUNCTIONS_DECL(ia, unsigned char *, struct ia_xx, ia_hash_t) +HASH_FUNCTIONS_DECL(iasubopt, struct in6_addr *, struct iasubopt, + iasubopt_hash_t) + +isc_result_t iasubopt_allocate(struct iasubopt **iasubopt, + const char *file, int line); +isc_result_t iasubopt_reference(struct iasubopt **iasubopt, + struct iasubopt *src, + const char *file, int line); +isc_result_t iasubopt_dereference(struct iasubopt **iasubopt, + const char *file, int line); + +isc_result_t ia_make_key(struct data_string *key, u_int32_t iaid, + const char *duid, unsigned int duid_len, + const char *file, int line); +isc_result_t ia_allocate(struct ia_xx **ia, u_int32_t iaid, + const char *duid, unsigned int duid_len, + const char *file, int line); +isc_result_t ia_reference(struct ia_xx **ia, struct ia_xx *src, + const char *file, int line); +isc_result_t ia_dereference(struct ia_xx **ia, + const char *file, int line); +isc_result_t ia_add_iasubopt(struct ia_xx *ia, struct iasubopt *iasubopt, + const char *file, int line); +void ia_remove_iasubopt(struct ia_xx *ia, struct iasubopt *iasubopt, + const char *file, int line); +isc_boolean_t ia_equal(const struct ia_xx *a, const struct ia_xx *b); + +isc_result_t ipv6_pool_allocate(struct ipv6_pool **pool, u_int16_t type, + const struct in6_addr *start_addr, + int bits, int units, + const char *file, int line); +isc_result_t ipv6_pool_reference(struct ipv6_pool **pool, + struct ipv6_pool *src, + const char *file, int line); +isc_result_t ipv6_pool_dereference(struct ipv6_pool **pool, + const char *file, int line); +isc_result_t create_lease6(struct ipv6_pool *pool, + struct iasubopt **addr, + unsigned int *attempts, + const struct data_string *uid, + time_t soft_lifetime_end_time); +isc_result_t add_lease6(struct ipv6_pool *pool, + struct iasubopt *lease, + time_t valid_lifetime_end_time); +isc_result_t renew_lease6(struct ipv6_pool *pool, struct iasubopt *lease); +isc_result_t expire_lease6(struct iasubopt **leasep, + struct ipv6_pool *pool, time_t now); +isc_result_t release_lease6(struct ipv6_pool *pool, struct iasubopt *lease); +isc_result_t decline_lease6(struct ipv6_pool *pool, struct iasubopt *lease); +isc_boolean_t lease6_exists(const struct ipv6_pool *pool, + const struct in6_addr *addr); +isc_boolean_t lease6_usable(struct iasubopt *lease); +isc_result_t cleanup_lease6(ia_hash_t *ia_table, + struct ipv6_pool *pool, + struct iasubopt *lease, + struct ia_xx *ia); +isc_result_t mark_lease_unavailble(struct ipv6_pool *pool, + const struct in6_addr *addr); +isc_result_t create_prefix6(struct ipv6_pool *pool, + struct iasubopt **pref, + unsigned int *attempts, + const struct data_string *uid, + time_t soft_lifetime_end_time); +isc_boolean_t prefix6_exists(const struct ipv6_pool *pool, + const struct in6_addr *pref, u_int8_t plen); + +isc_result_t add_ipv6_pool(struct ipv6_pool *pool); +isc_result_t find_ipv6_pool(struct ipv6_pool **pool, u_int16_t type, + const struct in6_addr *addr); +isc_boolean_t ipv6_in_pool(const struct in6_addr *addr, + const struct ipv6_pool *pool); + +isc_result_t renew_leases(struct ia_xx *ia); +isc_result_t release_leases(struct ia_xx *ia); +isc_result_t decline_leases(struct ia_xx *ia); +void schedule_lease_timeout(struct ipv6_pool *pool); +void schedule_all_ipv6_lease_timeouts(); + +void mark_hosts_unavailable(void); +void mark_phosts_unavailable(void); +void mark_interfaces_unavailable(void); + +dhcp_ddns_cb_t *ddns_cb_alloc(const char *file, int line); +void ddns_cb_free (dhcp_ddns_cb_t *ddns_cb, const char *file, int line); +void ddns_cb_forget_zone (dhcp_ddns_cb_t *ddns_cb); + +//void *key_from_zone(struct dns_zone *zone); + +isc_result_t +ddns_modify_fwd(dhcp_ddns_cb_t *ddns_cb, const char *file, int line); + +isc_result_t +ddns_modify_ptr(dhcp_ddns_cb_t *ddns_cb, const char *file, int line); + +void +ddns_cancel(dhcp_ddns_cb_t *ddns_cb, const char *file, int line); + +#define MAX_ADDRESS_STRING_LEN \ + (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")) diff --git a/includes/dhctoken.h b/includes/dhctoken.h new file mode 100644 index 0000000..b72010d --- /dev/null +++ b/includes/dhctoken.h @@ -0,0 +1,368 @@ +/* dhctoken.h + + Tokens for config file lexer and parser. */ + +/* + * Copyright (c) 2011-2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004,2007-2009 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +enum dhcp_token { + SEMI = ';', + DOT = '.', + COLON = ':', + COMMA = ',', + SLASH = '/', + LBRACE = '{', + RBRACE = '}', + LPAREN = '(', + RPAREN = ')', + EQUAL = '=', + TILDE = '~', + BANG = '!', + PERCENT = '%', + PLUS = '+', + MINUS = '-', + ASTERISK = '*', + AMPERSAND = '&', + PIPE = '|', + CARET = '^', + ENDOFLINE = '\n', + QUESTIONMARK = '?', + + HOST = 256, + FIRST_TOKEN = HOST, + HARDWARE = 257, + FILENAME = 258, + FIXED_ADDR = 259, + OPTION = 260, + ETHERNET = 261, + STRING = 262, + NUMBER = 263, + NUMBER_OR_NAME = 264, + NAME = 265, + TIMESTAMP = 266, + STARTS = 267, + ENDS = 268, + UID = 269, + CLASS = 270, + LEASE = 271, + RANGE = 272, + PACKET = 273, + CIADDR = 274, + YIADDR = 275, + SIADDR = 276, + GIADDR = 277, + SUBNET = 278, + NETMASK = 279, + DEFAULT_LEASE_TIME = 280, + MAX_LEASE_TIME = 281, + VENDOR_CLASS = 282, + USER_CLASS = 283, + SHARED_NETWORK = 284, + SERVER_NAME = 285, + DYNAMIC_BOOTP = 286, + SERVER_IDENTIFIER = 287, + DYNAMIC_BOOTP_LEASE_CUTOFF = 288, + DYNAMIC_BOOTP_LEASE_LENGTH = 289, + BOOT_UNKNOWN_CLIENTS = 290, + NEXT_SERVER = 291, + TOKEN_RING = 292, + GROUP = 293, + ONE_LEASE_PER_CLIENT = 294, + GET_LEASE_HOSTNAMES = 295, + USE_HOST_DECL_NAMES = 296, + SEND = 297, + CLIENT_IDENTIFIER = 298, + REQUEST = 299, + REQUIRE = 300, + TIMEOUT = 301, + RETRY = 302, + SELECT_TIMEOUT = 303, + SCRIPT = 304, + INTERFACE = 305, + RENEW = 306, + REBIND = 307, + EXPIRE = 308, + UNKNOWN_CLIENTS = 309, + ALLOW = 310, + DENY = 312, + BOOTING = 313, + DEFAULT = 314, + MEDIA = 315, + MEDIUM = 316, + ALIAS = 317, + REBOOT = 318, + TOKEN_ABANDONED = 319, + BACKOFF_CUTOFF = 320, + INITIAL_INTERVAL = 321, + NAMESERVER = 322, + DOMAIN = 323, + SEARCH = 324, + SUPERSEDE = 325, + APPEND = 326, + PREPEND = 327, + HOSTNAME = 328, + CLIENT_HOSTNAME = 329, + REJECT = 330, + USE_LEASE_ADDR_FOR_DEFAULT_ROUTE = 331, + MIN_LEASE_TIME = 332, + MIN_SECS = 333, + AND = 334, + OR = 335, + SUBSTRING = 337, + SUFFIX = 338, + CHECK = 339, + EXTRACT_INT = 340, + IF = 341, + TOKEN_ADD = 342, + BREAK = 343, + ELSE = 344, + ELSIF = 345, + SUBCLASS = 346, + MATCH = 347, + SPAWN = 348, + WITH = 349, + EXISTS = 350, + POOL = 351, + UNKNOWN = 352, + CLIENTS = 353, + KNOWN = 354, + AUTHENTICATED = 355, + UNAUTHENTICATED = 356, + ALL = 357, + DYNAMIC = 358, + MEMBERS = 359, + OF = 360, + PSEUDO = 361, + LIMIT = 362, + BILLING = 363, + PEER = 364, + FAILOVER = 365, + MY = 366, + PARTNER = 367, + PRIMARY = 368, + SECONDARY = 369, + IDENTIFIER = 370, + PORT = 371, + MAX_TRANSMIT_IDLE = 372, + MAX_RESPONSE_DELAY = 373, + PARTNER_DOWN = 374, + NORMAL = 375, + COMMUNICATIONS_INTERRUPTED = 376, + POTENTIAL_CONFLICT = 377, + RECOVER = 378, + TOKEN_FDDI = 379, + AUTHORITATIVE = 380, + TOKEN_NOT = 381, + AUTHENTICATION = 383, + IGNORE = 384, + ACCEPT = 385, + PREFER = 386, + DONT = 387, + CODE = 388, + ARRAY = 389, + BOOLEAN = 390, + INTEGER = 391, + SIGNED = 392, + UNSIGNED = 393, + IP_ADDRESS = 394, + TEXT = 395, + STRING_TOKEN = 396, + SPACE = 397, + CONCAT = 398, + ENCODE_INT = 399, + REVERSE = 402, + LEASED_ADDRESS = 403, + BINARY_TO_ASCII = 404, + PICK = 405, + CONFIG_OPTION = 406, + HOST_DECL_NAME = 407, + ON = 408, + EXPIRY = 409, + RELEASE = 410, + COMMIT = 411, + DNS_UPDATE = 412, + LEASE_TIME = 413, + STATIC = 414, + NEVER = 415, + INFINITE = 416, + TOKEN_DELETED = 417, + UPDATED_DNS_RR = 418, + DNS_DELETE = 419, + DUPLICATES = 420, + DECLINES = 421, + TSTP = 422, + TSFP = 423, + OWNER = 424, + IS = 425, + HBA = 426, + MAX_UNACKED_UPDATES = 427, + MCLT = 428, + SPLIT = 429, + AT = 430, + TOKEN_NO = 431, + TOKEN_DELETE = 432, + NS_UPDATE = 433, + UPDATE = 434, + SWITCH = 435, + CASE = 436, + NS_FORMERR = 437, + NS_NOERROR = 438, + NS_NOTAUTH = 439, + NS_NOTIMP = 440, + NS_NOTZONE = 441, + NS_NXDOMAIN = 442, + NS_NXRRSET = 443, + NS_REFUSED = 444, + NS_SERVFAIL = 445, + NS_YXDOMAIN = 446, + NS_YXRRSET = 447, + TOKEN_NULL = 448, + TOKEN_SET = 449, + DEFINED = 450, + UNSET = 451, + EVAL = 452, + LET = 453, + FUNCTION = 454, + DEFINE = 455, + ZONE = 456, + KEY = 457, + SECRET = 458, + ALGORITHM = 459, + LOAD = 460, + BALANCE = 461, + TOKEN_MAX = 462, + SECONDS = 463, + ADDRESS = 464, + RESOLUTION_INTERRUPTED = 465, + STATE = 466, + UNKNOWN_STATE = 567, + CLTT = 568, + INCLUDE = 569, + BINDING = 570, + TOKEN_FREE = 571, + TOKEN_ACTIVE = 572, + TOKEN_EXPIRED = 573, + TOKEN_RELEASED = 574, + TOKEN_RESET = 575, + TOKEN_BACKUP = 576, + TOKEN_RESERVED = 577, + TOKEN_BOOTP = 578, + TOKEN_NEXT = 579, + OMAPI = 580, + LOG = 581, + FATAL = 582, + ERROR = 583, + TOKEN_DEBUG = 584, + INFO = 585, + RETURN = 586, + PAUSED = 587, + RECOVER_DONE = 588, + SHUTDOWN = 589, + STARTUP = 590, + ENCAPSULATE = 591, + VENDOR = 592, + CLIENT_STATE = 593, + INIT_REBOOT = 594, + TOKEN_INIT = 595, + SELECT = 596, + BOUND = 597, + RENEWING = 598, + REBINDING = 599, + RECONTACT_INTERVAL = 600, + CLIENT_UPDATES = 601, + TOKEN_NEW = 601, + TRANSMISSION = 602, + TOKEN_CLOSE = 603, + TOKEN_CREATE = 604, + TOKEN_OPEN = 605, + TOKEN_HELP = 606, + END_OF_FILE = 607, + RECOVER_WAIT = 608, + TOKEN_SERVER = 609, + CONNECT = 610, + REMOVE = 611, + REFRESH = 612, + DOMAIN_NAME = 613, + DO_FORWARD_UPDATE = 614, + KNOWN_CLIENTS = 615, + ATSFP = 616, + LCASE = 617, + UCASE = 618, + WIDTH = 619, + LENGTH = 620, + HASH = 621, + SIZE = 622, + EPOCH = 623, + DB_TIME_FORMAT = 624, + LOCAL = 625, + MAX_LEASE_MISBALANCE = 626, + MAX_LEASE_OWNERSHIP = 627, + MAX_BALANCE = 628, + MIN_BALANCE = 629, + DOMAIN_LIST = 630, + LEASEQUERY = 631, + EXECUTE = 632, + IP6_ADDRESS = 633, + FIXED_ADDR6 = 634, + COMPRESSED = 635, + SUBNET6 = 636, + HOST_IDENTIFIER = 637, + IA_NA = 638, + IA_TA = 639, + IA_PD = 640, + IAADDR = 641, + IAPREFIX = 642, + LEASE6 = 643, + PREFERRED_LIFE = 644, + MAX_LIFE = 645, + DEFAULT_DUID = 646, + SERVER_DUID = 647, + LLT = 648, + EN = 649, + LL = 650, + RANGE6 = 651, + WHITESPACE = 652, + TOKEN_ALSO = 653, + AFTER = 654, + ZEROLEN = 655, + TEMPORARY = 656, + PREFIX6 = 657, + FIXED_PREFIX6 = 658, + ANYCAST_MAC = 659, + CONFLICT_DONE = 660, + AUTO_PARTNER_DOWN = 661, + GETHOSTNAME = 662, + REWIND = 663, + INITIAL_DELAY = 664, + GETHOSTBYNAME = 665, + PRIMARY6 = 666, + SECONDARY6 = 667, + TOKEN_INFINIBAND = 668 +}; + +#define is_identifier(x) ((x) >= FIRST_TOKEN && \ + (x) != STRING && \ + (x) != NUMBER && \ + (x) != END_OF_FILE) diff --git a/includes/failover.h b/includes/failover.h new file mode 100644 index 0000000..b49c241 --- /dev/null +++ b/includes/failover.h @@ -0,0 +1,396 @@ +/* failover.h + + Definitions for address trees... */ + +/* + * Copyright (c) 2004,2005,2007,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2000-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#if defined (FAILOVER_PROTOCOL) +struct failover_option_info { + int code; + const char *name; + enum { FT_UINT8, FT_IPADDR, FT_UINT32, FT_BYTES, FT_TEXT_OR_BYTES, + FT_DDNS, FT_DDNS1, FT_UINT16, FT_TEXT, + FT_UNDEF, FT_DIGEST } type; + int num_present; + int offset; + u_int32_t bit; +}; + +typedef struct { + unsigned count; + u_int8_t *data; +} failover_option_t; + +/* Failover configuration defaults. */ +#ifndef DEFAULT_MAX_BALANCE_TIME +# define DEFAULT_MAX_BALANCE_TIME 3600 +#endif + +#ifndef DEFAULT_MIN_BALANCE_TIME +# define DEFAULT_MIN_BALANCE_TIME 60 +#endif + +#ifndef DEFAULT_MAX_LEASE_MISBALANCE +# define DEFAULT_MAX_LEASE_MISBALANCE 15 +#endif + +#ifndef DEFAULT_MAX_LEASE_OWNERSHIP +# define DEFAULT_MAX_LEASE_OWNERSHIP 10 +#endif + +#ifndef DEFAULT_MAX_FLYING_UPDATES +# define DEFAULT_MAX_FLYING_UPDATES 100 +#endif + +#ifndef DEFAULT_MAX_RESPONSE_DELAY +# define DEFAULT_MAX_RESPONSE_DELAY 20 +#endif + +/* + * IANA has assigned ports 647 ("dhcp-failover") and 847 ("dhcp-failover2"). + * Of these, only port 647 is mentioned in the -12 draft revision. We're not + * sure if they are supposed to indicate primary and secondary? No matter, + * we'll stick to the -12 draft revision level. + */ +#ifndef DEFAULT_FAILOVER_PORT +# define DEFAULT_FAILOVER_PORT 647 +#endif + +#define FM_OFFSET(x) (long)(&(((failover_message_t *)0) -> x)) + +/* All of the below definitions are mandated by draft-ietf-dhc-failover-12. + * The Sections referenced are Sections within that document of that + * version, and may be different in other documents of other versions. + */ + +/* Failover message options from Section 12: */ +#define FTO_ADDRESSES_TRANSFERRED 1 +#define FTB_ADDRESSES_TRANSFERRED 0x00000002 +#define FTO_ASSIGNED_IP_ADDRESS 2 +#define FTB_ASSIGNED_IP_ADDRESS 0x00000004 +#define FTO_BINDING_STATUS 3 +#define FTB_BINDING_STATUS 0x00000008 +#define FTO_CLIENT_IDENTIFIER 4 +#define FTB_CLIENT_IDENTIFIER 0x00000010 +#define FTO_CHADDR 5 +#define FTB_CHADDR 0x00000020 +#define FTO_CLTT 6 +#define FTB_CLTT 0x00000040 +#define FTO_REPLY_OPTIONS 7 +#define FTB_REPLY_OPTIONS 0x00000080 +#define FTO_REQUEST_OPTIONS 8 +#define FTB_REQUEST_OPTIONS 0x00000100 +#define FTO_DDNS 9 +#define FTB_DDNS 0x00000200 +#define FTO_DELAYED_SERVICE 10 +#define FTB_DELAYED_SERVICE 0x00000400 +#define FTO_HBA 11 +#define FTB_HBA 0x00000800 +#define FTO_IP_FLAGS 12 +#define FTB_IP_FLAGS 0x00001000 +#define FTO_LEASE_EXPIRY 13 +#define FTB_LEASE_EXPIRY 0x00002000 +#define FTO_MAX_UNACKED 14 +#define FTB_MAX_UNACKED 0x00004000 +#define FTO_MCLT 15 +#define FTB_MCLT 0x00008000 +#define FTO_MESSAGE 16 +#define FTB_MESSAGE 0x00010000 +#define FTO_MESSAGE_DIGEST 17 +#define FTB_MESSAGE_DIGEST 0x00020000 +#define FTO_POTENTIAL_EXPIRY 18 +#define FTB_POTENTIAL_EXPIRY 0x00040000 +#define FTO_RECEIVE_TIMER 19 +#define FTB_RECEIVE_TIMER 0x00080000 +#define FTO_PROTOCOL_VERSION 20 +#define FTB_PROTOCOL_VERSION 0x00100000 +#define FTO_REJECT_REASON 21 +#define FTB_REJECT_REASON 0x00200000 +#define FTO_RELATIONSHIP_NAME 22 +#define FTB_RELATIONSHIP_NAME 0x00400000 +#define FTO_SERVER_FLAGS 23 +#define FTB_SERVER_FLAGS 0x00800000 +#define FTO_SERVER_STATE 24 +#define FTB_SERVER_STATE 0x01000000 +#define FTO_STOS 25 +#define FTB_STOS 0x02000000 +#define FTO_TLS_REPLY 26 +#define FTB_TLS_REPLY 0x04000000 +#define FTO_TLS_REQUEST 27 +#define FTB_TLS_REQUEST 0x08000000 +#define FTO_VENDOR_CLASS 28 +#define FTB_VENDOR_CLASS 0x10000000 +#define FTO_VENDOR_OPTIONS 29 +#define FTB_VENDOR_OPTIONS 0x20000000 + +#define FTO_MAX FTO_VENDOR_OPTIONS + +/* Failover protocol message types from Section 6.1: */ +#define FTM_POOLREQ 1 +#define FTM_POOLRESP 2 +#define FTM_BNDUPD 3 +#define FTM_BNDACK 4 +#define FTM_CONNECT 5 +#define FTM_CONNECTACK 6 +#define FTM_UPDREQALL 7 +#define FTM_UPDDONE 8 +#define FTM_UPDREQ 9 +#define FTM_STATE 10 +#define FTM_CONTACT 11 +#define FTM_DISCONNECT 12 + +#define FTM_MAX FTM_DISCONNECT + +/* Reject reasons from Section 12.21: */ +#define FTR_ILLEGAL_IP_ADDR 1 +#define FTR_FATAL_CONFLICT 2 +#define FTR_MISSING_BINDINFO 3 +#define FTR_TIMEMISMATCH 4 +#define FTR_INVALID_MCLT 5 +#define FTR_MISC_REJECT 6 +#define FTR_DUP_CONNECTION 7 +#define FTR_INVALID_PARTNER 8 +#define FTR_TLS_UNSUPPORTED 9 +#define FTR_TLS_UNCONFIGURED 10 +#define FTR_TLS_REQUIRED 11 +#define FTR_DIGEST_UNSUPPORTED 12 +#define FTR_DIGEST_UNCONFIGURED 13 +#define FTR_VERSION_MISMATCH 14 +#define FTR_OUTDATED_BIND_INFO 15 +#define FTR_LESS_CRIT_BIND_INFO 16 +#define FTR_NO_TRAFFIC 17 +#define FTR_HBA_CONFLICT 18 +#define FTR_IP_NOT_RESERVED 19 +#define FTR_IP_DIGEST_FAILURE 20 +#define FTR_IP_MISSING_DIGEST 21 +#define FTR_UNKNOWN 254 + +/* Message size limitations defined in Section 6.1: */ +#define DHCP_FAILOVER_MIN_MESSAGE_SIZE 12 +#define DHCP_FAILOVER_MAX_MESSAGE_SIZE 2048 + +/* Failover server flags from Section 12.23: */ +#define FTF_SERVER_STARTUP 1 + +/* DDNS flags from Section 12.9. These are really their names. */ +#define FTF_DDNS_C 0x0001 +#define FTF_DDNS_A 0x0002 +#define FTF_DDNS_D 0x0004 +#define FTF_DDNS_P 0x0008 + +/* FTO_IP_FLAGS contents from Section 12.12: */ +#define FTF_IP_FLAG_RESERVE 0x0001 +#define FTF_IP_FLAG_BOOTP 0x0002 + +/* FTO_MESSAGE_DIGEST Type Codes from Section 12.17: */ +#define FTT_MESSAGE_DIGEST_HMAC_MD5 0x01 + +typedef struct failover_message { + int refcnt; + struct failover_message *next; + + int options_present; + + u_int32_t time; + u_int32_t xid; + u_int8_t type; + + /* One-byte options. */ + u_int8_t binding_status; + u_int8_t delayed_service; + u_int8_t protocol_version; + u_int8_t reject_reason; + u_int8_t server_flags; + u_int8_t server_state; + u_int8_t tls_reply; + u_int8_t tls_request; + + /* Two-byte options. */ + u_int16_t ip_flags; + + /* Four-byte options. */ + u_int32_t addresses_transferred; + u_int32_t assigned_addr; + u_int32_t cltt; + u_int32_t expiry; + u_int32_t max_unacked; + u_int32_t mclt; + u_int32_t potential_expiry; + u_int32_t receive_timer; + u_int32_t stos; + + /* Arbitrary field options. */ + failover_option_t chaddr; + failover_option_t client_identifier; + failover_option_t hba; + failover_option_t message; + failover_option_t message_digest; + failover_option_t relationship_name; + failover_option_t reply_options; + failover_option_t request_options; + failover_option_t vendor_class; + failover_option_t vendor_options; + + /* Special contents options. */ + ddns_fqdn_t ddns; +} failover_message_t; + +typedef struct { + OMAPI_OBJECT_PREAMBLE; + struct option_cache *peer_address; + unsigned peer_port; + int options_present; + enum dhcp_flink_state { + dhcp_flink_start, + dhcp_flink_message_length_wait, + dhcp_flink_message_wait, + dhcp_flink_disconnected, + dhcp_flink_state_max + } state; + failover_message_t *imsg; + struct _dhcp_failover_state *state_object; + u_int16_t imsg_len; + unsigned imsg_count; + u_int8_t imsg_payoff; /* Pay*load* offset. :') */ + u_int32_t xid; +} dhcp_failover_link_t; + +typedef struct _dhcp_failover_listener { + OMAPI_OBJECT_PREAMBLE; + struct _dhcp_failover_listener *next; + omapi_addr_t address; +} dhcp_failover_listener_t; +#endif /* FAILOVER_PROTOCOL */ + +/* A failover peer's running state. */ +enum failover_state { + unknown_state = 0, /* XXX: Not a standard state. */ + startup = 1, + normal = 2, + communications_interrupted = 3, + partner_down = 4, + potential_conflict = 5, + recover = 6, + paused = 7, + shut_down = 8, + recover_done = 9, + resolution_interrupted = 10, + conflict_done = 11, + + /* Draft revision 12 of the failover protocol documents a RECOVER-WAIT + * state, but does not enumerate its value in the section 12.24 + * table. ISC DHCP 3.0.x used value 254 even though the state was + * not documented at all. For the time being, we will continue to use + * this value. + */ + recover_wait = 254 +}; + +/* Service states are simplifications of failover states, particularly + useful because the startup state isn't actually implementable as a + separate failover state without maintaining a state stack. */ + +enum service_state { + unknown_service_state, + cooperating, + not_cooperating, + service_partner_down, + not_responding, + service_startup +}; + +#if defined (FAILOVER_PROTOCOL) +typedef struct _dhcp_failover_config { + struct option_cache *address; + int port; + u_int32_t max_flying_updates; + enum failover_state state; + TIME stos; + u_int32_t max_response_delay; +} dhcp_failover_config_t; + +typedef struct _dhcp_failover_state { + OMAPI_OBJECT_PREAMBLE; + struct _dhcp_failover_state *next; + char *name; /* Name of this failover instance. */ + dhcp_failover_config_t me; /* My configuration. */ + dhcp_failover_config_t partner; /* Partner's configuration. */ + enum failover_state saved_state; /* Saved state during startup. */ + struct data_string server_identifier; /* Server identifier (IP addr) */ + u_int32_t mclt; + + u_int8_t *hba; /* Hash bucket array for load balancing. */ + int load_balance_max_secs; + + u_int32_t max_lease_misbalance, max_lease_ownership; + u_int32_t max_balance, min_balance; + TIME last_balance, sched_balance; + + u_int32_t auto_partner_down; + + enum service_state service_state; + const char *nrr; /* Printable reason why we're in the + not_responding service state (empty + string if we are responding. */ + + dhcp_failover_link_t *link_to_peer; /* Currently-established link + to peer. */ + + enum { + primary, secondary + } i_am; /* We are primary or secondary in this relationship. */ + + TIME last_packet_sent; /* Timestamp on last packet we sent. */ + TIME last_timestamp_received; /* The last timestamp we sent that + has been returned by our partner. */ + TIME skew; /* The skew between our clock and our partner's. */ + struct lease *update_queue_head; /* List of leases we haven't sent + to peer. */ + struct lease *update_queue_tail; + + struct lease *ack_queue_head; /* List of lease updates the peer + hasn't yet acked. */ + struct lease *ack_queue_tail; + + struct lease *send_update_done; /* When we get a BNDACK for this + lease, send an UPDDONE message. */ + int cur_unacked_updates; /* Number of updates we've sent + that have not yet been acked. */ + + /* List of messages which we haven't + acked yet. */ + failover_message_t *toack_queue_head; + failover_message_t *toack_queue_tail; + int pending_acks; /* Number of messages in the toack + queue. */ + int pool_count; /* Number of pools referencing this + failover state object. */ + int curUPD; /* If an UPDREQ* message is in motion, + this value indicates which one. */ + u_int32_t updxid; /* XID of UPDREQ* message in action. */ +} dhcp_failover_state_t; + +#define DHCP_FAILOVER_VERSION 1 +#endif /* FAILOVER_PROTOCOL */ diff --git a/includes/heap.h b/includes/heap.h new file mode 100644 index 0000000..e44a23a --- /dev/null +++ b/includes/heap.h @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC") + * 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 ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC 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: heap.h,v 1.3 2007/05/19 19:16:25 dhankins Exp $ */ + +#ifndef ISC_HEAP_H +#define ISC_HEAP_H 1 + +/*! \file isc/heap.h */ + +/*% + * The comparision function returns ISC_TRUE if the first argument has + * higher priority than the second argument, and ISC_FALSE otherwise. + */ +typedef isc_boolean_t (*isc_heapcompare_t)(void *, void *); + +/*% + * The index function allows the client of the heap to receive a callback + * when an item's index number changes. This allows it to maintain + * sync with its external state, but still delete itself, since deletions + * from the heap require the index be provided. + */ +typedef void (*isc_heapindex_t)(void *, unsigned int); + +/*% + * The heapaction function is used when iterating over the heap. + * + * NOTE: The heap structure CANNOT BE MODIFIED during the call to + * isc_heap_foreach(). + */ +typedef void (*isc_heapaction_t)(void *, void *); + +typedef struct isc_heap isc_heap_t; + +isc_result_t +isc_heap_create(isc_heapcompare_t compare, + isc_heapindex_t index, unsigned int size_increment, + isc_heap_t **heapp); +/*!< + * \brief Create a new heap. The heap is implemented using a space-efficient + * storage method. When the heap elements are deleted space is not freed + * but will be reused when new elements are inserted. + * + * Requires: + *\li "mctx" is valid. + *\li "compare" is a function which takes two void * arguments and + * returns ISC_TRUE if the first argument has a higher priority than + * the second, and ISC_FALSE otherwise. + *\li "index" is a function which takes a void *, and an unsigned int + * argument. This function will be called whenever an element's + * index value changes, so it may continue to delete itself from the + * heap. This option may be NULL if this functionality is unneeded. + *\li "size_increment" is a hint about how large the heap should grow + * when resizing is needed. If this is 0, a default size will be + * used, which is currently 1024, allowing space for an additional 1024 + * heap elements to be inserted before adding more space. + *\li "heapp" is not NULL, and "*heap" is NULL. + * + * Returns: + *\li ISC_R_SUCCESS - success + *\li ISC_R_NOMEMORY - insufficient memory + */ + +void +isc_heap_destroy(isc_heap_t **heapp); +/*!< + * \brief Destroys a heap. + * + * Requires: + *\li "heapp" is not NULL and "*heap" points to a valid isc_heap_t. + */ + +isc_result_t +isc_heap_insert(isc_heap_t *heap, void *elt); +/*!< + * \brief Inserts a new element into a heap. + * + * Requires: + *\li "heapp" is not NULL and "*heap" points to a valid isc_heap_t. + */ + +void +isc_heap_delete(isc_heap_t *heap, unsigned int index); +/*!< + * \brief Deletes an element from a heap, by element index. + * + * Requires: + *\li "heapp" is not NULL and "*heap" points to a valid isc_heap_t. + *\li "index" is a valid element index, as provided by the "index" callback + * provided during heap creation. + */ + +void +isc_heap_increased(isc_heap_t *heap, unsigned int index); +/*!< + * \brief Indicates to the heap that an element's priority has increased. + * This function MUST be called whenever an element has increased in priority. + * + * Requires: + *\li "heapp" is not NULL and "*heap" points to a valid isc_heap_t. + *\li "index" is a valid element index, as provided by the "index" callback + * provided during heap creation. + */ + +void +isc_heap_decreased(isc_heap_t *heap, unsigned int index); +/*!< + * \brief Indicates to the heap that an element's priority has decreased. + * This function MUST be called whenever an element has decreased in priority. + * + * Requires: + *\li "heapp" is not NULL and "*heap" points to a valid isc_heap_t. + *\li "index" is a valid element index, as provided by the "index" callback + * provided during heap creation. + */ + +void * +isc_heap_element(isc_heap_t *heap, unsigned int index); +/*!< + * \brief Returns the element for a specific element index. + * + * Requires: + *\li "heapp" is not NULL and "*heap" points to a valid isc_heap_t. + *\li "index" is a valid element index, as provided by the "index" callback + * provided during heap creation. + * + * Returns: + *\li A pointer to the element for the element index. + */ + +void +isc_heap_foreach(isc_heap_t *heap, isc_heapaction_t action, void *uap); +/*!< + * \brief Iterate over the heap, calling an action for each element. The + * order of iteration is not sorted. + * + * Requires: + *\li "heapp" is not NULL and "*heap" points to a valid isc_heap_t. + *\li "action" is not NULL, and is a function which takes two arguments. + * The first is a void *, representing the element, and the second is + * "uap" as provided to isc_heap_foreach. + *\li "uap" is a caller-provided argument, and may be NULL. + * + * Note: + *\li The heap structure CANNOT be modified during this iteration. The only + * safe function to call while iterating the heap is isc_heap_element(). + */ + +#endif /* ISC_HEAP_H */ diff --git a/includes/inet.h b/includes/inet.h new file mode 100644 index 0000000..4493e3e --- /dev/null +++ b/includes/inet.h @@ -0,0 +1,79 @@ +/* inet.h + + Portable definitions for internet addresses */ + +/* + * Copyright (c) 2004,2007,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +/* An internet address of up to 128 bits. */ + +struct iaddr { + unsigned len; + unsigned char iabuf [16]; +}; + +struct iaddrlist { + struct iaddrlist *next; + struct iaddr addr; +}; + + +/* struct iaddrmatch - used to compare a host IP against a subnet spec + * + * There is a space/speed tradeoff here implied by the use of a second + * struct iaddr to hold the mask; while using an unsigned (byte!) to + * represent the subnet prefix length would be more memory efficient, + * it makes run-time mask comparisons more expensive. Since such + * entries are used currently only in restricted circumstances + * (wanting to reject a subnet), the decision is in favour of run-time + * efficiency. + */ + +struct iaddrmatch { + struct iaddr addr; + struct iaddr mask; +}; + +/* its list ... */ + +struct iaddrmatchlist { + struct iaddrmatchlist *next; + struct iaddrmatch match; +}; + + +/* + * Structure to store information about a CIDR network. + */ + +struct iaddrcidrnet { + struct iaddr lo_addr; + int bits; +}; + +struct iaddrcidrnetlist { + struct iaddrcidrnetlist *next; + struct iaddrcidrnet cidrnet; +}; + diff --git a/includes/isc-dhcp/dst.h b/includes/isc-dhcp/dst.h new file mode 100644 index 0000000..65c54d2 --- /dev/null +++ b/includes/isc-dhcp/dst.h @@ -0,0 +1,142 @@ +#ifndef DST_H +#define DST_H + +#ifndef HAS_DST_KEY +typedef struct dst_key { + char *dk_key_name; /* name of the key */ + int dk_key_size; /* this is the size of the key in bits */ + int dk_proto; /* what protocols this key can be used for */ + int dk_alg; /* algorithm number from key record */ + unsigned dk_flags; /* and the flags of the public key */ + unsigned dk_id; /* identifier of the key */ +} DST_KEY; +#endif /* HAS_DST_KEY */ + +/* + * DST Crypto API defintions + */ +void dst_init(void); +int dst_check_algorithm(const int); + +int dst_sign_data(const int mode, /* specifies INIT/UPDATE/FINAL/ALL */ + DST_KEY *in_key, /* the key to use */ + void **context, /* pointer to state structure */ + const u_char *data, /* data to be signed */ + const unsigned len, /* length of input data */ + u_char *signature, /* buffer to write signature to */ + const unsigned sig_len); /* size of output buffer */ + +int dst_verify_data(const int mode, /* specifies INIT/UPDATE/FINAL/ALL */ + DST_KEY *in_key, /* the key to use */ + void **context, /* pointer to state structure */ + const u_char *data, /* data to be verified */ + const unsigned len, /* length of input data */ + const u_char *signature,/* buffer containing signature */ + const unsigned sig_len); /* length of signature */ + + +DST_KEY *dst_read_key(const char *in_name, /* name of key */ + const unsigned in_id, /* key tag identifier */ + const int in_alg, /* key algorithm */ + const int key_type); /* Private/PublicKey wanted*/ + +int dst_write_key(const DST_KEY *key, /* key to write out */ + const int key_type); /* Public/Private */ + +DST_KEY *dst_dnskey_to_key(const char *in_name, /* KEY record name */ + const u_char *key, /* KEY RDATA */ + const unsigned len); /* size of input buffer*/ + + +int dst_key_to_dnskey(const DST_KEY *key, /* key to translate */ + u_char *out_storage, /* output buffer */ + const unsigned out_len); /* size of out_storage*/ + + +DST_KEY *dst_buffer_to_key(const char *key_name, /* name of the key */ + const int alg, /* algorithm */ + const unsigned flags, /* dns flags */ + const int protocol, /* dns protocol */ + const u_char *key_buf, /* key in dns wire fmt */ + const unsigned key_len); /* size of key */ + + +int dst_key_to_buffer(DST_KEY *key, u_char *out_buff, unsigned buf_len); + +DST_KEY *dst_generate_key(const char *name, /* name of new key */ + const int bits, /* size of new key */ + const int exp, /* alg dependent parameter*/ + const unsigned flags, /* key DNS flags */ + const int protocol, /* key DNS protocol */ + const int alg); /* key algorithm to generate */ + +DST_KEY *dst_free_key(DST_KEY *f_key); +int dst_compare_keys(const DST_KEY *key1, const DST_KEY *key2); + +int dst_sig_size(DST_KEY *key); + +int dst_random(const int mode, unsigned wanted, u_char *outran); + + +/* support for dns key tags/ids */ +u_int16_t dst_s_dns_key_id(const u_char *dns_key_rdata, + const unsigned rdata_len); +u_int16_t dst_s_id_calc(const u_char *key_data, const unsigned key_len); + +/* Used by callers as well as by the library. */ +#define RAW_KEY_SIZE 8192 /* large enough to store any key */ + +/* DST_API control flags */ +/* These are used used in functions dst_sign_data and dst_verify_data */ +#define SIG_MODE_INIT 1 /* initalize digest */ +#define SIG_MODE_UPDATE 2 /* add data to digest */ +#define SIG_MODE_FINAL 4 /* generate/verify signature */ +#define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL) + +/* Flags for dst_read_private_key() */ +#define DST_FORCE_READ 0x1000000 +#define DST_CAN_SIGN 0x010F +#define DST_NO_AUTHEN 0x8000 +#define DST_EXTEND_FLAG 0x1000 +#define DST_STANDARD 0 +#define DST_PRIVATE 0x2000000 +#define DST_PUBLIC 0x4000000 +#define DST_RAND_SEMI 1 +#define DST_RAND_STD 2 +#define DST_RAND_KEY 3 +#define DST_RAND_DSS 4 + + +/* DST algorithm codes */ +#define KEY_RSA 1 +#define KEY_DH 2 +#define KEY_DSA 3 +#define KEY_PRIVATE 254 +#define KEY_EXPAND 255 +#define KEY_HMAC_MD5 157 +#define KEY_HMAC_SHA1 158 +#define UNKNOWN_KEYALG 0 +#define DST_MAX_ALGS KEY_HMAC_SHA1 + +/* DST constants to locations in KEY record changes in new KEY record */ +#define DST_FLAGS_SIZE 2 +#define DST_KEY_PROT 2 +#define DST_KEY_ALG 3 +#define DST_EXT_FLAG 4 +#define DST_KEY_START 4 + +#ifndef SIGN_F_NOKEY +#define SIGN_F_NOKEY 0xC000 +#endif + +/* error codes from dst routines */ +#define SIGN_INIT_FAILURE (-23) +#define SIGN_UPDATE_FAILURE (-24) +#define SIGN_FINAL_FAILURE (-25) +#define VERIFY_INIT_FAILURE (-26) +#define VERIFY_UPDATE_FAILURE (-27) +#define VERIFY_FINAL_FAILURE (-28) +#define MISSING_KEY_OR_SIGNATURE (-30) +#define UNSUPPORTED_KEYALG (-31) + +#endif /* DST_H */ diff --git a/includes/minires.h b/includes/minires.h new file mode 100644 index 0000000..2e6126c --- /dev/null +++ b/includes/minires.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004,2007-2009 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2001-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * http://www.isc.org/ + */ +#ifndef MINIRES_H +#define MINIRES_H + +#include "cdefs.h" +#include "osdep.h" + +/* + * Based on the Dynamic DNS reference implementation by Viraj Bais + * <viraj_bais@ccm.fm.intel.com> + */ + +int MRns_name_compress(const char *, u_char *, size_t, const unsigned char **, + const unsigned char **); +int MRns_name_unpack(const unsigned char *, const unsigned char *, + const unsigned char *, unsigned char *, size_t); +int MRns_name_pack (const unsigned char *, unsigned char *, + unsigned, const unsigned char **, const unsigned char **); +int MRns_name_ntop(const unsigned char *, char *, size_t); +int MRns_name_pton(const char *, u_char *, size_t); +int MRns_name_uncompress_list(const unsigned char*, int buflen, char*, size_t); +int MRns_name_compress_list(const char*, int buflen, unsigned char*, size_t); + +#endif /* MINIRES_H */ diff --git a/includes/netinet/if_ether.h b/includes/netinet/if_ether.h new file mode 100644 index 0000000..a133710 --- /dev/null +++ b/includes/netinet/if_ether.h @@ -0,0 +1,62 @@ +/* $NetBSD: if_ether.h,v 1.20 1995/06/12 00:47:27 mycroft Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. 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. + * + * @(#)if_ether.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef netinet_if_ether_h +#define netinet_if_ether_h + +/* + * Ethernet address - 6 octets + * this is only used by the ethers(3) functions. + */ +struct ether_addr { + u_int8_t ether_addr_octet[6]; +}; + +/* + * Structure of a 10Mb/s Ethernet header. + */ +#define ETHER_ADDR_LEN 6 + +struct isc_ether_header { + u_int8_t ether_dhost[ETHER_ADDR_LEN]; + u_int8_t ether_shost[ETHER_ADDR_LEN]; + u_int16_t ether_type; +}; + +#define ETHERTYPE_PUP 0x0200 /* PUP protocol */ +#define ETHERTYPE_IP 0x0800 /* IP protocol */ +#define ETHERTYPE_ARP 0x0806 /* address resolution protocol */ + +#define ETHER_HEADER_SIZE (ETHER_ADDR_LEN * 2 + sizeof (u_int16_t)) + +#endif diff --git a/includes/netinet/ip.h b/includes/netinet/ip.h new file mode 100644 index 0000000..9d20e5f --- /dev/null +++ b/includes/netinet/ip.h @@ -0,0 +1,159 @@ +/* $NetBSD: ip.h,v 1.9 1995/05/15 01:22:44 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. 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. + * + * @(#)ip.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * Definitions for internet protocol version 4. + * Per RFC 791, September 1981. + */ +#define IPVERSION 4 + +/* + * Structure of an internet header, naked of options. + * + * We declare ip_len and ip_off to be short, rather than u_short + * pragmatically since otherwise unsigned comparisons can result + * against negative integers quite easily, and fail in subtle ways. + */ +struct ip { + u_int8_t ip_fvhl; /* header length, version */ + u_int8_t ip_tos; /* type of service */ + int16_t ip_len; /* total length */ + u_int16_t ip_id; /* identification */ + int16_t ip_off; /* fragment offset field */ +#define IP_DF 0x4000 /* dont fragment flag */ +#define IP_MF 0x2000 /* more fragments flag */ +#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ + u_int8_t ip_ttl; /* time to live */ + u_int8_t ip_p; /* protocol */ + u_int16_t ip_sum; /* checksum */ + struct in_addr ip_src, ip_dst; /* source and dest address */ +}; + +#define IP_V(iph) ((iph)->ip_fvhl >> 4) +#define IP_HL(iph) (((iph)->ip_fvhl & 0x0F) << 2) +#define IP_V_SET(iph,x) ((iph)->ip_fvhl = ((iph)->ip_fvhl & 0x0F) | ((x) << 4)) +#define IP_HL_SET(iph,x) ((iph)->ip_fvhl = \ + ((iph)->ip_fvhl & 0xF0) | (((x) >> 2) & 0x0F)) + +#define IP_MAXPACKET 65535 /* maximum packet size */ + +/* + * Definitions for IP type of service (ip_tos) + */ +#define IPTOS_LOWDELAY 0x10 +#define IPTOS_THROUGHPUT 0x08 +#define IPTOS_RELIABILITY 0x04 +/* IPTOS_LOWCOST 0x02 XXX */ + +/* + * Definitions for IP precedence (also in ip_tos) (hopefully unused) + */ +#define IPTOS_PREC_NETCONTROL 0xe0 +#define IPTOS_PREC_INTERNETCONTROL 0xc0 +#define IPTOS_PREC_CRITIC_ECP 0xa0 +#define IPTOS_PREC_FLASHOVERRIDE 0x80 +#define IPTOS_PREC_FLASH 0x60 +#define IPTOS_PREC_IMMEDIATE 0x40 +#define IPTOS_PREC_PRIORITY 0x20 +#define IPTOS_PREC_ROUTINE 0x00 + +/* + * Definitions for options. + */ +#define IPOPT_COPIED(o) ((o)&0x80) +#define IPOPT_CLASS(o) ((o)&0x60) +#define IPOPT_NUMBER(o) ((o)&0x1f) + +#define IPOPT_CONTROL 0x00 +#define IPOPT_RESERVED1 0x20 +#define IPOPT_DEBMEAS 0x40 +#define IPOPT_RESERVED2 0x60 + +#define IPOPT_EOL 0 /* end of option list */ +#define IPOPT_NOP 1 /* no operation */ + +#define IPOPT_RR 7 /* record packet route */ +#define IPOPT_TS 68 /* timestamp */ +#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ +#define IPOPT_LSRR 131 /* loose source route */ +#define IPOPT_SATID 136 /* satnet id */ +#define IPOPT_SSRR 137 /* strict source route */ + +/* + * Offsets to fields in options other than EOL and NOP. + */ +#define IPOPT_OPTVAL 0 /* option ID */ +#define IPOPT_OLEN 1 /* option length */ +#define IPOPT_OFFSET 2 /* offset within option */ +#define IPOPT_MINOFF 4 /* min value of above */ + +/* + * Time stamp option structure. + */ +struct ip_timestamp { + u_int8_t ipt_code; /* IPOPT_TS */ + u_int8_t ipt_len; /* size of structure (variable) */ + u_int8_t ipt_ptr; /* index of current entry */ + u_int8_t ipt_flg_oflw; /* flags, see below, overflow counter */ + union ipt_timestamp { + u_int32_t ipt_time[1]; + struct ipt_ta { + struct in_addr ipt_addr; + u_int32_t ipt_time; + } ipt_ta[1]; + } ipt_timestamp; +}; + +/* flag bits for ipt_flg */ +#define IPOPT_TS_TSONLY 0 /* timestamps only */ +#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ +#define IPOPT_TS_PRESPEC 3 /* specified modules only */ + +/* bits for security (not byte swapped) */ +#define IPOPT_SECUR_UNCLASS 0x0000 +#define IPOPT_SECUR_CONFID 0xf135 +#define IPOPT_SECUR_EFTO 0x789a +#define IPOPT_SECUR_MMMM 0xbc4d +#define IPOPT_SECUR_RESTR 0xaf13 +#define IPOPT_SECUR_SECRET 0xd788 +#define IPOPT_SECUR_TOPSECRET 0x6bc5 + +/* + * Internet implementation parameters. + */ +#define MAXTTL 255 /* maximum time to live (seconds) */ +#define IPDEFTTL 64 /* default ttl, from RFC 1340 */ +#define IPFRAGTTL 60 /* time to live for frags, slowhz */ +#define IPTTLDEC 1 /* subtracted when forwarding */ + +#define IP_MSS 576 /* default maximum segment size */ diff --git a/includes/netinet/ip_icmp.h b/includes/netinet/ip_icmp.h new file mode 100644 index 0000000..0f40c3b --- /dev/null +++ b/includes/netinet/ip_icmp.h @@ -0,0 +1,178 @@ +/* $NetBSD: ip_icmp.h,v 1.11 1996/08/03 15:48:18 neil Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. 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. + * + * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93 + */ + + +/* + * Interface Control Message Protocol Definitions. + * Per RFC 792, September 1981. + */ + +/* + * Internal of an ICMP Router Advertisement + */ +struct icmp_ra_addr { + u_int32_t ira_addr; + u_int32_t ira_preference; +}; + +/* + * Structure of an icmp header. + */ +struct icmp { + u_int8_t icmp_type; /* type of message, see below */ + u_int8_t icmp_code; /* type sub code */ + u_int16_t icmp_cksum; /* ones complement cksum of struct */ + union { + u_int8_t ih_pptr; /* ICMP_PARAMPROB */ + struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ + struct ih_idseq { + int16_t icd_id; + int16_t icd_seq; + } ih_idseq; + int32_t ih_void; + + /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */ + struct ih_pmtu { + int16_t ipm_void; + int16_t ipm_nextmtu; + } ih_pmtu; + struct ih_rtradv { + u_int8_t irt_num_addrs; + u_int8_t irt_wpa; + u_int16_t irt_lifetime; + } ih_rtradv; + } icmp_hun; +#define icmp_pptr icmp_hun.ih_pptr +#define icmp_gwaddr icmp_hun.ih_gwaddr +#define icmp_id icmp_hun.ih_idseq.icd_id +#define icmp_seq icmp_hun.ih_idseq.icd_seq +#define icmp_void icmp_hun.ih_void +#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void +#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu +#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs +#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa +#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime + union { + struct id_ts { + u_int32_t its_otime; + u_int32_t its_rtime; + u_int32_t its_ttime; + } id_ts; + struct id_ip { + struct ip idi_ip; + /* options and then 64 bits of data */ + } id_ip; + struct icmp_ra_addr id_radv; + u_int32_t id_mask; + int8_t id_data[1]; + } icmp_dun; +#define icmp_otime icmp_dun.id_ts.its_otime +#define icmp_rtime icmp_dun.id_ts.its_rtime +#define icmp_ttime icmp_dun.id_ts.its_ttime +#define icmp_ip icmp_dun.id_ip.idi_ip +#define icmp_radv icmp_dun.id_mask +#define icmp_mask icmp_dun.id_mask +#define icmp_data icmp_dun.id_data +}; + +/* + * Lower bounds on packet lengths for various types. + * For the error advice packets must first insure that the + * packet is large enought to contain the returned ip header. + * Only then can we do the check to see if 64 bits of packet + * data have been returned, since we need to check the returned + * ip header length. + */ +#define ICMP_MINLEN 8 /* abs minimum */ +#define ICMP_TSLEN (8 + 3 * sizeof (u_int32_t)) /* timestamp */ +#define ICMP_MASKLEN 12 /* address mask */ +#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */ +#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) + /* N.B.: must separately check that ip_hl >= 5 */ + +/* + * Definition of type and code field values. + */ +#define ICMP_ECHOREPLY 0 /* echo reply */ +#define ICMP_UNREACH 3 /* dest unreachable, codes: */ +#define ICMP_UNREACH_NET 0 /* bad net */ +#define ICMP_UNREACH_HOST 1 /* bad host */ +#define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */ +#define ICMP_UNREACH_PORT 3 /* bad port */ +#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */ +#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */ +#define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */ +#define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */ +#define ICMP_UNREACH_ISOLATED 8 /* src host isolated */ +#define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */ +#define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */ +#define ICMP_UNREACH_TOSNET 11 /* bad tos for net */ +#define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */ +#define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */ +#define ICMP_REDIRECT 5 /* shorter route, codes: */ +#define ICMP_REDIRECT_NET 0 /* for network */ +#define ICMP_REDIRECT_HOST 1 /* for host */ +#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */ +#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */ +#define ICMP_ECHO 8 /* echo service */ +#define ICMP_ROUTERADVERT 9 /* router advertisement */ +#define ICMP_ROUTERSOLICIT 10 /* router solicitation */ +#define ICMP_TIMXCEED 11 /* time exceeded, code: */ +#define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ +#define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ +#define ICMP_PARAMPROB 12 /* ip header bad */ +#define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */ +#define ICMP_TSTAMP 13 /* timestamp request */ +#define ICMP_TSTAMPREPLY 14 /* timestamp reply */ +#define ICMP_IREQ 15 /* information request */ +#define ICMP_IREQREPLY 16 /* information reply */ +#define ICMP_MASKREQ 17 /* address mask request */ +#define ICMP_MASKREPLY 18 /* address mask reply */ + +#define ICMP_MAXTYPE 18 + +#define ICMP_INFOTYPE(type) \ + ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ + (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ + (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ + (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ + (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) + +#ifdef _KERNEL +void icmp_error __P((struct mbuf *, int, int, n_long, struct ifnet *)); +void icmp_input __P((struct mbuf *, ...)); +void icmp_reflect __P((struct mbuf *)); +void icmp_send __P((struct mbuf *, struct mbuf *)); +int icmp_sysctl __P((int *, u_int, void *, size_t *, void *, size_t)); +#endif + diff --git a/includes/netinet/udp.h b/includes/netinet/udp.h new file mode 100644 index 0000000..d86cf44 --- /dev/null +++ b/includes/netinet/udp.h @@ -0,0 +1,66 @@ +/* $NetBSD: udp.h,v 1.6 1995/04/13 06:37:10 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. 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. + * + * @(#)udp.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * Portions Copyright (c) 2004,2009 by Internet Systems Consortium, Inc. ("ISC") + * Portions Copyright (c) 2000-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + */ + +/* + * Udp protocol header. + * Per RFC 768, September, 1981. + */ +struct udphdr { + u_int16_t uh_sport; /* source port */ + u_int16_t uh_dport; /* destination port */ + u_int16_t uh_ulen; /* udp length */ + u_int16_t uh_sum; /* udp checksum */ +}; diff --git a/includes/omapip/alloc.h b/includes/omapip/alloc.h new file mode 100644 index 0000000..407f590 --- /dev/null +++ b/includes/omapip/alloc.h @@ -0,0 +1,105 @@ +/* alloc.h + + Definitions for the object management API protocol memory allocation... */ + +/* + * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +isc_result_t omapi_buffer_new (omapi_buffer_t **, const char *, int); +isc_result_t omapi_buffer_reference (omapi_buffer_t **, + omapi_buffer_t *, const char *, int); +isc_result_t omapi_buffer_dereference (omapi_buffer_t **, const char *, int); + +#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \ + defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) +#define DMDOFFSET (sizeof (struct dmalloc_preamble)) +#define DMLFSIZE 16 +#define DMUFSIZE 16 +#define DMDSIZE (DMDOFFSET + DMLFSIZE + DMUFSIZE) + +struct dmalloc_preamble { + struct dmalloc_preamble *prev, *next; + const char *file; + int line; + size_t size; + unsigned long generation; + unsigned char low_fence [DMLFSIZE]; +}; +#else +#define DMDOFFSET 0 +#define DMDSIZE 0 +#endif + +/* rc_history flags... */ +#define RC_LEASE 1 +#define RC_MISC 2 + +#if defined (DEBUG_RC_HISTORY) +#if !defined (RC_HISTORY_MAX) +# define RC_HISTORY_MAX 256 +#endif + +#if !defined (RC_HISTORY_FLAGS) +# define RC_HISTORY_FLAGS (RC_LEASE | RC_MISC) +#endif + +struct rc_history_entry { + const char *file; + int line; + void *reference; + void *addr; + int refcnt; +}; + +#define rc_register(x, l, r, y, z, d, f) do { \ + if (RC_HISTORY_FLAGS & ~(f)) { \ + rc_history [rc_history_index].file = (x); \ + rc_history [rc_history_index].line = (l); \ + rc_history [rc_history_index].reference = (r); \ + rc_history [rc_history_index].addr = (y); \ + rc_history [rc_history_index].refcnt = (z); \ + rc_history_next (d); \ + } \ + } while (0) +#define rc_register_mdl(r, y, z, d, f) \ + rc_register (__FILE__, __LINE__, r, y, z, d, f) +#else +#define rc_register(file, line, reference, addr, refcnt, d, f) +#define rc_register_mdl(reference, addr, refcnt, d, f) +#endif + +#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \ + defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) +extern struct dmalloc_preamble *dmalloc_list; +extern unsigned long dmalloc_outstanding; +extern unsigned long dmalloc_longterm; +extern unsigned long dmalloc_generation; +extern unsigned long dmalloc_cutoff_generation; +#endif + +#if defined (DEBUG_RC_HISTORY) +extern struct rc_history_entry rc_history [RC_HISTORY_MAX]; +extern int rc_history_index; +extern int rc_history_count; +#endif diff --git a/includes/omapip/buffer.h b/includes/omapip/buffer.h new file mode 100644 index 0000000..f31aa99 --- /dev/null +++ b/includes/omapip/buffer.h @@ -0,0 +1,77 @@ +/* buffer.h + + Definitions for the object management API protocol buffering... */ + +/* + * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +/* OMAPI buffers are ring buffers, which means that the beginning of the + buffer and the end of the buffer chase each other around. As long as + the tail never catches up to the head, there's room in the buffer for + data. + + - If the tail and the head are equal, the buffer is empty. + + - If the tail is less than the head, the contents of the buffer + are the bytes from the head to the end of buffer, and in addition, + the bytes between the beginning of the buffer and the tail, not + including the byte addressed by the tail. + + - If the tail is greater than the head, then the buffer contains + valid bytes starting with the byte addressed by the head, and + ending with the byte before the byte addressed by the tail. + + There will always be at least one byte of waste, because the tail can't + increase so that it's equal to the head (that would represent an empty + buffer. */ +#define OMAPI_BUF_SIZE 4048 +typedef struct _omapi_buffer { + struct _omapi_buffer *next; /* Buffers can be chained. */ + u_int32_t refcnt; /* Buffers are reference counted. */ + u_int16_t head, tail; /* Buffers are organized in a ring. */ + char buf [OMAPI_BUF_SIZE]; /* The actual buffer is included in + the buffer data structure. */ +} omapi_buffer_t; + +#define BUFFER_BYTES_FREE(x) \ + ((x) -> tail > (x) -> head \ + ? sizeof ((x) -> buf) - ((x) -> tail - (x) -> head) \ + : (x) -> head - (x) -> tail) + +#define BYTES_IN_BUFFER(x) \ + ((x) -> tail > (x) -> head \ + ? (x) -> tail - (x) -> head - 1 \ + : sizeof ((x) -> buf) - ((x) -> head - (x) -> tail) - 1) + +isc_result_t omapi_connection_require (omapi_object_t *, unsigned); +isc_result_t omapi_connection_copyout (unsigned char *, + omapi_object_t *, unsigned); +isc_result_t omapi_connection_copyin (omapi_object_t *, + const unsigned char *, unsigned); +isc_result_t omapi_connection_flush (omapi_object_t *); +isc_result_t omapi_connection_get_uint32 (omapi_object_t *, u_int32_t *); +isc_result_t omapi_connection_put_uint32 (omapi_object_t *, u_int32_t); +isc_result_t omapi_connection_get_uint16 (omapi_object_t *, u_int16_t *); +isc_result_t omapi_connection_put_uint16 (omapi_object_t *, u_int32_t); + diff --git a/includes/omapip/convert.h b/includes/omapip/convert.h new file mode 100644 index 0000000..589594a --- /dev/null +++ b/includes/omapip/convert.h @@ -0,0 +1,46 @@ +/* convert.h + + Safe copying of integers into and out of a non-aligned memory buffer. */ + +/* + * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#ifndef OMAPI_CONVERT_H +#define OMAPI_CONVERT_H + +u_int32_t getULong (const unsigned char *); +int32_t getLong (const unsigned char *); +u_int32_t getUShort (const unsigned char *); +int32_t getShort (const unsigned char *); +u_int32_t getUChar (const unsigned char *); +void putULong (unsigned char *, u_int32_t); +void putLong (unsigned char *, int32_t); +void putUShort (unsigned char *, u_int32_t); +void putShort (unsigned char *, int32_t); +void putUChar (unsigned char *, u_int32_t); +int converted_length (const unsigned char *, unsigned int, unsigned int); +int binary_to_ascii (unsigned char *, const unsigned char *, + unsigned int, unsigned int); + +#endif /* OMAPI_CONVERT_H */ diff --git a/includes/omapip/hash.h b/includes/omapip/hash.h new file mode 100644 index 0000000..4e7a413 --- /dev/null +++ b/includes/omapip/hash.h @@ -0,0 +1,161 @@ +/* hash.h + + Definitions for hashing... */ + +/* + * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1995-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#ifndef OMAPI_HASH_H +#define OMAPI_HASH_H + +#if !defined (DEFAULT_HASH_SIZE) +# define DEFAULT_HASH_SIZE 9973 +#endif + +#if !defined (KEY_HASH_SIZE) +# define KEY_HASH_SIZE 1009 +#endif + +/* The purpose of the hashed_object_t struct is to not match anything else. */ +typedef struct { + int foo; +} hashed_object_t; + +typedef isc_result_t (*hash_foreach_func)(const void *, unsigned, void *); +typedef int (*hash_reference) (hashed_object_t **, hashed_object_t *, + const char *, int); +typedef int (*hash_dereference) (hashed_object_t **, const char *, int); + +struct hash_bucket { + struct hash_bucket *next; + const unsigned char *name; + unsigned len; + hashed_object_t *value; +}; + +typedef int (*hash_comparator_t)(const void *, const void *, size_t); + +struct hash_table { + unsigned hash_count; + hash_reference referencer; + hash_dereference dereferencer; + hash_comparator_t cmp; + unsigned (*do_hash)(const void *, unsigned, unsigned); + + /* This must remain the last entry in this table. */ + struct hash_bucket *buckets [1]; +}; + +struct named_hash { + struct named_hash *next; + const char *name; + struct hash_table *hash; +}; + +#define HASH_FUNCTIONS_DECL(name, bufarg, type, hashtype) \ +void name##_hash_add (hashtype *, bufarg, unsigned, type *, \ + const char *, int); \ +void name##_hash_delete (hashtype *, bufarg, unsigned, \ + const char *, int); \ +int name##_hash_lookup (type **, hashtype *, bufarg, unsigned, \ + const char *, int); \ +unsigned char * name##_hash_report(hashtype *); \ +int name##_hash_foreach (hashtype *, hash_foreach_func); \ +int name##_new_hash (hashtype **, unsigned, const char *, int); \ +void name##_free_hash_table (hashtype **, const char *, int); + + +#define HASH_FUNCTIONS(name, bufarg, type, hashtype, ref, deref, hasher) \ +void name##_hash_add (hashtype *table, \ + bufarg buf, unsigned len, type *ptr, \ + const char *file, int line) \ +{ \ + add_hash ((struct hash_table *)table, buf, \ + len, (hashed_object_t *)ptr, file, line); \ +} \ + \ +void name##_hash_delete (hashtype *table, bufarg buf, unsigned len, \ + const char *file, int line) \ +{ \ + delete_hash_entry ((struct hash_table *)table, buf, len, \ + file, line); \ +} \ + \ +int name##_hash_lookup (type **ptr, hashtype *table, \ + bufarg buf, unsigned len, const char *file, int line) \ +{ \ + return hash_lookup ((hashed_object_t **)ptr, \ + (struct hash_table *)table, \ + buf, len, file, line); \ +} \ + \ +unsigned char * name##_hash_report(hashtype *table) \ +{ \ + return hash_report((struct hash_table *)table); \ +} \ + \ +int name##_hash_foreach (hashtype *table, hash_foreach_func func) \ +{ \ + return hash_foreach ((struct hash_table *)table, \ + func); \ +} \ + \ +int name##_new_hash (hashtype **tp, unsigned c, const char *file, int line) \ +{ \ + return new_hash ((struct hash_table **)tp, \ + (hash_reference)ref, (hash_dereference)deref, c, \ + hasher, file, line); \ +} \ + \ +void name##_free_hash_table (hashtype **table, const char *file, int line) \ +{ \ + free_hash_table ((struct hash_table **)table, file, line); \ +} + +void relinquish_hash_bucket_hunks (void); +int new_hash_table (struct hash_table **, unsigned, const char *, int); +void free_hash_table (struct hash_table **, const char *, int); +struct hash_bucket *new_hash_bucket (const char *, int); +void free_hash_bucket (struct hash_bucket *, const char *, int); +int new_hash(struct hash_table **, + hash_reference, hash_dereference, unsigned, + unsigned (*do_hash)(const void *, unsigned, unsigned), + const char *, int); +unsigned do_string_hash(const void *, unsigned, unsigned); +unsigned do_case_hash(const void *, unsigned, unsigned); +unsigned do_id_hash(const void *, unsigned, unsigned); +unsigned do_number_hash(const void *, unsigned, unsigned); +unsigned do_ip4_hash(const void *, unsigned, unsigned); +unsigned char *hash_report(struct hash_table *); +void add_hash (struct hash_table *, + const void *, unsigned, hashed_object_t *, + const char *, int); +void delete_hash_entry (struct hash_table *, const void *, + unsigned, const char *, int); +int hash_lookup (hashed_object_t **, struct hash_table *, + const void *, unsigned, const char *, int); +int hash_foreach (struct hash_table *, hash_foreach_func); +int casecmp (const void *s, const void *t, size_t len); + +#endif /* OMAPI_HASH_H */ diff --git a/includes/omapip/isclib.h b/includes/omapip/isclib.h new file mode 100644 index 0000000..30abacd --- /dev/null +++ b/includes/omapip/isclib.h @@ -0,0 +1,130 @@ +/* isclib.h + + connections to the isc and dns libraries */ + +/* + * Copyright (c) 2009,2013,2014 by Internet Systems Consortium, Inc. ("ISC") + * + * 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * http://www.isc.org/ + * + */ + +#ifndef ISCLIB_H +#define ISCLIB_H + +#include "config.h" + +#include <syslog.h> + +#define MAXWIRE 256 + +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> + +#include <arpa/inet.h> + +#include <unistd.h> +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <netdb.h> + +#include <isc/buffer.h> +#include <isc/lex.h> +#include <isc/lib.h> +#include <isc/app.h> +#include <isc/mem.h> +#include <isc/parseint.h> +#include <isc/socket.h> +#include <isc/sockaddr.h> +#include <isc/task.h> +#include <isc/timer.h> +#include <isc/heap.h> +#include <isc/random.h> + +#include <dns/client.h> +#include <dns/fixedname.h> +#include <dns/keyvalues.h> +#include <dns/lib.h> +#include <dns/name.h> +#include <dns/rdata.h> +#include <dns/rdataclass.h> +#include <dns/rdatalist.h> +#include <dns/rdataset.h> +#include <dns/rdatastruct.h> +#include <dns/rdatatype.h> +#include <dns/result.h> +#include <dns/secalg.h> +#include <dns/tsec.h> + +#include <dst/dst.h> + +#include "result.h" + + +/* + * DHCP context structure + * This holds the libisc information for a dhcp entity + */ + +typedef struct dhcp_context { + isc_mem_t *mctx; + isc_appctx_t *actx; + int actx_started; + isc_taskmgr_t *taskmgr; + isc_task_t *task; + isc_socketmgr_t *socketmgr; + isc_timermgr_t *timermgr; +#if defined (NSUPDATE) + dns_client_t *dnsclient; +#endif +} dhcp_context_t; + +extern dhcp_context_t dhcp_gbl_ctx; + +#define DHCP_MAXDNS_WIRE 256 +#define DHCP_MAXNS 3 +#define DHCP_HMAC_MD5_NAME "HMAC-MD5.SIG-ALG.REG.INT." +#define DHCP_HMAC_SHA1_NAME "HMAC-SHA1.SIG-ALG.REG.INT." +#define DHCP_HMAC_SHA224_NAME "HMAC-SHA224.SIG-ALG.REG.INT." +#define DHCP_HMAC_SHA256_NAME "HMAC-SHA256.SIG-ALG.REG.INT." +#define DHCP_HMAC_SHA384_NAME "HMAC-SHA384.SIG-ALG.REG.INT." +#define DHCP_HMAC_SHA512_NAME "HMAC-SHA512.SIG-ALG.REG.INT." + +isc_result_t dhcp_isc_name(unsigned char *namestr, + dns_fixedname_t *namefix, + dns_name_t **name); + +isc_result_t +isclib_make_dst_key(char *inname, + char *algorithm, + unsigned char *secret, + int length, + dst_key_t **dstkey); + +isc_result_t dhcp_context_create(void); +void isclib_cleanup(void); + +void dhcp_signal_handler(int signal); +extern int shutdown_signal; + +#endif /* ISCLIB_H */ diff --git a/includes/omapip/omapip.h b/includes/omapip/omapip.h new file mode 100644 index 0000000..c4724e3 --- /dev/null +++ b/includes/omapip/omapip.h @@ -0,0 +1,616 @@ +/* omapip.h + + Definitions for the object management API and protocol... */ + +/* + * Copyright (c) 2009,2013-2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#ifndef _OMAPIP_H_ +#define _OMAPIP_H_ +#include "result.h" +#include <stdarg.h> + +#include <dns/tsec.h> + +typedef unsigned int omapi_handle_t; + +struct __omapi_object; +typedef struct __omapi_object omapi_object_t; + +typedef enum { + omapi_datatype_int, + omapi_datatype_string, + omapi_datatype_data, + omapi_datatype_object +} omapi_datatype_t; + +typedef struct { + int refcnt; + omapi_datatype_t type; + union { + struct { + unsigned len; +#define OMAPI_TYPED_DATA_NOBUFFER_LEN (sizeof (int) + \ + sizeof (omapi_datatype_t) + \ + sizeof (int)) + unsigned char value [1]; + } buffer; +#define OMAPI_TYPED_DATA_OBJECT_LEN (sizeof (int) + \ + sizeof (omapi_datatype_t) + \ + sizeof (omapi_object_t *)) + omapi_object_t *object; +#define OMAPI_TYPED_DATA_REF_LEN (sizeof (int) + \ + sizeof (omapi_datatype_t) + \ + 3 * sizeof (void *)) + struct { + void *ptr; + isc_result_t (*reference) (void *, + void *, const char *, int); + isc_result_t (*dereference) (void *, + const char *, int); + } ref; +#define OMAPI_TYPED_DATA_INT_LEN (sizeof (int) + \ + sizeof (omapi_datatype_t) + \ + sizeof (int)) + int integer; + } u; +} omapi_typed_data_t; + +typedef struct { + int refcnt; + unsigned len; +#define OMAPI_DATA_STRING_EMPTY_SIZE (2 * sizeof (int)) + unsigned char value [1]; +} omapi_data_string_t; + +typedef struct { + int refcnt; + omapi_data_string_t *name; + omapi_typed_data_t *value; +} omapi_value_t; + +typedef struct __omapi_object_type_t { + const char *name; + struct __omapi_object_type_t *next; + + isc_result_t (*set_value) (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); + isc_result_t (*get_value) (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, omapi_value_t **); + isc_result_t (*destroy) (omapi_object_t *, const char *, int); + isc_result_t (*signal_handler) (omapi_object_t *, + const char *, va_list); + isc_result_t (*stuff_values) (omapi_object_t *, + omapi_object_t *, omapi_object_t *); + isc_result_t (*lookup) (omapi_object_t **, omapi_object_t *, + omapi_object_t *); + isc_result_t (*create) (omapi_object_t **, omapi_object_t *); + isc_result_t (*remove) (omapi_object_t *, omapi_object_t *); + isc_result_t (*freer) (omapi_object_t *, const char *, int); + isc_result_t (*allocator) (omapi_object_t **, const char *, int); + isc_result_t (*sizer) (size_t); + size_t size; + int rc_flag; + isc_result_t (*initialize) (omapi_object_t *, const char *, int); +} omapi_object_type_t; + +#define OMAPI_OBJECT_PREAMBLE \ + omapi_object_type_t *type; \ + int refcnt; \ + omapi_handle_t handle; \ + omapi_object_t *outer, *inner + +/* The omapi handle structure. */ +struct __omapi_object { + OMAPI_OBJECT_PREAMBLE; +}; + +/* The port on which applications should listen for OMAPI connections. */ +#define OMAPI_PROTOCOL_PORT 7911 + +typedef struct { + unsigned addrtype; + unsigned addrlen; + unsigned char address [16]; + unsigned port; +} omapi_addr_t; + +typedef struct { + int refcnt; + unsigned count; + omapi_addr_t *addresses; +} omapi_addr_list_t; + +typedef struct auth_key { + OMAPI_OBJECT_PREAMBLE; + char *name; + char *algorithm; + omapi_data_string_t *key; + dns_tsec_t *tsec_key; +} omapi_auth_key_t; + +#define OMAPI_CREATE 1 +#define OMAPI_UPDATE 2 +#define OMAPI_EXCL 4 +#define OMAPI_NOTIFY_PROTOCOL 8 + +#define OMAPI_OBJECT_ALLOC(name, stype, type) \ +isc_result_t name##_allocate (stype **p, const char *file, int line) \ +{ \ + return omapi_object_allocate ((omapi_object_t **)p, \ + type, 0, file, line); \ +} \ + \ +isc_result_t name##_reference (stype **pptr, stype *ptr, \ + const char *file, int line) \ +{ \ + return omapi_object_reference ((omapi_object_t **)pptr, \ + (omapi_object_t *)ptr, file, line); \ +} \ + \ +isc_result_t name##_dereference (stype **ptr, const char *file, int line) \ +{ \ + return omapi_object_dereference ((omapi_object_t **)ptr, file, line); \ +} + +#define OMAPI_OBJECT_ALLOC_DECL(name, stype, type) \ +isc_result_t name##_allocate (stype **p, const char *file, int line); \ +isc_result_t name##_reference (stype **pptr, stype *ptr, \ + const char *file, int line); \ +isc_result_t name##_dereference (stype **ptr, const char *file, int line); + +typedef isc_result_t (*omapi_array_ref_t) (char **, char *, const char *, int); +typedef isc_result_t (*omapi_array_deref_t) (char **, const char *, int); + +/* An extensible array type. */ +typedef struct { + char **data; + omapi_array_ref_t ref; + omapi_array_deref_t deref; + int count; + int max; +} omapi_array_t; + +#define OMAPI_ARRAY_TYPE(name, stype) \ +isc_result_t name##_array_allocate (omapi_array_t **p, \ + const char *file, int line) \ +{ \ + return (omapi_array_allocate \ + (p, \ + (omapi_array_ref_t)name##_reference, \ + (omapi_array_deref_t)name##_dereference, \ + file, line)); \ +} \ + \ +isc_result_t name##_array_free (omapi_array_t **p, \ + const char *file, int line) \ +{ \ + return omapi_array_free (p, file, line); \ +} \ + \ +isc_result_t name##_array_extend (omapi_array_t *pptr, stype *ptr, int *index,\ + const char *file, int line) \ +{ \ + return omapi_array_extend (pptr, (char *)ptr, index, file, line); \ +} \ + \ +isc_result_t name##_array_set (omapi_array_t *pptr, stype *ptr, int index, \ + const char *file, int line) \ +{ \ + return omapi_array_set (pptr, (char *)ptr, index, file, line); \ +} \ + \ +isc_result_t name##_array_lookup (stype **ptr, omapi_array_t *pptr, \ + int index, const char *file, int line) \ +{ \ + return omapi_array_lookup ((char **)ptr, pptr, index, file, line); \ +} + +#define OMAPI_ARRAY_TYPE_DECL(name, stype) \ +isc_result_t name##_array_allocate (omapi_array_t **, const char *, int); \ +isc_result_t name##_array_free (omapi_array_t **, const char *, int); \ +isc_result_t name##_array_extend (omapi_array_t *, stype *, int *, \ + const char *, int); \ +isc_result_t name##_array_set (omapi_array_t *, \ + stype *, int, const char *, int); \ +isc_result_t name##_array_lookup (stype **, \ + omapi_array_t *, int, const char *, int) + +#define omapi_array_foreach_begin(array, stype, var) \ + { \ + int omapi_array_foreach_index; \ + stype *var = (stype *)0; \ + for (omapi_array_foreach_index = 0; \ + array && \ + omapi_array_foreach_index < (array) -> count; \ + omapi_array_foreach_index++) { \ + if ((array) -> data [omapi_array_foreach_index]) { \ + ((*(array) -> ref) \ + ((char **)&var, \ + (array) -> data [omapi_array_foreach_index],\ + MDL)); + +#define omapi_array_foreach_end(array, stype, var) \ + (*(array) -> deref) ((char **)&var, MDL); \ + } \ + } \ + } + +isc_result_t omapi_protocol_connect (omapi_object_t *, + const char *, unsigned, omapi_object_t *); +isc_result_t omapi_connect_list (omapi_object_t *, omapi_addr_list_t *, + omapi_addr_t *); +isc_result_t omapi_protocol_listen (omapi_object_t *, unsigned, int); +isc_boolean_t omapi_protocol_authenticated (omapi_object_t *); +isc_result_t omapi_protocol_configure_security (omapi_object_t *, + isc_result_t (*) + (omapi_object_t *, + omapi_addr_t *), + isc_result_t (*) + (omapi_object_t *, + omapi_auth_key_t *)); +isc_result_t omapi_protocol_accept (omapi_object_t *); +isc_result_t omapi_protocol_send_intro (omapi_object_t *, unsigned, unsigned); +isc_result_t omapi_protocol_ready (omapi_object_t *); +isc_result_t omapi_protocol_add_auth (omapi_object_t *, omapi_object_t *, + omapi_handle_t); +isc_result_t omapi_protocol_lookup_auth (omapi_object_t **, omapi_object_t *, + omapi_handle_t); +isc_result_t omapi_protocol_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_protocol_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_protocol_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); + +isc_result_t omapi_protocol_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_protocol_send_message (omapi_object_t *, + omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_protocol_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_protocol_listener_set_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_protocol_listener_get_value (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_protocol_listener_destroy (omapi_object_t *, + const char *, int); +isc_result_t omapi_protocol_listener_signal (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_protocol_listener_stuff (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_protocol_send_status (omapi_object_t *, omapi_object_t *, + isc_result_t, unsigned, const char *); +isc_result_t omapi_protocol_send_open (omapi_object_t *, omapi_object_t *, + const char *, omapi_object_t *, + unsigned); +isc_result_t omapi_protocol_send_update (omapi_object_t *, omapi_object_t *, + unsigned, omapi_object_t *); + +isc_result_t omapi_connect (omapi_object_t *, const char *, unsigned); +isc_result_t omapi_disconnect (omapi_object_t *, int); +int omapi_connection_readfd (omapi_object_t *); +int omapi_connection_writefd (omapi_object_t *); +isc_result_t omapi_connection_connect (omapi_object_t *); +isc_result_t omapi_connection_reader (omapi_object_t *); +isc_result_t omapi_connection_writer (omapi_object_t *); +isc_result_t omapi_connection_reaper (omapi_object_t *); +isc_result_t omapi_connection_output_auth_length (omapi_object_t *, + unsigned *); +isc_result_t omapi_connection_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_connection_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_connection_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_connection_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_connection_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_connection_write_typed_data (omapi_object_t *, + omapi_typed_data_t *); +isc_result_t omapi_connection_put_name (omapi_object_t *, const char *); +isc_result_t omapi_connection_put_string (omapi_object_t *, const char *); +isc_result_t omapi_connection_put_handle (omapi_object_t *c, + omapi_object_t *h); + +isc_result_t omapi_listen (omapi_object_t *, unsigned, int); +isc_result_t omapi_listen_addr (omapi_object_t *, + omapi_addr_t *, int); +isc_result_t omapi_listener_accept (omapi_object_t *); +int omapi_listener_readfd (omapi_object_t *); +isc_result_t omapi_accept (omapi_object_t *); +isc_result_t omapi_listener_configure_security (omapi_object_t *, + isc_result_t (*) + (omapi_object_t *, + omapi_addr_t *)); +isc_result_t omapi_listener_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_listener_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_listener_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_listener_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_listener_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); + +isc_result_t omapi_register_io_object (omapi_object_t *, + int (*)(omapi_object_t *), + int (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *)); +isc_result_t omapi_reregister_io_object (omapi_object_t *, + int (*)(omapi_object_t *), + int (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *), + isc_result_t (*)(omapi_object_t *)); +isc_result_t omapi_unregister_io_object (omapi_object_t *); +isc_result_t omapi_dispatch (struct timeval *); +isc_result_t omapi_wait_for_completion (omapi_object_t *, struct timeval *); +isc_result_t omapi_one_dispatch (omapi_object_t *, struct timeval *); +isc_result_t omapi_io_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_io_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, omapi_value_t **); +isc_result_t omapi_io_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_io_signal_handler (omapi_object_t *, const char *, va_list); +isc_result_t omapi_io_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_waiter_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_io_state_foreach (isc_result_t (*func) (omapi_object_t *, + void *), + void *p); + +isc_result_t omapi_generic_new (omapi_object_t **, const char *, int); +isc_result_t omapi_generic_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_generic_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_generic_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_generic_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_generic_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_generic_clear_flags (omapi_object_t *); + +isc_result_t omapi_message_new (omapi_object_t **, const char *, int); +isc_result_t omapi_message_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_message_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_message_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_message_signal_handler (omapi_object_t *, + const char *, va_list); +isc_result_t omapi_message_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_message_register (omapi_object_t *); +isc_result_t omapi_message_unregister (omapi_object_t *); +isc_result_t omapi_message_process (omapi_object_t *, omapi_object_t *); + +OMAPI_OBJECT_ALLOC_DECL (omapi_auth_key, + omapi_auth_key_t, omapi_type_auth_key) +isc_result_t omapi_auth_key_new (omapi_auth_key_t **, const char *, int); +isc_result_t omapi_auth_key_destroy (omapi_object_t *, const char *, int); +isc_result_t omapi_auth_key_enter (omapi_auth_key_t *); +isc_result_t omapi_auth_key_lookup_name (omapi_auth_key_t **, const char *); +isc_result_t omapi_auth_key_lookup (omapi_object_t **, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_auth_key_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_auth_key_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); + +extern omapi_object_type_t *omapi_type_connection; +extern omapi_object_type_t *omapi_type_listener; +extern omapi_object_type_t *omapi_type_io_object; +extern omapi_object_type_t *omapi_type_generic; +extern omapi_object_type_t *omapi_type_protocol; +extern omapi_object_type_t *omapi_type_protocol_listener; +extern omapi_object_type_t *omapi_type_waiter; +extern omapi_object_type_t *omapi_type_remote; +extern omapi_object_type_t *omapi_type_message; +extern omapi_object_type_t *omapi_type_auth_key; + +extern omapi_object_type_t *omapi_object_types; + +void omapi_type_relinquish (void); +isc_result_t omapi_init (void); +isc_result_t omapi_object_type_register (omapi_object_type_t **, + const char *, + isc_result_t (*) + (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *), + isc_result_t (*) + (omapi_object_t *, + omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **), + isc_result_t (*) (omapi_object_t *, + const char *, int), + isc_result_t (*) (omapi_object_t *, + const char *, + va_list), + isc_result_t (*) (omapi_object_t *, + omapi_object_t *, + omapi_object_t *), + isc_result_t (*) (omapi_object_t **, + omapi_object_t *, + omapi_object_t *), + isc_result_t (*) (omapi_object_t **, + omapi_object_t *), + isc_result_t (*) (omapi_object_t *, + omapi_object_t *), + isc_result_t (*) (omapi_object_t *, + const char *, int), + isc_result_t (*) (omapi_object_t **, + const char *, int), + isc_result_t (*) (size_t), size_t, + isc_result_t (*) (omapi_object_t *, + const char *, int), + int); +isc_result_t omapi_signal (omapi_object_t *, const char *, ...); +isc_result_t omapi_signal_in (omapi_object_t *, const char *, ...); +isc_result_t omapi_set_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_typed_data_t *); +isc_result_t omapi_set_value_str (omapi_object_t *, omapi_object_t *, + const char *, omapi_typed_data_t *); +isc_result_t omapi_set_boolean_value (omapi_object_t *, omapi_object_t *, + const char *, int); +isc_result_t omapi_set_int_value (omapi_object_t *, omapi_object_t *, + const char *, int); +isc_result_t omapi_set_object_value (omapi_object_t *, omapi_object_t *, + const char *, omapi_object_t *); +isc_result_t omapi_set_string_value (omapi_object_t *, omapi_object_t *, + const char *, const char *); +isc_result_t omapi_get_value (omapi_object_t *, omapi_object_t *, + omapi_data_string_t *, + omapi_value_t **); +isc_result_t omapi_get_value_str (omapi_object_t *, omapi_object_t *, + const char *, omapi_value_t **); +isc_result_t omapi_stuff_values (omapi_object_t *, + omapi_object_t *, + omapi_object_t *); +isc_result_t omapi_object_create (omapi_object_t **, omapi_object_t *, + omapi_object_type_t *); +isc_result_t omapi_object_update (omapi_object_t *, omapi_object_t *, + omapi_object_t *, omapi_handle_t); +int omapi_data_string_cmp (omapi_data_string_t *, omapi_data_string_t *); +int omapi_ds_strcmp (omapi_data_string_t *, const char *); +int omapi_td_strcmp (omapi_typed_data_t *, const char *); +int omapi_td_strcasecmp (omapi_typed_data_t *, const char *); +isc_result_t omapi_make_value (omapi_value_t **, omapi_data_string_t *, + omapi_typed_data_t *, const char *, int); +isc_result_t omapi_make_const_value (omapi_value_t **, omapi_data_string_t *, + const unsigned char *, + unsigned, const char *, int); +isc_result_t omapi_make_int_value (omapi_value_t **, omapi_data_string_t *, + int, const char *, int); +isc_result_t omapi_make_uint_value (omapi_value_t **, omapi_data_string_t *, + unsigned int, const char *, int); +isc_result_t omapi_make_object_value (omapi_value_t **, omapi_data_string_t *, + omapi_object_t *, const char *, int); +isc_result_t omapi_make_handle_value (omapi_value_t **, omapi_data_string_t *, + omapi_object_t *, const char *, int); +isc_result_t omapi_make_string_value (omapi_value_t **, omapi_data_string_t *, + const char *, const char *, int); +isc_result_t omapi_get_int_value (unsigned long *, omapi_typed_data_t *); + +isc_result_t omapi_object_handle (omapi_handle_t *, omapi_object_t *); +isc_result_t omapi_handle_lookup (omapi_object_t **, omapi_handle_t); +isc_result_t omapi_handle_td_lookup (omapi_object_t **, omapi_typed_data_t *); + +void * dmalloc (unsigned, const char *, int); +void dfree (void *, const char *, int); +#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \ + defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) +void dmalloc_reuse (void *, const char *, int, int); +void dmalloc_dump_outstanding (void); +#else +#define dmalloc_reuse(x,y,l,z) +#endif +#define MDL __FILE__, __LINE__ +#if defined (DEBUG_RC_HISTORY) +void dump_rc_history (void *); +void rc_history_next (int); +#endif +void omapi_print_dmalloc_usage_by_caller (void); +isc_result_t omapi_object_allocate (omapi_object_t **, + omapi_object_type_t *, + size_t, const char *, int); +isc_result_t omapi_object_initialize (omapi_object_t *, + omapi_object_type_t *, + size_t, size_t, const char *, int); +isc_result_t omapi_object_reference (omapi_object_t **, + omapi_object_t *, const char *, int); +isc_result_t omapi_object_dereference (omapi_object_t **, const char *, int); +isc_result_t omapi_typed_data_new (const char *, int, omapi_typed_data_t **, + omapi_datatype_t, ...); +isc_result_t omapi_typed_data_reference (omapi_typed_data_t **, + omapi_typed_data_t *, + const char *, int); +isc_result_t omapi_typed_data_dereference (omapi_typed_data_t **, + const char *, int); +isc_result_t omapi_data_string_new (omapi_data_string_t **, + unsigned, const char *, int); +isc_result_t omapi_data_string_reference (omapi_data_string_t **, + omapi_data_string_t *, + const char *, int); +isc_result_t omapi_data_string_dereference (omapi_data_string_t **, + const char *, int); +isc_result_t omapi_value_new (omapi_value_t **, const char *, int); +isc_result_t omapi_value_reference (omapi_value_t **, + omapi_value_t *, const char *, int); +isc_result_t omapi_value_dereference (omapi_value_t **, const char *, int); +isc_result_t omapi_addr_list_new (omapi_addr_list_t **, unsigned, + const char *, int); +isc_result_t omapi_addr_list_reference (omapi_addr_list_t **, + omapi_addr_list_t *, + const char *, int); +isc_result_t omapi_addr_list_dereference (omapi_addr_list_t **, + const char *, int); + +isc_result_t omapi_array_allocate (omapi_array_t **, omapi_array_ref_t, + omapi_array_deref_t, const char *, int); +isc_result_t omapi_array_free (omapi_array_t **, const char *, int); +isc_result_t omapi_array_extend (omapi_array_t *, char *, int *, + const char *, int); +isc_result_t omapi_array_set (omapi_array_t *, void *, int, const char *, int); +isc_result_t omapi_array_lookup (char **, + omapi_array_t *, int, const char *, int); +OMAPI_ARRAY_TYPE_DECL(omapi_object, omapi_object_t); +#endif /* _OMAPIP_H_ */ diff --git a/includes/omapip/omapip_p.h b/includes/omapip/omapip_p.h new file mode 100644 index 0000000..788c91e --- /dev/null +++ b/includes/omapip/omapip_p.h @@ -0,0 +1,299 @@ +/* omapip_p.h + + Private master include file for the OMAPI library. */ + +/* + * Copyright (c) 2009-2010,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#ifndef __OMAPIP_OMAPIP_P_H__ +#define __OMAPIP_OMAPIP_P_H__ + +#ifndef __CYGWIN32__ +#include <sys/types.h> +#include <netinet/in.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <arpa/inet.h> + +#include <netdb.h> +#else +#define fd_set cygwin_fd_set +#include <sys/types.h> +#endif +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <memory.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <ctype.h> +#include <time.h> + +/* + * XXX: I'm not sure why these were here. +#include "cdefs.h" +#include "osdep.h" + */ + +#include <dst/dst.h> +#include "result.h" + +#include <omapip/convert.h> +#include <omapip/hash.h> +#include <omapip/omapip.h> +#include <omapip/trace.h> + +/* DST_API control flags */ +/* These are used in functions dst_sign_data and dst_verify_data */ +#define SIG_MODE_INIT 1 /* initalize digest */ +#define SIG_MODE_UPDATE 2 /* add data to digest */ +#define SIG_MODE_FINAL 4 /* generate/verify signature */ +#define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL) + +/* OMAPI protocol header, version 1.00 */ +typedef struct { + u_int32_t authlen; /* Length of authenticator. */ + u_int32_t authid; /* Authenticator object ID. */ + u_int32_t op; /* Opcode. */ + omapi_handle_t handle; /* Handle of object being operated on, + or zero. */ + u_int32_t id; /* Transaction ID. */ + u_int32_t rid; /* ID of transaction to which this is a response. */ +} omapi_protocol_header_t; + +#define OMAPI_PROTOCOL_VERSION 100 + +#define OMAPI_OP_OPEN 1 +#define OMAPI_OP_REFRESH 2 +#define OMAPI_OP_UPDATE 3 +#define OMAPI_OP_NOTIFY 4 +#define OMAPI_OP_STATUS 5 +#define OMAPI_OP_DELETE 6 + +typedef enum { + omapi_connection_unconnected, + omapi_connection_connecting, + omapi_connection_connected, + omapi_connection_disconnecting, + omapi_connection_closed +} omapi_connection_state_t; + +typedef enum { + omapi_protocol_intro_wait, + omapi_protocol_header_wait, + omapi_protocol_signature_wait, + omapi_protocol_name_wait, + omapi_protocol_name_length_wait, + omapi_protocol_value_wait, + omapi_protocol_value_length_wait +} omapi_protocol_state_t; + +typedef struct __omapi_message_object { + OMAPI_OBJECT_PREAMBLE; + struct __omapi_message_object *next, *prev; + omapi_object_t *object; + omapi_object_t *notify_object; + struct __omapi_protocol_object *protocol_object; + u_int32_t authlen; + omapi_typed_data_t *authenticator; + u_int32_t authid; + omapi_object_t *id_object; + u_int32_t op; + u_int32_t h; + u_int32_t id; + u_int32_t rid; +} omapi_message_object_t; + +typedef struct __omapi_remote_auth { + struct __omapi_remote_auth *next; + omapi_handle_t remote_handle; + omapi_object_t *a; +} omapi_remote_auth_t; + +typedef struct __omapi_protocol_object { + OMAPI_OBJECT_PREAMBLE; + u_int32_t header_size; + u_int32_t protocol_version; + u_int32_t next_xid; + + omapi_protocol_state_t state; /* Input state. */ + int reading_message_values; /* True if reading message-specific + values. */ + omapi_message_object_t *message; /* Incoming message. */ + omapi_data_string_t *name; /* Incoming name. */ + omapi_typed_data_t *value; /* Incoming value. */ + isc_result_t verify_result; + omapi_remote_auth_t *default_auth; /* Default authinfo to use. */ + omapi_remote_auth_t *remote_auth_list; /* Authenticators active on + this connection. */ + + isc_boolean_t insecure; /* Set to allow unauthenticated + messages. */ + + isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *); +} omapi_protocol_object_t; + +typedef struct { + OMAPI_OBJECT_PREAMBLE; + + isc_boolean_t insecure; /* Set to allow unauthenticated + messages. */ + + isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *); +} omapi_protocol_listener_object_t; + +#include <omapip/buffer.h> + +typedef struct __omapi_listener_object { + OMAPI_OBJECT_PREAMBLE; + int socket; /* Connection socket. */ + int index; + struct sockaddr_in address; + isc_result_t (*verify_addr) (omapi_object_t *, omapi_addr_t *); +} omapi_listener_object_t; + +typedef struct __omapi_connection_object { + OMAPI_OBJECT_PREAMBLE; + int socket; /* Connection socket. */ + int32_t index; + omapi_connection_state_t state; + struct sockaddr_in remote_addr; + struct sockaddr_in local_addr; + omapi_addr_list_t *connect_list; /* List of addresses to which + to connect. */ + int cptr; /* Current element we are connecting to. */ + u_int32_t bytes_needed; /* Bytes of input needed before wakeup. */ + u_int32_t in_bytes; /* Bytes of input already buffered. */ + omapi_buffer_t *inbufs; + u_int32_t out_bytes; /* Bytes of output in buffers. */ + omapi_buffer_t *outbufs; + omapi_listener_object_t *listener; /* Listener that accepted this + connection, if any. */ + dst_key_t *in_key; /* Authenticator signing incoming + data. */ + void *in_context; /* Input hash context. */ + dst_key_t *out_key; /* Authenticator signing outgoing + data. */ + void *out_context; /* Output hash context. */ +} omapi_connection_object_t; + +typedef struct __omapi_io_object { + OMAPI_OBJECT_PREAMBLE; + struct __omapi_io_object *next; + int (*readfd) (omapi_object_t *); + int (*writefd) (omapi_object_t *); + isc_result_t (*reader) (omapi_object_t *); + isc_result_t (*writer) (omapi_object_t *); + isc_result_t (*reaper) (omapi_object_t *); + isc_socket_t *fd; + isc_boolean_t closed; /* ISC_TRUE = closed, do not use */ +} omapi_io_object_t; + +typedef struct __omapi_generic_object { + OMAPI_OBJECT_PREAMBLE; + omapi_value_t **values; + u_int8_t *changed; + int nvalues, va_max; +} omapi_generic_object_t; + +typedef struct __omapi_waiter_object { + OMAPI_OBJECT_PREAMBLE; + int ready; + isc_result_t waitstatus; + struct __omapi_waiter_object *next; +} omapi_waiter_object_t; + +#define OMAPI_HANDLE_TABLE_SIZE 120 + +typedef struct __omapi_handle_table { + omapi_handle_t first, limit; + omapi_handle_t next; + int leafp; + union { + omapi_object_t *object; + struct __omapi_handle_table *table; + } children [OMAPI_HANDLE_TABLE_SIZE]; +} omapi_handle_table_t; + +#include <omapip/alloc.h> + +OMAPI_OBJECT_ALLOC_DECL (omapi_protocol, omapi_protocol_object_t, + omapi_type_protocol) +OMAPI_OBJECT_ALLOC_DECL (omapi_protocol_listener, + omapi_protocol_listener_object_t, + omapi_type_protocol_listener) +OMAPI_OBJECT_ALLOC_DECL (omapi_connection, + omapi_connection_object_t, omapi_type_connection) +OMAPI_OBJECT_ALLOC_DECL (omapi_listener, + omapi_listener_object_t, omapi_type_listener) +OMAPI_OBJECT_ALLOC_DECL (omapi_io, + omapi_io_object_t, omapi_type_io_object) +OMAPI_OBJECT_ALLOC_DECL (omapi_waiter, + omapi_waiter_object_t, omapi_type_waiter) +OMAPI_OBJECT_ALLOC_DECL (omapi_generic, + omapi_generic_object_t, omapi_type_generic) +OMAPI_OBJECT_ALLOC_DECL (omapi_message, + omapi_message_object_t, omapi_type_message) + +isc_result_t omapi_connection_sign_data (int mode, + dst_key_t *key, + void **context, + const unsigned char *data, + const unsigned len, + omapi_typed_data_t **result); +isc_result_t omapi_listener_connect (omapi_connection_object_t **obj, + omapi_listener_object_t *listener, + int socket, + struct sockaddr_in *remote_addr); +void omapi_listener_trace_setup (void); +void omapi_connection_trace_setup (void); +void omapi_buffer_trace_setup (void); +void omapi_connection_register (omapi_connection_object_t *, + const char *, int); +OMAPI_ARRAY_TYPE_DECL(omapi_listener, omapi_listener_object_t); +OMAPI_ARRAY_TYPE_DECL(omapi_connection, omapi_connection_object_t); + +isc_result_t omapi_handle_clear(omapi_handle_t); + +extern int log_perror; +extern void (*log_cleanup) (void); + +void log_fatal (const char *, ...) + __attribute__((__format__(__printf__,1,2))) ISC_DHCP_NORETURN; +int log_error (const char *, ...) + __attribute__((__format__(__printf__,1,2))); +int log_info (const char *, ...) + __attribute__((__format__(__printf__,1,2))); +int log_debug (const char *, ...) + __attribute__((__format__(__printf__,1,2))); +void do_percentm (char *obuf, const char *ibuf); + +isc_result_t uerr2isc (int); +isc_result_t ns_rcode_to_isc (int); + +extern omapi_message_object_t *omapi_registered_messages; + +#endif /* __OMAPIP_OMAPIP_P_H__ */ diff --git a/includes/omapip/result.h b/includes/omapip/result.h new file mode 100644 index 0000000..ae5f7d6 --- /dev/null +++ b/includes/omapip/result.h @@ -0,0 +1,121 @@ +/* result.h + */ + +/* + * Copyright (C) 2009,2014 Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + */ + +#ifndef DHCP_RESULT_H +#define DHCP_RESULT_H 1 + +#include <isc/lang.h> +#include <isc/resultclass.h> +#include <isc/types.h> + +#include <isc/result.h> + +/* + * DHCP result codes + */ + +/* + * In the previous code the results started at 36 + * rather than ISC_RESULTCLASS_DHCP + 0 + * ISC_R_NOTCONNECTED was + 4 (40), it has been superseded by the isc version + */ + +#define DHCP_R_HOSTUNKNOWN (ISC_RESULTCLASS_DHCP + 0) +#define DHCP_R_VERSIONMISMATCH (ISC_RESULTCLASS_DHCP + 1) +#define DHCP_R_PROTOCOLERROR (ISC_RESULTCLASS_DHCP + 2) +#define DHCP_R_INVALIDARG (ISC_RESULTCLASS_DHCP + 3) +#define DHCP_R_NOTYET (ISC_RESULTCLASS_DHCP + 4) +#define DHCP_R_UNCHANGED (ISC_RESULTCLASS_DHCP + 5) +#define DHCP_R_MULTIPLE (ISC_RESULTCLASS_DHCP + 6) +#define DHCP_R_KEYCONFLICT (ISC_RESULTCLASS_DHCP + 7) +#define DHCP_R_BADPARSE (ISC_RESULTCLASS_DHCP + 8) +#define DHCP_R_NOKEYS (ISC_RESULTCLASS_DHCP + 9) +#define DHCP_R_KEY_UNKNOWN (ISC_RESULTCLASS_DHCP + 10) +#define DHCP_R_INVALIDKEY (ISC_RESULTCLASS_DHCP + 11) +#define DHCP_R_INCOMPLETE (ISC_RESULTCLASS_DHCP + 12) +#define DHCP_R_FORMERR (ISC_RESULTCLASS_DHCP + 13) +#define DHCP_R_SERVFAIL (ISC_RESULTCLASS_DHCP + 14) +#define DHCP_R_NXDOMAIN (ISC_RESULTCLASS_DHCP + 15) +#define DHCP_R_NOTIMPL (ISC_RESULTCLASS_DHCP + 16) +#define DHCP_R_REFUSED (ISC_RESULTCLASS_DHCP + 17) +#define DHCP_R_YXDOMAIN (ISC_RESULTCLASS_DHCP + 18) +#define DHCP_R_YXRRSET (ISC_RESULTCLASS_DHCP + 19) +#define DHCP_R_NXRRSET (ISC_RESULTCLASS_DHCP + 20) +#define DHCP_R_NOTAUTH (ISC_RESULTCLASS_DHCP + 21) +#define DHCP_R_NOTZONE (ISC_RESULTCLASS_DHCP + 22) +#define DHCP_R_BADSIG (ISC_RESULTCLASS_DHCP + 23) +#define DHCP_R_BADKEY (ISC_RESULTCLASS_DHCP + 24) +#define DHCP_R_BADTIME (ISC_RESULTCLASS_DHCP + 25) +#define DHCP_R_NOROOTZONE (ISC_RESULTCLASS_DHCP + 26) +#define DHCP_R_DESTADDRREQ (ISC_RESULTCLASS_DHCP + 27) +#define DHCP_R_CROSSZONE (ISC_RESULTCLASS_DHCP + 28) +#define DHCP_R_NO_TSIG (ISC_RESULTCLASS_DHCP + 29) +#define DHCP_R_NOT_EQUAL (ISC_RESULTCLASS_DHCP + 30) +#define DHCP_R_CONNRESET (ISC_RESULTCLASS_DHCP + 31) +#define DHCP_R_UNKNOWNATTRIBUTE (ISC_RESULTCLASS_DHCP + 32) + +#define DHCP_R_NRESULTS 33 /*%< Number of results */ + +// Included for historical reasons, these should be removed as +// soon as reasonable +#ifdef INCLUDE_OLD_DHCP_ISC_ERROR_CODES +#define ISC_R_HOSTUNKNOWN DHCP_R_HOSTUNKNOWN +#define ISC_R_VERSIONMISMATCH DHCP_R_VERSIONMISMATCH +#define ISC_R_PROTOCOLERROR DHCP_R_PROTOCOLERROR +#define ISC_R_INVALIDARG DHCP_R_INVALIDARG +#define ISC_R_NOTYET DHCP_R_NOTYET +#define ISC_R_UNCHANGED DHCP_R_UNCHANGED +#define ISC_R_KEYCONFLICT DHCP_R_KEYCONFLICT +#define ISC_R_BADPARSE DHCP_R_BADPARSE +#define ISC_R_NOKEYS DHCP_R_NOKEYS +#define ISC_R_KEY_UNKNOWN DHCP_R_KEY_UNKNOWN +#define ISC_R_INVALIDKEY DHCP_R_INVALIDKEY +#define ISC_R_INCOMPLETE DHCP_R_INCOMPLETE +#define ISC_R_FORMERR DHCP_R_FORMERR +#define ISC_R_SERVFAIL DHCP_R_SERVFAIL +#define ISC_R_NXDOMAIN DHCP_R_NXDOMAIN +#define ISC_R_NOTIMPL DHCP_R_NOTIMPL +#define ISC_R_REFUSED DHCP_R_REFUSED +#define ISC_R_YXDOMAIN DHCP_R_YXDOMAIN +#define ISC_R_YXRRSET DHCP_R_YXRRSET +#define ISC_R_NXRRSET DHCP_R_NXRRSET +#define ISC_R_NOTAUTH DHCP_R_NOTAUTH +#define ISC_R_NOTZONE DHCP_R_NOTZONE +#define ISC_R_BADSIG DHCP_R_BADSIG +#define ISC_R_BADKEY DHCP_R_BADKEY +#define ISC_R_BADTIME DHCP_R_BADTIME +#define ISC_R_NOROOTZONE DHCP_R_NOROOTZONE +#define ISC_R_DESTADDRREQ DHCP_R_DESTADDRREQ +#define ISC_R_CROSSZONE DHCP_R_CROSSZONE +#define ISC_R_NO_TSIG DHCP_R_NO_TSIG +#define ISC_R_NOT_EQUAL DHCP_R_NOT_EQUAL +#define ISC_R_CONNRESET DHCP_R_CONNRESET +#define ISC_R_UNKNOWNATTRIBUTE DHCP_R_UNKNOWNATTRIBUTE +#endif + +isc_result_t +dhcp_result_register(void); + +#endif /* DHCP_RESULT_H */ diff --git a/includes/omapip/trace.h b/includes/omapip/trace.h new file mode 100644 index 0000000..d55587b --- /dev/null +++ b/includes/omapip/trace.h @@ -0,0 +1,111 @@ +/* trace.h + + Definitions for omapi tracing facility... */ + +/* + * Copyright (c) 2004,2005,2007,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2001-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#define TRACEFILE_MAGIC 0x64484370UL /* dHCp */ +#define TRACEFILE_VERSION 1 + +/* The first thing in a trace file is the header, which basically just + defines the version of the file. */ +typedef struct { + u_int32_t magic; /* Magic number for trace file. */ + u_int32_t version; /* Version of file. */ + int32_t hlen; /* Length of this header. */ + int32_t phlen; /* Length of packet headers. */ +} tracefile_header_t; + +/* The trace file is composed of a bunch of trace packets. Each such packet + has a type, followed by a length, followed by a timestamp, followed by + the actual contents of the packet. The type indexes are not fixed - + they are allocated either on readback or when writing a trace file. + One index type is reserved - type zero means that this record is a type + name to index mapping. */ +typedef struct { + u_int32_t type_index; /* Index to the type of handler that this + packet needs. */ + u_int32_t length; /* Length of the packet. This includes + everything except the fixed header. */ + u_int32_t when; /* When the packet was written. */ + u_int32_t pad; /* Round this out to a quad boundary. */ +} tracepacket_t; + +#define TRACE_INDEX_MAPPING_SIZE 4 /* trace_index_mapping_t less name. */ +typedef struct { + u_int32_t index; + char name [1]; +} trace_index_mapping_t; + +struct trace_type; /* forward */ +typedef struct trace_type trace_type_t; + +struct trace_type { + trace_type_t *next; + int index; + char *name; + void *baggage; + void (*have_packet) (trace_type_t *, unsigned, char *); + void (*stop_tracing) (trace_type_t *); +}; + +typedef struct trace_iov { + const char *buf; + unsigned len; +} trace_iov_t; + +typedef struct { + u_int16_t addrtype; + u_int16_t addrlen; + u_int8_t address [16]; + u_int16_t port; +} trace_addr_t; + +void trace_free_all (void); +int trace_playback (void); +int trace_record (void); +isc_result_t trace_init(void (*set_time)(time_t), const char *, int); +isc_result_t trace_begin (const char *, const char *, int); +isc_result_t trace_write_packet (trace_type_t *, unsigned, const char *, + const char *, int); +isc_result_t trace_write_packet_iov (trace_type_t *, int, trace_iov_t *, + const char *, int); +void trace_type_stash (trace_type_t *); +trace_type_t *trace_type_register (const char *, void *, + void (*) (trace_type_t *, + unsigned, char *), + void (*) (trace_type_t *), + const char *, int); +void trace_stop (void); +void trace_index_map_input (trace_type_t *, unsigned, char *); +void trace_index_stop_tracing (trace_type_t *); +void trace_replay_init (void); +void trace_file_replay (const char *); +isc_result_t trace_get_next_packet (trace_type_t **, tracepacket_t *, + char **, unsigned *, unsigned *); +isc_result_t trace_get_file (trace_type_t *, + const char *, unsigned *, char **); +isc_result_t trace_get_packet (trace_type_t **, unsigned *, char **); +time_t trace_snoop_time (trace_type_t **); diff --git a/includes/osdep.h b/includes/osdep.h new file mode 100644 index 0000000..0d1c05d --- /dev/null +++ b/includes/osdep.h @@ -0,0 +1,287 @@ +/* osdep.h + + Operating system dependencies... */ + +/* + * Copyright (c) 2004-2005,2007-2010,2014 by Internet Systems Consortium, + * Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +#if !defined (__ISC_DHCP_OSDEP_H__) +#define __ISC_DHCP_OSDEP_H__ + +#include "site.h" + +#include "config.h" + +#include <inttypes.h> + +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1234 +#endif /* LITTLE_ENDIAN */ + +#ifndef BIG_ENDIAN +#define BIG_ENDIAN 4321 +#endif /* BIG_ENDIAN */ + +#ifndef BYTE_ORDER +#define BYTE_ORDER DHCP_BYTE_ORDER +#endif /* BYTE_ORDER */ + +/* Porting:: + + If you add a new network API, you must add a check for it below: */ + +#if !defined (USE_SOCKETS) && \ + !defined (USE_SOCKET_SEND) && \ + !defined (USE_SOCKET_RECEIVE) && \ + !defined (USE_RAW_SOCKETS) && \ + !defined (USE_RAW_SEND) && \ + !defined (USE_SOCKET_RECEIVE) && \ + !defined (USE_BPF) && \ + !defined (USE_BPF_SEND) && \ + !defined (USE_BPF_RECEIVE) && \ + !defined (USE_LPF) && \ + !defined (USE_LPF_SEND) && \ + !defined (USE_LPF_RECEIVE) && \ + !defined (USE_NIT) && \ + !defined (USE_NIT_SEND) && \ + !defined (USE_NIT_RECEIVE) && \ + !defined (USE_DLPI_SEND) && \ + !defined (USE_DLPI_RECEIVE) +/* Determine default socket API to USE. */ +# if defined(HAVE_BPF) +# define USE_BPF 1 +# elif defined(HAVE_LPF) +# define USE_LPF 1 +# elif defined(HAVE_DLPI) +# define USE_DLPI 1 +# endif +#endif + +#if !defined (TIME_MAX) +# define TIME_MAX 2147483647 +#endif + +/* snprintf/vsnprintf hacks. for systems with no libc versions only. */ +#ifdef NO_SNPRINTF + extern int isc_print_snprintf(char *, size_t, const char *, ...); + extern int isc_print_vsnprintf(char *, size_t, const char *, va_list ap); +# define snprintf isc_print_snprintf +# define vsnprintf isc_print_vsnprintf +#endif + +/* Porting:: + + If you add a new network API, and have it set up so that it can be + used for sending or receiving, but doesn't have to be used for both, + then set up an ifdef like the ones below: */ + +#ifdef USE_SOCKETS +# define USE_SOCKET_SEND +# define USE_SOCKET_RECEIVE +# if defined(HAVE_DLPI) +# define USE_DLPI_HWADDR +# endif +#endif + +#ifdef USE_RAW_SOCKETS +# define USE_RAW_SEND +# define USE_SOCKET_RECEIVE +#endif + +#ifdef USE_BPF +# define USE_BPF_SEND +# define USE_BPF_RECEIVE +#endif + +#ifdef USE_LPF +# define USE_LPF_SEND +# define USE_LPF_RECEIVE +#endif + +#ifdef USE_NIT +# define USE_NIT_SEND +# define USE_NIT_RECEIVE +#endif + +#ifdef USE_DLPI +# define USE_DLPI_SEND +# define USE_DLPI_RECEIVE +#endif + +#ifdef USE_UPF +# define USE_UPF_SEND +# define USE_UPF_RECEIVE +#endif + +/* Porting:: + + If you add support for sending packets directly out an interface, + and your support does not do ARP or routing, you must use a fallback + mechanism to deal with packets that need to be sent to routers. + Currently, all low-level packet interfaces use BSD sockets as a + fallback. */ + +#if defined (USE_BPF_SEND) || defined (USE_NIT_SEND) || \ + defined (USE_DLPI_SEND) || defined (USE_UPF_SEND) || \ + defined (USE_LPF_SEND) || \ + (defined (USE_SOCKET_SEND) && defined (HAVE_SO_BINDTODEVICE)) +# define USE_SOCKET_FALLBACK +# define USE_FALLBACK +#endif + +/* Porting:: + + If you add support for sending packets directly out an interface + and need to be able to assemble packets, add the USE_XXX_SEND + definition for your interface to the list tested below. */ + +#if defined (USE_RAW_SEND) || defined (USE_BPF_SEND) || \ + defined (USE_NIT_SEND) || defined (USE_UPF_SEND) || \ + defined (USE_DLPI_SEND) || defined (USE_LPF_SEND) +# define PACKET_ASSEMBLY +#endif + +/* Porting:: + + If you add support for receiving packets directly from an interface + and need to be able to decode raw packets, add the USE_XXX_RECEIVE + definition for your interface to the list tested below. */ + +#if defined (USE_RAW_RECEIVE) || defined (USE_BPF_SEND) || \ + defined (USE_NIT_RECEIVE) || defined (USE_UPF_RECEIVE) || \ + defined (USE_DLPI_RECEIVE) || defined (USE_LPF_RECEIVE) +# define PACKET_DECODING +#endif + +/* If we don't have a DLPI packet filter, we have to filter in userland. + Probably not worth doing, actually. */ +#if defined (USE_DLPI_RECEIVE) && !defined (USE_DLPI_PFMOD) +# define USERLAND_FILTER +#endif + +/* jmp_buf is assumed to be a struct unless otherwise defined in the + system header. */ +#ifndef jbp_decl +# define jbp_decl(x) jmp_buf *x +#endif +#ifndef jref +# define jref(x) (&(x)) +#endif +#ifndef jdref +# define jdref(x) (*(x)) +#endif +#ifndef jrefproto +# define jrefproto jmp_buf * +#endif + +#ifndef BPF_FORMAT +# define BPF_FORMAT "/dev/bpf%d" +#endif + +#if defined (F_SETFD) && !defined (HAVE_SETFD) +# define HAVE_SETFD +#endif + +#if defined (IFF_POINTOPOINT) && !defined (HAVE_IFF_POINTOPOINT) +# define HAVE_IFF_POINTOPOINT +#endif + +#if defined (AF_LINK) && !defined (HAVE_AF_LINK) +# define HAVE_AF_LINK +#endif + +#if defined (ARPHRD_TUNNEL) && !defined (HAVE_ARPHRD_TUNNEL) +# define HAVE_ARPHRD_TUNNEL +#endif + +#if defined (ARPHRD_LOOPBACK) && !defined (HAVE_ARPHRD_LOOPBACK) +# define HAVE_ARPHRD_LOOPBACK +#endif + +#if defined (ARPHRD_ROSE) && !defined (HAVE_ARPHRD_ROSE) +# define HAVE_ARPHRD_ROSE +#endif + +#if defined (ARPHRD_IRDA) && !defined (HAVE_ARPHRD_IRDA) +# define HAVE_ARPHRD_IRDA +#endif + +#if defined (ARPHRD_SIT) && !defined (HAVE_ARPHRD_SIT) +# define HAVE_ARPHRD_SIT +#endif + +#if defined (ARPHRD_IEEE1394) & !defined (HAVE_ARPHRD_IEEE1394) +# define HAVE_ARPHRD_IEEE1394 +#endif + +#if defined (ARPHRD_IEEE802) && !defined (HAVE_ARPHRD_IEEE802) +# define HAVE_ARPHRD_IEEE802 +#endif + +#if defined (ARPHRD_IEEE802_TR) && !defined (HAVE_ARPHRD_IEEE802_TR) +# define HAVE_ARPHRD_IEEE802_TR +#endif + +#if defined (ARPHRD_FDDI) && !defined (HAVE_ARPHRD_FDDI) +# define HAVE_ARPHRD_FDDI +#endif + +#if defined (ARPHRD_AX25) && !defined (HAVE_ARPHRD_AX25) +# define HAVE_ARPHRD_AX25 +#endif + +#if defined (ARPHRD_NETROM) && !defined (HAVE_ARPHRD_NETROM) +# define HAVE_ARPHRD_NETROM +#endif + +#if defined (ARPHRD_METRICOM) && !defined (HAVE_ARPHRD_METRICOM) +# define HAVE_ARPHRD_METRICOM +#endif + +#if defined (SO_BINDTODEVICE) && !defined (HAVE_SO_BINDTODEVICE) +# define HAVE_SO_BINDTODEVICE +#endif + +#if defined (AF_LINK) && !defined (HAVE_AF_LINK) +# define HAVE_AF_LINK +#endif + +/* Linux needs to define SHUT_* in /usr/include/sys/socket.h someday... */ +#if !defined (SHUT_RD) +# define SHUT_RD 0 +#endif + +#if !defined (SOCKLEN_T) +# define SOCKLEN_T socklen_t +#elif defined(_AIX) +#undef SOCKLEN_T +#define SOCKLEN_T socklen_t +#endif + +#if !defined (STDERR_FILENO) +# define STDERR_FILENO 2 +#endif + +#endif /* __ISC_DHCP_OSDEP_H__ */ diff --git a/includes/site.h b/includes/site.h new file mode 100644 index 0000000..a8264ab --- /dev/null +++ b/includes/site.h @@ -0,0 +1,320 @@ +/* Site-specific definitions. + + For supported systems, you shouldn't need to make any changes here. + However, you may want to, in order to deal with site-specific + differences. */ + +/* Add any site-specific definitions and inclusions here... */ + +/* #include <site-foo-bar.h> */ +/* #define SITE_FOOBAR */ + +/* Define this if you don't want dhcpd to run as a daemon and do want + to see all its output printed to stdout instead of being logged via + syslog(). This also makes dhcpd use the dhcpd.conf in its working + directory and write the dhcpd.leases file there. */ + +/* #define DEBUG */ + +/* Define this to see what the parser is parsing. You probably don't + want to see this. */ + +/* #define DEBUG_TOKENS */ + +/* Define this to see dumps of incoming and outgoing packets. This + slows things down quite a bit... */ + +/* #define DEBUG_PACKET */ + +/* Define this if you want to see dumps of expression evaluation. */ + +/* #define DEBUG_EXPRESSIONS */ + +/* Define this if you want to see dumps of find_lease() in action. */ + +/* #define DEBUG_FIND_LEASE */ + +/* Define this if you want to see dumps of parsed expressions. */ + +/* #define DEBUG_EXPRESSION_PARSE */ + +/* Define this if you want to watch the class matching process. */ + +/* #define DEBUG_CLASS_MATCHING */ + +/* Define this if you want to track memory usage for the purpose of + noticing memory leaks quickly. */ + +/* #define DEBUG_MEMORY_LEAKAGE */ +/* #define DEBUG_MEMORY_LEAKAGE_ON_EXIT */ + +/* Define this if you want exhaustive (and very slow) checking of the + malloc pool for corruption. */ + +/* #define DEBUG_MALLOC_POOL */ + +/* Define this if you want to see a message every time a lease's state + changes. */ +/* #define DEBUG_LEASE_STATE_TRANSITIONS */ + +/* Define this if you want to maintain a history of the last N operations + that changed reference counts on objects. This can be used to debug + cases where an object is dereferenced too often, or not often enough. */ + +/* #define DEBUG_RC_HISTORY */ + +/* Define this if you want to see the history every cycle. */ + +/* #define DEBUG_RC_HISTORY_EXHAUSTIVELY */ + +/* This is the number of history entries to maintain - by default, 256. */ + +/* #define RC_HISTORY_MAX 10240 */ + +/* Define this if you want dhcpd to dump core when a non-fatal memory + allocation error is detected (i.e., something that would cause a + memory leak rather than a memory smash). */ + +/* #define POINTER_DEBUG */ + +/* Define this if you want debugging output for DHCP failover protocol + messages. */ + +/* #define DEBUG_FAILOVER_MESSAGES */ + +/* Define this to include contact messages in failover message debugging. + The contact messages are sent once per second, so this can generate a + lot of log entries. */ + +/* #define DEBUG_FAILOVER_CONTACT_MESSAGES */ + +/* Define this if you want debugging output for DHCP failover protocol + event timeout timing. */ + +/* #define DEBUG_FAILOVER_TIMING */ + +/* Define this if you want to include contact message timing, which is + performed once per second and can generate a lot of log entries. */ + +/* #define DEBUG_FAILOVER_CONTACT_TIMING */ + +/* Define this if you want all leases written to the lease file, even if + they are free leases that have never been used. */ + +/* #define DEBUG_DUMP_ALL_LEASES */ + +/* Define this if you want to see the requests and replies between the + DHCP code and the DNS library code. */ + +/* #define DEBUG_DNS_UPDATES */ + +/* Define this if you want DHCP failover protocol support in the DHCP + server. */ + +/* #define FAILOVER_PROTOCOL */ + +/* Define this if you want DNS update functionality to be available. */ + +#define NSUPDATE + +/* Define this if you want the dhcpd.pid file to go somewhere other than + the default (which varies from system to system, but is usually either + /etc or /var/run. */ + +/* #define _PATH_DHCPD_PID "/var/run/dhcpd.pid" */ + +/* Define this if you want the dhcpd.leases file (the dynamic lease database) + to go somewhere other than the default location, which is normally + /etc/dhcpd.leases. */ + +/* #define _PATH_DHCPD_DB "/etc/dhcpd.leases" */ + +/* Define this if you want the dhcpd.conf file to go somewhere other than + the default location. By default, it goes in /etc/dhcpd.conf. */ + +/* #define _PATH_DHCPD_CONF "/etc/dhcpd.conf" */ + +/* Network API definitions. You do not need to choose one of these - if + you don't choose, one will be chosen for you in your system's config + header. DON'T MESS WITH THIS UNLESS YOU KNOW WHAT YOU'RE DOING!!! */ + +/* Define USE_SOCKETS to use the standard BSD socket API. + + On many systems, the BSD socket API does not provide the ability to + send packets to the 255.255.255.255 broadcast address, which can + prevent some clients (e.g., Win95) from seeing replies. This is + not a problem on Solaris. + + In addition, the BSD socket API will not work when more than one + network interface is configured on the server. + + However, the BSD socket API is about as efficient as you can get, so if + the aforementioned problems do not matter to you, or if no other + API is supported for your system, you may want to go with it. */ + +/* #define USE_SOCKETS */ + +/* Define this to use the Sun Streams NIT API. + + The Sun Streams NIT API is only supported on SunOS 4.x releases. */ + +/* #define USE_NIT */ + +/* Define this to use the Berkeley Packet Filter API. + + The BPF API is available on all 4.4-BSD derivatives, including + NetBSD, FreeBSD and BSDI's BSD/OS. It's also available on + DEC Alpha OSF/1 in a compatibility mode supported by the Alpha OSF/1 + packetfilter interface. */ + +/* #define USE_BPF */ + +/* Define this to use the raw socket API. + + The raw socket API is provided on many BSD derivatives, and provides + a way to send out raw IP packets. It is only supported for sending + packets - packets must be received with the regular socket API. + This code is experimental - I've never gotten it to actually transmit + a packet to the 255.255.255.255 broadcast address - so use it at your + own risk. */ + +/* #define USE_RAW_SOCKETS */ + +/* Define this to change the logging facility used by dhcpd. */ + +/* #define DHCPD_LOG_FACILITY LOG_DAEMON */ + + +/* Define this if you want to be able to execute external commands + during conditional evaluation. */ + +/* #define ENABLE_EXECUTE */ + +/* Define this if you aren't debugging and you want to save memory + (potentially a _lot_ of memory) by allocating leases in chunks rather + than one at a time. */ + +#define COMPACT_LEASES + +/* Define this if you want to be able to save and playback server operational + traces. */ + +/* #define TRACING */ + +/* Define this if you want the server to use the previous behavior + when determining the DDNS TTL. If the user has specified a ddns-ttl + option that is used to detemine the ttl. (If the user specifies + an option that references the lease structure it is only usable + for v4. In that case v6 will use the default.) Otherwise when + defined the defaults are: v4 - 1/2 the lease time, + v6 - DEFAULT_DDNS_TTL. When undefined the defaults are 1/2 the + (preferred) lease time for both but with a cap on the maximum. */ + +/* #define USE_OLD_DDNS_TTL */ + +/* Define this if you want a DHCPv6 server to send replies to the + source port of the message it received. This is useful for testing + but is only included for backwards compatibility. */ +/* #define REPLY_TO_SOURCE_PORT */ + +/* Define this if you want to enable strict checks in DNS Updates mechanism. + Do not enable this unless are DHCP developer. */ +/* #define DNS_UPDATES_MEMORY_CHECKS */ + +/* Define this if you want to allow domain list in domain-name option. + RFC2132 does not allow that behavior, but it is somewhat used due + to historic reasons. Note that it may be removed some time in the + future. */ + +#define ACCEPT_LIST_IN_DOMAIN_NAME + +/* In RFC3315 section 17.2.2 stated that if the server was not going + to be able to assign any addresses to any IAs in a subsequent Request + from a client that the server should not include any IAs. This + requirement was removed in an errata from August 2010. Define the + following if you want the pre-errata version. + You should only enable this option if you have clients that + require the original functionality. */ + +/* #define RFC3315_PRE_ERRATA_2010_08 */ + +/* In previous versions of the code when the server generates a NAK + it doesn't attempt to determine if the configuration included a + server ID for that client. Defining this option causes the server + to make a modest effort to determine the server id when building + a NAK as a response. This effort will only check the first subnet + and pool associated with a shared subnet and will not check for + host declarations. With some configurations the server id + computed for a NAK may not match that computed for an ACK. */ + +/* #define SERVER_ID_FOR_NAK */ + +/* When processing a request do a simple check to compare the + server id the client sent with the one the server would send. + In order to minimize the complexity of the code the server + only checks for a server id option in the global and subnet + scopes. Complicated configurations may result in differnet + server ids for this check and when the server id for a reply + packet is determined, which would prohibit the server from + responding. + + The primary use for this option is when a client broadcasts + a request but requires the response to come from one of the + failover peers. An example of this would be when a client + reboots while its lease is still active - in this case both + servers will normally respond. Most of the time the client + won't check the server id and can use either of the responses. + However if the client does check the server id it may reject + the response if it came from the wrong peer. If the timing + is such that the "wrong" peer responds first most of the time + the client may not get an address for some time. + + Currently this option is only available when failover is in + use. + + Care should be taken before enabling this option. */ + +/* #define SERVER_ID_CHECK */ + +/* In the v6 server code log the addresses as they are assigned + to make it easier for an admin to see what has beend done. + This default to off to avoid changes to what is currently + logged. */ + +/* #define LOG_V6_ADDRESSES */ + +/* Define the default prefix length passed from the client to + the script when modifying an IPv6 IA_NA or IA_TA address. + The two most useful values are 128 which is what the current + specifications call for or 64 which is what has been used in + the past. For most OSes 128 will indicate that the address + is a host address and doesn't include any on-link information. + 64 indicates that the first 64 bits are the subnet or on-link + prefix. */ +#define DHCLIENT_DEFAULT_PREFIX_LEN 64 + +/* Enable the gentle shutdown signal handling. Currently this + means that on SIGINT or SIGTERM a client will release its + address and a server in a failover pair will go through + partner down. Both of which can be undesireable in some + situations. We plan to revisit this feature and may + make non-backwards compatible changes including the + removal of this define. Use at your own risk. */ +/* #define ENABLE_GENTLE_SHUTDOWN */ + +/* Include old error codes. This is provided in case you + are building an external program similar to omshell for + which you need the ISC_R_* error codes. You should switch + to DHCP_R_* error codes for those that have been defined + (see includes/omapip/result.h). The extra defines and + this option will be removed at some time. */ +/* #define INCLUDE_OLD_DHCP_ISC_ERROR_CODES */ + +/* Enable conversion at startup of leases from FTS_BACKUP to FTS_FREE + when either their pool has no configured failover peer or + FAILOVER_PROTOCOL is not enabled. This allows the leases to be + reclaimed by the server after a pool's configuration has changed + from failover to standalone. Prior to this such leases would remain + stuck in the backup state. */ +/* #define CONVERT_BACKUP_TO_FREE */ + diff --git a/includes/statement.h b/includes/statement.h new file mode 100644 index 0000000..3acdd79 --- /dev/null +++ b/includes/statement.h @@ -0,0 +1,104 @@ +/* statement.h + + Definitions for executable statements... */ + +/* + * Copyright (c) 2004,2007,2009,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +struct executable_statement { + int refcnt; + struct executable_statement *next; + enum statement_op { + null_statement, + if_statement, + add_statement, + eval_statement, + break_statement, + default_option_statement, + supersede_option_statement, + append_option_statement, + prepend_option_statement, + send_option_statement, + statements_statement, + on_statement, + switch_statement, + case_statement, + default_statement, + set_statement, + unset_statement, + let_statement, + define_statement, + log_statement, + return_statement, + execute_statement + } op; + union { + struct { + struct executable_statement *tc, *fc; + struct expression *expr; + } ie; + struct expression *eval; + struct expression *retval; + struct class *add; + struct option_cache *option; + struct option_cache *supersede; + struct option_cache *prepend; + struct option_cache *append; + struct executable_statement *statements; + struct { + int evtypes; +# define ON_COMMIT 1 +# define ON_EXPIRY 2 +# define ON_RELEASE 4 +# define ON_TRANSMISSION 8 + struct executable_statement *statements; + } on; + struct { + struct expression *expr; + struct executable_statement *statements; + } s_switch; + struct expression *c_case; + struct { + char *name; + struct expression *expr; + struct executable_statement *statements; + } set, let; + char *unset; + struct { + enum { + log_priority_fatal, + log_priority_error, + log_priority_debug, + log_priority_info + } priority; + struct expression *expr; + } log; + struct { + char *command; + struct expression *arglist; + int argc; + } execute; + } data; +}; + diff --git a/includes/t_api.h b/includes/t_api.h new file mode 100644 index 0000000..e22bb83 --- /dev/null +++ b/includes/t_api.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2004-2007,2009 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC 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: t_api.h,v 1.3.8.1 2009/11/20 01:49:01 sar Exp $ */ + +#ifndef TESTS_T_API_H +#define TESTS_T_API_H 1 + +/*! \file tests/t_api.h */ + +#include <stdio.h> + +#include <omapip/result.h> +#include <isc/lang.h> +#include <isc/formatcheck.h> + +/* + * + * Result codes. + * + */ + +#define T_PASS 0x1 +#define T_FAIL 0x2 +#define T_UNRESOLVED 0x3 +#define T_UNSUPPORTED 0x4 +#define T_UNTESTED 0x5 +#define T_THREADONLY 0x6 + +/* + * + * Assertion class codes. + * + */ + +#define T_OPTIONAL 0x0 +#define T_REQUIRED 0x1 + +/* + * Misc + */ + +#define T_MAXTOKS 16 +#define T_ARG(n) (*(av + (n))) + +typedef void (*PFV)(void); + +typedef struct { + PFV pfv; + const char *func_name; +} testspec_t; + +extern int T_debug; +extern testspec_t T_testlist[]; + +ISC_LANG_BEGINDECLS + +void +t_assert(const char *component, int anum, int class, const char *what, ...) + ISC_FORMAT_PRINTF(4, 5); + +void +t_info(const char *format, ...) ISC_FORMAT_PRINTF(1, 2); + +void +t_result(int result); + +char * +t_getenv(const char *name); + +char * +t_fgetbs(FILE *fp); + +isc_result_t +t_dns_result_fromtext(char *result); + +unsigned int +t_dc_method_fromtext(char *dc_method); + +int +t_bustline(char *line, char **toks); + +int +t_eval(const char *filename, int (*func)(char **), int nargs); + +ISC_LANG_ENDDECLS + +#endif /* TESTS_T_API_H */ + diff --git a/includes/tree.h b/includes/tree.h new file mode 100644 index 0000000..332e6b6 --- /dev/null +++ b/includes/tree.h @@ -0,0 +1,350 @@ +/* tree.h + + Definitions for address trees... */ + +/* + * Copyright (c) 2011,2013,2014 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004,2007-2009 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-2003 by 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 ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. + * + * Internet Systems Consortium, Inc. + * 950 Charter Street + * Redwood City, CA 94063 + * <info@isc.org> + * https://www.isc.org/ + * + */ + +/* A pair of pointers, suitable for making a linked list. */ +typedef struct _pair { + caddr_t car; + struct _pair *cdr; +} *pair; + +struct option_chain_head { + int refcnt; + pair first; +}; + +struct enumeration_value { + const char *name; + u_int8_t value; +}; + +struct enumeration { + struct enumeration *next; + const char *name; + unsigned width; + struct enumeration_value *values; +}; + +/* Tree node types... */ +#define TREE_CONCAT 1 +#define TREE_HOST_LOOKUP 2 +#define TREE_CONST 3 +#define TREE_LIMIT 4 +#define TREE_DATA_EXPR 5 + +/* A data buffer with a reference count. */ +struct buffer { + int refcnt; + unsigned char data [1]; +}; + +/* XXX The mechanism by which data strings are returned is currently + XXX broken: rather than returning an ephemeral pointer, we create + XXX a reference to the data in the caller's space, which the caller + XXX then has to dereference - instead, the reference should be + XXX ephemeral by default and be made a persistent reference explicitly. */ +/* XXX on the other hand, it seems to work pretty nicely, so maybe the + XXX above comment is meshuggenah. */ +/* XXX I think the above comment tries to say this: + XXX http://tinyurl.com/2tjqre */ + +/* A string of data bytes, possibly accompanied by a larger buffer. */ +struct data_string { + struct buffer *buffer; + const unsigned char *data; + unsigned len; /* Does not include NUL terminator, if any. */ + int terminated; +}; + +enum expression_context { + context_any, /* indefinite */ + context_boolean, + context_data, + context_numeric, + context_dns, + context_data_or_numeric, /* indefinite */ + context_function +}; + +struct fundef { + int refcnt; + struct string_list *args; + struct executable_statement *statements; +}; + +struct binding_value { + int refcnt; + enum { + binding_boolean, + binding_data, + binding_numeric, + binding_dns, + binding_function + } type; + union value { + struct data_string data; + unsigned long intval; + int boolean; +#if defined (NSUPDATE_OLD) + ns_updrec *dns; +#endif + struct fundef *fundef; + struct binding_value *bv; + } value; +}; + +struct binding { + struct binding *next; + char *name; + struct binding_value *value; +}; + +struct binding_scope { + int refcnt; + struct binding_scope *outer; + struct binding *bindings; +}; + +/* Expression tree structure. */ + +enum expr_op { + expr_none, + expr_match, + expr_check, + expr_equal, + expr_substring, + expr_suffix, + expr_concat, + expr_host_lookup, + expr_and, + expr_or, + expr_not, + expr_option, + expr_hardware, + expr_packet, + expr_const_data, + expr_extract_int8, + expr_extract_int16, + expr_extract_int32, + expr_encode_int8, + expr_encode_int16, + expr_encode_int32, + expr_const_int, + expr_exists, + expr_encapsulate, + expr_known, + expr_reverse, + expr_leased_address, + expr_binary_to_ascii, + expr_config_option, + expr_host_decl_name, + expr_pick_first_value, + expr_lease_time, + expr_dns_transaction, + expr_static, + expr_ns_add, + expr_ns_delete, + expr_ns_exists, + expr_ns_not_exists, + expr_not_equal, + expr_null, + expr_variable_exists, + expr_variable_reference, + expr_filename, + expr_sname, + expr_arg, + expr_funcall, + expr_function, + expr_add, + expr_subtract, + expr_multiply, + expr_divide, + expr_remainder, + expr_binary_and, + expr_binary_or, + expr_binary_xor, + expr_client_state, + expr_ucase, + expr_lcase, + expr_regex_match, + expr_iregex_match, + expr_gethostname, + expr_concat_dclist +}; + +struct expression { + int refcnt; + enum expr_op op; + union expr_union { + struct { + struct expression *expr; + struct expression *offset; + struct expression *len; + } substring; + struct expression *equal [2]; + struct expression *and [2]; + struct expression *or [2]; + struct expression *not; + struct expression *add; + struct expression *subtract; + struct expression *multiply; + struct expression *divide; + struct expression *remainder; + struct collection *check; + struct { + struct expression *expr; + struct expression *len; + } suffix; + struct expression *lcase; + struct expression *ucase; + struct option *option; + struct option *config_option; + struct { + struct expression *offset; + struct expression *len; + } packet; + struct data_string const_data; + struct expression *extract_int; + struct expression *encode_int; + unsigned long const_int; + struct expression *concat [2]; + struct dns_host_entry *host_lookup; + struct option *exists; + struct data_string encapsulate; + struct { + struct expression *base; + struct expression *width; + struct expression *separator; + struct expression *buffer; + } b2a; + struct { + struct expression *width; + struct expression *buffer; + } reverse; + struct { + struct expression *car; + struct expression *cdr; + } pick_first_value; + struct { + struct expression *car; + struct expression *cdr; + } dns_transaction; + struct { + unsigned rrclass; + unsigned rrtype; + struct expression *rrname; + struct expression *rrdata; + struct expression *ttl; + } ns_add; + struct { + unsigned rrclass; + unsigned rrtype; + struct expression *rrname; + struct expression *rrdata; + } ns_delete, ns_exists, ns_not_exists; + char *variable; + struct { + struct expression *val; + struct expression *next; + } arg; + struct { + char *name; + struct expression *arglist; + } funcall; + struct fundef *func; + } data; + int flags; +# define EXPR_EPHEMERAL 1 +}; + +/* DNS host entry structure... */ +struct dns_host_entry { + int refcnt; + TIME timeout; + struct data_string data; + char hostname [1]; +}; + +struct option_cache; /* forward */ +struct packet; /* forward */ +struct option_state; /* forward */ +struct decoded_option_state; /* forward */ +struct lease; /* forward */ +struct client_state; /* forward */ + +struct universe { + const char *name; + struct option_cache *(*lookup_func) (struct universe *, + struct option_state *, + unsigned); + void (*save_func) (struct universe *, struct option_state *, + struct option_cache *, isc_boolean_t); + void (*foreach) (struct packet *, + struct lease *, struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, struct universe *, void *, + void (*) (struct option_cache *, struct packet *, + struct lease *, struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *, void *)); + void (*delete_func) (struct universe *universe, + struct option_state *, int); + int (*option_state_dereference) (struct universe *, + struct option_state *, + const char *, int); + int (*decode) (struct option_state *, + const unsigned char *, unsigned, struct universe *); + int (*encapsulate) (struct data_string *, struct packet *, + struct lease *, struct client_state *, + struct option_state *, struct option_state *, + struct binding_scope **, + struct universe *); + u_int32_t (*get_tag) (const unsigned char *); + void (*store_tag) (unsigned char *, u_int32_t); + u_int32_t (*get_length) (const unsigned char *); + void (*store_length) (unsigned char *, u_int32_t); + int tag_size, length_size; + unsigned site_code_min, end; + option_name_hash_t *name_hash; + option_code_hash_t *code_hash; + struct option *enc_opt; + int index; + + /* Flags should probably become condensed. */ + int concat_duplicates; +}; + +struct option { + const char *name; + const char *format; + struct universe *universe; + unsigned code; + int refcnt; +}; |