Forum Discussion

Abdul_1034's avatar
Abdul_1034
Icon for Nimbostratus rankNimbostratus
Oct 06, 2014

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 minute

set static::holdtime 60

Number of messages per 1 minute

set static::smtp_msg_per_period 1

Checking the TMM and CPUs

set 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 }

2 Replies

  • R_Eastman_13667's avatar
    R_Eastman_13667
    Historic F5 Account

    You have too many square brackets in your class match if statement. It should look like this:

    [class match [IP::client_addr] equals "SMTP_OFFENDERS"]

    • Abdul_1034's avatar
      Abdul_1034
      Icon for Nimbostratus rankNimbostratus
      I should have replaced much earlier. I found the issue and fixed it. Thanks R Eastman.