Forum Discussion

Tomeq_93315's avatar
Tomeq_93315
Icon for Nimbostratus rankNimbostratus
Nov 25, 2013

redirection iRule based on IP and URI

Hi,

 

I'm having problem with the following iRule. I does not work. It looks like it's not trying even the first condition:

 

    when HTTP_REQUEST {
            log local0. "Client [IP::client_addr]"
    if {   ([IP::addr [IP::client_addr] equals x.x.x.x]) and ([HTTP::uri] eq "/someuriwithparameters*")   }
            {  log local0. "Client [IP::client_addr] matched case 1"   
               pool POOL1  }
    if {    ([IP::addr [IP::client_addr] equals y.y.y.y]) and ([HTTP::uri] eq "/someuriwithparameters2*")   }
            {  log local0. "Client [IP::client_addr] matched case 2"   
               pool POOL1  }   
            }

It just drops "Client x.x.x.x" to /var/log/ltm but nothing happens, redirection doesn't work... I've tried IP:addr conditions and HTTP:uri with brackets "()" and without. No change at all.

 

Any mistake in code here?

 

Thanks, Tomek

 

5 Replies

  • A few []'s in the wrong place. Also, you can't use wildcards with an 'equals'.

    when HTTP_REQUEST {
     log local0. "Client [IP::client_addr]"
    
     if { ( [IP::addr [IP::client_addr]] equals "x.x.x.x" ) and ( [string tolower [HTTP::uri]] starts_with "/someuriwithparameters" ) } {
      log local0. "Client [IP::client_addr] matched case 1"   
      pool POOL1
     }
     if { ( [IP::addr [IP::client_addr]] equals "y.y.y.y") and ( [string tolower [HTTP::uri]] starts_with "/someuriwithparameters2" ) } {
      log local0. "Client [IP::client_addr] matched case 2"   
      pool POOL1
     }   
    }
    
  • Hi, it drops an error: "01070151:3: Rule [iRule_Backend_Access_2] error: line 3: [wrong args] [IP::addr [IP::client_addr]] line 10: [wrong args] [IP::addr [IP::client_addr]]"

     

    is that because we use routing domains?

     

  • Apologies IP::addr always catches me out. This should work;

    when HTTP_REQUEST {
     log local0. "Client [IP::client_addr]"
    
     if { ( [IP::addr [IP::client_addr] equals x.x.x.x] ) and ( [string tolower [HTTP::uri]] starts_with "/someuriwithparameters" ) } {
      log local0. "Client [IP::client_addr] matched case 1"   
      pool POOL1
     }
     if { ( [IP::addr [IP::client_addr] equals y.y.y.y] ) and ( [string tolower [HTTP::uri]] starts_with "/someuriwithparameters2" ) } {
      log local0. "Client [IP::client_addr] matched case 2"   
      pool POOL1
     }   
    }
    
  • Your script looks more or less the same as mine ;) Unfortunately, it seems that function: [IP::addr [IP::client_addr] equals y.y.y.y] does not work, when routing domains are used.

     

    Without additional parsing/formating it wouldn't extract dotted decimal IP. I've decided to use just [IP::client_addr] with % notation added. It's ok, but... I was suprised that this function is not rounting domain aware.

     

  • Hmmm, I'll have to keep that in mind for the future. It makes sense really as there needs to be a default and I assume that's common. You wouldn't want it to randomly detect a RD as you may have two using the same address space.