For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

2funky_105078's avatar
Jul 31, 2014

iRule error optimization

Hi,

For the iRule guru's, i am looking on a way to optimize this iRule which fails saying that the else is not accepted at the end.

Can I do a IF with inside a SWITCH and then a HTTP::redirect in the ELSE? Any way to optimize this, as it is going to be run many times (>100k users).

Thanks!

when HTTP_REQUEST {
if { [active_members [LB::server pool]] > 0 } {
   switch -glob [string tolower [HTTP::host]] {
     "one.example.com*"
          {
            if { not ([HTTP::uri] starts_with "/_markethome.aspx?")} {
                   HTTP::redirect http://[HTTP::host]/_markethome.aspx?[HTTP::uri]
                  return
               } 
          }
     "nceforleaders*"
          {
                 HTTP::redirect http://theother.example.com/index.html
                 return
          }
      default { return }
     } 
else {
   HTTP::redirect http://globe.example.com
   return
     }
}}

2 Replies

  • or better do this way

    when HTTP_REQUEST {
    IF [active_members [LB::server pool]] == 0 } {
    do redirect to last resource}
    switch -glob [string tolower [HTTP::host]] {
         "one.example.com*"
         -....
          "two.example.com*"
         -....
    }
    
  • This actually looks pretty solid. It's going to run exactly one time for each HTTP request times the total number of HTTP requests from all users over some given amount of time. That's not a bad thing. The order that you're placing these is marginally important for such a small iRule. For anything substantially larger, I'd recommend putting more prevalent conditions closer to the top.