summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2008-02-05 10:50:00 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2008-02-05 10:50:00 -0800
commit50127014a2b863fb4b5e31f5f61230b22f371e63 (patch)
tree0139682d74ed9068bc8f0e2bc53d349ba2841715 /scripts
parentd8075f1b0189a8a788dd8c5b31f8dcbd4e652415 (diff)
downloadvyatta-cfg-qos-50127014a2b863fb4b5e31f5f61230b22f371e63.tar.gz
vyatta-cfg-qos-50127014a2b863fb4b5e31f5f61230b22f371e63.zip
handle undefined values better
If getprotocol or getdsfield is called with undefined value, then return undefined.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/VyattaQosUtil.pm24
1 files changed, 14 insertions, 10 deletions
diff --git a/scripts/VyattaQosUtil.pm b/scripts/VyattaQosUtil.pm
index ef2e916..3a115db 100644
--- a/scripts/VyattaQosUtil.pm
+++ b/scripts/VyattaQosUtil.pm
@@ -2,6 +2,7 @@ package VyattaQosUtil;
use POSIX;
require Exporter;
@EXPORT = qw/getRate getSize getProtocol getDsfield interfaceRate/;
+use strict;
sub get_num {
my ($str) = @_;
@@ -77,17 +78,18 @@ sub getSize {
}
sub getProtocol {
- my ($p) = @_;
+ my ($str) = @_;
- if ($p =~ /^([0-9]+)|(0x[0-9a-fA-F]+)$/) {
- if ($p < 0 || $p > 255) {
- die "$p is not a valid protocol number\n";
+ defined $str or return;
+ if ($str =~ /^([0-9]+)|(0x[0-9a-fA-F]+)$/) {
+ if ($str < 0 || $str > 255) {
+ die "$str is not a valid protocol number\n";
}
- return $p;
+ return $str;
}
- my ($name, $aliases, $proto) = getprotobyname($p);
- (defined $proto) or die "\"$p\" unknown protocol\n";
+ my ($name, $aliases, $proto) = getprotobyname($str);
+ (defined $proto) or die "\"$str\" unknown protocol\n";
return $proto;
}
@@ -98,6 +100,8 @@ sub getDsfield {
my $match = undef;
my $dsFileName = '/etc/iproute2/rt_dsfield';
+ defined $str or return;
+
if ($str =~ /^([0-9]+)|(0x[0-9a-fA-F]+)$/) {
if ($str < 0 || $str > 255) {
die "$str is not a valid dsfield value\n";
@@ -109,9 +113,9 @@ sub getDsfield {
while (<$ds>) {
next if /^#/;
chomp;
- my @fields = split;
- if ($str eq $fields[1]) {
- $match = $fields[0];
+ my ($value, $name) = split;
+ if ($str eq $name) {
+ $match = $value;
last;
}
}