Forum Discussion

John_Giannone_4's avatar
John_Giannone_4
Icon for Nimbostratus rankNimbostratus
Jun 09, 2008

IRules for Redirection on GTM

We are currently using a GTM 1500 to redirect incoming web traffic based on Geographic locaiton. So when someone comes to our mainsite (for example) and they are from Australia, we serve them the IP of our domain.au site. For this we are using Regions and Topology records. Woroks great.

 

 

We want to change to IRules however, so we can redirect customers for several different wide IPs. The IRule we have configued per DEV central is as follows, however, I am told by F5 that it doesnt work and there may be a bug:

 

 

when DNS_REQUEST {

 

if {[whereis [IP::remote_addr]] contains "US"} {

 

pool raileurope_us_pool

 

}

 

if {[whereis [IP::remote_addr]] contains "AU"} {

 

pool raileurope_au_pool

 

}

 

if {[whereis [IP::remote_addr]] contains "JP"} {

 

pool raileurope_jp_pool

 

}

 

if {[whereis [IP::remote_addr]] contains "ZA"} {

 

pool raileurope_sa_pool

 

}

 

if {[whereis [IP::remote_addr]] contains "BO"} {

 

pool raileurope_bolivia_pool

 

}

 

if {[whereis [IP::remote_addr]] contains "CL"} {

 

pool raileurope_chile_pool

 

}

 

if {[whereis [IP::remote_addr]] contains "CO"} {

 

pool raileurope_columbia_pool

 

}

 

if {[whereis [IP::remote_addr]] contains "EC"} {

 

pool raileurope_ecuador_pool

 

}

 

if {[whereis [IP::remote_addr]] contains "PY"} {

 

pool raileurope_paraguay_pool

 

}

 

if {[whereis [IP::remote_addr]] contains "PE"} {

 

pool raileurope_peru_pool

 

}

 

if {[whereis [IP::remote_addr]] contains "UY"} {

 

pool raileurope_uruguay_pool

 

}

 

if {[whereis [IP::remote_addr]] contains "VE"} {

 

pool raileurope_venezuela_pool

 

} else {

 

pool raileurope_us_pool

 

}

 

}

 

 

I am told by F5 that the following IRule does work. Is there a better way to write it though:

 

 

when DNS_REQUEST {

 

set wherefrom [whereis [IP::remote_addr]]

 

 

if {$wherefrom ends_with "US"} {

 

pool raileurope_us_pool

 

} elseif {$wherefrom ends_with "AU"} {

 

pool raileurope_au_pool

 

} elseif {$wherefrom ends_with "JP"} {

 

pool raileurope_jp_pool

 

} elseif {$wherefrom ends_with "ZA"} {

 

pool raileurope_sa_pool

 

} elseif {$wherefrom ends_with "BO"} {

 

pool raileurope_bolivia_pool

 

} elseif {$wherefrom ends_with "CL"} {

 

pool raileurope_chile_pool

 

} elseif {$wherefrom ends_with "CO"} {

 

pool raileurope_columbia_pool

 

} elseif {$wherefrom ends_with "EC"} {

 

pool raileurope_ecuador_pool

 

} elseif {$wherefrom ends_with "PY"} {

 

pool raileurope_paraguay_pool

 

} elseif {$wherefrom ends_with "PE"} {

 

pool raileurope_peru_pool

 

} elseif {$wherefrom ends_with "UY"} {

 

pool raileurope_uruguay_pool

 

} elseif {$wherefrom ends_with "VE"} {

 

pool raileurope_venezuela_pool

 

} else {

 

pool raileurope_us_pool

 

}

 

}

 

3 Replies

  • I haven't ever written any iRules to take advantage of GTM

    However, the general the rule of thumb is if get into 25 or more if-elseif statements to use the switch statements.

    Example:

       
       when DNS_REQUEST {    
          set wherefrom [whereis [IP::remote_addr]] 
          switch -glob $wherefrom {   
          "*US" { pool raileurope_us_pool }   
          "*AU" { pool raileurope_au_pool }   
          "*JP" { pool raileurope_jp_pool }   
           .   
           .   
           .   
          default { raileurope_us_pool }   
         }   
       }   
       

    Click here and/or Click here for more details about using "switch"

    Hope this helps.

    CB
  • cmbhatt's suggestion of using a switch is definitely a good one. Did F5 provide you with a CR number describing the bug? It seems odd that saving the output from [whereis [IP::remote_addr]] would make any difference versus using the commands in every line. The former option would be more efficient (with a switch being even better), but they should be functionally the same.

     

     

    Aaron
  • NO CR number, they arent even sure it is a bug. They couldn't get the IRule to work, so were going to escalate it.