]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/nsecrecords.cc
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "dnsrecords.hh"
27 void NSECRecordContent::report(void)
29 regist(1, 47, &make
, &make
, "NSEC");
32 DNSRecordContent
* NSECRecordContent::make(const string
& content
)
34 return new NSECRecordContent(content
);
37 NSECRecordContent::NSECRecordContent(const string
& content
, const string
& zone
)
39 RecordTextReader
rtr(content
, DNSName(zone
));
49 void NSECRecordContent::toPacket(DNSPacketWriter
& pw
)
54 set
<uint16_t>::const_iterator i
;
60 for(i
=d_set
.begin(); i
!= d_set
.end(); ++i
){
61 uint16_t bit
= (*i
)%256;
62 window
= static_cast<int>((*i
) / 256);
64 if (window
!= oldWindow
) {
66 res
[0] = static_cast<unsigned char>(oldWindow
);
67 res
[1] = static_cast<unsigned char>(len
);
68 tmp
.assign(res
, res
+len
+2);
74 res
[2+bit
/8] |= 1 << (7-(bit
%8));
78 res
[0] = static_cast<unsigned char>(window
);
79 res
[1] = static_cast<unsigned char>(len
);
80 tmp
.assign(res
, res
+len
+2);
84 NSECRecordContent::DNSRecordContent
* NSECRecordContent::make(const DNSRecord
&dr
, PacketReader
& pr
)
86 NSECRecordContent
* ret
=new NSECRecordContent();
87 pr
.xfrName(ret
->d_next
);
91 // 00 06 20 00 00 00 00 03 -> NS RRSIG NSEC ( 2, 46, 47 ) counts from left
96 throw MOADNSException("NSEC record with impossibly small bitmap");
98 for(unsigned int n
= 0; n
+1 < bitmap
.size();) {
99 unsigned int window
=static_cast<unsigned char>(bitmap
[n
++]);
100 unsigned int blen
=static_cast<unsigned char>(bitmap
[n
++]);
102 // end if zero padding and ensure packet length
103 if(window
== 0 && blen
== 0) break;
104 if(n
+ blen
> bitmap
.size())
105 throw MOADNSException("NSEC record with bitmap length > packet length");
107 for(unsigned int k
=0; k
< blen
; k
++) {
108 uint8_t val
=bitmap
[n
++];
109 for(int bit
= 0; bit
< 8 ; ++bit
, val
>>=1)
111 ret
->d_set
.insert((7-bit
) + 8*(k
) + 256*window
);
118 string
NSECRecordContent::getZoneRepresentation(bool noDot
) const
121 RecordTextWriter
rtw(ret
);
124 for(set
<uint16_t>::const_iterator i
=d_set
.begin(); i
!=d_set
.end(); ++i
) {
126 ret
+=NumberToType(*i
);
132 ////// begin of NSEC3
134 void NSEC3RecordContent::report(void)
136 regist(1, 50, &make
, &make
, "NSEC3");
139 DNSRecordContent
* NSEC3RecordContent::make(const string
& content
)
141 return new NSEC3RecordContent(content
);
144 NSEC3RecordContent::NSEC3RecordContent(const string
& content
, const string
& zone
)
146 RecordTextReader
rtr(content
, DNSName(zone
));
147 rtr
.xfr8BitInt(d_algorithm
);
148 rtr
.xfr8BitInt(d_flags
);
149 rtr
.xfr16BitInt(d_iterations
);
151 rtr
.xfrHexBlob(d_salt
);
152 rtr
.xfrBase32HexBlob(d_nexthash
);
161 void NSEC3RecordContent::toPacket(DNSPacketWriter
& pw
)
163 pw
.xfr8BitInt(d_algorithm
);
164 pw
.xfr8BitInt(d_flags
);
165 pw
.xfr16BitInt(d_iterations
);
166 pw
.xfr8BitInt(d_salt
.length());
169 pw
.xfr8BitInt(d_nexthash
.length());
170 pw
.xfrBlob(d_nexthash
);
173 set
<uint16_t>::const_iterator i
;
179 for(i
=d_set
.begin(); i
!= d_set
.end(); ++i
){
180 uint16_t bit
= (*i
)%256;
181 window
= static_cast<int>((*i
) / 256);
183 if (window
!= oldWindow
) {
184 if (oldWindow
> -1) {
185 res
[0] = static_cast<unsigned char>(oldWindow
);
186 res
[1] = static_cast<unsigned char>(len
);
187 tmp
.assign(res
, res
+len
+2);
193 res
[2+bit
/8] |= 1 << (7-(bit
%8));
197 res
[0] = static_cast<unsigned char>(window
);
198 res
[1] = static_cast<unsigned char>(len
);
201 tmp
.assign(res
, res
+len
+2);
206 NSEC3RecordContent::DNSRecordContent
* NSEC3RecordContent::make(const DNSRecord
&dr
, PacketReader
& pr
)
208 NSEC3RecordContent
* ret
=new NSEC3RecordContent();
209 pr
.xfr8BitInt(ret
->d_algorithm
);
210 pr
.xfr8BitInt(ret
->d_flags
);
211 pr
.xfr16BitInt(ret
->d_iterations
);
214 pr
.xfrBlob(ret
->d_salt
, len
);
217 pr
.xfrBlob(ret
->d_nexthash
, len
);
222 // 00 06 20 00 00 00 00 03 -> NS RRSIG NSEC ( 2, 46, 47 ) counts from left
227 if(bitmap
.size() < 2)
228 throw MOADNSException("NSEC3 record with impossibly small bitmap");
230 for(unsigned int n
= 0; n
+1 < bitmap
.size();) {
231 unsigned int window
=static_cast<unsigned char>(bitmap
[n
++]);
232 unsigned int innerlen
=static_cast<unsigned char>(bitmap
[n
++]);
234 // end if zero padding and ensure packet length
235 if(window
== 0&&innerlen
== 0) break;
236 if(n
+innerlen
>bitmap
.size())
237 throw MOADNSException("NSEC record with bitmap length > packet length");
239 for(unsigned int k
=0; k
< innerlen
; k
++) {
240 uint8_t val
=bitmap
[n
++];
241 for(int bit
= 0; bit
< 8 ; ++bit
, val
>>=1)
243 ret
->d_set
.insert((7-bit
) + 8*(k
) + 256*window
);
250 string
NSEC3RecordContent::getZoneRepresentation(bool noDot
) const
253 RecordTextWriter
rtw(ret
);
254 rtw
.xfr8BitInt(d_algorithm
);
255 rtw
.xfr8BitInt(d_flags
);
256 rtw
.xfr16BitInt(d_iterations
);
258 rtw
.xfrHexBlob(d_salt
);
259 rtw
.xfrBase32HexBlob(d_nexthash
);
260 for(set
<uint16_t>::const_iterator i
=d_set
.begin(); i
!=d_set
.end(); ++i
) {
262 ret
+=NumberToType(*i
);
269 void NSEC3PARAMRecordContent::report(void)
271 regist(1, 51, &make
, &make
, "NSEC3PARAM");
272 regist(254, 51, &make
, &make
, "NSEC3PARAM");
275 DNSRecordContent
* NSEC3PARAMRecordContent::make(const string
& content
)
277 return new NSEC3PARAMRecordContent(content
);
280 NSEC3PARAMRecordContent::NSEC3PARAMRecordContent(const string
& content
, const string
& zone
)
282 RecordTextReader
rtr(content
, DNSName(zone
));
283 rtr
.xfr8BitInt(d_algorithm
);
284 rtr
.xfr8BitInt(d_flags
);
285 rtr
.xfr16BitInt(d_iterations
);
286 rtr
.xfrHexBlob(d_salt
);
289 void NSEC3PARAMRecordContent::toPacket(DNSPacketWriter
& pw
)
291 pw
.xfr8BitInt(d_algorithm
);
292 pw
.xfr8BitInt(d_flags
);
293 pw
.xfr16BitInt(d_iterations
);
294 pw
.xfr8BitInt(d_salt
.length());
295 // cerr<<"salt: '"<<makeHexDump(d_salt)<<"', "<<d_salt.length()<<endl;
299 NSEC3PARAMRecordContent::DNSRecordContent
* NSEC3PARAMRecordContent::make(const DNSRecord
&dr
, PacketReader
& pr
)
301 NSEC3PARAMRecordContent
* ret
=new NSEC3PARAMRecordContent();
302 pr
.xfr8BitInt(ret
->d_algorithm
);
303 pr
.xfr8BitInt(ret
->d_flags
);
304 pr
.xfr16BitInt(ret
->d_iterations
);
307 pr
.xfrHexBlob(ret
->d_salt
, len
);
311 string
NSEC3PARAMRecordContent::getZoneRepresentation(bool noDot
) const
314 RecordTextWriter
rtw(ret
);
315 rtw
.xfr8BitInt(d_algorithm
);
316 rtw
.xfr8BitInt(d_flags
);
317 rtw
.xfr16BitInt(d_iterations
);
318 rtw
.xfrHexBlob(d_salt
);