For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Edgar_Palamarch's avatar
Edgar_Palamarch
Icon for Nimbostratus rankNimbostratus
Nov 06, 2015

Dynamic Pools and 'CATCH'

We are trying to implement a CATCH statement in an iRule that directs traffic to different pools depending on URI. The names of the pools are taken from the URI. If no such pool exists, requests are taken to the default pool.

Here is what I have. It works, but if you change that firstFolder in the browser address for anything, it still redirects to the original pool from the first hit and displays the page.

I do appreciate your help!

when HTTP_REQUEST {
set protocol "_443.pool"
set default_pool [LB::server pool]
set firstFolder [findstr [string tolower [HTTP::path]] "/" 1 "/"]
set newpool ""
set newpool "$firstFolder$protocol"
set uri [HTTP::uri [string map [list "/$firstFolder" ""] [HTTP::uri] ] ]
 log local0. "Default Pool $default_pool"
 log local0. "New Pool $newpool"
    if { "" ne $newpool } {
      if { [catch { pool $newpool } ] } {
        log local0. "ERROR: Attempting to assign traffic to non-existent pool $newpool"
      pool "$default_pool$uri"
        log local0. "ERROR: switching to default pool $default_pool"
}
}
}

2 Replies

  • Here is an example of what the iRule should be doing: 1. Request is made to https://www.MyTestDomain.com/firstFolder/site/jumppage 2. firstFolder is detected, $protocol is appended to it, and request is redirected to another pool with the name firstFolder_443.pool 3. The iRule removes the firstFolder from the URI, and the new pool firstFolder_443.pool serves the request as https://www.MyTestDomain.com/site/jumppage 4. If there is no such pool firstFolder_443.pool, the request is sent to the default pool the virtual is mapped to ([LB::server pool]).
  • Hi Edgar, This test script was slightly harder than I expected :) but, it maybe works for you.

    Regards
    when CLIENT_ACCEPTED {
        set default_pool [LB::server pool]
    }
    
    when HTTP_REQUEST {
        log local0. " Requesting URI: [HTTP::uri]"
        Check if is a complete path (e.g. /path/resource, /path/path/resource, ...)
        if { [URI::path [HTTP::uri] depth] > 0 } {
            set firstPath [findstr [HTTP::uri] "/" 1 "/"]
    
        Check if is a possible path (e.g. /path or /resource - discards root and /resource.ext )
        } elseif { [HTTP::uri] ne "/" and not [string match "*.*" [HTTP::uri]] } {
            set firstPath [string range [HTTP::uri] 1 end]
    
        Set to default pool
        } else {
            log local0. " Request to default pool $default_pool"
            pool $default_pool
            return 
        }
    
        log local0. " First path: $firstPath | URI path: [URI::path [HTTP::uri]]"
        set newpool "${firstPath}_443.pool"
        log local0. " Try pool: $newpool / Catch pool: $default_pool"
        if { [catch { pool $newpool }] } {
            log local0. "ERROR: Attempting to assign traffic to non-existent pool $newpool"
            log local0. "ERROR: switching to default pool $default_pool"
            pool $default_pool
        } else {
            Remove pool path from uri
            set uri [string range [HTTP::uri] [expr [string len $firstPath]+1] end]
            if { $uri eq "" } {
                set uri "/"
            }
            HTTP::uri $uri
            log local0. " Selected pool: $newpool | Request URI: [HTTP::uri]"
            unset uri
        }
        unset firstPath newpool
    }