Forum Discussion
Paul_Slosberg_8
May 17, 2007Historic F5 Account
A better way
Greetings,
Im trying to grab the last octect of the client adress so I can then use that to send the thraffic to the proper pool. I will have 254 pools that I need to send traffic too. Im trying to use variables to stream line this i-Rule any help or sugestions would be great. I will be using a nework virtual server and 254 port spcific pools. ie (4001-4254)
when CLIENT_ACCEPTED {
set port_info [getfield [IP::client_addr] "." 4]
set poolname "mypool_"
if
{ $port_info matches_regex "[ 1-9]"}
{ pool $poolname400$portinfo }
elseif
{ $port_info matches_regex "[ 10-99]"}
{pool $poolname40$port_info}
else
{ $port_info matches_regex "[ 100-254]"}{
pool $poolname4$portinfo}
}
}
13 Replies
Sort By
- JRahm
Admin
regex is expensive. Try this:when CLIENT_ACCEPTED { set port_info [getfield [IP::client_addr] "." 4] if { [string length $port_info] equals "1" } { pool mypool_400$port_info } elseif { [string length $port_info] equals "2" } { pool mypool_40$port_info } elseif { [string length $port_info] equals "3" } { pool mypool_4$port_info } else { pool myDefault } }
- Paul_Slosberg_8Historic F5 AccountIll stat testing thank you! I have been searching for a way to search string length. Ill let you know how it goes.
- hoolio
Cirrostratus
You could use a switch statement on the string length of $port_info to avoid using a regex. The string length command is more efficient than the regex comparison.... switch [string length $port_info] { 1 { pool $poolname400$portinfo } 2 { pool $poolname40$portinfo } 3 { pool $poolname4$portinfo } }
- hoolio
Cirrostratus
Didn't see that you posted, Citizen... - JRahm
Admin
Yeah, I've noticed that certain patters produce undesired displays in DC. - You've had your share of showing off, I thought I'd get my dig in while I had a chance...
- Paul_Slosberg_8Historic F5 AccountCrazy stuff, now I will test these thanks!!!
- JRahm
Admin
perhaps this is a dumb question, but are all the pools already defined? Either way, I'd introduce some logging and you can check your /var/log/ltm file to see if you are getting any runtime TCL errors. - Paul_Slosberg_8Historic F5 AccountYes the pools would be predefined. So far this has been working great. It would be great if I could use a one wild card pool as well but unfortunately the I rule editor will take this command but it does not work in practice.
when CLIENT_ACCEPTED { TCP::local_port 4[format "%.3d" [getfield [IP::local_addr] "." 4]]}
- What do you mean when you say that the editor will take this command? The TCP::local_port command is read-only and in your case you are trying to set it to a value. When I load the above iRule into the editor and try to save it, it yields this error:
"command is not valid in the current scope"
Recent Discussions
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