Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CXXCBC-336: Do not fallback to 8.8.8.8, if we cannot obtain system DNS server #533

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@
/cmake-build-report.tar.gz
/.idea/vcs.xml
/.idea/workspace.xml
/.idea/editor.xml
/.idea/sonarlint
/.cache
/.vs
Expand Down
4 changes: 4 additions & 0 deletions core/io/dns_client.cxx
Expand Up @@ -285,6 +285,10 @@ dns_client::query_srv(const std::string& name,
const dns_config& config,
utils::movable_function<void(dns_srv_response&&)>&& handler)
{
if (config.nameserver().empty()) {
return handler({ {} });
}

std::error_code ec;
auto address = asio::ip::make_address(config.nameserver(), ec);
if (ec) {
Expand Down
19 changes: 15 additions & 4 deletions core/io/dns_config.cxx
Expand Up @@ -53,6 +53,7 @@ load_resolv_conf()
fixed_info = (FIXED_INFO*)malloc(sizeof(FIXED_INFO));
if (fixed_info == NULL) {
CB_LOG_WARNING("Error allocating memory needed to call GetNetworkParams");
return {};
}
buf = sizeof(FIXED_INFO);

Expand All @@ -63,6 +64,7 @@ load_resolv_conf()
fixed_info = (FIXED_INFO*)malloc(buf);
if (fixed_info == NULL) {
CB_LOG_WARNING("Error allocating memory needed to call GetNetworkParams");
return {};
}
}

Expand All @@ -86,10 +88,12 @@ load_resolv_conf()
}
} else {
CB_LOG_WARNING("GetNetworkParams failed with error: {}", ret);
return {};
}

if (fixed_info)
if (fixed_info) {
free(fixed_info);
}

if (dns_servers.size() > 0) {
CB_LOG_DEBUG(
Expand Down Expand Up @@ -153,10 +157,17 @@ dns_config::system_config()
std::error_code ec;
asio::ip::make_address(nameserver, ec);
if (ec) {
CB_LOG_DEBUG("Unable to parse \"{}\" as a network address, fall back to \"{}\"", nameserver, default_nameserver);
nameserver = default_nameserver;
std::string extra_info{};
#ifndef _WIN32
extra_info = fmt::format(" in \"{}\"", default_resolv_conf_path);
#endif
CB_LOG_WARNING("System DNS detection failed: unable to parse \"{}\" as a network address{}. DNS-SRV will not work "
"unless nameserver is specified explicitly in the options.",
nameserver,
extra_info);
} else {
instance.nameserver_ = nameserver;
}
instance.nameserver_ = nameserver;
});

return instance;
Expand Down
2 changes: 1 addition & 1 deletion core/io/dns_config.hxx
Expand Up @@ -40,7 +40,7 @@ class dns_config
[[nodiscard]] std::chrono::milliseconds timeout() const;

private:
std::string nameserver_{ default_nameserver };
std::string nameserver_{};
avsej marked this conversation as resolved.
Show resolved Hide resolved
std::uint16_t port_{ default_port };
std::chrono::milliseconds timeout_{ timeout_defaults::dns_srv_timeout };
};
Expand Down