blib/lib/Net/DNS/ToolKit/RR/SOA.pm

filter: Statementstmt 100% 35 / 35 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 7 / 21 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 65.3% 51 / 78 CC 10 SCAR 26.7
CC
10
Cov
73%
put
22.5
BEGIN
1.0
BEGIN
1.0
CRAP 14.4
↑ Summary blib/lib/Net/DNS/ToolKit/RR/ISDN.pm »
1 package Net::DNS::ToolKit::RR::SOA;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 #use warnings;
5  
6 1 ▶use Net::DNS::ToolKit qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
7 get16
8 get32
9 put16
10 put32
11 dn_comp
12 dn_expand
13 1 );
14 1 ▶use Net::DNS::Codes qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 $VERSION = do { my @r = (q$Revision: 0.02 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
18  
19 =head1 NAME
20  
21 Net::DNS::ToolKit::RR::SOA - Resource Record Handler
22  
23 =head1 SYNOPSIS
24  
25 DO NOT use Net::DNS::ToolKit::RR::SOA
26 DO NOT require Net::DNS::ToolKit::RR::SOA
27  
28 Net::DNS::ToolKit::RR::SOA is autoloaded by
29 class Net::DNS::ToolKit::RR and its methods
30 are instantiated in a 'special' manner.
31  
32 use Net::DNS::ToolKit::RR;
33 ($get,$put,$parse) = new Net::DNS::ToolKit::RR;
34  
35 ($newoff,$name,$type,$class,$ttl,$rdlength,
36 ) = $get->SOA(\$buffer,$offset);
37  
38 Note: the $get->SOA method is normally called
39 via: @stuff = $get->next(\$buffer,$offset);
40  
41 ($newoff,@dnptrs)=$put->SOA(\$buffer,$offset,\@dnptrs,
42 $name,$type,$class,$ttl,
43 $mname,$rname,$serial,$refresh,$retry,$expire,$min);
44  
45 $NAME,$TYPE,$CLASS,$TTL,$rdlength,
46 $MNAME,$RNAME,$serial,$refresh,$retry,$expire,$min)
47 = $parse->SOA($name,$type,$class,$ttl,$rdlength,
48 $mname,$rname,$serial,$refresh,$retry,$expire,$min);
49  
50 =head1 DESCRIPTION
51  
52 B<Net::DNS::ToolKit::RR:SOA> appends an SOA resource record to a DNS packet
53 under construction, recovers an SOA resource record from a packet being decoded, and
54 converts the numeric/binary portions of the resource record to human
55 readable form.
56  
57 Description from RFC1035.txt
58  
59 3.2.1. Format
60  
61 All RRs have the same top level format shown below:
62  
63 1 1 1 1 1 1
64 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
65 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
66 | NAME |
67 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
68 | TYPE |
69 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
70 | CLASS |
71 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
72 | TTL |
73 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
74 | RDLENGTH |
75 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
76 | RDATA |
77 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
78  
79 NAME an owner name, i.e., the name of the node to which this
80 resource record pertains.
81  
82 TYPE two octets containing one of the RR TYPE codes.
83  
84 CLASS two octets containing one of the RR CLASS codes.
85  
86 TTL a 32 bit signed integer that specifies the time interval
87 that the resource record may be cached before the source
88 of the information should again be consulted. Zero
89 values are interpreted to mean that the RR can only be
90 used for the transaction in progress, and should not be
91 cached. For example, SOA records are always distributed
92 with a zero TTL to prohibit caching. Zero values can
93 also be used for extremely volatile data.
94  
95 RDLENGTH an unsigned 16 bit integer that specifies the length
96 in octets of the RDATA field.
97  
98 RDATA a variable length string of octets that describes the
99 resource. The format of this information varies
100 according to the TYPE and CLASS of the resource record.
101  
102 3.3.13. SOA RDATA format
103  
104 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
105 / MNAME /
106 / /
107 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
108 / RNAME /
109 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
110 | SERIAL |
111 | |
112 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
113 | REFRESH |
114 | |
115 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
116 | RETRY |
117 | |
118 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
119 | EXPIRE |
120 | |
121 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
122 | MINIMUM |
123 | |
124 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
125  
126 where:
127  
128 MNAME The <domain-name> of the name server that was
129 the original or primary source of data for this
130 zone.
131  
132 RNAME A <domain-name> which specifies the mailbox of
133 the person responsible for this zone.
134  
135 SERIAL The unsigned 32 bit version number of the
136 original copy of the zone. Zone transfers
137 preserve this value. This value wraps and
138 should be compared using sequence space
139 arithmetic.
140  
141 REFRESH A 32 bit time interval before the zone
142 should be refreshed.
143  
144 RETRY A 32 bit time interval that should elapse
145 before a failed refresh should be retried.
146  
147 EXPIRE A 32 bit time value that specifies the upper
148 limit on the time interval that can elapse
149 before the zone is no longer authoritative.
150  
151 MINIMUM The unsigned 32 bit minimum TTL field that
152 should be exported with any RR from this zone.
153  
154 SOA records cause no additional section processing.
155  
156 All times are in units of seconds.
157  
158 Most of these fields are pertinent only for name server maintenance
159 operations. However, MINIMUM is used in all query operations that
160 retrieve RRs from a zone. Whenever a RR is sent in a response to a
161 query, the TTL field is set to the maximum of the TTL field from the RR
162 and the MINIMUM field in the appropriate SOA. Thus MINIMUM is a lower
163 bound on the TTL field for all RRs in a zone. Note that this use of
164 MINIMUM should occur when the RRs are copied into the response and not
165 when the zone is loaded from a master file or via a zone transfer. The
166 reason for this provison is to allow future dynamic update facilities to
167 change the SOA RR with known semantics.
168  
169 =over 4
170  
171 =item * @stuff = $get->SOA(\$buffer,$offset);
172  
173 Get the contents of the resource record.
174  
175 USE: @stuff = $get->next(\$buffer,$offset);
176  
177 where: @stuff = (
178 $newoff $name,$type,$class,$ttl,$rdlength,
179 $mname,$rname,$serial,$refresh,$retry,$expire,$min);
180  
181 All except the last five (5) items,
182 B<$mname,$rname,$serial,$refresh,$retry,$expire,$min>, are provided by
183 the class loader, B<Net::DNS::ToolKit::RR>. The code in this method knows
184 how to retrieve B<$mname,$rname,$serial,$refresh,$retry,$expire,$min>.
185  
186 input: pointer to buffer,
187 offset into buffer
188 returns: offset to next resource,
189 @common RR elements,
190 primary server name,
191 zone contact,
192 RR serial number,
193 REFRESH timer,
194 RETRY timer,
195 EXPIRE timer,
196 MINIMUM ttl
197  
198 =cut
199  
200 1 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
201 1 my($self,$bp,$offset) = @_;
202 1 $offset += INT16SZ; # don't need rdlength
203 1 ($offset, my $mname) = dn_expand($bp,$offset);
204 1 ($offset, my $rname) = dn_expand($bp,$offset);
205 1 (my $serial,$offset) = get32($bp,$offset);
206 1 (my $refresh,$offset) = get32($bp,$offset);
207 1 (my $retry,$offset) = get32($bp,$offset);
208 1 (my $expire,$offset) = get32($bp,$offset);
209 1 (my $min,$offset) = get32($bp,$offset);
210 1 return($offset,$mname,$rname,$serial,$refresh,$retry,$expire,$min);
211 }
212  
213 =item * ($newoff,@dnptrs)=$put->SOA(\$buffer,$offset,\@dnptrs,
214 $name,$type,$class,$ttl,
215 $mname,$rname,$serial,$refresh,$retry,$expire,$min);
216  
217 Append an SOA record to $buffer.
218  
219 where @common = (
220 $name,$type,$class,$ttl);
221  
222 The method will insert the $rdlength,
223 $mname, $rname, $serial, $refresh, $retry, $expire, and $min, then
224 return the updated pointer to the array of compressed names
225  
226 The class loader, B<Net::DNS::ToolKit::RR>, inserts the @common elements and
227 returns updated @dnptrs. This module knows how to insert its RDATA and
228 calculate the $rdlength.
229  
230 input: pointer to buffer,
231 offset (normally end of buffer),
232 pointer to compressed name array,
233 @common RR elements,
234 primary server name,
235 zone contact,
236 RR serial number,
237 REFRESH timer,
238 RETRY timer,
239 EXPIRE timer,
240 MINIMUM ttl
241
242 output: offset to next RR,
243 new compressed name pointer array,
244 or empty list () on error.
245  
246 =cut
247  
248 1 ▶sub put {
Subroutine put: called CC=10 SCAR=31.1
Pod undocumented
249 1 ▶ return () unless @_; # always return on error
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
250 1 my($self,$bp,$off,$dnp,$mname,$rname,$serial,$refresh,$retry,$expire,$min) = @_;
251 1 my $rdlp = $off; # save pointer to rdlength
252 1 my ($doff,@dnptrs); # data start, pointer array
253 1 ▶ return () unless # check for valid and get
Branch: 1 branch
BranchTrueFalseTotal
unless $doff = put16($bp, $off, 0) and ($off, @dnptrs) = &dn_comp($bp, $doff, \$mname, $dnp) and ($off, @dnptrs) = &dn_comp($bp, $off, \$rname, \@dnptrs) and $off = put32($bp, $off, $serial) and $off = put32($bp, $off, $refresh) and $off = put32($bp, $off, $retry) and $off = put32($bp, $off, $expire) and $off = put32($bp, $off, $min) 0 1 1
Condition33%7/21
$doff = put16($bp, $off, 0) and ($off, @dnptrs) = &dn_comp($bp, $doff, \$mname, $dnp) and ($off, @dnptrs) = &dn_comp($bp, $off, \$rname, \@dnptrs) and $off = put32($bp, $off, $serial) and $off = put32($bp, $off, $refresh) and $off = put32($bp, $off, $retry) and $off = put32($bp, $off, $expire) and $off = put32($bp, $off, $min)
!ll&&!rl&&r
001
$doff = put16($bp, $off, 0) and ($off, @dnptrs) = &dn_comp($bp, $doff, \$mname, $dnp) and ($off, @dnptrs) = &dn_comp($bp, $off, \$rname, \@dnptrs) and $off = put32($bp, $off, $serial) and $off = put32($bp, $off, $refresh) and $off = put32($bp, $off, $retry) and $off = put32($bp, $off, $expire)
!ll&&!rl&&r
001
$doff = put16($bp, $off, 0) and ($off, @dnptrs) = &dn_comp($bp, $doff, \$mname, $dnp) and ($off, @dnptrs) = &dn_comp($bp, $off, \$rname, \@dnptrs) and $off = put32($bp, $off, $serial) and $off = put32($bp, $off, $refresh) and $off = put32($bp, $off, $retry)
!ll&&!rl&&r
001
$doff = put16($bp, $off, 0) and ($off, @dnptrs) = &dn_comp($bp, $doff, \$mname, $dnp) and ($off, @dnptrs) = &dn_comp($bp, $off, \$rname, \@dnptrs) and $off = put32($bp, $off, $serial) and $off = put32($bp, $off, $refresh)
!ll&&!rl&&r
001
$doff = put16($bp, $off, 0) and ($off, @dnptrs) = &dn_comp($bp, $doff, \$mname, $dnp) and ($off, @dnptrs) = &dn_comp($bp, $off, \$rname, \@dnptrs) and $off = put32($bp, $off, $serial)
!ll&&!rl&&r
001
$doff = put16($bp, $off, 0) and ($off, @dnptrs) = &dn_comp($bp, $doff, \$mname, $dnp) and ($off, @dnptrs) = &dn_comp($bp, $off, \$rname, \@dnptrs)
!ll&&!rl&&r
001
$doff = put16($bp, $off, 0) and ($off, @dnptrs) = &dn_comp($bp, $doff, \$mname, $dnp)
!ll&&!rl&&r
001
MC/DC0%0/8
$doff = put16($bp, $off, 0) and ($off, @dnptrs) = &dn_comp($bp, $doff, \$mname, $dnp) and ($off, @dnptrs) = &dn_comp($bp, $off, \$rname, \@dnptrs) and $off = put32($bp, $off, $serial) and $off = put32($bp, $off, $refresh) and $off = put32($bp, $off, $retry) and $off = put32($bp, $off, $expire) and $off = put32($bp, $off, $min)
$doff = put16($bp, $off, 0) ($off, @dnptrs) = &dn_comp($bp, $doff, \$mname, $dnp) ($off, @dnptrs) = &dn_comp($bp, $off, \$rname, \@dnptrs) $off = put32($bp, $off, $serial) $off = put32($bp, $off, $refresh) $off = put32($bp, $off, $retry) $off = put32($bp, $off, $expire) $off = put32($bp, $off, $min)
Truth table11%1/9
A and B and C and D and E and F and G and H
A= $doff = put16($bp, $off, 0)B= ($off, @dnptrs) = &dn_comp($bp, $doff, \$mname, $dnp)C= ($off, @dnptrs) = &dn_comp($bp, $off, \$rname, \@dnptrs)D= $off = put32($bp, $off, $serial)E= $off = put32($bp, $off, $refresh)F= $off = put32($bp, $off, $retry)G= $off = put32($bp, $off, $expire)H= $off = put32($bp, $off, $min)
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
254 ($doff = put16($bp,$off,0)) && # offset for names
255 (($off,@dnptrs) = dn_comp($bp,$doff,\$mname,$dnp)) &&
256 (($off,@dnptrs) = dn_comp($bp,$off,\$rname,\@dnptrs)) &&
257 ($off = put32($bp,$off,$serial)) &&
258 ($off = put32($bp,$off,$refresh)) &&
259 ($off = put32($bp,$off,$retry)) &&
260 ($off = put32($bp,$off,$expire)) &&
261 ($off = put32($bp,$off,$min));
262 # rdlength = new offset - previous offset
263 1 put16($bp,$rdlp, $off - $doff);
264 1 return($off,@dnptrs);
265 }
266  
267 =item * (@COMMON,$MNAME,$RNAME,$serial,$refresh,$retry,$expire,$min)
268 = $parse->A(@common,
269 $mname,$rname,$serial,$refresh,$retry,$expire,$min);
270  
271 Converts binary/numeric field data into human readable form. The common RR
272 elements are supplied by the class loader, B<Net::DNS::ToolKit::RR>.
273 For SOA RR's, this returns $mxdname terminated with '.'
274  
275 input: primary server name,
276 zone contact,
277 serial number,
278 refresh timer,
279 retry timer,
280 expire timer,
281 minimum ttl
282 returns: SERVER NAME '.' terminated
283 CONTACT NAME '.' terminated
284 serial number,
285 refresh timer,
286 retry timer,
287 expire timer,
288 minimum ttl
289  
290 =back
291  
292 =cut
293  
294 1 ▶sub parse {
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
295 1 my($self,$mname,$rname,@rest) = @_;
296 1 return($mname.'.',$rname.'.',@rest);
297 }
298  
299 =head1 DEPENDENCIES
300  
301 Net::DNS::ToolKit
302 Net::DNS::Codes
303  
304 =head1 EXPORT
305  
306 none
307  
308 =head1 AUTHOR
309  
310 Michael Robinton <michael@bizsystems.com>
311  
312 =head1 COPYRIGHT
313  
314 Copyright 2003 - 2011, Michael Robinton <michael@bizsystems.com>
315
316 Michael Robinton <michael@bizsystems.com>
317  
318 All rights reserved.
319  
320 This program is free software; you can redistribute it and/or modify
321 it under the terms of either:
322  
323 a) the GNU General Public License as published by the Free
324 Software Foundation; either version 2, or (at your option) any
325 later version, or
326  
327 b) the "Artistic License" which comes with this distribution.
328  
329 This program is distributed in the hope that it will be useful,
330 but WITHOUT ANY WARRANTY; without even the implied warranty of
331 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
332 the GNU General Public License or the Artistic License for more details.
333  
334 You should have received a copy of the Artistic License with this
335 distribution, in the file named "Artistic". If not, I'll be glad to provide
336 one.
337  
338 You should also have received a copy of the GNU General Public License
339 along with this program in the file named "Copying". If not, write to the
340  
341 Free Software Foundation, Inc.
342 59 Temple Place, Suite 330
343 Boston, MA 02111-1307, USA
344  
345 or visit their web page on the internet at:
346  
347 http://www.gnu.org/copyleft/gpl.html.
348  
349 =head1 See also:
350  
351 Net::DNS::Codes(3), Net::DNS::ToolKit(3)
352  
353 =cut
354  
355 1 1;
↑ Summary blib/lib/Net/DNS/ToolKit/RR/ISDN.pm »