diff --git a/conf.c b/conf.c index 912ac82..b3061c9 100644 --- a/conf.c +++ b/conf.c @@ -201,6 +201,9 @@ static char *bind_cmd_iface = NULL; /* Path to the Unix domain command socket. */ static char *bind_cmd_path = NULL; +/* Differentiated Services Code Point (DSCP) in transmitted NTP packets */ +static int ntp_dscp = 0; + /* Path to Samba (ntp_signd) socket. */ static char *ntp_signd_socket = NULL; @@ -560,6 +563,8 @@ CNF_ParseLine(const char *filename, int number, char *line) parse_allow_deny(p, ntp_restrictions, 0); } else if (!strcasecmp(command, "driftfile")) { parse_string(p, &drift_file); + } else if (!strcasecmp(command, "dscp")) { + parse_int(p, &ntp_dscp); } else if (!strcasecmp(command, "dumpdir")) { parse_string(p, &dumpdir); } else if (!strcasecmp(command, "dumponexit")) { @@ -2297,6 +2302,14 @@ CNF_GetBindCommandAddress(int family, IPAddr *addr) /* ================================================== */ +int +CNF_GetNtpDscp(void) +{ + return ntp_dscp; +} + +/* ================================================== */ + char * CNF_GetNtpSigndSocket(void) { diff --git a/conf.h b/conf.h index c35f245..b1f6e64 100644 --- a/conf.h +++ b/conf.h @@ -83,6 +83,7 @@ extern char *CNF_GetBindNtpInterface(void); extern char *CNF_GetBindAcquisitionInterface(void); extern char *CNF_GetBindCommandInterface(void); extern char *CNF_GetBindCommandPath(void); +extern int CNF_GetNtpDscp(void); extern char *CNF_GetNtpSigndSocket(void); extern char *CNF_GetPidFile(void); extern REF_LeapMode CNF_GetLeapSecMode(void); diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc index 51e1d88..5ea864d 100644 --- a/doc/chrony.conf.adoc +++ b/doc/chrony.conf.adoc @@ -652,6 +652,19 @@ An example of the directive is: bindacqdevice eth0 ---- +[[dscp]]*dscp* _point_:: +The *dscp* directive sets the Differentiated Services Code Point (DSCP) in +transmitted NTP packets to the specified value. It can improve stability of NTP +measurements in local networks where switches or routers are configured to +prioritise forwarding of packets with specific DSCP values. The default value +is 0 and the maximum value is 63. ++ +An example of the directive (setting the Expedited Forwarding class) is: ++ +---- +dscp 46 +---- + [[dumpdir]]*dumpdir* _directory_:: To compute the rate of gain or loss of time, *chronyd* has to store a measurement history for each of the time sources it uses. diff --git a/ntp_io.c b/ntp_io.c index 075f0cf..9d18df8 100644 --- a/ntp_io.c +++ b/ntp_io.c @@ -83,7 +83,7 @@ static void read_from_socket(int sock_fd, int event, void *anything); static int open_socket(int family, int local_port, int client_only, IPSockAddr *remote_addr) { - int sock_fd, sock_flags, events = SCH_FILE_INPUT; + int sock_fd, sock_flags, dscp, events = SCH_FILE_INPUT; IPSockAddr local_addr; char *iface; @@ -111,6 +111,14 @@ open_socket(int family, int local_port, int client_only, IPSockAddr *remote_addr return INVALID_SOCK_FD; } + dscp = CNF_GetNtpDscp(); + if (dscp > 0 && dscp < 64) { +#ifdef IP_TOS + if (!SCK_SetIntOption(sock_fd, IPPROTO_IP, IP_TOS, dscp << 2)) + ; +#endif + } + if (!client_only && family == IPADDR_INET4 && local_addr.port > 0) bound_server_sock_fd4 = local_addr.ip_addr.addr.in4 != INADDR_ANY;