fir3net
PPS-Firenetbanner-780.5x190-30-03-17

F5 LTM - iRule Variables

The F5 offers a number of different ways to you can represent your data via iRules such as variables, tables, datagroups and arrays. Within this article we will look at the variables. There are 2 main types of variables, local and global.

Local

Local variables represent data within your local namespace, and are assigned the same scope as the iRule that created it. This also means that local variables are shared across all iRules for a Virtual Server. In addition to this local variables are also session based.

Below shows you how you would assign, output and unassign a local variable.

set uri "picture.jpg"     <- assign var
log local0. "uri is $uri" <- output var
unset uri                 <- unassign var

Global

Unlike local variables, global variables exist outside of the local namespace, meaning that they aren't bound to a single session but instead a TMM instance. An example of when a global variable may be required would be the assignment of an IP address to a variable that you would want available to every session across the F5 system.

Unfortunately global variables are not shared across TMM instances and are only available globally within the local TMM instances. Because of this using a global variable within an iRule demotes CMP (Clustered Multi-Processing) from the associated virtual server.

set ::uri "picture.jpg"     <- assign var
log local0. "uri is $::uri" <- output var
unset ::uri                 <- unassign var

Static Global

Static global variables overcome the CMP demotion problem by sharing the data across each TMM instance. However as the name suggests the variable is static, and is only defined each time the iRule is initialized. 

when RULE_INIT {
  set static::debug 0
}

when HTTP_REQUEST {
  if { $static::debug } {
    log local0. "debug equals $static::debug"
}

References

https://devcentral.f5.com/tech-tips/articles/irules-101-03-variables
https://devcentral.f5.com/tech-tips/articles/-the101-irules-101-variables
http://support.f5.com/kb/en-us/solutions/public/13000/000/sol13033.html 
https://devcentral.f5.com/wiki/irules.static.ashx

Tags: TCL, iRule, BIG-IP F5

About the Author

RDonato

R Donato

Rick Donato is the Founder and Chief Editor of Fir3net.com. He currently works as a Principal Network Security Engineer and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001