Forum Discussion

dave_it_25516's avatar
dave_it_25516
Icon for Nimbostratus rankNimbostratus
Aug 23, 2012

Global Variables

If a global variable exist in an iRule and it is not applied to a Virtual Server, does it still have any affect on the F5 or the traffic. Does a global variable need to be applied to a Virtual Host to have any affect on traffic?

If a global variable exists in an iRule, does that variable only affect the Virtual Server it is applied to?

Example. Virtual Host for example.com has an iRule applied to it that contains global variables set for pool selection based on what is contained in the "host" of the request.

Since this iRule exist and is applied to a Virtual Server, does that mean it would affect requests to a separate virtual host that doesn't have that iRule applied?

So would a request for qa.mysite.com be routed to a pool_qa_dest as declared in another iRule applied to the virtual server for example.com since the variable is global?

if { [string tolower [HTTP::host]] contains ".qa." } {
set poolDestination $::pool_qa_dest
} elseif { [string tolower [HTTP::host]] contains ".uat." } {
set poolDestination $::pool_uat_dest
} else {
set poolDestination $::pool_prod_dest
}

1 Reply

  • If a global variable exist in an iRule and it is not applied to a Virtual Server, does it still have any affect on the F5 or the traffic. no but you know if irule refers to the global variable, you will get no such variable error and connection will be reseted.

    [root@ve10:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
            log local0. "\$::test $::test"
    }
    }
    [root@ve10:Active] config  b rule myglobal list
    rule myglobal {
       when HTTP_REQUEST {
            set ::test "hello world"
    }
    }
    
    [root@ve10:Active] config  curl -I http://172.28.19.79
    curl: (52) Empty reply from server
    
    [root@ve10:Active] config  cat /var/log/ltm
    Aug 25 18:57:33 local/tmm err tmm[4925]: 01220001:3: TCL error: myrule  - can't read "::test": no such variable     while executing "log local0. "\$::test $::test""
    
    

    If a global variable exists in an iRule, does that variable only affect the Virtual Server it is applied to?no. it is visible globally.

    Since this iRule exist and is applied to a Virtual Server, does that mean it would affect requests to a separate virtual host that doesn't have that iRule applied?no. global variable is just a variable which is globally accessible. traffic will be load-balanced based on virtual server configuration which handles that traffic.

    hope this helps.