summaryrefslogtreecommitdiff
path: root/ot_udp.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-25 18:51:51 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-25 18:51:51 +0100
commit2c7659ec930277981b6333b5b3aff7840d11933c (patch)
tree1c363ce905ef1a62395f398335a94a47916af278 /ot_udp.c
parent632960a33eb8d23925b2bbef24d5065de7280aef (diff)
Decouple config parsing from binding and worker spawning
* Options are parsed now into a listener description list before binding them at once and starting the workers later * UDP workers can now be configured per connection * socket reuse is now done more sensibly, mcast sockets always reused * Hold-off logic after spawning udp workers removed
Diffstat (limited to 'ot_udp.c')
-rw-r--r--ot_udp.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/ot_udp.c b/ot_udp.c
index dc8267c..7f6517f 100644
--- a/ot_udp.c
+++ b/ot_udp.c
@@ -26,9 +26,6 @@ static uint32_t g_rijndael_round_key[44] = {0};
26static volatile uint32_t g_key_of_the_hour[2] = {0}; 26static volatile uint32_t g_key_of_the_hour[2] = {0};
27static volatile ot_time g_hour_of_the_key; 27static volatile ot_time g_hour_of_the_key;
28 28
29static pthread_mutex_t udp_start_mutex = PTHREAD_MUTEX_INITIALIZER;
30static pthread_cond_t udp_start_cond = PTHREAD_COND_INITIALIZER;
31static int g_opentracker_started = 0;
32 29
33static void udp_generate_rijndael_round_key(void) { 30static void udp_generate_rijndael_round_key(void) {
34 uint32_t key[16]; 31 uint32_t key[16];
@@ -211,11 +208,6 @@ static void *udp_worker(void *args) {
211 ws.debugbuf = malloc(G_DEBUGBUF_SIZE); 208 ws.debugbuf = malloc(G_DEBUGBUF_SIZE);
212#endif 209#endif
213 210
214 pthread_mutex_lock(&udp_start_mutex);
215 while(g_opentracker_running && !g_opentracker_started)
216 pthread_cond_wait(&udp_start_cond, &udp_start_mutex);
217 pthread_mutex_unlock(&udp_start_mutex);
218
219 while (g_opentracker_running) 211 while (g_opentracker_running)
220 handle_udp6(sock, &ws); 212 handle_udp6(sock, &ws);
221 213
@@ -227,20 +219,18 @@ static void *udp_worker(void *args) {
227 return NULL; 219 return NULL;
228} 220}
229 221
230void udp_init(int64_t sock, unsigned int worker_count) { 222void udp_init(void) {
231 pthread_t thread_id;
232 if (!g_rijndael_round_key[0]) 223 if (!g_rijndael_round_key[0])
233 udp_generate_rijndael_round_key(); 224 udp_generate_rijndael_round_key();
225}
226
227void udp_workers_install(int64_t sock, unsigned int worker_count) {
228 pthread_t thread_id;
229
234#ifdef _DEBUG 230#ifdef _DEBUG
235 fprintf(stderr, " installing %d workers on udp socket %ld\n", worker_count, (unsigned long)sock); 231 fprintf(stderr, "Installing %d workers on udp socket %ld\n", worker_count, (unsigned long)sock);
236#endif 232#endif
237 while (worker_count--) 233 while (worker_count--)
238 pthread_create(&thread_id, NULL, udp_worker, (void *)sock); 234 pthread_create(&thread_id, NULL, udp_worker, (void *)sock);
239} 235}
240 236
241void udp_kickoff(void) {
242 pthread_mutex_lock(&udp_start_mutex);
243 g_opentracker_started = 1;
244 pthread_cond_broadcast(&udp_start_cond);
245 pthread_mutex_unlock(&udp_start_mutex);
246}