Changeset 658
- Timestamp:
- 04/05/2006 01:11:35 PM (3 years ago)
- Location:
- trunk/pdns/pdns
- Files:
-
- 2 modified
-
syncres.cc (modified) (8 diffs)
-
syncres.hh (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/syncres.cc
r655 r658 66 66 int SyncRes::doResolve(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret, int depth, set<GetBestNSAnswer>& beenthere) 67 67 { 68 69 68 string prefix; 70 69 if(s_log) { … … 73 72 } 74 73 75 int res ;74 int res=0; 76 75 if(!(d_nocache && qtype.getCode()==QType::NS && qname.empty())) { 77 76 if(doCNAMECacheCheck(qname,qtype,ret,depth,res)) // will reroute us if needed … … 114 113 115 114 if(!doResolve(qname,QType(QType::A), res,depth+1,beenthere) && !res.empty()) { 116 for(res_t::const_iterator i=res.begin(); i!= res.end(); ++i) 115 for(res_t::const_iterator i=res.begin(); i!= res.end(); ++i) { 117 116 if(i->qtype.getCode()==QType::A) { 118 117 uint32_t ip; … … 120 119 ret.push_back(ntohl(ip)); 121 120 } 121 } 122 122 } 123 123 if(ret.size() > 1) … … 248 248 QType sqt(qtype); 249 249 uint32_t sttl=0; 250 251 pair<string,QType> tuple(toLower(qname), QType(0)); 252 negcache_t::iterator ni=s_negcache.find(tuple); 253 254 if(ni!=s_negcache.end()) { 255 res=0; 256 if((uint32_t)d_now.tv_sec < ni->d_ttd) { 257 sttl=ni->d_ttd - d_now.tv_sec; 258 LOG<<prefix<<qname<<": Entire record '"<<toLower(qname)<<"', is negatively cached for another "<<sttl<<" seconds"<<endl; 259 res=RCode::NXDomain; 260 giveNegative=true; 261 sqname=ni->d_qname; 262 sqt=QType::SOA; 263 } 264 else { 265 LOG<<prefix<<qname<<": Entire record '"<<toLower(qname)<<"' was negatively cached, but entry expired"<<endl; 266 s_negcache.erase(ni); 267 } 268 } 269 270 if(!giveNegative) { // let's try some more 271 tuple.second=qtype; 272 LOG<<prefix<<qname<<": Looking for direct cache hit of '"<<qname<<"|"<<qtype.getName()<<"', negative cached: "<<s_negcache.count(tuple)<<endl; 273 274 res=0; 275 ni=s_negcache.find(tuple); 276 if(ni!=s_negcache.end()) { 250 // cout<<"Lookup for '"<<qname<<"|"<<qtype.getName()<<"'\n"; 251 252 pair<negcache_t::const_iterator, negcache_t::const_iterator> range=s_negcache.equal_range(tie(toLower(qname))); 253 negcache_t::iterator ni; 254 for(ni=range.first; ni != range.second; ni++) { 255 // we have something 256 if(ni->d_qtype.getCode() == 0 || ni->d_qtype == qtype) { 257 res=0; 277 258 if((uint32_t)d_now.tv_sec < ni->d_ttd) { 278 259 sttl=ni->d_ttd - d_now.tv_sec; 279 LOG<<prefix<<qname<<": "<<qtype.getName()<<" is negatively cached for another "<<sttl<<" seconds"<<endl; 280 res=RCode::NoError; // only this record doesn't exist 260 if(ni->d_qtype.getCode()) { 261 LOG<<prefix<<qname<<": "<<qtype.getName()<<" is negatively cached for another "<<sttl<<" seconds"<<endl; 262 res = RCode::NoError; 263 } 264 else { 265 LOG<<prefix<<qname<<": Entire record '"<<toLower(qname)<<"', is negatively cached for another "<<sttl<<" seconds"<<endl; 266 res= RCode::NXDomain; 267 } 281 268 giveNegative=true; 282 269 sqname=ni->d_qname; 283 sqt="SOA"; 270 sqt=QType::SOA; 271 break; 284 272 } 285 273 else { 286 LOG<<prefix<<qname<<": "<<qtype.getName()<<" was negatively cached, but entry expired"<<endl; 287 s_negcache.erase(ni); 274 LOG<<prefix<<qname<<": Entire record '"<<toLower(qname)<<"' was negatively cached, but entry expired"<<endl; 288 275 } 289 276 } … … 315 302 316 303 LOG<<endl; 317 if(found && !expired) 304 if(found && !expired) { 305 res=0; 318 306 return true; 307 } 319 308 else 320 309 LOG<<prefix<<qname<<": cache had only stale entries"<<endl; 321 310 } 311 322 312 return false; 323 313 } … … 527 517 ne.d_qname=i->qname; 528 518 ne.d_ttd=d_now.tv_sec + min(i->ttl, 3600U); // controversial 529 ne.d_ key.first=toLower(qname);530 ne.d_ key.second=QType(0);519 ne.d_name=toLower(qname); 520 ne.d_qtype=QType(0); 531 521 s_negcache.insert(ne); 532 522 negindic=true; … … 568 558 ne.d_qname=i->qname; 569 559 ne.d_ttd=d_now.tv_sec + min(3600U,i->ttl); 570 ne.d_key=make_pair(toLower(qname), qtype); 560 ne.d_name=toLower(qname); 561 ne.d_qtype=qtype; 571 562 if(qtype.getCode()) // prevents us from blacking out a whole domain 572 563 s_negcache.insert(ne); -
trunk/pdns/pdns/syncres.hh
r655 r658 26 26 struct NegCacheEntry 27 27 { 28 pair<string, QType> d_key;28 string d_name; 29 29 QType d_qtype; 30 30 string d_qname; … … 249 249 indexed_by < 250 250 ordered_unique< 251 member<NegCacheEntry, pair<string,QType>, &NegCacheEntry::d_key> 251 composite_key< 252 NegCacheEntry, 253 member<NegCacheEntry, string, &NegCacheEntry::d_name>, 254 member<NegCacheEntry, QType, &NegCacheEntry::d_qtype> 255 > 252 256 >, 253 257 ordered_non_unique<