2 * daemon/daemon.h - collection of workers that handles requests.
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
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.
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.
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.
39 * The daemon consists of global settings and a number of workers.
45 #include "util/locks.h"
46 #include "util/alloc.h"
47 #include "services/modstack.h"
49 # include "util/winsock_event.h"
63 * Structure holding worker list.
64 * Holds globally visible information.
67 /** The config settings */
68 struct config_file* cfg;
69 /** the chroot dir in use, NULL if none */
71 /** pidfile that is used */
73 /** port number that has ports opened. */
75 /** array of listening ports, opened. Listening ports per worker,
76 * or just one element[0] shared by the worker threads. */
77 struct listen_port** ports;
78 /** size of ports array */
80 /** port number for remote that has ports opened. */
82 /** listening ports for remote control */
83 struct listen_port* rc_ports;
84 /** remote control connections management (for first worker) */
85 struct daemon_remote* rc;
86 /** ssl context for listening to dnstcp over ssl, and connecting ssl */
87 void* listen_sslctx, *connect_sslctx;
88 /** num threads allocated */
90 /** the worker entries */
91 struct worker** workers;
92 /** do we need to exit unbound (or is it only a reload?) */
94 /** master random table ; used for port div between threads on reload*/
95 struct ub_randstate* rand;
96 /** master allocation cache */
97 struct alloc_cache superalloc;
98 /** the module environment master value, copied and changed by threads*/
99 struct module_env* env;
100 /** stack of module callbacks */
101 struct module_stack mods;
102 /** access control, which client IPs are allowed to connect */
103 struct acl_list* acl;
104 /** local authority zones */
105 struct local_zones* local_zones;
106 /** last time of statistics printout */
107 struct timeval time_last_stat;
108 /** time when daemon started */
109 struct timeval time_boot;
113 * Initialize daemon structure.
114 * @return: The daemon structure, or NULL on error.
116 struct daemon* daemon_init(void);
119 * Open shared listening ports (if needed).
120 * The cfg member pointer must have been set for the daemon.
121 * @param daemon: the daemon.
122 * @return: false on error.
124 int daemon_open_shared_ports(struct daemon* daemon);
127 * Fork workers and start service.
128 * When the routine exits, it is no longer forked.
129 * @param daemon: the daemon.
131 void daemon_fork(struct daemon* daemon);
134 * Close off the worker thread information.
135 * Bring the daemon back into state ready for daemon_fork again.
136 * @param daemon: the daemon.
138 void daemon_cleanup(struct daemon* daemon);
141 * Delete workers, close listening ports.
142 * @param daemon: the daemon.
144 void daemon_delete(struct daemon* daemon);
147 * Apply config settings.
148 * @param daemon: the daemon.
149 * @param cfg: new config settings.
151 void daemon_apply_cfg(struct daemon* daemon, struct config_file* cfg);
153 #endif /* DAEMON_H */