summaryrefslogtreecommitdiffstats
path: root/perl-install/network
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.org>2005-06-25 02:40:44 +0000
committerOlivier Blin <oblin@mandriva.org>2005-06-25 02:40:44 +0000
commit333b7b0b80fa44345b2678c6f97d8bde83a21ddb (patch)
tree313159fad501c2968b0875fda56cd2a4a2bd3824 /perl-install/network
parent864b12e7379714fc5ffa7f13a150020fead5139c (diff)
downloaddrakx-333b7b0b80fa44345b2678c6f97d8bde83a21ddb.tar
drakx-333b7b0b80fa44345b2678c6f97d8bde83a21ddb.tar.gz
drakx-333b7b0b80fa44345b2678c6f97d8bde83a21ddb.tar.bz2
drakx-333b7b0b80fa44345b2678c6f97d8bde83a21ddb.tar.xz
drakx-333b7b0b80fa44345b2678c6f97d8bde83a21ddb.zip
don't fork to get route with "ip route", use /proc/net/route instead
(TODO: handle IPv6 with /proc/net/ipv6_route)
Diffstat (limited to 'perl-install/network')
-rw-r--r--perl-install/network/tools.pm30
1 files changed, 24 insertions, 6 deletions
diff --git a/perl-install/network/tools.pm b/perl-install/network/tools.pm
index 45c4eb4e6..ae8eb8c96 100644
--- a/perl-install/network/tools.pm
+++ b/perl-install/network/tools.pm
@@ -4,6 +4,7 @@ use strict;
use common;
use run_program;
use c;
+use Socket;
sub write_secret_backend {
my ($a, $b) = @_;
@@ -179,7 +180,8 @@ sub find_matching_interface {
sub get_default_gateway_interface {
my ($net) = @_;
my @intfs = sort keys %{$net->{ifcfg}};
- `$::prefix/sbin/ip route show` =~ /^default.*\s+dev\s+(\S+)/m && $1 ||
+ my $routes = get_routes();
+ (find { $routes->{$_}{gateway} } keys %$routes) ||
$net->{network}{GATEWAYDEV} ||
$net->{network}{GATEWAY} && find_matching_interface($net, $net->{network}{GATEWAY}) ||
(find { get_interface_type($net->{ifcfg}{$_}) eq 'adsl' } @intfs) ||
@@ -190,11 +192,9 @@ sub get_default_gateway_interface {
}
sub get_interface_status {
- my ($gw_intf) = @_;
- my @routes = `$::prefix/sbin/ip route show`;
- my $is_up = any { /\s+dev\s+$gw_intf(?:\s+|$)/ } @routes;
- my ($gw_address) = join('', @routes) =~ /^default\s+via\s+(\S+).*\s+dev\s+$gw_intf(?:\s+|$)/m;
- return $is_up, $gw_address;
+ my ($intf) = @_;
+ my $routes = get_routes();
+ return $routes->{$intf}{network}, $routes->{$intf}{gateway};
}
#- returns (gateway_interface, interface is up, gateway address, dns server address)
@@ -230,4 +230,22 @@ sub get_interface_ip_address {
$net->{ifcfg}{$interface}{IPADDR};
}
+sub host_hex_to_dotted {
+ my ($address) = @_;
+ inet_ntoa(pack('N', unpack('L', pack('H8', $address))));
+}
+
+sub get_routes {
+ my %routes;
+ foreach (cat_("/proc/net/route")) {
+ if (/^(\w+)\s+([0-9A-F]+)\s+([0-9A-F]+)\s+(?:[0-9A-F]+)\s+\d+\s+\d+\s+(\d+)\s+([0-9A-F]+)/) {
+ hex($2) and $routes{$1}{network} = host_hex_to_dotted($2);
+ hex($3) and $routes{$1}{gateway} = host_hex_to_dotted($3);
+ $4 and $routes{$1}{metric} = $4;
+ }
+ }
+ #- TODO: handle IPv6 with /proc/net/ipv6_route
+ \%routes;
+}
+
1;