From ee1ada80baf5d8cb169d167838e9cf191f3e5134 Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Sat, 6 May 2006 19:50:46 +0000 Subject: [PATCH] implement reload-zones make loading zones do a 'round trip' of records to see if they make it alive add 'unregistering' of record types (unused for now) make zone loading a lot more helpful in reporting errors git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@823 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/dnsparser.hh | 7 ++ pdns/dnsrecords.cc | 2 +- pdns/dnsrecords.hh | 5 ++ pdns/docs/pdns.sgml | 15 +++- pdns/docs/rec_control.1.txt | 168 ++++++++++++++++++------------------ pdns/pdns_recursor.cc | 64 ++++++++++++++ pdns/rec_channel_rec.cc | 7 +- pdns/recursor_cache.hh | 3 +- pdns/syncres.hh | 2 + 9 files changed, 184 insertions(+), 89 deletions(-) diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 889347da3..42697fb0f 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -180,6 +180,13 @@ public: getNamemap()[make_pair(cl,ty)]=name; } + static void unregist(uint16_t cl, uint16_t ty) + { + pair key=make_pair(cl, ty); + getTypemap().erase(key); + getZmakermap().erase(key); + } + static uint16_t TypeToNumber(const string& name) { for(namemap_t::const_iterator i=getNamemap().begin(); i!=getNamemap().end();++i) diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 9076dbc78..92ca107ed 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -287,6 +287,7 @@ void reportBasicTypes() SRVRecordContent::report(); PTRRecordContent::report(); DNSRecordContent::regist(3, ns_t_txt, &TXTRecordContent::make, &TXTRecordContent::make, "TXT"); + TXTRecordContent::report(); DNSRecordContent::regist(1, 255, 0, 0, "ANY"); } @@ -302,7 +303,6 @@ void reportOtherTypes() CERTRecordContent::report(); NSECRecordContent::report(); OPTRecordContent::report(); - TXTRecordContent::report(); } void reportAllTypes() diff --git a/pdns/dnsrecords.hh b/pdns/dnsrecords.hh index b6532f7fc..466950ce2 100644 --- a/pdns/dnsrecords.hh +++ b/pdns/dnsrecords.hh @@ -31,6 +31,7 @@ using namespace boost; #define includeboilerplate(RNAME) RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr); \ RNAME##RecordContent(const string& zoneData); \ static void report(void); \ + static void unreport(void); \ static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); \ static DNSRecordContent* make(const string& zonedata); \ string getZoneRepresentation() const; \ @@ -289,6 +290,10 @@ void RNAME##RecordContent::toPacket(DNSPacketWriter& pw) void RNAME##RecordContent::report(void) \ { \ regist(1, RTYPE, &RNAME##RecordContent::make, &RNAME##RecordContent::make, #RNAME); \ +} \ +void RNAME##RecordContent::unreport(void) \ +{ \ + unregist(1, RTYPE); \ } \ \ RNAME##RecordContent::RNAME##RecordContent(const string& zoneData) : DNSRecordContent(RTYPE) \ diff --git a/pdns/docs/pdns.sgml b/pdns/docs/pdns.sgml index c7a9f24a3..5ad52d0ae 100644 --- a/pdns/docs/pdns.sgml +++ b/pdns/docs/pdns.sgml @@ -6379,6 +6379,16 @@ local0.err /var/log/pdns.err + + reload-zones + + + Reload data about all authoritative and forward zones. The configuration file is also scanned + to see if the auth-domain, forward-domain and export-etc-hosts + statements have changed, and if so, these changes are incorporated. + + + top-remotes @@ -6402,9 +6412,8 @@ local0.err /var/log/pdns.err - Ubunty Breezy ships a version of Boost that has problems with this command! Either refrain from - using wipe-cache or download a more recent Boost into the PowerDNS source directory, as explained in the - README + In PowerDNS versions 3.0.0 and 3.0.1 this command is slightly buggy and might cause your nameserver to crash if the first + query after wiping the cache is for the domain you just wiped. diff --git a/pdns/docs/rec_control.1.txt b/pdns/docs/rec_control.1.txt index 496b041bf..8cc1b4ba5 100644 --- a/pdns/docs/rec_control.1.txt +++ b/pdns/docs/rec_control.1.txt @@ -1,97 +1,101 @@ -REC_CONTROL(1) -============== -bert hubert -v3.0, 19 April 2006 - -NAME ----- -rec_control - control pdns_recursor - -SYNOPSIS --------- -'rec_control' [--help] [--socket-dir] [--socket-pid] command .. - -DESCRIPTION ------------ -rec_control(1) allows the operator to control a running instance -of the pdns_recursor. - -The commands that can be passed to the recursor are described on -http://doc.powerdns.com/rec-control.html - -EXAMPLES --------- - +REC_CONTROL(1) +============== +bert hubert +v3.0, 19 April 2006 + +NAME +---- +rec_control - control pdns_recursor + +SYNOPSIS +-------- +'rec_control' [--help] [--socket-dir] [--socket-pid] command .. + +DESCRIPTION +----------- +rec_control(1) allows the operator to control a running instance +of the pdns_recursor. + +The commands that can be passed to the recursor are described on +http://doc.powerdns.com/rec-control.html + +EXAMPLES +-------- + To stop the recursor by hand, run: # rec_control quit -To dump the cache to disk, execute: - - # rec_control dump-cache /tmp/the-cache - -OPTIONS -------- - +To dump the cache to disk, execute: + + # rec_control dump-cache /tmp/the-cache + +OPTIONS +------- + --help:: provide this helpful message --socket-dir:: Where the controlsocket will live - + --socket-pid:: When running in SMP mode, pid of pdns_recursor to control - -COMMANDS --------- -dump-cache filename:: - Dumps the entire cache to the filename mentioned. This file should - not exist already, PowerDNS will refuse to overwrite it. While - dumping, the recursor will not answer questions. - -get statistic:: - Retrieve a statistic. For items that can be queried, see - http://doc.powerdns.com/recursor-stats.html - -ping:: - Check if server is alive. - -quit:: - Request shutdown of the recursor - -top-remotes:: - Shows the top-20 most active remote hosts. Statistics are over the - last 'remotes-ringbuffer-entries' queries, which defaults to 0. - -wipe-cache domain0 [domain1]:: - Wipe entries from the cache. This is useful if, for example, an - important server has a new IP address, but the TTL has not yet - expired. Multiple domain names can be passed. Note that you must - terminate a domain with a .! So to wipe powerdns.org, issue - 'rec_control wipe-cache powerdns.org.'. + +COMMANDS +-------- +dump-cache filename:: + Dumps the entire cache to the filename mentioned. This file should + not exist already, PowerDNS will refuse to overwrite it. While + dumping, the recursor will not answer questions. + +get statistic:: + Retrieve a statistic. For items that can be queried, see + http://doc.powerdns.com/recursor-stats.html + +ping:: + Check if server is alive. + +quit:: + Request shutdown of the recursor + +reload-zones:: + Reload authoritative and forward zones. Retains current configuration + in case of errors. + +top-remotes:: + Shows the top-20 most active remote hosts. Statistics are over the + last 'remotes-ringbuffer-entries' queries, which defaults to 0. + +wipe-cache domain0 [domain1]:: + Wipe entries from the cache. This is useful if, for example, an + important server has a new IP address, but the TTL has not yet + expired. Multiple domain names can be passed. Note that you must + terminate a domain with a .! So to wipe powerdns.org, issue + 'rec_control wipe-cache powerdns.org.'. Versions beyond 3.1 don't need the trailing dot. Consider not only wiping 'www.domain.com.' but also 'domain.com.', as the cached nameservers or target of CNAME may continue to be undesired. -BUGS ----- -None known. File new ones at http://wiki.powerdns.com. - -AUTHOR ------- -Written by PowerDNS.COM BV, bert hubert, - -RESOURCES ---------- -Website: http://wiki.powerdns.com, http://www.powerdns.com - -SEE ALSO --------- -pdns_recursor(1) - -COPYING -------- -Copyright (C) 2006 PowerDNS.COM BV. Free use of this software -is granted under the terms of the GNU General Public License (GPL) version -2. - +BUGS +---- +None known. File new ones at http://wiki.powerdns.com. + +AUTHOR +------ +Written by PowerDNS.COM BV, bert hubert, + +RESOURCES +--------- +Website: http://wiki.powerdns.com, http://www.powerdns.com + +SEE ALSO +-------- +pdns_recursor(1) + +COPYING +------- +Copyright (C) 2006 PowerDNS.COM BV. Free use of this software +is granted under the terms of the GNU General Public License (GPL) version +2. + diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index e715a7ef5..e058a3309 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1204,10 +1204,62 @@ static void makeIPToNamesZone(const vector& parts) } } + +void parseAuthAndForwards(); + +string reloadAuthAndForwards() +{ + SyncRes::domainmap_t original=SyncRes::s_domainmap; + + try { + L<second.d_records.begin(); j != i->second.d_records.end(); ++j) + RC.doWipeCache(j->qname); + } + + string configname=::arg()["config-dir"]+"/recursor.conf"; + cleanSlashes(configname); + + if(!::arg().preParseFile(configname.c_str(), "forward-zones")) + L<second.d_records.begin(); j != i->second.d_records.end(); ++j) + RC.doWipeCache(j->qname); + } + + // this is pretty blunt + SyncRes::s_negcache.clear(); + return "ok\n"; + } + catch(exception& e) { + L< parts_t; parts_t parts; for(int n=0; n < 2 ; ++n ) { @@ -1224,7 +1276,19 @@ void parseAuthAndForwards() ZoneParserTNG zpt(headers.second, headers.first); DNSResourceRecord rr; while(zpt.get(rr)) { + try { + string tmp=DNSRR2String(rr); + rr=String2DNSRR(rr.qname, rr.qtype, tmp, 3600); + } + catch(exception &e) { + throw AhuException("Error parsing record '"+rr.qname+"' of type "+rr.qtype.getName()+" in zone '"+headers.first+"' from file '"+headers.second+"': "+e.what()); + } + catch(...) { + throw AhuException("Error parsing record '"+rr.qname+"' of type "+rr.qtype.getName()+" in zone '"+headers.first+"' from file '"+headers.second+"'"); + } + ad.d_records.insert(rr); + } } else { diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 54892fef6..fa489aad7 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -255,7 +255,10 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP if(cmd=="ping") return "pong\n"; - - return "Unknown command '"+cmd+"'\n"; + if(cmd=="reload-zones") { + return reloadAuthAndForwards(); + } + + return "Unknown command '"+cmd+"'\n"; } diff --git a/pdns/recursor_cache.hh b/pdns/recursor_cache.hh index 23845e1ce..1a5bbd83c 100644 --- a/pdns/recursor_cache.hh +++ b/pdns/recursor_cache.hh @@ -117,6 +117,7 @@ private: string d_cachedqname; bool d_cachecachevalid; }; - +string DNSRR2String(const DNSResourceRecord& rr); +DNSResourceRecord String2DNSRR(const string& qname, const QType& qt, const string& serial, uint32_t ttd); #endif diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 7ddce01e8..0b3412b56 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -477,4 +477,6 @@ replacing_insert(Index& i,const typename Index::value_type& x) return res; } + +std::string reloadAuthAndForwards(); #endif -- 2.40.0