]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/unbound/daemon/daemon.h
Fix multiple vulnerabilities in unbound.
[FreeBSD/FreeBSD.git] / contrib / unbound / daemon / daemon.h
1 /*
2  * daemon/daemon.h - collection of workers that handles requests.
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  * 
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * 
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * 
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  * 
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 /**
37  * \file
38  *
39  * The daemon consists of global settings and a number of workers.
40  */
41
42 #ifndef DAEMON_H
43 #define DAEMON_H
44
45 #include "util/locks.h"
46 #include "util/alloc.h"
47 #include "services/modstack.h"
48 struct config_file;
49 struct worker;
50 struct listen_port;
51 struct slabhash;
52 struct module_env;
53 struct rrset_cache;
54 struct acl_list;
55 struct local_zones;
56 struct views;
57 struct ub_randstate;
58 struct daemon_remote;
59 struct respip_set;
60 struct shm_main_info;
61
62 #include "dnstap/dnstap_config.h"
63 #ifdef USE_DNSTAP
64 struct dt_env;
65 #endif
66
67 #include "dnscrypt/dnscrypt_config.h"
68 #ifdef USE_DNSCRYPT
69 struct dnsc_env;
70 #endif
71
72 /**
73  * Structure holding worker list.
74  * Holds globally visible information.
75  */
76 struct daemon {
77         /** The config settings */
78         struct config_file* cfg;
79         /** the chroot dir in use, NULL if none */
80         char* chroot;
81         /** pidfile that is used */
82         char* pidfile;
83         /** port number that has ports opened. */
84         int listening_port;
85         /** array of listening ports, opened.  Listening ports per worker,
86          * or just one element[0] shared by the worker threads. */
87         struct listen_port** ports;
88         /** size of ports array */
89         size_t num_ports;
90         /** reuseport is enabled if true */
91         int reuseport;
92         /** port number for remote that has ports opened. */
93         int rc_port;
94         /** listening ports for remote control */
95         struct listen_port* rc_ports;
96         /** remote control connections management (for first worker) */
97         struct daemon_remote* rc;
98         /** ssl context for listening to dnstcp over ssl, and connecting ssl */
99         void* listen_sslctx, *connect_sslctx;
100         /** num threads allocated */
101         int num;
102         /** the worker entries */
103         struct worker** workers;
104         /** do we need to exit unbound (or is it only a reload?) */
105         int need_to_exit;
106         /** master random table ; used for port div between threads on reload*/
107         struct ub_randstate* rand;
108         /** master allocation cache */
109         struct alloc_cache superalloc;
110         /** the module environment master value, copied and changed by threads*/
111         struct module_env* env;
112         /** stack of module callbacks */
113         struct module_stack mods;
114         /** access control, which client IPs are allowed to connect */
115         struct acl_list* acl;
116         /** TCP connection limit, limit connections from client IPs */
117         struct tcl_list* tcl;
118         /** local authority zones */
119         struct local_zones* local_zones;
120         /** last time of statistics printout */
121         struct timeval time_last_stat;
122         /** time when daemon started */
123         struct timeval time_boot;
124         /** views structure containing view tree */
125         struct views* views;
126 #ifdef USE_DNSTAP
127         /** the dnstap environment master value, copied and changed by threads*/
128         struct dt_env* dtenv;
129 #endif
130         struct shm_main_info* shm_info;
131         /** response-ip set with associated actions and tags. */
132         struct respip_set* respip_set;
133         /** some response-ip tags or actions are configured if true */
134         int use_response_ip;
135         /** some RPZ policies are configured */
136         int use_rpz;
137 #ifdef USE_DNSCRYPT
138         /** the dnscrypt environment */
139         struct dnsc_env* dnscenv;
140 #endif
141 };
142
143 /**
144  * Initialize daemon structure.
145  * @return: The daemon structure, or NULL on error.
146  */
147 struct daemon* daemon_init(void);
148
149 /**
150  * Open shared listening ports (if needed).
151  * The cfg member pointer must have been set for the daemon.
152  * @param daemon: the daemon.
153  * @return: false on error.
154  */
155 int daemon_open_shared_ports(struct daemon* daemon);
156
157 /**
158  * Fork workers and start service.
159  * When the routine exits, it is no longer forked.
160  * @param daemon: the daemon.
161  */
162 void daemon_fork(struct daemon* daemon);
163
164 /**
165  * Close off the worker thread information.
166  * Bring the daemon back into state ready for daemon_fork again.
167  * @param daemon: the daemon.
168  */
169 void daemon_cleanup(struct daemon* daemon);
170
171 /**
172  * Delete workers, close listening ports.
173  * @param daemon: the daemon.
174  */
175 void daemon_delete(struct daemon* daemon);
176
177 /**
178  * Apply config settings.
179  * @param daemon: the daemon.
180  * @param cfg: new config settings.
181  */
182 void daemon_apply_cfg(struct daemon* daemon, struct config_file* cfg);
183
184 #endif /* DAEMON_H */