mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-01 08:03:31 +01:00
cache .exit address better (i think)
svn:r3684
This commit is contained in:
parent
2ecd3ff709
commit
5b24ca6cde
@ -490,20 +490,35 @@ int client_dns_incr_failures(const char *address)
|
|||||||
/** Record the fact that <b>address</b> resolved to <b>val</b>.
|
/** Record the fact that <b>address</b> resolved to <b>val</b>.
|
||||||
* We can now use this in subsequent streams via addressmap_rewrite()
|
* We can now use this in subsequent streams via addressmap_rewrite()
|
||||||
* so we can more correctly choose an exit that will allow <b>address</b>.
|
* so we can more correctly choose an exit that will allow <b>address</b>.
|
||||||
|
*
|
||||||
|
* If <b>exitname</b> is defined, then append the addresses with
|
||||||
|
* ".exitname.exit" before registering the mapping.
|
||||||
*/
|
*/
|
||||||
void client_dns_set_addressmap(const char *address, uint32_t val)
|
void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname)
|
||||||
{
|
{
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
char *addr;
|
char extendedaddress[MAX_SOCKS_ADDR_LEN+MAX_HEX_NICKNAME_LEN+10];
|
||||||
|
char valbuf[INET_NTOA_BUF_LEN];
|
||||||
|
char extendedval[INET_NTOA_BUF_LEN+MAX_HEX_NICKNAME_LEN+10];
|
||||||
|
|
||||||
tor_assert(address); tor_assert(val);
|
tor_assert(address); tor_assert(val);
|
||||||
|
|
||||||
if (tor_inet_aton(address, &in))
|
if (tor_inet_aton(address, &in))
|
||||||
return; /* If address was an IP address already, don't add a mapping. */
|
return; /* If address was an IP address already, don't add a mapping. */
|
||||||
in.s_addr = htonl(val);
|
in.s_addr = htonl(val);
|
||||||
addr = tor_malloc(INET_NTOA_BUF_LEN);
|
tor_inet_ntoa(&in,valbuf,sizeof(valbuf));
|
||||||
tor_inet_ntoa(&in,addr,INET_NTOA_BUF_LEN);
|
if (exitname) {
|
||||||
addressmap_register(address, addr,
|
tor_snprintf(extendedaddress, sizeof(extendedaddress),
|
||||||
|
"%s.%s.exit", address, exitname);
|
||||||
|
tor_snprintf(extendedval, sizeof(extendedval),
|
||||||
|
"%s.%s.exit", valbuf, exitname);
|
||||||
|
} else {
|
||||||
|
tor_snprintf(extendedaddress, sizeof(extendedaddress),
|
||||||
|
"%s", address);
|
||||||
|
tor_snprintf(extendedval, sizeof(extendedval),
|
||||||
|
"%s", valbuf);
|
||||||
|
}
|
||||||
|
addressmap_register(extendedaddress, tor_strdup(extendedval),
|
||||||
time(NULL) + MAX_DNS_ENTRY_AGE);
|
time(NULL) + MAX_DNS_ENTRY_AGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -754,8 +769,8 @@ int connection_ap_handshake_send_resolve(connection_t *ap_conn, circuit_t *circ)
|
|||||||
}
|
}
|
||||||
|
|
||||||
string_addr = ap_conn->socks_request->address;
|
string_addr = ap_conn->socks_request->address;
|
||||||
payload_len = strlen(string_addr);
|
payload_len = strlen(string_addr)+1;
|
||||||
tor_assert(strlen(string_addr) <= RELAY_PAYLOAD_SIZE);
|
tor_assert(payload_len <= RELAY_PAYLOAD_SIZE);
|
||||||
|
|
||||||
log_fn(LOG_DEBUG,"Sending relay cell to begin stream %d.",ap_conn->stream_id);
|
log_fn(LOG_DEBUG,"Sending relay cell to begin stream %d.",ap_conn->stream_id);
|
||||||
|
|
||||||
@ -840,7 +855,8 @@ void connection_ap_handshake_socks_resolved(connection_t *conn,
|
|||||||
if (answer_type == RESOLVED_TYPE_IPV4) {
|
if (answer_type == RESOLVED_TYPE_IPV4) {
|
||||||
uint32_t a = get_uint32(answer);
|
uint32_t a = get_uint32(answer);
|
||||||
if (a)
|
if (a)
|
||||||
client_dns_set_addressmap(conn->socks_request->address, ntohl(a));
|
client_dns_set_addressmap(conn->socks_request->address, ntohl(a),
|
||||||
|
conn->chosen_exit_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn->socks_request->socks_version == 4) {
|
if (conn->socks_request->socks_version == 4) {
|
||||||
|
@ -1289,7 +1289,7 @@ void addressmap_rewrite(char *address, size_t maxlen);
|
|||||||
int addressmap_already_mapped(const char *address);
|
int addressmap_already_mapped(const char *address);
|
||||||
void addressmap_register(const char *address, char *new_address, time_t expires);
|
void addressmap_register(const char *address, char *new_address, time_t expires);
|
||||||
int client_dns_incr_failures(const char *address);
|
int client_dns_incr_failures(const char *address);
|
||||||
void client_dns_set_addressmap(const char *address, uint32_t val);
|
void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname);
|
||||||
|
|
||||||
void parse_socks_policy(void);
|
void parse_socks_policy(void);
|
||||||
void free_socks_policy(void);
|
void free_socks_policy(void);
|
||||||
|
@ -518,7 +518,8 @@ connection_edge_process_relay_cell_not_open(
|
|||||||
connection_mark_for_close(conn);
|
connection_mark_for_close(conn);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
client_dns_set_addressmap(conn->socks_request->address, addr);
|
client_dns_set_addressmap(conn->socks_request->address, addr,
|
||||||
|
conn->chosen_exit_name);
|
||||||
|
|
||||||
/* check if he *ought* to have allowed it */
|
/* check if he *ought* to have allowed it */
|
||||||
exitrouter = router_get_by_digest(circ->build_state->chosen_exit_digest);
|
exitrouter = router_get_by_digest(circ->build_state->chosen_exit_digest);
|
||||||
@ -591,7 +592,8 @@ connection_edge_process_relay_cell_not_open(
|
|||||||
connection_mark_for_close(conn);
|
connection_mark_for_close(conn);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
client_dns_set_addressmap(conn->socks_request->address, addr);
|
client_dns_set_addressmap(conn->socks_request->address, addr,
|
||||||
|
conn->chosen_exit_name);
|
||||||
}
|
}
|
||||||
circuit_log_path(LOG_INFO,circ);
|
circuit_log_path(LOG_INFO,circ);
|
||||||
connection_ap_handshake_socks_reply(conn, NULL, 0, 1);
|
connection_ap_handshake_socks_reply(conn, NULL, 0, 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user