ipv6prefix matches an ipv6 prefix length (0..128)
ipsubnet matches an ipv4mask or an ipv6prefix
---
 src/PVE/JSONSchema.pm | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 36a2de9..8fa5651 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -220,6 +220,28 @@ sub pve_verify_ipv4mask {
     return $mask;
 }
 
+register_format('ipv6prefix', \&pve_verify_ipv6prefix);
+sub pve_verify_ipv6prefix {
+    my ($subnet, $noerr) = @_;
+    ($subnet) = grep(/^\d+$/, $subnet);
+    return $subnet if defined($subnet) && $subnet <= 128;
+    return undef if $noerr;
+    die "value is not a valid ipv6 subnet range\n";
+}
+
+register_format('ipsubnet', \&pve_verify_ipsubnet);
+sub pve_verify_ipsubnet {
+    my ($subnet, $noerr) = @_;
+
+    if (!(pve_verify_ipv6prefix($subnet, 1) ||
+          pve_verify_ipv4mask($subnet, 1)))
+    {
+       return undef if $noerr;
+       die "value does not look like a valid subnet mask\n";
+    }
+    return $subnet;
+}
+
 register_format('CIDR', \&pve_verify_cidr);
 sub pve_verify_cidr {
     my ($cidr, $noerr) = @_;
-- 
2.1.4


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to