NAME
Net::DNS::TestNS - Perl extension for simulating simple Nameservers
SYNOPSIS
use Net::DNS::TestNS;
ABSTRACT
Class for setting up "simple DNS" servers.
DESCRIPTION
Class to setup a number of nameservers that respond to specific DNS queries (QNAME,QTYPE) by prespecified answers. This class is to be used in test suites where you want to have servers to show predefined behavior.
If the server will do a lookup based on QNAME,QTYPE and return the specified data. If there is no QNAME, QTYPE match the server will return a SERVFAIL.
A log will be written to STDERR it contains time, IP/PORT, QNAME, QTYPE, RCODE
Configuration file
Thew class uses an XML file to read its configuration. The DTD can be obtained through the variable $Net::DNS::TestNS::TESTNS_DTD.
The setup is split in a number of servers, each with a unique IP/port number, each server has 1 or more QNAMEs it will respond to. Each QNAME can have QTYPEs specified.
For each QNAME,QTYPE an answer needs to be specified, response code and header bits can be tweaked through the qtype attributes.
The content of the packet can be specified through ans, aut and add elements, each specifying one RR record to end up in the answer, authority or additional section.
The optional 'delay' attribute in the QTYPE element specifies how many seconds the server should wait until an answer is returned.
If the query does not match against data specified in the configuration a SERVFAIL is returned.
new
my $server=Net::DNS::TestNS->new($configfile, {
Verbose => 1,
});
Read the configuration files and bind to ports. One can use <!-- include="file" --> anywhere inside the configuration file to include other XML configuration fragments.
The second optional argument is hash that contains customization parameters. Verbose boolean Makes the code more verbose.
new returns the object reference on success and 0 on failure. On failure the class variable $Net::DNS::TestNS::errorcondition is set.
verbose
$self->verbose(1);
Sets verbosity at run time.
run
Spawns off the servers and process the data.
medea
Cleanup function that kills all the children spawned by the instance. Also known by its alias 'stop'.
Configuration file example
<?xml version="1.0"?>
<!-- DTD is in-line and obligatory -->
<!DOCTYPE testns [
<!ELEMENT testns (server*)>
<!-- Root element has required IP and PORT attribute -->
<!ELEMENT server (qname?)>
<!ATTLIST server ip CDATA #REQUIRED>
<!ATTLIST server port CDATA #REQUIRED>
<!-- A server has answers for a number of possible QNAME QTYPE questions -->
<!-- A QNAME should be fully specified -->
<!ELEMENT qname (qtype*)>
<!ATTLIST qname name CDATA #REQUIRED>
<!ELEMENT qtype (ans*,aut*,add*)>
<!ATTLIST qtype type CDATA #REQUIRED>
<!ATTLIST qtype rcode CDATA #REQUIRED>
<!ATTLIST qtype aa (1|0) #REQUIRED>
<!ATTLIST qtype ra (1|0) #REQUIRED>
<!ATTLIST qtype ad (1|0) #REQUIRED>
<!ATTLIST qtype delay CDATA "0" >
<!-- Each of these contain one RR. -->
<!ELEMENT ans (#PCDATA) >
<!ELEMENT aut (#PCDATA) >
<!ELEMENT add (#PCDATA) >
]>
<!-- Start of the configuration -->
<testns>
<!-- First server -->
<server ip="127.0.0.1" port="5354"> <qname name="bla.foo"> <!-- bla.foo ANY returns a formerr --> <qtype type="ANY" rcode="FORMERR" aa="1" ra="0" ad="0" > </qtype> <!-- bla.foo TXT returns two RRs in the answer section --> <qtype type="TXT" rcode="NOERROR" aa="1" ra="0" ad="1" > <ans> bla.foo. 3600 IN TXT "TEXT" </ans> <ans> bla.foo. 3600 IN TXT "Other text" </ans> </qtype>
<!-- bla.foo A Returns extra crap in the additional section -->
<qtype type="A" rcode="NOERROR" aa="1" ra="0" ad="1" >
<ans>
bla.foo. 3600 IN A 10.0.0.1
</ans>
<ans>
bla.foo. 3600 IN A 10.0.0.2
</ans>
<ans>
bla.foo. 3600 IN A 10.0.0.3
</ans>
<aut></aut>
<add>
bla.foo. 3600 IN A 10.0.0.3
</add>
</qtype>
</qname>
</server>
<!-- Second server on port 5355 --> <server ip="127.0.0.1" port="5355">
<qname name="bla.foo">
<!-- a NXDOMAIN with authoritative content; does not make sense does it -->
<qtype type="TXT" rcode="NXDOMAIN" aa="0" ra="1" ad="1" >
<ans>
bla.foo. 3600 IN TXT "TEXT"
</ans>
<ans>
bla.foo. 3600 IN TXT "From port 5355"
</ans>
<aut></aut>
<add></add>
</qtype>
</qname>
</server>
</testns>
Known Deficiencies and TODO
The module is based on Net::DNS::Nameserver. There is no way to distinguish if the query came over TCP or UDP; besides UDP truncation is not available in Net::DNS::Nameserver.
AUTHOR
Olaf Kolkman, <olaf@net-dns.org<gt>
COPYRIGHT AND LICENSE
Copyright (c) 2003-2005 RIPE NCC. Author Olaf M. Kolkman <olaf@net-dns.net>
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.
THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.