Forum Discussion
Jack_H_39707
Nimbostratus
Apr 30, 2010Is there an IRules to control active connections?
Dear all, I am very new to F5 and would really appreciate if any of the members here could help me.
Is there an IRules which allow F5 to control the active connections? Meaning, If I allowed 20 c...
The_Bhattman
Nimbostratus
Apr 30, 2010You are right.
Here is another code that might work, it works based on cookies.
rule session_limit {
when RULE_INIT {
array set ::active_sessions { }
set ::total_active_clients 0
set ::max_active_clients 20
}
when HTTP_REQUEST {
if { not [info exists client_id] } {
if { [HTTP::cookie exists "ClientID"] } {
set client_id [HTTP::cookie "ClientID"]
set need_cookie 0
} else {
set client_id [string range [AES::key 128] 8 end]
set need_cookie 1
}
if { not [info exists ::active_sessions($client_id)] } {
if { $::total_active_clients >= $::max_active_clients } {
HTTP::redirect "http://mydomain.com/error.page"
return
}
incr ::total_active_clients
set ::active_sessions($client_id) 1
} else {
incr ::active_sessions($client_id)
}
}
}
when HTTP_RESPONSE {
if { $need_cookie } {
HTTP::cookie insert name "ClientID" value $client_id
set need_cookie 0
}
}
when CLIENT_CLOSED {
if { [info exists client_id] and [info exists ::active_sessions($client_id)] } {
incr ::active_sessions($client_id) -1
if { $::active_sessions($client_id) <= 0 } {
unset ::active_sessions($client_id)
incr ::total_active_clients -1
}
}
}
}
Bhattman
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
