tor  0.4.1.0-alpha-dev
Data Structures | Macros | Typedefs | Functions | Variables
policies.c File Reference
#include "core/or/or.h"
#include "feature/client/bridges.h"
#include "app/config/config.h"
#include "core/or/policies.h"
#include "feature/dirparse/policy_parse.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "feature/relay/router.h"
#include "feature/relay/routermode.h"
#include "lib/geoip/geoip.h"
#include "ht.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/encoding/confline.h"
#include "core/or/addr_policy_st.h"
#include "feature/dirclient/dir_server_st.h"
#include "feature/nodelist/microdesc_st.h"
#include "feature/nodelist/node_st.h"
#include "core/or/port_cfg_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerstatus_st.h"

Go to the source code of this file.

Data Structures

struct  policy_summary_item_t
 
struct  policy_map_ent_t
 

Macros

#define POLICIES_PRIVATE
 
#define MAX_EXITPOLICY_SUMMARY_LEN   1000
 
#define REJECT(arg)   STMT_BEGIN *msg = tor_strdup(arg); goto err; STMT_END
 
#define CMP_FIELD(field)
 
#define DEFAULT_EXIT_POLICY
 
#define REDUCED_EXIT_POLICY
 
#define AT(x)   ((policy_summary_item_t*)smartlist_get(summary, x))
 
#define IPV4_BITS   (32)
 
#define REJECT_CUTOFF_SCALE_IPV4   (0)
 
#define REJECT_CUTOFF_COUNT_IPV4
 
#define IPV6_BITS   (128)
 
#define REJECT_CUTOFF_SCALE_IPV6   (64)
 
#define REJECT_CUTOFF_COUNT_IPV6
 

Typedefs

typedef struct policy_summary_item_t policy_summary_item_t
 
typedef struct policy_map_ent_t policy_map_ent_t
 

Functions

static int policies_parse_exit_policy_internal (config_line_t *cfg, smartlist_t **dest, int ipv6_exit, int rejectprivate, const smartlist_t *configured_addresses, int reject_interface_addresses, int reject_configured_port_addresses, int add_default_policy, int add_reduced_policy)
 
void policy_expand_private (smartlist_t **policy)
 
void policy_expand_unspec (smartlist_t **policy)
 
static int parse_addr_policy (config_line_t *cfg, smartlist_t **dest, int assume_action)
 
static int parse_reachable_addresses (void)
 
static int firewall_is_fascist_impl (void)
 
int firewall_is_fascist_or (void)
 
int firewall_is_fascist_dir (void)
 
static int addr_policy_permits_tor_addr (const tor_addr_t *addr, uint16_t port, smartlist_t *policy)
 
static int addr_policy_permits_address (uint32_t addr, uint16_t port, smartlist_t *policy)
 
STATIC int fascist_firewall_allows_address (const tor_addr_t *addr, uint16_t port, smartlist_t *firewall_policy, int pref_only, int pref_ipv6)
 
int fascist_firewall_use_ipv6 (const or_options_t *options)
 
static int fascist_firewall_prefer_ipv6_impl (const or_options_t *options)
 
 MOCK_IMPL (int, fascist_firewall_rand_prefer_ipv6_addr,(void))
 
int fascist_firewall_prefer_ipv6_orport (const or_options_t *options)
 
int fascist_firewall_prefer_ipv6_dirport (const or_options_t *options)
 
int fascist_firewall_allows_address_addr (const tor_addr_t *addr, uint16_t port, firewall_connection_t fw_connection, int pref_only, int pref_ipv6)
 
static int fascist_firewall_allows_address_ap (const tor_addr_port_t *ap, firewall_connection_t fw_connection, int pref_only, int pref_ipv6)
 
static int fascist_firewall_allows_address_ipv4h (uint32_t ipv4h_or_addr, uint16_t ipv4_or_port, firewall_connection_t fw_connection, int pref_only, int pref_ipv6)
 
static int fascist_firewall_allows_base (uint32_t ipv4h_addr, uint16_t ipv4_orport, uint16_t ipv4_dirport, const tor_addr_t *ipv6_addr, uint16_t ipv6_orport, uint16_t ipv6_dirport, firewall_connection_t fw_connection, int pref_only, int pref_ipv6)
 
static int fascist_firewall_allows_ri_impl (const routerinfo_t *ri, firewall_connection_t fw_connection, int pref_only, int pref_ipv6)
 
static int fascist_firewall_allows_rs_impl (const routerstatus_t *rs, firewall_connection_t fw_connection, int pref_only, int pref_ipv6)
 
int fascist_firewall_allows_rs (const routerstatus_t *rs, firewall_connection_t fw_connection, int pref_only)
 
static int fascist_firewall_allows_md_impl (const microdesc_t *md, firewall_connection_t fw_connection, int pref_only, int pref_ipv6)
 
int fascist_firewall_allows_node (const node_t *node, firewall_connection_t fw_connection, int pref_only)
 
int fascist_firewall_allows_dir_server (const dir_server_t *ds, firewall_connection_t fw_connection, int pref_only)
 
static const tor_addr_port_tfascist_firewall_choose_address_impl (const tor_addr_port_t *a, const tor_addr_port_t *b, int want_a, firewall_connection_t fw_connection, int pref_only, int pref_ipv6)
 
STATIC const tor_addr_port_tfascist_firewall_choose_address (const tor_addr_port_t *a, const tor_addr_port_t *b, int want_a, firewall_connection_t fw_connection, int pref_only, int pref_ipv6)
 
static void fascist_firewall_choose_address_base (const tor_addr_t *ipv4_addr, uint16_t ipv4_orport, uint16_t ipv4_dirport, const tor_addr_t *ipv6_addr, uint16_t ipv6_orport, uint16_t ipv6_dirport, firewall_connection_t fw_connection, int pref_only, int pref_ipv6, tor_addr_port_t *ap)
 
static void fascist_firewall_choose_address_ipv4h (uint32_t ipv4h_addr, uint16_t ipv4_orport, uint16_t ipv4_dirport, const tor_addr_t *ipv6_addr, uint16_t ipv6_orport, uint16_t ipv6_dirport, firewall_connection_t fw_connection, int pref_only, int pref_ipv6, tor_addr_port_t *ap)
 
static int node_awaiting_ipv6 (const or_options_t *options, const node_t *node)
 
void fascist_firewall_choose_address_rs (const routerstatus_t *rs, firewall_connection_t fw_connection, int pref_only, tor_addr_port_t *ap)
 
void fascist_firewall_choose_address_node (const node_t *node, firewall_connection_t fw_connection, int pref_only, tor_addr_port_t *ap)
 
void fascist_firewall_choose_address_dir_server (const dir_server_t *ds, firewall_connection_t fw_connection, int pref_only, tor_addr_port_t *ap)
 
int dir_policy_permits_address (const tor_addr_t *addr)
 
int socks_policy_permits_address (const tor_addr_t *addr)
 
static int addr_is_in_cc_list (uint32_t addr, const smartlist_t *cc_list)
 
int authdir_policy_permits_address (uint32_t addr, uint16_t port)
 
int authdir_policy_valid_address (uint32_t addr, uint16_t port)
 
int authdir_policy_badexit_address (uint32_t addr, uint16_t port)
 
int validate_addr_policies (const or_options_t *options, char **msg)
 
static int load_policy_from_option (config_line_t *config, const char *option_name, smartlist_t **policy, int assume_action)
 
int policies_parse_from_options (const or_options_t *options)
 
static int single_addr_policy_eq (const addr_policy_t *a, const addr_policy_t *b)
 
int addr_policies_eq (const smartlist_t *a, const smartlist_t *b)
 
static HT_HEAD (policy_map, policy_map_ent_t)
 
static unsigned int policy_hash (const policy_map_ent_t *ent)
 
 HT_PROTOTYPE (HT_GENERATE2(policy_map, HT_GENERATE2(policy_map_ent_t, HT_GENERATE2(node, HT_GENERATE2(policy_hash, HT_GENERATE2(policy_eq)
 
static addr_policy_result_t compare_known_tor_addr_to_addr_policy (const tor_addr_t *addr, uint16_t port, const smartlist_t *policy)
 
static addr_policy_result_t compare_known_tor_addr_to_addr_policy_noport (const tor_addr_t *addr, const smartlist_t *policy)
 
static addr_policy_result_t compare_unknown_tor_addr_to_addr_policy (uint16_t port, const smartlist_t *policy)
 
 MOCK_IMPL (addr_policy_result_t, compare_tor_addr_to_addr_policy,(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy))
 
static int addr_policy_covers (addr_policy_t *a, addr_policy_t *b)
 
static int addr_policy_intersects (addr_policy_t *a, addr_policy_t *b)
 
STATIC void append_exit_policy_string (smartlist_t **policy, const char *more)
 
void addr_policy_append_reject_addr (smartlist_t **dest, const tor_addr_t *addr)
 
static int tor_addr_is_public_for_reject (const tor_addr_t *addr)
 
static void addr_policy_append_reject_addr_filter (smartlist_t **dest, const tor_addr_t *addr, int ipv4_rules, int ipv6_rules)
 
void addr_policy_append_reject_addr_list (smartlist_t **dest, const smartlist_t *addrs)
 
static void addr_policy_append_reject_addr_list_filter (smartlist_t **dest, const smartlist_t *addrs, int ipv4_rules, int ipv6_rules)
 
static void exit_policy_remove_redundancies (smartlist_t *dest)
 
void policies_parse_exit_policy_reject_private (smartlist_t **dest, int ipv6_exit, const smartlist_t *configured_addresses, int reject_interface_addresses, int reject_configured_port_addresses)
 
static void policies_log_first_redundant_entry (const smartlist_t *policy)
 
int policies_parse_exit_policy (config_line_t *cfg, smartlist_t **dest, exit_policy_parser_cfg_t options, const smartlist_t *configured_addresses)
 
static void policies_copy_addr_to_smartlist (smartlist_t *addr_list, const tor_addr_t *addr)
 
static void policies_copy_ipv4h_to_smartlist (smartlist_t *addr_list, uint32_t ipv4h_addr)
 
static void policies_copy_outbound_addresses_to_smartlist (smartlist_t *addr_list, const or_options_t *or_options)
 
int policies_parse_exit_policy_from_options (const or_options_t *or_options, uint32_t local_address, const tor_addr_t *ipv6_local_address, smartlist_t **result)
 
void policies_exit_policy_append_reject_star (smartlist_t **dest)
 
void policies_set_node_exitpolicy_to_reject_all (node_t *node)
 
static int exit_policy_is_general_exit_helper (smartlist_t *policy, int port)
 
int exit_policy_is_general_exit (smartlist_t *policy)
 
int policy_is_reject_star (const smartlist_t *policy, sa_family_t family, int default_reject)
 
int policy_write_item (char *buf, size_t buflen, const addr_policy_t *policy, int format_for_desc)
 
static smartlist_tpolicy_summary_create (void)
 
static policy_summary_item_tpolicy_summary_item_split (policy_summary_item_t *old, uint16_t new_starts)
 
static int policy_summary_split (smartlist_t *summary, uint16_t prt_min, uint16_t prt_max)
 
static void policy_summary_accept (smartlist_t *summary, uint16_t prt_min, uint16_t prt_max, sa_family_t family)
 
static void policy_summary_reject (smartlist_t *summary, maskbits_t maskbits, uint16_t prt_min, uint16_t prt_max, sa_family_t family)
 
static void policy_summary_add_item (smartlist_t *summary, addr_policy_t *p)
 
char * policy_summarize (smartlist_t *policy, sa_family_t family)
 
short_policy_tparse_short_policy (const char *summary)
 
char * write_short_policy (const short_policy_t *policy)
 
void short_policy_free_ (short_policy_t *policy)
 
addr_policy_result_t compare_tor_addr_to_short_policy (const tor_addr_t *addr, uint16_t port, const short_policy_t *policy)
 
int short_policy_is_reject_star (const short_policy_t *policy)
 
addr_policy_result_t compare_tor_addr_to_node_policy (const tor_addr_t *addr, uint16_t port, const node_t *node)
 
char * policy_dump_to_string (const smartlist_t *policy_list, int include_ipv4, int include_ipv6)
 
int getinfo_helper_policies (control_connection_t *conn, const char *question, char **answer, const char **errmsg)
 
void addr_policy_list_free_ (smartlist_t *lst)
 
void addr_policy_free_ (addr_policy_t *p)
 
void policies_free_all (void)
 

Variables

static smartlist_tsocks_policy = NULL
 
static smartlist_tdir_policy = NULL
 
static smartlist_tauthdir_reject_policy = NULL
 
static smartlist_tauthdir_invalid_policy = NULL
 
static smartlist_tauthdir_badexit_policy = NULL
 
static smartlist_treachable_or_addr_policy = NULL
 
static smartlist_treachable_dir_addr_policy = NULL
 
static const char * private_nets []
 

Detailed Description

Code to parse and use address policies and exit policies.

We have two key kinds of address policy: full and compressed. A full policy is an array of accept/reject patterns, to be applied in order. A short policy is simply a list of ports. This module handles both kinds, including generic functions to apply them to addresses, and also including code to manage the global policies that we apply to incoming and outgoing connections.

Definition in file policies.c.

Macro Definition Documentation

◆ CMP_FIELD

#define CMP_FIELD (   field)
Value:
do { \
if (a->field != b->field) { \
return 0; \
} \
} while (0)

◆ DEFAULT_EXIT_POLICY

#define DEFAULT_EXIT_POLICY
Value:
"reject *:25,reject *:119,reject *:135-139,reject *:445," \
"reject *:563,reject *:1214,reject *:4661-4666," \
"reject *:6346-6429,reject *:6699,reject *:6881-6999,accept *:*"

Definition at line 1916 of file policies.c.

◆ MAX_EXITPOLICY_SUMMARY_LEN

#define MAX_EXITPOLICY_SUMMARY_LEN   1000

Maximum length of an exit policy summary.

Definition at line 44 of file policies.c.

◆ REDUCED_EXIT_POLICY

#define REDUCED_EXIT_POLICY
Value:
"accept *:20-23,accept *:43,accept *:53,accept *:79-81,accept *:88," \
"accept *:110,accept *:143,accept *:194,accept *:220,accept *:389," \
"accept *:443,accept *:464,accept *:465,accept *:531,accept *:543-544," \
"accept *:554,accept *:563,accept *:587,accept *:636,accept *:706," \
"accept *:749,accept *:873,accept *:902-904,accept *:981,accept *:989-995," \
"accept *:1194,accept *:1220,accept *:1293,accept *:1500,accept *:1533," \
"accept *:1677,accept *:1723,accept *:1755,accept *:1863," \
"accept *:2082-2083,accept *:2086-2087,accept *:2095-2096," \
"accept *:2102-2104,accept *:3128,accept *:3389,accept *:3690," \
"accept *:4321,accept *:4643,accept *:5050,accept *:5190," \
"accept *:5222-5223,accept *:5228,accept *:5900,accept *:6660-6669," \
"accept *:6679,accept *:6697,accept *:8000,accept *:8008,accept *:8074," \
"accept *:8080,accept *:8082,accept *:8087-8088,accept *:8232-8233," \
"accept *:8332-8333,accept *:8443,accept *:8888,accept *:9418," \
"accept *:9999,accept *:10000,accept *:11371,accept *:19294," \
"accept *:19638,accept *:50002,accept *:64738,reject *:*"

Definition at line 1921 of file policies.c.

◆ REJECT_CUTOFF_COUNT_IPV4

#define REJECT_CUTOFF_COUNT_IPV4
Value:
(UINT64_C(1) << \
(IPV4_BITS - REJECT_CUTOFF_SCALE_IPV4 - 7))

Definition at line 2425 of file policies.c.

◆ REJECT_CUTOFF_COUNT_IPV6

#define REJECT_CUTOFF_COUNT_IPV6
Value:
(UINT64_C(1) << \
(IPV6_BITS - REJECT_CUTOFF_SCALE_IPV6 - 16))

Definition at line 2437 of file policies.c.

Typedef Documentation

◆ policy_map_ent_t

Node in hashtable used to store address policy entries.

◆ policy_summary_item_t

Element of an exit policy summary

Function Documentation

◆ addr_is_in_cc_list()

static int addr_is_in_cc_list ( uint32_t  addr,
const smartlist_t cc_list 
)
static

Return true iff the address addr is in a country listed in the case-insensitive list of country codes cc_list.

Definition at line 1116 of file policies.c.

Referenced by authdir_policy_badexit_address(), authdir_policy_permits_address(), and authdir_policy_valid_address().

◆ addr_policies_eq()

int addr_policies_eq ( const smartlist_t a,
const smartlist_t b 
)

As single_addr_policy_eq, but compare every element of two policies.

Definition at line 1319 of file policies.c.

Referenced by router_differences_are_cosmetic().

◆ addr_policy_append_reject_addr()

void addr_policy_append_reject_addr ( smartlist_t **  dest,
const tor_addr_t addr 
)

Add "reject <b>addr</b>:*" to dest, creating the list as needed.

Definition at line 1612 of file policies.c.

References addr_policy_t::addr, addr_policy_t::maskbits, addr_policy_t::policy_type, addr_policy_t::prt_max, addr_policy_t::prt_min, tor_addr_copy(), tor_addr_family(), and tor_assert().

Referenced by addr_policy_append_reject_addr_list().

◆ addr_policy_append_reject_addr_list()

void addr_policy_append_reject_addr_list ( smartlist_t **  dest,
const smartlist_t addrs 
)

Add "reject addr:*" to dest, for each addr in addrs, creating the list as needed.

Definition at line 1669 of file policies.c.

References addr_policy_append_reject_addr(), SMARTLIST_FOREACH_BEGIN, and tor_assert().

◆ addr_policy_append_reject_addr_list_filter()

static void addr_policy_append_reject_addr_list_filter ( smartlist_t **  dest,
const smartlist_t addrs,
int  ipv4_rules,
int  ipv6_rules 
)
static

Add "reject addr:*" to dest, for each addr in addrs, creating the list as needed. Filter using

Definition at line 1683 of file policies.c.

References SMARTLIST_FOREACH_BEGIN, and tor_assert().

Referenced by policies_parse_exit_policy_reject_private().

◆ addr_policy_covers()

static int addr_policy_covers ( addr_policy_t a,
addr_policy_t b 
)
static

Return true iff the address policy a covers every case that would be covered by b, so that a,b is redundant.

Definition at line 1553 of file policies.c.

References addr_policy_t::addr, addr_policy_t::maskbits, tor_addr_compare_masked(), and tor_addr_family().

◆ addr_policy_free_()

void addr_policy_free_ ( addr_policy_t p)

Release all storage held by p.

Definition at line 3107 of file policies.c.

References addr_policy_t::is_canonical, addr_policy_t::refcnt, tor_assert(), and tor_free.

◆ addr_policy_intersects()

static int addr_policy_intersects ( addr_policy_t a,
addr_policy_t b 
)
static

Return true iff the address policies a and b intersect, that is, there exists an address/port that is covered by a that is also covered by b.

Definition at line 1577 of file policies.c.

References addr_policy_t::addr, addr_policy_t::maskbits, and tor_addr_compare_masked().

◆ addr_policy_list_free_()

void addr_policy_list_free_ ( smartlist_t lst)

Release all storage held by p.

Definition at line 3097 of file policies.c.

References SMARTLIST_FOREACH.

◆ addr_policy_permits_address()

static int addr_policy_permits_address ( uint32_t  addr,
uint16_t  port,
smartlist_t policy 
)
static

Return true iff policy (possibly NULL) will allow a connection to addr:port. addr is an IPv4 address given in host order.

Definition at line 396 of file policies.c.

References addr_policy_permits_tor_addr(), and tor_addr_from_ipv4h.

Referenced by authdir_policy_badexit_address(), authdir_policy_permits_address(), and authdir_policy_valid_address().

◆ addr_policy_permits_tor_addr()

static int addr_policy_permits_tor_addr ( const tor_addr_t addr,
uint16_t  port,
smartlist_t policy 
)
static

Return true iff policy (possibly NULL) will allow a connection to addr:port.

Definition at line 373 of file policies.c.

References ADDR_POLICY_ACCEPTED, ADDR_POLICY_PROBABLY_ACCEPTED, ADDR_POLICY_PROBABLY_REJECTED, and ADDR_POLICY_REJECTED.

Referenced by addr_policy_permits_address(), dir_policy_permits_address(), fascist_firewall_allows_address(), and socks_policy_permits_address().

◆ append_exit_policy_string()

STATIC void append_exit_policy_string ( smartlist_t **  policy,
const char *  more 
)

Add the exit policy described by more to policy.

Definition at line 1598 of file policies.c.

References parse_addr_policy().

Referenced by policies_exit_policy_append_reject_star(), policies_parse_exit_policy_from_options(), and policies_parse_exit_policy_internal().

◆ authdir_policy_badexit_address()

int authdir_policy_badexit_address ( uint32_t  addr,
uint16_t  port 
)

Return 1 if addr:port should be marked as a bad exit, based on authdir_badexit_policy. Else return 0.

Definition at line 1157 of file policies.c.

References addr_is_in_cc_list(), addr_policy_permits_address(), and authdir_badexit_policy.

◆ authdir_policy_permits_address()

int authdir_policy_permits_address ( uint32_t  addr,
uint16_t  port 
)

Return 1 if addr:port is permitted to publish to our directory, based on authdir_reject_policy. Else return 0.

Definition at line 1135 of file policies.c.

References addr_is_in_cc_list(), addr_policy_permits_address(), and authdir_reject_policy.

◆ authdir_policy_valid_address()

int authdir_policy_valid_address ( uint32_t  addr,
uint16_t  port 
)

Return 1 if addr:port is considered valid in our directory, based on authdir_invalid_policy. Else return 0.

Definition at line 1146 of file policies.c.

References addr_is_in_cc_list(), addr_policy_permits_address(), and authdir_invalid_policy.

◆ compare_known_tor_addr_to_addr_policy()

static addr_policy_result_t compare_known_tor_addr_to_addr_policy ( const tor_addr_t addr,
uint16_t  port,
const smartlist_t policy 
)
static

Helper for compare_tor_addr_to_addr_policy. Implements the case where addr and port are both known.

Definition at line 1408 of file policies.c.

References SMARTLIST_FOREACH_BEGIN.

◆ compare_known_tor_addr_to_addr_policy_noport()

static addr_policy_result_t compare_known_tor_addr_to_addr_policy_noport ( const tor_addr_t addr,
const smartlist_t policy 
)
static

Helper for compare_tor_addr_to_addr_policy. Implements the case where addr is known but port is not.

Definition at line 1436 of file policies.c.

References SMARTLIST_FOREACH_BEGIN.

◆ compare_tor_addr_to_node_policy()

addr_policy_result_t compare_tor_addr_to_node_policy ( const tor_addr_t addr,
uint16_t  port,
const node_t node 
)

Decide whether addr:port is probably or definitely accepted or rejected by node. See compare_tor_addr_to_addr_policy for details on addr/port interpretation.

Definition at line 2918 of file policies.c.

References ADDR_POLICY_PROBABLY_REJECTED, ADDR_POLICY_REJECTED, compare_tor_addr_to_short_policy(), routerinfo_t::exit_policy, microdesc_t::exit_policy, routerinfo_t::ipv6_exit_policy, microdesc_t::ipv6_exit_policy, node_t::rejects_all, and tor_addr_family().

Referenced by circuit_stream_is_being_handled(), connection_ap_get_begincell_flags(), and router_exit_policy_all_nodes_reject().

◆ compare_tor_addr_to_short_policy()

addr_policy_result_t compare_tor_addr_to_short_policy ( const tor_addr_t addr,
uint16_t  port,
const short_policy_t policy 
)

See whether the addr:port address is likely to be accepted or rejected by the summarized policy policy. Return values are as for compare_tor_addr_to_addr_policy. Unlike the regular addr_policy functions, requires the port be specified.

Definition at line 2853 of file policies.c.

References tor_addr_is_null(), and tor_assert().

Referenced by compare_tor_addr_to_node_policy(), and router_compare_to_my_exit_policy().

◆ compare_unknown_tor_addr_to_addr_policy()

static addr_policy_result_t compare_unknown_tor_addr_to_addr_policy ( uint16_t  port,
const smartlist_t policy 
)
static

Helper for compare_tor_addr_to_addr_policy. Implements the case where port is known but address is not.

Definition at line 1479 of file policies.c.

References SMARTLIST_FOREACH_BEGIN.

◆ dir_policy_permits_address()

int dir_policy_permits_address ( const tor_addr_t addr)

Return 1 if addr is permitted to connect to our dir port, based on dir_policy. Else return 0.

Definition at line 1099 of file policies.c.

References addr_policy_permits_tor_addr(), and dir_policy.

◆ exit_policy_is_general_exit()

int exit_policy_is_general_exit ( smartlist_t policy)

Return true iff ri is "useful as an exit node", meaning it allows exit to at least one /8 address space for each of ports 80 and 443.

Definition at line 2261 of file policies.c.

References exit_policy_is_general_exit_helper().

◆ exit_policy_is_general_exit_helper()

static int exit_policy_is_general_exit_helper ( smartlist_t policy,
int  port 
)
static

Return 1 if there is at least one /8 subnet in policy that allows exiting to port. Otherwise, return 0.

Definition at line 2213 of file policies.c.

References SMARTLIST_FOREACH_BEGIN, tor_addr_family(), tor_addr_from_ipv4h, tor_addr_to_ipv4h(), and tor_assert().

Referenced by exit_policy_is_general_exit().

◆ exit_policy_remove_redundancies()

static void exit_policy_remove_redundancies ( smartlist_t dest)
static

Detect and excise "dead code" from the policy *dest.

Definition at line 1698 of file policies.c.

◆ fascist_firewall_allows_address()

STATIC int fascist_firewall_allows_address ( const tor_addr_t addr,
uint16_t  port,
smartlist_t firewall_policy,
int  pref_only,
int  pref_ipv6 
)

Return true iff we think our firewall will let us make a connection to addr:port.

If we are configured as a server, ignore any address family preference and just use IPv4. Otherwise:

  • return false for all IPv4 addresses:
    • if ClientUseIPv4 is 0, or if pref_only and pref_ipv6 are both true;
  • return false for all IPv6 addresses:

Return false if addr is NULL or tor_addr_is_null(), or if port is 0.

Definition at line 419 of file policies.c.

References addr_policy_permits_tor_addr(), or_options_t::ClientUseIPv4, fascist_firewall_use_ipv6(), tor_addr_family(), and tor_addr_is_null().

◆ fascist_firewall_allows_address_addr()

int fascist_firewall_allows_address_addr ( const tor_addr_t addr,
uint16_t  port,
firewall_connection_t  fw_connection,
int  pref_only,
int  pref_ipv6 
)

Return true iff we think our firewall will let us make a connection to addr:port. Uses ReachableORAddresses or ReachableDirAddresses based on fw_connection. If pref_only is true, return true if addr is in the client's preferred address family, which is IPv6 if pref_ipv6 is true, and IPv4 otherwise. If pref_only is false, ignore pref_ipv6, and return true if addr is allowed.

Definition at line 556 of file policies.c.

Referenced by bridge_passes_guard_filter(), and fascist_firewall_allows_address_ap().

◆ fascist_firewall_allows_address_ap()

static int fascist_firewall_allows_address_ap ( const tor_addr_port_t ap,
firewall_connection_t  fw_connection,
int  pref_only,
int  pref_ipv6 
)
static

Return true iff we think our firewall will let us make a connection to addr:port (ap). Uses ReachableORAddresses or ReachableDirAddresses based on fw_connection. pref_only and pref_ipv6 work as in fascist_firewall_allows_address_addr().

Definition at line 581 of file policies.c.

References fascist_firewall_allows_address_addr(), and tor_assert().

Referenced by fascist_firewall_choose_address_impl().

◆ fascist_firewall_allows_base()

static int fascist_firewall_allows_base ( uint32_t  ipv4h_addr,
uint16_t  ipv4_orport,
uint16_t  ipv4_dirport,
const tor_addr_t ipv6_addr,
uint16_t  ipv6_orport,
uint16_t  ipv6_dirport,
firewall_connection_t  fw_connection,
int  pref_only,
int  pref_ipv6 
)
static

Return true iff we think our firewall will let us make a connection to ipv4h_addr/ipv6_addr. Uses ipv4_orport/ipv6_orport/ReachableORAddresses or ipv4_dirport/ipv6_dirport/ReachableDirAddresses based on IPv4/IPv6 and fw_connection. pref_only and pref_ipv6 work as in fascist_firewall_allows_address_addr().

Definition at line 617 of file policies.c.

Referenced by fascist_firewall_allows_ri_impl(), and fascist_firewall_allows_rs_impl().

◆ fascist_firewall_allows_dir_server()

int fascist_firewall_allows_dir_server ( const dir_server_t ds,
firewall_connection_t  fw_connection,
int  pref_only 
)

Like fascist_firewall_allows_rs(), but takes ds.

Definition at line 770 of file policies.c.

References dir_server_t::fake_status, and fascist_firewall_allows_rs().

◆ fascist_firewall_allows_md_impl()

static int fascist_firewall_allows_md_impl ( const microdesc_t md,
firewall_connection_t  fw_connection,
int  pref_only,
int  pref_ipv6 
)
static

Return true iff we think our firewall will let us make a connection to ipv6_addr:ipv6_orport based on ReachableORAddresses. If fw_connection is FIREWALL_DIR_CONNECTION, returns 0. pref_only and pref_ipv6 work as in fascist_firewall_allows_address_addr().

Definition at line 710 of file policies.c.

◆ fascist_firewall_allows_node()

int fascist_firewall_allows_node ( const node_t node,
firewall_connection_t  fw_connection,
int  pref_only 
)

Like fascist_firewall_allows_base(), but takes node, and looks up pref_ipv6 from node_ipv6_or/dir_preferred().

Definition at line 732 of file policies.c.

Referenced by node_passes_guard_filter().

◆ fascist_firewall_allows_ri_impl()

static int fascist_firewall_allows_ri_impl ( const routerinfo_t ri,
firewall_connection_t  fw_connection,
int  pref_only,
int  pref_ipv6 
)
static

◆ fascist_firewall_allows_rs()

int fascist_firewall_allows_rs ( const routerstatus_t rs,
firewall_connection_t  fw_connection,
int  pref_only 
)

Like fascist_firewall_allows_base(), but takes rs. When rs is a fake_status from a dir_server_t, it can have a reachable address, even when the corresponding node does not. nodes can be missing addresses when there's no consensus (IPv4 and IPv6), or when there is a microdescriptor consensus, but no microdescriptors (microdescriptors have IPv6, the microdesc consensus does not).

Definition at line 686 of file policies.c.

Referenced by fascist_firewall_allows_dir_server().

◆ fascist_firewall_allows_rs_impl()

static int fascist_firewall_allows_rs_impl ( const routerstatus_t rs,
firewall_connection_t  fw_connection,
int  pref_only,
int  pref_ipv6 
)
static

Like fascist_firewall_allows_rs, but takes pref_ipv6.

Definition at line 664 of file policies.c.

References routerstatus_t::addr, routerstatus_t::dir_port, fascist_firewall_allows_base(), routerstatus_t::ipv6_addr, routerstatus_t::ipv6_orport, and routerstatus_t::or_port.

◆ fascist_firewall_choose_address()

STATIC const tor_addr_port_t* fascist_firewall_choose_address ( const tor_addr_port_t a,
const tor_addr_port_t b,
int  want_a,
firewall_connection_t  fw_connection,
int  pref_only,
int  pref_ipv6 
)

If a and b are both valid and preferred by fw_connection, choose one based on want_a and return it. Otherwise, return whichever is preferred. If neither are preferred, and pref_only is false:

  • If a and b are both allowed by fw_connection, choose one based on want_a and return it.
  • Otherwise, return whichever is preferred. Otherwise, return NULL.

Definition at line 831 of file policies.c.

References fascist_firewall_choose_address_impl().

◆ fascist_firewall_choose_address_base()

static void fascist_firewall_choose_address_base ( const tor_addr_t ipv4_addr,
uint16_t  ipv4_orport,
uint16_t  ipv4_dirport,
const tor_addr_t ipv6_addr,
uint16_t  ipv6_orport,
uint16_t  ipv6_dirport,
firewall_connection_t  fw_connection,
int  pref_only,
int  pref_ipv6,
tor_addr_port_t ap 
)
static

Copy an address and port into ap that we think our firewall will let us connect to. Uses ipv4_addr/ipv6_addr and ipv4_orport/ipv6_orport/ReachableORAddresses or ipv4_dirport/ipv6_dirport/ReachableDirAddresses based on IPv4/IPv6 and fw_connection. If pref_only, only choose preferred addresses. In either case, choose a preferred address before an address that's not preferred. If both addresses could be chosen (they are both preferred or both allowed) choose IPv6 if pref_ipv6 is true, otherwise choose IPv4.

Definition at line 864 of file policies.c.

References tor_addr_copy(), tor_addr_make_null(), and tor_assert().

Referenced by fascist_firewall_choose_address_ipv4h().

◆ fascist_firewall_choose_address_dir_server()

void fascist_firewall_choose_address_dir_server ( const dir_server_t ds,
firewall_connection_t  fw_connection,
int  pref_only,
tor_addr_port_t ap 
)

◆ fascist_firewall_choose_address_impl()

static const tor_addr_port_t* fascist_firewall_choose_address_impl ( const tor_addr_port_t a,
const tor_addr_port_t b,
int  want_a,
firewall_connection_t  fw_connection,
int  pref_only,
int  pref_ipv6 
)
static

If a and b are both valid and allowed by fw_connection, choose one based on want_a and return it. Otherwise, return whichever is allowed. Otherwise, return NULL. pref_only and pref_ipv6 work as in fascist_firewall_allows_address_addr().

Definition at line 793 of file policies.c.

References fascist_firewall_allows_address_ap().

Referenced by fascist_firewall_choose_address().

◆ fascist_firewall_choose_address_ipv4h()

static void fascist_firewall_choose_address_ipv4h ( uint32_t  ipv4h_addr,
uint16_t  ipv4_orport,
uint16_t  ipv4_dirport,
const tor_addr_t ipv6_addr,
uint16_t  ipv6_orport,
uint16_t  ipv6_dirport,
firewall_connection_t  fw_connection,
int  pref_only,
int  pref_ipv6,
tor_addr_port_t ap 
)
static

Like fascist_firewall_choose_address_base(), but takes a host-order IPv4 address as the first parameter.

Definition at line 910 of file policies.c.

References fascist_firewall_choose_address_base(), tor_addr_from_ipv4h, tor_addr_make_null(), and tor_assert().

◆ fascist_firewall_choose_address_node()

void fascist_firewall_choose_address_node ( const node_t node,
firewall_connection_t  fw_connection,
int  pref_only,
tor_addr_port_t ap 
)

Like fascist_firewall_choose_address_base(), but takes node, and looks up the node's IPv6 preference rather than taking an argument for pref_ipv6.

Definition at line 1022 of file policies.c.

References tor_addr_make_null(), and tor_assert().

Referenced by extend_info_from_node().

◆ fascist_firewall_choose_address_rs()

void fascist_firewall_choose_address_rs ( const routerstatus_t rs,
firewall_connection_t  fw_connection,
int  pref_only,
tor_addr_port_t ap 
)

Like fascist_firewall_choose_address_base(), but takes rs. Consults the corresponding node, then falls back to rs if node is NULL. This should only happen when there's no valid consensus, and rs doesn't correspond to a bridge client's bridge.

Definition at line 984 of file policies.c.

References routerstatus_t::identity_digest, tor_addr_make_null(), and tor_assert().

Referenced by fascist_firewall_choose_address_dir_server().

◆ fascist_firewall_prefer_ipv6_dirport()

int fascist_firewall_prefer_ipv6_dirport ( const or_options_t options)

Do we prefer to connect to IPv6 DirPorts?

(node_ipv6_dir_preferred() doesn't support bridge client per-node IPv6 preferences. There's no reason to use it instead of this function.)

Definition at line 532 of file policies.c.

References or_options_t::ClientPreferIPv6DirPort, and fascist_firewall_prefer_ipv6_impl().

◆ fascist_firewall_prefer_ipv6_impl()

static int fascist_firewall_prefer_ipv6_impl ( const or_options_t options)
static

Do we prefer to connect to IPv6, ignoring ClientPreferIPv6ORPort and ClientPreferIPv6DirPort? If we're unsure, return -1, otherwise, return 1 for IPv6 and 0 for IPv4.

Definition at line 474 of file policies.c.

References or_options_t::ClientUseIPv4, and fascist_firewall_use_ipv6().

Referenced by fascist_firewall_prefer_ipv6_dirport(), and fascist_firewall_prefer_ipv6_orport().

◆ fascist_firewall_prefer_ipv6_orport()

int fascist_firewall_prefer_ipv6_orport ( const or_options_t options)

Do we prefer to connect to IPv6 ORPorts? Use node_ipv6_or_preferred() whenever possible: it supports bridge client per-node IPv6 preferences.

Definition at line 507 of file policies.c.

References or_options_t::ClientAutoIPv6ORPort, or_options_t::ClientPreferIPv6ORPort, and fascist_firewall_prefer_ipv6_impl().

◆ fascist_firewall_use_ipv6()

int fascist_firewall_use_ipv6 ( const or_options_t options)

Is this client configured to use IPv6? Returns true if the client might use IPv6 for some of its connections (including dual-stack and IPv6-only clients), and false if it will never use IPv6 for any connections. Use node_ipv6_or/dir_preferred() when checking a specific node and OR/Dir port: it supports bridge client per-node IPv6 preferences.

Definition at line 458 of file policies.c.

References or_options_t::ClientAutoIPv6ORPort, or_options_t::ClientPreferIPv6DirPort, or_options_t::ClientPreferIPv6ORPort, or_options_t::ClientUseIPv4, or_options_t::ClientUseIPv6, and or_options_t::UseBridges.

Referenced by fascist_firewall_allows_address(), and fascist_firewall_prefer_ipv6_impl().

◆ firewall_is_fascist_dir()

int firewall_is_fascist_dir ( void  )

Return true iff the firewall options, including ClientUseIPv4 0 and ClientUseIPv6 0, might block any Dir address:port combination. Address preferences may still change which address is selected even if this function returns false.

Definition at line 364 of file policies.c.

References reachable_dir_addr_policy.

◆ firewall_is_fascist_or()

int firewall_is_fascist_or ( void  )

Return true iff the firewall options, including ClientUseIPv4 0 and ClientUseIPv6 0, might block any OR address:port combination. Address preferences may still change which address is selected even if this function returns false.

Definition at line 353 of file policies.c.

References reachable_or_addr_policy.

◆ getinfo_helper_policies()

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

Implementation for GETINFO control command: knows the answer for questions about "exit-policy/..."

Definition at line 2999 of file policies.c.

◆ HT_PROTOTYPE()

HT_PROTOTYPE ( HT_GENERATE2(  policy_map,
HT_GENERATE2(  policy_map_ent_t,
HT_GENERATE2(  node,
HT_GENERATE2(  policy_hash,
HT_GENERATE2(  policy_eq 
)

Given a pointer to an addr_policy_t, return a copy of the pointer to the "canonical" copy of that addr_policy_t; the canonical copy is a single reference-counted object.

Definition at line 1375 of file policies.c.

◆ load_policy_from_option()

static int load_policy_from_option ( config_line_t config,
const char *  option_name,
smartlist_t **  policy,
int  assume_action 
)
static

Parse string in the same way that the exit policy is parsed, and put the processed version in *policy. Ignore port specifiers.

Definition at line 1232 of file policies.c.

Referenced by policies_parse_from_options().

◆ MOCK_IMPL()

MOCK_IMPL ( addr_policy_result_t  ,
compare_tor_addr_to_addr_policy  ,
(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy)   
)

Decide whether a given addr:port is definitely accepted, definitely rejected, probably accepted, or probably rejected by a given policy. If addr is 0, we don't know the IP of the target address. If port is 0, we don't know the port of the target address. (At least one of addr and port must be provided. If you want to know whether a policy would definitely reject an unknown address:port, use policy_is_reject_star().)

We could do better by assuming that some ranges never match typical addresses (127.0.0.1, and so on). But we'll try this for now.

Definition at line 1529 of file policies.c.

References ADDR_POLICY_ACCEPTED, and tor_addr_is_null().

◆ parse_addr_policy()

static int parse_addr_policy ( config_line_t cfg,
smartlist_t **  dest,
int  assume_action 
)
static

Given a linked list of config lines containing "accept[6]" and "reject[6]" tokens, parse them and append the result to dest. Return -1 if any tokens are malformed (and don't append any), else return 0.

If assume_action is nonnegative, then insert its action (ADDR_POLICY_ACCEPT or ADDR_POLICY_REJECT) for items that specify no action.

Definition at line 193 of file policies.c.

References smartlist_split_string().

Referenced by append_exit_policy_string(), and policies_parse_exit_policy_internal().

◆ parse_reachable_addresses()

static int parse_reachable_addresses ( void  )
static

Helper: parse the Reachable(Dir|OR)?Addresses fields into reachable_(or|dir)_addr_policy. The options should already have been validated by validate_addr_policies.

Definition at line 256 of file policies.c.

References or_options_t::ReachableAddresses, or_options_t::ReachableDirAddresses, and or_options_t::ReachableORAddresses.

Referenced by policies_parse_from_options().

◆ parse_short_policy()

short_policy_t* parse_short_policy ( const char *  summary)

Convert a summarized policy string into a short_policy_t. Return NULL if the string is not well-formed.

Definition at line 2716 of file policies.c.

◆ policies_copy_addr_to_smartlist()

static void policies_copy_addr_to_smartlist ( smartlist_t addr_list,
const tor_addr_t addr 
)
static

Helper function that adds a copy of addr to a smartlist as long as it is non-NULL and not tor_addr_is_null().

The caller is responsible for freeing all the tor_addr_t* in the smartlist.

Definition at line 2061 of file policies.c.

References tor_addr_is_null().

Referenced by policies_copy_ipv4h_to_smartlist().

◆ policies_copy_ipv4h_to_smartlist()

static void policies_copy_ipv4h_to_smartlist ( smartlist_t addr_list,
uint32_t  ipv4h_addr 
)
static

Helper function that adds ipv4h_addr to a smartlist as a tor_addr_t *, as long as it is not tor_addr_is_null(), by converting it to a tor_addr_t and passing it to policies_add_addr_to_smartlist.

The caller is responsible for freeing all the tor_addr_t* in the smartlist.

Definition at line 2077 of file policies.c.

References policies_copy_addr_to_smartlist(), and tor_addr_from_ipv4h.

◆ policies_copy_outbound_addresses_to_smartlist()

static void policies_copy_outbound_addresses_to_smartlist ( smartlist_t addr_list,
const or_options_t or_options 
)
static

Helper function that adds copies of or_options->OutboundBindAddresses to a smartlist as tor_addr_t *, as long as or_options is non-NULL, and the addresses are not tor_addr_is_null(), by passing them to policies_add_addr_to_smartlist.

The caller is responsible for freeing all the tor_addr_t* in the smartlist.

Definition at line 2094 of file policies.c.

◆ policies_exit_policy_append_reject_star()

void policies_exit_policy_append_reject_star ( smartlist_t **  dest)

Add "reject *:*" to the end of the policy in *dest, allocating *dest as needed.

Definition at line 2197 of file policies.c.

References append_exit_policy_string().

◆ policies_free_all()

void policies_free_all ( void  )

Release all storage held by policy variables.

Definition at line 3128 of file policies.c.

◆ policies_log_first_redundant_entry()

static void policies_log_first_redundant_entry ( const smartlist_t policy)
static

Iterate through policy looking for redundant entries. Log a warning message with the first redundant entry, if any is found.

Definition at line 1857 of file policies.c.

References SMARTLIST_FOREACH_BEGIN, tor_addr_family(), and tor_assert().

Referenced by policies_parse_exit_policy_internal().

◆ policies_parse_exit_policy()

int policies_parse_exit_policy ( config_line_t cfg,
smartlist_t **  dest,
exit_policy_parser_cfg_t  options,
const smartlist_t configured_addresses 
)

Parse exit policy in cfg into dest smartlist.

Prepend an entry that rejects all IPv6 destinations unless EXIT_POLICY_IPV6_ENABLED bit is set in options bitmask.

If EXIT_POLICY_REJECT_PRIVATE bit is set in options:

  • prepend an entry that rejects all destinations in all netblocks reserved for private use.
  • prepend entries that reject the advertised relay addresses in configured_addresses If EXIT_POLICY_REJECT_LOCAL_INTERFACES bit is set in options:
  • prepend entries that reject publicly routable addresses on this exit relay by calling policies_parse_exit_policy_internal
  • prepend entries that reject the outbound bind addresses in configured_addresses
  • prepend entries that reject all configured port addresses

If EXIT_POLICY_ADD_DEFAULT bit is set in options, append default exit policy entries to result smartlist.

Definition at line 2035 of file policies.c.

◆ policies_parse_exit_policy_from_options()

int policies_parse_exit_policy_from_options ( const or_options_t or_options,
uint32_t  local_address,
const tor_addr_t ipv6_local_address,
smartlist_t **  result 
)

Parse ExitPolicy member of or_options into result smartlist. If or_options->IPv6Exit is false, prepend an entry that rejects all IPv6 destinations.

If or_options->ExitPolicyRejectPrivate is true:

  • prepend an entry that rejects all destinations in all netblocks reserved for private use.
  • if local_address is non-zero, treat it as a host-order IPv4 address, and add it to the list of configured addresses.
  • if ipv6_local_address is non-NULL, and not the null tor_addr_t, add it to the list of configured addresses. If or_options->ExitPolicyRejectLocalInterfaces is true:
  • if or_options->OutboundBindAddresses[][0] (=IPv4) is not the null tor_addr_t, add it to the list of configured addresses.
  • if or_options->OutboundBindAddresses[][1] (=IPv6) is not the null tor_addr_t, add it to the list of configured addresses.

If or_options->BridgeRelay is false, append entries of default Tor exit policy into result smartlist.

If or_options->ExitRelay is false, or is auto without specifying an exit policy, then make our exit policy into "reject *:*" regardless.

Definition at line 2134 of file policies.c.

References append_exit_policy_string(), or_options_t::ExitPolicy, or_options_t::ExitRelay, or_options_t::IPv6Exit, and or_options_t::ReducedExitPolicy.

Referenced by validate_addr_policies().

◆ policies_parse_exit_policy_internal()

static int policies_parse_exit_policy_internal ( config_line_t cfg,
smartlist_t **  dest,
int  ipv6_exit,
int  rejectprivate,
const smartlist_t configured_addresses,
int  reject_interface_addresses,
int  reject_configured_port_addresses,
int  add_default_policy,
int  add_reduced_policy 
)
static

Parse the exit policy cfg into the linked list *dest.

If ipv6_exit is false, prepend "reject *6:*" to the policy.

If configured_addresses contains addresses:

  • prepend entries that reject the addresses in this list. These may be the advertised relay addresses and/or the outbound bind addresses, depending on the ExitPolicyRejectPrivate and ExitPolicyRejectLocalInterfaces settings. If rejectprivate is true:
  • prepend "reject private:*" to the policy. If reject_interface_addresses is true:
  • prepend entries that reject publicly routable interface addresses on this exit relay by calling policies_parse_exit_policy_reject_private If reject_configured_port_addresses is true:
  • prepend entries that reject all configured port addresses

If cfg doesn't end in an absolute accept or reject and if add_default_policy is true, add the default exit policy afterwards.

Return -1 if we can't parse cfg, else return 0.

This function is used to parse the exit policy from our torrc. For the functions used to parse the exit policy from a router descriptor, see router_add_exit_policy.

Definition at line 1967 of file policies.c.

References append_exit_policy_string(), parse_addr_policy(), policies_log_first_redundant_entry(), and policies_parse_exit_policy_reject_private().

◆ policies_parse_exit_policy_reject_private()

void policies_parse_exit_policy_reject_private ( smartlist_t **  dest,
int  ipv6_exit,
const smartlist_t configured_addresses,
int  reject_interface_addresses,
int  reject_configured_port_addresses 
)

Reject private helper for policies_parse_exit_policy_internal: rejects publicly routable addresses on this exit relay.

Add reject entries to the linked list *dest:

  • if configured_addresses is non-NULL, add entries that reject each tor_addr_t in the list as a destination.
  • if reject_interface_addresses is true, add entries that reject each public IPv4 and IPv6 address of each interface on this machine.
  • if reject_configured_port_addresses is true, add entries that reject each IPv4 and IPv6 address configured for a port.

IPv6 entries are only added if ipv6_exit is true. (All IPv6 addresses are already blocked by policies_parse_exit_policy_internal if ipv6_exit is false.)

The list in dest is created as needed.

Definition at line 1800 of file policies.c.

References addr_policy_append_reject_addr_list_filter(), SMARTLIST_FOREACH_BEGIN, and tor_assert().

Referenced by policies_parse_exit_policy_internal().

◆ policies_parse_from_options()

int policies_parse_from_options ( const or_options_t options)

◆ policies_set_node_exitpolicy_to_reject_all()

void policies_set_node_exitpolicy_to_reject_all ( node_t node)

Replace the exit policy of node with reject *:*

Definition at line 2205 of file policies.c.

References node_t::rejects_all.

◆ policy_dump_to_string()

char* policy_dump_to_string ( const smartlist_t policy_list,
int  include_ipv4,
int  include_ipv6 
)

Given policy_list, a list of addr_policy_t, produce a string representation of the list. If include_ipv4 is true, include IPv4 entries. If include_ipv6 is true, include IPv6 entries.

Definition at line 2956 of file policies.c.

References SMARTLIST_FOREACH_BEGIN, and tor_addr_family().

◆ policy_expand_private()

void policy_expand_private ( smartlist_t **  policy)

Replace all "private" entries in *policy with their expanded equivalents.

Definition at line 104 of file policies.c.

References addr_policy_t::addr, addr_policy_t::is_canonical, addr_policy_t::is_private, addr_policy_t::maskbits, private_nets, smartlist_add(), SMARTLIST_FOREACH_BEGIN, and tor_addr_parse_mask_ports().

◆ policy_expand_unspec()

void policy_expand_unspec ( smartlist_t **  policy)

Expand each of the AF_UNSPEC elements in *policy (which indicate protocol-neutral wildcards) into a pair of wildcard elements: one IPv4- specific and one IPv6-specific.

Definition at line 144 of file policies.c.

References addr_policy_t::is_canonical, smartlist_add(), SMARTLIST_FOREACH_BEGIN, and tor_addr_family().

◆ policy_hash()

static unsigned int policy_hash ( const policy_map_ent_t ent)
static

◆ policy_is_reject_star()

int policy_is_reject_star ( const smartlist_t policy,
sa_family_t  family,
int  default_reject 
)

Return false if policy might permit access to some addr:port; otherwise if we are certain it rejects everything, return true. If no part of policy matches, return default_reject. NULL policies are allowed, and treated as empty.

Definition at line 2275 of file policies.c.

References SMARTLIST_FOREACH_BEGIN, and tor_addr_family().

◆ policy_summarize()

char* policy_summarize ( smartlist_t policy,
sa_family_t  family 
)

Create a string representing a summary for an exit policy. The summary will either be an "accept" plus a comma-separated list of port ranges or a "reject" plus port-ranges, depending on which is shorter.

If no exits are allowed at all then "reject 1-65535" is returned. If no ports are blocked instead of "reject " we return "accept 1-65535". (These are an exception to the shorter-representation-wins rule).

Definition at line 2604 of file policies.c.

◆ policy_summary_accept()

static void policy_summary_accept ( smartlist_t summary,
uint16_t  prt_min,
uint16_t  prt_max,
sa_family_t  family 
)
static

Mark port ranges as accepted if they are below the reject_count for family

Definition at line 2475 of file policies.c.

◆ policy_summary_add_item()

static void policy_summary_add_item ( smartlist_t summary,
addr_policy_t p 
)
static

Add a single exit policy item to our summary:

If it is an accept, ignore it unless it is for all IP addresses ("*", i.e. its prefixlen/maskbits is 0). Otherwise call policy_summary_accept().

If it is a reject, ignore it if it is about one of the private networks. Otherwise call policy_summary_reject().

Definition at line 2563 of file policies.c.

◆ policy_summary_create()

static smartlist_t* policy_summary_create ( void  )
static

Create a new exit policy summary, initially only with a single port 1-64k item

Definition at line 2375 of file policies.c.

◆ policy_summary_item_split()

static policy_summary_item_t* policy_summary_item_split ( policy_summary_item_t old,
uint16_t  new_starts 
)
static

Split the summary item in item at the port new_starts. The current item is changed to end at new-starts - 1, the new item copies reject_count and accepted from the old item, starts at new_starts and ends at the port where the original item previously ended.

Definition at line 2399 of file policies.c.

◆ policy_summary_reject()

static void policy_summary_reject ( smartlist_t summary,
maskbits_t  maskbits,
uint16_t  prt_min,
uint16_t  prt_max,
sa_family_t  family 
)
static

Count the number of addresses in a network in family with prefixlen maskbits against the given portrange.

Definition at line 2498 of file policies.c.

◆ policy_summary_split()

static int policy_summary_split ( smartlist_t summary,
uint16_t  prt_min,
uint16_t  prt_max 
)
static

Split an exit policy summary so that prt_min and prt_max fall at exactly the start and end of an item respectively.

Definition at line 2444 of file policies.c.

◆ policy_write_item()

int policy_write_item ( char *  buf,
size_t  buflen,
const addr_policy_t policy,
int  format_for_desc 
)

Write a single address policy to the buf_len byte buffer at buf. Return the number of characters written, or -1 on failure.

Definition at line 2299 of file policies.c.

References addr_policy_t::addr, addr_policy_t::is_private, addr_policy_t::maskbits, addr_policy_t::policy_type, addr_policy_t::prt_max, addr_policy_t::prt_min, TOR_ADDR_BUF_LEN, tor_addr_family(), tor_addr_to_str(), and tor_snprintf().

◆ short_policy_free_()

void short_policy_free_ ( short_policy_t policy)

Release all storage held in policy.

Definition at line 2843 of file policies.c.

References tor_free.

◆ short_policy_is_reject_star()

int short_policy_is_reject_star ( const short_policy_t policy)

Return true iff policy seems reject all ports

Definition at line 2901 of file policies.c.

References short_policy_t::entries, short_policy_t::is_accept, short_policy_t::n_entries, and tor_assert().

Referenced by node_exit_policy_rejects_all().

◆ single_addr_policy_eq()

static int single_addr_policy_eq ( const addr_policy_t a,
const addr_policy_t b 
)
static

Compare two provided address policy items, and renturn -1, 0, or 1 if the first is less than, equal to, or greater than the second.

Definition at line 1295 of file policies.c.

◆ socks_policy_permits_address()

int socks_policy_permits_address ( const tor_addr_t addr)

Return 1 if addr is permitted to connect to our socks port, based on socks_policy. Else return 0.

Definition at line 1108 of file policies.c.

References addr_policy_permits_tor_addr(), and socks_policy.

◆ validate_addr_policies()

int validate_addr_policies ( const or_options_t options,
char **  msg 
)

Config helper: If there's any problem with the policy configuration options in options, return -1 and set msg to a newly allocated description of the error. Else return 0.

Definition at line 1171 of file policies.c.

References policies_parse_exit_policy_from_options().

◆ write_short_policy()

char* write_short_policy ( const short_policy_t policy)

Variable Documentation

◆ authdir_badexit_policy

smartlist_t* authdir_badexit_policy = NULL
static

Policy that addresses for incoming router descriptors must not match in order to not be marked as BadExit.

Definition at line 58 of file policies.c.

Referenced by authdir_policy_badexit_address(), and policies_parse_from_options().

◆ authdir_invalid_policy

smartlist_t* authdir_invalid_policy = NULL
static

Policy that addresses for incoming router descriptors must match in order to be marked as valid in our networkstatus.

Definition at line 55 of file policies.c.

Referenced by authdir_policy_valid_address(), and policies_parse_from_options().

◆ authdir_reject_policy

smartlist_t* authdir_reject_policy = NULL
static

Policy that addresses for incoming router descriptors must match in order to be published by us.

Definition at line 52 of file policies.c.

Referenced by authdir_policy_permits_address(), and policies_parse_from_options().

◆ dir_policy

smartlist_t* dir_policy = NULL
static

Policy that addresses for incoming directory connections must match.

Definition at line 49 of file policies.c.

Referenced by dir_policy_permits_address(), and policies_parse_from_options().

◆ private_nets

const char* private_nets[]
static
Initial value:
= {
"0.0.0.0/8", "169.254.0.0/16",
"127.0.0.0/8", "192.168.0.0/16", "10.0.0.0/8", "172.16.0.0/12",
"[::]/8",
"[fc00::]/7", "[fe80::]/10", "[fec0::]/10", "[ff00::]/8", "[::]/127",
NULL
}

Private networks. This list is used in two places, once to expand the "private" keyword when parsing our own exit policy, secondly to ignore just such networks when building exit policy summaries. It is important that all authorities agree on that list when creating summaries, so don't just change this without a proper migration plan and a proposal and stuff.

Definition at line 82 of file policies.c.

Referenced by policy_expand_private().

◆ reachable_dir_addr_policy

smartlist_t* reachable_dir_addr_policy = NULL
static

Parsed addr_policy_t describing which addresses we believe we can connect to directories at.

Definition at line 65 of file policies.c.

Referenced by firewall_is_fascist_dir().

◆ reachable_or_addr_policy

smartlist_t* reachable_or_addr_policy = NULL
static

Parsed addr_policy_t describing which addresses we believe we can start circuits at.

Definition at line 62 of file policies.c.

Referenced by firewall_is_fascist_or().

◆ socks_policy

smartlist_t* socks_policy = NULL
static

Policy that addresses for incoming SOCKS connections must match.

Definition at line 47 of file policies.c.

Referenced by policies_parse_from_options(), and socks_policy_permits_address().