[pve-devel] applied: [PATCH v2 pve-common] JSONSchema: Add format for MAC address verification

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Jan 22 11:14:00 CET 2019


On 1/22/19 11:01 AM, Christian Ebner wrote:
> Adds a format to verify MAC addresses to JSONSchema.
> 
> Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
> ---
> 
> Version 2:
>     * Droped standard option as discussed on mailing list
>     * Changed regex to be more strict
> 
>  src/PVE/JSONSchema.pm | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 

applied, thanks!

> diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
> index fb58ad3..36fa994 100644
> --- a/src/PVE/JSONSchema.pm
> +++ b/src/PVE/JSONSchema.pm
> @@ -204,6 +204,17 @@ sub pve_verify_node_name {
>      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) = @_;
> 





More information about the pve-devel mailing list