From: bert hubert Date: Sun, 29 Nov 2015 12:41:41 +0000 (+0100) Subject: move all the lua configuration items to a struct that is RCU for easy reloading X-Git-Tag: dnsdist-1.0.0-alpha1~171^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f3c18728358716e07094ae7ff259f6194872bc43;p=pdns move all the lua configuration items to a struct that is RCU for easy reloading --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 8c1e09d37..8da6b6a67 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -80,11 +80,13 @@ extern SortList g_sortlist; #include "filterpo.hh" #include "rpzloader.hh" #include "validate-recursor.hh" +#include "rec-lua-conf.hh" + #ifndef RECURSOR #include "statbag.hh" StatBag S; #endif -void loadRecursorLuaConfig(const std::string& fname); + __thread FDMultiplexer* t_fdm; __thread unsigned int t_id; unsigned int g_maxTCPPerClient; @@ -819,7 +821,7 @@ void startDoResolve(void *p) if(ret.size()) { orderAndShuffle(ret); - if(auto sl = g_sortlist.getOrderCmp(dc->d_remote)) { + if(auto sl = g_luaconfs.getCopy().sortlist.getOrderCmp(dc->d_remote)) { sort(ret.begin(), ret.end(), *sl); variableAnswer=true; } diff --git a/pdns/rec-lua-conf.cc b/pdns/rec-lua-conf.cc index 1dabe6e7c..7471413c6 100644 --- a/pdns/rec-lua-conf.cc +++ b/pdns/rec-lua-conf.cc @@ -2,11 +2,32 @@ #include #include "namespaces.hh" #include "logger.hh" +#include "rec-lua-conf.hh" #include "sortlist.hh" -SortList g_sortlist; +GlobalStateHolder g_luaconfs; + +/* SO HOW DOES THIS WORK! AND PLEASE PAY ATTENTION! + This function can be called at any time. It is expected to overwrite all the contents + of LuaConfigItems, which is held in a GlobalStateHolder for RCU properties. + + This function can be called again at a later date, so you must make sure that anything you + allow to be configured from here lives in g_luaconfs AND NOWHERE ELSE. + + If someone loads an empty Lua file, the default LuaConfigItems struct MUST MAKE SENSE. + + To make this easy on you, here is a LuaConfigItems constructor where you + can set sane defaults: +*/ + +LuaConfigItems::LuaConfigItems() +{ +} + void loadRecursorLuaConfig(const std::string& fname) { + LuaConfigItems lci; + LuaContext Lua; if(fname.empty()) return; @@ -15,7 +36,7 @@ void loadRecursorLuaConfig(const std::string& fname) theL()<<"Unable to read configuration file from '"< > > > > argvec_t; Lua.writeFunction("addSortList", - [](const std::string& formask_, + [&lci](const std::string& formask_, const boost::variant& masks, boost::optional order_) { try { Netmask formask(formask_); - int order = order_ ? (*order_) : g_sortlist.getMaxOrder(formask)+1; + int order = order_ ? (*order_) : lci.sortlist.getMaxOrder(formask)+1; if(auto str = boost::get(&masks)) - g_sortlist.addEntry(formask, Netmask(*str), order); + lci.sortlist.addEntry(formask, Netmask(*str), order); else { auto vec = boost::get(&masks); for(const auto& e : *vec) { if(auto s = boost::get(&e.second)) { - g_sortlist.addEntry(formask, Netmask(*s), order); + lci.sortlist.addEntry(formask, Netmask(*s), order); } else { const auto& v =boost::get > >(e.second); for(const auto& e : v) - g_sortlist.addEntry(formask, Netmask(e.second), order); + lci.sortlist.addEntry(formask, Netmask(e.second), order); } ++order; } @@ -54,5 +75,5 @@ void loadRecursorLuaConfig(const std::string& fname) } }); Lua.executeCode(ifs); - + g_luaconfs.setState(lci); }