Skip to content

Commit

Permalink
dndist: apply Remi's comments, thanks
Browse files Browse the repository at this point in the history
  • Loading branch information
chbruyand committed Jul 3, 2024
1 parent 3b66414 commit 0ace845
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
9 changes: 6 additions & 3 deletions pdns/dnsdistdist/dnsdist-lua-hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace dnsdist::lua::hooks
{
using MaintenanceCallback = std::function<void()>;
using TicketsKeyAddedHook = std::function<void(const char*, size_t)>;

static LockGuarded<std::vector<MaintenanceCallback>> s_maintenanceHooks;

void runMaintenanceHooks(const LuaContext& context)
Expand All @@ -16,7 +19,7 @@ void runMaintenanceHooks(const LuaContext& context)
}
}

void addMaintenanceCallback(const LuaContext& context, MaintenanceCallback callback)
static void addMaintenanceCallback(const LuaContext& context, MaintenanceCallback callback)
{
(void)context;
s_maintenanceHooks.lock()->push_back(std::move(callback));
Expand All @@ -27,15 +30,15 @@ void clearMaintenanceHooks()
s_maintenanceHooks.lock()->clear();
}

void setTicketsKeyAddedHook(const LuaContext& context, const TicketsKeyAddedHook& hook)
static void setTicketsKeyAddedHook(const LuaContext& context, const TicketsKeyAddedHook& hook)
{
TLSCtx::setTicketsKeyAddedHook([hook](const std::string& key) {
try {
auto lua = g_lua.lock();
hook(key.c_str(), key.size());
}
catch (const std::exception& exp) {
warnlog("Error calling the Lua hook after new tickets key has been added", exp.what());
warnlog("Error calling the Lua hook after new tickets key has been added: %s", exp.what());
}
});
}
Expand Down
5 changes: 0 additions & 5 deletions pdns/dnsdistdist/dnsdist-lua-hooks.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ class LuaContext;

namespace dnsdist::lua::hooks
{
using MaintenanceCallback = std::function<void()>;
using TicketsKeyAddedHook = std::function<void(const char*, size_t)>;

void runMaintenanceHooks(const LuaContext& context);
void addMaintenanceCallback(const LuaContext& context, MaintenanceCallback callback);
void setTicketsKeyAddedHook(const LuaContext& context, const TicketsKeyAddedHook& hook);
void clearMaintenanceHooks();
void setupLuaHooks(LuaContext& luaCtx);
}
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/docs/reference/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2175,7 +2175,7 @@ Other functions

.. function:: setTicketsKeyAddedHook(callback)

.. versionadded:: 1.9.0
.. versionadded:: 1.9.6

Set a Lua function that will be called everytime a new tickets key is added. The function receives:

Expand Down
2 changes: 2 additions & 0 deletions pdns/libssl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ void OpenSSLTLSTicketKeysRing::addKey(std::shared_ptr<OpenSSLTLSTicketKey>&& new
auto key = d_ticketKeys.read_lock()->front();
auto keyContent = key->content();
TLSCtx::getTicketsKeyAddedHook()(keyContent);
// fills mem with 0's
OPENSSL_cleanse(keyContent.data(), keyContent.size());
}
}

Expand Down
2 changes: 2 additions & 0 deletions pdns/tcpiohandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ class GnuTLSTicketsKey
if (d_key.data != nullptr && d_key.size > 0) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
result.append(reinterpret_cast<const char*>(d_key.data), d_key.size);
safe_memory_lock(result.data(), result.size());
}
return result;
}
Expand Down Expand Up @@ -1758,6 +1759,7 @@ class GnuTLSIOCtx: public TLSCtx
auto ticketsKey = *(d_ticketsKey.read_lock());
auto content = ticketsKey->content();
TLSCtx::getTicketsKeyAddedHook()(content);
safe_memory_release(content.data(), content.size());
}
}
void rotateTicketsKey(time_t now) override
Expand Down

0 comments on commit 0ace845

Please sign in to comment.