[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Restore the 'address' value of tunneled connections
commit 26946c659b5abdc38fd4dc8cd4b4659aadcf05f0
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Wed Oct 17 11:23:26 2012 -0400
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.
---
src/or/channel.c | 10 +++++++++-
src/or/channel.h | 10 +++++++---
src/or/channeltls.c | 25 +++++++++++++++++++------
src/or/connection_edge.c | 2 +-
4 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/src/or/channel.c b/src/or/channel.c
index 10097ae..13aa007 100644
--- a/src/or/channel.c
+++ b/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);
}
/**
diff --git a/src/or/channel.h b/src/or/channel.h
index 33b7c8f..d90335c 100644
--- a/src/or/channel.h
+++ b/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);
diff --git a/src/or/channeltls.c b/src/or/channeltls.c
index 234aa31..a7ac83f 100644
--- a/src/or/channeltls.c
+++ b/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);
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 53b57eb..4d528a8 100644
--- a/src/or/connection_edge.c
+++ b/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
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits