mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 20:33:31 +01:00
Remove compare_addr_to_node_policy
Instead, use compare_tor_addr_to_node_policy everywhere. One advantage of this is that compare_tor_addr_to_node_policy can better distinguish 0.0.0.0 from "unknown", which caused a nasty bug with microdesc users.
This commit is contained in:
parent
f40df02f3e
commit
6aef89bda4
@ -2634,7 +2634,7 @@ node_handles_some_port(const node_t *node, smartlist_t *needed_ports)
|
|||||||
port = *(uint16_t *)smartlist_get(needed_ports, i);
|
port = *(uint16_t *)smartlist_get(needed_ports, i);
|
||||||
tor_assert(port);
|
tor_assert(port);
|
||||||
if (node)
|
if (node)
|
||||||
r = compare_addr_to_node_policy(0, port, node);
|
r = compare_tor_addr_to_node_policy(NULL, port, node);
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
if (r != ADDR_POLICY_REJECTED && r != ADDR_POLICY_PROBABLY_REJECTED)
|
if (r != ADDR_POLICY_REJECTED && r != ADDR_POLICY_PROBABLY_REJECTED)
|
||||||
|
@ -509,7 +509,7 @@ circuit_stream_is_being_handled(edge_connection_t *conn,
|
|||||||
ok = connection_ap_can_use_exit(conn, exitnode);
|
ok = connection_ap_can_use_exit(conn, exitnode);
|
||||||
} else {
|
} else {
|
||||||
addr_policy_result_t r;
|
addr_policy_result_t r;
|
||||||
r = compare_addr_to_node_policy(0, port, exitnode);
|
r = compare_tor_addr_to_node_policy(NULL, port, exitnode);
|
||||||
ok = r != ADDR_POLICY_REJECTED && r != ADDR_POLICY_PROBABLY_REJECTED;
|
ok = r != ADDR_POLICY_REJECTED && r != ADDR_POLICY_PROBABLY_REJECTED;
|
||||||
}
|
}
|
||||||
if (ok) {
|
if (ok) {
|
||||||
@ -1262,10 +1262,12 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn,
|
|||||||
if (check_exit_policy) {
|
if (check_exit_policy) {
|
||||||
if (!conn->chosen_exit_name) {
|
if (!conn->chosen_exit_name) {
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
uint32_t addr = 0;
|
tor_addr_t addr, *addrp=NULL;
|
||||||
if (tor_inet_aton(conn->socks_request->address, &in))
|
if (tor_inet_aton(conn->socks_request->address, &in)) {
|
||||||
addr = ntohl(in.s_addr);
|
tor_addr_from_in(&addr, &in);
|
||||||
if (router_exit_policy_all_nodes_reject(addr,
|
addrp = &addr;
|
||||||
|
}
|
||||||
|
if (router_exit_policy_all_nodes_reject(addrp,
|
||||||
conn->socks_request->port,
|
conn->socks_request->port,
|
||||||
need_uptime)) {
|
need_uptime)) {
|
||||||
log_notice(LD_APP,
|
log_notice(LD_APP,
|
||||||
|
@ -3193,11 +3193,13 @@ connection_ap_can_use_exit(edge_connection_t *conn, const node_t *exit)
|
|||||||
if (conn->socks_request->command == SOCKS_COMMAND_CONNECT &&
|
if (conn->socks_request->command == SOCKS_COMMAND_CONNECT &&
|
||||||
!conn->use_begindir) {
|
!conn->use_begindir) {
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
uint32_t addr = 0;
|
tor_addr_t addr, *addrp = NULL;
|
||||||
addr_policy_result_t r;
|
addr_policy_result_t r;
|
||||||
if (tor_inet_aton(conn->socks_request->address, &in))
|
if (tor_inet_aton(conn->socks_request->address, &in)) {
|
||||||
addr = ntohl(in.s_addr);
|
tor_addr_from_in(&addr, &in);
|
||||||
r = compare_addr_to_node_policy(addr, conn->socks_request->port, exit);
|
addrp = &addr;
|
||||||
|
}
|
||||||
|
r = compare_tor_addr_to_node_policy(addrp, conn->socks_request->port, exit);
|
||||||
if (r == ADDR_POLICY_REJECTED)
|
if (r == ADDR_POLICY_REJECTED)
|
||||||
return 0; /* We know the address, and the exit policy rejects it. */
|
return 0; /* We know the address, and the exit policy rejects it. */
|
||||||
if (r == ADDR_POLICY_PROBABLY_REJECTED && !conn->chosen_exit_name)
|
if (r == ADDR_POLICY_PROBABLY_REJECTED && !conn->chosen_exit_name)
|
||||||
|
@ -689,7 +689,7 @@ compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port,
|
|||||||
if (!policy) {
|
if (!policy) {
|
||||||
/* no policy? accept all. */
|
/* no policy? accept all. */
|
||||||
return ADDR_POLICY_ACCEPTED;
|
return ADDR_POLICY_ACCEPTED;
|
||||||
} else if (tor_addr_is_null(addr)) {
|
} else if (addr == NULL || tor_addr_is_null(addr)) {
|
||||||
tor_assert(port != 0);
|
tor_assert(port != 0);
|
||||||
return compare_unknown_tor_addr_to_addr_policy(port, policy);
|
return compare_unknown_tor_addr_to_addr_policy(port, policy);
|
||||||
} else if (port == 0) {
|
} else if (port == 0) {
|
||||||
@ -1457,17 +1457,6 @@ short_policy_is_reject_star(const short_policy_t *policy)
|
|||||||
policy->entries[0].max_port == 65535);
|
policy->entries[0].max_port == 65535);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Decides whether addr:port is probably or definitely accepted or rejcted by
|
|
||||||
* <b>node</b>. See compare_tor_addr_to_addr_policy for details on addr/port
|
|
||||||
* interpretation. */
|
|
||||||
addr_policy_result_t
|
|
||||||
compare_addr_to_node_policy(uint32_t addr, uint16_t port, const node_t *node)
|
|
||||||
{
|
|
||||||
tor_addr_t a;
|
|
||||||
tor_addr_from_ipv4h(&a, addr);
|
|
||||||
return compare_tor_addr_to_node_policy(&a, port, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Decides whether addr:port is probably or definitely accepted or rejcted by
|
/** Decides whether addr:port is probably or definitely accepted or rejcted by
|
||||||
* <b>node</b>. See compare_tor_addr_to_addr_policy for details on addr/port
|
* <b>node</b>. See compare_tor_addr_to_addr_policy for details on addr/port
|
||||||
* interpretation. */
|
* interpretation. */
|
||||||
|
@ -38,8 +38,6 @@ int cmp_addr_policies(smartlist_t *a, smartlist_t *b);
|
|||||||
addr_policy_result_t compare_tor_addr_to_addr_policy(const tor_addr_t *addr,
|
addr_policy_result_t compare_tor_addr_to_addr_policy(const tor_addr_t *addr,
|
||||||
uint16_t port, const smartlist_t *policy);
|
uint16_t port, const smartlist_t *policy);
|
||||||
|
|
||||||
addr_policy_result_t compare_addr_to_node_policy(uint32_t addr,
|
|
||||||
uint16_t port, const node_t *node);
|
|
||||||
addr_policy_result_t compare_tor_addr_to_node_policy(const tor_addr_t *addr,
|
addr_policy_result_t compare_tor_addr_to_node_policy(const tor_addr_t *addr,
|
||||||
uint16_t port, const node_t *node);
|
uint16_t port, const node_t *node);
|
||||||
|
|
||||||
|
@ -4028,7 +4028,7 @@ routerlist_retry_directory_downloads(time_t now)
|
|||||||
/** Return 1 if all running sufficiently-stable routers we can use will reject
|
/** Return 1 if all running sufficiently-stable routers we can use will reject
|
||||||
* addr:port, return 0 if any might accept it. */
|
* addr:port, return 0 if any might accept it. */
|
||||||
int
|
int
|
||||||
router_exit_policy_all_nodes_reject(uint32_t addr, uint16_t port,
|
router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port,
|
||||||
int need_uptime)
|
int need_uptime)
|
||||||
{ /* XXXX MOVE */
|
{ /* XXXX MOVE */
|
||||||
addr_policy_result_t r;
|
addr_policy_result_t r;
|
||||||
@ -4037,7 +4037,7 @@ router_exit_policy_all_nodes_reject(uint32_t addr, uint16_t port,
|
|||||||
if (node->is_running &&
|
if (node->is_running &&
|
||||||
!node_is_unreliable(node, need_uptime, 0, 0)) {
|
!node_is_unreliable(node, need_uptime, 0, 0)) {
|
||||||
|
|
||||||
r = compare_addr_to_node_policy(addr, port, node);
|
r = compare_tor_addr_to_node_policy(addr, port, node);
|
||||||
|
|
||||||
if (r != ADDR_POLICY_REJECTED && r != ADDR_POLICY_PROBABLY_REJECTED)
|
if (r != ADDR_POLICY_REJECTED && r != ADDR_POLICY_PROBABLY_REJECTED)
|
||||||
return 0; /* this one could be ok. good enough. */
|
return 0; /* this one could be ok. good enough. */
|
||||||
|
@ -129,7 +129,7 @@ void router_load_extrainfo_from_string(const char *s, const char *eos,
|
|||||||
int descriptor_digests);
|
int descriptor_digests);
|
||||||
|
|
||||||
void routerlist_retry_directory_downloads(time_t now);
|
void routerlist_retry_directory_downloads(time_t now);
|
||||||
int router_exit_policy_all_nodes_reject(uint32_t addr, uint16_t port,
|
int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port,
|
||||||
int need_uptime);
|
int need_uptime);
|
||||||
|
|
||||||
int router_exit_policy_rejects_all(const routerinfo_t *router);
|
int router_exit_policy_rejects_all(const routerinfo_t *router);
|
||||||
|
Loading…
Reference in New Issue
Block a user