Forum Discussion
Optimizing Irule
Any suggestions for optimization appreciated.
when CLIENT_ACCEPTED {
if {([class match [whereis [IP::client_addr] country] eq Allowed_Country_Test] or [class match [IP::client_addr] eq allowed_ip])} {
set allowed 1 }
else { set allowed 0 }}
when HTTP_REQUEST {
if { $allowed } {
if {[whereis [IP::client_addr] country ] eq "FI" and [HTTP::uri] contains "/compass/" } {
pool CompassFI_Test_http_pool
} elseif {[whereis [IP::client_addr] country ] eq "DK" and [HTTP::uri] contains "/compass/" } {
pool CompassDK_Test_http_pool
} else {
pool Compass_Test_http_pool
}
} else {
do whatever you want to indicate the block, e.g.
HTTP::respond 403 content "The country or IP is not allowed to access this site"
}
}
/Craig
3 Replies
- hoolio
Cirrostratus
Hi Craig,
Here's an example which minimized the repeated commands with an intermediate variable for the country code:when CLIENT_ACCEPTED { set cc [whereis [IP::client_addr] country] if { [class match $cc eq Allowed_Country_Test] or [class match [IP::client_addr] eq allowed_ip] } { set allowed 1 } else { set allowed 0 } } when HTTP_REQUEST { if { $allowed } { switch $cc { "FI" - "DK" { if {[HTTP::uri] contains "/compass/" } { pool Compass${cc}_Test_http_pool } else { pool Compass_Test_http_pool } } default { pool Compass_Test_http_pool } } } else { do whatever you want to indicate the block, e.g. HTTP::respond 403 content "The country or IP is not allowed to access this site" } }
Aaron - CGI
Altostratus
Thanks Aaron that was much cleaner than the previous rule. /Craig - CGI
Altostratus
Hi Aaron it would seem that we have a problem with the application it needs the ports to be changed in the host header,and we use diiferent ports depending on the country.
Now i know the synatx for the port change:-
HTTP::header replace Host [string map {:80 :7775} [HTTP::host]] for Finland and then
HTTP::header replace Host [string map {:80 :7776} [HTTP::host]] for Denmark and then last
HTTP::header replace Host [string map {:80 :7777} [HTTP::host]] for the default pool
But iam not sure how to combine these statements in the optimised irule you helped me with.
Now i could probably do this i another irule but it would be much better to combine them.
Any ideas ?
/Craig
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com