d_nxdomain = d_lw->readVariable<boost::optional<luacall_t>>("nxdomain").get_value_or(0);
d_postresolve = d_lw->readVariable<boost::optional<luacall_t>>("postresolve").get_value_or(0);
d_preoutquery = d_lw->readVariable<boost::optional<luacall_t>>("preoutquery").get_value_or(0);
+ d_maintenance = d_lw->readVariable<boost::optional<luamaintenance_t>>("maintenance").get_value_or(0);
d_ipfilter = d_lw->readVariable<boost::optional<ipfilter_t>>("ipfilter").get_value_or(0);
d_gettag = d_lw->readVariable<boost::optional<gettag_t>>("gettag").get_value_or(0);
d_gettag_ffi = d_lw->readVariable<boost::optional<gettag_ffi_t>>("gettag_ffi").get_value_or(0);
}
+void RecursorLua4::maintenance() const
+{
+ if (d_maintenance) {
+ d_maintenance();
+ }
+}
+
bool RecursorLua4::prerpz(DNSQuestion& dq, int& ret) const
{
return genhook(d_prerpz, dq, ret);
unsigned int gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector<std::string>* policyTags, LuaContext::LuaObject& data, const std::map<uint16_t, EDNSOptionView>&, bool tcp, std::string& requestorId, std::string& deviceId) const;
unsigned int gettag_ffi(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector<std::string>* policyTags, LuaContext::LuaObject& data, const std::map<uint16_t, EDNSOptionView>&, bool tcp, std::string& requestorId, std::string& deviceId, uint32_t& ttlCap, bool& variable) const;
+ void maintenance() const;
bool prerpz(DNSQuestion& dq, int& ret) const;
bool preresolve(DNSQuestion& dq, int& ret) const;
bool nxdomain(DNSQuestion& dq, int& ret) const;
virtual void postPrepareContext() override;
virtual void postLoad() override;
private:
+ typedef std::function<void()> luamaintenance_t;
+ luamaintenance_t d_maintenance;
typedef std::function<bool(DNSQuestion*)> luacall_t;
luacall_t d_prerpz, d_preresolve, d_nxdomain, d_nodata, d_postresolve, d_preoutquery, d_postoutquery;
bool genhook(const luacall_t& func, DNSQuestion& dq, int& ret) const;
bool listenOnTCP(true);
time_t last_stat = 0;
- time_t last_carbon=0;
+ time_t last_carbon=0, last_lua_maintenance=0;
time_t carbonInterval=::arg().asNum("carbon-interval");
+ time_t luaMaintenanceInterval=::arg().asNum("lua-maintenance-interval");
counter.store(0); // used to periodically execute certain tasks
for(;;) {
while(MT->schedule(&g_now)); // MTasker letting the mthreads do their thing
last_carbon = g_now.tv_sec;
}
}
+ if(!t_id && (g_now.tv_sec - last_lua_maintenance >= luaMaintenanceInterval)) {
+ t_pdl->maintenance();
+ last_lua_maintenance = g_now.tv_sec;
+ }
t_fdm->run(&g_now);
// 'run' updates g_now for us
::arg().set("etc-hosts-file", "Path to 'hosts' file")="/etc/hosts";
::arg().set("serve-rfc1918", "If we should be authoritative for RFC 1918 private IP space")="yes";
::arg().set("lua-dns-script", "Filename containing an optional 'lua' script that will be used to modify dns answers")="";
+ ::arg().set("lua-maintenance-interval", "Number of seconds between calls to the lua user defined maintenance() function")="1";
::arg().set("latency-statistic-size","Number of latency values to calculate the qa-latency average")="10000";
::arg().setSwitch( "disable-packetcache", "Disable packetcache" )= "no";
::arg().set("ecs-ipv4-bits", "Number of bits of IPv4 address to pass for EDNS Client Subnet")="24";
^^^
.. literalinclude:: ../../RECURSOR-MIB.txt
+
+.. _hooks-maintenance-callback:
+
+Maintenance callback
+--------------------
+Starting with version 4.1.3 of the recursor, it is possible to define a `maintenance()` callback function that will be called periodically.
+This function expects no argument and doesn't return any value
+
+.. code-block:: Lua
+
+ function maintenance()
+ -- This would be called every second
+ -- Perform here your maintenance
+ end
+
+The interval can be configured through the :ref:`setting-maintenance-interval` setting.
Path to a lua file to manipulate the Recursor's answers. See :doc:`lua-scripting/index` for more information.
+.. _setting-maintenance-interval:
+
+``lua-maintenance-interval``
+-------------------
+.. versionadded:: 4.1.3
+
+- Integer
+- Default: 1
+
+
+The interval between calls to the Lua user defined `maintenance()` function in seconds.
+See :ref:`hooks-maintenance-callback`
+
.. _setting-max-cache-entries:
``max-cache-entries``