summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/VyattaQosTrafficShaper.pm18
-rw-r--r--scripts/VyattaQosUtil.pm15
2 files changed, 31 insertions, 2 deletions
diff --git a/scripts/VyattaQosTrafficShaper.pm b/scripts/VyattaQosTrafficShaper.pm
index 5ba60dd..f321e9b 100644
--- a/scripts/VyattaQosTrafficShaper.pm
+++ b/scripts/VyattaQosTrafficShaper.pm
@@ -253,9 +253,27 @@ sub new {
bless $self, $class;
$self->_define($config);
+ $self->_validate($config);
+
return $self;
}
+sub _validate {
+ my $self = shift;
+
+ if ( $self->{_rate} ne "auto" ) {
+ my $classes = $self->{_classes};
+ my $default = shift @$classes;
+ my $rate = VyattaQosUtil::getRate($self->{_rate});
+
+ $default->rateCheck($rate, "$self->{_level} default");
+
+ foreach my $class (@$classes) {
+ $class->rateCheck($rate, "$self->{_level} class $class->{id}");
+ }
+ }
+}
+
# Rate can be something like "auto" or "10.2mbit"
sub _getAutoRate {
my ($rate, $dev) = @_;
diff --git a/scripts/VyattaQosUtil.pm b/scripts/VyattaQosUtil.pm
index f847116..eca0ca3 100644
--- a/scripts/VyattaQosUtil.pm
+++ b/scripts/VyattaQosUtil.pm
@@ -220,17 +220,28 @@ sub getIfIndex {
# return result in bits per second
sub interfaceRate {
my ($interface) = @_;
+ my $speed;
my $config = new VyattaConfig;
$config->setLevel("interfaces ethernet");
if ($config->exists("$interface")) {
- my $speed = $config->returnValue("$interface speed");
+ $speed = $config->returnValue("$interface speed");
if (defined($speed) && $speed ne "auto") {
return $speed * 1000000;
}
}
- return ethtoolRate($interface);
+ # During boot it may take time for auto-negotiation
+ for (my $retries = 0; $retries < 5; $retries++) {
+ $speed = ethtoolRate($interface);
+ if (defined $speed) {
+ return $speed;
+ }
+ sleep 1;
+ }
+
+ warn "Could not determine speed for $interface, assuming 100mbit\n";
+ return 100 * 1000000;
}
## ethtoolRate("eth0")