[or-cvs] r17983: {tor} Make outgoing DNS requests respect OutboundBindAddress. Fixe (in tor/trunk: . src/or)
nickm at seul.org
nickm at seul.org
Tue Jan 6 20:50:55 UTC 2009
Author: nickm
Date: 2009-01-06 15:50:55 -0500 (Tue, 06 Jan 2009)
New Revision: 17983
Modified:
tor/trunk/ChangeLog
tor/trunk/src/or/dns.c
tor/trunk/src/or/dnsserv.c
tor/trunk/src/or/eventdns.c
tor/trunk/src/or/eventdns.h
Log:
Make outgoing DNS requests respect OutboundBindAddress.
Fixes the bug part of bug 789.
Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog 2009-01-06 20:50:51 UTC (rev 17982)
+++ tor/trunk/ChangeLog 2009-01-06 20:50:55 UTC (rev 17983)
@@ -1,6 +1,8 @@
Changes in version 0.2.1.11-alpha - 2009-01-??
+ o Minor bugfixes:
+ - Make outbound DNS packets respect the OutboundBindAddress setting.
+ Fixes the bug part of bug 798.
-
Changes in version 0.2.1.10-alpha - 2009-01-06
o Major bugfixes:
- If the cached networkstatus consensus is more than five days old,
Modified: tor/trunk/src/or/dns.c
===================================================================
--- tor/trunk/src/or/dns.c 2009-01-06 20:50:51 UTC (rev 17982)
+++ tor/trunk/src/or/dns.c 2009-01-06 20:50:55 UTC (rev 17983)
@@ -1102,6 +1102,25 @@
conf_fname = "/etc/resolv.conf";
#endif
+ if (options->OutboundBindAddress) {
+ tor_addr_t addr;
+ if (tor_addr_from_str(&addr, options->OutboundBindAddress) < 0) {
+ log_warn(LD_CONFIG,"Outbound bind address '%s' didn't parse. Ignoring.",
+ options->OutboundBindAddress);
+ } else {
+ int socklen;
+ struct sockaddr_storage ss;
+ socklen = tor_addr_to_sockaddr(&addr, 0,
+ (struct sockaddr *)&ss, sizeof(ss));
+ if (socklen < 0) {
+ log_warn(LD_BUG, "Couldn't convert outboung bind address to sockaddr."
+ " Ignoring.");
+ } else {
+ evdns_set_default_outgoing_bind_address((struct sockaddr *)&ss,socklen);
+ }
+ }
+ }
+
evdns_set_log_fn(evdns_log_cb);
if (conf_fname) {
if (stat(conf_fname, &st)) {
Modified: tor/trunk/src/or/dnsserv.c
===================================================================
--- tor/trunk/src/or/dnsserv.c 2009-01-06 20:50:51 UTC (rev 17982)
+++ tor/trunk/src/or/dnsserv.c 2009-01-06 20:50:55 UTC (rev 17983)
@@ -294,7 +294,7 @@
dnsserv_configure_listener(connection_t *conn)
{
tor_assert(conn);
- tor_assert(conn->s);
+ tor_assert(conn->s >= 0);
tor_assert(conn->type == CONN_TYPE_AP_DNS_LISTENER);
conn->dns_server_port = evdns_add_server_port(conn->s, 0,
Modified: tor/trunk/src/or/eventdns.c
===================================================================
--- tor/trunk/src/or/eventdns.c 2009-01-06 20:50:51 UTC (rev 17982)
+++ tor/trunk/src/or/eventdns.c 2009-01-06 20:50:55 UTC (rev 17983)
@@ -2203,6 +2203,23 @@
return 0;
}
+static struct sockaddr_storage global_bind_address;
+static socklen_t global_bind_addrlen = 0;
+static int global_bind_addr_is_set = 0;
+void
+evdns_set_default_outgoing_bind_address(const struct sockaddr *addr,
+ socklen_t addrlen)
+{
+ memset(&global_bind_address, 0, sizeof(global_bind_address));
+ if (addr) {
+ assert(addrlen <= sizeof(global_bind_address));
+ memcpy(&global_bind_address, addr, addrlen);
+ global_bind_addrlen = addrlen;
+ global_bind_addr_is_set = 1;
+ } else {
+ global_bind_addr_is_set = 0;
+ }
+}
/* exported function */
int
@@ -2251,6 +2268,15 @@
fcntl(ns->socket, F_SETFL, O_NONBLOCK);
#endif
+ if (global_bind_addr_is_set) {
+ if (bind(ns->socket, (struct sockaddr *)&global_bind_address,
+ global_bind_addrlen) < 0) {
+ log(EVDNS_LOG_DEBUG, "Couldn't bind to outgoing address.");
+ err = 2;
+ goto out2;
+ }
+ }
+
if (connect(ns->socket, address, addrlen) != 0) {
log(EVDNS_LOG_DEBUG, "Couldn't open socket to nameserver.");
err = 2;
Modified: tor/trunk/src/or/eventdns.h
===================================================================
--- tor/trunk/src/or/eventdns.h 2009-01-06 20:50:51 UTC (rev 17982)
+++ tor/trunk/src/or/eventdns.h 2009-01-06 20:50:55 UTC (rev 17983)
@@ -264,6 +264,7 @@
int evdns_resume(void);
int evdns_nameserver_ip_add(const char *ip_as_string);
int evdns_nameserver_sockaddr_add(const struct sockaddr *sa, socklen_t len);
+void evdns_set_default_outgoing_bind_address(const struct sockaddr *addr, socklen_t addrlen);
int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr);
int evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr);
struct in_addr;
More information about the tor-commits
mailing list