]> git.proxmox.com Git - pve-common.git/commitdiff
export regular expressions for IPv4 and IPv6 addresses
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 30 Oct 2013 11:38:30 +0000 (12:38 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 30 Oct 2013 11:38:30 +0000 (12:38 +0100)
The regular expression in Regexp::IPv6 is very difficult to read, so
we simply define our own here.

data/PVE/Tools.pm

index 0961e9289a690caa4f4e65a6bd54309ccca6118d..735cbdeda65eaac934437315d7ac6553c8b32354 100644 (file)
@@ -19,6 +19,8 @@ use Text::ParseWords;
 use String::ShellQuote;
 
 our @EXPORT_OK = qw(
+$IPV6RE
+$IPV4RE
 lock_file 
 lock_file_full
 run_command 
@@ -40,6 +42,22 @@ my $pvetaskdir = "$pvelogdir/tasks";
 mkdir $pvelogdir;
 mkdir $pvetaskdir;
 
+my $IPV4OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
+our $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
+my $IPV6H16 = "(?:[0-9a-fA-F]{1,4})";
+my $IPV6LS32 = "(?:(?:$IPV4RE|$IPV6H16:$IPV6H16))";
+
+our $IPV6RE = "(?:" .
+    "(?:(?:" .                             "(?:$IPV6H16:){6})$IPV6LS32)|" .
+    "(?:(?:" .                           "::(?:$IPV6H16:){5})$IPV6LS32)|" .
+    "(?:(?:(?:" .              "$IPV6H16)?::(?:$IPV6H16:){4})$IPV6LS32)|" .
+    "(?:(?:(?:(?:$IPV6H16:){0,1}$IPV6H16)?::(?:$IPV6H16:){3})$IPV6LS32)|" .
+    "(?:(?:(?:(?:$IPV6H16:){0,2}$IPV6H16)?::(?:$IPV6H16:){2})$IPV6LS32)|" .
+    "(?:(?:(?:(?:$IPV6H16:){0,3}$IPV6H16)?::(?:$IPV6H16:){1})$IPV6LS32)|" .
+    "(?:(?:(?:(?:$IPV6H16:){0,4}$IPV6H16)?::" .           ")$IPV6LS32)|" .
+    "(?:(?:(?:(?:$IPV6H16:){0,5}$IPV6H16)?::" .            ")$IPV6H16)|" .
+    "(?:(?:(?:(?:$IPV6H16:){0,6}$IPV6H16)?::" .                    ")))";
+
 sub run_with_timeout {
     my ($timeout, $code, @param) = @_;