1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-06-12 17:14:46 +02:00

Suppress high rate events via set::log-throttle (similar to Linux kernel)

And ship with these by default (no need to copy this set block):

set {
	log-throttle {
		CONNTHROTTLE_IPV6_LIMIT 100:60;
		MAXPERIP_LIMIT 100:60;
	};
};

You can do the same for other events, or even override existing ones,
and use the special value "unlimited" to turn default set ratelimits off:

set {
	log-throttle {
		CONNTHROTTLE_IPV6_LIMIT 50:60;
		MAXPERIP_LIMIT unlimited;
	};
};

Suggested in 2020 at https://bugs.unrealircd.org/view.php?id=5523
(and keeping it simple)
This commit is contained in:
Bram Matthys
2026-05-05 18:59:50 +02:00
parent f765905b15
commit e5be93a9f8
5 changed files with 318 additions and 4 deletions
+10
View File
@@ -32,6 +32,15 @@ struct FloodSettings {
long period[MAXFLOODOPTIONS];
};
typedef struct LogThrottleConfig LogThrottleConfig;
struct LogThrottleConfig {
LogThrottleConfig *prev, *next;
char *event_id; /**< the event_id this policy applies to */
int threshold; /**< per-window cap */
int period; /**< window length in seconds */
int unlimited; /**< if set, never throttle */
};
enum UHAllowed { UHALLOW_ALWAYS, UHALLOW_NOCHANS, UHALLOW_REJOIN, UHALLOW_NEVER };
struct ChMode {
@@ -114,6 +123,7 @@ struct Configuration {
int modes_on_join_set;
char *level_on_join;
FloodSettings *floodsettings;
LogThrottleConfig *log_throttle;
int ident_connect_timeout;
int ident_read_timeout;
long default_bantime;
+29 -4
View File
@@ -1422,11 +1422,29 @@ extern const char *log_type_valtostring(LogType v);
* parameters explicitly, put log_data_source() at the beginning of the argument list
* and then use non-portable ## __VA_ARGS__ for the remainder.
*/
#define unreal_log(...) do { LogData *lds = log_data_source(__FILE__, __LINE__, __FUNCTION__); do_unreal_log(__VA_ARGS__, lds, NULL); log_data_free(lds); } while(0)
#define unreal_log_raw(...) do { LogData *lds = log_data_source(__FILE__, __LINE__, __FUNCTION__); do_unreal_log_raw(__VA_ARGS__, lds, NULL); log_data_free(lds); } while(0)
#define unreal_log(level, sys, id, ...) do { \
if (!log_throttled((sys), (id))) { \
LogData *lds = log_data_source(__FILE__, __LINE__, __FUNCTION__); \
do_unreal_log((level), (sys), (id), __VA_ARGS__, lds, NULL); \
log_data_free(lds); \
} \
} while(0)
#define unreal_log_raw(level, sys, id, ...) do { \
if (!log_throttled((sys), (id))) { \
LogData *lds = log_data_source(__FILE__, __LINE__, __FUNCTION__); \
do_unreal_log_raw((level), (sys), (id), __VA_ARGS__, lds, NULL); \
log_data_free(lds); \
} \
} while(0)
#else
#define unreal_log(...) do_unreal_log(__VA_ARGS__, NULL)
#define unreal_log_raw(...) do_unreal_log_raw(__VA_ARGS__, NULL)
#define unreal_log(level, sys, id, ...) do { \
if (!log_throttled((sys), (id))) \
do_unreal_log((level), (sys), (id), __VA_ARGS__, NULL); \
} while(0)
#define unreal_log_raw(level, sys, id, ...) do { \
if (!log_throttled((sys), (id))) \
do_unreal_log_raw((level), (sys), (id), __VA_ARGS__, NULL); \
} while(0)
#endif
extern void do_unreal_log(LogLevel loglevel, const char *subsystem, const char *event_id, Client *client, const char *msg, ...) __attribute__((format(printf,5,0)));
extern void do_unreal_log_raw(LogLevel loglevel, const char *subsystem, const char *event_id, Client *client, const char *msg, ...);
@@ -1448,6 +1466,13 @@ extern void log_pre_rehash(void);
extern int log_tests(void);
extern void config_pre_run_log(void);
extern void log_blocks_switchover(void);
extern void log_throttle_init(void);
extern int log_throttled(const char *subsystem, const char *event_id);
extern void log_throttle_rehash(void);
extern void free_log_throttle_config(LogThrottleConfig *c);
extern LogThrottleConfig *find_log_throttle_config(LogThrottleConfig *list, const char *event_id);
extern void add_log_throttle_config(LogThrottleConfig **list, const char *event_id, int threshold, int period, int unlimited);
extern EVENT(log_throttle_flush);
extern void postconf_defaults_log_block(void);
extern int valid_loglevel(int v);
extern LogLevel log_level_stringtoval(const char *str);