Changeset 1433
- Timestamp:
- 10/13/09 21:33:08 (5 months ago)
- Location:
- trunk/pdns/pdns
- Files:
-
- 3 added
- 4 modified
-
Makefile.am (modified) (3 diffs)
-
dist-recursor (modified) (2 diffs)
-
dns.cc (added)
-
dns.hh (modified) (1 diff)
-
pdns_recursor.cc (modified) (15 diffs)
-
recpacketcache.cc (added)
-
recpacketcache.hh (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/Makefile.am
r1401 r1433 30 30 session.cc session.hh misc.cc misc.hh receiver.cc ueberbackend.cc \ 31 31 dynlistener.cc dynlistener.hh dynhandler.cc dynhandler.hh \ 32 resolver.hh resolver.cc communicator.cc communicator.hh dnsproxy.cc \32 resolver.hh resolver.cc slavecommunicator.cc mastercommunicator.cc communicator.hh dnsproxy.cc \ 33 33 dnsproxy.hh randombackend.cc unix_utility.cc common_startup.cc \ 34 34 utility.hh iputils.hh common_startup.hh unix_semaphore.cc \ … … 42 42 aes/aescrypt.c aes/aes.h aes/aeskey.c aes/aes_modes.c aes/aesopt.h \ 43 43 aes/aestab.c aes/aestab.h aes/brg_endian.h aes/brg_types.h aes/dns_random.cc \ 44 randomhelper.cc 44 randomhelper.cc 45 45 46 46 # … … 127 127 rec_channel_rec.cc selectmplexer.cc epollmplexer.cc sillyrecords.cc htimer.cc htimer.hh \ 128 128 aes/dns_random.cc aes/aescrypt.c aes/aeskey.c aes/aestab.c aes/aes_modes.c \ 129 lua-pdns-recursor.cc lua-pdns-recursor.hh randomhelper.cc 129 lua-pdns-recursor.cc lua-pdns-recursor.hh randomhelper.cc \ 130 recpacketcache.cc recpacketcache.hh dns.cc 130 131 131 132 if NEDMALLOC -
trunk/pdns/pdns/dist-recursor
r1424 r1433 7 7 mplexer.hh win32_mtasker.hh win32_utility.cc ntservice.hh singleton.hh \ 8 8 recursorservice.hh dns_random.hh lua-pdns-recursor.hh namespaces.hh \ 9 md5.hh"9 recpacketcache.hh" 10 10 11 11 CFILES="syncres.cc misc.cc unix_utility.cc qtype.cc \ … … 16 16 win32_mtasker.cc win32_rec_channel.cc win32_logger.cc ntservice.cc \ 17 17 recursorservice.cc sillyrecords.cc lua-pdns-recursor.cc randomhelper.cc \ 18 md5.cc devpollmplexer.cc"18 devpollmplexer.cc recpacketcache.cc dns.cc" 19 19 20 20 cd docs -
trunk/pdns/pdns/dns.hh
r1273 r1433 249 249 #define L theL() 250 250 extern time_t s_starttime; 251 252 #endif 251 std::string questionExpand(const char* packet, uint16_t len, uint16_t& type); 252 #endif -
trunk/pdns/pdns/pdns_recursor.cc
r1430 r1433 26 26 27 27 #include <boost/foreach.hpp> 28 #include "recpacketcache.hh" 28 29 #include "utility.hh" 29 30 #include "dns_random.hh" 30 #include "md5.hh"31 31 #include <iostream> 32 32 #include <errno.h> … … 74 74 bool g_logCommonErrors; 75 75 shared_ptr<PowerDNSLua> g_pdl; 76 RecursorPacketCache g_packetCache; 77 76 78 #include "namespaces.hh" 77 79 … … 80 82 #include <semaphore.h> 81 83 #endif 82 map<string, string> g_packetCache; 84 83 85 84 86 MemRecursorCache RC; … … 95 97 map<int, ComboAddress> g_listenSocketsAddresses; // is shared across all threads right now 96 98 struct DNSComboWriter { 97 DNSComboWriter(const char* data, uint16_t len, const st d::string& hash, const struct timeval& now) : d_mdp(data, len), d_now(now),98 d_hash(hash),d_tcp(false), d_socket(-1)99 DNSComboWriter(const char* data, uint16_t len, const struct timeval& now) : d_mdp(data, len), d_now(now), 100 d_tcp(false), d_socket(-1) 99 101 {} 100 102 MOADNSParser d_mdp; … … 116 118 struct timeval d_now; 117 119 ComboAddress d_remote; 118 string d_hash;119 120 bool d_tcp; 120 121 int d_socket; … … 603 604 } 604 605 } 606 uint32_t minTTL=numeric_limits<uint32_t>::max(); 605 607 if(res<0) { 606 608 pw.getHeader()->rcode=RCode::ServFail; … … 622 624 } 623 625 626 624 627 if(ret.size()) { 625 628 shuffle(ret); … … 628 631 for(vector<DNSResourceRecord>::const_iterator i=ret.begin(); i!=ret.end(); ++i) { 629 632 pw.startRecord(i->qname, i->qtype.getCode(), i->ttl, i->qclass, (DNSPacketWriter::Place)i->d_place); 630 633 minTTL = min(minTTL, i->ttl); 631 634 if(i->qtype.getCode() == QType::A) { // blast out A record w/o doing whole dnswriter thing 632 635 uint32_t ip=0; … … 651 654 if(!dc->d_tcp) { 652 655 sendto(dc->d_socket, (const char*)&*packet.begin(), packet.size(), 0, (struct sockaddr *)(&dc->d_remote), dc->d_remote.getSocklen()); 653 if(pw.getHeader()->rcode==RCode::NoError || pw.getHeader()->rcode==RCode::NXDomain ) 654 g_packetCache[dc->d_hash]=string((const char*)&*packet.begin(), packet.size()); 655 else 656 ; // cerr<<"rcode:" <<(int)pw.getHeader()->rcode<<endl; 656 g_packetCache.insertResponsePacket(string((const char*)&*packet.begin(), packet.size()), g_now.tv_sec, 657 min(minTTL, 658 pw.getHeader()->rcode == RCode::ServFail ? (uint32_t)60 : (uint32_t) 3600 659 ) 660 ); 657 661 } 658 662 else { … … 800 804 DNSComboWriter* dc=0; 801 805 try { 802 dc=new DNSComboWriter(tconn.data, tconn.qlen, string(),g_now);806 dc=new DNSComboWriter(tconn.data, tconn.qlen, g_now); 803 807 } 804 808 catch(MOADNSException &mde) { … … 867 871 } 868 872 869 void questionExpand(const char* packet, uint16_t len, char* qname, int maxlen, uint16_t& type)870 {871 type=0;872 const unsigned char* end=(const unsigned char*)packet+len;873 unsigned char* lbegin=(unsigned char*)packet+12;874 unsigned char* pos=lbegin;875 unsigned char labellen;876 877 // 3www4ds9a2nl0878 char *dst=qname;879 char* lend=dst + maxlen;880 881 if(!*pos)882 *dst++='.';883 884 while((labellen=*pos++) && pos < end) { // "scan and copy"885 if(dst >= lend)886 throw runtime_error("Label length exceeded destination length");887 for(;labellen;--labellen)888 *dst++ = *pos++;889 *dst++='.';890 }891 *dst=0;892 893 if(pos + labellen + 2 <= end) // is this correct XXX FIXME?894 type=(*pos)*256 + *(pos+1);895 896 897 // cerr<<"Returning: '"<< string(tmp+1, pos) <<"'\n";898 }899 900 string questionExpand(const char* packet, uint16_t len, uint16_t& type)901 {902 char tmp[512];903 questionExpand(packet, len, tmp, sizeof(tmp), type);904 return tmp;905 }906 873 907 874 … … 936 903 else { 937 904 ++g_stats.qcounter; 938 uint16_t tmp = dh->id; 939 dh->id=0; 940 941 MD5Summer md5s; 942 md5s.feed(data, len); 943 string hash = md5s.get(); 944 // cerr<<"hash: "<<makeHexDump(hash)<<endl; 945 dh->id=tmp; 946 947 if(g_packetCache.count(hash)) { 905 906 string response; 907 if(g_packetCache.getResponsePacket(string(data, len), g_now.tv_sec, &response)) { 948 908 g_stats.packetCacheHits++; 949 909 SyncRes::s_queries++; 950 string reply=g_packetCache[hash]; 951 ((struct dnsheader*)reply.c_str())->id=tmp; 952 sendto(fd, reply.c_str(), reply.length(), 0, (struct sockaddr*) &fromaddr, fromaddr.getSocklen()); 910 sendto(fd, response.c_str(), response.length(), 0, (struct sockaddr*) &fromaddr, fromaddr.getSocklen()); 953 911 return; 954 912 } 955 913 956 DNSComboWriter* dc = new DNSComboWriter(data, len, hash,g_now);914 DNSComboWriter* dc = new DNSComboWriter(data, len, g_now); 957 915 dc->setSocket(fd); 958 916 dc->setRemote(&fromaddr); … … 1658 1616 if(::arg().mustDo("export-etc-hosts")) { 1659 1617 string line; 1660 string fname ;1661 1662 ifstream ifs( "/etc/hosts");1618 string fname=::arg()["etc-hosts-file"]; 1619 1620 ifstream ifs(fname.c_str()); 1663 1621 if(!ifs) { 1664 1622 L<<Logger::Warning<<"Could not open /etc/hosts for reading"<<endl; … … 2015 1973 Utility::gettimeofday(&g_now, 0); 2016 1974 t_fdm->run(&g_now); 2017 Utility::gettimeofday(&g_now, 0);1975 // 'run' updates g_now for us 2018 1976 2019 1977 if(listenOnTCP) { … … 2140 2098 ::arg().set("forward-zones-file", "File with domain=ip pairs for forwarding")=""; 2141 2099 ::arg().set("export-etc-hosts", "If we should serve up contents from /etc/hosts")="off"; 2100 ::arg().set("etc-hosts-file", "Path to 'hosts' file")="/etc/hosts"; 2142 2101 ::arg().set("serve-rfc1918", "If we should be authoritative for RFC 1918 private IP space")=""; 2143 2102 ::arg().set("auth-can-lower-ttl", "If we follow RFC 2181 to the letter, an authoritative server can lower the TTL of NS records")="off";