Skip to content

Commit

Permalink
Test query to nsd over IPv6 socket.
Browse files Browse the repository at this point in the history
Create zone file with A and AAAA records in zone regress.
Start nsd with zone file listening on ::1.
Write hosts of regress zone into pfresolved config.
Start pfresolved with nsd as resolver.
Wait until pfresolved creates table regress-pfresolved.
Read IP addresses from pf table with pfctl.
Check that pfresolved added IPv4 and IPv6 addresses.
Check that pf table contains all IPv4 and IPv6 addresses.
Check that IPv6 ::1 socket was used.
  • Loading branch information
bluhm committed Nov 7, 2023
1 parent 3cf13d4 commit a914dea
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
9 changes: 9 additions & 0 deletions regress/Nsd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package Nsd;
use parent 'Proc';
use Carp;
use File::Basename;
use Socket;
use Sys::Hostname;

sub new {
Expand All @@ -44,6 +45,14 @@ sub new {
print $fh "# test $test\n";
print $fh "server:\n";
print $fh " chroot: \"\"\n";
if ($self->{listen}{domain} && $self->{listen}{domain} == AF_INET) {
print $fh " do-ip4: yes\n";
print $fh " do-ip6: no\n";
}
if ($self->{listen}{domain} && $self->{listen}{domain} == AF_INET6) {
print $fh " do-ip4: no\n";
print $fh " do-ip6: yes\n";
}
print $fh " ip-address: $self->{addr}\n";
print $fh " pidfile: \"\"\n";
print $fh " port: $self->{port}\n";
Expand Down
8 changes: 8 additions & 0 deletions regress/args-nsd.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@
# Read IP addresses from pf table with pfctl.
# Check that pfresolved added IPv4 and IPv6 addresses.
# Check that pf table contains all IPv4 and IPv6 addresses.
# Check that IPv4 127.0.0.1 socket was used.

use strict;
use warnings;
use Socket;

our %args = (
listen => { domain => AF_INET, addr => "127.0.0.1" },
nsd => {
record_list => [
"foo IN A 192.0.2.1",
"bar IN AAAA 2001:DB8::1",
"foobar IN A 192.0.2.2",
"foobar IN AAAA 2001:DB8::2",
],
loggrep => {
qr/listen on ip-address 127.0.0.1\@\d+ \(udp\)/ => 1,
qr/listen on ip-address [0-9A-Fa-f:]+@\d+ / => 0,
},
},
pfresolved => {
address_list => [ map { "$_.regress." } qw(foo bar foobar) ],
loggrep => {
qr/-r 127.0.0.1\@\d+/ => 1,
qr{added: 192.0.2.1/32,} => 1,
qr{added: 2001:db8::1/128,} => 1,
qr{added: 192.0.2.2/32,} => 1,
Expand Down
48 changes: 48 additions & 0 deletions regress/args-nsd6.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Create zone file with A and AAAA records in zone regress.
# Start nsd with zone file listening on ::1.
# Write hosts of regress zone into pfresolved config.
# Start pfresolved with nsd as resolver.
# Wait until pfresolved creates table regress-pfresolved.
# Read IP addresses from pf table with pfctl.
# Check that pfresolved added IPv4 and IPv6 addresses.
# Check that pf table contains all IPv4 and IPv6 addresses.
# Check that IPv6 ::1 socket was used.

use strict;
use warnings;
use Socket;

our %args = (
nsd => {
listen => { domain => AF_INET6, addr => "::1" },
record_list => [
"foo IN A 192.0.2.1",
"bar IN AAAA 2001:DB8::1",
"foobar IN A 192.0.2.2",
"foobar IN AAAA 2001:DB8::2",
],
loggrep => {
qr/listen on ip-address [0-9.]\@\d+ / => 0,
qr/listen on ip-address ::1@\d+ \(udp\) / => 1,
},
},
pfresolved => {
address_list => [ map { "$_.regress." } qw(foo bar foobar) ],
loggrep => {
qr/-r ::1\@\d+/ => 1,
qr{added: 192.0.2.1/32,} => 1,
qr{added: 2001:db8::1/128,} => 1,
qr{added: 192.0.2.2/32,} => 1,
qr{added: 2001:db8::2/128,} => 1,
},
},
pfctl => {
updates => 5,
loggrep => {
qr/^ 192.0.2.[12]$/ => 2,
qr/^ 2001:db8::[12]$/ => 2,
},
},
);

1;

0 comments on commit a914dea

Please sign in to comment.