Forum Discussion

FNowak_29320's avatar
FNowak_29320
Icon for Nimbostratus rankNimbostratus
May 26, 2014

"bad IP address format" errors when using geolocation iRule

Hey guys,

I am currently working on an iRule that shall append an URL parameter called "isCountryEMD=yes" whenever US or CA users try to access my website. I am using multiple domains where some of them are using a CDN and some of them don't. To cover both scenarios I am checking the geolocation with either IP::client_addr or the HTTP header "True-Client-IP" which is being set by my CDN, containing the origin IP address of my visitors:

when HTTP_REQUEST { 
set True_Client_IP "[HTTP::header "True-Client-IP"]%1"
  if { (([whereis [IP::client_addr] country] equals "US") or ([whereis [IP::client_addr] country] equals "CA") or ([whereis $True_Client_IP country] equals "US") or ([whereis $True_Client_IP country] equals "CA")) }
    {
      if { [HTTP::uri] contains "?"}{
           HTTP::uri "[HTTP::uri]&isCountryEMD=yes"
           log local0. "GEOREDIRECT - URL: [HTTP::host][HTTP::uri] - IP Remote: [IP::client_addr] - True-IP: $True_Client_IP"
           pool pool_ebiz_prod_80
          } else {
             HTTP::uri "[HTTP::uri]?isCountryEMD=yes"
             pool pool_ebiz_prod_80
            }
    }
}
  • I am using set to append the True-Client-IP variable with an %1 due to route-domain requirements

The iRule seems to work fine but I can see a lot of error messages in /var/log/ltm:

May 26 17:58:26 err tmm2[10930]: 01220001:3: TCL error: /DMZ_700/irule_-prod-80-EMD  - bad IP address format (line 3)     invoked from within "whereis $True_Client_IP country"
May 26 17:58:28 err tmm3[10930]: 01220001:3: TCL error: /DMZ_700/irule_-prod-80-EMD  - bad IP address format (line 3)     invoked from within "whereis $True_Client_IP country"
May 26 17:58:32 err tmm1[10929]: 01220001:3: TCL error: /DMZ_700/irule_-prod-80-EMD  - bad IP address format (line 3)     invoked from within "whereis $True_Client_IP country"
May 26 17:58:43 err tmm3[10930]: 01220001:3: TCL error: /DMZ_700/irule_-prod-80-EMD  - bad IP address format (line 3)     invoked from within "whereis $True_Client_IP country"
May 26 17:58:46 err tmm[10929]: 01220001:3: TCL error: /DMZ_700/irule_-prod-80-EMD  - bad IP address format (line 3)     invoked from within "whereis $True_Client_IP country"
May 26 17:58:48 err tmm1[10929]: 01220001:3: TCL error: /DMZ_700/irule_-prod-80-EMD  - bad IP address format (line 3)     invoked from within "whereis $True_Client_IP country"
May 26 17:58:52 err tmm3[10930]: 01220001:3: TCL error: /DMZ_700/irule_-prod-80-EMD  - bad IP address format (line 3)     invoked from within "whereis $True_Client_IP country"
  • Hi,

     

    Enable logs and check the variable True_Client_IP I did test with this irule and it works. I have a return with FR for the country code. I suppose the returned format is wrong.

     

    when HTTP_REQUEST
    {
    log local0. "IP addr : [IP::client_addr]"
    set myip "78.210.81.133"
    log local0. "Where is : [whereis $myip country]"
    }
  • Thanks nitass for the recommended approach - the rule is now working without any errors. F5 also gave a nice hint to use the return command to ensure that the iRule processing stops as soon as a condition is met. They already saw cases where the iRule ran into errors when not using the command.

     

    when HTTP_REQUEST {

     

    if { [HTTP::header exists "True-Client-IP"] } { set True_Client_IP "[HTTP::header "True-Client-IP"]%1" } else { set True_Client_IP [IP::client_addr] }

     

    if { (([whereis [IP::client_addr] country] equals "US") or ([whereis [IP::client_addr] country] equals "CA") or ([whereis [string tolower $True_Client_IP] country] equals "US") or ([whereis [string tolower $True_Client_IP] country] equals "CA")) } { if { [HTTP::uri] contains "?"}{ HTTP::uri "[HTTP::uri]&isCountryEMD=yes" pool pool_ebiz_prod_443 return } else { HTTP::uri "[HTTP::uri]?isCountryEMD=yes" pool pool_ebiz_prod_443 return } } }