Tor  0.4.7.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/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/connstats.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"
#include "feature/relay/selftest.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 const char * describe_portnum (int port)
 
STATIC const char * describe_relay_port (const port_cfg_t *port)
 
static bool port_cfg_eq (const port_cfg_t *p1, const port_cfg_t *p2)
 
STATIC void remove_duplicate_orports (smartlist_t *ports)
 
static int check_and_prune_server_ports (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_and_prune_server_ports()

static int check_and_prune_server_ports ( 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 337 of file relay_config.c.

◆ 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 690 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 635 of file relay_config.c.

◆ describe_portnum()

static const char* describe_portnum ( int  port)
static

Return a static buffer describing the port number in port, which may CFG_AUTO_PORT.

Definition at line 141 of file relay_config.c.

◆ describe_relay_port()

STATIC const char* describe_relay_port ( const port_cfg_t port)

Return a static buffer containing the human readable logging string that describes the given port object.

Definition at line 155 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 1055 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 972 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 1403 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 1282 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 1344 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 1374 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 1573 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 1627 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 1598 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 1457 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 1555 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 1232 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 1208 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 726 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 917 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 825 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 586 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 1098 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. Does not set *msg. Always returns 0.

Definition at line 549 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 783 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 1183 of file relay_config.c.

◆ port_cfg_eq()

static bool port_cfg_eq ( const port_cfg_t p1,
const port_cfg_t p2 
)
static

Return true iff port p1 is equal to p2.

This does a field by field comparaison.

Definition at line 195 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 newly allocated string describing the problem, and return -1.

Definition at line 438 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 519 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 118 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 84 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 75 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 106 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 92 of file relay_config.c.

Referenced by router_should_be_dirserver().

◆ remove_duplicate_orports()

STATIC void remove_duplicate_orports ( smartlist_t ports)

Attempt to find duplicate ORPort that would be superseded by another and remove them from the given ports list. This is possible if we have for instance:

ORPort 9050 ORPort [4242::1]:9050

First one binds to both v4 and v6 address but second one is specific to an address superseding the global bind one.

Another example is this one:

ORPort 9001 ORPort [4242::1]:9002 ORPort [4242::2]:9003

In this case, all IPv4 and IPv6 are kept since we do allow multiple ORPorts but the published port will be the first explicit one if any to be published or else the implicit.

The following is O(n^2) but it is done at bootstrap or config reload and the list is not very long usually.

Definition at line 249 of file relay_config.c.

Variable Documentation

◆ global_dirfrontpagecontents

char* global_dirfrontpagecontents = NULL
static

Contents of most recently read DirPortFrontPage file.

Definition at line 50 of file relay_config.c.

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