]> CyberLeo.Net >> Repos - FreeBSD/releng/10.1.git/blob - contrib/unbound/daemon/daemon.h
Remove empty sections.
[FreeBSD/releng/10.1.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 #ifdef UB_ON_WINDOWS
49 #  include "util/winsock_event.h"
50 #endif
51 struct config_file;
52 struct worker;
53 struct listen_port;
54 struct slabhash;
55 struct module_env;
56 struct rrset_cache;
57 struct acl_list;
58 struct local_zones;
59 struct ub_randstate;
60 struct daemon_remote;
61
62 /**
63  * Structure holding worker list.
64  * Holds globally visible information.
65  */
66 struct daemon {
67         /** The config settings */
68         struct config_file* cfg;
69         /** the chroot dir in use, NULL if none */
70         char* chroot;
71         /** pidfile that is used */
72         char* pidfile;
73         /** port number that has ports opened. */
74         int listening_port;
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 */
79         size_t num_ports;
80         /** port number for remote that has ports opened. */
81         int rc_port;
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 */
89         int num;
90         /** the worker entries */
91         struct worker** workers;
92         /** do we need to exit unbound (or is it only a reload?) */
93         int need_to_exit;
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;
110 };
111
112 /**
113  * Initialize daemon structure.
114  * @return: The daemon structure, or NULL on error.
115  */
116 struct daemon* daemon_init(void);
117
118 /**
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.
123  */
124 int daemon_open_shared_ports(struct daemon* daemon);
125
126 /**
127  * Fork workers and start service.
128  * When the routine exits, it is no longer forked.
129  * @param daemon: the daemon.
130  */
131 void daemon_fork(struct daemon* daemon);
132
133 /**
134  * Close off the worker thread information.
135  * Bring the daemon back into state ready for daemon_fork again.
136  * @param daemon: the daemon.
137  */
138 void daemon_cleanup(struct daemon* daemon);
139
140 /**
141  * Delete workers, close listening ports.
142  * @param daemon: the daemon.
143  */
144 void daemon_delete(struct daemon* daemon);
145
146 /**
147  * Apply config settings.
148  * @param daemon: the daemon.
149  * @param cfg: new config settings.
150  */
151 void daemon_apply_cfg(struct daemon* daemon, struct config_file* cfg);
152
153 #endif /* DAEMON_H */