]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
tcp-handler: fix TCP socket indexing if TLS and TCP reuseport configured
authorDaniel Salzman <daniel.salzman@nic.cz>
Thu, 16 Jul 2026 10:35:01 +0000 (12:35 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Thu, 16 Jul 2026 10:35:01 +0000 (12:35 +0200)
src/knot/server/tcp-handler.c

index 30d6a08fe8cd30cf205b95c995fa339b124d9033..e131144e50bf0fe8d1c6594ac542c5b205a64d0b 100644 (file)
@@ -125,7 +125,7 @@ static void tcp_log_error(const struct sockaddr_storage *ss, const char *operati
 }
 
 static unsigned tcp_set_ifaces(const iface_t *ifaces, size_t n_ifaces,
-                               fdset_t *fds, int thread_id, bool *tls)
+                               fdset_t *fds, unsigned dt_thread_id, bool *tls)
 {
        if (n_ifaces == 0) {
                return 0;
@@ -136,14 +136,11 @@ static unsigned tcp_set_ifaces(const iface_t *ifaces, size_t n_ifaces,
                        continue;
                }
 
-               int tcp_id = 0;
+               unsigned tcp_id = 0;
 #ifdef ENABLE_REUSEPORT
                if (conf()->cache.srv_tcp_reuseport && i->addr.ss_family != AF_UNIX) {
-                       /* Note: thread_ids start with UDP threads, TCP threads follow. */
-                       assert((i->fd_udp_count <= thread_id) &&
-                              (thread_id < i->fd_tcp_count + i->fd_udp_count));
-
-                       tcp_id = thread_id - i->fd_udp_count;
+                       assert(dt_thread_id < i->fd_tcp_count);
+                       tcp_id = dt_thread_id;
                }
 #endif
                int ret = fdset_add(fds, i->fd_tcp[tcp_id], FDSET_POLLIN, (void *)i);
@@ -363,14 +360,15 @@ int tcp_master(dthread_t *thread)
        }
 
        iohandler_t *handler = (iohandler_t *)thread->data;
-       int thread_id = handler->thread_id[dt_get_id(thread)];
+       unsigned dt_thread_id = dt_get_id(thread);
+       unsigned thread_id = handler->thread_id[dt_thread_id];
 
 #ifdef ENABLE_REUSEPORT
        /* Set thread affinity to CPU core (overlaps with UDP/XDP). */
        if (conf()->cache.srv_tcp_reuseport) {
                unsigned cpu = dt_online_cpus();
                if (cpu > 1) {
-                       unsigned cpu_mask = (dt_get_id(thread) % cpu);
+                       unsigned cpu_mask = (dt_thread_id % cpu);
                        dt_setaffinity(thread, &cpu_mask, 1);
                }
        }
@@ -409,7 +407,7 @@ int tcp_master(dthread_t *thread)
        bool tls = false;
        tcp.client_threshold = tcp_set_ifaces(handler->server->ifaces,
                                              handler->server->n_ifaces,
-                                             &tcp.set, thread_id, &tls);
+                                             &tcp.set, dt_thread_id, &tls);
        if (tcp.client_threshold == 0) {
                goto finish; /* Terminate on zero interfaces. */
        }