From da16c425ef8c17a753ae0abc3fdb26a328004062 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Thu, 7 Jun 2012 19:20:36 +0300 Subject: Start passing ports to tor_check_port_forwarding(). Conflicts: src/or/transports.c --- src/or/config.c | 35 +++++++++++++++++++++++++++++++++++ src/or/main.c | 2 +- src/or/transports.c | 27 +++++++++++++++++++++++++++ src/or/transports.h | 2 ++ 4 files changed, 65 insertions(+), 1 deletion(-) 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 *answer 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 { -- cgit v1.2.3