xref: /openbsd-src/usr.sbin/nsd/remote.h (revision b71395ea3d4830c6fd338870b804059761b8292d)
1d3fecca9Ssthen /*
2d3fecca9Ssthen  * remote.h - remote control for the NSD daemon.
3d3fecca9Ssthen  *
4d3fecca9Ssthen  * Copyright (c) 2008, NLnet Labs. All rights reserved.
5d3fecca9Ssthen  *
6d3fecca9Ssthen  * This software is open source.
7d3fecca9Ssthen  *
8d3fecca9Ssthen  * Redistribution and use in source and binary forms, with or without
9d3fecca9Ssthen  * modification, are permitted provided that the following conditions
10d3fecca9Ssthen  * are met:
11d3fecca9Ssthen  *
12d3fecca9Ssthen  * Redistributions of source code must retain the above copyright notice,
13d3fecca9Ssthen  * this list of conditions and the following disclaimer.
14d3fecca9Ssthen  *
15d3fecca9Ssthen  * Redistributions in binary form must reproduce the above copyright notice,
16d3fecca9Ssthen  * this list of conditions and the following disclaimer in the documentation
17d3fecca9Ssthen  * and/or other materials provided with the distribution.
18d3fecca9Ssthen  *
19d3fecca9Ssthen  * Neither the name of the NLNET LABS nor the names of its contributors may
20d3fecca9Ssthen  * be used to endorse or promote products derived from this software without
21d3fecca9Ssthen  * specific prior written permission.
22d3fecca9Ssthen  *
23d3fecca9Ssthen  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24cbbc2d6cSbrad  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25cbbc2d6cSbrad  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26cbbc2d6cSbrad  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27cbbc2d6cSbrad  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28cbbc2d6cSbrad  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29cbbc2d6cSbrad  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30cbbc2d6cSbrad  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31cbbc2d6cSbrad  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32cbbc2d6cSbrad  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33cbbc2d6cSbrad  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34d3fecca9Ssthen  */
35d3fecca9Ssthen 
36d3fecca9Ssthen /**
37d3fecca9Ssthen  * \file
38d3fecca9Ssthen  *
39d3fecca9Ssthen  * This file contains the remote control functionality for the daemon.
40d3fecca9Ssthen  * The remote control can be performed using either the commandline
41d3fecca9Ssthen  * nsd-control tool, or a SSLv3/TLS capable web browser.
42d3fecca9Ssthen  * The channel is secured using SSLv3 or TLSv1, and certificates.
43d3fecca9Ssthen  * Both the server and the client(control tool) have their own keys.
44d3fecca9Ssthen  */
45d3fecca9Ssthen 
46d3fecca9Ssthen #ifndef DAEMON_REMOTE_H
47d3fecca9Ssthen #define DAEMON_REMOTE_H
48d3fecca9Ssthen struct xfrd_state;
49d3fecca9Ssthen struct nsd_options;
50d3fecca9Ssthen 
51d3fecca9Ssthen /* private, defined in remote.c to keep ssl.h out of this header */
52d3fecca9Ssthen struct daemon_remote;
53d3fecca9Ssthen 
54d3fecca9Ssthen /* the remote control needs less backlog than the tcp53 service */
55d3fecca9Ssthen #define TCP_BACKLOG_REMOTE 16 /* listen() tcp backlog */
56d3fecca9Ssthen 
57d3fecca9Ssthen /**
58d3fecca9Ssthen  * Create new remote control state for the daemon.
59d3fecca9Ssthen  * Also setups the control port.
60d3fecca9Ssthen  * @param cfg: config file with key file settings.
61d3fecca9Ssthen  * @return new state, or NULL on failure.
62d3fecca9Ssthen  */
63d3fecca9Ssthen struct daemon_remote* daemon_remote_create(struct nsd_options* cfg);
64d3fecca9Ssthen 
65d3fecca9Ssthen /**
66d3fecca9Ssthen  * remote control state to delete.
67d3fecca9Ssthen  * @param rc: state to delete.
68d3fecca9Ssthen  */
69d3fecca9Ssthen void daemon_remote_delete(struct daemon_remote* rc);
70d3fecca9Ssthen 
71d3fecca9Ssthen /**
72d3fecca9Ssthen  * Close remote control ports.  Clears up busy connections.
73d3fecca9Ssthen  * Does not delete the rc itself, or the ssl context (with its keys).
74d3fecca9Ssthen  * @param rc: state to close.
75d3fecca9Ssthen  */
76d3fecca9Ssthen void daemon_remote_close(struct daemon_remote* rc);
77d3fecca9Ssthen 
78d3fecca9Ssthen /**
79d3fecca9Ssthen  * Open and create listening ports for remote control.
80d3fecca9Ssthen  * @param rc: rc state that contains list of accept port sockets.
81d3fecca9Ssthen  * @param cfg: config options.
82d3fecca9Ssthen  * @return false on failure.
83d3fecca9Ssthen  */
84d3fecca9Ssthen int daemon_remote_open_ports(struct daemon_remote* rc,
85d3fecca9Ssthen 	struct nsd_options* cfg);
86d3fecca9Ssthen 
87d3fecca9Ssthen /**
88d3fecca9Ssthen  * Setup comm points for accepting remote control connections.
89d3fecca9Ssthen  * @param rc: state
90d3fecca9Ssthen  * @param xfrd: the process that hosts the control connection.
91d3fecca9Ssthen  *	The rc is attached to its event base.
92d3fecca9Ssthen  */
93d3fecca9Ssthen void daemon_remote_attach(struct daemon_remote* rc, struct xfrd_state* xfrd);
94d3fecca9Ssthen 
95d3fecca9Ssthen /**
96*18e77612Sflorian  * Create and bind local listening socket
97*18e77612Sflorian  * @param path: path to the socket.
98*18e77612Sflorian  * @param noproto: on error, this is set true if cause is that local sockets
99*18e77612Sflorian  *	are not supported.
100*18e77612Sflorian  * @return: the socket. -1 on error.
101*18e77612Sflorian  */
102*18e77612Sflorian int create_local_accept_sock(const char* path, int* noproto);
103*18e77612Sflorian 
104d3fecca9Ssthen #endif /* DAEMON_REMOTE_H */
105