rootns.c revision 63b0524b961b6dce1aa18488d7175ca4ee17778f
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews/*
1fdd2470b625a58b57d0b155e6caf8c4fc0afe8aAutomatic Updater * Copyright (C) 2004, 2005, 2007, 2008, 2010, 2012-2015 Internet Systems Consortium, Inc. ("ISC")
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Copyright (C) 1999-2002 Internet Software Consortium.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews *
4a14ce5ba00ab7bc55c99ffdcf59c7a4ab902721Automatic Updater * Permission to use, copy, modify, and/or distribute this software for any
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * copyright notice and this permission notice appear in all copies.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews *
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews */
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews/* $Id: rootns.c,v 1.40.476.1 2012/02/07 00:44:14 each Exp $ */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews/*! \file */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
e21a2904f02a03fa06b6db04d348f65fe9c67b2bMark Andrews#include <config.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <isc/buffer.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <isc/string.h> /* Required for HP/UX (and others?) */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <isc/util.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/callbacks.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/db.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/dbiterator.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/fixedname.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/log.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/master.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/rdata.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/rdata.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/rdataset.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/rdatasetiter.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/rdatastruct.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/rdatatype.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/result.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/rootns.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <dns/view.h>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsstatic char root_ns[] =
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews";\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"; Internet Root Nameservers\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews";\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"$TTL 518400\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews". 518400 IN NS A.ROOT-SERVERS.NET.\n"
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater". 518400 IN NS B.ROOT-SERVERS.NET.\n"
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater". 518400 IN NS C.ROOT-SERVERS.NET.\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews". 518400 IN NS D.ROOT-SERVERS.NET.\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews". 518400 IN NS E.ROOT-SERVERS.NET.\n"
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater". 518400 IN NS F.ROOT-SERVERS.NET.\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews". 518400 IN NS G.ROOT-SERVERS.NET.\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews". 518400 IN NS H.ROOT-SERVERS.NET.\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews". 518400 IN NS I.ROOT-SERVERS.NET.\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews". 518400 IN NS J.ROOT-SERVERS.NET.\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews". 518400 IN NS K.ROOT-SERVERS.NET.\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews". 518400 IN NS L.ROOT-SERVERS.NET.\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews". 518400 IN NS M.ROOT-SERVERS.NET.\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"A.ROOT-SERVERS.NET. 3600000 IN A 198.41.0.4\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"A.ROOT-SERVERS.NET. 3600000 IN AAAA 2001:503:BA3E::2:30\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"B.ROOT-SERVERS.NET. 3600000 IN A 192.228.79.201\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"C.ROOT-SERVERS.NET. 3600000 IN A 192.33.4.12\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"C.ROOT-SERVERS.NET. 3600000 IN AAAA 2001:500:2::c\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"D.ROOT-SERVERS.NET. 3600000 IN A 199.7.91.13\n"
f6da30bb5447c23d880b09f601441e70c5313557Mark Andrews"D.ROOT-SERVERS.NET. 3600000 IN AAAA 2001:500:2d::d\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"E.ROOT-SERVERS.NET. 3600000 IN A 192.203.230.10\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"F.ROOT-SERVERS.NET. 3600000 IN A 192.5.5.241\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"F.ROOT-SERVERS.NET. 3600000 IN AAAA 2001:500:2F::F\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"G.ROOT-SERVERS.NET. 3600000 IN A 192.112.36.4\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"H.ROOT-SERVERS.NET. 3600000 IN A 128.63.2.53\n"
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater"H.ROOT-SERVERS.NET. 3600000 IN AAAA 2001:500:1::803F:235\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"I.ROOT-SERVERS.NET. 3600000 IN A 192.36.148.17\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"I.ROOT-SERVERS.NET. 3600000 IN AAAA 2001:7fe::53\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"J.ROOT-SERVERS.NET. 3600000 IN A 192.58.128.30\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"J.ROOT-SERVERS.NET. 3600000 IN AAAA 2001:503:C27::2:30\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"K.ROOT-SERVERS.NET. 3600000 IN A 193.0.14.129\n"
f7b41fd9291b8f4dba27e2b57e1d93f0913a4f1dMark Andrews"K.ROOT-SERVERS.NET. 3600000 IN AAAA 2001:7FD::1\n"
f7b41fd9291b8f4dba27e2b57e1d93f0913a4f1dMark Andrews"L.ROOT-SERVERS.NET. 3600000 IN A 199.7.83.42\n"
f7b41fd9291b8f4dba27e2b57e1d93f0913a4f1dMark Andrews"L.ROOT-SERVERS.NET. 604800 IN AAAA 2001:500:3::42\n"
f7b41fd9291b8f4dba27e2b57e1d93f0913a4f1dMark Andrews"M.ROOT-SERVERS.NET. 3600000 IN A 202.12.27.33\n"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"M.ROOT-SERVERS.NET. 3600000 IN AAAA 2001:DC3::35\n";
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsstatic isc_result_t
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsin_rootns(dns_rdataset_t *rootns, dns_name_t *name) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_result_t result;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdata_ns_t ns;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (!dns_rdataset_isassociated(rootns))
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews return (ISC_R_NOTFOUND);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_rdataset_first(rootns);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews while (result == ISC_R_SUCCESS) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdataset_current(rootns, &rdata);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_rdata_tostruct(&rdata, &ns, NULL);
9fbbfb5757a1e3e86d7dea62c4e63ffc2303ca2bAutomatic Updater if (result != ISC_R_SUCCESS)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews return (result);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (dns_name_compare(name, &ns.name) == 0)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews return (ISC_R_SUCCESS);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_rdataset_next(rootns);
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews dns_rdata_reset(&rdata);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews }
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews if (result == ISC_R_NOMORE)
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews result = ISC_R_NOTFOUND;
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews return (result);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews}
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsstatic isc_result_t
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewscheck_node(dns_rdataset_t *rootns, dns_name_t *name,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdatasetiter_t *rdsiter) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_result_t result;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdataset_t rdataset;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdataset_init(&rdataset);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_rdatasetiter_first(rdsiter);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews while (result == ISC_R_SUCCESS) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdatasetiter_current(rdsiter, &rdataset);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews switch (rdataset.type) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews case dns_rdatatype_a:
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews case dns_rdatatype_aaaa:
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = in_rootns(rootns, name);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (result != ISC_R_SUCCESS)
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews goto cleanup;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews break;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews case dns_rdatatype_ns:
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (dns_name_compare(name, dns_rootname) == 0)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews break;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews /*FALLTHROUGH*/
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews default:
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews result = ISC_R_FAILURE;
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews goto cleanup;
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews }
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews dns_rdataset_disassociate(&rdataset);
a057e8e33baa5fa369be28a9680585200ce3ff73Mark Andrews result = dns_rdatasetiter_next(rdsiter);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews }
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (result == ISC_R_NOMORE)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = ISC_R_SUCCESS;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews cleanup:
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (dns_rdataset_isassociated(&rdataset))
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdataset_disassociate(&rdataset);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews return (result);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews}
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsstatic isc_result_t
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewscheck_hints(dns_db_t *db) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_result_t result;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdataset_t rootns;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_dbiterator_t *dbiter = NULL;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_dbnode_t *node = NULL;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_stdtime_t now;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_fixedname_t fixname;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_name_t *name;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdatasetiter_t *rdsiter = NULL;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_stdtime_get(&now);
bf056b7184b38281c1b0bf0cf21b5982fa1a4edaMark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_fixedname_init(&fixname);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews name = dns_fixedname_name(&fixname);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdataset_init(&rootns);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews (void)dns_db_find(db, dns_rootname, NULL, dns_rdatatype_ns, 0,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews now, NULL, name, &rootns, NULL);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_db_createiterator(db, 0, &dbiter);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (result != ISC_R_SUCCESS)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews goto cleanup;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_dbiterator_first(dbiter);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews while (result == ISC_R_SUCCESS) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_dbiterator_current(dbiter, &node, name);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (result != ISC_R_SUCCESS)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews goto cleanup;
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews result = dns_db_allrdatasets(db, node, NULL, now, &rdsiter);
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews if (result != ISC_R_SUCCESS)
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews goto cleanup;
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews result = check_node(&rootns, name, rdsiter);
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews if (result != ISC_R_SUCCESS)
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews goto cleanup;
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews dns_rdatasetiter_destroy(&rdsiter);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_db_detachnode(db, &node);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_dbiterator_next(dbiter);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews }
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (result == ISC_R_NOMORE)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = ISC_R_SUCCESS;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews cleanup:
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (dns_rdataset_isassociated(&rootns))
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdataset_disassociate(&rootns);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (rdsiter != NULL)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdatasetiter_destroy(&rdsiter);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (node != NULL)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_db_detachnode(db, &node);
f7b41fd9291b8f4dba27e2b57e1d93f0913a4f1dMark Andrews if (dbiter != NULL)
f7b41fd9291b8f4dba27e2b57e1d93f0913a4f1dMark Andrews dns_dbiterator_destroy(&dbiter);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews return (result);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews}
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updaterisc_result_t
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updaterdns_rootns_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater const char *filename, dns_db_t **target)
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater{
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater isc_result_t result, eresult;
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater isc_buffer_t source;
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater unsigned int len;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdatacallbacks_t callbacks;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_db_t *db = NULL;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews REQUIRE(target != NULL && *target == NULL);
285254345ce5ab270848f8c11f7be146793f1e00Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews rdclass, 0, NULL, &db);
285254345ce5ab270848f8c11f7be146793f1e00Mark Andrews if (result != ISC_R_SUCCESS)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews goto failure;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews len = strlen(root_ns);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_buffer_init(&source, root_ns, len);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_buffer_add(&source, len);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdatacallbacks_init(&callbacks);
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews result = dns_db_beginload(db, &callbacks);
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews if (result != ISC_R_SUCCESS)
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews goto failure;
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews if (filename != NULL) {
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews /*
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews * Load the hints from the specified filename.
3b4098640dd85040270f39b9a5ee5e22de99d3d6Mark Andrews */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_master_loadfile(filename, &db->origin,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews &db->origin, db->rdclass,
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews DNS_MASTER_HINT,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews &callbacks, db->mctx);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews } else if (rdclass == dns_rdataclass_in) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews /*
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Default to using the Internet root servers.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_master_loadbuffer(&source, &db->origin,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews &db->origin, db->rdclass,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews DNS_MASTER_HINT,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews &callbacks, db->mctx);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews } else
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = ISC_R_NOTFOUND;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews eresult = dns_db_endload(db, &callbacks);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = eresult;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews goto failure;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (check_hints(db) != ISC_R_SUCCESS)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews DNS_LOGMODULE_HINTS, ISC_LOG_WARNING,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews "extra data in root hints '%s'",
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews (filename != NULL) ? filename : "<BUILT-IN>");
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews *target = db;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews return (ISC_R_SUCCESS);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews failure:
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_HINTS,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews ISC_LOG_ERROR, "could not configure root hints from "
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews "'%s': %s", (filename != NULL) ? filename : "<BUILT-IN>",
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_result_totext(result));
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (db != NULL)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_db_detach(&db);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews return (result);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews}
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsstatic void
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updaterreport(dns_view_t *view, dns_name_t *name, isc_boolean_t missing,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdata_t *rdata)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews{
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews const char *viewname = "", *sep = "";
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews char namebuf[DNS_NAME_FORMATSIZE];
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews char typebuf[DNS_RDATATYPE_FORMATSIZE];
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews char databuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:123.123.123.123")];
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater isc_buffer_t buffer;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_result_t result;
1224c3b69b3d18f7127aa042644936af25a2d679Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (strcmp(view->name, "_bind") != 0 &&
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews strcmp(view->name, "_default") != 0) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews viewname = view->name;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews sep = ": view ";
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews }
e2e4d321999340802f77adaacd19c797d04b4b95Automatic Updater
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_name_format(name, namebuf, sizeof(namebuf));
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdatatype_format(rdata->type, typebuf, sizeof(typebuf));
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_buffer_init(&buffer, databuf, sizeof(databuf) - 1);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = dns_rdata_totext(rdata, NULL, &buffer);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews RUNTIME_CHECK(result == ISC_R_SUCCESS);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews databuf[isc_buffer_usedlength(&buffer)] = '\0';
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (missing)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews DNS_LOGMODULE_HINTS, ISC_LOG_WARNING,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews "checkhints%s%s: %s/%s (%s) missing from hints",
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews sep, viewname, namebuf, typebuf, databuf);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews else
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews DNS_LOGMODULE_HINTS, ISC_LOG_WARNING,
4abdfc917e6635a7c81d1f931a0c79227e72d025Mark Andrews "checkhints%s%s: %s/%s (%s) extra record "
4abdfc917e6635a7c81d1f931a0c79227e72d025Mark Andrews "in hints", sep, viewname, namebuf, typebuf,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews databuf);
4abdfc917e6635a7c81d1f931a0c79227e72d025Mark Andrews}
4abdfc917e6635a7c81d1f931a0c79227e72d025Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsstatic isc_boolean_t
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsinrrset(dns_rdataset_t *rrset, dns_rdata_t *rdata) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews isc_result_t result;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews dns_rdata_t current = DNS_RDATA_INIT;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
result = dns_rdataset_first(rrset);
while (result == ISC_R_SUCCESS) {
dns_rdataset_current(rrset, &current);
if (dns_rdata_compare(rdata, &current) == 0)
return (ISC_TRUE);
dns_rdata_reset(&current);
result = dns_rdataset_next(rrset);
}
return (ISC_FALSE);
}
/*
* Check that the address RRsets match.
*
* Note we don't complain about missing glue records.
*/
static void
check_address_records(dns_view_t *view, dns_db_t *hints, dns_db_t *db,
dns_name_t *name, isc_stdtime_t now)
{
isc_result_t hresult, rresult, result;
dns_rdataset_t hintrrset, rootrrset;
dns_rdata_t rdata = DNS_RDATA_INIT;
dns_name_t *foundname;
dns_fixedname_t fixed;
dns_rdataset_init(&hintrrset);
dns_rdataset_init(&rootrrset);
dns_fixedname_init(&fixed);
foundname = dns_fixedname_name(&fixed);
hresult = dns_db_find(hints, name, NULL, dns_rdatatype_a, 0,
now, NULL, foundname, &hintrrset, NULL);
rresult = dns_db_find(db, name, NULL, dns_rdatatype_a,
DNS_DBFIND_GLUEOK, now, NULL, foundname,
&rootrrset, NULL);
if (hresult == ISC_R_SUCCESS &&
(rresult == ISC_R_SUCCESS || rresult == DNS_R_GLUE)) {
result = dns_rdataset_first(&rootrrset);
while (result == ISC_R_SUCCESS) {
dns_rdata_reset(&rdata);
dns_rdataset_current(&rootrrset, &rdata);
if (!inrrset(&hintrrset, &rdata))
report(view, name, ISC_TRUE, &rdata);
result = dns_rdataset_next(&rootrrset);
}
result = dns_rdataset_first(&hintrrset);
while (result == ISC_R_SUCCESS) {
dns_rdata_reset(&rdata);
dns_rdataset_current(&hintrrset, &rdata);
if (!inrrset(&rootrrset, &rdata))
report(view, name, ISC_FALSE, &rdata);
result = dns_rdataset_next(&hintrrset);
}
}
if (hresult == ISC_R_NOTFOUND &&
(rresult == ISC_R_SUCCESS || rresult == DNS_R_GLUE)) {
result = dns_rdataset_first(&rootrrset);
while (result == ISC_R_SUCCESS) {
dns_rdata_reset(&rdata);
dns_rdataset_current(&rootrrset, &rdata);
report(view, name, ISC_TRUE, &rdata);
result = dns_rdataset_next(&rootrrset);
}
}
if (dns_rdataset_isassociated(&rootrrset))
dns_rdataset_disassociate(&rootrrset);
if (dns_rdataset_isassociated(&hintrrset))
dns_rdataset_disassociate(&hintrrset);
/*
* Check AAAA records.
*/
hresult = dns_db_find(hints, name, NULL, dns_rdatatype_aaaa, 0,
now, NULL, foundname, &hintrrset, NULL);
rresult = dns_db_find(db, name, NULL, dns_rdatatype_aaaa,
DNS_DBFIND_GLUEOK, now, NULL, foundname,
&rootrrset, NULL);
if (hresult == ISC_R_SUCCESS &&
(rresult == ISC_R_SUCCESS || rresult == DNS_R_GLUE)) {
result = dns_rdataset_first(&rootrrset);
while (result == ISC_R_SUCCESS) {
dns_rdata_reset(&rdata);
dns_rdataset_current(&rootrrset, &rdata);
if (!inrrset(&hintrrset, &rdata))
report(view, name, ISC_TRUE, &rdata);
dns_rdata_reset(&rdata);
result = dns_rdataset_next(&rootrrset);
}
result = dns_rdataset_first(&hintrrset);
while (result == ISC_R_SUCCESS) {
dns_rdata_reset(&rdata);
dns_rdataset_current(&hintrrset, &rdata);
if (!inrrset(&rootrrset, &rdata))
report(view, name, ISC_FALSE, &rdata);
dns_rdata_reset(&rdata);
result = dns_rdataset_next(&hintrrset);
}
}
if (hresult == ISC_R_NOTFOUND &&
(rresult == ISC_R_SUCCESS || rresult == DNS_R_GLUE)) {
result = dns_rdataset_first(&rootrrset);
while (result == ISC_R_SUCCESS) {
dns_rdata_reset(&rdata);
dns_rdataset_current(&rootrrset, &rdata);
report(view, name, ISC_TRUE, &rdata);
dns_rdata_reset(&rdata);
result = dns_rdataset_next(&rootrrset);
}
}
if (dns_rdataset_isassociated(&rootrrset))
dns_rdataset_disassociate(&rootrrset);
if (dns_rdataset_isassociated(&hintrrset))
dns_rdataset_disassociate(&hintrrset);
}
void
dns_root_checkhints(dns_view_t *view, dns_db_t *hints, dns_db_t *db) {
isc_result_t result;
dns_rdata_t rdata = DNS_RDATA_INIT;
dns_rdata_ns_t ns;
dns_rdataset_t hintns, rootns;
const char *viewname = "", *sep = "";
isc_stdtime_t now;
dns_name_t *name;
dns_fixedname_t fixed;
REQUIRE(hints != NULL);
REQUIRE(db != NULL);
REQUIRE(view != NULL);
isc_stdtime_get(&now);
if (strcmp(view->name, "_bind") != 0 &&
strcmp(view->name, "_default") != 0) {
viewname = view->name;
sep = ": view ";
}
dns_rdataset_init(&hintns);
dns_rdataset_init(&rootns);
dns_fixedname_init(&fixed);
name = dns_fixedname_name(&fixed);
result = dns_db_find(hints, dns_rootname, NULL, dns_rdatatype_ns, 0,
now, NULL, name, &hintns, NULL);
if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_HINTS, ISC_LOG_WARNING,
"checkhints%s%s: unable to get root NS rrset "
"from hints: %s", sep, viewname,
dns_result_totext(result));
goto cleanup;
}
result = dns_db_find(db, dns_rootname, NULL, dns_rdatatype_ns, 0,
now, NULL, name, &rootns, NULL);
if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_HINTS, ISC_LOG_WARNING,
"checkhints%s%s: unable to get root NS rrset "
"from cache: %s", sep, viewname,
dns_result_totext(result));
goto cleanup;
}
/*
* Look for missing root NS names.
*/
result = dns_rdataset_first(&rootns);
while (result == ISC_R_SUCCESS) {
dns_rdataset_current(&rootns, &rdata);
result = dns_rdata_tostruct(&rdata, &ns, NULL);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
result = in_rootns(&hintns, &ns.name);
if (result != ISC_R_SUCCESS) {
char namebuf[DNS_NAME_FORMATSIZE];
/* missing from hints */
dns_name_format(&ns.name, namebuf, sizeof(namebuf));
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_HINTS, ISC_LOG_WARNING,
"checkhints%s%s: unable to find root "
"NS '%s' in hints", sep, viewname,
namebuf);
} else
check_address_records(view, hints, db, &ns.name, now);
dns_rdata_reset(&rdata);
result = dns_rdataset_next(&rootns);
}
if (result != ISC_R_NOMORE) {
goto cleanup;
}
/*
* Look for extra root NS names.
*/
result = dns_rdataset_first(&hintns);
while (result == ISC_R_SUCCESS) {
dns_rdataset_current(&hintns, &rdata);
result = dns_rdata_tostruct(&rdata, &ns, NULL);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
result = in_rootns(&rootns, &ns.name);
if (result != ISC_R_SUCCESS) {
char namebuf[DNS_NAME_FORMATSIZE];
/* extra entry in hints */
dns_name_format(&ns.name, namebuf, sizeof(namebuf));
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_HINTS, ISC_LOG_WARNING,
"checkhints%s%s: extra NS '%s' in hints",
sep, viewname, namebuf);
}
dns_rdata_reset(&rdata);
result = dns_rdataset_next(&hintns);
}
if (result != ISC_R_NOMORE) {
goto cleanup;
}
cleanup:
if (dns_rdataset_isassociated(&rootns))
dns_rdataset_disassociate(&rootns);
if (dns_rdataset_isassociated(&hintns))
dns_rdataset_disassociate(&hintns);
}