Repository navigation
Fix DHCP NTP handoff from NetworkManager to timesyncd - #4351
Open
kevinwieland wants to merge 2 commits into
Open
kevinwieland wants to merge 2 commits into
kevinwieland wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="runs/setup_timesync.sh" line_range="22" />
<code_context>
+
+install -d -o root -g root -m 0755 /etc/NetworkManager/dispatcher.d
+if ! cmp -s "$source_file" "$dispatcher"; then
+ install -o root -g root -m 0755 "$source_file" "$dispatcher"
+ echo "installed NetworkManager DHCP NTP dispatcher"
+fi
</code_context>
<issue_to_address>
**Rogue DHCP can control system time**
When a rogue DHCP server supplies option 42 on a connected interface, the dispatcher accepts any syntactically valid DHCP NTP address, writes it as the active timesyncd server, and restarts timesyncd; the server can then skew the host clock and disrupt time-dependent security checks.
Restrict importing DHCP NTP servers to explicitly trusted NetworkManager connections, or otherwise require a trusted/authenticated time source.
</issue_to_address>
### Comment 2
<location path="runs/setup_timesync.sh" line_range="22" />
<code_context>
+
+install -d -o root -g root -m 0755 /etc/NetworkManager/dispatcher.d
+if ! cmp -s "$source_file" "$dispatcher"; then
+ install -o root -g root -m 0755 "$source_file" "$dispatcher"
+ echo "installed NetworkManager DHCP NTP dispatcher"
+fi
</code_context>
<issue_to_address>
**DHCP servers are discarded**
When a connected interface has an NTP server in its DHCPv4 lease, the dispatcher’s `awk` parser uses `.` as a regular-expression separator, so it splits each IPv4 address at every character instead of at literal dots. No address passes the four-octet check, leaving timesyncd without the DHCP-provided servers.
Use a literal-dot separator such as `[.]` when splitting the address into octets.
</issue_to_address>
### Comment 3
<location path="runs/setup_timesync.sh" line_range="11-12" />
<code_context>
+fi
+
+# Do not change systems using dhcpcd, networkd or another time service.
+if ! command -v nmcli >/dev/null || ! systemctl is-active --quiet NetworkManager.service ||
+ ! systemctl is-active --quiet systemd-timesyncd.service; then
+ echo "NetworkManager/timesyncd not active, skipping DHCP NTP integration"
+ exit 0
</code_context>
<issue_to_address>
**DHCP NTP handoff stays absent**
When openWB startup runs before NetworkManager or systemd-timesyncd becomes active, `setup_timesync.sh` exits successfully without installing the dispatcher, and startup does not retry after the services become active, so DHCP NTP servers are not handed to timesyncd for the rest of that boot.
Arrange for setup to run after both services are active or retry it when they become active.
Also at `runs/atreboot.sh:100-101`.
</issue_to_address>
### Comment 4
<location path="runs/setup_timesync.sh" line_range="30" />
<code_context>
+chmod 0755 "$dispatcher"
+
+# The connection may already be up before the dispatcher is installed.
+"$dispatcher" none refresh
</code_context>
<issue_to_address>
**Some DHCP time servers are discarded**
When a DHCP NTP option contains multiple addresses rendered with comma separators, `awk` splits the option value on whitespace and passes each token directly to `split(..., ".")`; when NetworkManager renders multiple servers comma-separated, the comma makes the preceding address fail validation, so that server is omitted from timesyncd’s configuration.
Normalize the NetworkManager list separators before validating each address.
</issue_to_address>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NetworkManager receives NTP servers via DHCPv4 option 42 but does not automatically pass them to systemd-timesyncd. This change installs the missing integration during openWB startup.
/run/systemd/timesyncd.conf.d/60-openwb-dhcp.conf, leaving existing static NTP settings untouched.The integration is only installed when both NetworkManager and systemd-timesyncd are already active. No packages are installed or services enabled. DHCPv6 is outside this change's scope.
Validation
git diff --checkpassed.Custom startup scripts that bypass
runs/atreboot.shmust invokeruns/setup_timesync.shseparately; external startup scripts and systemd drop-ins are not modified.Summary by Sourcery
Integrate NetworkManager DHCP NTP servers with systemd-timesyncd during openWB startup without changing systems that do not use both services.
New Features:
Bug Fixes:
Enhancements: