Forum Discussion
midhun_108442
Nimbostratus
Jan 21, 2012Help need to create a irule for limit Client Connection
Hi,
Can anyone help us to create a irule to limit number of client connection hitting to Virtual server , I got the same irule scenario in Dev central site for (iRule.Limit Connection from Client) , but thats not working with me its only logging the message not blocking the connection ,Kindly anyone help me to provide the irule for the same.
Regards,
Midhun P.K
25 Replies
Sort By
- hoolio
Cirrostratus
Hi Midhun,From http://devcentral.f5.com/wiki/iRules.table.ashx Limit each client IP address to 20 concurrent connections when CLIENT_ACCEPTED { Set a subtable name with a standard prefix and the client IP set tbl "connlimit:[IP::client_addr]" Use a key of the client IP:port set key "[IP::client_addr][TCP::client_port]" Check if the subtable has over 20 entries if { [table keys -subtable $tbl -count] > 20 } { reject } else { Add the client IP:port to the client IP-specific subtable with a max lifetime of 180 seconds table set -subtable $tbl $key "ignored" 180 } } when CLIENT_CLOSED { When the client connection is closed, remove the table entry table delete -subtable $tbl $key }
- midhun_108442
Nimbostratus
- midhun_108442
Nimbostratus
Hi Hoolio, - midhun_108442
Nimbostratus
Hi Hoolio, - hoolio
Cirrostratus
Can you try this version with logging, retest and post the logs?From http://devcentral.f5.com/wiki/iRules.table.ashx Limit each client IP address to 20 concurrent connections when CLIENT_ACCEPTED { Max connections per client IP set limit 20 Set a subtable name with a standard prefix and the client IP set tbl "connlimit:[IP::client_addr]" Use a key of the client IP:port set key "[IP::client_addr][TCP::client_port]" Check if the subtable has over X entries if { [table keys -subtable $tbl -count] > $limit } { log local0. "[IP::client_addr]:[TCP::client_port]: Rejecting connection ([table keys -subtable $tbl -count] connections / limit: $limit)" reject } else { Add the client IP:port to the client IP-specific subtable with a max lifetime of 1800 seconds (30min) table set -subtable $tbl $key "ignored" 1800 log local0. "[IP::client_addr]:[TCP::client_port]: Allowing connection ([table keys -subtable $tbl -count] connections / limit: $limit)" } } when CLIENT_CLOSED { When the client connection is closed, remove the table entry table delete -subtable $tbl $key log local0. "[IP::client_addr]:[TCP::client_port]: Decrementing ([table keys -subtable $tbl -count] connections / limit: $limit)" }
- Thomas_Heloin_3Historic F5 AccountHello,
when CLIENT_ACCEPTED { if { [table incr [IP::client_addr]] > [class match [IP::client_addr] equals conn_limit] } { log local0. "counter: [table lookup [IP::client_addr]]" table incr [IP::client_addr] -1 TCP::close Tested in v11.1 HF1, TMM is not stable when doing TCP::close and table manipulation in CLIENT_CLOSED event This solution appears more stable, no guarantees however. event CLIENT_CLOSED disable } else { log local0. "counter: [table lookup [IP::client_addr]]" } } when CLIENT_CLOSED { table incr [IP::client_addr] -1 log local0. "counter: [table lookup [IP::client_addr]]" }
- midhun_108442
Nimbostratus
Hi Hoolio, - midhun_108442
Nimbostratus
Hi Hoolio, - hoolio
Cirrostratus
If you change > to >= it should work:From http://devcentral.f5.com/wiki/iRules.table.ashx Limit each client IP address to 20 concurrent connections when CLIENT_ACCEPTED { Max connections per client IP set limit 20 Set a subtable name with a standard prefix and the client IP set tbl "connlimit:[IP::client_addr]" Use a key of the client IP:port set key "[IP::client_addr][TCP::client_port]" Check if the subtable has over X entries if { [table keys -subtable $tbl -count] >= $limit } { log local0. "[IP::client_addr]:[TCP::client_port]: Rejecting connection ([table keys -subtable $tbl -count] connections / limit: $limit)" reject } else { Add the client IP:port to the client IP-specific subtable with a max lifetime of 1800 seconds (30min) table set -subtable $tbl $key "ignored" 1800 log local0. "[IP::client_addr]:[TCP::client_port]: Allowing connection ([table keys -subtable $tbl -count] connections / limit: $limit)" } } when CLIENT_CLOSED { When the client connection is closed, remove the table entry table delete -subtable $tbl $key log local0. "[IP::client_addr]:[TCP::client_port]: Decrementing ([table keys -subtable $tbl -count] connections / limit: $limit)" }
- midhun_108442
Nimbostratus
Hi Hoolio,
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