[Pdns-users] Patch to powerdns for autoserial with gsql backend
bert hubert
ahu at ds9a.nl
Sun Feb 29 15:31:47 UTC 2004
On Thu, Feb 26, 2004 at 08:00:30AM -0500, Derrik Pates wrote:
> The attached patch adds better autoserial support, and actually
> implements the method for the gsql backend. I use it on my servers at
> work, and I've had other positive reports on it as well.
Derrik,
This will work but it is wrong from an architectural point of view. The idea
is that the DNSBackend::getSOA is dumb and that if backends have smarter
ways to determine the SOA, including the serial, they can override getSOA.
So the 'right' way to do this is to leave dnsbackend.cc along and have
gsqlbackend.cc contain the code you added to getSOA there.
Could you rework your patch? I'll promise to merge it ASAP.
Review with suggestions:
> diff -ur orig/pdns-2.9.15/modules/gmysqlbackend/gmysqlbackend.cc pdns-2.9.15/modules/gmysqlbackend/gmysqlbackend.cc
> --- orig/pdns-2.9.15/modules/gmysqlbackend/gmysqlbackend.cc Tue Jan 14 10:23:45 2003
> +++ pdns-2.9.15/modules/gmysqlbackend/gmysqlbackend.cc Wed Feb 25 17:45:48 2004
> @@ -72,6 +72,7 @@
> declare(suffix,"update-lastcheck-query","", "update domains set last_check=%d where id=%d");
> declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'");
> declare(suffix,"delete-zone-query","", "delete from records where domain_id=%d");
> + declare(suffix,"zone-serial-query","", "select max(change_date) from records where domain_id=%d");
>
>
> }
This is needed anyhow, so please keep this.
> diff -ur orig/pdns-2.9.15/modules/gpgsqlbackend/gpgsqlbackend.cc pdns-2.9.15/modules/gpgsqlbackend/gpgsqlbackend.cc
> --- orig/pdns-2.9.15/modules/gpgsqlbackend/gpgsqlbackend.cc Fri Jan 16 14:53:45 2004
> +++ pdns-2.9.15/modules/gpgsqlbackend/gpgsqlbackend.cc Wed Feb 25 17:46:15 2004
> @@ -73,6 +73,7 @@
> declare(suffix,"update-lastcheck-query","", "update domains set last_check=%d where id=%d");
> declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'");
> declare(suffix,"delete-zone-query","", "delete from records where domain_id=%d");
> + declare(suffix,"zone-serial-query","", "select max(change_date) from records where domain_id=%d");
>
>
> }
Same.
> diff -ur orig/pdns-2.9.15/pdns/backends/gsql/gsqlbackend.cc pdns-2.9.15/pdns/backends/gsql/gsqlbackend.cc
> --- orig/pdns-2.9.15/pdns/backends/gsql/gsqlbackend.cc Fri Jan 16 17:18:12 2004
> +++ pdns-2.9.15/pdns/backends/gsql/gsqlbackend.cc Wed Feb 25 17:48:47 2004
> @@ -238,6 +238,7 @@
> d_UpdateLastCheckofZoneQuery=getArg("update-lastcheck-query");
> d_InfoOfAllMasterDomainsQuery=getArg("info-all-master-query");
> d_DeleteZoneQuery=getArg("delete-zone-query");
> + d_ZoneSerialQuery=getArg("zone-serial-query");
> }
>
>
Fine up to here!
> @@ -341,6 +342,25 @@
> }
> }
> return false;
> +}
> +
> +u_int32_t GSQLBackend::fetchZoneSerial(u_int32_t domain_id)
> +{
> +
> + string format;
> + char output[1024];
> + format = d_ZoneSerialQuery;
> + snprintf(output, sizeof(output)-1, format.c_str(), domain_id);
> + try {
> + d_db->doQuery(output, d_result);
> + }
> + catch(SSqlException &e) {
> + throw AhuException("Database error trying to query serial for domain_id "+itoa(domain_id)+": "+e.txtReason());
> + }
> + if(!d_result.empty()) {
> + return (atoi(d_result[0][0].c_str()));
> + }
> + return 0;
> }
Fine too, except that it needs to be local to the gsqlbackends, 'protected'.
> bool GSQLBackend::createSlaveDomain(const string &ip, const string &domain, const string &account)
> diff -ur orig/pdns-2.9.15/pdns/backends/gsql/gsqlbackend.hh pdns-2.9.15/pdns/backends/gsql/gsqlbackend.hh
> --- orig/pdns-2.9.15/pdns/backends/gsql/gsqlbackend.hh Sat Aug 23 10:35:35 2003
> +++ pdns-2.9.15/pdns/backends/gsql/gsqlbackend.hh Wed Feb 25 17:49:41 2004
> @@ -33,6 +33,7 @@
> bool feedRecord(const DNSResourceRecord &r);
> bool createSlaveDomain(const string &ip, const string &domain, const string &account);
> bool superMasterBackend(const string &ip, const string &domain, const vector<DNSResourceRecord>&nsset, string *account, DNSBackend **db);
> + u_int32_t fetchZoneSerial(u_int32_t domain_id);
Fine too, except that it needs to be protected.
> --- orig/pdns-2.9.15/pdns/dnsbackend.cc Fri Oct 24 13:33:55 2003
> +++ pdns-2.9.15/pdns/dnsbackend.cc Wed Feb 25 17:52:38 2004
> @@ -231,6 +231,11 @@
> if(sd.hostmaster.empty())
> sd.hostmaster="hostmaster."+domain;
>
> + // try to let the backend be smart and figure this out for us faster. this
> + // should replace the following sub-optimal method.
> + if(!sd.serial)
> + sd.serial = this->fetchZoneSerial(sd.domain_id);
> +
> if(!sd.serial) { // magic time!
> DLOG(L<<Logger::Warning<<"Doing soa serialnumber autocalculation for "<<rr.qname<<endl);
This has to move to getSOA() in the gsqlbackend.
> diff -ur orig/pdns-2.9.15/pdns/dnsbackend.hh pdns-2.9.15/pdns/dnsbackend.hh
> --- orig/pdns-2.9.15/pdns/dnsbackend.hh Sat Aug 23 10:35:35 2003
> +++ pdns-2.9.15/pdns/dnsbackend.hh Wed Feb 25 17:51:48 2004
> @@ -169,6 +169,11 @@
> return false;
> }
>
> + virtual u_int32_t fetchZoneSerial(u_int32_t domain_id)
> + {
> + return 0;
> + }
> +
This needs to go.
Thanks!
--
http://www.PowerDNS.com Open source, database driven DNS Software
http://lartc.org Linux Advanced Routing & Traffic Control HOWTO
More information about the Pdns-users
mailing list