iRule if based on incoming IP

Hi,

I have a problem here… I’m trying to make an iRule perform specific action if incoming traffic comes from a specific IP address. I have:

if {[IP::addr [IP::client_addr] equals 10.8.199.231]}{
    log local0. "dupa"
}

now I’m quite sure my IP is 10.8.199.231 but when I log this traffic using:

log local0. "Incoming IP: [IP::client_addr]"

i get in log:

10.8.199.231%3

How can I catch traffic from this IP to code some exceptions?

I guess the %3 is added because you are using multiple route domains.

If you add to your condition equals “10.8.199.231%3”

It will match

Regards

Not sure if this is the cause of your issue but you don’t need to put the IP address in quotes, try it without as per the wiki: https://clouddocs.f5.com/api/irules/IP__client_addr.html

if {[IP::addr [IP::client_addr] equals 10.8.199.231%3]} {
        log local0. "IDMS dupa"
    }

Did you refer this Q&A and Q&A.

So it would be something like below,

set rd "%[ROUTE::domain]"
set client_ip [string map "$rd \"\"" [IP::client_addr]]
if {$client_ip equals "10.8.199.231"} {
    log local0. "IDMS dupa"
}

Hi,

you can extract Route domain and IP Address with split and compare it with IP::addr (useful if you need to compare network with netmask evaluation)

elseif {$incURI contains "csmon"}{
    set _redirect "0"
    log local0. "IDMS test Monitoring: [HTTP::uri]"
    log local0. "IDMS test inc IP: [IP::client_addr]"
    lassign [split [IP::client_addr] "%"] IP_addr rd
    if {[IP::addr $IP_addr equals "10.8.199.231"] && $rd equals [ROUTE::domain]} {
        log local0. "IDMS dupa"
    }   
}