Tor  0.4.5.0-alpha-dev
routerset.c
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2020, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * \file routerset.c
9  *
10  * \brief Functions and structures to handle set-type selection of routers
11  * by name, ID, address, etc.
12  *
13  * This module implements the routerset_t data structure, whose purpose
14  * is to specify a set of relays based on a list of their identities or
15  * properties. Routersets can restrict relays by IP address mask,
16  * identity fingerprint, country codes, and nicknames (deprecated).
17  *
18  * Routersets are typically used for user-specified restrictions, and
19  * are created by invoking routerset_new and routerset_parse from
20  * config.c and confmgt.c. To use a routerset, invoke one of
21  * routerset_contains_...() functions , or use
22  * routerstatus_get_all_nodes() / routerstatus_subtract_nodes() to
23  * manipulate a smartlist of node_t pointers.
24  *
25  * Country-code restrictions are implemented in geoip.c.
26  */
27 
28 #define ROUTERSET_PRIVATE
29 
30 #include "core/or/or.h"
31 #include "core/or/policies.h"
32 #include "feature/client/bridges.h"
37 #include "lib/conf/conftypes.h"
38 #include "lib/confmgt/typedvar.h"
39 #include "lib/encoding/confline.h"
40 #include "lib/geoip/geoip.h"
41 
42 #include "core/or/addr_policy_st.h"
43 #include "core/or/extend_info_st.h"
48 
49 /** Return a new empty routerset. */
50 routerset_t *
52 {
53  routerset_t *result = tor_malloc_zero(sizeof(routerset_t));
54  result->list = smartlist_new();
55  result->names = strmap_new();
56  result->digests = digestmap_new();
57  result->policies = smartlist_new();
58  result->country_names = smartlist_new();
59  return result;
60 }
61 
62 /** If <b>c</b> is a country code in the form {cc}, return a newly allocated
63  * string holding the "cc" part. Else, return NULL. */
64 STATIC char *
66 {
67  char *country;
68 
69  if (strlen(c) < 4 || c[0] !='{' || c[3] !='}')
70  return NULL;
71 
72  country = tor_strndup(c+1, 2);
73  tor_strlower(country);
74  return country;
75 }
76 
77 /** Update the routerset's <b>countries</b> bitarray_t. Called whenever
78  * the GeoIP IPv4 database is reloaded.
79  */
80 void
81 routerset_refresh_countries(routerset_t *target)
82 {
83  int cc;
84  bitarray_free(target->countries);
85 
86  if (!geoip_is_loaded(AF_INET)) {
87  target->countries = NULL;
88  target->n_countries = 0;
89  return;
90  }
91  target->n_countries = geoip_get_n_countries();
92  target->countries = bitarray_init_zero(target->n_countries);
93  SMARTLIST_FOREACH_BEGIN(target->country_names, const char *, country) {
94  cc = geoip_get_country(country);
95  if (cc >= 0) {
96  tor_assert(cc < target->n_countries);
97  bitarray_set(target->countries, cc);
98  } else {
99  log_warn(LD_CONFIG, "Country code '%s' is not recognized.",
100  country);
101  }
102  } SMARTLIST_FOREACH_END(country);
103 }
104 
105 /** Parse the string <b>s</b> to create a set of routerset entries, and add
106  * them to <b>target</b>. In log messages, refer to the string as
107  * <b>description</b>. Return 0 on success, -1 on failure.
108  *
109  * Three kinds of elements are allowed in routersets: nicknames, IP address
110  * patterns, and fingerprints. They may be surrounded by optional space, and
111  * must be separated by commas.
112  */
113 int
114 routerset_parse(routerset_t *target, const char *s, const char *description)
115 {
116  int r = 0;
117  int added_countries = 0;
118  char *countryname;
119  smartlist_t *list = smartlist_new();
120  int malformed_list;
121  smartlist_split_string(list, s, ",",
122  SPLIT_SKIP_SPACE | SPLIT_IGNORE_BLANK, 0);
123  SMARTLIST_FOREACH_BEGIN(list, char *, nick) {
124  addr_policy_t *p;
125  /* if it doesn't pass our validation, assume it's malformed */
126  malformed_list = 1;
127  if (is_legal_hexdigest(nick)) {
128  char d[DIGEST_LEN];
129  if (*nick == '$')
130  ++nick;
131  log_debug(LD_CONFIG, "Adding identity %s to %s", nick, description);
132  base16_decode(d, sizeof(d), nick, HEX_DIGEST_LEN);
133  digestmap_set(target->digests, d, (void*)1);
134  } else if (is_legal_nickname(nick)) {
135  log_debug(LD_CONFIG, "Adding nickname %s to %s", nick, description);
136  strmap_set_lc(target->names, nick, (void*)1);
137  } else if ((countryname = routerset_get_countryname(nick)) != NULL) {
138  log_debug(LD_CONFIG, "Adding country %s to %s", nick,
139  description);
140  smartlist_add(target->country_names, countryname);
141  added_countries = 1;
142  } else if ((strchr(nick,'.') || strchr(nick, ':') || strchr(nick, '*'))
144  nick, ADDR_POLICY_REJECT,
145  &malformed_list))) {
146  /* IPv4 addresses contain '.', IPv6 addresses contain ':',
147  * and wildcard addresses contain '*'. */
148  log_debug(LD_CONFIG, "Adding address %s to %s", nick, description);
149  smartlist_add(target->policies, p);
150  } else if (malformed_list) {
151  log_warn(LD_CONFIG, "Entry '%s' in %s is malformed. Discarding entire"
152  " list.", nick, description);
153  r = -1;
154  tor_free(nick);
155  SMARTLIST_DEL_CURRENT(list, nick);
156  } else {
157  log_notice(LD_CONFIG, "Entry '%s' in %s is ignored. Using the"
158  " remainder of the list.", nick, description);
159  tor_free(nick);
160  SMARTLIST_DEL_CURRENT(list, nick);
161  }
162  } SMARTLIST_FOREACH_END(nick);
163  policy_expand_unspec(&target->policies);
164  smartlist_add_all(target->list, list);
165  smartlist_free(list);
166  if (added_countries)
168  return r;
169 }
170 
171 /** Add all members of the set <b>source</b> to <b>target</b>. */
172 void
173 routerset_union(routerset_t *target, const routerset_t *source)
174 {
175  char *s;
176  tor_assert(target);
177  if (!source || !source->list)
178  return;
179  s = routerset_to_string(source);
180  routerset_parse(target, s, "other routerset");
181  tor_free(s);
182 }
183 
184 /** Return true iff <b>set</b> lists only nicknames and digests, and includes
185  * no IP ranges or countries. */
186 int
187 routerset_is_list(const routerset_t *set)
188 {
189  return smartlist_len(set->country_names) == 0 &&
190  smartlist_len(set->policies) == 0;
191 }
192 
193 /** Return true iff we need a GeoIP IP-to-country database to make sense of
194  * <b>set</b>. */
195 int
196 routerset_needs_geoip(const routerset_t *set)
197 {
198  return set && smartlist_len(set->country_names);
199 }
200 
201 /** Return true iff there are no entries in <b>set</b>. */
202 int
203 routerset_is_empty(const routerset_t *set)
204 {
205  return !set || smartlist_len(set->list) == 0;
206 }
207 
208 /** Return the number of entries in <b>set</b>. This does NOT return a
209  * negative value. */
210 int
211 routerset_len(const routerset_t *set)
212 {
213  if (!set) {
214  return 0;
215  }
216  return smartlist_len(set->list);
217 }
218 
219 /** Helper. Return true iff <b>set</b> contains a router based on the other
220  * provided fields. Return higher values for more specific subentries: a
221  * single router is more specific than an address range of routers, which is
222  * more specific in turn than a country code.
223  *
224  * (If country is -1, then we take the country
225  * from addr.) */
226 static int
227 routerset_contains2(const routerset_t *set, const tor_addr_t *addr,
228  uint16_t orport, const tor_addr_t *addr2,
229  uint16_t orport2, const char *nickname,
230  const char *id_digest, country_t country)
231 {
232  if (!set || !set->list)
233  return 0;
234  if (nickname && strmap_get_lc(set->names, nickname))
235  return 4;
236  if (id_digest && digestmap_get(set->digests, id_digest))
237  return 4;
238  if (addr && compare_tor_addr_to_addr_policy(addr, orport, set->policies)
240  return 3;
241  if (addr2 && compare_tor_addr_to_addr_policy(addr2, orport2, set->policies)
243  return 3;
244  if (set->countries) {
245  if (country < 0 && addr)
246  country = geoip_get_country_by_addr(addr);
247 
248  if (country >= 0 && country < set->n_countries &&
249  bitarray_is_set(set->countries, country))
250  return 2;
251  }
252  return 0;
253 }
254 
255 /** Helper. Like routerset_contains2() but for a single IP/port combo.
256  */
257 STATIC int
258 routerset_contains(const routerset_t *set, const tor_addr_t *addr,
259  uint16_t orport, const char *nickname,
260  const char *id_digest, country_t country)
261 {
262  return routerset_contains2(set, addr, orport, NULL, 0,
263  nickname, id_digest, country);
264 }
265 
266 /** If *<b>setp</b> includes at least one country code, or if
267  * <b>only_some_cc_set</b> is 0, add the ?? and A1 country codes to
268  * *<b>setp</b>, creating it as needed. Return true iff *<b>setp</b> changed.
269  */
270 int
271 routerset_add_unknown_ccs(routerset_t **setp, int only_if_some_cc_set)
272 {
273  routerset_t *set;
274  int add_unknown, add_a1;
275  if (only_if_some_cc_set) {
276  if (!*setp || smartlist_len((*setp)->country_names) == 0)
277  return 0;
278  }
279  if (!*setp)
280  *setp = routerset_new();
281 
282  set = *setp;
283 
284  add_unknown = ! smartlist_contains_string_case(set->country_names, "??") &&
285  geoip_get_country("??") >= 0;
286  add_a1 = ! smartlist_contains_string_case(set->country_names, "a1") &&
287  geoip_get_country("A1") >= 0;
288 
289  if (add_unknown) {
290  smartlist_add_strdup(set->country_names, "??");
291  smartlist_add_strdup(set->list, "{??}");
292  }
293  if (add_a1) {
294  smartlist_add_strdup(set->country_names, "a1");
295  smartlist_add_strdup(set->list, "{a1}");
296  }
297 
298  if (add_unknown || add_a1) {
300  return 1;
301  }
302  return 0;
303 }
304 
305 /** Return true iff we can tell that <b>ei</b> is a member of <b>set</b>. */
306 int
307 routerset_contains_extendinfo(const routerset_t *set, const extend_info_t *ei)
308 {
309  const tor_addr_port_t *ap1 = NULL, *ap2 = NULL;
310  if (! tor_addr_is_null(&ei->orports[0].addr))
311  ap1 = &ei->orports[0];
312  if (! tor_addr_is_null(&ei->orports[1].addr))
313  ap2 = &ei->orports[1];
314  return routerset_contains2(set,
315  ap1 ? &ap1->addr : NULL,
316  ap1 ? ap1->port : 0,
317  ap2 ? &ap2->addr : NULL,
318  ap2 ? ap2->port : 0,
319  ei->nickname,
320  ei->identity_digest,
321  -1 /*country*/);
322 }
323 
324 /** Return true iff <b>ri</b> is in <b>set</b>. If country is <b>-1</b>, we
325  * look up the country. */
326 int
327 routerset_contains_router(const routerset_t *set, const routerinfo_t *ri,
328  country_t country)
329 {
330  return routerset_contains2(set, &ri->ipv4_addr, ri->ipv4_orport,
331  &ri->ipv6_addr, ri->ipv6_orport, ri->nickname,
332  ri->cache_info.identity_digest, country);
333 }
334 
335 /** Return true iff <b>rs</b> is in <b>set</b>. If country is <b>-1</b>, we
336  * look up the country. */
337 int
338 routerset_contains_routerstatus(const routerset_t *set,
339  const routerstatus_t *rs,
340  country_t country)
341 {
342  return routerset_contains(set,
343  &rs->ipv4_addr,
344  rs->ipv4_orport,
345  rs->nickname,
346  rs->identity_digest,
347  country);
348 }
349 
350 /** Return true iff <b>node</b> is in <b>set</b>. */
351 int
352 routerset_contains_node(const routerset_t *set, const node_t *node)
353 {
354  if (node->rs)
355  return routerset_contains_routerstatus(set, node->rs, node->country);
356  else if (node->ri)
357  return routerset_contains_router(set, node->ri, node->country);
358  else
359  return 0;
360 }
361 
362 /** Return true iff <b>routerset</b> contains the bridge <b>bridge</b>. */
363 int
364 routerset_contains_bridge(const routerset_t *set, const bridge_info_t *bridge)
365 {
366  const char *id = (const char*)bridge_get_rsa_id_digest(bridge);
367  const tor_addr_port_t *addrport = bridge_get_addr_port(bridge);
368 
369  tor_assert(addrport);
370  return routerset_contains(set, &addrport->addr, addrport->port,
371  NULL, id, -1);
372 }
373 
374 /** Add every known node_t that is a member of <b>routerset</b> to
375  * <b>out</b>, but never add any that are part of <b>excludeset</b>.
376  * If <b>running_only</b>, only add the running ones. */
377 void
378 routerset_get_all_nodes(smartlist_t *out, const routerset_t *routerset,
379  const routerset_t *excludeset, int running_only)
380 {
381  tor_assert(out);
382  if (!routerset || !routerset->list)
383  return;
384 
385  if (routerset_is_list(routerset)) {
386  /* No routers are specified by type; all are given by name or digest.
387  * we can do a lookup in O(len(routerset)). */
388  SMARTLIST_FOREACH(routerset->list, const char *, name, {
389  const node_t *node = node_get_by_nickname(name, 0);
390  if (node) {
391  if (!running_only || node->is_running)
392  if (!routerset_contains_node(excludeset, node))
393  smartlist_add(out, (void*)node);
394  }
395  });
396  } else {
397  /* We need to iterate over the routerlist to get all the ones of the
398  * right kind. */
399  const smartlist_t *nodes = nodelist_get_list();
400  SMARTLIST_FOREACH(nodes, const node_t *, node, {
401  if (running_only && !node->is_running)
402  continue;
403  if (routerset_contains_node(routerset, node) &&
404  !routerset_contains_node(excludeset, node))
405  smartlist_add(out, (void*)node);
406  });
407  }
408 }
409 
410 /** Remove every node_t from <b>lst</b> that is in <b>routerset</b>. */
411 void
412 routerset_subtract_nodes(smartlist_t *lst, const routerset_t *routerset)
413 {
414  tor_assert(lst);
415  if (!routerset)
416  return;
417  SMARTLIST_FOREACH(lst, const node_t *, node, {
418  if (routerset_contains_node(routerset, node)) {
419  //log_debug(LD_DIR, "Subtracting %s",r->nickname);
420  SMARTLIST_DEL_CURRENT(lst, node);
421  }
422  });
423 }
424 
425 /** Return a new string that when parsed by routerset_parse_string() will
426  * yield <b>set</b>. */
427 char *
428 routerset_to_string(const routerset_t *set)
429 {
430  if (!set || !set->list)
431  return tor_strdup("");
432  return smartlist_join_strings(set->list, ",", 0, NULL);
433 }
434 
435 /** Helper: return true iff old and new are both NULL, or both non-NULL
436  * equal routersets. */
437 int
438 routerset_equal(const routerset_t *old, const routerset_t *new)
439 {
440  if (routerset_is_empty(old) && routerset_is_empty(new)) {
441  /* Two empty sets are equal */
442  return 1;
443  } else if (routerset_is_empty(old) || routerset_is_empty(new)) {
444  /* An empty set is equal to nothing else. */
445  return 0;
446  }
447  tor_assert(old != NULL);
448  tor_assert(new != NULL);
449 
450  if (smartlist_len(old->list) != smartlist_len(new->list))
451  return 0;
452 
453  SMARTLIST_FOREACH(old->list, const char *, cp1, {
454  const char *cp2 = smartlist_get(new->list, cp1_sl_idx);
455  if (strcmp(cp1, cp2))
456  return 0;
457  });
458 
459  return 1;
460 }
461 
462 /** Free all storage held in <b>routerset</b>. */
463 void
464 routerset_free_(routerset_t *routerset)
465 {
466  if (!routerset)
467  return;
468 
469  SMARTLIST_FOREACH(routerset->list, char *, cp, tor_free(cp));
470  smartlist_free(routerset->list);
471  SMARTLIST_FOREACH(routerset->policies, addr_policy_t *, p,
472  addr_policy_free(p));
473  smartlist_free(routerset->policies);
474  SMARTLIST_FOREACH(routerset->country_names, char *, cp, tor_free(cp));
475  smartlist_free(routerset->country_names);
476 
477  strmap_free(routerset->names, NULL);
478  digestmap_free(routerset->digests, NULL);
479  bitarray_free(routerset->countries);
480  tor_free(routerset);
481 }
482 
483 /**
484  * config helper: parse a routerset-typed variable.
485  *
486  * Takes as input as a single line in <b>line</b>; writes its results into a
487  * routerset_t** passed as <b>target</b>. On success return 0; on failure
488  * return -1 and store an error message into *<b>errmsg</b>.
489  **/
490 /*
491  * Warning: For this type, the default value (NULL) and "" are sometimes
492  * considered different values. That is generally risky, and best avoided for
493  * other types in the future. For cases where we want the default to be "all
494  * routers" (like EntryNodes) we should add a new routerset value indicating
495  * "all routers" (see #31908)
496  */
497 static int
498 routerset_kv_parse(void *target, const config_line_t *line, char **errmsg,
499  const void *params)
500 {
501  (void)params;
502  routerset_t **p = (routerset_t**)target;
503  routerset_free(*p); // clear the old value, if any.
504  routerset_t *rs = routerset_new();
505  if (routerset_parse(rs, line->value, line->key) < 0) {
506  routerset_free(rs);
507  *errmsg = tor_strdup("Invalid router list.");
508  return -1;
509  } else {
510  if (routerset_is_empty(rs)) {
511  /* Represent empty sets as NULL. */
512  routerset_free(rs);
513  }
514  *p = rs;
515  return 0;
516  }
517 }
518 
519 /**
520  * config helper: encode a routerset-typed variable.
521  *
522  * Return a newly allocated string containing the value of the
523  * routerset_t** passed as <b>value</b>.
524  */
525 static char *
526 routerset_encode(const void *value, const void *params)
527 {
528  (void)params;
529  const routerset_t **p = (const routerset_t**)value;
530  return routerset_to_string(*p);
531 }
532 
533 /**
534  * config helper: free and clear a routerset-typed variable.
535  *
536  * Clear the routerset_t** passed as <b>value</b>.
537  */
538 static void
539 routerset_clear(void *value, const void *params)
540 {
541  (void)params;
542  routerset_t **p = (routerset_t**)value;
543  routerset_free(*p); // sets *p to NULL.
544 }
545 
546 /**
547  * config helper: copy a routerset-typed variable.
548  *
549  * Takes it input from a routerset_t** in <b>src</b>; writes its output to a
550  * routerset_t** in <b>dest</b>. Returns 0 on success, -1 on (impossible)
551  * failure.
552  **/
553 static int
554 routerset_copy(void *dest, const void *src, const void *params)
555 {
556  (void)params;
557  routerset_t **output = (routerset_t**)dest;
558  const routerset_t *input = *(routerset_t**)src;
559  routerset_free(*output); // sets *output to NULL
560  if (! routerset_is_empty(input)) {
561  *output = routerset_new();
562  routerset_union(*output, input);
563  }
564  return 0;
565 }
566 
567 /**
568  * Function table to implement a routerset_t-based configuration type.
569  **/
572  .encode = routerset_encode,
573  .clear = routerset_clear,
574  .copy = routerset_copy
575 };
576 
577 /**
578  * Definition of a routerset_t-based configuration type.
579  *
580  * Values are mapped to and from strings using the format defined in
581  * routerset_parse(): nicknames, IP address patterns, and fingerprints--with
582  * optional space, separated by commas.
583  *
584  * Empty sets are represented as NULL.
585  **/
587  .name = "RouterList",
588  .fns = &routerset_type_fns
589 };
routerset_union
void routerset_union(routerset_t *target, const routerset_t *source)
Definition: routerset.c:173
country_t
int16_t country_t
Definition: country.h:17
routerset_add_unknown_ccs
int routerset_add_unknown_ccs(routerset_t **setp, int only_if_some_cc_set)
Definition: routerset.c:271
router_parse_addr_policy_item_from_string
addr_policy_t * router_parse_addr_policy_item_from_string(const char *s, int assume_action, int *malformed_list)
Definition: policy_parse.c:44
tor_free
#define tor_free(p)
Definition: malloc.h:52
routerinfo_t
Definition: routerinfo_st.h:20
smartlist_split_string
int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep, int flags, int max)
Definition: smartlist_split.c:37
name
const char * name
Definition: config.c:2443
var_type_fns_t::kv_parse
int(* kv_parse)(void *target, const struct config_line_t *line, char **errmsg, const void *params)
Definition: var_type_def_st.h:72
tor_addr_t
Definition: address.h:69
compare_tor_addr_to_addr_policy
addr_policy_result_t compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy)
Definition: policies.c:1486
smartlist_add_strdup
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
Definition: smartlist_core.c:137
ADDR_POLICY_REJECTED
@ ADDR_POLICY_REJECTED
Definition: policies.h:42
routerset_contains_extendinfo
int routerset_contains_extendinfo(const routerset_t *set, const extend_info_t *ei)
Definition: routerset.c:307
routerset_get_all_nodes
void routerset_get_all_nodes(smartlist_t *out, const routerset_t *routerset, const routerset_t *excludeset, int running_only)
Definition: routerset.c:378
addr_policy_st.h
Address policy structures.
tor_assert
#define tor_assert(expr)
Definition: util_bug.h:102
routerset_type_fns
static const var_type_fns_t routerset_type_fns
Definition: routerset.c:570
bridge_get_rsa_id_digest
const uint8_t * bridge_get_rsa_id_digest(const bridge_info_t *bridge)
Definition: bridges.c:147
routerset_contains_node
int routerset_contains_node(const routerset_t *set, const node_t *node)
Definition: routerset.c:352
geoip_is_loaded
int geoip_is_loaded(sa_family_t family)
Definition: geoip.c:458
smartlist_add_all
void smartlist_add_all(smartlist_t *s1, const smartlist_t *s2)
Definition: smartlist_core.c:125
smartlist_add
void smartlist_add(smartlist_t *sl, void *element)
Definition: smartlist_core.c:117
var_type_def_t::name
const char * name
Definition: var_type_def_st.h:150
routerset_refresh_countries
void routerset_refresh_countries(routerset_t *target)
Definition: routerset.c:81
routerstatus_t
Definition: routerstatus_st.h:19
is_legal_nickname
int is_legal_nickname(const char *s)
Definition: nickname.c:19
routerset_needs_geoip
int routerset_needs_geoip(const routerset_t *set)
Definition: routerset.c:196
routerstatus_t::nickname
char nickname[MAX_NICKNAME_LEN+1]
Definition: routerstatus_st.h:25
smartlist_new
smartlist_t * smartlist_new(void)
Definition: smartlist_core.c:26
routerinfo_t::ipv6_addr
tor_addr_t ipv6_addr
Definition: routerinfo_st.h:30
routerset_to_string
char * routerset_to_string(const routerset_t *set)
Definition: routerset.c:428
SMARTLIST_FOREACH
#define SMARTLIST_FOREACH(sl, type, var, cmd)
Definition: smartlist_foreach.h:112
var_type_def_t
Definition: var_type_def_st.h:146
addr_policy_t
Definition: addr_policy_st.h:26
signed_descriptor_t::identity_digest
char identity_digest[DIGEST_LEN]
Definition: signed_descriptor_st.h:31
routerset_clear
static void routerset_clear(void *value, const void *params)
Definition: routerset.c:539
base16_decode
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:506
routerset_subtract_nodes
void routerset_subtract_nodes(smartlist_t *lst, const routerset_t *routerset)
Definition: routerset.c:412
DIGEST_LEN
#define DIGEST_LEN
Definition: digest_sizes.h:20
routerset_is_empty
int routerset_is_empty(const routerset_t *set)
Definition: routerset.c:203
strmap_set_lc
void * strmap_set_lc(strmap_t *map, const char *key, void *val)
Definition: map.c:346
bridges.h
Header file for circuitbuild.c.
geoip.h
Header file for geoip.c.
routerinfo_t::ipv4_addr
tor_addr_t ipv4_addr
Definition: routerinfo_st.h:25
tor_addr_port_t
Definition: address.h:81
routerstatus_t::ipv4_orport
uint16_t ipv4_orport
Definition: routerstatus_st.h:33
bitarray_init_zero
static bitarray_t * bitarray_init_zero(unsigned int n_bits)
Definition: bitarray.h:33
node_t
Definition: node_st.h:34
geoip_get_country
country_t geoip_get_country(const char *country)
Definition: geoip.c:101
routerset_kv_parse
static int routerset_kv_parse(void *target, const config_line_t *line, char **errmsg, const void *params)
Definition: routerset.c:498
routerset_encode
static char * routerset_encode(const void *value, const void *params)
Definition: routerset.c:526
extend_info_t::orports
tor_addr_port_t orports[EXTEND_INFO_MAX_ADDRS]
Definition: extend_info_st.h:36
routerset_equal
int routerset_equal(const routerset_t *old, const routerset_t *new)
Definition: routerset.c:438
nodelist.h
Header file for nodelist.c.
bitarray_set
static void bitarray_set(bitarray_t *b, int bit)
Definition: bitarray.h:68
routerset_get_countryname
STATIC char * routerset_get_countryname(const char *c)
Definition: routerset.c:65
routerset.h
Header file for routerset.c.
routerset_free_
void routerset_free_(routerset_t *routerset)
Definition: routerset.c:464
routerinfo_st.h
Router descriptor structure.
routerset_copy
static int routerset_copy(void *dest, const void *src, const void *params)
Definition: routerset.c:554
LD_CONFIG
#define LD_CONFIG
Definition: log.h:68
routerset_contains_router
int routerset_contains_router(const routerset_t *set, const routerinfo_t *ri, country_t country)
Definition: routerset.c:327
geoip_get_country_by_addr
int geoip_get_country_by_addr(const tor_addr_t *addr)
Definition: geoip.c:424
ROUTERSET_type_defn
const var_type_def_t ROUTERSET_type_defn
Definition: routerset.c:586
policy_expand_unspec
void policy_expand_unspec(smartlist_t **policy)
Definition: policies.c:145
extend_info_st.h
Extend-info structure.
routerstatus_st.h
Routerstatus (consensus entry) structure.
smartlist_contains_string_case
int smartlist_contains_string_case(const smartlist_t *sl, const char *element)
Definition: smartlist.c:133
typedvar.h
Header for lib/confmgt/typedvar.c.
policy_parse.h
Header file for policy_parse.c.
nodelist_get_list
const smartlist_t * nodelist_get_list(void)
Definition: nodelist.c:966
routerset_len
int routerset_len(const routerset_t *set)
Definition: routerset.c:211
extend_info_t::identity_digest
char identity_digest[DIGEST_LEN]
Definition: extend_info_st.h:31
bridge_info_t
Definition: bridges.c:43
confline.h
Header for confline.c.
tor_strlower
void tor_strlower(char *s)
Definition: util_string.c:127
nickname.h
Header file for nickname.c.
tor_addr_is_null
int tor_addr_is_null(const tor_addr_t *addr)
Definition: address.c:780
strmap_get_lc
void * strmap_get_lc(const strmap_t *map, const char *key)
Definition: map.c:360
var_type_def_st.h
Structure declarations for typedvar type definitions.
node_t::country
country_t country
Definition: node_st.h:92
bitarray_is_set
static unsigned int bitarray_is_set(bitarray_t *b, int bit)
Definition: bitarray.h:81
SMARTLIST_FOREACH_BEGIN
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
Definition: smartlist_foreach.h:78
SMARTLIST_DEL_CURRENT
#define SMARTLIST_DEL_CURRENT(sl, var)
Definition: smartlist_foreach.h:120
HEX_DIGEST_LEN
#define HEX_DIGEST_LEN
Definition: crypto_digest.h:35
node_st.h
Node information structure.
routerset_parse
int routerset_parse(routerset_t *target, const char *s, const char *description)
Definition: routerset.c:114
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)
Definition: routerset.c:227
policies.h
Header file for policies.c.
config_line_t
Definition: confline.h:29
extend_info_t::nickname
char nickname[MAX_HEX_NICKNAME_LEN+1]
Definition: extend_info_st.h:28
conftypes.h
Types used to specify configurable options.
routerset_contains_routerstatus
int routerset_contains_routerstatus(const routerset_t *set, const routerstatus_t *rs, country_t country)
Definition: routerset.c:338
var_type_fns_t
Definition: var_type_def_st.h:49
geoip_get_n_countries
int geoip_get_n_countries(void)
Definition: geoip.c:437
STATIC
#define STATIC
Definition: testsupport.h:32
routerset_contains_bridge
int routerset_contains_bridge(const routerset_t *set, const bridge_info_t *bridge)
Definition: routerset.c:364
routerinfo_t::nickname
char * nickname
Definition: routerinfo_st.h:22
bridge_get_addr_port
const tor_addr_port_t * bridge_get_addr_port(const bridge_info_t *bridge)
Definition: bridges.c:161
routerstatus_t::identity_digest
char identity_digest[DIGEST_LEN]
Definition: routerstatus_st.h:27
smartlist_t
Definition: smartlist_core.h:26
smartlist_join_strings
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
Definition: smartlist.c:279
routerset_is_list
int routerset_is_list(const routerset_t *set)
Definition: routerset.c:187
routerset_new
routerset_t * routerset_new(void)
Definition: routerset.c:51
extend_info_t
Definition: extend_info_st.h:27
is_legal_hexdigest
int is_legal_hexdigest(const char *s)
Definition: nickname.c:45
or.h
Master header file for Tor-specific functionality.
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)
Definition: routerset.c:258