Forum Discussion

Ameya_4149's avatar
Ameya_4149
Icon for Nimbostratus rankNimbostratus
Feb 16, 2012

iRules for Source IP based routing

Hi folks,

 

I am trying to write an iRule for Source IP based routing. So what I am trying to do is if a packet comes from a specific pool of IP's, my LTM should fooward it to a specific server. If the IP is not from that pool, it will be forwarded to the default pool. Also if all the servers in a specific pool are down, the packets should be forwarded to the default pool.

 

 

This is my code, want to know if we can do better. I am also looking for a low processing time.

 

 

when CLIENT_ACCEPTED {

 

if { [ class match [IP::client_addr] equals DataGroup_RegionA ] } {

 

if { [active_members Pool_A] < 1 } {

 

pool Default_pool}

 

else {pool Pool_A}

 

} elseif { [ class match [IP::client_addr] equals DataGroup_RegionB ] } {

 

if { [active_members Pool_B] < 1 } {

 

pool Default_pool}

 

else {pool Pool_B}

 

} elseif { [ class match [IP::client_addr] equals DataGroup_RegionC ] } {

 

if { [active_members Pool_C] < 1 } {

 

pool Default_pool}

 

else {pool Pool_C}

 

} else {pool Default_pool}

 

}

 

 

 

Pool A, B, C has more than 1 members (servers)

 

Default_pool has all the servers listed in Pool A, B and C

 

 

Thanks,

 

Ameya
  • This iRule works, but I need an iRule to be applied only on the new one. Can this objective be met, without touching the wild card VS that is configured already?

     

     

    Thanks,

     

     

    r_dynamo
  • OK, well I guess it can just be applied to the wildcard VS like so;

    
    when CLIENT_ACCEPTED {
     if { [IP::addr [IP::client_addr] equals 1.1.1.1] } {
      do something
     }
     elseif {
      virtual 'new virtual name'
     }
    }
    
  • Sorry, no elseif required;

    
    when CLIENT_ACCEPTED {
     if { [IP::addr [IP::client_addr] equals 1.1.1.1] } {
      do something
     }
     else {
      virtual 'new virtual name'
     }
    }