]> git.proxmox.com Git - pve-common.git/commitdiff
add additional methods for IP address verification
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 23 Apr 2015 06:19:03 +0000 (08:19 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 23 Apr 2015 06:19:03 +0000 (08:19 +0200)
src/PVE/JSONSchema.pm

index f42519cbfe26ee3f91cf1fbacd53323ea1e5876f..028766c13e07459122d03331400f6428bdebd53b 100644 (file)
@@ -147,13 +147,35 @@ register_format('ipv4', \&pve_verify_ipv4);
 sub pve_verify_ipv4 {
     my ($ipv4, $noerr) = @_;
 
-    if (!Net::IP::ip_is_ipv4($ipv4))  {
-       return undef if $noerr;
-       die "value does not look like a valid IP address\n";
+    if ($ipv4 !~ m/^(?:$IPV4RE)$/) {
+       return undef if $noerr;
+       die "value does not look like a valid IPv4 address\n";
     }
     return $ipv4;
 }
 
+register_format('ipv6', \&pve_verify_ipv6);
+sub pve_verify_ipv4 {
+    my ($ipv6, $noerr) = @_;
+
+    if ($ipv6 !~ m/^(?:$IPV6RE)$/) {
+       return undef if $noerr;
+       die "value does not look like a valid IPv6 address\n";
+    }
+    return $ipv6;
+}
+
+register_format('ip', \&pve_verify_ip);
+sub pve_verify_ip {
+    my ($ip, $noerr) = @_;
+
+    if ($ip !~ m/^(?:(?:$IPV4RE)|(?:$IPV6RE))$/) {
+       return undef if $noerr;
+       die "value does not look like a valid IP address\n";
+    }
+    return $ip;
+}
+
 my $ipv4_mask_hash = {
     '128.0.0.0' => 1,
     '192.0.0.0' => 2,