/*
PowerDNS Versatile Database Driven Nameserver
- Copyright (C) 2002 - 2008 PowerDNS.COM BV
+ Copyright (C) 2002 - 2015 PowerDNS.COM BV
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
class RandomBackend : public DNSBackend
{
public:
- RandomBackend(const string &suffix="")
+ RandomBackend(const string &suffix="")
{
setArgPrefix("random"+suffix);
d_ourname=DNSName(getArg("hostname"));
+ d_want_A=false;
+ d_want_SOA=false;
}
bool list(const DNSName &target, int id, bool include_disabled) {
return false; // we don't support AXFR
}
-
+
void lookup(const QType &type, const DNSName &qdomain, DNSPacket *p, int zoneId)
{
- if((type.getCode()!=QType::ANY && type.getCode()!=QType::A) || qdomain==d_ourname) // we only know about random.example.com A by default
- d_answer=""; // no answer
- else {
- ostringstream os;
- os<<Utility::random()%256<<"."<<Utility::random()%256<<"."<<Utility::random()%256<<"."<<Utility::random()%256;
- d_answer=os.str(); // our random ip address
+ if(qdomain == d_ourname){
+ switch (type.getCode()) {
+ case QType::A:
+ d_want_A = true;
+ break;
+ case QType::SOA:
+ d_want_SOA = true;
+ break;
+ case QType::ANY:
+ d_want_A = true;
+ d_want_SOA = true;
+ break;
+ }
+ } else { // We know nothing
+ d_want_A = false;
+ d_want_SOA = false;
}
-
}
bool get(DNSResourceRecord &rr)
{
- if(!d_answer.empty()) {
- rr.qname=d_ourname; // fill in details
- rr.qtype=QType::A; // A record
- rr.ttl=5; // 5 seconds
- rr.auth = 1; // it may be random.. but it is auth!
- rr.content=d_answer;
-
- d_answer=""; // this was the last answer
-
+ // fill in details
+ rr.qname=d_ourname;
+ rr.ttl=5; // 5 seconds
+ rr.auth=1; // it may be random.. but it is auth!
+
+ if(d_want_A) {
+ rr.qtype=QType::A;
+ ostringstream os;
+ os<<Utility::random()%256<<"."<<Utility::random()%256<<"."<<Utility::random()%256<<"."<<Utility::random()%256;
+ rr.content=os.str();
+ d_want_A=false;
return true;
}
- return false; // no more data
+
+ if(d_want_SOA) {
+ rr.qtype=QType::SOA;
+ rr.content="ns1." + d_ourname.toString() + " hostmaster." + d_ourname.toString() + " 1234567890 86400 7200 604800 300";
+ d_want_SOA=false;
+ return true;
+ }
+
+ return false;
}
-
+
private:
- string d_answer;
DNSName d_ourname;
+ bool d_want_A;
+ bool d_want_SOA;
};
/* SECOND PART */
};
static RandomLoader randomLoader;
-