aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2013-11-16 18:29:54 +0200
committerNick Mathewson <nickm@torproject.org>2014-02-03 14:20:17 -0500
commit3a4b24c3aba56475822ad94d268b48fd58b74645 (patch)
tree42eeca5141f199b241dd1358431ab04d364adf9b /src/or
parent5991f9a15646d53b838562fd1424b6a8fd9ef614 (diff)
downloadtor-3a4b24c3aba56475822ad94d268b48fd58b74645.tar
tor-3a4b24c3aba56475822ad94d268b48fd58b74645.tar.gz
Removing is_internal_IP() function. Resolves ticket 4645.
Diffstat (limited to 'src/or')
-rw-r--r--src/or/config.c15
-rw-r--r--src/or/directory.c15
-rw-r--r--src/or/dirserv.c7
3 files changed, 30 insertions, 7 deletions
diff --git a/src/or/config.c b/src/or/config.c
index e7847d583..f840b5e28 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -2053,6 +2053,7 @@ resolve_my_address(int warn_severity, const or_options_t *options,
int notice_severity = warn_severity <= LOG_NOTICE ?
LOG_NOTICE : warn_severity;
+ tor_addr_t myaddr;
tor_assert(addr_out);
/*
@@ -2103,8 +2104,11 @@ resolve_my_address(int warn_severity, const or_options_t *options,
"local interface. Using that.", fmt_addr32(addr));
strlcpy(hostname, "<guessed from interfaces>", sizeof(hostname));
} else { /* resolved hostname into addr */
+ myaddr.family = AF_INET;
+ myaddr.addr.in_addr.s_addr = htonl(addr);
+
if (!explicit_hostname &&
- is_internal_IP(addr, 0)) {
+ tor_addr_is_internal(&myaddr, 0)) {
uint32_t interface_ip;
log_fn(notice_severity, LD_CONFIG, "Guessed local hostname '%s' "
@@ -2114,7 +2118,7 @@ resolve_my_address(int warn_severity, const or_options_t *options,
if (get_interface_address(warn_severity, &interface_ip)) {
log_fn(warn_severity, LD_CONFIG,
"Could not get local interface IP address. Too bad.");
- } else if (is_internal_IP(interface_ip, 0)) {
+ } else if (tor_addr_is_internal(&myaddr, 0)) {
log_fn(notice_severity, LD_CONFIG,
"Interface IP address '%s' is a private address too. "
"Ignoring.", fmt_addr32(interface_ip));
@@ -2138,8 +2142,11 @@ resolve_my_address(int warn_severity, const or_options_t *options,
* out if it is and we don't want that.
*/
+ myaddr.family = AF_INET;
+ myaddr.addr.in_addr.s_addr = htonl(addr);
+
addr_string = tor_dup_ip(addr);
- if (is_internal_IP(addr, 0)) {
+ if (tor_addr_is_internal(&myaddr, 0)) {
/* make sure we're ok with publishing an internal IP */
if (!options->DirAuthorities && !options->AlternateDirAuthority) {
/* if they are using the default authorities, disallow internal IPs
@@ -2245,7 +2252,7 @@ is_local_addr(const tor_addr_t *addr)
* resolve_my_address will never be called at all). In those cases,
* last_resolved_addr will be 0, and so checking to see whether ip is on
* the same /24 as last_resolved_addr will be the same as checking whether
- * it was on net 0, which is already done by is_internal_IP.
+ * it was on net 0, which is already done by tor_addr_is_internal.
*/
if ((last_resolved_addr & (uint32_t)0xffffff00ul)
== (ip & (uint32_t)0xffffff00ul))
diff --git a/src/or/directory.c b/src/or/directory.c
index 0cacf0661..7f26affa2 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -1415,12 +1415,23 @@ http_set_address_origin(const char *headers, connection_t *conn)
fwd = http_get_header(headers, "X-Forwarded-For: ");
if (fwd) {
struct in_addr in;
- if (!tor_inet_aton(fwd, &in) || is_internal_IP(ntohl(in.s_addr), 0)) {
- log_debug(LD_DIR, "Ignoring unrecognized or internal IP %s",
+ if (!tor_inet_aton(fwd, &in)) {
+ log_debug(LD_DIR, "Ignoring unrecognized IP %s",
escaped(fwd));
tor_free(fwd);
return;
}
+
+ tor_addr_t toraddr;
+ toraddr.family = AF_INET;
+ toraddr.addr.in_addr = in;
+
+ if (tor_addr_is_internal(&toraddr,0)) {
+ log_debug(LD_DIR, "Ignoring local IP %s", escaped(fwd));
+ tor_free(fwd);
+ return;
+ }
+
tor_free(conn->address);
conn->address = tor_strdup(fwd);
tor_free(fwd);
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index c0e000c75..4a25f99a4 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -533,7 +533,12 @@ dirserv_router_has_valid_address(routerinfo_t *ri)
ri->address);
return -1;
}
- if (is_internal_IP(ntohl(iaddr.s_addr), 0)) {
+
+ tor_addr_t toraddr;
+ toraddr.family = AF_INET;
+ toraddr.addr.in_addr = iaddr;
+
+ if (tor_addr_is_internal(&toraddr, 0)) {
log_info(LD_DIRSERV,
"Router %s published internal IP address '%s'. Refusing.",
router_describe(ri), ri->address);