1 /* $NetBSD: dns.h,v 1.4 2025/01/26 16:25:49 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 #pragma once 17 18 /*! \file */ 19 20 #include <inttypes.h> 21 #include <stdbool.h> 22 23 #include <isc/buffer.h> 24 #include <isc/hash.h> 25 #include <isc/log.h> 26 #include <isc/loop.h> 27 #include <isc/mem.h> 28 #include <isc/result.h> 29 #include <isc/string.h> 30 #include <isc/timer.h> 31 #include <isc/util.h> 32 33 #include <dns/cache.h> 34 #include <dns/diff.h> 35 #include <dns/zone.h> 36 37 #include <tests/isc.h> 38 39 extern dns_zonemgr_t *zonemgr; 40 41 typedef struct { 42 dns_diffop_t op; 43 const char *owner; 44 dns_ttl_t ttl; 45 const char *type; 46 const char *rdata; 47 } zonechange_t; 48 49 #define ZONECHANGE_SENTINEL { 0, NULL, 0, NULL, NULL } 50 51 isc_result_t 52 dns_test_makeview(const char *name, bool with_dispatchmgr, bool with_cache, 53 dns_view_t **viewp); 54 55 /*% 56 * Create a zone with origin 'name', return a pointer to the zone object in 57 * 'zonep'. 58 * 59 * If 'view' is set, the returned zone will be assigned to the passed view. 60 * 'createview' must be set to false when 'view' is non-NULL. 61 * 62 * If 'view' is not set and 'createview' is true, a new view is also created 63 * and the returned zone is assigned to it. This imposes two requirements on 64 * the caller: 1) the returned zone has to be subsequently assigned to a zone 65 * manager, otherwise its cleanup will fail, 2) the created view has to be 66 * cleaned up by the caller. 67 * 68 * If 'view' is not set and 'createview' is false, the returned zone will not 69 * be assigned to any view. 70 */ 71 isc_result_t 72 dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view, 73 bool createview); 74 75 void 76 dns_test_setupzonemgr(void); 77 78 isc_result_t 79 dns_test_managezone(dns_zone_t *zone); 80 81 void 82 dns_test_releasezone(dns_zone_t *zone); 83 84 void 85 dns_test_closezonemgr(void); 86 87 void 88 dns_test_nap(uint32_t usec); 89 90 isc_result_t 91 dns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin, 92 const char *testfile); 93 94 isc_result_t 95 dns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz, 96 size_t *sizep); 97 98 char * 99 dns_test_tohex(const unsigned char *data, size_t len, char *buf, size_t buflen); 100 101 /*% 102 * Try parsing text form RDATA in "src" (of class "rdclass" and type "rdtype") 103 * into a structure representing that RDATA at "rdata", storing the 104 * uncompressed wire form of that RDATA at "dst", which is "dstlen" bytes long. 105 * Set 'warnings' to true to print logged warnings from dns_rdata_fromtext(). 106 */ 107 isc_result_t 108 dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass, 109 dns_rdatatype_t rdtype, unsigned char *dst, 110 size_t dstlen, const char *src, bool warnings); 111 112 void 113 dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname); 114 115 /*% 116 * Given a pointer to an uninitialized dns_diff_t structure in 'diff', make it 117 * contain diff tuples representing zone database changes listed in 'changes'. 118 * Set 'warnings' to true to print logged warnings from dns_rdata_fromtext(). 119 */ 120 isc_result_t 121 dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes, 122 bool warnings); 123