summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2018-10-15 16:13:22 +0300
committerrl1987 <rl1987@sdf.lonestar.org>2018-10-15 16:18:31 +0300
commit89c4a3a0b6f824841ab03d39ca59acc73a80b728 (patch)
treee424fd1a2a7b68ae14a4b173f3298f6b3b0879eb
parent9bb00a74bc4ebdb154e0f9289ed4ab362ee5c564 (diff)
downloadtor-89c4a3a0b6f824841ab03d39ca59acc73a80b728.tar.gz
tor-89c4a3a0b6f824841ab03d39ca59acc73a80b728.zip
Write a comment to explain may_need_rebind condition
-rw-r--r--src/core/mainloop/connection.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index 5ebfac6bee..5c0799fbe3 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -2797,6 +2797,15 @@ 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),