tor  0.4.0.0-alpha-dev
Data Structures | Macros | Typedefs | Functions | Variables
control.c File Reference
#include "core/or/or.h"
#include "app/config/config.h"
#include "app/config/confparse.h"
#include "app/main/main.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
#include "core/or/channel.h"
#include "core/or/channeltls.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuitstats.h"
#include "core/or/circuituse.h"
#include "core/or/command.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
#include "core/or/ocirc_event.h"
#include "core/or/policies.h"
#include "core/or/reasons.h"
#include "core/or/versions.h"
#include "core/proto/proto_control0.h"
#include "core/proto/proto_http.h"
#include "feature/client/addressmap.h"
#include "feature/client/bridges.h"
#include "feature/client/dnsserv.h"
#include "feature/client/entrynodes.h"
#include "feature/control/control.h"
#include "feature/control/fmt_serverstatus.h"
#include "feature/control/getinfo_geoip.h"
#include "feature/dircache/dirserv.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dirclient/dlstatus.h"
#include "feature/dircommon/directory.h"
#include "feature/hibernate/hibernate.h"
#include "feature/hs/hs_cache.h"
#include "feature/hs/hs_common.h"
#include "feature/hs/hs_control.h"
#include "feature/hs_common/shared_random_client.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/relay/router.h"
#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendcommon.h"
#include "feature/rend/rendparse.h"
#include "feature/rend/rendservice.h"
#include "feature/stats/geoip_stats.h"
#include "feature/stats/predict_ports.h"
#include "lib/buf/buffers.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_util.h"
#include "lib/encoding/confline.h"
#include "lib/evloop/compat_libevent.h"
#include "lib/version/torversion.h"
#include "feature/dircache/cached_dir_st.h"
#include "feature/control/control_connection_st.h"
#include "core/or/cpath_build_state_st.h"
#include "core/or/entry_connection_st.h"
#include "feature/nodelist/extrainfo_st.h"
#include "feature/nodelist/networkstatus_st.h"
#include "feature/nodelist/node_st.h"
#include "core/or/or_connection_st.h"
#include "core/or/or_circuit_st.h"
#include "core/or/origin_circuit_st.h"
#include "feature/nodelist/microdesc_st.h"
#include "feature/rend/rend_authorized_client_st.h"
#include "feature/rend/rend_encoded_v2_service_descriptor_st.h"
#include "feature/rend/rend_service_descriptor_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerlist_st.h"
#include "core/or/socks_request_st.h"
#include <pwd.h>
#include <sys/resource.h>
#include "lib/crypt_ops/crypto_s2k.h"
#include "lib/evloop/procmon.h"

Go to the source code of this file.

Data Structures

struct  queued_event_s
 
struct  control_event_t
 
struct  signal_t
 
struct  getinfo_item_t
 
struct  cached_bw_event_s
 

Macros

#define CONTROL_PRIVATE
 
#define OCIRC_EVENT_PRIVATE
 
#define STATE_IS_OPEN(s)   ((s) == CONTROL_CONN_STATE_OPEN)
 
#define EVENT_IS_INTERESTING(e)   (!! (global_event_mask & EVENT_MASK_(e)))
 
#define ANY_EVENT_IS_INTERESTING(e)   (!! (global_event_mask & (e)))
 
#define AUTHENTICATION_COOKIE_LEN   32
 
#define SAFECOOKIE_SERVER_TO_CONTROLLER_CONSTANT   "Tor safe cookie authentication server-to-controller hash"
 
#define SAFECOOKIE_CONTROLLER_TO_SERVER_CONSTANT   "Tor safe cookie authentication controller-to-server hash"
 
#define SAFECOOKIE_SERVER_NONCE_LEN   DIGEST256_LEN
 
#define NEWLY_ENABLED(ev)   (! (old_mask & (ev)) && (new_mask & (ev)))
 
#define queued_event_free(ev)   FREE_AND_NULL(queued_event_t, queued_event_free_, (ev))
 
#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 N_BW_EVENTS_TO_CACHE   300
 
#define CONTROL_EVENT_STATUS_BODY(event, sev)
 

Typedefs

typedef uint64_t event_mask_t
 
typedef struct queued_event_s queued_event_t
 
typedef int(* getinfo_helper_t) (control_connection_t *, const char *q, char **a, const char **error_out)
 
typedef struct getinfo_item_t getinfo_item_t
 

Functions

static void connection_printf_to_buf (control_connection_t *conn, const char *format,...) CHECK_PRINTF(2
 
static void static void send_control_event_impl (uint16_t event, const char *format, va_list ap) CHECK_PRINTF(2
 
static void static void static int control_event_status (int type, int severity, const char *format, va_list args) CHECK_PRINTF(3
 
static void static void static int static void send_control_done (control_connection_t *conn)
 
static void send_control_event (uint16_t event, const char *format,...) CHECK_PRINTF(2
 
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 handle_control_hsfetch (control_connection_t *conn, uint32_t len, const char *body)
 
static int handle_control_hspost (control_connection_t *conn, uint32_t len, const char *body)
 
static int handle_control_add_onion (control_connection_t *conn, uint32_t len, const char *body)
 
static int handle_control_del_onion (control_connection_t *conn, uint32_t len, const char *body)
 
static int write_stream_target_to_buf (entry_connection_t *conn, char *buf, size_t len)
 
static void orconn_target_get_name (char *buf, size_t len, or_connection_t *conn)
 
static int get_cached_network_liveness (void)
 
static void set_cached_network_liveness (int liveness)
 
static void flush_queued_events_cb (mainloop_event_t *event, void *arg)
 
static char * download_status_to_string (const download_status_t *dl)
 
static void control_get_bytes_rw_last_sec (uint64_t *r, uint64_t *w)
 
control_connection_tTO_CONTROL_CONN (connection_t *c)
 
static int event_to_log_severity (int event)
 
static int log_severity_to_event (int severity)
 
static void clear_circ_bw_fields (void)
 
void control_update_global_event_mask (void)
 
void control_adjust_event_log_severity (void)
 
int control_event_is_interesting (int event)
 
int control_any_per_second_event_enabled (void)
 
void control_per_second_events (void)
 
static void connection_write_str_to_buf (const char *s, control_connection_t *conn)
 
STATIC size_t write_escaped_data (const char *data, size_t len, char **out)
 
STATIC size_t read_escaped_data (const char *data, size_t len, char **out)
 
static 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)
 
int control_connection_add_local_fd (tor_socket_t sock, unsigned flags)
 
void control_ports_write_to_file (void)
 
void control_initialize_event_queue (void)
 
static int * get_block_event_queue (void)
 
 MOCK_IMPL (STATIC void, queue_control_event_string,(uint16_t event, char *msg))
 
static void queued_event_free_ (queued_event_t *ev)
 
static void queued_events_flush_all (int force)
 
 MOCK_IMPL (STATIC void, send_control_event_string,(uint16_t event, const char *msg))
 
static origin_circuit_tget_circ (const char *id)
 
static entry_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 handle_control_takeownership (control_connection_t *conn, uint32_t len, const char *body)
 
static int handle_control_dropownership (control_connection_t *conn, uint32_t len, const char *body)
 
static int address_is_invalid_mapaddress_target (const char *addr)
 
static int getinfo_helper_misc (control_connection_t *conn, const char *question, char **answer, const char **errmsg)
 
static char * munge_extrainfo_into_routerinfo (const char *ri_body, const signed_descriptor_t *ri, const signed_descriptor_t *ei)
 
static int getinfo_helper_listeners (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
STATIC int getinfo_helper_current_time (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
STATIC int getinfo_helper_dir (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
static char * digest_list_to_string (const smartlist_t *sl)
 
STATIC void getinfo_helper_downloads_networkstatus (const char *flavor, download_status_t **dl_to_emit, const char **errmsg)
 
STATIC void getinfo_helper_downloads_cert (const char *fp_sk_req, download_status_t **dl_to_emit, smartlist_t **digest_list, const char **errmsg)
 
STATIC void getinfo_helper_downloads_desc (const char *desc_req, download_status_t **dl_to_emit, smartlist_t **digest_list, const char **errmsg)
 
STATIC void getinfo_helper_downloads_bridge (const char *bridge_req, download_status_t **dl_to_emit, smartlist_t **digest_list, const char **errmsg)
 
STATIC int getinfo_helper_downloads (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
static char * circuit_describe_status_for_controller (origin_circuit_t *circ)
 
static int getinfo_helper_events (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
STATIC int getinfo_helper_onions (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
static int getinfo_helper_liveness (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
static int getinfo_helper_sr (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
static int handle_getinfo_helper (control_connection_t *control_conn, const char *question, char **answer, const char **err_out)
 
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)
 
static int handle_control_authchallenge (control_connection_t *conn, uint32_t len, const char *body)
 
static int handle_control_dropguards (control_connection_t *conn, uint32_t len, const char *body)
 
static hs_service_add_ephemeral_status_t add_onion_helper_add_service (int hs_version, add_onion_secret_key_t *pk, smartlist_t *port_cfgs, int max_streams, int max_streams_close_circuit, int auth_type, smartlist_t *auth_clients, char **address_out)
 
STATIC int add_onion_helper_keyarg (const char *arg, int discard_pk, const char **key_new_alg_out, char **key_new_blob_out, add_onion_secret_key_t *decoded_key, int *hs_version, char **err_msg_out)
 
STATIC rend_authorized_client_tadd_onion_helper_clientauth (const char *arg, int *created, char **err_msg)
 
int connection_control_finished_flushing (control_connection_t *conn)
 
int connection_control_reached_eof (control_connection_t *conn)
 
static void lost_owning_controller (const char *owner_type, const char *loss_manner)
 
void connection_control_closed (control_connection_t *conn)
 
static int is_valid_initial_command (control_connection_t *conn, const char *cmd)
 
static int peek_connection_has_control0_command (connection_t *conn)
 
static int peek_connection_has_http_command (connection_t *conn)
 
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)
 
static int control_event_circuit_status_minor (origin_circuit_t *circ, circuit_status_minor_event_t e, int purpose, const struct timeval *tv)
 
int control_event_circuit_purpose_changed (origin_circuit_t *circ, int old_purpose)
 
int control_event_circuit_cannibalized (origin_circuit_t *circ, int old_purpose, const struct timeval *old_tv_created)
 
int control_event_stream_status (entry_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_circ_bandwidth_used (void)
 
int control_event_circ_bandwidth_used_for_circ (origin_circuit_t *ocirc)
 
int control_event_conn_bandwidth (connection_t *conn)
 
int control_event_conn_bandwidth_used (void)
 
void sum_up_cell_stats_by_command (circuit_t *circ, cell_stats_t *cell_stats)
 
void append_cell_stats_by_command (smartlist_t *event_parts, const char *key, const uint64_t *include_if_non_zero, const uint64_t *number_to_include)
 
void format_cell_stats (char **event_string, circuit_t *circ, cell_stats_t *cell_stats)
 
int control_event_circuit_cell_stats (void)
 
int control_event_bandwidth_used (uint32_t n_read, uint32_t n_written)
 
STATIC char * get_bw_samples (void)
 
void disable_control_logging (void)
 
void enable_control_logging (void)
 
void control_event_logmsg (int severity, uint32_t domain, const char *msg)
 
void control_event_logmsg_pending (void)
 
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, const int cached)
 
int control_event_network_liveness_update (int liveness)
 
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 (buildtimeout_set_event_t type, const char *args)
 
int control_event_signal (uintptr_t signal_num)
 
int control_event_networkstatus_changed_single (const routerstatus_t *rs)
 
int control_event_my_descriptor_changed (void)
 
int control_event_general_status (int severity, const char *format,...)
 
int control_event_general_error (const char *format,...)
 
int control_event_client_status (int severity, const char *format,...)
 
int control_event_client_error (const char *format,...)
 
int control_event_server_status (int severity, const char *format,...)
 
int control_event_server_error (const char *format,...)
 
int control_event_guard (const char *nickname, const char *digest, const char *status)
 
int control_event_conf_changed (const smartlist_t *elements)
 
char * get_controller_cookie_file_name (void)
 
int init_control_cookie_authentication (int enabled)
 
static void owning_controller_procmon_cb (void *unused)
 
void monitor_owning_controller_process (const char *process_spec)
 
void control_event_clients_seen (const char *controller_str)
 
void control_event_transport_launched (const char *mode, const char *transport_name, tor_addr_t *addr, uint16_t port)
 
void control_event_pt_log (const char *log)
 
void control_event_pt_status (const char *status)
 
const char * rend_auth_type_to_string (rend_auth_type_t auth_type)
 
 MOCK_IMPL (const char *, node_describe_longname_by_id,(const char *id_digest))
 
static const char * rend_hsaddress_str_or_unknown (const char *onion_address)
 
void control_event_hs_descriptor_requested (const char *onion_address, rend_auth_type_t auth_type, const char *id_digest, const char *desc_id, const char *hsdir_index)
 
static const char * get_desc_id_from_query (const rend_data_t *rend_data, const char *hsdir_fp)
 
void control_event_hs_descriptor_created (const char *onion_address, const char *desc_id, int replica)
 
void control_event_hs_descriptor_upload (const char *onion_address, const char *id_digest, const char *desc_id, const char *hsdir_index)
 
static void event_hs_descriptor_receive_end (const char *action, const char *onion_address, const char *desc_id, rend_auth_type_t auth_type, const char *hsdir_id_digest, const char *reason)
 
void control_event_hs_descriptor_upload_end (const char *action, const char *onion_address, const char *id_digest, const char *reason)
 
void control_event_hsv2_descriptor_received (const char *onion_address, const rend_data_t *rend_data, const char *hsdir_id_digest)
 
void control_event_hsv3_descriptor_received (const char *onion_address, const char *desc_id, const char *hsdir_id_digest)
 
void control_event_hs_descriptor_uploaded (const char *id_digest, const char *onion_address)
 
void control_event_hsv2_descriptor_failed (const rend_data_t *rend_data, const char *hsdir_id_digest, const char *reason)
 
void control_event_hsv3_descriptor_failed (const char *onion_address, const char *desc_id, const char *hsdir_id_digest, const char *reason)
 
void control_event_hs_descriptor_content (const char *onion_address, const char *desc_id, const char *hsdir_id_digest, const char *content)
 
void control_event_hs_descriptor_upload_failed (const char *id_digest, const char *onion_address, const char *reason)
 
void control_free_all (void)
 

Variables

static event_mask_t global_event_mask = 0
 
static int disable_log_messages = 0
 
static int authentication_cookie_is_set = 0
 
static uint8_t * authentication_cookie = NULL
 
static smartlist_tdetached_onion_services = NULL
 
static uint64_t stats_prev_n_read = 0
 
static uint64_t stats_prev_n_written = 0
 
static tor_threadlocal_t block_event_queue_flag
 
static smartlist_tqueued_control_events = NULL
 
static int flush_queued_event_pending = 0
 
static tor_mutex_tqueued_control_events_lock = NULL
 
static mainloop_event_tflush_queued_events_event = NULL
 
static const struct control_event_t control_event_table []
 
static const struct signal_t signal_table []
 
static const getinfo_item_t getinfo_items []
 
static const char CONTROLPORT_IS_NOT_AN_HTTP_PROXY_MSG []
 
static int next_measurement_idx = 0
 
static int n_measurements = 0
 
static struct cached_bw_event_s cached_bw_events [N_BW_EVENTS_TO_CACHE]
 
static int network_is_live = 0
 
static char * owning_controller_process_spec = NULL
 
static tor_process_monitor_towning_controller_process_monitor = NULL
 

Detailed Description

Implementation for Tor's control-socket interface.

A "controller" is an external program that monitors and controls a Tor instance via a text-based protocol. It connects to Tor via a connection to a local socket.

The protocol is line-driven. The controller sends commands terminated by a CRLF. Tor sends lines that are either replies to what the controller has said, or events that Tor sends to the controller asynchronously based on occurrences in the Tor network model.

See the control-spec.txt file in the torspec.git repository for full details on protocol.

This module generally has two kinds of entry points: those based on having received a command on a controller socket, which are handled in connection_control_process_inbuf(), and dispatched to individual functions with names like control_handle_COMMANDNAME(); and those based on events that occur elsewhere in Tor, which are handled by functions with names like control_event_EVENTTYPE().

Controller events are not sent immediately; rather, they are inserted into the queued_control_events array, and flushed later from flush_queued_events_cb(). Doing this simplifies our callgraph greatly, by limiting the number of places in Tor that can call back into the network stack.

Definition in file control.c.

Macro Definition Documentation

◆ ANY_EVENT_IS_INTERESTING

#define ANY_EVENT_IS_INTERESTING (   e)    (!! (global_event_mask & (e)))

Macro: true if any event from the bitfield 'e' is interesting.

Definition at line 158 of file control.c.

Referenced by control_any_per_second_event_enabled().

◆ AUTHENTICATION_COOKIE_LEN

#define AUTHENTICATION_COOKIE_LEN   32

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

Definition at line 163 of file control.c.

◆ CONTROL_EVENT_STATUS_BODY

#define CONTROL_EVENT_STATUS_BODY (   event,
  sev 
)
Value:
int r; \
do { \
va_list ap; \
if (!EVENT_IS_INTERESTING(event)) \
return 0; \
\
va_start(ap, format); \
r = control_event_status((event), (sev), format, ap); \
va_end(ap); \
} while (0)
#define EVENT_IS_INTERESTING(e)
Definition: control.c:154
static void static void static int control_event_status(int type, int severity, const char *format, va_list args) CHECK_PRINTF(3
Definition: control.c:6746

Definition at line 6792 of file control.c.

◆ EVENT_IS_INTERESTING

#define EVENT_IS_INTERESTING (   e)    (!! (global_event_mask & EVENT_MASK_(e)))

◆ MAX_COMMAND_LINE_LENGTH

#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.

Definition at line 5347 of file control.c.

◆ STATE_IS_OPEN

#define STATE_IS_OPEN (   s)    ((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.

Definition at line 135 of file control.c.

Referenced by control_update_global_event_mask().

Typedef Documentation

◆ event_mask_t

typedef uint64_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.

Definition at line 143 of file control.c.

◆ getinfo_helper_t

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

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 and optionally set *error_out to point to an error message to be delivered to the controller. On success, or if the key is not recognized, return 0. Do not set a if the key is not recognized but you may set error_out to improve the error message.

Definition at line 3225 of file control.c.

◆ getinfo_item_t

A single item for the GETINFO question-to-answer-function table.

◆ queued_event_t

Represents an event that's queued to be sent to one or more controllers.

Function Documentation

◆ add_onion_helper_clientauth()

STATIC rend_authorized_client_t* add_onion_helper_clientauth ( const char *  arg,
int *  created,
char **  err_msg 
)

Helper function to handle parsing a ClientAuth argument to the ADD_ONION command. Return a new rend_authorized_client_t, or NULL and an optional control protocol error message on failure. The caller is responsible for freeing the returned auth_client and err_msg.

If 'created' is specified, it will be set to 1 when a new cookie has been generated.

Definition at line 5130 of file control.c.

References tor_assert().

◆ add_onion_helper_keyarg()

STATIC int add_onion_helper_keyarg ( const char *  arg,
int  discard_pk,
const char **  key_new_alg_out,
char **  key_new_blob_out,
add_onion_secret_key_t *  decoded_key,
int *  hs_version,
char **  err_msg_out 
)

Helper function to handle parsing the KeyType:KeyBlob argument to the ADD_ONION command. Return a new crypto_pk_t and if a new key was generated and the private key not discarded, the algorithm and serialized private key, or NULL and an optional control protocol error message on failure. The caller is responsible for freeing the returned key_new_blob and err_msg.

Note: The error messages returned are deliberately vague to avoid echoing key material.

Definition at line 4994 of file control.c.

References smartlist_split_string().

◆ address_is_invalid_mapaddress_target()

static int address_is_invalid_mapaddress_target ( const char *  addr)
static

Return true iff addr is unusable as a mapaddress target because of containing funny characters.

Definition at line 1769 of file control.c.

References address_is_invalid_destination(), and strcmpstart().

◆ append_cell_stats_by_command()

void append_cell_stats_by_command ( smartlist_t event_parts,
const char *  key,
const uint64_t *  include_if_non_zero,
const uint64_t *  number_to_include 
)

Helper: append a cell statistics string to event_parts, prefixed with key=. Statistics consist of comma-separated key:value pairs with lower-case command strings as keys and cell numbers or total waiting times as values. A key:value pair is included if the entry in include_if_non_zero is not zero, but with the (possibly zero) entry from number_to_include. Both arrays are expected to have a length of CELL_COMMAND_MAX_ + 1. If no entry in include_if_non_zero is positive, no string will be added to event_parts.

Definition at line 6225 of file control.c.

Referenced by format_cell_stats().

◆ circuit_describe_status_for_controller()

static char* circuit_describe_status_for_controller ( origin_circuit_t circ)
static

◆ circuit_purpose_from_string()

static uint8_t circuit_purpose_from_string ( const char *  string)
static

Given a string, convert it to a circuit purpose.

Definition at line 3553 of file control.c.

References CIRCUIT_PURPOSE_C_GENERAL, CIRCUIT_PURPOSE_CONTROLLER, CIRCUIT_PURPOSE_UNKNOWN, and strcasecmpstart().

◆ clear_circ_bw_fields()

static void clear_circ_bw_fields ( void  )
static

◆ connection_control_closed()

void connection_control_closed ( control_connection_t conn)

◆ connection_control_finished_flushing()

int connection_control_finished_flushing ( control_connection_t conn)

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

Definition at line 5268 of file control.c.

References tor_assert().

Referenced by connection_finished_flushing().

◆ connection_control_process_inbuf()

int connection_control_process_inbuf ( control_connection_t conn)

Called when data has arrived on a v1 control connection: Try to fetch commands from conn->inbuf, and execute them.

Definition at line 5395 of file control.c.

References CONTROL_CONN_STATE_NEEDAUTH, CONTROL_CONN_STATE_OPEN, control_connection_t::incoming_cmd, connection_t::state, and tor_assert().

Referenced by connection_process_inbuf().

◆ connection_control_reached_eof()

int connection_control_reached_eof ( control_connection_t conn)

Called when conn has gotten its socket closed.

Definition at line 5276 of file control.c.

References tor_assert().

Referenced by connection_reached_eof().

◆ connection_printf_to_buf()

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.

Definition at line 722 of file control.c.

References tor_vasprintf().

Referenced by handle_control_hspost(), and handle_control_postdescriptor().

◆ connection_write_str_to_buf()

static void connection_write_str_to_buf ( const char *  s,
control_connection_t conn 
)
inlinestatic

Append a NUL-terminated string s to the end of conn->outbuf.

Definition at line 481 of file control.c.

Referenced by handle_control_saveconf(), and send_control_done().

◆ control_adjust_event_log_severity()

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.

Definition at line 376 of file control.c.

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

Referenced by control_update_global_event_mask().

◆ control_any_per_second_event_enabled()

int control_any_per_second_event_enabled ( void  )

Return true if any event that needs to fire once a second is enabled.

Definition at line 420 of file control.c.

References ANY_EVENT_IS_INTERESTING.

Referenced by control_per_second_events(), and control_update_global_event_mask().

◆ control_connection_add_local_fd()

int control_connection_add_local_fd ( tor_socket_t  sock,
unsigned  flags 
)

Create and add a new controller connection on sock. If CC_LOCAL_FD_IS_OWNER is set in flags, this Tor process should exit when the connection closes. If CC_LOCAL_FD_IS_AUTHENTICATED is set, then the connection does not need to authenticate.

Definition at line 682 of file control.c.

◆ control_event_address_mapped()

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

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.

Definition at line 6506 of file control.c.

References EVENT_IS_INTERESTING.

◆ control_event_bandwidth_used()

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.

Definition at line 6333 of file control.c.

Referenced by control_per_second_events().

◆ control_event_buildtimeout_set()

int control_event_buildtimeout_set ( buildtimeout_set_event_t  type,
const char *  args 
)

Called when we compute a new circuitbuildtimeout

Definition at line 6639 of file control.c.

◆ control_event_circ_bandwidth_used()

int control_event_circ_bandwidth_used ( void  )

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

Definition at line 6076 of file control.c.

References CIRCUIT_IS_ORIGIN, control_event_circ_bandwidth_used_for_circ(), EVENT_IS_INTERESTING, SMARTLIST_FOREACH_BEGIN, and TO_ORIGIN_CIRCUIT().

Referenced by control_per_second_events().

◆ control_event_circ_bandwidth_used_for_circ()

int control_event_circ_bandwidth_used_for_circ ( origin_circuit_t ocirc)

Emit a CIRC_BW event line for a specific circuit.

This function sets the values it emits to 0, and does not emit an event if there is no new data to report since the last call.

Therefore, it may be called at any frequency.

Definition at line 6101 of file control.c.

Referenced by control_event_circ_bandwidth_used().

◆ control_event_circuit_cannibalized()

int control_event_circuit_cannibalized ( origin_circuit_t circ,
int  old_purpose,
const struct timeval old_tv_created 
)

circ has changed its purpose from old_purpose, and its created-time from old_tv_created: tell any interested controllers.

Definition at line 5783 of file control.c.

References control_event_circuit_status_minor().

◆ control_event_circuit_cell_stats()

int control_event_circuit_cell_stats ( void  )

A second or more has elapsed: tell any interested control connection how many cells have been processed for a given circuit.

Definition at line 6297 of file control.c.

References EVENT_IS_INTERESTING.

Referenced by control_per_second_events().

◆ control_event_circuit_purpose_changed()

int control_event_circuit_purpose_changed ( origin_circuit_t circ,
int  old_purpose 
)

circ has changed its purpose from old_purpose: tell any interested controllers.

Definition at line 5769 of file control.c.

References control_event_circuit_status_minor().

◆ control_event_circuit_status()

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

Something major has happened to circuit circ: tell any interested control connections.

Definition at line 5639 of file control.c.

◆ control_event_circuit_status_minor()

static int control_event_circuit_status_minor ( origin_circuit_t circ,
circuit_status_minor_event_t  e,
int  purpose,
const struct timeval tv 
)
static

Something minor has happened to circuit circ: tell any interested control connections.

Definition at line 5696 of file control.c.

References EVENT_IS_INTERESTING, and tor_assert().

Referenced by control_event_circuit_cannibalized(), and control_event_circuit_purpose_changed().

◆ control_event_client_error()

int control_event_client_error ( const char *  format,
  ... 
)

Format and send an EVENT_STATUS_CLIENT LOG_ERR event, and flush it to the controller(s) immediately.

Definition at line 6836 of file control.c.

◆ control_event_client_status()

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.

Definition at line 6827 of file control.c.

Referenced by circuit_note_clock_jumped().

◆ control_event_clients_seen()

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.

Definition at line 7032 of file control.c.

References send_control_event().

◆ control_event_conf_changed()

int control_event_conf_changed ( const smartlist_t elements)

Called when a configuration option changes. This is generally triggered by SETCONF requests and RELOAD/SIGHUP signals. The elements is a smartlist_t containing (key, value, ...) pairs in sequence. value can be NULL.

Definition at line 6895 of file control.c.

References EVENT_IS_INTERESTING.

◆ control_event_conn_bandwidth()

int control_event_conn_bandwidth ( connection_t conn)

Print out CONN_BW event for a single OR/DIR/EXIT conn and reset bandwidth counters.

Definition at line 6144 of file control.c.

References CONN_TYPE_DIR, CONN_TYPE_EXIT, CONN_TYPE_OR, EVENT_IS_INTERESTING, connection_t::global_identifier, connection_t::n_read_conn_bw, connection_t::n_written_conn_bw, send_control_event(), and connection_t::type.

Referenced by control_event_conn_bandwidth_used().

◆ control_event_conn_bandwidth_used()

int control_event_conn_bandwidth_used ( void  )

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

Definition at line 6179 of file control.c.

References control_event_conn_bandwidth(), EVENT_IS_INTERESTING, and SMARTLIST_FOREACH.

Referenced by control_per_second_events().

◆ control_event_descriptors_changed()

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.

Definition at line 6474 of file control.c.

References EVENT_IS_INTERESTING, and SMARTLIST_FOREACH.

Referenced by routerlist_descriptors_added().

◆ control_event_general_error()

int control_event_general_error ( const char *  format,
  ... 
)

Format and send an EVENT_STATUS_GENERAL LOG_ERR event, and flush it to the controller(s) immediately.

Definition at line 6816 of file control.c.

◆ control_event_general_status()

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

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

Definition at line 6807 of file control.c.

Referenced by circuit_note_clock_jumped(), and control_event_logmsg().

◆ control_event_guard()

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

Called when the status of an entry guard with the given nickname and identity digest has changed to status: tells any controllers that care.

Definition at line 6868 of file control.c.

◆ control_event_hs_descriptor_content()

void control_event_hs_descriptor_content ( const char *  onion_address,
const char *  desc_id,
const char *  hsdir_id_digest,
const char *  content 
)

Send HS_DESC_CONTENT event after completion of a successful fetch from hs directory. If hsdir_id_digest is NULL, it is replaced by "UNKNOWN". If content is NULL, it is replaced by an empty string. The onion_address or desc_id set to NULL will not trigger the control event.

Definition at line 7485 of file control.c.

◆ control_event_hs_descriptor_created()

void control_event_hs_descriptor_created ( const char *  onion_address,
const char *  desc_id,
int  replica 
)

send HS_DESC CREATED event when a local service generates a descriptor.

onion_address is service address. desc_id is the descriptor ID. replica is the the descriptor replica number. If it is negative, it is ignored.

Definition at line 7221 of file control.c.

◆ control_event_hs_descriptor_requested()

void control_event_hs_descriptor_requested ( const char *  onion_address,
rend_auth_type_t  auth_type,
const char *  id_digest,
const char *  desc_id,
const char *  hsdir_index 
)

send HS_DESC requested event.

rend_query is used to fetch requested onion address and auth type. hs_dir is the description of contacting hs directory. desc_id_base32 is the ID of requested hs descriptor. hsdir_index is the HSDir fetch index value for v3, an hex string.

Definition at line 7143 of file control.c.

◆ control_event_hs_descriptor_upload()

void control_event_hs_descriptor_upload ( const char *  onion_address,
const char *  id_digest,
const char *  desc_id,
const char *  hsdir_index 
)

send HS_DESC upload event.

onion_address is service address. hs_dir is the description of contacting hs directory. desc_id is the ID of requested hs descriptor.

Definition at line 7249 of file control.c.

◆ control_event_hs_descriptor_upload_end()

void control_event_hs_descriptor_upload_end ( const char *  action,
const char *  onion_address,
const char *  id_digest,
const char *  reason 
)

send HS_DESC event after got response from hs directory.

NOTE: this is an internal function used by following functions: control_event_hs_descriptor_uploaded control_event_hs_descriptor_upload_failed

So do not call this function directly.

Definition at line 7323 of file control.c.

◆ control_event_hs_descriptor_upload_failed()

void control_event_hs_descriptor_upload_failed ( const char *  id_digest,
const char *  onion_address,
const char *  reason 
)

Send HS_DESC event to inform controller upload of hidden service descriptor identified by id_digest failed. If reason is not NULL, add it to REASON= field.

Definition at line 7522 of file control.c.

◆ control_event_hs_descriptor_uploaded()

void control_event_hs_descriptor_uploaded ( const char *  id_digest,
const char *  onion_address 
)

send HS_DESC UPLOADED event

called when we successfully uploaded a hidden service descriptor.

Definition at line 7408 of file control.c.

◆ control_event_hsv2_descriptor_failed()

void control_event_hsv2_descriptor_failed ( const rend_data_t rend_data,
const char *  hsdir_id_digest,
const char *  reason 
)

Send HS_DESC event to inform controller that query rend_data failed to retrieve hidden service descriptor from directory identified by id_digest. If NULL, "UNKNOWN" is used. If reason is not NULL, add it to REASON= field.

Definition at line 7425 of file control.c.

◆ control_event_hsv2_descriptor_received()

void control_event_hsv2_descriptor_received ( const char *  onion_address,
const rend_data_t rend_data,
const char *  hsdir_id_digest 
)

send HS_DESC RECEIVED event

called when we successfully received a hidden service descriptor.

Definition at line 7353 of file control.c.

◆ control_event_hsv3_descriptor_failed()

void control_event_hsv3_descriptor_failed ( const char *  onion_address,
const char *  desc_id,
const char *  hsdir_id_digest,
const char *  reason 
)

Send HS_DESC event to inform controller that the query to onion_address failed to retrieve hidden service descriptor desc_id from directory identified by hsdir_id_digest. If NULL, "UNKNOWN" is used. If reason is not NULL, add it to REASON= field.

Definition at line 7459 of file control.c.

◆ control_event_is_interesting()

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.

Definition at line 413 of file control.c.

References EVENT_IS_INTERESTING.

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

◆ control_event_logmsg()

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

We got a log message: tell any interested control connections.

Definition at line 6401 of file control.c.

References control_event_general_status(), disable_log_messages, esc_for_log(), EVENT_IS_INTERESTING, in_main_thread(), LD_BUG, LOG_NOTICE, log_severity_to_event(), and tor_free.

Referenced by control_adjust_event_log_severity().

◆ control_event_logmsg_pending()

void control_event_logmsg_pending ( void  )

Logging callback: called when there is a queued pending log callback.

Definition at line 6456 of file control.c.

References flush_queued_events_event, in_main_thread(), mainloop_event_activate(), and tor_assert().

◆ control_event_my_descriptor_changed()

int control_event_my_descriptor_changed ( void  )

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

Definition at line 6735 of file control.c.

References send_control_event().

◆ control_event_network_liveness_update()

int control_event_network_liveness_update ( int  liveness)

The network liveness has changed; this is called from circuitstats.c whenever we receive a cell, or when timeout expires and we assume the network is down.

Definition at line 6555 of file control.c.

◆ control_event_networkstatus_changed()

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.

Definition at line 6621 of file control.c.

References control_event_networkstatus_changed_helper().

◆ control_event_networkstatus_changed_helper()

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.

Definition at line 6585 of file control.c.

References EVENT_IS_INTERESTING.

Referenced by control_event_networkstatus_changed(), and control_event_newconsensus().

◆ control_event_networkstatus_changed_single()

int control_event_networkstatus_changed_single ( const routerstatus_t rs)

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

Definition at line 6717 of file control.c.

References EVENT_IS_INTERESTING.

Referenced by mark_all_dirservers_up().

◆ control_event_newconsensus()

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.

Definition at line 6629 of file control.c.

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

Referenced by notify_control_networkstatus_changed().

◆ control_event_or_conn_status()

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.

Definition at line 5966 of file control.c.

◆ control_event_pt_log()

void control_event_pt_log ( const char *  log)

A pluggable transport called pt_name has emitted a log message found in message at severity log level.

Definition at line 7056 of file control.c.

References send_control_event().

◆ control_event_pt_status()

void control_event_pt_status ( const char *  status)

A pluggable transport has emitted a STATUS message found in status.

Definition at line 7066 of file control.c.

◆ control_event_server_error()

int control_event_server_error ( const char *  format,
  ... 
)

Format and send an EVENT_STATUS_SERVER LOG_ERR event, and flush it to the controller(s) immediately.

Definition at line 6856 of file control.c.

◆ control_event_server_status()

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

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

Definition at line 6847 of file control.c.

Referenced by inform_testing_reachability(), and on_hibernate_state_change().

◆ control_event_signal()

int control_event_signal ( uintptr_t  signal_num)

Called when a signal has been processed from signal_callback

Definition at line 6677 of file control.c.

References control_event_is_interesting().

◆ control_event_status()

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.

Definition at line 6746 of file control.c.

◆ control_event_stream_bandwidth()

int control_event_stream_bandwidth ( edge_connection_t edge_conn)

Print out STREAM_BW event for a single conn

Definition at line 6014 of file control.c.

◆ control_event_stream_bandwidth_used()

int control_event_stream_bandwidth_used ( void  )

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

Definition at line 6040 of file control.c.

References EVENT_IS_INTERESTING.

Referenced by control_per_second_events().

◆ control_event_stream_status()

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

Something has happened to the stream associated with AP connection conn: tell any interested control connections.

Definition at line 5819 of file control.c.

Referenced by connection_ap_detach_retriable(), and remap_event_helper().

◆ control_event_transport_launched()

void control_event_transport_launched ( const char *  mode,
const char *  transport_name,
tor_addr_t addr,
uint16_t  port 
)

A new pluggable transport called transport_name was launched on addr:port. mode is either "server" or "client" depending on the mode of the pluggable transport. "650" SP "TRANSPORT_LAUNCHED" SP Mode SP Name SP Address SP Port

Definition at line 7045 of file control.c.

References fmt_addr, and send_control_event().

◆ control_free_all()

void control_free_all ( void  )

Free any leftover allocated memory of the control.c subsystem.

Definition at line 7535 of file control.c.

◆ control_get_bytes_rw_last_sec()

static void control_get_bytes_rw_last_sec ( uint64_t *  n_read,
uint64_t *  n_written 
)
static

Set n_read and n_written to the total number of bytes read and written by Tor since the last call to this function.

Call this only from the main thread.

Definition at line 445 of file control.c.

References stats_n_bytes_read, and stats_n_bytes_written.

Referenced by control_per_second_events().

◆ control_per_second_events()

void control_per_second_events ( void  )

◆ control_ports_write_to_file()

void control_ports_write_to_file ( void  )

Write all of the open control ports to ControlPortWriteToFile

Definition at line 744 of file control.c.

References CONN_TYPE_CONTROL_LISTENER, or_options_t::ControlPortWriteToFile, smartlist_add_asprintf(), and SMARTLIST_FOREACH_BEGIN.

◆ control_setconf_helper()

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

Helper for setconf and resetconf. Acts like setconf, except it passes use_defaults on to options_trial_assign(). Modifies the contents of body.

Definition at line 1076 of file control.c.

Referenced by handle_control_resetconf(), and handle_control_setconf().

◆ control_update_global_event_mask()

void control_update_global_event_mask ( void  )

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

Definition at line 320 of file control.c.

References CONN_TYPE_CONTROL, control_adjust_event_log_severity(), control_any_per_second_event_enabled(), global_event_mask, SMARTLIST_FOREACH, and STATE_IS_OPEN.

Referenced by connection_control_closed(), and connection_free_all().

◆ decode_escaped_string()

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.

Definition at line 648 of file control.c.

References get_escaped_string_length(), and tor_assert().

◆ decode_hashed_passwords()

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_RFC2440_SPECIFIER_LEN+DIGEST_LEN) on success, or NULL on failure.

Definition at line 1411 of file control.c.

References base16_decode(), base64_decode(), DIGEST_LEN, S2K_RFC2440_SPECIFIER_LEN, smartlist_add(), strcmpstart(), and tor_assert().

◆ digest_list_to_string()

static char* digest_list_to_string ( const smartlist_t sl)
static

Given a smartlist of 20-byte digests, return a newly allocated string containing each of those digests in order, formatted in HEX, and terminated with a newline.

Definition at line 2428 of file control.c.

Referenced by getinfo_helper_downloads().

◆ disable_control_logging()

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.

Definition at line 6385 of file control.c.

References disable_log_messages.

◆ download_status_to_string()

static char * download_status_to_string ( const download_status_t dl)
static

Turn a download_status_t into a human-readable description in a newly allocated string. The format is specified in control-spec.txt, under the documentation for "GETINFO download/..." .

Definition at line 2452 of file control.c.

Referenced by getinfo_helper_downloads().

◆ enable_control_logging()

void enable_control_logging ( void  )

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

Definition at line 6393 of file control.c.

References disable_log_messages, and tor_assert().

◆ event_hs_descriptor_receive_end()

static void event_hs_descriptor_receive_end ( const char *  action,
const char *  onion_address,
const char *  desc_id,
rend_auth_type_t  auth_type,
const char *  hsdir_id_digest,
const char *  reason 
)
static

send HS_DESC event after got response from hs directory.

NOTE: this is an internal function used by following functions: control_event_hsv2_descriptor_received control_event_hsv2_descriptor_failed control_event_hsv3_descriptor_failed

So do not call this function directly.

Definition at line 7283 of file control.c.

◆ event_to_log_severity()

static int event_to_log_severity ( int  event)
inlinestatic

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

Definition at line 275 of file control.c.

References LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_NOTICE, and LOG_WARN.

Referenced by control_adjust_event_log_severity().

◆ extract_escaped_string()

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.

Definition at line 628 of file control.c.

References get_escaped_string_length().

◆ find_element_starting_with()

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.

Definition at line 3596 of file control.c.

◆ flush_queued_events_cb()

static void flush_queued_events_cb ( mainloop_event_t event,
void *  arg 
)
static

Libevent callback: Flushes pending events to controllers that are interested in them.

Definition at line 990 of file control.c.

References queued_events_flush_all().

◆ format_cell_stats()

void format_cell_stats ( char **  event_string,
circuit_t circ,
cell_stats_t *  cell_stats 
)

◆ get_circ()

static origin_circuit_t* get_circ ( const char *  id)
static

Given a text circuit id, return the corresponding circuit.

Definition at line 1045 of file control.c.

References circuit_get_by_global_id(), and tor_parse_ulong().

Referenced by handle_control_closecircuit(), and handle_control_setcircuitpurpose().

◆ get_controller_cookie_file_name()

char* get_controller_cookie_file_name ( void  )

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

Definition at line 6926 of file control.c.

References or_options_t::CookieAuthFile.

Referenced by tor_cleanup().

◆ get_desc_id_from_query()

static const char* get_desc_id_from_query ( const rend_data_t rend_data,
const char *  hsdir_fp 
)
static

For an HS descriptor query rend_data, using the onion_address and HSDir fingerprint hsdir_fp, find out which descriptor ID in the query is the right one.

Return a pointer of the binary descriptor ID found in the query's object or NULL if not found.

Definition at line 7176 of file control.c.

◆ get_escaped_string_length()

static int get_escaped_string_length ( const char *  start,
size_t  in_len_max,
int *  chars_out 
)
inlinestatic

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.

Definition at line 592 of file control.c.

Referenced by decode_escaped_string(), and extract_escaped_string().

◆ get_stream()

static entry_connection_t* get_stream ( const char *  id)
static

Given a text stream id, return the corresponding AP connection.

Definition at line 1057 of file control.c.

References CONN_TYPE_AP, connection_get_by_global_id(), connection_t::marked_for_close, tor_parse_uint64(), and connection_t::type.

Referenced by handle_control_closestream(), and handle_control_redirectstream().

◆ getargs_helper()

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.

Definition at line 3572 of file control.c.

References smartlist_split_string().

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

◆ getinfo_helper_current_time()

STATIC int getinfo_helper_current_time ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Implementation helper for GETINFO: answers requests for information about the current time in both local and UTC forms.

Definition at line 2093 of file control.c.

◆ getinfo_helper_dir()

STATIC int getinfo_helper_dir ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Implementation helper for GETINFO: knows the answers for questions about directory information.

Definition at line 2118 of file control.c.

References node_get_by_hex_id(), signed_descriptor_get_body(), and strcmpstart().

◆ getinfo_helper_downloads()

STATIC int getinfo_helper_downloads ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Implementation helper for GETINFO: knows the answers for questions about download status information.

Definition at line 2749 of file control.c.

References digest_list_to_string(), download_status_to_string(), getinfo_helper_downloads_bridge(), getinfo_helper_downloads_cert(), getinfo_helper_downloads_desc(), getinfo_helper_downloads_networkstatus(), SMARTLIST_FOREACH, strcmpstart(), tor_assert(), and tor_free.

◆ getinfo_helper_downloads_bridge()

STATIC void getinfo_helper_downloads_bridge ( const char *  bridge_req,
download_status_t **  dl_to_emit,
smartlist_t **  digest_list,
const char **  errmsg 
)

Handle the bridge download cases for getinfo_helper_downloads()

Definition at line 2706 of file control.c.

References base16_decode(), DIGEST_LEN, and HEX_DIGEST_LEN.

Referenced by getinfo_helper_downloads().

◆ getinfo_helper_downloads_cert()

STATIC void getinfo_helper_downloads_cert ( const char *  fp_sk_req,
download_status_t **  dl_to_emit,
smartlist_t **  digest_list,
const char **  errmsg 
)

Handle the cert download cases for getinfo_helper_downloads()

Definition at line 2560 of file control.c.

References base16_decode(), DIGEST_LEN, HEX_DIGEST_LEN, and strcmpstart().

Referenced by getinfo_helper_downloads().

◆ getinfo_helper_downloads_desc()

STATIC void getinfo_helper_downloads_desc ( const char *  desc_req,
download_status_t **  dl_to_emit,
smartlist_t **  digest_list,
const char **  errmsg 
)

Handle the routerdesc download cases for getinfo_helper_downloads()

Definition at line 2660 of file control.c.

References base16_decode(), DIGEST_LEN, and HEX_DIGEST_LEN.

Referenced by getinfo_helper_downloads().

◆ getinfo_helper_downloads_networkstatus()

STATIC void getinfo_helper_downloads_networkstatus ( const char *  flavor,
download_status_t **  dl_to_emit,
const char **  errmsg 
)

Handle the consensus download cases for getinfo_helper_downloads()

Definition at line 2531 of file control.c.

Referenced by getinfo_helper_downloads().

◆ getinfo_helper_events()

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

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

Definition at line 2909 of file control.c.

◆ getinfo_helper_listeners()

static int getinfo_helper_listeners ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)
static

Implementation helper for GETINFO: answers requests for information about which ports are bound.

Definition at line 2034 of file control.c.

◆ getinfo_helper_liveness()

static int getinfo_helper_liveness ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)
static

Implementation helper for GETINFO: answers queries about network liveness.

Definition at line 3180 of file control.c.

◆ getinfo_helper_misc()

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

Implementation helper for GETINFO: knows the answers for various trivial-to-implement questions.

Definition at line 1869 of file control.c.

◆ getinfo_helper_onions()

STATIC int getinfo_helper_onions ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Implementation helper for GETINFO: knows how to enumerate hidden services created via the control port.

Definition at line 3150 of file control.c.

References detached_onion_services, and control_connection_t::ephemeral_onion_services.

◆ getinfo_helper_sr()

static int getinfo_helper_sr ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)
static

Implementation helper for GETINFO: answers queries about shared random value.

Definition at line 3200 of file control.c.

◆ handle_control_add_onion()

static int handle_control_add_onion ( control_connection_t conn,
uint32_t  len,
const char *  body 
)
static

Called when we get a ADD_ONION command; parse the body, and set up the new ephemeral Onion Service.

Definition at line 4689 of file control.c.

References getargs_helper().

◆ handle_control_attachstream()

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

Called when we get an ATTACHSTREAM message. Try to attach the requested stream, and report success or failure.

Definition at line 3821 of file control.c.

References getargs_helper().

◆ handle_control_authchallenge()

static int handle_control_authchallenge ( control_connection_t conn,
uint32_t  len,
const char *  body 
)
static

Called when we get an AUTHCHALLENGE command.

Definition at line 4232 of file control.c.

References DIGEST256_LEN, and HEX_DIGEST256_LEN.

◆ handle_control_authenticate()

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

Called when we get an AUTHENTICATE message. Check whether the authentication is valid, and if so, update the connection's state to OPEN. Reply with DONE or ERROR.

We only get here if both kinds of authentication failed.

Definition at line 1451 of file control.c.

◆ handle_control_closecircuit()

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.

Definition at line 4076 of file control.c.

References get_circ(), and getargs_helper().

◆ handle_control_closestream()

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.

Definition at line 4038 of file control.c.

References get_stream(), and getargs_helper().

◆ handle_control_del_onion()

static int handle_control_del_onion ( control_connection_t conn,
uint32_t  len,
const char *  body 
)
static

Called when we get a DEL_ONION command; parse the body, and remove the existing ephemeral Onion Service.

Definition at line 5183 of file control.c.

References getargs_helper().

◆ handle_control_dropguards()

static int handle_control_dropguards ( control_connection_t conn,
uint32_t  len,
const char *  body 
)
static

Implementation for the DROPGUARDS command.

Definition at line 4386 of file control.c.

References smartlist_split_string().

◆ handle_control_dropownership()

static int handle_control_dropownership ( control_connection_t conn,
uint32_t  len,
const char *  body 
)
static

Called when we get a DROPOWNERSHIP command. Mark this connection as a non-owning connection, so that we will not exit if the connection closes.

Definition at line 1750 of file control.c.

References control_connection_t::is_owning_control_connection.

◆ handle_control_extendcircuit()

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

Called when we get an EXTENDCIRCUIT message. Try to extend the listed circuit, and report success or failure.

Definition at line 3620 of file control.c.

References CIRCUIT_PURPOSE_C_GENERAL, and getargs_helper().

◆ handle_control_getconf()

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

Called when we receive a GETCONF message. Parse the request, and reply with a CONFVALUE or an ERROR message

Definition at line 1197 of file control.c.

References smartlist_split_string().

◆ handle_control_getinfo()

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.

Definition at line 3477 of file control.c.

References smartlist_split_string().

◆ handle_control_hsfetch()

static int handle_control_hsfetch ( control_connection_t conn,
uint32_t  len,
const char *  body 
)
static

Implementation for the HSFETCH command.

Definition at line 4418 of file control.c.

References DIGEST_LEN, and getargs_helper().

◆ handle_control_hspost()

static int handle_control_hspost ( control_connection_t conn,
uint32_t  len,
const char *  body 
)
static

Implementation for the HSPOST command.

Definition at line 4521 of file control.c.

References connection_printf_to_buf().

◆ handle_control_loadconf()

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

Called when we get a +LOADCONF message.

Definition at line 1266 of file control.c.

References options_init_from_string().

◆ handle_control_mapaddress()

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

Called when we get a MAPADDRESS command; try to bind all listed addresses, and report success or failure.

Definition at line 1780 of file control.c.

References smartlist_split_string().

◆ handle_control_postdescriptor()

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

Called when we get a POSTDESCRIPTOR message. Try to learn the provided descriptor, and report success or failure.

Definition at line 3916 of file control.c.

References connection_printf_to_buf().

◆ handle_control_protocolinfo()

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

Called when we get a PROTOCOLINFO command: send back a reply.

Definition at line 4159 of file control.c.

References control_connection_t::have_sent_protocolinfo, and smartlist_split_string().

◆ handle_control_redirectstream()

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.

Definition at line 3990 of file control.c.

References get_stream(), and getargs_helper().

◆ handle_control_resetconf()

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.

Definition at line 1189 of file control.c.

References control_setconf_helper().

◆ handle_control_resolve()

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

Called when we get a RESOLVE command: start trying to resolve the listed addresses.

Definition at line 4117 of file control.c.

References control_connection_t::event_mask.

◆ handle_control_saveconf()

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.

Definition at line 1644 of file control.c.

References connection_write_str_to_buf(), or_options_t::IncludeUsed, options_save_current(), send_control_done(), and strcmpstart().

◆ handle_control_setcircuitpurpose()

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

Called when we get a SETCIRCUITPURPOSE message. If we can find the circuit and it's a valid purpose, change it.

Definition at line 3776 of file control.c.

References get_circ(), and getargs_helper().

◆ handle_control_setconf()

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.

Definition at line 1180 of file control.c.

References control_setconf_helper().

◆ handle_control_setevents()

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.

Definition at line 1355 of file control.c.

References smartlist_split_string().

◆ handle_control_signal()

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

Definition at line 1688 of file control.c.

◆ handle_control_takeownership()

static int handle_control_takeownership ( control_connection_t conn,
uint32_t  len,
const char *  body 
)
static

Called when we get a TAKEOWNERSHIP command. Mark this connection as an owning connection, so that we will exit if the connection closes.

Definition at line 1730 of file control.c.

References control_connection_t::is_owning_control_connection.

◆ handle_control_usefeature()

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.

Definition at line 4352 of file control.c.

References smartlist_split_string().

◆ handle_getinfo_helper()

static int handle_getinfo_helper ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  err_out 
)
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.

Definition at line 3452 of file control.c.

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

◆ is_keyval_pair()

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.

Definition at line 3610 of file control.c.

◆ is_valid_initial_command()

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.

Definition at line 5329 of file control.c.

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

◆ list_getinfo_options()

static char * list_getinfo_options ( void  )
static

Allocate and return a list of recognized GETINFO options.

Definition at line 3424 of file control.c.

References getinfo_items, smartlist_add_asprintf(), SMARTLIST_FOREACH, smartlist_join_strings(), smartlist_sort_strings(), tor_free, and getinfo_item_t::varname.

◆ log_severity_to_event()

static int log_severity_to_event ( int  severity)
inlinestatic

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

Definition at line 289 of file control.c.

References LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_NOTICE, and LOG_WARN.

Referenced by control_event_logmsg().

◆ lost_owning_controller()

static void lost_owning_controller ( const char *  owner_type,
const char *  loss_manner 
)
static

Shut down this Tor instance in the same way that SIGINT would, but with a log message appropriate for the loss of an owning controller.

Definition at line 5288 of file control.c.

Referenced by owning_controller_procmon_cb().

◆ MOCK_IMPL() [1/3]

MOCK_IMPL ( STATIC  void,
queue_control_event_string  ,
(uint16_t event, char *msg)   
)

Helper: inserts an event on the list of events queued to be sent to one or more controllers, and schedules the events to be flushed if needed.

This function takes ownership of msg, and may free it.

We queue these events rather than send them immediately in order to break the dependency in our callgraph from code that generates events for the controller, and the network layer at large. Otherwise, nearly every interesting part of Tor would potentially call every other interesting part of Tor.

Definition at line 862 of file control.c.

◆ MOCK_IMPL() [2/3]

MOCK_IMPL ( STATIC  void,
send_control_event_string  ,
(uint16_t event, const char *msg)   
)

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

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

Definition at line 1002 of file control.c.

◆ MOCK_IMPL() [3/3]

MOCK_IMPL ( const char *  ,
node_describe_longname_by_id  ,
(const char *id_digest)   
)

Return a longname the node whose identity is id_digest. If node_get_by_id() returns NULL, base 16 encoding of id_digest is returned instead.

This function is not thread-safe. Each call to this function invalidates previous values returned by this function.

Definition at line 7104 of file control.c.

References MAX_VERBOSE_NICKNAME_LEN, and node_get_verbose_nickname_by_id().

◆ monitor_owning_controller_process()

void monitor_owning_controller_process ( const char *  process_spec)

Set process_spec as Tor's owning controller process. Exit on failure.

Definition at line 6981 of file control.c.

References owning_controller_process_monitor, owning_controller_process_spec, and tor_assert().

◆ munge_extrainfo_into_routerinfo()

static char* munge_extrainfo_into_routerinfo ( const char *  ri_body,
const signed_descriptor_t ri,
const 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.

Definition at line 1990 of file control.c.

References signed_descriptor_get_body(), and signed_descriptor_t::signed_descriptor_len.

◆ orconn_target_get_name()

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

Figure out the best name for the target router of an OR connection conn, and write it into the len-character buffer name.

Definition at line 5944 of file control.c.

◆ owning_controller_procmon_cb()

static void owning_controller_procmon_cb ( void *  unused)
static

Process-termination monitor callback for Tor's owning controller process.

Definition at line 6971 of file control.c.

References lost_owning_controller().

◆ peek_connection_has_control0_command()

static int peek_connection_has_control0_command ( connection_t conn)
static

Wrapper around peek_buf_has_control0 command: presents the same interface as that underlying functions, but takes a connection_t intead of a buf_t.

Definition at line 5354 of file control.c.

References connection_t::inbuf.

◆ queued_event_free_()

static void queued_event_free_ ( queued_event_t ev)
static

Release all storage held by ev.

Definition at line 914 of file control.c.

References tor_free.

◆ queued_events_flush_all()

static void queued_events_flush_all ( int  force)
static

Send every queued event to every controller that's interested in it, and remove the events from the queue. If force is true, then make all controllers send their data out immediately, since we may be about to shut down.

Definition at line 928 of file control.c.

References flush_pending_log_callbacks().

Referenced by flush_queued_events_cb().

◆ read_escaped_data()

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.

Definition at line 551 of file control.c.

◆ rend_auth_type_to_string()

const char* rend_auth_type_to_string ( rend_auth_type_t  auth_type)

Convert rendezvous auth type to string for HS_DESC control events

Definition at line 7076 of file control.c.

◆ rend_hsaddress_str_or_unknown()

static const char* rend_hsaddress_str_or_unknown ( const char *  onion_address)
static

Return either the onion address if the given pointer is a non empty string else the unknown string.

Definition at line 7115 of file control.c.

◆ send_control_done()

static void send_control_done ( control_connection_t conn)
static

Send a "DONE" message down the control connection conn.

Definition at line 788 of file control.c.

References connection_write_str_to_buf().

Referenced by handle_control_saveconf().

◆ send_control_event()

static void send_control_event ( uint16_t  event,
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.

Definition at line 1034 of file control.c.

References send_control_event_impl().

Referenced by control_event_clients_seen(), control_event_conn_bandwidth(), control_event_my_descriptor_changed(), control_event_pt_log(), and control_event_transport_launched().

◆ send_control_event_impl()

static void send_control_event_impl ( uint16_t  event,
const char *  format,
va_list  ap 
)
static

Helper for send_control_event and control_event_status: 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.

Definition at line 1015 of file control.c.

References tor_vasprintf().

Referenced by send_control_event().

◆ sum_up_cell_stats_by_command()

void sum_up_cell_stats_by_command ( circuit_t circ,
cell_stats_t *  cell_stats 
)

Helper: iterate over cell statistics of circ and sum up added cells, removed cells, and waiting times by cell command and direction. Store results in cell_stats. Free cell statistics of the circuit afterwards.

Definition at line 6194 of file control.c.

References SMARTLIST_FOREACH_BEGIN, circuit_t::testing_cell_stats, and tor_assert().

◆ TO_CONTROL_CONN()

control_connection_t* TO_CONTROL_CONN ( connection_t c)

Convert a connection_t* to an control_connection_t*; assert if the cast is invalid.

Definition at line 266 of file control.c.

References DOWNCAST, and tor_assert().

Referenced by connection_finished_flushing(), connection_free_all(), connection_process_inbuf(), and connection_reached_eof().

◆ write_escaped_data()

STATIC 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.

Definition at line 495 of file control.c.

References SIZE_T_CEILING, and tor_assert().

◆ write_stream_target_to_buf()

static int write_stream_target_to_buf ( entry_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.

Definition at line 5798 of file control.c.

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

Variable Documentation

◆ authentication_cookie

uint8_t* authentication_cookie = NULL
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.)

Definition at line 171 of file control.c.

◆ authentication_cookie_is_set

int authentication_cookie_is_set = 0
static

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

Definition at line 167 of file control.c.

◆ block_event_queue_flag

tor_threadlocal_t block_event_queue_flag
static

Pointer to int. If this is greater than 0, we don't allow new events to be queued.

Definition at line 802 of file control.c.

◆ control_event_table

const struct control_event_t control_event_table[]
static

Table mapping event values to their names. Used to implement SETEVENTS and GETINFO events/names, and to keep they in sync.

Definition at line 1317 of file control.c.

◆ CONTROLPORT_IS_NOT_AN_HTTP_PROXY_MSG

const char CONTROLPORT_IS_NOT_AN_HTTP_PROXY_MSG[]
static
Initial value:
=
"HTTP/1.0 501 Tor ControlPort is not an HTTP proxy"
"\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n"
"<html>\n"
"<head>\n"
"<title>Tor's ControlPort is not an HTTP proxy</title>\n"
"</head>\n"
"<body>\n"
"<h1>Tor's ControlPort is not an HTTP proxy</h1>\n"
"<p>\n"
"It appears you have configured your web browser to use Tor's control port"
" as an HTTP proxy.\n"
"This is not correct: Tor's default SOCKS proxy port is 9050.\n"
"Please configure your client accordingly.\n"
"</p>\n"
"<p>\n"
"See <a href=\"https://www.torproject.org/documentation.html\">"
"https://www.torproject.org/documentation.html</a> for more "
"information.\n"
"<!-- Plus this comment, to make the body response more than 512 bytes, so "
" IE will be willing to display it. Comment comment comment comment "
" comment comment comment comment comment comment comment comment.-->\n"
"</p>\n"
"</body>\n"
"</html>\n"

Definition at line 5365 of file control.c.

◆ detached_onion_services

smartlist_t* detached_onion_services = NULL
static

The list of onion services that have been added via ADD_ONION that do not belong to any particular control connection.

Definition at line 182 of file control.c.

Referenced by getinfo_helper_onions().

◆ disable_log_messages

int disable_log_messages = 0
static

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

Definition at line 150 of file control.c.

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

◆ flush_queued_event_pending

int flush_queued_event_pending = 0
static

True if the flush_queued_events_event is pending.

Definition at line 809 of file control.c.

◆ flush_queued_events_event

mainloop_event_t* flush_queued_events_event = NULL
static

An event that should fire in order to flush the contents of queued_control_events.

Definition at line 816 of file control.c.

Referenced by control_event_logmsg_pending().

◆ getinfo_items

const getinfo_item_t getinfo_items[]
static

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

Definition at line 3244 of file control.c.

Referenced by handle_getinfo_helper(), and list_getinfo_options().

◆ global_event_mask

event_mask_t global_event_mask = 0
static

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

Definition at line 147 of file control.c.

Referenced by control_update_global_event_mask().

◆ network_is_live

int network_is_live = 0
static

Cached liveness for network liveness events and GETINFO

Definition at line 6537 of file control.c.

◆ owning_controller_process_monitor

tor_process_monitor_t* owning_controller_process_monitor = NULL
static

A process-termination monitor for Tor's owning controller, or NULL if this Tor instance is not currently owned by a process.

Definition at line 6966 of file control.c.

Referenced by monitor_owning_controller_process().

◆ owning_controller_process_spec

char* owning_controller_process_spec = NULL
static

A copy of the process specifier of Tor's owning controller, or NULL if this Tor instance is not currently owned by a process.

Definition at line 6962 of file control.c.

Referenced by monitor_owning_controller_process().

◆ queued_control_events

smartlist_t* queued_control_events = NULL
static

Holds a smartlist of queued_event_t objects that may need to be sent to one or more controllers

Definition at line 806 of file control.c.

◆ queued_control_events_lock

tor_mutex_t* queued_control_events_lock = NULL
static

Lock to protect the above fields.

Definition at line 812 of file control.c.

◆ signal_table

const struct signal_t signal_table[]
static
Initial value:
= {
{ SIGHUP, "RELOAD" },
{ SIGHUP, "HUP" },
{ SIGINT, "SHUTDOWN" },
{ SIGUSR1, "DUMP" },
{ SIGUSR1, "USR1" },
{ SIGUSR2, "DEBUG" },
{ SIGUSR2, "USR2" },
{ SIGTERM, "HALT" },
{ SIGTERM, "TERM" },
{ SIGTERM, "INT" },
{ SIGNEWNYM, "NEWNYM" },
{ SIGCLEARDNSCACHE, "CLEARDNSCACHE"},
{ SIGHEARTBEAT, "HEARTBEAT"},
{ SIGACTIVE, "ACTIVE" },
{ SIGDORMANT, "DORMANT" },
{ 0, NULL },
}

Definition at line 1665 of file control.c.