Forum Discussion
iRule - Sliding window
Dears,
I'm trying to include a sliding window of time to counting requests. (e.g. if I have 8 req in 60 sec, block for 600 sec.)
So, I did change ($static::timeout $static::timeout) to ($static::timeout $static::winsec) and include (set static::winsec 60). But, didn't work. Have I missed something here ?
Here a working iRule that I'm using to block more than 8 reqs:
when HTTP_REQUEST {
if { [HTTP::uri] ends_with "/URI" and [HTTP::method] eq "POST"}{
set static::maxRate 8
set static::timeout 600
set client_IP_addr [IP::client_addr]
set getcount [table lookup -notouch "$client_IP_addr:[HTTP::uri]"]
if { $getcount equals "" } {
table set "$client_IP_addr:[HTTP::uri]" "1" $static::timeout $static::timeout
} else {
if { $getcount < $static::maxRate } {
table incr -notouch "$client_IP_addr:[HTTP::uri]"
} else {
log -noname local0. "REQUEST Rejected: current requestCount for $client_IP_addr"
reject
}
}
}
}
Cheers, Bruno
- Kevin_Davies_40
Nacreous
Try the following..
when HTTP_REQUEST { create a unique entry for each request that will expire in 60 seconds table set -subtable "[IP::client_addr]:[HTTP::uri]" [TMM::cmp_unit][clock clicks] 0 60 if {[table keys -subtable "[IP::client_addr]:[HTTP::uri]" -count] > 8} { log -noname local0. "REQUEST Rejected: current request for $client_IP_addr" reject } }
- Stanislas_Piro2
Cumulonimbus
Hi,
don't change static variables in HTTP_REQUEST event... static variables are variables shared by all TMM
static variables may be set in RULE_INIT (when irule is loaded : restart of appliance or code change)
when RULE_INIT { set static::maxRate 8 set static::timeout 600 }
then use the variable in HTTP_REQUEST.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com