Forum Discussion

MR_Freddy_31338's avatar
MR_Freddy_31338
Icon for Nimbostratus rankNimbostratus
Jan 30, 2019

IRule Customization

We have a requirement to create irlue with the following logic

 

We have One VS and Two POOL (Pool x and Pool Y)and differentiate the traffic based on requested hostname by the following irule

 

==================

 

when HTTP_REQUEST { if {([HTTP::host] contains "auction.com")} {pool Auction-Pool}

 

if {([HTTP::host] contains "test.com") {pool test-Pool}

 

}

 

====================

 

For certain hostname (auction.com) we need to do the following

 

From internet: All users has to access : https://auction.com

 

From internet: All users should not have to access to: https://auction.com/test/admin

 

From intranet : Only following subnet below should have access to : https://auction.com/test/admin

 

Network1 Range: 10.10.10.X/24

 

Network2 Range: 20.20.20.X/24

 

2 Replies

  • I think the following should work for you:

    when HTTP_REQUEST {
        set selectedPool [LB::server pool]
        set lowerHost [string tolower [HTTP::host]]
        set lowerPath [string tolower [HTTP::path]]
    
        if {$lowerHost ends_with "auction.com"} {
            set clientIP [getfield [IP::client_addr] "%" 1]
            if {($lowerPath starts_with "/test/admin") && !(([IP::addr $clientIP equals 10.10.10.0/24]) || ([IP::addr $clientIP equals 20.20.20.0/24]))} {
                reject
            }
            set selectedPool Auction-Pool
    
        } elseif {$lowerHost ends_with "test.com"} {
            set selectedPool test-Pool
        }
        pool $selectedPool
    }
    

    I have also published as a snippet here Snippet: irule-customization-63561