17#if DETWS_ENABLE_AUTH_LOCKOUT
25 uint32_t lock_start_ms;
40LockoutBucket *find_bucket(LockoutCtx &c,
const DetIp *ip)
48bool bucket_locked(
const LockoutBucket *b, uint32_t now_ms)
51 return b->lock_ms != 0 && (uint32_t)(now_ms - b->lock_start_ms) < b->lock_ms;
56uint32_t auth_lockout_remaining_ms(
const DetIp *ip, uint32_t now_ms)
60 LockoutBucket *b = find_bucket(s_lock, ip);
61 if (!b || b->lock_ms == 0)
63 uint32_t elapsed = now_ms - b->lock_start_ms;
64 if (elapsed >= b->lock_ms)
66 return b->lock_ms - elapsed;
69void auth_lockout_fail(
const DetIp *ip, uint32_t now_ms)
74 LockoutBucket *b = find_bucket(s_lock, ip);
90 if ((uint32_t)(now_ms - s_lock.buckets[i].last_ms) > (uint32_t)(now_ms - s_lock.buckets[lru].last_ms))
92 if (!bucket_locked(&s_lock.buckets[i], now_ms) &&
94 (uint32_t)(now_ms - s_lock.buckets[i].last_ms) > (uint32_t)(now_ms - s_lock.buckets[slot].last_ms)))
99 b = &s_lock.buckets[slot];
103 b->lock_start_ms = now_ms;
107 if (b->fails < 0xFFFF)
129 b->lock_start_ms = now_ms;
133void auth_lockout_succeed(
const DetIp *ip)
137 LockoutBucket *b = find_bucket(s_lock, ip);
143 b->lock_start_ms = 0;
148void auth_lockout_reset(
void)
153 s_lock.buckets[i].lock_start_ms = 0;
154 s_lock.buckets[i].lock_ms = 0;
155 s_lock.buckets[i].last_ms = 0;
156 s_lock.buckets[i].fails = 0;
#define DETWS_AUTH_LOCKOUT_BASE_MS
First lockout duration in ms; doubles on each further failure.
#define DETWS_AUTH_LOCKOUT_THRESHOLD
Consecutive failed auths from one IP before it is locked out.
#define DETWS_AUTH_LOCKOUT_SLOTS
Number of source IPs the auth lockout tracks (BSS bucket table).
#define DETWS_AUTH_LOCKOUT_MAX_MS
Maximum lockout duration in ms (the exponential backoff cap).
Per-peer brute-force lockout for HTTP auth (DETWS_ENABLE_AUTH_LOCKOUT).
bool det_ip_is_unspecified(const DetIp *ip)
True if ip is empty (DetIpFamily::DET_IP_NONE) or the all-zero unspecified address (0....
bool det_ip_equal(const DetIp *a, const DetIp *b)
True if a and b are the same family and address.
@ DET_IP_NONE
empty / unparsed
A v4 or v6 address in network (big-endian) byte order.