From 9bb00a74bc4ebdb154e0f9289ed4ab362ee5c564 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Tue, 2 Oct 2018 15:47:05 +0300 Subject: [PATCH 1/2] Refrain from listener rebinding when address families differ --- changes/bug27928 | 4 ++++ src/core/mainloop/connection.c | 1 + 2 files changed, 5 insertions(+) create mode 100644 changes/bug27928 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..5ebfac6bee 100644 --- a/src/core/mainloop/connection.c +++ b/src/core/mainloop/connection.c @@ -2798,6 +2798,7 @@ retry_listener_ports(smartlist_t *old_conns, } #ifdef ENABLE_LISTENER_REBIND 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) { From 89c4a3a0b6f824841ab03d39ca59acc73a80b728 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Mon, 15 Oct 2018 16:13:22 +0300 Subject: [PATCH 2/2] Write a comment to explain may_need_rebind condition --- src/core/mainloop/connection.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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),