From: Pieter Lexis Date: Wed, 14 Feb 2018 10:41:18 +0000 (+0100) Subject: ixfrdist: Guard all reads and writes on g_soas X-Git-Tag: dnsdist-1.3.0~104^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=26ecdd799a87e130aab1b3a4859e974613d53e10;p=thirdparty%2Fpdns.git ixfrdist: Guard all reads and writes on g_soas --- diff --git a/pdns/ixfrdist.cc b/pdns/ixfrdist.cc index d8d4150dec..7e7d626d35 100644 --- a/pdns/ixfrdist.cc +++ b/pdns/ixfrdist.cc @@ -194,8 +194,13 @@ void updateThread() { } time_t now = time(nullptr); for (const auto &domain : g_domains) { - if ((g_soas.find(domain) != g_soas.end() && now - lastCheck[domain] < g_soas[domain]->d_st.refresh) || // Only check if we have waited `refresh` seconds - (g_soas.find(domain) == g_soas.end() && now - lastCheck[domain] < 30)) { // Or if we could not get an update at all still, every 30 seconds + shared_ptr current_soa; + if (g_soas.find(domain) != g_soas.end()) { + std::lock_guard guard(g_soas_mutex); + current_soa = g_soas[domain]; + } + if ((current_soa != nullptr && now - lastCheck[domain] < current_soa->d_st.refresh) || // Only check if we have waited `refresh` seconds + (current_soa == nullptr && now - lastCheck[domain] < 30)) { // Or if we could not get an update at all still, every 30 seconds continue; } string dir = g_workdir + "/" + domain.toString(); @@ -206,11 +211,11 @@ void updateThread() { try { lastCheck[domain] = now; auto newSerial = getSerialFromMaster(g_master, domain, sr); // TODO TSIG - if(g_soas.find(domain) != g_soas.end()) { + if(current_soa != nullptr) { if (g_verbose) { - cerr<<"[INFO] Got SOA Serial for "<d_st.serial; + cerr<<"[INFO] Got SOA Serial for "<d_st.serial; } - if (newSerial == g_soas[domain]->d_st.serial) { + if (newSerial == current_soa->d_st.serial) { if (g_verbose) { cerr<<", not updating."< soa; try { AXFRRetriever axfr(g_master, domain, tt, &local); @@ -331,7 +338,10 @@ bool makeSOAPacket(const MOADNSParser& mdp, vector& packet) { pw.getHeader()->qr = 1; pw.startRecord(mdp.d_qname, QType::SOA); - g_soas[mdp.d_qname]->toPacket(pw); + { + std::lock_guard guard(g_soas_mutex); + g_soas[mdp.d_qname]->toPacket(pw); + } pw.commit(); return true; @@ -418,7 +428,11 @@ bool makeIXFRPackets(const MOADNSParser& mdp, const shared_ptr string dir = g_workdir + "/" + mdp.d_qname.toString(); // Get the new SOA only once, so it will not change under our noses from the // updateThread. - uint32_t newSerial = g_soas[mdp.d_qname]->d_st.serial; + uint32_t newSerial; + { + std::lock_guard guard(g_soas_mutex); + newSerial = g_soas[mdp.d_qname]->d_st.serial; + } if (rfc1982LessThan(newSerial, clientSOA->d_st.serial)){ /* RFC 1995 Section 2