mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-08 20:58:20 +03:00
resolved: enable TCP_FASTOPEN + TCP_NODELAY on stub TCP socket
Latency matters. Four our local DNS stub it's not really that important, but let's still do it, it's basically free after all.
This commit is contained in:
parent
6283e71ba8
commit
8624f1286a
@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <net/if_arp.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
@ -987,6 +988,22 @@ static int set_dns_stub_common_socket_options(int fd, int family) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_dns_stub_common_tcp_socket_options(int fd) {
|
||||
int r;
|
||||
|
||||
assert(fd >= 0);
|
||||
|
||||
r = setsockopt_int(fd, IPPROTO_TCP, TCP_FASTOPEN, 5); /* Everybody appears to pick qlen=5, let's do the same here. */
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to enable TCP_FASTOPEN on TCP listening socket, ignoring: %m");
|
||||
|
||||
r = setsockopt_int(fd, IPPROTO_TCP, TCP_NODELAY, true);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to enable TCP_NODELAY mode, ignoring: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int manager_dns_stub_fd(Manager *m, int type) {
|
||||
union sockaddr_union sa = {
|
||||
.in.sin_family = AF_INET,
|
||||
@ -1010,6 +1027,12 @@ static int manager_dns_stub_fd(Manager *m, int type) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (type == SOCK_STREAM) {
|
||||
r = set_dns_stub_common_tcp_socket_options(fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Make sure no traffic from outside the local host can leak to onto this socket */
|
||||
r = socket_bind_to_ifindex(fd, LOOPBACK_IFINDEX);
|
||||
if (r < 0)
|
||||
@ -1081,6 +1104,12 @@ static int manager_dns_stub_fd_extra(Manager *m, DnsStubListenerExtra *l, int ty
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
if (type == SOCK_STREAM) {
|
||||
r = set_dns_stub_common_tcp_socket_options(fd);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Do not set IP_TTL for extra DNS stub listeners, as the address may not be local and in that case
|
||||
* people may want ttl > 1. */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user