summaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-06-09 14:22:44 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-06-09 14:22:44 +0100
commitae6f563623c765e574bd9a211be7524f7495ea28 (patch)
tree1a43bace3e697c00c5e90c0efe0f6124ba753898 /src/libserver
parent488f72bad4fab719861b4641ff832f60729a5950 (diff)
downloadrspamd-ae6f563623c765e574bd9a211be7524f7495ea28.tar.gz
rspamd-ae6f563623c765e574bd9a211be7524f7495ea28.zip
[Project] Preliminary usage of the reuseport
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/worker_util.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 639fc9480..d5e603cfa 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -933,6 +933,36 @@ rspamd_main_heartbeat_start (struct rspamd_worker *wrk, struct ev_loop *event_lo
ev_timer_start (event_loop, &wrk->hb.heartbeat_ev);
}
+static bool
+rspamd_maybe_reuseport_socket (struct rspamd_worker_listen_socket *ls)
+{
+ if (ls->fd == -1 || ls->is_systemd ||
+ rspamd_inet_address_get_af (ls->addr) == AF_UNIX) {
+ return false;
+ }
+
+#if defined(SO_REUSEPORT) && defined(SO_REUSEADDR)
+ gint nfd;
+
+ nfd = rspamd_inet_address_listen (ls->addr,
+ (ls->type == RSPAMD_WORKER_SOCKET_UDP ? SOCK_DGRAM : SOCK_STREAM),
+ RSPAMD_INET_ADDRESS_LISTEN_ASYNC|RSPAMD_INET_ADDRESS_LISTEN_REUSEPORT,
+ -1);
+
+ if (nfd == -1) {
+ msg_warn ("cannot create reuseport listen socket for %d: %s",
+ ls->fd, strerror (errno));
+ }
+ else {
+ close (ls->fd);
+ ls->fd = nfd;
+ }
+#else
+
+#endif
+
+ return false;
+}
/**
* Handles worker after fork returned zero
@@ -1006,6 +1036,17 @@ rspamd_handle_child_fork (struct rspamd_worker *wrk,
}
}
+ /* Reuseport before dropping privs */
+ GList *cur = cf->listen_socks;
+
+ while (cur) {
+ struct rspamd_worker_listen_socket *ls =
+ (struct rspamd_worker_listen_socket *)cur->data;
+
+ rspamd_maybe_reuseport_socket (ls);
+ cur = g_list_next (cur);
+ }
+
/* Drop privileges */
rspamd_worker_drop_priv (rspamd_main);
/* Set limits */