summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-10-16 17:29:50 -0400
committerNick Mathewson <nickm@torproject.org>2018-10-16 17:29:50 -0400
commit698629f5a9eca21e0251f5d249f176a00aebf871 (patch)
tree77c87de6ec958685a3a296be5b1083959240e29e
parent8a0b7414870d2e0ddf90db8184b36be7309bd5c1 (diff)
parent89c4a3a0b6f824841ab03d39ca59acc73a80b728 (diff)
downloadtor-698629f5a9eca21e0251f5d249f176a00aebf871.tar.gz
tor-698629f5a9eca21e0251f5d249f176a00aebf871.zip
Merge remote-tracking branch 'tor-github/pr/404'
-rw-r--r--changes/bug279284
-rw-r--r--src/core/mainloop/connection.c10
2 files changed, 14 insertions, 0 deletions
diff --git a/changes/bug27928 b/changes/bug27928
new file mode 100644
index 0000000000..a4ea63e8fe
--- /dev/null
+++ b/changes/bug27928
@@ -0,0 +1,4 @@
+ o Minor bugfixes (networking):
+ - Refrain from attempting socket rebinding when old
+ and new listeners are in different address families.
+ Fixes bug 27928; bugfix on 0.3.5.1-alpha.
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index 9ef0561a55..5c0799fbe3 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -2797,7 +2797,17 @@ retry_listener_ports(smartlist_t *old_conns,
break;
}
#ifdef ENABLE_LISTENER_REBIND
+ /* Rebinding may be needed if all of the following are true:
+ * 1) Address family is the same in old and new listeners.
+ * 2) Port number matches exactly (numeric value is the same).
+ * 3) *One* of listeners (either old one or new one) has a
+ * wildcard IP address (0.0.0.0 or [::]).
+ *
+ * These are the exact conditions for a first bind() syscall
+ * to fail with EADDRINUSE.
+ */
const int may_need_rebind =
+ tor_addr_family(&wanted->addr) == tor_addr_family(&conn->addr) &&
port_matches_exact && bool_neq(tor_addr_is_null(&wanted->addr),
tor_addr_is_null(&conn->addr));
if (replacements && may_need_rebind) {