summaryrefslogtreecommitdiff
path: root/scripts/system
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/system')
-rwxr-xr-xscripts/system/vyatta_update_resolv.pl38
1 files changed, 26 insertions, 12 deletions
diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl
index ee14034b..f193fd96 100755
--- a/scripts/system/vyatta_update_resolv.pl
+++ b/scripts/system/vyatta_update_resolv.pl
@@ -25,17 +25,27 @@
use strict;
use lib "/opt/vyatta/share/perl5/";
-
use Getopt::Long;
+use Vyatta::Config;
+
my $dhclient_script = 0;
-GetOptions("dhclient-script=i" => \$dhclient_script);
+my $config_mode = 0;
+GetOptions("dhclient-script=i" => \$dhclient_script,
+ "config-mode=i" => \$config_mode,
+);
-use Vyatta::Config;
my $vc = new Vyatta::Config();
-
$vc->setLevel('system');
+
my @domains;
my $domain_name = undef;
+my $allow_dhcp_nameservers = '';
+
+if ($config_mode == 1) {
+ $allow_dhcp_nameservers = $vc->returnValue('allow-dhcp-nameservers');
+} else {
+ $allow_dhcp_nameservers = $vc->returnOrigValue('allow-dhcp-nameservers');
+}
if ($dhclient_script == 1) {
@domains = $vc->returnOrigValues('domain-search domain');
@@ -66,6 +76,7 @@ foreach my $domain (@domains) {
}
# add domain names received from dhcp client to domain search in /etc/resolv.conf if domain-name not set in CLI
+
if (!defined($domain_name)) {
my @dhcp_interfaces_resolv_files = `ls /etc/ | grep resolv.conf.dhclient-new`;
if ($#dhcp_interfaces_resolv_files >= 0) {
@@ -93,14 +104,16 @@ if ($domain_name && length($domain_name) > 0) {
$domain = "domain\t\t$domain_name\t\t#line generated by $0\n";
}
-# update /etc/resolv.conf for name-servers received from dhcp client, only done when dhclient-script calls this script
-# and allow-dhcp-nameservers is set to true (default)
-if (($dhclient_script == 1) && ($vc->returnOrigValue('allow-dhcp-nameservers') eq "true")) {
+# update /etc/resolv.conf with name-servers received from dhcp client, done when this script is called
+# with either the dhclient-script (on DHCP changes) or config-mode (allow-dhcp-nameservers) options.
+
+if (($dhclient_script == 1) || ($config_mode == 1)) {
my @current_dhcp_nameservers;
my $restart_ntp = 0;
- # code below to add new name-servers received from dhcp client
-
+ # code below to add new name-servers received from dhcp client, but only if allow-dhcp-nameservers
+ # is set to true (default)
+
my @dhcp_interfaces_resolv_files = `ls /etc/ | grep resolv.conf.dhclient-new`;
if ($#dhcp_interfaces_resolv_files >= 0) {
my $ns_count = 0;
@@ -127,7 +140,7 @@ if (($dhclient_script == 1) && ($vc->returnOrigValue('allow-dhcp-nameservers') e
}
}
}
- if ($ns_in_resolvconf == 0) {
+ if (($ns_in_resolvconf == 0) && ($allow_dhcp_nameservers eq "true")) {
open (my $rf, '>>', '/etc/resolv.conf')
or die "$! error trying to overwrite";
print $rf "nameserver\t$ns\t\t#nameserver written by $0\n";
@@ -139,7 +152,8 @@ if (($dhclient_script == 1) && ($vc->returnOrigValue('allow-dhcp-nameservers') e
}
}
- # code below to remove old name-servers from /etc/resolv.conf that were not received in this response from dhcp-server
+ # code below to remove old name-servers from /etc/resolv.conf that were not received in this response
+ # from dhcp-server, or to remove previous dhcp supplied name-servers if allow-dhcp-nameservers is false
my @nameservers_dhcp_in_resolvconf = `grep 'nameserver written' /etc/resolv.conf`;
my @dhcp_nameservers_in_resolvconf;
@@ -149,7 +163,7 @@ if (($dhclient_script == 1) && ($vc->returnOrigValue('allow-dhcp-nameservers') e
$dhcp_nameservers_in_resolvconf[$count_nameservers_in_resolvconf] = $dhcp_nameserver[1];
$count_nameservers_in_resolvconf++;
}
- if ($#current_dhcp_nameservers < 0) {
+ if (($#current_dhcp_nameservers < 0) || ($allow_dhcp_nameservers eq "false")) {
for my $dhcpnameserver (@dhcp_nameservers_in_resolvconf) {
my $cmd = "sed -i '/$dhcpnameserver\t/d' /etc/resolv.conf";
system($cmd);