Maintained by: NLnet Labs
Data Structures | Macros | Functions | Variables
remote.c File Reference

This file contains the remote control functionality for the daemon. More...

#include "config.h"
#include <ctype.h>
#include "daemon/remote.h"
#include "daemon/worker.h"
#include "daemon/daemon.h"
#include "daemon/stats.h"
#include "daemon/cachedump.h"
#include "util/log.h"
#include "util/config_file.h"
#include "util/net_help.h"
#include "util/module.h"
#include "services/listen_dnsport.h"
#include "services/cache/rrset.h"
#include "services/cache/infra.h"
#include "services/mesh.h"
#include "services/localzone.h"
#include "util/storage/slabhash.h"
#include "util/fptr_wlist.h"
#include "util/data/dname.h"
#include "validator/validator.h"
#include "validator/val_kcache.h"
#include "validator/val_kentry.h"
#include "validator/val_anchor.h"
#include "iterator/iterator.h"
#include "iterator/iter_fwd.h"
#include "iterator/iter_hints.h"
#include "iterator/iter_delegpt.h"
#include "services/outbound_list.h"
#include "services/outside_network.h"
#include "ldns/str2wire.h"
#include "ldns/parseutil.h"
#include "ldns/wire2str.h"
#include "ldns/sbuffer.h"

Data Structures

struct  del_info
 Local info for deletion functions. More...
 
struct  infra_arg
 structure for argument data for dump infra host More...
 

Macros

#define SQ   "="
 what to put on statistics lines between var and value, ": " or "="
 

Functions

static void timeval_subtract (struct timeval *d, const struct timeval *end, const struct timeval *start)
 subtract timers and the values do not overflow or become negative
 
static void timeval_divide (struct timeval *avg, const struct timeval *sum, size_t d)
 divide sum of timers to get average
 
struct daemon_remotedaemon_remote_create (struct config_file *cfg)
 Create new remote control state for the daemon. More...
 
void daemon_remote_clear (struct daemon_remote *rc)
 remote control state to clear up. More...
 
void daemon_remote_delete (struct daemon_remote *rc)
 remote control state to delete. More...
 
static int add_open (const char *ip, int nr, struct listen_port **list, int noproto_is_err)
 Add and open a new control port. More...
 
struct listen_portdaemon_remote_open_ports (struct config_file *cfg)
 Open and create listening ports for remote control. More...
 
static int accept_open (struct daemon_remote *rc, int fd)
 open accept commpoint
 
int daemon_remote_open_accept (struct daemon_remote *rc, struct listen_port *ports, struct worker *worker)
 Setup comm points for accepting remote control connections. More...
 
void daemon_remote_stop_accept (struct daemon_remote *rc)
 Stop accept handlers for TCP (until enabled again) More...
 
void daemon_remote_start_accept (struct daemon_remote *rc)
 Stop accept handlers for TCP (until enabled again) More...
 
int remote_accept_callback (struct comm_point *c, void *arg, int err, struct comm_reply *ATTR_UNUSED(rep))
 
static void state_list_remove_elem (struct rc_state **list, struct comm_point *c)
 delete from list
 
static void clean_point (struct daemon_remote *rc, struct rc_state *s)
 decrease active count and remove commpoint from busy list
 
int ssl_print_text (SSL *ssl, const char *text)
 
static int ssl_print_vmsg (SSL *ssl, const char *format, va_list args)
 print text over the ssl connection
 
int ssl_printf (SSL *ssl, const char *format,...)
 printf style printing to the ssl connection
 
int ssl_read_line (SSL *ssl, char *buf, size_t max)
 
static char * skipwhite (char *str)
 skip whitespace, return new pointer into string
 
static void send_ok (SSL *ssl)
 send the OK to the control client
 
static void do_stop (SSL *ssl, struct daemon_remote *rc)
 do the stop command
 
static void do_reload (SSL *ssl, struct daemon_remote *rc)
 do the reload command
 
static void do_verbosity (SSL *ssl, char *str)
 do the verbosity command
 
static int print_stats (SSL *ssl, const char *nm, struct stats_info *s)
 print stats from statinfo
 
static int print_thread_stats (SSL *ssl, int i, struct stats_info *s)
 print stats for one thread
 
static int print_longnum (SSL *ssl, char *desc, size_t x)
 print long number
 
static int print_mem (SSL *ssl, struct worker *worker, struct daemon *daemon)
 print mem stats
 
static int print_uptime (SSL *ssl, struct worker *worker, int reset)
 print uptime stats
 
static int print_hist (SSL *ssl, struct stats_info *s)
 print extended histogram
 
static int print_ext (SSL *ssl, struct stats_info *s)
 print extended stats
 
static void do_stats (SSL *ssl, struct daemon_remote *rc, int reset)
 do the stats command
 
static int parse_arg_name (SSL *ssl, char *str, uint8_t **res, size_t *len, int *labs)
 parse commandline argument domain name
 
static int find_arg2 (SSL *ssl, char *arg, char **arg2)
 find second argument, modifies string
 
static void do_zone_add (SSL *ssl, struct worker *worker, char *arg)
 Add a new zone.
 
static void do_zone_remove (SSL *ssl, struct worker *worker, char *arg)
 Remove a zone.
 
static void do_data_add (SSL *ssl, struct worker *worker, char *arg)
 Add new RR data.
 
static void do_data_remove (SSL *ssl, struct worker *worker, char *arg)
 Remove RR data.
 
static void do_lookup (SSL *ssl, struct worker *worker, char *arg)
 cache lookup of nameservers
 
static void do_cache_remove (struct worker *worker, uint8_t *nm, size_t nmlen, uint16_t t, uint16_t c)
 flush something from rrset and msg caches
 
static void do_flush_type (SSL *ssl, struct worker *worker, char *arg)
 flush a type
 
static void do_flush_stats (SSL *ssl, struct worker *worker)
 flush statistics
 
static void infra_del_host (struct lruhash_entry *e, void *arg)
 callback to delete hosts in infra cache
 
static void do_flush_infra (SSL *ssl, struct worker *worker, char *arg)
 flush infra cache
 
static void do_flush_requestlist (SSL *ssl, struct worker *worker)
 flush requestlist
 
static void zone_del_rrset (struct lruhash_entry *e, void *arg)
 callback to delete rrsets in a zone
 
static void zone_del_msg (struct lruhash_entry *e, void *arg)
 callback to delete messages in a zone
 
static void zone_del_kcache (struct lruhash_entry *e, void *arg)
 callback to delete keys in zone
 
static void do_flush_zone (SSL *ssl, struct worker *worker, char *arg)
 remove all rrsets and keys from zone from cache
 
static void bogus_del_rrset (struct lruhash_entry *e, void *arg)
 callback to delete bogus rrsets
 
static void bogus_del_msg (struct lruhash_entry *e, void *arg)
 callback to delete bogus messages
 
static void bogus_del_kcache (struct lruhash_entry *e, void *arg)
 callback to delete bogus keys
 
static void do_flush_bogus (SSL *ssl, struct worker *worker)
 remove all rrsets and keys from zone from cache
 
static void do_flush_name (SSL *ssl, struct worker *w, char *arg)
 remove name rrset from cache
 
static int ssl_print_name_dp (SSL *ssl, char *str, uint8_t *nm, uint16_t dclass, struct delegpt *dp)
 printout a delegation point info
 
static int print_root_fwds (SSL *ssl, struct iter_forwards *fwds, uint8_t *root)
 print root forwards
 
static struct delegptparse_delegpt (SSL *ssl, char *args, uint8_t *nm, int allow_names)
 parse args into delegpt
 
static void do_forward (SSL *ssl, struct worker *worker, char *args)
 do the status command
 
static int parse_fs_args (SSL *ssl, char *args, uint8_t **nm, struct delegpt **dp, int *insecure, int *prime)
 
static void do_forward_add (SSL *ssl, struct worker *worker, char *args)
 do the forward_add command
 
static void do_forward_remove (SSL *ssl, struct worker *worker, char *args)
 do the forward_remove command
 
static void do_stub_add (SSL *ssl, struct worker *worker, char *args)
 do the stub_add command
 
static void do_stub_remove (SSL *ssl, struct worker *worker, char *args)
 do the stub_remove command
 
static void do_insecure_add (SSL *ssl, struct worker *worker, char *arg)
 do the insecure_add command
 
static void do_insecure_remove (SSL *ssl, struct worker *worker, char *arg)
 do the insecure_remove command
 
static void do_status (SSL *ssl, struct worker *worker)
 do the status command
 
static void get_mesh_age (struct mesh_state *m, char *buf, size_t len, struct module_env *env)
 get age for the mesh state
 
static void get_mesh_status (struct mesh_area *mesh, struct mesh_state *m, char *buf, size_t len)
 get status of a mesh state
 
static void do_dump_requestlist (SSL *ssl, struct worker *worker)
 do the dump_requestlist command
 
static void dump_infra_host (struct lruhash_entry *e, void *arg)
 callback for every host element in the infra cache
 
static void do_dump_infra (SSL *ssl, struct worker *worker)
 do the dump_infra command
 
static void do_log_reopen (SSL *ssl, struct worker *worker)
 do the log_reopen command
 
static void do_set_option (SSL *ssl, struct worker *worker, char *arg)
 do the set_option command
 
void remote_get_opt_ssl (char *line, void *arg)
 routine to printout option values over SSL
 
static void do_get_option (SSL *ssl, struct worker *worker, char *arg)
 do the get_option command
 
static void do_list_forwards (SSL *ssl, struct worker *worker)
 do the list_forwards command
 
static void do_list_stubs (SSL *ssl, struct worker *worker)
 do the list_stubs command
 
static void do_list_local_zones (SSL *ssl, struct worker *worker)
 do the list_local_zones command
 
static void do_list_local_data (SSL *ssl, struct worker *worker)
 do the list_local_data command
 
static void distribute_cmd (struct daemon_remote *rc, SSL *ssl, char *cmd)
 tell other processes to execute the command
 
static int cmdcmp (char *p, const char *cmd, size_t len)
 check for name with end-of-string, space or tab after it
 
static void execute_cmd (struct daemon_remote *rc, SSL *ssl, char *cmd, struct worker *worker)
 execute a remote control command
 
void daemon_remote_exec (struct worker *worker)
 Handle nonthreaded remote cmd execution. More...
 
static void handle_req (struct daemon_remote *rc, struct rc_state *s, SSL *ssl)
 handle remote control request
 
int remote_control_callback (struct comm_point *c, void *arg, int err, struct comm_reply *ATTR_UNUSED(rep))
 

Variables

static const int inhibit_zero = 1
 if true, inhibits a lot of =0 lines from the stats output
 

Detailed Description

This file contains the remote control functionality for the daemon.

The remote control can be performed using either the commandline unbound-control tool, or a SSLv3/TLS capable web browser. The channel is secured using SSLv3 or TLSv1, and certificates. Both the server and the client(control tool) have their own keys.

Function Documentation

struct daemon_remote* daemon_remote_create ( struct config_file cfg)
read

Create new remote control state for the daemon.

Parameters
cfg,:config file with key file settings.
Returns
new state, or NULL on failure.

References daemon_remote_delete(), fname_after_chroot(), log_crypto_err(), log_err(), daemon_remote::max_active, config_file::remote_control_enable, config_file::server_cert_file, config_file::server_key_file, VERB_ALGO, and verbose().

Referenced by perform_setup(), and service_init().

void daemon_remote_clear ( struct daemon_remote rc)

remote control state to clear up.

Busy and accept points are closed. Does not delete the rc itself, or the ssl context (with its keys).

Parameters
rc,:state to clear.

References daemon_remote::accept_list, daemon_remote::active, daemon_remote::busy_list, rc_state::c, comm_point_delete(), listen_list_delete(), rc_state::next, and daemon_remote::worker.

Referenced by daemon_cleanup(), and daemon_remote_delete().

void daemon_remote_delete ( struct daemon_remote rc)

remote control state to delete.

Parameters
rc,:state to delete.

Referenced by daemon_delete(), and daemon_remote_create().

static int add_open ( const char *  ip,
int  nr,
struct listen_port **  list,
int  noproto_is_err 
)
static

Add and open a new control port.

Parameters
ip,:ip str
nr,:port nr
list,:list head
noproto_is_err,:if lack of protocol support is an error.
Returns
false on failure.

References create_tcp_accept_sock(), listen_port::fd, log_err(), and listen_port::next.

Referenced by daemon_remote_open_ports().

struct listen_port* daemon_remote_open_ports ( struct config_file cfg)
read

Open and create listening ports for remote control.

Parameters
cfg,:config options.
Returns
list of ports or NULL on failure. can be freed with listening_ports_free().

References add_open(), config_file::control_ifs, config_file::control_port, config_file::do_ip4, config_file::do_ip6, listening_ports_free(), log_assert, config_strlist::next, config_file::remote_control_enable, and config_strlist::str.

Referenced by daemon_open_shared_ports().

int daemon_remote_open_accept ( struct daemon_remote rc,
struct listen_port ports,
struct worker worker 
)

Setup comm points for accepting remote control connections.

Parameters
rc,:state
ports,:already opened ports.
worker,:worker with communication base. and links to command channels.
Returns
false on error.

References accept_open(), listen_port::fd, log_err(), listen_port::next, and daemon_remote::worker.

Referenced by worker_init().

void daemon_remote_stop_accept ( struct daemon_remote rc)

Stop accept handlers for TCP (until enabled again)

Parameters
rc,:state

References daemon_remote::accept_list, listen_list::com, and listen_list::next.

Referenced by worker_stop_accept().

void daemon_remote_start_accept ( struct daemon_remote rc)

Stop accept handlers for TCP (until enabled again)

Parameters
rc,:state

References daemon_remote::accept_list, listen_list::com, and listen_list::next.

Referenced by worker_start_accept().

void daemon_remote_exec ( struct worker worker)

Handle nonthreaded remote cmd execution.

Parameters
worker,:this worker (the remote worker).

References worker::cmd, execute_cmd(), log_err(), tube_read_msg(), VERB_ALGO, and verbose().