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 LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * 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 /** listening ports, opened, to be shared by threads */
76 struct listen_port* ports;
77 /** port number for remote that has ports opened. */
79 /** listening ports for remote control */
80 struct listen_port* rc_ports;
81 /** remote control connections management (for first worker) */
82 struct daemon_remote* rc;
83 /** ssl context for listening to dnstcp over ssl, and connecting ssl */
84 void* listen_sslctx, *connect_sslctx;
85 /** num threads allocated */
87 /** the worker entries */
88 struct worker** workers;
89 /** do we need to exit unbound (or is it only a reload?) */
91 /** master random table ; used for port div between threads on reload*/
92 struct ub_randstate* rand;
93 /** master allocation cache */
94 struct alloc_cache superalloc;
95 /** the module environment master value, copied and changed by threads*/
96 struct module_env* env;
97 /** stack of module callbacks */
98 struct module_stack mods;
99 /** access control, which client IPs are allowed to connect */
100 struct acl_list* acl;
101 /** local authority zones */
102 struct local_zones* local_zones;
103 /** last time of statistics printout */
104 struct timeval time_last_stat;
105 /** time when daemon started */
106 struct timeval time_boot;
110 * Initialize daemon structure.
111 * @return: The daemon structure, or NULL on error.
113 struct daemon* daemon_init(void);
116 * Open shared listening ports (if needed).
117 * The cfg member pointer must have been set for the daemon.
118 * @param daemon: the daemon.
119 * @return: false on error.
121 int daemon_open_shared_ports(struct daemon* daemon);
124 * Fork workers and start service.
125 * When the routine exits, it is no longer forked.
126 * @param daemon: the daemon.
128 void daemon_fork(struct daemon* daemon);
131 * Close off the worker thread information.
132 * Bring the daemon back into state ready for daemon_fork again.
133 * @param daemon: the daemon.
135 void daemon_cleanup(struct daemon* daemon);
138 * Delete workers, close listening ports.
139 * @param daemon: the daemon.
141 void daemon_delete(struct daemon* daemon);
144 * Apply config settings.
145 * @param daemon: the daemon.
146 * @param cfg: new config settings.
148 void daemon_apply_cfg(struct daemon* daemon, struct config_file* cfg);
150 #endif /* DAEMON_H */