control.c File Reference

Implementation for Tor's control-socket interface. See doc/spec/control-spec.txt for full details on protocol. More...

#include "or.h"

Data Structures

struct  getinfo_item_t

Defines

#define CONTROL_PRIVATE
#define STATE_IS_OPEN(s)   ((s) == CONTROL_CONN_STATE_OPEN)
#define _EVENT_MIN   0x0001
#define EVENT_CIRCUIT_STATUS   0x0001
#define EVENT_STREAM_STATUS   0x0002
#define EVENT_OR_CONN_STATUS   0x0003
#define EVENT_BANDWIDTH_USED   0x0004
#define EVENT_LOG_OBSOLETE   0x0005
#define EVENT_NEW_DESC   0x0006
#define EVENT_DEBUG_MSG   0x0007
#define EVENT_INFO_MSG   0x0008
#define EVENT_NOTICE_MSG   0x0009
#define EVENT_WARN_MSG   0x000A
#define EVENT_ERR_MSG   0x000B
#define EVENT_ADDRMAP   0x000C
#define EVENT_DESCCHANGED   0x000E
#define EVENT_STATUS_CLIENT   0x0010
#define EVENT_STATUS_SERVER   0x0011
#define EVENT_STATUS_GENERAL   0x0012
#define EVENT_GUARD   0x0013
#define EVENT_STREAM_BANDWIDTH_USED   0x0014
#define EVENT_CLIENTS_SEEN   0x0015
#define EVENT_NEWCONSENSUS   0x0016
#define EVENT_BUILDTIMEOUT_SET   0x0017
#define _EVENT_MAX   0x0017
#define EVENT_IS_INTERESTING(e)   (global_event_mask & (1<<(e)))
#define AUTHENTICATION_COOKIE_LEN   32
#define BOOTSTRAP_MSG_LEN   1024
#define ALL_FORMATS   1
#define CONNECTION_PRINTF_TO_BUF_BUFFERSIZE   1024
#define SEND_CONTROL1_EVENT_BUFFERSIZE   10064
#define ITEM(name, fn, desc)   { name, getinfo_helper_##fn, desc, 0 }
#define PREFIX(name, fn, desc)   { name, getinfo_helper_##fn, desc, 1 }
#define DOC(name, desc)   { name, NULL, desc, 0 }
#define MAX_COMMAND_LINE_LENGTH   (1024*1024)
#define BOOTSTRAP_PROBLEM_THRESHOLD   10

Typedefs

typedef uint32_t event_mask_t
typedef int event_format_t
typedef int(* getinfo_helper_t )(control_connection_t *, const char *q, char **a)

Functions

static void connection_printf_to_buf (control_connection_t *conn, const char *format,...) CHECK_PRINTF(2
static void static void send_control_done (control_connection_t *conn)
static void send_control_event (uint16_t event, event_format_t which, const char *format,...) CHECK_PRINTF(3
static void static int handle_control_setconf (control_connection_t *conn, uint32_t len, char *body)
static int handle_control_resetconf (control_connection_t *conn, uint32_t len, char *body)
static int handle_control_getconf (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_loadconf (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_setevents (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_authenticate (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_signal (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_mapaddress (control_connection_t *conn, uint32_t len, const char *body)
static char * list_getinfo_options (void)
static int handle_control_getinfo (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_extendcircuit (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_setcircuitpurpose (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_attachstream (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_postdescriptor (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_redirectstream (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_closestream (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_closecircuit (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_resolve (control_connection_t *conn, uint32_t len, const char *body)
static int handle_control_usefeature (control_connection_t *conn, uint32_t len, const char *body)
static int write_stream_target_to_buf (edge_connection_t *conn, char *buf, size_t len)
static void orconn_target_get_name (char *buf, size_t len, or_connection_t *conn)
static char * get_cookie_file (void)
static INLINE int event_to_log_severity (int event)
static INLINE int log_severity_to_event (int severity)
void control_update_global_event_mask (void)
void control_adjust_event_log_severity (void)
int control_event_is_interesting (int event)
static INLINE void connection_write_str_to_buf (const char *s, control_connection_t *conn)
size_t write_escaped_data (const char *data, size_t len, char **out)
size_t read_escaped_data (const char *data, size_t len, char **out)
static INLINE int get_escaped_string_length (const char *start, size_t in_len_max, int *chars_out)
static const char * extract_escaped_string (const char *start, size_t in_len_max, char **out, size_t *out_len)
static const char * decode_escaped_string (const char *start, size_t in_len_max, char **out, size_t *out_len)
static void send_control_event_string (uint16_t event, event_format_t which, const char *msg)
static void send_control_event_impl (uint16_t event, event_format_t which, const char *format, va_list ap)
static origin_circuit_tget_circ (const char *id)
static edge_connection_tget_stream (const char *id)
static int control_setconf_helper (control_connection_t *conn, uint32_t len, char *body, int use_defaults)
smartlist_tdecode_hashed_passwords (config_line_t *passwords)
static int handle_control_saveconf (control_connection_t *conn, uint32_t len, const char *body)
static int getinfo_helper_misc (control_connection_t *conn, const char *question, char **answer)
static char * munge_extrainfo_into_routerinfo (const char *ri_body, signed_descriptor_t *ri, signed_descriptor_t *ei)
static int getinfo_helper_dir (control_connection_t *control_conn, const char *question, char **answer)
static int getinfo_helper_events (control_connection_t *control_conn, const char *question, char **answer)
static int handle_getinfo_helper (control_connection_t *control_conn, const char *question, char **answer)
static uint8_t circuit_purpose_from_string (const char *string)
static smartlist_tgetargs_helper (const char *command, control_connection_t *conn, const char *body, int min_args, int max_args)
static const char * find_element_starting_with (smartlist_t *sl, int start_at, const char *prefix)
static int is_keyval_pair (const char *s)
static int handle_control_protocolinfo (control_connection_t *conn, uint32_t len, const char *body)
int connection_control_finished_flushing (control_connection_t *conn)
int connection_control_reached_eof (control_connection_t *conn)
static int is_valid_initial_command (control_connection_t *conn, const char *cmd)
int connection_control_process_inbuf (control_connection_t *conn)
int control_event_circuit_status (origin_circuit_t *circ, circuit_status_event_t tp, int reason_code)
int control_event_stream_status (edge_connection_t *conn, stream_status_event_t tp, int reason_code)
int control_event_or_conn_status (or_connection_t *conn, or_conn_status_event_t tp, int reason)
int control_event_stream_bandwidth (edge_connection_t *edge_conn)
int control_event_stream_bandwidth_used (void)
int control_event_bandwidth_used (uint32_t n_read, uint32_t n_written)
void disable_control_logging (void)
void enable_control_logging (void)
void control_event_logmsg (int severity, uint32_t domain, const char *msg)
int control_event_descriptors_changed (smartlist_t *routers)
int control_event_address_mapped (const char *from, const char *to, time_t expires, const char *error)
int control_event_or_authdir_new_descriptor (const char *action, const char *desc, size_t desclen, const char *msg)
static int control_event_networkstatus_changed_helper (smartlist_t *statuses, uint16_t event, const char *event_string)
int control_event_networkstatus_changed (smartlist_t *statuses)
int control_event_newconsensus (const networkstatus_t *consensus)
int control_event_buildtimeout_set (const circuit_build_times_t *cbt, buildtimeout_set_event_t type)
int control_event_networkstatus_changed_single (routerstatus_t *rs)
int control_event_my_descriptor_changed (void)
static int control_event_status (int type, int severity, const char *format, va_list args)
int control_event_general_status (int severity, const char *format,...)
int control_event_client_status (int severity, const char *format,...)
int control_event_server_status (int severity, const char *format,...)
int control_event_guard (const char *nickname, const char *digest, const char *status)
int init_cookie_authentication (int enabled)
static int bootstrap_status_to_string (bootstrap_status_t s, const char **tag, const char **summary)
void control_event_bootstrap (bootstrap_status_t status, int progress)
void control_event_bootstrap_problem (const char *warn, int reason)
void control_event_clients_seen (const char *controller_str)

Variables

static event_mask_t global_event_mask = 0
static int disable_log_messages = 0
static int authentication_cookie_is_set = 0
static char authentication_cookie [AUTHENTICATION_COOKIE_LEN]
static char last_sent_bootstrap_message [BOOTSTRAP_MSG_LEN]
static const getinfo_item_t getinfo_items []
static int bootstrap_percent = BOOTSTRAP_STATUS_UNDEF
static int bootstrap_problems = 0


Detailed Description

Implementation for Tor's control-socket interface. See doc/spec/control-spec.txt for full details on protocol.


Define Documentation

#define ALL_FORMATS   1

#define AUTHENTICATION_COOKIE_LEN   32

If we're using cookie-type authentication, how long should our cookies be?

Referenced by handle_control_authenticate(), and init_cookie_authentication().

#define BOOTSTRAP_MSG_LEN   1024

A sufficiently large size to record the last bootstrap phase string.

Referenced by control_event_bootstrap(), and control_event_bootstrap_problem().

#define EVENT_IS_INTERESTING (  )     (global_event_mask & (1<<(e)))

#define MAX_COMMAND_LINE_LENGTH   (1024*1024)

Do not accept any control command of more than 1MB in length. Anything that needs to be anywhere near this long probably means that one of our interfaces is broken.

Referenced by connection_control_process_inbuf().

#define STATE_IS_OPEN (  )     ((s) == CONTROL_CONN_STATE_OPEN)

Yield true iff s is the state of a control_connection_t that has finished authentication and is accepting commands.

Referenced by control_update_global_event_mask(), and handle_control_protocolinfo().


Typedef Documentation

typedef int event_format_t

Bit field of flags to select how to format a controller event. Recognized flag is ALL_FORMATS.

typedef uint32_t event_mask_t

Bitfield: The bit 1<<e is set if any open control connection is interested in events of type e. We use this so that we can decide to skip generating event messages that nobody has interest in without having to walk over the global connection list to find out.

typedef int(* getinfo_helper_t)(control_connection_t *, const char *q, char **a)

Callback function for GETINFO: on a given control connection, try to answer the question q and store the newly-allocated answer in *a. If an internal error occurs, return -1. On success, or if the key is not recognized, return 0. Do not set a if the key is not recognized.


Function Documentation

static int bootstrap_status_to_string ( bootstrap_status_t  s,
const char **  tag,
const char **  summary 
) [static]

Convert the name of a bootstrapping phase s into strings tag and summary suitable for display by the controller.

Referenced by control_event_bootstrap(), and control_event_bootstrap_problem().

static uint8_t circuit_purpose_from_string ( const char *  string  )  [static]

int connection_control_finished_flushing ( control_connection_t conn  ) 

Called when conn has no more bytes left on its outbuf.

References connection_stop_writing(), TO_CONN, and tor_assert.

Referenced by connection_finished_flushing().

int connection_control_process_inbuf ( control_connection_t conn  ) 

int connection_control_reached_eof ( control_connection_t conn  ) 

Called when conn has gotten its socket closed.

References LD_CONTROL, TO_CONN, and tor_assert.

Referenced by connection_reached_eof().

static void connection_printf_to_buf ( control_connection_t conn,
const char *  format,
  ... 
) [static]

Acts like sprintf, but writes its formatted string to the end of conn->outbuf. The message may be truncated if it is too long, but it will always end with a CRLF sequence.

Currently the length of the message is limited to 1024 (including the ending CR LF NUL ("\\r\\n\\0").

References LD_BUG, TO_CONN, and tor_vsnprintf().

Referenced by connection_control_process_inbuf(), control_setconf_helper(), getargs_helper(), handle_control_attachstream(), handle_control_authenticate(), handle_control_closecircuit(), handle_control_closestream(), handle_control_extendcircuit(), handle_control_getconf(), handle_control_getinfo(), handle_control_loadconf(), handle_control_postdescriptor(), handle_control_protocolinfo(), handle_control_redirectstream(), handle_control_setcircuitpurpose(), handle_control_setevents(), handle_control_signal(), and handle_control_usefeature().

static INLINE void connection_write_str_to_buf ( const char *  s,
control_connection_t conn 
) [static]

void control_adjust_event_log_severity ( void   ) 

Adjust the log severities that result in control_event_logmsg being called to match the severity of log messages that any controllers are interested in.

References change_callback_log_severity(), control_event_logmsg(), EVENT_IS_INTERESTING, and event_to_log_severity().

Referenced by options_act_reversible().

int control_event_address_mapped ( const char *  from,
const char *  to,
time_t  expires,
const char *  error 
)

Called when an address mapping on from from changes to to. expires values less than 3 are special; see connection_edge.c. If error is non-NULL, it is an error code describing the failure mode of the mapping.

References ALL_FORMATS, EVENT_IS_INTERESTING, format_iso_time(), format_local_iso_time(), and send_control_event().

Referenced by addressmap_register(), handle_control_resolve(), and tell_controller_about_resolved_result().

int control_event_bandwidth_used ( uint32_t  n_read,
uint32_t  n_written 
)

A second or more has elapsed: tell any interested control connections how much bandwidth we used.

References ALL_FORMATS, EVENT_IS_INTERESTING, and send_control_event().

Referenced by second_elapsed_callback().

void control_event_bootstrap ( bootstrap_status_t  status,
int  progress 
)

Called when Tor has made progress at bootstrapping its directory information and initial circuits.

status is the new status, that is, what task we will be doing next. percent is zero if we just started this task, else it represents progress on the task.

References BOOTSTRAP_MSG_LEN, bootstrap_status_to_string(), control_event_client_status(), last_sent_bootstrap_message, LD_CONTROL, and tor_snprintf().

Referenced by circuit_handle_first_hop(), circuit_send_next_onion_skin(), connection_edge_process_relay_cell_not_open(), connection_or_finished_connecting(), do_main_loop(), load_downloaded_routers(), and update_router_have_minimum_dir_info().

void control_event_bootstrap_problem ( const char *  warn,
int  reason 
)

int control_event_buildtimeout_set ( const circuit_build_times_t cbt,
buildtimeout_set_event_t  type 
)

int control_event_circuit_status ( origin_circuit_t circ,
circuit_status_event_t  tp,
int  reason_code 
)

int control_event_client_status ( int  severity,
const char *  format,
  ... 
)

Format and send an EVENT_STATUS_CLIENT event whose main text is obtained by formatting the arguments using the printf-style format.

References control_event_status(), and EVENT_IS_INTERESTING.

Referenced by circuit_note_clock_jumped(), circuit_send_next_onion_skin(), consider_plaintext_ports(), control_event_bootstrap(), control_event_bootstrap_problem(), fetch_from_buf_socks(), networkstatus_set_current_consensus(), and update_router_have_minimum_dir_info().

void control_event_clients_seen ( const char *  controller_str  ) 

We just generated a new summary of which countries we've seen clients from recently. Send a copy to the controller in case it wants to display it for the user.

References send_control_event().

Referenced by geoip_bridge_stats_write().

int control_event_descriptors_changed ( smartlist_t routers  ) 

Called whenever we receive new router descriptors: tell any interested control connections. routers is a list of routerinfo_t's.

References ALL_FORMATS, EVENT_IS_INTERESTING, MAX_VERBOSE_NICKNAME_LEN, router_get_verbose_nickname(), send_control_event_string(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), tor_free, and tor_snprintf().

Referenced by dirserv_add_descriptor(), and routerlist_descriptors_added().

int control_event_general_status ( int  severity,
const char *  format,
  ... 
)

int control_event_guard ( const char *  nickname,
const char *  digest,
const char *  status 
)

int control_event_is_interesting ( int  event  ) 

Return true iff the event with code c is being sent to any current control connection. This is useful if the amount of work needed to prepare to call the appropriate control_event_...() function is high.

References EVENT_IS_INTERESTING.

Referenced by control_event_buildtimeout_set(), control_event_newconsensus(), and notify_control_networkstatus_changed().

void control_event_logmsg ( int  severity,
uint32_t  domain,
const char *  msg 
)

int control_event_my_descriptor_changed ( void   ) 

Our own router descriptor has changed; tell any controllers that care.

References ALL_FORMATS, and send_control_event().

Referenced by router_rebuild_descriptor().

int control_event_networkstatus_changed ( smartlist_t statuses  ) 

Called when the routerstatus_ts statuses have changed: sends an NS event to any controller that cares.

References control_event_networkstatus_changed_helper().

Referenced by control_event_networkstatus_changed_single(), and notify_control_networkstatus_changed().

static int control_event_networkstatus_changed_helper ( smartlist_t statuses,
uint16_t  event,
const char *  event_string 
) [static]

Helper function for NS-style events. Constructs and sends an event of type event with string event_string out of the set of networkstatuses statuses. Currently it is used for NS events and NEWCONSENSUS events.

References ALL_FORMATS, EVENT_IS_INTERESTING, networkstatus_getinfo_helper_single(), send_control_event_string(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), tor_free, and write_escaped_data().

Referenced by control_event_networkstatus_changed(), and control_event_newconsensus().

int control_event_networkstatus_changed_single ( routerstatus_t rs  ) 

Called when a single local_routerstatus_t has changed: Sends an NS event to any controller that cares.

References control_event_networkstatus_changed(), EVENT_IS_INTERESTING, smartlist_add(), smartlist_create(), and smartlist_free().

Referenced by router_set_status().

int control_event_newconsensus ( const networkstatus_t consensus  ) 

Called when we get a new consensus networkstatus. Sends a NEWCONSENSUS event consisting of an NS-style line for each relay in the consensus.

References control_event_is_interesting(), control_event_networkstatus_changed_helper(), and networkstatus_t::routerstatus_list.

Referenced by notify_control_networkstatus_changed().

int control_event_or_authdir_new_descriptor ( const char *  action,
const char *  desc,
size_t  desclen,
const char *  msg 
)

The authoritative dirserver has received a new descriptor that has passed basic syntax checks and is properly self-signed.

Notify any interested party of the new descriptor and what has been done with it, and also optionally give an explanation/reason.

References ALL_FORMATS, EVENT_IS_INTERESTING, send_control_event_string(), tor_free, tor_snprintf(), and write_escaped_data().

Referenced by dirserv_add_descriptor().

int control_event_or_conn_status ( or_connection_t conn,
or_conn_status_event_t  tp,
int  reason 
)

Called when the status of an OR connection conn changes: tell any interested control connections. tp is the new status for the connection. If conn has just closed or failed, then reason may be the reason why.

References ALL_FORMATS, circuit_count_pending_on_or_conn(), EVENT_IS_INTERESTING, LD_BUG, or_connection_t::n_circuits, orconn_end_reason_to_control_string(), orconn_target_get_name(), send_control_event(), and tor_snprintf().

Referenced by connection_about_to_close_connection(), connection_init_accepted_conn(), connection_or_check_valid_tls_handshake(), connection_or_connect(), connection_or_connect_failed(), and connection_or_set_state_open().

int control_event_server_status ( int  severity,
const char *  format,
  ... 
)

static int control_event_status ( int  type,
int  severity,
const char *  format,
va_list  args 
) [static]

Helper: sends a status event where type is one of EVENT_STATUS_{GENERAL,CLIENT,SERVER}, where severity is one of LOG_{NOTICE,WARN,ERR}, and where format is a printf-style format string corresponding to args.

References ALL_FORMATS, LD_BUG, send_control_event_impl(), and tor_snprintf().

Referenced by control_event_client_status(), control_event_general_status(), and control_event_server_status().

int control_event_stream_bandwidth ( edge_connection_t edge_conn  ) 

int control_event_stream_bandwidth_used ( void   ) 

A second or more has elapsed: tell any interested control connections how much bandwidth streams have used.

References edge_connection_t::_base, ALL_FORMATS, CONN_TYPE_AP, EVENT_IS_INTERESTING, get_connection_array(), connection_t::global_identifier, edge_connection_t::n_read, edge_connection_t::n_written, send_control_event(), and TO_EDGE_CONN().

Referenced by second_elapsed_callback().

int control_event_stream_status ( edge_connection_t conn,
stream_status_event_t  tp,
int  reason_code 
)

static int control_setconf_helper ( control_connection_t conn,
uint32_t  len,
char *  body,
int  use_defaults 
) [static]

void control_update_global_event_mask ( void   ) 

Set global_event_mask* to the bitwise OR of each live control connection's event_mask field.

References CONN_TYPE_CONTROL, get_connection_array(), global_event_mask, STATE_IS_OPEN, and TO_CONTROL_CONN().

Referenced by connection_free(), connection_free_all(), and handle_control_setevents().

static const char* decode_escaped_string ( const char *  start,
size_t  in_len_max,
char **  out,
size_t *  out_len 
) [static]

Given a pointer to a string starting at start containing in_len_max characters, decode a string beginning with one double quote, containing any number of non-quote characters or characters escaped with a backslash, and ending with a final double quote. Place the resulting string (unquoted, unescaped) into a newly allocated string in *out; store its length in out_len. On success, return a pointer to the character immediately following the escaped string. On failure, return NULL.

References get_escaped_string_length(), and tor_assert.

Referenced by handle_control_authenticate().

smartlist_t* decode_hashed_passwords ( config_line_t passwords  ) 

Decode the hashed, base64'd passwords stored in passwords. Return a smartlist of acceptable passwords (unterminated strings of length S2K_SPECIFIER_LEN+DIGEST_LEN) on success, or NULL on failure.

References base16_decode(), base64_decode(), DIGEST_LEN, config_line_t::next, S2K_SPECIFIER_LEN, smartlist_add(), smartlist_create(), smartlist_free(), strcmpstart(), tor_assert, tor_free, and config_line_t::value.

Referenced by handle_control_authenticate().

void disable_control_logging ( void   ) 

Called when we are sending a log message to the controllers: suspend sending further log messages to the controllers until we're done. Used by CONN_LOG_PROTECT.

References disable_log_messages.

void enable_control_logging ( void   ) 

We're done sending a log message to the controllers: re-enable controller logging. Used by CONN_LOG_PROTECT.

References disable_log_messages, and tor_assert.

static INLINE int event_to_log_severity ( int  event  )  [static]

Given a control event code for a message event, return the corresponding log severity.

Referenced by control_adjust_event_log_severity().

static const char* extract_escaped_string ( const char *  start,
size_t  in_len_max,
char **  out,
size_t *  out_len 
) [static]

As decode_escaped_string, but does not decode the string: copies the entire thing, including quotation marks.

References get_escaped_string_length().

Referenced by control_setconf_helper().

static const char* find_element_starting_with ( smartlist_t sl,
int  start_at,
const char *  prefix 
) [static]

Helper. Return the first element of sl at index start_at or higher that starts with prefix, case-insensitive. Return NULL if no such element exists.

References strcasecmpstart().

Referenced by handle_control_attachstream(), handle_control_extendcircuit(), handle_control_resolve(), and handle_control_setcircuitpurpose().

static origin_circuit_t* get_circ ( const char *  id  )  [static]

static char * get_cookie_file ( void   )  [static]

Helper: Return a newly allocated string containing a path to the file where we store our authentication cookie.

References or_options_t::CookieAuthFile, get_datadir_fname, and get_options().

Referenced by handle_control_protocolinfo(), and init_cookie_authentication().

static INLINE int get_escaped_string_length ( const char *  start,
size_t  in_len_max,
int *  chars_out 
) [static]

If the first in_len_max characters in start contain a double-quoted string with escaped characters, return the length of that string (as encoded, including quotes). Otherwise return -1.

Referenced by decode_escaped_string(), and extract_escaped_string().

static edge_connection_t* get_stream ( const char *  id  )  [static]

static smartlist_t* getargs_helper ( const char *  command,
control_connection_t conn,
const char *  body,
int  min_args,
int  max_args 
) [static]

Return a newly allocated smartlist containing the arguments to the command waiting in body. If there are fewer than min_args arguments, or if max_args is nonnegative and there are more than max_args arguments, send a 512 error to the controller, using command as the command name in the error message.

References connection_printf_to_buf(), smartlist_create(), smartlist_free(), smartlist_split_string(), and tor_free.

Referenced by handle_control_attachstream(), handle_control_closecircuit(), handle_control_closestream(), handle_control_extendcircuit(), handle_control_redirectstream(), and handle_control_setcircuitpurpose().

static int getinfo_helper_dir ( control_connection_t control_conn,
const char *  question,
char **  answer 
) [static]

static int getinfo_helper_events ( control_connection_t control_conn,
const char *  question,
char **  answer 
) [static]

Implementation helper for GETINFO: knows how to generate summaries of the current states of things we send events about.

References or_connection_t::_base, edge_connection_t::_base, _circuit_get_global_list(), addressmap_get_mappings(), AP_CONN_STATE_CIRCUIT_WAIT, AP_CONN_STATE_CONNECT_WAIT, AP_CONN_STATE_CONTROLLER_WAIT, AP_CONN_STATE_NATD_WAIT, AP_CONN_STATE_OPEN, AP_CONN_STATE_RENDDESC_WAIT, AP_CONN_STATE_RESOLVE_WAIT, AP_CONN_STATE_SOCKS_WAIT, check_whether_dirport_reachable(), check_whether_orport_reachable(), circuit_get_by_edge_conn(), CIRCUIT_IS_ORIGIN, circuit_list_path_for_controller(), circuit_purpose_to_controller_string(), CIRCUIT_STATE_OPEN, networkstatus_t::client_versions, socks_request_t::command, CONN_TYPE_AP, CONN_TYPE_OR, directories_have_accepted_server_descriptor(), geoip_get_bridge_stats_controller(), get_connection_array(), get_n_authorities(), get_options(), origin_circuit_t::global_identifier, connection_t::global_identifier, has_completed_circuit, last_sent_bootstrap_message, LD_BUG, LD_GENERAL, circuit_t::marked_for_close, networkstatus_get_latest_consensus(), circuit_t::next, or_connection_t::nickname, OR_CONN_STATE_OPEN, orconn_target_get_name(), circuit_t::purpose, router_have_minimum_dir_info(), server_mode(), networkstatus_t::server_versions, smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), edge_connection_t::socks_request, connection_t::state, circuit_t::state, strcmpstart(), TO_EDGE_CONN(), TO_OR_CONN(), TO_ORIGIN_CIRCUIT(), tor_fragile_assert, tor_free, tor_snprintf(), tor_version_is_obsolete(), V3_AUTHORITY, VS_EMPTY, VS_NEW, VS_NEW_IN_SERIES, VS_OLD, VS_RECOMMENDED, VS_UNKNOWN, VS_UNRECOMMENDED, and write_stream_target_to_buf().

static int getinfo_helper_misc ( control_connection_t conn,
const char *  question,
char **  answer 
) [static]

static int handle_control_attachstream ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

static int handle_control_authenticate ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

static int handle_control_closecircuit ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

Called when we get a CLOSECIRCUIT command; try to close the named circuit and report success or failure.

References connection_printf_to_buf(), get_circ(), getargs_helper(), LD_CONTROL, origin_circuit_t::p_streams, send_control_done(), smartlist_free(), TO_CIRCUIT, and tor_free.

Referenced by connection_control_process_inbuf().

static int handle_control_closestream ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

Called when we get a CLOSESTREAM command; try to close the named stream and report success or failure.

References connection_printf_to_buf(), get_stream(), getargs_helper(), send_control_done(), smartlist_free(), tor_free, and tor_parse_ulong().

Referenced by connection_control_process_inbuf().

static int handle_control_extendcircuit ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

static int handle_control_getconf ( control_connection_t conn,
uint32_t  body_len,
const char *  body 
) [static]

static int handle_control_getinfo ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

Called when we receive a GETINFO command. Try to fetch all requested information, and reply with information or error message.

References connection_printf_to_buf(), connection_write_str_to_buf(), handle_getinfo_helper(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_split_string(), TO_CONN, tor_free, and write_escaped_data().

Referenced by connection_control_process_inbuf().

static int handle_control_loadconf ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

Called when we get a +LOADCONF message.

References connection_printf_to_buf(), LD_CONTROL, options_init_from_string(), send_control_done(), and tor_free.

Referenced by connection_control_process_inbuf().

static int handle_control_mapaddress ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

static int handle_control_postdescriptor ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

static int handle_control_protocolinfo ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

static int handle_control_redirectstream ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

Called when we receive a REDIRECTSTERAM command. Try to change the target address of the named AP stream, and report success or failure.

References socks_request_t::address, connection_printf_to_buf(), get_stream(), getargs_helper(), socks_request_t::port, send_control_done(), smartlist_free(), edge_connection_t::socks_request, tor_free, and tor_parse_ulong().

Referenced by connection_control_process_inbuf().

static int handle_control_resetconf ( control_connection_t conn,
uint32_t  len,
char *  body 
) [static]

Called when we receive a RESETCONF message: parse the body and try to update our configuration. Reply with a DONE or ERROR message. Modifies the contents of body.

References control_setconf_helper().

Referenced by connection_control_process_inbuf().

static int handle_control_resolve ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

static int handle_control_saveconf ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

Called when we get a SAVECONF command. Try to flush the current options to disk, and report success or failure.

References connection_write_str_to_buf(), options_save_current(), and send_control_done().

Referenced by connection_control_process_inbuf().

static int handle_control_setcircuitpurpose ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

static int handle_control_setconf ( control_connection_t conn,
uint32_t  len,
char *  body 
) [static]

Called when we receive a SETCONF message: parse the body and try to update our configuration. Reply with a DONE or ERROR message. Modifies the contents of body.

References control_setconf_helper().

Referenced by connection_control_process_inbuf().

static int handle_control_setevents ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

Called when we get a SETEVENTS message: update conn->event_mask, and reply with DONE or ERROR.

References connection_printf_to_buf(), control_update_global_event_mask(), control_connection_t::event_mask, send_control_done(), smartlist_create(), smartlist_free(), smartlist_split_string(), and tor_free.

Referenced by connection_control_process_inbuf().

static int handle_control_signal ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

Called when we get a SIGNAL command. React to the provided signal, and report success or failure. (If the signal results in a shutdown, success may not be reported.)

References connection_printf_to_buf(), control_signal_act(), send_control_done(), TO_CONN, and tor_free.

Referenced by connection_control_process_inbuf().

static int handle_control_usefeature ( control_connection_t conn,
uint32_t  len,
const char *  body 
) [static]

Called when we get a USEFEATURE command: parse the feature list, and set up the control_connection's options properly.

References connection_printf_to_buf(), send_control_done(), smartlist_create(), smartlist_free(), smartlist_split_string(), and tor_free.

Referenced by connection_control_process_inbuf().

static int handle_getinfo_helper ( control_connection_t control_conn,
const char *  question,
char **  answer 
) [static]

Lookup the 'getinfo' entry question, and return the answer in *answer (or NULL if key not recognized). Return 0 if success or unrecognized, or -1 if recognized but internal error.

References getinfo_item_t::fn, strcmpstart(), tor_assert, and getinfo_item_t::varname.

Referenced by handle_control_getinfo().

int init_cookie_authentication ( int  enabled  ) 

Choose a random authentication cookie and write it to disk. Anybody who can read the cookie from disk will be considered authorized to use the control connection. Return -1 if we can't write the file, or 0 on success.

References authentication_cookie, authentication_cookie_is_set, AUTHENTICATION_COOKIE_LEN, crypto_rand(), escaped(), get_cookie_file(), get_options(), LD_FS, tor_free, and write_bytes_to_file().

Referenced by options_act().

static int is_keyval_pair ( const char *  s  )  [static]

Helper. Return true iff s is an argument that we should treat as a key-value pair.

Referenced by handle_control_extendcircuit(), and handle_control_resolve().

static int is_valid_initial_command ( control_connection_t conn,
const char *  cmd 
) [static]

Return true iff cmd is allowable (or at least forgivable) at this stage of the protocol.

References control_connection_t::_base, CONTROL_CONN_STATE_OPEN, control_connection_t::have_sent_protocolinfo, and connection_t::state.

Referenced by connection_control_process_inbuf().

static char * list_getinfo_options ( void   )  [static]

static INLINE int log_severity_to_event ( int  severity  )  [static]

Given a log severity, return the corresponding control event code.

Referenced by control_event_logmsg().

static char* munge_extrainfo_into_routerinfo ( const char *  ri_body,
signed_descriptor_t ri,
signed_descriptor_t ei 
) [static]

Awful hack: return a newly allocated string based on a routerinfo and (possibly) an extrainfo, sticking the read-history and write-history from ei into the resulting string. The thing you get back won't necessarily have a valid signature.

New code should never use this; it's for backward compatibility.

NOTE: ri_body is as returned by signed_descriptor_get_body: it might not be NUL-terminated.

References signed_descriptor_get_body(), signed_descriptor_t::signed_descriptor_len, tor_assert, and tor_free.

static void orconn_target_get_name ( char *  name,
size_t  len,
or_connection_t conn 
) [static]

size_t read_escaped_data ( const char *  data,
size_t  len,
char **  out 
)

Given a len-character string in data, made of lines terminated by CRLF, allocate a new string in *out, and copy the contents of data into *out, removing any period that appears at the start of a line, and replacing all CRLF sequences with LF. Return the number of bytes in *out.

Referenced by handle_control_postdescriptor().

static void send_control_done ( control_connection_t conn  )  [static]

static void send_control_event ( uint16_t  event,
event_format_t  which,
const char *  format,
  ... 
) [static]

Send an event to all v1 controllers that are listening for code event. The event's body is created by the printf-style format in format, and other arguments as provided.

Currently the length of the message is limited to 1024 (including the ending \n\r\0.

References send_control_event_impl().

Referenced by control_event_address_mapped(), control_event_bandwidth_used(), control_event_buildtimeout_set(), control_event_circuit_status(), control_event_clients_seen(), control_event_guard(), control_event_logmsg(), control_event_my_descriptor_changed(), control_event_or_conn_status(), control_event_stream_bandwidth(), control_event_stream_bandwidth_used(), and control_event_stream_status().

static void send_control_event_impl ( uint16_t  event,
event_format_t  which,
const char *  format,
va_list  ap 
) [static]

Helper for send_control1_event and send_control1_event_extended: Send an event to all v1 controllers that are listening for code event. The event's body is created by the printf-style format in format, and other arguments as provided.

Currently the length of the message is limited to 1024 (including the ending \r\n\0).

References ALL_FORMATS, LD_BUG, send_control_event_string(), and tor_vsnprintf().

Referenced by control_event_status(), and send_control_event().

static void send_control_event_string ( uint16_t  event,
event_format_t  which,
const char *  msg 
) [static]

Send an event to all v1 controllers that are listening for code event. The event's body is given by msg.

If which & SHORT_NAMES, the event contains short-format names: send it to controllers that haven't enabled the VERBOSE_NAMES feature. If which & LONG_NAMES, the event contains long-format names: send it to controllers that have enabled VERBOSE_NAMES.

The EXTENDED_FORMAT and NONEXTENDED_FORMAT flags behave similarly with respect to the EXTENDED_EVENTS feature.

References CONN_TYPE_CONTROL, CONTROL_CONN_STATE_OPEN, control_connection_t::event_mask, get_connection_array(), strcmpstart(), TO_CONN, TO_CONTROL_CONN(), and tor_assert.

Referenced by control_event_descriptors_changed(), control_event_networkstatus_changed_helper(), control_event_or_authdir_new_descriptor(), and send_control_event_impl().

size_t write_escaped_data ( const char *  data,
size_t  len,
char **  out 
)

Given a len-character string in data, made of lines terminated by CRLF, allocate a new string in *out, and copy the contents of data into *out, adding a period before any period that appears at the start of a line, and adding a period-CRLF line at the end. Replace all LF characters sequences with CRLF. Return the number of bytes in *out.

References tor_assert.

Referenced by control_event_networkstatus_changed_helper(), control_event_or_authdir_new_descriptor(), and handle_control_getinfo().

static int write_stream_target_to_buf ( edge_connection_t conn,
char *  buf,
size_t  len 
) [static]

Given an AP connection conn and a len-character buffer buf, determine the address:port combination requested on conn, and write it to buf. Return 0 on success, -1 on failure.

References socks_request_t::address, edge_connection_t::chosen_exit_name, connection_edge_is_rendezvous_stream(), socks_request_t::port, edge_connection_t::socks_request, and tor_snprintf().

Referenced by control_event_stream_status(), and getinfo_helper_events().


Variable Documentation

char authentication_cookie[AUTHENTICATION_COOKIE_LEN] [static]

If authentication_cookie_is_set, a secret cookie that we've stored to disk and which we're using to authenticate controllers. (If the controller can read it off disk, it has permission to connect.

Referenced by handle_control_authenticate(), and init_cookie_authentication().

int authentication_cookie_is_set = 0 [static]

If true, we've set authentication_cookie to a secret code and stored it to disk.

Referenced by init_cookie_authentication().

int bootstrap_percent = BOOTSTRAP_STATUS_UNDEF [static]

What percentage through the bootstrap process are we? We remember this so we can avoid sending redundant bootstrap status events, and so we can guess context for the bootstrap messages which are ambiguous. It starts at 'undef', but gets set to 'starting' while Tor initializes.

int bootstrap_problems = 0 [static]

How many problems have we had getting to the next bootstrapping phase? These include failure to establish a connection to a Tor relay, failures to finish the TLS handshake, failures to validate the consensus document, etc.

int disable_log_messages = 0 [static]

True iff we have disabled log messages from being sent to the controller

Referenced by control_event_logmsg(), disable_control_logging(), and enable_control_logging().

const getinfo_item_t getinfo_items[] [static]

Table mapping questions accepted by GETINFO to the functions that know how to answer them.

An event mask of all the events that any controller is interested in receiving.

Referenced by control_update_global_event_mask().

char last_sent_bootstrap_message[BOOTSTRAP_MSG_LEN] [static]

What was the last bootstrap phase message we sent? We keep track of this so we can respond to getinfo status/bootstrap-phase queries.

Referenced by control_event_bootstrap(), control_event_bootstrap_problem(), and getinfo_helper_events().


Generated on Tue May 25 00:30:42 2010 for tor by  doxygen 1.5.6