Prechádzať zdrojové kódy

Restore the 'address' value of tunneled connections

When we merged the channel code, we made the 'address' field of linked
directory connections created with begindir (and their associated edge
connections) contain an address:port string, when they should only
have contained the address part.

This patch also tweaks the interface to the get_descr method of
channels so that it takes a set of flags rather than a single flag.
Nick Mathewson 11 rokov pred
rodič
commit
26946c659b
4 zmenil súbory, kde vykonal 36 pridanie a 11 odobranie
  1. 9 1
      src/or/channel.c
  2. 7 3
      src/or/channel.h
  3. 19 6
      src/or/channeltls.c
  4. 1 1
      src/or/connection_edge.c

+ 9 - 1
src/or/channel.c

@@ -3484,7 +3484,15 @@ channel_get_actual_remote_descr(channel_t *chan)
   tor_assert(chan->get_remote_descr);
 
   /* Param 1 indicates the actual description */
-  return chan->get_remote_descr(chan, 1);
+  return chan->get_remote_descr(chan, GRD_FLAG_ORIGINAL);
+}
+
+/** DOCDOC */
+const char *
+channel_get_actual_remote_address(channel_t *chan)
+{
+  /* Param 1 indicates the actual description */
+  return chan->get_remote_descr(chan, GRD_FLAG_ORIGINAL|GRD_FLAG_ADDR_ONLY);
 }
 
 /**

+ 7 - 3
src/or/channel.h

@@ -79,10 +79,13 @@ struct channel_s {
    * available.
    */
   int (*get_remote_addr)(channel_t *, tor_addr_t *);
+#define GRD_FLAG_ORIGINAL 1
+#define GRD_FLAG_ADDR_ONLY 2
   /*
-   * Get a text description of the remote endpoint; canonicalized if the
-   * arg is 0, or the one we originally connected to/received from if it's
-   * 1.
+   * Get a text description of the remote endpoint; canonicalized if the flag
+   * GRD_FLAG_ORIGINAL is not set, or the one we originally connected
+   * to/received from if it is.  If GRD_FLAG_ADDR_ONLY is set, we return only
+   * the original address.
    */
   const char * (*get_remote_descr)(channel_t *, int);
   /* Check if the lower layer has queued writes */
@@ -424,6 +427,7 @@ const char * channel_describe_transport(channel_t *chan);
 void channel_dump_statistics(channel_t *chan, int severity);
 void channel_dump_transport_statistics(channel_t *chan, int severity);
 const char * channel_get_actual_remote_descr(channel_t *chan);
+const char * channel_get_actual_remote_address(channel_t *chan);
 int channel_get_addr_if_possible(channel_t *chan, tor_addr_t *addr_out);
 const char * channel_get_canonical_remote_descr(channel_t *chan);
 int channel_has_queued_writes(channel_t *chan);

+ 19 - 6
src/or/channeltls.c

@@ -53,7 +53,7 @@ static const char * channel_tls_describe_transport_method(channel_t *chan);
 static int
 channel_tls_get_remote_addr_method(channel_t *chan, tor_addr_t *addr_out);
 static const char *
-channel_tls_get_remote_descr_method(channel_t *chan, int req);
+channel_tls_get_remote_descr_method(channel_t *chan, int flags);
 static int channel_tls_has_queued_writes_method(channel_t *chan);
 static int channel_tls_is_canonical_method(channel_t *chan, int req);
 static int
@@ -412,7 +412,7 @@ channel_tls_get_remote_addr_method(channel_t *chan, tor_addr_t *addr_out)
  */
 
 static const char *
-channel_tls_get_remote_descr_method(channel_t *chan, int req)
+channel_tls_get_remote_descr_method(channel_t *chan, int flags)
 {
 #define MAX_DESCR_LEN 32
 
@@ -427,21 +427,34 @@ channel_tls_get_remote_descr_method(channel_t *chan, int req)
 
   conn = TO_CONN(tlschan->conn);
 
-  switch (req) {
+  switch (flags) {
     case 0:
-      /* Canonical address */
+      /* Canonical address with port*/
       tor_snprintf(buf, MAX_DESCR_LEN + 1,
                    "%s:%u", conn->address, conn->port);
       answer = buf;
       break;
-    case 1:
-      /* Actual address */
+    case GRD_FLAG_ORIGINAL:
+      /* Actual address with port */
       addr_str = tor_dup_addr(&(tlschan->conn->real_addr));
       tor_snprintf(buf, MAX_DESCR_LEN + 1,
                    "%s:%u", addr_str, conn->port);
       tor_free(addr_str);
       answer = buf;
       break;
+    case GRD_FLAG_ADDR_ONLY:
+      /* Canonical address, no port */
+      strlcpy(buf, conn->address, sizeof(buf));
+      answer = buf;
+      break;
+    case GRD_FLAG_ORIGINAL|GRD_FLAG_ADDR_ONLY:
+      /* Actual address, no port */
+      addr_str = tor_dup_addr(&(tlschan->conn->real_addr));
+      strlcpy(buf, addr_str, sizeof(buf));
+      tor_free(addr_str);
+      answer = buf;
+      break;
+
     default:
       /* Something's broken in channel.c */
       tor_assert(1);

+ 1 - 1
src/or/connection_edge.c

@@ -3105,7 +3105,7 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
      * we might already have corrected base_.addr[ess] for the relay's
      * canonical IP address. */
     if (or_circ && or_circ->p_chan)
-      address = tor_strdup(channel_get_actual_remote_descr(or_circ->p_chan));
+      address = tor_strdup(channel_get_actual_remote_address(or_circ->p_chan));
     else
       address = tor_strdup("127.0.0.1");
     port = 1; /* XXXX This value is never actually used anywhere, and there