aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2012-06-07 19:20:36 +0300
committerGeorge Kadianakis <desnacked@riseup.net>2012-09-05 18:08:18 +0300
commitda16c425ef8c17a753ae0abc3fdb26a328004062 (patch)
treeca4cb298c5393740d44dd616cd4ef5b7c86d7309
parentcd05f35d2cdf50d31108428cf5c19549d468dbc0 (diff)
downloadtor-da16c425ef8c17a753ae0abc3fdb26a328004062.tar
tor-da16c425ef8c17a753ae0abc3fdb26a328004062.tar.gz
Start passing ports to tor_check_port_forwarding().
Conflicts: src/or/transports.c
-rw-r--r--src/or/config.c35
-rw-r--r--src/or/main.c2
-rw-r--r--src/or/transports.c27
-rw-r--r--src/or/transports.h2
4 files changed, 65 insertions, 1 deletions
diff --git a/src/or/config.c b/src/or/config.c
index f21016d48..ad422efcd 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -7254,6 +7254,41 @@ remove_file_if_very_old(const char *fname, time_t now)
}
}
+/** Return a smartlist of ports that must be forwarded by
+ * tor-fw-helper. The smartlist contains the ports in a string format
+ * that is understandable by tor-fw-helper. */
+smartlist_t *
+get_list_of_ports_to_forward(void)
+{
+ smartlist_t *ports_to_forward = smartlist_new();
+ int port = 0;
+
+ /** XXX TODO tor-fw-helper does not support forwarding ports to
+ other hosts than the local one. If the user is binding to a
+ different IP address, tor-fw-helper won't work. */
+ port = get_primary_or_port(); /* Get ORPort */
+ if (port)
+ smartlist_add_asprintf(ports_to_forward, "%d:%d", port, port);
+
+ port = get_primary_dir_port(); /* Get DirPort */
+ if (port)
+ smartlist_add_asprintf(ports_to_forward, "%d:%d", port, port);
+
+ /* Get ports of transport proxies */
+ smartlist_t *transport_ports = get_transport_proxy_ports();
+ if (transport_ports) {
+ smartlist_add_all(ports_to_forward, transport_ports);
+ smartlist_free(transport_ports);
+ }
+
+ if (!smartlist_len(ports_to_forward)) {
+ smartlist_free(ports_to_forward);
+ ports_to_forward = NULL;
+ }
+
+ return ports_to_forward;
+}
+
/** Helper to implement GETINFO functions about configuration variables (not
* their values). Given a "config/names" question, set *<b>answer</b> to a
* new string describing the supported configuration variables and their
diff --git a/src/or/main.c b/src/or/main.c
index 7b750ba75..75a6d6541 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1547,7 +1547,7 @@ run_scheduled_events(time_t now)
options->PortForwarding &&
is_server) {
#define PORT_FORWARDING_CHECK_INTERVAL 5
- smartlist_t *ports_to_forward = NULL;//get_list_of_ports_to_forward();
+ smartlist_t *ports_to_forward = get_list_of_ports_to_forward();
if (ports_to_forward) {
tor_check_port_forwarding(options->PortForwardingHelper,
ports_to_forward,
diff --git a/src/or/transports.c b/src/or/transports.c
index 9edeebdba..f2c604ce8 100644
--- a/src/or/transports.c
+++ b/src/or/transports.c
@@ -1324,6 +1324,33 @@ pt_prepare_proxy_list_for_config_read(void)
tor_assert(unconfigured_proxies_n == 0);
}
+/** Return a smartlist containing the ports where our pluggable
+ * transports are listening. */
+smartlist_t *
+get_transport_proxy_ports(void)
+{
+ smartlist_t *sl = NULL;
+
+ if (!managed_proxy_list)
+ return NULL;
+
+ /** XXX assume that external proxy ports have been forwarded
+ manually */
+ SMARTLIST_FOREACH_BEGIN(managed_proxy_list, const managed_proxy_t *, mp) {
+ if (!mp->is_server || mp->conf_state != PT_PROTO_COMPLETED)
+ continue;
+
+ if (!sl) sl = smartlist_new();
+
+ tor_assert(mp->transports);
+ SMARTLIST_FOREACH(mp->transports, const transport_t *, t,
+ smartlist_add_asprintf(sl, "%u:%u", t->port, t->port));
+
+ } SMARTLIST_FOREACH_END(mp);
+
+ return sl;
+}
+
/** Return the pluggable transport string that we should display in
* our extra-info descriptor. If we shouldn't display such a string,
* or we have nothing to display, return NULL. The string is
diff --git a/src/or/transports.h b/src/or/transports.h
index 3fd97f8c2..86a2530fc 100644
--- a/src/or/transports.h
+++ b/src/or/transports.h
@@ -54,6 +54,8 @@ void pt_free_all(void);
void pt_prepare_proxy_list_for_config_read(void);
void sweep_proxy_list(void);
+smartlist_t *get_transport_proxy_ports(void);
+
#ifdef PT_PRIVATE
/** State of the managed proxy configuration protocol. */
enum pt_proto_state {