Dears,
I have got the iRules for session control the HTTP request from customer. However I found that the counter sometimes can’t release after OVER the said limit even the iRules contains “set total_active_clients to 0” in CLIENT_CLOSED. As the iRules is so critical for my client also i am not so professional as you guys in iRules, I would like to seek you guys help for take a look on it? Moreover, any suggestion or modification for this iRules?
**********************************************************when RULE_INIT {
set ::total_active_clients_a 0
set ::max_active_clients_a 10
set ::total_active_clients_b 0
set ::max_active_clients_b 10
}
when HTTP_REQUEST {
switch [HTTP::host] {
abc.com {
log local0. “Access to abc.com”
set site a
incr ::total_active_clients_a
log local0. “total requests are $::total_active_clients_a”
set cur_time_a [clock seconds]
set start_time_a $cur_time_a
if { $cur_time_a == $start_time_a } {
if { $::total_active_clients_a <= $::max_active_clients_a } {
HTTP::redirect “http://www.yahoo.com.hk”
return
}
}
}
xyz.com {
log local0. “Access to xyz.com”
set site b
set cur_time_b [clock seconds]
incr ::total_active_clients_b
log local0. “total requests are $::total_active_clients_b”
set cur_time_b [clock seconds]
set start_time_b $cur_time_b
if { $cur_time_b == $start_time_b } {
if { $::total_active_clients_b >= $::max_active_clients_b } {
HTTP::redirect “http://www.google.com/”
return
}
}
}
}
}
when HTTP_RESPONSE {
log local0. “site is $site”
if { $site == “a” } {
log local0. “site a is true”
set cur_time_for_cookie [clock seconds]
log local0. “cookie value for site a is $cur_time_for_cookie”
set cookie_value_crc [crc32 $cur_time_for_cookie]
log local0. “crc32 is $cookie_value_crc”
HTTP::cookie insert name “site_a_cookie” value “$cookie_value_crc” domain “a.com”
HTTP::cookie encrypt “site_a_cookie” password
HTTP::cookie expires “site_a_cookie” 50000 relative
} elseif { $site == “b” } {
log local0. “site b is true”
set cur_time_for_cookie [clock seconds]
log local0. “cookie value for site b is $cur_time_for_cookie”
set cookie_value_crc [crc32 $cur_time_for_cookie]
log local0. “crc32 is $cookie_value_crc”
HTTP::cookie insert name “site_b_cookie” value “$cur_time_for_cookie” domain “b.com”
HTTP::cookie encrypt “site_b_cookie” password
HTTP::cookie expires “site_b_cookie” 50000 relative
}
}
when CLIENT_CLOSED {
log local0. “site $site request closed”
if { $site == “a” } {
incr ::total_active_clients_a -1
if { $::total_active_clients_a <= 0 } {
set ::total_active_clients_a 0
}
} elseif { $site == “b” } {
incr ::total_active_clients_b -1
if { $::total_active_clients_b <= 0 } {
set ::total_active_clients_b 0
}
}
}
**********************************************************