]> git.proxmox.com Git - pve-common.git/commitdiff
move Network::get_active_interfaces to ProcFSTools
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 3 Jun 2016 09:09:23 +0000 (11:09 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 3 Jun 2016 09:22:40 +0000 (11:22 +0200)
This avoids a circular dependency between PVE::INotify and
PVE::Network.

Also renamed to get_active_network_interfaces since the
package name now doesn't hint at this anymore.

src/PVE/INotify.pm
src/PVE/Network.pm
src/PVE/ProcFSTools.pm

index 8cc00f80df28b0e4e94b846a6d33eb4f3ec3d890..7fb3490c452862770dcb07c7eb70e12d079444ef 100644 (file)
@@ -14,6 +14,7 @@ use Fcntl qw(:DEFAULT :flock);
 use PVE::SafeSyslog;
 use PVE::Exception qw(raise_param_exc);
 use PVE::Tools;
 use PVE::SafeSyslog;
 use PVE::Exception qw(raise_param_exc);
 use PVE::Tools;
+use PVE::ProcFSTools;
 use Storable qw(dclone);            
 use Linux::Inotify2;
 use base 'Exporter';
 use Storable qw(dclone);            
 use Linux::Inotify2;
 use base 'Exporter';
@@ -785,7 +786,7 @@ my $extract_ovs_option = sub {
 sub read_etc_network_interfaces {
     my ($filename, $fh) = @_;
     my $proc_net_dev = IO::File->new('/proc/net/dev', 'r');
 sub read_etc_network_interfaces {
     my ($filename, $fh) = @_;
     my $proc_net_dev = IO::File->new('/proc/net/dev', 'r');
-    my $active = PVE::Network::get_active_interfaces();
+    my $active = PVE::ProcFSTools::get_active_network_interfaces();
     return __read_etc_network_interfaces($fh, $proc_net_dev, $active);
 }
 
     return __read_etc_network_interfaces($fh, $proc_net_dev, $active);
 }
 
index ce4305a3390454f71d3141f14146965079c1a0c2..63476d3d98dc1a42aa799e69fd660fcef0af7793 100644 (file)
@@ -11,12 +11,6 @@ use POSIX qw(ECONNREFUSED);
 
 use Net::IP;
 
 
 use Net::IP;
 
-use Socket qw(IPPROTO_IP);
-
-use constant IFF_UP => 1;
-use constant IFNAMSIZ => 16;
-use constant SIOCGIFFLAGS => 0x8913;
-
 # host network related utility functions
 
 our $ipv4_reverse_mask = [
 # host network related utility functions
 
 our $ipv4_reverse_mask = [
@@ -537,36 +531,4 @@ sub is_ip_in_cidr {
     return $cidr_obj->overlaps($ip_obj) == $Net::IP::IP_B_IN_A_OVERLAP;
 }
 
     return $cidr_obj->overlaps($ip_obj) == $Net::IP::IP_B_IN_A_OVERLAP;
 }
 
-# struct ifreq { // FOR SIOCGIFFLAGS:
-#   char ifrn_name[IFNAMSIZ]
-#   short ifru_flags
-# };
-my $STRUCT_IFREQ_SIOCGIFFLAGS = 'Z' . IFNAMSIZ . 's1';
-sub get_active_interfaces {
-    # Use the interface name list from /proc/net/dev
-    open my $fh, '<', '/proc/net/dev'
-       or die "failed to open /proc/net/dev: $!\n";
-    # And filter by IFF_UP flag fetched via a PF_INET6 socket ioctl:
-    my $sock;
-    socket($sock, PF_INET6, SOCK_DGRAM, &IPPROTO_IP)
-    or socket($sock, PF_INET, SOCK_DGRAM, &IPPROTO_IP)
-    or return [];
-
-    my $ifaces = [];
-    while(defined(my $line = <$fh>)) {
-       next if $line !~ /^\s*([^:\s]+):/;
-       my $ifname = $1;
-       my $ifreq = pack($STRUCT_IFREQ_SIOCGIFFLAGS, $ifname, 0);
-       if (!defined(ioctl($sock, SIOCGIFFLAGS, $ifreq))) {
-           warn "failed to get interface flags for: $ifname\n";
-           next;
-       }
-       my ($name, $flags) = unpack($STRUCT_IFREQ_SIOCGIFFLAGS, $ifreq);
-       push @$ifaces, $ifname if ($flags & IFF_UP);
-    }
-    close $fh;
-    close $sock;
-    return $ifaces;
-}
-
 1;
 1;
index eadb4e6cda52abf1dc83a7432d33aaad00cffa00..05fd744367a9780fa80a719751bb897eb4296ecd 100644 (file)
@@ -8,6 +8,12 @@ use IO::File;
 use PVE::Tools;
 use Cwd qw();
 
 use PVE::Tools;
 use Cwd qw();
 
+use Socket qw(PF_INET PF_INET6 SOCK_DGRAM IPPROTO_IP);
+
+use constant IFF_UP => 1;
+use constant IFNAMSIZ => 16;
+use constant SIOCGIFFLAGS => 0x8913;
+
 my $clock_ticks = POSIX::sysconf(&POSIX::_SC_CLK_TCK);
 
 my $cpuinfo;
 my $clock_ticks = POSIX::sysconf(&POSIX::_SC_CLK_TCK);
 
 my $cpuinfo;
@@ -374,4 +380,36 @@ sub upid_wait {
     }
 }
 
     }
 }
 
+# struct ifreq { // FOR SIOCGIFFLAGS:
+#   char ifrn_name[IFNAMSIZ]
+#   short ifru_flags
+# };
+my $STRUCT_IFREQ_SIOCGIFFLAGS = 'Z' . IFNAMSIZ . 's1';
+sub get_active_network_interfaces {
+    # Use the interface name list from /proc/net/dev
+    open my $fh, '<', '/proc/net/dev'
+       or die "failed to open /proc/net/dev: $!\n";
+    # And filter by IFF_UP flag fetched via a PF_INET6 socket ioctl:
+    my $sock;
+    socket($sock, PF_INET6, SOCK_DGRAM, &IPPROTO_IP)
+    or socket($sock, PF_INET, SOCK_DGRAM, &IPPROTO_IP)
+    or return [];
+
+    my $ifaces = [];
+    while(defined(my $line = <$fh>)) {
+       next if $line !~ /^\s*([^:\s]+):/;
+       my $ifname = $1;
+       my $ifreq = pack($STRUCT_IFREQ_SIOCGIFFLAGS, $ifname, 0);
+       if (!defined(ioctl($sock, SIOCGIFFLAGS, $ifreq))) {
+           warn "failed to get interface flags for: $ifname\n";
+           next;
+       }
+       my ($name, $flags) = unpack($STRUCT_IFREQ_SIOCGIFFLAGS, $ifreq);
+       push @$ifaces, $ifname if ($flags & IFF_UP);
+    }
+    close $fh;
+    close $sock;
+    return $ifaces;
+}
+
 1;
 1;