Tor  0.4.3.0-alpha-dev
Macros | Enumerations | Functions | Variables
config.c File Reference

Code to interpret the user's configuration of Tor. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "lib/confmgt/confmgt.h"
#include "app/config/statefile.h"
#include "app/main/main.h"
#include "app/main/subsysmgr.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
#include "core/mainloop/netstatus.h"
#include "core/or/channel.h"
#include "core/or/circuitlist.h"
#include "core/or/circuitmux.h"
#include "core/or/circuitmux_ewma.h"
#include "core/or/circuitstats.h"
#include "core/or/connection_edge.h"
#include "core/or/dos.h"
#include "core/or/policies.h"
#include "core/or/relay.h"
#include "core/or/scheduler.h"
#include "feature/client/addressmap.h"
#include "feature/client/bridges.h"
#include "feature/client/entrynodes.h"
#include "feature/client/transports.h"
#include "feature/control/control.h"
#include "feature/control/control_auth.h"
#include "feature/control/control_events.h"
#include "feature/dircache/dirserv.h"
#include "feature/hibernate/hibernate.h"
#include "feature/hs/hs_config.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nickname.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
#include "feature/relay/dns.h"
#include "feature/relay/ext_orport.h"
#include "feature/relay/routermode.h"
#include "feature/relay/relay_config.h"
#include "feature/relay/transport_config.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendservice.h"
#include "lib/geoip/geoip.h"
#include "feature/stats/geoip_stats.h"
#include "lib/compress/compress.h"
#include "lib/confmgt/structvar.h"
#include "lib/crypt_ops/crypto_init.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_util.h"
#include "lib/encoding/confline.h"
#include "lib/net/resolve.h"
#include "lib/sandbox/sandbox.h"
#include "lib/version/torversion.h"
#include "lib/crypt_ops/crypto_openssl_mgt.h"
#include "lib/meminfo/meminfo.h"
#include "lib/osinfo/uname.h"
#include "lib/process/daemon.h"
#include "lib/process/pidfile.h"
#include "lib/process/restrict.h"
#include "lib/process/setuid.h"
#include "lib/process/process.h"
#include "lib/net/gethostname.h"
#include "lib/thread/numcpus.h"
#include "lib/encoding/keyval.h"
#include "lib/fs/conffile.h"
#include "lib/evloop/procmon.h"
#include "feature/dirauth/authmode.h"
#include "feature/dirauth/dirauth_config.h"
#include "core/or/connection_st.h"
#include "core/or/port_cfg_st.h"
#include "auth_dirs.inc"
#include "fallback_dirs.inc"
#include "testnet.inc"

Go to the source code of this file.

Macros

#define CONFIG_PRIVATE
 
#define MIN_CONSTRAINED_TCP_BUFFER   2048
 
#define MAX_CONSTRAINED_TCP_BUFFER   262144 /* 256k */
 
#define DOWNLOAD_SCHEDULE(name)   { #name "DownloadSchedule", #name "DownloadInitialDelay", 0, 1 }
 
#define VAR(varname, conftype, member, initvalue)   CONFIG_VAR_ETYPE(or_options_t, varname, conftype, member, 0, initvalue)
 
#define VAR_D(varname, conftype, member, initvalue)   CONFIG_VAR_DEFN(or_options_t, varname, conftype, member, 0, initvalue)
 
#define VAR_NODUMP(varname, conftype, member, initvalue)
 
#define VAR_NODUMP_IMMUTABLE(varname, conftype, member, initvalue)
 
#define VAR_INVIS(varname, conftype, member, initvalue)
 
#define V(member, conftype, initvalue)   VAR(#member, conftype, member, initvalue)
 
#define VAR_IMMUTABLE(varname, conftype, member, initvalue)
 
#define V_IMMUTABLE(member, conftype, initvalue)   VAR_IMMUTABLE(#member, conftype, member, initvalue)
 
#define V_D(member, type, initvalue)   VAR_D(#member, type, member, initvalue)
 
#define OBSOLETE(varname)   CONFIG_VAR_OBSOLETE(varname)
 
#define VPORT(member)
 
#define UINT64_MAX_STRING   "18446744073709551615"
 
#define OR_OPTIONS_MAGIC   9090909
 
#define CHECK_OPTIONS_MAGIC(opt)
 
#define YES_IF_CHANGED_BOOL(opt)   if (!CFG_EQ_BOOL(old_options, new_options, opt)) return 1;
 
#define YES_IF_CHANGED_INT(opt)   if (!CFG_EQ_INT(old_options, new_options, opt)) return 1;
 
#define YES_IF_CHANGED_STRING(opt)   if (!CFG_EQ_STRING(old_options, new_options, opt)) return 1;
 
#define YES_IF_CHANGED_LINELIST(opt)   if (!CFG_EQ_LINELIST(old_options, new_options, opt)) return 1;
 
#define YES_IF_CHANGED_SMARTLIST(opt)   if (!CFG_EQ_SMARTLIST(old_options, new_options, opt)) return 1;
 
#define YES_IF_CHANGED_ROUTERSET(opt)   if (!CFG_EQ_ROUTERSET(old_options, new_options, opt)) return 1;
 
#define MIN_REND_POST_PERIOD   (10*60)
 
#define MIN_REND_POST_PERIOD_TESTING   (5)
 
#define MAX_CIRCS_AVAILABLE_TIME   (24*60*60)
 
#define MAX_DIR_PERIOD   ((7*24*60*60)/2)
 
#define MIN_MAX_CIRCUIT_DIRTINESS   10
 
#define MAX_MAX_CIRCUIT_DIRTINESS   (30*24*60*60)
 
#define MIN_CIRCUIT_STREAM_TIMEOUT   10
 
#define RECOMMENDED_MIN_CIRCUIT_BUILD_TIMEOUT   (10)
 
#define REJECT(arg)   STMT_BEGIN *msg = tor_strdup(arg); return -1; STMT_END
 
#define COMPLAIN(args, ...)   STMT_BEGIN log_warn(LD_CONFIG, args, ##__VA_ARGS__); STMT_END
 
#define CHECK_DEFAULT(arg)
 
#define ONE_GIGABYTE   (UINT64_C(1) << 30)
 
#define ONE_MEGABYTE   (UINT64_C(1) << 20)
 
#define RAM_IS_VERY_LARGE(x)   (0)
 
#define BAD_CHANGE_TO(opt, how)
 
#define SB_NOCHANGE_STR(opt)
 
#define SB_NOCHANGE_LINELIST(opt)
 
#define SB_NOCHANGE_INT(opt)
 
#define GENERATED_FILE_PREFIX
 
#define GENERATED_FILE_COMMENT
 

Enumerations

enum  takes_argument_t { ARGUMENT_NONE = 0, ARGUMENT_NECESSARY = 1, ARGUMENT_OPTIONAL = 2 }
 

Functions

 DUMMY_TYPECHECK_INSTANCE (or_options_t)
 
static int options_check_transition_cb (const void *old, const void *new, char **msg)
 
static int parse_ports (or_options_t *options, int validate_only, char **msg_out, int *n_ports_out, int *world_writable_control_socket)
 
static int validate_data_directories (or_options_t *options)
 
static int write_configuration_file (const char *fname, const or_options_t *options)
 
static void init_libevent (const or_options_t *options)
 
static int opt_streq (const char *s1, const char *s2)
 
static int parse_outbound_addresses (or_options_t *options, int validate_only, char **msg)
 
static void config_maybe_load_geoip_files_ (const or_options_t *options, const or_options_t *old_options)
 
static int options_validate_cb (const void *old_options, void *options, char **msg)
 
static void cleanup_protocol_warning_severity_level (void)
 
static void set_protocol_warning_severity_level (int warning_severity)
 
static void options_clear_cb (const config_mgr_t *mgr, void *opts)
 
static setopt_err_t options_validate_and_set (const or_options_t *old_options, or_options_t *new_options, char **msg_out)
 
STATIC const config_mgr_tget_options_mgr (void)
 
or_options_tget_options_mutable (void)
 
const or_options_tget_options (void)
 
static config_line_tget_options_defaults (void)
 
int set_options (or_options_t *new_val, char **msg)
 
STATIC void or_options_free_ (or_options_t *options)
 
void config_free_all (void)
 
const char * safe_str_client_opts (const or_options_t *options, const char *address)
 
const char * safe_str_opts (const or_options_t *options, const char *address)
 
const char * escaped_safe_str_client (const char *address)
 
const char * escaped_safe_str (const char *address)
 
int get_protocol_warning_severity_level (void)
 
void init_protocol_warning_severity_level (void)
 
STATIC void add_default_trusted_dir_authorities (dirinfo_type_t type)
 
void add_default_fallback_dir_servers (void)
 
static int validate_dir_servers (const or_options_t *options, const or_options_t *old_options)
 
int consider_adding_dir_servers (const or_options_t *options, const or_options_t *old_options)
 
static int check_and_create_data_directory (int create, const char *directory, int group_readable, const char *owner, char **msg_out)
 
int create_keys_directory (const or_options_t *options)
 
STATIC int options_act_reversible (const or_options_t *old_options, char **msg)
 
int options_need_geoip_info (const or_options_t *options, const char **reason_out)
 
static int options_transition_affects_guards (const or_options_t *old_options, const or_options_t *new_options)
 
STATIC int options_act (const or_options_t *old_options)
 
parsed_cmdline_tconfig_parse_commandline (int argc, char **argv, int ignore_errors)
 
void parsed_cmdline_free_ (parsed_cmdline_t *cmdline)
 
int option_is_recognized (const char *key)
 
const char * option_get_canonical_name (const char *key)
 
config_line_toption_get_assignment (const or_options_t *options, const char *key)
 
setopt_err_t options_trial_assign (config_line_t *list, unsigned flags, char **msg)
 
static void print_usage (void)
 
static void list_torrc_options (void)
 
static void list_deprecated_options (void)
 
static void list_enabled_modules (void)
 
uint32_t get_last_resolved_addr (void)
 
void reset_last_resolved_addr (void)
 
int using_default_dir_authorities (const or_options_t *options)
 
int resolve_my_address (int warn_severity, const or_options_t *options, uint32_t *addr_out, const char **method_out, char **hostname_out)
 
int is_local_addr (const tor_addr_t *addr)
 
or_options_toptions_new (void)
 
void options_init (or_options_t *options)
 
char * options_dump (const or_options_t *options, int how_to_dump)
 
static int validate_ports_csv (smartlist_t *sl, const char *name, char **msg)
 
int config_ensure_bandwidth_cap (uint64_t *value, const char *desc, char **msg)
 
static int warn_if_option_path_is_relative (const char *option, const char *filepath)
 
static int warn_about_relative_paths (const or_options_t *options)
 
static int options_validate_scheduler (or_options_t *options, char **msg)
 
STATIC int options_validate_single_onion (or_options_t *options, char **msg)
 
STATIC uint64_t compute_real_max_mem_in_queues (const uint64_t val, int log_guess)
 
static const char * get_default_conf_file (int defaults_file)
 
static char * find_torrc_filename (const config_line_t *cmd_arg, int defaults_file, int *using_default_fname, int *ignore_missing_torrc)
 
static char * load_torrc_from_stdin (void)
 
static char * load_torrc_from_disk (const config_line_t *cmd_arg, int defaults_file)
 
int options_init_from_torrc (int argc, char **argv)
 
setopt_err_t options_init_from_string (const char *cf_defaults, const char *cf, int command, const char *command_arg, char **msg)
 
const char * get_torrc_fname (int defaults_fname)
 
void config_register_addressmaps (const or_options_t *options)
 
int addressmap_register_auto (const char *from, const char *to, time_t expires, addressmap_entry_source_t addrmap_source, const char **msg)
 
STATIC int open_and_add_file_log (const log_severity_list_t *severity, const char *filename, int truncate_log)
 
static int options_init_log_granularity (const or_options_t *options, int validate_only)
 
STATIC int options_init_logs (const or_options_t *old_options, or_options_t *options, int validate_only)
 
static int validate_transport_socks_arguments (const smartlist_t *args)
 
void bridge_line_free_ (bridge_line_t *bridge_line)
 
bridge_line_tparse_bridge_line (const char *line)
 
int pt_parse_transport_line (const or_options_t *options, const char *line, int validate_only, int server)
 
STATIC int parse_dir_authority_line (const char *line, dirinfo_type_t required_type, int validate_only)
 
int parse_dir_fallback_line (const char *line, int validate_only)
 
port_cfg_tport_cfg_new (size_t namelen)
 
void port_cfg_free_ (port_cfg_t *port)
 
static void warn_nonlocal_client_ports (const smartlist_t *ports, const char *portname, const int listener_type)
 
static void warn_nonlocal_controller_ports (smartlist_t *ports, unsigned forbid_nonlocal)
 
int port_cfg_line_extract_addrport (const char *line, char **addrport_out, int *is_unix_out, const char **rest_out)
 
static void warn_client_dns_cache (const char *option, int disabling)
 
int port_parse_config (smartlist_t *out, const config_line_t *ports, const char *portname, int listener_type, const char *defaultaddr, int defaultport, const unsigned flags)
 
int port_count_real_listeners (const smartlist_t *ports, int listenertype, int count_sockets)
 
int port_binds_ipv4 (const port_cfg_t *port)
 
int port_binds_ipv6 (const port_cfg_t *port)
 
const smartlist_tget_configured_ports (void)
 
char * get_first_listener_addrport_string (int listener_type)
 
int get_first_advertised_port_by_type_af (int listener_type, int address_family)
 
const tor_addr_tget_first_advertised_addr_by_type_af (int listener_type, int address_family)
 
int port_exists_by_type_addr_port (int listener_type, const tor_addr_t *addr, int port, int check_wildcard)
 
int port_exists_by_type_addr32h_port (int listener_type, uint32_t addr_ipv4h, int port, int check_wildcard)
 
static char * get_data_directory (const char *val)
 
int options_save_current (void)
 
int get_num_cpus (const or_options_t *options)
 
char * options_get_dir_fname2_suffix (const or_options_t *options, directory_root_t roottype, const char *sub1, const char *sub2, const char *suffix)
 
int check_or_create_data_subdir (const char *subdir)
 
int write_to_data_subdir (const char *subdir, const char *fname, const char *str, const char *descr)
 
int getinfo_helper_config (control_connection_t *conn, const char *question, char **answer, const char **errmsg)
 
static int verify_and_store_outbound_address (sa_family_t family, tor_addr_t *addr, outbound_addr_t type, or_options_t *options, int validate_only)
 
static int parse_outbound_address_lines (const config_line_t *lines, outbound_addr_t type, or_options_t *options, int validate_only, char **msg)
 
static void config_load_geoip_file_ (sa_family_t family, const char *fname, const char *default_fname)
 
int init_cookie_authentication (const char *fname, const char *header, int cookie_len, int group_readable, uint8_t **cookie_out, int *cookie_is_set_out)
 
int options_any_client_port_set (const or_options_t *options)
 

Variables

static const char unix_socket_prefix [] = "unix:"
 
static const char unix_q_socket_prefix [] = "unix:\""
 
static const config_abbrev_t option_abbrevs_ []
 
static const config_var_t option_vars_ []
 
static const char * default_authorities []
 
static const char * default_fallbacks []
 
struct {
   const char *   k
 
   const char *   v
 
testing_tor_network_defaults []
 
static const config_deprecation_t option_deprecation_notes_ []
 
static const config_format_t options_format
 
static or_options_tglobal_options = NULL
 
static or_options_tglobal_default_options = NULL
 
static char * torrc_fname = NULL
 
static char * torrc_defaults_fname = NULL
 
static parsed_cmdline_tglobal_cmdline = NULL
 
static smartlist_tconfigured_ports = NULL
 
static int in_option_validation = 0
 
static int libevent_initialized = 0
 
static config_mgr_toptions_mgr = NULL
 
static bool testing_network_configured = false
 
static atomic_counter_t protocol_warning_severity_level
 
static int have_low_ports = -1
 
struct {
   const char *   name
 
   takes_argument_t   takes_argument
 
   tor_cmdline_mode_t   command
 
   int   quiet
 
CMDLINE_ONLY_OPTIONS []
 
static uint32_t last_resolved_addr = 0
 

Detailed Description

Code to interpret the user's configuration of Tor.

This module handles torrc configuration file, including parsing it, combining it with torrc.defaults and the command line, allowing user changes to it (via editing and SIGHUP or via the control port), writing it back to disk (because of SAVECONF from the control port), and – most importantly, acting on it.

The module additionally has some tools for manipulating and inspecting values that are calculated as a result of the configured options.

How to add new options

To add new items to the torrc, there are a minimum of three places to edit:

Additionally, you might need to edit these places too:

Changing the value of an option

Because of the SAVECONF command from the control port, it's a bad idea to change the value of any user-configured option in the or_options_t. If you want to sometimes do this anyway, we recommend that you create a secondary field in or_options_t; that you have the user option linked only to the secondary field; that you use the secondary field to initialize the one that Tor actually looks at; and that you use the one Tor looks as the one that you modify.

Definition in file config.c.

Macro Definition Documentation

◆ BAD_CHANGE_TO

#define BAD_CHANGE_TO (   opt,
  how 
)
Value:
do { \
*msg = tor_strdup("While Tor is running"how", changing " #opt \
" is not allowed"); \
return -1; \
} while (0)

◆ CHECK_DEFAULT

#define CHECK_DEFAULT (   arg)
Value:
STMT_BEGIN \
if (!config_is_same(get_options_mgr(),options, \
dflt_options,#arg)) { \
or_options_free(dflt_options); \
REJECT(#arg " may only be changed in testing Tor " \
"networks!"); \
} \
STMT_END
STATIC const config_mgr_t * get_options_mgr(void)
Definition: config.c:915
int config_is_same(const config_mgr_t *mgr, const void *o1, const void *o2, const char *name)
Definition: confmgt.c:1067

◆ CHECK_OPTIONS_MAGIC

#define CHECK_OPTIONS_MAGIC (   opt)
Value:
STMT_END
STATIC const config_mgr_t * get_options_mgr(void)
Definition: config.c:915
void config_check_toplevel_magic(const config_mgr_t *mgr, const void *object)
Definition: confmgt.c:347

Definition at line 926 of file config.c.

◆ DOWNLOAD_SCHEDULE

#define DOWNLOAD_SCHEDULE (   name)    { #name "DownloadSchedule", #name "DownloadInitialDelay", 0, 1 }

macro to help with the bulk rename of *DownloadSchedule to *DowloadInitialDelay .

Definition at line 184 of file config.c.

◆ GENERATED_FILE_COMMENT

#define GENERATED_FILE_COMMENT
Value:
"# The old torrc file was renamed " \
"to torrc.orig.1 or similar, and Tor will ignore it"

This string can change; it tries to give the reader an idea that editing this file by hand is not a good plan.

Definition at line 6657 of file config.c.

◆ GENERATED_FILE_PREFIX

#define GENERATED_FILE_PREFIX
Value:
"# This file was generated by Tor; " \
"if you edit it, comments will not be preserved"

This string must remain the same forevermore. It is how we recognize that the torrc file doesn't need to be backed up.

Definition at line 6653 of file config.c.

◆ MAX_CIRCS_AVAILABLE_TIME

#define MAX_CIRCS_AVAILABLE_TIME   (24*60*60)

Highest allowable value for CircuitsAvailableTimeout. If this is too large, client connections will stay open for too long, incurring extra padding overhead.

Definition at line 2895 of file config.c.

◆ MAX_DIR_PERIOD

#define MAX_DIR_PERIOD   ((7*24*60*60)/2)

Highest allowable value for RendPostPeriod.

Definition at line 2898 of file config.c.

◆ MAX_MAX_CIRCUIT_DIRTINESS

#define MAX_MAX_CIRCUIT_DIRTINESS   (30*24*60*60)

Highest allowable value for MaxCircuitDirtiness: prevents time_t overflows.

Definition at line 2906 of file config.c.

◆ MIN_CIRCUIT_STREAM_TIMEOUT

#define MIN_CIRCUIT_STREAM_TIMEOUT   10

Lowest allowable value for CircuitStreamTimeout; if this is too low, Tor will generate too many circuits and potentially overload the network.

Definition at line 2910 of file config.c.

◆ MIN_MAX_CIRCUIT_DIRTINESS

#define MIN_MAX_CIRCUIT_DIRTINESS   10

Lowest allowable value for MaxCircuitDirtiness; if this is too low, Tor will generate too many circuits and potentially overload the network.

Definition at line 2902 of file config.c.

◆ MIN_REND_POST_PERIOD

#define MIN_REND_POST_PERIOD   (10*60)

Lowest allowable value for RendPostPeriod; if this is too low, hidden services can overload the directory system.

Definition at line 2889 of file config.c.

◆ OBSOLETE

#define OBSOLETE (   varname)    CONFIG_VAR_OBSOLETE(varname)

An entry for config_vars: "The option <b>varname</b> is obsolete."

Definition at line 291 of file config.c.

◆ OR_OPTIONS_MAGIC

#define OR_OPTIONS_MAGIC   9090909

Magic value for or_options_t.

Definition at line 867 of file config.c.

◆ RECOMMENDED_MIN_CIRCUIT_BUILD_TIMEOUT

#define RECOMMENDED_MIN_CIRCUIT_BUILD_TIMEOUT   (10)

Lowest recommended value for CircuitBuildTimeout; if it is set too low and LearnCircuitBuildTimeout is off, the failure rate for circuit construction may be very high. In that case, if it is set below this threshold emit a warning.

Definition at line 2917 of file config.c.

◆ SB_NOCHANGE_INT

#define SB_NOCHANGE_INT (   opt)
Value:
if (! CFG_EQ_INT(old, new_val, opt)) \
BAD_CHANGE_TO(opt," with Sandbox active")

◆ SB_NOCHANGE_LINELIST

#define SB_NOCHANGE_LINELIST (   opt)
Value:
if (! CFG_EQ_LINELIST(old, new_val, opt)) \
BAD_CHANGE_TO(opt," with Sandbox active")

◆ SB_NOCHANGE_STR

#define SB_NOCHANGE_STR (   opt)
Value:
if (! CFG_EQ_STRING(old, new_val, opt)) \
BAD_CHANGE_TO(opt," with Sandbox active")

◆ UINT64_MAX_STRING

#define UINT64_MAX_STRING   "18446744073709551615"

UINT64_MAX as a decimal string

Definition at line 306 of file config.c.

◆ V_D

#define V_D (   member,
  type,
  initvalue 
)    VAR_D(#member, type, member, initvalue)

As V, but uses a type definition instead of a type enum

Definition at line 287 of file config.c.

◆ VAR

#define VAR (   varname,
  conftype,
  member,
  initvalue 
)    CONFIG_VAR_ETYPE(or_options_t, varname, conftype, member, 0, initvalue)

An entry for config_vars: "The option varname has type CONFIG_TYPE_conftype, and corresponds to or_options_t.member"

Definition at line 259 of file config.c.

◆ VAR_IMMUTABLE

#define VAR_IMMUTABLE (   varname,
  conftype,
  member,
  initvalue 
)
Value:
CONFIG_VAR_ETYPE(or_options_t, varname, conftype, member, \
CFLG_IMMUTABLE, initvalue)
#define CFLG_IMMUTABLE
Definition: conftypes.h:196
#define CONFIG_VAR_ETYPE(structtype, varname, vartype, membername, varflags, initval)
Definition: confmacros.h:35

Definition at line 279 of file config.c.

◆ VAR_INVIS

#define VAR_INVIS (   varname,
  conftype,
  member,
  initvalue 
)
Value:
CONFIG_VAR_ETYPE(or_options_t, varname, conftype, member, \
#define CFLG_NOSET
Definition: conftypes.h:164
#define CFLG_NOLIST
Definition: conftypes.h:158
#define CFLG_NODUMP
Definition: conftypes.h:151
#define CONFIG_VAR_ETYPE(structtype, varname, vartype, membername, varflags, initval)
Definition: confmacros.h:35

Definition at line 272 of file config.c.

◆ VAR_NODUMP

#define VAR_NODUMP (   varname,
  conftype,
  member,
  initvalue 
)
Value:
CONFIG_VAR_ETYPE(or_options_t, varname, conftype, member, \
CFLG_NODUMP, initvalue)
#define CFLG_NODUMP
Definition: conftypes.h:151
#define CONFIG_VAR_ETYPE(structtype, varname, vartype, membername, varflags, initval)
Definition: confmacros.h:35

Definition at line 266 of file config.c.

◆ VAR_NODUMP_IMMUTABLE

#define VAR_NODUMP_IMMUTABLE (   varname,
  conftype,
  member,
  initvalue 
)
Value:
CONFIG_VAR_ETYPE(or_options_t, varname, conftype, member, \
#define CFLG_IMMUTABLE
Definition: conftypes.h:196
#define CFLG_NODUMP
Definition: conftypes.h:151
#define CONFIG_VAR_ETYPE(structtype, varname, vartype, membername, varflags, initval)
Definition: confmacros.h:35

Definition at line 269 of file config.c.

◆ VPORT

#define VPORT (   member)
Value:
VAR(#member "Lines", LINELIST_V, member ## _lines, NULL), \
VAR(#member, LINELIST_S, member ## _lines, NULL), \
VAR_NODUMP("__" #member, LINELIST_S, member ## _lines, NULL)
#define VAR(varname, conftype, member, initvalue)
Definition: config.c:259

Macro to declare *Port options. Each one comes in three entries. For example, most users should use "SocksPort" to configure the socks port, but TorBrowser wants to use __SocksPort so that it isn't stored by SAVECONF. The SocksPortLines virtual option is used to query both options from the controller.

Definition at line 300 of file config.c.

Enumeration Type Documentation

◆ takes_argument_t

Enumeration to describe the syntax for a command-line option.

Enumerator
ARGUMENT_NONE 

Describe an option that does not take an argument.

ARGUMENT_NECESSARY 

Describes an option that takes a single argument.

ARGUMENT_OPTIONAL 

Describes an option that takes a single optional argument.

Definition at line 2198 of file config.c.

Function Documentation

◆ add_default_fallback_dir_servers()

void add_default_fallback_dir_servers ( void  )

Add the default fallback directory servers into the fallback directory server list.

Definition at line 1227 of file config.c.

◆ add_default_trusted_dir_authorities()

STATIC void add_default_trusted_dir_authorities ( dirinfo_type_t  type)

Add the default directory authorities directly into the trusted dir list, but only add them insofar as they share bits with type. Each authority's bits are restricted to the bits shared with type. If type is ALL_DIRINFO or NO_DIRINFO (zero), add all authorities.

Definition at line 1213 of file config.c.

◆ addressmap_register_auto()

int addressmap_register_auto ( const char *  from,
const char *  to,
time_t  expires,
addressmap_entry_source_t  addrmap_source,
const char **  msg 
)

As addressmap_register(), but detect the wildcarded status of "from" and "to", and do not steal a reference to to.

Definition at line 4697 of file config.c.

◆ bridge_line_free_()

void bridge_line_free_ ( bridge_line_t bridge_line)

Deallocate a bridge_line_t structure.

Definition at line 4965 of file config.c.

◆ check_and_create_data_directory()

static int check_and_create_data_directory ( int  create,
const char *  directory,
int  group_readable,
const char *  owner,
char **  msg_out 
)
static

Make sure that directory exists, with appropriate ownership and permissions (as modified by group_readable). If create, create the directory if it is missing. Return 0 on success. On failure, return -1 and set *msg_out.

Definition at line 1366 of file config.c.

◆ check_or_create_data_subdir()

int check_or_create_data_subdir ( const char *  subdir)

Check wether the data directory has a private subdirectory subdir. If not, try to create it. Return 0 on success, -1 otherwise.

Definition at line 6845 of file config.c.

◆ cleanup_protocol_warning_severity_level()

static void cleanup_protocol_warning_severity_level ( void  )
static

Tear down protocol_warning_severity_level.

Definition at line 1199 of file config.c.

◆ config_ensure_bandwidth_cap()

int config_ensure_bandwidth_cap ( uint64_t *  value,
const char *  desc,
char **  msg 
)

If value exceeds ROUTER_MAX_DECLARED_BANDWIDTH, write a complaint into *msg using string desc, and return -1. Else return 0.

Definition at line 2871 of file config.c.

◆ config_free_all()

void config_free_all ( void  )

Release all memory and resources held by global configuration structures.

Definition at line 1067 of file config.c.

◆ config_load_geoip_file_()

static void config_load_geoip_file_ ( sa_family_t  family,
const char *  fname,
const char *  default_fname 
)
static

Load one of the geoip files, family determining which one. default_fname is used if on Windows and fname equals "<default>".

Definition at line 7073 of file config.c.

Referenced by config_maybe_load_geoip_files_().

◆ config_maybe_load_geoip_files_()

static void config_maybe_load_geoip_files_ ( const or_options_t options,
const or_options_t old_options 
)
static

Load geoip files for IPv4 and IPv6 if options and old_options indicate we should.

Definition at line 7106 of file config.c.

◆ config_parse_commandline()

parsed_cmdline_t* config_parse_commandline ( int  argc,
char **  argv,
int  ignore_errors 
)

Helper: Read a list of configuration options from the command line. If successful, return a newly allocated parsed_cmdline_t; otherwise return NULL.

If ignore_errors is set, try to recover from all recoverable errors and return the best command line we can.

Definition at line 2283 of file config.c.

Referenced by options_init_from_torrc(), and tor_init().

◆ config_register_addressmaps()

void config_register_addressmaps ( const or_options_t options)

Adjust the address map based on the MapAddress elements in the configuration options

Definition at line 4651 of file config.c.

◆ consider_adding_dir_servers()

int consider_adding_dir_servers ( const or_options_t options,
const or_options_t old_options 
)

Look at all the config options and assign new dir authorities as appropriate.

Definition at line 1295 of file config.c.

◆ create_keys_directory()

int create_keys_directory ( const or_options_t options)

Ensure that our keys directory exists, with appropriate permissions. Return 0 on success, -1 on failure.

Definition at line 1403 of file config.c.

◆ DUMMY_TYPECHECK_INSTANCE()

DUMMY_TYPECHECK_INSTANCE ( or_options_t  )

dummy instance of or_options_t, used for type-checking its members with CONF_CHECK_VAR_TYPE.

◆ escaped_safe_str()

const char* escaped_safe_str ( const char *  address)

Equivalent to escaped(safe_str(address)). See reentrancy note on escaped(): don't use this outside the main thread, or twice in the same log statement.

Definition at line 1150 of file config.c.

◆ escaped_safe_str_client()

const char* escaped_safe_str_client ( const char *  address)

Equivalent to escaped(safe_str_client(address)). See reentrancy note on escaped(): don't use this outside the main thread, or twice in the same log statement.

Definition at line 1138 of file config.c.

◆ find_torrc_filename()

static char* find_torrc_filename ( const config_line_t cmd_arg,
int  defaults_file,
int *  using_default_fname,
int *  ignore_missing_torrc 
)
static

Learn config file name from command line arguments, or use the default.

If defaults_file is true, we're looking for torrc-defaults; otherwise, we're looking for the regular torrc_file.

Set *using_default_fname to true if we're using the default configuration file name; or false if we've set it from the command line.

Set *ignore_missing_torrc to true if we should ignore the resulting filename if it doesn't exist.

Definition at line 4191 of file config.c.

Referenced by load_torrc_from_disk().

◆ get_configured_ports()

const smartlist_t* get_configured_ports ( void  )

Return a list of port_cfg_t for client ports parsed from the options.

Definition at line 6403 of file config.c.

Referenced by get_first_advertised_port_by_type_af(), policies_parse_exit_policy_reject_private(), and proxy_mode().

◆ get_data_directory()

static char* get_data_directory ( const char *  val)
static

Allocate and return a good value for the DataDirectory based on val, which may be NULL. Return NULL on failure.

Definition at line 6576 of file config.c.

Referenced by validate_data_directories().

◆ get_default_conf_file()

static const char* get_default_conf_file ( int  defaults_file)
static

Return the default location for our torrc file (if defaults_file is false), or for the torrc-defaults file (if defaults_file is true).

Definition at line 4157 of file config.c.

Referenced by get_torrc_fname().

◆ get_first_advertised_addr_by_type_af()

const tor_addr_t* get_first_advertised_addr_by_type_af ( int  listener_type,
int  address_family 
)

Return the first advertised address of type listener_type in address_family. Returns NULL if there is no advertised address, and when passed AF_UNSPEC.

Definition at line 6496 of file config.c.

◆ get_first_advertised_port_by_type_af()

int get_first_advertised_port_by_type_af ( int  listener_type,
int  address_family 
)

Return the first advertised port of type listener_type in address_family. Returns 0 when no port is found, and when passed AF_UNSPEC.

Definition at line 6474 of file config.c.

Referenced by router_get_advertised_or_port_by_af().

◆ get_first_listener_addrport_string()

char* get_first_listener_addrport_string ( int  listener_type)

Return an address:port string representation of the address where the first listener_type listener waits for connections. Return NULL if we couldn't find a listener. The string is allocated on the heap and it's the responsibility of the caller to free it after use.

This function is meant to be used by the pluggable transport proxy spawning code, please make sure that it fits your purposes before using it.

Definition at line 6420 of file config.c.

◆ get_last_resolved_addr()

uint32_t get_last_resolved_addr ( void  )

Accessor for last_resolved_addr from outside this file.

Definition at line 2495 of file config.c.

Referenced by router_pick_published_address().

◆ get_num_cpus()

int get_num_cpus ( const or_options_t options)

Return the number of cpus configured in options. If we are told to auto-detect the number of cpus, return the auto-detected number.

Definition at line 6753 of file config.c.

Referenced by init_libevent().

◆ get_options()

const or_options_t* get_options ( void  )

Returns the currently configured options

Definition at line 941 of file config.c.

Referenced by add_wildcarded_test_address(), address_is_invalid_destination(), assert_identity_keys_ok(), authdir_policy_badexit_address(), authdir_policy_permits_address(), authdir_policy_valid_address(), channelpadding_decide_to_pad_channel(), channelpadding_get_channel_idle_timeout(), channelpadding_get_circuits_available_timeout(), check_descriptor_ipaddress_changed(), choose_good_entry_server(), choose_good_exit_server(), choose_good_exit_server_general(), choose_good_middle_server(), circpad_is_padding_allowed(), circpad_machine_conditions_met(), circuit_all_predicted_ports_handled(), circuit_build_needed_circs(), circuit_build_no_more_hops(), circuit_build_times_count_close(), circuit_build_times_count_timeout(), circuit_build_times_get_initial_timeout(), circuit_build_times_handle_completed_hop(), circuit_build_times_init(), circuit_build_times_new_consensus_params(), circuit_build_times_parse_state(), circuit_build_times_set_timeout(), circuit_expire_building(), circuit_expire_old_circs_as_needed(), circuit_expire_old_circuits_clientside(), circuit_find_to_cannibalize(), circuit_get_open_circ_or_launch(), circuit_handle_first_hop(), circuit_is_acceptable(), circuit_log_ancient_one_hop_circuits(), circuit_note_clock_jumped(), circuit_should_use_vanguards(), circuit_stream_is_being_handled(), circuit_testing_failed(), circuit_testing_opened(), client_get_random_intro(), command_process_create_cell(), command_process_relay_cell(), compare_tor_addr_to_short_policy(), compute_retry_timeout(), config_load_geoip_file_(), configure_nameservers(), conn_get_proxy_type(), connection_ap_can_use_exit(), connection_ap_expire_beginning(), connection_ap_get_original_destination(), connection_ap_handshake_attach_circuit(), connection_ap_handshake_process_socks(), connection_ap_handshake_rewrite_and_attach(), connection_ap_handshake_send_begin(), connection_ap_rewrite_and_attach_if_allowed(), connection_bucket_init(), connection_check_oos(), connection_connect_sockaddr(), connection_dir_client_request_failed(), connection_exit_begin_conn(), connection_finished_connecting(), connection_is_rate_limited(), connection_listener_new_for_port(), connection_or_check_valid_tls_handshake(), connection_or_client_learned_peer_id(), connection_or_connect(), consider_hibernation(), consider_plaintext_ports(), consider_publishable_server(), consider_recording_trackhost(), control_event_circuit_cell_stats(), control_event_conn_bandwidth(), control_event_conn_bandwidth_used(), control_ports_write_to_file(), count_loading_descriptors_progress(), create_managed_proxy_environment(), decide_if_publishable_server(), dir_routerdesc_download_failed(), dirauth_set_routerstatus_from_routerinfo(), directory_get_from_dirserver(), directory_handle_command_post(), directory_info_has_arrived(), dirserv_add_descriptor(), dirserv_compute_performance_thresholds(), dirserv_generate_networkstatus_vote_obj(), dirserv_get_credible_bandwidth_kb(), dirserv_get_flag_thresholds_line(), dirserv_orconn_tls_done(), dirserv_router_get_status(), dirserv_router_has_valid_address(), dirserv_set_router_is_running(), dirserv_set_routerstatus_testing(), dirserv_should_launch_reachability_test(), dirserv_single_reachability_test(), dirserv_test_reachability(), dirserv_thinks_router_is_hs_dir(), dirvote_get_preferred_voting_intervals(), dns_init(), dns_launch_correctness_checks(), dns_reset(), dns_servers_relaunch_checks(), do_dump_config(), do_hash_password(), do_hup(), entry_guards_changed_for_guard_selection(), entry_guards_expand_sample(), entry_guards_update_filtered_sets(), entry_guards_update_state(), escaped_safe_str(), escaped_safe_str_client(), evdns_log_cb(), extrainfo_dump_to_string_stats_helper(), fascist_firewall_allows_address(), fascist_firewall_allows_rs(), fascist_firewall_choose_address_rs(), fetch_networkstatus_callback(), geoip_note_client_seen(), geoip_note_ns_response(), get_accounting_bytes(), get_bridge_dl_status_by_id(), get_controller_cookie_file_name(), get_ext_or_auth_cookie_file_name(), get_guard_confirmed_min_lifetime(), get_guard_lifetime(), get_intro_point_max_lifetime(), get_intro_point_min_lifetime(), get_max_age_to_cache(), get_n_primary_guards(), get_possible_sybil_list(), get_proxy_addrport(), get_pt_proxy_uri(), get_start_time_of_current_round(), get_time_period_length(), get_voting_interval(), getinfo_helper_events(), guard_in_node_family(), guards_update_all(), handle_control_authenticate(), handle_control_getconf(), handle_control_saveconf(), handle_get_descriptor(), handle_get_networkstatus_bridges(), handle_signals(), hibernate_begin(), hibernate_hard_limit_reached(), hibernate_soft_limit_reached(), hs_clean_last_hid_serv_requests(), hs_dos_consensus_has_changed(), hs_pick_hsdir(), hs_service_add_ephemeral(), hs_service_map_has_changed(), hs_service_requires_uptime_circ(), init_keys(), init_v3_authority_keys(), ip_address_changed(), is_test_address(), launch_descriptor_downloads(), launch_direct_bridge_descriptor_fetch(), launch_one_resolve(), launch_test_addresses(), learned_bridge_descriptor(), list_bridge_identities(), load_service_keys(), log_cert_expiration(), log_heartbeat(), mark_circuit_unusable_for_new_conns(), mark_my_descriptor_dirty(), my_exit_policy_rejects(), net_is_completely_disabled(), net_is_disabled(), netstatus_load_from_state(), networkstatus_get_latest_consensus(), networkstatus_set_current_consensus(), node_has_preferred_descriptor(), node_ipv6_dir_preferred(), node_ipv6_or_preferred(), nodelist_add_node_and_family(), nodelist_set_consensus(), nodelist_set_routerinfo(), nodes_in_same_family(), on_hibernate_state_change(), optimistic_data_enabled(), options_act_bridge_stats(), options_act_dirauth(), options_act_dirauth_mtbf(), options_act_relay(), options_act_relay_accounting(), options_act_relay_bandwidth(), options_act_relay_desc(), options_act_relay_dir(), options_act_relay_dos(), options_act_server_transport(), options_save_current(), options_trial_assign(), parse_reachable_addresses(), pathbias_check_close_success_count(), pathbias_check_use_success_count(), pathbias_measure_close_rate(), pathbias_measure_use_rate(), pathbias_scale_close_rates(), pathbias_scale_use_rates(), periodic_event_dispatch(), pick_intro_point(), pt_get_bindaddr_from_config(), pt_get_extra_info_descriptor_string(), pt_get_options_for_server_transport(), pubsub_connect(), purpose_needs_anonymity(), record_num_bytes_transferred_impl(), refresh_all_country_info(), rend_cache_store_v2_desc_as_dir(), rend_client_any_intro_points_usable(), rend_client_get_random_intro_impl(), rend_client_introduction_acked(), rend_client_send_introduction(), rend_consider_descriptor_republication(), rend_consider_services_intro_points(), rend_consider_services_upload(), rend_mid_rendezvous(), rend_service_launch_establish_intro(), rend_service_load_keys(), rep_hist_circbuilding_dormant(), rep_hist_dump_stats(), rep_hist_fill_bandwidth_history(), rep_history_clean(), rescan_periodic_events_cb(), retry_all_listeners(), rewrite_node_address_for_bridge(), route_len_for_purpose(), router_add_to_routerlist(), router_build_fresh_unsigned_extrainfo(), router_build_fresh_unsigned_routerinfo(), router_compare_to_my_exit_policy(), router_counts_toward_thresholds(), router_dirport_found_reachable(), router_do_reachability_checks(), router_find_exact_exit_enclave(), router_get_my_extrainfo(), router_get_my_routerinfo_with_err(), router_have_minimum_dir_info(), router_initialize_tls_context(), router_is_active(), router_new_address_suggestion(), router_orport_found_reachable(), router_perform_bandwidth_test(), router_rebuild_descriptor(), router_should_be_dirserver(), router_should_check_reachability(), router_upload_dir_desc_to_dirservers(), router_write_fingerprint(), routerparse_init(), routers_update_status_from_consensus_networkstatus(), safe_str_client_opts(), safe_str_opts(), select_scheduler(), server_identity_key_is_set(), should_apply_guardfraction(), should_use_create_fast_for_circuit(), signewnym_impl(), sr_act_post_consensus(), sr_get_string_for_consensus(), sr_get_string_for_vote(), tor_cleanup(), update_all_descriptor_downloads(), update_consensus_networkstatus_downloads(), update_consensus_networkstatus_fetch_time(), update_consensus_networkstatus_fetch_time_impl(), update_consensus_router_descriptor_downloads(), update_expected_bandwidth(), update_extrainfo_downloads(), update_microdesc_downloads(), update_networkstatus_downloads(), update_router_descriptor_downloads(), update_router_have_minimum_dir_info(), update_send_buffer_size(), upload_descriptor_to_hsdir(), upload_service_descriptor(), usable_consensus_flavor(), and warn_if_last_router_excluded().

◆ get_options_defaults()

static config_line_t* get_options_defaults ( void  )
static

Return a set of lines for any default options that we want to override from those set in our config_var_t values.

Definition at line 955 of file config.c.

Referenced by options_init().

◆ get_options_mgr()

STATIC const config_mgr_t* get_options_mgr ( void  )

◆ get_options_mutable()

or_options_t* get_options_mutable ( void  )

Returns the currently configured options.

Definition at line 932 of file config.c.

Referenced by get_options(), options_act(), and options_act_reversible().

◆ get_protocol_warning_severity_level()

int get_protocol_warning_severity_level ( void  )

Return the severity level that should be used for warnings of severity LOG_PROTOCOL_WARN.

Definition at line 1171 of file config.c.

◆ get_torrc_fname()

const char* get_torrc_fname ( int  defaults_fname)

Return the location for our configuration file. May return NULL.

Definition at line 4637 of file config.c.

Referenced by options_save_current().

◆ getinfo_helper_config()

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

Helper to implement GETINFO functions about configuration variables (not their values). Given a "config/names" question, set *answer to a new string describing the supported configuration variables and their types.

Definition at line 6883 of file config.c.

◆ init_cookie_authentication()

int init_cookie_authentication ( const char *  fname,
const char *  header,
int  cookie_len,
int  group_readable,
uint8_t **  cookie_out,
int *  cookie_is_set_out 
)

Initialize cookie authentication (used so far by the ControlPort and Extended ORPort).

Allocate memory and create a cookie (of length cookie_len) in cookie_out. Then write it down to fname and prepend it with header.

If group_readable is set, set fname to be readable by the default GID.

If the whole procedure was successful, set cookie_is_set_out to True.

Definition at line 7142 of file config.c.

◆ init_libevent()

static void init_libevent ( const or_options_t options)
static

Initialize the libevent library.

Definition at line 6767 of file config.c.

◆ init_protocol_warning_severity_level()

void init_protocol_warning_severity_level ( void  )

Initialize the log warning severity level for protocol warnings. Call only once at startup.

Definition at line 1189 of file config.c.

Referenced by tor_run_main().

◆ is_local_addr()

int is_local_addr ( const tor_addr_t addr)

Return true iff addr is judged to be on the same network as us, or on a private network.

Definition at line 2762 of file config.c.

◆ list_deprecated_options()

static void list_deprecated_options ( void  )
static

Print all deprecated but non-obsolete torrc options.

Definition at line 2472 of file config.c.

Referenced by options_init_from_torrc().

◆ list_enabled_modules()

static void list_enabled_modules ( void  )
static

Print all compile-time modules and their enabled/disabled status.

Definition at line 2484 of file config.c.

Referenced by options_init_from_torrc().

◆ list_torrc_options()

static void list_torrc_options ( void  )
static

Print all non-obsolete torrc options.

Definition at line 2454 of file config.c.

Referenced by options_init_from_torrc().

◆ load_torrc_from_disk()

static char* load_torrc_from_disk ( const config_line_t cmd_arg,
int  defaults_file 
)
static

Load a configuration file from disk, setting torrc_fname or torrc_defaults_fname if successful.

If defaults_file is true, load torrc-defaults; otherwise load torrc.

Return the contents of the file on success, and NULL on failure.

Definition at line 4275 of file config.c.

◆ load_torrc_from_stdin()

static char* load_torrc_from_stdin ( void  )
static

Read the torrc from standard input and return it as a string. Upon failure, return NULL.

Definition at line 4260 of file config.c.

◆ open_and_add_file_log()

STATIC int open_and_add_file_log ( const log_severity_list_t severity,
const char *  filename,
int  truncate_log 
)

As add_file_log, but open the file as appropriate.

Definition at line 4741 of file config.c.

◆ opt_streq()

static int opt_streq ( const char *  s1,
const char *  s2 
)
static

Helper: return true iff s1 and s2 are both NULL, or both non-NULL equal strings.

Definition at line 4033 of file config.c.

Referenced by config_maybe_load_geoip_files_().

◆ option_get_assignment()

config_line_t* option_get_assignment ( const or_options_t options,
const char *  key 
)

Return a canonical list of the options assigned for key.

Definition at line 2409 of file config.c.

Referenced by handle_control_getconf().

◆ option_get_canonical_name()

const char* option_get_canonical_name ( const char *  key)

Return the canonical name of a configuration option, or NULL if no such option exists.

Definition at line 2401 of file config.c.

Referenced by handle_control_getconf().

◆ option_is_recognized()

int option_is_recognized ( const char *  key)

Return true iff key is a valid configuration option.

Definition at line 2393 of file config.c.

Referenced by handle_control_getconf().

◆ options_act()

STATIC int options_act ( const or_options_t old_options)

Fetch the active option list, and take actions based on it. All of the things we do should survive being done repeatedly. If present, old_options contains the previous value of the options.

Return 0 if all goes well, return -1 if it's time to die.

Note: We haven't moved all the "act on new configuration" logic the options_act* functions yet. Some is still in do_hup() and other places.

Definition at line 1812 of file config.c.

Referenced by set_options().

◆ options_act_reversible()

STATIC int options_act_reversible ( const or_options_t old_options,
char **  msg 
)

Fetch the active option list, and take actions based on it. All of the things we do should survive being done repeatedly. If present, old_options contains the previous value of the options.

Return 0 if all goes well, return -1 if things went badly.

Definition at line 1432 of file config.c.

Referenced by set_options().

◆ options_any_client_port_set()

int options_any_client_port_set ( const or_options_t options)

Return true if any option is set in options to make us behave as a client.

Definition at line 7201 of file config.c.

Referenced by handle_missing_protocol_warning().

◆ options_check_transition_cb()

static int options_check_transition_cb ( const void *  old_,
const void *  new_val_,
char **  msg 
)
static

Check if any config options have changed but aren't allowed to.

Definition at line 4040 of file config.c.

◆ options_clear_cb()

static void options_clear_cb ( const config_mgr_t mgr,
void *  opts 
)
static

Release additional memory allocated in options

Definition at line 1027 of file config.c.

◆ options_dump()

char* options_dump ( const or_options_t options,
int  how_to_dump 
)

Return a string containing a possible configuration file that would give the configuration in options. If minimal is true, do not include options that are the same as Tor's defaults.

Definition at line 2818 of file config.c.

◆ options_get_dir_fname2_suffix()

char* options_get_dir_fname2_suffix ( const or_options_t options,
directory_root_t  roottype,
const char *  sub1,
const char *  sub2,
const char *  suffix 
)

Return a newly allocated string holding a filename relative to the directory in options specified by roottype. If sub1 is present, it is the first path component after the data directory. If sub2 is also present, it is the second path component after the data directory. If suffix is present, it is appended to the filename.

Note: Consider using macros in config.h that wrap this function; you should probably never need to call it as-is.

Definition at line 6802 of file config.c.

◆ options_init()

void options_init ( or_options_t options)

Set options to hold reasonable defaults for most options. Each option defaults to zero.

Definition at line 2798 of file config.c.

◆ options_init_from_string()

setopt_err_t options_init_from_string ( const char *  cf_defaults,
const char *  cf,
int  command,
const char *  command_arg,
char **  msg 
)

Load the options from the configuration in cf, validate them for consistency and take actions based on them.

Return 0 if success, negative on error:

  • -1 for general errors.
  • -2 for failure to parse/validate,
  • -3 for transition not allowed
  • -4 for error while setting the new options

Definition at line 4527 of file config.c.

Referenced by handle_control_loadconf().

◆ options_init_from_torrc()

int options_init_from_torrc ( int  argc,
char **  argv 
)

Read a configuration file into options, finding the configuration file location based on the command line. After loading the file call options_init_from_string() to load the config. Return 0 if success, -1 if failure, and 1 if we succeeded but should exit anyway.

Definition at line 4327 of file config.c.

◆ options_init_log_granularity()

static int options_init_log_granularity ( const or_options_t options,
int  validate_only 
)
static

Try to set our global log granularity from options->LogGranularity, adjusting it as needed so that we are an even divisor of a second, or an even multiple of seconds. Return 0 on success, -1 on failure.

Definition at line 4760 of file config.c.

Referenced by options_init_logs().

◆ options_init_logs()

STATIC int options_init_logs ( const or_options_t old_options,
or_options_t options,
int  validate_only 
)

Initialize the logs based on the configuration file.

Definition at line 4799 of file config.c.

◆ options_need_geoip_info()

int options_need_geoip_info ( const or_options_t options,
const char **  reason_out 
)

If we need to have a GEOIP ip-to-country map to run with our configured options, return 1 and set *reason_out to a description of why.

Definition at line 1735 of file config.c.

Referenced by config_load_geoip_file_().

◆ options_new()

or_options_t* options_new ( void  )

Return a new empty or_options_t. Used for testing.

Definition at line 2788 of file config.c.

◆ options_save_current()

int options_save_current ( void  )

Save the current configuration file value to disk. Return 0 on success, -1 on failure.

Definition at line 6740 of file config.c.

Referenced by handle_control_saveconf().

◆ options_transition_affects_guards()

static int options_transition_affects_guards ( const or_options_t old_options,
const or_options_t new_options 
)
static

Return true if changing the configuration from old to new affects the guard subsystem.

Definition at line 1778 of file config.c.

Referenced by options_act().

◆ options_trial_assign()

setopt_err_t options_trial_assign ( config_line_t list,
unsigned  flags,
char **  msg 
)

Try assigning list to the global options. You do this by duping options, assigning list to the new one, then validating it. If it's ok, then throw out the old one and stick with the new one. Else, revert to old and return failure. Return SETOPT_OK on success, or a setopt_err_t on failure.

If not success, point *msg to a newly allocated string describing what went wrong.

Definition at line 2424 of file config.c.

Referenced by control_setconf_helper().

◆ options_validate_and_set()

static setopt_err_t options_validate_and_set ( const or_options_t old_options,
or_options_t new_options,
char **  msg_out 
)
static

Validate new_options. If it is valid, and it is a reasonable replacement for old_options, replace the previous value of the global options, and return return SETOPT_OK.

If it is not valid, then free new_options, set *msg_out to a newly allocated error message, and return an error code.

Definition at line 2928 of file config.c.

Referenced by options_trial_assign().

◆ options_validate_cb()

static int options_validate_cb ( const void *  old_options_,
void *  options_,
char **  msg 
)
static

Legacy validation/normalization callback for or_options_t. See legacy_validate_fn_t for more information.

Definition at line 3164 of file config.c.

◆ or_options_free_()

STATIC void or_options_free_ ( or_options_t options)

Release all memory allocated in options

Definition at line 1059 of file config.c.

◆ parse_bridge_line()

bridge_line_t* parse_bridge_line ( const char *  line)

Parse the contents of a string, line, containing a Bridge line, into a bridge_line_t.

Validates that the IP:PORT, fingerprint, and SOCKS arguments (given to the Pluggable Transport, if a one was specified) are well-formed.

Returns NULL If the Bridge line could not be validated, and returns a bridge_line_t containing the parsed information otherwise.

Bridge line format: Bridge [transport] IP:PORT [id-fingerprint] [k=v] [k=v] ...

Definition at line 4991 of file config.c.

◆ parse_dir_authority_line()

STATIC int parse_dir_authority_line ( const char *  line,
dirinfo_type_t  required_type,
int  validate_only 
)

Read the contents of a DirAuthority line from line. If validate_only is 0, and the line is well-formed, and it shares any bits with required_type or required_type is NO_DIRINFO (zero), then add the dirserver described in the line (minus whatever bits it's missing) as a valid authority. Return 0 on success or filtering out by type, or -1 if the line isn't well-formed or if we can't add it.

Definition at line 5309 of file config.c.

◆ parse_dir_fallback_line()

int parse_dir_fallback_line ( const char *  line,
int  validate_only 
)

Read the contents of a FallbackDir line from line. If validate_only is 0, and the line is well-formed, then add the dirserver described in the line as a fallback directory. Return 0 on success, or -1 if the line isn't well-formed or if we can't add it.

Definition at line 5467 of file config.c.

Referenced by add_default_fallback_dir_servers().

◆ parse_outbound_addresses()

static int parse_outbound_addresses ( or_options_t options,
int  validate_only,
char **  msg 
)
static

Parse outbound bind address option lines. If validate_only is not 0 update OutboundBindAddresses in options. Only one address can be set for any of these values. On failure, set msg (if provided) to a newly allocated string containing a description of the problem and return -1.

Definition at line 7039 of file config.c.

◆ parse_ports()

static int parse_ports ( or_options_t options,
int  validate_only,
char **  msg,
int *  n_ports_out,
int *  world_writable_control_socket 
)
static

Parse all ports from options. On success, set *n_ports_out to the number of ports that are listed, update the *Port_set values in options, and return 0. On failure, set *msg to a description of the problem and return -1.

If validate_only is false, set configured_client_ports to the new list of ports parsed from options.

Definition at line 6246 of file config.c.

◆ parsed_cmdline_free_()

void parsed_cmdline_free_ ( parsed_cmdline_t cmdline)

Release all storage held by cmdline.

Definition at line 2382 of file config.c.

◆ port_cfg_free_()

void port_cfg_free_ ( port_cfg_t port)

Free all storage held in port

Definition at line 5587 of file config.c.

◆ port_cfg_line_extract_addrport()

int port_cfg_line_extract_addrport ( const char *  line,
char **  addrport_out,
int *  is_unix_out,
const char **  rest_out 
)

Take a string (line) that begins with either an address:port, a port, or an AF_UNIX address, optionally quoted, prefixed with "unix:". Parse that line, and on success, set addrport_out to a new string containing the beginning portion (without prefix). Iff there was a unix: prefix, set is_unix_out to true. On success, also set rest_out to point to the part of the line after the address portion.

Return 0 on success, -1 on failure.

Definition at line 5673 of file config.c.

◆ port_cfg_new()

port_cfg_t* port_cfg_new ( size_t  namelen)

Allocate and return a new port_cfg_t with reasonable defaults.

Definition at line 5573 of file config.c.

◆ port_count_real_listeners()

int port_count_real_listeners ( const smartlist_t ports,
int  listenertype,
int  count_sockets 
)

Return the number of ports which are actually going to listen with type listenertype. Do not count no_listen ports. Only count unix sockets if count_sockets is true.

Definition at line 6221 of file config.c.

◆ port_exists_by_type_addr_port()

int port_exists_by_type_addr_port ( int  listener_type,
const tor_addr_t addr,
int  port,
int  check_wildcard 
)

Return 1 if a port exists of type listener_type on addr and port. If check_wildcard is true, INADDR[6]_ANY and AF_UNSPEC addresses match any address of the appropriate family; and port -1 matches any port. To match auto ports, pass CFG_PORT_AUTO. (Does not match on the actual automatically chosen listener ports.)

Definition at line 6521 of file config.c.

◆ port_parse_config()

int port_parse_config ( smartlist_t out,
const config_line_t ports,
const char *  portname,
int  listener_type,
const char *  defaultaddr,
int  defaultport,
const unsigned  flags 
)

Parse port configuration for a single port type.

Read entries of the "FooPort" type from the list ports. Syntax is that FooPort can have any number of entries of the format "[Address:][Port] IsolationOptions".

In log messages, describe the port type as portname.

If no address is specified, default to defaultaddr. If no FooPort is given, default to defaultport (if 0, there is no default).

If CL_PORT_NO_STREAM_OPTIONS is set in flags, do not allow stream isolation options in the FooPort entries.

If CL_PORT_WARN_NONLOCAL is set in flags, warn if any of the ports are not on a local address. If CL_PORT_FORBID_NONLOCAL is set, this is a control port with no password set: don't even allow it.

If CL_PORT_SERVER_OPTIONS is set in flags, do not allow stream isolation options in the FooPort entries; instead allow the server-port option set.

If CL_PORT_TAKES_HOSTNAMES is set in flags, allow the options {No,}IPv{4,6}Traffic.

On success, if out is given, add a new port_cfg_t entry to out for every port that the client should listen on. Return 0 on success, -1 on failure.

Definition at line 5763 of file config.c.

◆ print_usage()

static void print_usage ( void  )
static

Print a usage message for tor.

Definition at line 2441 of file config.c.

Referenced by options_init_from_torrc().

◆ pt_parse_transport_line()

int pt_parse_transport_line ( const or_options_t options,
const char *  line,
int  validate_only,
int  server 
)

Read the contents of a ClientTransportPlugin or ServerTransportPlugin line from line, depending on the value of server. Return 0 if the line is well-formed, and -1 if it isn't.

If validate_only is 0, the line is well-formed, and the transport is needed by some bridge:

  • If it's an external proxy line, add the transport described in the line to our internal transport list.
  • If it's a managed proxy line, launch the managed proxy.

Definition at line 5108 of file config.c.

◆ reset_last_resolved_addr()

void reset_last_resolved_addr ( void  )

Reset last_resolved_addr from outside this file.

Definition at line 2502 of file config.c.

◆ resolve_my_address()

int resolve_my_address ( int  warn_severity,
const or_options_t options,
uint32_t *  addr_out,
const char **  method_out,
char **  hostname_out 
)

Attempt getting our non-local (as judged by tor_addr_is_internal() function) IP address using following techniques, listed in order from best (most desirable, try first) to worst (least desirable, try if everything else fails).

First, attempt using options->Address to get our non-local IP address.

If options->Address represents a non-local IP address, consider it ours.

If options->Address is a DNS name that resolves to a non-local IP address, consider this IP address ours.

If options->Address is NULL, fall back to getting local hostname and using it in above-described ways to try and get our IP address.

In case local hostname cannot be resolved to a non-local IP address, try getting an IP address of network interface in hopes it will be non-local one.

Fail if one or more of the following is true:

  • DNS name in options->Address cannot be resolved.
  • options->Address is a local host address.
  • Attempt at getting local hostname fails.
  • Attempt at getting network interface address fails.

Return 0 if all is well, or -1 if we can't find a suitable public IP address.

If we are returning 0:

  • Put our public IP address (in host order) into *addr_out.
  • If method_out is non-NULL, set *method_out to a static string describing how we arrived at our answer.
    • "CONFIGURED" - parsed from IP address string in options->Address
    • "RESOLVED" - resolved from DNS name in options->Address
    • "GETHOSTNAME" - resolved from a local hostname.
    • "INTERFACE" - retrieved from a network interface.
  • If hostname_out is non-NULL, and we resolved a hostname to get our address, set *hostname_out to a newly allocated string holding that hostname. (If we didn't get our address by resolving a hostname, set *hostname_out to NULL.)

XXXX ipv6

Definition at line 2564 of file config.c.

Referenced by router_pick_published_address().

◆ safe_str_client_opts()

const char* safe_str_client_opts ( const or_options_t options,
const char *  address 
)

Make address – a piece of information related to our operation as a client – safe to log according to the settings in options->SafeLogging, and return it.

(We return "[scrubbed]" if SafeLogging is "1", and address otherwise.)

Definition at line 1100 of file config.c.

◆ safe_str_opts()

const char* safe_str_opts ( const or_options_t options,
const char *  address 
)

Make address – a piece of information of unspecified sensitivity – safe to log according to the settings in options->SafeLogging, and return it.

(We return "[scrubbed]" if SafeLogging is anything besides "0", and address otherwise.)

Definition at line 1121 of file config.c.

◆ set_options()

int set_options ( or_options_t new_val,
char **  msg 
)

Change the current global options to contain new_val instead of their current value; take action based on the new value; free the old value as necessary. Returns 0 on success, -1 on failure.

Definition at line 977 of file config.c.

◆ set_protocol_warning_severity_level()

static void set_protocol_warning_severity_level ( int  warning_severity)
static

Set the protocol warning severity level to severity.

Definition at line 1178 of file config.c.

Referenced by init_protocol_warning_severity_level().

◆ validate_data_directories()

static int validate_data_directories ( or_options_t options)
static

Check and normalize the values of options->{Key,Data,Cache}Directory; return 0 if it is sane, -1 otherwise.

Definition at line 6615 of file config.c.

◆ validate_dir_servers()

static int validate_dir_servers ( const or_options_t options,
const or_options_t old_options 
)
static

Look at all the config options for using alternate directory authorities, and make sure none of them are broken. Also, warn the user if we changed any dangerous ones.

Definition at line 1243 of file config.c.

◆ validate_ports_csv()

static int validate_ports_csv ( smartlist_t sl,
const char *  name,
char **  msg 
)
static

Return 0 if every element of sl is a string holding a decimal representation of a port number, or if sl is NULL. Otherwise set *msg and return -1.

Definition at line 2847 of file config.c.

◆ validate_transport_socks_arguments()

static int validate_transport_socks_arguments ( const smartlist_t args)
static

Given a smartlist of SOCKS arguments to be passed to a transport proxy in args, validate them and return -1 if they are corrupted. Return 0 if they seem OK.

Definition at line 4931 of file config.c.

◆ warn_about_relative_paths()

static int warn_about_relative_paths ( const or_options_t options)
static

Scan options for occurrences of relative file/directory paths and log a warning whenever one is found.

Return 1 if there were relative paths; 0 otherwise.

Definition at line 3019 of file config.c.

◆ warn_if_option_path_is_relative()

static int warn_if_option_path_is_relative ( const char *  option,
const char *  filepath 
)
static

Log a warning message iff filepath is not absolute. Warning message must contain option name option and an absolute path that filepath will resolve to.

In case filepath is absolute, do nothing.

Return 1 if there were relative paths; 0 otherwise.

Definition at line 3000 of file config.c.

Referenced by warn_about_relative_paths().

◆ warn_nonlocal_client_ports()

static void warn_nonlocal_client_ports ( const smartlist_t ports,
const char *  portname,
const int  listener_type 
)
static

Warn for every port in ports of type listener_type that is on a publicly routable address.

Definition at line 5595 of file config.c.

◆ warn_nonlocal_controller_ports()

static void warn_nonlocal_controller_ports ( smartlist_t ports,
unsigned  forbid_nonlocal 
)
static

Given a list of port_cfg_t in ports, warn if any controller port there is listening on any non-loopback address. If forbid_nonlocal is true, then emit a stronger warning and remove the port from the list.

Definition at line 5625 of file config.c.

◆ write_configuration_file()

static int write_configuration_file ( const char *  fname,
const or_options_t options 
)
static

Save a configuration file for the configuration in options into the file fname. If the file already exists, and doesn't begin with GENERATED_FILE_PREFIX, rename it. Otherwise replace it. Return 0 on success, -1 on failure.

Definition at line 6665 of file config.c.

Referenced by options_save_current().

◆ write_to_data_subdir()

int write_to_data_subdir ( const char *  subdir,
const char *  fname,
const char *  str,
const char *  descr 
)

Create a file named fname with contents str in the subdirectory subdir of the data directory. descr should be a short description of the file's content and will be used for the warning message, if it's present and the write process fails. Return 0 on success, -1 otherwise.

Definition at line 6864 of file config.c.

Variable Documentation

◆ CMDLINE_ONLY_OPTIONS

const { ... } CMDLINE_ONLY_OPTIONS[]

Table describing arguments that Tor accepts on the command line, other than those that are the same as in torrc.

◆ command

◆ configured_ports

smartlist_t* configured_ports = NULL
static

◆ default_authorities

const char* default_authorities[]
static

List of default directory authorities

Definition at line 786 of file config.c.

◆ default_fallbacks

const char* default_fallbacks[]
static

List of fallback directory authorities. The list is generated by opt-in of relays that meet certain stability criteria.

Definition at line 796 of file config.c.

Referenced by add_default_fallback_dir_servers().

◆ global_cmdline

parsed_cmdline_t* global_cmdline = NULL
static

Result of parsing the command line.

Definition at line 901 of file config.c.

Referenced by options_init_from_torrc().

◆ global_default_options

or_options_t* global_default_options = NULL
static

The fallback options_t object; this is where we look for options not in torrc before we fall back to Tor's defaults.

Definition at line 895 of file config.c.

Referenced by config_free_all().

◆ global_options

or_options_t* global_options = NULL
static

Command-line and config-file options.

Definition at line 892 of file config.c.

Referenced by config_free_all(), get_options_mutable(), and set_options().

◆ in_option_validation

int in_option_validation = 0
static

True iff we're currently validating options, and any calls to get_options() are likely to be bugs.

Definition at line 906 of file config.c.

Referenced by options_validate_and_set().

◆ last_resolved_addr

uint32_t last_resolved_addr = 0
static

Last value actually set by resolve_my_address.

Definition at line 2491 of file config.c.

Referenced by get_last_resolved_addr(), and reset_last_resolved_addr().

◆ name

const char* name

◆ option_abbrevs_

const config_abbrev_t option_abbrevs_[]
static

A list of abbreviations and aliases to map command-line options, obsolete option names, or alternative option names, to their current values.

Definition at line 192 of file config.c.

◆ option_deprecation_notes_

const config_deprecation_t option_deprecation_notes_[]
static
Initial value:
= {
{ "HTTPProxy", "It only applies to direct unencrypted HTTP connections "
"to your directory server, which your Tor probably wasn't using." },
{ "HTTPProxyAuthenticator", "HTTPProxy is deprecated in favor of HTTPSProxy "
"which should be used with HTTPSProxyAuthenticator." },
{ "ReachableDirAddresses", "It has no effect on relays, and has had no "
"effect on clients since 0.2.8." },
{ "ClientPreferIPv6DirPort", "It has no effect on relays, and has had no "
"effect on clients since 0.2.8." },
{ NULL, NULL }
}

Definition at line 819 of file config.c.

◆ option_vars_

const config_var_t option_vars_[]
static

Array of configuration options. Until we disallow nonstandard abbreviations, order is significant, since the first matching option will be chosen first.

Definition at line 312 of file config.c.

◆ options_format

const config_format_t options_format
static
Initial value:
= {
.size = sizeof(or_options_t),
.magic = {
"or_options_t",
offsetof(or_options_t, magic_),
},
.abbrevs = option_abbrevs_,
.deprecations = option_deprecation_notes_,
.vars = option_vars_,
.legacy_validate_fn = options_validate_cb,
.check_transition_fn = options_check_transition_cb,
.clear_fn = options_clear_cb,
.has_config_suite = true,
.config_suite_offset = offsetof(or_options_t, subconfigs_),
}
static const config_abbrev_t option_abbrevs_[]
Definition: config.c:192
static int options_validate_cb(const void *old_options, void *options, char **msg)
Definition: config.c:3164
static int options_check_transition_cb(const void *old, const void *new, char **msg)
Definition: config.c:4040
static void options_clear_cb(const config_mgr_t *mgr, void *opts)
Definition: config.c:1027
#define OR_OPTIONS_MAGIC
Definition: config.c:867
static const config_var_t option_vars_[]
Definition: config.c:312

Configuration format for or_options_t.

Definition at line 870 of file config.c.

◆ protocol_warning_severity_level

atomic_counter_t protocol_warning_severity_level
static

The severity level that should be used for warnings of severity LOG_PROTOCOL_WARN.

We keep this outside the options, and we use an atomic_counter_t, in case one thread needs to use LOG_PROTOCOL_WARN while an option transition is happening in the main thread.

Definition at line 1166 of file config.c.

Referenced by cleanup_protocol_warning_severity_level(), get_protocol_warning_severity_level(), init_protocol_warning_severity_level(), and set_protocol_warning_severity_level().

◆ quiet

int quiet

If nonzero, set the quiet level to this. 1 is "hush", 2 is "quiet"

Definition at line 2217 of file config.c.

Referenced by add_default_log_for_quiet_level(), directory_info_has_arrived(), and tor_init().

◆ takes_argument

takes_argument_t takes_argument

Does this option accept an argument?

Definition at line 2213 of file config.c.

◆ testing_network_configured

bool testing_network_configured = false
static

True iff we have noticed that this is a testing tor network, and we should use the corresponding defaults.

Definition at line 950 of file config.c.

Referenced by get_options_defaults().

◆ testing_tor_network_defaults

const { ... } testing_tor_network_defaults[]

Override default values with these if the user sets the TestingTorNetwork option.

Referenced by get_options_defaults().

◆ torrc_defaults_fname

char* torrc_defaults_fname = NULL
static

Name of the most recently read torrc-defaults file.

Definition at line 899 of file config.c.

Referenced by get_torrc_fname(), and load_torrc_from_disk().

◆ torrc_fname

char* torrc_fname = NULL
static

Name of most recently read torrc file.

Definition at line 897 of file config.c.

Referenced by get_torrc_fname(), and load_torrc_from_disk().