Forum Discussion
Nesting operations within an iRule
I have 9000+ client subnets grouped into roughly 5 ranges. For example, is it possible to have a single iRule that performs the following evaluation:
- if client is in 172.16.0.0/16 then pool 1
- if client is in 172.17.0.0/16 then pool 2
- if client is in 172.18.0.0/16 then pool 3
5 Replies
- Arnaud_Lemaire
Employee
If you could map some range digit to pool name it would be easy. Alternative may be to use a data group to do some mapping.
- giltjr
Nimbostratus
Simple if/elseif structure. I sure you could use tables/data group, but I never used them, so I don't know how.
if {[IP::addr [IP::client_addr]/16 equals 172.16.0.0]} { pool POOL1 } elseif {[IP::addr [IP::client_addr]/16 equals 172.17.0.0]} { pool POOL2 } elseif {[IP::addr [IP::client_addr]/16 equals 172.18.0.0]} { pool POOL3 } else { pool DEFAULT } - Amit_Karnik
Nimbostratus
This is typically easily done with an "ip" type datagroup. You can probably write a small script to create an empty datagroup and then add all the records in it. The key would be the CIDR network and the value would be the pool name.
The iRule snippet you need is
if { [class match [client_addr] equals ] } { set poolname [class match -value [client_addr] equals ] pool $poolname } else { pool default-pool }Here is a sample data-group
ltm data-group internal dg_1 { records { 10.0.0.0/8 { data pool1 } } type ip } - someguy_126006
Nimbostratus
This is may be more scholastic/less practical for your use, but you could split into roughly 5 equal parts with a one-liner where pools are labled pool0-4.
pool "pool[expr [getfield [IP::client_addr] "." 2] % 5]" - larry_williams2
Nimbostratus
Thanks to all, the variety of solutions should cover my requirements.
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