init: Use the "prefer_ipv6" options available for rpc/listen address/interface
Fixes #4751 Adds using a preferred address family to dns name lookups related to listen address and rpc address, adhering to the respective "prefer" options. API, prometheus and broadcast address are all considered to be covered by the "listen_interface_prefer_ipv6" option. Note: scylla does not yet support actual interface binding, but these options should apply equally to address name parameters. Setting a "prefer_ipv6" option automtially enables ipv6 dns family query.
This commit is contained in:
5
init.cc
5
init.cc
@@ -65,7 +65,8 @@ void init_ms_fd_gossiper(sharded<gms::gossiper>& gossiper
|
||||
, double phi
|
||||
, bool sltba)
|
||||
{
|
||||
auto family = cfg.enable_ipv6_dns_lookup() ? std::nullopt : std::make_optional(net::inet_address::family::INET);
|
||||
auto preferred = cfg.listen_interface_prefer_ipv6() ? std::make_optional(net::inet_address::family::INET6) : std::nullopt;
|
||||
auto family = cfg.enable_ipv6_dns_lookup() || preferred ? 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;
|
||||
@@ -139,7 +140,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, family).get0());
|
||||
seeds.emplace(gms::inet_address::lookup(seed, family, preferred).get0());
|
||||
} catch (...) {
|
||||
startlog.error("Bad configuration: invalid value in 'seeds': '{}': {}", seed, std::current_exception());
|
||||
throw bad_configuration_error();
|
||||
|
||||
20
main.cc
20
main.cc
@@ -540,7 +540,8 @@ 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);
|
||||
auto preferred = cfg->listen_interface_prefer_ipv6() ? std::make_optional(net::inet_address::family::INET6) : std::nullopt;
|
||||
auto family = cfg->enable_ipv6_dns_lookup() || preferred ? 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;
|
||||
@@ -549,7 +550,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(), family).get0();
|
||||
return gms::inet_address::lookup(cfg->prometheus_address(), family, preferred).get0();
|
||||
} catch (...) {
|
||||
std::throw_with_nested(std::runtime_error(fmt::format("Unable to resolve prometheus_address {}", cfg->prometheus_address())));
|
||||
}
|
||||
@@ -567,7 +568,7 @@ int main(int ac, char** av) {
|
||||
}));
|
||||
prometheus::start(prometheus_server, pctx);
|
||||
with_scheduling_group(maintenance_scheduling_group, [&] {
|
||||
return prometheus_server.listen(socket_address{prom_addr.addr_list.front(), pport}).handle_exception([pport, &cfg] (auto ep) {
|
||||
return prometheus_server.listen(socket_address{prom_addr, pport}).handle_exception([pport, &cfg] (auto ep) {
|
||||
startlog.error("Could not start Prometheus API server on {}:{}: {}", cfg->prometheus_address(), pport, ep);
|
||||
return make_exception_future<>(ep);
|
||||
});
|
||||
@@ -575,14 +576,14 @@ int main(int ac, char** av) {
|
||||
}
|
||||
if (!broadcast_address.empty()) {
|
||||
try {
|
||||
utils::fb_utilities::set_broadcast_address(gms::inet_address::lookup(broadcast_address, family).get0());
|
||||
utils::fb_utilities::set_broadcast_address(gms::inet_address::lookup(broadcast_address, family, preferred).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, family).get0());
|
||||
utils::fb_utilities::set_broadcast_address(gms::inet_address::lookup(listen_address, family, preferred).get0());
|
||||
} catch (...) {
|
||||
startlog.error("Bad configuration: invalid 'listen_address': {}: {}", listen_address, std::current_exception());
|
||||
throw bad_configuration_error();
|
||||
@@ -593,13 +594,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, family).get0());
|
||||
utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address::lookup(broadcast_rpc_address, family, preferred).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, family).get0());
|
||||
utils::fb_utilities::set_broadcast_rpc_address(gms::inet_address::lookup(rpc_address, family, preferred).get0());
|
||||
}
|
||||
|
||||
// TODO: lib.
|
||||
@@ -644,15 +645,14 @@ int main(int ac, char** av) {
|
||||
// #293 - do not stop anything
|
||||
// engine().at_exit([] { return i_endpoint_snitch::stop_snitch(); });
|
||||
supervisor::notify("determining DNS name");
|
||||
auto e = [&] {
|
||||
auto ip = [&] {
|
||||
try {
|
||||
return seastar::net::dns::get_host_by_name(api_address).get0();
|
||||
return gms::inet_address::lookup(api_address, family, preferred).get0();
|
||||
} catch (...) {
|
||||
std::throw_with_nested(std::runtime_error(fmt::format("Unable to resolve api_address {}", api_address)));
|
||||
}
|
||||
}();
|
||||
supervisor::notify("starting API server");
|
||||
auto ip = e.addr_list.front();
|
||||
ctx.http_server.start("API").get();
|
||||
api::set_server_init(ctx).get();
|
||||
with_scheduling_group(maintenance_scheduling_group, [&] {
|
||||
|
||||
@@ -68,7 +68,6 @@
|
||||
#include "db/commitlog/commitlog.hh"
|
||||
#include "db/hints/manager.hh"
|
||||
#include <seastar/net/tls.hh>
|
||||
#include <seastar/net/dns.hh>
|
||||
#include "utils/exceptions.hh"
|
||||
#include "message/messaging_service.hh"
|
||||
#include "supervisor.hh"
|
||||
@@ -2206,11 +2205,13 @@ future<> storage_service::start_rpc_server() {
|
||||
auto& cfg = ss._db.local().get_config();
|
||||
auto port = cfg.rpc_port();
|
||||
auto addr = cfg.rpc_address();
|
||||
auto preferred = cfg.rpc_interface_prefer_ipv6() ? std::make_optional(net::inet_address::family::INET6) : std::nullopt;
|
||||
auto family = cfg.enable_ipv6_dns_lookup() || preferred ? std::nullopt : std::make_optional(net::inet_address::family::INET);
|
||||
auto keepalive = cfg.rpc_keepalive();
|
||||
thrift_server_config tsc;
|
||||
tsc.timeout_config = make_timeout_config(cfg);
|
||||
tsc.max_request_size = cfg.thrift_max_message_length_in_mb() * (uint64_t(1) << 20);
|
||||
return seastar::net::dns::resolve_name(addr).then([&ss, tserver, addr, port, keepalive, tsc] (seastar::net::inet_address ip) {
|
||||
return gms::inet_address::lookup(addr, family, preferred).then([&ss, tserver, addr, port, keepalive, tsc] (gms::inet_address ip) {
|
||||
return tserver->start(std::ref(ss._db), std::ref(cql3::get_query_processor()), std::ref(ss._auth_service), tsc).then([tserver, port, addr, ip, keepalive] {
|
||||
// #293 - do not stop anything
|
||||
//engine().at_exit([tserver] {
|
||||
@@ -2258,6 +2259,8 @@ future<> storage_service::start_native_transport() {
|
||||
|
||||
auto& cfg = ss._db.local().get_config();
|
||||
auto addr = cfg.rpc_address();
|
||||
auto preferred = cfg.rpc_interface_prefer_ipv6() ? std::make_optional(net::inet_address::family::INET6) : std::nullopt;
|
||||
auto family = cfg.enable_ipv6_dns_lookup() || preferred ? std::nullopt : std::make_optional(net::inet_address::family::INET);
|
||||
auto ceo = cfg.client_encryption_options();
|
||||
auto keepalive = cfg.rpc_keepalive();
|
||||
cql_transport::cql_server_config cql_server_config;
|
||||
@@ -2265,7 +2268,7 @@ future<> storage_service::start_native_transport() {
|
||||
cql_server_config.max_request_size = ss._db.local().get_available_memory() / 10;
|
||||
cql_server_config.allow_shard_aware_drivers = cfg.enable_shard_aware_drivers();
|
||||
cql_transport::cql_load_balance lb = cql_transport::parse_load_balance(cfg.load_balance());
|
||||
return seastar::net::dns::resolve_name(addr).then([&ss, cserver, addr, &cfg, lb, keepalive, ceo = std::move(ceo), cql_server_config] (seastar::net::inet_address ip) {
|
||||
return gms::inet_address::lookup(addr, family, preferred).then([&ss, cserver, addr, &cfg, lb, keepalive, ceo = std::move(ceo), cql_server_config] (seastar::net::inet_address ip) {
|
||||
return cserver->start(std::ref(service::get_storage_proxy()), std::ref(cql3::get_query_processor()), lb, std::ref(ss._auth_service), cql_server_config).then([cserver, &cfg, addr, ip, ceo, keepalive]() {
|
||||
// #293 - do not stop anything
|
||||
//engine().at_exit([cserver] {
|
||||
|
||||
Reference in New Issue
Block a user