From 4afeaeb4b6ab6c56e582436b17f367e216f16de1 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 25 Oct 2026 02:43:09 +0200 Subject: Use the new ot_socket abstraction for socket creation, read and write --- opentracker.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'opentracker.c') diff --git a/opentracker.c b/opentracker.c index af336aa..5b197d1 100644 --- a/opentracker.c +++ b/opentracker.c @@ -24,7 +24,6 @@ /* Libowfat */ #include "io.h" #include "iob.h" -#include "socket.h" /* Opentracker */ #include "ot_accesslist.h" @@ -35,6 +34,7 @@ #include "ot_mutex.h" #include "ot_random.h" #include "ot_scan.h" +#include "ot_socket.h" #include "ot_stats.h" #include "ot_udp.h" #include "trackerlogic.h" @@ -254,10 +254,10 @@ static void handle_accept(const int64_t serversocket) { struct http_data *cookie; int64_t sock; ot_ip6 ip; - uint16 port; + uint16_t port; tai6464 t; - while ((sock = socket_accept6(serversocket, ip, &port, NULL)) != -1) { + while ((sock = socket_accept(serversocket, ip, &port)) != -1) { /* Put fd into a non-blocking mode */ io_nonblock(sock); @@ -339,7 +339,7 @@ static void *server_mainloop(void *args) { } static int64_t ot_try_bind(ot_ip6 ip, uint16_t port, PROTO_FLAG proto) { - int64_t sock = proto == FLAG_TCP ? socket_tcp6() : socket_udp6(); + int64_t sock; #ifdef _DEBUG { @@ -352,11 +352,13 @@ static int64_t ot_try_bind(ot_ip6 ip, uint16_t port, PROTO_FLAG proto) { } #endif - if (socket_bind6_reuse(sock, ip, port, 0) == -1) - panic("socket_bind6_reuse"); - - if ((proto == FLAG_TCP) && (socket_listen(sock, SOMAXCONN) == -1)) - panic("socket_listen"); + if (proto == FLAG_TCP) { + if ((sock = socket_tcp_listen(ip, port)) == -1) + panic("socket_tcp_listen"); + } else { + if ((sock = socket_udp_bind(ip, port)) == -1) + panic("socket_udp_bind"); + } if (!io_fd(sock)) panic("io_fd"); @@ -450,6 +452,7 @@ typedef enum { CONFIG_LISTEN_TCP, CONFIG_LISTEN_UDP, CONFIG_LISTEN_UDP_WORKERS, + CONFIG_LISTEN_REUSEPORT, CONFIG_ACCESS_WHITELIST, CONFIG_ACCESS_BLACKLIST, CONFIG_ACCESS_FIFO_ADD, @@ -477,6 +480,7 @@ static const config_key config_keys[] = { CONFIG_KEY("listen.tcp", CONFIG_LISTEN_TCP), CONFIG_KEY("listen.udp", CONFIG_LISTEN_UDP), CONFIG_KEY("listen.udp.workers", CONFIG_LISTEN_UDP_WORKERS), + CONFIG_KEY("listen.reuseport", CONFIG_LISTEN_REUSEPORT), #ifdef WANT_ACCESSLIST_WHITE CONFIG_KEY("access.whitelist", CONFIG_ACCESS_WHITELIST), #elif defined(WANT_ACCESSLIST_BLACK) @@ -582,6 +586,13 @@ int parse_configfile(char *config_filename) { if (scan_udec(p, &value, UINT_MAX)) g_udp_workers = (unsigned int)value; break; + case CONFIG_LISTEN_REUSEPORT: + /* Like listen.udp.workers this is read when a socket is bound, so it + has to come before the listen lines it should apply to. */ + if (!scan_udec(p, &value, 1)) + goto parse_error; + g_socket_reuseport = (int)value; + break; #ifdef WANT_ACCESSLIST_WHITE case CONFIG_ACCESS_WHITELIST: set_config_option(&g_accesslist_filename, p); -- cgit v1.3