- `pdns.loglevels.Notice`
- `pdns.loglevels.Warning`
- `pdns.loglevels.Error`
+
+.. function:: pdnsrandom([maximum])
+
+ Get a random number.
+
+ :param int maximum: The largest number to return. This is 2^32 by default.
#include "namespaces.hh"
#include "ednssubnet.hh"
#include "lua-base4.hh"
+#include "dns_random.hh"
BaseLua4::BaseLua4() {
}
// pdnsload
d_lw->writeFunction("pdnslog", [](const std::string& msg, boost::optional<int> loglevel) { g_log << (Logger::Urgency)loglevel.get_value_or(Logger::Warning) << msg<<endl; });
+ d_lw->writeFunction("pdnsrandom", [](boost::optional<uint32_t> maximum) { return dns_random(maximum.get_value_or(0xffffffff)); });
// certain constants
d_pd.push_back({"PASS", (int)PolicyDecision::PASS});
.. function:: getRecursorThreadId() -> int
returns an unsigned integer identifying the thread handling the current request.
+
+.. function:: pdnsrandom([maximum])
+
+ Get a random number.
+
+ :param int maximum: The largest number to return. This is 2^32 by default.
self.assertEqual(len(res.answer), 2)
self.assertEqual(len(res.authority), 0)
self.assertResponseMatches(query, expected, res)
+
+
+class PDNSRandomTest(RecursorTest):
+ """Tests if pdnsrandom works"""
+
+ _confdir = 'pdnsrandom'
+ _config_template = """
+ """
+ _lua_dns_script_file = """
+ function preresolve (dq)
+ dq.rcode = pdns.NOERROR
+ dq:addAnswer(pdns.TXT, pdnsrandom())
+ return true
+ end
+ """
+
+ def testRandom(self):
+ query = dns.message.make_query('whatever.example.', 'TXT')
+
+ ans = set()
+
+ ret = self.sendUDPQuery(query)
+ ans.add(ret.answer[0])
+ ret = self.sendUDPQuery(query)
+ ans.add(ret.answer[0])
+
+ self.assertEqual(len(ans), 2)