Skip to content

Commit

Permalink
Improve parsing of tc output
Browse files Browse the repository at this point in the history
get_current_bandwidth_from_tc() failed to recognise bandwidths displayed in gigabits.

The fix adds code to handle gigabit units and to report a fatal error if the units are not recognised.
  • Loading branch information
tievolu authored Sep 7, 2023
1 parent 242a333 commit e4e2bf8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sqm-autorate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3511,14 +3511,18 @@ 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+)(K|M)bit/) {
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;
}
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");
}
}
}
}
Expand Down

0 comments on commit e4e2bf8

Please sign in to comment.