commit 963b3d15492c6cda3feac6efcff768913352ac2c Author: Nick Mathewson nickm@torproject.org Date: Sun Nov 25 14:31:35 2012 -0500
Refactor the code to check if an address is matched by automapsuffixes --- src/or/addressmap.c | 28 +++++++++++++++++++--------- src/or/addressmap.h | 2 ++ src/or/connection_edge.c | 8 ++------ 3 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/src/or/addressmap.c b/src/or/addressmap.c index 5815bfb..8502178 100644 --- a/src/or/addressmap.c +++ b/src/or/addressmap.c @@ -210,6 +210,24 @@ addressmap_clear_excluded_trackexithosts(const or_options_t *options) } STRMAP_FOREACH_END; }
+/** Return true iff <b>address</b> is one that we are configured to + * automap on resolve according to <b>options</b>. */ +int +addressmap_address_should_automap(const char *address, + const or_options_t *options) +{ + const smartlist_t *suffix_list = options->AutomapHostsSuffixes; + + if (!suffix_list) + return 0; + + SMARTLIST_FOREACH_BEGIN(suffix_list, const char *, suffix) { + if (!strcasecmpend(address, suffix)) + return 1; + } SMARTLIST_FOREACH_END(suffix); + return 0; +} + /** Remove all AUTOMAP mappings from the addressmap for which the * source address no longer matches AutomapHostsSuffixes, which is * no longer allowed by AutomapHostsOnResolve, or for which the @@ -232,15 +250,7 @@ addressmap_clear_invalid_automaps(const or_options_t *options) continue; /* not an automap mapping. */
if (!remove) { - int suffix_found = 0; - SMARTLIST_FOREACH(suffixes, const char *, suffix, { - if (!strcasecmpend(src_address, suffix)) { - suffix_found = 1; - break; - } - }); - if (!suffix_found) - remove = 1; + remove = ! addressmap_address_should_automap(src_address, options); }
if (!remove && ! address_is_in_virtual_range(ent->new_address)) diff --git a/src/or/addressmap.h b/src/or/addressmap.h index 0c73201..4534fff 100644 --- a/src/or/addressmap.h +++ b/src/or/addressmap.h @@ -42,6 +42,8 @@ void clear_trackexithost_mappings(const char *exitname); void client_dns_set_reverse_addressmap(entry_connection_t *for_conn, const char *address, const char *v, const char *exitname, int ttl); +int addressmap_address_should_automap(const char *address, + const or_options_t *options);
#endif
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 3207f58..9ccf58e 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -928,12 +928,8 @@ connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn,
if (socks->command == SOCKS_COMMAND_RESOLVE && !tor_inet_aton(socks->address, &addr_tmp) && - options->AutomapHostsOnResolve && options->AutomapHostsSuffixes) { - SMARTLIST_FOREACH(options->AutomapHostsSuffixes, const char *, cp, - if (!strcasecmpend(socks->address, cp)) { - automap = 1; - break; - }); + options->AutomapHostsOnResolve) { + automap = addressmap_address_should_automap(socks->address, options); if (automap) { const char *new_addr; new_addr = addressmap_register_virtual_address(
tor-commits@lists.torproject.org