Changeset 510
- Timestamp:
- 10/08/05 18:12:49 (8 years ago)
- Location:
- trunk/pdns
- Files:
-
- 1 added
- 10 modified
-
pdns/Makefile.am (modified) (2 diffs)
-
pdns/dnsparser.hh (modified) (1 diff)
-
pdns/dnspbench.cc (added)
-
pdns/dnsrecords.cc (modified) (8 diffs)
-
pdns/dnswriter.cc (modified) (7 diffs)
-
pdns/dnswriter.hh (modified) (4 diffs)
-
pdns/misc.cc (modified) (1 diff)
-
pdns/rcpgenerator.cc (modified) (3 diffs)
-
pdns/rcpgenerator.hh (modified) (2 diffs)
-
pdns/sdig.cc (modified) (1 diff)
-
regression-tests/double-srv/expected_result (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/Makefile.am
r503 r510 19 19 bin_PROGRAMS = pdns_control dnswasher dnsreplay 20 20 21 EXTRA_PROGRAMS=pdns_recursor sdig pdns_control qgen dnsscope dnsreplay_mindex21 EXTRA_PROGRAMS=pdns_recursor sdig dnspbench pdns_control qgen dnsscope dnsreplay_mindex 22 22 23 23 pdns_server_SOURCES=dnspacket.cc nameserver.cc tcpreceiver.hh \ … … 45 45 sdig_SOURCES=sdig.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnswriter.hh \ 46 46 misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh 47 48 dnspbench_SOURCES=dnspbench.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnswriter.hh \ 49 misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh 50 47 51 48 52 qgen_SOURCES=resolver.cc resolver.hh misc.cc unix_utility.cc qtype.cc \ -
trunk/pdns/pdns/dnsparser.hh
r507 r510 112 112 113 113 114 void xfrLabel(string &label )114 void xfrLabel(string &label, bool compress=false) 115 115 { 116 116 label=getLabel(); -
trunk/pdns/pdns/dnsrecords.cc
r508 r510 32 32 static void report(void) 33 33 { 34 regist(1, ns_t_aaaa,&make,"AAAA");34 regist(1, ns_t_aaaa, &make, "AAAA"); 35 35 } 36 36 … … 152 152 153 153 154 boilerplate_conv(NS, ns_t_ns, conv.xfrLabel(d_content ));155 boilerplate_conv(PTR, ns_t_ptr, conv.xfrLabel(d_content ));156 boilerplate_conv(CNAME, ns_t_cname, conv.xfrLabel(d_content ));154 boilerplate_conv(NS, ns_t_ns, conv.xfrLabel(d_content, true)); 155 boilerplate_conv(PTR, ns_t_ptr, conv.xfrLabel(d_content, true)); 156 boilerplate_conv(CNAME, ns_t_cname, conv.xfrLabel(d_content, true)); 157 157 boilerplate_conv(TXT, ns_t_txt, conv.xfrText(d_text)); 158 158 boilerplate_conv(SPF, 99, conv.xfrText(d_text)); … … 175 175 boilerplate_conv(MX, ns_t_mx, 176 176 conv.xfr16BitInt(d_preference); 177 conv.xfrLabel(d_mxname );177 conv.xfrLabel(d_mxname, true); 178 178 ) 179 179 … … 205 205 206 206 boilerplate_conv(SOA, ns_t_soa, 207 conv.xfrLabel(d_mname );208 conv.xfrLabel(d_rname );207 conv.xfrLabel(d_mname, true); 208 conv.xfrLabel(d_rname, true); 209 209 conv.xfr32BitInt(d_st.serial); 210 210 conv.xfr32BitInt(d_st.refresh); … … 222 222 ) 223 223 224 225 226 224 boilerplate_conv(RRSIG, 46, 227 225 conv.xfrType(d_type); … … 237 235 ) 238 236 239 240 241 237 boilerplate_conv(DNSKEY, 48, 242 238 conv.xfr16BitInt(d_flags); … … 246 242 ) 247 243 248 249 250 251 252 244 static struct Reporter 253 245 { … … 256 248 ARecordContent::report(); 257 249 AAAARecordContent::report(); 258 // OneLabelRecordContent::report();259 250 NSRecordContent::report(); 260 251 CNAMERecordContent::report(); -
trunk/pdns/pdns/dnswriter.cc
r508 r510 2 2 #include "misc.hh" 3 3 #include "dnsparser.hh" 4 5 static const string EncodeDNSLabel(const string& input)6 {7 typedef vector<string> parts_t;8 parts_t parts;9 stringtok(parts,input,".");10 11 string ret;12 for(parts_t::const_iterator i=parts.begin(); i!=parts.end(); ++i) {13 ret.append(1, (char)i->length());14 ret.append(*i);15 }16 ret.append(1,(char)0);17 return ret;18 }19 4 20 5 DNSPacketWriter::DNSPacketWriter(vector<uint8_t>& content, const string& qname, uint16_t qtype, uint16_t qclass) … … 31 16 d_content.insert(d_content.end(), ptr, ptr + sizeof(dnsheader)); 32 17 33 string label=EncodeDNSLabel(d_qname);34 ptr=(const uint8_t*) label.c_str();35 d_ content.insert(d_content.end(), ptr, ptr + label.length());36 18 xfrLabel(qname, false); 19 d_content.insert(d_content.end(), d_record.begin(), d_record.end()); 20 d_record.clear(); 21 37 22 qtype=htons(qtype); 38 23 ptr=(const uint8_t*)&qtype; … … 59 44 d_recordqclass=qclass; 60 45 d_recordttl=ttl; 46 47 d_stuff = 0; 48 49 xfrLabel(d_recordqname, true); 50 d_content.insert(d_content.end(), d_record.begin(), d_record.end()); 51 d_record.clear(); 52 53 d_stuff = sizeof(dnsrecordheader); // this is needed to get compressed label offsets right, the dnsrecordheader will be interspersed 61 54 62 55 dnsheader* dh=reinterpret_cast<dnsheader*>( &*d_content.begin()); … … 119 112 } 120 113 121 void DNSPacketWriter::xfrLabel(const string& label) 114 115 void DNSPacketWriter::xfrLabel(const string& label, bool compress) 122 116 { 123 string encoded=EncodeDNSLabel(label); 124 const uint8_t* ptr=reinterpret_cast<const uint8_t*>(encoded.c_str()); 117 typedef vector<string> parts_t; 118 parts_t parts; 119 stringtok(parts, label, "."); 120 121 string enc; 122 unsigned int pos=d_content.size() + d_record.size() + d_stuff; // d_stuff is amount of stuff that is yet to be written out - the dnsrecordheader for example 123 string chopped(label); 124 125 for(parts_t::const_iterator i=parts.begin(); i!=parts.end(); ++i) { 126 map<string, uint16_t>::iterator li; 127 if(compress && (li=d_labelmap.find(chopped))!=d_labelmap.end()) { // see if we've written out this domain before 128 uint16_t offset=li->second; 129 offset|=0xc000; 130 enc.append(1, (char)(offset >> 8)); 131 enc.append(1, (char)(offset & 0xff)); 132 goto out; // skip trailing 0 in case of compression 133 } 134 else if(compress || d_labelmap.count(chopped)) { // if 'compress' is true, li will be equal to d_labelmap.end() 135 d_labelmap[chopped]=pos; // if untrue, we need to count 136 } 137 enc.append(1, (char)i->length()); 138 enc.append(*i); 139 pos+=i->length()+1; 140 chopOff(chopped); // www.powerdns.com -> powerdns.com -> com 141 } 142 enc.append(1,(char)0); 125 143 126 d_record.insert(d_record.end(), ptr, ptr+encoded.size()); 144 out:; 145 146 const uint8_t* ptr=reinterpret_cast<const uint8_t*>(enc.c_str()); 147 d_record.insert(d_record.end(), ptr, ptr+enc.size()); 127 148 } 128 149 … … 137 158 void DNSPacketWriter::commit() 138 159 { 139 string label=EncodeDNSLabel(d_recordqname); // write out qname 140 141 const uint8_t* ptr=(const uint8_t*) label.c_str(); 142 d_content.insert(d_content.end(), ptr, ptr + label.length()); 143 144 // write out dnsrecordheader 160 // build dnsrecordheader 145 161 struct dnsrecordheader drh; 146 162 drh.d_type=htons(d_recordqtype); … … 149 165 drh.d_clen=htons(d_record.size()); 150 166 151 ptr=(const uint8_t*)&drh; 167 // and write out the header 168 const uint8_t* ptr=(const uint8_t*)&drh; 152 169 d_content.insert(d_content.end(), ptr, ptr+sizeof(drh)); 153 170 … … 155 172 d_content.insert(d_content.end(), d_record.begin(), d_record.end()); 156 173 157 d_record.clear(); // clear d_record 174 d_record.clear(); // clear d_record, ready for next record 158 175 } 159 176 -
trunk/pdns/pdns/dnswriter.hh
r508 r510 4 4 #include <string> 5 5 #include <vector> 6 #include <map> 6 7 #include <stdint.h> 7 8 … … 39 40 enum Place {ANSWER=1, AUTHORITY=2, ADDITIONAL=3}; 40 41 42 //! Start a DNS Packet in the vector passed, with question qname, qtype and qclass 41 43 DNSPacketWriter(vector<uint8_t>& content, const string& qname, uint16_t qtype, uint16_t qclass=1); 44 45 /** Start a new DNS record within this packet for namq, qtype, ttl, class and in the requested place. Note that packets can only be written in natural order - 46 ANSWER, AUTHORITY, ADDITIONAL */ 42 47 void startRecord(const string& name, uint16_t qtype, uint32_t ttl=3600, uint16_t qclass=1, Place place=ANSWER); 48 49 /** Shorthand way to add an Opt-record, for example for EDNS0 purposes */ 43 50 void addOpt(int udpsize, int extRCode, int Z); 51 52 /** needs to be called after the last record is added, but can be called again and again later on. Is called internally by startRecord too. 53 The content of the vector<> passed to the constructor is inconsistent until commit is called. 54 */ 55 void commit(); 44 56 45 57 void xfr32BitInt(uint32_t val); … … 61 73 void xfr8BitInt(uint8_t val); 62 74 63 void xfrLabel(const string& label );75 void xfrLabel(const string& label, bool compress=false); 64 76 void xfrText(const string& text); 65 77 void xfrBlob(const string& blob); 66 void commit(); 67 78 68 79 uint16_t d_pos; 69 80 … … 77 88 uint16_t d_recordqtype, d_recordqclass; 78 89 uint32_t d_recordttl; 90 map<string, uint16_t> d_labelmap; 91 uint16_t d_stuff; 79 92 }; 80 93 #endif -
trunk/pdns/pdns/misc.cc
r504 r510 322 322 char tmp[5]; 323 323 string ret; 324 ret.resize( str.size()*2.2);324 ret.resize((int)(str.size()*2.2)); 325 325 326 326 for(string::size_type n=0;n<str.size();++n) { -
trunk/pdns/pdns/rcpgenerator.cc
r507 r510 100 100 101 101 102 void RecordTextReader::xfrLabel(string& val )102 void RecordTextReader::xfrLabel(string& val, bool) 103 103 { 104 104 skipSpaces(); … … 110 110 if(val.empty()) 111 111 val=d_zone; 112 else {112 else if(!d_zone.empty()) { 113 113 char last=val[val.size()-1]; 114 114 … … 241 241 242 242 243 void RecordTextWriter::xfrLabel(const string& val )243 void RecordTextWriter::xfrLabel(const string& val, bool) 244 244 { 245 245 if(!d_string.empty()) -
trunk/pdns/pdns/rcpgenerator.hh
r507 r510 46 46 void xfrTime(uint32_t& val); 47 47 48 void xfrLabel(string& val );48 void xfrLabel(string& val, bool compress=false); 49 49 void xfrText(string& val); 50 50 void xfrBlob(string& val); … … 70 70 71 71 void xfrType(const uint16_t& val); 72 void xfrLabel(const string& val );72 void xfrLabel(const string& val, bool compress=false); 73 73 void xfrText(const string& val); 74 74 void xfrBlob(const string& val); -
trunk/pdns/pdns/sdig.cc
r508 r510 17 17 vector<uint8_t> packet; 18 18 19 19 20 DNSPacketWriter pw(packet, argv[3], DNSRecordContent::TypeToNumber(argv[4])); 21 #if 0 22 static char*ips[]={"198.41.0.4", "192.228.79.201", "192.33.4.12", "128.8.10.90", "192.203.230.10", "192.5.5.241", "192.112.36.4", "128.63.2.53", 23 "192.36.148.17","192.58.128.30", "193.0.14.129", "198.32.64.12", "202.12.27.33"}; 24 static char templ[40]; 25 strncpy(templ,"a.root-servers.net", sizeof(templ) - 1); 26 for(char c='a';c<='m';++c) { 27 *templ=c; 28 29 pw.startRecord("", DNSRecordContent::TypeToNumber("NS")); 30 NSRecordContent nrc(templ); 31 nrc.toPacket(pw); 32 } 20 33 21 pw.setRD(true); 34 for(char c='a';c<='m';++c) { 35 *templ=c; 36 37 pw.startRecord(templ, DNSRecordContent::TypeToNumber("A"), 3600, 1, DNSPacketWriter::ADDITIONAL); 38 ARecordContent arc(ips[c-'a']); 39 arc.toPacket(pw); 40 } 41 #endif 42 pw.commit(); 22 43 44 // pw.setRD(true); 45 46 23 47 /* 24 pw.startRecord("enum.powerdns.com", DNSRecordContent::TypeToNumber("NSEC")); 48 pw.startRecord("powerdns.com", DNSRecordContent::TypeToNumber("NS")); 49 NSRecordContent nrc("ns1.powerdns.com"); 50 nrc.toPacket(pw); 25 51 26 NSECRecordContent nrc("jnum.powerdns.com SRV A AAAA RRSIG"); 27 nrc.toPacket(pw); 52 pw.startRecord("powerdns.com", DNSRecordContent::TypeToNumber("NS")); 53 NSRecordContent nrc2("ns2.powerdns.com"); 54 nrc2.toPacket(pw); 55 56 // pw.addOpt(2800, 0, 0x8000); 28 57 */ 29 30 pw.addOpt(2800, 0, 0x8000);31 58 32 59 pw.commit(); -
trunk/pdns/regression-tests/double-srv/expected_result
r509 r510 1 1 0 _double._tcp.dc.test.com. IN SRV 3600 0 100 389 server1.test.com. 2 0 _double._tcp.dc.test.com. IN SRV 3600 1 100 389 server1.test.com. 2 3 Rcode: 0, RD: 0, TC: 0, AA: 1, opcode: 0 3 4 Reply to question for qname='_double._tcp.dc.test.com.', qtype=SRV