summaryrefslogtreecommitdiffstats
path: root/perl-install/network.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/network.pm')
-rw-r--r--perl-install/network.pm55
1 files changed, 29 insertions, 26 deletions
diff --git a/perl-install/network.pm b/perl-install/network.pm
index 29edb4ff3..b97a043ed 100644
--- a/perl-install/network.pm
+++ b/perl-install/network.pm
@@ -42,34 +42,11 @@ sub write_conf {
setVarsInSh($file, $netc, qw(NETWORKING FORWARD_IPV4 HOSTNAME DOMAINNAME GATEWAY GATEWAYDEV));
}
-sub add2hosts {
- my ($file, $ip, $hostname) = @_;
- my %l = ($ip => $hostname);
-
- local *F;
- if (-e $file) {
- open F, $file or die "cannot open $file: $!";
- /\s*(\S+)(.*)/ and $l{$1} = $2 foreach <F>;
- }
- log::l("writing host information to $file");
- open F, ">$file" or die "cannot write $file: $!";
- while (my ($ip, $v) = each %l) {
- print F "$ip";
- if ($v =~ /^\s/) {
- print F $v;
- } else {
- print F "\t\t$v";
- print F " $1" if $v =~ /(.*?)\./;
- }
- print F "\n";
- }
-}
-
sub write_resolv_conf {
my ($file, $netc) = @_;
# We always write these, even if they were autoconfigured. Otherwise, the reverse name lookup in the install doesn't work.
- unless ($netc->{DOMAINNAME} || $netc->{dnsServers}) {
+ unless ($netc->{DOMAINNAME} || dnsServers($netc)) {
unlink($file);
log::l("neither domain name nor dns server are configured");
return 0;
@@ -79,7 +56,7 @@ sub write_resolv_conf {
local *F;
open F, "> $file" or die "cannot write $file: $!";
print F "search $netc->{DOMAINNAME}\n" if $netc->{DOMAINNAME};
- print F "nameserver $_\n" foreach @{$netc->{dnsServers}};
+ print F "nameserver $_\n" foreach dnsServers($netc);
print F "#$_" foreach @l;
#res_init(); # reinit the resolver so DNS changes take affect
@@ -93,12 +70,34 @@ sub write_interface_conf {
setVarsInSh($file, $intf, qw(DEVICE BOOTPROTO IPADDR NETMASK NETWORK BROADCAST ONBOOT));
}
+sub add2hosts {
+ my ($file, $ip, $hostname) = @_;
+ my %l = ($ip => $hostname);
+
+ local *F;
+ if (-e $file) {
+ open F, $file or die "cannot open $file: $!";
+ /\s*(\S+)(.*)/ and $l{$1} = $2 foreach <F>;
+ }
+ log::l("writing host information to $file");
+ open F, ">$file" or die "cannot write $file: $!";
+ while (my ($ip, $v) = each %l) {
+ print F "$ip";
+ if ($v =~ /^\s/) {
+ print F $v;
+ } else {
+ print F "\t\t$v";
+ print F " $1" if $v =~ /(.*?)\./;
+ }
+ print F "\n";
+ }
+}
# The interface/gateway needs to be configured before this will work!
sub guessHostname {
my ($prefix, $netc, $intf) = @_;
- $intf->{isUp} && $netc->{dnsServers} or return 0;
+ $intf->{isUp} && dnsServers($netc) or return 0;
$netc->{HOSTNAME} && $netc->{DOMAINNAME} and return 1;
write_resolv_conf("$prefix/etc/resolv.conf", $netc);
@@ -127,3 +126,7 @@ sub getAvailableNetDevice {
$device;
}
+sub dnsServers {
+ my ($netc) = @_;
+ map { $netc->{$_} } qw(dnsServer dnsServer2 dnsServer3);
+}