aboutsummaryrefslogtreecommitdiff
path: root/src/or/dnsserv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/dnsserv.c')
-rw-r--r--src/or/dnsserv.c75
1 files changed, 59 insertions, 16 deletions
diff --git a/src/or/dnsserv.c b/src/or/dnsserv.c
index 69adcef9e..ecd45be77 100644
--- a/src/or/dnsserv.c
+++ b/src/or/dnsserv.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2012, The Tor Project, Inc. */
+/* Copyright (c) 2007-2013, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
@@ -35,7 +35,7 @@ evdns_server_callback(struct evdns_server_request *req, void *data_)
entry_connection_t *entry_conn;
edge_connection_t *conn;
int i = 0;
- struct evdns_server_question *q = NULL;
+ struct evdns_server_question *q = NULL, *supported_q = NULL;
struct sockaddr_storage addr;
struct sockaddr *sa;
int addrlen;
@@ -87,30 +87,37 @@ evdns_server_callback(struct evdns_server_request *req, void *data_)
for (i = 0; i < req->nquestions; ++i) {
if (req->questions[i]->dns_question_class != EVDNS_CLASS_INET)
continue;
+ if (! q)
+ q = req->questions[i];
switch (req->questions[i]->type) {
case EVDNS_TYPE_A:
+ case EVDNS_TYPE_AAAA:
case EVDNS_TYPE_PTR:
- q = req->questions[i];
+ /* We always pick the first one of these questions, if there is
+ one. */
+ if (! supported_q)
+ supported_q = q;
+ break;
default:
break;
}
}
+ if (supported_q)
+ q = supported_q;
if (!q) {
log_info(LD_APP, "None of the questions we got were ones we're willing "
"to support. Sending NOTIMPL.");
evdns_server_request_respond(req, DNS_ERR_NOTIMPL);
return;
}
- if (q->type != EVDNS_TYPE_A) {
- tor_assert(q->type == EVDNS_TYPE_PTR);
- }
/* Make sure the name isn't too long: This should be impossible, I think. */
if (err == DNS_ERR_NONE && strlen(q->name) > MAX_SOCKS_ADDR_LEN-1)
err = DNS_ERR_FORMAT;
- if (err != DNS_ERR_NONE) {
- /* We got an error? Then send back an answer immediately; we're done. */
+ if (err != DNS_ERR_NONE || !supported_q) {
+ /* We got an error? There's no question we're willing to answer? Then
+ * send back an answer immediately; we're done. */
evdns_server_request_respond(req, err);
return;
}
@@ -125,15 +132,28 @@ evdns_server_callback(struct evdns_server_request *req, void *data_)
TO_CONN(conn)->port = port;
TO_CONN(conn)->address = tor_dup_addr(&tor_addr);
- if (q->type == EVDNS_TYPE_A)
+ if (q->type == EVDNS_TYPE_A || q->type == EVDNS_TYPE_AAAA ||
+ q->type == EVDNS_QTYPE_ALL) {
entry_conn->socks_request->command = SOCKS_COMMAND_RESOLVE;
- else
+ } else {
+ tor_assert(q->type == EVDNS_TYPE_PTR);
entry_conn->socks_request->command = SOCKS_COMMAND_RESOLVE_PTR;
+ }
+
+ if (q->type == EVDNS_TYPE_A || q->type == EVDNS_QTYPE_ALL) {
+ entry_conn->ipv4_traffic_ok = 1;
+ entry_conn->ipv6_traffic_ok = 0;
+ entry_conn->prefer_ipv6_traffic = 0;
+ } else if (q->type == EVDNS_TYPE_AAAA) {
+ entry_conn->ipv4_traffic_ok = 0;
+ entry_conn->ipv6_traffic_ok = 1;
+ entry_conn->prefer_ipv6_traffic = 1;
+ }
strlcpy(entry_conn->socks_request->address, q->name,
sizeof(entry_conn->socks_request->address));
- entry_conn->socks_request->listener_type = listener->_base.type;
+ entry_conn->socks_request->listener_type = listener->base_.type;
entry_conn->dns_server_request = req;
entry_conn->isolation_flags = listener->isolation_flags;
entry_conn->session_group = listener->session_group;
@@ -146,7 +166,7 @@ evdns_server_callback(struct evdns_server_request *req, void *data_)
return;
}
- control_event_stream_status(entry_conn, STREAM_EVENT_NEW, 0);
+ control_event_stream_status(entry_conn, STREAM_EVENT_NEW_RESOLVE, 0);
/* Now, unless a controller asked us to leave streams unattached,
* throw the connection over to get rewritten (which will
@@ -169,7 +189,8 @@ evdns_server_callback(struct evdns_server_request *req, void *data_)
* response; -1 if we couldn't launch the request.
*/
int
-dnsserv_launch_request(const char *name, int reverse)
+dnsserv_launch_request(const char *name, int reverse,
+ control_connection_t *control_conn)
{
entry_connection_t *entry_conn;
edge_connection_t *conn;
@@ -178,7 +199,26 @@ dnsserv_launch_request(const char *name, int reverse)
/* Make a new dummy AP connection, and attach the request to it. */
entry_conn = entry_connection_new(CONN_TYPE_AP, AF_INET);
conn = ENTRY_TO_EDGE_CONN(entry_conn);
- conn->_base.state = AP_CONN_STATE_RESOLVE_WAIT;
+ conn->base_.state = AP_CONN_STATE_RESOLVE_WAIT;
+
+ tor_addr_copy(&TO_CONN(conn)->addr, &control_conn->base_.addr);
+#ifdef AF_UNIX
+ /*
+ * The control connection can be AF_UNIX and if so tor_dup_addr will
+ * unhelpfully say "<unknown address type>"; say "(Tor_internal)"
+ * instead.
+ */
+ if (control_conn->base_.socket_family == AF_UNIX) {
+ TO_CONN(conn)->port = 0;
+ TO_CONN(conn)->address = tor_strdup("(Tor_internal)");
+ } else {
+ TO_CONN(conn)->port = control_conn->base_.port;
+ TO_CONN(conn)->address = tor_dup_addr(&control_conn->base_.addr);
+ }
+#else
+ TO_CONN(conn)->port = control_conn->base_.port;
+ TO_CONN(conn)->address = tor_dup_addr(&control_conn->base_.addr);
+#endif
if (reverse)
entry_conn->socks_request->command = SOCKS_COMMAND_RESOLVE_PTR;
@@ -202,6 +242,8 @@ dnsserv_launch_request(const char *name, int reverse)
return -1;
}
+ control_event_stream_status(entry_conn, STREAM_EVENT_NEW_RESOLVE, 0);
+
/* Now, unless a controller asked us to leave streams unattached,
* throw the connection over to get rewritten (which will
* answer it immediately if it's in the cache, or completely bogus, or
@@ -289,8 +331,9 @@ dnsserv_resolved(entry_connection_t *conn,
* or more of the questions in the request); then, call
* evdns_server_request_respond. */
if (answer_type == RESOLVED_TYPE_IPV6) {
- log_info(LD_APP, "Got an IPv6 answer; that's not implemented.");
- err = DNS_ERR_NOTIMPL;
+ evdns_server_request_add_aaaa_reply(req,
+ name,
+ 1, answer, ttl);
} else if (answer_type == RESOLVED_TYPE_IPV4 && answer_len == 4 &&
conn->socks_request->command == SOCKS_COMMAND_RESOLVE) {
evdns_server_request_add_a_reply(req,