]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add SOA record to randombackend
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 16 Jun 2015 12:31:58 +0000 (14:31 +0200)
committermind04 <mind04@monshouwer.org>
Tue, 30 Jun 2015 06:12:48 +0000 (08:12 +0200)
modules/randombackend/randombackend.cc

index 33a729e7a32d93b2e1fb434ec125f3a790007ae8..e7b96b7d7ab05205b378f4e555066a6e3da087eb 100644 (file)
@@ -1,6 +1,6 @@
 /*
     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 */
@@ -112,4 +134,3 @@ public:
 };
 
 static RandomLoader randomLoader;
-