Forum Discussion
Mike_Pimlott_61
Nimbostratus
Nov 28, 2006Limit connections to node IP after load balancing
Hi
I have been trawling through the examples on the site and seem to have tried everythin to no avail.
I am trying to generate an iRule that will monitor the connections to a NODE after load balancing to limit the number of active connections. the node exists across 2 pools, so if there is a way of getting this information that would be good, otherwise a member based limit would be OK.
My requirement is to limit the connections to an MTA to 20 active sessions, and if an LB decision is made that passes a connection to a "full" member, then I need to to reselect the LB to get access to a different member.
Is there a way of doing this? everything I seem to try to get the conencted member IP I get errors in the log like.
Nov 28 10:23:22 tmm tmm[1754]: 01220001:3: TCL error: Rule IP_Address_mapping - Error: No connection established IP::remote_addr needs an established connection! (line 1) invoked from within "IP::remote_addr"
HELP!!!!
- hoolio
Cirrostratus
Hi, - Mike_Pimlott_61
Nimbostratus
this is fine thanks - it appeared that the connection limit was enforcing an artificial maximum number of connections rather than max concurrent, but it appears this may have been due to the testing software we have been using. although it still marked the members as unavailable due to connection limit (yellow triangle) - hoolio
Cirrostratus
Actually... it looks like there is a bug with iRules and the FastL4 profile: - Mike_64356
Nimbostratus
I am using the iRule which appears at http://devcentral.f5.com/wiki/default.aspx/iRules/LimitConnectionsFromClient.html as follows: - hoolio
Cirrostratus
I think there is a typo in the second Codeshare example. Can you replace 'info exist' with 'info exists' in the rule you're testing? - hoolio
Cirrostratus
I think it would also be more efficient to add the white list clients to a datagroup of the type address and then use matchclass (Click here) to check the client IP against the class. - hoolio
Cirrostratus
Actually, even though the TCL man page doesn't list it, 'info exist variable_name' works.when RULE_INIT { Clear the array of clients with open connections to the VIP array set ::active_clients { } Replace this array with a datagroup once done testing! array set white_client { 10.41.0.610 10.0.0.2 } } when CLIENT_ACCEPTED { log local0. "\$::active_clients: [array get ::active_clients] (size: [array size ::active_clients])" Check if the client is already in the active clients array if { ([info exists ::active_clients([IP::client_addr])]) } { Regardless of whether we reject this client, we've already accepted the TCP connection. so increment the counter for this client. The count will be decremented when the connection is closed. incr ::active_clients([IP::client_addr]) log local0. "Incremented \$::active_clients([IP::client_addr]) to: $::active_clients([IP::client_addr])" Check if client is already over the maximum if {$::active_clients([IP::client_addr]) > 10 } { Send TCP reset to client reject log local0. "Rejected IP [IP::client_addr], count ($::active_clients([IP::client_addr]))" } Don't need an else clause here. The default action will be to allow the connection to continue. } elseif { ![info exists ::white_client([IP::client_addr])] }{ Client wasn't already in the array and isn't in the white list, so add them to the array with a count of 1. set ::active_clients([IP::client_addr]) 1 log local0. "Initialised \$::active_clients([IP::client_addr]) to: 1" } } when CLIENT_CLOSED { Check if the client has a count in the array if { [info exists ::active_clients([IP::client_addr])]} { Decrement the count by 1 incr ::active_clients([IP::client_addr]) -1 Check if the count is 0 or negative if { $::active_clients([IP::client_addr]) <= 0 } { Clear the array element unset ::active_clients([IP::client_addr]) } } }
- Mike_64356
Nimbostratus
Aaron, - hoolio
Cirrostratus
Hi Mike,
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