Forum Discussion
Nat_Thirasuttakorn
May 11, 2009Employee
Hi saschareuter,
I think the follow modifications may help....
- use IP::addr command to manipulate IP address and validate if the address is valid (you may see example here:- http://devcentral.f5.com/wiki/default.aspx/iRules/IP__addr.html)
Here is an example iRule that I believe equivalent to yours....
when RULE_INIT {
Setting the ip for testing purposes because dev workstation does not belong to store-network ;-)
set ip 10.192.18.0
set net_start 172.20.0.0
set net_maskbit 14
set net_mask 0.3.255.224
0.3.255.224 = 00000000-00000011-11111111-11100000
net_size = 262144 so ignore first 14 bits
net_segment_size = 32 so ignore last 5 bits
set net_segment_bit 5
if { [IP::addr $ip/$net_maskbit equals $net_start] }{
log local0. "net $net_start found."
scan [IP::addr $ip mask $net_mask] "%d.%d.%d.%d" a b c d
set VKSTID [expr ( {$a} << 24 | {$b} << 16 | {$c} << 8 | {$d} ) >> {$net_segment_bit} ]
log local0. "VKSTID = $VKSTID"
}
set net_start 10.192.0.0
set net_maskbit 10
set net_mask 0.63.254.0
set net_segment_bit 9
if { [IP::addr $ip/$net_maskbit equals $net_start] }{
log local0. "net $net_start found."
scan [IP::addr $ip mask $net_mask] "%d.%d.%d.%d" a b c d
set VKSTID [expr ( {$a} << 24 | {$b} << 16 | {$c} << 8 | {$d} ) >> {$net_segment_bit} ]
log local0. "VKSTID = $VKSTID"
}
}
- combine some command together
- pre-calculate some value in RULE_INIT event and store it in global variable for reuse (for example, value related to 172.20.0.0 and 10.192.0.0)
- current version of BIG-IP does not support function (proc) but I believe you might be able to reduce number of lines of irule by using foreach and array variable.
Nat