Forum Discussion
CLIENT_DATA doesn't always seem to be firing
I am a newbie to writing iRules so I am probably (hopefully) making a simple rookie mistake... I'm trying to write an iRule following a couple of samples I have found to connect to one of two Oracle databases. Only one database will be active at a time - a pair of health monitors are working properly to route traffic appropriately. My intent is to find out from LB_SELECTED event which database server has been selected as active, and then set the correct Oracle SID in a CLIENT_DATA event.
I have numerous log statements in the iRule and it seems that the CLIENT_DATA logging rarely happens. When it does, the iRule works and the connection is successful. When it doesn't, then the connection fails. Our network analyst assures me that he has synched the iRule across our two F5's and that it is applied. I can only assume that the CLIENT_DATA doesn't get executed for every request, but I can't figure out why.
Like I said, this is probably a rookie mistake, so I'm hoping someone can help me out... My iRule is below. Thanks in advance, Andrew
Load Balancer has determined which database node to route traffic to - set SID accordingly
when LB_SELECTED {
log local0.debug "Entering LB_SELECTED"
set lb_host [LB::server addr]
switch [LB::server addr] {
10.116.245.99 { ;
set lb_sid "wsrrtest"
}
10.116.245.98 { ;
set lb_sid "wsrrtst1"
}
}
log local0.debug "Exiting LB_SELECTED"
TCP::collect
}
when CLIENT_DATA {
log local0.debug "CLIENT_DATA IN IRULE HAS FIRED"
if { [TCP::payload] contains "(CONNECT_DATA=" } {
log local0.debug "LOCATED ORACLE CONNECT_DATA IN IRULE"
if { [TCP::payload] contains "(SID=" } {
Find and save the SID the user/client has provided.
set sid [string tolower [findstr [TCP::payload] "(SID=" 5 ")"]]
if user supplied SID is different from what load balancer has selected, then replace it.
!! this assumes that the SID length will be the same!!!!
if { $sid != $lb_sid } {
set SID in TCP::payload to the load balancer selected SID
log local0.debug "Rewriting SID in TCP payload from $sid to $lb_sid"
set sid_match [regexp -all -inline -indices "SID=$sid" [TCP::payload]]
foreach sid $sid_match {
set sid_start [lindex $sid 0]
set sid_end [lindex $sid 1]
TCP::payload replace $sid_start [expr {$sid_end - $sid_start + 1}] "SID=$lb_sid"
}
log local0.debug "CHANGED SID IN TCP Payload to $lb_sid"
}
}
else {
log local0.debug "No SID found in CONNECT_DATA"
}
log the new connect_data string
set connect_data_str [findstr [TCP::payload] "(DESCRIPTION=" 12 ")))" ]
log local0.debug "$connect_data_str"
}
else {
log local0.debug "No CONNECT_DATA seen"
}
TCP::release
TCP::collect
}
3 Replies
- drew13_136080
Nimbostratus
TTT - is this UDP or TCP data? with the latter you might have to work with collect and release.
- What_Lies_Bene1
Cirrostratus
I think the issue here is with the collect and release commands.
I'd suggest you remove collect from the LB_SELECTED event and put it in the CLIENT_DATA one. Don't you also need to specify an amount of data?
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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