Tor  0.4.7.0-alpha-dev
Macros | Functions | Variables
routerset.c File Reference

Functions and structures to handle set-type selection of routers by name, ID, address, etc. More...

#include "core/or/or.h"
#include "core/or/policies.h"
#include "feature/client/bridges.h"
#include "feature/dirparse/policy_parse.h"
#include "feature/nodelist/nickname.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerset.h"
#include "lib/conf/conftypes.h"
#include "lib/confmgt/typedvar.h"
#include "lib/encoding/confline.h"
#include "lib/geoip/geoip.h"
#include "core/or/addr_policy_st.h"
#include "core/or/extend_info_st.h"
#include "feature/nodelist/node_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerstatus_st.h"
#include "lib/confmgt/var_type_def_st.h"

Go to the source code of this file.

Functions

routerset_t * routerset_new (void)
 
STATIC char * routerset_get_countryname (const char *c)
 
void routerset_refresh_countries (routerset_t *target)
 
int routerset_parse (routerset_t *target, const char *s, const char *description)
 
void routerset_union (routerset_t *target, const routerset_t *source)
 
int routerset_is_list (const routerset_t *set)
 
int routerset_needs_geoip (const routerset_t *set)
 
int routerset_is_empty (const routerset_t *set)
 
int routerset_len (const routerset_t *set)
 
static int routerset_contains2 (const routerset_t *set, const tor_addr_t *addr, uint16_t orport, const tor_addr_t *addr2, uint16_t orport2, const char *nickname, const char *id_digest, country_t country)
 
STATIC int routerset_contains (const routerset_t *set, const tor_addr_t *addr, uint16_t orport, const char *nickname, const char *id_digest, country_t country)
 
int routerset_add_unknown_ccs (routerset_t **setp, int only_if_some_cc_set)
 
int routerset_contains_extendinfo (const routerset_t *set, const extend_info_t *ei)
 
int routerset_contains_router (const routerset_t *set, const routerinfo_t *ri, country_t country)
 
int routerset_contains_routerstatus (const routerset_t *set, const routerstatus_t *rs, country_t country)
 
int routerset_contains_node (const routerset_t *set, const node_t *node)
 
int routerset_contains_bridge (const routerset_t *set, const bridge_info_t *bridge)
 
void routerset_get_all_nodes (smartlist_t *out, const routerset_t *routerset, const routerset_t *excludeset, int running_only)
 
void routerset_subtract_nodes (smartlist_t *lst, const routerset_t *routerset)
 
char * routerset_to_string (const routerset_t *set)
 
int routerset_equal (const routerset_t *old, const routerset_t *new)
 
void routerset_free_ (routerset_t *routerset)
 
static int routerset_kv_parse (void *target, const config_line_t *line, char **errmsg, const void *params)
 
static char * routerset_encode (const void *value, const void *params)
 
static void routerset_clear (void *value, const void *params)
 
static int routerset_copy (void *dest, const void *src, const void *params)
 
static void routerset_mark_fragile (void *target, const void *params)
 

Variables

static const var_type_fns_t routerset_type_fns
 
const var_type_def_t ROUTERSET_type_defn
 

Detailed Description

Functions and structures to handle set-type selection of routers by name, ID, address, etc.

This module implements the routerset_t data structure, whose purpose is to specify a set of relays based on a list of their identities or properties. Routersets can restrict relays by IP address mask, identity fingerprint, country codes, and nicknames (deprecated).

Routersets are typically used for user-specified restrictions, and are created by invoking routerset_new and routerset_parse from config.c and confmgt.c. To use a routerset, invoke one of routerset_contains_...() functions , or use routerstatus_get_all_nodes() / routerstatus_subtract_nodes() to manipulate a smartlist of node_t pointers.

Country-code restrictions are implemented in geoip.c.

Definition in file routerset.c.

Function Documentation

◆ routerset_add_unknown_ccs()

int routerset_add_unknown_ccs ( routerset_t **  setp,
int  only_if_some_cc_set 
)

If *setp includes at least one country code, or if only_some_cc_set is 0, add the ?? and A1 country codes to *setp, creating it as needed. Return true iff *setp changed.

Definition at line 272 of file routerset.c.

◆ routerset_clear()

static void routerset_clear ( void *  value,
const void *  params 
)
static

config helper: free and clear a routerset-typed variable.

Clear the routerset_t** passed as value.

Definition at line 551 of file routerset.c.

◆ routerset_contains()

STATIC int routerset_contains ( const routerset_t *  set,
const tor_addr_t addr,
uint16_t  orport,
const char *  nickname,
const char *  id_digest,
country_t  country 
)

Helper. Like routerset_contains2() but for a single IP/port combo.

Definition at line 259 of file routerset.c.

Referenced by routerset_contains_bridge(), and routerset_contains_routerstatus().

◆ routerset_contains2()

static int routerset_contains2 ( const routerset_t *  set,
const tor_addr_t addr,
uint16_t  orport,
const tor_addr_t addr2,
uint16_t  orport2,
const char *  nickname,
const char *  id_digest,
country_t  country 
)
static

Helper. Return true iff set contains a router based on the other provided fields. Return higher values for more specific subentries: a single router is more specific than an address range of routers, which is more specific in turn than a country code.

(If country is -1, then we take the country from addr.)

Definition at line 228 of file routerset.c.

Referenced by routerset_contains(), routerset_contains_extendinfo(), and routerset_contains_router().

◆ routerset_contains_bridge()

int routerset_contains_bridge ( const routerset_t *  set,
const bridge_info_t bridge 
)

Return true iff routerset contains the bridge bridge.

Definition at line 365 of file routerset.c.

Referenced by bridge_passes_guard_filter(), and fetch_bridge_descriptors().

◆ routerset_contains_extendinfo()

int routerset_contains_extendinfo ( const routerset_t *  set,
const extend_info_t ei 
)

Return true iff we can tell that ei is a member of set.

Definition at line 308 of file routerset.c.

◆ routerset_contains_node()

int routerset_contains_node ( const routerset_t *  set,
const node_t node 
)

Return true iff node is in set.

Definition at line 353 of file routerset.c.

Referenced by node_passes_guard_filter(), pick_restricted_middle_node(), router_find_exact_exit_enclave(), and routerset_subtract_nodes().

◆ routerset_contains_router()

int routerset_contains_router ( const routerset_t *  set,
const routerinfo_t ri,
country_t  country 
)

Return true iff ri is in set. If country is -1, we look up the country.

Definition at line 328 of file routerset.c.

Referenced by router_should_check_reachability(), and routerset_contains_node().

◆ routerset_contains_routerstatus()

int routerset_contains_routerstatus ( const routerset_t *  set,
const routerstatus_t rs,
country_t  country 
)

Return true iff rs is in set. If country is -1, we look up the country.

Definition at line 339 of file routerset.c.

Referenced by routerset_contains_node().

◆ routerset_copy()

static int routerset_copy ( void *  dest,
const void *  src,
const void *  params 
)
static

config helper: copy a routerset-typed variable.

Takes it input from a routerset_t** in src; writes its output to a routerset_t** in dest. Returns 0 on success, -1 on (impossible) failure.

Definition at line 566 of file routerset.c.

◆ routerset_encode()

static char* routerset_encode ( const void *  value,
const void *  params 
)
static

config helper: encode a routerset-typed variable.

Return a newly allocated string containing the value of the routerset_t** passed as value.

Definition at line 538 of file routerset.c.

◆ routerset_equal()

int routerset_equal ( const routerset_t *  old,
const routerset_t *  new 
)

Helper: return true iff old and new are both NULL, or both non-NULL equal routersets.

Definition at line 439 of file routerset.c.

◆ routerset_free_()

void routerset_free_ ( routerset_t *  routerset)

Free all storage held in routerset.

Definition at line 465 of file routerset.c.

◆ routerset_get_all_nodes()

void routerset_get_all_nodes ( smartlist_t out,
const routerset_t *  routerset,
const routerset_t *  excludeset,
int  running_only 
)

Add every known node_t that is a member of routerset to out, but never add any that are part of excludeset. If running_only, only add the running ones.

Definition at line 379 of file routerset.c.

◆ routerset_get_countryname()

STATIC char* routerset_get_countryname ( const char *  c)

If c is a country code in the form {cc}, return a newly allocated string holding the "cc" part. Else, return NULL.

Definition at line 66 of file routerset.c.

◆ routerset_is_empty()

int routerset_is_empty ( const routerset_t *  set)

Return true iff there are no entries in set.

Definition at line 204 of file routerset.c.

Referenced by addressmap_clear_excluded_trackexithosts(), and routerset_equal().

◆ routerset_is_list()

int routerset_is_list ( const routerset_t *  set)

Return true iff set lists only nicknames and digests, and includes no IP ranges or countries.

Definition at line 188 of file routerset.c.

Referenced by routerset_get_all_nodes().

◆ routerset_kv_parse()

static int routerset_kv_parse ( void *  target,
const config_line_t line,
char **  errmsg,
const void *  params 
)
static

config helper: parse a routerset-typed variable.

Takes as input as a single line in line; writes its results into a routerset_t** passed as target. On success return 0; on failure return -1 and store an error message into *errmsg.

Definition at line 499 of file routerset.c.

◆ routerset_len()

int routerset_len ( const routerset_t *  set)

Return the number of entries in set. This does NOT return a negative value.

Definition at line 212 of file routerset.c.

◆ routerset_needs_geoip()

int routerset_needs_geoip ( const routerset_t *  set)

Return true iff we need a GeoIP IP-to-country database to make sense of set.

Definition at line 197 of file routerset.c.

Referenced by options_need_geoip_info().

◆ routerset_new()

routerset_t* routerset_new ( void  )

Return a new empty routerset.

Definition at line 51 of file routerset.c.

◆ routerset_parse()

int routerset_parse ( routerset_t *  target,
const char *  s,
const char *  description 
)

Parse the string s to create a set of routerset entries, and add them to target. In log messages, refer to the string as description. Return 0 on success, -1 on failure.

Three kinds of elements are allowed in routersets: nicknames, IP address patterns, and fingerprints. They may be surrounded by optional space, and must be separated by commas.

Definition at line 115 of file routerset.c.

Referenced by routerset_union().

◆ routerset_refresh_countries()

void routerset_refresh_countries ( routerset_t *  target)

Update the routerset's countries bitarray_t. Called whenever the GeoIP IPv4 database is reloaded.

Definition at line 82 of file routerset.c.

Referenced by refresh_all_country_info().

◆ routerset_subtract_nodes()

void routerset_subtract_nodes ( smartlist_t lst,
const routerset_t *  routerset 
)

Remove every node_t from lst that is in routerset.

Definition at line 413 of file routerset.c.

◆ routerset_to_string()

char* routerset_to_string ( const routerset_t *  set)

Return a new string that when parsed by routerset_parse_string() will yield set.

Definition at line 429 of file routerset.c.

Referenced by routerset_encode(), and routerset_union().

◆ routerset_union()

void routerset_union ( routerset_t *  target,
const routerset_t *  source 
)

Add all members of the set source to target.

Definition at line 174 of file routerset.c.

Variable Documentation

◆ ROUTERSET_type_defn

const var_type_def_t ROUTERSET_type_defn
Initial value:
= {
.name = "RouterList",
.flags = CFLG_NOREPLACE
}
#define CFLG_NOREPLACE
Definition: conftypes.h:194
static const var_type_fns_t routerset_type_fns
Definition: routerset.c:591

Definition of a routerset_t-based configuration type.

Values are mapped to and from strings using the format defined in routerset_parse(): nicknames, IP address patterns, and fingerprints–with optional space, separated by commas.

Empty sets are represented as NULL.

Definition at line 608 of file routerset.c.

◆ routerset_type_fns

const var_type_fns_t routerset_type_fns
static
Initial value:
= {
.kv_parse = routerset_kv_parse,
.encode = routerset_encode,
.clear = routerset_clear,
.copy = routerset_copy,
.mark_fragile = routerset_mark_fragile,
}
static char * routerset_encode(const void *value, const void *params)
Definition: routerset.c:538
static void routerset_clear(void *value, const void *params)
Definition: routerset.c:551
static int routerset_kv_parse(void *target, const config_line_t *line, char **errmsg, const void *params)
Definition: routerset.c:499
static int routerset_copy(void *dest, const void *src, const void *params)
Definition: routerset.c:566

Function table to implement a routerset_t-based configuration type.

Definition at line 591 of file routerset.c.