Macros | Functions | Variables
routerset.c File Reference
#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.


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_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 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 confparse.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 257 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. 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 227 of file routerset.c.

References ADDR_POLICY_REJECTED, bitarray_is_set(), and strmap_get_lc().

Referenced by routerset_contains_bridge(), routerset_contains_extendinfo(), routerset_contains_router(), and routerset_contains_routerstatus().

◆ 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 350 of file routerset.c.

References bridge_get_addr_port(), bridge_get_rsa_id_digest(), routerset_contains(), and tor_assert().

Referenced by bridge_passes_guard_filter(), fetch_bridge_descriptors(), and launch_direct_bridge_descriptor_fetch().

◆ 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 293 of file routerset.c.

References extend_info_t::addr, extend_info_t::identity_digest, extend_info_t::nickname, extend_info_t::port, and routerset_contains().

◆ 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 338 of file routerset.c.

References node_t::country, routerset_contains_router(), and routerset_contains_routerstatus().

Referenced by node_passes_guard_filter(), 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 306 of file routerset.c.

References routerinfo_t::addr, signed_descriptor_t::identity_digest, routerinfo_t::nickname, routerinfo_t::or_port, routerset_contains(), and tor_addr_from_ipv4h.

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 322 of file routerset.c.

References routerstatus_t::addr, routerstatus_t::identity_digest, routerstatus_t::nickname, routerstatus_t::or_port, routerset_contains(), and tor_addr_from_ipv4h.

Referenced by dirserv_set_routerstatus_testing(), and routerset_contains_node().

◆ 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 424 of file routerset.c.

References routerset_is_empty(), and tor_assert().

◆ routerset_free_()

void routerset_free_ ( routerset_t *  routerset)

Free all storage held in routerset.

Definition at line 450 of file routerset.c.

References SMARTLIST_FOREACH, and tor_free.

◆ 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 364 of file routerset.c.

References routerset_is_list(), SMARTLIST_FOREACH, and tor_assert().

◆ 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 65 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 203 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 187 of file routerset.c.

Referenced by routerset_get_all_nodes().

◆ 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 211 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 196 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 114 of file routerset.c.

References smartlist_split_string().

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 81 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 398 of file routerset.c.

References routerset_contains_node(), SMARTLIST_DEL_CURRENT, SMARTLIST_FOREACH, and tor_assert().

◆ 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 414 of file routerset.c.

Referenced by 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 173 of file routerset.c.

References routerset_parse(), routerset_to_string(), tor_assert(), and tor_free.

Variable Documentation

◆ ROUTERSET_type_defn

const var_type_def_t ROUTERSET_type_defn
Initial value:
= {
.name = "RouterList",
.fns = &routerset_type_fns

Definition at line 522 of file routerset.c.

◆ routerset_type_fns

const var_type_fns_t routerset_type_fns
Initial value:
= {
.kv_parse = routerset_kv_parse,
.encode = routerset_encode,
.clear = routerset_clear,
.copy = routerset_copy

Definition at line 515 of file routerset.c.