Forum Discussion
class variable pairs possible?
when CLIENT_ACCEPTED {
if {[IP::addr [IP::client_addr] equals "10.64.40.0/24"] } {
node 10.64.40.2
} elseif {[IP::addr [IP::client_addr] equals "10.64.41.0/24"] } {
node 10.64.41.2
}
}
etc...
Is it possible to use class with a pair of matched variables? I'm going to have quite a number of these statements and would prefer to keep the irule as small as possible.
Thanks,
-Ken
7 Replies
- hoolio
Cirrostratus
Hi Ken,
You can use the IP host/subnet = value format (name = value pairing) in 10.1+:class ip_subnets_class { { host 1.1.1.1 { "10.11.0.1" } network 2.2.2.0/24 { "10.10.10.10" } } }
You can then use something like 'set dest [class match -value [IP::client_addr] equals ip_subnets_class]' to do the lookup.
Aaron - Colin_Walker_12Historic F5 AccountSo to re-write your current iRule using hoolio's (sweet and simple) logic above:
when CLIENT_ACCEPTED { set dest [class match -value [IP::client_addr] equals ip_subnets_class] node $dest }
Nice work hoolio, as always.
Colin - yammy1688_99834
Nimbostratus
Thanks!Didn't work when I defined the class in the irule itself, but worked fine if I defined it in the data group list from the GUI.
- hoolio
Cirrostratus
Yes, by design, datagroups/classes are separate objects from iRules, so they need to be defined independently.
Glad it's working for you.
Aaron - yammy1688_99834
Nimbostratus
made a small change to it too, otherwise it broke other stuff since it's being applied to a 0.0.0.0/0.0.0.0 forwarding VS.when CLIENT_ACCEPTED {
if {[class match [IP::client_addr] equals subnets] } {set dest [class match -value [IP::client_addr] equals subnets]node $dest}}
- hoolio
Cirrostratus
Hi Yammy,
You could try this to eliminate the second class lookup:when CLIENT_ACCEPTED { set dest [class match -value [IP::client_addr] equals subnets] if {$dest ne ""} { node $dest } }
Aaron - Colin_Walker_12Historic F5 AccountGood to know it's working, thanks. And yes, classes are intentionally separate config objects.
Colin
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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