Skip to content

Commit 9ca0d3f

Browse files
jtc3161srh
andcommitted
Don't use DNS resolution when finding local ip addresses.
Removes use of DNS to find local ip addresses to bind to, except on Windows. Also removes mistaken "Ignore loopback addresses" logic, which happened to get its conditional flipped the wrong way. The flipped "Ignore loopback addresses" logic meant that we would remove all non-loopback addresses that got returned by the DNS lookup. So removing the DNS lookup entirely won't break things. The behavior on Windows never used getifaddrs, it just used DNS lookup. We keep the old behavior on Windows because limited manpower prevents us from using the Windows alternative to getifaddrs. Fixes #4600. Co-authored-by: Sam Hughes <[email protected]>
1 parent a8bb2e9 commit 9ca0d3f

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

src/arch/address.cc

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,28 +155,19 @@ std::set<ip_address_t> hostname_to_ips(const std::string &host) {
155155
std::set<ip_address_t> get_local_ips(const std::set<ip_address_t> &filter,
156156
local_ip_filter_t filter_type) {
157157
std::set<ip_address_t> all_ips;
158-
std::set<ip_address_t> filtered_ips;
159-
158+
#ifdef _WIN32
159+
// NOTE: We used to use hostname_to_ips for all OSes, we stopped using it because
160+
// DNS resolution could be slow. Now we only use it for Windows because nobody's
161+
// fixed the Windows implementation to get the network interfaces more sensibly.
160162
try {
161163
all_ips = hostname_to_ips(str_gethostname());
162164
} catch (const host_lookup_exc_t &ex) {
163165
// Continue on, this probably means there's no DNS entry for this host
164166
}
165167

166-
#ifdef _WIN32
167168
// TODO WINDOWS: is this enough?
168169
all_ips.emplace("127.0.0.1");
169170
#else
170-
// Ignore loopback addresses - those will be returned by getifaddrs, and
171-
// getaddrinfo is not so trustworthy.
172-
// See https://github.com/rethinkdb/rethinkdb/issues/2405
173-
for (auto it = all_ips.begin(); it != all_ips.end();) {
174-
auto curr = it++;
175-
if (!curr->is_loopback()) {
176-
all_ips.erase(curr);
177-
}
178-
}
179-
180171
struct ifaddrs *addrs;
181172
int res = getifaddrs(&addrs);
182173
guarantee_err(res == 0,
@@ -195,6 +186,7 @@ std::set<ip_address_t> get_local_ips(const std::set<ip_address_t> &filter,
195186
freeifaddrs(addrs);
196187
#endif
197188

189+
std::set<ip_address_t> filtered_ips;
198190
// Remove any addresses that don't fit the filter
199191
for (auto const &ip : all_ips) {
200192
if (filter_type == local_ip_filter_t::ALL ||

src/clustering/administration/main/serve.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ peer_address_set_t look_up_peers_addresses(const std::vector<host_and_port_t> &n
5555
}
5656

5757
std::string service_address_ports_t::get_addresses_string(
58-
std::set<ip_address_t> actual_addresses) const {
58+
std::set<ip_address_t> actual_addresses) {
5959

6060
bool first = true;
6161
std::string result;
@@ -74,8 +74,7 @@ std::string service_address_ports_t::get_addresses_string(
7474
return result;
7575
}
7676

77-
bool service_address_ports_t::is_bind_all(
78-
std::set<ip_address_t> addresses) const {
77+
bool service_address_ports_t::is_bind_all(const std::set<ip_address_t> &addresses) {
7978
// If the set is empty, it means we're listening on all addresses.
8079
return addresses.empty();
8180
}
@@ -611,7 +610,7 @@ bool do_serve(io_backender_t *io_backender,
611610
serve_info.ports.local_addresses_http.size() == 1 ? "" : "es",
612611
addresses_string.c_str());
613612

614-
if (!serve_info.ports.is_bind_all(serve_info.ports.local_addresses)) {
613+
if (!service_address_ports_t::is_bind_all(serve_info.ports.local_addresses)) {
615614
if(serve_info.config_file) {
616615
logNTC("To fully expose RethinkDB on the network, bind to "
617616
"all addresses by adding `bind=all' to the config "

src/clustering/administration/main/serve.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ struct service_address_ports_t {
8080
sanitize_port(reql_port, "reql_port", port_offset);
8181
}
8282

83-
std::string get_addresses_string(
84-
std::set<ip_address_t> actual_addresses) const;
83+
static std::string get_addresses_string(std::set<ip_address_t> actual_addresses);
8584

86-
bool is_bind_all(std::set<ip_address_t> addresses) const;
85+
static bool is_bind_all(const std::set<ip_address_t> &addresses);
8786

8887
std::set<ip_address_t> local_addresses;
8988
std::set<ip_address_t> local_addresses_cluster;

0 commit comments

Comments
 (0)