pub struct IpsetDdosProtection { /* private fields */ }Expand description
Production DDoS protection backed by Linux ipset.
Per-IP scores use linear time decay: each allow_request adds 1.0 point,
each report_bad_request adds bad_request_penalty points, and the score
drains at decay_per_second points/second. This means sustained low-rate
traffic stabilises below the threshold while bursts trigger quickly.
When a score first crosses score_threshold, the IP is added to the named
ipset via ipset add <set_name> <ip> --exist. A second 10-second moka cache
(ipset_throttle) prevents hammering the ipset command.
try_acquire_connection additionally enforces a per-IP connection cap
(max_connections_per_ip).
Implementations§
Trait Implementations§
Source§impl DdosProtection for IpsetDdosProtection
impl DdosProtection for IpsetDdosProtection
Source§fn allow_request(&self, ip: &str) -> bool
fn allow_request(&self, ip: &str) -> bool
Returns
true if the request from ip should be processed, false if it should be
dropped immediately.Source§fn report_bad_request(&self, ip: &str)
fn report_bad_request(&self, ip: &str)
Notify the implementation that a request from
ip was rejected. Implementations
should use this to accumulate evidence and eventually ban repeat offenders.Source§fn try_acquire_connection(&self, ip: &str) -> bool
fn try_acquire_connection(&self, ip: &str) -> bool
Try to acquire a connection slot for
ip, checking both the ban score and the
per-IP connection cap. Returns true and increments the connection count on
success. Returns false if the IP is blocked or over the per-IP cap. Read moreSource§fn release_connection(&self, ip: &str)
fn release_connection(&self, ip: &str)
Release a connection slot previously acquired by
try_acquire_connection.
Called automatically by DdosConnectionGuard::drop.Auto Trait Implementations§
impl !Freeze for IpsetDdosProtection
impl !RefUnwindSafe for IpsetDdosProtection
impl Send for IpsetDdosProtection
impl Sync for IpsetDdosProtection
impl Unpin for IpsetDdosProtection
impl UnsafeUnpin for IpsetDdosProtection
impl !UnwindSafe for IpsetDdosProtection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more