]> git.proxmox.com Git - pve-storage.git/commitdiff
iSCSI ipv6 support
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 31 Aug 2015 09:02:25 +0000 (11:02 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 31 Aug 2015 13:50:34 +0000 (15:50 +0200)
PVE/Storage.pm
PVE/Storage/ISCSIPlugin.pm
PVE/Storage/LunCmd/Iet.pm
PVE/Storage/Plugin.pm

index d55b64585225e588b5d13945f6fe6611dff3b599..927219ab878fd99287973c5cccece722eb80eb40 100755 (executable)
@@ -12,7 +12,7 @@ use File::Path;
 use Cwd 'abs_path';
 use Socket;
 
-use PVE::Tools qw(run_command file_read_firstline);
+use PVE::Tools qw(run_command file_read_firstline $IPV6RE);
 use PVE::Cluster qw(cfs_read_file cfs_lock_file);
 use PVE::Exception qw(raise_param_exc);
 use PVE::JSONSchema;
@@ -1008,12 +1008,11 @@ sub scan_zfs {
 sub resolv_portal {
     my ($portal, $noerr) = @_;
 
-    if ($portal =~ m/^([^:]+)(:(\d+))?$/) {
-       my $server = $1;
-       my $port = $3;
-
+    my ($server, $port) = PVE::Tools::parse_host_and_port($portal);
+    if ($server) {
        if (my $ip = resolv_server($server)) {
            $server = $ip;
+           $server = "[$server]" if $server =~ /^$IPV6RE$/;
            return $port ? "$server:$port" : $server;
        }
     }
index 7614bf093449a6daa8d1a321e99cdfc1f52826bb..b6c722467588f0cabb05a555bf02bee1a72abb1c 100644 (file)
@@ -5,10 +5,9 @@ use warnings;
 use File::stat;
 use IO::Dir;
 use IO::File;
-use PVE::Tools qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach);
+use PVE::Tools qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach $IPV4RE $IPV6RE);
 use PVE::Storage::Plugin;
 use PVE::JSONSchema qw(get_standard_option);
-use Net::Ping;
 
 use base qw(PVE::Storage::Plugin);
 
@@ -62,10 +61,9 @@ sub iscsi_session_list {
 sub iscsi_test_portal {
     my ($portal) = @_;
 
-    my ($server, $port) = split(':', $portal);
-    my $p = Net::Ping->new("tcp", 2);
-    $p->port_number($port || 3260);
-    return $p->ping($server);
+    my ($server, $port) = PVE::Tools::parse_host_and_port($portal);
+    return 0 if !$server;
+    return PVE::Network::tcp_ping($server, $port || 3260, 2);
 }
 
 sub iscsi_discovery {
@@ -83,7 +81,7 @@ sub iscsi_discovery {
     run_command($cmd, outfunc => sub {
        my $line = shift;
 
-       if ($line =~ m/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+)\,\S+\s+(\S+)\s*$/) {
+       if ($line =~ m/^((?:$IPV4RE|\[$IPV6RE\]):\d+)\,\S+\s+(\S+)\s*$/) {
            my $portal = $1;
            my $target = $2;
            # one target can have more than one portal (multipath).
index 98c062bd2d45f92621c1f4f275dfea5f447c3cc8..4a8ebd5a1af49927054aa1b7356e33081ebe83bc 100644 (file)
@@ -57,12 +57,12 @@ my $execute_command = sub {
     $err .= "$line";
     };
 
-    $target = 'root@' . $scfg->{portal};
-
     if ($exec eq 'scp') {
-        $cmd = [@scp_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $method, "$target:$params[0]"];
+        $target = 'root@[' . $scfg->{portal} . ']';
+        $cmd = [@scp_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", '--', $method, "$target:$params[0]"];
     } else {
-        $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $method, @params];
+        $target = 'root@' . $scfg->{portal};
+        $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, '--', $method, @params];
     }
 
     eval {
index 7325535afd1075efadd4a097894a73aeba24eaba..6741fecf2bf8690cedf7eb070e00859f608ebe8e 100644 (file)
@@ -133,7 +133,7 @@ sub verify_portal_dns {
     my ($portal, $noerr) = @_;
 
     # IP or DNS name with optional port
-    if ($portal !~ m/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|[[:alnum:]\-\.]+)(:\d+)?$/) {
+    if (!PVE::Tools::parse_host_and_port($portal)) {
        return undef if $noerr;
        die "value does not look like a valid portal address\n";
     }