mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
+5
-4
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user