[Networkmanager] NetworkManager handling of NTP options

Thomas Haller thaller at redhat.com
Fri Mar 10 21:07:49 UTC 2023


On Fri, 2023-03-10 at 21:50 +0100, mh at mike.franken.de wrote:
> Hi *,
> 
> I am using systemd-timesyncd for managing the ntp server entries on
> my 
> clients. Because NetworkManager doesn't update timesyncd.conf, I
> wrote a 
> dispatcher script, that is doing this job. The script is using the 
> DHCP[46]_NTP_SERVERS env vars, NetworkManager is providing to
> dispatcher 
> scripts.
> Everything works fine for DHCP connections, but as for my wireguard
> VPN 
> connection this doesn't work, because there isn't any setting for ntp
> servers 
> - at least I couldn't find one.
> So I thought, I could add a static fallback entry to
> /etc/sysconfig/network/
> config in NETCONFIG_NTP_STATIC_SERVERS. Indeed this entry is written
> to some 
> files, for example to chrony.servers.
> But I couldn't find any easy way to get that value from my dispatcher
> script 
> besides reading NETCONFIG_NTP_STATIC_SERVERS myself. Is this really
> the way to 
> do this or am I missing something here?

Maybe NetworkManager should directly integrate with timesyncd or crony.
On the other hand, the dispatcher solution may not be too terrible...


Maybe in the future, a NetworkManager profile could just have a "ntp"
option, which the dispatcher script could read and use -- or, if NM
directly integrates with timesyncd/chrony to actively push those
settings.



> Whats more: If this static entry exists, NetworkManager is writing it
> to the 
> above mentioned files even if it gets ntp servers from a DHCP
> connection. Is 
> this correct?
> 
> debug: ntp-runtime Module called
> debug: Resolved ntp-policy 'auto' for service 'NetworkManager' to 
> 'STATIC_FALLBACK NetworkManager'
> debug: Static Fallback
> debug: Use NetworkManager policy merged settings
> debug: exec get_ntp_settings: /run/netconfig/NetworkManager.netconfig
> debug:      get_ntp_settings: NTP_SERVER_LIST=''
> debug: exit get_ntp_settings: /run/netconfig/NetworkManager.netconfig
> debug: write_chrony_servers: 192.168.1.1
> debug: ntp servers written to /run/netconfig/chrony.servers
> debug: write_ntpd_servers: 192.168.1.1
> debug: ntp servers written to /run/ntp/servers-netconfig


I guess, you could hard code it in your script, like

WIREGUARD_UUID=...

if [ "$CONNECTION_UUID" = "$WIREGUARD_UUID" ]; then
    NTP=...
else
    NTP="$DHCP4_NTP_SERVERS $DHCP6_NTP_SERVERS"
fi



if, you could honor certain files in etc, like

if [ -f "/etc/NetworkManager/ntp/$CONNECTION_UUID" ]; then
    NTP="$(cat "/etc/NetworkManager/ntp/$CONNECTION_UUID")"
else
    NTP="$DHCP4_NTP_SERVERS $DHCP6_NTP_SERVERS"
fi


Of course, if you somehow like "NETCONFIG_NTP_STATIC_SERVERS", then the
your dispatcher script could read that variable from somewhere... you
can script whatever suits you.



Note that connection profiles already support arbitrary user-data, so
you could set a user-data in the profile like "my.ntp.servers=...".
That could be nice, but the major problem with that is, that nmcli
doesn't support getting/setting those fields, that makes it rather
cumbersome. The example script [1] shows how to access user-data from
python.

[1]
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/9bf193f1a8fb2dc53f1026a5d38fcfe575976fcb/examples/python/gi/setting-user-data.py


> 
> 
> - openSUSE Tumbleweed 20230308
> - NetworkManager-1.42.2-1.1.x86_64
> - systemd-252.7-1.1.x86_64
> 
> 
> TIA.
> 
> Bye.
> Michael.
> 
> 



More information about the Networkmanager mailing list