summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.com>2008-03-05 21:12:07 +0000
committerOlivier Blin <oblin@mandriva.com>2008-03-05 21:12:07 +0000
commite6673a9b02ed8c7e1d95a675efd13de4c51adca2 (patch)
tree9b54b6302ad0b62f04b49323edd4764ff96857b7 /lib
parent5ac00a05812e0e60c5fa0ab89ca798a7593c2331 (diff)
downloaddrakx-net-e6673a9b02ed8c7e1d95a675efd13de4c51adca2.tar
drakx-net-e6673a9b02ed8c7e1d95a675efd13de4c51adca2.tar.gz
drakx-net-e6673a9b02ed8c7e1d95a675efd13de4c51adca2.tar.bz2
drakx-net-e6673a9b02ed8c7e1d95a675efd13de4c51adca2.tar.xz
drakx-net-e6673a9b02ed8c7e1d95a675efd13de4c51adca2.zip
add utility functions for real/vlan/virtual interfaces
Diffstat (limited to 'lib')
-rw-r--r--lib/network/connection/ethernet.pm9
-rw-r--r--lib/network/tools.pm24
2 files changed, 28 insertions, 5 deletions
diff --git a/lib/network/connection/ethernet.pm b/lib/network/connection/ethernet.pm
index 2f4e7af..1e147ca 100644
--- a/lib/network/connection/ethernet.pm
+++ b/lib/network/connection/ethernet.pm
@@ -4,6 +4,7 @@ use base qw(network::connection);
use strict;
use common;
+use network::tools;
our @dhcp_clients = qw(dhclient dhcpcd pump dhcpxd);
@@ -23,7 +24,7 @@ sub get_unlisted_devices {
my ($interfaces, $listed_devices) = @_;
my @unlisted_interfaces = sort(difference2($interfaces, [ map { device_to_interface($_) } @$listed_devices ]));
map { interface_to_device($_) || +{
- description => $_ =~ /:\d+$/ ? N("Virtual interface") : $_,
+ description => network::tools::is_virtual_interface($_) ? N("Virtual interface") : $_,
interface => $_ },
} @unlisted_interfaces;
}
@@ -339,7 +340,7 @@ sub device_matches_interface_HwIDs {
sub get_interface_sysfs_path {
my ($interface) = @_;
- $interface =~ s/:\d+$//;
+ $interface = network::tools::get_real_interface($interface);
my $dev_path = "/sys/class/net/$interface/device";
my $bus = detect_devices::get_sysfs_field_from_link($dev_path, 'bus');
if ($bus eq 'ieee1394') {
@@ -470,7 +471,7 @@ sub get_eth_card_mac_address {
#- write interfaces MAC address in iftab
sub update_iftab() {
#- skip aliases interfaces
- foreach my $intf (grep { !/:\d+$/ } detect_devices::get_lan_interfaces()) {
+ foreach my $intf (grep { !network::tools::is_virtual_interface($_) } detect_devices::get_lan_interfaces()) {
my ($link_type, $mac_address) = get_eth_card_mac_address($intf) or next;
#- do not write zeroed MAC addresses in iftab, it confuses ifrename
$mac_address =~ /^[0:]+$/ and next;
@@ -490,7 +491,7 @@ sub update_udev_net_config() {
my $udev_net_config = "/etc/udev/rules.d/61-net_config.rules";
my @old_config = cat_($udev_net_config);
#- skip aliases and vlan interfaces
- foreach my $intf (grep { !/[:.]\d+$/ } detect_devices::get_lan_interfaces()) {
+ foreach my $intf (grep { network::tools::is_real_interface($_) } detect_devices::get_lan_interfaces()) {
(undef, my $mac_address) = get_eth_card_mac_address($intf) or next;
#- do not write zeroed MAC addresses
$mac_address =~ /^[0:]+$/ and next;
diff --git a/lib/network/tools.pm b/lib/network/tools.pm
index 0db6b26..b62d876 100644
--- a/lib/network/tools.pm
+++ b/lib/network/tools.pm
@@ -158,9 +158,31 @@ sub get_default_gateway_interface {
(find { get_interface_type($net->{ifcfg}{$_}) eq 'ethernet' && $net->{ifcfg}{$_}{BOOTPROTO} eq 'dhcp' } @intfs);
}
-sub get_interface_status {
+#- remove suffix from virtual interfaces
+sub get_real_interface {
my ($intf) = @_;
$intf =~ s/:\d+$//;
+ $intf;
+}
+
+sub is_virtual_interface {
+ my ($intf) = @_;
+ $intf =~ /:\d+$/;
+}
+
+sub is_vlan_interface {
+ my ($intf) = @_;
+ $intf =~ /\.\d+$/;
+}
+
+sub is_real_interface {
+ my ($intf) = @_;
+ !is_virtual_interface($intf) && !is_vlan_interface($intf);
+}
+
+sub get_interface_status {
+ my ($intf) = @_;
+ $intf = get_real_interface($intf);
my $routes = get_routes();
return $routes->{$intf}{network}, $routes->{$intf}{network} eq '0.0.0.0' && $routes->{$intf}{gateway};
}