Skip to content

Commit

Permalink
Allow to secify interface number or use all numbers in netlink.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluhm committed Dec 24, 2023
1 parent ca51b68 commit c9798da
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 19 deletions.
53 changes: 48 additions & 5 deletions net.pl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
-d date set date string and change to sub directory, may be current
-D cvsdate update sources from cvs to this date
-h host user and host for network link test, user defaults to root
-i iface list of interfaces: all @allifaces
-i iface list of interfaces, may contain number: all @allifaces
-m modify list of modify modes: all @allmodifymodes
-N repeat number of build, reboot, test repetitions per step
-P patch apply patch to clean kernel source
Expand Down Expand Up @@ -138,6 +138,11 @@
print $fh "TESTMODES ", join(" ", sort keys %testmode), "\n";
close($fh);

delete $ENV{MANAGEMENT_IF};
environment("$netlinkdir/bin/env-$host.sh");
my $management_if = $ENV{MANAGEMENT_IF}
or die "MANAGEMENT_IF is not in 'env-$host.sh'";

# setup remote machines

usehosts(bindir => "$netlinkdir/bin", date => $date,
Expand Down Expand Up @@ -198,16 +203,29 @@ END
my @dmesg = <$fh>;
$iface = join(",", @allifaces) if $iface eq "all";
foreach my $if (split(/,/, $iface)) {
grep { $_ eq $if } @allifaces
my ($iftype, $num) = $if =~ /^([a-z]+)([0-9]+)?$/
or die "Invalid interface '$if'";
grep { $_ eq $iftype } @allifaces
or die "Unknown interface '$if'";
unless (grep { /^$if\d+ at / } @dmesg) {
unless (grep { /^$iftype\d+ at / } @dmesg) {
if ($opts{i} eq "all") {
next;
} else {
die "Interface '$if' does not exist in dmesg";
die "Interface type '$if' does not exist in dmesg";
}
}
push @ifaces, "iface-$if";
my $numre = defined($num) ? qr/$num/ : qr/[0-9]*[02468]+/;
foreach my $ifnum (map { /^$iftype($numre) at / ? $1 : () } @dmesg) {
if (($iftype.($ifnum + 0)) eq $management_if ||
($iftype.($ifnum + 1)) eq $management_if) {
if (defined($num)) {
die "Cannot use inferface '$if', conflicts management";
} else {
next;
}
}
push @ifaces, "iface-$iftype$ifnum";
}
}
@ifaces or die "No suitable interfaces in '$iface' found";
}
Expand Down Expand Up @@ -339,6 +357,31 @@ END

exit;

# parse shell script that is setting environment for some tests
# FOO=bar
# FOO="bar"
# export FOO=bar
# export FOO BAR
sub environment {
my $file = shift;

open(my $fh, '<', $file)
or die "Open '$file' for reading failed: $!";
while (<$fh>) {
chomp;
s/#.*$//;
s/\s+$//;
s/^export\s+(?=\w+=)//;
s/^export\s+\w+.*//;
next if /^$/;
if (/^(\w+)=(\S+)$/ or /^(\w+)="([^"]*)"/ or /^(\w+)='([^']*)'/) {
$ENV{$1}=$2;
} else {
die "Unknown environment line in '$file': $_";
}
}
}
sub mkdir_num {
my ($path) = @_;
Expand Down
1 change: 1 addition & 0 deletions netlink-html.pl
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ sub html_hier_test_row_util {
"iface-ixl" => 10 * 10 ** 9,
"iface-bnxt" => 10 * 10 ** 9,
);
$iface =~ s/\d+$//;
my $linerate = $linerates{$iface} || 10 ** 9;
my $rate = $value / $linerate;
my $style = sprintf(
Expand Down
42 changes: 28 additions & 14 deletions netlink.pl
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@
my @alltestmodes = sort qw(all fragment icmp tcp udp splice);

my %opts;
getopts('c:e:i:l:m:r:t:v', \%opts) or do {
getopts('c:e:i:m:t:v', \%opts) or do {
print STDERR <<"EOF";
usage: netlink.pl [-v] [-c pseudo] [-e environment] [-i iface]
[-l index] [-m modify] [-r index] [-t timeout] [test ...]
usage: netlink.pl [-v] [-c pseudo] [-e environment] [-i iface] [-m modify]
[-t timeout] [test ...]
-c pseudo pseudo network device: @allpseudos
-e environ parse environment for tests from shell script
-i iface interface: @allifaces
-l index interface index, default 0
-i iface interface, may contain number: @allifaces
-m modify modify mode: @allmodifymodes
-r index interface index, default 1
-t timeout timeout for a single test, default 60 seconds
-v verbose
test ... test mode: @alltestmodes
Expand All @@ -58,17 +56,33 @@
my $modify = $opts{m};

my $line = $ENV{NETLINK_LINE} || die "NETLINK_LINE is not in env";
my $management_if = $ENV{MANAGEMENT_IF} || die "MANAGEMENT_IF is not in env";
my $management_if = $ENV{MANAGEMENT_IF}
or die "MANAGEMENT_IF is not in env";

# ifN if N is even then it is left, odd means right.
my $left_ifidx = $opts{l} || ("${iface}0" eq $management_if? 2 : 0);
my $right_ifidx = $opts{r} || ("${iface}1" eq $management_if? 3 : 1);
my ($iftype, $ifnum) = $iface =~ /^([a-z]+)([0-9]+)?$/;
grep { $_ eq $iftype } @allifaces
or die "Unknown interface '$iface'";
my ($left_ifidx, $right_ifidx);
if (defined($ifnum)) {
$left_ifidx = $ifnum + 0;
$right_ifidx = $ifnum + 1;
} else {
$left_ifidx = 0;
$right_ifidx = 1;
}
if (($iftype.$left_ifidx) eq $management_if ||
($iftype.$right_ifidx) eq $management_if) {
if (defined($ifnum)) {
die "Cannot use inferface '$iface', conflicts management";
} else {
$left_ifidx = 2;
$right_ifidx = 3;
}
}

warn "left interface should be in the wrong network" if ($left_ifidx % 2);
warn "right interface should be in the wrong network" if (!$right_ifidx % 2);

grep { $_ eq $iface } @allifaces
or die "Unknown interface '$iface'";
!$modify || grep { $_ eq $modify } @allmodifymodes
or die "Unknnown modify mode '$modify'";
grep { $_ eq $pseudo } @allpseudos
Expand All @@ -95,7 +109,7 @@
my $ip4prefix = '10.10';
my $ip6prefix = 'fdd7:e83e:66bd:10';

my $obsd_l_if = $iface . $left_ifidx;
my $obsd_l_if = $iftype . $left_ifidx;
my $obsd_l_net = "$ip4prefix.${line}1.0/24";
my $obsd_l_addr = "$ip4prefix.${line}1.2";
my $obsd_l_net6 = "${ip6prefix}${line}1::/64";
Expand All @@ -104,7 +118,7 @@
my @obsd_l_addr_range = map { "$ip4prefix.${line}1.2$_" } 0..9;
my @obsd_l_addr6_range = map { "${ip6prefix}${line}1::2$_" } 0..9;

my $obsd_r_if = $iface . $right_ifidx;
my $obsd_r_if = $iftype . $right_ifidx;
my $obsd_r_net = "$ip4prefix.${line}2.0/24";
my $obsd_r_addr = "$ip4prefix.${line}2.3";
my $obsd_r_net6 = "${ip6prefix}${line}2::/64";
Expand Down

0 comments on commit c9798da

Please sign in to comment.