aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2012-03-31 14:04:58 +0200
committerGeorge Kadianakis <desnacked@riseup.net>2012-03-31 14:04:58 +0200
commit10232dc0423792a8fb61b9ec136d7ffd5484216b (patch)
tree76e2b7b2696a11b1ce02eec2cad64eab90e0b061 /src/or
parentfedf76a2e6452124c38ecc51cea6567b9d5cc23d (diff)
downloadtor-10232dc0423792a8fb61b9ec136d7ffd5484216b.tar
tor-10232dc0423792a8fb61b9ec136d7ffd5484216b.tar.gz
Pass OR address to PT proxy, even with IPv6 or ORListenAddress.
Introduce get_first_listener_addrport_for_pt() which returns a string containing the addrport of the first listener we could find. Use it to form the TOR_PT_ORPORT managed proxy protocol line.
Diffstat (limited to 'src/or')
-rw-r--r--src/or/config.c53
-rw-r--r--src/or/config.h2
-rw-r--r--src/or/transports.c9
3 files changed, 60 insertions, 4 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 2a8c54096..5ea1f5ede 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -6026,6 +6026,59 @@ get_configured_ports(void)
return configured_ports;
}
+/** Return an <address>:<port> string representation of the address
+ * where the first <b>listener_type</b> listener waits for
+ * connections. Return NULL if we couldn't find a listener. The
+ * string is allocated on the heap and it's the responsibility of the
+ * caller to free it after use.
+ *
+ * This function is meant to be used by the pluggable transport proxy
+ * spawning code. */
+char *
+get_first_listener_addrport_for_pt(int listener_type)
+{
+ static const char *ipv4_localhost = "127.0.0.1";
+ static const char *ipv6_localhost = "[::1]";
+ const char *address;
+ uint16_t port;
+ char *string = NULL;
+
+ if (!configured_ports)
+ return NULL;
+
+ SMARTLIST_FOREACH_BEGIN(configured_ports, const port_cfg_t *, cfg) {
+
+ if (cfg->type == listener_type &&
+ tor_addr_family(&cfg->addr) != AF_UNSPEC) {
+
+ /* We found the first listener of the type we are interested in! */
+
+ /* If a listener is listening on INADDR_ANY, assume that it's
+ also listening on 127.0.0.1, and point the transport proxy
+ there: */
+ if (tor_addr_is_null(&cfg->addr))
+ address = tor_addr_is_v4(&cfg->addr) ? ipv4_localhost : ipv6_localhost;
+ else
+ address = fmt_and_decorate_addr(&cfg->addr);
+
+ /* If a listener is configured with port 'auto', we are forced
+ to iterate all listener connections and find out in which
+ port it ended up listening: */
+ if (cfg->port == CFG_AUTO_PORT)
+ port = router_get_active_listener_port_by_type(listener_type);
+ else
+ port = cfg->port;
+
+ tor_asprintf(&string, "%s:%u", address, port);
+
+ return string;
+ }
+
+ } SMARTLIST_FOREACH_END(cfg);
+
+ return NULL;
+}
+
/** Return the first advertised port of type <b>listener_type</b> in
<b>address_family</b>. */
int
diff --git a/src/or/config.h b/src/or/config.h
index 0f7c61886..fd84d9b60 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -72,6 +72,8 @@ int get_first_advertised_port_by_type_af(int listener_type,
#define get_primary_dir_port() \
(get_first_advertised_port_by_type_af(CONN_TYPE_DIR_LISTENER, AF_INET))
+char *get_first_listener_addrport_for_pt(int listener_type);
+
int options_need_geoip_info(const or_options_t *options,
const char **reason_out);
diff --git a/src/or/transports.c b/src/or/transports.c
index 564603e1f..1f2149381 100644
--- a/src/or/transports.c
+++ b/src/or/transports.c
@@ -957,8 +957,6 @@ get_bindaddr_for_server_proxy(const managed_proxy_t *mp)
static process_environment_t *
create_managed_proxy_environment(const managed_proxy_t *mp)
{
- const or_options_t *options = get_options();
-
/* Environment variables to be added to or set in mp's environment. */
smartlist_t *envs = smartlist_new();
/* XXXX The next time someone touches this code, shorten the name of
@@ -993,8 +991,11 @@ create_managed_proxy_environment(const managed_proxy_t *mp)
}
if (mp->is_server) {
- smartlist_add_asprintf(envs, "TOR_PT_ORPORT=127.0.0.1:%s",
- options->ORPort->value);
+ {
+ char *orport_tmp = get_first_listener_addrport_for_pt(CONN_TYPE_OR_LISTENER);
+ smartlist_add_asprintf(envs, "TOR_PT_ORPORT=%s", orport_tmp);
+ tor_free(orport_tmp);
+ }
{
char *bindaddr_tmp = get_bindaddr_for_server_proxy(mp);