#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;
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;
}
#include <fstream>
#include "namespaces.hh"
#include "logger.hh"
+#include "rec-lua-conf.hh"
#include "sortlist.hh"
-SortList g_sortlist;
+GlobalStateHolder<LuaConfigItems> 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;
theL()<<"Unable to read configuration file from '"<<fname<<"': "<<strerror(errno)<<endl;
return;
}
- Lua.writeFunction("clearSortlist", []() { g_sortlist.clear(); });
+ Lua.writeFunction("clearSortlist", [&lci]() { lci.sortlist.clear(); });
/* we can get: "1.2.3.4"
{"1.2.3.4", "4.5.6.7"}
typedef vector<pair<int,boost::variant<string, vector<pair<int, string> > > > > argvec_t;
Lua.writeFunction("addSortList",
- [](const std::string& formask_,
+ [&lci](const std::string& formask_,
const boost::variant<string, argvec_t>& masks,
boost::optional<int> 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<string>(&masks))
- g_sortlist.addEntry(formask, Netmask(*str), order);
+ lci.sortlist.addEntry(formask, Netmask(*str), order);
else {
auto vec = boost::get<argvec_t>(&masks);
for(const auto& e : *vec) {
if(auto s = boost::get<string>(&e.second)) {
- g_sortlist.addEntry(formask, Netmask(*s), order);
+ lci.sortlist.addEntry(formask, Netmask(*s), order);
}
else {
const auto& v =boost::get<vector<pair<int, string> > >(e.second);
for(const auto& e : v)
- g_sortlist.addEntry(formask, Netmask(e.second), order);
+ lci.sortlist.addEntry(formask, Netmask(e.second), order);
}
++order;
}
}
});
Lua.executeCode(ifs);
-
+ g_luaconfs.setState(lci);
}