diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-10-28 17:13:37 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-11-14 23:16:21 -0500 |
commit | ca8843df0adb088b028b5599cd3062ea608f716b (patch) | |
tree | 01ec663df0343f0e9a007981faf8fb1b6229a316 /src | |
parent | 7908ab209350782646dfc112d346ea75974b9dec (diff) | |
download | tor-ca8843df0adb088b028b5599cd3062ea608f716b.tar tor-ca8843df0adb088b028b5599cd3062ea608f716b.tar.gz |
Refactor client_dns_set_{reverse_,}addressmap() to take a circ
We'd like these functions to be circuit-relative so that we can
implement a per-circuit DNS cache and per-circuit DNS cache rules for
proposal 205 or its successors. I'm doing this now, as a part of the
IPv6 exits code, since there are about to be a few more instances
of code using this.
Diffstat (limited to 'src')
-rw-r--r-- | src/or/addressmap.c | 14 | ||||
-rw-r--r-- | src/or/addressmap.h | 6 | ||||
-rw-r--r-- | src/or/connection_edge.c | 13 | ||||
-rw-r--r-- | src/or/relay.c | 7 |
4 files changed, 28 insertions, 12 deletions
diff --git a/src/or/addressmap.c b/src/or/addressmap.c index fec83a7eb..4aa46fc6e 100644 --- a/src/or/addressmap.c +++ b/src/or/addressmap.c @@ -571,7 +571,8 @@ client_dns_clear_failures(const char *address) * <b>ttl</b>seconds; otherwise, we use the default. */ static void -client_dns_set_addressmap_impl(const char *address, const char *name, +client_dns_set_addressmap_impl(origin_circuit_t *on_circ, + const char *address, const char *name, const char *exitname, int ttl) { @@ -579,6 +580,7 @@ client_dns_set_addressmap_impl(const char *address, const char *name, char extendedaddress[MAX_SOCKS_ADDR_LEN+MAX_VERBOSE_NICKNAME_LEN+10]; /* 123.123.123.123.<hex or nickname>.exit\0 or just 123.123.123.123\0 */ char extendedval[INET_NTOA_BUF_LEN+MAX_VERBOSE_NICKNAME_LEN+10]; + (void)on_circ; tor_assert(address); tor_assert(name); @@ -617,7 +619,8 @@ client_dns_set_addressmap_impl(const char *address, const char *name, * <b>ttl</b>seconds; otherwise, we use the default. */ void -client_dns_set_addressmap(const char *address, uint32_t val, +client_dns_set_addressmap(origin_circuit_t *on_circ, + const char *address, uint32_t val, const char *exitname, int ttl) { @@ -631,7 +634,7 @@ client_dns_set_addressmap(const char *address, uint32_t val, in.s_addr = htonl(val); tor_inet_ntoa(&in,valbuf,sizeof(valbuf)); - client_dns_set_addressmap_impl(address, valbuf, exitname, ttl); + client_dns_set_addressmap_impl(on_circ, address, valbuf, exitname, ttl); } /** Add a cache entry noting that <b>address</b> (ordinarily a dotted quad) @@ -644,13 +647,14 @@ client_dns_set_addressmap(const char *address, uint32_t val, * <b>ttl</b>seconds; otherwise, we use the default. */ void -client_dns_set_reverse_addressmap(const char *address, const char *v, +client_dns_set_reverse_addressmap(origin_circuit_t *on_circ, + const char *address, const char *v, const char *exitname, int ttl) { char *s = NULL; tor_asprintf(&s, "REVERSE[%s]", address); - client_dns_set_addressmap_impl(s, v, exitname, ttl); + client_dns_set_addressmap_impl(on_circ, s, v, exitname, ttl); tor_free(s); } diff --git a/src/or/addressmap.h b/src/or/addressmap.h index 911c7ac29..dd8fc9bcf 100644 --- a/src/or/addressmap.h +++ b/src/or/addressmap.h @@ -28,14 +28,16 @@ int parse_virtual_addr_network(const char *val, int validate_only, char **msg); int client_dns_incr_failures(const char *address); void client_dns_clear_failures(const char *address); -void client_dns_set_addressmap(const char *address, uint32_t val, +void client_dns_set_addressmap(origin_circuit_t *on_circ, + const char *address, uint32_t val, const char *exitname, int ttl); const char *addressmap_register_virtual_address(int type, char *new_address); void addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires, int want_expiry); int address_is_in_virtual_range(const char *addr); void clear_trackexithost_mappings(const char *exitname); -void client_dns_set_reverse_addressmap(const char *address, const char *v, +void client_dns_set_reverse_addressmap(origin_circuit_t *on_circ, + const char *address, const char *v, const char *exitname, int ttl); #endif diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 1ee88f3cd..f548576a2 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -1915,14 +1915,21 @@ connection_ap_handshake_socks_resolved(entry_connection_t *conn, size_t replylen; if (ttl >= 0) { + origin_circuit_t *origin_circ = NULL; + circuit_t *circ = ENTRY_TO_EDGE_CONN(conn)->on_circuit; + if (CIRCUIT_IS_ORIGIN(circ)) /* should always be true */ + origin_circ = TO_ORIGIN_CIRCUIT(circ); if (answer_type == RESOLVED_TYPE_IPV4 && answer_len == 4) { uint32_t a = ntohl(get_uint32(answer)); - if (a) - client_dns_set_addressmap(conn->socks_request->address, a, + if (a) { + client_dns_set_addressmap(origin_circ, + conn->socks_request->address, a, conn->chosen_exit_name, ttl); + } } else if (answer_type == RESOLVED_TYPE_HOSTNAME && answer_len < 256) { char *cp = tor_strndup((char*)answer, answer_len); - client_dns_set_reverse_addressmap(conn->socks_request->address, + client_dns_set_reverse_addressmap(origin_circ, + conn->socks_request->address, cp, conn->chosen_exit_name, ttl); tor_free(cp); diff --git a/src/or/relay.c b/src/or/relay.c index 25fc2e77b..76e9d2550 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -725,7 +725,9 @@ connection_ap_process_end_not_open( connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL); return 0; } - client_dns_set_addressmap(conn->socks_request->address, addr, + + client_dns_set_addressmap(circ, + conn->socks_request->address, addr, conn->chosen_exit_name, ttl); } /* check if he *ought* to have allowed it */ @@ -898,7 +900,8 @@ connection_edge_process_relay_cell_not_open( ttl = (int)ntohl(get_uint32(cell->payload+RELAY_HEADER_SIZE+4)); else ttl = -1; - client_dns_set_addressmap(entry_conn->socks_request->address, addr, + client_dns_set_addressmap(TO_ORIGIN_CIRCUIT(circ), + entry_conn->socks_request->address, addr, entry_conn->chosen_exit_name, ttl); remap_event_helper(entry_conn, addr); |