mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 22:58:50 +01:00
Removing is_internal_IP() function. Resolves ticket 4645.
This commit is contained in:
parent
5991f9a156
commit
3a4b24c3ab
7 changed files with 33 additions and 22 deletions
3
changes/ticket4645
Normal file
3
changes/ticket4645
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
o Code simplifications and refactoring:
|
||||||
|
- Removing is_internal_IP() function. Resolves ticket 4645.
|
||||||
|
|
|
@ -1421,19 +1421,6 @@ get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr)
|
||||||
* XXXX024 IPv6 deprecate some of these.
|
* XXXX024 IPv6 deprecate some of these.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Return true iff <b>ip</b> (in host order) is an IP reserved to localhost,
|
|
||||||
* or reserved for local networks by RFC 1918.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
is_internal_IP(uint32_t ip, int for_listening)
|
|
||||||
{
|
|
||||||
tor_addr_t myaddr;
|
|
||||||
myaddr.family = AF_INET;
|
|
||||||
myaddr.addr.in_addr.s_addr = htonl(ip);
|
|
||||||
|
|
||||||
return tor_addr_is_internal(&myaddr, for_listening);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Given an address of the form "ip:port", try to divide it into its
|
/** Given an address of the form "ip:port", try to divide it into its
|
||||||
* ip and port portions, setting *<b>address_out</b> to a newly
|
* ip and port portions, setting *<b>address_out</b> to a newly
|
||||||
* allocated string holding the address portion and *<b>port_out</b>
|
* allocated string holding the address portion and *<b>port_out</b>
|
||||||
|
|
|
@ -214,7 +214,6 @@ int tor_addr_port_parse(int severity, const char *addrport,
|
||||||
int tor_addr_hostname_is_local(const char *name);
|
int tor_addr_hostname_is_local(const char *name);
|
||||||
|
|
||||||
/* IPv4 helpers */
|
/* IPv4 helpers */
|
||||||
int is_internal_IP(uint32_t ip, int for_listening);
|
|
||||||
int addr_port_lookup(int severity, const char *addrport, char **address,
|
int addr_port_lookup(int severity, const char *addrport, char **address,
|
||||||
uint32_t *addr, uint16_t *port_out);
|
uint32_t *addr, uint16_t *port_out);
|
||||||
int parse_port_range(const char *port, uint16_t *port_min_out,
|
int parse_port_range(const char *port, uint16_t *port_min_out,
|
||||||
|
|
|
@ -2053,6 +2053,7 @@ resolve_my_address(int warn_severity, const or_options_t *options,
|
||||||
int notice_severity = warn_severity <= LOG_NOTICE ?
|
int notice_severity = warn_severity <= LOG_NOTICE ?
|
||||||
LOG_NOTICE : warn_severity;
|
LOG_NOTICE : warn_severity;
|
||||||
|
|
||||||
|
tor_addr_t myaddr;
|
||||||
tor_assert(addr_out);
|
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));
|
"local interface. Using that.", fmt_addr32(addr));
|
||||||
strlcpy(hostname, "<guessed from interfaces>", sizeof(hostname));
|
strlcpy(hostname, "<guessed from interfaces>", sizeof(hostname));
|
||||||
} else { /* resolved hostname into addr */
|
} else { /* resolved hostname into addr */
|
||||||
|
myaddr.family = AF_INET;
|
||||||
|
myaddr.addr.in_addr.s_addr = htonl(addr);
|
||||||
|
|
||||||
if (!explicit_hostname &&
|
if (!explicit_hostname &&
|
||||||
is_internal_IP(addr, 0)) {
|
tor_addr_is_internal(&myaddr, 0)) {
|
||||||
uint32_t interface_ip;
|
uint32_t interface_ip;
|
||||||
|
|
||||||
log_fn(notice_severity, LD_CONFIG, "Guessed local hostname '%s' "
|
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)) {
|
if (get_interface_address(warn_severity, &interface_ip)) {
|
||||||
log_fn(warn_severity, LD_CONFIG,
|
log_fn(warn_severity, LD_CONFIG,
|
||||||
"Could not get local interface IP address. Too bad.");
|
"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,
|
log_fn(notice_severity, LD_CONFIG,
|
||||||
"Interface IP address '%s' is a private address too. "
|
"Interface IP address '%s' is a private address too. "
|
||||||
"Ignoring.", fmt_addr32(interface_ip));
|
"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.
|
* 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);
|
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 */
|
/* make sure we're ok with publishing an internal IP */
|
||||||
if (!options->DirAuthorities && !options->AlternateDirAuthority) {
|
if (!options->DirAuthorities && !options->AlternateDirAuthority) {
|
||||||
/* if they are using the default authorities, disallow internal IPs
|
/* 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,
|
* 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
|
* 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
|
* 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)
|
if ((last_resolved_addr & (uint32_t)0xffffff00ul)
|
||||||
== (ip & (uint32_t)0xffffff00ul))
|
== (ip & (uint32_t)0xffffff00ul))
|
||||||
|
|
|
@ -1415,12 +1415,23 @@ http_set_address_origin(const char *headers, connection_t *conn)
|
||||||
fwd = http_get_header(headers, "X-Forwarded-For: ");
|
fwd = http_get_header(headers, "X-Forwarded-For: ");
|
||||||
if (fwd) {
|
if (fwd) {
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
if (!tor_inet_aton(fwd, &in) || is_internal_IP(ntohl(in.s_addr), 0)) {
|
if (!tor_inet_aton(fwd, &in)) {
|
||||||
log_debug(LD_DIR, "Ignoring unrecognized or internal IP %s",
|
log_debug(LD_DIR, "Ignoring unrecognized IP %s",
|
||||||
escaped(fwd));
|
escaped(fwd));
|
||||||
tor_free(fwd);
|
tor_free(fwd);
|
||||||
return;
|
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);
|
tor_free(conn->address);
|
||||||
conn->address = tor_strdup(fwd);
|
conn->address = tor_strdup(fwd);
|
||||||
tor_free(fwd);
|
tor_free(fwd);
|
||||||
|
|
|
@ -533,7 +533,12 @@ dirserv_router_has_valid_address(routerinfo_t *ri)
|
||||||
ri->address);
|
ri->address);
|
||||||
return -1;
|
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,
|
log_info(LD_DIRSERV,
|
||||||
"Router %s published internal IP address '%s'. Refusing.",
|
"Router %s published internal IP address '%s'. Refusing.",
|
||||||
router_describe(ri), ri->address);
|
router_describe(ri), ri->address);
|
||||||
|
|
|
@ -402,7 +402,6 @@ test_addr_ip6_helpers(void)
|
||||||
test_internal_ip("::ffff:169.254.0.0", 0);
|
test_internal_ip("::ffff:169.254.0.0", 0);
|
||||||
test_internal_ip("::ffff:169.254.255.255", 0);
|
test_internal_ip("::ffff:169.254.255.255", 0);
|
||||||
test_external_ip("::ffff:169.255.0.0", 0);
|
test_external_ip("::ffff:169.255.0.0", 0);
|
||||||
test_assert(is_internal_IP(0x7f000001, 0));
|
|
||||||
|
|
||||||
/* tor_addr_compare(tor_addr_t x2) */
|
/* tor_addr_compare(tor_addr_t x2) */
|
||||||
test_addr_compare("ffff::", ==, "ffff::0");
|
test_addr_compare("ffff::", ==, "ffff::0");
|
||||||
|
|
Loading…
Add table
Reference in a new issue