Commit 200e2498 authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

r7046@Kushana: nickm | 2006-08-05 13:57:04 -0400

 Make it possible for dns_init() to fail; note failure of eventdns configuratoin.


svn:r7059
parent 65b58e13
...@@ -105,7 +105,7 @@ static int dnsworker_main(void *data); ...@@ -105,7 +105,7 @@ static int dnsworker_main(void *data);
static int spawn_dnsworker(void); static int spawn_dnsworker(void);
static int spawn_enough_dnsworkers(void); static int spawn_enough_dnsworkers(void);
#else #else
static void configure_nameservers(void); static int configure_nameservers(void);
#endif #endif
static void _assert_cache_ok(void); static void _assert_cache_ok(void);
#ifdef DEBUG_DNS_CACHE #ifdef DEBUG_DNS_CACHE
...@@ -160,14 +160,16 @@ eventdns_log_cb(const char *msg) ...@@ -160,14 +160,16 @@ eventdns_log_cb(const char *msg)
#endif #endif
/** Initialize the DNS subsystem; called by the OR process. */ /** Initialize the DNS subsystem; called by the OR process. */
void int
dns_init(void) dns_init(void)
{ {
init_cache_map(); init_cache_map();
dnsworkers_rotate(); dnsworkers_rotate();
#ifdef USE_EVENTDNS #ifdef USE_EVENTDNS
if (server_mode(get_options())) if (server_mode(get_options()))
configure_nameservers(); return configure_nameservers();
return 0;
#endif
#endif #endif
} }
...@@ -1180,7 +1182,7 @@ connection_dns_reached_eof(connection_t *conn) ...@@ -1180,7 +1182,7 @@ connection_dns_reached_eof(connection_t *conn)
return 0; return 0;
} }
static int nameservers_configured = 0; static int nameservers_configured = 0;
static void static int
configure_nameservers(void) configure_nameservers(void)
{ {
or_options_t *options; or_options_t *options;
...@@ -1195,16 +1197,37 @@ configure_nameservers(void) ...@@ -1195,16 +1197,37 @@ configure_nameservers(void)
struct in_addr in; struct in_addr in;
if (tor_inet_aton(ip, &in)) { if (tor_inet_aton(ip, &in)) {
log_info(LD_EXIT, "Adding nameserver '%s'", ip); log_info(LD_EXIT, "Adding nameserver '%s'", ip);
eventdns_nameserver_add(in.s_addr); if (eventdns_nameserver_add(in.s_addr))
log_warn(LD_EXIT, "Unable to add nameserver '%s'", ip);
} }
}); });
if (eventdns_count_nameservers() == 0) {
log_err(LD_EXIT, "Unable to add any configured nameserver. "
"Either remove the Nameservers line from your configuration, or "
"put in a namerserver that we can parse.");
return -1;
}
} else { } else {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
eventdns_config_windows_nameservers(); if (eventdns_config_windows_nameservers())
return -1;
if (eventdns_count_nameservers() == 0) {
log_err(LD_EXIT, "Unable to find any platform nameservers in "
"your Windows configuration. Perhaps you should add a "
"Nameservers line to your torrc?");
return -1;
}
#else #else
log_info(LD_EXIT, "Parsing /etc/resolv.conf"); log_info(LD_EXIT, "Parsing /etc/resolv.conf");
eventdns_resolv_conf_parse(DNS_OPTION_NAMESERVERS|DNS_OPTION_MISC, if (eventdns_resolv_conf_parse(DNS_OPTION_NAMESERVERS|DNS_OPTION_MISC,
"/etc/resolv.conf"); "/etc/resolv.conf"))
return -1;
if (eventdns_count_nameservers() == 0) {
log_err(LD_EXIT, "Unable to find any platform nameservers in "
"/etc/resolv.conf. Perhaps you should add a Nameservers line "
"to your torrc?");
return -1;
}
#endif #endif
} }
nameservers_configured = 1; nameservers_configured = 1;
......
...@@ -2123,7 +2123,7 @@ void cached_dir_decref(cached_dir_t *d); ...@@ -2123,7 +2123,7 @@ void cached_dir_decref(cached_dir_t *d);
/********************************* dns.c ***************************/ /********************************* dns.c ***************************/
void dns_init(void); int dns_init(void);
void dns_free_all(void); void dns_free_all(void);
uint32_t dns_clip_ttl(uint32_t ttl); uint32_t dns_clip_ttl(uint32_t ttl);
int connection_dns_finished_flushing(connection_t *conn); int connection_dns_finished_flushing(connection_t *conn);
......
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