Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mrash/fwknop
Browse files Browse the repository at this point in the history
  • Loading branch information
damienstuart committed Feb 4, 2024
2 parents c076802 + 77cc88a commit 2d02b54
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 28 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Expand Up @@ -11,6 +11,11 @@ fwknop-2.6.11 (12/09/2019):
--user-agent option to specify any desired User-Agent string. This
feature was added to close issue #296 reported by github user
@fishcreek.
- [test suite] Add gpg.conf and gpg-agent.conf to set 'pinentry-mode
loopback' to restore GPG full cycle tests. This works with GPG 2.2.27 on
Ubuntu 22.04 for example.
- [test suite] Prefer the 'ip' command over the older 'ifconfig' command
for interface operations and loopback detection.

fwknop-2.6.10 (08/06/2018):
- [server] Add MAX_FW_TIMEOUT to access.conf stanzas to allow a maximum
Expand Down
99 changes: 71 additions & 28 deletions test/test-fwknop.pl
Expand Up @@ -305,6 +305,7 @@
our $perl_path = '';
our $prove_path = '';
our $ifconfig_path = '';
our $ip_path = '';
my $readelf_path = '';
our $platform = '';
our $help = 0;
Expand Down Expand Up @@ -760,7 +761,9 @@
### run an fwknop command under gdb from a previous test run
exit &gdb_test_cmd() if $gdb_test_file;

$ifconfig_path = &find_command('ifconfig') unless $ifconfig_path;
### only need one of 'ip' or 'ifconfig', prefer 'ip'
$ip_path = &find_command('ip') unless $ip_path;
$ifconfig_path = &find_command('ifconfig') unless $ifconfig_path or $ip_path;
&identify_loopback_intf() unless $list_mode or $client_only_mode;

### make sure everything looks as expected before continuing
Expand Down Expand Up @@ -1982,15 +1985,15 @@ ()
open F, "< $make_file" or die $!;
while (<F>) {
if (m|test/$conf_dir/(\S+)|) {
if (m|conf/(\S+)|) {
$makefile_conf_files{$1} = '';
} elsif (m|test/$tests_dir/(\S+)|) {
} elsif (m|test/tests/(\S+)|) {
$makefile_test_scripts{$1} = '';
}
}
close F;
for my $f (glob("$conf_dir/*")) {
for my $f (glob("conf/*")) {
next if -d $f;
next unless $f =~ /\.conf/ or $f =~ /fwknop/;
if ($f =~ m|$conf_dir/(\S+)|) {
Expand All @@ -2002,8 +2005,8 @@ ()
}
}
for my $f (glob("$tests_dir/*.pl")) {
if ($f =~ m|$tests_dir/(\S+)|) {
for my $f (glob("tests/*.pl")) {
if ($f =~ m|tests/(\S+)|) {
unless (defined $makefile_test_scripts{$1}) {
&write_test_file("[-] test suite script file $1 not in $make_file.\n",
$curr_test_file);
Expand Down Expand Up @@ -6133,9 +6136,15 @@ ()

&start_fwknopd($test_hr);

&run_cmd("$ifconfig_path lo down", $cmd_out_tmp, $curr_test_file);
sleep 5;
&run_cmd("$ifconfig_path lo up", $cmd_out_tmp, $curr_test_file);
if ($ip_path) {
&run_cmd("$ip_path link set $loopback_intf down", $cmd_out_tmp, $curr_test_file);
sleep 5;
&run_cmd("$ip_path link set $loopback_intf up", $cmd_out_tmp, $curr_test_file);
} else {
&run_cmd("$ifconfig_path $loopback_intf down", $cmd_out_tmp, $curr_test_file);
sleep 5;
&run_cmd("$ifconfig_path $loopback_intf up", $cmd_out_tmp, $curr_test_file);
}

if (&is_fwknopd_running()) {
$rv = 0 unless $test_hr->{'no_exit_intf_down'} eq $YES;
Expand Down Expand Up @@ -7107,11 +7116,17 @@ ()
$cmd_out_tmp, $curr_test_file);

my $have_gpgme = 0;
my $net_cmd = '';
if ($ip_path) {
$net_cmd = "$ip_path addr";
} else {
$net_cmd = "$ifconfig_path -a";
}

for my $cmd (
'uname -a',
'uptime',
'ifconfig -a',
"$net_cmd",
'ls -l /etc', 'if [ -e /etc/issue ]; then cat /etc/issue; fi',
'if [ `which iptables` ]; then iptables -V; fi',
'if [ -e /proc/cpuinfo ]; then cat /proc/cpuinfo; fi',
Expand Down Expand Up @@ -7761,7 +7776,7 @@ ()
$lcov_path = &find_command('lcov') unless $lcov_path;
$genhtml_path = &find_command('genhtml') unless $genhtml_path;

unless ($ifconfig_path) {
unless ($ip_path or $ifconfig_path) {
push @tests_to_exclude, qr/down interface/;
}

Expand Down Expand Up @@ -7980,10 +7995,18 @@ ()
sub identify_loopback_intf() {
return if $loopback_intf;

die "[*] ifconfig command not found, use --loopback <name>"
unless $ifconfig_path;
die "[*] ip and ifconfig commands not found, use --loopback <name>"
unless $ip_path or $ifconfig_path;

### Linux 'ip addr'
### 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
### link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
### inet 127.0.0.1/8 scope host lo
### valid_lft forever preferred_lft forever
### inet6 ::1/128 scope host
### valid_lft forever preferred_lft forever

### Linux:
### Linux 'ifconfig -a':

### lo Link encap:Local Loopback
### inet addr:127.0.0.1 Mask:255.0.0.0
Expand All @@ -8006,23 +8029,43 @@ ()
my $intf = '';
my $found_loopback_intf = 0;

my $cmd = "$ifconfig_path -a";
open C, "$cmd |" or die "[*] (use --loopback <name>) $cmd: $!";
while (<C>) {
if (/^(\S+?):?\s+.*loopback/i) {
$intf = $1;
next;
}
if (/^\S/ and $intf and not $found_loopback_intf) {
### should not happen
last;
if ($ip_path) {
my $cmd = "$ip_path addr";
open C, "$cmd |" or die "[*] (use --loopback <name>) $cmd: $!";
while (<C>) {
if (/^\s*\d+\:\s+(\S+?)\:\s+.*loopback/i) {
$intf = $1;
next;
}
if (/^\S/ and $intf and not $found_loopback_intf) {
### should not happen
last;
}
if ($intf and /\b127\.0\.0\.1/) {
$found_loopback_intf = 1;
last;
}
}
if ($intf and /\b127\.0\.0\.1\b/) {
$found_loopback_intf = 1;
last;
close C;
} else {
my $cmd = "$ifconfig_path -a";
open C, "$cmd |" or die "[*] (use --loopback <name>) $cmd: $!";
while (<C>) {
if (/^(\S+?):?\s+.*loopback/i) {
$intf = $1;
next;
}
if (/^\S/ and $intf and not $found_loopback_intf) {
### should not happen
last;
}
if ($intf and /\b127\.0\.0\.1\b/) {
$found_loopback_intf = 1;
last;
}
}
close C;
}
close C;

die "[*] could not determine loopback interface, use --loopback <name>"
unless $found_loopback_intf;
Expand Down

0 comments on commit 2d02b54

Please sign in to comment.