}
+uint32_t getHighestSerialFromDir(const std::string& dir)
+{
+ return 1445497587;
+}
- bool canonCompare(const DNSRecord& a, const DNSRecord& b)
- {
- if(a.d_name.canonCompare(b.d_name))
- return true;
- if(a.d_name!=b.d_name) {
- return false;
- }
- string lzrp, rzrp;
- if(a.d_content)
- lzrp=toLower(a.d_content->getZoneRepresentation());
- if(b.d_content)
- rzrp=toLower(b.d_content->getZoneRepresentation());
- auto atype = a.d_type == QType::SOA ? 0 : a.d_type;
- auto btype = b.d_type == QType::SOA ? 0 : b.d_type;
-
- return tie(atype, a.d_class, lzrp) <
- tie(btype, b.d_class, rzrp);
- }
-
int main(int argc, char** argv)
try
{
shared_ptr<SOARecordContent> sr;
uint32_t serial = getSerial(master, zone, sr);
- sr->d_st.serial=1445514388;
+ uint32_t ourSerial = getHighestSerialFromDir(argv[4]);
+
+ cout<<"Our serial: "<<ourSerial<<", their serial: "<<serial<<endl;
+
+ ZoneParserTNG zpt(argv[4]+string("/")+std::to_string(ourSerial), zone);
+ DNSResourceRecord rr;
+ unsigned int nrecords=0;
+ records_t records;
+
+ while(zpt.get(rr)) {
+ ++nrecords;
+ if(rr.qtype.getCode() == QType::CNAME && rr.content.empty())
+ rr.content=".";
+ rr.qname = rr.qname.makeRelative(zone);
+ records.insert(DNSRecord(rr));
+ }
-
+ cout<<"Parsed "<<nrecords<<" records"<<endl;
+ sr->d_st.serial= ourSerial;
auto deltas = getIXFRDeltas(master, zone, sr);
-
-
+ cout<<"Got "<<deltas.size()<<" deltas, applying.."<<endl;
+ int oldserial;
+ for(const auto& delta : deltas) {
+ for(const auto& r : records) {
+ if(r.d_type == QType::SOA) {
+ oldserial=std::dynamic_pointer_cast<SOARecordContent>(r.d_content)->d_st.serial;
+ cout<<"Serial before application: "<< oldserial <<endl;
+ break;
+ }
+ }
+
+ const auto& remove = delta.first;
+ const auto& add = delta.second;
+ set<DNSRecord> toremove;
+ ofstream report(string(argv[4]) +"/delta."+std::to_string(oldserial));
+ for(const auto& rr : remove) {
+ auto range = records.equal_range(tie(rr.d_name, rr.d_type, rr.d_class, rr.d_content));
+ if(range.first == range.second) {
+ cerr<<"Could not find record "<<rr.d_name<<" to remove!!"<<endl;
+ exit(1);
+ }
+ if(rr.d_type == QType::SOA) {
+ cout<<"Serial to remove: "<< std::dynamic_pointer_cast<SOARecordContent>(rr.d_content)->d_st.serial <<endl;
+ }
+ records.erase(range.first, range.second);
+ report<<'-'<< (rr.d_name+zone) <<" IN "<<DNSRecordContent::NumberToType(rr.d_type)<<" "<<rr.d_content->getZoneRepresentation()<<endl;
+ }
+ cout<<"Adding "<<add.size()<<" records now"<<endl;
+ uint32_t newserial=0;
+ for(const auto& rr : add) {
+ if(rr.d_type == QType::SOA) {
+ newserial=std::dynamic_pointer_cast<SOARecordContent>(rr.d_content)->d_st.serial;
+ cout<<"Serial to ADD: "<< newserial <<endl;
+ }
+ report<<'+'<< (rr.d_name+zone) <<" IN "<<DNSRecordContent::NumberToType(rr.d_type)<<" "<<rr.d_content->getZoneRepresentation()<<endl;
+ records.insert(rr);
+ }
+ if(newserial == serial) {
+ FILE* fp=fopen((string(argv[4]) +"/"+std::to_string(newserial)).c_str(), "w");
+ for(const auto& r: records) {
+ fprintf(fp, "%s\t%d\tIN\t%s\t%s\n", (r.d_name+zone).toString().c_str(),
+ r.d_ttl,
+ DNSRecordContent::NumberToType(r.d_type).c_str(),
+ r.d_content->getZoneRepresentation().c_str());
+ }
+ fclose(fp);
+
+ }
+ }
}
catch(PDNSException &e2) {
cerr<<"Fatal: "<<e2.reason<<endl;