X-Git-Url: https://git.librecmc.org/?p=oweals%2Ftinc.git;a=blobdiff_plain;f=src%2Fnet_socket.c;h=6195c16c74550b084cc1fa7097b11390bf347f79;hp=3467804eec16f00bd995d439adb493feb620a92e;hb=d3297fbd3b8c8c8a4661f5bbf89aca5cacba8b5a;hpb=96e33d749cd61dd5f103ffef2e5e833f30185787 diff --git a/src/net_socket.c b/src/net_socket.c index 3467804..6195c16 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -639,6 +639,9 @@ void setup_outgoing_connection(outgoing_t *outgoing) { new connection */ bool handle_new_meta_connection(int sock) { + static const int max_accept_burst = 10; + static int last_accept_burst; + static int last_accept_time; connection_t *c; sockaddr_t sa; int fd; @@ -651,6 +654,22 @@ bool handle_new_meta_connection(int sock) { return false; } + if(last_accept_time == now) { + last_accept_burst++; + + if(last_accept_burst >= max_accept_burst) { + if(last_accept_burst == max_accept_burst) { + ifdebug(CONNECTIONS) logger(LOG_WARNING, "Throttling incoming connections"); + } + + tarpit(fd); + return false; + } + } else { + last_accept_burst = 0; + last_accept_time = now; + } + sockaddrunmap(&sa); c = new_connection(); @@ -672,7 +691,6 @@ bool handle_new_meta_connection(int sock) { connection_add(c); c->allow_request = ID; - send_id(c); return true; }