mirror of
https://git.proxmox.com/git/pve-common
synced 2025-08-06 15:29:54 +00:00
Added PVE::Network::tcp_ping to replace Net::Ping
We use Net::Ping twice in pve-storage (once for ISCSIPlugin and once in GlusterfsPlugin, both with the 'tcp' variant.), but Net::Ping doesn't support IPv6.
This commit is contained in:
parent
c38cea65b6
commit
b6bff92ee5
@ -6,6 +6,8 @@ use PVE::Tools qw(run_command);
|
||||
use PVE::ProcFSTools;
|
||||
use PVE::INotify;
|
||||
use File::Basename;
|
||||
use IO::Socket::IP;
|
||||
use POSIX qw(ECONNREFUSED);
|
||||
|
||||
# host network related utility functions
|
||||
|
||||
@ -437,4 +439,32 @@ sub activate_bridge_vlan {
|
||||
return $bridgevlan;
|
||||
}
|
||||
|
||||
sub tcp_ping {
|
||||
my ($host, $port, $timeout) = @_;
|
||||
|
||||
my $refused = 1;
|
||||
|
||||
$timeout = 3 if !$timeout; # sane default
|
||||
if (!$port) {
|
||||
# Net::Ping defaults to the echo port
|
||||
$port = 7;
|
||||
} else {
|
||||
# Net::Ping's port_number() implies service_check(1)
|
||||
$refused = 0;
|
||||
}
|
||||
|
||||
my ($sock, $result);
|
||||
eval {
|
||||
$result = PVE::Tools::run_with_timeout($timeout, sub {
|
||||
$sock = IO::Socket::IP->new(PeerHost => $host, PeerPort => $port, Type => SOCK_STREAM);
|
||||
$result = $refused if $! == ECONNREFUSED;
|
||||
});
|
||||
};
|
||||
if ($sock) {
|
||||
$sock->close();
|
||||
$result = 1;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user