diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-25 02:43:09 +0200 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-25 02:43:09 +0200 |
| commit | 4afeaeb4b6ab6c56e582436b17f367e216f16de1 (patch) | |
| tree | b9b958494436556274132a87db3ab79cf62722e7 /opentracker.c | |
| parent | 7af7598086e5a3f9a75507cd6f9907a98faf3d9d (diff) | |
Use the new ot_socket abstraction for socket creation, read and write
Diffstat (limited to 'opentracker.c')
| -rw-r--r-- | opentracker.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/opentracker.c b/opentracker.c index af336aa..5b197d1 100644 --- a/opentracker.c +++ b/opentracker.c | |||
| @@ -24,7 +24,6 @@ | |||
| 24 | /* Libowfat */ | 24 | /* Libowfat */ |
| 25 | #include "io.h" | 25 | #include "io.h" |
| 26 | #include "iob.h" | 26 | #include "iob.h" |
| 27 | #include "socket.h" | ||
| 28 | 27 | ||
| 29 | /* Opentracker */ | 28 | /* Opentracker */ |
| 30 | #include "ot_accesslist.h" | 29 | #include "ot_accesslist.h" |
| @@ -35,6 +34,7 @@ | |||
| 35 | #include "ot_mutex.h" | 34 | #include "ot_mutex.h" |
| 36 | #include "ot_random.h" | 35 | #include "ot_random.h" |
| 37 | #include "ot_scan.h" | 36 | #include "ot_scan.h" |
| 37 | #include "ot_socket.h" | ||
| 38 | #include "ot_stats.h" | 38 | #include "ot_stats.h" |
| 39 | #include "ot_udp.h" | 39 | #include "ot_udp.h" |
| 40 | #include "trackerlogic.h" | 40 | #include "trackerlogic.h" |
| @@ -254,10 +254,10 @@ static void handle_accept(const int64_t serversocket) { | |||
| 254 | struct http_data *cookie; | 254 | struct http_data *cookie; |
| 255 | int64_t sock; | 255 | int64_t sock; |
| 256 | ot_ip6 ip; | 256 | ot_ip6 ip; |
| 257 | uint16 port; | 257 | uint16_t port; |
| 258 | tai6464 t; | 258 | tai6464 t; |
| 259 | 259 | ||
| 260 | while ((sock = socket_accept6(serversocket, ip, &port, NULL)) != -1) { | 260 | while ((sock = socket_accept(serversocket, ip, &port)) != -1) { |
| 261 | 261 | ||
| 262 | /* Put fd into a non-blocking mode */ | 262 | /* Put fd into a non-blocking mode */ |
| 263 | io_nonblock(sock); | 263 | io_nonblock(sock); |
| @@ -339,7 +339,7 @@ static void *server_mainloop(void *args) { | |||
| 339 | } | 339 | } |
| 340 | 340 | ||
| 341 | static int64_t ot_try_bind(ot_ip6 ip, uint16_t port, PROTO_FLAG proto) { | 341 | static int64_t ot_try_bind(ot_ip6 ip, uint16_t port, PROTO_FLAG proto) { |
| 342 | int64_t sock = proto == FLAG_TCP ? socket_tcp6() : socket_udp6(); | 342 | int64_t sock; |
| 343 | 343 | ||
| 344 | #ifdef _DEBUG | 344 | #ifdef _DEBUG |
| 345 | { | 345 | { |
| @@ -352,11 +352,13 @@ static int64_t ot_try_bind(ot_ip6 ip, uint16_t port, PROTO_FLAG proto) { | |||
| 352 | } | 352 | } |
| 353 | #endif | 353 | #endif |
| 354 | 354 | ||
| 355 | if (socket_bind6_reuse(sock, ip, port, 0) == -1) | 355 | if (proto == FLAG_TCP) { |
| 356 | panic("socket_bind6_reuse"); | 356 | if ((sock = socket_tcp_listen(ip, port)) == -1) |
| 357 | 357 | panic("socket_tcp_listen"); | |
| 358 | if ((proto == FLAG_TCP) && (socket_listen(sock, SOMAXCONN) == -1)) | 358 | } else { |
| 359 | panic("socket_listen"); | 359 | if ((sock = socket_udp_bind(ip, port)) == -1) |
| 360 | panic("socket_udp_bind"); | ||
| 361 | } | ||
| 360 | 362 | ||
| 361 | if (!io_fd(sock)) | 363 | if (!io_fd(sock)) |
| 362 | panic("io_fd"); | 364 | panic("io_fd"); |
| @@ -450,6 +452,7 @@ typedef enum { | |||
| 450 | CONFIG_LISTEN_TCP, | 452 | CONFIG_LISTEN_TCP, |
| 451 | CONFIG_LISTEN_UDP, | 453 | CONFIG_LISTEN_UDP, |
| 452 | CONFIG_LISTEN_UDP_WORKERS, | 454 | CONFIG_LISTEN_UDP_WORKERS, |
| 455 | CONFIG_LISTEN_REUSEPORT, | ||
| 453 | CONFIG_ACCESS_WHITELIST, | 456 | CONFIG_ACCESS_WHITELIST, |
| 454 | CONFIG_ACCESS_BLACKLIST, | 457 | CONFIG_ACCESS_BLACKLIST, |
| 455 | CONFIG_ACCESS_FIFO_ADD, | 458 | CONFIG_ACCESS_FIFO_ADD, |
| @@ -477,6 +480,7 @@ static const config_key config_keys[] = { | |||
| 477 | CONFIG_KEY("listen.tcp", CONFIG_LISTEN_TCP), | 480 | CONFIG_KEY("listen.tcp", CONFIG_LISTEN_TCP), |
| 478 | CONFIG_KEY("listen.udp", CONFIG_LISTEN_UDP), | 481 | CONFIG_KEY("listen.udp", CONFIG_LISTEN_UDP), |
| 479 | CONFIG_KEY("listen.udp.workers", CONFIG_LISTEN_UDP_WORKERS), | 482 | CONFIG_KEY("listen.udp.workers", CONFIG_LISTEN_UDP_WORKERS), |
| 483 | CONFIG_KEY("listen.reuseport", CONFIG_LISTEN_REUSEPORT), | ||
| 480 | #ifdef WANT_ACCESSLIST_WHITE | 484 | #ifdef WANT_ACCESSLIST_WHITE |
| 481 | CONFIG_KEY("access.whitelist", CONFIG_ACCESS_WHITELIST), | 485 | CONFIG_KEY("access.whitelist", CONFIG_ACCESS_WHITELIST), |
| 482 | #elif defined(WANT_ACCESSLIST_BLACK) | 486 | #elif defined(WANT_ACCESSLIST_BLACK) |
| @@ -582,6 +586,13 @@ int parse_configfile(char *config_filename) { | |||
| 582 | if (scan_udec(p, &value, UINT_MAX)) | 586 | if (scan_udec(p, &value, UINT_MAX)) |
| 583 | g_udp_workers = (unsigned int)value; | 587 | g_udp_workers = (unsigned int)value; |
| 584 | break; | 588 | break; |
| 589 | case CONFIG_LISTEN_REUSEPORT: | ||
| 590 | /* Like listen.udp.workers this is read when a socket is bound, so it | ||
| 591 | has to come before the listen lines it should apply to. */ | ||
| 592 | if (!scan_udec(p, &value, 1)) | ||
| 593 | goto parse_error; | ||
| 594 | g_socket_reuseport = (int)value; | ||
| 595 | break; | ||
| 585 | #ifdef WANT_ACCESSLIST_WHITE | 596 | #ifdef WANT_ACCESSLIST_WHITE |
| 586 | case CONFIG_ACCESS_WHITELIST: | 597 | case CONFIG_ACCESS_WHITELIST: |
| 587 | set_config_option(&g_accesslist_filename, p); | 598 | set_config_option(&g_accesslist_filename, p); |
