Net::DNS::ZoneFile::Fast - parse BIND8/9 zone files


Net-DNS-ZoneFile-Fast documentation  | view source Contained in the Net-DNS-ZoneFile-Fast distribution.

Index


NAME

Top

Net::DNS::ZoneFile::Fast -- parse BIND8/9 zone files

SYNOPSIS

Top

  use Net::DNS::ZoneFile::Fast;

  my $rr = Net::DNS::ZoneFile::Fast::parse($zone_text);

DESCRIPTION

Top

The Net::DNS::ZoneFile::Fast module provides an ability to parse zone files that BIND8 and BIND9 use, fast. Currently it provides a single function, parse(), which returns a reference to an array of traditional Net::DNS::RR objects, so that no new API has to be learned in order to manipulate zone records.

Great care was taken to ensure that parse() does its job as fast as possible, so it is interesting to use this module to parse huge zones. As an example datapoint, it takes less than 5 seconds to parse a 2.2 MB zone with about 72000 records on an Athlon XP 2600+ box.

On the other hand, it is likely that Net::DNS::RR objects that parse() returns are going to be further processed. To make it easier to link any record back to the zone file (say, to report a logical error like infamous `CNAME and other data' back to the user, or to do a zone file modification), parse() inserts line numbering information into Net::DNS::RR objects.

The module currently understands:

$GENERATE directive
$ORIGIN directive
$TTL directive
$INCLUDE directive (only while processing files or filehandles)
A records
AAAA records
CNAME records
DNAME records
HINFO records
LOC records
MX records
NS records
PTR records
RP records
SOA records
SRV records
TXT records
RRSIG records
DNSKEY records
DS records
NSEC records
RRSIG records

Non-standard third-party modules

Net::DNS.

Exports

None.

Subroutines

parse

Parses zone data and returns a reference to an array of Net::DNS::RR objects if successful. Takes the following named (no pun intended) parameters:

text

A semi-mandatory parameter, textual contents of the zone to be parsed.

fh

A semi-mandatory parameter, a file handle from which zone contents can be read for parsing.

file

A semi-mandatory parameter, a file name with the zone to parse.

origin

An optional parameter specifying zone origin. The default is ".". A trailing "." is appended if necessary.

on_error

An optional parameter, user-defined error handler. If specified, it must be a subroutine reference, which will be called on any error. This subroutine will be passed two parameters: a line number in the zone, where the error occurred, and the error description.

soft_errors

By default, parse throws an exception on any error. Set this optional parameter to a true value to avoid this. The default is false, unless on_error is also specified, in which case it is true.

includes_root

An optional parameter. By default, any $INCLUDE directives encountered will be tested for existence and readability. If the base path of the included filename is not your current working directory, this test will fail. Set the includes_root to the same as your named.conf file to avoid this failure.

quiet

An optional parameter. By default, on any error, the error description is printed via warn(). Set quiet to a true value if you don't want this. The default is false, unless on_error is also specified, in which case it is true.

debug

An optional parameter. If set to true, will produce some debug printing. You probably don't want to use that.

One of text, fh, file must be specified. If more than one is specified at the same time, fh takes precedence over file, which takes precedence over text.

As a special case, if parse is called with a single, unnamed parameter, it is assumed to be a zone text.

If parse is unsuccessful, and does not throw an exception (because either on_error or soft_errors was specified), parse returns undef.

The returned Net::DNS::RR are normal in every respect, except that each of them has two extra keys, Line and Lines, which correspondingly are the line number in the zone text where the record starts, and the number of lines the record spans. This information can be accessed either via hash lookup ($rr->{Line}), or via an accessor method ($rr->Line).

BUGS

Top

The parse() subroutine is not re-entrant, and it probably will never be.

There is also no guarantee that parse() will successfully parse every zone parsable by BIND, and no guarantee that BIND will parse every zone parsable by parse(). That said, parse() appears to do the right thing on around 50000 real life zones I tested it with.

SOA serial numbers with a decimal point are not supported (they're not a legal zonefile contstruct, although bind8 supported them. Even bind is dropping support for them in future releases).

COPYRIGHT AND LICENSE

Top

CREDITS

Top

Anton Berezin created the versions up until 0.5. Wes Hardaker at Sparta implemented the DNSSEC patches and took over maintenance of the module from 0.6 onward.

Anton's original CREDITS section:

  This module was largely inspired by the I<Net::DNS::ZoneFile> module
  by Luis E. Munoz.

  Many thanks to Phil Regnauld and Luis E. Munoz for discussions.

SEE ALSO

Top

http://www.dnssec-tools.org/, Net::DNS(3), Net::DNS::RR(3), Net::DNS::SEC(3)


Net-DNS-ZoneFile-Fast documentation  | view source Contained in the Net-DNS-ZoneFile-Fast distribution.