Commit ca8843df authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

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.
parent 7908ab20
......@@ -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);
}
......
......@@ -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
......
......@@ -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);
......
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment