Home | History | Annotate | Line # | Download | only in dist
      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 #ifdef BIND8_STATS
     52 struct nsdst;
     53 struct remote_stream;
     54 struct evbuffer;
     55 #endif /* BIND8_STATS */
     56 
     57 /* private, defined in remote.c to keep ssl.h out of this header */
     58 struct daemon_remote;
     59 
     60 /* the remote control needs less backlog than the tcp53 service */
     61 #define TCP_BACKLOG_REMOTE 16 /* listen() tcp backlog */
     62 
     63 /**
     64  * Create new remote control state for the daemon.
     65  * Also setups the control port.
     66  * @param cfg: config file with key file settings.
     67  * @return new state, or NULL on failure.
     68  */
     69 struct daemon_remote* daemon_remote_create(struct nsd_options* cfg);
     70 
     71 /**
     72  * remote control state to delete.
     73  * @param rc: state to delete.
     74  */
     75 void daemon_remote_delete(struct daemon_remote* rc);
     76 
     77 /**
     78  * Close remote control ports.  Clears up busy connections.
     79  * Does not delete the rc itself, or the ssl context (with its keys).
     80  * @param rc: state to close.
     81  */
     82 void daemon_remote_close(struct daemon_remote* rc);
     83 
     84 /**
     85  * Open and create listening ports for remote control.
     86  * @param rc: rc state that contains list of accept port sockets.
     87  * @param cfg: config options.
     88  * @return false on failure.
     89  */
     90 int daemon_remote_open_ports(struct daemon_remote* rc,
     91 	struct nsd_options* cfg);
     92 
     93 /**
     94  * Setup comm points for accepting remote control connections.
     95  * @param rc: state
     96  * @param xfrd: the process that hosts the control connection.
     97  *	The rc is attached to its event base.
     98  */
     99 void daemon_remote_attach(struct daemon_remote* rc, struct xfrd_state* xfrd);
    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 void xfrd_reload_config(struct xfrd_state *xfrd);
    111 
    112 #ifdef BIND8_STATS
    113 
    114 /**
    115  * Allocate stats temp arrays, for taking a coherent snapshot of the
    116  * statistics values at that time.
    117  * @param xfrd: the process that hosts the control connection.
    118  * @param stats: where to store the stats pointer
    119  * @param zonestats: where to store the zonestats pointer
    120  */
    121 void process_stats_alloc(struct xfrd_state* xfrd,
    122                          struct nsdst** stats,
    123                          struct nsdst** zonestats);
    124 
    125 /**
    126  * Grab a copy of the statistics, at this particular time.
    127  * @param xfrd: the process that hosts the control connection.
    128  * @param stattime: where to write the timeofday
    129  * @param stats: where to copy the stats to
    130  * @param zonestats: where to copy the zonestats to
    131  */
    132 void process_stats_grab(struct xfrd_state* xfrd,
    133                         struct timeval* stattime,
    134                         struct nsdst* stats,
    135                         struct nsdst** zonestats);
    136 /**
    137  * Add the old and new processes stat values into the first part of the
    138  * array of stats
    139  * @param xfrd: the process that hosts the control connection.
    140  * @param stats: the stats pointer
    141  */
    142 void process_stats_add_old_new(struct xfrd_state* xfrd, struct nsdst* stats);
    143 
    144 /**
    145  * Manage clearing of stats, a cumulative count of cleared statistics
    146  * @param xfrd: the process that hosts the control connection.
    147  * @param stats: the stats pointer
    148  * @param peek: whether to reset the stats time (0) or not (1)
    149  */
    150 void
    151 process_stats_manage_clear(struct xfrd_state* xfrd,
    152                            struct nsdst* stats,
    153                            int peek);
    154 
    155 /**
    156  * Add up the statistics to get the total over the server children.
    157  * @param xfrd: the process that hosts the control connection.
    158  * @param total: where to store the total data
    159  * @param stats: the stats pointer
    160  */
    161 void process_stats_add_total(struct xfrd_state* xfrd,
    162                              struct nsdst* total,
    163                              struct nsdst* stats);
    164 
    165 /**
    166  * Process the statistics and output them
    167  * @param ssl: the remote stream to write normal remote-control output to
    168  * @param evbuf: the HTTP buffer to write prometheus metrics output to
    169  * @param xfrd: the process that hosts the control connection.
    170  * @param peek: whether to reset the stats time (0) or not (1)
    171  */
    172 void process_stats(struct remote_stream* ssl,
    173                    struct evbuffer* evbuf,
    174                    struct xfrd_state* xfrd,
    175                    int peek);
    176 
    177 #ifdef USE_ZONE_STATS
    178 /**
    179  * Process the zonestat statistics and output them
    180  * @param ssl: the remote stream to write normal remote-control output to
    181  * @param evbuf: the HTTP buffer to write prometheus metrics output to
    182  * @param xfrd: the process that hosts the control connection.
    183  * @param clear: whether to reset the stats time
    184  * @param zonestats: the zonestats pointer
    185  */
    186 void zonestat_print(struct remote_stream *ssl, struct evbuffer *evbuf,
    187                     struct xfrd_state *xfrd, int clear,
    188                     struct nsdst **zonestats);
    189 #endif /*USE_ZONE_STATS*/
    190 
    191 const char* opcode2str(int o);
    192 
    193 void timeval_subtract(struct timeval *d, const struct timeval *end,
    194                       const struct timeval *start);
    195 
    196 #endif /* BIND8_STATS */
    197 
    198 #endif /* DAEMON_REMOTE_H */
    199