Forum Discussion
Chris_Phillips
Nimbostratus
Aug 03, 2006iRule as stored function or similar
Hi,
I have an iRule with a dozen lines or so and amd really hoping that there is some way to use this one single iRule as a stored function for instances of it. I mean, i will be using seper...
Chris_Phillips
Nimbostratus
Aug 04, 2006Hi,
thanks for everything everyone's said here. I've updated my one single iRule to store data in an array using the virtual name as the array key:
when RULE_INIT {
number of times an ip address can be used between lookups
set ::max_usage_count 3
array of resolved ip addresses
array set ::server_ipaddr { }
array of resolved address uses
array set ::usage_count { }
log local0. "Completed RULE_INIT on lookup"
}
when CLIENT_ACCEPTED {
initialize usage count if not yet done for this VS
if { [ info exists ::usage_count([virtual name]) ] == 0 } {
set ::usage_count([virtual name]) 0
}
use server_ipaddr if it exists, use dummy localhost if not
if { [ info exists ::server_ipaddr([virtual name]) ] == 1 } {
node $::server_ipaddr([virtual name]) [getfield [virtual name] "_" 3]
} else {
this WILL fail, but only occurs on very first usage when no IP address is known yet.
node 127.0.0.1
}
decrement usage_count for this virtual server
incr ::usage_count([virtual name]) -1
call lookup if maximum usages has happened and reset usage counter
if { $::usage_count([virtual name]) <= 0 } {
set ::usage_count([virtual name]) $::max_usage_count
NAME::lookup [getfield [virtual name] "_" 2]
}
}
when NAME_RESOLVED {
assign resolved name to server_ipaddr array
if {[scan [NAME::response] "%d.%d.%d.%d" a b c d] == 4 } {
set ::server_ipaddr([virtual name]) [NAME::response]
}
}
I realised that as i already wanted to put the destination server and port number in the virtual server name, i could just split on an underscore (e.g. vs_example.com_443) to get all the configuration details i needed. I can then store additional dunamic data in two global arrays as i go along.
I'm very happy with the logic here, but wonder about the optimization of it all. I've read tips that advise against intermediate local variable names (otherwise i would have been tempted to copy [virtual name] to a local variable in the CLIENT_ACCEPTED event) but if anyone has other pointers to tweak the efficieny, every little helps. i'm doing a lot of repeated array lookups and getfields... i'm lead to believe that's the best approach if anything though.
Cheers
Chris
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects