summaryrefslogtreecommitdiff
path: root/ot_config.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-31 00:30:09 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-31 00:30:09 +0100
commite9445a41e5cbb4f1a1091302efdf3e80d0d70c7f (patch)
treef2229d101a618f5d6747aa339f0d32bdc0191479 /ot_config.c
parent15f9f81b5a8398fefca023e90d8d1c168ecef620 (diff)
Add config parsers for multiple tcp socket readers and a helper to see if we can offer it on the platform
Diffstat (limited to 'ot_config.c')
-rw-r--r--ot_config.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/ot_config.c b/ot_config.c
index a0dbef1..272acf1 100644
--- a/ot_config.c
+++ b/ot_config.c
@@ -14,6 +14,7 @@
14 14
15/* Opentracker */ 15/* Opentracker */
16#include "ot_accesslist.h" 16#include "ot_accesslist.h"
17#include "ot_event.h"
17#include "ot_config.h" 18#include "ot_config.h"
18#include "ot_http.h" 19#include "ot_http.h"
19#include "ot_ip.h" 20#include "ot_ip.h"
@@ -32,7 +33,8 @@ const char *g_statefile;
32static ot_listen *g_listen; 33static ot_listen *g_listen;
33static size_t g_listen_count; 34static size_t g_listen_count;
34static int g_listen_shared; 35static int g_listen_shared;
35static int g_listen_workers = 1; 36static int g_listen_workers_udp = 1;
37static int g_listen_workers_tcp = 0;
36 38
37static void panic(const char *routine) __attribute__((noreturn)); 39static void panic(const char *routine) __attribute__((noreturn));
38static void panic(const char *routine) { 40static void panic(const char *routine) {
@@ -196,6 +198,7 @@ typedef enum {
196 CONFIG_LISTEN_TCP, 198 CONFIG_LISTEN_TCP,
197 CONFIG_LISTEN_UDP, 199 CONFIG_LISTEN_UDP,
198 CONFIG_LISTEN_UDP_WORKERS, 200 CONFIG_LISTEN_UDP_WORKERS,
201 CONFIG_LISTEN_TCP_WORKERS,
199 CONFIG_LISTEN_SHARED, 202 CONFIG_LISTEN_SHARED,
200 CONFIG_ACCESS_WHITELIST, 203 CONFIG_ACCESS_WHITELIST,
201 CONFIG_ACCESS_BLACKLIST, 204 CONFIG_ACCESS_BLACKLIST,
@@ -224,6 +227,7 @@ static const config_key config_keys[] = {
224 CONFIG_KEY("listen.tcp", CONFIG_LISTEN_TCP), 227 CONFIG_KEY("listen.tcp", CONFIG_LISTEN_TCP),
225 CONFIG_KEY("listen.udp", CONFIG_LISTEN_UDP), 228 CONFIG_KEY("listen.udp", CONFIG_LISTEN_UDP),
226 CONFIG_KEY("listen.udp.workers", CONFIG_LISTEN_UDP_WORKERS), 229 CONFIG_KEY("listen.udp.workers", CONFIG_LISTEN_UDP_WORKERS),
230 CONFIG_KEY("listen.tcp.workers", CONFIG_LISTEN_TCP_WORKERS),
227 CONFIG_KEY("listen.shared", CONFIG_LISTEN_SHARED), 231 CONFIG_KEY("listen.shared", CONFIG_LISTEN_SHARED),
228#ifdef WANT_ACCESSLIST_WHITE 232#ifdef WANT_ACCESSLIST_WHITE
229 CONFIG_KEY("access.whitelist", CONFIG_ACCESS_WHITELIST), 233 CONFIG_KEY("access.whitelist", CONFIG_ACCESS_WHITELIST),
@@ -318,7 +322,7 @@ static int parse_configfile(char *config_filename) {
318 if (!off || !listen_scan_options(p + off, &shared, &workers)) 322 if (!off || !listen_scan_options(p + off, &shared, &workers))
319 goto parse_error; 323 goto parse_error;
320 if (kind != CONFIG_LISTEN_UDP) 324 if (kind != CONFIG_LISTEN_UDP)
321 listen_append(tmpip, tmpport, FLAG_TCP, shared, OT_LISTEN_INHERIT), ++bound; 325 listen_append(tmpip, tmpport, FLAG_TCP, shared, workers), ++bound;
322 if (kind != CONFIG_LISTEN_TCP) 326 if (kind != CONFIG_LISTEN_TCP)
323 listen_append(tmpip, tmpport, FLAG_UDP, shared, workers), ++bound; 327 listen_append(tmpip, tmpport, FLAG_UDP, shared, workers), ++bound;
324 break; 328 break;
@@ -326,7 +330,12 @@ static int parse_configfile(char *config_filename) {
326 case CONFIG_LISTEN_UDP_WORKERS: 330 case CONFIG_LISTEN_UDP_WORKERS:
327 if (!scan_uint(p, &value, UINT_MAX)) 331 if (!scan_uint(p, &value, UINT_MAX))
328 goto parse_error; 332 goto parse_error;
329 g_listen_workers = (int)value; 333 g_listen_workers_udp = (int)value;
334 break;
335 case CONFIG_LISTEN_TCP_WORKERS:
336 if (!scan_uint(p, &value, UINT_MAX))
337 goto parse_error;
338 g_listen_workers_tcp = (int)value;
330 break; 339 break;
331 case CONFIG_LISTEN_SHARED: 340 case CONFIG_LISTEN_SHARED:
332 if (!scan_uint(p, &value, 1)) 341 if (!scan_uint(p, &value, 1))
@@ -446,7 +455,16 @@ static void listen_resolve_defaults(void) {
446 if (entry->shared == OT_LISTEN_INHERIT) 455 if (entry->shared == OT_LISTEN_INHERIT)
447 entry->shared = g_listen_shared; 456 entry->shared = g_listen_shared;
448 if (entry->workers == OT_LISTEN_INHERIT) 457 if (entry->workers == OT_LISTEN_INHERIT)
449 entry->workers = g_listen_workers; 458 entry->workers = entry->proto == FLAG_TCP ? g_listen_workers_tcp : g_listen_workers_udp;
459
460 /* A tcp worker hands a connection it cannot finish to the event loop,
461 which only one thread may touch where the set is ours rather than the
462 kernel's */
463 if (entry->proto == FLAG_TCP && entry->workers > 1 && !event_can_share()) {
464 fprintf(stderr, "Warning: Multiple workers impossible on this platform with event mechanism %s chosen.\n",
465 event_mechanism());
466 entry->workers = 1;
467 }
450 } 468 }
451} 469}
452 470