mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
Implement option to turn off DNS cache modification by a client port
(This is part 3 of making DNS cache use enabled/disabled on a per-client port basis. This implements the UseCacheIPv[46]DNS options)
This commit is contained in:
parent
f33487668f
commit
7536c40e96
@ -594,13 +594,13 @@ client_dns_clear_failures(const char *address)
|
||||
* <b>ttl</b>seconds; otherwise, we use the default.
|
||||
*/
|
||||
static void
|
||||
client_dns_set_addressmap_impl(origin_circuit_t *on_circ,
|
||||
client_dns_set_addressmap_impl(entry_connection_t *for_conn,
|
||||
const char *address, const char *name,
|
||||
const char *exitname,
|
||||
int ttl)
|
||||
{
|
||||
char *extendedaddress=NULL, *extendedval=NULL;
|
||||
(void)on_circ;
|
||||
(void)for_conn;
|
||||
|
||||
tor_assert(address);
|
||||
tor_assert(name);
|
||||
@ -640,7 +640,7 @@ client_dns_set_addressmap_impl(origin_circuit_t *on_circ,
|
||||
* <b>ttl</b>seconds; otherwise, we use the default.
|
||||
*/
|
||||
void
|
||||
client_dns_set_addressmap(origin_circuit_t *on_circ,
|
||||
client_dns_set_addressmap(entry_connection_t *for_conn,
|
||||
const char *address,
|
||||
const tor_addr_t *val,
|
||||
const char *exitname,
|
||||
@ -655,14 +655,18 @@ client_dns_set_addressmap(origin_circuit_t *on_circ,
|
||||
if (tor_addr_parse(&addr_tmp, address) >= 0)
|
||||
return; /* If address was an IP address already, don't add a mapping. */
|
||||
|
||||
/* XXXXX For now, don't cache IPv6 addresses. */
|
||||
if (tor_addr_family(val) != AF_INET)
|
||||
return;
|
||||
if (tor_addr_family(val) == AF_INET) {
|
||||
if (! for_conn->cache_ipv4_answers)
|
||||
return;
|
||||
} else if (tor_addr_family(val) == AF_INET6) {
|
||||
if (! for_conn->cache_ipv6_answers)
|
||||
return;
|
||||
}
|
||||
|
||||
if (! tor_addr_to_str(valbuf, val, sizeof(valbuf), 1))
|
||||
return;
|
||||
|
||||
client_dns_set_addressmap_impl(on_circ, address, valbuf, exitname, ttl);
|
||||
client_dns_set_addressmap_impl(for_conn, address, valbuf, exitname, ttl);
|
||||
}
|
||||
|
||||
/** Add a cache entry noting that <b>address</b> (ordinarily a dotted quad)
|
||||
@ -675,14 +679,21 @@ client_dns_set_addressmap(origin_circuit_t *on_circ,
|
||||
* <b>ttl</b>seconds; otherwise, we use the default.
|
||||
*/
|
||||
void
|
||||
client_dns_set_reverse_addressmap(origin_circuit_t *on_circ,
|
||||
client_dns_set_reverse_addressmap(entry_connection_t *for_conn,
|
||||
const char *address, const char *v,
|
||||
const char *exitname,
|
||||
int ttl)
|
||||
{
|
||||
char *s = NULL;
|
||||
{
|
||||
tor_addr_t tmp_addr;
|
||||
sa_family_t f = tor_addr_parse(&tmp_addr, address);
|
||||
if ((f == AF_INET && ! for_conn->cache_ipv4_answers) ||
|
||||
(f == AF_INET6 && ! for_conn->cache_ipv6_answers))
|
||||
return;
|
||||
}
|
||||
tor_asprintf(&s, "REVERSE[%s]", address);
|
||||
client_dns_set_addressmap_impl(on_circ, s, v, exitname, ttl);
|
||||
client_dns_set_addressmap_impl(for_conn, s, v, exitname, ttl);
|
||||
tor_free(s);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ 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(origin_circuit_t *on_circ,
|
||||
void client_dns_set_addressmap(entry_connection_t *for_conn,
|
||||
const char *address, const tor_addr_t *val,
|
||||
const char *exitname, int ttl);
|
||||
const char *addressmap_register_virtual_address(int type, char *new_address);
|
||||
@ -39,7 +39,7 @@ 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(origin_circuit_t *on_circ,
|
||||
void client_dns_set_reverse_addressmap(entry_connection_t *for_conn,
|
||||
const char *address, const char *v,
|
||||
const char *exitname, int ttl);
|
||||
|
||||
|
@ -2072,7 +2072,7 @@ connection_ap_handshake_socks_resolved(entry_connection_t *conn,
|
||||
tor_addr_t a;
|
||||
tor_addr_from_ipv4n(&a, get_uint32(answer));
|
||||
if (! tor_addr_is_null(&a)) {
|
||||
client_dns_set_addressmap(origin_circ,
|
||||
client_dns_set_addressmap(conn,
|
||||
conn->socks_request->address, &a,
|
||||
conn->chosen_exit_name, ttl);
|
||||
}
|
||||
@ -2080,13 +2080,13 @@ connection_ap_handshake_socks_resolved(entry_connection_t *conn,
|
||||
tor_addr_t a;
|
||||
tor_addr_from_ipv6_bytes(&a, (char*)answer);
|
||||
if (! tor_addr_is_null(&a)) {
|
||||
client_dns_set_addressmap(origin_circ,
|
||||
client_dns_set_addressmap(conn,
|
||||
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(origin_circ,
|
||||
client_dns_set_reverse_addressmap(conn,
|
||||
conn->socks_request->address,
|
||||
cp,
|
||||
conn->chosen_exit_name, ttl);
|
||||
|
@ -742,7 +742,7 @@ connection_ap_process_end_not_open(
|
||||
return 0;
|
||||
}
|
||||
|
||||
client_dns_set_addressmap(circ,
|
||||
client_dns_set_addressmap(conn,
|
||||
conn->socks_request->address, &addr,
|
||||
conn->chosen_exit_name, ttl);
|
||||
}
|
||||
@ -979,7 +979,7 @@ connection_edge_process_relay_cell_not_open(
|
||||
return 0;
|
||||
}
|
||||
|
||||
client_dns_set_addressmap(TO_ORIGIN_CIRCUIT(circ),
|
||||
client_dns_set_addressmap(entry_conn,
|
||||
entry_conn->socks_request->address, &addr,
|
||||
entry_conn->chosen_exit_name, ttl);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user