unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
connect-flood.c (2168B)
1 /* 2 * Connection throttling (set::anti-flood::connect-flood) 3 * (C) Copyright 2022- Bram Matthys and the UnrealIRCd team. 4 * License: GPLv2 or later 5 */ 6 7 #include "unrealircd.h" 8 9 ModuleHeader MOD_HEADER 10 = { 11 "connect-flood", 12 "6.0.0", 13 "set::anti-flood::connect-flood", 14 "UnrealIRCd Team", 15 "unrealircd-6", 16 }; 17 18 /* Forward declaration */ 19 int connect_flood_accept(Client *client); 20 int connect_flood_ip_change(Client *client, const char *oldip); 21 22 MOD_INIT() 23 { 24 MARK_AS_OFFICIAL_MODULE(modinfo); 25 26 HookAdd(modinfo->handle, HOOKTYPE_ACCEPT, -3000, connect_flood_accept); 27 HookAdd(modinfo->handle, HOOKTYPE_IP_CHANGE, -3000, connect_flood_ip_change); 28 29 return MOD_SUCCESS; 30 } 31 32 MOD_LOAD() 33 { 34 return MOD_SUCCESS; 35 } 36 37 MOD_UNLOAD() 38 { 39 return MOD_SUCCESS; 40 } 41 42 int connect_flood_throttle(Client *client, int exitflags) 43 { 44 int val; 45 char zlinebuf[512]; 46 47 if (!(val = throttle_can_connect(client))) 48 { 49 if (exitflags & NO_EXIT_CLIENT) 50 { 51 ircsnprintf(zlinebuf, sizeof(zlinebuf), 52 "ERROR :Closing Link: [%s] (Throttled: Reconnecting too fast) - " 53 "Email %s for more information.\r\n", 54 client->ip, KLINE_ADDRESS); 55 (void)send(client->local->fd, zlinebuf, strlen(zlinebuf), 0); 56 return HOOK_DENY; 57 } else { 58 ircsnprintf(zlinebuf, sizeof(zlinebuf), 59 "Throttled: Reconnecting too fast - " 60 "Email %s for more information.", 61 KLINE_ADDRESS); 62 /* WAS: exit_client(client, NULL, zlinebuf); 63 * Can't use exit_client() here because HOOKTYPE_IP_CHANGE call 64 * may be too deep. Eg: read_packet -> webserver_packet_in -> 65 * webserver_handle_request_header -> webserver_handle_request -> 66 * RunHook().... and then returning without touching anything 67 * after an exit_client() would not be feasible. 68 */ 69 dead_socket(client, zlinebuf); 70 return HOOK_DENY; 71 } 72 } 73 else if (val == 1) 74 add_throttling_bucket(client); 75 76 return 0; 77 } 78 79 int connect_flood_accept(Client *client) 80 { 81 if (client->local->listener->options & LISTENER_NO_CHECK_CONNECT_FLOOD) 82 return 0; 83 return connect_flood_throttle(client, NO_EXIT_CLIENT); 84 } 85 86 int connect_flood_ip_change(Client *client, const char *oldip) 87 { 88 return connect_flood_throttle(client, 0); 89 }