From 619e8acc3a69608f31a98588045a59c1eced1ed9 Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Wed, 4 Dec 2002 15:13:02 +0000 Subject: [PATCH] solaris fixes git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@56 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- configure.in | 8 +- pdns/Makefile.am | 6 +- pdns/common_startup.cc | 528 ++++++++++++++++++++--------------------- pdns/dnspacket.hh | 3 +- 4 files changed, 272 insertions(+), 273 deletions(-) diff --git a/configure.in b/configure.in index 1737fd8a9f..0b39522c81 100644 --- a/configure.in +++ b/configure.in @@ -295,10 +295,10 @@ do pgmysql) rm -f $srcdir/modules/pgmysqlbackend/OBJECTFILES cat /dev/null > $srcdir/modules/pgmysqlbackend/OBJECTLIBS - cat /dev/null > $srcdir/modules/pgmysqlbackend/OBJECTFILES + echo gmysqlbackend.o > $srcdir/modules/pgmysqlbackend/OBJECTFILES if test -n "$domysql" then - echo smysql.o > $srcdir/modules/pgmysqlbackend/OBJECTFILES + echo smysql.o >> $srcdir/modules/pgmysqlbackend/OBJECTFILES fi if test -n "$dopgsql" @@ -309,11 +309,11 @@ do esac - for b in $(cat $srcdir/modules/${a}backend/OBJECTFILES) + for b in `cat $srcdir/modules/${a}backend/OBJECTFILES` do moduleobjects="$moduleobjects ../modules/${a}backend/$b" done - modulelibs="$modulelibs $(cat $srcdir/modules/${a}backend/OBJECTLIBS)" + modulelibs="$modulelibs `cat $srcdir/modules/${a}backend/OBJECTLIBS`" done export moduledirs moduleobjects modulelibs diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 6f81f53870..3f79c8f01d 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -4,10 +4,8 @@ AM_CPPFLAGS=-Ibackends/bind EXTRA_DIST = codedocs/Makefile codedocs/doxygen.conf docs/Makefile \ docs/gslb-operations.sgml docs/powerdns-case.sgml docs/powerdns-install.sgml \ docs/powerdns-overview.sgml docs/powerdns-technical.sgml extra/Makefile \ -extra/null.c pdns.spec release-scripts/ debian/changelog debian/conffiles \ -debian/control debian/postinst debian/postrm debian/preinst \ -debian/prerm debian/rules docs/pdns.sgml \ -LICENSE choosepaths mtasker.cc COPYING +extra/null.c pdns.spec release-scripts/ docs/pdns.sgml \ +choosepaths mtasker.cc bin_SCRIPTS = pdns sysconf_DATA = pdns.conf-dist diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 54771b4012..99e7e10454 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -16,267 +16,267 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "common_startup.hh" - -typedef Distributor DNSDistributor; - - -ArgvMap theArg; -StatBag S; //!< Statistics are gathered accross PDNS via the StatBag class S -PacketCache PC; //!< This is the main PacketCache, shared accross all threads -DNSProxy *DP; -DynListener *dl; -CommunicatorClass Communicator; -UDPNameserver *N; -int avg_latency; -TCPNameserver *TN; - -ArgvMap &arg() -{ - return theArg; -} - - -void declareArguments() -{ - arg().set("local-port","The port on which we listen")="53"; - arg().setSwitch("log-failed-updates","If PDNS should log failed update requests")=""; - arg().setSwitch("log-dns-details","If PDNS should log failed update requests")=""; - arg().set("urlredirector","Where we send hosts to that need to be url redirected")="127.0.0.1"; - arg().set("smtpredirector","Our smtpredir MX host")="a.misconfigured.powerdns.smtp.server"; - arg().set("local-address","Local IP address to which we bind")="0.0.0.0"; - arg().set("local-ipv6","Local IP address to which we bind")=""; - arg().set("max-queue-length","Maximum queuelength before considering situation lost")="5000"; - arg().set("soa-serial-offset","Make sure that no SOA serial is less than this number")="0"; - arg().set("only-soa","Make sure that no SOA serial is less than this number")="org"; - arg().setCmd("help","Provide a helpful message"); - arg().setCmd("config","Provide a helpful message"); - arg().setCmd("list-modules","Lists all modules available"); - arg().setCmd("no-config","Don't parse configuration file"); - - arg().set("control-console","Debugging switch - don't use")="no"; // but I know you will! - arg().set("fancy-records","Process URL and MBOXFW records")="no"; - arg().set("wildcard-url","Process URL and MBOXFW records")="no"; - arg().set("wildcards","Honor wildcards in the database")=""; - arg().set("loglevel","Amount of logging. Higher is more. Do not set below 3")="4"; - arg().set("default-soa-name","name to insert in the SOA record if none set in the backend")="a.misconfigured.powerdns.server"; - arg().set("distributor-threads","Default number of Distributor (backend) threads to start")="3"; - arg().set("queue-limit","Maximum number of milliseconds to queue a query")="1500"; - arg().set("recursor","If recursion is desired, IP address of a recursing nameserver")="no"; - arg().set("lazy-recursion","Only recurse if question cannot be answered locally")="yes"; - arg().set("allow-recursion","List of netmasks that are allowed to recurse")=""; - - arg().set("disable-tcp","Do not listen to TCP queries")="no"; - arg().set("disable-axfr","Do not allow zone transfers")="no"; - - arg().set("config-name","Name of this virtual configuration - will rename the binary image")=""; - - arg().set("load-modules","Load this module - supply absolute or relative path")=""; - arg().set("launch","Which backends to launch and order to query them in")=""; - arg().setSwitch("disable-axfr","Disable zonetransfers but do allow TCP queries")="no"; - arg().set("allow-axfr-ips","If disabled, DO allow zonetransfers from these IP addresses")=""; - arg().set("slave-cycle-interval","Reschedule failed SOA serial checks once every .. seconds")="60"; - - arg().setSwitch("slave","Act as a slave")="no"; - arg().setSwitch("master","Act as a master")="no"; - arg().setSwitch("guardian","Run within a guardian process")="no"; - arg().setSwitch("skip-cname","Do not perform CNAME indirection for each query")="no"; - arg().setSwitch("strict-rfc-axfrs","Perform strictly rfc compliant axfrs (very slow)")="no"; - - arg().setSwitch("webserver","Start a webserver for monitoring")="no"; - arg().setSwitch("webserver-print-arguments","If the webserver should print arguments")="no"; - arg().set("webserver-address","IP Address of webserver to listen on")="127.0.0.1"; - arg().set("webserver-port","Port of webserver to listen on")="8081"; - arg().set("webserver-password","Password required for accessing the webserver")=""; - - arg().set("receiver-threads","Number of receiver threads to launch")="1"; - - arg().setSwitch("out-of-zone-additional-processing","Do out of zone additional processing")="no"; - arg().setSwitch("query-logging","Hint backends that queries should be logged")="no"; - - arg().set("cache-ttl","Seconds to store packets in the PacketCache")="20"; - arg().set("recursive-cache-ttl","Seconds to store packets in the PacketCache")="10"; - arg().set("negquery-cache-ttl","Seconds to store packets in the PacketCache")="60"; - arg().set("query-cache-ttl","Seconds to store packets in the PacketCache")="20"; - arg().set("soa-minimum-ttl","Default SOA mininum ttl")="3600"; - arg().set("max-tcp-connections","Maximum number of TCP connections")="10"; - - arg().setSwitch( "use-logfile", "Use a log file" )= "no"; - arg().set( "logfile", "Logfile to use" )= "pdns.log"; - -} - - - -void declareStats(void) -{ - S.declare("udp-queries","Number of UDP queries received"); - S.declare("udp-answers","Number of answers sent out over UDP"); - S.declare("recursing-answers","Number of recursive answers sent out"); - S.declare("recursing-questions","Number of questions sent to recursor"); - S.declare("corrupt-packets","Number of corrupt packets received"); - - S.declare("tcp-queries","Number of TCP queries received"); - S.declare("tcp-answers","Number of answers sent out over TCP"); - - S.declare("qsize-q","Number of questions waiting for database attention"); - - S.declare("deferred-cache-inserts","Amount of cache inserts that were deferred because of maintenance"); - S.declare("deferred-cache-lookup","Amount of cache lookups that were deferred because of maintenance"); - - S.declare("query-cache-hit","Number of hits on the query cache"); - S.declare("query-cache-miss","Number of misses on the query cache"); - - - S.declare("servfail-packets","Number of times a server-failed packet was sent out"); - S.declare("latency","Average number of microseconds needed to answer a question"); - S.declare("timedout-packets","Number of packets which weren't answered within timeout set"); - - S.declareRing("queries","UDP Queries Received"); - S.declareRing("nxdomain-queries","Queries for non-existent records within existent domains"); - S.declareRing("noerror-queries","Queries for existing records, but for type we don't have"); - S.declareRing("servfail-queries","Queries that could not be answered due to backend errors"); - S.declareRing("unauth-queries","Queries for domains that we are not authoritative for"); - S.declareRing("logmessages","Log Messages"); - S.declareRing("remotes","Remote server IP addresses"); - S.declareRing("remotes-unauth","Remote hosts querying domains for which we are not auth"); - S.declareRing("remotes-corrupt","Remote hosts sending corrupt packets"); - -} - - -int isGuarded(char **argv) -{ - char *p=strstr(argv[0],"-instance"); - - return !!p; -} - - -void sendout(const DNSDistributor::AnswerData &AD) -{ - static int &numanswered=*S.getPointer("udp-answers"); - if(!AD.A) - return; - - N->send(AD.A); - numanswered++; - int diff=AD.A->d_dt.udiff(); - avg_latency=(int)(0.999*avg_latency+0.001*diff); - - delete AD.A; - - -} - - -//! The qthread receives questions over the internet via the Nameserver class, and hands them to the Distributor for futher processing -void *qthread(void *p) -{ - DNSDistributor *D=static_cast(p); - - DNSPacket *P; - - DNSPacket question; - DNSPacket cached; - - int &numreceived=*S.getPointer("udp-queries"); - int &numanswered=*S.getPointer("udp-answers"); - numreceived=-1; - int diff; - - for(;;) { - if(!((numreceived++)%50)) { // maintenance tasks - S.set("latency",(int)avg_latency); - int qcount, acount; - D->getQueueSizes(qcount, acount); - S.set("qsize-q",qcount); - } - - if(!(P=N->receive(&question))) { // receive a packet inline - continue; // packet was broken, try again - } - - - S.ringAccount("queries", P->qdomain+"/"+P->qtype.getName()); - S.ringAccount("remotes",P->getRemote()); - - if(PC.get(P,&cached)) { // short circuit - does the PacketCache recognize this question? - cached.setRemote((struct sockaddr *)(P->remote),P->d_socklen); // inlined - cached.setSocket(P->getSocket()); // inlined - cached.spoofID(P->d.id); // inlined - cached.d.rd=P->d.rd; // copy in recursion desired bit - cached.commitD(); // commit d to the packet inlined - - N->send(&cached); // answer it then inlined - diff=P->d_dt.udiff(); - avg_latency=(int)(0.999*avg_latency+0.001*diff); // 'EWMA' - - numanswered++; - continue; - } - - D->question(P, &sendout); // otherwise, give to the distributor - } - return 0; -} - - -void mainthread() -{ - Utility::srandom(time(0)); - - int newgid=0; - if(!arg()["setgid"].empty()) - newgid=Utility::makeGidNumeric(arg()["setgid"]); - int newuid=0; - if(!arg()["setuid"].empty()) - newuid=Utility::makeUidNumeric(arg()["setuid"]); - if(!arg()["chroot"].empty()) { - if(chroot(arg()["chroot"].c_str())<0) { - L<onlyFrom(arg()["allow-recursion"]); - DP->go(); - } - // NOW SAFE TO CREATE THREADS! - dl->go(); - - - - - pthread_t qtid; - StatWebServer sws; - - if(arg()["webserver"]!="no") - sws.go(); - - if(arg().mustDo("slave") || arg().mustDo("master")) - Communicator.go(); - - if(TN) - TN->go(); // tcp nameserver launch - - // fork(); (this worked :-)) - for(int n=0;n(D)); // receives packets - } - - void *p; - pthread_join(qtid, &p); - - L< DNSDistributor; + + +ArgvMap theArg; +StatBag S; //!< Statistics are gathered accross PDNS via the StatBag class S +PacketCache PC; //!< This is the main PacketCache, shared accross all threads +DNSProxy *DP; +DynListener *dl; +CommunicatorClass Communicator; +UDPNameserver *N; +int avg_latency; +TCPNameserver *TN; + +ArgvMap &arg() +{ + return theArg; +} + + +void declareArguments() +{ + arg().set("local-port","The port on which we listen")="53"; + arg().setSwitch("log-failed-updates","If PDNS should log failed update requests")=""; + arg().setSwitch("log-dns-details","If PDNS should log failed update requests")=""; + arg().set("urlredirector","Where we send hosts to that need to be url redirected")="127.0.0.1"; + arg().set("smtpredirector","Our smtpredir MX host")="a.misconfigured.powerdns.smtp.server"; + arg().set("local-address","Local IP address to which we bind")="0.0.0.0"; + arg().set("local-ipv6","Local IP address to which we bind")=""; + arg().set("max-queue-length","Maximum queuelength before considering situation lost")="5000"; + arg().set("soa-serial-offset","Make sure that no SOA serial is less than this number")="0"; + arg().set("only-soa","Make sure that no SOA serial is less than this number")="org"; + arg().setCmd("help","Provide a helpful message"); + arg().setCmd("config","Provide a helpful message"); + arg().setCmd("list-modules","Lists all modules available"); + arg().setCmd("no-config","Don't parse configuration file"); + + arg().set("control-console","Debugging switch - don't use")="no"; // but I know you will! + arg().set("fancy-records","Process URL and MBOXFW records")="no"; + arg().set("wildcard-url","Process URL and MBOXFW records")="no"; + arg().set("wildcards","Honor wildcards in the database")=""; + arg().set("loglevel","Amount of logging. Higher is more. Do not set below 3")="4"; + arg().set("default-soa-name","name to insert in the SOA record if none set in the backend")="a.misconfigured.powerdns.server"; + arg().set("distributor-threads","Default number of Distributor (backend) threads to start")="3"; + arg().set("queue-limit","Maximum number of milliseconds to queue a query")="1500"; + arg().set("recursor","If recursion is desired, IP address of a recursing nameserver")="no"; + arg().set("lazy-recursion","Only recurse if question cannot be answered locally")="yes"; + arg().set("allow-recursion","List of netmasks that are allowed to recurse")=""; + + arg().set("disable-tcp","Do not listen to TCP queries")="no"; + arg().set("disable-axfr","Do not allow zone transfers")="no"; + + arg().set("config-name","Name of this virtual configuration - will rename the binary image")=""; + + arg().set("load-modules","Load this module - supply absolute or relative path")=""; + arg().set("launch","Which backends to launch and order to query them in")=""; + arg().setSwitch("disable-axfr","Disable zonetransfers but do allow TCP queries")="no"; + arg().set("allow-axfr-ips","If disabled, DO allow zonetransfers from these IP addresses")=""; + arg().set("slave-cycle-interval","Reschedule failed SOA serial checks once every .. seconds")="60"; + + arg().setSwitch("slave","Act as a slave")="no"; + arg().setSwitch("master","Act as a master")="no"; + arg().setSwitch("guardian","Run within a guardian process")="no"; + arg().setSwitch("skip-cname","Do not perform CNAME indirection for each query")="no"; + arg().setSwitch("strict-rfc-axfrs","Perform strictly rfc compliant axfrs (very slow)")="no"; + + arg().setSwitch("webserver","Start a webserver for monitoring")="no"; + arg().setSwitch("webserver-print-arguments","If the webserver should print arguments")="no"; + arg().set("webserver-address","IP Address of webserver to listen on")="127.0.0.1"; + arg().set("webserver-port","Port of webserver to listen on")="8081"; + arg().set("webserver-password","Password required for accessing the webserver")=""; + + arg().set("receiver-threads","Number of receiver threads to launch")="1"; + + arg().setSwitch("out-of-zone-additional-processing","Do out of zone additional processing")="no"; + arg().setSwitch("query-logging","Hint backends that queries should be logged")="no"; + + arg().set("cache-ttl","Seconds to store packets in the PacketCache")="20"; + arg().set("recursive-cache-ttl","Seconds to store packets in the PacketCache")="10"; + arg().set("negquery-cache-ttl","Seconds to store packets in the PacketCache")="60"; + arg().set("query-cache-ttl","Seconds to store packets in the PacketCache")="20"; + arg().set("soa-minimum-ttl","Default SOA mininum ttl")="3600"; + arg().set("max-tcp-connections","Maximum number of TCP connections")="10"; + + arg().setSwitch( "use-logfile", "Use a log file" )= "no"; + arg().set( "logfile", "Logfile to use" )= "pdns.log"; + +} + + + +void declareStats(void) +{ + S.declare("udp-queries","Number of UDP queries received"); + S.declare("udp-answers","Number of answers sent out over UDP"); + S.declare("recursing-answers","Number of recursive answers sent out"); + S.declare("recursing-questions","Number of questions sent to recursor"); + S.declare("corrupt-packets","Number of corrupt packets received"); + + S.declare("tcp-queries","Number of TCP queries received"); + S.declare("tcp-answers","Number of answers sent out over TCP"); + + S.declare("qsize-q","Number of questions waiting for database attention"); + + S.declare("deferred-cache-inserts","Amount of cache inserts that were deferred because of maintenance"); + S.declare("deferred-cache-lookup","Amount of cache lookups that were deferred because of maintenance"); + + S.declare("query-cache-hit","Number of hits on the query cache"); + S.declare("query-cache-miss","Number of misses on the query cache"); + + + S.declare("servfail-packets","Number of times a server-failed packet was sent out"); + S.declare("latency","Average number of microseconds needed to answer a question"); + S.declare("timedout-packets","Number of packets which weren't answered within timeout set"); + + S.declareRing("queries","UDP Queries Received"); + S.declareRing("nxdomain-queries","Queries for non-existent records within existent domains"); + S.declareRing("noerror-queries","Queries for existing records, but for type we don't have"); + S.declareRing("servfail-queries","Queries that could not be answered due to backend errors"); + S.declareRing("unauth-queries","Queries for domains that we are not authoritative for"); + S.declareRing("logmessages","Log Messages"); + S.declareRing("remotes","Remote server IP addresses"); + S.declareRing("remotes-unauth","Remote hosts querying domains for which we are not auth"); + S.declareRing("remotes-corrupt","Remote hosts sending corrupt packets"); + +} + + +int isGuarded(char **argv) +{ + char *p=strstr(argv[0],"-instance"); + + return !!p; +} + + +void sendout(const DNSDistributor::AnswerData &AD) +{ + static int &numanswered=*S.getPointer("udp-answers"); + if(!AD.A) + return; + + N->send(AD.A); + numanswered++; + int diff=AD.A->d_dt.udiff(); + avg_latency=(int)(0.999*avg_latency+0.001*diff); + + delete AD.A; + + +} + + +//! The qthread receives questions over the internet via the Nameserver class, and hands them to the Distributor for futher processing +void *qthread(void *p) +{ + DNSDistributor *D=static_cast(p); + + DNSPacket *P; + + DNSPacket question; + DNSPacket cached; + + int &numreceived=*S.getPointer("udp-queries"); + int &numanswered=*S.getPointer("udp-answers"); + numreceived=-1; + int diff; + + for(;;) { + if(!((numreceived++)%50)) { // maintenance tasks + S.set("latency",(int)avg_latency); + int qcount, acount; + D->getQueueSizes(qcount, acount); + S.set("qsize-q",qcount); + } + + if(!(P=N->receive(&question))) { // receive a packet inline + continue; // packet was broken, try again + } + + + S.ringAccount("queries", P->qdomain+"/"+P->qtype.getName()); + S.ringAccount("remotes",P->getRemote()); + + if(PC.get(P,&cached)) { // short circuit - does the PacketCache recognize this question? + cached.setRemote((struct sockaddr *)(P->remote),P->d_socklen); // inlined + cached.setSocket(P->getSocket()); // inlined + cached.spoofID(P->d.id); // inlined + cached.d.rd=P->d.rd; // copy in recursion desired bit + cached.commitD(); // commit d to the packet inlined + + N->send(&cached); // answer it then inlined + diff=P->d_dt.udiff(); + avg_latency=(int)(0.999*avg_latency+0.001*diff); // 'EWMA' + + numanswered++; + continue; + } + + D->question(P, &sendout); // otherwise, give to the distributor + } + return 0; +} + + +void mainthread() +{ + Utility::srandom(time(0)); + + int newgid=0; + if(!arg()["setgid"].empty()) + newgid=Utility::makeGidNumeric(arg()["setgid"]); + int newuid=0; + if(!arg()["setuid"].empty()) + newuid=Utility::makeUidNumeric(arg()["setuid"]); + if(!arg()["chroot"].empty()) { + if(chroot(arg()["chroot"].c_str())<0) { + L<onlyFrom(arg()["allow-recursion"]); + DP->go(); + } + // NOW SAFE TO CREATE THREADS! + dl->go(); + + + + + pthread_t qtid; + StatWebServer sws; + + if(arg()["webserver"]!="no") + sws.go(); + + if(arg().mustDo("slave") || arg().mustDo("master")) + Communicator.go(); + + if(TN) + TN->go(); // tcp nameserver launch + + // fork(); (this worked :-)) + for(int n=0;n(D)); // receives packets + } + + void *p; + pthread_join(qtid, &p); + + L<