]> git.proxmox.com Git - pve-common.git/commitdiff
JSONSchema: Add format for MAC address verification
authorChristian Ebner <c.ebner@proxmox.com>
Tue, 22 Jan 2019 10:01:39 +0000 (11:01 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 22 Jan 2019 10:11:43 +0000 (11:11 +0100)
Adds a format to verify MAC addresses to JSONSchema.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
src/PVE/JSONSchema.pm

index fb58ad357f2f4449cea27e7c38eb0af1a557026d..36fa994eb7e6d4bddeb2600585a085cdc7c7ba70 100644 (file)
@@ -204,6 +204,17 @@ sub pve_verify_node_name {
     return $node;
 }
 
     return $node;
 }
 
+register_format('mac-addr', \&pve_verify_mac_addr);
+sub pve_verify_mac_addr {
+    my ($mac_addr, $noerr) = @_;
+
+    if ($mac_addr !~ m/^[0-9a-f]{2}(:[0-9a-f]{2}){5}$/i) {
+       return undef if $noerr;
+       die "value does not look like a valid MAC address\n";
+    }
+    return $mac_addr;
+}
+
 register_format('ipv4', \&pve_verify_ipv4);
 sub pve_verify_ipv4 {
     my ($ipv4, $noerr) = @_;
 register_format('ipv4', \&pve_verify_ipv4);
 sub pve_verify_ipv4 {
     my ($ipv4, $noerr) = @_;