conf: add dscp directive

The directive sets the DSCP value in transmitted NTP packets, which can
be useful in local networks where switches/routers are configured to
prioritise packets with specific DSCP values.
This commit is contained in:
Miroslav Lichvar
2020-08-03 17:55:42 +02:00
parent e5cf006378
commit 6a5665ca58
4 changed files with 36 additions and 1 deletions

View File

@@ -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;