inet_address/init: Make ipv6 default enabled

Makes lookup find any (incl ipv6 numeric) address.
Init will look at enable_ipv6 and use explcit ipv4 family lookup if not
enabled.
This commit is contained in:
Calle Wilund
2019-04-02 13:02:09 +00:00
parent 1f5e1d22bf
commit 3cfb79e0ff
3 changed files with 11 additions and 8 deletions

View File

@@ -37,6 +37,7 @@
*/
#include <seastar/net/inet_address.hh>
#include <seastar/net/dns.hh>
#include <seastar/core/print.hh>
#include <seastar/core/future.hh>
#include "inet_address.hh"
@@ -44,7 +45,7 @@
using namespace seastar;
future<gms::inet_address> gms::inet_address::lookup(sstring name, opt_family family) {
return seastar::net::inet_address::find(name, family.value_or(net::inet_address::family::INET)).then([](seastar::net::inet_address&& a) {
return seastar::net::dns::resolve_name(name, family).then([](seastar::net::inet_address&& a) {
return make_ready_future<gms::inet_address>(a);
});
}

View File

@@ -65,7 +65,8 @@ void init_ms_fd_gossiper(sharded<gms::gossiper>& gossiper
, double phi
, bool sltba)
{
const auto listen = gms::inet_address::lookup(listen_address_in).get0();
auto family = cfg.enable_ipv6_dns_lookup() ? std::nullopt : std::make_optional(net::inet_address::family::INET);
const auto listen = gms::inet_address::lookup(listen_address_in, family).get0();
using encrypt_what = netw::messaging_service::encrypt_what;
using compress_what = netw::messaging_service::compress_what;
@@ -138,7 +139,7 @@ void init_ms_fd_gossiper(sharded<gms::gossiper>& gossiper
while (begin < seeds_str.length() && begin != (next=seeds_str.find(",",begin))) {
auto seed = boost::trim_copy(seeds_str.substr(begin,next-begin));
try {
seeds.emplace(gms::inet_address::lookup(seed).get0());
seeds.emplace(gms::inet_address::lookup(seed, family).get0());
} catch (...) {
startlog.error("Bad configuration: invalid value in 'seeds': '{}': {}", seed, std::current_exception());
throw bad_configuration_error();

11
main.cc
View File

@@ -509,6 +509,7 @@ int main(int ac, char** av) {
uint16_t api_port = cfg->api_port();
ctx.api_dir = cfg->api_ui_dir();
ctx.api_doc = cfg->api_doc_dir();
auto family = cfg->enable_ipv6_dns_lookup() ? std::nullopt : std::make_optional(net::inet_address::family::INET);
sstring listen_address = cfg->listen_address();
sstring rpc_address = cfg->rpc_address();
sstring api_address = cfg->api_address() != "" ? cfg->api_address() : rpc_address;
@@ -517,7 +518,7 @@ int main(int ac, char** av) {
std::optional<std::vector<sstring>> hinted_handoff_enabled = parse_hinted_handoff_enabled(cfg->hinted_handoff_enabled());
auto prom_addr = [&] {
try {
return seastar::net::dns::get_host_by_name(cfg->prometheus_address()).get0();
return seastar::net::dns::get_host_by_name(cfg->prometheus_address(), family).get0();
} catch (...) {
std::throw_with_nested(std::runtime_error(fmt::format("Unable to resolve prometheus_address {}", cfg->prometheus_address())));
}
@@ -543,14 +544,14 @@ int main(int ac, char** av) {
}
if (!broadcast_address.empty()) {
try {
utils::fb_utilities::set_broadcast_address(gms::inet_address::lookup(broadcast_address).get0());
utils::fb_utilities::set_broadcast_address(gms::inet_address::lookup(broadcast_address, family).get0());
} catch (...) {
startlog.error("Bad configuration: invalid 'broadcast_address': {}: {}", broadcast_address, std::current_exception());
throw bad_configuration_error();
}
} else if (!listen_address.empty()) {
try {
utils::fb_utilities::set_broadcast_address(gms::inet_address::lookup(listen_address).get0());
utils::fb_utilities::set_broadcast_address(gms::inet_address::lookup(listen_address, family).get0());
} catch (...) {
startlog.error("Bad configuration: invalid 'listen_address': {}: {}", listen_address, std::current_exception());
throw bad_configuration_error();
@@ -561,13 +562,13 @@ int main(int ac, char** av) {
}
if (!broadcast_rpc_address.empty()) {
utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address::lookup(broadcast_rpc_address).get0());
utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address::lookup(broadcast_rpc_address, family).get0());
} else {
if (rpc_address == "0.0.0.0") {
startlog.error("If rpc_address is set to a wildcard address {}, then you must set broadcast_rpc_address to a value other than {}", rpc_address, rpc_address);
throw bad_configuration_error();
}
utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address::lookup(rpc_address).get0());
utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address::lookup(rpc_address, family).get0());
}
// TODO: lib.