Forum Discussion
Eric_Stewart_36
Nimbostratus
Oct 15, 2018Verify iRule Syntax
Hello all
I am trying to write an iRule that will check for the incoming port, and then, check source IP address, and choose a Pool accordingly. This is my first iRule. Please let me know if this l...
Lee_Sutcliffe
Nacreous
Oct 17, 2018I would try to avoid using so many repeated 'if' statements as it can be come quite cumbersome and small changes could ended up breaking your iRule.
Using a datagroup with IP to pool mappings can be a cleaner way to achieve the same result. Switch statements are also faster and are a good alternative to using successive 'or' operators. Also the second 'if' block looks like it could be placed within the first - for this reason I've included it within the same switch 'or' block.
Datagroup
ltm data-group internal my_dg {
records {
10.1.1.1 {
data pool_a
}
10.1.1.2 {
data pool_b
}
}
type string
}
iRule
when CLIENT_ACCEPTED {
switch [TCP::local_port] {
"7002" -
"443" -
"8443" -
"7001" -
"80" {
if {[set my_app [class match -value [IP::addr[IP::client_addr] equals "my_dg"]]]} {
persist none
pool $my_app
}
}
}
}
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