diff --git a/docs/markdown/recursor/scripting.md b/docs/markdown/recursor/scripting.md index 76550b945db7..f4030a8c7836 100644 --- a/docs/markdown/recursor/scripting.md +++ b/docs/markdown/recursor/scripting.md @@ -379,6 +379,9 @@ entry. Entries are listed in the following table: Public Suffix List. In general it will tell you the 'registered domain' for a given name. +`getRecursorThreadId()` returns an unsigned integer identifying the thread +handling the current request. + ## DNS64 The `getFakeAAAARecords` and `getFakePTRRecords` followupFunctions can be used to implement DNS64. See [DNS64 support in the PowerDNS Recursor](dns64.md) for diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index faf5bef06afd..ea0cde2bf3bf 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -531,7 +531,11 @@ RecursorLua4::RecursorLua4(const std::string& fname) d_lw->registerFunction("incBy", &DynMetric::incBy); d_lw->registerFunction("set", &DynMetric::set); d_lw->registerFunction("get", &DynMetric::get); - + + d_lw->writeFunction("getRecursorThreadId", []() { + return getRecursorThreadId(); + }); + ifstream ifs(fname); if(!ifs) { diff --git a/pdns/lua-recursor4.hh b/pdns/lua-recursor4.hh index a684ee0ae356..4277b9721482 100644 --- a/pdns/lua-recursor4.hh +++ b/pdns/lua-recursor4.hh @@ -31,6 +31,7 @@ #endif string GenUDPQueryResponse(const ComboAddress& dest, const string& query); +unsigned int getRecursorThreadId(); class LuaContext; diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 2b6c91f90813..23d13ce8aac6 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -91,7 +91,7 @@ extern SortList g_sortlist; #endif __thread FDMultiplexer* t_fdm; -__thread unsigned int t_id; +static __thread unsigned int t_id; unsigned int g_maxTCPPerClient; unsigned int g_networkTimeoutMsec; uint64_t g_latencyStatSize; @@ -214,6 +214,10 @@ ArgvMap &arg() return theArg; } +unsigned int getRecursorThreadId() +{ + return t_id; +} void handleTCPClientWritable(int fd, FDMultiplexer::funcparam_t& var);