From c4e71b7c3b52029596a8d68c6b4fe2cb6dca1bdf Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 19 Aug 2019 09:47:56 +0200 Subject: [PATCH] Allow for pdns_features to be set for all products. lua-base4 provides mechanism, derived classes provide content. --- pdns/lua-base4.cc | 13 ++++++------- pdns/lua-base4.hh | 2 ++ pdns/lua-recursor4.cc | 8 ++++++++ pdns/lua-recursor4.hh | 1 + regression-tests.recursor-dnssec/test_Lua.py | 1 - 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pdns/lua-base4.cc b/pdns/lua-base4.cc index d643d4a2f..0b45c86c9 100644 --- a/pdns/lua-base4.cc +++ b/pdns/lua-base4.cc @@ -29,6 +29,9 @@ void BaseLua4::loadString(const std::string &script) { loadStream(iss); }; +// By default no features +void BaseLua4::getFeatures(Features &) { } + #if !defined(HAVE_LUA) void BaseLua4::prepareContext() { return; } @@ -43,13 +46,9 @@ void BaseLua4::prepareContext() { d_lw = std::unique_ptr(new LuaContext); // lua features available - d_lw->writeVariable("pdns_features", - vector > > { - // Add key-values pairs below. Make sure you add string values explicity converted to string. - // e.g. { "somekey", string("stringvalue") } - // Both int and double end up as a lua number type. - { "PR8001_devicename", true }, - }); + Features features; + getFeatures(features); + d_lw->writeVariable("pdns_features", features); // dnsheader d_lw->registerFunction("getID", [](dnsheader& dh) { return ntohs(dh.id); }); diff --git a/pdns/lua-base4.hh b/pdns/lua-base4.hh index c166e3f56..79300f778 100644 --- a/pdns/lua-base4.hh +++ b/pdns/lua-base4.hh @@ -30,4 +30,6 @@ protected: virtual void postLoad() = 0; typedef vector > in_t; vector > > d_pd; + typedef vector > > Features; + virtual void getFeatures(Features&); }; diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 8f918e6c6..9381f96ef 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -460,6 +460,14 @@ void RecursorLua4::postLoad() { d_gettag_ffi = d_lw->readVariable>("gettag_ffi").get_value_or(0); } +void RecursorLua4::getFeatures(Features & features) { + // Add key-values pairs below. + // Make sure you add string values explicity converted to string. + // e.g. features.push_back(make_pair("somekey", string("stringvalue")); + // Both int and double end up as a lua number type. + features.push_back(make_pair("PR8001_devicename", true)); +} + void RecursorLua4::maintenance() const { if (d_maintenance) { diff --git a/pdns/lua-recursor4.hh b/pdns/lua-recursor4.hh index 12a41b37d..4515136a4 100644 --- a/pdns/lua-recursor4.hh +++ b/pdns/lua-recursor4.hh @@ -141,6 +141,7 @@ public: protected: virtual void postPrepareContext() override; virtual void postLoad() override; + virtual void getFeatures(Features& features) override; private: typedef std::function luamaintenance_t; luamaintenance_t d_maintenance; diff --git a/regression-tests.recursor-dnssec/test_Lua.py b/regression-tests.recursor-dnssec/test_Lua.py index f31b708b2..a040ffbad 100644 --- a/regression-tests.recursor-dnssec/test_Lua.py +++ b/regression-tests.recursor-dnssec/test_Lua.py @@ -22,7 +22,6 @@ class GettagRecursorTest(RecursorTest): local tags = {} local data = {} - -- make sure we can pass data around to the other hooks data['canary'] = 'from-gettag' -- 2.40.0