Commit graph

24 commits

Author SHA1 Message Date
Miroslav Lichvar
27e20a568b socket: enable only specified IP families
Allow an IP family to be specified in the socket initialization in order
to globally disable the other family. This replaces the ntp_io and
cmdmon code handling the -4/-6 options and fixes a case where the NTP
client could still use a disabled family if the source was specified
with an IP address.
2020-06-17 15:24:55 +02:00
Miroslav Lichvar
80316de3b8 socket: don't log errors on removing socket
Call unlink() directly to avoid an error log message when a Unix domain
socket cannot be removed (e.g. SOCK refclock created for gpsd in
/var/run).
2020-06-17 15:24:55 +02:00
Miroslav Lichvar
e49aececce socket: don't set interface for sent packets
With asymmetric routing (e.g. with BGP) it may not be possible to
respond to a request using the same interface. In such case, setting the
interface index in IP*_PKTINFO* causes the packet to be silently dropped
by the kernel.

Until we can predict if sending with the specified interface will
succeed, or provide only a hint, don't set the interface and leave it
to the kernel to select an interface.

This reverts commit 5fc7674e36 ("ntp: set interface index in
IP*_PKTINFO when responding").

Reported-by: Arkadiusz Miśkiewicz <arekm@maven.pl>
2020-05-14 15:37:38 +02:00
Miroslav Lichvar
cfa39af345 socket: fix severity check in debug logging
Don't waste time formatting the debug message in log_message() when
debug output is disabled.

Fixes: 86a3ef9ed1 ("socket: add new socket support")
2020-03-26 11:06:54 +01:00
Miroslav Lichvar
8bab35c122 socket: increase maximum number of received messages
The buffers are no longer on stack. Increase their number for better
performance on heavily loaded servers.
2020-03-26 11:06:54 +01:00
Miroslav Lichvar
b20ef4cd7f socket: simplify receiving messages
Don't require the caller to provide a SCK_Message (on stack). Modify the
SCK_ReceiveMessage*() functions to return a pointer to static buffers,
as the message buffer which SCK_Message points to already is.
2020-03-26 11:04:18 +01:00
Miroslav Lichvar
b8b751a932 socket: enable port sharing on Linux
On Linux, enable the SO_REUSEPORT option on sockets bound to a port in
order to support load balancing with multiple chronyd instances
(configured to not adjust the system clock).

The IP_FREEBIND option already allowed different instances to bind to
the same address and port, but only one was actually receiving packets.

As the instances don't share their state, sharing the NTP port doesn't
work well with the interleaved mode, symmetric mode, and rate limiting.

Sharing the NTS-KE port will not work until the server keys can be
derived from a shared key.
2020-03-24 16:29:33 +01:00
Miroslav Lichvar
d29bef93e9 ntp: refactor NTP_Packet structure for extension fields 2020-03-05 16:02:15 +01:00
Miroslav Lichvar
dd0679ad45 socket: add function to check supported family
Don't log error when an IPv6 socket cannot be opened and chronyd was
built without IPv6 support.

Reported-by: Lonnie Abelbeck <lonnie@abelbeck.com>
2020-01-03 11:47:41 +01:00
Miroslav Lichvar
2bf1ba22f2 socket: change SCK_Send() declaration to const buffer 2019-12-12 13:03:31 +01:00
Miroslav Lichvar
dfc2f70876 socket: add support for opening socket pairs 2019-12-12 13:03:31 +01:00
Miroslav Lichvar
0dba2b9689 socket: add support for blocking sockets
Add a flag to open a blocking socket. The default stays non-blocking.
2019-12-12 13:03:31 +01:00
Miroslav Lichvar
e7fc2d31cc socket: remove unnecessary MSG_DONTWAIT flag
This is not needed since sockets are non-blocking by default.
2019-12-12 13:03:31 +01:00
Miroslav Lichvar
f231efb811 socket: add support for sending and receiving descriptors
Add support for the SCM_RIGHTS control message used in communication
with the privops helper.
2019-12-12 13:03:31 +01:00
Miroslav Lichvar
e18903a6b5 switch to new util file functions
Replace all fopen(), rename(), and unlink() calls with the new util
functions.
2019-10-24 12:48:45 +02:00
Miroslav Lichvar
02ada36838 socket: add support for TCP sockets
TCP sockets will be needed for NTS key establishment.
2019-08-27 17:10:13 +02:00
Miroslav Lichvar
81978f0ba0 socket: fix typo in union declaration 2019-08-08 17:32:48 +02:00
Miroslav Lichvar
622769cdfd util: add debug messages to UTI_FdSetCloexec() 2019-08-08 17:32:48 +02:00
Miroslav Lichvar
5e8ed72b89 socket: fix compiler warning
Don't define check_socket_flag() if no supported socket flag is defined.
2019-07-25 09:52:33 +02:00
Miroslav Lichvar
45e41b7ac1 socket: avoid unnecessary bind() call
Don't call bind() if the specified local address of a socket has port 0
and the "any" address. It will be bound automatically on connect() or
sendmsg().
2019-07-24 16:27:07 +02:00
Miroslav Lichvar
27fd751915 socket: add support for socket() flags
On start, check if the SOCK_CLOEXEC and SOCK_NONBLOCK flags are
supported in the socket() call and use them instead of fcntl() in order
to reduce the number of system calls required to send a client request.
2019-07-24 15:35:00 +02:00
Miroslav Lichvar
4d26cfc92b socket: make all sockets non-blocking
All networking code in chronyd (NTP server/client, signd client, cmdmon
server) assumes sending a message will not block, but only the signd
client actually checks for a write event and only the NTP server
requests a non-blocking socket. The cmdmon server and NTP client
(if using one socket for all servers) might be blocked.

chronyc doesn't need a non-blocking socket, but it is not expected to
block as it sends only one message at a time.

Prefer dropped messages over blocking in all cases. Remove the
SCK_FLAG_NONBLOCK flag and make all sockets non-blocking.
2019-07-24 10:21:14 +02:00
Miroslav Lichvar
47e4cb31b2 util: move and improve sockaddr-specific functions
Move the functions to socket.c and improve them to require and check the
sockaddr length.
2019-07-18 17:29:44 +02:00
Miroslav Lichvar
86a3ef9ed1 socket: add new socket support
Add a new file implementing support for opening sockets, sending and
receiving messages with control messages (e.g. addresses, timestamps),
and related operations, which should be simpler to use than the system
functions and allow their features to be reused between different parts
of the chrony code.

It is based on the ntp_io.c and ntp_io_linux.c files. It will be used by
the NTP client/server, cmdmon server, client, and others.
2019-07-18 16:54:48 +02:00