From d617b22cc6bbd7bc7a47d375197b60b9dcb781be Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 7 Mar 2016 15:20:12 +0100 Subject: [PATCH] dnsdist: Per-carbon server hostnames We used the last specified `ourname` for all servers. We still use the first specified interval for all servers for now. --- pdns/dnsdist-carbon.cc | 36 +++++++++++++++++++++--------------- pdns/dnsdist-lua.cc | 10 ++-------- pdns/dnsdist.hh | 6 +++--- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index 1702c61097..4741d59654 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -9,7 +9,7 @@ #undef L #include "dnsdist.hh" -GlobalStateHolder g_carbon; +GlobalStateHolder > g_carbon; static time_t s_start=time(0); uint64_t uptimeOfProcess(const std::string& str) { @@ -21,24 +21,30 @@ try { auto localCarbon = g_carbon.getLocal(); for(int numloops=0;;++numloops) { - if(localCarbon->servers.empty()) { + if(localCarbon->empty()) { sleep(1); continue; } - if(numloops) - sleep(localCarbon->interval); - - string hostname=localCarbon->ourname; - if(hostname.empty()) { - char tmp[80]; - memset(tmp, 0, sizeof(tmp)); - gethostname(tmp, sizeof(tmp)); - char *p = strchr(tmp, '.'); - if(p) *p=0; - hostname=tmp; - boost::replace_all(hostname, ".", "_"); + /* this is wrong, we use the interval of the first server + for every single one of them */ + if(numloops) { + const unsigned int interval = localCarbon->at(0).interval; + sleep(interval); } - for (auto server : localCarbon->servers) { + + for (const auto& conf : *localCarbon) { + const auto& server = conf.server; + std::string hostname = conf.ourname; + if(hostname.empty()) { + char tmp[80]; + memset(tmp, 0, sizeof(tmp)); + gethostname(tmp, sizeof(tmp)); + char *p = strchr(tmp, '.'); + if(p) *p=0; + hostname=tmp; + boost::replace_all(hostname, ".", "_"); + } + try { Socket s(server.sin4.sin_family, SOCK_STREAM); s.setNonBlocking(); diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 6777083377..9e8f29a26a 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -982,16 +982,10 @@ vector> setupLua(bool client, const std::string& confi g_lua.registerFunction("check",(bool (SuffixMatchNode::*)(const DNSName&) const) &SuffixMatchNode::check); g_lua.writeFunction("carbonServer", [](const std::string& address, boost::optional ourName, - boost::optional interval) { + boost::optional interval) { setLuaSideEffect(); auto ours = g_carbon.getCopy(); - ours.servers.push_back(ComboAddress(address, 2003)); - if(ourName) - ours.ourname=*ourName; - if(interval) - ours.interval=*interval; - if(!ours.interval) - ours.interval=1; + ours.push_back({ComboAddress(address, 2003), ourName ? *ourName : "", interval ? *interval : 30}); g_carbon.setState(ours); }); diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index bddbfb2295..5b7dc4660a 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -435,9 +435,9 @@ void removeServerFromPool(pools_t& pools, const string& poolName, std::shared_pt struct CarbonConfig { - vector servers; + ComboAddress server; std::string ourname; - unsigned int interval{30}; + unsigned int interval; }; enum ednsHeaderFlags { @@ -445,7 +445,7 @@ enum ednsHeaderFlags { EDNS_HEADER_FLAG_DO = 32768 }; -extern GlobalStateHolder g_carbon; +extern GlobalStateHolder > g_carbon; extern GlobalStateHolder g_policy; extern GlobalStateHolder g_dstates; extern GlobalStateHolder g_pools; -- 2.47.2