2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

[master] add libns and remove liblwres

4708.   [cleanup]       Legacy Windows builds (i.e. for XP and earlier)
                        are no longer supported. [RT #45186]

4707.	[func]		The lightweight resolver daemon and library (lwresd
			and liblwres) have been removed. [RT #45186]

4706.	[func]		Code implementing name server query processing has
			been moved from bin/named to a new library "libns".
			Functions remaining in bin/named are now prefixed
			with "named_" rather than "ns_".  This will make it
			easier to write unit tests for name server code, or
			link name server functionality into new tools.
			[RT #45186]
This commit is contained in:
Evan Hunt
2017-09-08 13:39:09 -07:00
parent 60387eb495
commit 8eb88aafee
567 changed files with 7123 additions and 85013 deletions

5
lib/ns/Atffile Normal file
View File

@@ -0,0 +1,5 @@
Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = bind9
tp: tests

91
lib/ns/Makefile.in Normal file
View File

@@ -0,0 +1,91 @@
# Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
# Attempt to disable parallel processing.
.NOTPARALLEL:
.NO_PARALLEL:
VERSION=@BIND9_VERSION@
@BIND9_MAJOR@
@LIBNS_API@
@BIND9_MAKE_INCLUDES@
USE_ISC_SPNEGO = @USE_ISC_SPNEGO@
CINCLUDES = -I. -I${top_srcdir}/lib/ns -Iinclude \
${NS_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES} \
@DST_OPENSSL_INC@ @DST_GSSAPI_INC@
CDEFINES =
CWARNINGS =
ISCLIBS = ../../lib/isc/libisc.@A@
ISCDEPLIBS = ../../lib/isc/libisc.@A@
DNSLIBS = ../../lib/dns/libdns.@A@
DNSDEPLIBS = ../../lib/dns/libdns.@A@
LIBS = @LIBS@
# Alphabetically
OBJS = client.@O@ interfacemgr.@O@ lib.@O@ \
listenlist.@O@ log.@O@ notify.@O@ query.@O@ \
server.@O@ sortlist.@O@ stats.@O@ update.@O@ \
version.@O@ xfrout.@O@
SRCS = client.c interfacemgr.c lib.c listenlist.c \
log.c notify.c query.c server.c sortlist.c stats.c \
update.c version.c xfrout.c
SUBDIRS = include
TARGETS = timestamp
TESTDIRS = @UNITTESTS@
@BIND9_MAKE_RULES@
version.@O@: version.c
${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} \
-DVERSION=\"${VERSION}\" \
-DMAJOR=\"${MAJOR}\" \
-DLIBINTERFACE=${LIBINTERFACE} \
-DLIBREVISION=${LIBREVISION} \
-DLIBAGE=${LIBAGE} \
-c ${srcdir}/version.c
libns.@SA@: ${OBJS}
${AR} ${ARFLAGS} $@ ${OBJS}
${RANLIB} $@
libns.la: ${OBJS}
${LIBTOOL_MODE_LINK} \
${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libns.la -rpath ${libdir} \
-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
${OBJS} ${ISCLIBS} @DNS_CRYPTO_LIBS@ ${LIBS}
timestamp: libns.@A@
touch timestamp
installdirs:
$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}
install:: timestamp installdirs
${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libns.@A@ \
${DESTDIR}${libdir}
uninstall::
${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libns.@A@
clean distclean::
rm -f libns.@A@ timestamp

12
lib/ns/api Normal file
View File

@@ -0,0 +1,12 @@
# LIBINTERFACE ranges
# 9.6: 50-59, 110-119
# 9.7: 60-79
# 9.8: 80-89, 120-129
# 9.9: 90-109, 170-179
# 9.9-sub: 130-139, 150-159
# 9.10: 140-149, 170-179
# 9.11: 160-169
# 9.12: 1200-1299
LIBINTERFACE = 1200
LIBREVISION = 0
LIBAGE = 0

3965
lib/ns/client.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
# Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
SUBDIRS = nserv
TARGETS =
@BIND9_MAKE_RULES@

View File

@@ -0,0 +1,32 @@
# Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
VERSION=@BIND9_VERSION@
HEADERS = client.h interfacemgr.h lib.h listenlist.h log.h \
notify.h query.h server.h sortlist.h stats.h \
types.h update.h version.h xfrout.h
SUBDIRS =
TARGETS =
@BIND9_MAKE_RULES@
installdirs:
$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${includedir}/ns
install:: installdirs
for i in ${HEADERS}; do \
${INSTALL_DATA} ${srcdir}/$$i ${DESTDIR}${includedir}/ns ; \
done
uninstall::
for i in ${HEADERS}; do \
rm -f ${DESTDIR}${includedir}/ns/$$i ; \
done

418
lib/ns/include/ns/client.h Normal file
View File

@@ -0,0 +1,418 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_CLIENT_H
#define NS_CLIENT_H 1
/*****
***** Module Info
*****/
/*! \file
* \brief
* This module defines two objects, ns_client_t and ns_clientmgr_t.
*
* An ns_client_t object handles incoming DNS requests from clients
* on a given network interface.
*
* Each ns_client_t object can handle only one TCP connection or UDP
* request at a time. Therefore, several ns_client_t objects are
* typically created to serve each network interface, e.g., one
* for handling TCP requests and a few (one per CPU) for handling
* UDP requests.
*
* Incoming requests are classified as queries, zone transfer
* requests, update requests, notify requests, etc, and handed off
* to the appropriate request handler. When the request has been
* fully handled (which can be much later), the ns_client_t must be
* notified of this by calling one of the following functions
* exactly once in the context of its task:
* \code
* ns_client_send() (sending a non-error response)
* ns_client_sendraw() (sending a raw response)
* ns_client_error() (sending an error response)
* ns_client_next() (sending no response)
*\endcode
* This will release any resources used by the request and
* and allow the ns_client_t to listen for the next request.
*
* A ns_clientmgr_t manages a number of ns_client_t objects.
* New ns_client_t objects are created by calling
* ns_clientmgr_createclients(). They are destroyed by
* destroying their manager.
*/
/***
*** Imports
***/
#include <isc/buffer.h>
#include <isc/magic.h>
#include <isc/stdtime.h>
#include <isc/quota.h>
#include <isc/queue.h>
#include <isc/platform.h>
#include <dns/db.h>
#include <dns/ecs.h>
#include <dns/fixedname.h>
#include <dns/name.h>
#include <dns/rdataclass.h>
#include <dns/rdatatype.h>
#include <dns/tcpmsg.h>
#include <dns/types.h>
#include <ns/query.h>
#include <ns/types.h>
/***
*** Types
***/
/*% nameserver client structure */
struct ns_client {
unsigned int magic;
isc_mem_t * mctx;
ns_server_t * sctx;
ns_clientmgr_t * manager;
int state;
int newstate;
int naccepts;
int nreads;
int nsends;
int nrecvs;
int nupdates;
int nctls;
int references;
isc_boolean_t needshutdown; /*
* Used by clienttest to get
* the client to go from
* inactive to free state
* by shutting down the
* client's task.
*/
unsigned int attributes;
isc_task_t * task;
dns_view_t * view;
dns_dispatch_t * dispatch;
isc_socket_t * udpsocket;
isc_socket_t * tcplistener;
isc_socket_t * tcpsocket;
unsigned char * tcpbuf;
dns_tcpmsg_t tcpmsg;
isc_boolean_t tcpmsg_valid;
isc_timer_t * timer;
isc_timer_t * delaytimer;
isc_boolean_t timerset;
dns_message_t * message;
isc_socketevent_t * sendevent;
isc_socketevent_t * recvevent;
unsigned char * recvbuf;
dns_rdataset_t * opt;
isc_uint16_t udpsize;
isc_uint16_t extflags;
isc_int16_t ednsversion; /* -1 noedns */
void (*next)(ns_client_t *);
void (*shutdown)(void *arg, isc_result_t result);
void *shutdown_arg;
ns_query_t query;
isc_time_t requesttime;
isc_stdtime_t now;
isc_time_t tnow;
dns_name_t signername; /*%< [T]SIG key name */
dns_name_t * signer; /*%< NULL if not valid sig */
isc_boolean_t mortal; /*%< Die after handling request */
isc_boolean_t pipelined; /*%< TCP queries not in sequence */
isc_quota_t *tcpquota;
isc_quota_t *recursionquota;
ns_interface_t *interface;
isc_sockaddr_t peeraddr;
isc_boolean_t peeraddr_valid;
isc_netaddr_t destaddr;
dns_ecs_t ecs; /*%< EDNS client subnet sent by client */
struct in6_pktinfo pktinfo;
isc_dscp_t dscp;
isc_event_t ctlevent;
#ifdef ALLOW_FILTER_AAAA
dns_aaaa_t filter_aaaa;
#endif
/*%
* Information about recent FORMERR response(s), for
* FORMERR loop avoidance. This is separate for each
* client object rather than global only to avoid
* the need for locking.
*/
struct {
isc_sockaddr_t addr;
isc_stdtime_t time;
dns_messageid_t id;
} formerrcache;
/*% Callback function to send a response when unit testing */
void (*sendcb)(isc_buffer_t *buf);
ISC_LINK(ns_client_t) link;
ISC_LINK(ns_client_t) rlink;
ISC_QLINK(ns_client_t) ilink;
unsigned char cookie[8];
isc_uint32_t expire;
};
typedef ISC_QUEUE(ns_client_t) client_queue_t;
typedef ISC_LIST(ns_client_t) client_list_t;
#define NS_CLIENT_MAGIC ISC_MAGIC('N','S','C','c')
#define NS_CLIENT_VALID(c) ISC_MAGIC_VALID(c, NS_CLIENT_MAGIC)
#define NS_CLIENTATTR_TCP 0x00001
#define NS_CLIENTATTR_RA 0x00002 /*%< Client gets recursive service */
#define NS_CLIENTATTR_PKTINFO 0x00004 /*%< pktinfo is valid */
#define NS_CLIENTATTR_MULTICAST 0x00008 /*%< recv'd from multicast */
#define NS_CLIENTATTR_WANTDNSSEC 0x00010 /*%< include dnssec records */
#define NS_CLIENTATTR_WANTNSID 0x00020 /*%< include nameserver ID */
#ifdef ALLOW_FILTER_AAAA
#define NS_CLIENTATTR_FILTER_AAAA 0x00040 /*%< suppress AAAAs */
#define NS_CLIENTATTR_FILTER_AAAA_RC 0x00080 /*%< recursing for A against AAAA */
#endif
#define NS_CLIENTATTR_WANTAD 0x00100 /*%< want AD in response if possible */
#define NS_CLIENTATTR_WANTCOOKIE 0x00200 /*%< return a COOKIE */
#define NS_CLIENTATTR_HAVECOOKIE 0x00400 /*%< has a valid COOKIE */
#define NS_CLIENTATTR_WANTEXPIRE 0x00800 /*%< return seconds to expire */
#define NS_CLIENTATTR_HAVEEXPIRE 0x01000 /*%< return seconds to expire */
#define NS_CLIENTATTR_WANTOPT 0x02000 /*%< add opt to reply */
#define NS_CLIENTATTR_HAVEECS 0x04000 /*%< received an ECS option */
#define NS_CLIENTATTR_WANTPAD 0x08000 /*%< pad reply */
#define NS_CLIENTATTR_USEKEEPALIVE 0x10000 /*%< use TCP keepalive */
#define NS_CLIENTATTR_NOSETFC 0x20000 /*%< don't set servfail cache */
/*
* Flag to use with the SERVFAIL cache to indicate
* that a query had the CD bit set.
*/
#define NS_FAILCACHE_CD 0x01
LIBNS_EXTERNAL_DATA extern unsigned int ns_client_requests;
/***
*** Functions
***/
/*
* Note! These ns_client_ routines MUST be called ONLY from the client's
* task in order to ensure synchronization.
*/
void
ns_client_send(ns_client_t *client);
/*%<
* Finish processing the current client request and
* send client->message as a response.
* \brief
* Note! These ns_client_ routines MUST be called ONLY from the client's
* task in order to ensure synchronization.
*/
void
ns_client_sendraw(ns_client_t *client, dns_message_t *msg);
/*%<
* Finish processing the current client request and
* send msg as a response using client->message->id for the id.
*/
void
ns_client_error(ns_client_t *client, isc_result_t result);
/*%<
* Finish processing the current client request and return
* an error response to the client. The error response
* will have an RCODE determined by 'result'.
*/
void
ns_client_next(ns_client_t *client, isc_result_t result);
/*%<
* Finish processing the current client request,
* return no response to the client.
*/
isc_boolean_t
ns_client_shuttingdown(ns_client_t *client);
/*%<
* Return ISC_TRUE iff the client is currently shutting down.
*/
void
ns_client_attach(ns_client_t *source, ns_client_t **target);
/*%<
* Attach '*targetp' to 'source'.
*/
void
ns_client_detach(ns_client_t **clientp);
/*%<
* Detach '*clientp' from its client.
*/
isc_result_t
ns_client_replace(ns_client_t *client);
/*%<
* Try to replace the current client with a new one, so that the
* current one can go off and do some lengthy work without
* leaving the dispatch/socket without service.
*/
void
ns_client_settimeout(ns_client_t *client, unsigned int seconds);
/*%<
* Set a timer in the client to go off in the specified amount of time.
*/
isc_result_t
ns_clientmgr_create(isc_mem_t *mctx, ns_server_t *sctx, isc_taskmgr_t *taskmgr,
isc_timermgr_t *timermgr, ns_clientmgr_t **managerp);
/*%<
* Create a client manager.
*/
void
ns_clientmgr_destroy(ns_clientmgr_t **managerp);
/*%<
* Destroy a client manager and all ns_client_t objects
* managed by it.
*/
isc_result_t
ns_clientmgr_createclients(ns_clientmgr_t *manager, unsigned int n,
ns_interface_t *ifp, isc_boolean_t tcp);
/*%<
* Create up to 'n' clients listening on interface 'ifp'.
* If 'tcp' is ISC_TRUE, the clients will listen for TCP connections,
* otherwise for UDP requests.
*/
isc_sockaddr_t *
ns_client_getsockaddr(ns_client_t *client);
/*%<
* Get the socket address of the client whose request is
* currently being processed.
*/
isc_result_t
ns_client_checkaclsilent(ns_client_t *client, isc_netaddr_t *netaddr,
dns_acl_t *acl, isc_boolean_t default_allow);
/*%<
* Convenience function for client request ACL checking.
*
* Check the current client request against 'acl'. If 'acl'
* is NULL, allow the request iff 'default_allow' is ISC_TRUE.
* If netaddr is NULL, check the ACL against client->peeraddr;
* otherwise check it against netaddr.
*
* Notes:
*\li This is appropriate for checking allow-update,
* allow-query, allow-transfer, etc. It is not appropriate
* for checking the blackhole list because we treat positive
* matches as "allow" and negative matches as "deny"; in
* the case of the blackhole list this would be backwards.
*
* Requires:
*\li 'client' points to a valid client.
*\li 'netaddr' points to a valid address, or is NULL.
*\li 'acl' points to a valid ACL, or is NULL.
*
* Returns:
*\li ISC_R_SUCCESS if the request should be allowed
* \li DNS_R_REFUSED if the request should be denied
*\li No other return values are possible.
*/
isc_result_t
ns_client_checkacl(ns_client_t *client,
isc_sockaddr_t *sockaddr,
const char *opname, dns_acl_t *acl,
isc_boolean_t default_allow,
int log_level);
/*%<
* Like ns_client_checkaclsilent, except the outcome of the check is
* logged at log level 'log_level' if denied, and at debug 3 if approved.
* Log messages will refer to the request as an 'opname' request.
*
* Requires:
*\li 'client' points to a valid client.
*\li 'sockaddr' points to a valid address, or is NULL.
*\li 'acl' points to a valid ACL, or is NULL.
*\li 'opname' points to a null-terminated string.
*/
void
ns_client_log(ns_client_t *client, isc_logcategory_t *category,
isc_logmodule_t *module, int level,
const char *fmt, ...) ISC_FORMAT_PRINTF(5, 6);
void
ns_client_logv(ns_client_t *client, isc_logcategory_t *category,
isc_logmodule_t *module, int level, const char *fmt, va_list ap) ISC_FORMAT_PRINTF(5, 0);
void
ns_client_aclmsg(const char *msg, const dns_name_t *name, dns_rdatatype_t type,
dns_rdataclass_t rdclass, char *buf, size_t len);
#define NS_CLIENT_ACLMSGSIZE(x) \
(DNS_NAME_FORMATSIZE + DNS_RDATATYPE_FORMATSIZE + \
DNS_RDATACLASS_FORMATSIZE + sizeof(x) + sizeof("'/'"))
void
ns_client_recursing(ns_client_t *client);
/*%<
* Add client to end of th recursing list.
*/
void
ns_client_killoldestquery(ns_client_t *client);
/*%<
* Kill the oldest recursive query (recursing list head).
*/
void
ns_client_dumprecursing(FILE *f, ns_clientmgr_t *manager);
/*%<
* Dump the outstanding recursive queries to 'f'.
*/
void
ns_client_qnamereplace(ns_client_t *client, dns_name_t *name);
/*%<
* Replace the qname.
*/
isc_result_t
ns_client_sourceip(dns_clientinfo_t *ci, isc_sockaddr_t **addrp);
isc_result_t
ns_client_addopt(ns_client_t *client, dns_message_t *message,
dns_rdataset_t **opt);
isc_result_t
ns__clientmgr_getclient(ns_clientmgr_t *manager, ns_interface_t *ifp,
isc_boolean_t tcp, ns_client_t **clientp);
/*
* Get a client object from the inactive queue, or create one, as needed.
* (Not intended for use outside this module and associated tests.)
*/
void
ns__client_request(isc_task_t *task, isc_event_t *event);
/*
* Handle client requests.
* (Not intended for use outside this module and associated tests.)
*/
#endif /* NS_CLIENT_H */

View File

@@ -0,0 +1,197 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_INTERFACEMGR_H
#define NS_INTERFACEMGR_H 1
/*****
***** Module Info
*****/
/*! \file
* \brief
* The interface manager monitors the operating system's list
* of network interfaces, creating and destroying listeners
* as needed.
*
* Reliability:
*\li No impact expected.
*
* Resources:
*
* Security:
* \li The server will only be able to bind to the DNS port on
* newly discovered interfaces if it is running as root.
*
* Standards:
*\li The API for scanning varies greatly among operating systems.
* This module attempts to hide the differences.
*/
/***
*** Imports
***/
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/socket.h>
#include <dns/geoip.h>
#include <dns/result.h>
#include <ns/listenlist.h>
#include <ns/types.h>
/***
*** Types
***/
#define IFACE_MAGIC ISC_MAGIC('I',':','-',')')
#define NS_INTERFACE_VALID(t) ISC_MAGIC_VALID(t, IFACE_MAGIC)
#define NS_INTERFACEFLAG_ANYADDR 0x01U /*%< bound to "any" address */
#define MAX_UDP_DISPATCH 128 /*%< Maximum number of UDP dispatchers
to start per interface */
/*% The nameserver interface structure */
struct ns_interface {
unsigned int magic; /*%< Magic number. */
ns_interfacemgr_t * mgr; /*%< Interface manager. */
isc_mutex_t lock;
int references; /*%< Locked */
unsigned int generation; /*%< Generation number. */
isc_sockaddr_t addr; /*%< Address and port. */
unsigned int flags; /*%< Interface characteristics */
char name[32]; /*%< Null terminated. */
dns_dispatch_t * udpdispatch[MAX_UDP_DISPATCH];
/*%< UDP dispatchers. */
isc_socket_t * tcpsocket; /*%< TCP socket. */
isc_dscp_t dscp; /*%< "listen-on" DSCP value */
int ntcptarget; /*%< Desired number of concurrent
TCP accepts */
int ntcpcurrent; /*%< Current ditto, locked */
int nudpdispatch; /*%< Number of UDP dispatches */
ns_clientmgr_t * clientmgr; /*%< Client manager. */
ISC_LINK(ns_interface_t) link;
};
/***
*** Functions
***/
isc_result_t
ns_interfacemgr_create(isc_mem_t *mctx,
ns_server_t *sctx,
isc_taskmgr_t *taskmgr,
isc_timermgr_t *timermgr,
isc_socketmgr_t *socketmgr,
dns_dispatchmgr_t *dispatchmgr,
isc_task_t *task,
unsigned int udpdisp,
dns_geoip_databases_t *geoip,
ns_interfacemgr_t **mgrp);
/*%<
* Create a new interface manager.
*
* Initially, the new manager will not listen on any interfaces.
* Call ns_interfacemgr_setlistenon() and/or ns_interfacemgr_setlistenon6()
* to set nonempty listen-on lists.
*/
void
ns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target);
void
ns_interfacemgr_detach(ns_interfacemgr_t **targetp);
void
ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr);
void
ns_interfacemgr_setbacklog(ns_interfacemgr_t *mgr, int backlog);
/*%<
* Set the size of the listen() backlog queue.
*/
isc_boolean_t
ns_interfacemgr_islistening(ns_interfacemgr_t *mgr);
/*%<
* Return if the manager is listening on any interface. It can be called
* after a scan or adjust.
*/
isc_result_t
ns_interfacemgr_scan(ns_interfacemgr_t *mgr, isc_boolean_t verbose);
/*%<
* Scan the operatings system's list of network interfaces
* and create listeners when new interfaces are discovered.
* Shut down the sockets for interfaces that go away.
*
* This should be called once on server startup and then
* periodically according to the 'interface-interval' option
* in named.conf.
*/
isc_result_t
ns_interfacemgr_adjust(ns_interfacemgr_t *mgr, ns_listenlist_t *list,
isc_boolean_t verbose);
/*%<
* Similar to ns_interfacemgr_scan(), but this function also tries to see the
* need for an explicit listen-on when a list element in 'list' is going to
* override an already-listening a wildcard interface.
*
* This function does not update localhost and localnets ACLs.
*
* This should be called once on server startup, after configuring views and
* zones.
*/
void
ns_interfacemgr_setlistenon4(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
/*%<
* Set the IPv4 "listen-on" list of 'mgr' to 'value'.
* The previous IPv4 listen-on list is freed.
*/
void
ns_interfacemgr_setlistenon6(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
/*%<
* Set the IPv6 "listen-on" list of 'mgr' to 'value'.
* The previous IPv6 listen-on list is freed.
*/
dns_aclenv_t *
ns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr);
void
ns_interface_attach(ns_interface_t *source, ns_interface_t **target);
void
ns_interface_detach(ns_interface_t **targetp);
void
ns_interface_shutdown(ns_interface_t *ifp);
/*%<
* Stop listening for queries on interface 'ifp'.
* May safely be called multiple times.
*/
void
ns_interfacemgr_dumprecursing(FILE *f, ns_interfacemgr_t *mgr);
isc_boolean_t
ns_interfacemgr_listeningon(ns_interfacemgr_t *mgr, const isc_sockaddr_t *addr);
ns_interface_t *
ns__interfacemgr_getif(ns_interfacemgr_t *mgr);
ns_interface_t *
ns__interfacemgr_nextif(ns_interface_t *ifp);
/*
* Functions to allow external callers to walk the interfaces list.
* (Not intended for use outside this module and associated tests.)
*/
#endif /* NS_INTERFACEMGR_H */

36
lib/ns/include/ns/lib.h Normal file
View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_LIB_H
#define NS_LIB_H 1
/*! \file ns/lib.h */
#include <isc/types.h>
#include <isc/lang.h>
ISC_LANG_BEGINDECLS
LIBNS_EXTERNAL_DATA extern unsigned int ns_pps;
LIBNS_EXTERNAL_DATA extern isc_msgcat_t *ns_msgcat;
isc_result_t
ns_lib_init(void);
/*%<
* A set of initialization procedures used in the NS library.
*/
void
ns_lib_shutdown(void);
/*%<
* Free temporary resources allocated in ns_lib_init().
*/
ISC_LANG_ENDDECLS
#endif /* NS_LIB_H */

View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_LISTENLIST_H
#define NS_LISTENLIST_H 1
/*****
***** Module Info
*****/
/*! \file
* \brief
* "Listen lists", as in the "listen-on" configuration statement.
*/
/***
*** Imports
***/
#include <isc/net.h>
#include <dns/types.h>
/***
*** Types
***/
typedef struct ns_listenelt ns_listenelt_t;
typedef struct ns_listenlist ns_listenlist_t;
struct ns_listenelt {
isc_mem_t * mctx;
in_port_t port;
isc_dscp_t dscp; /* -1 = not set, 0..63 */
dns_acl_t * acl;
ISC_LINK(ns_listenelt_t) link;
};
struct ns_listenlist {
isc_mem_t * mctx;
int refcount;
ISC_LIST(ns_listenelt_t) elts;
};
/***
*** Functions
***/
isc_result_t
ns_listenelt_create(isc_mem_t *mctx, in_port_t port, isc_dscp_t dscp,
dns_acl_t *acl, ns_listenelt_t **target);
/*%<
* Create a listen-on list element.
*/
void
ns_listenelt_destroy(ns_listenelt_t *elt);
/*%<
* Destroy a listen-on list element.
*/
isc_result_t
ns_listenlist_create(isc_mem_t *mctx, ns_listenlist_t **target);
/*%<
* Create a new, empty listen-on list.
*/
void
ns_listenlist_attach(ns_listenlist_t *source, ns_listenlist_t **target);
/*%<
* Attach '*target' to '*source'.
*/
void
ns_listenlist_detach(ns_listenlist_t **listp);
/*%<
* Detach 'listp'.
*/
isc_result_t
ns_listenlist_default(isc_mem_t *mctx, in_port_t port, isc_dscp_t dscp,
isc_boolean_t enabled, ns_listenlist_t **target);
/*%<
* Create a listen-on list with default contents, matching
* all addresses with port 'port' (if 'enabled' is ISC_TRUE),
* or no addresses (if 'enabled' is ISC_FALSE).
*/
#endif /* NS_LISTENLIST_H */

66
lib/ns/include/ns/log.h Normal file
View File

@@ -0,0 +1,66 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_LOG_H
#define NS_LOG_H 1
/*! \file */
#include <isc/log.h>
#include <isc/types.h>
LIBNS_EXTERNAL_DATA extern isc_log_t *ns_lctx;
LIBNS_EXTERNAL_DATA extern isc_logcategory_t ns_categories[];
LIBNS_EXTERNAL_DATA extern isc_logmodule_t ns_modules[];
#define NS_LOGCATEGORY_CLIENT (&ns_categories[0])
#define NS_LOGCATEGORY_NETWORK (&ns_categories[1])
#define NS_LOGCATEGORY_UPDATE (&ns_categories[2])
#define NS_LOGCATEGORY_QUERIES (&ns_categories[3])
#define NS_LOGCATEGORY_UPDATE_SECURITY (&ns_categories[4])
#define NS_LOGCATEGORY_QUERY_ERRORS (&ns_categories[5])
/*
* Backwards compatibility.
*/
#define NS_LOGCATEGORY_GENERAL ISC_LOGCATEGORY_GENERAL
#define NS_LOGMODULE_CLIENT (&ns_modules[0])
#define NS_LOGMODULE_QUERY (&ns_modules[1])
#define NS_LOGMODULE_INTERFACEMGR (&ns_modules[2])
#define NS_LOGMODULE_UPDATE (&ns_modules[3])
#define NS_LOGMODULE_XFER_IN (&ns_modules[4])
#define NS_LOGMODULE_XFER_OUT (&ns_modules[5])
#define NS_LOGMODULE_NOTIFY (&ns_modules[6])
void
ns_log_init(isc_log_t *lctx);
/*%<
* Make the libns categories and modules available for use with the
* ISC logging library.
*
* Requires:
*\li lctx is a valid logging context.
*
*\li ns_log_init() is called only once.
*
* Ensures:
*\li The categories and modules defined above are available for
* use by isc_log_usechannnel() and isc_log_write().
*/
void
ns_log_setcontext(isc_log_t *lctx);
/*%<
* Make the libns library use the provided context for logging internal
* messages.
*
* Requires:
*\li lctx is a valid logging context.
*/
#endif /* NS_LOG_H */

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_NOTIFY_H
#define NS_NOTIFY_H 1
#include <ns/client.h>
/***
*** Module Info
***/
/*! \file
* \brief
* RFC1996
* A Mechanism for Prompt Notification of Zone Changes (DNS NOTIFY)
*/
/***
*** Functions.
***/
void
ns_notify_start(ns_client_t *client);
/*%<
* Examines the incoming message to determine appropriate zone.
* Returns FORMERR if there is not exactly one question.
* Returns REFUSED if we do not serve the listed zone.
* Pass the message to the zone module for processing
* and returns the return status.
*
* Requires
*\li client to be valid.
*/
#endif /* NS_NOTIFY_H */

107
lib/ns/include/ns/query.h Normal file
View File

@@ -0,0 +1,107 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_QUERY_H
#define NS_QUERY_H 1
/*! \file */
#include <isc/types.h>
#include <isc/buffer.h>
#include <isc/netaddr.h>
#include <dns/rdataset.h>
#include <dns/rpz.h>
#include <dns/types.h>
#include <ns/types.h>
/*% nameserver database version structure */
typedef struct ns_dbversion {
dns_db_t *db;
dns_dbversion_t *version;
isc_boolean_t acl_checked;
isc_boolean_t queryok;
ISC_LINK(struct ns_dbversion) link;
} ns_dbversion_t;
/*% nameserver query structure */
struct ns_query {
unsigned int attributes;
unsigned int restarts;
isc_boolean_t timerset;
dns_name_t * qname;
dns_name_t * origqname;
dns_rdatatype_t qtype;
unsigned int dboptions;
unsigned int fetchoptions;
dns_db_t * gluedb;
dns_db_t * authdb;
dns_zone_t * authzone;
isc_boolean_t authdbset;
isc_boolean_t isreferral;
isc_mutex_t fetchlock;
dns_fetch_t * fetch;
dns_fetch_t * prefetch;
dns_rpz_st_t * rpz_st;
isc_bufferlist_t namebufs;
ISC_LIST(ns_dbversion_t) activeversions;
ISC_LIST(ns_dbversion_t) freeversions;
dns_rdataset_t * dns64_aaaa;
dns_rdataset_t * dns64_sigaaaa;
isc_boolean_t * dns64_aaaaok;
unsigned int dns64_aaaaoklen;
unsigned int dns64_options;
unsigned int dns64_ttl;
struct {
dns_db_t * db;
dns_zone_t * zone;
dns_dbnode_t * node;
dns_rdatatype_t qtype;
dns_name_t * fname;
dns_fixedname_t fixed;
isc_result_t result;
dns_rdataset_t * rdataset;
dns_rdataset_t * sigrdataset;
isc_boolean_t authoritative;
isc_boolean_t is_zone;
} redirect;
};
#define NS_QUERYATTR_RECURSIONOK 0x0001
#define NS_QUERYATTR_CACHEOK 0x0002
#define NS_QUERYATTR_PARTIALANSWER 0x0004
#define NS_QUERYATTR_NAMEBUFUSED 0x0008
#define NS_QUERYATTR_RECURSING 0x0010
#define NS_QUERYATTR_CACHEGLUEOK 0x0020
#define NS_QUERYATTR_QUERYOKVALID 0x0040
#define NS_QUERYATTR_QUERYOK 0x0080
#define NS_QUERYATTR_WANTRECURSION 0x0100
#define NS_QUERYATTR_SECURE 0x0200
#define NS_QUERYATTR_NOAUTHORITY 0x0400
#define NS_QUERYATTR_NOADDITIONAL 0x0800
#define NS_QUERYATTR_CACHEACLOKVALID 0x1000
#define NS_QUERYATTR_CACHEACLOK 0x2000
#define NS_QUERYATTR_DNS64 0x4000
#define NS_QUERYATTR_DNS64EXCLUDE 0x8000
#define NS_QUERYATTR_RRL_CHECKED 0x10000
#define NS_QUERYATTR_REDIRECT 0x20000
isc_result_t
ns_query_init(ns_client_t *client);
void
ns_query_free(ns_client_t *client);
void
ns_query_start(ns_client_t *client);
void
ns_query_cancel(ns_client_t *client);
#endif /* NS_QUERY_H */

199
lib/ns/include/ns/server.h Normal file
View File

@@ -0,0 +1,199 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_SERVER_H
#define NS_SERVER_H 1
/*! \file */
#include <isc/log.h>
#include <isc/fuzz.h>
#include <isc/magic.h>
#include <isc/quota.h>
#include <isc/sockaddr.h>
#include <isc/types.h>
#include <dns/acl.h>
#include <dns/types.h>
#include <ns/types.h>
#define NS_EVENT_CLIENTCONTROL (ISC_EVENTCLASS_NS + 0)
#define NS_SERVER_LOGQUERIES 0x00000001U /*%< log queries */
#define NS_SERVER_NOAA 0x00000002U /*%< -T noaa */
#define NS_SERVER_NOSOA 0x00000004U /*%< -T nosoa */
#define NS_SERVER_NONEAREST 0x00000008U /*%< -T nonearest */
#define NS_SERVER_CLIENTTEST 0x00000010U /*%< -T clienttest */
#define NS_SERVER_NOEDNS 0x00000020U /*%< -T noedns */
#define NS_SERVER_DROPEDNS 0x00000040U /*%< -T dropedns */
#define NS_SERVER_NOTCP 0x00000080U /*%< -T notcp */
#define NS_SERVER_DISABLE4 0x00000100U /*%< -6 */
#define NS_SERVER_DISABLE6 0x00000100U /*%< -4 */
/*%
* Type for callback function to get hostname.
*/
typedef isc_result_t
(*ns_hostnamecb_t)(char *buf, size_t len);
/*%
* Type for callback function to signal the fuzzer thread
* when built with AFL.
*/
typedef void
(*ns_fuzzcb_t)(void);
/*%
* Type for callback function to get the view that can answer a query.
*/
typedef isc_result_t
(*ns_matchview_t)(isc_netaddr_t *srcaddr, isc_netaddr_t *destaddr,
dns_message_t *message, dns_ecs_t *ecs,
isc_result_t *sigresultp, dns_view_t **viewp);
/*%
* Server context.
*/
struct ns_server {
unsigned int magic;
isc_mem_t * mctx;
isc_refcount_t references;
/*% Server cookie secret and algorithm */
unsigned char secret[32];
ns_cookiealg_t cookiealg;
ns_altsecretlist_t altsecrets;
/*% Quotas */
isc_quota_t recursionquota;
isc_quota_t tcpquota;
isc_quota_t xfroutquota;
/*% Test options and other configurables */
isc_uint32_t options;
unsigned int delay;
unsigned int initialtimo;
unsigned int idletimo;
unsigned int keepalivetimo;
unsigned int advertisedtimo;
dns_acl_t *blackholeacl;
dns_acl_t *keepresporder;
isc_uint16_t udpsize;
isc_uint16_t transfer_tcp_message_size;
isc_boolean_t interface_auto;
dns_tkeyctx_t * tkeyctx;
/*% Server id for NSID */
char * server_id;
ns_hostnamecb_t gethostname;
/*% Fuzzer callback */
isc_fuzztype_t fuzztype;
ns_fuzzcb_t fuzznotify;
/*% Callback to find a matching view for a query */
ns_matchview_t matchingview;
/*% Stats counters */
ns_stats_t * nsstats;
dns_stats_t * rcvquerystats;
dns_stats_t * opcodestats;
dns_stats_t * rcodestats;
isc_stats_t * udpinstats4;
isc_stats_t * udpoutstats4;
isc_stats_t * udpinstats6;
isc_stats_t * udpoutstats6;
isc_stats_t * tcpinstats4;
isc_stats_t * tcpoutstats4;
isc_stats_t * tcpinstats6;
isc_stats_t * tcpoutstats6;
};
struct ns_altsecret {
ISC_LINK(ns_altsecret_t) link;
unsigned char secret[32];
};
isc_result_t
ns_server_create(isc_mem_t *mctx, isc_entropy_t *entropy,
ns_matchview_t matchingview, ns_server_t **sctxp);
/*%<
* Create a server context object with default settings.
*/
void
ns_server_attach(ns_server_t *src, ns_server_t **dest);
/*%<
* Attach a server context.
*
* Requires:
*\li 'src' is valid.
*/
void
ns_server_detach(ns_server_t **sctxp);
/*%<
* Detach from a server context. If its reference count drops to zero, destroy
* it, freeing its memory.
*
* Requires:
*\li '*sctxp' is valid.
* Ensures:
*\li '*sctxp' is NULL on return.
*/
isc_result_t
ns_server_setserverid(ns_server_t *sctx, const char *serverid);
/*%<
* Set sctx->server_id to 'serverid'. If it was set previously, free the memory.
*
* Requires:
*\li 'sctx' is valid.
*/
void
ns_server_settimeouts(ns_server_t *sctx, unsigned int initial,
unsigned int idle, unsigned int keepalive,
unsigned int advertised);
void
ns_server_gettimeouts(ns_server_t *sctx, unsigned int *initial,
unsigned int *idle, unsigned int *keepalive,
unsigned int *advertised);
/*%<
* Set/get tcp-timeout values.
*
* Requires:
*\li 'sctx' is valid.
*/
void
ns_server_setoption(ns_server_t *sctx, unsigned int option,
isc_boolean_t value);
/*%<
* Set the given options on (if 'value' == #ISC_TRUE)
* or off (if 'value' == #ISC_FALSE).
*
* Requires:
*\li 'sctx' is valid
*/
isc_boolean_t
ns_server_getoption(ns_server_t *sctx, unsigned int option);
/*%<
* Returns the current value of the specified server option.
*
* Requires:
*\li 'sctx' is valid.
*/
#endif /* NS_SERVER_H */

View File

@@ -0,0 +1,79 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_SORTLIST_H
#define NS_SORTLIST_H 1
/*! \file */
#include <isc/types.h>
#include <dns/acl.h>
#include <dns/types.h>
/*%
* Type for callback functions that rank addresses.
*/
typedef int
(*dns_addressorderfunc_t)(const isc_netaddr_t *address, const void *arg);
/*%
* Return value type for setup_sortlist.
*/
typedef enum {
NS_SORTLISTTYPE_NONE,
NS_SORTLISTTYPE_1ELEMENT,
NS_SORTLISTTYPE_2ELEMENT
} ns_sortlisttype_t;
ns_sortlisttype_t
ns_sortlist_setup(dns_acl_t *acl, dns_aclenv_t *env,
isc_netaddr_t *clientaddr, const void **argp);
/*%<
* Find the sortlist statement in 'acl' (for ACL environment 'env')
* that applies to 'clientaddr', if any.
*
* If a 1-element sortlist item applies, return NS_SORTLISTTYPE_1ELEMENT and
* make '*argp' point to the matching subelement.
*
* If a 2-element sortlist item applies, return NS_SORTLISTTYPE_2ELEMENT and
* make '*argp' point to ACL that forms the second element.
*
* If no sortlist item applies, return NS_SORTLISTTYPE_NONE and set '*argp'
* to NULL.
*/
int
ns_sortlist_addrorder1(const isc_netaddr_t *addr, const void *arg);
/*%<
* Find the sort order of 'addr' in 'arg', the matching element
* of a 1-element top-level sortlist statement.
*/
int
ns_sortlist_addrorder2(const isc_netaddr_t *addr, const void *arg);
/*%<
* Find the sort order of 'addr' in 'arg', a topology-like
* ACL forming the second element in a 2-element top-level
* sortlist statement.
*/
void
ns_sortlist_byaddrsetup(dns_acl_t *sortlist_acl, dns_aclenv_t *env,
isc_netaddr_t *client_addr,
dns_addressorderfunc_t *orderp,
const void **argp);
/*%<
* Find the sortlist statement in 'acl' that applies to 'clientaddr', if any.
* If a sortlist statement applies, return in '*orderp' a pointer to a function
* for ranking network addresses based on that sortlist statement, and in
* '*argp' an argument to pass to said function. If no sortlist statement
* applies, set '*orderp' and '*argp' to NULL.
*/
#endif /* NS_SORTLIST_H */

120
lib/ns/include/ns/stats.h Normal file
View File

@@ -0,0 +1,120 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_STATS_H
#define NS_STATS_H 1
/*! \file ns/stats.h */
#include <ns/types.h>
/*%
* Server statistics counters. Used as isc_statscounter_t values.
*/
enum {
ns_statscounter_requestv4 = 0,
ns_statscounter_requestv6 = 1,
ns_statscounter_edns0in = 2,
ns_statscounter_badednsver = 3,
ns_statscounter_tsigin = 4,
ns_statscounter_sig0in = 5,
ns_statscounter_invalidsig = 6,
ns_statscounter_requesttcp = 7,
ns_statscounter_authrej = 8,
ns_statscounter_recurserej = 9,
ns_statscounter_xfrrej = 10,
ns_statscounter_updaterej = 11,
ns_statscounter_response = 12,
ns_statscounter_truncatedresp = 13,
ns_statscounter_edns0out = 14,
ns_statscounter_tsigout = 15,
ns_statscounter_sig0out = 16,
ns_statscounter_success = 17,
ns_statscounter_authans = 18,
ns_statscounter_nonauthans = 19,
ns_statscounter_referral = 20,
ns_statscounter_nxrrset = 21,
ns_statscounter_servfail = 22,
ns_statscounter_formerr = 23,
ns_statscounter_nxdomain = 24,
ns_statscounter_recursion = 25,
ns_statscounter_duplicate = 26,
ns_statscounter_dropped = 27,
ns_statscounter_failure = 28,
ns_statscounter_xfrdone = 29,
ns_statscounter_updatereqfwd = 30,
ns_statscounter_updaterespfwd = 31,
ns_statscounter_updatefwdfail = 32,
ns_statscounter_updatedone = 33,
ns_statscounter_updatefail = 34,
ns_statscounter_updatebadprereq = 35,
ns_statscounter_recursclients = 36,
ns_statscounter_dns64 = 37,
ns_statscounter_ratedropped = 38,
ns_statscounter_rateslipped = 39,
ns_statscounter_rpz_rewrites = 40,
ns_statscounter_udp = 41,
ns_statscounter_tcp = 42,
ns_statscounter_nsidopt = 43,
ns_statscounter_expireopt = 44,
ns_statscounter_otheropt = 45,
ns_statscounter_ecsopt = 46,
ns_statscounter_padopt = 47,
ns_statscounter_keepaliveopt = 48,
ns_statscounter_nxdomainredirect = 49,
ns_statscounter_nxdomainredirect_rlookup = 50,
ns_statscounter_cookiein = 51,
ns_statscounter_cookiebadsize = 52,
ns_statscounter_cookiebadtime = 53,
ns_statscounter_cookienomatch = 54,
ns_statscounter_cookiematch = 55,
ns_statscounter_cookienew = 56,
ns_statscounter_badcookie = 57,
ns_statscounter_nxdomainsynth = 58,
ns_statscounter_nodatasynth = 59,
ns_statscounter_wildcardsynth = 60,
ns_statscounter_trystale = 61,
ns_statscounter_usedstale = 62,
ns_statscounter_max = 63
};
void
ns_stats_attach(ns_stats_t *stats, ns_stats_t **statsp);
void
ns_stats_detach(ns_stats_t **statsp);
isc_result_t
ns_stats_create(isc_mem_t *mctx, int ncounters, ns_stats_t **statsp);
void
ns_stats_increment(ns_stats_t *stats, isc_statscounter_t counter);
void
ns_stats_decrement(ns_stats_t *stats, isc_statscounter_t counter);
isc_stats_t *
ns_stats_get(ns_stats_t *stats);
#endif /* NS_STATS_H */

30
lib/ns/include/ns/types.h Normal file
View File

@@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_TYPES_H
#define NS_TYPES_H 1
/*! \file */
typedef struct ns_altsecret ns_altsecret_t;
typedef ISC_LIST(ns_altsecret_t) ns_altsecretlist_t;
typedef struct ns_client ns_client_t;
typedef struct ns_clientmgr ns_clientmgr_t;
typedef struct ns_interface ns_interface_t;
typedef struct ns_interfacemgr ns_interfacemgr_t;
typedef struct ns_query ns_query_t;
typedef struct ns_server ns_server_t;
typedef struct ns_stats ns_stats_t;
typedef enum {
ns_cookiealg_aes,
ns_cookiealg_sha1,
ns_cookiealg_sha256
} ns_cookiealg_t;
#endif /* NS_TYPES_H */

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_UPDATE_H
#define NS_UPDATE_H 1
/*****
***** Module Info
*****/
/*! \file
* \brief
* RFC2136 Dynamic Update
*/
/***
*** Imports
***/
#include <dns/types.h>
#include <dns/result.h>
/***
*** Types.
***/
/***
*** Functions
***/
void
ns_update_start(ns_client_t *client, isc_result_t sigresult);
#endif /* NS_UPDATE_H */

View File

@@ -0,0 +1,17 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file ns/version.h */
#include <isc/platform.h>
LIBNS_EXTERNAL_DATA extern const char ns_version[];
LIBNS_EXTERNAL_DATA extern const unsigned int ns_libinterface;
LIBNS_EXTERNAL_DATA extern const unsigned int ns_librevision;
LIBNS_EXTERNAL_DATA extern const unsigned int ns_libage;

View File

@@ -0,0 +1,28 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef NS_XFROUT_H
#define NS_XFROUT_H 1
/*****
***** Module Info
*****/
/*! \file
* \brief
* Outgoing zone transfers (AXFR + IXFR).
*/
/***
*** Functions
***/
void
ns_xfr_start(ns_client_t *client, dns_rdatatype_t xfrtype);
#endif /* NS_XFROUT_H */

1313
lib/ns/interfacemgr.c Normal file

File diff suppressed because it is too large Load Diff

102
lib/ns/lib.c Normal file
View File

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <stddef.h>
#include <isc/mem.h>
#include <isc/msgcat.h>
#include <isc/mutex.h>
#include <isc/once.h>
#include <isc/util.h>
#include <dns/name.h>
#include <ns/lib.h>
/***
*** Globals
***/
LIBNS_EXTERNAL_DATA unsigned int ns_pps = 0U;
/***
*** Private
***/
static isc_once_t init_once = ISC_ONCE_INIT;
static isc_mem_t *ns_g_mctx = NULL;
static isc_boolean_t initialize_done = ISC_FALSE;
static isc_mutex_t reflock;
static unsigned int references = 0;
static void
initialize(void) {
isc_result_t result;
REQUIRE(initialize_done == ISC_FALSE);
result = isc_mem_create(0, 0, &ns_g_mctx);
if (result != ISC_R_SUCCESS)
return;
result = isc_mutex_init(&reflock);
if (result != ISC_R_SUCCESS)
goto cleanup_mctx;
initialize_done = ISC_TRUE;
return;
cleanup_mctx:
if (ns_g_mctx != NULL)
isc_mem_detach(&ns_g_mctx);
}
isc_result_t
ns_lib_init(void) {
isc_result_t result;
/*
* Since this routine is expected to be used by a normal application,
* it should be better to return an error, instead of an emergency
* abort, on any failure.
*/
result = isc_once_do(&init_once, initialize);
if (result != ISC_R_SUCCESS)
return (result);
if (!initialize_done)
return (ISC_R_FAILURE);
LOCK(&reflock);
references++;
UNLOCK(&reflock);
return (ISC_R_SUCCESS);
}
void
ns_lib_shutdown(void) {
isc_boolean_t cleanup_ok = ISC_FALSE;
LOCK(&reflock);
if (--references == 0)
cleanup_ok = ISC_TRUE;
UNLOCK(&reflock);
if (!cleanup_ok)
return;
if (ns_g_mctx != NULL)
isc_mem_detach(&ns_g_mctx);
}

128
lib/ns/listenlist.c Normal file
View File

@@ -0,0 +1,128 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <isc/mem.h>
#include <isc/util.h>
#include <dns/acl.h>
#include <ns/listenlist.h>
static void
destroy(ns_listenlist_t *list);
isc_result_t
ns_listenelt_create(isc_mem_t *mctx, in_port_t port, isc_dscp_t dscp,
dns_acl_t *acl, ns_listenelt_t **target)
{
ns_listenelt_t *elt = NULL;
REQUIRE(target != NULL && *target == NULL);
elt = isc_mem_get(mctx, sizeof(*elt));
if (elt == NULL)
return (ISC_R_NOMEMORY);
elt->mctx = mctx;
ISC_LINK_INIT(elt, link);
elt->port = port;
elt->dscp = dscp;
elt->acl = acl;
*target = elt;
return (ISC_R_SUCCESS);
}
void
ns_listenelt_destroy(ns_listenelt_t *elt) {
if (elt->acl != NULL)
dns_acl_detach(&elt->acl);
isc_mem_put(elt->mctx, elt, sizeof(*elt));
}
isc_result_t
ns_listenlist_create(isc_mem_t *mctx, ns_listenlist_t **target) {
ns_listenlist_t *list = NULL;
REQUIRE(target != NULL && *target == NULL);
list = isc_mem_get(mctx, sizeof(*list));
if (list == NULL)
return (ISC_R_NOMEMORY);
list->mctx = mctx;
list->refcount = 1;
ISC_LIST_INIT(list->elts);
*target = list;
return (ISC_R_SUCCESS);
}
static void
destroy(ns_listenlist_t *list) {
ns_listenelt_t *elt, *next;
for (elt = ISC_LIST_HEAD(list->elts);
elt != NULL;
elt = next)
{
next = ISC_LIST_NEXT(elt, link);
ns_listenelt_destroy(elt);
}
isc_mem_put(list->mctx, list, sizeof(*list));
}
void
ns_listenlist_attach(ns_listenlist_t *source, ns_listenlist_t **target) {
INSIST(source->refcount > 0);
source->refcount++;
*target = source;
}
void
ns_listenlist_detach(ns_listenlist_t **listp) {
ns_listenlist_t *list = *listp;
INSIST(list->refcount > 0);
list->refcount--;
if (list->refcount == 0)
destroy(list);
*listp = NULL;
}
isc_result_t
ns_listenlist_default(isc_mem_t *mctx, in_port_t port, isc_dscp_t dscp,
isc_boolean_t enabled, ns_listenlist_t **target)
{
isc_result_t result;
dns_acl_t *acl = NULL;
ns_listenelt_t *elt = NULL;
ns_listenlist_t *list = NULL;
REQUIRE(target != NULL && *target == NULL);
if (enabled)
result = dns_acl_any(mctx, &acl);
else
result = dns_acl_none(mctx, &acl);
if (result != ISC_R_SUCCESS)
goto cleanup;
result = ns_listenelt_create(mctx, port, dscp, acl, &elt);
if (result != ISC_R_SUCCESS)
goto cleanup_acl;
result = ns_listenlist_create(mctx, &list);
if (result != ISC_R_SUCCESS)
goto cleanup_listenelt;
ISC_LIST_APPEND(list->elts, elt, link);
*target = list;
return (ISC_R_SUCCESS);
cleanup_listenelt:
ns_listenelt_destroy(elt);
cleanup_acl:
dns_acl_detach(&acl);
cleanup:
return (result);
}

68
lib/ns/log.c Normal file
View File

@@ -0,0 +1,68 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <isc/result.h>
#include <isc/util.h>
#include <ns/log.h>
#ifndef ISC_FACILITY
#define ISC_FACILITY LOG_DAEMON
#endif
/*%
* When adding a new category, be sure to add the appropriate
* \#define to <ns/log.h>
*/
LIBNS_EXTERNAL_DATA isc_logcategory_t ns_categories[] = {
{ "client", 0 },
{ "network", 0 },
{ "update", 0 },
{ "queries", 0 },
{ "unmatched", 0 },
{ "update-security", 0 },
{ "query-errors", 0 },
{ NULL, 0 }
};
/*%
* When adding a new module, be sure to add the appropriate
* \#define to <ns/log.h>.
*/
LIBNS_EXTERNAL_DATA isc_logmodule_t ns_modules[] = {
{ "ns/main", 0 },
{ "ns/client", 0 },
{ "ns/server", 0 },
{ "ns/query", 0 },
{ "ns/interfacemgr", 0 },
{ "ns/update", 0 },
{ "ns/xfer-in", 0 },
{ "ns/xfer-out", 0 },
{ "ns/notify", 0 },
{ "ns/control", 0 },
{ NULL, 0 }
};
LIBNS_EXTERNAL_DATA isc_log_t *ns_lctx = NULL;
void
ns_log_init(isc_log_t *lctx) {
REQUIRE(lctx != NULL);
isc_log_registercategories(lctx, ns_categories);
isc_log_registermodules(lctx, ns_modules);
}
void
ns_log_setcontext(isc_log_t *lctx) {
ns_lctx = lctx;
}

164
lib/ns/notify.c Normal file
View File

@@ -0,0 +1,164 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <config.h>
#include <isc/log.h>
#include <isc/print.h>
#include <dns/message.h>
#include <dns/rdataset.h>
#include <dns/result.h>
#include <dns/tsig.h>
#include <dns/view.h>
#include <dns/zone.h>
#include <dns/zt.h>
#include <ns/log.h>
#include <ns/notify.h>
#include <ns/types.h>
/*! \file
* \brief
* This module implements notify as in RFC1996.
*/
static void
notify_log(ns_client_t *client, int level, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
ns_client_logv(client, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY,
level, fmt, ap);
va_end(ap);
}
static void
respond(ns_client_t *client, isc_result_t result) {
dns_rcode_t rcode;
dns_message_t *message;
isc_result_t msg_result;
message = client->message;
rcode = dns_result_torcode(result);
msg_result = dns_message_reply(message, ISC_TRUE);
if (msg_result != ISC_R_SUCCESS)
msg_result = dns_message_reply(message, ISC_FALSE);
if (msg_result != ISC_R_SUCCESS) {
ns_client_next(client, msg_result);
return;
}
message->rcode = rcode;
if (rcode == dns_rcode_noerror)
message->flags |= DNS_MESSAGEFLAG_AA;
else
message->flags &= ~DNS_MESSAGEFLAG_AA;
ns_client_send(client);
}
void
ns_notify_start(ns_client_t *client) {
dns_message_t *request = client->message;
isc_result_t result;
dns_name_t *zonename;
dns_rdataset_t *zone_rdataset;
dns_zone_t *zone = NULL;
char namebuf[DNS_NAME_FORMATSIZE];
char tsigbuf[DNS_NAME_FORMATSIZE + sizeof(": TSIG ''")];
dns_tsigkey_t *tsigkey;
/*
* Interpret the question section.
*/
result = dns_message_firstname(request, DNS_SECTION_QUESTION);
if (result != ISC_R_SUCCESS) {
notify_log(client, ISC_LOG_NOTICE,
"notify question section empty");
goto formerr;
}
/*
* The question section must contain exactly one question.
*/
zonename = NULL;
dns_message_currentname(request, DNS_SECTION_QUESTION, &zonename);
zone_rdataset = ISC_LIST_HEAD(zonename->list);
if (ISC_LIST_NEXT(zone_rdataset, link) != NULL) {
notify_log(client, ISC_LOG_NOTICE,
"notify question section contains multiple RRs");
goto formerr;
}
/* The zone section must have exactly one name. */
result = dns_message_nextname(request, DNS_SECTION_ZONE);
if (result != ISC_R_NOMORE) {
notify_log(client, ISC_LOG_NOTICE,
"notify question section contains multiple RRs");
goto formerr;
}
/* The one rdataset must be an SOA. */
if (zone_rdataset->type != dns_rdatatype_soa) {
notify_log(client, ISC_LOG_NOTICE,
"notify question section contains no SOA");
goto formerr;
}
tsigkey = dns_message_gettsigkey(request);
if (tsigkey != NULL) {
dns_name_format(&tsigkey->name, namebuf, sizeof(namebuf));
if (tsigkey->generated) {
char cnamebuf[DNS_NAME_FORMATSIZE];
dns_name_format(tsigkey->creator, cnamebuf,
sizeof(cnamebuf));
snprintf(tsigbuf, sizeof(tsigbuf), ": TSIG '%s' (%s)",
namebuf, cnamebuf);
} else {
snprintf(tsigbuf, sizeof(tsigbuf), ": TSIG '%s'",
namebuf);
}
} else
tsigbuf[0] = '\0';
dns_name_format(zonename, namebuf, sizeof(namebuf));
result = dns_zt_find(client->view->zonetable, zonename, 0, NULL,
&zone);
if (result != ISC_R_SUCCESS)
goto notauth;
switch (dns_zone_gettype(zone)) {
case dns_zone_master:
case dns_zone_slave:
case dns_zone_stub: /* Allow dialup passive to work. */
notify_log(client, ISC_LOG_INFO,
"received notify for zone '%s'%s", namebuf, tsigbuf);
respond(client, dns_zone_notifyreceive(zone,
ns_client_getsockaddr(client), request));
break;
default:
goto notauth;
}
dns_zone_detach(&zone);
return;
notauth:
notify_log(client, ISC_LOG_NOTICE,
"received notify for zone '%s'%s: not authoritative",
namebuf, tsigbuf);
result = DNS_R_NOTAUTH;
goto failure;
formerr:
result = DNS_R_FORMERR;
failure:
if (zone != NULL)
dns_zone_detach(&zone);
respond(client, result);
}

10041
lib/ns/query.c Normal file

File diff suppressed because it is too large Load Diff

257
lib/ns/server.c Normal file
View File

@@ -0,0 +1,257 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <isc/mem.h>
#include <isc/stats.h>
#include <dns/tkey.h>
#include <dns/stats.h>
#include <ns/server.h>
#include <ns/stats.h>
#define SCTX_MAGIC ISC_MAGIC('S','c','t','x')
#define SCTX_VALID(s) ISC_MAGIC_VALID(s, SCTX_MAGIC)
#define CHECKFATAL(op) \
do { result = (op); \
RUNTIME_CHECK(result == ISC_R_SUCCESS); \
} while (0) \
isc_result_t
ns_server_create(isc_mem_t *mctx, isc_entropy_t *entropy,
ns_matchview_t matchingview, ns_server_t **sctxp)
{
ns_server_t *sctx;
isc_result_t result;
REQUIRE(sctxp != NULL && *sctxp == NULL);
sctx = isc_mem_get(mctx, sizeof(*sctx));
if (sctx == NULL)
return (ISC_R_NOMEMORY);
memset(sctx, 0, sizeof(*sctx));
isc_mem_attach(mctx, &sctx->mctx);
result = isc_refcount_init(&sctx->references, 1);
if (result != ISC_R_SUCCESS)
goto cleanup;
CHECKFATAL(isc_quota_init(&sctx->xfroutquota, 10));
CHECKFATAL(isc_quota_init(&sctx->tcpquota, 10));
CHECKFATAL(isc_quota_init(&sctx->recursionquota, 100));
CHECKFATAL(dns_tkeyctx_create(mctx, entropy, &sctx->tkeyctx));
CHECKFATAL(ns_stats_create(mctx, ns_statscounter_max, &sctx->nsstats));
CHECKFATAL(dns_rdatatypestats_create(mctx, &sctx->rcvquerystats));
CHECKFATAL(dns_opcodestats_create(mctx, &sctx->opcodestats));
CHECKFATAL(dns_rcodestats_create(mctx, &sctx->rcodestats));
CHECKFATAL(isc_stats_create(mctx, &sctx->udpinstats4,
dns_sizecounter_in_max));
CHECKFATAL(isc_stats_create(mctx, &sctx->udpoutstats4,
dns_sizecounter_out_max));
CHECKFATAL(isc_stats_create(mctx, &sctx->udpinstats6,
dns_sizecounter_in_max));
CHECKFATAL(isc_stats_create(mctx, &sctx->udpoutstats6,
dns_sizecounter_out_max));
CHECKFATAL(isc_stats_create(mctx, &sctx->tcpinstats4,
dns_sizecounter_in_max));
CHECKFATAL(isc_stats_create(mctx, &sctx->tcpoutstats4,
dns_sizecounter_out_max));
CHECKFATAL(isc_stats_create(mctx, &sctx->tcpinstats6,
dns_sizecounter_in_max));
CHECKFATAL(isc_stats_create(mctx, &sctx->tcpoutstats6,
dns_sizecounter_out_max));
sctx->initialtimo = 300;
sctx->idletimo = 300;
sctx->keepalivetimo = 300;
sctx->advertisedtimo = 300;
sctx->udpsize = 4096;
sctx->transfer_tcp_message_size = 20480;
sctx->fuzztype = isc_fuzz_none;
sctx->fuzznotify = NULL;
sctx->gethostname = NULL;
sctx->matchingview = matchingview;
ISC_LIST_INIT(sctx->altsecrets);
sctx->magic = SCTX_MAGIC;
*sctxp = sctx;
return (ISC_R_SUCCESS);
cleanup:
isc_mem_putanddetach(&sctx->mctx, sctx, sizeof(*sctx));
return (result);
}
void
ns_server_attach(ns_server_t *src, ns_server_t **dest) {
REQUIRE(SCTX_VALID(src));
REQUIRE(dest != NULL && *dest == NULL);
isc_refcount_increment(&src->references, NULL);
*dest = src;
}
void
ns_server_detach(ns_server_t **sctxp) {
ns_server_t *sctx;
unsigned int refs;
REQUIRE(sctxp != NULL);
sctx = *sctxp;
REQUIRE(SCTX_VALID(sctx));
isc_refcount_decrement(&sctx->references, &refs);
if (refs == 0) {
ns_altsecret_t *altsecret;
sctx->magic = 0;
while ((altsecret = ISC_LIST_HEAD(sctx->altsecrets)) != NULL) {
ISC_LIST_UNLINK(sctx->altsecrets, altsecret, link);
isc_mem_put(sctx->mctx, altsecret, sizeof(*altsecret));
}
isc_quota_destroy(&sctx->recursionquota);
isc_quota_destroy(&sctx->tcpquota);
isc_quota_destroy(&sctx->xfroutquota);
if (sctx->server_id != NULL)
isc_mem_free(sctx->mctx, sctx->server_id);
if (sctx->blackholeacl != NULL)
dns_acl_detach(&sctx->blackholeacl);
if (sctx->keepresporder != NULL)
dns_acl_detach(&sctx->keepresporder);
if (sctx->tkeyctx != NULL)
dns_tkeyctx_destroy(&sctx->tkeyctx);
if (sctx->nsstats != NULL)
ns_stats_detach(&sctx->nsstats);
if (sctx->rcvquerystats != NULL)
dns_stats_detach(&sctx->rcvquerystats);
if (sctx->opcodestats != NULL)
dns_stats_detach(&sctx->opcodestats);
if (sctx->rcodestats != NULL)
dns_stats_detach(&sctx->rcodestats);
if (sctx->udpinstats4 != NULL)
isc_stats_detach(&sctx->udpinstats4);
if (sctx->tcpinstats4 != NULL)
isc_stats_detach(&sctx->tcpinstats4);
if (sctx->udpoutstats4 != NULL)
isc_stats_detach(&sctx->udpoutstats4);
if (sctx->tcpoutstats4 != NULL)
isc_stats_detach(&sctx->tcpoutstats4);
if (sctx->udpinstats6 != NULL)
isc_stats_detach(&sctx->udpinstats6);
if (sctx->tcpinstats6 != NULL)
isc_stats_detach(&sctx->tcpinstats6);
if (sctx->udpoutstats6 != NULL)
isc_stats_detach(&sctx->udpoutstats6);
if (sctx->tcpoutstats6 != NULL)
isc_stats_detach(&sctx->tcpoutstats6);
isc_mem_putanddetach(&sctx->mctx, sctx, sizeof(*sctx));
}
*sctxp = NULL;
}
isc_result_t
ns_server_setserverid(ns_server_t *sctx, const char *serverid) {
REQUIRE(SCTX_VALID(sctx));
if (sctx->server_id != NULL) {
isc_mem_free(sctx->mctx, sctx->server_id);
sctx->server_id = NULL;
}
if (serverid != NULL) {
sctx->server_id = isc_mem_strdup(sctx->mctx, serverid);
if (sctx->server_id == NULL)
return (ISC_R_NOMEMORY);
}
return (ISC_R_SUCCESS);
}
void
ns_server_settimeouts(ns_server_t *sctx, unsigned int initial,
unsigned int idle, unsigned int keepalive,
unsigned int advertised)
{
REQUIRE(SCTX_VALID(sctx));
sctx->initialtimo = initial;
sctx->idletimo = idle;
sctx->keepalivetimo = keepalive;
sctx->advertisedtimo = advertised;
}
void
ns_server_gettimeouts(ns_server_t *sctx, unsigned int *initial,
unsigned int *idle, unsigned int *keepalive,
unsigned int *advertised)
{
REQUIRE(SCTX_VALID(sctx));
REQUIRE(initial != NULL && idle != NULL &&
keepalive != NULL && advertised != NULL);
*initial = sctx->initialtimo;
*idle = sctx->idletimo;
*keepalive = sctx->keepalivetimo;
*advertised = sctx->advertisedtimo;
}
void
ns_server_setoption(ns_server_t *sctx, unsigned int option,
isc_boolean_t value)
{
REQUIRE(SCTX_VALID(sctx));
if (value) {
sctx->options |= option;
} else {
sctx->options &= ~option;
}
}
isc_boolean_t
ns_server_getoption(ns_server_t *sctx, unsigned int option) {
REQUIRE(SCTX_VALID(sctx));
return (ISC_TF((sctx->options & option) != 0));
}

163
lib/ns/sortlist.c Normal file
View File

@@ -0,0 +1,163 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <isc/mem.h>
#include <isc/util.h>
#include <dns/acl.h>
#include <dns/message.h>
#include <dns/result.h>
#include <ns/server.h>
#include <ns/sortlist.h>
ns_sortlisttype_t
ns_sortlist_setup(dns_acl_t *acl, dns_aclenv_t *env,
isc_netaddr_t *clientaddr, const void **argp)
{
unsigned int i;
if (acl == NULL)
goto dont_sort;
for (i = 0; i < acl->length; i++) {
/*
* 'e' refers to the current 'top level statement'
* in the sortlist (see ARM).
*/
dns_aclelement_t *e = &acl->elements[i];
dns_aclelement_t *try_elt;
dns_aclelement_t *order_elt = NULL;
const dns_aclelement_t *matched_elt = NULL;
if (e->type == dns_aclelementtype_nestedacl) {
dns_acl_t *inner = e->nestedacl;
if (inner->length == 0)
try_elt = e;
else if (inner->length > 2)
goto dont_sort;
else if (inner->elements[0].negative)
goto dont_sort;
else {
try_elt = &inner->elements[0];
if (inner->length == 2)
order_elt = &inner->elements[1];
}
} else {
/*
* BIND 8 allows bare elements at the top level
* as an undocumented feature.
*/
try_elt = e;
}
if (dns_aclelement_match(clientaddr, NULL, try_elt, env,
&matched_elt))
{
if (order_elt != NULL) {
if (order_elt->type ==
dns_aclelementtype_nestedacl)
{
*argp = order_elt->nestedacl;
return (NS_SORTLISTTYPE_2ELEMENT);
} else if (order_elt->type ==
dns_aclelementtype_localhost &&
env->localhost != NULL)
{
*argp = env->localhost;
return (NS_SORTLISTTYPE_2ELEMENT);
} else if (order_elt->type ==
dns_aclelementtype_localnets &&
env->localnets != NULL)
{
*argp = env->localnets;
return (NS_SORTLISTTYPE_2ELEMENT);
} else {
/*
* BIND 8 allows a bare IP prefix as
* the 2nd element of a 2-element
* sortlist statement.
*/
*argp = order_elt;
return (NS_SORTLISTTYPE_1ELEMENT);
}
} else {
INSIST(matched_elt != NULL);
*argp = matched_elt;
return (NS_SORTLISTTYPE_1ELEMENT);
}
}
}
/* No match; don't sort. */
dont_sort:
*argp = NULL;
return (NS_SORTLISTTYPE_NONE);
}
int
ns_sortlist_addrorder2(const isc_netaddr_t *addr, const void *arg) {
const dns_sortlist_arg_t *sla = (const dns_sortlist_arg_t *) arg;
const dns_aclenv_t *env = sla->env;
const dns_acl_t *sortacl = sla->acl;
int match;
(void)dns_acl_match(addr, NULL, sortacl, env, &match, NULL);
if (match > 0)
return (match);
else if (match < 0)
return (INT_MAX - (-match));
else
return (INT_MAX / 2);
}
int
ns_sortlist_addrorder1(const isc_netaddr_t *addr, const void *arg) {
const dns_sortlist_arg_t *sla = (const dns_sortlist_arg_t *) arg;
const dns_aclenv_t *env = sla->env;
const dns_aclelement_t *element = sla->element;
if (dns_aclelement_match(addr, NULL, element, env, NULL)) {
return (0);
}
return (INT_MAX);
}
void
ns_sortlist_byaddrsetup(dns_acl_t *sortlist_acl, dns_aclenv_t *env,
isc_netaddr_t *client_addr,
dns_addressorderfunc_t *orderp, const void **argp)
{
ns_sortlisttype_t sortlisttype;
sortlisttype = ns_sortlist_setup(sortlist_acl, env, client_addr, argp);
switch (sortlisttype) {
case NS_SORTLISTTYPE_1ELEMENT:
*orderp = ns_sortlist_addrorder1;
break;
case NS_SORTLISTTYPE_2ELEMENT:
*orderp = ns_sortlist_addrorder2;
break;
case NS_SORTLISTTYPE_NONE:
*orderp = NULL;
break;
default:
UNEXPECTED_ERROR(__FILE__, __LINE__,
"unexpected return from ns_sortlist_setup(): "
"%d", sortlisttype);
break;
}
}

125
lib/ns/stats.c Normal file
View File

@@ -0,0 +1,125 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/stats.h>
#include <isc/util.h>
#include <ns/stats.h>
#define NS_STATS_MAGIC ISC_MAGIC('N', 's', 't', 't')
#define NS_STATS_VALID(x) ISC_MAGIC_VALID(x, NS_STATS_MAGIC)
struct ns_stats {
/*% Unlocked */
unsigned int magic;
isc_mem_t *mctx;
isc_mutex_t lock;
isc_stats_t *counters;
/*% Locked by lock */
unsigned int references;
};
void
ns_stats_attach(ns_stats_t *stats, ns_stats_t **statsp) {
REQUIRE(NS_STATS_VALID(stats));
REQUIRE(statsp != NULL && *statsp == NULL);
LOCK(&stats->lock);
stats->references++;
UNLOCK(&stats->lock);
*statsp = stats;
}
void
ns_stats_detach(ns_stats_t **statsp) {
ns_stats_t *stats;
REQUIRE(statsp != NULL && NS_STATS_VALID(*statsp));
stats = *statsp;
*statsp = NULL;
LOCK(&stats->lock);
stats->references--;
UNLOCK(&stats->lock);
if (stats->references == 0) {
isc_stats_detach(&stats->counters);
DESTROYLOCK(&stats->lock);
isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
}
}
isc_result_t
ns_stats_create(isc_mem_t *mctx, int ncounters, ns_stats_t **statsp) {
ns_stats_t *stats;
isc_result_t result;
REQUIRE(statsp != NULL && *statsp == NULL);
stats = isc_mem_get(mctx, sizeof(*stats));
if (stats == NULL)
return (ISC_R_NOMEMORY);
stats->counters = NULL;
stats->references = 1;
result = isc_mutex_init(&stats->lock);
if (result != ISC_R_SUCCESS)
goto clean_stats;
result = isc_stats_create(mctx, &stats->counters, ncounters);
if (result != ISC_R_SUCCESS)
goto clean_mutex;
stats->magic = NS_STATS_MAGIC;
stats->mctx = NULL;
isc_mem_attach(mctx, &stats->mctx);
*statsp = stats;
return (ISC_R_SUCCESS);
clean_mutex:
DESTROYLOCK(&stats->lock);
clean_stats:
isc_mem_put(mctx, stats, sizeof(*stats));
return (result);
}
/*%
* Increment/Decrement methods
*/
void
ns_stats_increment(ns_stats_t *stats, isc_statscounter_t counter) {
REQUIRE(NS_STATS_VALID(stats));
isc_stats_increment(stats->counters, counter);
}
void
ns_stats_decrement(ns_stats_t *stats, isc_statscounter_t counter) {
REQUIRE(NS_STATS_VALID(stats));
isc_stats_decrement(stats->counters, counter);
}
isc_stats_t *
ns_stats_get(ns_stats_t *stats) {
REQUIRE(NS_STATS_VALID(stats));
return (stats->counters);
}

5
lib/ns/tests/Atffile Normal file
View File

@@ -0,0 +1,5 @@
Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = bind9
tp-glob: *_test

58
lib/ns/tests/Makefile.in Normal file
View File

@@ -0,0 +1,58 @@
# Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
# Attempt to disable parallel processing.
.NOTPARALLEL:
.NO_PARALLEL:
VERSION=@BIND9_VERSION@
@BIND9_MAKE_INCLUDES@
CINCLUDES = -I. -Iinclude ${NS_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES} \
@DST_OPENSSL_INC@
CDEFINES = @CRYPTO@ -DTESTS="\"${top_builddir}/lib/ns/tests/\""
ISCLIBS = ../../isc/libisc.@A@
ISCDEPLIBS = ../../isc/libisc.@A@
DNSLIBS = ../../dns/libdns.@A@ @DNS_CRYPTO_LIBS@
DNSDEPLIBS = ../../dns/libdns.@A@
NSLIBS = ../libns.@A@
NSDEPLIBS = ../libns.@A@
LIBS = @LIBS@ @ATFLIBS@
OBJS = nstest.@O@
SRCS = nstest.c \
listenlist_test.c \
notify_test.c
SUBDIRS =
TARGETS = listenlist_test@EXEEXT@ \
notify_test@EXEEXT@
@BIND9_MAKE_RULES@
listenlist_test@EXEEXT@: listenlist_test.@O@ nstest.@O@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
listenlist_test.@O@ nstest.@O@ ${NSLIBS} ${DNSLIBS} \
${ISCLIBS} ${LIBS}
notify_test@EXEEXT@: notify_test.@O@ nstest.@O@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
notify_test.@O@ nstest.@O@ ${NSLIBS} ${DNSLIBS} \
${ISCLIBS} ${LIBS}
unit::
sh ${top_srcdir}/unit/unittest.sh
clean distclean::
rm -f ${TARGETS}
rm -f atf.out

View File

@@ -0,0 +1,101 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <atf-c.h>
#include <stdio.h>
#include <unistd.h>
#include <isc/list.h>
#include <isc/print.h>
#include <dns/acl.h>
#include <ns/listenlist.h>
#include "nstest.h"
/*
* Helper functions
*/
ATF_TC(ns_listenlist_default);
ATF_TC_HEAD(ns_listenlist_default, tc) {
atf_tc_set_md_var(tc, "descr", "test that ns_listenlist_default works");
}
ATF_TC_BODY(ns_listenlist_default, tc) {
isc_result_t result;
ns_listenlist_t *list = NULL;
ns_listenelt_t *elt;
int count;
UNUSED(tc);
result = ns_test_begin(NULL, ISC_FALSE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = ns_listenlist_default(mctx, 5300, -1, ISC_FALSE, &list);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ATF_REQUIRE(list != NULL);
ATF_CHECK(!ISC_LIST_EMPTY(list->elts));
count = 0;
elt = ISC_LIST_HEAD(list->elts);
while (elt != NULL) {
ns_listenelt_t *next = ISC_LIST_NEXT(elt, link);
dns_acl_t *acl = NULL;
dns_acl_attach(elt->acl, &acl);
ISC_LIST_UNLINK(list->elts, elt, link);
ns_listenelt_destroy(elt);
elt = next;
ATF_CHECK(dns_acl_isnone(acl));
dns_acl_detach(&acl);
count++;
}
ATF_CHECK(ISC_LIST_EMPTY(list->elts));
ATF_CHECK_EQ(count, 1);
ns_listenlist_detach(&list);
result = ns_listenlist_default(mctx, 5300, -1, ISC_TRUE, &list);
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK(!ISC_LIST_EMPTY(list->elts));
/* This time just use ns_listenlist_detach() to destroy elements */
count = 0;
elt = ISC_LIST_HEAD(list->elts);
while (elt != NULL) {
ns_listenelt_t *next = ISC_LIST_NEXT(elt, link);
ATF_CHECK(dns_acl_isany(elt->acl));
elt = next;
count++;
}
ATF_CHECK_EQ(count, 1);
ns_listenlist_detach(&list);
ns_test_end();
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, ns_listenlist_default);
return (atf_no_error());
}

161
lib/ns/tests/notify_test.c Normal file
View File

@@ -0,0 +1,161 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <atf-c.h>
#include <stdio.h>
#include <unistd.h>
#include <isc/event.h>
#include <isc/print.h>
#include <isc/task.h>
#include <dns/acl.h>
#include <dns/rcode.h>
#include <dns/view.h>
#include <ns/client.h>
#include <ns/notify.h>
#include "nstest.h"
static dns_zone_t *zone = NULL;
static dns_view_t *view = NULL;
/*
* Helper functions
*/
static void
setup_zone(const char *zonename, const char *filename) {
isc_result_t result;
dns_db_t *db = NULL;
result = ns_test_makezone(zonename, &zone, NULL, ISC_TRUE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = ns_test_setupzonemgr();
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = ns_test_managezone(zone);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
view = dns_zone_getview(zone);
ATF_REQUIRE(view->zonetable != NULL);
view->nocookieudp = 512;
dns_zone_setfile(zone, filename);
result = dns_zone_load(zone);
ATF_REQUIRE(result == ISC_R_SUCCESS);
/* The zone should now be loaded; test it */
result = dns_zone_getdb(zone, &db);
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK(db != NULL);
if (db != NULL) {
dns_db_detach(&db);
}
}
static void
cleanup_zone() {
ns_test_releasezone(zone);
ns_test_closezonemgr();
dns_zone_detach(&zone);
dns_view_detach(&view);
}
static void
check_response(isc_buffer_t *buf) {
isc_result_t result;
dns_message_t *message = NULL;
char rcodebuf[20];
isc_buffer_t b;
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_message_parse(message, buf, 0);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
isc_buffer_init(&b, rcodebuf, sizeof(rcodebuf));
result = dns_rcode_totext(message->rcode, &b);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ATF_CHECK_EQ(message->rcode, dns_rcode_noerror);
dns_message_destroy(&message);
}
ATF_TC(notify_start);
ATF_TC_HEAD(notify_start, tc) {
atf_tc_set_md_var(tc, "descr", "notify start");
}
ATF_TC_BODY(notify_start, tc) {
isc_result_t result;
ns_client_t *client = NULL;
dns_message_t *nmsg = NULL;
unsigned char ndata[4096];
isc_buffer_t nbuf;
size_t nsize;
UNUSED(tc);
result = ns_test_begin(NULL, ISC_TRUE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = ns_test_getclient(NULL, ISC_FALSE, &client);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
setup_zone("example.com", "testdata/notify/zone1.db");
/*
* Create a NOTIFY message by parsing a file in testdata.
* (XXX: use better message mocking method when available.)
*/
result = ns_test_getdata("testdata/notify/notify1.msg",
ndata, sizeof(ndata), &nsize);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
isc_buffer_init(&nbuf, ndata, nsize);
isc_buffer_add(&nbuf, nsize);
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &nmsg);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_message_parse(nmsg, &nbuf, 0);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
/*
* Set up client object with this message and test the NOTIFY
* handler.
*/
dns_view_attach(view, &client->view);
client->message = nmsg;
nmsg = NULL;
client->sendcb = check_response;
ns_notify_start(client);
/*
* Clean up
*/
cleanup_zone();
ns_client_detach(&client);
ns_test_end();
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, notify_start);
return (atf_no_error());
}

552
lib/ns/tests/nstest.c Normal file
View File

@@ -0,0 +1,552 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <isc/app.h>
#include <isc/buffer.h>
#include <isc/entropy.h>
#include <isc/file.h>
#include <isc/hash.h>
#include <isc/mem.h>
#include <isc/os.h>
#include <isc/print.h>
#include <isc/string.h>
#include <isc/socket.h>
#include <isc/stdio.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
#include <dns/db.h>
#include <dns/dispatch.h>
#include <dns/fixedname.h>
#include <dns/log.h>
#include <dns/name.h>
#include <dns/result.h>
#include <dns/view.h>
#include <dns/zone.h>
#include <ns/client.h>
#include <ns/interfacemgr.h>
#include <ns/server.h>
#include "nstest.h"
isc_mem_t *mctx = NULL;
isc_entropy_t *ectx = NULL;
isc_log_t *lctx = NULL;
isc_taskmgr_t *taskmgr = NULL;
isc_task_t *maintask = NULL;
isc_timermgr_t *timermgr = NULL;
isc_socketmgr_t *socketmgr = NULL;
dns_zonemgr_t *zonemgr = NULL;
dns_dispatchmgr_t *dispatchmgr = NULL;
ns_clientmgr_t *clientmgr = NULL;
ns_interfacemgr_t *interfacemgr = NULL;
ns_server_t *sctx = NULL;
isc_boolean_t app_running = ISC_FALSE;
int ncpus;
isc_boolean_t debug_mem_record = ISC_TRUE;
isc_boolean_t run_managers = ISC_FALSE;
static isc_boolean_t hash_active = ISC_FALSE, dst_active = ISC_FALSE;
/*
* Logging categories: this needs to match the list in lib/ns/log.c.
*/
static isc_logcategory_t categories[] = {
{ "", 0 },
{ "client", 0 },
{ "network", 0 },
{ "update", 0 },
{ "queries", 0 },
{ "unmatched", 0 },
{ "update-security", 0 },
{ "query-errors", 0 },
{ NULL, 0 }
};
static isc_result_t
matchview(isc_netaddr_t *srcaddr, isc_netaddr_t *destaddr,
dns_message_t *message, dns_ecs_t *ecs,
isc_result_t *sigresultp, dns_view_t **viewp)
{
UNUSED(srcaddr);
UNUSED(destaddr);
UNUSED(message);
UNUSED(ecs);
UNUSED(sigresultp);
UNUSED(viewp);
return (ISC_R_NOTIMPLEMENTED);
}
/*
* These need to be shut down from a running task.
*/
isc_boolean_t shutdown_done = ISC_FALSE;
static void
shutdown_managers(isc_task_t *task, isc_event_t *event) {
UNUSED(task);
if (clientmgr != NULL) {
ns_clientmgr_destroy(&clientmgr);
}
if (interfacemgr != NULL) {
ns_interfacemgr_shutdown(interfacemgr);
ns_interfacemgr_detach(&interfacemgr);
}
if (dispatchmgr != NULL) {
dns_dispatchmgr_destroy(&dispatchmgr);
}
shutdown_done = ISC_TRUE;
run_managers = ISC_FALSE;
isc_event_free(&event);
}
static void
cleanup_managers(void) {
if (app_running)
isc_app_finish();
shutdown_done = ISC_FALSE;
if (maintask != NULL) {
isc_task_shutdown(maintask);
isc_task_destroy(&maintask);
}
while (run_managers && !shutdown_done) {
#ifndef ISC_PLATFORM_USETHREADS
while (isc__taskmgr_ready(taskmgr))
isc__taskmgr_dispatch(taskmgr);
#else
/*
* There's no straightforward way to determine
* whether all the clients have shut down, so
* we'll just sleep for a bit and hope.
*/
ns_test_nap(500000);
#endif
}
if (timermgr != NULL)
isc_timermgr_destroy(&timermgr);
if (sctx != NULL)
ns_server_detach(&sctx);
if (socketmgr != NULL)
isc_socketmgr_destroy(&socketmgr);
if (taskmgr != NULL)
isc_taskmgr_destroy(&taskmgr);
}
static void
scan_interfaces(isc_task_t *task, isc_event_t *event) {
UNUSED(task);
ns_interfacemgr_scan(interfacemgr, ISC_TRUE);
isc_event_free(&event);
}
static isc_result_t
create_managers(void) {
isc_result_t result;
ns_listenlist_t *listenon = NULL;
isc_event_t *event = NULL;
#ifdef ISC_PLATFORM_USETHREADS
ncpus = isc_os_ncpus();
#else
ncpus = 1;
#endif
CHECK(isc_taskmgr_create(mctx, ncpus, 0, &taskmgr));
CHECK(isc_task_create(taskmgr, 0, &maintask));
isc_taskmgr_setexcltask(taskmgr, maintask);
CHECK(isc_task_onshutdown(maintask, shutdown_managers, NULL));
CHECK(isc_timermgr_create(mctx, &timermgr));
CHECK(isc_socketmgr_create(mctx, &socketmgr));
CHECK(ns_server_create(mctx, ectx, matchview, &sctx));
CHECK(dns_dispatchmgr_create(mctx, ectx, &dispatchmgr));
CHECK(ns_interfacemgr_create(mctx, sctx, taskmgr, timermgr,
socketmgr, dispatchmgr, maintask,
ncpus, NULL, &interfacemgr));
CHECK(ns_clientmgr_create(mctx, sctx, taskmgr, timermgr,
&clientmgr));
CHECK(ns_listenlist_default(mctx, 5300, -1, ISC_TRUE, &listenon));
ns_interfacemgr_setlistenon4(interfacemgr, listenon);
ns_listenlist_detach(&listenon);
event = isc_event_allocate(mctx, maintask, ISC_TASKEVENT_TEST,
scan_interfaces, NULL,
sizeof (isc_event_t));
isc_task_send(maintask, &event);
#ifndef ISC_PLATFORM_USETHREADS
while (isc__taskmgr_ready(taskmgr))
isc__taskmgr_dispatch(taskmgr);
#else
/*
* There's no straightforward way to determine
* whether the interfaces have been scanned,
* we'll just sleep for a bit and hope.
*/
ns_test_nap(500000);
#endif
run_managers = ISC_TRUE;
return (ISC_R_SUCCESS);
cleanup:
cleanup_managers();
return (result);
}
isc_result_t
ns_test_begin(FILE *logfile, isc_boolean_t start_managers) {
isc_result_t result;
if (start_managers)
CHECK(isc_app_start());
if (debug_mem_record)
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
CHECK(isc_mem_create(0, 0, &mctx));
CHECK(isc_entropy_create(mctx, &ectx));
CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE));
hash_active = ISC_TRUE;
CHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_BLOCKING));
dst_active = ISC_TRUE;
if (logfile != NULL) {
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
CHECK(isc_log_create(mctx, &lctx, &logconfig));
isc_log_registercategories(lctx, categories);
isc_log_setcontext(lctx);
dns_log_init(lctx);
dns_log_setcontext(lctx);
destination.file.stream = logfile;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
CHECK(isc_log_createchannel(logconfig, "stderr",
ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC,
&destination, 0));
CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL));
}
dns_result_register();
if (start_managers)
CHECK(create_managers());
/*
* atf-run changes us to a /tmp directory, so tests
* that access test data files must first chdir to the proper
* location.
*/
if (chdir(TESTS) == -1)
CHECK(ISC_R_FAILURE);
return (ISC_R_SUCCESS);
cleanup:
ns_test_end();
return (result);
}
void
ns_test_end(void) {
if (dst_active) {
dst_lib_destroy();
dst_active = ISC_FALSE;
}
cleanup_managers();
if (hash_active) {
isc_hash_destroy();
hash_active = ISC_FALSE;
}
if (ectx != NULL)
isc_entropy_detach(&ectx);
if (lctx != NULL)
isc_log_destroy(&lctx);
if (mctx != NULL)
isc_mem_destroy(&mctx);
}
/*
* Create a view.
*/
isc_result_t
ns_test_makeview(const char *name, dns_view_t **viewp) {
isc_result_t result;
dns_view_t *view = NULL;
CHECK(dns_view_create(mctx, dns_rdataclass_in, name, &view));
*viewp = view;
return (ISC_R_SUCCESS);
cleanup:
if (view != NULL)
dns_view_detach(&view);
return (result);
}
/*
* Create a zone with origin 'name', return a pointer to the zone object in
* 'zonep'. If 'view' is set, add the zone to that view; otherwise, create
* a new view for the purpose.
*
* If the created view is going to be needed by the caller subsequently,
* then 'keepview' should be set to true; this will prevent the view
* from being detached. In this case, the caller is responsible for
* detaching the view.
*/
isc_result_t
ns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
isc_boolean_t keepview)
{
isc_result_t result;
dns_zone_t *zone = NULL;
isc_buffer_t buffer;
dns_fixedname_t fixorigin;
dns_name_t *origin;
if (view == NULL)
CHECK(dns_view_create(mctx, dns_rdataclass_in, "view", &view));
else if (!keepview)
keepview = ISC_TRUE;
zone = *zonep;
if (zone == NULL)
CHECK(dns_zone_create(&zone, mctx));
isc_buffer_constinit(&buffer, name, strlen(name));
isc_buffer_add(&buffer, strlen(name));
dns_fixedname_init(&fixorigin);
origin = dns_fixedname_name(&fixorigin);
CHECK(dns_name_fromtext(origin, &buffer, dns_rootname, 0, NULL));
CHECK(dns_zone_setorigin(zone, origin));
dns_zone_setview(zone, view);
dns_zone_settype(zone, dns_zone_master);
dns_zone_setclass(zone, view->rdclass);
dns_view_addzone(view, zone);
if (!keepview)
dns_view_detach(&view);
*zonep = zone;
return (ISC_R_SUCCESS);
cleanup:
if (zone != NULL)
dns_zone_detach(&zone);
if (view != NULL)
dns_view_detach(&view);
return (result);
}
isc_result_t
ns_test_setupzonemgr(void) {
isc_result_t result;
REQUIRE(zonemgr == NULL);
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
&zonemgr);
return (result);
}
isc_result_t
ns_test_managezone(dns_zone_t *zone) {
isc_result_t result;
REQUIRE(zonemgr != NULL);
result = dns_zonemgr_setsize(zonemgr, 1);
if (result != ISC_R_SUCCESS)
return (result);
result = dns_zonemgr_managezone(zonemgr, zone);
return (result);
}
void
ns_test_releasezone(dns_zone_t *zone) {
REQUIRE(zonemgr != NULL);
dns_zonemgr_releasezone(zonemgr, zone);
}
void
ns_test_closezonemgr(void) {
REQUIRE(zonemgr != NULL);
dns_zonemgr_shutdown(zonemgr);
dns_zonemgr_detach(&zonemgr);
}
isc_result_t
ns_test_getclient(ns_interface_t *ifp0, isc_boolean_t tcp,
ns_client_t **clientp)
{
isc_result_t result;
ns_interface_t *ifp = ifp0;
if (ifp == NULL) {
ifp = ns__interfacemgr_getif(interfacemgr);
}
if (ifp == NULL) {
return (ISC_R_FAILURE);
}
result = ns__clientmgr_getclient(clientmgr, ifp, tcp, clientp);
return (result);
}
/*
* Sleep for 'usec' microseconds.
*/
void
ns_test_nap(isc_uint32_t usec) {
#ifdef HAVE_NANOSLEEP
struct timespec ts;
ts.tv_sec = usec / 1000000;
ts.tv_nsec = (usec % 1000000) * 1000;
nanosleep(&ts, NULL);
#elif HAVE_USLEEP
usleep(usec);
#else
/*
* No fractional-second sleep function is available, so we
* round up to the nearest second and sleep instead
*/
sleep((usec / 1000000) + 1);
#endif
}
isc_result_t
ns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin,
const char *testfile)
{
isc_result_t result;
dns_fixedname_t fixed;
dns_name_t *name;
dns_fixedname_init(&fixed);
name = dns_fixedname_name(&fixed);
result = dns_name_fromstring(name, origin, 0, NULL);
if (result != ISC_R_SUCCESS)
return(result);
result = dns_db_create(mctx, "rbt", name, dbtype, dns_rdataclass_in,
0, NULL, db);
if (result != ISC_R_SUCCESS)
return (result);
result = dns_db_load(*db, testfile);
return (result);
}
static int
fromhex(char c) {
if (c >= '0' && c <= '9')
return (c - '0');
else if (c >= 'a' && c <= 'f')
return (c - 'a' + 10);
else if (c >= 'A' && c <= 'F')
return (c - 'A' + 10);
printf("bad input format: %02x\n", c);
exit(3);
/* NOTREACHED */
}
isc_result_t
ns_test_getdata(const char *file, unsigned char *buf,
size_t bufsiz, size_t *sizep)
{
isc_result_t result;
unsigned char *bp;
char *rp, *wp;
char s[BUFSIZ];
size_t len, i;
FILE *f = NULL;
int n;
result = isc_stdio_open(file, "r", &f);
if (result != ISC_R_SUCCESS)
return (result);
bp = buf;
while (fgets(s, sizeof(s), f) != NULL) {
rp = s;
wp = s;
len = 0;
while (*rp != '\0') {
if (*rp == '#')
break;
if (*rp != ' ' && *rp != '\t' &&
*rp != '\r' && *rp != '\n') {
*wp++ = *rp;
len++;
}
rp++;
}
if (len == 0U)
continue;
if (len % 2 != 0U)
CHECK(ISC_R_UNEXPECTEDEND);
if (len > bufsiz * 2)
CHECK(ISC_R_NOSPACE);
rp = s;
for (i = 0; i < len; i += 2) {
n = fromhex(*rp++);
n *= 16;
n += fromhex(*rp++);
*bp++ = n;
}
}
*sizep = bp - buf;
result = ISC_R_SUCCESS;
cleanup:
isc_stdio_close(f);
return (result);
}

90
lib/ns/tests/nstest.h Normal file
View File

@@ -0,0 +1,90 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <isc/buffer.h>
#include <isc/entropy.h>
#include <isc/hash.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
#include <dns/result.h>
#include <dns/zone.h>
#include <ns/interfacemgr.h>
#include <ns/client.h>
#define CHECK(r) \
do { \
result = (r); \
if (result != ISC_R_SUCCESS) \
goto cleanup; \
} while (0)
extern isc_mem_t *mctx;
extern isc_entropy_t *ectx;
extern isc_log_t *lctx;
extern isc_taskmgr_t *taskmgr;
extern isc_task_t *maintask;
extern isc_timermgr_t *timermgr;
extern isc_socketmgr_t *socketmgr;
extern dns_zonemgr_t *zonemgr;
extern dns_dispatchmgr_t *dispatchmgr;
extern ns_clientmgr_t *clientmgr;
extern ns_interfacemgr_t *interfacemgr;
extern ns_server_t *sctx;
extern isc_boolean_t app_running;
extern int ncpus;
extern isc_boolean_t debug_mem_record;
isc_result_t
ns_test_begin(FILE *logfile, isc_boolean_t create_managers);
void
ns_test_end(void);
isc_result_t
ns_test_makeview(const char *name, dns_view_t **viewp);
isc_result_t
ns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
isc_boolean_t keepview);
isc_result_t
ns_test_setupzonemgr(void);
isc_result_t
ns_test_managezone(dns_zone_t *zone);
void
ns_test_releasezone(dns_zone_t *zone);
void
ns_test_closezonemgr(void);
void
ns_test_nap(isc_uint32_t usec);
isc_result_t
ns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin,
const char *testfile);
isc_result_t
ns_test_getdata(const char *file, unsigned char *buf,
size_t bufsiz, size_t *sizep);
isc_result_t
ns_test_getclient(ns_interface_t *ifp0, isc_boolean_t tcp,
ns_client_t **clientp);

View File

@@ -0,0 +1,3 @@
# notify for example.com
10 a6 10 10 00 01 00 00 00 00 00 00 07 65 78 61
6d 70 6c 65 03 63 6f 6d 00 00 06 00 01

21
lib/ns/tests/testdata/notify/zone1.db vendored Normal file
View File

@@ -0,0 +1,21 @@
; Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
;
; This Source Code Form is subject to the terms of the Mozilla Public
; License, v. 2.0. If a copy of the MPL was not distributed with this
; file, You can obtain one at http://mozilla.org/MPL/2.0/.
$TTL 1000
@ in soa localhost. postmaster.localhost. (
1993050801 ;serial
3600 ;refresh
1800 ;retry
604800 ;expiration
3600 ) ;minimum
in ns ns.example.com.
in ns ns2.example.com.
in ns ns3.example.com.
ns in a 10.0.0.1
ns2 in a 10.0.0.2
ns3 in a 10.0.0.3
a in a 1.2.3.4

3496
lib/ns/update.c Normal file

File diff suppressed because it is too large Load Diff

17
lib/ns/version.c Normal file
View File

@@ -0,0 +1,17 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <ns/version.h>
const char ns_version[] = VERSION;
const unsigned int ns_libinterface = LIBINTERFACE;
const unsigned int ns_librevision = LIBREVISION;
const unsigned int ns_libage = LIBAGE;

48
lib/ns/win32/DLLMain.c Normal file
View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: DLLMain.c,v 1.6 2007/06/18 23:47:44 tbox Exp $ */
#include <windows.h>
#include <signal.h>
/*
* Called when we enter the DLL
*/
__declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL,
DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason) {
/*
* The DLL is loading due to process
* initialization or a call to LoadLibrary.
*/
case DLL_PROCESS_ATTACH:
break;
/* The attached process creates a new thread. */
case DLL_THREAD_ATTACH:
break;
/* The thread of the attached process terminates. */
case DLL_THREAD_DETACH:
break;
/*
* The DLL is unloading from a process due to
* process termination or a call to FreeLibrary.
*/
case DLL_PROCESS_DETACH:
break;
default:
break;
}
return (TRUE);
}

80
lib/ns/win32/libns.def Normal file
View File

@@ -0,0 +1,80 @@
LIBRARY libns
; Exported Functions
EXPORTS
ns_client_aclmsg
ns_client_addopt
ns_client_attach
ns_client_checkacl
ns_client_checkaclsilent
ns_client_detach
ns_client_dumprecursing
ns_client_error
ns_client_getsockaddr
ns_client_killoldestquery
ns_client_log
ns_client_logv
ns_client_next
ns_client_qnamereplace
ns_client_recursing
ns_client_replace
ns_client_send
ns_client_sendraw
ns_client_settimeout
ns_client_shuttingdown
ns_client_sourceip
ns_clientmgr_create
ns_clientmgr_createclients
ns_clientmgr_destroy
ns_interface_attach
ns_interface_detach
ns_interface_shutdown
ns_interfacemgr_adjust
ns_interfacemgr_attach
ns_interfacemgr_create
ns_interfacemgr_detach
ns_interfacemgr_dumprecursing
ns_interfacemgr_getaclenv
ns_interfacemgr_islistening
ns_interfacemgr_listeningon
ns_interfacemgr_scan
ns_interfacemgr_setbacklog
ns_interfacemgr_setlistenon4
ns_interfacemgr_setlistenon6
ns_interfacemgr_shutdown
ns_lib_init
ns_lib_shutdown
ns_listenelt_create
ns_listenelt_destroy
ns_listenlist_attach
ns_listenlist_create
ns_listenlist_default
ns_listenlist_detach
ns_log_init
ns_log_setcontext
ns_notify_start
ns_query_cancel
ns_query_free
ns_query_init
ns_query_start
ns_server_attach
ns_server_create
ns_server_detach
ns_server_getoption
ns_server_gettimeouts
ns_server_setoption
ns_server_setserverid
ns_server_settimeouts
ns_sortlist_addrorder1
ns_sortlist_addrorder2
ns_sortlist_byaddrsetup
ns_sortlist_setup
ns_stats_attach
ns_stats_create
ns_stats_decrement
ns_stats_detach
ns_stats_get
ns_stats_increment
ns_update_start
ns_xfr_start

View File

@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="libns.def" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="DLLMain.c">
<Filter>Library Source Files</Filter>
</ClCompile>
<ClCompile Include="version.c">
<Filter>Library Source Files</Filter>
</ClCompile>
<ClCompile Include="..\client.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\interfacemgr.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\lib.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\listenlist.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\log.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\notify.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\query.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\server.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\sortlist.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\stats.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\update.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\xfrout.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\ns\client.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\interfacemgr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\lib.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\listenlist.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\log.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\notify.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\query.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\server.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\sortlist.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\stats.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\types.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\update.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\version.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ns\xfrout.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|@PLATFORM@">
<Configuration>Debug</Configuration>
<Platform>@PLATFORM@</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|@PLATFORM@">
<Configuration>Release</Configuration>
<Platform>@PLATFORM@</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{82ACD33C-E75F-45B8-BB6D-42643A10D7EE}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>libns</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@PLATFORM@'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|@PLATFORM@'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|@PLATFORM@'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|@PLATFORM@'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@PLATFORM@'">
<LinkIncremental>true</LinkIncremental>
<OutDir>..\..\..\Build\$(Configuration)\</OutDir>
<IntDir>.\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|@PLATFORM@'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\..\..\Build\$(Configuration)\</OutDir>
<IntDir>.\$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@PLATFORM@'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;@CRYPTO@@USE_GSSAPI@_DEBUG;_USRDLL;LIBNS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.\;..\..\..\;include;..\include;..\..\isc\win32;..\..\isc\win32\include;..\..\isc\include;..\..\..\lib\dns\include;@LIBXML2_INC@@OPENSSL_INC@@GSSAPI_INC@@GEOIP_INC@%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeaderOutputFile>.\$(Configuration)\$(TargetName).pch</PrecompiledHeaderOutputFile>
<AssemblerListingLocation>.\$(Configuration)\</AssemblerListingLocation>
<ObjectFileName>.\$(Configuration)\</ObjectFileName>
<ProgramDataBaseFileName>$(OutDir)$(TargetName).pdb</ProgramDataBaseFileName>
<BrowseInformation>true</BrowseInformation>
<CompileAs>CompileAsC</CompileAs>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>..\..\..\Build\$(Configuration)\$(TargetName)$(TargetExt)</OutputFile>
<AdditionalLibraryDirectories>..\..\isc\win32\$(Configuration);..\..\..\lib\dns\win32\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>libisc.lib;libdns.lib;@LIBXML2_LIB@@OPENSSL_LIB@@GSSAPI_LIB@@GEOIP_LIB@ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>$(ProjectName).def</ModuleDefinitionFile>
<ImportLibrary>.\$(Configuration)\$(ProjectName).lib</ImportLibrary>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|@PLATFORM@'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>@INTRINSIC@</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;@CRYPTO@@USE_GSSAPI@NDEBUG;_USRDLL;LIBNS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.\;..\..\..\;include;..\include;..\..\isc\win32;..\..\isc\win32\include;..\..\isc\include;..\..\..\lib\dns\include;@LIBXML2_INC@@OPENSSL_INC@@GSSAPI_INC@@GEOIP_INC@%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<StringPooling>true</StringPooling>
<PrecompiledHeaderOutputFile>.\$(Configuration)\$(TargetName).pch</PrecompiledHeaderOutputFile>
<AssemblerListingLocation>.\$(Configuration)\</AssemblerListingLocation>
<ObjectFileName>.\$(Configuration)\</ObjectFileName>
<ProgramDataBaseFileName>$(OutDir)$(TargetName).pdb</ProgramDataBaseFileName>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CompileAs>CompileAsC</CompileAs>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<OutputFile>..\..\..\Build\$(Configuration)\$(TargetName)$(TargetExt)</OutputFile>
<AdditionalLibraryDirectories>..\..\isc\win32\$(Configuration);..\..\..\lib\dns\win32\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>libisc.lib;libdns.lib;@LIBXML2_LIB@@OPENSSL_LIB@@GSSAPI_LIB@@GEOIP_LIB@ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>$(ProjectName).def</ModuleDefinitionFile>
<ImportLibrary>.\$(Configuration)\$(ProjectName).lib</ImportLibrary>
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="libns.def" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\client.c" />
<ClCompile Include="..\interfacemgr.c" />
<ClCompile Include="..\lib.c" />
<ClCompile Include="..\listenlist.c" />
<ClCompile Include="..\log.c" />
<ClCompile Include="..\notify.c" />
<ClCompile Include="..\query.c" />
<ClCompile Include="..\server.c" />
<ClCompile Include="..\sortlist.c" />
<ClCompile Include="..\stats.c" />
<ClCompile Include="..\update.c" />
<ClCompile Include="..\xfrout.c" />
<ClCompile Include="DLLMain.c" />
<ClCompile Include="version.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\ns\client.h" />
<ClInclude Include="..\include\ns\interfacemgr.h" />
<ClInclude Include="..\include\ns\lib.h" />
<ClInclude Include="..\include\ns\listenlist.h" />
<ClInclude Include="..\include\ns\log.h" />
<ClInclude Include="..\include\ns\notify.h" />
<ClInclude Include="..\include\ns\query.h" />
<ClInclude Include="..\include\ns\server.h" />
<ClInclude Include="..\include\ns\sortlist.h" />
<ClInclude Include="..\include\ns\stats.h" />
<ClInclude Include="..\include\ns\types.h" />
<ClInclude Include="..\include\ns\update.h" />
<ClInclude Include="..\include\ns\version.h" />
<ClInclude Include="..\include\ns\xfrout.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

21
lib/ns/win32/version.c Normal file
View File

@@ -0,0 +1,21 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <versions.h>
#include <ns/version.h>
LIBNS_EXTERNAL_DATA const char ns_version[] = VERSION;
LIBNS_EXTERNAL_DATA const char ns_major[] = MAJOR;
LIBNS_EXTERNAL_DATA const char ns_mapapi[] = MAPAPI;
LIBNS_EXTERNAL_DATA const unsigned int ns_libinterface = LIBINTERFACE;
LIBNS_EXTERNAL_DATA const unsigned int ns_librevision = LIBREVISION;
LIBNS_EXTERNAL_DATA const unsigned int ns_libage = LIBAGE;

1709
lib/ns/xfrout.c Normal file

File diff suppressed because it is too large Load Diff