Forum Discussion
panos_101277
Nimbostratus
Apr 29, 2008Multiple irules using same local variable name
Hello,
First off thanks to all the contributors for their many examples and tips, it has really helped a lot.
My question is a simple one but I haven't been able to find an answer or figure out a way around it.
Is there a way for a variable to be specific to the irule it is created in? Ie can I do this:
irule1:
when HTTP_REQUEST {
set myvar "some value"
}
irule2:
when HTTP REQUEST {
set myvar "another value"
}
Note that these two rules would be attached to the same virtual server. The reason I'm asking is because I've been trying to setup my rules so that they share a lot of common code with local variables to point to different classes to define their behavior. However when I try to use them the local variables in the different irules all have the same value which suffice to say is less than ideal [Tongue]
(I originally posted this under iControl by mistake, since I can't move it I've reposted it here)
- hoolio
Cirrostratus
Hi, - panos_101277
Nimbostratus
That's what I was afraid of.. - hoolio
Cirrostratus
It is somewhat inconvenient. You could try something like setting a single local variable (not in RULE_INIT) in each rule to something unique and then build the variable names in that particular rule based on the first variable. Maybe an example would be easier to demonstrate:rule rule1 { when CLIENT_ACCEPTED { set var_prefix "rule1" set ${var_prefix}var1 "this is rule1's var1 value" log local0. "$var_prefix variable name ${var_prefix}var1, variable value: [set [subst ${var_prefix}var1]]" } }
rule rule2 { when CLIENT_ACCEPTED { set var_prefix "rule2" set ${var_prefix}var1 "this is rule2's var1 value" log local0. "$var_prefix variable name ${var_prefix}var1, variable value: [set [subst ${var_prefix}var1]]" } }
Rule test_rule1 : rule1 variable name rule1var1, variable value: this is rule1's var1 value Rule test_rule2 : rule2 variable name rule2var1, variable value: this is rule2's var1 value
- hoolio
Cirrostratus
What you're saying makes sense. I opened a case a bit ago asking F5 to support user-defined functions. If you want to push for this as well, you can open a case with F5 support (websupport.f5.com) and ask them to attach your case to the existing request. Check here for details: (Click here). - panos_101277
Nimbostratus
Yeah I'll do that definitely. Well to allow user-defined functions they would also need to have variable scope per function, that is better than having variable scope per irule.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects