void BaseLua4::prepareContext() {
d_lw = std::unique_ptr<LuaContext>(new LuaContext);
+ // lua features available
+ d_lw->writeVariable("pdns_features",
+ vector<pair<string, boost::variant<string,bool,int,double> > > {
+ // 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 },
+ });
+
// dnsheader
d_lw->registerFunction<int(dnsheader::*)()>("getID", [](dnsheader& dh) { return ntohs(dh.id); });
d_lw->registerFunction<bool(dnsheader::*)()>("getCD", [](dnsheader& dh) { return dh.cd; });
--- /dev/null
+Checking available features
+===========================
+.. versionadded:: 4.3.0
+
+To check if a Lua features is available, consult the global
+``pdns_features`` table. This table contains string keys with a values
+of type boolean, string or number. If a key is absent the value will
+evaluate to ``nil``, indicating the feature is not available.
+
+Currently, the following keys are defined:
+
+.. code-block:: Lua
+
+ pdns_feature["PR8001_devicename"] = true
+
+
logging
hooks
functions
+ features
+
local tags = {}
local data = {}
+
-- make sure we can pass data around to the other hooks
data['canary'] = 'from-gettag'
ans.add(ret.answer[0])
self.assertEqual(len(ans), 2)
+
+
+class PDNSFeaturesTest(RecursorTest):
+ """Tests if pdns_features works"""
+
+ _confdir = 'pdnsfeatures'
+ _config_template = """
+ """
+ _lua_dns_script_file = """
+ function preresolve (dq)
+ dq.rcode = pdns.NOERROR
+ -- test pdns_features
+ if pdns_features['nonexistent'] ~= nil then
+ print('PDNSFeaturesTest: case 1')
+ dq.rcode = pdns.SERVFAIL
+ end
+ if not pdns_features['PR8001_devicename'] then
+ print('PDNSFeaturesTest: case 2')
+ dq.rcode = pdns.SERVFAIL
+ end
+ return true
+ end
+ """
+
+ def testFeatures(self):
+ query = dns.message.make_query('whatever.example.', 'TXT')
+ res = self.sendUDPQuery(query)
+
+ self.assertRcodeEqual(res, dns.rcode.NOERROR)
+