From 7a78f9c54453338202b4b02576a588fcd3814803 Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Sat, 24 Jan 2015 11:32:05 +0000 Subject: vyatta-cfg-system: formatting changes for style consistency Update scripts/system/vyatta_update_console.pl to have consistent identation levels and style throughout. --- scripts/system/vyatta_update_console.pl | 79 +++++++++++++++++---------------- 1 file changed, 40 insertions(+), 39 deletions(-) (limited to 'scripts') diff --git a/scripts/system/vyatta_update_console.pl b/scripts/system/vyatta_update_console.pl index 0ee6a6e5..38c03744 100755 --- a/scripts/system/vyatta_update_console.pl +++ b/scripts/system/vyatta_update_console.pl @@ -34,13 +34,13 @@ die "$0 expects no arguments\n" if (@ARGV); sub update { my ($old, $new) = @_; - if ( compare($old, $new) != 0) { - move($new, $old) - or die "Can't move $new to $old"; - return 1; + if (compare($old, $new) != 0) { + move($new, $old) + or die "Can't move $new to $old"; + return 1; } else { - unlink($new); - return; + unlink($new); + return; } } @@ -48,14 +48,14 @@ my $INITTAB = "/etc/inittab"; my $TMPTAB = "/tmp/inittab.$$"; sub update_inittab { - open (my $inittab, '<', $INITTAB) - or die "Can't open $INITTAB: $!"; + open(my $inittab, '<', $INITTAB) + or die "Can't open $INITTAB: $!"; - open (my $tmp, '>', $TMPTAB) - or die "Can't open $TMPTAB: $!"; + open(my $tmp, '>', $TMPTAB) + or die "Can't open $TMPTAB: $!"; # Clone original inittab but remove all references to serial lines - print {$tmp} grep { ! /^T|^# Vyatta/ } <$inittab>; + print {$tmp} grep {!/^T|^# Vyatta/} <$inittab>; close $inittab; my $config = new Vyatta::Config; @@ -65,27 +65,28 @@ sub update_inittab { my $id = 0; foreach my $tty ($config->listNodes()) { - my $speed = $config->returnValue("$tty speed"); - $speed = 9600 unless $speed; - - printf {$tmp} "T%d:23:respawn:", $id; - if ($config->exists("$tty modem")) { - printf {$tmp} "/sbin/mgetty -x0 -s %d %s\n", $speed, $tty; - } else { - printf {$tmp} "/sbin/getty -L %s %d vt100\n", $tty, $speed; - } - - # id field is limited to 4 characters - if (++$id >= 1000) { - warn "Ignoring $tty only 1000 serial devices supported\n"; - last; - } + my $speed = $config->returnValue("$tty speed"); + $speed = 9600 unless $speed; + + printf {$tmp} "T%d:23:respawn:", $id; + if ($config->exists("$tty modem")) { + printf {$tmp} "/sbin/mgetty -x0 -s %d %s\n", $speed, $tty; + } else { + printf {$tmp} "/sbin/getty -L %s %d vt100\n", $tty, $speed; + } + + # id field is limited to 4 characters + if (++$id >= 1000) { + warn "Ignoring $tty only 1000 serial devices supported\n"; + last; + } } close $tmp; if (update($INITTAB, $TMPTAB)) { - # This is same as telinit q - it tells init to re-examine inittab - kill 1, 1; + + # This is same as telinit q - it tells init to re-examine inittab + kill 1, 1; } } @@ -104,20 +105,20 @@ sub update_grub { my $speed = $config->returnValue("ttyS0 speed"); $speed = "9600" unless defined($speed); - open (my $grub, '<', $GRUBCFG) - or die "Can't open $GRUBCFG: $!"; + open(my $grub, '<', $GRUBCFG) + or die "Can't open $GRUBCFG: $!"; - open (my $tmp, '>', $GRUBTMP) - or die "Can't open $GRUBTMP: $!"; + open(my $tmp, '>', $GRUBTMP) + or die "Can't open $GRUBTMP: $!"; while (<$grub>) { - if (/^serial / ) { - print {$tmp} "serial --unit=0 --speed=$speed\n"; - } elsif (/^(.* console=ttyS0),[0-9]+(.*)$/) { - print {$tmp} "$1,$speed$2\n"; - } else { - print {$tmp} $_; - } + if (/^serial /) { + print {$tmp} "serial --unit=0 --speed=$speed\n"; + } elsif (/^(.* console=ttyS0),[0-9]+(.*)$/) { + print {$tmp} "$1,$speed$2\n"; + } else { + print {$tmp} $_; + } } close $grub; close $tmp; -- cgit v1.2.3 From de086b75445f50cec560791aa5abd22347c563a2 Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Sat, 24 Jan 2015 13:57:44 +0000 Subject: vyatta-cfg-system: changes to update_inittab for xen console access Update the update_inittab function so when the system is configured for Xen console (hvc0) access, the correct values are written out to /etc/inittab. --- scripts/system/vyatta_update_console.pl | 39 ++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'scripts') diff --git a/scripts/system/vyatta_update_console.pl b/scripts/system/vyatta_update_console.pl index 38c03744..7c36ec7f 100755 --- a/scripts/system/vyatta_update_console.pl +++ b/scripts/system/vyatta_update_console.pl @@ -55,7 +55,8 @@ sub update_inittab { or die "Can't open $TMPTAB: $!"; # Clone original inittab but remove all references to serial lines - print {$tmp} grep {!/^T|^# Vyatta/} <$inittab>; + # and Xen consoles + print {$tmp} grep {!/^T|^# Vyatta|^h/} <$inittab>; close $inittab; my $config = new Vyatta::Config; @@ -63,22 +64,30 @@ sub update_inittab { print {$tmp} "# Vyatta console configuration (do not modify)\n"; - my $id = 0; + my $serial_id = 0; + my $xen_id = 0; + foreach my $tty ($config->listNodes()) { my $speed = $config->returnValue("$tty speed"); - $speed = 9600 unless $speed; - - printf {$tmp} "T%d:23:respawn:", $id; - if ($config->exists("$tty modem")) { - printf {$tmp} "/sbin/mgetty -x0 -s %d %s\n", $speed, $tty; - } else { - printf {$tmp} "/sbin/getty -L %s %d vt100\n", $tty, $speed; - } - - # id field is limited to 4 characters - if (++$id >= 1000) { - warn "Ignoring $tty only 1000 serial devices supported\n"; - last; + if ($tty =~ /^hvc\d/) { + $speed = 38400 unless $speed; + printf {$tmp} "h%d:23:respawn:", $xen_id; + printf {$tmp} "/sbin/getty %d %s\n", $speed, $tty; + $xen_id++; + } else { + $speed = 9600 unless $speed; + printf {$tmp} "T%d:23:respawn:", $serial_id; + if ($config->exists("$tty modem")) { + printf {$tmp} "/sbin/mgetty -x0 -s %d %s\n", $speed, $tty; + } else { + printf {$tmp} "/sbin/getty -L %s %d vt100\n", $tty, $speed; + } + + # id field is limited to 4 characters + if (++$serial_id >= 1000) { + warn "Ignoring $tty only 1000 serial devices supported\n"; + last; + } } } close $tmp; -- cgit v1.2.3 From 935deedc1499e1446fad6e153f761f11817be201 Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Sun, 8 Feb 2015 19:33:14 +0000 Subject: vyatta-cfg-system: allow dynamic dns updating from behind nat Add a couple of configuration options to DDNS, to allow the use=web option from ddclient when determining the external IP address. This will allow DDNS to be correctly updated when behind a NAT device. Syntax: set service dns dynamic interface eth0 use-web url (url to use) set service dns dynamic interface eth0 use-web skip (search for this) Bug #455 http://bugzilla.vyos.net/show_bug.cgi?id=455 --- scripts/dynamic-dns/vyatta-dynamic-dns.pl | 12 ++++++++++-- .../service/dns/dynamic/interface/node.tag/use-web/node.def | 1 + .../dns/dynamic/interface/node.tag/use-web/skip/node.def | 2 ++ .../dns/dynamic/interface/node.tag/use-web/url/node.def | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 templates/service/dns/dynamic/interface/node.tag/use-web/node.def create mode 100644 templates/service/dns/dynamic/interface/node.tag/use-web/skip/node.def create mode 100644 templates/service/dns/dynamic/interface/node.tag/use-web/url/node.def (limited to 'scripts') diff --git a/scripts/dynamic-dns/vyatta-dynamic-dns.pl b/scripts/dynamic-dns/vyatta-dynamic-dns.pl index 8788730f..83206253 100755 --- a/scripts/dynamic-dns/vyatta-dynamic-dns.pl +++ b/scripts/dynamic-dns/vyatta-dynamic-dns.pl @@ -96,16 +96,24 @@ sub dynamicdns_get_constants { $output .= "ssl=yes\n"; $output .= "pid=$ddclient_run_dir/ddclient_$interface.pid\n"; $output .= "cache=$ddclient_cache_dir/ddclient_$interface.cache\n"; - $output .= "use=if, if=$interface\n\n\n"; return $output; } sub dynamicdns_get_values { - my $output = ''; + my $output; my $config = new Vyatta::Config; $config->setLevel("service dns dynamic interface $interface"); + my $web_url = $config->returnValue("use-web url"); + my $web_skip = $config->returnValue("use-web skip"); + + if ($web_url && $web_skip) { + $output = "use=web, web=$web_url, web-skip='".$web_skip."'\n\n\n"; + } else { + $output = "use=if, if=$interface\n\n\n"; + } + my @services = $config->listNodes("service"); foreach my $service (@services) { $config->setLevel("service dns dynamic interface $interface service $service"); diff --git a/templates/service/dns/dynamic/interface/node.tag/use-web/node.def b/templates/service/dns/dynamic/interface/node.tag/use-web/node.def new file mode 100644 index 00000000..f1b86b6d --- /dev/null +++ b/templates/service/dns/dynamic/interface/node.tag/use-web/node.def @@ -0,0 +1 @@ +help: Web check used for obtaining the external IP address diff --git a/templates/service/dns/dynamic/interface/node.tag/use-web/skip/node.def b/templates/service/dns/dynamic/interface/node.tag/use-web/skip/node.def new file mode 100644 index 00000000..f316a4b5 --- /dev/null +++ b/templates/service/dns/dynamic/interface/node.tag/use-web/skip/node.def @@ -0,0 +1,2 @@ +help: Skip everything before this on the given URL +type: txt diff --git a/templates/service/dns/dynamic/interface/node.tag/use-web/url/node.def b/templates/service/dns/dynamic/interface/node.tag/use-web/url/node.def new file mode 100644 index 00000000..164ddde4 --- /dev/null +++ b/templates/service/dns/dynamic/interface/node.tag/use-web/url/node.def @@ -0,0 +1,2 @@ +help: URL to obtain the current external IP address +type: txt -- cgit v1.2.3 From 865bfab01e256ce839991a1b9d54f3e4cb62a8ac Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Mon, 9 Feb 2015 21:01:35 +0000 Subject: vyatta-cfg-system: invalid resolv.conf format causing extra DNS request The resolv.conf file contains comments at the end of the search and domain entries which cause unexpected behaviour on lookups. Moving these to the line above in each case fixes the issue. Bug #468 http://bugzilla.vyos.net/show_bug.cgi?id=468 --- scripts/system/vyatta_update_resolv.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl index 921052f0..93e6041d 100755 --- a/scripts/system/vyatta_update_resolv.pl +++ b/scripts/system/vyatta_update_resolv.pl @@ -96,12 +96,12 @@ if (!defined($domain_name)) { my $search = ''; if (length($doms) > 0) { - $search = "search\t\t$doms\t\t#line generated by $0\n"; + $search = "#line generated by $0\nsearch\t\t$doms\n"; } my $domain = ''; if ($domain_name && length($domain_name) > 0) { - $domain = "domain\t\t$domain_name\t\t#line generated by $0\n"; + $domain = "#line generated by $0\ndomain\t\t$domain_name\n"; } # update /etc/resolv.conf with name-servers received from dhcp client, done when this script is called @@ -221,7 +221,7 @@ foreach my $line (@resolv) { if (length($domain) > 0) { print $r $domain; } - } else { + } elsif ($line !~ /^#line generated by\s/) { print $r $line; } } -- cgit v1.2.3 From 93a49639c983e8f61ca942efe68ede46053ea03a Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Tue, 10 Feb 2015 22:56:06 +0000 Subject: vyatta-cfg-system: multiple servers for dns forwarding domain override When configuring DNS fowarding, allow multiple servers to be specified when setting domain overrides, in order to allow Dnsmasq to gracefully handle unavailable nameservers. Bug #408 http://bugzilla.vyos.net/show_bug.cgi?id=408 --- scripts/dns-forwarding/vyatta-dns-forwarding.pl | 25 ++++++++++++++-------- .../dns/forwarding/domain/node.tag/server/node.def | 1 + 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/dns-forwarding/vyatta-dns-forwarding.pl b/scripts/dns-forwarding/vyatta-dns-forwarding.pl index b5efd269..217a520a 100755 --- a/scripts/dns-forwarding/vyatta-dns-forwarding.pl +++ b/scripts/dns-forwarding/vyatta-dns-forwarding.pl @@ -63,7 +63,7 @@ sub dnsforwarding_get_values { my $output = ''; my $config = new Vyatta::Config; my $use_dnsmasq_conf = 0; - my (@listen_interfaces, $cache_size, @use_nameservers, $use_system_nameservers, @use_dhcp_nameservers, @domain, $server, $ignore_hosts_file); + my (@listen_interfaces, $cache_size, @use_nameservers, $use_system_nameservers, @use_dhcp_nameservers, @domains, $server, $ignore_hosts_file); $config->setLevel("service dns forwarding"); @@ -73,7 +73,7 @@ sub dnsforwarding_get_values { @use_nameservers = $config->returnOrigValues("name-server"); $use_system_nameservers = $config->existsOrig("system"); @use_dhcp_nameservers = $config->returnOrigValues("dhcp"); - @domain = $config->listOrigNodes("domain"); + @domains = $config->listOrigNodes("domain"); $ignore_hosts_file = $config->returnOrigValue("ignore-hosts-file"); } else { @@ -82,7 +82,7 @@ sub dnsforwarding_get_values { @use_nameservers = $config->returnValues("name-server"); $use_system_nameservers = $config->exists("system"); @use_dhcp_nameservers = $config->returnValues("dhcp"); - @domain = $config->listNodes("domain"); + @domains = $config->listNodes("domain"); $ignore_hosts_file = $config->exists("ignore-hosts-file"); } @@ -112,7 +112,7 @@ sub dnsforwarding_get_values { my $sys_config = new Vyatta::Config; $sys_config->setLevel("system"); my @system_nameservers; - if ($outside_cli == 1){ + if ($outside_cli == 1) { @system_nameservers = $sys_config->returnOrigValues("name-server"); } else { @system_nameservers = $sys_config->returnValues("name-server"); @@ -123,11 +123,18 @@ sub dnsforwarding_get_values { } } } - if (@domain != 0) { - foreach my $dom (@domain) { - my $ser = $config->returnValue("domain $dom server"); - if (defined ($ser)) { - $output .="server=/$dom/$ser\t# domain-override\n"; + if (@domains != 0) { + foreach my $domain (@domains) { + my @domain_servers; + if ($outside_cli == 1) { + @domain_servers = $config->returnValues("domain $domain server"); + } else { + @domain_servers = $config->returnValues("domain $domain server"); + } + if (@domain_servers > 0) { + foreach my $domain_server (@domain_servers) { + $output .="server=/$domain/$domain_server\t# domain-override\n"; + } } } } diff --git a/templates/service/dns/forwarding/domain/node.tag/server/node.def b/templates/service/dns/forwarding/domain/node.tag/server/node.def index 3dec7d5d..8f40a299 100644 --- a/templates/service/dns/forwarding/domain/node.tag/server/node.def +++ b/templates/service/dns/forwarding/domain/node.tag/server/node.def @@ -1,2 +1,3 @@ +multi: type: ipv4 help: DNS server to forward queries -- cgit v1.2.3 From 24c99255b867e48ae3369a23f866951e8607fbbe Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Sat, 14 Feb 2015 10:36:55 +0000 Subject: vyatta-cfg-system: redesign the layout and updating of /etc/resolv.conf Following the documentation, /etc/resolv.conf should only have comments inserted that start with # at the beginning of a line, comments in other locations are not supported. The exisiting method of tracking changes in this file (done by both vyatta-system-nameservers and vyatta_update_resolv.pl) relies on this unsupported feature. This commit restructures the updates so they use comments on the preceding line to track changes, along with updating the old style comments to the new ones when the relevant scripts are called. This also fixes a previous issue (which was reverted) where IPv6 nameservers worked incorrectly when the /etc/resolv.conf line ended with a comment. Bug #486 http://bugzilla.vyos.net/show_bug.cgi?id=486 --- scripts/system/vyatta_update_resolv.pl | 74 ++++++++++++++++++++++++---------- scripts/vyatta-system-nameservers | 2 +- 2 files changed, 53 insertions(+), 23 deletions(-) (limited to 'scripts') diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl index 93e6041d..4c54cfce 100755 --- a/scripts/system/vyatta_update_resolv.pl +++ b/scripts/system/vyatta_update_resolv.pl @@ -37,7 +37,7 @@ GetOptions("dhclient-script=i" => \$dhclient_script, my $vc = new Vyatta::Config(); $vc->setLevel('system'); -my @domains; +my @search_domains; my $domain_name = undef; my $disable_dhcp_nameservers = undef; @@ -48,34 +48,36 @@ if ($config_mode == 1) { } if ($dhclient_script == 1) { - @domains = $vc->returnOrigValues('domain-search domain'); + @search_domains = $vc->returnOrigValues('domain-search domain'); $domain_name = $vc->returnOrigValue('domain-name'); } else { - @domains = $vc->returnValues('domain-search domain'); + @search_domains = $vc->returnValues('domain-search domain'); $domain_name = $vc->returnValue('domain-name'); } -if ($dhclient_script == 0 && @domains > 0 && $domain_name && length($domain_name) > 0) { - my @loc; +if ($dhclient_script == 0 && @search_domains > 0 && $domain_name && length($domain_name) > 0) { + my @location; if ($vc->returnOrigValues('domain-search domain') > 0) { - @loc = ["system","domain-name"]; + @location = ["system","domain-name"]; } else { - @loc = ["system","domain-search","domain"]; + @location = ["system","domain-search","domain"]; } - Vyatta::Config::outputError(@loc,"System configuration error. Both \'domain-name\' and \'domain-search\' are specified, but only one of these mutually exclusive parameters is allowed."); + Vyatta::Config::outputError(@location,"System configuration error. Both \'domain-name\' and \'domain-search\' are specified, but only one of these mutually exclusive parameters is allowed."); exit(1); } -my $doms = ''; -foreach my $domain (@domains) { - if (length($doms) > 0) { - $doms .= ' '; +my $search_domain_list = ''; +foreach my $domain (@search_domains) { + if (length($search_domain_list) > 0) { + $search_domain_list .= ' '; } - $doms .= $domain; + $search_domain_list .= $domain; } -# add domain names received from dhcp client to domain search in /etc/resolv.conf if domain-name not set in CLI +# add domain searches received from the dhcp client to those already in /etc/resolv.conf, as long as domain-name is not set in the CLI + +my $search_includes_dhcp = 0; if (!defined($domain_name)) { my @dhcp_interfaces_resolv_files = `ls /etc/ | grep resolv.conf.dhclient-new`; @@ -88,20 +90,27 @@ if (!defined($domain_name)) { my @dhcp_domains = split(/\s+/, $search_string, 2); my $dhcp_domain = $dhcp_domains[1]; chomp $dhcp_domain; - $doms .= ' ' . $dhcp_domain; + $search_domain_list .= ' ' . $dhcp_domain; + $search_includes_dhcp = 1; } } } } my $search = ''; -if (length($doms) > 0) { - $search = "#line generated by $0\nsearch\t\t$doms\n"; +if (length($search_domain_list) > 0) { + my $source; + if ($search_includes_dhcp == 1) { + $source = "(system + dhcp)"; + } else { + $source = "(system)"; + } + $search = "#line generated by vyatta_update_resolv.pl $source\nsearch\t\t$search_domain_list\n"; } my $domain = ''; if ($domain_name && length($domain_name) > 0) { - $domain = "#line generated by $0\ndomain\t\t$domain_name\n"; + $domain = "#line generated by vyatta_update_resolv.pl (system)\ndomain\t\t$domain_name\n"; } # update /etc/resolv.conf with name-servers received from dhcp client, done when this script is called @@ -143,7 +152,7 @@ if (($dhclient_script == 1) || ($config_mode == 1)) { if (($ns_in_resolvconf == 0) && !($disable_dhcp_nameservers)) { open (my $rf, '>>', '/etc/resolv.conf') or die "$! error trying to overwrite"; - print $rf "nameserver\t$ns\t\t#nameserver written by $0\n"; + print $rf "#nameserver written by vyatta_update_resolv.pl (dhcp)\nnameserver\t$ns\n"; close $rf; $restart_ntp = 1; } @@ -156,7 +165,16 @@ if (($dhclient_script == 1) || ($config_mode == 1)) { # from dhcp-server, or to remove previous dhcp supplied name-servers if disable-dhcp-nameservers has # been enabled. - my @nameservers_dhcp_in_resolvconf = `grep 'nameserver written' /etc/resolv.conf`; + my $found_old = 0; + + my @nameservers_dhcp_in_resolvconf = `sed -n '/nameserver written/{n;P;}' /etc/resolv.conf`; + for my $old_style_nameservers (@nameservers_dhcp_in_resolvconf) { + if ($old_style_nameservers =~ /#line generated by/){ + @nameservers_dhcp_in_resolvconf = `sed -n '/nameserver written/{P;}' /etc/resolv.conf`; + $found_old = 1; + last; + } + } my @dhcp_nameservers_in_resolvconf; my $count_nameservers_in_resolvconf = 0; for my $count_dhcp_nameserver (@nameservers_dhcp_in_resolvconf) { @@ -166,20 +184,32 @@ if (($dhclient_script == 1) || ($config_mode == 1)) { } if (($#current_dhcp_nameservers < 0) || ($disable_dhcp_nameservers)) { for my $dhcpnameserver (@dhcp_nameservers_in_resolvconf) { - my $cmd = "sed -i '/$dhcpnameserver\t/d' /etc/resolv.conf"; + my $cmd; + chomp $dhcpnameserver; + if ($found_old == 1) { + $cmd = "sed -i '/nameserver\t$dhcpnameserver/d' /etc/resolv.conf"; + } else { + $cmd = "sed -i -n '/nameserver\t$dhcpnameserver/".'{n;x;d;};x;1d;p;${x;p;}'."' /etc/resolv.conf"; + } system($cmd); $restart_ntp = 1; } } else { for my $dhcpnameserver (@dhcp_nameservers_in_resolvconf) { my $found = 0; + my $cmd; + chomp $dhcpnameserver; for my $currentnameserver (@current_dhcp_nameservers) { if ($dhcpnameserver eq $currentnameserver){ $found = 1; } } if ($found == 0) { - my $cmd = "sed -i '/$dhcpnameserver\t/d' /etc/resolv.conf"; + if ($found_old == 1) { + $cmd = "sed -i '/nameserver\t$dhcpnameserver/d' /etc/resolv.conf"; + } else { + $cmd = "sed -i -n '/nameserver\t$dhcpnameserver/".'{n;x;d;};x;1d;p;${x;p;}'."' /etc/resolv.conf"; + } system($cmd); $restart_ntp = 1; } diff --git a/scripts/vyatta-system-nameservers b/scripts/vyatta-system-nameservers index 74f2c8b6..7b66cf77 100755 --- a/scripts/vyatta-system-nameservers +++ b/scripts/vyatta-system-nameservers @@ -53,7 +53,7 @@ update_system_nameservers () { # find last instance of cli inserted nameserver # insert currently received nameserver immediately after that # this is done to keep system set nameservers priority over dhcp received nameservers - cli_ns_array=($(awk '{if (!$3) print $2}' /etc/resolv.conf)) + cli_ns_array=($(awk '{if (/(dhcp)/) exit 0; if (!$3) print $2}' /etc/resolv.conf)) cli_ns_array_len=${#cli_ns_array[*]} line_num=0 if [ $cli_ns_array_len -gt 0 ]; then -- cgit v1.2.3 From 6648f37a5895f259de2068504520f64f225c1899 Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Sat, 14 Feb 2015 13:35:27 +0000 Subject: vyatta-cfg-system: remove blank domain search and expand comment type Tighten the checks for configured search domains to exclude adding unnecessary blank domains and expand the comments added to /etc/resolv.conf to indicate the source of the search domains. Bug #486 http://bugzilla.vyos.net/show_bug.cgi?id=486 --- scripts/system/vyatta_update_resolv.pl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl index 4c54cfce..0dfa4bec 100755 --- a/scripts/system/vyatta_update_resolv.pl +++ b/scripts/system/vyatta_update_resolv.pl @@ -68,11 +68,14 @@ if ($dhclient_script == 0 && @search_domains > 0 && $domain_name && length($doma } my $search_domain_list = ''; +my $search_includes_system = 0; + foreach my $domain (@search_domains) { if (length($search_domain_list) > 0) { $search_domain_list .= ' '; } $search_domain_list .= $domain; + $search_includes_system = 1; } # add domain searches received from the dhcp client to those already in /etc/resolv.conf, as long as domain-name is not set in the CLI @@ -90,7 +93,10 @@ if (!defined($domain_name)) { my @dhcp_domains = split(/\s+/, $search_string, 2); my $dhcp_domain = $dhcp_domains[1]; chomp $dhcp_domain; - $search_domain_list .= ' ' . $dhcp_domain; + if (length($search_domain_list) > 0) { + $search_domain_list .= ' '; + } + $search_domain_list .= $dhcp_domain; $search_includes_dhcp = 1; } } @@ -100,10 +106,14 @@ if (!defined($domain_name)) { my $search = ''; if (length($search_domain_list) > 0) { my $source; - if ($search_includes_dhcp == 1) { - $source = "(system + dhcp)"; + if ($search_includes_system == 1) { + if ($search_includes_dhcp == 1) { + $source = "(system + dhcp)"; + } else { + $source = "(system)"; + } } else { - $source = "(system)"; + $source = "(dhcp)"; } $search = "#line generated by vyatta_update_resolv.pl $source\nsearch\t\t$search_domain_list\n"; } -- cgit v1.2.3