root/trunk/pdns/pdns/dnsrecords.cc @ 670

Revision 670, 7.7 KB (checked in by ahu, 4 years ago)

1) make everyting intrinsically case-insensitive
2) clear up . oddness, removing all calls to toLowerCanonic

Line 
1/*
2    PowerDNS Versatile Database Driven Nameserver
3    Copyright (C) 2005  PowerDNS.COM BV
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License version 2 as
7    published by the Free Software Foundation
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17*/
18
19#include "dnsrecords.hh"
20
21boilerplate_conv(A, ns_t_a, conv.xfrIP(d_ip));
22
23uint32_t ARecordContent::getIP() const
24{
25  return d_ip;
26}
27
28void ARecordContent::doRecordCheck(const DNSRecord& dr)
29{ 
30  if(dr.d_clen!=4)
31    throw MOADNSException("Wrong size for A record ("+lexical_cast<string>(dr.d_clen)+")");
32}
33
34class AAAARecordContent : public DNSRecordContent
35{
36public:
37  AAAARecordContent() : DNSRecordContent(ns_t_aaaa)
38  {}
39
40  static void report(void)
41  {
42    regist(1, ns_t_aaaa, &make, &make, "AAAA");
43  }
44
45  static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr) 
46  {
47    if(dr.d_clen!=16)
48      throw MOADNSException("Wrong size for AAAA record");
49
50    AAAARecordContent* ret=new AAAARecordContent();
51    pr.copyRecord((unsigned char*) &ret->d_ip6, 16);
52    return ret;
53  }
54
55  static DNSRecordContent* make(const string& zone) 
56  {
57    AAAARecordContent *ar=new AAAARecordContent();
58    if(Utility::inet_pton( AF_INET6, zone.c_str(), static_cast< void * >( ar->d_ip6 )) < 0)
59      throw MOADNSException("Asked to encode '"+zone+"' as an IPv6 address, but does not parse");
60    return ar;
61  }
62
63  void toPacket(DNSPacketWriter& pw)
64  {
65    string blob(d_ip6, d_ip6+16);
66    pw.xfrBlob(blob);
67  }
68 
69  string getZoneRepresentation() const
70  {
71    ostringstream str;
72
73    char hex[4];
74    for(size_t n=0; n< 16 ; n+=2) {
75      snprintf(hex,sizeof(hex)-1, "%x", d_ip6[n]);
76      str << hex;
77      snprintf(hex,sizeof(hex)-1, "%02x", d_ip6[n+1]);
78      str << hex;
79      if(n!=14)
80        str<<":";
81    }
82
83    return str.str();
84  }
85
86private:
87  unsigned char d_ip6[16];
88};
89
90
91void NSECRecordContent::report(void)
92{
93  regist(1, 47, &make, &make, "NSEC");
94}
95
96DNSRecordContent* NSECRecordContent::make(const string& content)
97{
98  return new NSECRecordContent(content);
99}
100
101NSECRecordContent::NSECRecordContent(const string& content, const string& zone) : DNSRecordContent(47)
102{
103  RecordTextReader rtr(content, zone);
104  rtr.xfrLabel(d_next);
105
106  while(!rtr.eof()) {
107    uint16_t type;
108    rtr.xfrType(type);
109    d_set.insert(type);
110  }
111}
112
113void NSECRecordContent::toPacket(DNSPacketWriter& pw)
114{
115  pw.xfrLabel(d_next);
116
117  uint8_t res[34];
118  memset(res, 0, sizeof(res));
119
120  set<uint16_t>::const_iterator i;
121  for(i=d_set.begin(); i != d_set.end() && *i<255; ++i){
122    res[2+*i/8] |= 1 << (7-(*i%8));
123  }
124  int len=0;
125  if(!d_set.empty()) 
126    len=1+*--i/8;
127
128  res[1]=len;
129
130  string tmp;
131  tmp.assign(res, res+len+2);
132  pw.xfrBlob(tmp);
133}
134
135NSECRecordContent::DNSRecordContent* NSECRecordContent::make(const DNSRecord &dr, PacketReader& pr) 
136{
137  NSECRecordContent* ret=new NSECRecordContent();
138  pr.xfrLabel(ret->d_next);
139  string bitmap;
140  pr.xfrBlob(bitmap);
141 
142  // 00 06 20 00 00 00 00 03  -> NS RRSIG NSEC  ( 2, 46, 47 ) counts from left
143 
144  if(bitmap.size() < 2)
145    throw MOADNSException("NSEC record with impossibly small bitmap");
146 
147  if(bitmap[0])
148    throw MOADNSException("Can't deal with NSEC mappings > 255 yet");
149 
150  unsigned int len=bitmap[1];
151  if(bitmap.size()!=2+len)
152    throw MOADNSException("Can't deal with multi-part NSEC mappings yet");
153 
154  for(unsigned int n=0 ; n < len ; ++n) {
155    uint8_t val=bitmap[2+n];
156    for(int bit = 0; bit < 8 ; ++bit , val>>=1)
157      if(val & 1) {
158        ret->d_set.insert((7-bit) + 8*(n));
159      }
160  }
161 
162  return ret;
163}
164
165string NSECRecordContent::getZoneRepresentation() const
166{
167  string ret;
168  RecordTextWriter rtw(ret);
169  rtw.xfrLabel(d_next);
170 
171  for(set<uint16_t>::const_iterator i=d_set.begin(); i!=d_set.end(); ++i) {
172    ret+=" ";
173    ret+=NumberToType(*i);
174  }
175 
176  return ret;
177}
178
179
180
181boilerplate_conv(NS, ns_t_ns, conv.xfrLabel(d_content, true));
182boilerplate_conv(PTR, ns_t_ptr, conv.xfrLabel(d_content, true));
183boilerplate_conv(CNAME, ns_t_cname, conv.xfrLabel(d_content, true));
184boilerplate_conv(TXT, ns_t_txt, conv.xfrText(d_text));
185boilerplate_conv(SPF, 99, conv.xfrText(d_text));
186boilerplate_conv(HINFO, ns_t_hinfo,  conv.xfrText(d_cpu);   conv.xfrText(d_host));
187
188boilerplate_conv(RP, ns_t_rp,
189                 conv.xfrLabel(d_mbox);   
190                 conv.xfrLabel(d_info)
191                 );
192
193
194boilerplate_conv(OPT, ns_t_opt,
195                 conv.xfrText(d_data)
196                 );
197
198MXRecordContent::MXRecordContent(uint16_t preference, const string& mxname) : DNSRecordContent(ns_t_mx), d_preference(preference), d_mxname(mxname)
199{
200}
201
202boilerplate_conv(MX, ns_t_mx, 
203                 conv.xfr16BitInt(d_preference);
204                 conv.xfrLabel(d_mxname, true);
205                 )
206
207
208boilerplate_conv(NAPTR, ns_t_naptr,
209                 conv.xfr16BitInt(d_order);    conv.xfr16BitInt(d_preference);
210                 conv.xfrText(d_flags);        conv.xfrText(d_services);         conv.xfrText(d_regexp);
211                 conv.xfrLabel(d_replacement);
212                 )
213
214
215
216SRVRecordContent::SRVRecordContent(uint16_t preference, uint16_t weight, uint16_t port, const string& target) 
217  : DNSRecordContent(ns_t_srv), d_preference(preference), d_weight(weight), d_port(port), d_target(target)
218{}
219
220boilerplate_conv(SRV, ns_t_srv, 
221                 conv.xfr16BitInt(d_preference);   conv.xfr16BitInt(d_weight);   conv.xfr16BitInt(d_port);
222                 conv.xfrLabel(d_target);
223                 )
224
225
226
227SOARecordContent::SOARecordContent(const string& mname, const string& rname, const struct soatimes& st) 
228  : DNSRecordContent(ns_t_soa), d_mname(mname), d_rname(rname)
229{
230  d_st=st;
231}
232
233boilerplate_conv(SOA, ns_t_soa, 
234                 conv.xfrLabel(d_mname, true);
235                 conv.xfrLabel(d_rname, true);
236                 conv.xfr32BitInt(d_st.serial);
237                 conv.xfr32BitInt(d_st.refresh);
238                 conv.xfr32BitInt(d_st.retry);
239                 conv.xfr32BitInt(d_st.expire);
240                 conv.xfr32BitInt(d_st.minimum);
241                 );
242
243
244boilerplate_conv(DS, 43, 
245                 conv.xfr16BitInt(d_tag); 
246                 conv.xfr8BitInt(d_algorithm); 
247                 conv.xfr8BitInt(d_digesttype); 
248                 conv.xfrHexBlob(d_digest);
249                 )
250
251
252boilerplate_conv(SSHFP, 44, 
253                 conv.xfr8BitInt(d_algorithm); 
254                 conv.xfr8BitInt(d_fptype); 
255                 conv.xfrHexBlob(d_fingerprint);
256                 )
257
258boilerplate_conv(RRSIG, 46, 
259                 conv.xfrType(d_type); 
260                 conv.xfr8BitInt(d_algorithm); 
261                 conv.xfr8BitInt(d_labels); 
262
263                 conv.xfr32BitInt(d_originalttl); 
264                 conv.xfrTime(d_sigexpire); 
265                 conv.xfrTime(d_siginception); 
266                 conv.xfr16BitInt(d_tag); 
267                 conv.xfrLabel(d_signer);
268                 conv.xfrBlob(d_signature);
269                 )
270                 
271boilerplate_conv(DNSKEY, 48, 
272                 conv.xfr16BitInt(d_flags); 
273                 conv.xfr8BitInt(d_protocol); 
274                 conv.xfr8BitInt(d_algorithm); 
275                 conv.xfrBlob(d_key);
276                 )
277
278void reportBasicTypes()
279{
280    ARecordContent::report();
281    AAAARecordContent::report();
282    NSRecordContent::report();
283    CNAMERecordContent::report();
284    MXRecordContent::report();
285    SOARecordContent::report();
286    SRVRecordContent::report();
287    PTRRecordContent::report();
288}
289
290void reportOtherTypes()
291{
292   TXTRecordContent::report();
293   SPFRecordContent::report();
294   NAPTRRecordContent::report();
295   RPRecordContent::report();
296   DNSKEYRecordContent::report();
297   RRSIGRecordContent::report();
298   DSRecordContent::report();
299   SSHFPRecordContent::report();
300   NSECRecordContent::report();
301   OPTRecordContent::report();
302   DNSRecordContent::regist(1,255, 0, 0, "ANY");
303}
304
305void reportAllTypes()
306{
307  reportBasicTypes();
308  reportOtherTypes();
309}
310
311#if 0
312static struct Reporter
313{
314  Reporter()
315  {
316    reportAllTypes();
317  }
318} reporter __attribute__((init_priority(65535)));
319#endif
Note: See TracBrowser for help on using the browser.