[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Remove compare_addr_to_node_policy



commit 6aef89bda4800384eddf79e42d965c2b011acdb4
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri Jul 15 12:58:13 2011 -0400

    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.
---
 src/or/circuitbuild.c    |    2 +-
 src/or/circuituse.c      |   12 +++++++-----
 src/or/connection_edge.c |   10 ++++++----
 src/or/policies.c        |   13 +------------
 src/or/policies.h        |    2 --
 src/or/routerlist.c      |    4 ++--
 src/or/routerlist.h      |    2 +-
 7 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 4397aa5..f7d5524 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -2634,7 +2634,7 @@ node_handles_some_port(const node_t *node, smartlist_t *needed_ports)
     port = *(uint16_t *)smartlist_get(needed_ports, i);
     tor_assert(port);
     if (node)
-      r = compare_addr_to_node_policy(0, port, node);
+      r = compare_tor_addr_to_node_policy(NULL, port, node);
     else
       continue;
     if (r != ADDR_POLICY_REJECTED && r != ADDR_POLICY_PROBABLY_REJECTED)
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 67677ef..460c41f 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -509,7 +509,7 @@ circuit_stream_is_being_handled(edge_connection_t *conn,
           ok = connection_ap_can_use_exit(conn, exitnode);
         } else {
           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;
         }
         if (ok) {
@@ -1262,10 +1262,12 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn,
   if (check_exit_policy) {
     if (!conn->chosen_exit_name) {
       struct in_addr in;
-      uint32_t addr = 0;
-      if (tor_inet_aton(conn->socks_request->address, &in))
-        addr = ntohl(in.s_addr);
-      if (router_exit_policy_all_nodes_reject(addr,
+      tor_addr_t addr, *addrp=NULL;
+      if (tor_inet_aton(conn->socks_request->address, &in)) {
+        tor_addr_from_in(&addr, &in);
+        addrp = &addr;
+      }
+      if (router_exit_policy_all_nodes_reject(addrp,
                                               conn->socks_request->port,
                                               need_uptime)) {
         log_notice(LD_APP,
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index a4a77af..867bd7a 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -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 &&
       !conn->use_begindir) {
     struct in_addr in;
-    uint32_t addr = 0;
+    tor_addr_t addr, *addrp = NULL;
     addr_policy_result_t r;
-    if (tor_inet_aton(conn->socks_request->address, &in))
-      addr = ntohl(in.s_addr);
-    r = compare_addr_to_node_policy(addr, conn->socks_request->port, exit);
+    if (tor_inet_aton(conn->socks_request->address, &in)) {
+      tor_addr_from_in(&addr, &in);
+      addrp = &addr;
+    }
+    r = compare_tor_addr_to_node_policy(addrp, conn->socks_request->port, exit);
     if (r == ADDR_POLICY_REJECTED)
       return 0; /* We know the address, and the exit policy rejects it. */
     if (r == ADDR_POLICY_PROBABLY_REJECTED && !conn->chosen_exit_name)
diff --git a/src/or/policies.c b/src/or/policies.c
index 93cae76..40e5277 100644
--- a/src/or/policies.c
+++ b/src/or/policies.c
@@ -689,7 +689,7 @@ compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port,
   if (!policy) {
     /* no policy? accept all. */
     return ADDR_POLICY_ACCEPTED;
-  } else if (tor_addr_is_null(addr)) {
+  } else if (addr == NULL || tor_addr_is_null(addr)) {
     tor_assert(port != 0);
     return compare_unknown_tor_addr_to_addr_policy(port, policy);
   } else if (port == 0) {
@@ -1461,17 +1461,6 @@ short_policy_is_reject_star(const short_policy_t *policy)
  * <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
- * <b>node</b>.  See compare_tor_addr_to_addr_policy for details on addr/port
- * interpretation. */
-addr_policy_result_t
 compare_tor_addr_to_node_policy(const tor_addr_t *addr, uint16_t port,
                                 const node_t *node)
 {
diff --git a/src/or/policies.h b/src/or/policies.h
index 9859b00..51716ab 100644
--- a/src/or/policies.h
+++ b/src/or/policies.h
@@ -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,
                               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,
                               uint16_t port, const node_t *node);
 
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index c0a233c..2fff4c9 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -4028,7 +4028,7 @@ routerlist_retry_directory_downloads(time_t now)
 /** Return 1 if all running sufficiently-stable routers we can use will reject
  * addr:port, return 0 if any might accept it. */
 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)
 { /* XXXX MOVE */
   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 &&
         !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)
         return 0; /* this one could be ok. good enough. */
diff --git a/src/or/routerlist.h b/src/or/routerlist.h
index 1129046..cae8814 100644
--- a/src/or/routerlist.h
+++ b/src/or/routerlist.h
@@ -129,7 +129,7 @@ void router_load_extrainfo_from_string(const char *s, const char *eos,
                                        int descriptor_digests);
 
 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 router_exit_policy_rejects_all(const routerinfo_t *router);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits