Forum Discussion

Neil_66348's avatar
Neil_66348
Icon for Nimbostratus rankNimbostratus
Nov 09, 2010

iRule GeoIP Targeting

Hi Guys ,

 

 

We're looking to implement some targeting thats found in 10.2 on our F5's.

 

 

Performing matching at the IP level works fine , I've found some example code for matching to the internal quova database. The example below as pulled from an article on the F5 website , however can't seem to get it to compile.

 

 

We've created an iRule data Group list of type String as well.

 

 

when HTTP_REQUEST {

 

set region [class match -value [whereis [IP::client_addr] abbrev] equals uk_regions]

 

if { $region ne "" } {

 

switch $region York { pool $region }

 

Greater London { HTTP::redirect http://dev.application.com/grlondon }

 

Leeds { HTTP::redirect http://dev.application.com/leeds}

 

Stockport { HTTP::redirection http://dev.application.com/stockport }

 

} else { pool devpool }

 

}

 

 

When going to complile I get the errors o:

 

line 4: [wrong args] [switch $region]

 

line 5: [undefined procedure: York] [York { pool $region }]

 

line 6: [undefined procedure: Greater] [Greater London { HTTP::redirect http://dev.application.com/grlondon }]

 

line 7: [undefined procedure: Leeds] [Leeds { HTTP::redirect http://dev.application.com/leeds}]

 

line 8: [undefined procedure: Stockport] [Stockport { HTTP::redirection http://dev.application.com/stockport }]

 

 

Any help greatly appreciated.

 

 

many Thanks

 

 

Nei

8 Replies

  • Hey Neil,

    I have to preface this with the fact that I am not really good at iRules, but here is what I came up with. Give it a shot and see what you get, it at least compiles on my BIG-IP:

    
     when HTTP_REQUEST { 
       set region [class match -value [whereis [IP::client_addr] abbrev] equals uk_regions]
       if {$region ne ""}{ 
       switch $region {
       "York" { pool $region }
       "Greater London" {HTTP::redirect http://dev.application.com/grlondon}
       "Leeds" {HTTP::redirect http://dev.application.com/leeds}
       "Stockport" {HTTP::redirect http://dev.application.com/stockport}
    default {pool devpool}
    }
    }
    }
    
  • Hi ,

     

     

    That compiles , which is a great.

     

     

    Using an iRule to dump out to a local0, determined I need to use "state" to determine eg "Greater London" / "York" etc. This successfully posts eg ,

     

     

    when CLIENT_ACCEPTED { log local0. "Got client: [whereis [IP::client_addr] country continent state isp]" }

     

     

    Rule GeoIPLog : Got client: GB EU York {verizon business}

     

    Rule GeoIPLog : Got client: GB EU {Greater London} {btnet uk regional network}

     

     

    The iRule posts no errors , however nor is matching the pickup of the "state" to redirect to the correct redirect...

     

     

    when HTTP_REQUEST {

     

    set state [class match -value [whereis [IP::client_addr] abbrev] equals uk_regions]

     

    if {$state ne ""}{

     

    switch $state {

     

    "Greater London" {HTTP::redirect }

     

    "Leeds" {HTTP::redirect }

     

    "York" {HTTP::redirect }

     

    default {pool TIN-HTTP-POOL}

     

    }

     

    }

     

    }

     

     

    Any ideas why its not picking up to redirect the client to the applicable address....

     

     

    Thanks

     

     

    Neil
  • I am not certain but it looks like to me you are setting your state to equal the two letter abbreviation in the iRule. But you want to actually return the word, not the two letter abbrev so using state instead of abbrev in the iRule and I think this should work:

     
    when HTTP_REQUEST { 
       set state [class match -value [whereis [IP::client_addr] state] equals uk_regions]
        if {$state ne ""}{
        switch $state { 
       "Greater London" {HTTP::redirect http://62.190.x.x/ab/grlon/}
        "Leeds" {HTTP::redirect http://62.190.x.x/ab/leeds}
        "York" {HTTP::redirect http://62.190.x.x/tv/York/} 
          default {pool TIN-HTTP-POOL}
    }
    }
    }
    
    
  • Just in case other folks are looking at using Geolocation here is an excellent article written by Jason on the subject:

     

     

    http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/1082330/New-Geolocation-Capabilities-in-v101.aspx

     

  • Hi ,

     

     

    Arrggg , didn't notice that one on using abbrev...great thanks

     

     

    Testing with an iRule from the article works fine:

     

     

    when CLIENT_ACCEPTED { if { !(([whereis [IP::client_addr] state] equals "York") or ([whereis [IP::client_addr] state] equals "Leeds")) } { pool TIN-HTTP-POOL }}

     

     

    So , I think this leads onto another problem with potentially it using the Data List lookup from the if and the switch $state

     

     

    when HTTP_REQUEST {

     

    set state [class match -value [whereis [IP::client_addr] state] equals uk_regions]

     

    if {$state ne ""}{

     

    switch $state {

     

    "Greater London" {HTTP::redirect "http://62.190.x.c/ab/grlon/"}

     

    "Leeds" {HTTP::redirect "http://62.190.x.x/ab/leeds"}

     

    "York" {HTTP::redirect "http://62.190.x.x/ab/York/"}

     

    default {pool TIN-HTTP-POOL}

     

    }

     

    }

     

    }

     

     

    Changing the data list type from string to integer reveals:

     

    - bad IP network address formatInvalid class element York for class uk_region invoked from within "class match -value [whereis [IP::client_addr] state] equals uk_region"

     

     

    So clearly it has to be string , but crucially shows that the first part is functioning in terms of finding the "state" in the first place just now an issue with the element for the lookup to that list...

     

     

    Thanks

     

     

    Neil

     

  • Hi Guys ,

     

     

    An update.

     

     

    Was using Internet Explorer , which was a real problem...using Chrome showed up the loop and then with HTTPWatch on IE , showed a loop.

     

     

    Now:

     

    when HTTP_REQUEST {

     

    set state [class match -value [whereis [IP::client_addr] state] equals uk_regions]

     

    if {($state ne "")}{

     

    switch $state {

     

    Leeds { pool $region }

     

    York {HTTP::redirect http://62.190.1.1/ab/york}

     

    grlond {HTTP::redirect http://www.google.com/news}

     

    default {pool DEV-HTTP-POOL}

     

    }

     

    }

     

    }

     

     

    The above works for www.google.com/news , however for the York redirect to 62.190.1.1/ab/york , a redirect loop occurs. The iRule is on the virtual server runs on the same address of the website for redirection. So the problem now is that the redirection loops if going back to the same IP....

     

     

    Anyone seen that one...

     

     

    THanks

     

     

    Neil
  • I have never used it before, but I am very curious if something like this would work? It does compile, I am just uncertain of the ramifications of using event disable in an iRule:

     
    when HTTP_REQUEST { 
       set state [class match -value [whereis [IP::client_addr] state] equals uk_regions]
        if {($state ne "")}{
        switch $state { 
         Leeds { pool $region } 
          York {if { [HTTP::uri] starts_with "/ab/york"} {
    event HTTP_REQUEST disable
    } else {
    HTTP::redirect http://62.190.1.1/ab/york
    }
    }
          grlond {HTTP::redirect http://www.google.com/news} 
          default {pool DEV-HTTP-POOL}
    }
    }
    }