xref: /openbsd/usr.sbin/nsd/remote.h (revision 73471bf0)
1 /*
2  * remote.h - remote control for the NSD daemon.
3  *
4  * Copyright (c) 2008, 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  * This file contains the remote control functionality for the daemon.
40  * The remote control can be performed using either the commandline
41  * nsd-control tool, or a SSLv3/TLS capable web browser.
42  * The channel is secured using SSLv3 or TLSv1, and certificates.
43  * Both the server and the client(control tool) have their own keys.
44  */
45 
46 #ifndef DAEMON_REMOTE_H
47 #define DAEMON_REMOTE_H
48 struct xfrd_state;
49 struct nsd_options;
50 
51 /* private, defined in remote.c to keep ssl.h out of this header */
52 struct daemon_remote;
53 
54 /* the remote control needs less backlog than the tcp53 service */
55 #define TCP_BACKLOG_REMOTE 16 /* listen() tcp backlog */
56 
57 /**
58  * Create new remote control state for the daemon.
59  * Also setups the control port.
60  * @param cfg: config file with key file settings.
61  * @return new state, or NULL on failure.
62  */
63 struct daemon_remote* daemon_remote_create(struct nsd_options* cfg);
64 
65 /**
66  * remote control state to delete.
67  * @param rc: state to delete.
68  */
69 void daemon_remote_delete(struct daemon_remote* rc);
70 
71 /**
72  * Close remote control ports.  Clears up busy connections.
73  * Does not delete the rc itself, or the ssl context (with its keys).
74  * @param rc: state to close.
75  */
76 void daemon_remote_close(struct daemon_remote* rc);
77 
78 /**
79  * Open and create listening ports for remote control.
80  * @param rc: rc state that contains list of accept port sockets.
81  * @param cfg: config options.
82  * @return false on failure.
83  */
84 int daemon_remote_open_ports(struct daemon_remote* rc,
85 	struct nsd_options* cfg);
86 
87 /**
88  * Setup comm points for accepting remote control connections.
89  * @param rc: state
90  * @param xfrd: the process that hosts the control connection.
91  *	The rc is attached to its event base.
92  */
93 void daemon_remote_attach(struct daemon_remote* rc, struct xfrd_state* xfrd);
94 
95 /**
96  * Process statistic results and send them
97  * @param rc: state.
98  */
99 void daemon_remote_process_stats(struct daemon_remote* rc);
100 
101 /**
102  * Create and bind local listening socket
103  * @param path: path to the socket.
104  * @param noproto: on error, this is set true if cause is that local sockets
105  *	are not supported.
106  * @return: the socket. -1 on error.
107  */
108 int create_local_accept_sock(const char* path, int* noproto);
109 
110 #endif /* DAEMON_REMOTE_H */
111