Skip to content

Commit b589bc8

Browse files
authored
Merge pull request #15842 from rgacogne/ddist20-backport-15823
dnsdist-2.0.x: Backport 15823 - Bring back listening on multiple web server addresses
2 parents aea63db + 94badcd commit b589bc8

File tree

12 files changed

+44
-38
lines changed

12 files changed

+44
-38
lines changed

pdns/dnsdistdist/dnsdist-configuration-yaml.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -803,15 +803,15 @@ static void loadBinds(const ::rust::Vec<dnsdist::rust::settings::BindConfigurati
803803

804804
static void loadWebServer(const dnsdist::rust::settings::WebserverConfiguration& webConfig)
805805
{
806-
ComboAddress local;
807-
try {
808-
local = ComboAddress{std::string(webConfig.listen_address)};
809-
}
810-
catch (const PDNSException& e) {
811-
throw std::runtime_error(std::string("Error parsing the bind address for the webserver: ") + e.reason);
812-
}
813-
dnsdist::configuration::updateRuntimeConfiguration([local, &webConfig](dnsdist::configuration::RuntimeConfiguration& config) {
814-
config.d_webServerAddress = local;
806+
dnsdist::configuration::updateRuntimeConfiguration([&webConfig](dnsdist::configuration::RuntimeConfiguration& config) {
807+
for (const auto& address : webConfig.listen_addresses) {
808+
try {
809+
config.d_webServerAddresses.emplace(ComboAddress(std::string(address)));
810+
}
811+
catch (const PDNSException& exp) {
812+
throw std::runtime_error(std::string("Error parsing bind address for the webserver: ") + exp.reason);
813+
}
814+
}
815815
if (!webConfig.password.empty()) {
816816
auto holder = std::make_shared<CredentialsHolder>(std::string(webConfig.password), webConfig.hash_plaintext_credentials);
817817
if (!holder->wasHashed() && holder->isHashingAvailable()) {
@@ -1088,7 +1088,7 @@ bool loadConfigurationFromFile(const std::string& fileName, [[maybe_unused]] boo
10881088
}
10891089
#endif /* DISABLE_CARBON */
10901090

1091-
if (!globalConfig.webserver.listen_address.empty()) {
1091+
if (!globalConfig.webserver.listen_addresses.empty()) {
10921092
const auto& webConfig = globalConfig.webserver;
10931093
loadWebServer(webConfig);
10941094
}

pdns/dnsdistdist/dnsdist-configuration.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ struct RuntimeConfiguration
127127
NetmaskGroup d_proxyProtocolACL;
128128
NetmaskGroup d_consoleACL;
129129
NetmaskGroup d_webServerACL;
130-
std::optional<ComboAddress> d_webServerAddress{std::nullopt};
130+
std::set<ComboAddress> d_webServerAddresses;
131131
dnsdist::QueryCount::Configuration d_queryCountConfig;
132132
ComboAddress d_consoleServerAddress{"127.0.0.1:5199"};
133133
std::string d_consoleKey;

pdns/dnsdistdist/dnsdist-lua.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,15 +1069,15 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
10691069
}
10701070

10711071
dnsdist::configuration::updateRuntimeConfiguration([local](dnsdist::configuration::RuntimeConfiguration& config) {
1072-
config.d_webServerAddress = local;
1072+
config.d_webServerAddresses.emplace(local);
10731073
});
10741074

10751075
if (dnsdist::configuration::isImmutableConfigurationDone()) {
10761076
try {
10771077
auto sock = Socket(local.sin4.sin_family, SOCK_STREAM, 0);
10781078
sock.bind(local, true);
10791079
sock.listen(5);
1080-
thread thr(dnsdist::webserver::WebserverThread, std::move(sock));
1080+
thread thr(dnsdist::webserver::WebserverThread, local, std::move(sock));
10811081
thr.detach();
10821082
}
10831083
catch (const std::exception& e) {

pdns/dnsdistdist/dnsdist-settings-definitions.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,10 @@ key_value_stores:
407407

408408
webserver:
409409
parameters:
410-
- name: "listen_address"
411-
type: "String"
410+
- name: "listen_addresses"
411+
type: "Vec<String>"
412412
default: ""
413-
description: "IP address and port to listen on"
413+
description: "IP addresses and ports to listen on"
414414
- name: "password"
415415
type: "String"
416416
default: ""

pdns/dnsdistdist/dnsdist-web.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,23 +1914,22 @@ void setMaxConcurrentConnections(size_t max)
19141914
s_connManager.setMaxConcurrentConnections(max);
19151915
}
19161916

1917-
void WebserverThread(Socket sock)
1917+
void WebserverThread(ComboAddress listeningAddress, Socket sock)
19181918
{
19191919
setThreadName("dnsdist/webserv");
19201920
// coverity[auto_causes_copy]
1921-
const auto local = *dnsdist::configuration::getCurrentRuntimeConfiguration().d_webServerAddress;
1922-
infolog("Webserver launched on %s", local.toStringWithPort());
1921+
infolog("Webserver launched on %s", listeningAddress.toStringWithPort());
19231922

19241923
{
19251924
const auto& config = dnsdist::configuration::getCurrentRuntimeConfiguration();
19261925
if (!config.d_webPassword && config.d_dashboardRequiresAuthentication) {
1927-
warnlog("Webserver launched on %s without a password set!", local.toStringWithPort());
1926+
warnlog("Webserver launched on %s without a password set!", listeningAddress.toStringWithPort());
19281927
}
19291928
}
19301929

19311930
for (;;) {
19321931
try {
1933-
ComboAddress remote(local);
1932+
ComboAddress remote(listeningAddress);
19341933
int fileDesc = SAccept(sock.getHandle(), remote);
19351934

19361935
if (!isClientAllowedByACL(remote)) {

pdns/dnsdistdist/dnsdist-web.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace dnsdist::webserver
88
{
9-
void WebserverThread(Socket sock);
9+
void WebserverThread(ComboAddress listeningAddress, Socket sock);
1010
void setMaxConcurrentConnections(size_t max);
1111
void registerBuiltInWebHandlers();
1212
void clearWebHandlers();

pdns/dnsdistdist/dnsdist.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,7 +3305,7 @@ static void startFrontends()
33053305
struct ListeningSockets
33063306
{
33073307
Socket d_consoleSocket{-1};
3308-
Socket d_webServerSocket{-1};
3308+
std::vector<std::pair<ComboAddress, Socket>> d_webServerSockets;
33093309
};
33103310

33113311
static ListeningSockets initListeningSockets()
@@ -3325,12 +3325,12 @@ static ListeningSockets initListeningSockets()
33253325
}
33263326
}
33273327

3328-
if (currentConfig.d_webServerAddress) {
3329-
const auto& local = *currentConfig.d_webServerAddress;
3328+
for (const auto& local : currentConfig.d_webServerAddresses) {
33303329
try {
3331-
result.d_webServerSocket = Socket(local.sin4.sin_family, SOCK_STREAM, 0);
3332-
result.d_webServerSocket.bind(local, true);
3333-
result.d_webServerSocket.listen(5);
3330+
auto webServerSocket = Socket(local.sin4.sin_family, SOCK_STREAM, 0);
3331+
webServerSocket.bind(local, true);
3332+
webServerSocket.listen(5);
3333+
result.d_webServerSockets.emplace_back(local, std::move(webServerSocket));
33343334
}
33353335
catch (const std::exception& exp) {
33363336
errlog("Unable to bind to web server socket on %s: %s", local.toStringWithPort(), exp.what());
@@ -3603,8 +3603,8 @@ int main(int argc, char** argv)
36033603
std::thread consoleControlThread(dnsdist::console::controlThread, std::move(listeningSockets.d_consoleSocket));
36043604
consoleControlThread.detach();
36053605
}
3606-
if (dnsdist::configuration::getCurrentRuntimeConfiguration().d_webServerAddress) {
3607-
std::thread webServerThread(dnsdist::webserver::WebserverThread, std::move(listeningSockets.d_webServerSocket));
3606+
for (auto& [listeningAddress, socket] : listeningSockets.d_webServerSockets) {
3607+
std::thread webServerThread(dnsdist::webserver::WebserverThread, listeningAddress, std::move(socket));
36083608
webServerThread.detach();
36093609
}
36103610

regression-tests.dnsdist/test_API.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,12 @@ def testServerDownNoLatencyLocalhost(self):
434434
class TestAPIWritable(APITestsBase):
435435
__test__ = True
436436
_APIWriteDir = '/tmp'
437-
_config_params = ['_testServerPort', '_webServerPort', '_webServerBasicAuthPasswordHashed', '_webServerAPIKeyHashed', '_APIWriteDir']
437+
_config_params = ['_testServerPort', '_webServerPort', '_webServerPort', '_webServerBasicAuthPasswordHashed', '_webServerAPIKeyHashed', '_APIWriteDir']
438438
_config_template = """
439439
setACL({"127.0.0.1/32", "::1/128"})
440-
newServer{address="127.0.0.1:%s"}
441-
webserver("127.0.0.1:%s")
440+
newServer{address="127.0.0.1:%d"}
441+
webserver("127.0.0.1:%d")
442+
webserver("127.0.0.2:%d")
442443
setWebserverConfig({password="%s", apiKey="%s"})
443444
setAPIWritable(true, "%s")
444445
"""

regression-tests.dnsdist/test_OutgoingDOH.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ class TestOutgoingDOHOpenSSLYaml(DNSDistTest, OutgoingDOHTests):
370370
health_checks:
371371
mode: "UP"
372372
webserver:
373-
listen_address: "127.0.0.1:%d"
373+
listen_addresses:
374+
- "127.0.0.1:%d"
374375
password: "%s"
375376
api_key: "%s"
376377
acl:

regression-tests.dnsdist/test_OutgoingTLS.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ class TestOutgoingTLSOpenSSLYaml(DNSDistTest, OutgoingTLSTests):
184184
ca_store: "ca.pem"
185185
subject_name: "powerdns.com"
186186
webserver:
187-
listen_address: "127.0.0.1:%d"
187+
listen_addresses:
188+
- "127.0.0.1:%d"
188189
password: "%s"
189190
api_key: "%s"
190191
acl:

0 commit comments

Comments
 (0)