* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <boost/format.hpp>
+
#include "config.h"
#include "dnsdist.hh"
#include "dnsdist-backend.hh"
#include "dnsdist.hh"
#include "dnsdist-console.hh"
#include "dnsdist-crypto.hh"
+#include "dnsdist-lua.hh"
#include "threadname.hh"
static LockGuarded<std::vector<pair<timeval, string>>> s_confDelta;
#include "dnsdist-lua-inspection-ffi.h"
}
+#include "ext/luawrapper/include/LuaContext.hpp"
+
// dnsdist_ffi_stat_node_t is a lightuserdata
template <>
struct LuaContext::Pusher<dnsdist_ffi_stat_node_t*>
#include "tcpiohandler-mplexer.hh"
#include "dnswriter.hh"
#include "dolog.hh"
+#include "dnsdist-lua.hh"
#include "dnsdist-random.hh"
#include "dnsdist-tcp.hh"
#include "dnsdist-nghttp2.hh"
auto ret = tmpContext.executeCode<ServerPolicy::ffipolicyfunc_t>(code);
}
-thread_local ServerPolicy::PerThreadState ServerPolicy::t_perThreadState;
+struct ServerPolicy::PerThreadState
+{
+ LuaContext d_luaContext;
+ std::unordered_map<std::string, ffipolicyfunc_t> d_policies;
+};
+
+thread_local std::unique_ptr<ServerPolicy::PerThreadState> ServerPolicy::t_perThreadState;
const ServerPolicy::ffipolicyfunc_t& ServerPolicy::getPerThreadPolicy() const
{
auto& state = t_perThreadState;
- if (!state.d_initialized) {
- setupLuaLoadBalancingContext(state.d_luaContext);
- state.d_initialized = true;
+ if (!state) {
+ state = std::make_unique<ServerPolicy::PerThreadState>();
+ setupLuaLoadBalancingContext(state->d_luaContext);
}
- const auto& it = state.d_policies.find(d_name);
- if (it != state.d_policies.end()) {
- return it->second;
+ const auto& policyIt = state->d_policies.find(d_name);
+ if (policyIt != state->d_policies.end()) {
+ return policyIt->second;
}
- auto newPolicy = state.d_luaContext.executeCode<ServerPolicy::ffipolicyfunc_t>(d_perThreadPolicyCode);
- state.d_policies[d_name] = std::move(newPolicy);
- return state.d_policies.at(d_name);
+ auto newPolicy = state->d_luaContext.executeCode<ServerPolicy::ffipolicyfunc_t>(d_perThreadPolicyCode);
+ state->d_policies[d_name] = std::move(newPolicy);
+ return state->d_policies.at(d_name);
}
std::shared_ptr<DownstreamState> ServerPolicy::getSelectedBackend(const ServerPolicy::NumberedServerVector& servers, DNSQuestion& dq) const
}
private:
- struct PerThreadState
- {
- LuaContext d_luaContext;
- std::unordered_map<std::string, ffipolicyfunc_t> d_policies;
- bool d_initialized{false};
- };
+ struct PerThreadState;
const ffipolicyfunc_t& getPerThreadPolicy() const;
- static thread_local PerThreadState t_perThreadState;
+ static thread_local std::unique_ptr<PerThreadState> t_perThreadState;
public:
std::string d_name;
#include "dnsdist-lua-ffi-interface.h"
}
+#include "ext/luawrapper/include/LuaContext.hpp"
+
// dnsdist_ffi_dnsquestion_t is a lightuserdata
template<>
struct LuaContext::Pusher<dnsdist_ffi_dnsquestion_t*> {
*/
#pragma once
+#include <random>
+
#include "dolog.hh"
#include "dnsdist.hh"
#include "dnsdist-dnsparser.hh"
#include "dnsparser.hh"
-#include <random>
+
+#include "ext/luawrapper/include/LuaContext.hpp"
+
+extern RecursiveLockGuarded<LuaContext> g_lua;
+extern std::string g_outputBuffer; // locking for this is ok, as locked by g_luamutex
class SpoofAction : public DNSAction
{
#include "dnsdist.hh"
#include "dnsdist-ecs.hh"
#include "dnsdist-kvs.hh"
+#include "dnsdist-lua.hh"
#include "dnsdist-lua-ffi.hh"
#include "dolog.hh"
#include "dnsparser.hh"
#include <thread>
#include <netinet/tcp.h>
#include <queue>
+#include <boost/format.hpp>
#include "dnsdist.hh"
#include "dnsdist-concurrent-connections.hh"
#include "dnsdist-dynbpf.hh"
#include "dnsdist-frontend.hh"
#include "dnsdist-healthchecks.hh"
+#include "dnsdist-lua.hh"
#include "dnsdist-metrics.hh"
#include "dnsdist-prometheus.hh"
#include "dnsdist-rings.hh"
#pragma once
#include "config.h"
-#include "ext/luawrapper/include/LuaContext.hpp"
#include <condition_variable>
#include <memory>
};
void responderThread(std::shared_ptr<DownstreamState> dss);
-extern RecursiveLockGuarded<LuaContext> g_lua;
-extern std::string g_outputBuffer; // locking for this is ok, as locked by g_luamutex
class DNSDistPacketCache;
#include "dnsdist-rules.hh"
-void checkParameterBound(const std::string& parameter, uint64_t value, size_t max);
void checkParameterBound(const std::string& parameter, uint64_t value, size_t max)
{
if (value > max) {