]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
If DisableNetwork, don't even try to open non-controller listeners
authorNick Mathewson <nickm@torproject.org>
Thu, 19 Apr 2012 03:32:02 +0000 (23:32 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 19 Apr 2012 03:32:02 +0000 (23:32 -0400)
Fix for 5604; bugfix on 0.2.3.9-alpha, which introduced DisableNetwork.

changes/bug5604 [new file with mode: 0644]
src/or/config.c
src/or/connection.c
src/or/connection.h
src/or/main.c

diff --git a/changes/bug5604 b/changes/bug5604
new file mode 100644 (file)
index 0000000..4c72f3c
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor bugfixes:
+    - Don't try to open non-control listeners when DisableNetwork is set.
+      Previousy, we'd open all listeners, then immediately close them.
+      Fixes bug 5604; bugfix on 0.2.3.9-alpha.
index 696bbd04409899681075001416e7dcdc552feb71..8c44a716bcdfa42090b9b98053e952f8958f9481 100644 (file)
@@ -1119,7 +1119,8 @@ options_act_reversible(const or_options_t *old_options, char **msg)
      * networking is disabled, this will close all but the control listeners,
      * but disable those. */
     if (!we_are_hibernating()) {
-      if (retry_all_listeners(replaced_listeners, new_listeners) < 0) {
+      if (retry_all_listeners(replaced_listeners, new_listeners,
+                              options->DisableNetwork) < 0) {
         *msg = tor_strdup("Failed to bind one of the listener ports.");
         goto rollback;
       }
index 1c034c655bdb8d829cc4a91b6484b472710bfa86..642ee6e957df08b18d2185d11b09b590bede2e35 100644 (file)
@@ -1812,12 +1812,20 @@ connection_read_proxy_handshake(connection_t *conn)
 static int
 retry_listener_ports(smartlist_t *old_conns,
                      const smartlist_t *ports,
-                     smartlist_t *new_conns)
+                     smartlist_t *new_conns,
+                     int close_all_noncontrol)
 {
   smartlist_t *launch = smartlist_new();
   int r = 0;
 
-  smartlist_add_all(launch, ports);
+  if (close_all_noncontrol) {
+    SMARTLIST_FOREACH(ports, port_cfg_t *, p, {
+        if (p->type == CONN_TYPE_CONTROL_LISTENER)
+          smartlist_add(launch, p);
+    });
+  } else {
+    smartlist_add_all(launch, ports);
+  }
 
   /* Iterate through old_conns, comparing it to launch: remove from both lists
    * each pair of elements that corresponds to the same port. */
@@ -1920,7 +1928,7 @@ retry_listener_ports(smartlist_t *old_conns,
  */
 int
 retry_all_listeners(smartlist_t *replaced_conns,
-                    smartlist_t *new_conns)
+                    smartlist_t *new_conns, int close_all_noncontrol)
 {
   smartlist_t *listeners = smartlist_new();
   const or_options_t *options = get_options();
@@ -1935,7 +1943,8 @@ retry_all_listeners(smartlist_t *replaced_conns,
 
   if (retry_listener_ports(listeners,
                            get_configured_ports(),
-                           new_conns) < 0)
+                           new_conns,
+                           close_all_noncontrol) < 0)
     retval = -1;
 
   /* Any members that were still in 'listeners' don't correspond to
index c4b8bf8abebba23f2e122a6bb7c81395ed4d522c..bdeefa2549c955e8e81700fa4977f6b2e5d72b05 100644 (file)
@@ -64,7 +64,8 @@ int get_proxy_addrport(tor_addr_t *addr, uint16_t *port, int *proxy_type,
                        const connection_t *conn);
 
 int retry_all_listeners(smartlist_t *replaced_conns,
-                        smartlist_t *new_conns);
+                        smartlist_t *new_conns,
+                        int close_all_noncontrol);
 
 void connection_mark_all_noncontrol_listeners(void);
 void connection_mark_all_noncontrol_connections(void);
index 9022f2eb877456949ee93670fe2ffe1ad7977709..f104b66cd7fd8fea16e091603ad206a13ef7ae22 100644 (file)
@@ -1428,7 +1428,7 @@ run_scheduled_events(time_t now)
 
   /** 3d. And every 60 seconds, we relaunch listeners if any died. */
   if (!net_is_disabled() && time_to_check_listeners < now) {
-    retry_all_listeners(NULL, NULL);
+    retry_all_listeners(NULL, NULL, 0);
     time_to_check_listeners = now+60;
   }