Forum Discussion
jayanthi_41101
Nimbostratus
Aug 31, 2011Multiple irules that have same events
I have 2 irules that have 2 datagroups and redirects to different pool but handles the same events HTTP_REQUEST and HTTP_RESPONSE.
Will all the requests go through both irules even if the data matches with only one of the datagroup?
Is it the first match that will happen or will both irules be passed through irrespective of whether it matches or not?
14 Replies
- hoolio
Cirrostratus
Can you post anonymized copies of the iRules for a more definitive answer? In general, all events will be run from all of the iRules enabled on a virtual server.
Aaron - jayanthi_41101
Nimbostratus
irule 1
when HTTP_REQUEST {
set a1 (has value from first datagroup)
if (a1!="") {
pool b1
}
}
when HTTP_RESPONSE {
if (a1!="") { Do something}
}
irule 2
when HTTP_REQUEST {
set a1 (gets value from second datagroup)
set a2 "a1"
if (a2!="") {
pool b1
}
}
when HTTP_RESPONSE {
if (a2!="") { Do something}
what will happen here for the first irule.. will it still go to HTTP_REQUEST and HTTP_RESPONSE in second irule? and will the value of a1 persist across all request or even for the next new request? - jayanthi_41101
Nimbostratus
irule 1
when HTTP_REQUEST {
set a1 (has value from first datagroup)
if (a1!="") {
pool b1
}
}
when HTTP_RESPONSE {
if (a1!="") { Do something}
}
irule 2
when HTTP_REQUEST {
set a1 (gets value from second datagroup)
set a2 "a1"
if (a2!="") {
pool b1
}
}
when HTTP_RESPONSE {
if (a2!="") { Do something}
what will happen here for the first irule.. will it still go to HTTP_REQUEST and HTTP_RESPONSE in second irule? and will the value of a1 persist across all request or even for the next new request? - hoolio
Cirrostratus
I guess the important question is what do you want the behavior to be?
By default, if rule1 is listed first in the order of iRules added to the virtual server its events will run first. For example if this was your virtual server config:virtual http_vs { snat automap pool http_pool destination 10.1.0.15:80 ip protocol 6 rules { rule1 rule2 } profiles { http {} tcp {} } }
And rule1 and rule2 both had HTTP_REQUEST and HTTP_RESPONSE events, when the HTTP request headers are parsed from the client rule1's HTTP_REQUEST event would be triggered then rule2's HTTP_REQUEST event would be triggered. When the pool member responds, rule1's HTTP_RESPONSE event would be triggered followed by rule2's HTTP_RESPONSE event.
The variables from rule1 would be available to rule2. If you use the same variable name in rule2 it would overwrite the value rule1 set. In your example, rule2 would overwrite the value for a1 in its HTTP_REQUEST event. When rule1 references a1 in HTTP_RESPONSE, it would be using the value that rule2 assigned in its HTTP_RESPONSE.
There are a few ways you can affect this behavior. You can override the default priority of an iRule or events within an iRule using the priority command:
http://devcentral.f5.com/wiki/iRules.priority.ashx
You can also use unique variable names across the two iRules if you want to avoid conflicts between the two iRules. You could also combine the iRules to make these dependencies more clear.
You could also disable individual events or all subsequent events using the event disable command. I try to avoid this as I think it's a sledgehammer approach that can cause problems in the future if you need to add more iRules to a virtual server. But the option is there.
http://devcentral.f5.com/wiki/iRules.event.ashx
Aaron - jayanthi_41101
Nimbostratus
Thanks Aaron.
The expectation is not to get overwritten. So, i guess I will consolidate into one irule.
But just to know, so will it always go to HTTP_RESPONSE and HTTP_REQUEST always in the priority in which the irule has been bound to the VIP and is it always true that all the duplicate variables will get overwritten? or is it just unpredictable? - hoolio
Cirrostratus
If you want to avoid tramping between the variables in different iRules you could name them uniquely. You don't have to combine the iRules if you don't want to.
Explicit priority set in the iRule takes precedence over the order the iRules are listed in the GUI. But yes, if the priority isn't set and the order of the iRules on the virtual server aren't changed, rule1's HTTP_REQUEST will always be triggered before rule2's HTTP_REQUEST event. And similarly rule1's HTTP_RESPONSE will always fire before rule2's HTTP_RESPONSE.
Aaron - Puli
Nimbostratus
Hi Aaron,
are the priorities for all events in an iRule ?
Can i have 100 to HTTP_REQUEST in irule1, 200 for HTTP_REQUEST for irule2,
similarly, 100 for HTTP_RESPONSE in iRule 1 and 200 for HTTP_RESPONSE for irule2 ?
thanks,
Puli. - What_Lies_Bene1
Cirrostratus
Yes there are, lowest wins;priority 100 when HTTP_XXX { - Michael_Yates
Nimbostratus
Hi Puli,
You can control the priority of events individually. See the Priority command.
All iRules applied to a specific virtual server are compiled together and the Priority command sets the processing order of the events you specify when they are compiled together.
If no priority is specified then the events are place in the order that the iRules are applied to the Virtual Server. - Puli
Nimbostratus
thanks, this is what i currently have.
I have 8 right iRule, each given a priority. 100 through 800
Each iRule only has the HTTP_REQUEST event.
I have an
1) One common HTTP_RESPONSE iRule code that needs to be triggred for all iRule, no matter the priority.
This remove cache-control header.
2) An HTTP_RESPONSE specific code for each of the 8 iRules.
specific header inserted for each of the iRules in the response.
Eg: iRule 1 will have a the Server header repalce to "BigIP iRule 1" etc
Need some suggestions here on the priority.
and also how i can assign the common HTTP_RESPONSE to all iRules.
One way i guess is add it in each of the 8 iRule along with the specific HTTP_RESPONSE section.
Can you give me an example on the priorities will look like
thanks,
Puli
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
