Changeset 505
- Timestamp:
- 10/02/05 15:28:51 (8 years ago)
- Location:
- trunk/pdns/pdns
- Files:
-
- 8 modified
-
dnsparser.cc (modified) (2 diffs)
-
dnsparser.hh (modified) (4 diffs)
-
dnsrecords.cc (modified) (6 diffs)
-
dnsrecords.hh (modified) (4 diffs)
-
dnswriter.cc (modified) (1 diff)
-
dnswriter.hh (modified) (1 diff)
-
rcpgenerator.cc (modified) (6 diffs)
-
rcpgenerator.hh (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/dnsparser.cc
r501 r505 154 154 ah.d_clen=ntohs(ah.d_clen); 155 155 ah.d_ttl=ntohl(ah.d_ttl); 156 157 d_startrecordpos=d_pos; // needed for getBlob later on 158 d_recordlen=ah.d_clen; 156 159 } 157 160 … … 259 262 } 260 263 } 264 265 void PacketReader::xfrBlob(string& blob) 266 { 267 blob.assign(&d_content.at(d_pos), &d_content.at(d_startrecordpos + d_recordlen - 1 ) + 1); 268 269 d_pos = d_startrecordpos + d_recordlen; 270 } -
trunk/pdns/pdns/dnsparser.hh
r502 r505 76 76 77 77 uint32_t get32BitInt(); 78 79 78 uint16_t get16BitInt(); 80 79 uint8_t get8BitInt(); … … 95 94 } 96 95 96 void xfr8BitInt(uint8_t& val) 97 { 98 val=get8BitInt(); 99 } 100 101 97 102 void xfrLabel(string &label) 98 103 { … … 104 109 text=getText(); 105 110 } 111 112 void xfrBlob(string& blob); 106 113 107 114 static uint16_t get16BitInt(const vector<unsigned char>&content, uint16_t& pos); … … 118 125 119 126 private: 127 uint16_t d_startrecordpos; // needed for getBlob later on 128 uint16_t d_recordlen; // dito 120 129 const vector<uint8_t>& d_content; 121 130 }; -
trunk/pdns/pdns/dnsrecords.cc
r502 r505 19 19 #include "dnsrecords.hh" 20 20 21 #define boilerplate(RNAME, RTYPE) \ 22 RNAME##RecordContent::DNSRecordContent* RNAME##RecordContent::make(const DNSRecord& dr, PacketReader& pr) \ 23 { \ 24 return new RNAME##RecordContent(dr, pr); \ 25 } \ 26 \ 27 RNAME##RecordContent::RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr) \ 28 { \ 29 doRecordCheck(dr); \ 30 xfrPacket(pr); \ 31 } \ 32 \ 33 RNAME##RecordContent::DNSRecordContent* RNAME##RecordContent::make(const string& zonedata) \ 34 { \ 35 return new RNAME##RecordContent(zonedata); \ 36 } \ 37 \ 38 void RNAME##RecordContent::toPacket(DNSPacketWriter& pw) \ 39 { \ 40 this->xfrPacket(pw); \ 41 } \ 42 \ 43 void RNAME##RecordContent::report(void) \ 44 { \ 45 regist(1, RTYPE, &RNAME##RecordContent::make, #RNAME); \ 46 } \ 47 \ 48 RNAME##RecordContent::RNAME##RecordContent(const string& zoneData) \ 49 { \ 50 RecordTextReader rtr(zoneData); \ 51 xfrPacket(rtr); \ 52 } \ 53 \ 54 string RNAME##RecordContent::getZoneRepresentation() const \ 55 { \ 56 string ret; \ 57 RecordTextWriter rtw(ret); \ 58 const_cast<RNAME##RecordContent*>(this)->xfrPacket(rtw); \ 59 return ret; \ 60 } 61 62 63 #define boilerplate_conv(RNAME, CONV) \ 64 template<class Convertor> \ 65 void RNAME##RecordContent::xfrPacket(Convertor& conv) \ 66 { \ 67 CONV; \ 68 } \ 69 70 71 boilerplate(A, ns_t_a) 72 73 template<class Convertor> 74 void ARecordContent::xfrPacket(Convertor& conv) 75 { 76 conv.xfrIP(d_ip); 77 } 78 21 boilerplate_conv(A, ns_t_a, conv.xfrIP(d_ip)); 22 79 23 void ARecordContent::doRecordCheck(const DNSRecord& dr) 80 24 { … … 122 66 }; 123 67 124 125 boilerplate(NS, ns_t_ns) 126 boilerplate_conv(NS, conv.xfrLabel(d_content)) 127 128 boilerplate(PTR, ns_t_ptr) 129 boilerplate_conv(PTR, conv.xfrLabel(d_content)) 130 131 boilerplate(CNAME, ns_t_cname) 132 boilerplate_conv(CNAME, conv.xfrLabel(d_content)) 133 134 boilerplate(TXT, ns_t_txt) 135 boilerplate_conv(TXT, conv.xfrText(d_text)) 136 137 138 boilerplate(HINFO, ns_t_hinfo) 139 boilerplate_conv(HINFO, conv.xfrText(d_cpu); conv.xfrText(d_host)) 140 141 boilerplate(RP, ns_t_rp) 142 boilerplate_conv(RP, conv.xfrLabel(d_mbox); conv.xfrLabel(d_info)) 143 144 145 boilerplate(MX, ns_t_mx) 68 class NSECRecordContent : public DNSRecordContent 69 { 70 public: 71 static void report(void) 72 { 73 regist(1,47 ,&make,"NSEC"); 74 } 75 76 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr) 77 { 78 NSECRecordContent* ret=new NSECRecordContent(); 79 pr.xfrLabel(ret->d_next); 80 string bitmap; 81 pr.xfrBlob(bitmap); 82 83 cout<<"get bitmap: "<<makeHexDump(bitmap)<<endl; 84 85 // 00 06 20 00 00 00 00 03 -> NS RRSIG NSEC ( 2, 46, 47 ) counts from left 86 87 if(bitmap.size() < 2) 88 throw MOADNSException("NSEC record with impossibly small bitmap"); 89 90 if(bitmap[0]) 91 throw MOADNSException("Can't deal with NSEC mappings > 255 yet"); 92 93 int len=bitmap[1]; 94 if(bitmap.size()!=2+len) 95 throw MOADNSException("Can't deal with multi-part NSEC mappings yet"); 96 97 for(int n=0 ; n < len ; ++n) { 98 uint8_t val=bitmap[2+n]; 99 for(int bit = 0; bit < 8 ; ++bit , val>>=1) 100 if(val & 1) { 101 ret->d_set.insert((7-bit) + 8*(n)); 102 } 103 } 104 105 return ret; 106 } 107 108 string getZoneRepresentation() const 109 { 110 string ret; 111 RecordTextWriter rtw(ret); 112 rtw.xfrLabel(d_next); 113 114 for(set<uint16_t>::const_iterator i=d_set.begin(); i!=d_set.end(); ++i) { 115 ret+=" "; 116 ret+=NumberToType(*i); 117 } 118 119 return ret; 120 } 121 122 private: 123 string d_next; 124 set<uint16_t> d_set; 125 }; 126 127 128 129 130 boilerplate_conv(NS, ns_t_ns, conv.xfrLabel(d_content)); 131 boilerplate_conv(PTR, ns_t_ptr, conv.xfrLabel(d_content)); 132 boilerplate_conv(CNAME, ns_t_cname, conv.xfrLabel(d_content)); 133 boilerplate_conv(TXT, ns_t_txt, conv.xfrText(d_text)); 134 boilerplate_conv(SPF, 99, conv.xfrText(d_text)); 135 boilerplate_conv(HINFO, ns_t_hinfo, conv.xfrText(d_cpu); conv.xfrText(d_host)); 136 137 boilerplate_conv(RP, ns_t_rp, 138 conv.xfrLabel(d_mbox); 139 conv.xfrLabel(d_info) 140 ); 141 146 142 147 143 MXRecordContent::MXRecordContent(uint16_t preference, const string& mxname) : d_preference(preference), d_mxname(mxname) … … 149 145 } 150 146 151 template<class Convertor> 152 void MXRecordContent::xfrPacket(Convertor& conv) 153 { 154 conv.xfr16BitInt(d_preference); 155 conv.xfrLabel(d_mxname); 156 } 157 158 boilerplate(NAPTR, ns_t_naptr) 159 160 template<class Convertor> 161 void NAPTRRecordContent::xfrPacket(Convertor& conv) 162 { 163 conv.xfr16BitInt(d_order); conv.xfr16BitInt(d_preference); 164 conv.xfrText(d_flags); conv.xfrText(d_services); conv.xfrText(d_regexp); 165 conv.xfrLabel(d_replacement); 166 } 167 168 169 boilerplate(SRV, ns_t_srv) 147 boilerplate_conv(MX, ns_t_mx, 148 conv.xfr16BitInt(d_preference); 149 conv.xfrLabel(d_mxname); 150 ) 151 152 153 boilerplate_conv(NAPTR, ns_t_naptr, 154 conv.xfr16BitInt(d_order); conv.xfr16BitInt(d_preference); 155 conv.xfrText(d_flags); conv.xfrText(d_services); conv.xfrText(d_regexp); 156 conv.xfrLabel(d_replacement); 157 ) 158 159 160 170 161 SRVRecordContent::SRVRecordContent(uint16_t preference, uint16_t weight, uint16_t port, const string& target) 171 162 : d_preference(preference), d_weight(weight), d_port(port), d_target(target) 172 163 {} 173 164 174 template<class Convertor> void SRVRecordContent::xfrPacket(Convertor& conv) 175 { 176 conv.xfr16BitInt(d_preference); conv.xfr16BitInt(d_weight); conv.xfr16BitInt(d_port); 177 conv.xfrLabel(d_target); 178 } 179 180 181 boilerplate(SOA, ns_t_soa) 165 boilerplate_conv(SRV, ns_t_srv, 166 conv.xfr16BitInt(d_preference); conv.xfr16BitInt(d_weight); conv.xfr16BitInt(d_port); 167 conv.xfrLabel(d_target); 168 ) 169 170 182 171 183 172 SOARecordContent::SOARecordContent(const string& mname, const string& rname, const struct soatimes& st) … … 187 176 } 188 177 189 template<class Convertor> 190 void SOARecordContent::xfrPacket(Convertor& conv) 191 { 192 conv.xfrLabel(d_mname); 193 conv.xfrLabel(d_rname); 194 195 conv.xfr32BitInt(d_st.serial); 196 conv.xfr32BitInt(d_st.refresh); 197 conv.xfr32BitInt(d_st.retry); 198 conv.xfr32BitInt(d_st.expire); 199 conv.xfr32BitInt(d_st.minimum); 200 } 201 178 boilerplate_conv(SOA, ns_t_soa, 179 conv.xfrLabel(d_mname); 180 conv.xfrLabel(d_rname); 181 conv.xfr32BitInt(d_st.serial); 182 conv.xfr32BitInt(d_st.refresh); 183 conv.xfr32BitInt(d_st.retry); 184 conv.xfr32BitInt(d_st.expire); 185 conv.xfr32BitInt(d_st.minimum); 186 ); 187 188 189 boilerplate_conv(DS, 43, 190 conv.xfr16BitInt(d_tag); 191 conv.xfr8BitInt(d_algorithm); 192 conv.xfr8BitInt(d_digesttype); 193 conv.xfrBlob(d_digest); 194 ) 195 196 197 198 boilerplate_conv(RRSIG, 46, 199 conv.xfr16BitInt(d_type); 200 conv.xfr8BitInt(d_algorithm); 201 conv.xfr8BitInt(d_labels); 202 203 conv.xfr32BitInt(d_originalttl); 204 conv.xfr32BitInt(d_sigexpire); 205 conv.xfr32BitInt(d_siginception); 206 conv.xfr16BitInt(d_tag); 207 conv.xfrLabel(d_signer); 208 conv.xfrBlob(d_signature); 209 ) 210 211 212 213 boilerplate_conv(DNSKEY, 48, 214 conv.xfr16BitInt(d_flags); 215 conv.xfr8BitInt(d_protocol); 216 conv.xfr8BitInt(d_algorithm); 217 conv.xfrBlob(d_key); 218 ) 219 220 221 222 202 223 203 224 static struct Reporter … … 212 233 PTRRecordContent::report(); 213 234 TXTRecordContent::report(); 235 SPFRecordContent::report(); 214 236 SOARecordContent::report(); 215 237 MXRecordContent::report(); … … 217 239 SRVRecordContent::report(); 218 240 RPRecordContent::report(); 241 DNSKEYRecordContent::report(); 242 RRSIGRecordContent::report(); 243 DSRecordContent::report(); 244 NSECRecordContent::report(); 219 245 DNSRecordContent::regist(1,255,0,"ANY"); 220 246 } -
trunk/pdns/pdns/dnsrecords.hh
r502 r505 24 24 #include "rcpgenerator.hh" 25 25 #include <boost/lexical_cast.hpp> 26 #include <set> 27 26 28 using namespace std; 27 29 using namespace boost; … … 94 96 }; 95 97 98 class SPFRecordContent : public DNSRecordContent 99 { 100 public: 101 includeboilerplate(SPF) 102 103 private: 104 string d_text; 105 }; 106 107 96 108 class NSRecordContent : public DNSRecordContent 97 109 { … … 139 151 string d_mbox, d_info; 140 152 }; 153 154 155 class DNSKEYRecordContent : public DNSRecordContent 156 { 157 public: 158 includeboilerplate(DNSKEY) 159 160 private: 161 uint16_t d_flags; 162 uint8_t d_protocol; 163 uint8_t d_algorithm; 164 string d_key; 165 }; 166 167 class DSRecordContent : public DNSRecordContent 168 { 169 public: 170 includeboilerplate(DS) 171 172 private: 173 uint16_t d_tag; 174 uint8_t d_algorithm, d_digesttype; 175 string d_digest; 176 }; 177 178 179 class RRSIGRecordContent : public DNSRecordContent 180 { 181 public: 182 includeboilerplate(RRSIG) 183 184 private: 185 uint16_t d_type; 186 uint8_t d_algorithm, d_labels; 187 uint32_t d_originalttl, d_sigexpire, d_siginception; 188 uint16_t d_tag; 189 string d_signer, d_signature; 190 }; 191 141 192 142 193 … … 165 216 }; 166 217 218 219 #define boilerplate(RNAME, RTYPE) \ 220 RNAME##RecordContent::DNSRecordContent* RNAME##RecordContent::make(const DNSRecord& dr, PacketReader& pr) \ 221 { \ 222 return new RNAME##RecordContent(dr, pr); \ 223 } \ 224 \ 225 RNAME##RecordContent::RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr) \ 226 { \ 227 doRecordCheck(dr); \ 228 xfrPacket(pr); \ 229 } \ 230 \ 231 RNAME##RecordContent::DNSRecordContent* RNAME##RecordContent::make(const string& zonedata) \ 232 { \ 233 return new RNAME##RecordContent(zonedata); \ 234 } \ 235 \ 236 void RNAME##RecordContent::toPacket(DNSPacketWriter& pw) \ 237 { \ 238 this->xfrPacket(pw); \ 239 } \ 240 \ 241 void RNAME##RecordContent::report(void) \ 242 { \ 243 regist(1, RTYPE, &RNAME##RecordContent::make, #RNAME); \ 244 } \ 245 \ 246 RNAME##RecordContent::RNAME##RecordContent(const string& zoneData) \ 247 { \ 248 RecordTextReader rtr(zoneData); \ 249 xfrPacket(rtr); \ 250 } \ 251 \ 252 string RNAME##RecordContent::getZoneRepresentation() const \ 253 { \ 254 string ret; \ 255 RecordTextWriter rtw(ret); \ 256 const_cast<RNAME##RecordContent*>(this)->xfrPacket(rtw); \ 257 return ret; \ 258 } 259 260 261 #define boilerplate_conv(RNAME, TYPE, CONV) \ 262 boilerplate(RNAME, TYPE) \ 263 template<class Convertor> \ 264 void RNAME##RecordContent::xfrPacket(Convertor& conv) \ 265 { \ 266 CONV; \ 267 } \ 268 167 269 #endif -
trunk/pdns/pdns/dnswriter.cc
r497 r505 88 88 } 89 89 90 void DNSPacketWriter::xfrBlob(const string& blob) 91 { 92 const uint8_t* ptr=reinterpret_cast<const uint8_t*>(blob.c_str()); 93 94 d_record.insert(d_record.end(), ptr, ptr+blob.size()); 95 } 96 90 97 91 98 void DNSPacketWriter::commit() -
trunk/pdns/pdns/dnswriter.hh
r502 r505 51 51 void xfrLabel(const string& label); 52 52 void xfrText(const string& text); 53 53 void xfrBlob(const string& blob); 54 54 void commit(); 55 55 -
trunk/pdns/pdns/rcpgenerator.cc
r502 r505 21 21 #include <boost/lexical_cast.hpp> 22 22 #include <iostream> 23 #include "base64.hh" 23 24 using namespace boost; 24 25 … … 63 64 if(val!=tmp) 64 65 throw RecordTextException("Overflow reading 16 bit integer from record content"); // fixme improve 66 } 67 68 void RecordTextReader::xfr8BitInt(uint8_t &val) 69 { 70 uint32_t tmp; 71 xfr32BitInt(tmp); 72 val=tmp; 73 if(val!=tmp) 74 throw RecordTextException("Overflow reading 8 bit integer from record content"); // fixme improve 65 75 } 66 76 … … 84 94 } 85 95 96 void RecordTextReader::xfrBlob(string& val) 97 { 98 skipSpaces(); 99 int pos=d_pos; 100 while(d_pos < d_end && !isspace(d_string[d_pos])) 101 d_pos++; 102 103 val.assign(d_string.c_str()+pos, d_string.c_str() + d_pos); 104 105 // XXX FIXME add base-64 decode here! 106 107 } 108 86 109 void RecordTextReader::xfrText(string& val) 87 110 { … … 102 125 throw RecordTextException("Data field in DNS should end on a quote (\") in '"+d_string+"'"); 103 126 d_pos++; 104 105 } 127 } 128 106 129 107 130 … … 149 172 } 150 173 174 void RecordTextWriter::xfr8BitInt(const uint8_t& val) 175 { 176 xfr32BitInt(val); 177 } 178 151 179 152 180 void RecordTextWriter::xfrLabel(const string& val) … … 155 183 d_string.append(1,' '); 156 184 d_string+=val; 185 } 186 187 void RecordTextWriter::xfrBlob(const string& val) 188 { 189 if(!d_string.empty()) 190 d_string.append(1,' '); 191 192 d_string+=Base64Encode(val); 157 193 } 158 194 -
trunk/pdns/pdns/rcpgenerator.hh
r502 r505 40 40 void xfr32BitInt(uint32_t& val); 41 41 void xfr16BitInt(uint16_t& val); 42 void xfr8BitInt(uint8_t& val); 42 43 43 44 void xfrIP(uint32_t& val); 44 45 void xfrLabel(string& val); 45 46 void xfrText(string& val); 47 void xfrBlob(string& val); 46 48 47 49 private: … … 59 61 void xfr32BitInt(const uint32_t& val); 60 62 void xfr16BitInt(const uint16_t& val); 63 void xfr8BitInt(const uint8_t& val); 61 64 void xfrIP(const uint32_t& val); 62 65 void xfrLabel(const string& val); 63 66 void xfrText(const string& val); 67 void xfrBlob(const string& val); 64 68 65 69 private: