Forum Discussion
Greenberg
Nimbostratus
Mar 08, 2012iRule to Limit Connections from Source IP to Destination IP
Guys,
Novice to iRules brings himself before you.
I've been given a requirement to Limit the number of Connections from a number of Source Hosts to a Destination.
This is where I've gotten to:-
bigpipe class 'conn_limit_Pi {
host <> {"<>"}
}'
bigpipe rule '_Pi_throttle_tcp_connections {
when CLIENT_ACCEPT {
set limit [class match [IP:client_addr] equals conn_limit_Pi]
set tbl "connlimit:[IP:client_addr]"
set key "[IP::client_addr][TCP::client_port]"
if { [table keys -subtable $tbl -count] >= $limit } {
reject
} else {
table set -subtable $tbl $key "ignored" <>
}
}
when CLIENT_CLOSED {
table delete -subtable $tbl $key
}'
Unfortunately I am unable to find how to target the Destination. Would another "Class" Statement do the Trick? And if so, how would I introduce this into the iRule to Target the Destination if ir Orginates from the Specific Source.
Thanks in Advance.
Chris.
14 Replies
Sort By
- hoolio
Cirrostratus
Hi Chris,when CLIENT_ACCEPTED { if { not [IP::addr [IP::local_addr] equals 1.1.1.1] }{ return } ...
when CLIENT_ACCEPTED { if { not [class match [IP:local_addr] equals conn_limit_destinations_dg] }{ return } ...
when CLIENT_CLOSED { if {[info exists key]}{ table delete -subtable $tbl $key } }
- Greenberg
Nimbostratus
Hi Aaron,bigpipe rule '_Pi_throttle_tcp_connections { when RULE_INIT { set ::max_connections 100 set static ::active_connections 0 } when HTTP_REQUEST { if {$::active_connections > $::max_connections} then { HTTP::respond 302 Location "Webpage.html" "Connection" "Close" "Cache-Control" "no-cache" "Pragma" "no-cache" TCP::close incr ::active_connections 1 elseif { [HTTP::cookie exists ] } then { persist uie [HTTP::cookie ] } } } when CLIENT_CLOSED { incr ::active_connections -1 }'
- Greenberg
Nimbostratus
Guys,when RULE_INIT { set ::max_connections 100 set static::active_connections 0 } when HTTP_REQUEST { if { not [HTTP::cookie exists ] and $::active_connections > $::max_connections} { HTTP::respond 302 Location "" "Connection" "Close" "Cache-Control" "no-cache" "Pragma" "no-cache" TCP::close } { incr ::active_connections 1 } } when CLIENT_CLOSED { incr ::active_connections -1 }
- hoolio
Cirrostratus
... - hoolio
Cirrostratus
What are you actually trying to accomplish? Do you want to limit the number of connections per client per second (a rate)? Or do you want to limit the number of concurrent connections per client over a time interval? Do you want/need to send an HTTP response if a client makes an HTTP request while over the limit? Do you want to allow clients who already have established a "session" with the virtual server to be able to exceed the limit and track this with a session cookie? - Greenberg
Nimbostratus
Hi Aaron, - hoolio
Cirrostratus
Thanks, that's a bit clearer. Is the app setting the cookie or do you want the iRule to do it? - Greenberg
Nimbostratus
Hi Aaron, - hoolio
Cirrostratus
This might be my last question... :) Is the application built on IIS? If so, it's not very secure to implement HTTP URI based security in iRules as the validation can be bypassed fairly easily: - Greenberg
Nimbostratus
Hi Aaron,
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