From 8592b46edd2ff2677c09fd37bc7ab3aaf3d69c33 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 11 Oct 2019 16:12:54 +0200 Subject: [PATCH] dnsdist: Fix indentation in newServer() --- pdns/dnsdist-lua.cc | 420 ++++++++++++++++++++++---------------------- 1 file changed, 210 insertions(+), 210 deletions(-) diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 275e6859b..798abbf09 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -200,63 +200,63 @@ void setupLuaConfig(bool client) size_t numberOfSockets = 1; std::set cpus; - if(vars.count("source")) { - /* handle source in the following forms: - - v4 address ("192.0.2.1") - - v6 address ("2001:DB8::1") - - interface name ("eth0") - - v4 address and interface name ("192.0.2.1@eth0") - - v6 address and interface name ("2001:DB8::1@eth0") - */ - const string source = boost::get(vars["source"]); - bool parsed = false; - std::string::size_type pos = source.find("@"); - if (pos == std::string::npos) { - /* no '@', try to parse that as a valid v4/v6 address */ - try { - sourceAddr = ComboAddress(source); - parsed = true; - } - catch(...) - { - } - } - - if (parsed == false) - { - /* try to parse as interface name, or v4/v6@itf */ - sourceItfName = source.substr(pos == std::string::npos ? 0 : pos + 1); - unsigned int itfIdx = if_nametoindex(sourceItfName.c_str()); - - if (itfIdx != 0) { - if (pos == 0 || pos == std::string::npos) { - /* "eth0" or "@eth0" */ - sourceItf = itfIdx; - } - else { - /* "192.0.2.1@eth0" */ - sourceAddr = ComboAddress(source.substr(0, pos)); - sourceItf = itfIdx; - } + if(vars.count("source")) { + /* handle source in the following forms: + - v4 address ("192.0.2.1") + - v6 address ("2001:DB8::1") + - interface name ("eth0") + - v4 address and interface name ("192.0.2.1@eth0") + - v6 address and interface name ("2001:DB8::1@eth0") + */ + const string source = boost::get(vars["source"]); + bool parsed = false; + std::string::size_type pos = source.find("@"); + if (pos == std::string::npos) { + /* no '@', try to parse that as a valid v4/v6 address */ + try { + sourceAddr = ComboAddress(source); + parsed = true; + } + catch(...) + { + } + } + + if (parsed == false) + { + /* try to parse as interface name, or v4/v6@itf */ + sourceItfName = source.substr(pos == std::string::npos ? 0 : pos + 1); + unsigned int itfIdx = if_nametoindex(sourceItfName.c_str()); + + if (itfIdx != 0) { + if (pos == 0 || pos == std::string::npos) { + /* "eth0" or "@eth0" */ + sourceItf = itfIdx; + } + else { + /* "192.0.2.1@eth0" */ + sourceAddr = ComboAddress(source.substr(0, pos)); + sourceItf = itfIdx; + } #ifdef SO_BINDTODEVICE - /* we need to retain CAP_NET_RAW to be able to set SO_BINDTODEVICE in the health checks */ - g_capabilitiesToRetain.insert("CAP_NET_RAW"); + /* we need to retain CAP_NET_RAW to be able to set SO_BINDTODEVICE in the health checks */ + g_capabilitiesToRetain.insert("CAP_NET_RAW"); #endif - } - else - { - warnlog("Dismissing source %s because '%s' is not a valid interface name", source, sourceItfName); - } - } - } - - if (vars.count("sockets")) { - numberOfSockets = std::stoul(boost::get(vars["sockets"])); - if (numberOfSockets == 0) { - warnlog("Dismissing invalid number of sockets '%s', using 1 instead", boost::get(vars["sockets"])); - numberOfSockets = 1; - } - } + } + else + { + warnlog("Dismissing source %s because '%s' is not a valid interface name", source, sourceItfName); + } + } + } + + if (vars.count("sockets")) { + numberOfSockets = std::stoul(boost::get(vars["sockets"])); + if (numberOfSockets == 0) { + warnlog("Dismissing invalid number of sockets '%s', using 1 instead", boost::get(vars["sockets"])); + numberOfSockets = 1; + } + } if(client) { // do not construct DownstreamState now, it would try binding sockets. @@ -264,183 +264,183 @@ void setupLuaConfig(bool client) } ret=std::make_shared(serverAddr, sourceAddr, sourceItf, sourceItfName, numberOfSockets); - if(vars.count("qps")) { - int qpsVal=std::stoi(boost::get(vars["qps"])); - ret->qps=QPSLimiter(qpsVal, qpsVal); - } - - if(vars.count("order")) { - ret->order=std::stoi(boost::get(vars["order"])); - } - - if(vars.count("weight")) { - try { - int weightVal=std::stoi(boost::get(vars["weight"])); - - if(weightVal < 1) { - errlog("Error creating new server: downstream weight value must be greater than 0."); - return ret; - } - - ret->setWeight(weightVal); - } - catch(std::exception& e) { - // std::stoi will throw an exception if the string isn't in a value int range - errlog("Error creating new server: downstream weight value must be between %s and %s", 1, std::numeric_limits::max()); - return ret; - } - } - - if(vars.count("retries")) { - ret->retries=std::stoi(boost::get(vars["retries"])); - } - - if(vars.count("checkInterval")) { - ret->checkInterval=static_cast(std::stoul(boost::get(vars["checkInterval"]))); - } - - if(vars.count("tcpConnectTimeout")) { - ret->tcpConnectTimeout=std::stoi(boost::get(vars["tcpConnectTimeout"])); - } - - if(vars.count("tcpSendTimeout")) { - ret->tcpSendTimeout=std::stoi(boost::get(vars["tcpSendTimeout"])); - } - - if(vars.count("tcpRecvTimeout")) { - ret->tcpRecvTimeout=std::stoi(boost::get(vars["tcpRecvTimeout"])); - } - - if(vars.count("tcpFastOpen")) { - bool fastOpen = boost::get(vars["tcpFastOpen"]); - if (fastOpen) { + if(vars.count("qps")) { + int qpsVal=std::stoi(boost::get(vars["qps"])); + ret->qps=QPSLimiter(qpsVal, qpsVal); + } + + if(vars.count("order")) { + ret->order=std::stoi(boost::get(vars["order"])); + } + + if(vars.count("weight")) { + try { + int weightVal=std::stoi(boost::get(vars["weight"])); + + if(weightVal < 1) { + errlog("Error creating new server: downstream weight value must be greater than 0."); + return ret; + } + + ret->setWeight(weightVal); + } + catch(std::exception& e) { + // std::stoi will throw an exception if the string isn't in a value int range + errlog("Error creating new server: downstream weight value must be between %s and %s", 1, std::numeric_limits::max()); + return ret; + } + } + + if(vars.count("retries")) { + ret->retries=std::stoi(boost::get(vars["retries"])); + } + + if(vars.count("checkInterval")) { + ret->checkInterval=static_cast(std::stoul(boost::get(vars["checkInterval"]))); + } + + if(vars.count("tcpConnectTimeout")) { + ret->tcpConnectTimeout=std::stoi(boost::get(vars["tcpConnectTimeout"])); + } + + if(vars.count("tcpSendTimeout")) { + ret->tcpSendTimeout=std::stoi(boost::get(vars["tcpSendTimeout"])); + } + + if(vars.count("tcpRecvTimeout")) { + ret->tcpRecvTimeout=std::stoi(boost::get(vars["tcpRecvTimeout"])); + } + + if(vars.count("tcpFastOpen")) { + bool fastOpen = boost::get(vars["tcpFastOpen"]); + if (fastOpen) { #ifdef MSG_FASTOPEN - ret->tcpFastOpen=true; + ret->tcpFastOpen=true; #else - warnlog("TCP Fast Open has been configured on downstream server %s but is not supported", boost::get(vars["address"])); + warnlog("TCP Fast Open has been configured on downstream server %s but is not supported", boost::get(vars["address"])); #endif - } - } + } + } + + if(vars.count("name")) { + ret->name=boost::get(vars["name"]); + } - if(vars.count("name")) { - ret->name=boost::get(vars["name"]); - } + if (vars.count("id")) { + ret->setId(boost::lexical_cast(boost::get(vars["id"]))); + } - if (vars.count("id")) { - ret->setId(boost::lexical_cast(boost::get(vars["id"]))); - } + if(vars.count("checkName")) { + ret->checkName=DNSName(boost::get(vars["checkName"])); + } - if(vars.count("checkName")) { - ret->checkName=DNSName(boost::get(vars["checkName"])); - } + if(vars.count("checkType")) { + ret->checkType=boost::get(vars["checkType"]); + } - if(vars.count("checkType")) { - ret->checkType=boost::get(vars["checkType"]); - } + if(vars.count("checkClass")) { + ret->checkClass=std::stoi(boost::get(vars["checkClass"])); + } - if(vars.count("checkClass")) { - ret->checkClass=std::stoi(boost::get(vars["checkClass"])); - } + if(vars.count("checkFunction")) { + ret->checkFunction= boost::get(vars["checkFunction"]); + } - if(vars.count("checkFunction")) { - ret->checkFunction= boost::get(vars["checkFunction"]); - } + if(vars.count("checkTimeout")) { + ret->checkTimeout = std::stoi(boost::get(vars["checkTimeout"])); + } - if(vars.count("checkTimeout")) { - ret->checkTimeout = std::stoi(boost::get(vars["checkTimeout"])); - } + if(vars.count("setCD")) { + ret->setCD=boost::get(vars["setCD"]); + } - if(vars.count("setCD")) { - ret->setCD=boost::get(vars["setCD"]); - } + if(vars.count("mustResolve")) { + ret->mustResolve=boost::get(vars["mustResolve"]); + } - if(vars.count("mustResolve")) { - ret->mustResolve=boost::get(vars["mustResolve"]); - } + if(vars.count("useClientSubnet")) { + ret->useECS=boost::get(vars["useClientSubnet"]); + } - if(vars.count("useClientSubnet")) { - ret->useECS=boost::get(vars["useClientSubnet"]); - } + if(vars.count("disableZeroScope")) { + ret->disableZeroScope=boost::get(vars["disableZeroScope"]); + } - if(vars.count("disableZeroScope")) { - ret->disableZeroScope=boost::get(vars["disableZeroScope"]); - } + if(vars.count("ipBindAddrNoPort")) { + ret->ipBindAddrNoPort=boost::get(vars["ipBindAddrNoPort"]); + } - if(vars.count("ipBindAddrNoPort")) { - ret->ipBindAddrNoPort=boost::get(vars["ipBindAddrNoPort"]); - } + if(vars.count("addXPF")) { + ret->xpfRRCode=std::stoi(boost::get(vars["addXPF"])); + } - if(vars.count("addXPF")) { - ret->xpfRRCode=std::stoi(boost::get(vars["addXPF"])); - } + if(vars.count("maxCheckFailures")) { + ret->maxCheckFailures=std::stoi(boost::get(vars["maxCheckFailures"])); + } - if(vars.count("maxCheckFailures")) { - ret->maxCheckFailures=std::stoi(boost::get(vars["maxCheckFailures"])); - } + if(vars.count("rise")) { + ret->minRiseSuccesses=std::stoi(boost::get(vars["rise"])); + } - if(vars.count("rise")) { - ret->minRiseSuccesses=std::stoi(boost::get(vars["rise"])); - } + if(vars.count("cpus")) { + for (const auto cpu : boost::get>>(vars["cpus"])) { + cpus.insert(std::stoi(cpu.second)); + } + } - if(vars.count("cpus")) { - for (const auto cpu : boost::get>>(vars["cpus"])) { - cpus.insert(std::stoi(cpu.second)); - } - } + /* this needs to be done _AFTER_ the order has been set, + since the server are kept ordered inside the pool */ + auto localPools = g_pools.getCopy(); + if(vars.count("pool")) { + if(auto* pool = boost::get(&vars["pool"])) { + ret->pools.insert(*pool); + } + else { + auto pools = boost::get > >(vars["pool"]); + for(auto& p : pools) { + ret->pools.insert(p.second); + } + } + for(const auto& poolName: ret->pools) { + addServerToPool(localPools, poolName, ret); + } + } + else { + addServerToPool(localPools, "", ret); + } + g_pools.setState(localPools); - /* this needs to be done _AFTER_ the order has been set, - since the server are kept ordered inside the pool */ - auto localPools = g_pools.getCopy(); - if(vars.count("pool")) { - if(auto* pool = boost::get(&vars["pool"])) { - ret->pools.insert(*pool); - } - else { - auto pools = boost::get > >(vars["pool"]); - for(auto& p : pools) { - ret->pools.insert(p.second); - } - } - for(const auto& poolName: ret->pools) { - addServerToPool(localPools, poolName, ret); - } - } - else { - addServerToPool(localPools, "", ret); - } - g_pools.setState(localPools); + if (ret->connected) { + ret->threadStarted.test_and_set(); + + if(g_launchWork) { + g_launchWork->push_back([ret,cpus]() { + ret->tid = thread(responderThread, ret); + if (!cpus.empty()) { + mapThreadToCPUList(ret->tid.native_handle(), cpus); + } + }); + } + else { + ret->tid = thread(responderThread, ret); + if (!cpus.empty()) { + mapThreadToCPUList(ret->tid.native_handle(), cpus); + } + } + } - if (ret->connected) { - ret->threadStarted.test_and_set(); - - if(g_launchWork) { - g_launchWork->push_back([ret,cpus]() { - ret->tid = thread(responderThread, ret); - if (!cpus.empty()) { - mapThreadToCPUList(ret->tid.native_handle(), cpus); - } - }); - } - else { - ret->tid = thread(responderThread, ret); - if (!cpus.empty()) { - mapThreadToCPUList(ret->tid.native_handle(), cpus); - } - } - } - - auto states = g_dstates.getCopy(); - states.push_back(ret); - std::stable_sort(states.begin(), states.end(), [](const decltype(ret)& a, const decltype(ret)& b) { - return a->order < b->order; - }); - g_dstates.setState(states); - return ret; - } ); + auto states = g_dstates.getCopy(); + states.push_back(ret); + std::stable_sort(states.begin(), states.end(), [](const decltype(ret)& a, const decltype(ret)& b) { + return a->order < b->order; + }); + g_dstates.setState(states); + return ret; + } ); g_lua.writeFunction("rmServer", - [](boost::variant, int> var) - { + [](boost::variant, int> var) + { setLuaSideEffect(); shared_ptr server; auto* rem = boost::get>(&var); @@ -461,7 +461,7 @@ void setupLuaConfig(bool client) g_pools.setState(localPools); states.erase(remove(states.begin(), states.end(), server), states.end()); g_dstates.setState(states); - } ); + } ); g_lua.writeFunction("setServerPolicy", [](ServerPolicy policy) { setLuaSideEffect(); -- 2.40.0