Forum Discussion
Ken_Wong_48678
Sep 30, 2005Historic F5 Account
limit client connection
Hi guys,
Is it possible using irule to limit number of connections from each client ip address?
If yes, pls. give me some samples how to do it. Thanks!
Regards,
Ken
- Colin_Walker_12Historic F5 AccountThat's a great question, and one we've seen before.
- Ken_Wong_48678Historic F5 AccountHi Colin,
when RULE_INIT { array set ::active_clients { } log local0. "phase1" } when CLIENT_ACCEPTED { set client_ip [IP::remote_addr] if { [info exists ::active_clients($client_ip)] } { if {$::active_clients($client_ip) > 5 } { log "Client $client_ip has too many connections" reject return } else { log local0. "$::active_clients($client_ip)" incr ::active_clients($client_ip) } } else { set ::active_clients($client_ip) 1 } } when CLIENT_CLOSED { if { [info exists ::active_clients($client_ip)] } { incr ::active_clients($client_ip) -1 if { $::active_clients($client_ip) <= 0 } { unset ::active_clients($client_ip) } } }
- unRuleY_95363Historic F5 AccountI think the problem with your iRule is that after doing the "reject" command, the CLIENT_CLOSED event is still evaluated. So, the active_client count is decremented even though it wasn't incremented by this connection. So, you should move the "incr ::active_client($client_ip)" line to before the check for > 5. That way the current connection will be counted and then decremented after being reset.
- unRuleY_95363Historic F5 AccountAnother way to handle this would be to disable the CLIENT_CLOSED event when you do the reject. You can do this by adding the command "event CLIENT_CLOSED disable" before the "return" where you reject the connection.
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