summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Gilligan <gilligan@vyatta.com>2009-01-21 11:01:56 -0800
committerBob Gilligan <gilligan@vyatta.com>2009-01-21 11:01:56 -0800
commitb3146bf20dd8bfb5be2c9850c791b42cf9a3a97a (patch)
treea1ab4bd99194fc55d0b4150f52b5dc18ea648759
parentabe20d48f6a96a2f636672d50b9274c71acf7d9f (diff)
downloadvyatta-cfg-b3146bf20dd8bfb5be2c9850c791b42cf9a3a97a.tar.gz
vyatta-cfg-b3146bf20dd8bfb5be2c9850c791b42cf9a3a97a.zip
Add more IPv6 address and prefix validation functions.
-rwxr-xr-xlib/Vyatta/TypeChecker.pm44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/Vyatta/TypeChecker.pm b/lib/Vyatta/TypeChecker.pm
index 086fee7..c3dd682 100755
--- a/lib/Vyatta/TypeChecker.pm
+++ b/lib/Vyatta/TypeChecker.pm
@@ -64,6 +64,9 @@ my %type_handler = (
'macaddr' => \&validate_macaddr,
'macaddr_negate' => \&validate_macaddr_negate,
'ipv6' => \&validate_ipv6,
+ 'ipv6_negate' => \&validate_ipv6_negate,
+ 'ipv6net' => \&validate_ipv6net,
+ 'ipv6net_negate' => \&validate_ipv6net_negate,
);
sub validate_ipv4 {
@@ -195,6 +198,41 @@ sub validate_ipv6 {
return 1;
}
+sub validate_ipv6_negate {
+ my $value = shift;
+ if ($value =~ m/^\!(.*)$/) {
+ $value = $1;
+ }
+ return validate_ipv6($value);
+}
+
+sub validate_ipv6net {
+ my $value = shift;
+
+ if ($value =~ m/^(.*)\/(.*)$/) {
+ my $ipv6_addr = $1;
+ my $prefix_length = $2;
+ if ($prefix_length < 0 || $prefix_length > 128) {
+ print "Invalid prefix length: $prefix_length\n";
+ return 0;
+ }
+ return validate_ipv6($ipv6_addr);
+
+ } else {
+ print "\"$value\" is not a valid IPv6 prefix\n";
+ return 0;
+ }
+}
+
+sub validate_ipv6net_negate {
+ my $value = shift;
+
+ if ($value =~ m/^\!(.*)$/) {
+ $value = $1;
+ }
+ return validate_ipv6net($value);
+}
+
sub validateType {
my ($type, $value, $quiet) = @_;
if (!defined($type) || !defined($value)) {
@@ -231,3 +269,9 @@ sub findType {
}
1;
+
+# Local Variables:
+# mode: perl
+# indent-tabs-mode: nil
+# perl-indent-level: 2
+# End: