mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
confd: new NTP setting stratum-weight
This patch adds support for chronyd's stratumpweight both in the NTP client (ietf-system) and client+server (ietf-ntp) should fix the flaky NTP stratum test. Also, make sure to *not* 'rm -rf /etc/chrony/conf.d/*' in system.c to prevent clobbering settings potentially made in ntp.c Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+6
-1
@@ -18,7 +18,7 @@ static int change(sr_session_ctx_t *session, struct lyd_node *config, struct lyd
|
||||
sr_event_t event, struct confd *confd)
|
||||
{
|
||||
struct lyd_node *ntp, *entry, *makestep, *refclock;
|
||||
const char *port;
|
||||
const char *port, *sw;
|
||||
FILE *fp;
|
||||
|
||||
if (diff && !lydx_get_xpathf(diff, XPATH_NTP_))
|
||||
@@ -68,6 +68,11 @@ static int change(sr_session_ctx_t *session, struct lyd_node *config, struct lyd
|
||||
fprintf(fp, "# Generated by confd\n");
|
||||
fprintf(fp, "# This file configures chronyd as an NTP server\n\n");
|
||||
|
||||
/* Global NTP source selection options */
|
||||
sw = lydx_get_cattr(ntp, "stratum-weight");
|
||||
if (sw)
|
||||
fprintf(fp, "stratumweight %s\n\n", sw);
|
||||
|
||||
/* Port configuration (optional) */
|
||||
port = lydx_get_cattr(ntp, "port");
|
||||
if (port) {
|
||||
|
||||
+20
-1
@@ -25,6 +25,7 @@
|
||||
#define XPATH_BASE_ "/ietf-system:system"
|
||||
#define XPATH_AUTH_ XPATH_BASE_"/authentication"
|
||||
#define XPATH_NTP_ XPATH_BASE_"/ntp"
|
||||
#define NTP_CLIENT_CONF "/etc/chrony/conf.d/ntp-client.conf"
|
||||
#define XPATH_DNS_ XPATH_BASE_"/dns-resolver"
|
||||
#define XPATH_HOSTNAME_ XPATH_BASE_"/hostname"
|
||||
#define XPATH_MOTD_BANNER_ XPATH_BASE_"/infix-system:motd-banner"
|
||||
@@ -304,7 +305,8 @@ static int change_ntp_client(sr_session_ctx_t *session, struct lyd_node *config,
|
||||
|
||||
case SR_EV_DONE:
|
||||
if (!srx_enabled(session, XPATH_NTP_"/enabled")) {
|
||||
systemf("rm -rf /etc/chrony/conf.d/* /etc/chrony/sources.d/*");
|
||||
(void)remove(NTP_CLIENT_CONF);
|
||||
systemf("rm -f /etc/chrony/sources.d/*");
|
||||
/* Note: chronyd enable/disable is managed centrally in core.c */
|
||||
systemf("initctl -nbq touch chronyd");
|
||||
return SR_ERR_OK;
|
||||
@@ -405,6 +407,23 @@ static int change_ntp_client(sr_session_ctx_t *session, struct lyd_node *config,
|
||||
}
|
||||
sr_free_values(val, cnt);
|
||||
|
||||
/* Write global NTP client options (stratumweight, etc.) to conf.d */
|
||||
if (srx_enabled(session, XPATH_NTP_"/enabled")) {
|
||||
char *sw = srx_get_str(session, XPATH_NTP_"/infix-system:stratum-weight");
|
||||
FILE *fp = fopen(NTP_CLIENT_CONF, "w");
|
||||
|
||||
if (fp) {
|
||||
fprintf(fp, "# Generated by confd\n");
|
||||
if (sw)
|
||||
fprintf(fp, "stratumweight %s\n", sw);
|
||||
fclose(fp);
|
||||
} else {
|
||||
ERRNO("Failed creating %s", NTP_CLIENT_CONF);
|
||||
}
|
||||
if (sw)
|
||||
free(sw);
|
||||
}
|
||||
|
||||
if (changes) {
|
||||
if (touch("/run/chrony/.changes"))
|
||||
ERRNO("Failed recording changes to NTP client");
|
||||
|
||||
@@ -42,7 +42,7 @@ MODULES=(
|
||||
"infix-firewall-services@2025-04-26.yang"
|
||||
"infix-firewall-icmp-types@2025-04-26.yang"
|
||||
"infix-meta@2025-12-10.yang"
|
||||
"infix-system@2025-12-02.yang"
|
||||
"infix-system@2026-03-09.yang"
|
||||
"infix-services@2025-12-10.yang"
|
||||
"ieee802-ethernet-interface@2019-06-21.yang"
|
||||
"infix-ethernet-interface@2024-02-27.yang"
|
||||
@@ -51,6 +51,6 @@ MODULES=(
|
||||
"ietf-crypto-types -e cleartext-symmetric-keys"
|
||||
"infix-crypto-types@2025-11-09.yang"
|
||||
"ietf-keystore -e symmetric-keys"
|
||||
"infix-ntp@2026-02-08.yang"
|
||||
"infix-ntp@2026-03-09.yang"
|
||||
"infix-keystore@2025-12-17.yang"
|
||||
)
|
||||
|
||||
@@ -29,6 +29,15 @@ module infix-ntp {
|
||||
contact "kernelkit@googlegroups.com";
|
||||
description "Infix deviations and augments to ietf-ntp.";
|
||||
|
||||
revision 2026-03-09 {
|
||||
description "Add stratumweight to NTP server configuration.
|
||||
|
||||
Allows tuning the weight of stratum in NTP source selection
|
||||
relative to measured distance. Setting to 0.0 ensures lower
|
||||
stratum sources are always preferred regardless of distance.";
|
||||
reference "internal";
|
||||
}
|
||||
|
||||
revision 2026-02-08 {
|
||||
description
|
||||
"Add GPS/GNSS reference clock support.
|
||||
@@ -56,6 +65,25 @@ module infix-ntp {
|
||||
*/
|
||||
|
||||
augment "/ntp:ntp" {
|
||||
leaf stratum-weight {
|
||||
type decimal64 {
|
||||
fraction-digits 3;
|
||||
range "0.0..max";
|
||||
}
|
||||
default "0.001";
|
||||
units "seconds";
|
||||
description
|
||||
"Weight of stratum in NTP source selection relative to measured distance.
|
||||
|
||||
A one-stratum difference counts as this many seconds of additional
|
||||
distance when comparing candidates.
|
||||
|
||||
The default (0.001 = 1ms) means stratum only wins when distance
|
||||
differences are less than 1ms. Setting it to 0.0 ensures that a
|
||||
lower-stratum source is always preferred over a higher-stratum source,
|
||||
regardless of their measured distances.";
|
||||
}
|
||||
|
||||
container makestep {
|
||||
presence "Enable clock stepping for large offsets";
|
||||
description
|
||||
|
||||
@@ -28,6 +28,15 @@ module infix-system {
|
||||
contact "kernelkit@googlegroups.com";
|
||||
description "Infix augments and deviations to ietf-system.";
|
||||
|
||||
revision 2026-03-09 {
|
||||
description "Add stratumweight to NTP client configuration.
|
||||
|
||||
Allows tuning the weight of stratum in NTP source selection
|
||||
relative to measured distance. Setting to 0.0 ensures lower
|
||||
stratum sources are always preferred regardless of distance.";
|
||||
reference "internal";
|
||||
}
|
||||
|
||||
revision 2025-12-02 {
|
||||
description "Extend services with runtime statistics:
|
||||
- Add statistics container with memory-usage, uptime, restart-count";
|
||||
@@ -307,6 +316,27 @@ module infix-system {
|
||||
}
|
||||
}
|
||||
|
||||
augment "/sys:system/sys:ntp" {
|
||||
leaf stratum-weight {
|
||||
type decimal64 {
|
||||
fraction-digits 3;
|
||||
range "0.0..max";
|
||||
}
|
||||
default "0.001";
|
||||
units "seconds";
|
||||
description
|
||||
"Weight of stratum in NTP source selection relative to measured distance.
|
||||
|
||||
A one-stratum difference counts as this many seconds of additional
|
||||
distance when comparing candidates.
|
||||
|
||||
The default (0.001 = 1ms) means stratum only wins when distance
|
||||
differences are less than 1ms. Setting it to 0.0 ensures that a
|
||||
lower-stratum source is always preferred over a higher-stratum source,
|
||||
regardless of their measured distances.";
|
||||
}
|
||||
}
|
||||
|
||||
augment "/sys:system/sys:authentication/sys:user" {
|
||||
description "Augment of ietf-system to support setting login shell for users.";
|
||||
leaf shell {
|
||||
|
||||
@@ -107,6 +107,7 @@ with infamy.Test() as test:
|
||||
"system": {
|
||||
"ntp": {
|
||||
"enabled": True,
|
||||
"infix-system:stratum-weight": 0.0,
|
||||
"server": [{
|
||||
"name": "srv1",
|
||||
"udp": {
|
||||
|
||||
Reference in New Issue
Block a user