summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAlex Harpin <development@landsofshadow.co.uk>2015-02-28 11:04:10 +0000
committerAlex Harpin <development@landsofshadow.co.uk>2015-02-28 11:04:10 +0000
commit684f854ac20a45dc4c3ce01228ffda04e33b4238 (patch)
treeb18fe5451bc7e7be254efa35b7c0cc225dc66e7f /scripts
parent93afdd6e8d13450e5229ccb22474bdea86bf3d1d (diff)
downloadvyatta-cfg-system-684f854ac20a45dc4c3ce01228ffda04e33b4238.tar.gz
vyatta-cfg-system-684f854ac20a45dc4c3ce01228ffda04e33b4238.zip
vyatta-cfg-system: skip over invalid ntp servers rather than exiting
Skip over either invalid ntp servers, or ntp server hostnames that have failed to resolve correctly, and continue to process the rest of the configuration. Bug #94 http://bugzilla.vyos.net/show_bug.cgi?id=94
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/system/vyatta_update_ntp.pl44
1 files changed, 24 insertions, 20 deletions
diff --git a/scripts/system/vyatta_update_ntp.pl b/scripts/system/vyatta_update_ntp.pl
index f32a9407..36a2807e 100755
--- a/scripts/system/vyatta_update_ntp.pl
+++ b/scripts/system/vyatta_update_ntp.pl
@@ -32,23 +32,25 @@ GetOptions("dhclient-script=i" => \$dhclient_script,
sub ntp_format {
my ($cidr_or_host) = @_;
my $ip = NetAddr::IP->new($cidr_or_host);
- die "$cidr_or_host: not a valid IP address" unless $ip;
-
- my $address = $ip->addr();
- my $mask = $ip->mask();
+ if (defined($ip)) {
+ my $address = $ip->addr();
+ my $mask = $ip->mask();
- if ($mask eq '255.255.255.255') {
- if ($ip->version() == 6) {
- return "-6 $address";
+ if ($ip->masklen() == 32) {
+ if ($ip->version() == 6) {
+ return "-6 $address";
+ } else {
+ return "$address";
+ }
} else {
- return "$address";
+ if ($ip->version() == 6) {
+ return "-6 $address mask $mask";
+ } else {
+ return "$address mask $mask";
+ }
}
} else {
- if ($ip->version() == 6) {
- return "-6 $address mask $mask";
- } else {
- return "$address mask $mask";
- }
+ return undef;
}
}
@@ -91,15 +93,17 @@ if (scalar(@servers) > 0) {
print $output "# Servers\n\n";
foreach my $server (@servers) {
my $server_addr = ntp_format($server);
- print $output "server $server_addr iburst";
- for my $property (qw(dynamic noselect preempt prefer)) {
- if ($dhclient_script == 1) {
- print $output " $property" if ($cfg->existsOrig("server $server $property"));
- } else {
- print $output " $property" if ($cfg->exists("server $server $property"));
+ if (defined($server_addr)) {
+ print $output "server $server_addr iburst";
+ for my $property (qw(dynamic noselect preempt prefer)) {
+ if ($dhclient_script == 1) {
+ print $output " $property" if ($cfg->existsOrig("server $server $property"));
+ } else {
+ print $output " $property" if ($cfg->exists("server $server $property"));
+ }
}
+ print $output "\nrestrict $server_addr nomodify notrap nopeer noquery\n";
}
- print $output "\nrestrict $server_addr nomodify notrap nopeer noquery\n";
}
print $output "\n";
}