diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-04-08 18:02:03 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-01-13 12:41:15 -0500 |
commit | 9d0fab9872807ef212fadb3feb299cf6309a185f (patch) | |
tree | e7dcafceb46a841cfe1fe67da22b747ebe3aa675 /src/or | |
parent | ab6bd78eca0f3edc7ed910d8567c409fe3dfdd92 (diff) | |
download | tor-9d0fab9872807ef212fadb3feb299cf6309a185f.tar.gz tor-9d0fab9872807ef212fadb3feb299cf6309a185f.zip |
Allow MapAddress and Automap to work together
The trick here is to apply mapaddress first, and only then apply
automapping. Otherwise, the automap checks don't get done.
Fix for bug 7555; bugfix on all versions of Tor supporting both
MapAddress and AutoMap.
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/addressmap.c | 36 | ||||
-rw-r--r-- | src/or/addressmap.h | 7 | ||||
-rw-r--r-- | src/or/connection_edge.c | 17 |
3 files changed, 49 insertions, 11 deletions
diff --git a/src/or/addressmap.c b/src/or/addressmap.c index 0f417e6369..ea01894634 100644 --- a/src/or/addressmap.c +++ b/src/or/addressmap.c @@ -390,13 +390,35 @@ addressmap_rewrite(char *address, size_t maxlen, goto done; } - if (ent && ent->source == ADDRMAPSRC_DNS) { - sa_family_t f; - tor_addr_t tmp; - f = tor_addr_parse(&tmp, ent->new_address); - if (f == AF_INET && !(flags & AMR_FLAG_USE_IPV4_DNS)) - goto done; - else if (f == AF_INET6 && !(flags & AMR_FLAG_USE_IPV6_DNS)) + switch (ent->source) { + case ADDRMAPSRC_DNS: + { + sa_family_t f; + tor_addr_t tmp; + f = tor_addr_parse(&tmp, ent->new_address); + if (f == AF_INET && !(flags & AMR_FLAG_USE_IPV4_DNS)) + goto done; + else if (f == AF_INET6 && !(flags & AMR_FLAG_USE_IPV6_DNS)) + goto done; + } + break; + case ADDRMAPSRC_CONTROLLER: + case ADDRMAPSRC_TORRC: + if (!(flags & AMR_FLAG_USE_MAPADDRESS)) + goto done; + break; + case ADDRMAPSRC_AUTOMAP: + if (!(flags & AMR_FLAG_USE_AUTOMAP)) + goto done; + break; + case ADDRMAPSRC_TRACKEXIT: + if (!(flags & AMR_FLAG_USE_TRACKEXIT)) + goto done; + break; + case ADDRMAPSRC_NONE: + default: + log_warn(LD_BUG, "Unknown addrmap source value %d. Ignoring it.", + (int) ent->source); goto done; } diff --git a/src/or/addressmap.h b/src/or/addressmap.h index bb737e47f4..ff108df024 100644 --- a/src/or/addressmap.h +++ b/src/or/addressmap.h @@ -16,8 +16,11 @@ void addressmap_clean(time_t now); void addressmap_clear_configured(void); void addressmap_clear_transient(void); void addressmap_free_all(void); -#define AMR_FLAG_USE_IPV4_DNS (1u<<0) -#define AMR_FLAG_USE_IPV6_DNS (1u<<1) +#define AMR_FLAG_USE_IPV4_DNS (1u<<0) +#define AMR_FLAG_USE_IPV6_DNS (1u<<1) +#define AMR_FLAG_USE_MAPADDRESS (1u<<2) +#define AMR_FLAG_USE_AUTOMAP (1u<<3) +#define AMR_FLAG_USE_TRACKEXIT (1u<<4) int addressmap_rewrite(char *address, size_t maxlen, unsigned flags, time_t *expires_out, addressmap_entry_source_t *exit_source_out); diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index ca99a86ae0..7a77f5e20a 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -946,6 +946,15 @@ connection_ap_handshake_rewrite(entry_connection_t *conn, if (! conn->original_dest_address) conn->original_dest_address = tor_strdup(conn->socks_request->address); + if (socks->command != SOCKS_COMMAND_RESOLVE_PTR) { + const unsigned rewrite_flags = AMR_FLAG_USE_MAPADDRESS; + if (addressmap_rewrite(socks->address, sizeof(socks->address), + rewrite_flags, &out->map_expires, &out->exit_source)) { + control_event_stream_status(conn, STREAM_EVENT_REMAP, + REMAP_STREAM_SOURCE_CACHE); + } + } + if (socks->command == SOCKS_COMMAND_RESOLVE && tor_addr_parse(&addr_tmp, socks->address)<0 && options->AutomapHostsOnResolve) { @@ -1014,16 +1023,20 @@ connection_ap_handshake_rewrite(entry_connection_t *conn, } } else if (!out->automap) { /* For address map controls, remap the address. */ - unsigned rewrite_flags = 0; + unsigned rewrite_flags = AMR_FLAG_USE_AUTOMAP | AMR_FLAG_USE_TRACKEXIT; + addressmap_entry_source_t exit_source2; if (conn->use_cached_ipv4_answers) rewrite_flags |= AMR_FLAG_USE_IPV4_DNS; if (conn->use_cached_ipv6_answers) rewrite_flags |= AMR_FLAG_USE_IPV6_DNS; if (addressmap_rewrite(socks->address, sizeof(socks->address), - rewrite_flags, &out->map_expires, &out->exit_source)) { + rewrite_flags, &out->map_expires, &exit_source2)) { control_event_stream_status(conn, STREAM_EVENT_REMAP, REMAP_STREAM_SOURCE_CACHE); } + if (out->exit_source == ADDRMAPSRC_NONE) { + out->exit_source = exit_source2; + } } if (!out->automap && address_is_in_virtual_range(socks->address)) { |