whitelist + geoblocking in iRule

Hi,

the problem is I would like to allow some countries and some IPs from not allowed countries to get access.

I’m not quite sure why this won’t work:

when CLIENT_ACCEPTED {
        switch[ whereis [IP::client_addr] country ] {
            "DE" { set allowed 1 }
            "AT" { set allowed 1 }
            "CH" { set allowed 1 }
            "LI" { set allowed 1 }
            "LU" { set allowed 1 }
                default { set allowed 0 }
        }
                elseif {
                        if {
                          [matchclass [IP::client_addr] equals datagroup whitelistIP ] } {
                          pool datagroup-whitelistIP
                          }   
        else {
            reject
        }
    }

Can anybody help me?

Hi

you may try the iRule below as a starting point…

when CLIENT_ACCEPTED {
    if { [class match [IP::client_addr] equals whitelistIP] } then {
        pool insert_your_pool_name
    } else {
        switch -exact -- [whereis [IP::client_addr] country] {
            "DE" -
            "AT" -
            "CH" -
            "LI" -
            "LU" { 
                pool insert_your_pool_name
            }
            default { 
                reject
            }
        }
    }
}

Note: Reordered theandnestings, optimized thecommand and finally changed the(is a deprecated command) to become.

[if]
[switch]
[switch]
[matchclass]
[class match]

Cheers, Kai