import socket
import struct
-from dns import rdataclass, rdatatype, update
+from dns import message, rdataclass, rdatatype, update
import pytest
@pytest.mark.parametrize(
"rdtype,rdclass,ttl,rdata",
[
+ (rdatatype.SRV, rdataclass.NONE, 0, b"\x00\x00\x00\x00\x00\x00\x01"),
(rdatatype.SRV, rdataclass.NONE, 0, b"\x00"),
(rdatatype.KX, rdataclass.NONE, 0, b""),
(rdatatype.PX, rdataclass.NONE, 0, b""),
s.sendall(packet)
try:
rwire = s.recv(4096)
- res = dns.message.from_wire(rwire)
+ res = message.from_wire(rwire)
isctest.check.formerr(res)
except Exception: # pylint: disable=broad-except
pass
up.add("foo.example.", 300, rdtype, rdata)
res = isctest.query.tcp(up, "10.53.0.2")
isctest.check.notimp(res)
+
+
+def test_class_undefined(ns2):
+ up = update.UpdateMessage(".", rdclass=257)
+ up.present(".", 0)
+ up.answer[0].rdclass = rdataclass.NONE
+ with ns2.watch_log_from_here() as watcher:
+ res = isctest.query.tcp(up, "10.53.0.2")
+ isctest.check.notimp(res)
+ watcher.wait_for_line("invalid message class: CLASS257")
+
+
+def test_class_zero(ns2):
+ up = update.UpdateMessage(".", rdclass=0)
+ up.present(".", 0)
+ up.answer[0].rdclass = rdataclass.NONE
+ with ns2.watch_log_from_here() as watcher:
+ res = isctest.query.tcp(up, "10.53.0.2")
+ isctest.check.formerr(res)
+ watcher.wait_for_line("message class could not be determined")
+
+
+def test_class_any(ns2):
+ up = update.UpdateMessage(".", rdclass=rdataclass.ANY)
+ up.present(".", 0)
+ up.answer[0].rdclass = rdataclass.NONE
+ with ns2.watch_log_from_here() as watcher:
+ res = isctest.query.tcp(up, "10.53.0.2")
+ isctest.check.formerr(res)
+ watcher.wait_for_line("message parsing failed: FORMERR")
+
+
+def test_class_none(ns2):
+ up = update.UpdateMessage(".", rdclass=rdataclass.NONE)
+ up.present(".", 0)
+ up.answer[0].rdclass = rdataclass.NONE
+ with ns2.watch_log_from_here() as watcher:
+ res = isctest.query.tcp(up, "10.53.0.2")
+ isctest.check.formerr(res)
+ watcher.wait_for_line("message parsing failed: FORMERR")
n=$((n + 1))
ret=0
echo_i "check that TYPE=0 update is handled ($n)"
+nextpart ns1/named.run >/dev/null
echo "a0e4280000010000000100000000060001c00c000000fe000000000000" \
- | $PERL ../packet.pl -a 10.53.0.1 -p ${PORT} -t tcp >/dev/null || ret=1
+ | $PERL ../packet.pl -a 10.53.0.1 -p ${PORT} -t tcp -b >/dev/null || ret=1
+wait_for_log 2 "message parsing failed: FORMERR" ns1/named.run || ret=1
$DIG $DIGOPTS +tcp version.bind txt ch @10.53.0.1 >dig.out.ns1.$n || ret=1
grep "status: NOERROR" dig.out.ns1.$n >/dev/null || ret=1
[ $ret = 0 ] || {
n=$((n + 1))
ret=0
echo_i "check that TYPE=0 additional data is handled ($n)"
+nextpart ns1/named.run >/dev/null
echo "a0e4280000010000000000010000060001c00c000000fe000000000000" \
- | $PERL ../packet.pl -a 10.53.0.1 -p ${PORT} -t tcp >/dev/null || ret=1
-$DIG $DIGOPTS +tcp version.bind txt ch @10.53.0.1 >dig.out.ns1.$n || ret=1
-grep "status: NOERROR" dig.out.ns1.$n >/dev/null || ret=1
-[ $ret = 0 ] || {
- echo_i "failed"
- status=1
-}
-
-n=$((n + 1))
-ret=0
-echo_i "check that update to undefined class is handled ($n)"
-echo "a0e4280000010001000000000000060101c00c000000fe000000000000" \
- | $PERL ../packet.pl -a 10.53.0.1 -p ${PORT} -t tcp >/dev/null || ret=1
+ | $PERL ../packet.pl -a 10.53.0.1 -p ${PORT} -t tcp -b >/dev/null || ret=1
+wait_for_log 2 "message parsing failed: FORMERR" ns1/named.run || ret=1
$DIG $DIGOPTS +tcp version.bind txt ch @10.53.0.1 >dig.out.ns1.$n || ret=1
grep "status: NOERROR" dig.out.ns1.$n >/dev/null || ret=1
[ $ret = 0 ] || {
# -p <port>: specify port
# -t <protocol>: specify UDP or TCP
# -r <num>: send packet <num> times
+# -b: blocking io
# -d: dump response packets
#
# If not specified, address defaults to 127.0.0.1, port to 53, protocol
use Getopt::Std;
use IO::File;
use IO::Socket;
+use Net::DNS;
+use Net::DNS::Packet;
sub usage {
print ("Usage: packet.pl [-a address] [-d] [-p port] [-t (tcp|udp)] [-r <repeats>] [file]\n");
my $proto;
sub dumppacket {
- use Net::DNS;
- use Net::DNS::Packet;
my $rin;
my $rout;
}
my %options={};
-getopts("a:dp:t:r:", \%options);
+getopts("a:bdp:t:r:", \%options);
my $addr = "127.0.0.1";
$addr = $options{a} if defined $options{a};
my $repeats = 1;
$repeats = $options{r} if defined $options{r};
+my $blocking = defined $options{b} ? 1 : 0;
+
my $file = "STDIN";
if (@ARGV >= 1) {
my $filename = shift @ARGV;
my $output = unpack("H*", $data);
print ("sending $repeats time(s): $output\n");
+
+if (defined $options{d}) {
+ my $request;
+ if ($Net::DNS::VERSION > 0.68) {
+ $request = new Net::DNS::Packet(\$data, 0);
+ $@ and die $@;
+ } else {
+ my $err;
+ ($request, $err) = new Net::DNS::Packet(\$data, 0);
+ $err and die $err;
+ }
+ $request->print;
+}
+
$sock = IO::Socket::INET->new(PeerAddr => $addr, PeerPort => $port,
- Blocking => 0,
+ Blocking => $blocking,
Proto => $proto,) or die "$!";
STDOUT->autoflush(1);