Debian Codegraph @

tests/include/tests/dns.h

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