[tor-commits] [tor/master] Refactor client_dns_set_{reverse_, }addressmap() to take a circ

nickm at torproject.org nickm at torproject.org
Thu Nov 15 19:47:52 UTC 2012


commit ca8843df0adb088b028b5599cd3062ea608f716b
Author: Nick Mathewson <nickm at torproject.org>
Date:   Sun Oct 28 17:13:37 2012 -0400

    Refactor client_dns_set_{reverse_,}addressmap() to take a circ
    
    We'd like these functions to be circuit-relative so that we can
    implement a per-circuit DNS cache and per-circuit DNS cache rules for
    proposal 205 or its successors.  I'm doing this now, as a part of the
    IPv6 exits code, since there are about to be a few more instances
    of code using this.
---
 src/or/addressmap.c      |   14 +++++++++-----
 src/or/addressmap.h      |    6 ++++--
 src/or/connection_edge.c |   13 ++++++++++---
 src/or/relay.c           |    7 +++++--
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/or/addressmap.c b/src/or/addressmap.c
index fec83a7..4aa46fc 100644
--- a/src/or/addressmap.c
+++ b/src/or/addressmap.c
@@ -571,7 +571,8 @@ client_dns_clear_failures(const char *address)
  * <b>ttl</b>seconds; otherwise, we use the default.
  */
 static void
-client_dns_set_addressmap_impl(const char *address, const char *name,
+client_dns_set_addressmap_impl(origin_circuit_t *on_circ,
+                               const char *address, const char *name,
                                const char *exitname,
                                int ttl)
 {
@@ -579,6 +580,7 @@ client_dns_set_addressmap_impl(const char *address, const char *name,
   char extendedaddress[MAX_SOCKS_ADDR_LEN+MAX_VERBOSE_NICKNAME_LEN+10];
   /* 123.123.123.123.<hex or nickname>.exit\0  or just  123.123.123.123\0 */
   char extendedval[INET_NTOA_BUF_LEN+MAX_VERBOSE_NICKNAME_LEN+10];
+  (void)on_circ;
 
   tor_assert(address);
   tor_assert(name);
@@ -617,7 +619,8 @@ client_dns_set_addressmap_impl(const char *address, const char *name,
  * <b>ttl</b>seconds; otherwise, we use the default.
  */
 void
-client_dns_set_addressmap(const char *address, uint32_t val,
+client_dns_set_addressmap(origin_circuit_t *on_circ,
+                          const char *address, uint32_t val,
                           const char *exitname,
                           int ttl)
 {
@@ -631,7 +634,7 @@ client_dns_set_addressmap(const char *address, uint32_t val,
   in.s_addr = htonl(val);
   tor_inet_ntoa(&in,valbuf,sizeof(valbuf));
 
-  client_dns_set_addressmap_impl(address, valbuf, exitname, ttl);
+  client_dns_set_addressmap_impl(on_circ, address, valbuf, exitname, ttl);
 }
 
 /** Add a cache entry noting that <b>address</b> (ordinarily a dotted quad)
@@ -644,13 +647,14 @@ client_dns_set_addressmap(const char *address, uint32_t val,
  * <b>ttl</b>seconds; otherwise, we use the default.
  */
 void
-client_dns_set_reverse_addressmap(const char *address, const char *v,
+client_dns_set_reverse_addressmap(origin_circuit_t *on_circ,
+                                  const char *address, const char *v,
                                   const char *exitname,
                                   int ttl)
 {
   char *s = NULL;
   tor_asprintf(&s, "REVERSE[%s]", address);
-  client_dns_set_addressmap_impl(s, v, exitname, ttl);
+  client_dns_set_addressmap_impl(on_circ, s, v, exitname, ttl);
   tor_free(s);
 }
 
diff --git a/src/or/addressmap.h b/src/or/addressmap.h
index 911c7ac..dd8fc9b 100644
--- a/src/or/addressmap.h
+++ b/src/or/addressmap.h
@@ -28,14 +28,16 @@ int parse_virtual_addr_network(const char *val, int validate_only,
                                char **msg);
 int client_dns_incr_failures(const char *address);
 void client_dns_clear_failures(const char *address);
-void client_dns_set_addressmap(const char *address, uint32_t val,
+void client_dns_set_addressmap(origin_circuit_t *on_circ,
+                               const char *address, uint32_t val,
                                const char *exitname, int ttl);
 const char *addressmap_register_virtual_address(int type, char *new_address);
 void addressmap_get_mappings(smartlist_t *sl, time_t min_expires,
                              time_t max_expires, int want_expiry);
 int address_is_in_virtual_range(const char *addr);
 void clear_trackexithost_mappings(const char *exitname);
-void client_dns_set_reverse_addressmap(const char *address, const char *v,
+void client_dns_set_reverse_addressmap(origin_circuit_t *on_circ,
+                                       const char *address, const char *v,
                                        const char *exitname, int ttl);
 
 #endif
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 1ee88f3..f548576 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -1915,14 +1915,21 @@ connection_ap_handshake_socks_resolved(entry_connection_t *conn,
   size_t replylen;
 
   if (ttl >= 0) {
+    origin_circuit_t *origin_circ = NULL;
+    circuit_t *circ = ENTRY_TO_EDGE_CONN(conn)->on_circuit;
+    if (CIRCUIT_IS_ORIGIN(circ)) /* should always be true */
+      origin_circ = TO_ORIGIN_CIRCUIT(circ);
     if (answer_type == RESOLVED_TYPE_IPV4 && answer_len == 4) {
       uint32_t a = ntohl(get_uint32(answer));
-      if (a)
-        client_dns_set_addressmap(conn->socks_request->address, a,
+      if (a) {
+        client_dns_set_addressmap(origin_circ,
+                                  conn->socks_request->address, a,
                                   conn->chosen_exit_name, ttl);
+      }
     } else if (answer_type == RESOLVED_TYPE_HOSTNAME && answer_len < 256) {
       char *cp = tor_strndup((char*)answer, answer_len);
-      client_dns_set_reverse_addressmap(conn->socks_request->address,
+      client_dns_set_reverse_addressmap(origin_circ,
+                                        conn->socks_request->address,
                                         cp,
                                         conn->chosen_exit_name, ttl);
       tor_free(cp);
diff --git a/src/or/relay.c b/src/or/relay.c
index 25fc2e7..76e9d25 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -725,7 +725,9 @@ connection_ap_process_end_not_open(
             connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL);
             return 0;
           }
-          client_dns_set_addressmap(conn->socks_request->address, addr,
+
+          client_dns_set_addressmap(circ,
+                                    conn->socks_request->address, addr,
                                     conn->chosen_exit_name, ttl);
         }
         /* check if he *ought* to have allowed it */
@@ -898,7 +900,8 @@ connection_edge_process_relay_cell_not_open(
         ttl = (int)ntohl(get_uint32(cell->payload+RELAY_HEADER_SIZE+4));
       else
         ttl = -1;
-      client_dns_set_addressmap(entry_conn->socks_request->address, addr,
+      client_dns_set_addressmap(TO_ORIGIN_CIRCUIT(circ),
+                                entry_conn->socks_request->address, addr,
                                 entry_conn->chosen_exit_name, ttl);
 
       remap_event_helper(entry_conn, addr);





More information about the tor-commits mailing list