Tor  0.4.4.0-alpha-dev
Macros | Functions | Variables
relay_config.c File Reference

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

#include "orconfig.h"
#include "feature/relay/relay_config.h"
#include "lib/encoding/confline.h"
#include "lib/confmgt/confmgt.h"
#include "lib/container/smartlist.h"
#include "lib/geoip/geoip.h"
#include "lib/meminfo/meminfo.h"
#include "lib/osinfo/uname.h"
#include "lib/process/setuid.h"
#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/cpuworker.h"
#include "core/mainloop/mainloop.h"
#include "core/or/circuitbuild.h"
#include "core/or/connection_or.h"
#include "core/or/port_cfg_st.h"
#include "feature/hibernate/hibernate.h"
#include "feature/nodelist/nickname.h"
#include "feature/stats/geoip_stats.h"
#include "feature/stats/predict_ports.h"
#include "feature/stats/rephist.h"
#include "feature/dirauth/authmode.h"
#include "feature/dircache/consdiffmgr.h"
#include "feature/relay/dns.h"
#include "feature/relay/routermode.h"

Go to the source code of this file.

Macros

#define RELAY_CONFIG_PRIVATE
 
#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 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 ONE_MEGABYTE   (UINT64_C(1) << 20)
 
#define DIRCACHE_MIN_MEM_MB   300
 
#define DIRCACHE_MIN_MEM_BYTES   (DIRCACHE_MIN_MEM_MB*ONE_MEGABYTE)
 
#define STRINGIFY(val)   #val
 
#define RELAY_BRIDGE_STATS_DELAY   (6 * 60 * 60)
 

Functions

const char * relay_get_dirportfrontpage (void)
 
void relay_config_free_all (void)
 
uint32_t relay_get_effective_bwrate (const or_options_t *options)
 
uint32_t relay_get_effective_bwburst (const or_options_t *options)
 
void port_warn_nonlocal_ext_orports (const smartlist_t *ports, const char *portname)
 
static int check_server_ports (const smartlist_t *ports, const or_options_t *options, int *n_low_ports_out)
 
int port_parse_ports_relay (or_options_t *options, char **msg, smartlist_t *ports_out, int *have_low_ports_out)
 
void port_update_port_set_relay (or_options_t *options, const smartlist_t *ports)
 
int options_validate_relay_os (const or_options_t *old_options, or_options_t *options, char **msg)
 
int options_validate_relay_info (const or_options_t *old_options, or_options_t *options, char **msg)
 
static int compute_publishserverdescriptor (or_options_t *options)
 
STATIC int check_bridge_distribution_setting (const char *bd)
 
int options_validate_publish_server (const or_options_t *old_options, or_options_t *options, char **msg)
 
int options_validate_relay_padding (const or_options_t *old_options, or_options_t *options, char **msg)
 
int options_validate_relay_bandwidth (const or_options_t *old_options, or_options_t *options, char **msg)
 
int options_validate_relay_accounting (const or_options_t *old_options, or_options_t *options, char **msg)
 
static int normalize_nickname_list (config_line_t **normalized_out, const config_line_t *lst, const char *name, char **msg)
 
STATIC int have_enough_mem_for_dircache (const or_options_t *options, size_t total_mem, char **msg)
 
int options_validate_relay_mode (const or_options_t *old_options, or_options_t *options, char **msg)
 
int options_validate_relay_testing (const or_options_t *old_options, or_options_t *options, char **msg)
 
static int options_transition_affects_workers (const or_options_t *old_options, const or_options_t *new_options)
 
static int options_transition_affects_descriptor (const or_options_t *old_options, const or_options_t *new_options)
 
int options_act_relay (const or_options_t *old_options)
 
int options_act_relay_accounting (const or_options_t *old_options)
 
int options_act_relay_bandwidth (const or_options_t *old_options)
 
int options_act_bridge_stats (const or_options_t *old_options)
 
int options_act_relay_stats (const or_options_t *old_options, bool *print_notice_out)
 
void options_act_relay_stats_msg (void)
 
int options_act_relay_desc (const or_options_t *old_options)
 
int options_act_relay_dos (const or_options_t *old_options)
 
int options_act_relay_dir (const or_options_t *old_options)
 

Variables

static char * global_dirfrontpagecontents = NULL
 

Detailed Description

Code to interpret the user's configuration of Tor's relay module.

Definition in file relay_config.c.

Function Documentation

◆ check_bridge_distribution_setting()

STATIC int check_bridge_distribution_setting ( const char *  bd)

Validate the configured bridge distribution method from a BridgeDistribution config line.

The input bd, is a string taken from the BridgeDistribution config line (if present). If the option wasn't set, return 0 immediately. The BridgeDistribution option is then validated. Currently valid, recognised options are:

  • "none"
  • "any"
  • "https"
  • "email"
  • "moat"

If the option string is unrecognised, a warning will be logged and 0 is returned. If the option string contains an invalid character, -1 is returned.

Definition at line 477 of file relay_config.c.

◆ check_server_ports()

static int check_server_ports ( const smartlist_t ports,
const or_options_t options,
int *  n_low_ports_out 
)
static

Given a list of port_cfg_t in ports, check them for internal consistency and warn as appropriate. On Unix-based OSes, set *n_low_ports_out to the number of sub-1024 ports we will be binding, and warn if we may be unable to re-bind after hibernation.

Definition at line 140 of file relay_config.c.

◆ compute_publishserverdescriptor()

static int compute_publishserverdescriptor ( or_options_t options)
static

Parse an authority type from options->PublishServerDescriptor and write it to options->PublishServerDescriptor_. Treat "1" as "v3" unless BridgeRelay is 1, in which case treat it as "bridge". Treat "0" as "". Return 0 on success or -1 if not a recognized authority type (in which case the value of PublishServerDescriptor_ is undefined).

Definition at line 422 of file relay_config.c.

◆ have_enough_mem_for_dircache()

STATIC int have_enough_mem_for_dircache ( const or_options_t options,
size_t  total_mem,
char **  msg 
)

Create a warning message for emitting if we are a dircache but may not have enough system memory, or if we are not a dircache but probably should be. Return -1 when a message is returned in msg, else return 0.

Definition at line 842 of file relay_config.c.

◆ normalize_nickname_list()

static int normalize_nickname_list ( config_line_t **  normalized_out,
const config_line_t lst,
const char *  name,
char **  msg 
)
static

Verify whether lst is a list of strings containing valid-looking comma-separated nicknames, or NULL. Will normalise lst to prefix '$' to any nickname or fingerprint that needs it. Also splits comma-separated list elements into multiple elements. Return 0 on success. Warn and return -1 on failure.

Definition at line 759 of file relay_config.c.

◆ options_act_bridge_stats()

int options_act_bridge_stats ( const or_options_t old_options)

Fetch the active option list, and take bridge statistics 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 into the options_act* functions yet. Some is still in do_hup() and other places.

Definition at line 1192 of file relay_config.c.

◆ options_act_relay()

int options_act_relay ( const or_options_t old_options)

Fetch the active option list, and take relay 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 into the options_act* functions yet. Some is still in do_hup() and other places.

Definition at line 1069 of file relay_config.c.

◆ options_act_relay_accounting()

int options_act_relay_accounting ( const or_options_t old_options)

Fetch the active option list, and take relay accounting 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 into the options_act* functions yet. Some is still in do_hup() and other places.

Definition at line 1133 of file relay_config.c.

◆ options_act_relay_bandwidth()

int options_act_relay_bandwidth ( const or_options_t old_options)

Fetch the active option list, and take relay bandwidth 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 into the options_act* functions yet. Some is still in do_hup() and other places.

Definition at line 1163 of file relay_config.c.

◆ options_act_relay_desc()

int options_act_relay_desc ( const or_options_t old_options)

Fetch the active option list, and take relay descriptor 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 into the options_act* functions yet. Some is still in do_hup() and other places.

Definition at line 1362 of file relay_config.c.

◆ options_act_relay_dir()

int options_act_relay_dir ( const or_options_t old_options)

Fetch the active option list, and take dirport 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 into the options_act* functions yet. Some is still in do_hup() and other places.

Definition at line 1416 of file relay_config.c.

◆ options_act_relay_dos()

int options_act_relay_dos ( const or_options_t old_options)

Fetch the active option list, and take relay DoS 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 into the options_act* functions yet. Some is still in do_hup() and other places.

Definition at line 1387 of file relay_config.c.

◆ options_act_relay_stats()

int options_act_relay_stats ( const or_options_t old_options,
bool *  print_notice_out 
)

Fetch the active option list, and take relay statistics 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.

Sets *print_notice_out if we enabled stats, and need to print a stats log using options_act_relay_stats_msg().

If loading the GeoIP file failed, sets DirReqStatistics and EntryStatistics to 0. This breaks the normalization/act ordering introduced in 29211.

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 into the options_act* functions yet. Some is still in do_hup() and other places.

Definition at line 1246 of file relay_config.c.

◆ options_act_relay_stats_msg()

void options_act_relay_stats_msg ( void  )

Print a notice about relay/dirauth stats being enabled.

Definition at line 1344 of file relay_config.c.

◆ options_transition_affects_descriptor()

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

Return 1 if any change from old_options to new_options will require us to generate a new descriptor; else return 0.

Definition at line 1019 of file relay_config.c.

Referenced by options_act_relay_desc().

◆ options_transition_affects_workers()

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

Return 1 if any change from old_options to new_options will require us to rotate the CPU and DNS workers; else return 0.

Definition at line 995 of file relay_config.c.

Referenced by options_act_relay().

◆ options_validate_publish_server()

int options_validate_publish_server ( const or_options_t old_options,
or_options_t options,
char **  msg 
)

Legacy validation/normalization function for the bridge relay options. Uses old_options as the previous options.

Returns 0 on success, returns -1 and sets *msg to a newly allocated string on error.

Definition at line 513 of file relay_config.c.

◆ options_validate_relay_accounting()

int options_validate_relay_accounting ( const or_options_t old_options,
or_options_t options,
char **  msg 
)

Legacy validation/normalization function for the relay bandwidth accounting options. Uses old_options as the previous options.

Returns 0 on success, returns -1 and sets *msg to a newly allocated string on error.

Definition at line 704 of file relay_config.c.

◆ options_validate_relay_bandwidth()

int options_validate_relay_bandwidth ( const or_options_t old_options,
or_options_t options,
char **  msg 
)

Legacy validation/normalization function for the relay bandwidth options. Uses old_options as the previous options.

Returns 0 on success, returns -1 and sets *msg to a newly allocated string on error.

Definition at line 612 of file relay_config.c.

◆ options_validate_relay_info()

int options_validate_relay_info ( const or_options_t old_options,
or_options_t options,
char **  msg 
)

Legacy validation/normalization function for the relay info options. Uses old_options as the previous options.

Returns 0 on success, returns -1 and sets *msg to a newly allocated string on error.

Definition at line 377 of file relay_config.c.

◆ options_validate_relay_mode()

int options_validate_relay_mode ( const or_options_t old_options,
or_options_t options,
char **  msg 
)

Legacy validation/normalization function for the relay mode options. Uses old_options as the previous options.

Returns 0 on success, returns -1 and sets *msg to a newly allocated string on error.

Definition at line 885 of file relay_config.c.

◆ options_validate_relay_os()

int options_validate_relay_os ( const or_options_t old_options,
or_options_t options,
char **  msg 
)

Legacy validation function, which checks that the current OS is usable in relay mode, if options is set to a relay mode.

Warns about OSes with potential issues. Always returns 0.

Definition at line 340 of file relay_config.c.

◆ options_validate_relay_padding()

int options_validate_relay_padding ( const or_options_t old_options,
or_options_t options,
char **  msg 
)

Legacy validation/normalization function for the relay padding options. Uses old_options as the previous options.

Returns 0 on success, returns -1 and sets *msg to a newly allocated string on error.

Definition at line 570 of file relay_config.c.

◆ options_validate_relay_testing()

int options_validate_relay_testing ( const or_options_t old_options,
or_options_t options,
char **  msg 
)

Legacy validation/normalization function for the relay testing options in options. Uses old_options as the previous options.

Returns 0 on success, returns -1 and sets *msg to a newly allocated string on error.

Definition at line 970 of file relay_config.c.

◆ port_parse_ports_relay()

int port_parse_ports_relay ( or_options_t options,
char **  msg,
smartlist_t ports_out,
int *  have_low_ports_out 
)

Parse all relay ports from options. On success, add parsed ports to ports, and return 0. On failure, set *msg to a description of the problem and return -1.

Definition at line 238 of file relay_config.c.

◆ port_update_port_set_relay()

void port_update_port_set_relay ( or_options_t options,
const smartlist_t ports 
)

Update the relay *Port_set values in options from ports.

Definition at line 311 of file relay_config.c.

◆ port_warn_nonlocal_ext_orports()

void port_warn_nonlocal_ext_orports ( const smartlist_t ports,
const char *  portname 
)

Warn for every Extended ORPort port in ports that is on a publicly routable address.

Definition at line 117 of file relay_config.c.

◆ relay_config_free_all()

void relay_config_free_all ( void  )

Release all memory and resources held by global relay configuration structures.

Definition at line 83 of file relay_config.c.

◆ relay_get_dirportfrontpage()

const char* relay_get_dirportfrontpage ( void  )

Return the contents of our frontpage string, or NULL if not configured.

Definition at line 74 of file relay_config.c.

Referenced by handle_get_frontpage().

◆ relay_get_effective_bwburst()

uint32_t relay_get_effective_bwburst ( const or_options_t options)

Return the bandwidthburst that we are going to report to the authorities based on the config options.

Definition at line 105 of file relay_config.c.

◆ relay_get_effective_bwrate()

uint32_t relay_get_effective_bwrate ( const or_options_t options)

Return the bandwidthrate that we are going to report to the authorities based on the config options.

Definition at line 91 of file relay_config.c.

Referenced by router_should_be_dirserver().

Variable Documentation

◆ global_dirfrontpagecontents

char* global_dirfrontpagecontents = NULL
static

Contents of most recently read DirPortFrontPage file.

Definition at line 49 of file relay_config.c.

Referenced by options_act_relay_dir(), relay_config_free_all(), and relay_get_dirportfrontpage().