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