2011-02-26 02:26:33 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2011-02-26 02:26:33 +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-02-26 02:26:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2017-07-25 07:34:27 +02:00
|
|
|
#include <atf-c.h>
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2015-10-06 14:10:49 +11:00
|
|
|
#include <stdlib.h>
|
2011-09-03 19:22:43 +00:00
|
|
|
#include <time.h>
|
2011-09-02 21:15:39 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <isc/app.h>
|
|
|
|
#include <isc/buffer.h>
|
2015-10-02 12:32:42 -07:00
|
|
|
#include <isc/file.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <isc/hash.h>
|
2017-07-25 07:34:27 +02:00
|
|
|
#include <isc/hex.h>
|
2017-10-25 09:21:57 +02:00
|
|
|
#include <isc/lex.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <isc/mem.h>
|
2011-07-06 01:36:32 +00:00
|
|
|
#include <isc/os.h>
|
2015-10-02 14:38:59 -07:00
|
|
|
#include <isc/print.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <isc/string.h>
|
2011-07-06 01:36:32 +00:00
|
|
|
#include <isc/socket.h>
|
2015-10-02 12:32:42 -07:00
|
|
|
#include <isc/stdio.h>
|
2011-07-06 01:36:32 +00:00
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/timer.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
2011-12-05 20:51:41 +00:00
|
|
|
#include <dns/db.h>
|
2011-09-02 21:15:39 +00:00
|
|
|
#include <dns/fixedname.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
#include <dns/log.h>
|
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/result.h>
|
2011-09-02 21:15:39 +00:00
|
|
|
#include <dns/view.h>
|
|
|
|
#include <dns/zone.h>
|
2011-02-26 02:26:33 +00:00
|
|
|
|
|
|
|
#include "dnstest.h"
|
|
|
|
|
|
|
|
isc_mem_t *mctx = NULL;
|
|
|
|
isc_log_t *lctx = NULL;
|
2011-07-06 01:36:32 +00:00
|
|
|
isc_taskmgr_t *taskmgr = NULL;
|
2011-09-02 21:15:39 +00:00
|
|
|
isc_task_t *maintask = NULL;
|
2011-07-06 01:36:32 +00:00
|
|
|
isc_timermgr_t *timermgr = NULL;
|
|
|
|
isc_socketmgr_t *socketmgr = NULL;
|
2011-09-02 21:15:39 +00:00
|
|
|
dns_zonemgr_t *zonemgr = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
bool app_running = false;
|
2011-07-06 01:36:32 +00:00
|
|
|
int ncpus;
|
2018-04-17 08:29:14 -07:00
|
|
|
bool debug_mem_record = true;
|
2011-02-26 02:26:33 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool dst_active = false;
|
2011-02-26 02:26:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Logging categories: this needs to match the list in bin/named/log.c.
|
|
|
|
*/
|
|
|
|
static isc_logcategory_t categories[] = {
|
2011-03-01 23:48:07 +00:00
|
|
|
{ "", 0 },
|
|
|
|
{ "client", 0 },
|
|
|
|
{ "network", 0 },
|
|
|
|
{ "update", 0 },
|
|
|
|
{ "queries", 0 },
|
|
|
|
{ "unmatched", 0 },
|
2011-02-26 02:26:33 +00:00
|
|
|
{ "update-security", 0 },
|
|
|
|
{ "query-errors", 0 },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
static void
|
2014-03-04 10:42:25 -08:00
|
|
|
cleanup_managers(void) {
|
2011-09-02 21:15:39 +00:00
|
|
|
if (app_running)
|
|
|
|
isc_app_finish();
|
2011-07-06 01:36:32 +00:00
|
|
|
if (socketmgr != NULL)
|
|
|
|
isc_socketmgr_destroy(&socketmgr);
|
2011-09-02 21:15:39 +00:00
|
|
|
if (maintask != NULL)
|
|
|
|
isc_task_destroy(&maintask);
|
2011-07-06 01:36:32 +00:00
|
|
|
if (taskmgr != NULL)
|
|
|
|
isc_taskmgr_destroy(&taskmgr);
|
|
|
|
if (timermgr != NULL)
|
|
|
|
isc_timermgr_destroy(&timermgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2014-03-04 10:42:25 -08:00
|
|
|
create_managers(void) {
|
2011-07-06 01:36:32 +00:00
|
|
|
isc_result_t result;
|
|
|
|
ncpus = isc_os_ncpus();
|
|
|
|
|
|
|
|
CHECK(isc_taskmgr_create(mctx, ncpus, 0, &taskmgr));
|
|
|
|
CHECK(isc_timermgr_create(mctx, &timermgr));
|
|
|
|
CHECK(isc_socketmgr_create(mctx, &socketmgr));
|
2011-09-02 21:15:39 +00:00
|
|
|
CHECK(isc_task_create(taskmgr, 0, &maintask));
|
2011-07-06 01:36:32 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
2017-10-25 09:21:57 +02:00
|
|
|
cleanup:
|
2011-07-06 01:36:32 +00:00
|
|
|
cleanup_managers();
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_test_begin(FILE *logfile, bool start_managers) {
|
2011-02-26 02:26:33 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2011-10-10 02:46:16 +00:00
|
|
|
if (start_managers)
|
|
|
|
CHECK(isc_app_start());
|
2015-12-09 19:07:20 +05:30
|
|
|
if (debug_mem_record)
|
|
|
|
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
|
2011-02-26 02:26:33 +00:00
|
|
|
CHECK(isc_mem_create(0, 0, &mctx));
|
|
|
|
|
2018-04-22 14:56:28 +02:00
|
|
|
CHECK(dst_lib_init(mctx, NULL));
|
2018-04-17 08:29:14 -07:00
|
|
|
dst_active = true;
|
2011-02-26 02:26:33 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2011-07-06 01:36:32 +00:00
|
|
|
if (start_managers)
|
|
|
|
CHECK(create_managers());
|
|
|
|
|
2011-09-02 21:15:39 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
2011-02-26 02:26:33 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
2017-10-25 09:21:57 +02:00
|
|
|
cleanup:
|
2011-02-26 02:26:33 +00:00
|
|
|
dns_test_end();
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-04 10:42:25 -08:00
|
|
|
dns_test_end(void) {
|
2018-08-24 11:21:27 +02:00
|
|
|
cleanup_managers();
|
|
|
|
|
2017-09-12 19:05:46 -07:00
|
|
|
if (dst_active) {
|
|
|
|
dst_lib_destroy();
|
2018-04-17 08:29:14 -07:00
|
|
|
dst_active = false;
|
2017-09-12 19:05:46 -07:00
|
|
|
}
|
2011-07-06 01:36:32 +00:00
|
|
|
|
2016-07-11 13:36:16 +10:00
|
|
|
if (lctx != NULL)
|
|
|
|
isc_log_destroy(&lctx);
|
|
|
|
|
2011-02-26 02:26:33 +00:00
|
|
|
if (mctx != NULL)
|
|
|
|
isc_mem_destroy(&mctx);
|
2018-08-24 11:21:27 +02:00
|
|
|
|
2011-02-26 02:26:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 22:22:53 -07:00
|
|
|
/*
|
|
|
|
* Create a view.
|
|
|
|
*/
|
|
|
|
isc_result_t
|
2015-02-26 14:43:45 +05:30
|
|
|
dns_test_makeview(const char *name, dns_view_t **viewp) {
|
2014-05-29 22:22:53 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-09-02 21:15:39 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
|
2018-04-17 08:29:14 -07:00
|
|
|
bool createview)
|
2011-09-02 21:15:39 +00:00
|
|
|
{
|
2018-03-13 14:06:04 +01:00
|
|
|
dns_fixedname_t fixed_origin;
|
2011-09-02 21:15:39 +00:00
|
|
|
dns_zone_t *zone = NULL;
|
2018-03-13 14:06:04 +01:00
|
|
|
isc_result_t result;
|
2011-09-02 21:15:39 +00:00
|
|
|
dns_name_t *origin;
|
|
|
|
|
2018-03-13 14:06:04 +01:00
|
|
|
REQUIRE(view == NULL || !createview);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the zone structure.
|
|
|
|
*/
|
|
|
|
result = dns_zone_create(&zone, mctx);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set zone type and origin.
|
|
|
|
*/
|
2011-09-02 21:15:39 +00:00
|
|
|
dns_zone_settype(zone, dns_zone_master);
|
2018-03-13 14:06:04 +01:00
|
|
|
origin = dns_fixedname_initname(&fixed_origin);
|
|
|
|
result = dns_name_fromstring(origin, name, 0, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
goto detach_zone;
|
|
|
|
}
|
|
|
|
result = dns_zone_setorigin(zone, origin);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
goto detach_zone;
|
|
|
|
}
|
2011-09-02 21:15:39 +00:00
|
|
|
|
2018-03-13 14:06:04 +01:00
|
|
|
/*
|
|
|
|
* If requested, create a view.
|
|
|
|
*/
|
|
|
|
if (createview) {
|
|
|
|
result = dns_test_makeview("view", &view);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
goto detach_zone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If a view was passed as an argument or created above, attach the
|
|
|
|
* created zone to it. Otherwise, set the zone's class to IN.
|
|
|
|
*/
|
|
|
|
if (view != NULL) {
|
|
|
|
dns_zone_setview(zone, view);
|
|
|
|
dns_zone_setclass(zone, view->rdclass);
|
|
|
|
dns_view_addzone(view, zone);
|
|
|
|
} else {
|
|
|
|
dns_zone_setclass(zone, dns_rdataclass_in);
|
|
|
|
}
|
2011-09-02 21:15:39 +00:00
|
|
|
|
|
|
|
*zonep = zone;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
2018-03-13 14:06:04 +01:00
|
|
|
detach_zone:
|
|
|
|
dns_zone_detach(&zone);
|
|
|
|
|
2011-09-02 21:15:39 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2014-03-04 10:42:25 -08:00
|
|
|
dns_test_setupzonemgr(void) {
|
2011-09-02 21:15:39 +00:00
|
|
|
isc_result_t result;
|
|
|
|
REQUIRE(zonemgr == NULL);
|
2011-09-02 23:46:33 +00:00
|
|
|
|
2011-09-02 21:15:39 +00:00
|
|
|
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
|
|
|
&zonemgr);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_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
|
|
|
|
dns_test_releasezone(dns_zone_t *zone) {
|
|
|
|
REQUIRE(zonemgr != NULL);
|
|
|
|
dns_zonemgr_releasezone(zonemgr, zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-04 10:42:25 -08:00
|
|
|
dns_test_closezonemgr(void) {
|
2011-09-02 21:15:39 +00:00
|
|
|
REQUIRE(zonemgr != NULL);
|
2011-09-02 23:46:33 +00:00
|
|
|
|
2011-09-02 21:15:39 +00:00
|
|
|
dns_zonemgr_shutdown(zonemgr);
|
|
|
|
dns_zonemgr_detach(&zonemgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sleep for 'usec' microseconds.
|
|
|
|
*/
|
|
|
|
void
|
2018-03-28 14:19:37 +02:00
|
|
|
dns_test_nap(uint32_t usec) {
|
2011-09-02 21:15:39 +00:00
|
|
|
#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
|
|
|
|
}
|
2011-12-04 23:48:12 +00:00
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin,
|
2011-12-05 23:46:35 +00:00
|
|
|
const char *testfile)
|
2011-12-04 23:48:12 +00:00
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
dns_fixedname_t fixed;
|
|
|
|
dns_name_t *name;
|
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
name = dns_fixedname_initname(&fixed);
|
2011-12-04 23:48:12 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-04-03 13:22:09 +02:00
|
|
|
result = dns_db_load(*db, testfile, dns_masterformat_text, 0);
|
2011-12-04 23:48:12 +00:00
|
|
|
return (result);
|
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
|
2017-07-25 07:34:27 +02:00
|
|
|
/*
|
|
|
|
* Format contents of given memory region as a hex string, using the buffer
|
|
|
|
* of length 'buflen' pointed to by 'buf'. 'buflen' must be at least three
|
|
|
|
* times 'len'. Always returns 'buf'.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
dns_test_tohex(const unsigned char *data, size_t len, char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
isc_constregion_t source = {
|
|
|
|
.base = data,
|
|
|
|
.length = len
|
|
|
|
};
|
|
|
|
isc_buffer_t target;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
memset(buf, 0, buflen);
|
|
|
|
isc_buffer_init(&target, buf, buflen);
|
|
|
|
result = isc_hex_totext((isc_region_t *)&source, 1, " ", &target);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
2015-10-02 12:32:42 -07:00
|
|
|
isc_result_t
|
|
|
|
dns_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;
|
2015-10-08 09:56:48 -07:00
|
|
|
FILE *f = NULL;
|
2015-10-02 12:32:42 -07:00
|
|
|
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)
|
2015-10-08 09:56:48 -07:00
|
|
|
CHECK(ISC_R_UNEXPECTEDEND);
|
2015-10-02 12:32:42 -07:00
|
|
|
if (len > bufsiz * 2)
|
2015-10-08 09:56:48 -07:00
|
|
|
CHECK(ISC_R_NOSPACE);
|
2015-10-02 12:32:42 -07:00
|
|
|
rp = s;
|
|
|
|
for (i = 0; i < len; i += 2) {
|
|
|
|
n = fromhex(*rp++);
|
|
|
|
n *= 16;
|
|
|
|
n += fromhex(*rp++);
|
|
|
|
*bp++ = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*sizep = bp - buf;
|
|
|
|
|
2015-10-08 09:56:48 -07:00
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
cleanup:
|
2015-10-16 17:23:35 +11:00
|
|
|
isc_stdio_close(f);
|
2015-10-08 09:56:48 -07:00
|
|
|
return (result);
|
2015-10-02 12:32:42 -07:00
|
|
|
}
|
2017-10-25 09:21:57 +02:00
|
|
|
|
|
|
|
isc_result_t
|
2018-05-09 13:12:08 +02:00
|
|
|
dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
|
|
|
|
dns_rdatatype_t rdtype, unsigned char *dst,
|
|
|
|
size_t dstlen, const char *src)
|
2017-10-25 09:21:57 +02:00
|
|
|
{
|
|
|
|
isc_buffer_t source, target;
|
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
size_t length;
|
|
|
|
|
|
|
|
REQUIRE(rdata != NULL);
|
|
|
|
REQUIRE(DNS_RDATA_INITIALIZED(rdata));
|
|
|
|
REQUIRE(dst != NULL);
|
|
|
|
REQUIRE(src != NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up source to hold the input string.
|
|
|
|
*/
|
|
|
|
length = strlen(src);
|
|
|
|
isc_buffer_constinit(&source, src, length);
|
|
|
|
isc_buffer_add(&source, length);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a lexer as one is required by dns_rdata_fromtext().
|
|
|
|
*/
|
|
|
|
result = isc_lex_create(mctx, 64, &lex);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Point lexer at source.
|
|
|
|
*/
|
|
|
|
result = isc_lex_openbuffer(lex, &source);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
goto destroy_lexer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up target for storing uncompressed wire form of provided RDATA.
|
|
|
|
*/
|
|
|
|
isc_buffer_init(&target, dst, dstlen);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse input string, determining result.
|
|
|
|
*/
|
|
|
|
result = dns_rdata_fromtext(rdata, rdclass, rdtype, lex, dns_rootname,
|
2018-10-27 09:58:23 +11:00
|
|
|
0, mctx, &target, NULL);
|
2017-10-25 09:21:57 +02:00
|
|
|
|
|
|
|
destroy_lexer:
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
2018-02-28 14:12:02 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname) {
|
|
|
|
size_t length;
|
|
|
|
isc_buffer_t *b = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
dns_name_t *name;
|
|
|
|
|
|
|
|
length = strlen(namestr);
|
|
|
|
|
|
|
|
result = isc_buffer_allocate(mctx, &b, length);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
isc_buffer_putmem(b, (const unsigned char *) namestr, length);
|
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
name = dns_fixedname_initname(fname);
|
2018-02-28 14:12:02 -08:00
|
|
|
ATF_REQUIRE(name != NULL);
|
|
|
|
result = dns_name_fromtext(name, b, dns_rootname, 0, NULL);
|
|
|
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
isc_buffer_free(&b);
|
|
|
|
}
|
2018-03-13 14:06:06 +01:00
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes) {
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
unsigned char rdata_buf[1024];
|
|
|
|
dns_difftuple_t *tuple = NULL;
|
|
|
|
isc_consttextregion_t region;
|
|
|
|
dns_rdatatype_t rdatatype;
|
|
|
|
dns_fixedname_t fixedname;
|
|
|
|
dns_rdata_t rdata;
|
|
|
|
dns_name_t *name;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
REQUIRE(diff != NULL);
|
|
|
|
REQUIRE(changes != NULL);
|
|
|
|
|
|
|
|
dns_diff_init(mctx, diff);
|
|
|
|
|
|
|
|
for (i = 0; changes[i].owner != NULL; i++) {
|
|
|
|
/*
|
|
|
|
* Parse owner name.
|
|
|
|
*/
|
|
|
|
name = dns_fixedname_initname(&fixedname);
|
|
|
|
result = dns_name_fromstring(name, changes[i].owner, 0, mctx);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse RDATA type.
|
|
|
|
*/
|
|
|
|
region.base = changes[i].type;
|
|
|
|
region.length = strlen(changes[i].type);
|
|
|
|
result = dns_rdatatype_fromtext(&rdatatype,
|
|
|
|
(isc_textregion_t *)®ion);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse RDATA.
|
|
|
|
*/
|
|
|
|
dns_rdata_init(&rdata);
|
|
|
|
result = dns_test_rdatafromstring(&rdata, dns_rdataclass_in,
|
|
|
|
rdatatype, rdata_buf,
|
|
|
|
sizeof(rdata_buf),
|
|
|
|
changes[i].rdata);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a diff tuple for the parsed change and append it to
|
|
|
|
* the diff.
|
|
|
|
*/
|
|
|
|
result = dns_difftuple_create(mctx, changes[i].op, name,
|
|
|
|
changes[i].ttl, &rdata, &tuple);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dns_diff_append(diff, &tuple);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
dns_diff_clear(diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|