|
Tor 0.4.9.3-alpha-dev
|
Implementation for Tor's control-socket interface. More...
#include "core/or/or.h"#include "app/config/config.h"#include "app/main/main.h"#include "core/mainloop/connection.h"#include "core/mainloop/mainloop.h"#include "core/or/connection_or.h"#include "core/proto/proto_control0.h"#include "core/proto/proto_http.h"#include "feature/control/control.h"#include "feature/control/control_auth.h"#include "feature/control/control_cmd.h"#include "feature/control/control_events.h"#include "feature/control/control_proto.h"#include "feature/hs/hs_common.h"#include "feature/hs/hs_service.h"#include "lib/evloop/procmon.h"#include "feature/control/control_connection_st.h"Go to the source code of this file.
Macros | |
| #define | CONTROL_MODULE_PRIVATE |
| #define | CONTROL_PRIVATE |
| #define | MAX_COMMAND_LINE_LENGTH (1024*1024) |
Variables | |
| const struct signal_name_t | signal_table [] |
| static const char | CONTROLPORT_IS_NOT_AN_HTTP_PROXY_MSG [] |
| static int | network_is_live = 0 |
| static char * | owning_controller_process_spec = NULL |
| static tor_process_monitor_t * | owning_controller_process_monitor = NULL |
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.
| #define MAX_COMMAND_LINE_LENGTH (1024*1024) |
| void connection_control_closed | ( | control_connection_t * | conn | ) |
Called when conn is being freed.
Definition at line 231 of file control.c.
Referenced by connection_free_().
| int connection_control_finished_flushing | ( | control_connection_t * | conn | ) |
Called when conn has no more bytes left on its outbuf.
Definition at line 201 of file control.c.
Referenced by connection_finished_flushing().
| 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 420 of file control.c.
Referenced by connection_process_inbuf().
| int connection_control_reached_eof | ( | control_connection_t * | conn | ) |
Called when conn has gotten its socket closed.
Definition at line 209 of file control.c.
Referenced by connection_reached_eof().
| const control_connection_t * CONST_TO_CONTROL_CONN | ( | const connection_t * | c | ) |
Cast a const connection_t * to a const control_connection_t *.
Exit with an assertion failure if the input is not a control_connection_t.
| 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 95 of file control.c.
Referenced by options_act().
| void control_free_all | ( | void | ) |
Free any leftover allocated memory of the control.c subsystem.
Definition at line 622 of file control.c.
Referenced by tor_free_all().
| void control_ports_write_to_file | ( | void | ) |
Write all of the open control ports to ControlPortWriteToFile
Definition at line 134 of file control.c.
Referenced by options_act().
|
static |
Check if a control connection has tried to use a known invalid protocol. If it has, then:
Definition at line 397 of file control.c.
Referenced by connection_control_process_inbuf().
|
static |
Return an error on a control connection that tried to use HTTP.
Definition at line 384 of file control.c.
Referenced by control_protocol_is_valid().
|
static |
Return an error on a control connection that tried to use the v0 protocol.
Definition at line 365 of file control.c.
Referenced by control_protocol_is_valid().
| STATIC char * control_split_incoming_command | ( | char * | incoming_cmd, |
| size_t * | data_len, | ||
| char ** | current_cmd_out | ||
| ) |
Helper: take a nul-terminated command of given length, and find where the command starts and the arguments begin. Separate them, allocate a new string in current_cmd_out for the command, and return a pointer to the arguments.
Definition at line 305 of file control.c.
Referenced by connection_control_process_inbuf().
|
static |
Return true iff cmd is allowable (or at least forgivable) at this stage of the protocol.
Definition at line 262 of file control.c.
Referenced by connection_control_process_inbuf().
|
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 221 of file control.c.
Referenced by connection_control_closed(), and owning_controller_procmon_cb().
| void monitor_owning_controller_process | ( | const char * | process_spec | ) |
Set process_spec as Tor's owning controller process. Exit on failure.
Definition at line 573 of file control.c.
Referenced by options_act().
|
static |
Process-termination monitor callback for Tor's owning controller process.
Definition at line 563 of file control.c.
Referenced by monitor_owning_controller_process().
|
static |
Wrapper around peek_buf_has_control0 command: presents the same interface as that underlying functions, but takes a connection_t instead of a buf_t.
Definition at line 287 of file control.c.
Referenced by control_protocol_is_valid().
|
static |
| control_connection_t * TO_CONTROL_CONN | ( | connection_t * | c | ) |
Cast a connection_t * to a control_connection_t *.
Exit with an assertion failure if the input is not a control_connection_t.
Definition at line 71 of file control.c.
Referenced by connection_finished_flushing(), connection_free_(), connection_free_all(), connection_free_minimal(), connection_process_inbuf(), connection_reached_eof(), CONST_TO_CONTROL_CONN(), and queued_events_flush_all().
|
static |
|
static |
|
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 558 of file control.c.
Referenced by monitor_owning_controller_process().
|
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 554 of file control.c.
Referenced by monitor_owning_controller_process().
| const struct signal_name_t signal_table[] |