diff mbox series

[1/1] package/chrony: optional NetworkManager DHCP integration

Message ID 20250207133128.3646294-1-fiona.klute@gmx.de
State New
Headers show
Series [1/1] package/chrony: optional NetworkManager DHCP integration | expand

Commit Message

Fiona Klute Feb. 7, 2025, 1:31 p.m. UTC
If the new BR2_PACKAGE_CHRONY_NM_DHCP option is enabled, chrony will
automatically add NTP servers received over DHCP to its sources. This
is particularly useful for devices without a battery-backed RTC, if
the local DHCP (including DHCPv6) server announces nearby NTP servers.

Signed-off-by: Fiona Klute <fiona.klute@gmx.de>
---
 package/chrony/Config.in | 14 ++++++++++++++
 package/chrony/chrony.mk |  8 ++++++++
 2 files changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/package/chrony/Config.in b/package/chrony/Config.in
index 453e4f6c3f..7b3515e5af 100644
--- a/package/chrony/Config.in
+++ b/package/chrony/Config.in
@@ -17,4 +17,18 @@  config BR2_PACKAGE_CHRONY_DEBUG_LOGGING
 	  enabled at runtime. If disabled, code for debug logging will
 	  not be compiled in.
 
+config BR2_PACKAGE_CHRONY_NM_DHCP
+	bool "receive NTP sources from NetworkManager DHCP client"
+	depends on BR2_PACKAGE_NETWORK_MANAGER
+	help
+	  Install a NetworkManager dispatcher script that writes NTP
+	  servers received over DHCP to a per-interface sources file
+	  and reloads sources, and add a "sourcedir" directive to use
+	  those files to the default config.
+
+	  Note that if you enable this option and override the default
+	  chrony config (e.g. in an overlay) you need to make sure
+	  that the "sourcedir /var/run/chrony-dhcp" directive remains
+	  in effect.
+
 endif
diff --git a/package/chrony/chrony.mk b/package/chrony/chrony.mk
index 642e1d8fd6..0685211b75 100644
--- a/package/chrony/chrony.mk
+++ b/package/chrony/chrony.mk
@@ -65,6 +65,13 @@  else
 CHRONY_CONF_OPTS += --without-nettle
 endif
 
+ifeq ($(BR2_PACKAGE_CHRONY_NM_DHCP),y)
+define CHRONY_INSTALL_NM_DHCP_CMDS
+	$(INSTALL) -D -m 755 $(@D)/examples/chrony.nm-dispatcher.dhcp $(TARGET_DIR)/etc/NetworkManager/dispatcher.d/chrony.dhcp
+	echo "sourcedir /var/run/chrony-dhcp" >>$(TARGET_DIR)/etc/chrony.conf
+endef
+endif
+
 define CHRONY_CONFIGURE_CMDS
 	cd $(@D) && $(TARGET_CONFIGURE_OPTS) ./configure $(CHRONY_CONF_OPTS)
 endef
@@ -76,6 +83,7 @@  endef
 define CHRONY_INSTALL_TARGET_CMDS
 	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) DESTDIR="$(TARGET_DIR)" install
 	$(INSTALL) -D -m 644 $(@D)/examples/chrony.conf.example2 $(TARGET_DIR)/etc/chrony.conf
+	$(CHRONY_INSTALL_NM_DHCP_CMDS)
 endef
 
 define CHRONY_INSTALL_INIT_SYSV