[pve-devel] [RFC PATCH 1/7] JSONSchema: ipv6subnet and ipsubnet

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Jun 22 16:06:54 CEST 2015


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

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 36a2de9..12a209e 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -220,6 +220,28 @@ sub pve_verify_ipv4mask {
     return $mask;
 }
 
+register_format('ipv6subnet', \&pve_verify_ipv6subnet);
+sub pve_verify_ipv6subnet {
+    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_ipv6subnet($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





More information about the pve-devel mailing list