Commit da6bd21b authored by Nick Mathewson's avatar Nick Mathewson 🐻
Browse files

r12644@0-41-wifi: nickm | 2007-03-23 16:02:23 -0400

 Eliminate more redundant circuit_t arguments when edge_connection_t is already supplied and the circuit is already attached.


svn:r9900
parent 306d5400
...@@ -1183,11 +1183,11 @@ connection_ap_handshake_attach_chosen_circuit(edge_connection_t *conn, ...@@ -1183,11 +1183,11 @@ connection_ap_handshake_attach_chosen_circuit(edge_connection_t *conn,
consider_recording_trackhost(conn, circ); consider_recording_trackhost(conn, circ);
/* fall through */ /* fall through */
case SOCKS_COMMAND_CONNECT_DIR: case SOCKS_COMMAND_CONNECT_DIR:
if (connection_ap_handshake_send_begin(conn, circ)<0) if (connection_ap_handshake_send_begin(conn)<0)
return -1; return -1;
break; break;
default: default:
if (connection_ap_handshake_send_resolve(conn, circ)<0) if (connection_ap_handshake_send_resolve(conn)<0)
return -1; return -1;
} }
...@@ -1286,7 +1286,7 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn) ...@@ -1286,7 +1286,7 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn)
*/ */
rendcirc->_base.timestamp_dirty = time(NULL); rendcirc->_base.timestamp_dirty = time(NULL);
link_apconn_to_circ(conn, rendcirc); link_apconn_to_circ(conn, rendcirc);
if (connection_ap_handshake_send_begin(conn, rendcirc) < 0) if (connection_ap_handshake_send_begin(conn) < 0)
return 0; /* already marked, let them fade away */ return 0; /* already marked, let them fade away */
return 1; return 1;
} }
......
...@@ -291,8 +291,9 @@ command_process_created_cell(cell_t *cell, or_connection_t *conn) ...@@ -291,8 +291,9 @@ command_process_created_cell(cell_t *cell, or_connection_t *conn)
} else { /* pack it into an extended relay cell, and send it. */ } else { /* pack it into an extended relay cell, and send it. */
log_debug(LD_OR, log_debug(LD_OR,
"Converting created cell to extended relay cell, sending."); "Converting created cell to extended relay cell, sending.");
connection_edge_send_command(NULL, circ, RELAY_COMMAND_EXTENDED, relay_send_command_from_edge(0, circ, RELAY_COMMAND_EXTENDED,
cell->payload, ONIONSKIN_REPLY_LEN); cell->payload, ONIONSKIN_REPLY_LEN,
NULL);
} }
} }
...@@ -383,8 +384,8 @@ command_process_destroy_cell(cell_t *cell, or_connection_t *conn) ...@@ -383,8 +384,8 @@ command_process_destroy_cell(cell_t *cell, or_connection_t *conn)
char payload[1]; char payload[1];
log_debug(LD_OR, "Delivering 'truncated' back."); log_debug(LD_OR, "Delivering 'truncated' back.");
payload[0] = (char)reason; payload[0] = (char)reason;
connection_edge_send_command(NULL, circ, RELAY_COMMAND_TRUNCATED, relay_send_command_from_edge(0, circ, RELAY_COMMAND_TRUNCATED,
payload, sizeof(payload)); payload, sizeof(payload), NULL);
} }
} }
} }
......
...@@ -211,7 +211,7 @@ connection_edge_end(edge_connection_t *conn, char reason) ...@@ -211,7 +211,7 @@ connection_edge_end(edge_connection_t *conn, char reason)
circ = circuit_get_by_edge_conn(conn); circ = circuit_get_by_edge_conn(conn);
if (circ && !circ->marked_for_close) { if (circ && !circ->marked_for_close) {
log_debug(LD_EDGE,"Sending end on conn (fd %d).",conn->_base.s); log_debug(LD_EDGE,"Sending end on conn (fd %d).",conn->_base.s);
connection_edge_send_command(conn, circ, RELAY_COMMAND_END, connection_edge_send_command(conn, RELAY_COMMAND_END,
payload, payload_len); payload, payload_len);
} else { } else {
log_debug(LD_EDGE,"No circ to send end on conn (fd %d).", log_debug(LD_EDGE,"No circ to send end on conn (fd %d).",
...@@ -301,7 +301,6 @@ connection_edge_finished_connecting(edge_connection_t *edge_conn) ...@@ -301,7 +301,6 @@ connection_edge_finished_connecting(edge_connection_t *edge_conn)
/* deliver a 'connected' relay cell back through the circuit. */ /* deliver a 'connected' relay cell back through the circuit. */
if (connection_edge_is_rendezvous_stream(edge_conn)) { if (connection_edge_is_rendezvous_stream(edge_conn)) {
if (connection_edge_send_command(edge_conn, if (connection_edge_send_command(edge_conn,
circuit_get_by_edge_conn(edge_conn),
RELAY_COMMAND_CONNECTED, NULL, 0) < 0) RELAY_COMMAND_CONNECTED, NULL, 0) < 0)
return 0; /* circuit is closed, don't continue */ return 0; /* circuit is closed, don't continue */
} else { } else {
...@@ -310,7 +309,6 @@ connection_edge_finished_connecting(edge_connection_t *edge_conn) ...@@ -310,7 +309,6 @@ connection_edge_finished_connecting(edge_connection_t *edge_conn)
set_uint32(connected_payload+4, set_uint32(connected_payload+4,
htonl(dns_clip_ttl(edge_conn->address_ttl))); htonl(dns_clip_ttl(edge_conn->address_ttl)));
if (connection_edge_send_command(edge_conn, if (connection_edge_send_command(edge_conn,
circuit_get_by_edge_conn(edge_conn),
RELAY_COMMAND_CONNECTED, RELAY_COMMAND_CONNECTED,
connected_payload, 8) < 0) connected_payload, 8) < 0)
return 0; /* circuit is closed, don't continue */ return 0; /* circuit is closed, don't continue */
...@@ -1740,12 +1738,14 @@ again: ...@@ -1740,12 +1738,14 @@ again:
* If ap_conn is broken, mark it for close and return -1. Else return 0. * If ap_conn is broken, mark it for close and return -1. Else return 0.
*/ */
int int
connection_ap_handshake_send_begin(edge_connection_t *ap_conn, connection_ap_handshake_send_begin(edge_connection_t *ap_conn)
origin_circuit_t *circ)
{ {
char payload[CELL_PAYLOAD_SIZE]; char payload[CELL_PAYLOAD_SIZE];
int payload_len; int payload_len;
int begin_type; int begin_type;
origin_circuit_t *circ;
tor_assert(ap_conn->on_circuit);
circ = TO_ORIGIN_CIRCUIT(ap_conn->on_circuit);
tor_assert(ap_conn->_base.type == CONN_TYPE_AP); tor_assert(ap_conn->_base.type == CONN_TYPE_AP);
tor_assert(ap_conn->_base.state == AP_CONN_STATE_CIRCUIT_WAIT); tor_assert(ap_conn->_base.state == AP_CONN_STATE_CIRCUIT_WAIT);
...@@ -1774,7 +1774,7 @@ connection_ap_handshake_send_begin(edge_connection_t *ap_conn, ...@@ -1774,7 +1774,7 @@ connection_ap_handshake_send_begin(edge_connection_t *ap_conn,
tor_assert(circ->build_state->onehop_tunnel == 0); tor_assert(circ->build_state->onehop_tunnel == 0);
} }
if (connection_edge_send_command(ap_conn, TO_CIRCUIT(circ), begin_type, if (connection_edge_send_command(ap_conn, begin_type,
begin_type == RELAY_COMMAND_BEGIN ? payload : NULL, begin_type == RELAY_COMMAND_BEGIN ? payload : NULL,
begin_type == RELAY_COMMAND_BEGIN ? payload_len : 0) < 0) begin_type == RELAY_COMMAND_BEGIN ? payload_len : 0) < 0)
return -1; /* circuit is closed, don't continue */ return -1; /* circuit is closed, don't continue */
...@@ -1794,12 +1794,14 @@ connection_ap_handshake_send_begin(edge_connection_t *ap_conn, ...@@ -1794,12 +1794,14 @@ connection_ap_handshake_send_begin(edge_connection_t *ap_conn,
* If ap_conn is broken, mark it for close and return -1. Else return 0. * If ap_conn is broken, mark it for close and return -1. Else return 0.
*/ */
int int
connection_ap_handshake_send_resolve(edge_connection_t *ap_conn, connection_ap_handshake_send_resolve(edge_connection_t *ap_conn)
origin_circuit_t *circ)
{ {
int payload_len, command; int payload_len, command;
const char *string_addr; const char *string_addr;
char inaddr_buf[32]; char inaddr_buf[32];
origin_circuit_t *circ;
tor_assert(ap_conn->on_circuit);
circ = TO_ORIGIN_CIRCUIT(ap_conn->on_circuit);
tor_assert(ap_conn->_base.type == CONN_TYPE_AP); tor_assert(ap_conn->_base.type == CONN_TYPE_AP);
tor_assert(ap_conn->_base.state == AP_CONN_STATE_CIRCUIT_WAIT); tor_assert(ap_conn->_base.state == AP_CONN_STATE_CIRCUIT_WAIT);
...@@ -1841,7 +1843,7 @@ connection_ap_handshake_send_resolve(edge_connection_t *ap_conn, ...@@ -1841,7 +1843,7 @@ connection_ap_handshake_send_resolve(edge_connection_t *ap_conn,
log_debug(LD_APP, log_debug(LD_APP,
"Sending relay cell to begin stream %d.", ap_conn->stream_id); "Sending relay cell to begin stream %d.", ap_conn->stream_id);
if (connection_edge_send_command(ap_conn, TO_CIRCUIT(circ), if (connection_edge_send_command(ap_conn,
RELAY_COMMAND_RESOLVE, RELAY_COMMAND_RESOLVE,
string_addr, payload_len) < 0) string_addr, payload_len) < 0)
return -1; /* circuit is closed, don't continue */ return -1; /* circuit is closed, don't continue */
...@@ -2238,13 +2240,14 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ) ...@@ -2238,13 +2240,14 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
return connection_exit_connect_dir(n_stream); return connection_exit_connect_dir(n_stream);
} }
TO_OR_CIRCUIT(circ)->n_streams = n_stream; n_stream->on_circuit = circ;
/* send it off to the gethostbyname farm */ /* send it off to the gethostbyname farm */
switch (dns_resolve(n_stream, NULL)) { switch (dns_resolve(n_stream)) {
case 1: /* resolve worked */ case 1: /* resolve worked */
/* add it into the linked list of n_streams on this circuit */ /* add it into the linked list of n_streams on this circuit */
n_stream->next_stream = TO_OR_CIRCUIT(circ)->n_streams; n_stream->next_stream = TO_OR_CIRCUIT(circ)->n_streams;
n_stream->on_circuit = circ;
TO_OR_CIRCUIT(circ)->n_streams = n_stream; TO_OR_CIRCUIT(circ)->n_streams = n_stream;
assert_circuit_ok(circ); assert_circuit_ok(circ);
...@@ -2255,12 +2258,11 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ) ...@@ -2255,12 +2258,11 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
end_payload[0] = END_STREAM_REASON_RESOLVEFAILED; end_payload[0] = END_STREAM_REASON_RESOLVEFAILED;
relay_send_command_from_edge(rh.stream_id, circ, RELAY_COMMAND_END, relay_send_command_from_edge(rh.stream_id, circ, RELAY_COMMAND_END,
end_payload, 1, NULL); end_payload, 1, NULL);
/* n_stream got freed. don't touch it. */ /* n_stream got detached and freed. don't touch it. */
break; break;
case 0: /* resolve added to pending list */ case 0: /* resolve added to pending list */
/* add it into the linked list of resolving_streams on this circuit */ /* add it into the linked list of resolving_streams on this circuit */
n_stream->next_stream = TO_OR_CIRCUIT(circ)->resolving_streams; n_stream->next_stream = TO_OR_CIRCUIT(circ)->resolving_streams;
n_stream->on_circuit = circ;
TO_OR_CIRCUIT(circ)->resolving_streams = n_stream; TO_OR_CIRCUIT(circ)->resolving_streams = n_stream;
assert_circuit_ok(circ); assert_circuit_ok(circ);
; ;
...@@ -2296,8 +2298,10 @@ connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ) ...@@ -2296,8 +2298,10 @@ connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ)
dummy_conn->_base.state = EXIT_CONN_STATE_RESOLVEFAILED; dummy_conn->_base.state = EXIT_CONN_STATE_RESOLVEFAILED;
dummy_conn->_base.purpose = EXIT_PURPOSE_RESOLVE; dummy_conn->_base.purpose = EXIT_PURPOSE_RESOLVE;
dummy_conn->on_circuit = TO_CIRCUIT(circ);
/* send it off to the gethostbyname farm */ /* send it off to the gethostbyname farm */
switch (dns_resolve(dummy_conn, circ)) { switch (dns_resolve(dummy_conn)) {
case -1: /* Impossible to resolve; a resolved cell was sent. */ case -1: /* Impossible to resolve; a resolved cell was sent. */
/* Connection freed; don't touch it. */ /* Connection freed; don't touch it. */
return 0; return 0;
...@@ -2307,7 +2311,6 @@ connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ) ...@@ -2307,7 +2311,6 @@ connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ)
return 0; return 0;
case 0: /* resolve added to pending list */ case 0: /* resolve added to pending list */
dummy_conn->next_stream = circ->resolving_streams; dummy_conn->next_stream = circ->resolving_streams;
dummy_conn->on_circuit = TO_CIRCUIT(circ);
circ->resolving_streams = dummy_conn; circ->resolving_streams = dummy_conn;
assert_circuit_ok(TO_CIRCUIT(circ)); assert_circuit_ok(TO_CIRCUIT(circ));
break; break;
...@@ -2392,7 +2395,6 @@ connection_exit_connect(edge_connection_t *edge_conn) ...@@ -2392,7 +2395,6 @@ connection_exit_connect(edge_connection_t *edge_conn)
/* rendezvous stream */ /* rendezvous stream */
/* don't send an address back! */ /* don't send an address back! */
connection_edge_send_command(edge_conn, connection_edge_send_command(edge_conn,
circuit_get_by_edge_conn(edge_conn),
RELAY_COMMAND_CONNECTED, RELAY_COMMAND_CONNECTED,
NULL, 0); NULL, 0);
} else { /* normal stream */ } else { /* normal stream */
...@@ -2402,7 +2404,6 @@ connection_exit_connect(edge_connection_t *edge_conn) ...@@ -2402,7 +2404,6 @@ connection_exit_connect(edge_connection_t *edge_conn)
set_uint32(connected_payload+4, set_uint32(connected_payload+4,
htonl(dns_clip_ttl(edge_conn->address_ttl))); htonl(dns_clip_ttl(edge_conn->address_ttl)));
connection_edge_send_command(edge_conn, connection_edge_send_command(edge_conn,
circuit_get_by_edge_conn(edge_conn),
RELAY_COMMAND_CONNECTED, RELAY_COMMAND_CONNECTED,
connected_payload, 8); connected_payload, 8);
} }
...@@ -2475,7 +2476,6 @@ connection_exit_connect_dir(edge_connection_t *exit_conn) ...@@ -2475,7 +2476,6 @@ connection_exit_connect_dir(edge_connection_t *exit_conn)
connection_start_reading(TO_CONN(exit_conn)); connection_start_reading(TO_CONN(exit_conn));
if (connection_edge_send_command(exit_conn, if (connection_edge_send_command(exit_conn,
circuit_get_by_edge_conn(exit_conn),
RELAY_COMMAND_CONNECTED, NULL, 0) < 0) { RELAY_COMMAND_CONNECTED, NULL, 0) < 0) {
connection_mark_for_close(TO_CONN(exit_conn)); connection_mark_for_close(TO_CONN(exit_conn));
connection_mark_for_close(TO_CONN(dir_conn)); connection_mark_for_close(TO_CONN(dir_conn));
......
...@@ -92,9 +92,8 @@ static void purge_expired_resolves(time_t now); ...@@ -92,9 +92,8 @@ static void purge_expired_resolves(time_t now);
static void dns_found_answer(const char *address, int is_reverse, static void dns_found_answer(const char *address, int is_reverse,
uint32_t addr, const char *hostname, char outcome, uint32_t addr, const char *hostname, char outcome,
uint32_t ttl); uint32_t ttl);
static void send_resolved_cell(edge_connection_t *conn, or_circuit_t *circ, static void send_resolved_cell(edge_connection_t *conn, uint8_t answer_type);
uint8_t answer_type); static int launch_resolve(edge_connection_t *exitconn);
static int launch_resolve(edge_connection_t *exitconn, or_circuit_t *circ);
static void add_wildcarded_test_address(const char *address); static void add_wildcarded_test_address(const char *address);
static int configure_nameservers(int force); static int configure_nameservers(int force);
static int answer_is_wildcarded(const char *ip); static int answer_is_wildcarded(const char *ip);
...@@ -389,8 +388,7 @@ purge_expired_resolves(time_t now) ...@@ -389,8 +388,7 @@ purge_expired_resolves(time_t now)
* <b>conn</b>'s attached circuit. * <b>conn</b>'s attached circuit.
*/ */
static void static void
send_resolved_cell(edge_connection_t *conn, or_circuit_t *circ, send_resolved_cell(edge_connection_t *conn, uint8_t answer_type)
uint8_t answer_type)
{ {
char buf[RELAY_PAYLOAD_SIZE]; char buf[RELAY_PAYLOAD_SIZE];
size_t buflen; size_t buflen;
...@@ -425,14 +423,7 @@ send_resolved_cell(edge_connection_t *conn, or_circuit_t *circ, ...@@ -425,14 +423,7 @@ send_resolved_cell(edge_connection_t *conn, or_circuit_t *circ,
} }
// log_notice(LD_EXIT, "Sending a regular RESOLVED reply: "); // log_notice(LD_EXIT, "Sending a regular RESOLVED reply: ");
if (!circ) { connection_edge_send_command(conn, RELAY_COMMAND_RESOLVED, buf, buflen);
circuit_t *tmp = circuit_get_by_edge_conn(conn);
if (! CIRCUIT_IS_ORIGIN(tmp))
circ = TO_OR_CIRCUIT(tmp);
}
connection_edge_send_command(conn, TO_CIRCUIT(circ),
RELAY_COMMAND_RESOLVED, buf, buflen);
} }
/** Send a response to the RESOLVE request of a connection for an in-addr.arpa /** Send a response to the RESOLVE request of a connection for an in-addr.arpa
...@@ -444,8 +435,7 @@ send_resolved_cell(edge_connection_t *conn, or_circuit_t *circ, ...@@ -444,8 +435,7 @@ send_resolved_cell(edge_connection_t *conn, or_circuit_t *circ,
* <b>conn</b>'s attached circuit. * <b>conn</b>'s attached circuit.
*/ */
static void static void
send_resolved_hostname_cell(edge_connection_t *conn, or_circuit_t *circ, send_resolved_hostname_cell(edge_connection_t *conn, const char *hostname)
const char *hostname)
{ {
char buf[RELAY_PAYLOAD_SIZE]; char buf[RELAY_PAYLOAD_SIZE];
size_t buflen; size_t buflen;
...@@ -462,15 +452,8 @@ send_resolved_hostname_cell(edge_connection_t *conn, or_circuit_t *circ, ...@@ -462,15 +452,8 @@ send_resolved_hostname_cell(edge_connection_t *conn, or_circuit_t *circ,
set_uint32(buf+2+namelen, htonl(ttl)); set_uint32(buf+2+namelen, htonl(ttl));
buflen = 2+namelen+4; buflen = 2+namelen+4;
if (!circ) {
circuit_t *tmp = circuit_get_by_edge_conn(conn);
if (! CIRCUIT_IS_ORIGIN(tmp))
circ = TO_OR_CIRCUIT(tmp);
}
// log_notice(LD_EXIT, "Sending a reply RESOLVED reply: %s", hostname); // log_notice(LD_EXIT, "Sending a reply RESOLVED reply: %s", hostname);
connection_edge_send_command(conn, TO_CIRCUIT(circ), connection_edge_send_command(conn, RELAY_COMMAND_RESOLVED, buf, buflen);
RELAY_COMMAND_RESOLVED, buf, buflen);
// log_notice(LD_EXIT, "Sent"); // log_notice(LD_EXIT, "Sent");
} }
...@@ -525,9 +508,8 @@ parse_inaddr_arpa_address(const char *address, struct in_addr *in) ...@@ -525,9 +508,8 @@ parse_inaddr_arpa_address(const char *address, struct in_addr *in)
* need to send back an END cell, since connection_exit_begin_conn will * need to send back an END cell, since connection_exit_begin_conn will
* do that for us.) * do that for us.)
* *
* If <b>oncirc</b> is provided, and this is a resolve request, we have * If we have a cached answer, send the answer back along <b>exitconn</b>'s
* a cached answer, send the answer back along oncirc; otherwise, send * attached circuit.
* the answer back along <b>exitconn</b>'s attached circuit.
* *
* Else, if seen before and pending, add conn to the pending list, * Else, if seen before and pending, add conn to the pending list,
* and return 0. * and return 0.
...@@ -536,18 +518,17 @@ parse_inaddr_arpa_address(const char *address, struct in_addr *in) ...@@ -536,18 +518,17 @@ parse_inaddr_arpa_address(const char *address, struct in_addr *in)
* dns farm, and return 0. * dns farm, and return 0.
*/ */
int int
dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc) dns_resolve(edge_connection_t *exitconn)
{ {
cached_resolve_t *resolve; cached_resolve_t *resolve;
cached_resolve_t search; cached_resolve_t search;
pending_connection_t *pending_connection; pending_connection_t *pending_connection;
circuit_t *circ;
struct in_addr in; struct in_addr in;
time_t now = time(NULL); time_t now = time(NULL);
int is_reverse = 0, is_resolve, r; int is_reverse = 0, is_resolve, r;
or_circuit_t *oncirc = TO_OR_CIRCUIT(exitconn->on_circuit);
assert_connection_ok(TO_CONN(exitconn), 0); assert_connection_ok(TO_CONN(exitconn), 0);
tor_assert(exitconn->_base.s == -1); tor_assert(exitconn->_base.s == -1);
assert_cache_ok(); assert_cache_ok();
is_resolve = exitconn->_base.purpose == EXIT_PURPOSE_RESOLVE; is_resolve = exitconn->_base.purpose == EXIT_PURPOSE_RESOLVE;
...@@ -558,7 +539,7 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc) ...@@ -558,7 +539,7 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc)
exitconn->_base.addr = ntohl(in.s_addr); exitconn->_base.addr = ntohl(in.s_addr);
exitconn->address_ttl = DEFAULT_DNS_TTL; exitconn->address_ttl = DEFAULT_DNS_TTL;
if (is_resolve) if (is_resolve)
send_resolved_cell(exitconn, oncirc, RESOLVED_TYPE_IPV4); send_resolved_cell(exitconn, RESOLVED_TYPE_IPV4);
return 1; return 1;
} }
if (address_is_invalid_destination(exitconn->_base.address, 0)) { if (address_is_invalid_destination(exitconn->_base.address, 0)) {
...@@ -566,10 +547,8 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc) ...@@ -566,10 +547,8 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc)
"Rejecting invalid destination address %s", "Rejecting invalid destination address %s",
escaped_safe_str(exitconn->_base.address)); escaped_safe_str(exitconn->_base.address));
if (is_resolve) if (is_resolve)
send_resolved_cell(exitconn, oncirc, RESOLVED_TYPE_ERROR); send_resolved_cell(exitconn, RESOLVED_TYPE_ERROR);
circ = circuit_get_by_edge_conn(exitconn); circuit_detach_stream(TO_CIRCUIT(oncirc), exitconn);
if (circ)
circuit_detach_stream(circ, exitconn);
if (!exitconn->_base.marked_for_close) if (!exitconn->_base.marked_for_close)
connection_free(TO_CONN(exitconn)); connection_free(TO_CONN(exitconn));
return -1; return -1;
...@@ -601,10 +580,8 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc) ...@@ -601,10 +580,8 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc)
escaped_safe_str(exitconn->_base.address)); escaped_safe_str(exitconn->_base.address));
if (exitconn->_base.purpose == EXIT_PURPOSE_RESOLVE) if (exitconn->_base.purpose == EXIT_PURPOSE_RESOLVE)
send_resolved_cell(exitconn, oncirc, RESOLVED_TYPE_ERROR); send_resolved_cell(exitconn, RESOLVED_TYPE_ERROR);
circ = circuit_get_by_edge_conn(exitconn); circuit_detach_stream(TO_CIRCUIT(oncirc), exitconn);
if (circ)
circuit_detach_stream(circ, exitconn);
if (!exitconn->_base.marked_for_close) if (!exitconn->_base.marked_for_close)
connection_free(TO_CONN(exitconn)); connection_free(TO_CONN(exitconn));
return -1; return -1;
...@@ -637,12 +614,12 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc) ...@@ -637,12 +614,12 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc)
exitconn->address_ttl = resolve->ttl; exitconn->address_ttl = resolve->ttl;
if (resolve->is_reverse) { if (resolve->is_reverse) {
tor_assert(is_resolve); tor_assert(is_resolve);
send_resolved_hostname_cell(exitconn, oncirc, send_resolved_hostname_cell(exitconn,
resolve->result.hostname); resolve->result.hostname);
} else { } else {
exitconn->_base.addr = resolve->result.addr; exitconn->_base.addr = resolve->result.addr;
if (is_resolve) if (is_resolve)
send_resolved_cell(exitconn, oncirc, RESOLVED_TYPE_IPV4); send_resolved_cell(exitconn, RESOLVED_TYPE_IPV4);
} }
return 1; return 1;
case CACHE_STATE_CACHED_FAILED: case CACHE_STATE_CACHED_FAILED:
...@@ -650,10 +627,8 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc) ...@@ -650,10 +627,8 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc)
exitconn->_base.s, exitconn->_base.s,
escaped_safe_str(exitconn->_base.address)); escaped_safe_str(exitconn->_base.address));
if (is_resolve) if (is_resolve)
send_resolved_cell(exitconn, oncirc, RESOLVED_TYPE_ERROR); send_resolved_cell(exitconn, RESOLVED_TYPE_ERROR);
circ = circuit_get_by_edge_conn(exitconn); circuit_detach_stream(TO_CIRCUIT(oncirc), exitconn);
if (circ)
circuit_detach_stream(circ, exitconn);
if (!exitconn->_base.marked_for_close) if (!exitconn->_base.marked_for_close)
connection_free(TO_CONN(exitconn)); connection_free(TO_CONN(exitconn));
return -1; return -1;
...@@ -683,7 +658,7 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc) ...@@ -683,7 +658,7 @@ dns_resolve(edge_connection_t *exitconn, or_circuit_t *oncirc)
log_debug(LD_EXIT,"Launching %s.", log_debug(LD_EXIT,"Launching %s.",
escaped_safe_str(exitconn->_base.address)); escaped_safe_str(exitconn->_base.address));
assert_cache_ok(); assert_cache_ok();
return launch_resolve(exitconn, oncirc); return launch_resolve(exitconn);
} }
/** Log an error and abort if conn is waiting for a DNS resolve. /** Log an error and abort if conn is waiting for a DNS resolve.
...@@ -953,7 +928,7 @@ dns_found_answer(const char *address, int is_reverse, uint32_t addr, ...@@ -953,7 +928,7 @@ dns_found_answer(const char *address, int is_reverse, uint32_t addr,
/* This detach must happen after we send the end cell. */ /* This detach must happen after we send the end cell. */
circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn); circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn);
} else { } else {
send_resolved_cell(pendconn, NULL, RESOLVED_TYPE_ERROR); send_resolved_cell(pendconn, RESOLVED_TYPE_ERROR);
/* This detach must happen after we send the resolved cell. */ /* This detach must happen after we send the resolved cell. */
circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn); circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn);
} }
...@@ -980,9 +955,9 @@ dns_found_answer(const char *address, int is_reverse, uint32_t addr, ...@@ -980,9 +955,9 @@ dns_found_answer(const char *address, int is_reverse, uint32_t addr,
* but it does the right thing. */ * but it does the right thing. */
pendconn->_base.state = EXIT_CONN_STATE_RESOLVEFAILED; pendconn->_base.state = EXIT_CONN_STATE_RESOLVEFAILED;
if (is_reverse) if (is_reverse)
send_resolved_hostname_cell(pendconn, NULL, hostname); send_resolved_hostname_cell(pendconn, hostname);
else else
send_resolved_cell(pendconn, NULL, RESOLVED_TYPE_IPV4); send_resolved_cell(pendconn, RESOLVED_TYPE_IPV4);
circ = circuit_get_by_edge_conn(pendconn); circ = circuit_get_by_edge_conn(pendconn);
tor_assert(circ); tor_assert(circ);
circuit_detach_stream(circ, pendconn); circuit_detach_stream(circ, pendconn);
...@@ -1187,7 +1162,7 @@ evdns_callback(int result, char type, int count, int ttl, void *addresses, ...@@ -1187,7 +1162,7 @@ evdns_callback(int result, char type, int count, int ttl, void *addresses,
/** For eventdns: start resolving as necessary to find the target for /** For eventdns: start resolving as necessary to find the target for
* <b>exitconn</b> */ * <b>exitconn</b> */
static int static int
launch_resolve(edge_connection_t *exitconn, or_circuit_t *circ) launch_resolve(edge_connection_t *exitconn)
{ {
char *addr = tor_strdup(exitconn->_base.address); char *addr = tor_strdup(exitconn->_base.address);
struct in_addr in; struct in_addr in;
...@@ -1222,10 +1197,10 @@ launch_resolve(edge_connection_t *exitconn, or_circuit_t *circ) ...@@ -1222,10 +1197,10 @@ launch_resolve(edge_connection_t *exitconn, or_circuit_t *circ)
escaped_safe_str(addr), r); escaped_safe_str(addr), r);
if (exitconn->_base.purpose == EXIT_PURPOSE_RESOLVE) { if (exitconn->_base.purpose == EXIT_PURPOSE_RESOLVE) {
if (evdns_err_is_transient(r)) if (evdns_err_is_transient(r))
send_resolved_cell(exitconn, circ, RESOLVED_TYPE_ERROR_TRANSIENT); send_resolved_cell(exitconn, RESOLVED_TYPE_ERROR_TRANSIENT);
else { else {
exitconn->address_ttl = DEFAULT_DNS_TTL; exitconn->address_ttl = DEFAULT_DNS_TTL;
send_resolved_cell(exitconn, circ, RESOLVED_TYPE_ERROR); send_resolved_cell(exitconn, RESOLVED_TYPE_ERROR);
} }
} }
dns_cancel_pending_resolve(addr); /* also sends end and frees */ dns_cancel_pending_resolve(addr); /* also sends end and frees */
......
...@@ -2195,10 +2195,8 @@ int connection_edge_end_errno(edge_connection_t *conn); ...@@ -2195,10 +2195,8 @@ int connection_edge_end_errno(edge_connection_t *conn);
int connection_edge_finished_flushing(edge_connection_t *conn); int connection_edge_finished_flushing(edge_connection_t *conn);
int connection_edge_finished_connecting(edge_connection_t *conn); int connection_edge_finished_connecting(edge_connection_t *conn);
int connection_ap_handshake_send_begin(edge_connection_t *ap_conn, int connection_ap_handshake_send_begin(edge_connection_t *ap_conn);
origin_circuit_t *circ); int connection_ap_handshake_send_resolve(edge_connection_t *ap_conn);
int connection_ap_handshake_send_resolve(edge_connection_t *ap_conn,
origin_circuit_t *circ);
int connection_ap_make_bridge(char *address, uint16_t port, int connection_ap_make_bridge(char *address, uint16_t port,
const char *digest, int command); const char *digest, int command);
...@@ -2477,7 +2475,7 @@ void connection_dns_remove(edge_connection_t *conn); ...@@ -2477,7 +2475,7 @@ void connection_dns_remove(edge_connection_t *conn);
void assert_connection_edge_not_dns_pending(edge_connection_t *conn); void assert_connection_edge_not_dns_pending(edge_connection_t *conn);
void assert_all_pending_dns_resolves_ok(void); void assert_all_pending_dns_resolves_ok(void);
void dns_cancel_pending_resolve(const char *question); void dns_cancel_pending_resolve(const char *question);
int dns_resolve(edge_connection_t *exitconn, or_circuit_t *circ); int dns_resolve(edge_connection_t *exitconn);
void dns_launch_correctness_checks(void); void dns_launch_correctness_checks(void);
int dns_seems_to_be_broken(void);