I love ingenuity.  DevCentral community member wassim asked a question a little more than a month ago that has been asked several times before: How do you build a class in GTM so you don’t have to use a hoard of if statements to account for your addresses?  Well, classes (datagroups) aren’t yet supported in GTM iRules, so the options have been sparse.  One option that could be utilized is to build a list that you can initialize in RULE_INIT:

   1: when RULE_INIT {
   2:     set addr_group1 [list \
   3:         "10.10.10.0" \
   4:         "10.10.20.0" \
   5:         "10.10.30.0" \
   6:     ]
   7:     set addr_group2 [list \
   8:    "10.20.10.0" \
   9:         "10.20.20.0" \
  10:         "10.20.30.0" \
  11:     ]
  12: }

This, while possible, is hardly ideal.  A few days ago, rather than drop the issue, wassim posted back with an alternative solution: Regions.  GTM Regions allows one to assemble groups of topology records, which once assembled, can be referenced from an iRule:

   1: when DNS_REQUEST {
   2:     if { [matchregion ldns addr_group1] } {
   3:         host 1.2.3.4
   4:     elseif { [matchregion ldns addr_group2] } {
   5:         host 5.6.7.8
   6:     } else {
   7:         host 1.1.1.1
   8:     }
   9: }

Still have if/else statements, but it will be trimmed down to as many regions as you have defined.  Nice work, wassim!

Related Articles