Forum Discussion

larry_williams2's avatar
larry_williams2
Icon for Nimbostratus rankNimbostratus
Oct 24, 2014

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

  • 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's avatar
    giltjr
    Icon for Nimbostratus rankNimbostratus

    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
    }
    
  • 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
    }
    
  • 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]"