From 4a97278a26e946b079963accab6e7cb605c703e1 Mon Sep 17 00:00:00 2001 From: Alexander Bluhm Date: Fri, 3 Nov 2023 15:39:07 +0100 Subject: [PATCH] Test localhost in config file. Write localhost into pfresolved config. Wait until pfresolved creates table regress-pfresolved. Read IP addresses from pf table with pfctl. Check that pfresolved added 127.0.0.1 and ::1. Check that table contains 127.0.0.1 and ::1. --- regress/Pfctl.pm | 12 ++++++++---- regress/Pfresolved.pm | 2 +- regress/args-localhost.pl | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 regress/args-localhost.pl diff --git a/regress/Pfctl.pm b/regress/Pfctl.pm index dd2af2b..f0acda3 100644 --- a/regress/Pfctl.pm +++ b/regress/Pfctl.pm @@ -34,12 +34,16 @@ sub new { sub child { my $self = shift; + my $timeout = $self->{timeout} || 5; + my $updates = $self->{updates}; my $pfresolved = $self->{pfresolved}; - my $table = "updating addresses for pf table"; - $pfresolved->loggrep($table, 5) - or die ref($self), " no '$table' in $pfresolved->{logfile} ". - "after 5 seconds"; + my $table = "updated addresses for pf table"; + my $tomsg = $timeout ? " after $timeout seconds" : ""; + my $upmsg = $updates ? " for $updates times" : ""; + $pfresolved->loggrep($table, $timeout, $updates) + or die ref($self), " no '$table' in $pfresolved->{logfile}", + $tomsg, $upmsg; open(STDOUT, '>&', \*STDERR) or die ref($self), " dup STDOUT failed: $!"; diff --git a/regress/Pfresolved.pm b/regress/Pfresolved.pm index 6d29a3b..687740d 100644 --- a/regress/Pfresolved.pm +++ b/regress/Pfresolved.pm @@ -68,7 +68,7 @@ sub child { my @ktrace; @ktrace = ($self->{ktraceexec}, "-i", "-f", $self->{ktracefile}) if $self->{ktraceexec}; - my @cmd = (@sudo, @ktrace, $self->{execfile}, "-dvv", + my @cmd = (@sudo, @ktrace, $self->{execfile}, "-dvvv", "-f", $self->{conffile}); print STDERR "execute: @cmd\n"; exec @cmd; diff --git a/regress/args-localhost.pl b/regress/args-localhost.pl new file mode 100644 index 0000000..2081f9e --- /dev/null +++ b/regress/args-localhost.pl @@ -0,0 +1,27 @@ +# Write localhost into pfresolved config. +# Wait until pfresolved creates table regress-pfresolved. +# Read IP addresses from pf table with pfctl. +# Check that pfresolved added 127.0.0.1 and ::1. +# Check that table contains 127.0.0.1 and ::1. + +use strict; +use warnings; + +our %args = ( + pfresolved => { + address_list => [qw(localhost.)], # must resolve A and AAAA + loggrep => { + qr{added: 127.0.0.1/32,} => 1, + qr{added: ::1/128,} => 1, + }, + }, + pfctl => { + updates => 3, + loggrep => { + qr/^ 127.0.0.1$/ => 1, + qr/^ ::1$/ => 1, + }, + }, +); + +1;