|
@@ -1908,12 +1908,16 @@ static uint32_t last_resolved_addr = 0;
|
|
|
* holding that hostname. (If we didn't get our address by resolving a
|
|
|
* hostname, set *<b>hostname_out</b> to NULL.)
|
|
|
*
|
|
|
+ * If <b>use_cached_addr</b> is true, and we have a plausible answer,
|
|
|
+ * provide that answer and return.
|
|
|
+ *
|
|
|
* XXXX ipv6
|
|
|
*/
|
|
|
int
|
|
|
resolve_my_address(int warn_severity, const or_options_t *options,
|
|
|
uint32_t *addr_out,
|
|
|
- const char **method_out, char **hostname_out)
|
|
|
+ const char **method_out, char **hostname_out,
|
|
|
+ int use_cached_addr)
|
|
|
{
|
|
|
struct in_addr in;
|
|
|
uint32_t addr; /* host order */
|
|
@@ -1930,6 +1934,18 @@ resolve_my_address(int warn_severity, const or_options_t *options,
|
|
|
|
|
|
tor_assert(addr_out);
|
|
|
|
|
|
+ /*
|
|
|
+ * Step zero: if used_cached_addr is true, and we have a cached answer,
|
|
|
+ * just return it and be done.
|
|
|
+ */
|
|
|
+
|
|
|
+ if (use_cached_addr && last_resolved_addr) {
|
|
|
+ *addr_out = last_resolved_addr;
|
|
|
+ if (method_out)
|
|
|
+ *method_out = "CACHED";
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
* Step one: Fill in 'hostname' to be our best guess.
|
|
|
*/
|
|
@@ -2343,7 +2359,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
|
|
|
if (authdir_mode(options)) {
|
|
|
/* confirm that our address isn't broken, so we can complain now */
|
|
|
uint32_t tmp;
|
|
|
- if (resolve_my_address(LOG_WARN, options, &tmp, NULL, NULL) < 0)
|
|
|
+ if (resolve_my_address(LOG_WARN, options, &tmp, NULL, NULL, 0) < 0)
|
|
|
REJECT("Failed to resolve/guess local address. See logs for details.");
|
|
|
}
|
|
|
|