unbound 0.1
Data Structures | Defines | Functions | Variables
remote.c File Reference

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

#include "config.h"
#include <openssl/err.h>
#include <ctype.h>
#include "ldns/ldns.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 "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 <sys/types.h>
#include <netdb.h>

Data Structures

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

Defines

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

Functions

static void log_crypto_err (const char *str)
 log ssl crypto err
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.
void daemon_remote_clear (struct daemon_remote *rc)
 remote control state to clear up.
void daemon_remote_delete (struct daemon_remote *rc)
 remote control state to delete.
static int add_open (const char *ip, int nr, struct listen_port **list, int noproto_is_err)
 Add and open a new control port.
struct listen_portdaemon_remote_open_ports (struct config_file *cfg)
 Open and create listening ports for remote control.
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.
int remote_accept_callback (struct comm_point *c, void *arg, int err, struct comm_reply *rep)
 handle remote control accept callbacks
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)
 Print fixed line of text over ssl connection in blocking mode.
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)
 Read until
is encountered If SSL signals EOF, the string up to then is returned (without
).
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 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 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, struct regional *region, char *args, uint8_t *root)
 parse args into delegpt
static void do_forward (SSL *ssl, struct worker *worker, char *args)
 do the status 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_lame (struct lruhash_entry *e, void *arg)
 callback for every lame element in the infra cache
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.
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 *rep)
 handle remote control data callbacks

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.

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.

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().

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.

Referenced by worker_init().

int ssl_print_text ( SSL *  ssl,
const char *  text 
)

Print fixed line of text over ssl connection in blocking mode.

Parameters:
ssl,:print to
text,:the text.
Returns:
false on connection failure.

References log_crypto_err(), VERB_QUERY, and verbose().

Referenced by ssl_print_vmsg().

int ssl_read_line ( SSL *  ssl,
char *  buf,
size_t  max 
)

Read until
is encountered If SSL signals EOF, the string up to then is returned (without
).

Parameters:
ssl,:the SSL connection to read from. blocking.
buf,:buffer to read to.
max,:size of buffer.
Returns:
false on connection failure.

References log_crypto_err(), and log_err().

Referenced by handle_req(), and ssl_read_buf().

void daemon_remote_exec ( struct worker worker)

Handle nonthreaded remote cmd execution.

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

Referenced by worker_handle_control_cmd().