X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=src%2FPVE%2FNetwork.pm;h=34a280f60022292469d6ed1e4c7c32793cd62981;hb=027e1e4e39772b265d32a8871b2a53d50442c7cd;hp=ff4a89c4a8beb1fe4c50174e785f72852507dee0;hpb=5d35df41fc429afe9d2639b0ab91edc38861622d;p=pve-common.git diff --git a/src/PVE/Network.pm b/src/PVE/Network.pm index ff4a89c..34a280f 100644 --- a/src/PVE/Network.pm +++ b/src/PVE/Network.pm @@ -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 @@ -411,7 +413,7 @@ sub activate_bridge_vlan { my @ifaces = (); my $dir = "/sys/class/net/$bridge/brif"; - PVE::Tools::dir_glob_foreach($dir, '((eth|bond)\d+)', sub { + PVE::Tools::dir_glob_foreach($dir, '((eth|bond)\d+(\.\d+)?)', sub { push @ifaces, $_[0]; }); @@ -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;