-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write constant IP addresses into pfresolved config. Wait until pfresolved creates table regress-pfresolved. Read IP addresses from pf table with pfctl. Check that output IP is the same as input IP.
- Loading branch information
Showing
6 changed files
with
99 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# $OpenBSD$ | ||
|
||
# Copyright (c) 2023 Alexander Bluhm <bluhm@openbsd.org> | ||
# | ||
# Permission to use, copy, modify, and distribute this software for any | ||
# purpose with or without fee is hereby granted, provided that the above | ||
# copyright notice and this permission notice appear in all copies. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
# ANY SPECIAL, DIRECT, 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. | ||
|
||
use strict; | ||
use warnings; | ||
|
||
package Pfctl; | ||
use parent 'Proc'; | ||
use Carp; | ||
|
||
sub new { | ||
my $class = shift; | ||
my %args = @_; | ||
$args{func} ||= \&func; | ||
$args{logfile} ||= "pfctl.log"; | ||
$args{up} ||= "Table"; | ||
|
||
my $self = Proc::new($class, %args); | ||
return $self; | ||
} | ||
|
||
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"; | ||
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: $!"; | ||
} | ||
|
||
sub func { | ||
my $self = shift; | ||
my @sudo = $ENV{SUDO} ? $ENV{SUDO} : (); | ||
|
||
my @cmd = (@sudo, qw(pfctl -t regress-pfresolved -T show)); | ||
system(@cmd) | ||
and die die ref($self), " command '@cmd' failed: $?"; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Write constant IP addresses into pfresolved config. | ||
# Wait until pfresolved creates table regress-pfresolved. | ||
# Read IP addresses from pf table with pfctl. | ||
# Check that output IP is the same as input IP. | ||
|
||
use strict; | ||
use warnings; | ||
|
||
our %args = ( | ||
pfresolved => { | ||
address_list => [qw(192.0.2.1 2001:DB8::1)], # documentation IPs | ||
}, | ||
pfctl => { | ||
loggrep => { | ||
qr/^ 192.0.2.1$/ => 1, | ||
qr/^ 2001:db8::1$/ => 1, | ||
}, | ||
}, | ||
); | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters