From 973ad2b563bdf60d0496f3dd7e8989b74c8735fc Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Wed, 18 Dec 2002 16:22:20 +0000 Subject: [PATCH] added comments mostly git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@86 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- ChangeLog | 1 + TODO | 2 +- pdns/backends/bind/bindbackend.cc | 125 ++++++++++++++++------------- pdns/backends/bind/bindbackend.hh | 62 ++++++++++----- pdns/backends/bind/bindparser.cc | 9 +-- pdns/backends/bind/bindparser.hh | 3 +- pdns/backends/bind/bindparser.yy | 5 +- pdns/backends/bind/zone2sql.cc | 9 ++- pdns/backends/bind/zoneparser.hh | 4 +- pdns/backends/bind/zoneparser2.cc | 4 +- pdns/dnsbackend.hh | 20 ++--- pdns/docs/pdns.sgml | 127 +++++++++++++++++++++++++++++- pdns/dynhandler.cc | 5 +- pdns/ueberbackend.cc | 9 ++- pdns/ueberbackend.hh | 26 +++--- 15 files changed, 290 insertions(+), 121 deletions(-) diff --git a/ChangeLog b/ChangeLog index b18b7189d..f3c828c8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ Changes since 2.9.2: - configparser now strips leading spaces in arguments - improved chroot error reporting - lots of bind backend work + - we now ignore 'hint' 'forward' whatever zones Changes since 2.9.1: - removed debugging output from the webserver (found by Paul Wouters) diff --git a/TODO b/TODO index 54096cf22..95bfed5c2 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -reset yacc/lex in bindparser +don't read 'hint' and 'forward' sections bugs: pdns.conf-dist contains old descriptions diff --git a/pdns/backends/bind/bindbackend.cc b/pdns/backends/bind/bindbackend.cc index e00318ee2..bd6cfba44 100644 --- a/pdns/backends/bind/bindbackend.cc +++ b/pdns/backends/bind/bindbackend.cc @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// $Id: bindbackend.cc,v 1.4 2002/12/18 09:30:13 ahu Exp $ +// $Id: bindbackend.cc,v 1.5 2002/12/18 16:22:20 ahu Exp $ #include #include #include @@ -73,7 +73,7 @@ bool BBDomainInfo::current() if(d_checknow) return false; - if(!d_checkinterval || (time(0)-d_lastcheck&parts, Utility::pid_t ppid) { - for(map::iterator i=self->d_bbds.begin();i!=self->d_bbds.end();++i) + for(map::iterator i=us->d_bbds.begin();i!=us->d_bbds.end();++i) i->second.d_checknow=true; return "queued"; } -static void callback(const string &domain, const string &qtype, const string &content, int ttl, int prio) +static void callback(unsigned int domain_id, const string &domain, const string &qtype, const string &content, int ttl, int prio) { us->insert(domain_id,domain,qtype,content,ttl,prio); } @@ -323,7 +320,6 @@ BindBackend::BindBackend(const string &suffix) bbd.d_filename=""; bbd.d_id=0; d_bbds[0]=bbd; - d_bbds[0].d_loaded=true; } @@ -331,19 +327,19 @@ BindBackend::BindBackend(const string &suffix) extern DynListener *dl; - self=this; + us=this; dl->registerFunc("BIND-RELOAD", &DLReloadHandler); } -void BindBackend::rediscover() +void BindBackend::rediscover(string *status) { - loadConfig(); + loadConfig(status); } -void BindBackend::loadConfig() +void BindBackend::loadConfig(string* status) { - static int s_confcount; + static int domain_id; if(!getArg("config").empty()) { BindParser BP; @@ -367,7 +363,6 @@ void BindBackend::loadConfig() int rejected=0; int newdomains=0; - s_confcount++; map nbbds; @@ -376,32 +371,44 @@ void BindBackend::loadConfig() ++i) { BBDomainInfo bbd; - bbd.d_name=i->name; - bbd.d_filename=i->filename; - bbd.d_master=i->master; - - bbd.setCtime(); - bbd.setCheckInterval(getArgAsNum("check-interval")); - + if(i->type!="master" && i->type!="slave") { + L<type<<"' zone '"<name<<"'"<::const_iterator j=d_bbds.begin(); for(;j!=d_bbds.end();++j) - if(j->second.d_name==bbd.d_name) { - bbd.d_id=j->second.d_id; + if(j->second.d_name==i->name) { + bbd=j->second; break; } - if(j==d_bbds.end()) + if(j==d_bbds.end()) { // entirely new bbd.d_id=domain_id++; + bbd.setCtime(); + bbd.setCheckInterval(getArgAsNum("check-interval")); + nbbds[bbd.d_id].d_loaded=false; + } + + bbd.d_name=i->name; + bbd.d_filename=i->filename; + bbd.d_master=i->master; nbbds[bbd.d_id]=bbd; - L<name<<"' from file '"<filename<<"'"<filename,i->name); // calls callback for us - nbbds[bbd.d_id].d_loaded=true; - } - catch(AhuException &ae) { - L<name<<"' from file '"<filename<<"': "<name<<"' from file '"<filename<<"'"<filename,i->name,bbd.d_id); // calls callback for us + nbbds[bbd.d_id].d_loaded=true; // does this perform locking for us? + } + catch(AhuException &ae) { + ostringstream msg; + msg<<" error parsing '"<name<<"' from file '"<filename<<"': "< *>&tmp=d_zone_id_map[bbd.d_id]; // shrink trick @@ -410,15 +417,29 @@ void BindBackend::loadConfig() int remdomains=0; - vector oldnames, newnames; - for(map::const_iterator j=d_bbds.begin();j!=d_bbds.end();++j) - oldnames.push_back(j->second.d_name); - for(map::const_iterator j=nbbds.begin();j!=nbbds.end();++j) - newnames.push_back(j->second.d_name); + set oldnames, newnames; + for(map::const_iterator j=d_bbds.begin();j!=d_bbds.end();++j) { + oldnames.insert(j->second.d_name); + } + for(map::const_iterator j=nbbds.begin();j!=nbbds.end();++j) { + newnames.insert(j->second.d_name); + } + + vector diff; + set_difference(oldnames.begin(), oldnames.end(), newnames.begin(), newnames.end(), back_inserter(diff)); + remdomains=diff.size(); + + vector diff2; + set_difference(newnames.begin(), newnames.end(), oldnames.begin(), oldnames.end(), back_inserter(diff2)); + newdomains=diff2.size(); d_bbds.swap(nbbds); // commit + ostringstream msg; + msg<<" Done parsing domains, "<d_loaded=0; // block further access - // now nuke all records with our id - for(vector *>::const_iterator i=d_zone_id_map[bbd->d_id].begin(); - i!=d_zone_id_map[bbd->d_id].end();++i) - { - (*i)->clear(); - } - // cout<<"Now clearing the list of records"<d_id].clear(); - // now reload + // this emtpies all d_qnames vectors belonging to this domain. We find these vectors via d_zone_id_map + for(vector *>::iterator i=d_zone_id_map[bbd->d_id].begin(); + i!=d_zone_id_map[bbd->d_id].end();++i) { + (*i)->clear(); + } + // empty our d_zone_id_map of the references to the now empty vectors (which are not gone from d_qnames, btw) + d_zone_id_map[bbd->d_id].clear(); ZoneParser ZP; us=this; - domain_id=bbd->d_id; ZP.setCallback(&callback); - ZP.parse(bbd->d_filename,bbd->d_name); + ZP.parse(bbd->d_filename,bbd->d_name,bbd->d_id); bbd->setCtime(); // and raise d_loaded again! bbd->d_loaded=1; diff --git a/pdns/backends/bind/bindbackend.hh b/pdns/backends/bind/bindbackend.hh index 2b3a12e0b..ffc39b28c 100644 --- a/pdns/backends/bind/bindbackend.hh +++ b/pdns/backends/bind/bindbackend.hh @@ -40,21 +40,6 @@ class BBDomainInfo public: BBDomainInfo(); -#if 0 - BBDomainInfo(const BBDomainInfo &orig) { - d_name=orig.d_name; - d_loaded=orig.d_loaded; - d_rwlock=orig.d_rwlock; - cout<<"Copied "<<(void*)d_rwlock<<"/"<, hash_string, compare_string> c /** The BindBackend is a DNSBackend that can answer DNS related questions. It looks up data - in a Bind-style zone file */ + in a Bind-style zone file + + How this all works is quite complex and prone to change. There are a number of containers involved which, + together, contain everything we need to know about a domain or a record. + + A domain consists of records. So, 'example.com' has 'www.example.com' as a record. + + All record names are stored in the hash_map d_qnames, with their name as index. Attached to that index + is a vector of BBResourceRecords ('BindBackend') belonging to that qname. Each record contains a d_domainid, + which is the ID of the domain it belongs to. + + Then there is the map called d_bbds which has as its key the Domain ID, and attached a BBDomainInfo object, which + tells us domain metadata (place on disk, if it is a master or a slave etc). + + To allow for AXFRs, there is yet another container, the d_zone_id_map, which contains per domain_id a vector + of pointers to vectors of BBResourceRecords. When read in sequence, these deliver all records of a domain_id. + + As there is huge repitition in the right hand side of records, many records point to the same thing (IP address, nameserver), + a list of these is kept in s_contents, and each BBResourceRecord only contains a pointer to a record in s_contents. + + So, summarizing: + + class BBResourceRecord: + Everything you need to know about a record. In this context we call the name of a BBResourceRecord 'qname' + + class BBDomainInfo: + Domain metadata, like location on disk, last time zone was checked + + d_qnames >: + If you know the qname of a record, this gives you all records under that name. + + sets_contents: + Set of all 'contents' of records, the right hand sides. + + map* > > d_zone_id_map: + If you know the zone_id, this has a vector of pointers to vectors in d_qnames, for AXFR + + mapd_bbds: + Map of all domains we know about and metadata about them. + + +*/ class BindBackend : public DNSBackend { public: @@ -161,7 +187,7 @@ public: bool feedRecord(const DNSResourceRecord &r); bool commitTransaction(); void insert(int id, const string &qname, const string &qtype, const string &content, int ttl, int prio); - void rediscover(); + void rediscover(string *status=0); static HuffmanCodec s_hc; private: class handle @@ -213,5 +239,5 @@ private: void queueReload(BBDomainInfo *bbd); BBResourceRecord resourceMaker(int id, const string &qtype, const string &content, int ttl, int prio); static string DLReloadHandler(const vector&parts, Utility::pid_t ppid); - void loadConfig(); + void loadConfig(string *status=0); }; diff --git a/pdns/backends/bind/bindparser.cc b/pdns/backends/bind/bindparser.cc index b6aab10a3..5764a854f 100644 --- a/pdns/backends/bind/bindparser.cc +++ b/pdns/backends/bind/bindparser.cc @@ -205,7 +205,7 @@ static const short yyrline[] = 125, 132, 142, 144, 148, 149, 152, 155, 156, 160, 164, 165, 169, 169, 172, 179, 180, 184, 184, 184, 186, 190, 194, 195, 199, 199, 199, 199, 202, 205, - 206, 210, 216, 224, 233, 240 + 206, 210, 216, 224, 232, 239 }; #endif @@ -1058,12 +1058,11 @@ case 42: case 43: #line 226 "bindparser.yy" { - // printf("Found a filename: '%s'\n",$2); - // ztype=$2; + s_di.type=yyvsp[0]; } break; case 44: -#line 235 "bindparser.yy" +#line 234 "bindparser.yy" { yyval=yyvsp[0]; } @@ -1301,4 +1300,4 @@ yyreturn: #endif return yyresult; } -#line 241 "bindparser.yy" +#line 240 "bindparser.yy" diff --git a/pdns/backends/bind/bindparser.hh b/pdns/backends/bind/bindparser.hh index 1971037f1..3cd8dffca 100644 --- a/pdns/backends/bind/bindparser.hh +++ b/pdns/backends/bind/bindparser.hh @@ -29,11 +29,12 @@ class BindDomainInfo public: void clear() { - name=filename=master=""; + name=filename=master=type=""; } string name; string filename; string master; + string type; }; extern const char *bind_directory; diff --git a/pdns/backends/bind/bindparser.yy b/pdns/backends/bind/bindparser.yy index 68b623a44..d17a35838 100644 --- a/pdns/backends/bind/bindparser.yy +++ b/pdns/backends/bind/bindparser.yy @@ -222,10 +222,9 @@ zone_file_command: ; zone_type_command: - TYPETOK WORD +TYPETOK WORD { - // printf("Found a filename: '%s'\n",$2); - // ztype=$2; + s_di.type=$2; } ; diff --git a/pdns/backends/bind/zone2sql.cc b/pdns/backends/bind/zone2sql.cc index 8188b9b0b..cb9748ace 100644 --- a/pdns/backends/bind/zone2sql.cc +++ b/pdns/backends/bind/zone2sql.cc @@ -18,7 +18,7 @@ */ /* accepts a named.conf as parameter and outputs heaps of sql */ -// $Id: zone2sql.cc,v 1.3 2002/11/29 23:09:08 ahu Exp $ +// $Id: zone2sql.cc,v 1.4 2002/12/18 16:22:20 ahu Exp $ #ifdef WIN32 # pragma warning ( disable: 4786 ) # include @@ -64,7 +64,7 @@ bool g_intransaction; static int num_records; static string lastsoa_qname; -static void callback(const string &domain, const string &qtype, const string &content, int ttl, int prio) +static void callback(unsigned int domain_id,const string &domain, const string &qtype, const string &content, int ttl, int prio) { static int lastsoa_domain_id=-1; @@ -237,7 +237,7 @@ int main(int argc, char **argv) } lastsoa_qname=i->name; } - ZP.parse(i->filename,i->name); + ZP.parse(i->filename,i->name,0); } catch(AhuException &ae) { if(!arg().mustDo("on-error-resume-next")) @@ -256,8 +256,9 @@ int main(int argc, char **argv) ZoneParser ZP; ZP.setDirectory("."); ZP.setCallback(&callback); - ZP.parse(zonefile,arg()["zone-name"]); + ZP.parse(zonefile,arg()["zone-name"],0); dirty_hack_num++; + } cerr<<"Parsed "<&records); - typedef void callback_t(const string &domain, const string &qtype, const string &content, int ttl, int prio); + typedef void callback_t(unsigned int domain_id, const string &domain, const string &qtype, const string &content, int ttl, int prio); void setCallback(callback_t *callback); callback_t *d_callback; bool parseLine(const vector&words, vector &); diff --git a/pdns/backends/bind/zoneparser2.cc b/pdns/backends/bind/zoneparser2.cc index 58068c5a9..0cce3e6b0 100644 --- a/pdns/backends/bind/zoneparser2.cc +++ b/pdns/backends/bind/zoneparser2.cc @@ -46,7 +46,7 @@ void ZoneParser::setDirectory(const string &dir) } -void ZoneParser::parse(const string &fname, const string &origin) +void ZoneParser::parse(const string &fname, const string &origin, unsigned int domain_id) { d_filename=fname.c_str(); @@ -84,7 +84,7 @@ void ZoneParser::parse(const string &fname, const string &origin) } if(eatLine(line,rec)) for(vector::const_iterator i=rec.begin();i!=rec.end();++i) - d_callback(i->name, i->qtype,i->content,i->ttl,i->prio); + d_callback(domain_id,i->name, i->qtype,i->content,i->ttl,i->prio); } fclose(fds.top()); fds.pop(); diff --git a/pdns/dnsbackend.hh b/pdns/dnsbackend.hh index b859da2d9..b1661de3c 100644 --- a/pdns/dnsbackend.hh +++ b/pdns/dnsbackend.hh @@ -16,25 +16,25 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// $Id: dnsbackend.hh,v 1.1 2002/11/27 15:18:32 ahu Exp $ +// $Id: dnsbackend.hh,v 1.2 2002/12/18 16:22:20 ahu Exp $ /* (C) 2002 POWERDNS.COM BV */ #ifndef DNSBACKEND_HH #define DNSBACKEND_HH -class DNSPacket; - +class DNSPacket; + #include "utility.hh" #include #include #include #include -#include - -#ifndef WIN32 -# include -# include -#endif // WIN32 +#include + +#ifndef WIN32 +# include +# include +#endif // WIN32 #include "qtype.hh" #include "dns.hh" @@ -95,7 +95,7 @@ public: { } - virtual void rediscover() + virtual void rediscover(string* status=0) { } diff --git a/pdns/docs/pdns.sgml b/pdns/docs/pdns.sgml index 8bb1bc63c..7b133f846 100644 --- a/pdns/docs/pdns.sgml +++ b/pdns/docs/pdns.sgml @@ -15,7 +15,7 @@ - v2.1 $Date: 2002/12/13 15:22:33 $ + v2.1 $Date: 2002/12/18 16:22:20 $ @@ -85,6 +85,96 @@ Before proceeding, it is advised to check the release notes for your PDNS version, as specified in the name of the distribution file. + Version 2.9.3 + + Broad range of improvements. We now have an all-static .rpm and .deb for Linux users and a a link to an OpenBSD port. + Major news is that work on the Bind backend has progressed to the point that we've just retired our last Bind server and + replaced it with PowerDNS in Bind mode! This server is operating a number of master and slave setups so it should stress the Bind backend + quite a bit. + + + + + Again some changes in compilation instructions. The hybrid pgmysql backend has been split up into 'gmysql' and 'gpgsql', sharing + a common base within the PowerDNS server itself. This means that you can no longer compile + --with-modules="pgmysql" --enable-mysql --enable-pgsql but that you should now use: + --with-modules="gmysql gpgsql". The old launch-names remain available. + + + If you launch the Generic PgSQL backend as gpgsql2, all parameters will have gpsql2 as a prefix, for example + pgsql2-dbname. If launched as gpsql, the regular names are in effect. + + + + + Improvements: + + + + Bind backend can now deal with missing files and try to find them later. + + + + + General robustness improvements in Bind backend - many errors are now non-fatal. + + + + + Added support for retrieving RP (Responsible Person) records from remote masters. Serving them was already possible. + + + + + Added support for LOC records, which encode the geographical location of a host, both serving and retrieving (thanks to Marco Davids + using them on our last Bind server, forcing us to implement this silly record). + + + + + Configuration file parser now strips leading spaces too, allowing "chroot= /tmp" to work, as well as "chroot=/tmp" + (Thanks to Hub Dohmen for reporting this for months on end). + + + + + + Changes: + + + + gpgsql and gmysql backends split out of the hybdid pgmysqlbackend. This again changed compilation instructions! + + + + + + Bugfixes: + + + + Windows version did not compile without minor changes. + + + + + Confusing error reporting on Windows 98 (which does not support PowerDNS) fixed + + + + + Potential crashes with shortened packets addressed. An upgrade is advised! + + + + + pgmysql backend had problems launching when not compiled in but available as a module. Workaround for 2.9.2 is 'load-modules=pgmysql', + but even then gpgsql would not work! gmysql would then, however. These modules are now split out, removing such issues. + + + + + Version 2.9.2 Bugfixes galore. Solaris porting created some issues on all platforms. Great news is that PowerDNS is now in Debian 'sid' (unstable). The 2.9.1 @@ -4981,8 +5071,9 @@ while(<>) SuperslaveYes AutoserialYes CaseAll lower - Module namepgmysql - Lauch namegmysql and gpgsql2 + Module name < 2.9.3pgmysql + Module name > 2.9.2gmysql and gpgsql + Lauch namegmysql and gpgsql2 and gpgsql @@ -5789,6 +5880,36 @@ insert into Records (id,ZoneId, name,type,content,TimeToLive,Priority) select RE Currently disabled in prereleases. But see . + Commands + + pdns_control offers commands to communicate instructions to PowerDNS. These are detailed here. + + + rediscover + + + Reread the bind configuration file (named.conf). If parsing fails, the old configuration + remains in force and pdns_control reports the error. Any newly discovered domains are read, discarded domains + are removed from memory. + + + Except that with 2.9.3, they are not removed from memory. + + + + + + + bind-reload + + + All zones with a changed timestamp are reloaded at the next incoming query for them. + + + + + + diff --git a/pdns/dynhandler.cc b/pdns/dynhandler.cc index 72978b14e..db089f030 100644 --- a/pdns/dynhandler.cc +++ b/pdns/dynhandler.cc @@ -209,8 +209,9 @@ string DLRediscoverHandler(const vector&parts, Utility::pid_t ppid) PacketHandler P; try { L<rediscover(); - return "Ok"; + string status="Ok"; + P.getBackend()->rediscover(&status); + return status; } catch(AhuException &ae) { return ae.reason; diff --git a/pdns/ueberbackend.cc b/pdns/ueberbackend.cc index f7663c286..488fa3433 100644 --- a/pdns/ueberbackend.cc +++ b/pdns/ueberbackend.cc @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// $Id: ueberbackend.cc,v 1.5 2002/12/16 12:51:20 ahu Exp $ +// $Id: ueberbackend.cc,v 1.6 2002/12/18 16:22:20 ahu Exp $ /* (C) Copyright 2002 PowerDNS.COM BV */ #include "utility.hh" @@ -108,11 +108,14 @@ void UeberBackend::reload() } } -void UeberBackend::rediscover() +void UeberBackend::rediscover(string *status) { for ( vector< DNSBackend * >::iterator i = backends.begin(); i != backends.end(); ++i ) { - ( *i )->rediscover(); + string tmpstr; + ( *i )->rediscover(&tmpstr); + if(status) + *status+=tmpstr + (i!=backends.begin() ? "\n" : ""); } } diff --git a/pdns/ueberbackend.hh b/pdns/ueberbackend.hh index 79d812837..6ad8e5b39 100644 --- a/pdns/ueberbackend.hh +++ b/pdns/ueberbackend.hh @@ -24,18 +24,18 @@ #include #include #include -#include - -#ifndef WIN32 -#include -#include -#include -#include -#include -#include -#include -#include -#endif // WIN32 +#include + +#ifndef WIN32 +#include +#include +#include +#include +#include +#include +#include +#include +#endif // WIN32 #include "dnspacket.hh" #include "dnsbackend.hh" @@ -121,7 +121,7 @@ public: void getUnfreshSlaveInfos(vector* domains); void getUpdatedMasters(vector* domains); bool getDomainInfo(const string &domain, DomainInfo &di); - void rediscover(); + void rediscover(string* status=0); void reload(); private: DNSResourceRecord lastrr; -- 2.40.0