Forum Discussion

Jayou's avatar
Jayou
Icon for Nimbostratus rankNimbostratus
Sep 24, 2019

Irule to limit connections

Hi all,

 

Hope someone can help. I am attempting to use the below irule to limit the number of connections on a virtual server in order to provide a comment to the user when they are blocked.

 

Unfortunately it does seem to be hit but does not limit the connections. This is mostly new to me and although it appears to read correctly obviously doesn't work.

 

 

when RULE_INIT {

set ::active_connections 0

set ::max_connections 10

set ::html_content "Too Many Users - please try later"

 

}

when HTTP_REQUEST {

set over_limit 0

if {$::active_connections > $::max_connections } {

set over_limit 1

} else {

incr ::active_connections 1

}

if {$over_limit == 1}{

#Send a response

HTTP::respond 404 content $::html_content

#Close the connection

TCP::close

}

log local0. "Over limit (current/max: $::active_connections/$::max_connections). Sent response to [IP::client_addr]"

}

when CLIENT_CLOSED {

#A connection was closed, so decrement the global counter

incr ::active_connections -1

}

 

Thanks for any assistance anyone can give

No RepliesBe the first to reply