daemon.h revision 1.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 christos struct ub_randstate;
57 1.1 christos struct daemon_remote;
58 1.1 christos
59 1.1 christos #include "dnstap/dnstap_config.h"
60 1.1 christos #ifdef USE_DNSTAP
61 1.1 christos struct dt_env;
62 1.1 christos #endif
63 1.1 christos
64 1.1 christos /**
65 1.1 christos * Structure holding worker list.
66 1.1 christos * Holds globally visible information.
67 1.1 christos */
68 1.1 christos struct daemon {
69 1.1 christos /** The config settings */
70 1.1 christos struct config_file* cfg;
71 1.1 christos /** the chroot dir in use, NULL if none */
72 1.1 christos char* chroot;
73 1.1 christos /** pidfile that is used */
74 1.1 christos char* pidfile;
75 1.1 christos /** port number that has ports opened. */
76 1.1 christos int listening_port;
77 1.1 christos /** array of listening ports, opened. Listening ports per worker,
78 1.1 christos * or just one element[0] shared by the worker threads. */
79 1.1 christos struct listen_port** ports;
80 1.1 christos /** size of ports array */
81 1.1 christos size_t num_ports;
82 1.1 christos /** reuseport is enabled if true */
83 1.1 christos int reuseport;
84 1.1 christos /** port number for remote that has ports opened. */
85 1.1 christos int rc_port;
86 1.1 christos /** listening ports for remote control */
87 1.1 christos struct listen_port* rc_ports;
88 1.1 christos /** remote control connections management (for first worker) */
89 1.1 christos struct daemon_remote* rc;
90 1.1 christos /** ssl context for listening to dnstcp over ssl, and connecting ssl */
91 1.1 christos void* listen_sslctx, *connect_sslctx;
92 1.1 christos /** num threads allocated */
93 1.1 christos int num;
94 1.1 christos /** the worker entries */
95 1.1 christos struct worker** workers;
96 1.1 christos /** do we need to exit unbound (or is it only a reload?) */
97 1.1 christos int need_to_exit;
98 1.1 christos /** master random table ; used for port div between threads on reload*/
99 1.1 christos struct ub_randstate* rand;
100 1.1 christos /** master allocation cache */
101 1.1 christos struct alloc_cache superalloc;
102 1.1 christos /** the module environment master value, copied and changed by threads*/
103 1.1 christos struct module_env* env;
104 1.1 christos /** stack of module callbacks */
105 1.1 christos struct module_stack mods;
106 1.1 christos /** access control, which client IPs are allowed to connect */
107 1.1 christos struct acl_list* acl;
108 1.1 christos /** local authority zones */
109 1.1 christos struct local_zones* local_zones;
110 1.1 christos /** last time of statistics printout */
111 1.1 christos struct timeval time_last_stat;
112 1.1 christos /** time when daemon started */
113 1.1 christos struct timeval time_boot;
114 1.1 christos #ifdef USE_DNSTAP
115 1.1 christos /** the dnstap environment master value, copied and changed by threads*/
116 1.1 christos struct dt_env* dtenv;
117 1.1 christos #endif
118 1.1 christos };
119 1.1 christos
120 1.1 christos /**
121 1.1 christos * Initialize daemon structure.
122 1.1 christos * @return: The daemon structure, or NULL on error.
123 1.1 christos */
124 1.1 christos struct daemon* daemon_init(void);
125 1.1 christos
126 1.1 christos /**
127 1.1 christos * Open shared listening ports (if needed).
128 1.1 christos * The cfg member pointer must have been set for the daemon.
129 1.1 christos * @param daemon: the daemon.
130 1.1 christos * @return: false on error.
131 1.1 christos */
132 1.1 christos int daemon_open_shared_ports(struct daemon* daemon);
133 1.1 christos
134 1.1 christos /**
135 1.1 christos * Fork workers and start service.
136 1.1 christos * When the routine exits, it is no longer forked.
137 1.1 christos * @param daemon: the daemon.
138 1.1 christos */
139 1.1 christos void daemon_fork(struct daemon* daemon);
140 1.1 christos
141 1.1 christos /**
142 1.1 christos * Close off the worker thread information.
143 1.1 christos * Bring the daemon back into state ready for daemon_fork again.
144 1.1 christos * @param daemon: the daemon.
145 1.1 christos */
146 1.1 christos void daemon_cleanup(struct daemon* daemon);
147 1.1 christos
148 1.1 christos /**
149 1.1 christos * Delete workers, close listening ports.
150 1.1 christos * @param daemon: the daemon.
151 1.1 christos */
152 1.1 christos void daemon_delete(struct daemon* daemon);
153 1.1 christos
154 1.1 christos /**
155 1.1 christos * Apply config settings.
156 1.1 christos * @param daemon: the daemon.
157 1.1 christos * @param cfg: new config settings.
158 1.1 christos */
159 1.1 christos void daemon_apply_cfg(struct daemon* daemon, struct config_file* cfg);
160 1.1 christos
161 1.1 christos #endif /* DAEMON_H */
162