diff options
Diffstat (limited to 'opentracker.c')
| -rw-r--r-- | opentracker.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/opentracker.c b/opentracker.c index 8a39bde..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" |
| @@ -156,7 +156,7 @@ static ssize_t header_complete(char *request, ssize_t byte_count) { | |||
| 156 | return 0; | 156 | return 0; |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | static void handle_dead(const int64 sock) { | 159 | static void handle_dead(const int64_t sock) { |
| 160 | struct http_data *cookie = io_getcookie(sock); | 160 | struct http_data *cookie = io_getcookie(sock); |
| 161 | if (cookie) { | 161 | if (cookie) { |
| 162 | size_t i; | 162 | size_t i; |
| @@ -171,7 +171,7 @@ static void handle_dead(const int64 sock) { | |||
| 171 | io_close(sock); | 171 | io_close(sock); |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | static void handle_read(const int64 sock, struct ot_workstruct *ws) { | 174 | static void handle_read(const int64_t sock, struct ot_workstruct *ws) { |
| 175 | struct http_data *cookie = io_getcookie(sock); | 175 | struct http_data *cookie = io_getcookie(sock); |
| 176 | ssize_t byte_count = io_tryread(sock, ws->inbuf, G_INBUF_SIZE); | 176 | ssize_t byte_count = io_tryread(sock, ws->inbuf, G_INBUF_SIZE); |
| 177 | 177 | ||
| @@ -215,7 +215,7 @@ static void handle_read(const int64 sock, struct ot_workstruct *ws) { | |||
| 215 | } | 215 | } |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | static void handle_write(const int64 sock) { | 218 | static void handle_write(const int64_t sock) { |
| 219 | struct http_data *cookie = io_getcookie(sock); | 219 | struct http_data *cookie = io_getcookie(sock); |
| 220 | size_t i; | 220 | size_t i; |
| 221 | int chunked = 0; | 221 | int chunked = 0; |
| @@ -227,7 +227,7 @@ static void handle_write(const int64 sock) { | |||
| 227 | 227 | ||
| 228 | for (i = 0; i < cookie->batches; ++i) { | 228 | for (i = 0; i < cookie->batches; ++i) { |
| 229 | if (cookie->batch[i].bytesleft) { | 229 | if (cookie->batch[i].bytesleft) { |
| 230 | int64 res = iob_send(sock, cookie->batch + i); | 230 | int64_t res = iob_send(sock, cookie->batch + i); |
| 231 | 231 | ||
| 232 | if (res == -3) { | 232 | if (res == -3) { |
| 233 | handle_dead(sock); | 233 | handle_dead(sock); |
| @@ -250,14 +250,14 @@ static void handle_write(const int64 sock) { | |||
| 250 | handle_dead(sock); | 250 | handle_dead(sock); |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | static void handle_accept(const int64 serversocket) { | 253 | static void handle_accept(const int64_t serversocket) { |
| 254 | struct http_data *cookie; | 254 | struct http_data *cookie; |
| 255 | int64 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); |
| @@ -305,7 +305,7 @@ static void *server_mainloop(void *args) { | |||
| 305 | random_bytes(ws.rand48_state, sizeof(ws.rand48_state)); | 305 | random_bytes(ws.rand48_state, sizeof(ws.rand48_state)); |
| 306 | 306 | ||
| 307 | for (;;) { | 307 | for (;;) { |
| 308 | int64 sock; | 308 | int64_t sock; |
| 309 | 309 | ||
| 310 | io_wait(); | 310 | io_wait(); |
| 311 | 311 | ||
| @@ -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 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); |
