Forum Discussion

zhanghr_101384's avatar
zhanghr_101384
Icon for Nimbostratus rankNimbostratus
Oct 22, 2009

Global variables shared across virtual servers and irle scripts?

It seems that all global variables defined in RULE_INIT event are shared across different irule scripts, even if they are deployed on different virtual servers.

 

 

I have created one irule script for my local box testing, where some global variable are defined inside RULE_INIT. Then to test it in our DEV environment, I copied and renamed the same script, and set different values for all global variables for the DEV environment. Now, both scripts are imported into a same Big-Ip server, but deployed to different virtual servers there. What I found out is that the global variables will always have the same values, depending on which script is loaded last. Certainly this is not the behavior I want!

 

 

Can someone confirm this is expected behavior of irule and Big-Ip and I am not missing anything obvious?

 

 

If global variables are truly shared this way, is it a little too dangerous, as two irule script authors from two divisions of a company may name some global variables samely, causing a conflict without knowing it? To me, shouldn't the boundary of global variables be set up at least between virtual servers?

 

 

Besides making global variable names fully qualified, can someone recommend any other ways to avoid such conflicts?

 

 

Thanks a lot in advance!

2 Replies

  • This is expected. From a past post:

     

     

     

    http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&postid=25222&ptarget=25227

     

     

    Any variable declared in RULE_INIT is global. If you declare a variable using the global command or with two colons in front (set ::my_global_var 1), it will also be global. Global variables are accessible across all connections on any VIP. Local variables are accessible only on the current TCP connection pair (client - VIP and LTM - pool member).

     

     

    If you reference a global variable in two different rules on the same or different VIPs, the variable is shared between the two connections and can be trampled. The second link below has details on one option for variable names.

     

     

    Variable Scope & Lifetime

     

    http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&tpage=1&view=topic&postid=18430

     

     

    Multiple irules using same local variable name

     

    http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&postid=23503&ptarget=23582

     

     

     

     

     

    Besides making global variable names fully qualified, can someone recommend any other ways to avoid such conflicts?

     

     

     

     

    You'll need to come up with some scheme to ensure that your iRule's global variables are unique. Maybe you can come up with a naming convention within your company that does this. There isn't a simple technical solution for this.

     

     

    Aaron