summaryrefslogtreecommitdiffstats
path: root/log.h
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2024-12-07 11:05:36 +0100
committerDamien Miller <djm@mindrot.org>2024-12-07 11:22:56 +0100
commit5a6ddf946cf105189c2c99a04f86ce95edc55fc5 (patch)
treec210c21fd0439504b7c194c77f821e563e738b2f /log.h
parentupstream: allow glob(3) patterns for sshd_config AuthorizedKeysFile (diff)
downloadopenssh-5a6ddf946cf105189c2c99a04f86ce95edc55fc5.tar.xz
openssh-5a6ddf946cf105189c2c99a04f86ce95edc55fc5.zip
upstream: add infrastructure for ratelimited logging; feedback/ok
dtucker OpenBSD-Commit-ID: 18a83e5ac09d59aaf1e834fd6b796db89dd842e7
Diffstat (limited to 'log.h')
-rw-r--r--log.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/log.h b/log.h
index 8fe350b76..8e8dfc23f 100644
--- a/log.h
+++ b/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.34 2024/06/27 22:36:44 djm Exp $ */
+/* $OpenBSD: log.h,v 1.35 2024/12/07 10:05:37 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -81,6 +81,30 @@ void sshfatal(const char *, const char *, int, int,
void sshlogdirect(LogLevel, int, const char *, ...)
__attribute__((format(printf, 3, 4)));
+struct log_ratelimit_ctx {
+ /* configuration */
+ u_int threshold; /* events per second */
+ u_int max_accum; /* max events to accumulate */
+ u_int hysteresis; /* seconds */
+ u_int log_every; /* seconds */
+
+ /* state */
+ time_t last_event;
+ u_int accumulated_events; /* used for threshold comparisons */
+
+ /* state while actively rate-limiting */
+ int ratelimit_active;
+ time_t ratelimit_start;
+ time_t last_log;
+ time_t hysteresis_start;
+ u_int ratelimited_events;
+};
+
+void log_ratelimit_init(struct log_ratelimit_ctx *rl, u_int threshold,
+ u_int max_accum, u_int hysteresis, u_int log_every);
+int log_ratelimit(struct log_ratelimit_ctx *rl, time_t now, int *active,
+ u_int *events_dropped);
+
#define do_log2(level, ...) sshlog(__FILE__, __func__, __LINE__, 0, level, NULL, __VA_ARGS__)
#define debug3(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_DEBUG3, NULL, __VA_ARGS__)
#define debug2(...) sshlog(__FILE__, __func__, __LINE__, 0, SYSLOG_LEVEL_DEBUG2, NULL, __VA_ARGS__)