tor  master
Macros | Functions
routerset.c File Reference

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

#include "or.h"
#include "bridges.h"
#include "geoip.h"
#include "nodelist.h"
#include "policies.h"
#include "router.h"
#include "routerparse.h"
#include "routerset.h"
Include dependency graph for routerset.c:

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_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)
 

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.

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.

Here is the call graph for this function:

◆ 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.)

Here is the call graph for this function:
Here is the caller graph for this function:

◆ routerset_contains_bridge()

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

Return true iff routerset contains the bridge bridge.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ routerset_contains_node()

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

Return true iff node is in set.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:

◆ routerset_free_()

void routerset_free_ ( routerset_t *  routerset)

Free all storage held in routerset.

◆ 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.

Here is the call graph for this function:

◆ 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.

◆ routerset_is_empty()

int routerset_is_empty ( const routerset_t *  set)

Return true iff there are no entries in set.

Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ routerset_len()

int routerset_len ( const routerset_t *  set)

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

◆ 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.

Here is the caller graph for this function:

◆ routerset_new()

routerset_t* routerset_new ( void  )

Return a new empty routerset.

Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ routerset_subtract_nodes()

void routerset_subtract_nodes ( smartlist_t lst,
const routerset_t *  routerset 
)

Remove every node_t from lst that is in routerset.

Here is the call graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ routerset_union()

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

Add all members of the set source to target.

Here is the call graph for this function: