Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/confd/src/ntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_))
Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 20 additions & 1 deletion src/confd/src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/confd/yang/confd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
28 changes: 28 additions & 0 deletions src/confd/yang/confd/infix-ntp.yang
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions src/confd/yang/confd/infix-system.yang
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions test/case/ntp/client_stratum_selection/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"system": {
"ntp": {
"enabled": True,
"infix-system:stratum-weight": 0.0,
"server": [{
"name": "srv1",
"udp": {
Expand Down