2010-07-22 11:35:09 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2018-06-20 14:13:28 +02:00
|
|
|
* Copyright (c) 2007-2018, The Tor Project, Inc. */
|
2010-07-22 11:35:09 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file control.h
|
|
|
|
* \brief Header file for control.c.
|
|
|
|
**/
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_CONTROL_H
|
|
|
|
#define TOR_CONTROL_H
|
2010-07-22 11:35:09 +02:00
|
|
|
|
2018-06-15 16:17:27 +02:00
|
|
|
control_connection_t *TO_CONTROL_CONN(connection_t *);
|
|
|
|
|
2015-08-12 15:35:26 +02:00
|
|
|
void control_initialize_event_queue(void);
|
|
|
|
|
2010-07-22 11:35:09 +02:00
|
|
|
void control_update_global_event_mask(void);
|
|
|
|
void control_adjust_event_log_severity(void);
|
|
|
|
|
2011-05-09 18:13:37 +02:00
|
|
|
void control_ports_write_to_file(void);
|
|
|
|
|
2010-07-22 11:35:09 +02:00
|
|
|
/** Log information about the connection <b>conn</b>, protecting it as with
|
|
|
|
* CONN_LOG_PROTECT. Example:
|
|
|
|
*
|
|
|
|
* LOG_FN_CONN(conn, (LOG_DEBUG, "Socket %d wants to write", conn->s));
|
|
|
|
**/
|
|
|
|
#define LOG_FN_CONN(conn, args) \
|
|
|
|
CONN_LOG_PROTECT(conn, log_fn args)
|
|
|
|
|
2017-10-18 19:36:53 +02:00
|
|
|
#define CC_LOCAL_FD_IS_OWNER (1u<<0)
|
|
|
|
#define CC_LOCAL_FD_IS_AUTHENTICATED (1u<<1)
|
|
|
|
int control_connection_add_local_fd(tor_socket_t sock, unsigned flags);
|
|
|
|
|
2010-07-22 11:35:09 +02:00
|
|
|
int connection_control_finished_flushing(control_connection_t *conn);
|
|
|
|
int connection_control_reached_eof(control_connection_t *conn);
|
2011-05-20 01:27:51 +02:00
|
|
|
void connection_control_closed(control_connection_t *conn);
|
|
|
|
|
2010-07-22 11:35:09 +02:00
|
|
|
int connection_control_process_inbuf(control_connection_t *conn);
|
|
|
|
|
|
|
|
#define EVENT_NS 0x000F
|
|
|
|
int control_event_is_interesting(int event);
|
|
|
|
|
2018-05-07 23:41:54 +02:00
|
|
|
void control_per_second_events(void);
|
|
|
|
int control_any_per_second_event_enabled(void);
|
|
|
|
|
2010-07-22 11:35:09 +02:00
|
|
|
int control_event_circuit_status(origin_circuit_t *circ,
|
|
|
|
circuit_status_event_t e, int reason);
|
2012-01-11 16:28:20 +01:00
|
|
|
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);
|
2011-07-20 18:55:42 +02:00
|
|
|
int control_event_stream_status(entry_connection_t *conn,
|
2010-07-22 11:35:09 +02:00
|
|
|
stream_status_event_t e,
|
|
|
|
int reason);
|
|
|
|
int control_event_or_conn_status(or_connection_t *conn,
|
|
|
|
or_conn_status_event_t e, int reason);
|
|
|
|
int control_event_bandwidth_used(uint32_t n_read, uint32_t n_written);
|
|
|
|
int control_event_stream_bandwidth(edge_connection_t *edge_conn);
|
|
|
|
int control_event_stream_bandwidth_used(void);
|
2013-02-24 13:32:57 +01:00
|
|
|
int control_event_circ_bandwidth_used(void);
|
2013-02-06 14:15:32 +01:00
|
|
|
int control_event_conn_bandwidth(connection_t *conn);
|
|
|
|
int control_event_conn_bandwidth_used(void);
|
2013-02-06 14:37:38 +01:00
|
|
|
int control_event_circuit_cell_stats(void);
|
2012-06-05 01:51:00 +02:00
|
|
|
void control_event_logmsg(int severity, uint32_t domain, const char *msg);
|
2018-05-01 16:26:04 +02:00
|
|
|
void control_event_logmsg_pending(void);
|
2010-07-22 11:35:09 +02:00
|
|
|
int control_event_descriptors_changed(smartlist_t *routers);
|
|
|
|
int control_event_address_mapped(const char *from, const char *to,
|
2013-04-03 18:50:51 +02:00
|
|
|
time_t expires, const char *error,
|
|
|
|
const int cached);
|
2010-07-22 11:35:09 +02:00
|
|
|
int control_event_my_descriptor_changed(void);
|
2015-05-06 14:37:13 +02:00
|
|
|
int control_event_network_liveness_update(int liveness);
|
2010-07-22 11:35:09 +02:00
|
|
|
int control_event_networkstatus_changed(smartlist_t *statuses);
|
|
|
|
|
|
|
|
int control_event_newconsensus(const networkstatus_t *consensus);
|
2010-09-29 07:35:08 +02:00
|
|
|
int control_event_networkstatus_changed_single(const routerstatus_t *rs);
|
2010-07-22 11:35:09 +02:00
|
|
|
int control_event_general_status(int severity, const char *format, ...)
|
|
|
|
CHECK_PRINTF(2,3);
|
|
|
|
int control_event_client_status(int severity, const char *format, ...)
|
|
|
|
CHECK_PRINTF(2,3);
|
|
|
|
int control_event_server_status(int severity, const char *format, ...)
|
|
|
|
CHECK_PRINTF(2,3);
|
2015-07-30 16:43:37 +02:00
|
|
|
|
|
|
|
int control_event_general_error(const char *format, ...)
|
|
|
|
CHECK_PRINTF(1,2);
|
|
|
|
int control_event_client_error(const char *format, ...)
|
|
|
|
CHECK_PRINTF(1,2);
|
|
|
|
int control_event_server_error(const char *format, ...)
|
|
|
|
CHECK_PRINTF(1,2);
|
|
|
|
|
2010-07-22 11:35:09 +02:00
|
|
|
int control_event_guard(const char *nickname, const char *digest,
|
|
|
|
const char *status);
|
2013-04-17 17:34:15 +02:00
|
|
|
int control_event_conf_changed(const smartlist_t *elements);
|
2013-08-21 18:37:35 +02:00
|
|
|
int control_event_buildtimeout_set(buildtimeout_set_event_t type,
|
|
|
|
const char *args);
|
2010-11-14 23:33:55 +01:00
|
|
|
int control_event_signal(uintptr_t signal);
|
2010-07-22 11:35:09 +02:00
|
|
|
|
2012-12-05 18:16:04 +01:00
|
|
|
int init_control_cookie_authentication(int enabled);
|
2014-05-23 01:56:56 +02:00
|
|
|
char *get_controller_cookie_file_name(void);
|
2010-07-22 11:35:09 +02:00
|
|
|
smartlist_t *decode_hashed_passwords(config_line_t *passwords);
|
|
|
|
void disable_control_logging(void);
|
|
|
|
void enable_control_logging(void);
|
|
|
|
|
2011-05-16 19:25:59 +02:00
|
|
|
void monitor_owning_controller_process(const char *process_spec);
|
2011-05-15 17:23:04 +02:00
|
|
|
|
2015-02-20 08:03:42 +01:00
|
|
|
int control_event_bootstrap(bootstrap_status_t status, int progress);
|
2017-09-13 21:47:18 +02:00
|
|
|
MOCK_DECL(void, control_event_bootstrap_prob_or,(const char *warn,
|
2014-03-10 23:52:07 +01:00
|
|
|
int reason,
|
2014-03-27 20:58:43 +01:00
|
|
|
or_connection_t *or_conn));
|
2017-09-13 21:47:18 +02:00
|
|
|
void control_event_bootstrap_problem(const char *warn, const char *reason,
|
|
|
|
const connection_t *conn, int dowarn);
|
2010-07-22 11:35:09 +02:00
|
|
|
|
|
|
|
void control_event_clients_seen(const char *controller_str);
|
2013-01-23 11:41:19 +01:00
|
|
|
void control_event_transport_launched(const char *mode,
|
|
|
|
const char *transport_name,
|
|
|
|
tor_addr_t *addr, uint16_t port);
|
2013-10-09 17:13:06 +02:00
|
|
|
const char *rend_auth_type_to_string(rend_auth_type_t auth_type);
|
2014-02-05 01:33:48 +01:00
|
|
|
MOCK_DECL(const char *, node_describe_longname_by_id,(const char *id_digest));
|
2017-11-10 15:08:05 +01:00
|
|
|
void control_event_hs_descriptor_requested(const char *onion_address,
|
|
|
|
rend_auth_type_t auth_type,
|
|
|
|
const char *id_digest,
|
2017-11-10 18:07:57 +01:00
|
|
|
const char *desc_id,
|
|
|
|
const char *hsdir_index);
|
2017-11-10 15:08:05 +01:00
|
|
|
void control_event_hs_descriptor_created(const char *onion_address,
|
|
|
|
const char *desc_id,
|
2015-08-04 14:47:51 +02:00
|
|
|
int replica);
|
2017-11-10 15:08:05 +01:00
|
|
|
void control_event_hs_descriptor_upload(const char *onion_address,
|
|
|
|
const char *desc_id,
|
2017-11-10 20:48:52 +01:00
|
|
|
const char *hs_dir,
|
|
|
|
const char *hsdir_index);
|
2015-03-22 14:31:53 +01:00
|
|
|
void control_event_hs_descriptor_upload_end(const char *action,
|
2016-02-17 20:34:20 +01:00
|
|
|
const char *onion_address,
|
2015-03-22 14:31:53 +01:00
|
|
|
const char *hs_dir,
|
|
|
|
const char *reason);
|
2016-02-17 20:34:20 +01:00
|
|
|
void control_event_hs_descriptor_uploaded(const char *hs_dir,
|
|
|
|
const char *onion_address);
|
2017-11-10 17:25:16 +01:00
|
|
|
/* Hidden service v2 HS_DESC specific. */
|
|
|
|
void control_event_hsv2_descriptor_failed(const rend_data_t *rend_data,
|
|
|
|
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 *id_digest);
|
2017-11-10 20:01:33 +01:00
|
|
|
/* Hidden service v3 HS_DESC specific. */
|
|
|
|
void control_event_hsv3_descriptor_failed(const char *onion_address,
|
|
|
|
const char *desc_id,
|
|
|
|
const char *hsdir_id_digest,
|
|
|
|
const char *reason);
|
2017-11-10 20:12:34 +01:00
|
|
|
void control_event_hsv3_descriptor_received(const char *onion_address,
|
|
|
|
const char *desc_id,
|
|
|
|
const char *hsdir_id_digest);
|
2015-03-22 14:31:53 +01:00
|
|
|
void control_event_hs_descriptor_upload_failed(const char *hs_dir,
|
2016-02-17 20:34:20 +01:00
|
|
|
const char *onion_address,
|
2015-03-22 14:31:53 +01:00
|
|
|
const char *reason);
|
2015-02-24 22:17:14 +01:00
|
|
|
void control_event_hs_descriptor_content(const char *onion_address,
|
|
|
|
const char *desc_id,
|
|
|
|
const char *hsdir_fp,
|
|
|
|
const char *content);
|
2013-01-23 11:41:19 +01:00
|
|
|
|
2013-08-14 16:16:06 +02:00
|
|
|
void control_free_all(void);
|
2010-07-22 11:35:09 +02:00
|
|
|
|
|
|
|
#ifdef CONTROL_PRIVATE
|
2013-08-25 17:29:03 +02:00
|
|
|
/* Recognized asynchronous event types. It's okay to expand this list
|
|
|
|
* because it is used both as a list of v0 event types, and as indices
|
|
|
|
* into the bitfield to determine which controllers want which events.
|
|
|
|
*/
|
2015-03-22 04:22:56 +01:00
|
|
|
/* This bitfield has no event zero 0x0000 */
|
2013-08-25 17:29:03 +02:00
|
|
|
#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_CIRCUIT_STATUS_MINOR 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
|
2017-08-24 22:51:46 +02:00
|
|
|
/* There was an AUTHDIR_NEWDESCS event, but it no longer exists. We
|
|
|
|
can reclaim 0x000D. */
|
2013-08-25 17:29:03 +02:00
|
|
|
#define EVENT_DESCCHANGED 0x000E
|
|
|
|
/* Exposed above */
|
|
|
|
// #define EVENT_NS 0x000F
|
|
|
|
#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
|
2015-08-21 00:42:20 +02:00
|
|
|
#define EVENT_GOT_SIGNAL 0x0018
|
2013-08-25 17:29:03 +02:00
|
|
|
#define EVENT_CONF_CHANGED 0x0019
|
2013-10-28 11:30:49 +01:00
|
|
|
#define EVENT_CONN_BW 0x001A
|
|
|
|
#define EVENT_CELL_STATS 0x001B
|
2018-04-10 18:16:21 +02:00
|
|
|
/* UNUSED : 0x001C */
|
2013-10-28 11:30:49 +01:00
|
|
|
#define EVENT_CIRC_BANDWIDTH_USED 0x001D
|
2013-08-25 17:29:03 +02:00
|
|
|
#define EVENT_TRANSPORT_LAUNCHED 0x0020
|
2013-10-09 17:13:06 +02:00
|
|
|
#define EVENT_HS_DESC 0x0021
|
2015-02-24 22:17:14 +01:00
|
|
|
#define EVENT_HS_DESC_CONTENT 0x0022
|
2015-05-06 14:37:13 +02:00
|
|
|
#define EVENT_NETWORK_LIVENESS 0x0023
|
|
|
|
#define EVENT_MAX_ 0x0023
|
2015-03-22 04:22:56 +01:00
|
|
|
|
|
|
|
/* sizeof(control_connection_t.event_mask) in bits, currently a uint64_t */
|
|
|
|
#define EVENT_CAPACITY_ 0x0040
|
|
|
|
|
|
|
|
/* If EVENT_MAX_ ever hits 0x0040, we need to make the mask into a
|
2014-09-08 21:15:05 +02:00
|
|
|
* different structure, as it can only handle a maximum left shift of 1<<63. */
|
2013-08-25 17:29:03 +02:00
|
|
|
|
2015-03-22 04:25:42 +01:00
|
|
|
#if EVENT_MAX_ >= EVENT_CAPACITY_
|
|
|
|
#error control_connection_t.event_mask has an event greater than its capacity
|
|
|
|
#endif
|
|
|
|
|
2015-03-22 04:22:56 +01:00
|
|
|
#define EVENT_MASK_(e) (((uint64_t)1)<<(e))
|
|
|
|
|
|
|
|
#define EVENT_MASK_NONE_ ((uint64_t)0x0)
|
|
|
|
|
|
|
|
#define EVENT_MASK_ABOVE_MIN_ ((~((uint64_t)0x0)) << EVENT_MIN_)
|
|
|
|
#define EVENT_MASK_BELOW_MAX_ ((~((uint64_t)0x0)) \
|
|
|
|
>> (EVENT_CAPACITY_ - EVENT_MAX_ \
|
|
|
|
- EVENT_MIN_))
|
|
|
|
|
|
|
|
#define EVENT_MASK_ALL_ (EVENT_MASK_ABOVE_MIN_ \
|
|
|
|
& EVENT_MASK_BELOW_MAX_)
|
|
|
|
|
2010-07-22 11:35:09 +02:00
|
|
|
/* Used only by control.c and test.c */
|
2013-06-06 23:58:28 +02:00
|
|
|
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);
|
2013-08-25 17:29:03 +02:00
|
|
|
|
|
|
|
#ifdef TOR_UNIT_TESTS
|
|
|
|
MOCK_DECL(STATIC void,
|
2015-07-30 16:51:55 +02:00
|
|
|
send_control_event_string,(uint16_t event, const char *msg));
|
|
|
|
|
2015-07-30 16:43:37 +02:00
|
|
|
MOCK_DECL(STATIC void,
|
|
|
|
queue_control_event_string,(uint16_t event, char *msg));
|
2013-08-25 17:29:03 +02:00
|
|
|
|
|
|
|
void control_testing_set_global_event_mask(uint64_t mask);
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* defined(TOR_UNIT_TESTS) */
|
2013-05-31 15:51:25 +02:00
|
|
|
|
|
|
|
/** Helper structure: temporarily stores cell statistics for a circuit. */
|
|
|
|
typedef struct cell_stats_t {
|
|
|
|
/** Number of cells added in app-ward direction by command. */
|
|
|
|
uint64_t added_cells_appward[CELL_COMMAND_MAX_ + 1];
|
|
|
|
/** Number of cells added in exit-ward direction by command. */
|
|
|
|
uint64_t added_cells_exitward[CELL_COMMAND_MAX_ + 1];
|
|
|
|
/** Number of cells removed in app-ward direction by command. */
|
|
|
|
uint64_t removed_cells_appward[CELL_COMMAND_MAX_ + 1];
|
|
|
|
/** Number of cells removed in exit-ward direction by command. */
|
|
|
|
uint64_t removed_cells_exitward[CELL_COMMAND_MAX_ + 1];
|
|
|
|
/** Total waiting time of cells in app-ward direction by command. */
|
|
|
|
uint64_t total_time_appward[CELL_COMMAND_MAX_ + 1];
|
|
|
|
/** Total waiting time of cells in exit-ward direction by command. */
|
|
|
|
uint64_t total_time_exitward[CELL_COMMAND_MAX_ + 1];
|
|
|
|
} cell_stats_t;
|
|
|
|
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,
|
2013-09-12 10:51:55 +02:00
|
|
|
const uint64_t *include_if_non_zero,
|
|
|
|
const uint64_t *number_to_include);
|
2013-05-31 15:51:25 +02:00
|
|
|
void format_cell_stats(char **event_string, circuit_t *circ,
|
|
|
|
cell_stats_t *cell_stats);
|
2015-01-07 17:37:23 +01:00
|
|
|
STATIC char *get_bw_samples(void);
|
2015-04-25 10:23:15 +02:00
|
|
|
|
2017-12-05 20:24:00 +01:00
|
|
|
/* ADD_ONION secret key to create an ephemeral service. The command supports
|
|
|
|
* multiple versions so this union stores the key and passes it to the HS
|
|
|
|
* subsystem depending on the requested version. */
|
|
|
|
typedef union add_onion_secret_key_t {
|
|
|
|
/* Hidden service v2 secret key. */
|
|
|
|
crypto_pk_t *v2;
|
|
|
|
/* Hidden service v3 secret key. */
|
|
|
|
ed25519_secret_key_t *v3;
|
|
|
|
} add_onion_secret_key_t;
|
|
|
|
|
2017-11-09 18:20:29 +01:00
|
|
|
STATIC int add_onion_helper_keyarg(const char *arg, int discard_pk,
|
|
|
|
const char **key_new_alg_out,
|
2017-12-05 20:24:00 +01:00
|
|
|
char **key_new_blob_out,
|
|
|
|
add_onion_secret_key_t *decoded_key,
|
2017-11-09 18:20:29 +01:00
|
|
|
int *hs_version, char **err_msg_out);
|
|
|
|
|
2015-04-14 05:08:31 +02:00
|
|
|
STATIC rend_authorized_client_t *
|
|
|
|
add_onion_helper_clientauth(const char *arg, int *created, char **err_msg_out);
|
2016-06-28 23:30:57 +02:00
|
|
|
|
2017-01-28 21:49:18 +01:00
|
|
|
STATIC int getinfo_helper_onions(
|
|
|
|
control_connection_t *control_conn,
|
|
|
|
const char *question,
|
|
|
|
char **answer,
|
|
|
|
const char **errmsg);
|
2016-06-28 23:30:57 +02:00
|
|
|
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);
|
2017-04-22 02:17:27 +02:00
|
|
|
STATIC int getinfo_helper_dir(
|
|
|
|
control_connection_t *control_conn,
|
|
|
|
const char *question, char **answer,
|
|
|
|
const char **errmsg);
|
2018-04-17 02:16:37 +02:00
|
|
|
STATIC int getinfo_helper_current_time(
|
|
|
|
control_connection_t *control_conn,
|
|
|
|
const char *question, char **answer,
|
|
|
|
const char **errmsg);
|
2016-06-28 23:30:57 +02:00
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* defined(CONTROL_PRIVATE) */
|
2010-07-22 11:35:09 +02:00
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_CONTROL_H) */
|
2010-07-22 11:35:09 +02:00
|
|
|
|