[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Server transports should be instructed to bind on INADDR_ANY by default.



commit 539cb627f71b476eb325ae6fff829b1f360ada00
Author: George Kadianakis <desnacked@xxxxxxxxx>
Date:   Sun Dec 18 13:21:58 2011 +0100

    Server transports should be instructed to bind on INADDR_ANY by default.
---
 src/or/config.c     |   30 +++++++++++++++++++-----------
 src/or/config.h     |    2 +-
 src/or/transports.c |    7 ++++++-
 3 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/or/config.c b/src/or/config.c
index 073b44d..521f760 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -6828,21 +6828,29 @@ get_transport_bindaddr(const char *line, const char *transport)
   return NULL;
 }
 
-/** Return a static string containing the address:port a proxy
- *  transport should bind on. */
-const char *
+/** Return a string containing the address:port that a proxy transport
+ *  should bind on. The string is stored on the heap and must be freed
+ *  by the caller of this function. */
+char *
 get_bindaddr_for_transport(const char *transport)
 {
-  static const char default_addrport[] = "127.0.0.1:0";
-  const char *bindaddr = NULL;
+  char *default_addrport = NULL;
+  const char *stored_bindaddr = NULL;
 
   config_line_t *line = get_transport_in_state_by_name(transport);
-  if (!line)
-    return default_addrport;
-
-  bindaddr = get_transport_bindaddr(line->value, transport);
-
-  return bindaddr ? bindaddr : default_addrport;
+  if (!line) /* Found no references in state for this transport. */
+    goto no_bindaddr_found;
+
+  stored_bindaddr = get_transport_bindaddr(line->value, transport);
+  if (stored_bindaddr) /* found stored bindaddr in state file. */
+    return tor_strdup(stored_bindaddr);
+
+ no_bindaddr_found:
+  /** If we didn't find references for this pluggable transport in the
+      state file, we should instruct the pluggable transport proxy to
+      listen on INADDR_ANY on a random ephemeral port. */
+  tor_asprintf(&default_addrport, "%s:%s", fmt_addr32(INADDR_ANY), "0");
+  return default_addrport;
 }
 
 /** Save <b>transport</b> listening on <b>addr</b>:<b>port</b> to
diff --git a/src/or/config.h b/src/or/config.h
index 2d94192..88258c1 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -77,7 +77,7 @@ int options_need_geoip_info(const or_options_t *options,
 
 void save_transport_to_state(const char *transport_name,
                              const tor_addr_t *addr, uint16_t port);
-const char *get_bindaddr_for_transport(const char *transport);
+char *get_bindaddr_for_transport(const char *transport);
 
 int getinfo_helper_config(control_connection_t *conn,
                           const char *question, char **answer,
diff --git a/src/or/transports.c b/src/or/transports.c
index 06bc039..1041502 100644
--- a/src/or/transports.c
+++ b/src/or/transports.c
@@ -920,13 +920,18 @@ static char *
 get_bindaddr_for_proxy(const managed_proxy_t *mp)
 {
   char *bindaddr = NULL;
+  char *bindaddr_tmp = NULL;
   smartlist_t *string_tmp = smartlist_create();
 
   tor_assert(mp->is_server);
 
   SMARTLIST_FOREACH_BEGIN(mp->transports_to_launch, char *, t) {
-    tor_asprintf(&bindaddr, "%s-%s", t, get_bindaddr_for_transport(t));
+    bindaddr_tmp = get_bindaddr_for_transport(t);
+
+    tor_asprintf(&bindaddr, "%s-%s", t, bindaddr_tmp);
     smartlist_add(string_tmp, bindaddr);
+
+    tor_free(bindaddr_tmp);
   } SMARTLIST_FOREACH_END(t);
 
   bindaddr = smartlist_join_strings(string_tmp, ",", 0, NULL);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits