From f7e9c8ff3f02586d290f4618986dcac0b2a102d1 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 23 Jul 2008 15:02:38 -0700 Subject: Handle auto bandwidth value better Need to handle the case of devices that don't know their current speed. In this case, ethtool will print "Unknown!" which the old code wasn't handling right. Move the default speed stuff down into traffic shaper code as well, so any future policies using auto can make other choices as to what to do in this case. Bugfix: 3450 --- scripts/VyattaQosTrafficShaper.pm | 9 +++++---- scripts/VyattaQosUtil.pm | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/VyattaQosTrafficShaper.pm b/scripts/VyattaQosTrafficShaper.pm index e282533..ce4ea3f 100644 --- a/scripts/VyattaQosTrafficShaper.pm +++ b/scripts/VyattaQosTrafficShaper.pm @@ -106,7 +106,7 @@ my $rate = _getPercentRate($self->{_rate}, $limit); if ($rate > $limit) { - print "Configuration error in: $level\n"; + print STDERR "Configuration error in: $level\n"; printf STDERR "The bandwidth reserved for this class (%dKbps) must be less than\n", $rate / 1000; @@ -117,7 +117,7 @@ my $ceil = _getPercentRate($self->{_ceiling}, $limit); if (defined $ceil && $ceil < $rate) { - print "Configuration error in: $level\n"; + print STDERR "Configuration error in: $level\n"; printf STDERR "The bandwidth ceiling for this class (%dKbps) must be greater or equal to\n", $ceil / 1000; @@ -281,8 +281,9 @@ sub _getAutoRate { if ( $rate eq "auto" ) { $rate = VyattaQosUtil::interfaceRate($dev); - if ( ! defined $rate ) { - die "Interface $dev speed cannot be determined; use explicit bandwidth value\n"; + if (! defined $rate ) { + print STDERR "Interface $dev speed cannot be determined (assuming 10mbit)\n"; + $rate = 10000000; } } else { $rate = VyattaQosUtil::getRate($rate); diff --git a/scripts/VyattaQosUtil.pm b/scripts/VyattaQosUtil.pm index eca0ca3..668f5c1 100644 --- a/scripts/VyattaQosUtil.pm +++ b/scripts/VyattaQosUtil.pm @@ -235,13 +235,12 @@ sub interfaceRate { for (my $retries = 0; $retries < 5; $retries++) { $speed = ethtoolRate($interface); if (defined $speed) { - return $speed; + last; } sleep 1; } - warn "Could not determine speed for $interface, assuming 100mbit\n"; - return 100 * 1000000; + return $speed; } ## ethtoolRate("eth0") @@ -265,8 +264,10 @@ sub ethtoolRate { while (<$ethtool>) { my @line = split; if ($line[0] =~ /^Speed:/) { - $rate = $line[1]; - $rate =~ s#Mb/s#000000#; + if ($line[1] =~ /[0-9]+Mb\/s/ ) { + $rate = $line[1]; + $rate =~ s#Mb/s#000000#; + } last; } } -- cgit v1.2.3