Forum Discussion

pzinsou_74089's avatar
pzinsou_74089
Icon for Nimbostratus rankNimbostratus
Aug 29, 2007

irule optimization - redirect based on URL

Hello, this is my irule.

I need to know how to optimize it. Is there any max number of "contains" conditions for the if. Or can I add many number of site to redirect?

Can I add many many site or should I have to create a data group list?

Thanks for your help.

when HTTP_REQUEST {
  set Client_IP [clientside {IP::remote_addr}]
  if { [IP::addr $Client_IP equals "141.227.1.2"] } {
    log local0. "c'est le proxy1"
    if { [HTTP::host] contains "yahoo" or [HTTP::host] contains "bred" } {
      pool POOL_SURFING
      log local0. "on utilise le pool POOL_SURFING"
    } else {
      pool POOL_ISP
      log local0. "on utilise le pool ISP"
    }
  } else {
    pool POOL_ISP
    log local0. "on utilise le pool ISP"
  }
}
  • Your iRule is fine as long as your list of sites doesn't grow too large. There is no physical limit to the number of contains you can use, but by joining many "or" operators together in a single if statement, you'll eventually suffer a slight performance degredatation. Data Groups are one option and another option is to use a switch statement.

    when HTTP_REQUEST {
      set Client_IP [clientside {IP::remote_addr}]
      if { [IP::addr $Client_IP equals "141.227.1.2"] } {
        log local0. "c'est le proxy1"
        switch -glob [HTTP::host] {
          "*yahoo*" -
          "*bred*" {
            pool POOL_SURFING
            log local0. "on utilise le pool POOL_SURFING"
          }
          default {
            pool POOL_ISP
            log local0. "on utilise le pool ISP"
          }
        }
      } else {
        pool POOL_ISP
        log local0. "on utilise le pool ISP"
      }
    }

    I'd recommend you take a look at the "How to write fast iRules" document over in the wiki

    http://devcentral.f5.com/wiki/default.aspx/iRules/HowToWriteFastRules.html

    Click here

    -Joe