xref: /netbsd-src/external/mpl/bind/dist/tests/include/tests/ns.h (revision bcda20f65a8566e103791ec395f7f499ef322704)
1 /*	$NetBSD: ns.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/zone.h>
34 
35 #include <ns/client.h>
36 #include <ns/hooks.h>
37 #include <ns/interfacemgr.h>
38 
39 #include <tests/dns.h>
40 
41 typedef struct ns_test_id {
42 	const char *description;
43 	int	    lineno;
44 } ns_test_id_t;
45 
46 #define NS_TEST_ID(desc) { .description = desc, .lineno = __LINE__ }
47 
48 extern dns_dispatchmgr_t *dispatchmgr;
49 extern ns_interfacemgr_t *interfacemgr;
50 extern ns_server_t	 *sctx;
51 
52 extern atomic_uint_fast32_t client_refs[32];
53 extern atomic_uintptr_t	    client_addrs[32];
54 
55 #if ISC_NETMGR_TRACE
56 #define FLARG                                                                  \
57 	, const char *file ISC_ATTR_UNUSED, unsigned int line ISC_ATTR_UNUSED, \
58 		const char *func ISC_ATTR_UNUSED
59 #else
60 #define FLARG
61 #endif
62 
63 int
64 setup_server(void **state);
65 int
66 teardown_server(void **state);
67 void
68 shutdown_interfacemgr(void *arg ISC_ATTR_UNUSED);
69 
70 /*%
71  * Load data for zone "zonename" from file "filename" and start serving it to
72  * clients matching "view".  Only one zone loaded using this function can be
73  * served at any given time.
74  */
75 isc_result_t
76 ns_test_serve_zone(const char *zonename, const char *filename,
77 		   dns_view_t *view);
78 
79 /*%
80  * Release the zone loaded by ns_test_serve_zone().
81  */
82 void
83 ns_test_cleanup_zone(void);
84 
85 isc_result_t
86 ns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin,
87 	       const char *testfile);
88 
89 isc_result_t
90 ns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz,
91 		size_t *sizep);
92 
93 void
94 ns_test_getclient(ns_interface_t *ifp0, bool tcp, ns_client_t **clientp);
95 
96 /*%
97  * Structure containing parameters for ns_test_qctx_create().
98  */
99 typedef struct ns_test_qctx_create_params {
100 	const char     *qname;
101 	dns_rdatatype_t qtype;
102 	unsigned int	qflags;
103 	bool		with_cache;
104 } ns_test_qctx_create_params_t;
105 
106 /*%
107  * Prepare a query context identical with one that would be prepared if a query
108  * with given QNAME, QTYPE and flags was received from a client.  Recursion is
109  * assumed to be allowed for this client.  If "with_cache" is set to true,
110  * a cache database will be created and associated with the view matching the
111  * incoming query.
112  */
113 isc_result_t
114 ns_test_qctx_create(const ns_test_qctx_create_params_t *params,
115 		    query_ctx_t			      **qctxp);
116 
117 /*%
118  * Destroy a query context created by ns_test_qctx_create().
119  */
120 void
121 ns_test_qctx_destroy(query_ctx_t **qctxp);
122 
123 /*%
124  * A hook callback interrupting execution at given hook's insertion point.
125  */
126 ns_hookresult_t
127 ns_test_hook_catch_call(void *arg, void *data, isc_result_t *resultp);
128