From 71b9bb01926ee220b73fb3135c5e7f5de9c80023 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 20 Jul 2010 14:50:43 -0700 Subject: Validate shaper class ceiling Bug 5879 --- lib/Vyatta/Qos/ShaperClass.pm | 13 +++++-------- lib/Vyatta/Qos/Util.pm | 7 +++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/Vyatta/Qos/ShaperClass.pm b/lib/Vyatta/Qos/ShaperClass.pm index 088d37f..464c58d 100644 --- a/lib/Vyatta/Qos/ShaperClass.pm +++ b/lib/Vyatta/Qos/ShaperClass.pm @@ -78,7 +78,7 @@ sub matchRules { sub _getPercentRate { my ( $rate, $speed ) = @_; - return unless $rate; # no rate defined; + return unless defined $rate; # Rate might be a percentage of speed if ( $rate =~ /%$/ ) { @@ -87,13 +87,10 @@ sub _getPercentRate { die "Invalid percentage bandwidth: $percent\n"; } - $rate = ( $percent * $speed ) / 100.; - } - else { - $rate = getRate($rate); - } + return ( $percent * $speed ) / 100.; + } - return $rate; + return getRate($rate); } sub prioQdisc { @@ -223,7 +220,7 @@ sub rateCheck { } my $ceil = _getPercentRate( $self->{_ceiling}, $ifspeed ); - if ( defined $ceil && $ceil < $rate ) { + if ( defined($ceil) && $ceil < $rate ) { print STDERR "Configuration error in: $level\n"; printf STDERR "The bandwidth ceiling for this class (%dKbps) must be greater or equal to\n", diff --git a/lib/Vyatta/Qos/Util.pm b/lib/Vyatta/Qos/Util.pm index 7c7758d..afd6aaf 100644 --- a/lib/Vyatta/Qos/Util.pm +++ b/lib/Vyatta/Qos/Util.pm @@ -14,7 +14,6 @@ # Portions created by Vyatta are Copyright (C) 2008 Vyatta, Inc. # All Rights Reserved. # **** End License **** - package Vyatta::Qos::Util; use strict; use warnings; @@ -27,7 +26,7 @@ use base qw(Exporter); sub get_num { use POSIX qw(strtod); my ($str) = @_; - return unless $str; + return unless defined($str); # remove leading/trailing spaces $str =~ s/^\s+//; @@ -88,10 +87,10 @@ sub getAutoRate { sub getRate { my $rate = shift; - $rate or die "Rate not defined"; + defined $rate + or die "Rate not defined"; my ( $num, $suffix ) = get_num($rate); - defined $num or die "$rate is not a valid bandwidth (not a number)\n"; ( $num >= 0 ) -- cgit v1.2.3