2011-07-06 05:05:52 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2011-07-06 05:05:52 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* 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/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2011-07-06 05:05:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <atf-c.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/timer.h>
|
|
|
|
|
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/view.h>
|
|
|
|
#include <dns/zone.h>
|
|
|
|
|
|
|
|
#include "dnstest.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Individual unit tests
|
|
|
|
*/
|
|
|
|
ATF_TC(zonemgr_create);
|
|
|
|
ATF_TC_HEAD(zonemgr_create, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "create zone manager");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(zonemgr_create, tc) {
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_t *myzonemgr = NULL;
|
2011-07-06 05:05:52 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_TRUE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
2015-01-20 13:29:18 -08:00
|
|
|
&myzonemgr);
|
2011-07-06 05:05:52 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_shutdown(myzonemgr);
|
|
|
|
dns_zonemgr_detach(&myzonemgr);
|
|
|
|
ATF_REQUIRE_EQ(myzonemgr, NULL);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ATF_TC(zonemgr_managezone);
|
|
|
|
ATF_TC_HEAD(zonemgr_managezone, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "manage and release a zone");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(zonemgr_managezone, tc) {
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_t *myzonemgr = NULL;
|
2011-07-06 05:05:52 +00:00
|
|
|
dns_zone_t *zone = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_TRUE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
2015-01-20 13:29:18 -08:00
|
|
|
&myzonemgr);
|
2011-07-06 05:05:52 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2011-09-02 21:15:39 +00:00
|
|
|
result = dns_test_makezone("foo", &zone, NULL, ISC_FALSE);
|
2011-07-06 05:05:52 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/* This should not succeed until the dns_zonemgr_setsize() is run */
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_managezone(myzonemgr, zone);
|
2011-07-06 05:05:52 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_FAILURE);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_setsize(myzonemgr, 1);
|
2011-07-06 05:05:52 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/* Now it should succeed */
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_managezone(myzonemgr, zone);
|
2011-07-06 05:05:52 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 1);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_releasezone(myzonemgr, zone);
|
2011-07-06 05:05:52 +00:00
|
|
|
dns_zone_detach(&zone);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_shutdown(myzonemgr);
|
|
|
|
dns_zonemgr_detach(&myzonemgr);
|
|
|
|
ATF_REQUIRE_EQ(myzonemgr, NULL);
|
2011-07-06 05:05:52 +00:00
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
2013-02-20 21:39:05 -08:00
|
|
|
ATF_TC(zonemgr_createzone);
|
|
|
|
ATF_TC_HEAD(zonemgr_createzone, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "create and release a zone");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(zonemgr_createzone, tc) {
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_t *myzonemgr = NULL;
|
2013-02-20 21:39:05 -08:00
|
|
|
dns_zone_t *zone = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_TRUE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
2015-01-20 13:29:18 -08:00
|
|
|
&myzonemgr);
|
2013-02-20 21:39:05 -08:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/* This should not succeed until the dns_zonemgr_setsize() is run */
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_createzone(myzonemgr, &zone);
|
2013-02-20 21:39:05 -08:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_FAILURE);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_setsize(myzonemgr, 1);
|
2013-02-20 21:39:05 -08:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/* Now it should succeed */
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_createzone(myzonemgr, &zone);
|
2013-02-20 21:39:05 -08:00
|
|
|
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
|
|
|
ATF_CHECK(zone != NULL);
|
|
|
|
|
|
|
|
if (zone != NULL)
|
|
|
|
dns_zone_detach(&zone);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_shutdown(myzonemgr);
|
|
|
|
dns_zonemgr_detach(&myzonemgr);
|
|
|
|
ATF_REQUIRE_EQ(myzonemgr, NULL);
|
2013-02-20 21:39:05 -08:00
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
2011-11-04 05:51:02 +00:00
|
|
|
ATF_TC(zonemgr_unreachable);
|
|
|
|
ATF_TC_HEAD(zonemgr_unreachable, tc) {
|
|
|
|
atf_tc_set_md_var(tc, "descr", "manage and release a zone");
|
|
|
|
}
|
|
|
|
ATF_TC_BODY(zonemgr_unreachable, tc) {
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_t *myzonemgr = NULL;
|
2011-11-04 05:51:02 +00:00
|
|
|
dns_zone_t *zone = NULL;
|
|
|
|
isc_sockaddr_t addr1, addr2;
|
|
|
|
struct in_addr in;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_time_t now;
|
|
|
|
|
|
|
|
UNUSED(tc);
|
|
|
|
|
|
|
|
TIME_NOW(&now);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, ISC_TRUE);
|
|
|
|
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
2015-01-20 13:29:18 -08:00
|
|
|
&myzonemgr);
|
2011-11-04 05:51:02 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = dns_test_makezone("foo", &zone, NULL, ISC_FALSE);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_setsize(myzonemgr, 1);
|
2011-11-04 05:51:02 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_zonemgr_managezone(myzonemgr, zone);
|
2011-11-04 05:51:02 +00:00
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
in.s_addr = inet_addr("10.53.0.1");
|
|
|
|
isc_sockaddr_fromin(&addr1, &in, 2112);
|
|
|
|
in.s_addr = inet_addr("10.53.0.2");
|
|
|
|
isc_sockaddr_fromin(&addr2, &in, 5150);
|
2015-01-20 13:29:18 -08:00
|
|
|
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2013-09-21 17:12:39 +10:00
|
|
|
/*
|
|
|
|
* We require multiple unreachableadd calls to mark a server as
|
|
|
|
* unreachable.
|
|
|
|
*/
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
|
|
|
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
|
|
|
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
|
|
|
ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2011-11-04 05:51:02 +00:00
|
|
|
|
|
|
|
in.s_addr = inet_addr("10.53.0.3");
|
|
|
|
isc_sockaddr_fromin(&addr2, &in, 5150);
|
2015-01-20 13:29:18 -08:00
|
|
|
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2013-09-21 17:12:39 +10:00
|
|
|
/*
|
|
|
|
* We require multiple unreachableadd calls to mark a server as
|
|
|
|
* unreachable.
|
|
|
|
*/
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
|
|
|
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
|
|
|
ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2011-11-04 05:51:02 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
|
|
|
|
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2011-11-04 05:51:02 +00:00
|
|
|
|
|
|
|
in.s_addr = inet_addr("10.53.0.2");
|
|
|
|
isc_sockaddr_fromin(&addr2, &in, 5150);
|
2015-01-20 13:29:18 -08:00
|
|
|
ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
|
|
|
dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
|
|
|
|
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
2011-11-04 05:51:02 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_releasezone(myzonemgr, zone);
|
2011-11-04 05:51:02 +00:00
|
|
|
dns_zone_detach(&zone);
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_zonemgr_shutdown(myzonemgr);
|
|
|
|
dns_zonemgr_detach(&myzonemgr);
|
|
|
|
ATF_REQUIRE_EQ(myzonemgr, NULL);
|
2011-11-04 05:51:02 +00:00
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-06 05:05:52 +00:00
|
|
|
/*
|
|
|
|
* Main
|
|
|
|
*/
|
|
|
|
ATF_TP_ADD_TCS(tp) {
|
|
|
|
ATF_TP_ADD_TC(tp, zonemgr_create);
|
|
|
|
ATF_TP_ADD_TC(tp, zonemgr_managezone);
|
2013-02-20 21:39:05 -08:00
|
|
|
ATF_TP_ADD_TC(tp, zonemgr_createzone);
|
2011-11-04 05:51:02 +00:00
|
|
|
ATF_TP_ADD_TC(tp, zonemgr_unreachable);
|
2011-07-06 05:05:52 +00:00
|
|
|
return (atf_no_error());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX:
|
|
|
|
* dns_zonemgr API calls that are not yet part of this unit test:
|
|
|
|
*
|
|
|
|
* - dns_zonemgr_attach
|
|
|
|
* - dns_zonemgr_forcemaint
|
|
|
|
* - dns_zonemgr_resumexfrs
|
|
|
|
* - dns_zonemgr_shutdown
|
|
|
|
* - dns_zonemgr_setsize
|
|
|
|
* - dns_zonemgr_settransfersin
|
|
|
|
* - dns_zonemgr_getttransfersin
|
|
|
|
* - dns_zonemgr_settransfersperns
|
|
|
|
* - dns_zonemgr_getttransfersperns
|
|
|
|
* - dns_zonemgr_setiolimit
|
|
|
|
* - dns_zonemgr_getiolimit
|
|
|
|
* - dns_zonemgr_dbdestroyed
|
|
|
|
* - dns_zonemgr_setserialqueryrate
|
|
|
|
* - dns_zonemgr_getserialqueryrate
|
|
|
|
*/
|