mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
parameterize the loudness of resolve_my_address(), and call things
IP addresses, not IPs. svn:r6764
This commit is contained in:
parent
3d79eb52ab
commit
ee5f512e13
@ -1583,8 +1583,8 @@ print_usage(void)
|
||||
* public IP address.
|
||||
*/
|
||||
int
|
||||
resolve_my_address(or_options_t *options, uint32_t *addr_out,
|
||||
char **hostname_out)
|
||||
resolve_my_address(int warn_severity, or_options_t *options,
|
||||
uint32_t *addr_out, char **hostname_out)
|
||||
{
|
||||
struct in_addr in;
|
||||
struct hostent *rent;
|
||||
@ -1594,6 +1594,8 @@ resolve_my_address(or_options_t *options, uint32_t *addr_out,
|
||||
char tmpbuf[INET_NTOA_BUF_LEN];
|
||||
static uint32_t old_addr=0;
|
||||
const char *address = options->Address;
|
||||
int notice_severity = warn_severity <= LOG_NOTICE ?
|
||||
LOG_NOTICE : warn_severity;
|
||||
|
||||
tor_assert(addr_out);
|
||||
|
||||
@ -1604,13 +1606,13 @@ resolve_my_address(or_options_t *options, uint32_t *addr_out,
|
||||
explicit_hostname = 0; /* it's implicit */
|
||||
|
||||
if (gethostname(hostname, sizeof(hostname)) < 0) {
|
||||
log_warn(LD_NET,"Error obtaining local hostname");
|
||||
log_fn(warn_severity, LD_NET,"Error obtaining local hostname");
|
||||
return -1;
|
||||
}
|
||||
log_debug(LD_CONFIG,"Guessed local host name as '%s'",hostname);
|
||||
}
|
||||
|
||||
/* now we know hostname. resolve it and keep only the IP */
|
||||
/* now we know hostname. resolve it and keep only the IP address */
|
||||
|
||||
if (tor_inet_aton(hostname, &in) == 0) {
|
||||
/* then we have to resolve it */
|
||||
@ -1620,21 +1622,22 @@ resolve_my_address(or_options_t *options, uint32_t *addr_out,
|
||||
uint32_t interface_ip;
|
||||
|
||||
if (explicit_hostname) {
|
||||
log_warn(LD_CONFIG,"Could not resolve local Address '%s'. Failing.",
|
||||
hostname);
|
||||
log_fn(warn_severity, LD_CONFIG,
|
||||
"Could not resolve local Address '%s'. Failing.", hostname);
|
||||
return -1;
|
||||
}
|
||||
log_notice(LD_CONFIG, "Could not resolve guessed local hostname '%s'. "
|
||||
"Trying something else.", hostname);
|
||||
log_fn(notice_severity, LD_CONFIG,
|
||||
"Could not resolve guessed local hostname '%s'. "
|
||||
"Trying something else.", hostname);
|
||||
if (get_interface_address(&interface_ip)) {
|
||||
log_warn(LD_CONFIG, "Could not get local interface IP address. "
|
||||
"Failing.");
|
||||
log_fn(warn_severity, LD_CONFIG,
|
||||
"Could not get local interface IP address. Failing.");
|
||||
return -1;
|
||||
}
|
||||
in.s_addr = htonl(interface_ip);
|
||||
tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
|
||||
log_notice(LD_CONFIG, "Learned IP address '%s' for local interface."
|
||||
" Using that.", tmpbuf);
|
||||
log_fn(notice_severity, LD_CONFIG, "Learned IP address '%s' for "
|
||||
"local interface. Using that.", tmpbuf);
|
||||
strlcpy(hostname, "<guessed from interfaces>", sizeof(hostname));
|
||||
} else {
|
||||
tor_assert(rent->h_length == 4);
|
||||
@ -1645,24 +1648,26 @@ resolve_my_address(or_options_t *options, uint32_t *addr_out,
|
||||
uint32_t interface_ip;
|
||||
|
||||
tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
|
||||
log_notice(LD_CONFIG, "Guessed local hostname '%s' resolves to a "
|
||||
"private IP address (%s). Trying something else.", hostname,
|
||||
tmpbuf);
|
||||
log_fn(notice_severity, LD_CONFIG, "Guessed local hostname '%s' "
|
||||
"resolves to a private IP address (%s). Trying something "
|
||||
"else.", hostname, tmpbuf);
|
||||
|
||||
if (get_interface_address(&interface_ip)) {
|
||||
log_warn(LD_CONFIG, "Could not get local interface IP address. "
|
||||
"Too bad.");
|
||||
log_fn(warn_severity, LD_CONFIG,
|
||||
"Could not get local interface IP address. Too bad.");
|
||||
} else if (is_internal_IP(interface_ip, 0)) {
|
||||
struct in_addr in2;
|
||||
in2.s_addr = htonl(interface_ip);
|
||||
tor_inet_ntoa(&in2,tmpbuf,sizeof(tmpbuf));
|
||||
log_notice(LD_CONFIG, "Interface IP '%s' is a private address "
|
||||
"too. Ignoring.", tmpbuf);
|
||||
log_fn(notice_severity, LD_CONFIG,
|
||||
"Interface IP address '%s' is a private address too. "
|
||||
"Ignoring.", tmpbuf);
|
||||
} else {
|
||||
in.s_addr = htonl(interface_ip);
|
||||
tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
|
||||
log_notice(LD_CONFIG, "Learned IP address '%s' for local interface."
|
||||
" Using that.", tmpbuf);
|
||||
log_fn(notice_severity, LD_CONFIG,
|
||||
"Learned IP address '%s' for local interface."
|
||||
" Using that.", tmpbuf);
|
||||
strlcpy(hostname, "<guessed from interfaces>", sizeof(hostname));
|
||||
}
|
||||
}
|
||||
@ -1676,18 +1681,18 @@ resolve_my_address(or_options_t *options, uint32_t *addr_out,
|
||||
if (!options->DirServers) {
|
||||
/* if they are using the default dirservers, disallow internal IPs
|
||||
* always. */
|
||||
log_warn(LD_CONFIG,"Address '%s' resolves to private IP '%s'. "
|
||||
"Tor servers that use the default DirServers must have public "
|
||||
"IP addresses.",
|
||||
hostname, tmpbuf);
|
||||
log_fn(warn_severity, LD_CONFIG,
|
||||
"Address '%s' resolves to private IP address '%s'. "
|
||||
"Tor servers that use the default DirServers must have public "
|
||||
"IP addresses.", hostname, tmpbuf);
|
||||
return -1;
|
||||
}
|
||||
if (!explicit_ip) {
|
||||
/* even if they've set their own dirservers, require an explicit IP if
|
||||
* they're using an internal address. */
|
||||
log_warn(LD_CONFIG,"Address '%s' resolves to private IP '%s'. Please "
|
||||
"set the Address config option to be the IP you want to use.",
|
||||
hostname, tmpbuf);
|
||||
log_fn(warn_severity, LD_CONFIG, "Address '%s' resolves to private "
|
||||
"IP address '%s'. Please set the Address config option to be "
|
||||
"the IP address you want to use.", hostname, tmpbuf);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1695,7 +1700,9 @@ resolve_my_address(or_options_t *options, uint32_t *addr_out,
|
||||
log_debug(LD_CONFIG, "Resolved Address to '%s'.", tmpbuf);
|
||||
*addr_out = ntohl(in.s_addr);
|
||||
if (old_addr && old_addr != *addr_out) {
|
||||
log_notice(LD_NET, "Your IP seems to have changed. Updating.");
|
||||
/* Leave this as a notice, regardless of the requested severity,
|
||||
* at least until dynamic IP address support becomes bulletproof. */
|
||||
log_notice(LD_NET, "Your IP address seems to have changed. Updating.");
|
||||
server_has_changed_ip();
|
||||
}
|
||||
old_addr = *addr_out;
|
||||
@ -2125,7 +2132,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
|
||||
if (server_mode(options)) {
|
||||
/* confirm that our address isn't broken, so we can complain now */
|
||||
uint32_t tmp;
|
||||
if (resolve_my_address(options, &tmp, NULL) < 0)
|
||||
if (resolve_my_address(LOG_WARN, options, &tmp, NULL) < 0)
|
||||
REJECT("Failed to resolve/guess local address. See logs for details.");
|
||||
}
|
||||
|
||||
|
@ -1347,7 +1347,7 @@ generate_v2_networkstatus(void)
|
||||
int versioning = options->VersioningAuthoritativeDir;
|
||||
const char *contact;
|
||||
|
||||
if (resolve_my_address(options, &addr, &hostname)<0) {
|
||||
if (resolve_my_address(LOG_WARN, options, &addr, &hostname)<0) {
|
||||
log_warn(LD_NET, "Couldn't resolve my hostname");
|
||||
goto done;
|
||||
}
|
||||
|
@ -1631,8 +1631,8 @@ int config_get_lines(char *string, config_line_t **result);
|
||||
void config_free_lines(config_line_t *front);
|
||||
int options_trial_assign(config_line_t *list, int use_defaults,
|
||||
int clear_first, char **msg);
|
||||
int resolve_my_address(or_options_t *options, uint32_t *addr,
|
||||
char **hostname_out);
|
||||
int resolve_my_address(int warn_severity, or_options_t *options,
|
||||
uint32_t *addr, char **hostname_out);
|
||||
void options_init(or_options_t *options);
|
||||
int options_init_from_torrc(int argc, char **argv);
|
||||
int options_init_logs(or_options_t *options, int validate_only);
|
||||
|
@ -752,7 +752,7 @@ router_rebuild_descriptor(int force)
|
||||
if (desc_clean_since && !force)
|
||||
return 0;
|
||||
|
||||
if (resolve_my_address(options, &addr, NULL) < 0) {
|
||||
if (resolve_my_address(LOG_WARN, options, &addr, NULL) < 0) {
|
||||
log_warn(LD_CONFIG,"options->Address didn't resolve into an IP.");
|
||||
return -1;
|
||||
}
|
||||
@ -908,7 +908,7 @@ check_descriptor_ipaddress_changed(time_t now)
|
||||
return;
|
||||
|
||||
prev = desc_routerinfo->addr;
|
||||
if (resolve_my_address(options, &cur, NULL) < 0) {
|
||||
if (resolve_my_address(LOG_WARN, options, &cur, NULL) < 0) {
|
||||
log_warn(LD_CONFIG,"options->Address didn't resolve into an IP.");
|
||||
return;
|
||||
}
|
||||
|
@ -2645,7 +2645,7 @@ add_trusted_dir_server(const char *nickname, const char *address,
|
||||
trusted_dir_servers = smartlist_create();
|
||||
|
||||
if (!address) { /* The address is us; we should guess. */
|
||||
if (resolve_my_address(get_options(), &a, &hostname) < 0) {
|
||||
if (resolve_my_address(LOG_WARN, get_options(), &a, &hostname) < 0) {
|
||||
log_warn(LD_CONFIG,
|
||||
"Couldn't find a suitable address when adding ourself as a "
|
||||
"trusted directory server.");
|
||||
|
Loading…
Reference in New Issue
Block a user