Changeset 731
- Timestamp:
- 04/18/06 23:59:41 (7 years ago)
- Location:
- trunk/pdns/pdns
- Files:
-
- 8 modified
-
dns.hh (modified) (2 diffs)
-
dnsparser.cc (modified) (1 diff)
-
dnsrecords.cc (modified) (2 diffs)
-
iputils.hh (modified) (1 diff)
-
pdns_recursor.cc (modified) (11 diffs)
-
rec_channel_rec.cc (modified) (3 diffs)
-
syncres.cc (modified) (6 diffs)
-
syncres.hh (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/dns.hh
r681 r731 61 61 { 62 62 public: 63 DNSResourceRecord() : priority(0), d_place(ANSWER) {};63 DNSResourceRecord() : qclass(1), priority(0), d_place(ANSWER) {}; 64 64 ~DNSResourceRecord(){}; 65 65 … … 70 70 71 71 QType qtype; //!< qtype of this record, ie A, CNAME, MX etc 72 uint16_t qclass; //!< class of this record 72 73 string qname; //!< the name of this record, for example: www.powerdns.com 73 74 string content; //!< what this record points to. Example: 10.1.2.3 -
trunk/pdns/pdns/dnsparser.cc
r699 r731 55 55 stringtok(parts, tmp); 56 56 if(parts.size()!=3) 57 throw MOADNSException("Unknown record was stored incorrectly, need 3 fields, got "+lexical_cast<string>(parts.size()) );57 throw MOADNSException("Unknown record was stored incorrectly, need 3 fields, got "+lexical_cast<string>(parts.size())+": "+tmp ); 58 58 const string& relevant=parts[2]; 59 59 unsigned int total=atoi(parts[1].c_str()); -
trunk/pdns/pdns/dnsrecords.cc
r680 r731 283 283 void reportBasicTypes() 284 284 { 285 ARecordContent::report(); 286 AAAARecordContent::report(); 287 NSRecordContent::report(); 288 CNAMERecordContent::report(); 289 MXRecordContent::report(); 290 SOARecordContent::report(); 291 SRVRecordContent::report(); 292 PTRRecordContent::report(); 285 ARecordContent::report(); 286 AAAARecordContent::report(); 287 NSRecordContent::report(); 288 CNAMERecordContent::report(); 289 MXRecordContent::report(); 290 SOARecordContent::report(); 291 SRVRecordContent::report(); 292 PTRRecordContent::report(); 293 DNSRecordContent::regist(3, ns_t_txt, &TXTRecordContent::make, &TXTRecordContent::make, "TXT"); 293 294 } 294 295 295 296 void reportOtherTypes() 296 297 { 297 TXTRecordContent::report();298 298 SPFRecordContent::report(); 299 299 NAPTRRecordContent::report(); … … 307 307 OPTRecordContent::report(); 308 308 DNSRecordContent::regist(1,255, 0, 0, "ANY"); 309 TXTRecordContent::report(); 309 310 } 310 311 -
trunk/pdns/pdns/iputils.hh
r728 r731 50 50 else 51 51 return memcmp(&sin6.sin6_addr.s6_addr, &rhs.sin6.sin6_addr.s6_addr, 16) < 0; 52 } 53 54 socklen_t getSocklen() 55 { 56 if(sin4.sin_family == AF_INET) 57 return sizeof(sin4); 58 else 59 return sizeof(sin6); 52 60 } 53 61 -
trunk/pdns/pdns/pdns_recursor.cc
r730 r731 82 82 { 83 83 d_remote=*sa; 84 d_socklen= d_remote.sin4.sin_family == AF_INET ? sizeof(sockaddr_in) : sizeof(sockaddr_in6);85 84 } 86 85 … … 97 96 struct timeval d_now; 98 97 ComboAddress d_remote; 99 socklen_t d_socklen;100 98 bool d_tcp; 101 99 int d_socket; … … 459 457 sr.setCacheOnly(); 460 458 461 int res=sr.beginResolve(dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret);459 int res=sr.beginResolve(dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_mdp.d_qclass, ret); 462 460 if(res<0) { 463 461 pw.getHeader()->rcode=RCode::ServFail; … … 482 480 shuffle(ret); 483 481 for(vector<DNSResourceRecord>::const_iterator i=ret.begin();i!=ret.end();++i) { 484 pw.startRecord(i->qname, i->qtype.getCode(), i->ttl, 1, (DNSPacketWriter::Place)i->d_place); 485 486 shared_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(i->qtype.getCode(), 1, i->content)); 482 pw.startRecord(i->qname, i->qtype.getCode(), i->ttl, i->qclass, (DNSPacketWriter::Place)i->d_place); 483 shared_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(i->qtype.getCode(), i->qclass, i->content)); 487 484 488 485 drc->toPacket(pw); … … 500 497 sendit:; 501 498 if(!dc->d_tcp) { 502 sendto(dc->d_socket, &*packet.begin(), packet.size(), 0, (struct sockaddr *)(&dc->d_remote), dc->d_ socklen);499 sendto(dc->d_socket, &*packet.begin(), packet.size(), 0, (struct sockaddr *)(&dc->d_remote), dc->d_remote.getSocklen()); 503 500 } 504 501 else { … … 672 669 int newsock=accept(fd, (struct sockaddr*)&addr, &addrlen); 673 670 if(newsock>0) { 671 g_stats.addRemote(addr); 674 672 if(g_allowFrom && !g_allowFrom->match(&addr)) { 675 673 g_stats.unauthorizedTCP++; … … 698 696 } 699 697 700 701 698 void handleNewUDPQuestion(int fd, boost::any& var) 702 699 { 703 int d_len;700 int len; 704 701 char data[1500]; 705 702 ComboAddress fromaddr; 706 703 socklen_t addrlen=sizeof(fromaddr); 707 704 708 while((d_len=recvfrom(fd, data, sizeof(data), 0, (sockaddr *)&fromaddr, &addrlen)) >= 0) { 705 if((len=recvfrom(fd, data, sizeof(data), 0, (sockaddr *)&fromaddr, &addrlen)) >= 0) { 706 g_stats.addRemote(fromaddr); 709 707 if(g_allowFrom && !g_allowFrom->match(&fromaddr)) { 710 708 g_stats.unauthorizedUDP++; 711 continue;709 return; 712 710 } 713 711 714 712 try { 715 DNSComboWriter* dc = new DNSComboWriter(data, d_len, g_now);713 DNSComboWriter* dc = new DNSComboWriter(data, len, g_now); 716 714 717 715 dc->setRemote(&fromaddr); … … 792 790 } 793 791 794 795 792 void makeUDPServerSockets() 796 793 { … … 927 924 928 925 sr.setNoCache(); 929 int res=sr.beginResolve(".", QType(QType::NS), ret);926 int res=sr.beginResolve(".", QType(QType::NS), 1, ret); 930 927 if(!res) { 931 928 L<<Logger::Error<<"Refreshed . records"<<endl; … … 1176 1173 ::arg().set("hint-file", "If set, load root hints from this file")=""; 1177 1174 ::arg().set("max-cache-entries", "If set, maximum number of entries in the main cache")="0"; 1175 ::arg().set("max-negative-ttl", "maximum number of seconds to keep a negative cached entry in memory")="3600"; 1176 ::arg().set("server-id", "Returned when queried for 'server.id' TXT, defaults to hostname")=""; 1177 ::arg().set("remotes-ringbuffer-entries", "maximum number of packets to store statistics for")="0"; 1178 ::arg().set("version-string", "maximum number of packets to store statistics for")="PowerDNS Recursor "VERSION" $Id$"; 1178 1179 ::arg().set("allow-from", "If set, only allow these comma separated netmasks to recurse")="127.0.0.0/8, 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12"; 1179 1180 ::arg().set("max-tcp-per-client", "If set, maximum number of TCP sessions per client (IP address)")="0"; … … 1239 1240 } 1240 1241 1242 SyncRes::s_maxnegttl=::arg().asNum("max-negative-ttl"); 1243 SyncRes::s_serverID=::arg()["server-id"]; 1244 if(SyncRes::s_serverID.empty()) { 1245 char tmp[128]; 1246 gethostname(tmp, sizeof(tmp)-1); 1247 SyncRes::s_serverID=tmp; 1248 } 1249 1250 g_stats.remotes.resize(::arg().asNum("remotes-ringbuffer-entries")); 1251 memset(&*g_stats.remotes.begin(), 0, g_stats.remotes.size() * sizeof(RecursorStats::remotes_t::value_type)); 1241 1252 g_logCommonErrors=::arg().mustDo("log-common-errors"); 1242 1253 -
trunk/pdns/pdns/rec_channel_rec.cc
r721 r731 9 9 #include <boost/optional.hpp> 10 10 #include <boost/tuple/tuple.hpp> 11 #include <boost/format.hpp> 11 12 #include <sys/types.h> 12 13 #include <sys/stat.h> … … 182 183 } 183 184 185 string doTopRemotes() 186 { 187 typedef map<ComboAddress, int> counts_t; 188 counts_t counts; 189 190 unsigned int total=0; 191 for(RecursorStats::remotes_t::const_iterator i=g_stats.remotes.begin(); i != g_stats.remotes.end(); ++i) 192 if(i->sin4.sin_family) { 193 total++; 194 counts[*i]++; 195 } 196 197 typedef multimap<int, ComboAddress> rcounts_t; 198 rcounts_t rcounts; 199 200 for(counts_t::const_iterator i=counts.begin(); i != counts.end(); ++i) 201 rcounts.insert(make_pair(-i->second, i->first)); 202 203 ostringstream ret; 204 ret<<"Over last "<<total<<" queries:\n"; 205 format fmt("%.02f%%\t%s\n"); 206 if(total) 207 for(rcounts_t::const_iterator i=rcounts.begin(); i != rcounts.end(); ++i) 208 ret<< fmt % (-100.0*i->first/total) % i->second.toString(); 209 210 return ret.str(); 211 } 212 184 213 string RecursorControlParser::getAnswer(const string& question, RecursorControlParser::func_t** command) 185 214 { … … 210 239 if(cmd=="wipe-cache") 211 240 return doWipeCache(begin, end); 241 242 if(cmd=="top-remotes") 243 return doTopRemotes(); 212 244 213 245 return "Unknown command '"+cmd+"'\n"; -
trunk/pdns/pdns/syncres.cc
r721 r731 40 40 SyncRes::negcache_t SyncRes::s_negcache; 41 41 SyncRes::nsspeeds_t SyncRes::s_nsSpeeds; 42 42 unsigned int SyncRes::s_maxnegttl; 43 43 unsigned int SyncRes::s_queries; 44 44 unsigned int SyncRes::s_outgoingtimeouts; … … 47 47 unsigned int SyncRes::s_throttledqueries; 48 48 unsigned int SyncRes::s_nodelegated; 49 string SyncRes::s_serverID; 49 50 bool SyncRes::s_log; 50 51 … … 54 55 55 56 /** everything begins here - this is the entry point just after receiving a packet */ 56 int SyncRes::beginResolve(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret)57 int SyncRes::beginResolve(const string &qname, const QType &qtype, uint16_t qclass, vector<DNSResourceRecord>&ret) 57 58 { 58 59 s_queries++; … … 63 64 rr.qname=qname; 64 65 rr.qtype=qtype; 66 rr.qclass=1; 65 67 rr.ttl=86400; 66 68 if(qtype.getCode()==QType::PTR) … … 68 70 else 69 71 rr.content="127.0.0.1"; 72 ret.push_back(rr); 73 return 0; 74 } 75 76 if(qclass==3 && qtype.getCode()==QType::TXT && 77 (!strcasecmp(qname.c_str(), "version.bind.") || !strcasecmp(qname.c_str(), "id.server.") || !strcasecmp(qname.c_str(), "version.pdns.") ) 78 ) { 79 ret.clear(); 80 DNSResourceRecord rr; 81 rr.qname=qname; 82 rr.qtype=qtype; 83 rr.qclass=qclass; 84 rr.ttl=86400; 85 if(!strcasecmp(qname.c_str(),"version.bind.") || !strcasecmp(qname.c_str(),"version.pdns.")) 86 rr.content="\""+::arg()["version-string"]+"\""; 87 else 88 rr.content="\""+s_serverID+"\""; 70 89 ret.push_back(rr); 71 90 return 0; … … 546 565 547 566 ne.d_qname=i->qname; 548 ne.d_ttd=d_now.tv_sec + min(i->ttl, 3600U); // controversial567 ne.d_ttd=d_now.tv_sec + min(i->ttl, s_maxnegttl); // controversial 549 568 ne.d_name=qname; 550 569 ne.d_qtype=QType(0); -
trunk/pdns/pdns/syncres.hh
r721 r731 19 19 #include <boost/tuple/tuple_comparison.hpp> 20 20 #include "mtasker.hh" 21 22 /* external functions, opaque to us */ 21 #include "iputils.hh" 23 22 24 23 void primeHints(void); … … 215 214 explicit SyncRes(const struct timeval& now) : d_outqueries(0), d_tcpoutqueries(0), d_throttledqueries(0), d_timeouts(0), d_now(now), 216 215 d_cacheonly(false), d_nocache(false) { } 217 int beginResolve(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret);216 int beginResolve(const string &qname, const QType &qtype, uint16_t qclass, vector<DNSResourceRecord>&ret); 218 217 void setId(int id) 219 218 { … … 269 268 static throttle_t s_throttle; 270 269 struct timeval d_now; 270 static unsigned int s_maxnegttl; 271 static string s_serverID; 271 272 private: 272 273 struct GetBestNSAnswer; … … 312 313 }; 313 314 class Socket; 315 /* external functions, opaque to us */ 314 316 int asendtcp(const string& data, Socket* sock); 315 317 int arecvtcp(string& data, int len, Socket* sock); … … 373 375 uint64_t spoofCount; 374 376 uint64_t resourceLimits; 377 typedef vector<ComboAddress> remotes_t; 378 remotes_t remotes; 379 int d_remotepos; 380 void addRemote(const ComboAddress& remote) 381 { 382 if(!remotes.size()) 383 return; 384 385 remotes[(d_remotepos++) % remotes.size()]=remote; 386 } 375 387 }; 376 388