From: Roy Marples Date: Tue, 7 Feb 2023 18:25:45 +0000 (+0000) Subject: DHCP6: Request OPTION_NTP_SERVER to mirror DHCP X-Git-Tag: v10.0.0~4^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f6f61cbe3edfc8313d7db63d6ecf1b08d7232f1;p=thirdparty%2Fdhcpcd.git DHCP6: Request OPTION_NTP_SERVER to mirror DHCP RFC 5908 deprecates OPTION_SNTP_SERVERS. However we can support both at the same time as our scripts will uniqify the results if there are stupidly any duplicates. Fixes #183. --- diff --git a/hooks/50-ntp.conf b/hooks/50-ntp.conf index 767e8360..a26f1b5f 100644 --- a/hooks/50-ntp.conf +++ b/hooks/50-ntp.conf @@ -113,7 +113,7 @@ add_ntp_conf() [ -e "$cf" ] && rm "$cf" [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir" if [ -n "$new_ntp_servers" ]; then - for x in $new_ntp_servers; do + for x in $(uniqify $new_ntp_servers); do echo "server $x" >> "$cf" done fi @@ -131,10 +131,13 @@ remove_ntp_conf() # For ease of use, map DHCP6 names onto our DHCP4 names case "$reason" in BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6) - new_ntp_servers="$new_dhcp6_sntp_servers" + new_ntp_servers="$new_dhcp6_sntp_servers $new_dhcp6_ntp_server_addr $new_dhcp6_ntp_server_fqdn" ;; esac +echo DHCP6 test +echo $new_ntp_servers + if $if_configured; then if $if_up; then add_ntp_conf diff --git a/hooks/50-timesyncd.conf b/hooks/50-timesyncd.conf index c826804f..dff88173 100644 --- a/hooks/50-timesyncd.conf +++ b/hooks/50-timesyncd.conf @@ -25,7 +25,18 @@ add_timesyncd_conf() conf="$signature$NL" conf="${conf}[Time]$NL" - conf="${conf}NTP=$new_ntp_servers$NL" + conf="${conf}NTP=" + # Trim spaces + space=false + for ntp_server in $(uniqify $new_ntp_servers); do + if ! $space; then + space=true + else + conf="$conf " + fi + conf="$conf$ntp_server" + done + conf="$conf$NL" printf %s "$conf" > "$timesyncd_tmp" if change_file "$timesyncd_conf" "$timesyncd_tmp"; then @@ -36,7 +47,7 @@ add_timesyncd_conf() # For ease of use, map DHCP6 names onto our DHCP4 names case "$reason" in BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6) - new_ntp_servers="$new_dhcp6_sntp_servers" + new_ntp_servers="$new_dhcp6_sntp_servers $new_dhcp6_ntp_server_addr $new_dhcp6_ntp_server_fqdn" ;; esac diff --git a/src/dhcp6.c b/src/dhcp6.c index 3b40636a..1131f70f 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -147,12 +147,18 @@ struct dhcp_compat { uint16_t dhcp6_opt; }; +/* + * RFC 5908 deprecates OPTION_SNTP_SERVERS. + * But we can support both as the hook scripts will uniqify the + * results if the server returns both options. + */ static const struct dhcp_compat dhcp_compats[] = { { DHO_DNSSERVER, D6_OPTION_DNS_SERVERS }, { DHO_HOSTNAME, D6_OPTION_FQDN }, { DHO_DNSDOMAIN, D6_OPTION_FQDN }, { DHO_NISSERVER, D6_OPTION_NIS_SERVERS }, { DHO_NTPSERVER, D6_OPTION_SNTP_SERVERS }, + { DHO_NTPSERVER, D6_OPTION_NTP_SERVER }, { DHO_RAPIDCOMMIT, D6_OPTION_RAPID_COMMIT }, { DHO_FQDN, D6_OPTION_FQDN }, { DHO_VIVCO, D6_OPTION_VENDOR_CLASS }, diff --git a/src/dhcp6.h b/src/dhcp6.h index 5f72b9aa..3995c988 100644 --- a/src/dhcp6.h +++ b/src/dhcp6.h @@ -93,6 +93,7 @@ #define D6_OPTION_FQDN 39 #define D6_OPTION_POSIX_TIMEZONE 41 #define D6_OPTION_TZDB_TIMEZONE 42 +#define D6_OPTION_NTP_SERVER 56 #define D6_OPTION_PD_EXCLUDE 67 #define D6_OPTION_SOL_MAX_RT 82 #define D6_OPTION_INF_MAX_RT 83