Forum Discussion
Colin_Walker_12
Apr 08, 2009Historic F5 Account
v.10 Command Interoperability
While performing internal testing on some advanced iRules on the newly released v10 platform, we discovered a couple possible scenarios that users should be aware of. Making use of certain commands: ...
mrintzler
Nimbostratus
Apr 14, 2010I am running into an iRule compatibility issue between 9.4.5/10.0.1HF3 and 10.1.0. I have an array that I am running through with a foreach loop. I'm trying to set two variables to the array index and element for each array row. However, both variables are being set to the index for the first run through, and then the element on the second iteration, etc. It worked fine under 9.4.5 and 10.0.1. Here's the applicable code from the iRule:
Original concept by Deb Allen, F5 Networks
April 2006
when RULE_INIT {
set ::maxRate 3
set ::windowSecs 10
set ::refreshint 1000
set ::totalBMS 0
init array if non-existent
array set ::getHistory ""
wipe array if already existent
log local0. "Array initialized"
array unset ::getHistory
}
when HTTP_REQUEST {
if { [HTTP::method] eq "GET" } {
if { not ([HTTP::cookie exists "_sn"]) } {
Extract clients IP address
set client_ip [IP::remote_addr]
initialize the myMaxRate with global setting
set myMaxRate $::maxRate
set currentTime [clock seconds]
we need to count requests in last $windowSecs seconds, so mark the cutoff time
set windowStart [expr {$currentTime - $::windowSecs}]
if { $::totalBMS > $::refreshint } {
array unset ::getHistory
log local0. "$::refreshint hits reached. Resetting array"
set ::totalBMS 0
}
find GETs for this userID
set getCount 0
count GETs within the window, delete those that are older
foreach { sbrequestID requestTime } [array get ::getHistory ${client_ip}*] {
log local0. "Checking $sbrequestID for time $requestTime"
count GETs with start time > $windowStart, delete the rest
if { $requestTime > $windowStart } {
incr getCount 1
} else {
unset ::getHistory($sbrequestID)
}
}
if { $getCount < $myMaxRate } {
Allow request and add new record to array w/myUserID.rand + currentTime
set sbrequestID "${client_ip}_[expr { int(10000000 * rand()) }]"
log local0. "Setting getHistory with $sbrequestID and $currentTime"
set ::getHistory($sbrequestID) $currentTime
log local0. "Arrary set with [array get ::getHistory]"
} else {
Reject request with 501 server error
log local0. "Possible Abuse - User $client_ip"
HTTP::respond 501
return
}
}
}
}
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects