Data Structures | Macros | Enumerations | Functions
config.h File Reference

Header file for config.c. More...

#include "app/config/or_options_st.h"
#include "lib/testsupport/testsupport.h"
#include "app/config/quiet_level.h"

Go to the source code of this file.

Data Structures

struct  parsed_cmdline_t
struct  bridge_line_t


#define MIN_HEARTBEAT_PERIOD   (30*60)
#define LOG_PROTOCOL_WARN   (get_protocol_warning_severity_level())
#define CONFIG_BACKUP_PATTERN   "%s.orig.1"
#define OPTIONS_DUMP_ALL   2
#define options_get_datadir_fname2_suffix(options, sub1, sub2, suffix)
#define options_get_cachedir_fname2_suffix(options, sub1, sub2, suffix)
#define options_get_keydir_fname2_suffix(options, sub1, sub2, suffix)
#define options_get_datadir_fname(opts, sub1)    options_get_datadir_fname2_suffix((opts),(sub1), NULL, NULL)
#define options_get_datadir_fname2(opts, sub1, sub2)    options_get_datadir_fname2_suffix((opts),(sub1), (sub2), NULL)
#define get_datadir_fname2_suffix(sub1, sub2, suffix)    options_get_datadir_fname2_suffix(get_options(), (sub1), (sub2), (suffix))
#define get_datadir_fname(sub1)    get_datadir_fname2_suffix((sub1), NULL, NULL)
#define get_datadir_fname2(sub1, sub2)    get_datadir_fname2_suffix((sub1), (sub2), NULL)
#define get_datadir_fname_suffix(sub1, suffix)    get_datadir_fname2_suffix((sub1), NULL, (suffix))
#define options_get_keydir_fname(options, sub1)    options_get_keydir_fname2_suffix((options), (sub1), NULL, NULL)
#define get_keydir_fname_suffix(sub1, suffix)    options_get_keydir_fname2_suffix(get_options(), (sub1), NULL, suffix)
#define get_keydir_fname(sub1)    options_get_keydir_fname2_suffix(get_options(), (sub1), NULL, NULL)
#define get_cachedir_fname(sub1)    options_get_cachedir_fname2_suffix(get_options(), (sub1), NULL, NULL)
#define get_cachedir_fname_suffix(sub1, suffix)    options_get_cachedir_fname2_suffix(get_options(), (sub1), NULL, (suffix))
#define safe_str_client(address)    safe_str_client_opts(NULL, address)
#define safe_str(address)    safe_str_opts(NULL, address)
#define portconf_get_primary_dir_port()    (portconf_get_first_advertised_port(CONN_TYPE_DIR_LISTENER, AF_INET))
#define parsed_cmdline_free(c)    FREE_AND_NULL(parsed_cmdline_t, parsed_cmdline_free_, (c))
#define bridge_line_free(line)    FREE_AND_NULL(bridge_line_t, bridge_line_free_, (line))
#define CL_PORT_NO_STREAM_OPTIONS   (1u<<0)
#define CL_PORT_WARN_NONLOCAL   (1u<<1)
#define CL_PORT_SERVER_OPTIONS   (1u<<3)
#define CL_PORT_FORBID_NONLOCAL   (1u<<4)
#define CL_PORT_TAKES_HOSTNAMES   (1u<<5)
#define CL_PORT_IS_UNIXSOCKET   (1u<<6)
#define port_cfg_free(port)    FREE_AND_NULL(port_cfg_t, port_cfg_free_, (port))


enum  setopt_err_t {


const or_options_tget_options (void)
or_options_tget_options_mutable (void)
int set_options (or_options_t *new_val, char **msg)
void config_free_all (void)
const char * safe_str_client (const char *address)
const char * safe_str (const char *address)
const char * escaped_safe_str_client (const char *address)
const char * escaped_safe_str (const char *address)
void init_protocol_warning_severity_level (void)
int get_protocol_warning_severity_level (void)
setopt_err_t options_trial_assign (struct config_line_t *list, unsigned flags, char **msg)
void options_init (or_options_t *options)
char * options_dump (const or_options_t *options, int how_to_dump)
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)
int option_is_recognized (const char *key)
const char * option_get_canonical_name (const char *key)
struct config_line_toption_get_assignment (const or_options_t *options, const char *key)
int options_save_current (void)
const char * get_torrc_fname (int defaults_fname)
char * options_get_dir_fname2_suffix (const or_options_t *options, directory_root_t roottype, const char *sub1, const char *sub2, const char *suffix)
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)
int using_default_dir_authorities (const or_options_t *options)
int create_keys_directory (const or_options_t *options)
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 get_num_cpus (const or_options_t *options)
const smartlist_tget_configured_ports (void)
int port_binds_ipv4 (const port_cfg_t *port)
int port_binds_ipv6 (const port_cfg_t *port)
int portconf_get_first_advertised_port (int listener_type, int address_family)
const tor_addr_tportconf_get_first_advertised_addr (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)
char * get_first_listener_addrport_string (int listener_type)
int options_need_geoip_info (const or_options_t *options, const char **reason_out)
int getinfo_helper_config (control_connection_t *conn, const char *question, char **answer, const char **errmsg)
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)
or_options_toptions_new (void)
parsed_cmdline_tconfig_parse_commandline (int argc, char **argv, int ignore_errors)
void parsed_cmdline_free_ (parsed_cmdline_t *cmdline)
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)
int port_cfg_line_extract_addrport (const char *line, char **addrport_out, int *is_unix_out, const char **rest_out)
void bridge_line_free_ (bridge_line_t *bridge_line)
bridge_line_tparse_bridge_line (const char *line)
int options_any_client_port_set (const or_options_t *options)
int port_parse_config (smartlist_t *out, const struct config_line_t *ports, const char *portname, int listener_type, const char *defaultaddr, int defaultport, const unsigned flags)
port_cfg_tport_cfg_new (size_t namelen)
void port_cfg_free_ (port_cfg_t *port)
int port_count_real_listeners (const smartlist_t *ports, int listenertype, int count_sockets)
int pt_parse_transport_line (const or_options_t *options, const char *line, int validate_only, int server)
int config_ensure_bandwidth_cap (uint64_t *value, const char *desc, char **msg)

Detailed Description

Header file for config.c.

Definition in file config.h.

Macro Definition Documentation


#define CONFIG_BACKUP_PATTERN   "%s.orig.1"

Pattern for backing up configuration files

Definition at line 48 of file config.h.



Maximum default value for MaxMemInQueues, in bytes.

Definition at line 31 of file config.h.


#define MIN_HEARTBEAT_PERIOD   (30*60)

Lowest allowable value for HeartbeatPeriod; if this is too low, we might expose more information than we're comfortable with.

Definition at line 25 of file config.h.

◆ options_get_cachedir_fname2_suffix

#define options_get_cachedir_fname2_suffix (   options,
options_get_dir_fname2_suffix((options), DIRROOT_CACHEDIR, \
(sub1), (sub2), (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)
Definition: config.c:7083

Definition at line 108 of file config.h.

◆ options_get_datadir_fname2_suffix

#define options_get_datadir_fname2_suffix (   options,
options_get_dir_fname2_suffix((options), DIRROOT_DATADIR, \
(sub1), (sub2), (suffix))

Definition at line 105 of file config.h.

◆ options_get_keydir_fname

#define options_get_keydir_fname (   options,
)     options_get_keydir_fname2_suffix((options), (sub1), NULL, NULL)


Definition at line 130 of file config.h.

◆ options_get_keydir_fname2_suffix

#define options_get_keydir_fname2_suffix (   options,
options_get_dir_fname2_suffix((options), DIRROOT_KEYDIR, \
(sub1), (sub2), (suffix))

Definition at line 111 of file config.h.

Enumeration Type Documentation

◆ setopt_err_t

An error from options_trial_assign() or options_init_from_string().

Definition at line 51 of file config.h.

Function Documentation

◆ 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 4785 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 5057 of file config.c.

◆ check_or_create_data_subdir()

int check_or_create_data_subdir ( const char *  subdir)

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

Definition at line 7126 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 2960 of file config.c.

Referenced by dirauth_options_pre_normalize().

◆ config_free_all()

void config_free_all ( void  )

Release all memory and resources held by global configuration structures.

Definition at line 1046 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 2522 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 4739 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 1382 of file config.c.

◆ 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 1129 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 1117 of file config.c.

◆ 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 6674 of file config.c.

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

◆ 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 6691 of file config.c.

◆ 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 7034 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 926 of file config.c.

Referenced by add_authmethods(), add_wildcarded_test_address(), address_is_invalid_destination(), assert_identity_keys_ok(), authdir_policy_badexit_address(), authdir_policy_middleonly_address(), authdir_policy_permits_address(), authdir_policy_valid_address(), bwhist_bandwidth_assess(), bwhist_fill_bandwidth_history(), channelpadding_decide_to_pad_channel(), channelpadding_get_channel_idle_timeout(), channelpadding_get_circuits_available_timeout(), check_descriptor_bandwidth_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_apply(), 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_send_intermediate_onion_skin(), 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(), congestion_control_init_params(), 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_https_proxy_connect(), connection_is_rate_limited(), connection_listener_new_for_port(), connection_or_check_valid_tls_handshake(), connection_or_client_learned_peer_id(), connection_or_connect(), connection_socks5_proxy_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_sched_get_configured_interval(), dirauth_sched_get_cur_valid_after_time(), dirauth_set_routerstatus_from_routerinfo(), dirclient_dump_total_dls(), directory_get_from_dirserver(), directory_handle_command_post(), directory_info_has_arrived(), dirserv_compute_performance_thresholds(), dirserv_generate_networkstatus_vote_obj(), dirserv_router_has_valid_address(), dirserv_should_launch_reachability_test(), dirvote_get_preferred_voting_intervals(), dns_init(), dns_launch_correctness_checks(), dns_new_consensus_params(), dns_reset(), dns_servers_relaunch_checks(), do_dump_config(), do_hash_password(), do_hup(), do_list_fingerprint(), entry_guard_could_succeed(), 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(), extend_info_pick_orport(), extrainfo_dump_to_string_stats_helper(), fetch_networkstatus_callback(), find_and_remove_client_auth_creds_file(), format_client_stats_heartbeat(), 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_proxy_addrport(), get_pt_proxy_uri(), get_time_period_length(), get_voting_interval(), getinfo_helper_events(), guard_in_node_family(), guards_update_all(), handle_cmdline_passphrase_fd(), 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(), options_act_bridge_stats(), options_act_dirauth(), options_act_dirauth_mtbf(), options_act_once_on_startup(), 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_commit_log_transaction(), options_create_directories(), options_save_current(), options_start_log_transaction(), options_switch_id(), 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(), reachable_addr_allows(), reachable_addr_allows_rs(), reachable_addr_choose_from_rs(), record_num_bytes_transferred_impl(), refresh_all_country_info(), relay_address_new_suggestion(), rend_mid_rendezvous(), rep_hist_circbuilding_dormant(), rep_hist_dump_stats(), 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_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_orport_found_reachable(), router_perform_bandwidth_test(), 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(), signewnym_impl(), sr_act_post_consensus(), store_permanent_client_auth_credentials(), 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(), usable_consensus_flavor(), vanguards_lite_is_enabled(), and warn_if_last_router_excluded().

◆ get_options_mutable()

or_options_t* get_options_mutable ( void  )

◆ 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 1150 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 4725 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 7164 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 7430 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 1168 of file config.c.

Referenced by tor_run_main().

◆ option_get_assignment()

struct 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 2653 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 2645 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 2637 of file config.c.

Referenced by handle_control_getconf().

◆ 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 7489 of file config.c.

Referenced by handle_missing_protocol_warning().

◆ 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 2911 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 7083 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 2891 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 4615 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 4435 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 1965 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 2881 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 7021 of file config.c.

Referenced by handle_control_saveconf().

◆ 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 2668 of file config.c.

Referenced by control_setconf_helper().

◆ 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 5083 of file config.c.

◆ parsed_cmdline_free_()

void parsed_cmdline_free_ ( parsed_cmdline_t cmdline)

Release all storage held by cmdline.

Definition at line 2626 of file config.c.

◆ port_cfg_free_()

void port_cfg_free_ ( port_cfg_t port)

Free all storage held in port

Definition at line 5845 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 5931 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.

namelen is the length of the unix socket name (typically the filesystem path), not including the trailing NUL. It should be 0 for ports that are not zunix sockets.

Definition at line 5824 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 6488 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 6801 of file config.c.

◆ portconf_get_first_advertised_addr()

const tor_addr_t* portconf_get_first_advertised_addr ( 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 6786 of file config.c.

Referenced by routerconf_find_ipv6_or_ap(), and routerconf_has_ipv6_orport().

◆ portconf_get_first_advertised_port()

int portconf_get_first_advertised_port ( 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 6774 of file config.c.

Referenced by routerconf_find_or_port().

◆ 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 5262 of file config.c.

◆ 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 1079 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 1100 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 962 of file config.c.

◆ 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 7145 of file config.c.