summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-24 09:42:49 +1100
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-26 13:11:15 -0800
commit4bcfe92678e6a0f4d31ea198936a21638012158f (patch)
tree161b5eff3da1d368c53a7ed00e0c43f90f168ad5 /lib
parentabe20d48f6a96a2f636672d50b9274c71acf7d9f (diff)
downloadvyatta-cfg-4bcfe92678e6a0f4d31ea198936a21638012158f.tar.gz
vyatta-cfg-4bcfe92678e6a0f4d31ea198936a21638012158f.zip
Cleanup type checker
Use standard getprotoent() rather than manual parsing. Fix perlcritic warnings.
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Vyatta/TypeChecker.pm27
1 files changed, 7 insertions, 20 deletions
diff --git a/lib/Vyatta/TypeChecker.pm b/lib/Vyatta/TypeChecker.pm
index 086fee7..45803ea 100755
--- a/lib/Vyatta/TypeChecker.pm
+++ b/lib/Vyatta/TypeChecker.pm
@@ -46,11 +46,11 @@
# }
package Vyatta::TypeChecker;
+use strict;
+
our @EXPORT = qw(findType validateType);
use base qw(Exporter);
-use strict;
-
my %type_handler = (
'ipv4' => \&validate_ipv4,
'ipv4net' => \&validate_ipv4net,
@@ -124,24 +124,13 @@ sub validate_protocol {
my $value = shift;
$value = lc $value;
return 1 if ($value eq 'all');
+
if ($value =~ /^\d+$/) {
# 0 has special meaning to iptables
return 1 if $value >= 1 and $value <= 255;
}
- if (!open(IN, "</etc/protocols")) {
- print "can't open /etc/protocols";
- return 0;
- }
- my $ret = 0;
- while (<IN>) {
- s/^([^#]*)#.*$/$1/;
- if ((/^$value\s/) || (/^\S+\s+$value\s/)) {
- $ret = 1;
- last;
- }
- }
- close IN;
- return $ret;
+
+ return defined getprotobyname($value);
}
sub validate_protocol_negate {
@@ -215,9 +204,8 @@ sub validateType {
sub findType {
my ($value, @candidates) = @_;
- if (!defined($value) || ((scalar @candidates) < 1)) {
- return undef;
- }
+ return if (!defined($value) || ((scalar @candidates) < 1)); # undef
+
foreach my $type (@candidates) {
if (!defined($type_handler{$type})) {
next;
@@ -227,7 +215,6 @@ sub findType {
return $type;
}
}
- return undef;
}
1;