Tor  0.4.4.0-alpha-dev
addressmap.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 addressmap.c
9  *
10  * \brief The addressmap module manages the processes by which we rewrite
11  * addresses in client requess. It handles the MapAddress controller and
12  * torrc commands, and the TrackHostExits feature, and the client-side DNS
13  * cache (deprecated).
14  */
15 
16 #define ADDRESSMAP_PRIVATE
17 
19 
20 #include "core/or/or.h"
22 #include "core/or/circuituse.h"
23 #include "app/config/config.h"
28 
30 
31 /** A client-side struct to remember requests to rewrite addresses
32  * to new addresses. These structs are stored in the hash table
33  * "addressmap" below.
34  *
35  * There are 5 ways to set an address mapping:
36  * - A MapAddress command from the controller [permanent]
37  * - An AddressMap directive in the torrc [permanent]
38  * - When a TrackHostExits torrc directive is triggered [temporary]
39  * - When a DNS resolve succeeds [temporary]
40  * - When a DNS resolve fails [temporary]
41  *
42  * When an addressmap request is made but one is already registered,
43  * the new one is replaced only if the currently registered one has
44  * no "new_address" (that is, it's in the process of DNS resolve),
45  * or if the new one is permanent (expires==0 or 1).
46  *
47  * (We overload the 'expires' field, using "0" for mappings set via
48  * the configuration file, "1" for mappings set from the control
49  * interface, and other values for DNS and TrackHostExit mappings that can
50  * expire.)
51  *
52  * A mapping may be 'wildcarded'. If "src_wildcard" is true, then
53  * any address that ends with a . followed by the key for this entry will
54  * get remapped by it. If "dst_wildcard" is also true, then only the
55  * matching suffix of such addresses will get replaced by new_address.
56  */
57 typedef struct {
58  char *new_address;
59  time_t expires;
60  addressmap_entry_source_bitfield_t source:3;
61  unsigned src_wildcard:1;
62  unsigned dst_wildcard:1;
63  short num_resolve_failures;
65 
66 /** Entry for mapping addresses to which virtual address we mapped them to. */
67 typedef struct {
68  char *ipv4_address;
69  char *ipv6_address;
70  char *hostname_address;
72 
73 /** A hash table to store client-side address rewrite instructions. */
74 static strmap_t *addressmap=NULL;
75 
76 /**
77  * Table mapping addresses to which virtual address, if any, we
78  * assigned them to.
79  *
80  * We maintain the following invariant: if [A,B] is in
81  * virtaddress_reversemap, then B must be a virtual address, and [A,B]
82  * must be in addressmap. We do not require that the converse hold:
83  * if it fails, then we could end up mapping two virtual addresses to
84  * the same address, which is no disaster.
85  **/
86 static strmap_t *virtaddress_reversemap=NULL;
87 
88 /** Initialize addressmap. */
89 void
91 {
92  addressmap = strmap_new();
93  virtaddress_reversemap = strmap_new();
94 }
95 
96 #define addressmap_ent_free(ent) \
97  FREE_AND_NULL(addressmap_entry_t, addressmap_ent_free_, (ent))
98 
99 /** Free the memory associated with the addressmap entry <b>_ent</b>. */
100 static void
102 {
103  if (!ent)
104  return;
105 
106  tor_free(ent->new_address);
107  tor_free(ent);
108 }
109 
110 static void
111 addressmap_ent_free_void(void *ent)
112 {
114 }
115 
116 #define addressmap_virtaddress_ent_free(ent) \
117  FREE_AND_NULL(virtaddress_entry_t, addressmap_virtaddress_ent_free_, (ent))
118 
119 /** Free storage held by a virtaddress_entry_t* entry in <b>_ent</b>. */
120 static void
122 {
123  if (!ent)
124  return;
125  tor_free(ent->ipv4_address);
126  tor_free(ent->ipv6_address);
127  tor_free(ent->hostname_address);
128  tor_free(ent);
129 }
130 
131 static void
132 addressmap_virtaddress_ent_free_void(void *ent)
133 {
135 }
136 
137 /** Remove <b>address</b> (which must map to <b>ent</b>) from the
138  * virtual address map. */
139 static void
141 {
142  if (ent && ent->new_address &&
143  address_is_in_virtual_range(ent->new_address)) {
144  virtaddress_entry_t *ve =
145  strmap_get(virtaddress_reversemap, ent->new_address);
146  /*log_fn(LOG_NOTICE,"remove reverse mapping for %s",ent->new_address);*/
147  if (ve) {
148  if (!strcmp(address, ve->ipv4_address))
149  tor_free(ve->ipv4_address);
150  if (!strcmp(address, ve->ipv6_address))
151  tor_free(ve->ipv6_address);
152  if (!strcmp(address, ve->hostname_address))
153  tor_free(ve->hostname_address);
154  if (!ve->ipv4_address && !ve->ipv6_address && !ve->hostname_address) {
155  tor_free(ve);
156  strmap_remove(virtaddress_reversemap, ent->new_address);
157  }
158  }
159  }
160 }
161 
162 /** Remove <b>ent</b> (which must be mapped to by <b>address</b>) from the
163  * client address maps, and then free it. */
164 static void
165 addressmap_ent_remove(const char *address, addressmap_entry_t *ent)
166 {
167  addressmap_virtaddress_remove(address, ent);
168  addressmap_ent_free(ent);
169 }
170 
171 /** Unregister all TrackHostExits mappings from any address to
172  * *.exitname.exit. */
173 void
174 clear_trackexithost_mappings(const char *exitname)
175 {
176  char *suffix = NULL;
177  if (!addressmap || !exitname)
178  return;
179  tor_asprintf(&suffix, ".%s.exit", exitname);
180  tor_strlower(suffix);
181 
182  STRMAP_FOREACH_MODIFY(addressmap, address, addressmap_entry_t *, ent) {
183  if (ent->source == ADDRMAPSRC_TRACKEXIT &&
184  !strcmpend(ent->new_address, suffix)) {
185  addressmap_ent_remove(address, ent);
186  MAP_DEL_CURRENT(address);
187  }
188  } STRMAP_FOREACH_END;
189 
190  tor_free(suffix);
191 }
192 
193 /** Remove all TRACKEXIT mappings from the addressmap for which the target
194  * host is unknown or no longer allowed, or for which the source address
195  * is no longer in trackexithosts. */
196 void
198 {
199  const routerset_t *allow_nodes = options->ExitNodes;
200  const routerset_t *exclude_nodes = options->ExcludeExitNodesUnion_;
201 
202  if (!addressmap)
203  return;
204  if (routerset_is_empty(allow_nodes))
205  allow_nodes = NULL;
206  if (allow_nodes == NULL && routerset_is_empty(exclude_nodes))
207  return;
208 
209  STRMAP_FOREACH_MODIFY(addressmap, address, addressmap_entry_t *, ent) {
210  size_t len;
211  const char *target = ent->new_address, *dot;
212  char *nodename;
213  const node_t *node;
214 
215  if (!target) {
216  /* DNS resolving in progress */
217  continue;
218  } else if (strcmpend(target, ".exit")) {
219  /* Not a .exit mapping */
220  continue;
221  } else if (ent->source != ADDRMAPSRC_TRACKEXIT) {
222  /* Not a trackexit mapping. */
223  continue;
224  }
225  len = strlen(target);
226  if (len < 6)
227  continue; /* malformed. */
228  dot = target + len - 6; /* dot now points to just before .exit */
229  while (dot > target && *dot != '.')
230  dot--;
231  if (*dot == '.') dot++;
232  nodename = tor_strndup(dot, len-5-(dot-target));
233  node = node_get_by_nickname(nodename, NNF_NO_WARN_UNNAMED);
234  tor_free(nodename);
235  if (!node ||
236  (allow_nodes && !routerset_contains_node(allow_nodes, node)) ||
237  routerset_contains_node(exclude_nodes, node) ||
238  !hostname_in_track_host_exits(options, address)) {
239  /* We don't know this one, or we want to be rid of it. */
240  addressmap_ent_remove(address, ent);
241  MAP_DEL_CURRENT(address);
242  }
243  } STRMAP_FOREACH_END;
244 }
245 
246 /** Return true iff <b>address</b> is one that we are configured to
247  * automap on resolve according to <b>options</b>. */
248 int
250  const or_options_t *options)
251 {
252  const smartlist_t *suffix_list = options->AutomapHostsSuffixes;
253 
254  if (!suffix_list)
255  return 0;
256 
257  SMARTLIST_FOREACH_BEGIN(suffix_list, const char *, suffix) {
258  if (!strcmp(suffix, "."))
259  return 1;
260  if (!strcasecmpend(address, suffix))
261  return 1;
262  } SMARTLIST_FOREACH_END(suffix);
263  return 0;
264 }
265 
266 /** Remove all AUTOMAP mappings from the addressmap for which the
267  * source address no longer matches AutomapHostsSuffixes, which is
268  * no longer allowed by AutomapHostsOnResolve, or for which the
269  * target address is no longer in the virtual network. */
270 void
272 {
273  int clear_all = !options->AutomapHostsOnResolve;
274  const smartlist_t *suffixes = options->AutomapHostsSuffixes;
275 
276  if (!addressmap)
277  return;
278 
279  if (!suffixes)
280  clear_all = 1; /* This should be impossible, but let's be sure. */
281 
282  STRMAP_FOREACH_MODIFY(addressmap, src_address, addressmap_entry_t *, ent) {
283  int remove_this = clear_all;
284  if (ent->source != ADDRMAPSRC_AUTOMAP)
285  continue; /* not an automap mapping. */
286 
287  if (!remove_this) {
288  remove_this = ! addressmap_address_should_automap(src_address, options);
289  }
290 
291  if (!remove_this && ! address_is_in_virtual_range(ent->new_address))
292  remove_this = 1;
293 
294  if (remove_this) {
295  addressmap_ent_remove(src_address, ent);
296  MAP_DEL_CURRENT(src_address);
297  }
298  } STRMAP_FOREACH_END;
299 }
300 
301 /** Remove all entries from the addressmap that were set via the
302  * configuration file or the command line. */
303 void
305 {
306  addressmap_get_mappings(NULL, 0, 0, 0);
307 }
308 
309 /** Remove all entries from the addressmap that are set to expire, ever. */
310 void
312 {
313  addressmap_get_mappings(NULL, 2, TIME_MAX, 0);
314 }
315 
316 /** Clean out entries from the addressmap cache that were
317  * added long enough ago that they are no longer valid.
318  */
319 void
320 addressmap_clean(time_t now)
321 {
322  addressmap_get_mappings(NULL, 2, now, 0);
323 }
324 
325 /** Free all the elements in the addressmap, and free the addressmap
326  * itself. */
327 void
329 {
330  strmap_free(addressmap, addressmap_ent_free_void);
331  addressmap = NULL;
332 
333  strmap_free(virtaddress_reversemap, addressmap_virtaddress_ent_free_void);
334  virtaddress_reversemap = NULL;
335 }
336 
337 /** Try to find a match for AddressMap expressions that use
338  * wildcard notation such as '*.c.d *.e.f' (so 'a.c.d' will map to 'a.e.f') or
339  * '*.c.d a.b.c' (so 'a.c.d' will map to a.b.c).
340  * Return the matching entry in AddressMap or NULL if no match is found.
341  * For expressions such as '*.c.d *.e.f', truncate <b>address</b> 'a.c.d'
342  * to 'a' before we return the matching AddressMap entry.
343  *
344  * This function does not handle the case where a pattern of the form "*.c.d"
345  * matches the address c.d -- that's done by the main addressmap_rewrite
346  * function.
347  */
348 static addressmap_entry_t *
350 {
351  addressmap_entry_t *val;
352  char *cp;
353 
354  cp = address;
355  while ((cp = strchr(cp, '.'))) {
356  /* cp now points to a suffix of address that begins with a . */
357  val = strmap_get_lc(addressmap, cp+1);
358  if (val && val->src_wildcard) {
359  if (val->dst_wildcard)
360  *cp = '\0';
361  return val;
362  }
363  ++cp;
364  }
365  return NULL;
366 }
367 
368 /** Look at address, and rewrite it until it doesn't want any
369  * more rewrites; but don't get into an infinite loop.
370  * Don't write more than maxlen chars into address. Return true if the
371  * address changed; false otherwise. Set *<b>expires_out</b> to the
372  * expiry time of the result, or to <b>time_max</b> if the result does
373  * not expire.
374  *
375  * If <b>exit_source_out</b> is non-null, we set it as follows. If we the
376  * address starts out as a non-exit address, and we remap it to an .exit
377  * address at any point, then set *<b>exit_source_out</b> to the
378  * address_entry_source_t of the first such rule. Set *<b>exit_source_out</b>
379  * to ADDRMAPSRC_NONE if there is no such rewrite, or if the original address
380  * was a .exit.
381  */
382 int
383 addressmap_rewrite(char *address, size_t maxlen,
384  unsigned flags,
385  time_t *expires_out,
386  addressmap_entry_source_t *exit_source_out)
387 {
388  addressmap_entry_t *ent;
389  int rewrites;
390  time_t expires = TIME_MAX;
392  char *addr_orig = tor_strdup(address);
393  char *log_addr_orig = NULL;
394 
395  /* We use a loop here to limit the total number of rewrites we do,
396  * so that we can't hit an infinite loop. */
397  for (rewrites = 0; rewrites < 16; rewrites++) {
398  int exact_match = 0;
399  log_addr_orig = tor_strdup(escaped_safe_str_client(address));
400 
401  /* First check to see if there's an exact match for this address */
402  ent = strmap_get(addressmap, address);
403 
404  if (!ent || !ent->new_address) {
405  /* And if we don't have an exact match, try to check whether
406  * we have a pattern-based match.
407  */
408  ent = addressmap_match_superdomains(address);
409  } else {
410  if (ent->src_wildcard && !ent->dst_wildcard &&
411  !strcasecmp(address, ent->new_address)) {
412  /* This is a rule like "rewrite *.example.com to example.com", and we
413  * just got "example.com". Instead of calling it an infinite loop,
414  * call it complete. */
415  goto done;
416  }
417  exact_match = 1;
418  }
419 
420  if (!ent || !ent->new_address) {
421  /* We still have no match at all. We're done! */
422  goto done;
423  }
424 
425  /* Check wither the flags we were passed tell us not to use this
426  * mapping. */
427  switch (ent->source) {
428  case ADDRMAPSRC_DNS:
429  {
430  sa_family_t f;
431  tor_addr_t tmp;
432  f = tor_addr_parse(&tmp, ent->new_address);
433  if (f == AF_INET && !(flags & AMR_FLAG_USE_IPV4_DNS))
434  goto done;
435  else if (f == AF_INET6 && !(flags & AMR_FLAG_USE_IPV6_DNS))
436  goto done;
437  }
438  break;
440  case ADDRMAPSRC_TORRC:
441  if (!(flags & AMR_FLAG_USE_MAPADDRESS))
442  goto done;
443  break;
444  case ADDRMAPSRC_AUTOMAP:
445  if (!(flags & AMR_FLAG_USE_AUTOMAP))
446  goto done;
447  break;
449  if (!(flags & AMR_FLAG_USE_TRACKEXIT))
450  goto done;
451  break;
452  case ADDRMAPSRC_NONE:
453  default:
454  log_warn(LD_BUG, "Unknown addrmap source value %d. Ignoring it.",
455  (int) ent->source);
456  goto done;
457  }
458 
459  /* Now fill in the address with the new address. That might be via
460  * appending some new stuff to the end, or via just replacing it. */
461  if (ent->dst_wildcard && !exact_match) {
462  strlcat(address, ".", maxlen);
463  strlcat(address, ent->new_address, maxlen);
464  } else {
465  strlcpy(address, ent->new_address, maxlen);
466  }
467 
468  /* Is this now a .exit address? If so, remember where we got it.*/
469  if (!strcmpend(address, ".exit") &&
470  strcmpend(addr_orig, ".exit") &&
471  exit_source == ADDRMAPSRC_NONE) {
472  exit_source = ent->source;
473  }
474 
475  log_info(LD_APP, "Addressmap: rewriting %s to %s",
476  log_addr_orig, escaped_safe_str_client(address));
477  if (ent->expires > 1 && ent->expires < expires)
478  expires = ent->expires;
479 
480  tor_free(log_addr_orig);
481  }
482  log_warn(LD_CONFIG,
483  "Loop detected: we've rewritten %s 16 times! Using it as-is.",
484  escaped_safe_str_client(address));
485  /* it's fine to rewrite a rewrite, but don't loop forever */
486 
487  done:
488  tor_free(addr_orig);
489  tor_free(log_addr_orig);
490  if (exit_source_out)
491  *exit_source_out = exit_source;
492  if (expires_out)
493  *expires_out = expires;
494  return (rewrites > 0);
495 }
496 
497 /** If we have a cached reverse DNS entry for the address stored in the
498  * <b>maxlen</b>-byte buffer <b>address</b> (typically, a dotted quad) then
499  * rewrite to the cached value and return 1. Otherwise return 0. Set
500  * *<b>expires_out</b> to the expiry time of the result, or to <b>time_max</b>
501  * if the result does not expire. */
502 int
503 addressmap_rewrite_reverse(char *address, size_t maxlen, unsigned flags,
504  time_t *expires_out)
505 {
506  char *s, *cp;
507  addressmap_entry_t *ent;
508  int r = 0;
509  {
510  sa_family_t f;
511  tor_addr_t tmp;
512  f = tor_addr_parse(&tmp, address);
513  if (f == AF_INET && !(flags & AMR_FLAG_USE_IPV4_DNS))
514  return 0;
515  else if (f == AF_INET6 && !(flags & AMR_FLAG_USE_IPV6_DNS))
516  return 0;
517  /* FFFF we should reverse-map virtual addresses even if we haven't
518  * enabled DNS cacheing. */
519  }
520 
521  tor_asprintf(&s, "REVERSE[%s]", address);
522  ent = strmap_get(addressmap, s);
523  if (ent) {
524  cp = tor_strdup(escaped_safe_str_client(ent->new_address));
525  log_info(LD_APP, "Rewrote reverse lookup %s -> %s",
526  escaped_safe_str_client(s), cp);
527  tor_free(cp);
528  strlcpy(address, ent->new_address, maxlen);
529  r = 1;
530  }
531 
532  if (expires_out)
533  *expires_out = (ent && ent->expires > 1) ? ent->expires : TIME_MAX;
534 
535  tor_free(s);
536  return r;
537 }
538 
539 /** Return 1 if <b>address</b> is already registered, else return 0. If address
540  * is already registered, and <b>update_expires</b> is non-zero, then update
541  * the expiry time on the mapping with update_expires if it is a
542  * mapping created by TrackHostExits. */
543 int
544 addressmap_have_mapping(const char *address, int update_expiry)
545 {
546  addressmap_entry_t *ent;
547  if (!(ent=strmap_get_lc(addressmap, address)))
548  return 0;
549  if (update_expiry && ent->source==ADDRMAPSRC_TRACKEXIT)
550  ent->expires=time(NULL) + update_expiry;
551  return 1;
552 }
553 
554 /** Register a request to map <b>address</b> to <b>new_address</b>,
555  * which will expire on <b>expires</b> (or 0 if never expires from
556  * config file, 1 if never expires from controller, 2 if never expires
557  * (virtual address mapping) from the controller.)
558  *
559  * <b>new_address</b> should be a newly dup'ed string, which we'll use or
560  * free as appropriate. We will leave <b>address</b> alone.
561  *
562  * If <b>wildcard_addr</b> is true, then the mapping will match any address
563  * equal to <b>address</b>, or any address ending with a period followed by
564  * <b>address</b>. If <b>wildcard_addr</b> and <b>wildcard_new_addr</b> are
565  * both true, the mapping will rewrite addresses that end with
566  * ".<b>address</b>" into ones that end with ".<b>new_address</b>".
567  *
568  * If <b>new_address</b> is NULL, or <b>new_address</b> is equal to
569  * <b>address</b> and <b>wildcard_addr</b> is equal to
570  * <b>wildcard_new_addr</b>, remove any mappings that exist from
571  * <b>address</b>.
572  *
573  * It is an error to set <b>wildcard_new_addr</b> if <b>wildcard_addr</b> is
574  * not set. */
575 void
576 addressmap_register(const char *address, char *new_address, time_t expires,
578  const int wildcard_addr,
579  const int wildcard_new_addr)
580 {
581  addressmap_entry_t *ent;
582 
583  if (wildcard_new_addr)
584  tor_assert(wildcard_addr);
585 
586  ent = strmap_get(addressmap, address);
587  if (!new_address || (!strcasecmp(address,new_address) &&
588  wildcard_addr == wildcard_new_addr)) {
589  /* Remove the mapping, if any. */
590  tor_free(new_address);
591  if (ent) {
592  addressmap_ent_remove(address,ent);
593  strmap_remove(addressmap, address);
594  }
595  return;
596  }
597  if (!ent) { /* make a new one and register it */
598  ent = tor_malloc_zero(sizeof(addressmap_entry_t));
599  strmap_set(addressmap, address, ent);
600  } else if (ent->new_address) { /* we need to clean up the old mapping. */
601  if (expires > 1) {
602  log_info(LD_APP,"Temporary addressmap ('%s' to '%s') not performed, "
603  "since it's already mapped to '%s'",
604  safe_str_client(address),
605  safe_str_client(new_address),
606  safe_str_client(ent->new_address));
607  tor_free(new_address);
608  return;
609  }
610  if (address_is_in_virtual_range(ent->new_address) &&
611  expires != 2) {
612  /* XXX This isn't the perfect test; we want to avoid removing
613  * mappings set from the control interface _as virtual mapping */
614  addressmap_virtaddress_remove(address, ent);
615  }
616  tor_free(ent->new_address);
617  } /* else { we have an in-progress resolve with no mapping. } */
618 
619  ent->new_address = new_address;
620  ent->expires = expires==2 ? 1 : expires;
621  ent->num_resolve_failures = 0;
622  ent->source = source;
623  ent->src_wildcard = wildcard_addr ? 1 : 0;
624  ent->dst_wildcard = wildcard_new_addr ? 1 : 0;
625 
626  log_info(LD_CONFIG, "Addressmap: (re)mapped '%s' to '%s'",
627  safe_str_client(address),
628  safe_str_client(ent->new_address));
629  control_event_address_mapped(address, ent->new_address, expires, NULL, 1);
630 }
631 
632 /** An attempt to resolve <b>address</b> failed at some OR.
633  * Increment the number of resolve failures we have on record
634  * for it, and then return that number.
635  */
636 int
637 client_dns_incr_failures(const char *address)
638 {
639  addressmap_entry_t *ent = strmap_get(addressmap, address);
640  if (!ent) {
641  ent = tor_malloc_zero(sizeof(addressmap_entry_t));
642  ent->expires = time(NULL) + MAX_DNS_ENTRY_AGE;
643  strmap_set(addressmap,address,ent);
644  }
645  if (ent->num_resolve_failures < SHRT_MAX)
646  ++ent->num_resolve_failures; /* don't overflow */
647  log_info(LD_APP, "Address %s now has %d resolve failures.",
648  safe_str_client(address),
649  ent->num_resolve_failures);
650  return ent->num_resolve_failures;
651 }
652 
653 /** If <b>address</b> is in the client DNS addressmap, reset
654  * the number of resolve failures we have on record for it.
655  * This is used when we fail a stream because it won't resolve:
656  * otherwise future attempts on that address will only try once.
657  */
658 void
659 client_dns_clear_failures(const char *address)
660 {
661  addressmap_entry_t *ent = strmap_get(addressmap, address);
662  if (ent)
663  ent->num_resolve_failures = 0;
664 }
665 
666 /** Record the fact that <b>address</b> resolved to <b>name</b>.
667  * We can now use this in subsequent streams via addressmap_rewrite()
668  * so we can more correctly choose an exit that will allow <b>address</b>.
669  *
670  * If <b>exitname</b> is defined, then append the addresses with
671  * ".exitname.exit" before registering the mapping.
672  *
673  * If <b>ttl</b> is nonnegative, the mapping will be valid for
674  * <b>ttl</b>seconds; otherwise, we use the default.
675  */
676 static void
678  const char *address, const char *name,
679  const char *exitname,
680  int ttl)
681 {
682  char *extendedaddress=NULL, *extendedval=NULL;
683  (void)for_conn;
684 
685  tor_assert(address);
686  tor_assert(name);
687 
688  if (ttl<0)
689  ttl = DEFAULT_DNS_TTL;
690  else
691  ttl = clip_dns_ttl(ttl);
692 
693  if (exitname) {
694  /* XXXX fails to ever get attempts to get an exit address of
695  * google.com.digest[=~]nickname.exit; we need a syntax for this that
696  * won't make strict RFC952-compliant applications (like us) barf. */
697  tor_asprintf(&extendedaddress,
698  "%s.%s.exit", address, exitname);
699  tor_asprintf(&extendedval,
700  "%s.%s.exit", name, exitname);
701  } else {
702  tor_asprintf(&extendedaddress,
703  "%s", address);
704  tor_asprintf(&extendedval,
705  "%s", name);
706  }
707  addressmap_register(extendedaddress, extendedval,
708  time(NULL) + ttl, ADDRMAPSRC_DNS, 0, 0);
709  tor_free(extendedaddress);
710 }
711 
712 /** Record the fact that <b>address</b> resolved to <b>val</b>.
713  * We can now use this in subsequent streams via addressmap_rewrite()
714  * so we can more correctly choose an exit that will allow <b>address</b>.
715  *
716  * If <b>exitname</b> is defined, then append the addresses with
717  * ".exitname.exit" before registering the mapping.
718  *
719  * If <b>ttl</b> is nonnegative, the mapping will be valid for
720  * <b>ttl</b>seconds; otherwise, we use the default.
721  */
722 void
724  const char *address,
725  const tor_addr_t *val,
726  const char *exitname,
727  int ttl)
728 {
729  tor_addr_t addr_tmp;
730  char valbuf[TOR_ADDR_BUF_LEN];
731 
732  tor_assert(address);
733  tor_assert(val);
734 
735  if (tor_addr_parse(&addr_tmp, address) >= 0)
736  return; /* If address was an IP address already, don't add a mapping. */
737 
738  if (tor_addr_family(val) == AF_INET) {
739  if (! for_conn->entry_cfg.cache_ipv4_answers)
740  return;
741  } else if (tor_addr_family(val) == AF_INET6) {
742  if (! for_conn->entry_cfg.cache_ipv6_answers)
743  return;
744  }
745 
746  if (! tor_addr_to_str(valbuf, val, sizeof(valbuf), 1))
747  return;
748 
749  client_dns_set_addressmap_impl(for_conn, address, valbuf, exitname, ttl);
750 }
751 
752 /** Add a cache entry noting that <b>address</b> (ordinarily a dotted quad)
753  * resolved via a RESOLVE_PTR request to the hostname <b>v</b>.
754  *
755  * If <b>exitname</b> is defined, then append the addresses with
756  * ".exitname.exit" before registering the mapping.
757  *
758  * If <b>ttl</b> is nonnegative, the mapping will be valid for
759  * <b>ttl</b>seconds; otherwise, we use the default.
760  */
761 void
763  const char *address, const char *v,
764  const char *exitname,
765  int ttl)
766 {
767  char *s = NULL;
768  {
769  tor_addr_t tmp_addr;
770  sa_family_t f = tor_addr_parse(&tmp_addr, address);
771  if ((f == AF_INET && ! for_conn->entry_cfg.cache_ipv4_answers) ||
772  (f == AF_INET6 && ! for_conn->entry_cfg.cache_ipv6_answers))
773  return;
774  }
775  tor_asprintf(&s, "REVERSE[%s]", address);
776  client_dns_set_addressmap_impl(for_conn, s, v, exitname, ttl);
777  tor_free(s);
778 }
779 
780 /* By default, we hand out 127.192.0.1 through 127.254.254.254.
781  * These addresses should map to localhost, so even if the
782  * application accidentally tried to connect to them directly (not
783  * via Tor), it wouldn't get too far astray.
784  *
785  * These options are configured by parse_virtual_addr_network().
786  */
787 
788 static virtual_addr_conf_t virtaddr_conf_ipv4;
789 static virtual_addr_conf_t virtaddr_conf_ipv6;
790 
791 /** Read a netmask of the form 127.192.0.0/10 from "val", and check whether
792  * it's a valid set of virtual addresses to hand out in response to MAPADDRESS
793  * requests. Return 0 on success; set *msg (if provided) to a newly allocated
794  * string and return -1 on failure. If validate_only is false, sets the
795  * actual virtual address range to the parsed value. */
796 int
797 parse_virtual_addr_network(const char *val, sa_family_t family,
798  int validate_only,
799  char **msg)
800 {
801  const int ipv6 = (family == AF_INET6);
802  tor_addr_t addr;
803  maskbits_t bits;
804  const int max_prefix_bits = ipv6 ? 104 : 16;
805  virtual_addr_conf_t *conf = ipv6 ? &virtaddr_conf_ipv6 : &virtaddr_conf_ipv4;
806 
807  if (!val || val[0] == '\0') {
808  if (msg)
809  tor_asprintf(msg, "Value not present (%s) after VirtualAddressNetwork%s",
810  val?"Empty":"NULL", ipv6?"IPv6":"");
811  return -1;
812  }
813  if (tor_addr_parse_mask_ports(val, 0, &addr, &bits, NULL, NULL) < 0) {
814  if (msg)
815  tor_asprintf(msg, "Error parsing VirtualAddressNetwork%s %s",
816  ipv6?"IPv6":"", val);
817  return -1;
818  }
819  if (tor_addr_family(&addr) != family) {
820  if (msg)
821  tor_asprintf(msg, "Incorrect address type for VirtualAddressNetwork%s",
822  ipv6?"IPv6":"");
823  return -1;
824  }
825 #if 0
826  if (port_min != 1 || port_max != 65535) {
827  if (msg)
828  tor_asprintf(msg, "Can't specify ports on VirtualAddressNetwork%s",
829  ipv6?"IPv6":"");
830  return -1;
831  }
832 #endif /* 0 */
833 
834  if (bits > max_prefix_bits) {
835  if (msg)
836  tor_asprintf(msg, "VirtualAddressNetwork%s expects a /%d "
837  "network or larger",ipv6?"IPv6":"", max_prefix_bits);
838  return -1;
839  }
840 
841  if (validate_only)
842  return 0;
843 
844  tor_addr_copy(&conf->addr, &addr);
845  conf->bits = bits;
846 
847  return 0;
848 }
849 
850 /**
851  * Return true iff <b>addr</b> is likely to have been returned by
852  * client_dns_get_unused_address.
853  **/
854 int
855 address_is_in_virtual_range(const char *address)
856 {
857  tor_addr_t addr;
858  tor_assert(address);
859  if (!strcasecmpend(address, ".virtual")) {
860  return 1;
861  } else if (tor_addr_parse(&addr, address) >= 0) {
862  const virtual_addr_conf_t *conf = (tor_addr_family(&addr) == AF_INET6) ?
863  &virtaddr_conf_ipv6 : &virtaddr_conf_ipv4;
864  if (tor_addr_compare_masked(&addr, &conf->addr, conf->bits, CMP_EXACT)==0)
865  return 1;
866  }
867  return 0;
868 }
869 
870 /** Return a random address conforming to the virtual address configuration
871  * in <b>conf</b>.
872  */
873 STATIC void
874 get_random_virtual_addr(const virtual_addr_conf_t *conf, tor_addr_t *addr_out)
875 {
876  uint8_t tmp[4];
877  const uint8_t *addr_bytes;
878  uint8_t bytes[16];
879  const int ipv6 = tor_addr_family(&conf->addr) == AF_INET6;
880  const int total_bytes = ipv6 ? 16 : 4;
881 
882  tor_assert(conf->bits <= total_bytes * 8);
883 
884  /* Set addr_bytes to the bytes of the virtual network, in host order */
885  if (ipv6) {
886  addr_bytes = tor_addr_to_in6_addr8(&conf->addr);
887  } else {
888  set_uint32(tmp, tor_addr_to_ipv4n(&conf->addr));
889  addr_bytes = tmp;
890  }
891 
892  /* Get an appropriate number of random bytes. */
893  crypto_rand((char*)bytes, total_bytes);
894 
895  /* Now replace the first "conf->bits" bits of 'bytes' with addr_bytes*/
896  if (conf->bits >= 8)
897  memcpy(bytes, addr_bytes, conf->bits / 8);
898  if (conf->bits & 7) {
899  uint8_t mask = 0xff >> (conf->bits & 7);
900  bytes[conf->bits/8] &= mask;
901  bytes[conf->bits/8] |= addr_bytes[conf->bits/8] & ~mask;
902  }
903 
904  if (ipv6)
905  tor_addr_from_ipv6_bytes(addr_out, (char*) bytes);
906  else
907  tor_addr_from_ipv4n(addr_out, get_uint32(bytes));
908 
909  tor_assert(tor_addr_compare_masked(addr_out, &conf->addr,
910  conf->bits, CMP_EXACT)==0);
911 }
912 
913 /** Return a newly allocated string holding an address of <b>type</b>
914  * (one of RESOLVED_TYPE_{IPV4|IPV6|HOSTNAME}) that has not yet been
915  * mapped, and that is very unlikely to be the address of any real host.
916  *
917  * May return NULL if we have run out of virtual addresses.
918  */
919 static char *
921 {
922  char buf[64];
924 
925  if (type == RESOLVED_TYPE_HOSTNAME) {
926  char rand_bytes[10];
927  do {
928  crypto_rand(rand_bytes, sizeof(rand_bytes));
929  base32_encode(buf,sizeof(buf),rand_bytes,sizeof(rand_bytes));
930  strlcat(buf, ".virtual", sizeof(buf));
931  } while (strmap_get(addressmap, buf));
932  return tor_strdup(buf);
933  } else if (type == RESOLVED_TYPE_IPV4 || type == RESOLVED_TYPE_IPV6) {
934  const int ipv6 = (type == RESOLVED_TYPE_IPV6);
935  const virtual_addr_conf_t *conf = ipv6 ?
936  &virtaddr_conf_ipv6 : &virtaddr_conf_ipv4;
937 
938  /* Don't try more than 1000 times. This gives us P < 1e-9 for
939  * failing to get a good address so long as the address space is
940  * less than ~97.95% full. That's always going to be true under
941  * sensible circumstances for an IPv6 /10, and it's going to be
942  * true for an IPv4 /10 as long as we've handed out less than
943  * 4.08 million addresses. */
944  uint32_t attempts = 1000;
945 
946  tor_addr_t addr;
947 
948  while (attempts--) {
949  get_random_virtual_addr(conf, &addr);
950 
951  if (!ipv6) {
952  /* Don't hand out any .0 or .255 address. */
953  const uint32_t a = tor_addr_to_ipv4h(&addr);
954  if ((a & 0xff) == 0 || (a & 0xff) == 0xff)
955  continue;
956  }
957 
958  tor_addr_to_str(buf, &addr, sizeof(buf), 1);
959  if (!strmap_get(addressmap, buf)) {
960  /* XXXX This code is to make sure I didn't add an undecorated version
961  * by mistake. I hope it's needless. */
962  char tmp[TOR_ADDR_BUF_LEN];
963  tor_addr_to_str(tmp, &addr, sizeof(tmp), 0);
964  if (strmap_get(addressmap, tmp)) {
965  // LCOV_EXCL_START
966  log_warn(LD_BUG, "%s wasn't in the addressmap, but %s was.",
967  buf, tmp);
968  continue;
969  // LCOV_EXCL_STOP
970  }
971 
972  return tor_strdup(buf);
973  }
974  }
975  log_warn(LD_CONFIG, "Ran out of virtual addresses!");
976  return NULL;
977  } else {
978  // LCOV_EXCL_START
979  log_warn(LD_BUG, "Called with unsupported address type (%d)", type);
980  return NULL;
981  // LCOV_EXCL_STOP
982  }
983 }
984 
985 /** A controller has requested that we map some address of type
986  * <b>type</b> to the address <b>new_address</b>. Choose an address
987  * that is unlikely to be used, and map it, and return it in a newly
988  * allocated string. If another address of the same type is already
989  * mapped to <b>new_address</b>, try to return a copy of that address.
990  *
991  * The string in <b>new_address</b> may be freed or inserted into a map
992  * as appropriate. May return NULL if are out of virtual addresses.
993  **/
994 const char *
995 addressmap_register_virtual_address(int type, char *new_address)
996 {
997  char **addrp;
998  virtaddress_entry_t *vent;
999  int vent_needs_to_be_added = 0;
1000 
1001  tor_assert(new_address);
1004 
1005  vent = strmap_get(virtaddress_reversemap, new_address);
1006  if (!vent) {
1007  vent = tor_malloc_zero(sizeof(virtaddress_entry_t));
1008  vent_needs_to_be_added = 1;
1009  }
1010 
1011  if (type == RESOLVED_TYPE_IPV4)
1012  addrp = &vent->ipv4_address;
1013  else if (type == RESOLVED_TYPE_IPV6)
1014  addrp = &vent->ipv6_address;
1015  else
1016  addrp = &vent->hostname_address;
1017 
1018  if (*addrp) {
1019  addressmap_entry_t *ent = strmap_get(addressmap, *addrp);
1020  if (ent && ent->new_address &&
1021  !strcasecmp(new_address, ent->new_address)) {
1022  tor_free(new_address);
1023  tor_assert(!vent_needs_to_be_added);
1024  return *addrp;
1025  } else {
1026  log_warn(LD_BUG,
1027  "Internal confusion: I thought that '%s' was mapped to by "
1028  "'%s', but '%s' really maps to '%s'. This is a harmless bug.",
1029  safe_str_client(new_address),
1030  safe_str_client(*addrp),
1031  safe_str_client(*addrp),
1032  ent?safe_str_client(ent->new_address):"(nothing)");
1033  }
1034  }
1035 
1036  tor_free(*addrp);
1037  *addrp = addressmap_get_virtual_address(type);
1038  if (!*addrp) {
1039  tor_free(vent);
1040  tor_free(new_address);
1041  return NULL;
1042  }
1043  log_info(LD_APP, "Registering map from %s to %s", *addrp, new_address);
1044  if (vent_needs_to_be_added)
1045  strmap_set(virtaddress_reversemap, new_address, vent);
1046  addressmap_register(*addrp, new_address, 2, ADDRMAPSRC_AUTOMAP, 0, 0);
1047 
1048  /* FFFF register corresponding reverse mapping. */
1049 
1050 #if 0
1051  {
1052  /* Try to catch possible bugs */
1053  addressmap_entry_t *ent;
1054  ent = strmap_get(addressmap, *addrp);
1055  tor_assert(ent);
1056  tor_assert(!strcasecmp(ent->new_address,new_address));
1057  vent = strmap_get(virtaddress_reversemap, new_address);
1058  tor_assert(vent);
1059  tor_assert(!strcasecmp(*addrp,
1060  (type == RESOLVED_TYPE_IPV4) ?
1061  vent->ipv4_address : vent->hostname_address));
1062  log_info(LD_APP, "Map from %s to %s okay.",
1063  safe_str_client(*addrp),
1064  safe_str_client(new_address));
1065  }
1066 #endif /* 0 */
1067 
1068  return *addrp;
1069 }
1070 
1071 /** Return 1 if <b>address</b> has funny characters in it like colons. Return
1072  * 0 if it's fine, or if we're configured to allow it anyway. <b>client</b>
1073  * should be true if we're using this address as a client; false if we're
1074  * using it as a server.
1075  */
1076 int
1077 address_is_invalid_destination(const char *address, int client)
1078 {
1079  if (client) {
1080  if (get_options()->AllowNonRFC953Hostnames)
1081  return 0;
1082  } else {
1083  if (get_options()->ServerDNSAllowNonRFC953Hostnames)
1084  return 0;
1085  }
1086 
1087  /* It might be an IPv6 address! */
1088  {
1089  tor_addr_t a;
1090  if (tor_addr_parse(&a, address) >= 0)
1091  return 0;
1092  }
1093 
1094  while (*address) {
1095  if (TOR_ISALNUM(*address) ||
1096  *address == '-' ||
1097  *address == '.' ||
1098  *address == '_') /* Underscore is not allowed, but Windows does it
1099  * sometimes, just to thumb its nose at the IETF. */
1100  ++address;
1101  else
1102  return 1;
1103  }
1104  return 0;
1105 }
1106 
1107 /** Iterate over all address mappings which have expiry times between
1108  * min_expires and max_expires, inclusive. If sl is provided, add an
1109  * "old-addr new-addr expiry" string to sl for each mapping, omitting
1110  * the expiry time if want_expiry is false. If sl is NULL, remove the
1111  * mappings.
1112  */
1113 void
1114 addressmap_get_mappings(smartlist_t *sl, time_t min_expires,
1115  time_t max_expires, int want_expiry)
1116 {
1117  strmap_iter_t *iter;
1118  const char *key;
1119  void *val_;
1120  addressmap_entry_t *val;
1121 
1122  if (!addressmap)
1123  addressmap_init();
1124 
1125  for (iter = strmap_iter_init(addressmap); !strmap_iter_done(iter); ) {
1126  strmap_iter_get(iter, &key, &val_);
1127  val = val_;
1128  if (val->expires >= min_expires && val->expires <= max_expires) {
1129  if (!sl) {
1130  iter = strmap_iter_next_rmv(addressmap,iter);
1131  addressmap_ent_remove(key, val);
1132  continue;
1133  } else if (val->new_address) {
1134  const char *src_wc = val->src_wildcard ? "*." : "";
1135  const char *dst_wc = val->dst_wildcard ? "*." : "";
1136  if (want_expiry) {
1137  if (val->expires < 3 || val->expires == TIME_MAX)
1138  smartlist_add_asprintf(sl, "%s%s %s%s NEVER",
1139  src_wc, key, dst_wc, val->new_address);
1140  else {
1141  char isotime[ISO_TIME_LEN+1];
1142  format_iso_time(isotime, val->expires);
1143  smartlist_add_asprintf(sl, "%s%s %s%s \"%s\"",
1144  src_wc, key, dst_wc, val->new_address,
1145  isotime);
1146  }
1147  } else {
1148  smartlist_add_asprintf(sl, "%s%s %s%s",
1149  src_wc, key, dst_wc, val->new_address);
1150  }
1151  }
1152  }
1153  iter = strmap_iter_next(addressmap,iter);
1154  }
1155 }
void tor_addr_from_ipv4n(tor_addr_t *dest, uint32_t v4addr)
Definition: address.c:879
uint32_t clip_dns_ttl(uint32_t ttl)
static void addressmap_virtaddress_remove(const char *address, addressmap_entry_t *ent)
Definition: addressmap.c:140
void crypto_rand(char *to, size_t n)
Definition: crypto_rand.c:477
const char * tor_addr_to_str(char *dest, const tor_addr_t *addr, size_t len, int decorate)
Definition: address.c:328
void * strmap_get_lc(const strmap_t *map, const char *key)
Definition: map.c:393
void client_dns_clear_failures(const char *address)
Definition: addressmap.c:659
#define TOR_ADDR_BUF_LEN
Definition: address.h:210
Common functions for using (pseudo-)random number generators.
Definition: node_st.h:34
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
uint16_t sa_family_t
Definition: inaddr_st.h:77
int routerset_contains_node(const routerset_t *set, const node_t *node)
Definition: routerset.c:338
Header for addressmap.c.
#define MAX_DNS_ENTRY_AGE
int addressmap_have_mapping(const char *address, int update_expiry)
Definition: addressmap.c:544
static uint32_t tor_addr_to_ipv4n(const tor_addr_t *a)
Definition: address.h:147
Header file for nodelist.c.
int strcmpend(const char *s1, const char *s2)
Definition: util_string.c:242
struct smartlist_t * AutomapHostsSuffixes
int addressmap_address_should_automap(const char *address, const or_options_t *options)
Definition: addressmap.c:249
static addressmap_entry_t * addressmap_match_superdomains(char *address)
Definition: addressmap.c:349
Header file for config.c.
const or_options_t * get_options(void)
Definition: config.c:925
#define tor_assert(expr)
Definition: util_bug.h:102
void base32_encode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:60
static uint32_t tor_addr_to_ipv4h(const tor_addr_t *a)
Definition: address.h:155
struct routerset_t * ExitNodes
Definition: or_options_st.h:77
addressmap_entry_source_t
Definition: or.h:1023
#define MAP_DEL_CURRENT(keyvar)
Definition: map.h:140
#define tor_free(p)
Definition: malloc.h:52
const char * name
Definition: config.c:2440
void client_dns_set_addressmap(entry_connection_t *for_conn, const char *address, const tor_addr_t *val, const char *exitname, int ttl)
Definition: addressmap.c:723
void clear_trackexithost_mappings(const char *exitname)
Definition: addressmap.c:174
int addressmap_rewrite(char *address, size_t maxlen, unsigned flags, time_t *expires_out, addressmap_entry_source_t *exit_source_out)
Definition: addressmap.c:383
STATIC void get_random_virtual_addr(const virtual_addr_conf_t *conf, tor_addr_t *addr_out)
Definition: addressmap.c:874
#define STATIC
Definition: testsupport.h:32
static void set_uint32(void *cp, uint32_t v)
Definition: bytes.h:87
static uint32_t get_uint32(const void *cp)
Definition: bytes.h:54
uint8_t maskbits_t
Definition: address.h:62
Header file for routerset.c.
#define LD_APP
Definition: log.h:78
Definition: addressmap.c:57
void addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires, int want_expiry)
Definition: addressmap.c:1114
int strcasecmpend(const char *s1, const char *s2)
Definition: util_string.c:255
void addressmap_init(void)
Definition: addressmap.c:90
static void addressmap_virtaddress_ent_free_(virtaddress_entry_t *ent)
Definition: addressmap.c:121
int tor_asprintf(char **strp, const char *fmt,...)
Definition: printf.c:75
static strmap_t * virtaddress_reversemap
Definition: addressmap.c:86
void tor_addr_from_ipv6_bytes(tor_addr_t *dest, const char *ipv6_bytes)
Definition: address.c:890
void smartlist_add_asprintf(struct smartlist_t *sl, const char *pattern,...)
Definition: smartlist.c:36
Master header file for Tor-specific functionality.
int client_dns_incr_failures(const char *address)
Definition: addressmap.c:637
static void addressmap_ent_remove(const char *address, addressmap_entry_t *ent)
Definition: addressmap.c:165
int tor_addr_parse_mask_ports(const char *s, unsigned flags, tor_addr_t *addr_out, maskbits_t *maskbits_out, uint16_t *port_min_out, uint16_t *port_max_out)
Definition: address.c:543
int tor_addr_parse(tor_addr_t *addr, const char *src)
Definition: address.c:1260
void addressmap_free_all(void)
Definition: addressmap.c:328
Entry connection structure.
Header file for circuituse.c.
void tor_strlower(char *s)
Definition: util_string.c:127
void addressmap_clean(time_t now)
Definition: addressmap.c:320
int AutomapHostsOnResolve
const node_t * node_get_by_nickname(const char *nickname, unsigned flags)
Definition: nodelist.c:1013
int hostname_in_track_host_exits(const or_options_t *options, const char *address)
Definition: circuituse.c:2702
int address_is_in_virtual_range(const char *address)
Definition: addressmap.c:855
void addressmap_clear_configured(void)
Definition: addressmap.c:304
int addressmap_rewrite_reverse(char *address, size_t maxlen, unsigned flags, time_t *expires_out)
Definition: addressmap.c:503
#define DEFAULT_DNS_TTL
void addressmap_register(const char *address, char *new_address, time_t expires, addressmap_entry_source_t source, const int wildcard_addr, const int wildcard_new_addr)
Definition: addressmap.c:576
static void addressmap_ent_free_(addressmap_entry_t *ent)
Definition: addressmap.c:101
Header file for connection_edge.c.
void format_iso_time(char *buf, time_t t)
Definition: time_fmt.c:295
static char * addressmap_get_virtual_address(int type)
Definition: addressmap.c:920
unsigned int cache_ipv4_answers
int address_is_invalid_destination(const char *address, int client)
Definition: addressmap.c:1077
void client_dns_set_reverse_addressmap(entry_connection_t *for_conn, const char *address, const char *v, const char *exitname, int ttl)
Definition: addressmap.c:762
static strmap_t * addressmap
Definition: addressmap.c:74
static void client_dns_set_addressmap_impl(entry_connection_t *for_conn, const char *address, const char *name, const char *exitname, int ttl)
Definition: addressmap.c:677
struct routerset_t * ExcludeExitNodesUnion_
Definition: or_options_st.h:99
int tor_addr_compare_masked(const tor_addr_t *addr1, const tor_addr_t *addr2, maskbits_t mbits, tor_addr_comparison_t how)
Definition: address.c:980
#define tor_addr_to_in6_addr8(x)
Definition: address.h:130
void addressmap_clear_excluded_trackexithosts(const or_options_t *options)
Definition: addressmap.c:197
void addressmap_clear_transient(void)
Definition: addressmap.c:311
Definition: addressmap.c:67
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
Definition: address.c:909
int parse_virtual_addr_network(const char *val, sa_family_t family, int validate_only, char **msg)
Definition: addressmap.c:797
Header file for control_events.c.
const char * addressmap_register_virtual_address(int type, char *new_address)
Definition: addressmap.c:995
int control_event_address_mapped(const char *from, const char *to, time_t expires, const char *error, const int cached)
#define LD_BUG
Definition: log.h:86
#define LD_CONFIG
Definition: log.h:68
int routerset_is_empty(const routerset_t *set)
Definition: routerset.c:203
const char * escaped_safe_str_client(const char *address)
Definition: config.c:1116
void addressmap_clear_invalid_automaps(const or_options_t *options)
Definition: addressmap.c:271
static sa_family_t tor_addr_family(const tor_addr_t *a)
Definition: address.h:182