Need Help with Rate Limiting SMTP iRule
I am writing an iRule. Simply one to rate limit a group of users to 1 session per minute. I am able to compile my script iRule editor, but when I run it, I get the following error:
Oct 6 18:34:16 Test-F5 25150]: 01220001:3: TCL error: /Common/SMTP_Rate_v6 - invalid command name "1" while executing "[class match [IP::client_addr] equals SMTP_OFFENDERS]"
Here is my script bellow.. I appreciate it I someone can see what I'm doing wrong.
when RULE_INIT {
Messages in 1 minuteset static::holdtime 60
Number of messages per 1 minuteset static::smtp_msg_per_period 1
Checking the TMM and CPUsset static::smtp_rate_limiter_debug 0 if {([TMM::cmp_group]==0) and ([TMM::cmp_unit]==0)} { if {$static::smtp_rate_limiter_debug} {log local0. "-"} } } when CLIENT_ACCEPTED { set mcount [table lookup [IP::client_addr]] log local0. "Step0: Before" TCP::collect if { [[class match [IP::client_addr] equals SMTP_OFFENDERS]]} { log local0. "Step0: After If" if { [table timeout[-remaining] $key $mcount >= $holdtime] and [$smtp_msg_per_period > 1 ] } { TCP::payload replace 0 [TCP::payload length] "" TCP::respond "450 Temporarily blocked by Load Balancer. Exceeding Rate. \r\n" log local0. "Step1: message count: $mcount" } else { set mcount [table incr [IP::client_addr]] TCP::respond "220 $static::smtp_220_text\r\n" TCP::collect {log local0. "Step2: message count: $mcount"} return } } }
when SERVER_CONNECTED {
TCP::collect -all
}
when SERVER_DATA { if {[TCP::payload] starts_with "220"} { TCP::payload replace 0 [TCP::payload length] "" } if {[TCP::payload] starts_with "\r\n354"} { TCP::payload replace 0 [TCP::payload length] "354\r\n" } TCP::release TCP::collect }