Skip to content

Commit

Permalink
Improve error checking in get_current_bandwidth_from_tc()
Browse files Browse the repository at this point in the history
The error checking logic introduced in the previous commit was flawed. This commit fixes it.
  • Loading branch information
tievolu authored Sep 8, 2023
1 parent e4e2bf8 commit 1f6b395
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions sqm-autorate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3500,7 +3500,9 @@ sub get_current_bandwidth {
# from the SQM config. We should only need to do this once during initialisation.
sub get_current_bandwidth_from_tc {
my ($direction) = @_;


&check_direction($direction);

my $interface = "";
if ($direction eq "download") {
$interface = $dl_interfaces[0];
Expand All @@ -3511,20 +3513,25 @@ sub get_current_bandwidth_from_tc {

my @qdiscs = split(/\n/, &run_sys_command("tc -d qdisc"));
foreach my $qdisc (@qdiscs) {
if ($qdisc =~ / dev $interface .* bandwidth (\d+)(G|K|M)bit/) {
my $bw = $1;
my $bw_units = $2;
if ($bw_units eq "K") {
return $bw;
} elsif ($bw_units eq "M") {
return $bw * 1000;
} elsif ($bw_units eq "G") {
return $bw * 1000000;
if ($qdisc =~ / dev $interface .* bandwidth /) {
if ($qdisc =~ / dev $interface .* bandwidth (\d+)(G|K|M)bit/) {
my $bw = $1;
my $bw_units = $2;
if ($bw_units eq "K") {
return $bw;
} elsif ($bw_units eq "M") {
return $bw * 1000;
} elsif ($bw_units eq "G") {
return $bw * 1000000;
}
} else {
&fatal_error("Unknown bandwidth unit \"$bw_units\" in tc output");
&fatal_error("Failed to get bandwidth from tc output for interface \"$interface\":\n$qdisc");
}
}
}
}
}

# If we reach here the first interface for the specified direction wasn't listed in the tc output
&fatal_error("Failed to get bandwidth from tc output for interface \"$interface\"");
}

# Get the maximum allowed latency for the specified direction when bandwidth usage is significant
Expand Down

0 comments on commit 1f6b395

Please sign in to comment.