File Coverage

blib/lib/Net/DNS/ToolKit/RR/SOA.pm
Criterion Covered Total %
statement 31 31 100.0
branch 2 4 50.0
condition 7 21 33.3
subroutine 7 7 100.0
pod 0 3 0.0
total 47 66 71.2


line stmt bran cond sub pod time code
1             package Net::DNS::ToolKit::RR::SOA;
2              
3 1     1   1295 use strict;
  1         1  
  1         36  
4             #use warnings;
5              
6 1         55 use Net::DNS::ToolKit qw(
7             get16
8             get32
9             put16
10             put32
11             dn_comp
12             dn_expand
13 1     1   6 );
  1         1  
14 1     1   5 use Net::DNS::Codes qw(:constants);
  1         1  
  1         192  
15 1     1   4 use vars qw($VERSION);
  1         2  
  1         488  
16              
17             $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 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 of the name server that was
129             the original or primary source of data for this
130             zone.
131              
132             RNAME A 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. 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             sub get {
201 1     1 0 494 my($self,$bp,$offset) = @_;
202 1         7 $offset += INT16SZ; # don't need rdlength
203 1         41 ($offset, my $mname) = dn_expand($bp,$offset);
204 1         4 ($offset, my $rname) = dn_expand($bp,$offset);
205 1         6 (my $serial,$offset) = get32($bp,$offset);
206 1         4 (my $refresh,$offset) = get32($bp,$offset);
207 1         2 (my $retry,$offset) = get32($bp,$offset);
208 1         3 (my $expire,$offset) = get32($bp,$offset);
209 1         4 (my $min,$offset) = get32($bp,$offset);
210 1         4 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, 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             sub put {
249 1 50   1 0 348 return () unless @_; # always return on error
250 1         4 my($self,$bp,$off,$dnp,$mname,$rname,$serial,$refresh,$retry,$expire,$min) = @_;
251 1         3 my $rdlp = $off; # save pointer to rdlength
252 1         2 my ($doff,@dnptrs); # data start, pointer array
253 1 50 33     61 return () unless # check for valid and get
      33        
      33        
      33        
      33        
      33        
      33        
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         7 put16($bp,$rdlp, $off - $doff);
264 1         8 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.
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             sub parse {
295 1     1 0 1830 my($self,$mname,$rname,@rest) = @_;
296 1         13 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
311              
312             =head1 COPYRIGHT
313              
314             Copyright 2003 - 2011, Michael Robinton
315            
316             Michael Robinton
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;