summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorJakob Schlyter <jakob@cvs.openbsd.org>2010-01-15 19:25:01 +0000
committerJakob Schlyter <jakob@cvs.openbsd.org>2010-01-15 19:25:01 +0000
commit49e3fcbd01470accc046e592ea6625ecdccef0cb (patch)
treeadbfa5757b84776f97e2a818eb282c11c2222872 /usr.sbin
parentfff9e6573cd5ae10c6c83f6cd9d6996392fd0f7c (diff)
NSD v3.2.4
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/nsd/dbaccess.c903
-rw-r--r--usr.sbin/nsd/dname.h9
-rw-r--r--usr.sbin/nsd/options.h207
-rw-r--r--usr.sbin/nsd/packet.h18
-rw-r--r--usr.sbin/nsd/rbtree.c2
-rw-r--r--usr.sbin/nsd/region-allocator.h39
6 files changed, 377 insertions, 801 deletions
diff --git a/usr.sbin/nsd/dbaccess.c b/usr.sbin/nsd/dbaccess.c
index 4e11977d6bd..83cd5e2eb62 100644
--- a/usr.sbin/nsd/dbaccess.c
+++ b/usr.sbin/nsd/dbaccess.c
@@ -7,7 +7,7 @@
*
*/
-#include "config.h"
+#include <config.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -17,647 +17,444 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
+#include <stdio.h> /* DEBUG */
#include "dns.h"
#include "namedb.h"
#include "util.h"
#include "options.h"
-#include "rdata.h"
-#include "udb.h"
-#include "udbradtree.h"
-#include "udbzone.h"
-#include "zonec.h"
-#include "nsec3.h"
-#include "difffile.h"
-#include "nsd.h"
-
-static time_t udb_time = 0;
-static unsigned long udb_rrsets = 0;
-static unsigned long udb_rrset_count = 0;
-void
-namedb_close(struct namedb* db)
+int
+namedb_lookup(struct namedb *db,
+ const dname_type *dname,
+ domain_type **closest_match,
+ domain_type **closest_encloser)
{
- if(db) {
- if(db->udb) {
- udb_base_close(db->udb);
- udb_base_free(db->udb);
- db->udb = NULL;
- }
- zonec_desetup_parser();
- region_destroy(db->region);
- }
+ return domain_table_search(
+ db->domains, dname, closest_match, closest_encloser);
}
-void
-namedb_close_udb(struct namedb* db)
+static int
+read_magic(namedb_type *db)
{
- if(db) {
- /* we cannot actually munmap the data, because other
- * processes still need to access the udb, so cleanup the
- * udb */
- udb_base_free_keep_mmap(db->udb);
- db->udb = NULL;
- }
+ char buf[NAMEDB_MAGIC_SIZE];
+
+ if (fread(buf, sizeof(char), sizeof(buf), db->fd) != sizeof(buf))
+ return 0;
+
+ return memcmp(buf, NAMEDB_MAGIC, NAMEDB_MAGIC_SIZE) == 0;
}
-void
-apex_rrset_checks(namedb_type* db, rrset_type* rrset, domain_type* domain)
+static const dname_type *
+read_dname(FILE *fd, region_type *region)
{
- uint32_t soa_minimum;
- unsigned i;
- zone_type* zone = rrset->zone;
- assert(domain == zone->apex);
- (void)domain;
- if (rrset_rrtype(rrset) == TYPE_SOA) {
- zone->soa_rrset = rrset;
+ uint8_t size;
+ uint8_t temp[MAXDOMAINLEN];
- /* BUG #103 add another soa with a tweaked ttl */
- if(zone->soa_nx_rrset == 0) {
- zone->soa_nx_rrset = region_alloc(db->region,
- sizeof(rrset_type));
- zone->soa_nx_rrset->rr_count = 1;
- zone->soa_nx_rrset->next = 0;
- zone->soa_nx_rrset->zone = zone;
- zone->soa_nx_rrset->rrs = region_alloc(db->region,
- sizeof(rr_type));
- }
- memcpy(zone->soa_nx_rrset->rrs, rrset->rrs, sizeof(rr_type));
+ if (fread(&size, sizeof(uint8_t), 1, fd) != 1)
+ return NULL;
+ if (fread(temp, sizeof(uint8_t), size, fd) != size)
+ return NULL;
- /* check the ttl and MINIMUM value and set accordinly */
- memcpy(&soa_minimum, rdata_atom_data(rrset->rrs->rdatas[6]),
- rdata_atom_size(rrset->rrs->rdatas[6]));
- if (rrset->rrs->ttl > ntohl(soa_minimum)) {
- zone->soa_nx_rrset->rrs[0].ttl = ntohl(soa_minimum);
- }
- } else if (rrset_rrtype(rrset) == TYPE_NS) {
- zone->ns_rrset = rrset;
- } else if (rrset_rrtype(rrset) == TYPE_RRSIG) {
- for (i = 0; i < rrset->rr_count; ++i) {
- if(rr_rrsig_type_covered(&rrset->rrs[i])==TYPE_DNSKEY){
- zone->is_secure = 1;
- break;
- }
- }
- }
+ return dname_make(region, temp, 1);
}
-/** read rr */
-static void
-read_rr(namedb_type* db, rr_type* rr, udb_ptr* urr, domain_type* domain)
+static int
+read_size(namedb_type *db, uint32_t *result)
{
- buffer_type buffer;
- ssize_t c;
- assert(udb_ptr_get_type(urr) == udb_chunk_type_rr);
- rr->owner = domain;
- rr->type = RR(urr)->type;
- rr->klass = RR(urr)->klass;
- rr->ttl = RR(urr)->ttl;
-
- buffer_create_from(&buffer, RR(urr)->wire, RR(urr)->len);
- c = rdata_wireformat_to_rdata_atoms(db->region, db->domains,
- rr->type, RR(urr)->len, &buffer, &rr->rdatas);
- if(c == -1) {
- /* safe on error */
- rr->rdata_count = 0;
- rr->rdatas = NULL;
- return;
+ if (fread(result, sizeof(*result), 1, db->fd) == 1) {
+ *result = ntohl(*result);
+ return 1;
+ } else {
+ return 0;
}
- rr->rdata_count = c;
}
-/** calculate rr count */
-static uint16_t
-calculate_rr_count(udb_base* udb, udb_ptr* rrset)
+static domain_type *
+read_domain(namedb_type *db, uint32_t domain_count, domain_type **domains)
{
- udb_ptr rr;
- uint16_t num = 0;
- udb_ptr_new(&rr, udb, &RRSET(rrset)->rrs);
- while(rr.data) {
- num++;
- udb_ptr_set_rptr(&rr, udb, &RR(&rr)->next);
- }
- udb_ptr_unlink(&rr, udb);
- return num;
+ uint32_t domain_number;
+
+ if (!read_size(db, &domain_number))
+ return NULL;
+
+ if (domain_number == 0 || domain_number > domain_count)
+ return NULL;
+
+ return domains[domain_number - 1];
}
-/** read rrset */
-static void
-read_rrset(udb_base* udb, namedb_type* db, zone_type* zone,
- domain_type* domain, udb_ptr* urrset)
+static zone_type *
+read_zone(namedb_type *db, uint32_t zone_count, zone_type **zones)
{
- rrset_type* rrset;
- udb_ptr urr;
- unsigned i;
- assert(udb_ptr_get_type(urrset) == udb_chunk_type_rrset);
- /* if no RRs, do not create anything (robust) */
- if(RRSET(urrset)->rrs.data == 0)
- return;
- rrset = (rrset_type *) region_alloc(db->region, sizeof(rrset_type));
- rrset->zone = zone;
- rrset->rr_count = calculate_rr_count(udb, urrset);
- rrset->rrs = (rr_type *) region_alloc_array(
- db->region, rrset->rr_count, sizeof(rr_type));
- /* add the RRs */
- udb_ptr_new(&urr, udb, &RRSET(urrset)->rrs);
- for(i=0; i<rrset->rr_count; i++) {
- read_rr(db, &rrset->rrs[i], &urr, domain);
- udb_ptr_set_rptr(&urr, udb, &RR(&urr)->next);
- }
- udb_ptr_unlink(&urr, udb);
- domain_add_rrset(domain, rrset);
- if(domain == zone->apex)
- apex_rrset_checks(db, rrset, domain);
+ uint32_t zone_number;
+
+ if (!read_size(db, &zone_number))
+ return NULL;
+
+ if (zone_number == 0 || zone_number > zone_count)
+ return NULL;
+
+ return zones[zone_number - 1];
}
-/** read one elem from db, of type domain_d */
-static void read_node_elem(udb_base* udb, namedb_type* db,
- region_type* dname_region, zone_type* zone, struct domain_d* d)
+static int
+read_rdata_atom(namedb_type *db, uint16_t type, int index, uint32_t domain_count, domain_type **domains, rdata_atom_type *result)
{
- const dname_type* dname;
- domain_type* domain;
- udb_ptr urrset;
-
- dname = dname_make(dname_region, d->name, 0);
- if(!dname) return;
- domain = domain_table_insert(db->domains, dname);
- assert(domain); /* domain_table_insert should always return non-NULL */
-
- /* add rrsets */
- udb_ptr_init(&urrset, udb);
- udb_ptr_set_rptr(&urrset, udb, &d->rrsets);
- while(urrset.data) {
- read_rrset(udb, db, zone, domain, &urrset);
- udb_ptr_set_rptr(&urrset, udb, &RRSET(&urrset)->next);
-
- if(++udb_rrsets % ZONEC_PCT_COUNT == 0 && time(NULL) > udb_time + ZONEC_PCT_TIME) {
- udb_time = time(NULL);
- VERBOSITY(1, (LOG_INFO, "read %s %d %%",
- zone->opts->name,
- (int)(udb_rrsets*((unsigned long)100)/udb_rrset_count)));
- }
+ uint8_t data[65536];
+
+ if (rdata_atom_is_domain(type, index)) {
+ result->domain = read_domain(db, domain_count, domains);
+ if (!result->domain)
+ return 0;
+ } else {
+ uint16_t size;
+
+ if (fread(&size, sizeof(size), 1, db->fd) != 1)
+ return 0;
+ size = ntohs(size);
+ if (fread(data, sizeof(uint8_t), size, db->fd) != size)
+ return 0;
+
+ result->data = (uint16_t *) region_alloc(
+ db->region, sizeof(uint16_t) + size);
+ memcpy(result->data, &size, sizeof(uint16_t));
+ memcpy((uint8_t *) result->data + sizeof(uint16_t), data, size);
}
- region_free_all(dname_region);
- udb_ptr_unlink(&urrset, udb);
+
+ return 1;
}
-/** recurse read radix from disk. This radix tree is by domain name, so max of
- * 256 depth, and thus the stack usage is small. */
-static void read_zone_recurse(udb_base* udb, namedb_type* db,
- region_type* dname_region, zone_type* zone, struct udb_radnode_d* node)
+static rrset_type *
+read_rrset(namedb_type *db,
+ uint32_t domain_count, domain_type **domains,
+ uint32_t zone_count, zone_type **zones)
{
- if(node->elem.data) {
- /* pre-order process of node->elem, for radix tree this is
- * also in-order processing (identical to order tree_next()) */
- read_node_elem(udb, db, dname_region, zone, (struct domain_d*)
- (udb->base + node->elem.data));
- }
- if(node->lookup.data) {
- uint16_t i;
- struct udb_radarray_d* a = (struct udb_radarray_d*)
- (udb->base + node->lookup.data);
- /* we do not care for what the exact radix key is, we want
- * to add all of them and the read routine does not need
- * the radix-key, it has it stored */
- for(i=0; i<a->len; i++) {
- if(a->array[i].node.data) {
- read_zone_recurse(udb, db, dname_region, zone,
- (struct udb_radnode_d*)(udb->base +
- a->array[i].node.data));
- }
+ rrset_type *rrset;
+ int i, j;
+ domain_type *owner;
+ uint16_t type;
+ uint16_t klass;
+ uint32_t soa_minimum;
+
+ owner = read_domain(db, domain_count, domains);
+ if (!owner)
+ return NULL;
+
+ rrset = (rrset_type *) region_alloc(db->region, sizeof(rrset_type));
+
+ rrset->zone = read_zone(db, zone_count, zones);
+ if (!rrset->zone)
+ return NULL;
+
+ if (fread(&type, sizeof(type), 1, db->fd) != 1)
+ return NULL;
+ type = ntohs(type);
+
+ if (fread(&klass, sizeof(klass), 1, db->fd) != 1)
+ return NULL;
+ klass = ntohs(klass);
+
+ if (fread(&rrset->rr_count, sizeof(rrset->rr_count), 1, db->fd) != 1)
+ return NULL;
+ rrset->rr_count = ntohs(rrset->rr_count);
+ rrset->rrs = (rr_type *) region_alloc(
+ db->region, rrset->rr_count * sizeof(rr_type));
+
+ assert(rrset->rr_count > 0);
+
+ for (i = 0; i < rrset->rr_count; ++i) {
+ rr_type *rr = &rrset->rrs[i];
+
+ rr->owner = owner;
+ rr->type = type;
+ rr->klass = klass;
+
+ if (fread(&rr->rdata_count, sizeof(rr->rdata_count), 1, db->fd) != 1)
+ return NULL;
+ rr->rdata_count = ntohs(rr->rdata_count);
+ rr->rdatas = (rdata_atom_type *) region_alloc(
+ db->region, rr->rdata_count * sizeof(rdata_atom_type));
+
+ if (fread(&rr->ttl, sizeof(rr->ttl), 1, db->fd) != 1)
+ return NULL;
+ rr->ttl = ntohl(rr->ttl);
+
+ for (j = 0; j < rr->rdata_count; ++j) {
+ if (!read_rdata_atom(db, rr->type, j, domain_count, domains, &rr->rdatas[j]))
+ return NULL;
}
}
-}
-/** read zone data */
-static void
-read_zone_data(udb_base* udb, namedb_type* db, region_type* dname_region,
- udb_ptr* z, zone_type* zone)
-{
- udb_ptr dtree;
- /* recursively read domains, we only read so ptrs stay valid */
- udb_ptr_new(&dtree, udb, &ZONE(z)->domains);
- if(RADTREE(&dtree)->root.data)
- read_zone_recurse(udb, db, dname_region, zone,
- (struct udb_radnode_d*)
- (udb->base + RADTREE(&dtree)->root.data));
- udb_ptr_unlink(&dtree, udb);
-}
+ domain_add_rrset(owner, rrset);
-/** create a zone */
-zone_type*
-namedb_zone_create(namedb_type* db, const dname_type* dname,
- zone_options_t* zo)
-{
- zone_type* zone = (zone_type *) region_alloc(db->region,
- sizeof(zone_type));
- zone->node = radname_insert(db->zonetree, dname_name(dname),
- dname->name_size, zone);
- assert(zone->node);
- zone->apex = domain_table_insert(db->domains, dname);
- zone->apex->usage++; /* the zone.apex reference */
- zone->apex->is_apex = 1;
- zone->soa_rrset = NULL;
- zone->soa_nx_rrset = NULL;
- zone->ns_rrset = NULL;
-#ifdef NSEC3
- zone->nsec3_param = NULL;
- zone->nsec3_last = NULL;
- zone->nsec3tree = NULL;
- zone->hashtree = NULL;
- zone->wchashtree = NULL;
- zone->dshashtree = NULL;
-#endif
- zone->opts = zo;
- zone->filename = NULL;
- zone->logstr = NULL;
- zone->mtime = 0;
- zone->zonestatid = 0;
- zone->is_secure = 0;
- zone->is_changed = 0;
- zone->is_ok = 1;
- return zone;
-}
+ if (rrset_rrtype(rrset) == TYPE_SOA) {
+ assert(owner == rrset->zone->apex);
+ rrset->zone->soa_rrset = rrset;
-void
-namedb_zone_delete(namedb_type* db, zone_type* zone)
-{
- /* RRs and UDB and NSEC3 and so on must be already deleted */
- radix_delete(db->zonetree, zone->node);
-
- /* see if apex can be deleted */
- if(zone->apex) {
- zone->apex->usage --;
- zone->apex->is_apex = 0;
- if(zone->apex->usage == 0) {
- /* delete the apex, possibly */
- domain_table_deldomain(db, zone->apex);
+ /* BUG #103 add another soa with a tweaked ttl */
+ rrset->zone->soa_nx_rrset = region_alloc(db->region, sizeof(rrset_type));
+ rrset->zone->soa_nx_rrset->rrs =
+ region_alloc(db->region, rrset->rr_count * sizeof(rr_type));
+
+ memcpy(rrset->zone->soa_nx_rrset->rrs, rrset->rrs, sizeof(rr_type));
+ rrset->zone->soa_nx_rrset->rr_count = 1;
+ rrset->zone->soa_nx_rrset->next = 0;
+
+ /* also add a link to the zone */
+ rrset->zone->soa_nx_rrset->zone = rrset->zone;
+
+ /* check the ttl and MINIMUM value and set accordinly */
+ memcpy(&soa_minimum, rdata_atom_data(rrset->rrs->rdatas[6]),
+ rdata_atom_size(rrset->rrs->rdatas[6]));
+ if (rrset->rrs->ttl > ntohl(soa_minimum)) {
+ rrset->zone->soa_nx_rrset->rrs[0].ttl = ntohl(soa_minimum);
}
- }
- /* soa_rrset is freed when the SOA was deleted */
- if(zone->soa_nx_rrset) {
- region_recycle(db->region, zone->soa_nx_rrset->rrs,
- sizeof(rr_type));
- region_recycle(db->region, zone->soa_nx_rrset,
- sizeof(rrset_type));
+ } else if (owner == rrset->zone->apex
+ && rrset_rrtype(rrset) == TYPE_NS)
+ {
+ rrset->zone->ns_rrset = rrset;
}
-#ifdef NSEC3
- hash_tree_delete(db->region, zone->nsec3tree);
- hash_tree_delete(db->region, zone->hashtree);
- hash_tree_delete(db->region, zone->wchashtree);
- hash_tree_delete(db->region, zone->dshashtree);
-#endif
- if(zone->filename)
- region_recycle(db->region, zone->filename,
- strlen(zone->filename)+1);
- if(zone->logstr)
- region_recycle(db->region, zone->logstr,
- strlen(zone->logstr)+1);
- region_recycle(db->region, zone, sizeof(zone_type));
-}
-#ifdef HAVE_MMAP
-/** read a zone */
-static void
-read_zone(udb_base* udb, namedb_type* db, nsd_options_t* opt,
- region_type* dname_region, udb_ptr* z)
-{
- /* construct dname */
- const dname_type* dname = dname_make(dname_region, ZONE(z)->name, 0);
- zone_options_t* zo = dname?zone_options_find(opt, dname):NULL;
- zone_type* zone;
- if(!dname) return;
- if(!zo) {
- /* deleted from the options, remove it from the nsd.db too */
- VERBOSITY(2, (LOG_WARNING, "zone %s is deleted",
- dname_to_string(dname, NULL)));
- udb_zone_delete(udb, z);
- region_free_all(dname_region);
- return;
+#ifdef DNSSEC
+ if (rrset_rrtype(rrset) == TYPE_RRSIG && owner == rrset->zone->apex) {
+ for (i = 0; i < rrset->rr_count; ++i) {
+ if (rr_rrsig_type_covered(&rrset->rrs[i]) == TYPE_SOA) {
+ rrset->zone->is_secure = 1;
+ break;
+ }
+ }
}
- assert(udb_ptr_get_type(z) == udb_chunk_type_zone);
- udb_rrsets = 0;
- udb_rrset_count = ZONE(z)->rrset_count;
- zone = namedb_zone_create(db, dname, zo);
- region_free_all(dname_region);
- read_zone_data(udb, db, dname_region, z, zone);
- zone->is_changed = (ZONE(z)->is_changed != 0);
-#ifdef NSEC3
- prehash_zone_complete(db, zone);
#endif
+ return rrset;
}
-#endif /* HAVE_MMAP */
-#ifdef HAVE_MMAP
-/** read zones from nsd.db */
-static void
-read_zones(udb_base* udb, namedb_type* db, nsd_options_t* opt,
- region_type* dname_region)
+struct namedb *
+namedb_open (const char *filename, nsd_options_t* opt, size_t num_children)
{
- udb_ptr ztree, n, z;
- udb_ptr_init(&z, udb);
- udb_ptr_new(&ztree, udb, udb_base_get_userdata(udb));
- udb_radix_first(udb,&ztree,&n);
- udb_time = time(NULL);
- while(n.data) {
- udb_ptr_set_rptr(&z, udb, &RADNODE(&n)->elem);
- udb_radix_next(udb, &n); /* store in case n is deleted */
- read_zone(udb, db, opt, dname_region, &z);
- udb_ptr_zero(&z, udb);
- if(nsd.signal_hint_shutdown) break;
- }
- udb_ptr_unlink(&ztree, udb);
- udb_ptr_unlink(&n, udb);
- udb_ptr_unlink(&z, udb);
-}
-#endif /* HAVE_MMAP */
+ namedb_type *db;
+
+ /*
+ * Region used to store the loaded database. The region is
+ * freed in namedb_close.
+ */
+ region_type *db_region;
-#ifdef HAVE_MMAP
-/** try to read the udb file or fail */
-static int
-try_read_udb(namedb_type* db, int fd, const char* filename,
- nsd_options_t* opt)
-{
/*
* Temporary region used while loading domain names from the
* database. The region is freed after each time a dname is
* read from the database.
*/
- region_type* dname_region;
-
- assert(fd != -1);
- if(!(db->udb=udb_base_create_fd(filename, fd, &namedb_walkfunc,
- NULL))) {
- /* fd is closed by failed udb create call */
- VERBOSITY(1, (LOG_WARNING, "can not use %s, "
- "will create anew", filename));
- return 0;
- }
- /* sanity check if can be opened */
- if(udb_base_get_userflags(db->udb) != 0) {
- log_msg(LOG_WARNING, "%s was not closed properly, it might "
- "be corrupted, will create anew", filename);
- udb_base_free(db->udb);
- db->udb = NULL;
- return 0;
- }
- /* read if it can be opened */
- dname_region = region_create(xalloc, free);
- /* this operation does not fail, we end up with
- * something, even if that is an empty namedb */
- read_zones(db->udb, db, opt, dname_region);
- region_destroy(dname_region);
- return 1;
-}
-#endif /* HAVE_MMAP */
-
-struct namedb *
-namedb_open (const char* filename, nsd_options_t* opt)
-{
- namedb_type* db;
+ region_type *dname_region;
/*
- * Region used to store the loaded database. The region is
- * freed in namedb_close.
+ * Temporary region used to store array of domains and zones
+ * while loading the database. The region is freed before
+ * returning.
*/
- region_type* db_region;
- int fd;
+ region_type *temp_region;
+
+ uint32_t dname_count;
+ domain_type **domains; /* Indexed by domain number. */
+
+ uint32_t zone_count;
+ zone_type **zones; /* Indexed by zone number. */
+
+ uint32_t i;
+ uint32_t rrset_count = 0;
+ uint32_t rr_count = 0;
+
+ rrset_type *rrset;
+
+ DEBUG(DEBUG_DBACCESS, 2,
+ (LOG_INFO, "sizeof(namedb_type) = %lu\n", (unsigned long) sizeof(namedb_type)));
+ DEBUG(DEBUG_DBACCESS, 2,
+ (LOG_INFO, "sizeof(zone_type) = %lu\n", (unsigned long) sizeof(zone_type)));
+ DEBUG(DEBUG_DBACCESS, 2,
+ (LOG_INFO, "sizeof(domain_type) = %lu\n", (unsigned long) sizeof(domain_type)));
+ DEBUG(DEBUG_DBACCESS, 2,
+ (LOG_INFO, "sizeof(rrset_type) = %lu\n", (unsigned long) sizeof(rrset_type)));
+ DEBUG(DEBUG_DBACCESS, 2,
+ (LOG_INFO, "sizeof(rr_type) = %lu\n", (unsigned long) sizeof(rr_type)));
+ DEBUG(DEBUG_DBACCESS, 2,
+ (LOG_INFO, "sizeof(rdata_atom_type) = %lu\n", (unsigned long) sizeof(rdata_atom_type)));
+ DEBUG(DEBUG_DBACCESS, 2,
+ (LOG_INFO, "sizeof(rbnode_t) = %lu\n", (unsigned long) sizeof(rbnode_t)));
-#ifdef USE_MMAP_ALLOC
- db_region = region_create_custom(mmap_alloc, mmap_free, MMAP_ALLOC_CHUNK_SIZE,
- MMAP_ALLOC_LARGE_OBJECT_SIZE, MMAP_ALLOC_INITIAL_CLEANUP_SIZE, 1);
-#else /* !USE_MMAP_ALLOC */
db_region = region_create_custom(xalloc, free, DEFAULT_CHUNK_SIZE,
DEFAULT_LARGE_OBJECT_SIZE, DEFAULT_INITIAL_CLEANUP_SIZE, 1);
-#endif /* !USE_MMAP_ALLOC */
db = (namedb_type *) region_alloc(db_region, sizeof(struct namedb));
db->region = db_region;
db->domains = domain_table_create(db->region);
- db->zonetree = radix_tree_create(db->region);
+ db->zones = NULL;
+ db->zone_count = 0;
+ db->filename = region_strdup(db->region, filename);
+ db->crc = 0xffffffff;
db->diff_skip = 0;
- db->diff_pos = 0;
- zonec_setup_parser(db);
if (gettimeofday(&(db->diff_timestamp), NULL) != 0) {
log_msg(LOG_ERR, "unable to load %s: cannot initialize"
- "timestamp", filename);
+ "timestamp", db->filename);
region_destroy(db_region);
- return NULL;
+ return NULL;
}
- /* in dbless mode there is no file to read or mmap */
- if(filename == NULL || filename[0] == 0) {
- db->udb = NULL;
- return db;
+ /* Open it... */
+ db->fd = fopen(db->filename, "r");
+ if (db->fd == NULL) {
+ log_msg(LOG_ERR, "unable to load %s: %s",
+ db->filename, strerror(errno));
+ region_destroy(db_region);
+ return NULL;
}
-#ifndef HAVE_MMAP
- /* no mmap() system call, use dbless mode */
- VERBOSITY(1, (LOG_INFO, "no mmap(), ignoring database %s", filename));
- db->udb = NULL;
- (void)fd; (void)opt;
- return db;
-#else /* HAVE_MMAP */
-
- /* attempt to open, if does not exist, create a new one */
- fd = open(filename, O_RDWR);
- if(fd == -1) {
- if(errno != ENOENT) {
- log_msg(LOG_ERR, "%s: %s", filename, strerror(errno));
- region_destroy(db_region);
- return NULL;
- }
+ if (!read_magic(db)) {
+ log_msg(LOG_ERR, "corrupted database (read magic): %s", db->filename);
+ namedb_close(db);
+ return NULL;
}
- /* attempt to read the file (if it exists) */
- if(fd != -1) {
- if(!try_read_udb(db, fd, filename, opt))
- fd = -1;
+
+ if (!read_size(db, &zone_count)) {
+ log_msg(LOG_ERR, "corrupted database (read size): %s", db->filename);
+ namedb_close(db);
+ return NULL;
}
- /* attempt to create the file (if necessary or failed read) */
- if(fd == -1) {
- if(!(db->udb=udb_base_create_new(filename, &namedb_walkfunc,
- NULL))) {
- region_destroy(db_region);
+
+ DEBUG(DEBUG_DBACCESS, 1,
+ (LOG_INFO, "Retrieving %lu zones\n", (unsigned long) zone_count));
+
+ temp_region = region_create(xalloc, free);
+ dname_region = region_create(xalloc, free);
+
+ db->zone_count = zone_count;
+ zones = (zone_type **) region_alloc(temp_region,
+ zone_count * sizeof(zone_type *));
+ for (i = 0; i < zone_count; ++i) {
+ const dname_type *dname = read_dname(db->fd, dname_region);
+ if (!dname) {
+ log_msg(LOG_ERR, "corrupted database (read dname): %s", db->filename);
+ region_destroy(dname_region);
+ region_destroy(temp_region);
+ namedb_close(db);
return NULL;
}
- if(!udb_dns_init_file(db->udb)) {
- region_destroy(db->region);
+ zones[i] = (zone_type *) region_alloc(db->region,
+ sizeof(zone_type));
+ zones[i]->next = db->zones;
+ db->zones = zones[i];
+ zones[i]->apex = domain_table_insert(db->domains, dname);
+ zones[i]->soa_rrset = NULL;
+ zones[i]->soa_nx_rrset = NULL;
+ zones[i]->ns_rrset = NULL;
+#ifdef NSEC3
+ zones[i]->nsec3_soa_rr = NULL;
+ zones[i]->nsec3_last = NULL;
+#endif
+ zones[i]->opts = zone_options_find(opt, domain_dname(zones[i]->apex));
+ zones[i]->number = i + 1;
+ zones[i]->is_secure = 0;
+ zones[i]->updated = 1;
+ zones[i]->is_ok = 0;
+ zones[i]->dirty = region_alloc(db->region, sizeof(uint8_t)*num_children);
+ memset(zones[i]->dirty, 0, sizeof(uint8_t)*num_children);
+ if(!zones[i]->opts) {
+ log_msg(LOG_ERR, "cannot load database. Zone %s in db "
+ "%s, but not in config file (might "
+ "happen if you edited the config "
+ "file). Please rebuild database and "
+ "start again.",
+ dname_to_string(dname, NULL), db->filename);
+ region_destroy(dname_region);
+ region_destroy(temp_region);
+ namedb_close(db);
return NULL;
}
- }
- return db;
-#endif /* HAVE_MMAP */
-}
-/** the the file mtime stat (or nonexist or error) */
-static int
-file_get_mtime(const char* file, time_t* mtime, int* nonexist)
-{
- struct stat s;
- if(stat(file, &s) != 0) {
- *mtime = 0;
- *nonexist = (errno == ENOENT);
- return 0;
+ region_free_all(dname_region);
}
- *nonexist = 0;
- *mtime = s.st_mtime;
- return 1;
-}
-void
-namedb_read_zonefile(struct nsd* nsd, struct zone* zone, udb_base* taskudb,
- udb_ptr* last_task)
-{
- time_t mtime = 0;
- int nonexist = 0;
- unsigned int errors;
- const char* fname;
- if(!nsd->db || !zone || !zone->opts || !zone->opts->pattern->zonefile)
- return;
- fname = config_make_zonefile(zone->opts, nsd);
- if(!file_get_mtime(fname, &mtime, &nonexist)) {
- if(nonexist) {
- VERBOSITY(2, (LOG_INFO, "zonefile %s does not exist",
- fname));
- } else
- log_msg(LOG_ERR, "zonefile %s: %s",
- fname, strerror(errno));
- if(taskudb) task_new_soainfo(taskudb, last_task, zone, 0);
- return;
- } else {
- const char* zone_fname = zone->filename;
- time_t zone_mtime = zone->mtime;
- if(nsd->db->udb) {
- zone_fname = udb_zone_get_file_str(nsd->db->udb,
- dname_name(domain_dname(zone->apex)),
- domain_dname(zone->apex)->name_size);
- zone_mtime = (time_t)udb_zone_get_mtime(nsd->db->udb,
- dname_name(domain_dname(zone->apex)),
- domain_dname(zone->apex)->name_size);
- }
- /* if no zone_fname, then it was acquired in zone transfer,
- * see if the file is newer than the zone transfer
- * (regardless if this is a different file), because the
- * zone transfer is a different content source too */
- if(!zone_fname && zone_mtime >= mtime) {
- VERBOSITY(3, (LOG_INFO, "zonefile %s is older than "
- "zone transfer in memory", fname));
- return;
-
- /* if zone_fname, then the file was acquired from reading it,
- * and see if filename changed or mtime newer to read it */
- } else if(zone_fname && fname &&
- strcmp(zone_fname, fname) == 0 && zone_mtime >= mtime) {
- VERBOSITY(3, (LOG_INFO, "zonefile %s is not modified",
- fname));
- return;
- }
+ if (!read_size(db, &dname_count)) {
+ log_msg(LOG_ERR, "corrupted database (read size): %s", db->filename);
+ region_destroy(dname_region);
+ region_destroy(temp_region);
+ namedb_close(db);
+ return NULL;
}
- assert(parser);
- /* wipe zone from memory */
-#ifdef NSEC3
- nsec3_hash_tree_clear(zone);
-#endif
- delete_zone_rrs(nsd->db, zone);
-#ifdef NSEC3
- nsec3_clear_precompile(nsd->db, zone);
- zone->nsec3_param = NULL;
-#endif /* NSEC3 */
- errors = zonec_read(zone->opts->name, fname, zone);
- if(errors > 0) {
- log_msg(LOG_ERR, "zone %s file %s read with %u errors",
- zone->opts->name, fname, errors);
- /* wipe (partial) zone from memory */
- zone->is_ok = 1;
-#ifdef NSEC3
- nsec3_hash_tree_clear(zone);
-#endif
- delete_zone_rrs(nsd->db, zone);
-#ifdef NSEC3
- nsec3_clear_precompile(nsd->db, zone);
- zone->nsec3_param = NULL;
-#endif /* NSEC3 */
- if(nsd->db->udb) {
- region_type* dname_region;
- udb_ptr z;
- /* see if we can revert to the udb stored version */
- if(!udb_zone_search(nsd->db->udb, &z, dname_name(domain_dname(
- zone->apex)), domain_dname(zone->apex)->name_size)) {
- /* tell that zone contents has been lost */
- if(taskudb) task_new_soainfo(taskudb, last_task, zone, 0);
- return;
- }
- /* read from udb */
- dname_region = region_create(xalloc, free);
- udb_rrsets = 0;
- udb_rrset_count = ZONE(&z)->rrset_count;
- udb_time = time(NULL);
- read_zone_data(nsd->db->udb, nsd->db, dname_region, &z, zone);
+ DEBUG(DEBUG_DBACCESS, 1,
+ (LOG_INFO, "Retrieving %lu domain names\n", (unsigned long) dname_count));
+
+ domains = (domain_type **) region_alloc(
+ temp_region, dname_count * sizeof(domain_type *));
+ for (i = 0; i < dname_count; ++i) {
+ const dname_type *dname = read_dname(db->fd, dname_region);
+ if (!dname) {
+ log_msg(LOG_ERR, "corrupted database (read dname): %s", db->filename);
region_destroy(dname_region);
- udb_ptr_unlink(&z, nsd->db->udb);
- } else {
- if(zone->filename)
- region_recycle(nsd->db->region, zone->filename,
- strlen(zone->filename)+1);
- zone->filename = NULL;
- if(zone->logstr)
- region_recycle(nsd->db->region, zone->logstr,
- strlen(zone->logstr)+1);
- zone->logstr = NULL;
- }
- } else {
- VERBOSITY(1, (LOG_INFO, "zone %s read with success",
- zone->opts->name));
- zone->is_ok = 1;
- zone->is_changed = 0;
- /* store zone into udb */
- if(nsd->db->udb) {
- if(!write_zone_to_udb(nsd->db->udb, zone, mtime, fname)) {
- log_msg(LOG_ERR, "failed to store zone in db");
- } else {
- VERBOSITY(2, (LOG_INFO, "zone %s written to db",
- zone->opts->name));
- }
- } else {
- zone->mtime = mtime;
- if(zone->filename)
- region_recycle(nsd->db->region, zone->filename,
- strlen(zone->filename)+1);
- zone->filename = region_strdup(nsd->db->region, fname);
- if(zone->logstr)
- region_recycle(nsd->db->region, zone->logstr,
- strlen(zone->logstr)+1);
- zone->logstr = NULL;
+ region_destroy(temp_region);
+ namedb_close(db);
+ return NULL;
}
+ domains[i] = domain_table_insert(db->domains, dname);
+ region_free_all(dname_region);
}
- if(taskudb) task_new_soainfo(taskudb, last_task, zone, 0);
-#ifdef NSEC3
- prehash_zone_complete(nsd->db, zone);
+
+ region_destroy(dname_region);
+
+#ifndef NDEBUG
+ fprintf(stderr, "database region after loading domain names: ");
+ region_dump_stats(db->region, stderr);
+ fprintf(stderr, "\n");
#endif
-}
-void namedb_check_zonefile(struct nsd* nsd, udb_base* taskudb,
- udb_ptr* last_task, zone_options_t* zopt)
-{
- zone_type* zone;
- const dname_type* dname = (const dname_type*)zopt->node.key;
- /* find zone to go with it, or create it */
- zone = namedb_find_zone(nsd->db, dname);
- if(!zone) {
- zone = namedb_zone_create(nsd->db, dname, zopt);
+ while ((rrset = read_rrset(db, dname_count, domains, zone_count, zones))) {
+ ++rrset_count;
+ rr_count += rrset->rr_count;
+ }
+
+ DEBUG(DEBUG_DBACCESS, 1,
+ (LOG_INFO, "Retrieved %lu RRs in %lu RRsets\n",
+ (unsigned long) rr_count, (unsigned long) rrset_count));
+
+ region_destroy(temp_region);
+
+ if ((db->crc_pos = ftello(db->fd)) == -1) {
+ log_msg(LOG_ERR, "ftello %s failed: %s",
+ db->filename, strerror(errno));
+ namedb_close(db);
+ return NULL;
}
- namedb_read_zonefile(nsd, zone, taskudb, last_task);
+ if (!read_size(db, &db->crc)) {
+ log_msg(LOG_ERR, "corrupted database (read size): %s", db->filename);
+ namedb_close(db);
+ return NULL;
+ }
+ if (!read_magic(db)) {
+ log_msg(LOG_ERR, "corrupted database (read magic): %s", db->filename);
+ namedb_close(db);
+ return NULL;
+ }
+
+ fclose(db->fd);
+ db->fd = NULL;
+
+#ifndef NDEBUG
+ fprintf(stderr, "database region after loading database: ");
+ region_dump_stats(db->region, stderr);
+ fprintf(stderr, "\n");
+#endif
+
+ return db;
}
-void namedb_check_zonefiles(struct nsd* nsd, nsd_options_t* opt,
- udb_base* taskudb, udb_ptr* last_task)
+void
+namedb_close (struct namedb *db)
{
- zone_options_t* zo;
- /* check all zones in opt, create if not exist in main db */
- RBTREE_FOR(zo, zone_options_t*, opt->zone_options) {
- namedb_check_zonefile(nsd, taskudb, last_task, zo);
- if(nsd->signal_hint_shutdown) break;
+ if (db) {
+ if (db->fd) {
+ fclose(db->fd);
+ }
+ region_destroy(db->region);
}
}
diff --git a/usr.sbin/nsd/dname.h b/usr.sbin/nsd/dname.h
index 060afff5b15..b68bc0dfe40 100644
--- a/usr.sbin/nsd/dname.h
+++ b/usr.sbin/nsd/dname.h
@@ -217,7 +217,7 @@ static inline size_t
dname_total_size(const dname_type *dname)
{
return (sizeof(dname_type)
- + ((((size_t)dname->label_count) + ((size_t)dname->name_size))
+ + ((dname->label_count + dname->name_size)
* sizeof(uint8_t)));
}
@@ -374,11 +374,4 @@ const dname_type *dname_replace(region_type* region,
const dname_type* src,
const dname_type* dest);
-/** Convert uncompressed wireformat dname to a string */
-char* wiredname2str(const uint8_t* dname);
-/** convert uncompressed label to string */
-char* wirelabel2str(const uint8_t* label);
-/** check if two uncompressed dnames of the same total length are equal */
-int dname_equal_nocase(uint8_t* a, uint8_t* b, uint16_t len);
-
#endif /* _DNAME_H_ */
diff --git a/usr.sbin/nsd/options.h b/usr.sbin/nsd/options.h
index accf470a368..b676cd8ce9b 100644
--- a/usr.sbin/nsd/options.h
+++ b/usr.sbin/nsd/options.h
@@ -10,18 +10,15 @@
#ifndef OPTIONS_H
#define OPTIONS_H
-#include "config.h"
+#include <config.h>
#include <stdarg.h>
#include "region-allocator.h"
#include "rbtree.h"
struct query;
struct dname;
struct tsig_key;
-struct buffer;
-struct nsd;
typedef struct nsd_options nsd_options_t;
-typedef struct pattern_options pattern_options_t;
typedef struct zone_options zone_options_t;
typedef struct ipaddress_option ip_address_option_t;
typedef struct acl_options acl_options_t;
@@ -31,40 +28,21 @@ typedef struct config_parser_state config_parser_state_t;
* Options global for nsd.
*/
struct nsd_options {
- /* config file name */
- char* configfile;
/* options for zones, by apex, contains zone_options_t */
rbtree_t* zone_options;
- /* patterns, by name, contains pattern_options_t */
- rbtree_t* patterns;
- /* free space in zonelist file, contains zonelist_bucket */
- rbtree_t* zonefree;
- /* number of free space lines in zonelist file */
- size_t zonefree_number;
- /* zonelist file if open */
- FILE* zonelist;
- /* last offset in file (or 0 if none) */
- off_t zonelist_off;
-
- /* tree of zonestat names and their id values, entries are struct
- * zonestatname with malloced key=stringname. The number of items
- * is the max statnameid, no items are freed from this.
- * kept correct in the xfrd process, and on startup. */
- rbtree_t* zonestatnames;
-
- /* rbtree of keys defined, by name */
- rbtree_t* keys;
+ /* list of keys defined */
+ key_options_t* keys;
+ size_t numkeys;
/* list of ip adresses to bind to (or NULL for all) */
ip_address_option_t* ip_addresses;
- int ip_transparent;
int debug_mode;
int verbosity;
int hide_version;
- int do_ip4;
- int do_ip6;
+ int ip4_only;
+ int ip6_only;
const char* database;
const char* identity;
const char* logfile;
@@ -80,45 +58,9 @@ struct nsd_options {
const char* chroot;
const char* username;
const char* zonesdir;
+ const char* difffile;
const char* xfrdfile;
- const char* xfrdir;
- const char* zonelistfile;
- const char* nsid;
int xfrd_reload_timeout;
- int zonefiles_check;
- int zonefiles_write;
- int log_time_ascii;
- int round_robin;
- int reuseport;
-
- /** remote control section. enable toggle. */
- int control_enable;
- /** the interfaces the remote control should listen on */
- ip_address_option_t* control_interface;
- /** port number for the control port */
- int control_port;
- /** private key file for server */
- char* server_key_file;
- /** certificate file for server */
- char* server_cert_file;
- /** private key file for nsd-control */
- char* control_key_file;
- /** certificate file for nsd-control */
- char* control_cert_file;
-
-#ifdef RATELIMIT
- /** number of buckets in rrl hashtable */
- size_t rrl_size;
- /** max qps for queries, 0 is nolimit */
- size_t rrl_ratelimit;
- /** ratio of slipped responses, 0 is noslip */
- size_t rrl_slip;
- /** ip prefix length */
- size_t rrl_ipv4_prefix_length;
- size_t rrl_ipv6_prefix_length;
- /** max qps for whitelisted queries, 0 is nolimit */
- size_t rrl_whitelist_ratelimit;
-#endif
region_type* region;
};
@@ -129,48 +71,22 @@ struct ipaddress_option {
};
/*
- * Pattern of zone options, used to contain options for zone(s).
+ * Options for a zone
*/
-struct pattern_options {
+struct zone_options {
+ /* key is dname of apex */
rbnode_t node;
- const char* pname; /* name of the pattern, key of rbtree */
+
+ /* is apex of the zone */
+ const char* name;
const char* zonefile;
acl_options_t* allow_notify;
acl_options_t* request_xfr;
acl_options_t* notify;
acl_options_t* provide_xfr;
acl_options_t* outgoing_interface;
- const char* zonestats;
-#ifdef RATELIMIT
- uint16_t rrl_whitelist; /* bitmap with rrl types */
-#endif
uint8_t allow_axfr_fallback;
- uint8_t allow_axfr_fallback_is_default;
uint8_t notify_retry;
- uint8_t notify_retry_is_default;
- uint8_t implicit; /* pattern is implicit, part_of_config zone used */
- uint8_t xfrd_flags;
-};
-
-#define PATTERN_IMPLICIT_MARKER "_implicit_"
-
-/*
- * Options for a zone
- */
-struct zone_options {
- /* key is dname of apex */
- rbnode_t node;
-
- /* is apex of the zone */
- const char* name;
- /* if not part of config, the offset and linesize of zonelist entry */
- off_t off;
- int linesize;
- /* pattern for the zone options, if zone is part_of_config, this is
- * a anonymous pattern created in-place */
- pattern_options_t* pattern;
- /* zone is fixed into the main config, not in zonelist, cannot delete */
- uint8_t part_of_config;
};
union acl_addr_storage {
@@ -189,10 +105,9 @@ struct acl_options {
acl_options_t* next;
/* options */
- time_t ixfr_disabled;
- int bad_xfr_count;
uint8_t use_axfr_only;
uint8_t allow_udp;
+ time_t ixfr_disabled;
/* ip address range */
const char* ip_address_spec;
@@ -218,44 +133,23 @@ struct acl_options {
* Key definition
*/
struct key_options {
- rbnode_t node; /* key of tree is name */
- char* name;
- char* algorithm;
- char* secret;
+ key_options_t* next;
+ const char* name;
+ const char* algorithm;
+ const char* secret;
+#ifdef TSIG
struct tsig_key* tsig_key;
-};
-
-/** zone list free space */
-struct zonelist_free {
- struct zonelist_free* next;
- off_t off;
-};
-/** zonelist free bucket for a particular line length */
-struct zonelist_bucket {
- rbnode_t node; /* key is ptr to linesize */
- int linesize;
- struct zonelist_free* list;
-};
-
-/* default zonefile write interval if database is "", in seconds */
-#define ZONEFILES_WRITE_INTERVAL 3600
-
-struct zonestatname {
- rbnode_t node; /* key is malloced string with cooked zonestat name */
- unsigned id; /* index in nsd.zonestat array */
+#endif
};
/*
* Used during options parsing
*/
struct config_parser_state {
- char* filename;
- const char* chroot;
+ const char* filename;
int line;
int errors;
- int server_settings_seen;
nsd_options_t* opt;
- pattern_options_t* current_pattern;
zone_options_t* current_zone;
key_options_t* current_key;
ip_address_option_t* current_ip_address_option;
@@ -264,8 +158,6 @@ struct config_parser_state {
acl_options_t* current_notify;
acl_options_t* current_provide_xfr;
acl_options_t* current_outgoing_interface;
- void (*err)(void*,const char*);
- void* err_arg;
};
extern config_parser_state_t* cfg_parser;
@@ -277,61 +169,22 @@ static inline size_t nsd_options_num_zones(nsd_options_t* opt)
{ return opt->zone_options->count; }
/* insert a zone into the main options tree, returns 0 on error */
int nsd_options_insert_zone(nsd_options_t* opt, zone_options_t* zone);
-/* insert a pattern into the main options tree, returns 0 on error */
-int nsd_options_insert_pattern(nsd_options_t* opt, pattern_options_t* pat);
-/* parses options file. Returns false on failure. callback, if nonNULL,
- * gets called with error strings, default prints. */
-int parse_options_file(nsd_options_t* opt, const char* file,
- void (*err)(void*,const char*), void* err_arg);
+/* parses options file. Returns false on failure */
+int parse_options_file(nsd_options_t* opt, const char* file);
zone_options_t* zone_options_create(region_type* region);
-void zone_options_delete(nsd_options_t* opt, zone_options_t* zone);
/* find a zone by apex domain name, or NULL if not found. */
zone_options_t* zone_options_find(nsd_options_t* opt, const struct dname* apex);
-pattern_options_t* pattern_options_create(region_type* region);
-pattern_options_t* pattern_options_find(nsd_options_t* opt, const char* name);
-int pattern_options_equal(pattern_options_t* p, pattern_options_t* q);
-void pattern_options_remove(nsd_options_t* opt, const char* name);
-void pattern_options_add_modify(nsd_options_t* opt, pattern_options_t* p);
-void pattern_options_marshal(struct buffer* buffer, pattern_options_t* p);
-pattern_options_t* pattern_options_unmarshal(region_type* r, struct buffer* b);
key_options_t* key_options_create(region_type* region);
-void key_options_insert(nsd_options_t* opt, key_options_t* key);
key_options_t* key_options_find(nsd_options_t* opt, const char* name);
-void key_options_remove(nsd_options_t* opt, const char* name);
-int key_options_equal(key_options_t* p, key_options_t* q);
-void key_options_add_modify(nsd_options_t* opt, key_options_t* key);
-/* read in zone list file. Returns false on failure */
-int parse_zone_list_file(nsd_options_t* opt);
-/* create zone entry and add to the zonelist file */
-zone_options_t* zone_list_add(nsd_options_t* opt, const char* zname,
- const char* pname);
-/* create zonelist entry, do not insert in file (called by _add) */
-zone_options_t* zone_list_zone_insert(nsd_options_t* opt, const char* nm,
- const char* patnm, int linesize, off_t off);
-void zone_list_del(nsd_options_t* opt, zone_options_t* zone);
-void zone_list_compact(nsd_options_t* opt);
-void zone_list_close(nsd_options_t* opt);
-
-/* create zonestat name tree , for initially created zones */
-void options_zonestatnames_create(nsd_options_t* opt);
-/* Get zonestat id for zone options, add new entry if necessary.
- * instantiates the pattern's zonestat string */
-unsigned getzonestatid(nsd_options_t* opt, zone_options_t* zopt);
-/* create string, same options as zonefile but no chroot changes */
-const char* config_cook_string(zone_options_t* zone, const char* input);
-
-#if defined(HAVE_SSL)
/* tsig must be inited, adds all keys in options to tsig. */
void key_options_tsig_add(nsd_options_t* opt);
-#endif
/* check acl list, acl number that matches if passed(0..),
* or failure (-1) if dropped */
/* the reason why (the acl) is returned too (or NULL) */
int acl_check_incoming(acl_options_t* acl, struct query* q,
acl_options_t** reason);
-int acl_addr_matches_host(acl_options_t* acl, acl_options_t* host);
int acl_addr_matches(acl_options_t* acl, struct query* q);
int acl_key_matches(acl_options_t* acl, struct query* q);
int acl_addr_match_mask(uint32_t* a, uint32_t* b, uint32_t* mask, size_t sz);
@@ -342,18 +195,8 @@ int acl_same_host(acl_options_t* a, acl_options_t* b);
/* find acl by number in the list */
acl_options_t* acl_find_num(acl_options_t* acl, int num);
-/* see if two acl lists are the same (same elements in same order, or empty) */
-int acl_list_equal(acl_options_t* p, acl_options_t* q);
-/* see if two acl are the same */
-int acl_equal(acl_options_t* p, acl_options_t* q);
-
/* see if a zone is a slave or a master zone */
int zone_is_slave(zone_options_t* opt);
-/* create zonefile name, returns static pointer (perhaps to options data) */
-const char* config_make_zonefile(zone_options_t* zone, struct nsd* nsd);
-
-#define ZONEC_PCT_TIME 5 /* seconds, then it starts to print pcts */
-#define ZONEC_PCT_COUNT 100000 /* elements before pct check is done */
/* parsing helpers */
void c_error(const char* msg);
@@ -367,9 +210,5 @@ int parse_acl_range_type(char* ip, char** mask);
void parse_acl_range_subnet(char* p, void* addr, int maxbits);
/* clean up options */
void nsd_options_destroy(nsd_options_t* opt);
-/* replace occurrences of one with two in buf, pass length of buffer */
-void replace_str(char* buf, size_t len, const char* one, const char* two);
-/* apply pattern to the existing pattern in the parser */
-void config_apply_pattern(const char* name);
#endif /* OPTIONS_H */
diff --git a/usr.sbin/nsd/packet.h b/usr.sbin/nsd/packet.h
index 27ea9367d67..fe5dedb606f 100644
--- a/usr.sbin/nsd/packet.h
+++ b/usr.sbin/nsd/packet.h
@@ -140,20 +140,12 @@ struct query;
#define MAXRRSPP 10240 /* Maximum number of rr's per packet */
#define MAX_COMPRESSED_DNAMES MAXRRSPP /* Maximum number of compressed domains. */
#define MAX_COMPRESSION_OFFSET 16383 /* Compression pointers are 14 bit. */
-#define IPV4_MINIMAL_RESPONSE_SIZE 1480 /* Recommended minimal edns size for IPv4 */
-#define IPV6_MINIMAL_RESPONSE_SIZE 1220 /* Recommended minimal edns size for IPv6 */
-
-/* use round robin rotation */
-extern int round_robin;
/*
* Encode RR with OWNER as owner name into QUERY. Returns the number
* of RRs successfully encoded.
*/
-int packet_encode_rr(struct query *query,
- domain_type *owner,
- rr_type *rr,
- uint32_t ttl);
+int packet_encode_rr(struct query *query, domain_type *owner, rr_type *rr);
/*
* Encode RRSET with OWNER as the owner name into QUERY. Returns the
@@ -164,9 +156,7 @@ int packet_encode_rr(struct query *query,
int packet_encode_rrset(struct query *query,
domain_type *owner,
rrset_type *rrset,
- int truncate_rrset,
- size_t minimal_respsize,
- int* done);
+ int truncate_rrset);
/*
* Skip the RR at the current position in PACKET.
@@ -196,8 +186,4 @@ int packet_read_query_section(buffer_type *packet,
uint16_t* qtype,
uint16_t* qclass);
-/* read notify SOA serial from packet. buffer position is unmodified on return.
- * returns false on no-serial found or parse failure. */
-int packet_find_notify_serial(buffer_type *packet, uint32_t* serial);
-
#endif /* _PACKET_H_ */
diff --git a/usr.sbin/nsd/rbtree.c b/usr.sbin/nsd/rbtree.c
index 80f7bbb2b6e..d683fe10c62 100644
--- a/usr.sbin/nsd/rbtree.c
+++ b/usr.sbin/nsd/rbtree.c
@@ -7,7 +7,7 @@
*
*/
-#include "config.h"
+#include <config.h>
#include <assert.h>
#include <stdlib.h>
diff --git a/usr.sbin/nsd/region-allocator.h b/usr.sbin/nsd/region-allocator.h
index d525a2b05bc..41891651f45 100644
--- a/usr.sbin/nsd/region-allocator.h
+++ b/usr.sbin/nsd/region-allocator.h
@@ -18,23 +18,6 @@ typedef struct region region_type;
#define DEFAULT_LARGE_OBJECT_SIZE (DEFAULT_CHUNK_SIZE / 8)
#define DEFAULT_INITIAL_CLEANUP_SIZE 16
-
-/*
- * mmap allocator constants
- *
- */
-#ifdef USE_MMAP_ALLOC
-
-/* header starts with size_t containing allocated size info and has at least 16 bytes to align the returned memory */
-#define MMAP_ALLOC_HEADER_SIZE (sizeof(size_t) >= 16 ? (sizeof(size_t)) : 16)
-
-/* mmap allocator uses chunks of 32 4kB pages */
-#define MMAP_ALLOC_CHUNK_SIZE ((32 * 4096) - MMAP_ALLOC_HEADER_SIZE)
-#define MMAP_ALLOC_LARGE_OBJECT_SIZE (MMAP_ALLOC_CHUNK_SIZE / 8)
-#define MMAP_ALLOC_INITIAL_CLEANUP_SIZE 16
-
-#endif /* USE_MMAP_ALLOC */
-
/*
* Create a new region.
*/
@@ -76,11 +59,6 @@ size_t region_add_cleanup(region_type *region,
void (*action)(void *),
void *data);
-/*
- * Remove cleanup, both action and data must match exactly.
- */
-void region_remove_cleanup(region_type *region,
- void (*action)(void *), void *data);
/*
* Allocate SIZE bytes of memory inside REGION. The memory is
@@ -88,8 +66,6 @@ void region_remove_cleanup(region_type *region,
*/
void *region_alloc(region_type *region, size_t size);
-/** Allocate array with integer overflow checks, in region */
-void *region_alloc_array(region_type *region, size_t num, size_t size);
/*
* Allocate SIZE bytes of memory inside REGION and copy INIT into it.
@@ -98,12 +74,6 @@ void *region_alloc_array(region_type *region, size_t num, size_t size);
*/
void *region_alloc_init(region_type *region, const void *init, size_t size);
-/**
- * Allocate array (with integer overflow check on sizes), and init with
- * the given array copied into it. Allocated in the region
- */
-void *region_alloc_array_init(region_type *region, const void *init,
- size_t num, size_t size);
/*
* Allocate SIZE bytes of memory inside REGION that are initialized to
@@ -112,11 +82,6 @@ void *region_alloc_array_init(region_type *region, const void *init,
*/
void *region_alloc_zero(region_type *region, size_t size);
-/**
- * Allocate array (with integer overflow check on sizes), and zero it.
- * Allocated in the region.
- */
-void *region_alloc_array_zero(region_type *region, size_t num, size_t size);
/*
* Run the cleanup actions and free all memory associated with REGION.
@@ -142,10 +107,6 @@ void region_dump_stats(region_type *region, FILE *out);
/* get size of recyclebin */
size_t region_get_recycle_size(region_type* region);
-/* get size of region memory in use */
-size_t region_get_mem(region_type* region);
-/* get size of region memory unused */
-size_t region_get_mem_unused(region_type* region);
/* Debug print REGION statistics to LOG. */
void region_log_stats(region_type *region);