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:
<span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">when</span> <span style="color: #cc6633;">RULE_INIT</span> {<span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">set</span> addr_group1 [<span style="color: #0000ff;">list</span> \<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #006080;">"10.10.10.0"</span> \<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #006080;">"10.10.20.0"</span> \<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #006080;">"10.10.30.0"</span> \<span id="lnum6" style="color: #606060;"> 6:</span> ]<span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">set</span> addr_group2 [<span style="color: #0000ff;">list</span> \<span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #006080;">"10.20.10.0"</span> \<span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #006080;">"10.20.20.0"</span> \<span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #006080;">"10.20.30.0"</span> \<span id="lnum11" style="color: #606060;"> 11:</span> ]<span id="lnum12" style="color: #606060;"> 12:</span> }
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:
<span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">when</span> <span style="color: #cc6633;">DNS_REQUEST</span> {<span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;">if</span> { [<span style="color: #0000ff;">matchregion</span> ldns addr_group1] } {<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;">host</span> 1.2.3.4<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">elseif</span> { [<span style="color: #0000ff;">matchregion</span> ldns addr_group2] } {<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #0000ff;">host</span> 5.6.7.8<span id="lnum6" style="color: #606060;"> 6:</span> } <span style="color: #0000ff;">else</span> {<span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;">host</span> 1.1.1.1<span id="lnum8" style="color: #606060;"> 8:</span> }<span id="lnum9" style="color: #606060;"> 9:</span> }
Still have if/else statements, but it will be trimmed down to as many regions as you have defined. Nice work, wassim!
Related Articles
- GTM irule help with matchregion? - devcentral - F5 devcentral …
- GTM and iRules allowing intelligent redirection for most protocols …
- v10.1 - Configuring GTM’s DNS Security Extensions > DevCentral …
- GTM Geo Target based on State US -- Version 10.2 HF1 - DevCentral …
Technorati Tags: F5 DevCentral,BIG-IP GTM,GTM,iRules,wassim,Jason Rahm