Forum Discussion

Mohammad_Hamad_'s avatar
Mohammad_Hamad_
Icon for Nimbostratus rankNimbostratus
Dec 09, 2015

iRule Assistance

Hello, Glorious people of DevCentral,

I am facing an issue with a couple of iRules that are doing the same thing. First off, here is what the iRule looks like:

when HTTP_REQUEST {
                if{[HTTP::host] eq "example.home.com" and
               [HTTP::path] matches_regex "/home(/.*)\?" or 
               [HTTP::path] matches_regex "/home/services(/.*)\?" or
               [HTTP::path] matches_regex "/index(/.*)\?" or
               [HTTP::path] matches_regex "/default(/.*)\?" or
               [HTTP::path] matches_regex "/home/services/register(/.*)\?" }
                       pool myPool
                       ASM::enable MyPoolASM
    }

I have one Virtual Server where I am applying 5 iRules, and all these 5 iRules have the same pattern, but different regex matches and different pools to send traffic to. Now, when I put one iRule (like the one above), it works properly without any issues. However, if I put more than 1 iRule it immediately stops working and I get resets from the F5. All 5 iRules are looking for the same host match (example.home.com) so the first 2 lines of all 5 iRules are same.

Please let me know if I am doing anything wrong in the iRule, or if I can have multiple iRules with the "when HTTP_REQUEST" on a same VS.

Thank You, Mohammad Hamad

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus

    There's no problem with having multiple iRules processing the same event on the same VS (They just get executed in priority order, if all the same priority then they get executed in listed order). However you do have to watch out for things that you can't do twice. (e.g. trying to do multiple HTTP responses).

     

    Performing multiple pool statements should be fine. And the last one should be the winner. I'm not sure whether you can ASM::enable a profile multiple times though (I haven't tried). What's the error you get? Or is it the TMM process that's restarting (In which case that's a bug and you should open a support case).

     

    H

     

  • Also, for what its worth, the

    match_regex
    is a fairly expensive way to achieve what you want above. This is a more efficient method:

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] eq "example.home.com" } {
            switch -glob [HTTP::path] {
                "/home"   -
                "/home/*" -
                "/home/services"   -
                "/home/services/*" -
                "/home/services/register"   -
                "/home/services/register/*" -
                "/index"   -
                "/index/*" -
                "/default" -
                "/default/*" {
                    pool myPool
                    ASM::enable MyPoolASM
                }
            }
        }
    }
    

    It's probably also worth mentioning that /home/services(/.*) and /home/services/register(/.*) are covered by the /home(.*) branch. Also, your regexps end with the literal ?, but that is not part of

    HTTP::path
    , so that will never match.