From 87266d5b27778af56a814347fdd8926274b9c315 Mon Sep 17 00:00:00 2001 From: sayo Date: Sun, 11 Jun 2017 16:29:07 +0100 Subject: Fix to generate correct NTP config when specifying ipv6 servers. --- scripts/system/vyatta_update_ntp.pl | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'scripts/system/vyatta_update_ntp.pl') diff --git a/scripts/system/vyatta_update_ntp.pl b/scripts/system/vyatta_update_ntp.pl index 36a2807e..eaaae14a 100755 --- a/scripts/system/vyatta_update_ntp.pl +++ b/scripts/system/vyatta_update_ntp.pl @@ -35,19 +35,14 @@ sub ntp_format { if (defined($ip)) { my $address = $ip->addr(); my $mask = $ip->mask(); - - if ($ip->masklen() == 32) { - if ($ip->version() == 6) { - return "-6 $address"; - } else { - return "$address"; - } + + if ( + ($ip->version() == 6 && $ip->masklen() == 128) + || ($ip->version() == 4 && $ip->masklen() == 32) + ) { + return "$address"; } else { - if ($ip->version() == 6) { - return "-6 $address mask $mask"; - } else { - return "$address mask $mask"; - } + return "$address mask $mask"; } } else { return undef; -- cgit v1.2.3 From 3f248ff90ecb28ae15dcf8e8191e79ca7889f69d Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Tue, 20 Feb 2018 06:36:24 +0100 Subject: Rename the "client" NTP option to "allow-clients" to make it more clear what it does (fixes T553). --- scripts/system/vyatta_update_ntp.pl | 4 ++-- templates/system/ntp/allow-clients/address/node.def | 6 ++++++ templates/system/ntp/allow-clients/node.def | 1 + templates/system/ntp/client/address/node.def | 6 ------ templates/system/ntp/client/node.def | 1 - 5 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 templates/system/ntp/allow-clients/address/node.def create mode 100644 templates/system/ntp/allow-clients/node.def delete mode 100644 templates/system/ntp/client/address/node.def delete mode 100644 templates/system/ntp/client/node.def (limited to 'scripts/system/vyatta_update_ntp.pl') diff --git a/scripts/system/vyatta_update_ntp.pl b/scripts/system/vyatta_update_ntp.pl index eaaae14a..78a617bc 100755 --- a/scripts/system/vyatta_update_ntp.pl +++ b/scripts/system/vyatta_update_ntp.pl @@ -78,10 +78,10 @@ my @clients; if ($dhclient_script == 1) { @servers = $cfg->listOrigNodes("server"); - @clients = $cfg->returnOrigValues("client address"); + @clients = $cfg->returnOrigValues("allow-clients address"); } else { @servers = $cfg->listNodes("server"); - @clients = $cfg->returnValues("client address"); + @clients = $cfg->returnValues("allow-clients address"); } if (scalar(@servers) > 0) { diff --git a/templates/system/ntp/allow-clients/address/node.def b/templates/system/ntp/allow-clients/address/node.def new file mode 100644 index 00000000..a48a2b5a --- /dev/null +++ b/templates/system/ntp/allow-clients/address/node.def @@ -0,0 +1,6 @@ +multi: +type: ipv4net,ipv6net +help: IP address + +val_help: ipv4net; IP address and prefix length +val_help: ipv6net; IPv6 address and prefix length diff --git a/templates/system/ntp/allow-clients/node.def b/templates/system/ntp/allow-clients/node.def new file mode 100644 index 00000000..8228130e --- /dev/null +++ b/templates/system/ntp/allow-clients/node.def @@ -0,0 +1 @@ +help: Network Time Protocol (NTP) server options diff --git a/templates/system/ntp/client/address/node.def b/templates/system/ntp/client/address/node.def deleted file mode 100644 index a48a2b5a..00000000 --- a/templates/system/ntp/client/address/node.def +++ /dev/null @@ -1,6 +0,0 @@ -multi: -type: ipv4net,ipv6net -help: IP address - -val_help: ipv4net; IP address and prefix length -val_help: ipv6net; IPv6 address and prefix length diff --git a/templates/system/ntp/client/node.def b/templates/system/ntp/client/node.def deleted file mode 100644 index dd849f8f..00000000 --- a/templates/system/ntp/client/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Network Time Protocol (NTP) client -- cgit v1.2.3 From 9f5c33ea3fb6101c7ce49abe3762d4d497c37ce9 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 7 May 2018 22:41:31 +0200 Subject: T623: Rewrite NTP subsystem in new XML style interface definition --- Makefile.am | 1 - scripts/system/vyatta_update_ntp.pl | 115 --------------------- scripts/system/vyatta_update_resolv.pl | 15 --- scripts/vyatta-system-nameservers | 10 -- .../system/ntp/allow-clients/address/node.def | 6 -- templates/system/ntp/allow-clients/node.def | 1 - templates/system/ntp/node.def | 16 --- templates/system/ntp/server/node.def | 3 - .../system/ntp/server/node.tag/dynamic/node.def | 2 - .../system/ntp/server/node.tag/noselect/node.def | 1 - .../system/ntp/server/node.tag/preempt/node.def | 1 - .../system/ntp/server/node.tag/prefer/node.def | 1 - 12 files changed, 172 deletions(-) delete mode 100755 scripts/system/vyatta_update_ntp.pl delete mode 100644 templates/system/ntp/allow-clients/address/node.def delete mode 100644 templates/system/ntp/allow-clients/node.def delete mode 100644 templates/system/ntp/node.def delete mode 100644 templates/system/ntp/server/node.def delete mode 100644 templates/system/ntp/server/node.tag/dynamic/node.def delete mode 100644 templates/system/ntp/server/node.tag/noselect/node.def delete mode 100644 templates/system/ntp/server/node.tag/preempt/node.def delete mode 100644 templates/system/ntp/server/node.tag/prefer/node.def (limited to 'scripts/system/vyatta_update_ntp.pl') diff --git a/Makefile.am b/Makefile.am index 77088eaa..cfddd656 100644 --- a/Makefile.am +++ b/Makefile.am @@ -54,7 +54,6 @@ sbin_SCRIPTS += scripts/system/vyatta_update_resolv.pl sbin_SCRIPTS += scripts/system/vyatta_update_sysctl.pl sbin_SCRIPTS += scripts/system/vyatta_update_syslog.pl sbin_SCRIPTS += scripts/system/vyatta_update_console.pl -sbin_SCRIPTS += scripts/system/vyatta_update_ntp.pl sbin_SCRIPTS += scripts/system/irq-affinity.pl sbin_SCRIPTS += scripts/snmp/vyatta-snmp.pl sbin_SCRIPTS += scripts/snmp/vyatta-snmp-v3.pl diff --git a/scripts/system/vyatta_update_ntp.pl b/scripts/system/vyatta_update_ntp.pl deleted file mode 100755 index 78a617bc..00000000 --- a/scripts/system/vyatta_update_ntp.pl +++ /dev/null @@ -1,115 +0,0 @@ -#! /usr/bin/perl - -# **** License **** -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# This code was originally developed by Vyatta, Inc. -# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc. -# All Rights Reserved. -# -# **** End License **** - -# Filter ntp.conf - remove old servers and add current ones - -use strict; -use lib "/opt/vyatta/share/perl5"; -use Vyatta::Config; -use NetAddr::IP; -use Getopt::Long; - -my $dhclient_script = 0; - -GetOptions("dhclient-script=i" => \$dhclient_script, -); - -sub ntp_format { - my ($cidr_or_host) = @_; - my $ip = NetAddr::IP->new($cidr_or_host); - if (defined($ip)) { - my $address = $ip->addr(); - my $mask = $ip->mask(); - - if ( - ($ip->version() == 6 && $ip->masklen() == 128) - || ($ip->version() == 4 && $ip->masklen() == 32) - ) { - return "$address"; - } else { - return "$address mask $mask"; - } - } else { - return undef; - } -} - -my @ntp; -if (-e '/etc/ntp.conf') { - open (my $file, '<', '/etc/ntp.conf') - or die("$0: Error! Unable to open '/etc/ntp.conf' for input: $!\n"); - @ntp = <$file>; - close ($file); -} - -open (my $output, '>', '/etc/ntp.conf') - or die("$0: Error! Unable to open '/etc/ntp.conf' for output: $!\n"); - -my $cfg = new Vyatta::Config; -$cfg->setLevel("system ntp"); - -foreach my $line (@ntp) { - if ($line =~ /^# VyOS CLI configuration options/) { - print $output $line; - print $output "\n"; - last; - } else { - print $output $line; - } -} - -my @servers; -my @clients; - -if ($dhclient_script == 1) { - @servers = $cfg->listOrigNodes("server"); - @clients = $cfg->returnOrigValues("allow-clients address"); -} else { - @servers = $cfg->listNodes("server"); - @clients = $cfg->returnValues("allow-clients address"); -} - -if (scalar(@servers) > 0) { - print $output "# Servers\n\n"; - foreach my $server (@servers) { - my $server_addr = ntp_format($server); - 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 "\n"; -} - -if (scalar(@clients) > 0) { - print $output "# Clients\n\n"; - foreach my $client (@clients) { - my $address = ntp_format($client); - print $output "restrict $address nomodify notrap nopeer\n"; - } - print $output "\n"; -} - -exit 0; diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl index 51617fce..de09a760 100755 --- a/scripts/system/vyatta_update_resolv.pl +++ b/scripts/system/vyatta_update_resolv.pl @@ -30,7 +30,6 @@ use Vyatta::Config; my $dhclient_script = 0; my $config_mode = 0; -my $ntp_config = 0; GetOptions("dhclient-script=i" => \$dhclient_script, "config-mode=i" => \$config_mode, @@ -45,7 +44,6 @@ my $disable_dhcp_nameservers = undef; if ($config_mode == 1) { $disable_dhcp_nameservers = $vc->exists('disable-dhcp-nameservers'); - $ntp_config = $vc->exists('ntp server'); } else { $disable_dhcp_nameservers = $vc->existsOrig('disable-dhcp-nameservers'); } @@ -53,7 +51,6 @@ if ($config_mode == 1) { if ($dhclient_script == 1) { @search_domains = $vc->returnOrigValues('domain-search domain'); $domain_name = $vc->returnOrigValue('domain-name'); - $ntp_config = $vc->existsOrig('ntp server'); } else { @search_domains = $vc->returnValues('domain-search domain'); $domain_name = $vc->returnValue('domain-name'); @@ -132,7 +129,6 @@ if ($domain_name && length($domain_name) > 0) { 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, but only if disable-dhcp-nameservers # hasn't been enabled. @@ -168,7 +164,6 @@ if (($dhclient_script == 1) || ($config_mode == 1)) { or die "$! error trying to overwrite"; print $rf "#nameserver written by vyatta_update_resolv.pl (dhcp)\nnameserver\t$ns\n"; close $rf; - $restart_ntp = 1; } } } @@ -206,7 +201,6 @@ if (($dhclient_script == 1) || ($config_mode == 1)) { $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) { @@ -225,18 +219,9 @@ if (($dhclient_script == 1) || ($config_mode == 1)) { $cmd = "sed -i -n '/nameserver\t$dhcpnameserver/".'{n;x;d;};x;1d;p;${x;p;}'."' /etc/resolv.conf"; } system($cmd); - $restart_ntp = 1; } } } - if ($restart_ntp == 1) { - # this corresponds to what is done in name-server/node.def as a fix for bug 1300 - if ($ntp_config == 1) { - system("sudo /opt/vyatta/sbin/vyatta_update_ntp.pl --dhclient-script $dhclient_script"); - my $cmd_ntp_restart = "if [ -f /etc/ntp.conf ] && grep -q '^server' /etc/ntp.conf; then /usr/sbin/invoke-rc.d ntp restart >&/dev/null; fi &"; - system($cmd_ntp_restart); - } - } } # The following will re-write '/etc/resolv.conf' line by line, diff --git a/scripts/vyatta-system-nameservers b/scripts/vyatta-system-nameservers index 99019fd1..9c688e80 100755 --- a/scripts/vyatta-system-nameservers +++ b/scripts/vyatta-system-nameservers @@ -36,14 +36,6 @@ restart_dnsmasq () { fi } -restart_ntp () { - # restart ntp if ntp is configured - if [ -f /etc/ntp.conf ] && grep -q "^server" /etc/ntp.conf; then - sudo /opt/vyatta/sbin/vyatta_update_ntp.pl - /usr/sbin/invoke-rc.d ntp restart >&/dev/null - fi -} - update_system_nameservers () { nameserver=$1 touch /etc/resolv.conf @@ -70,7 +62,6 @@ update_system_nameservers () { mv -f /etc/resolv_tmp.conf /etc/resolv.conf fi restart_dnsmasq - restart_ntp } delete_system_nameserver () { @@ -79,7 +70,6 @@ delete_system_nameserver () { # remove specified nameserver sed -i "/$nameserver$/d" /etc/resolv.conf restart_dnsmasq - restart_ntp } # diff --git a/templates/system/ntp/allow-clients/address/node.def b/templates/system/ntp/allow-clients/address/node.def deleted file mode 100644 index a48a2b5a..00000000 --- a/templates/system/ntp/allow-clients/address/node.def +++ /dev/null @@ -1,6 +0,0 @@ -multi: -type: ipv4net,ipv6net -help: IP address - -val_help: ipv4net; IP address and prefix length -val_help: ipv6net; IPv6 address and prefix length diff --git a/templates/system/ntp/allow-clients/node.def b/templates/system/ntp/allow-clients/node.def deleted file mode 100644 index 8228130e..00000000 --- a/templates/system/ntp/allow-clients/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Network Time Protocol (NTP) server options diff --git a/templates/system/ntp/node.def b/templates/system/ntp/node.def deleted file mode 100644 index 38e67e05..00000000 --- a/templates/system/ntp/node.def +++ /dev/null @@ -1,16 +0,0 @@ -priority: 400 -help: Network Time Protocol (NTP) configuration - -end: - sudo /opt/vyatta/sbin/vyatta_update_ntp.pl - if grep -q '^server' /etc/ntp.conf - then - if pgrep -f -u ntp /usr/sbin/ntpd > /dev/null - then - sudo /usr/sbin/invoke-rc.d ntp force-reload - else - sudo /usr/sbin/invoke-rc.d ntp start - fi - else - sudo /usr/sbin/invoke-rc.d ntp stop - fi diff --git a/templates/system/ntp/server/node.def b/templates/system/ntp/server/node.def deleted file mode 100644 index 383bd992..00000000 --- a/templates/system/ntp/server/node.def +++ /dev/null @@ -1,3 +0,0 @@ -tag: -type: txt -help: Network Time Protocol (NTP) server diff --git a/templates/system/ntp/server/node.tag/dynamic/node.def b/templates/system/ntp/server/node.tag/dynamic/node.def deleted file mode 100644 index 2d68de16..00000000 --- a/templates/system/ntp/server/node.tag/dynamic/node.def +++ /dev/null @@ -1,2 +0,0 @@ -help: Allow server to be configured even if not reachable - diff --git a/templates/system/ntp/server/node.tag/noselect/node.def b/templates/system/ntp/server/node.tag/noselect/node.def deleted file mode 100644 index e2e061b5..00000000 --- a/templates/system/ntp/server/node.tag/noselect/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Marks the server as unused diff --git a/templates/system/ntp/server/node.tag/preempt/node.def b/templates/system/ntp/server/node.tag/preempt/node.def deleted file mode 100644 index ca89efa1..00000000 --- a/templates/system/ntp/server/node.tag/preempt/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Specifies the association as preemptable rather than the default persistent diff --git a/templates/system/ntp/server/node.tag/prefer/node.def b/templates/system/ntp/server/node.tag/prefer/node.def deleted file mode 100644 index 4855fd41..00000000 --- a/templates/system/ntp/server/node.tag/prefer/node.def +++ /dev/null @@ -1 +0,0 @@ -help: Marks the server as preferred -- cgit v1.2.3