]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP6: Request OPTION_NTP_SERVER to mirror DHCP
authorRoy Marples <roy@marples.name>
Tue, 7 Feb 2023 18:25:45 +0000 (18:25 +0000)
committerRoy Marples <roy@marples.name>
Tue, 7 Feb 2023 18:29:33 +0000 (18:29 +0000)
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.

hooks/50-ntp.conf
hooks/50-timesyncd.conf
src/dhcp6.c
src/dhcp6.h

index 767e83609dd6f28dfcd26e7f32025e28d7bac631..a26f1b5f2b0dc4bffd7dafe3128986111b2a0fe7 100644 (file)
@@ -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
index c826804f7722ef0666e3894d2f6d946d9a187bf4..dff8817324e3c289cb5b8a5ab71f50ff13ab6d1b 100644 (file)
@@ -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
 
index 3b40636a7703b3fd11aea85cba972d11d0cef6d1..1131f70f1c685f0a795b256a5c725439b3fa75b6 100644 (file)
@@ -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 },
index 5f72b9aa0c7c4460c65b2a142ed44dae9efc72c6..3995c988e3f9ad509638f93888fd4da98ddd6311 100644 (file)
@@ -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