Forum Discussion

Jayant_Shinde_4's avatar
Jayant_Shinde_4
Icon for Nimbostratus rankNimbostratus
Oct 24, 2012

iRUle help with Oracle database

Below is the code that I have written. Basically what it does is inspects the incoming connection packet and if it has service_name in it replaces the incoming service_name with the actual database service name. If I do not do this then I get Oracle error "TNS listner does not know of service".

 

THis code works with Oracle 11g client, but having trouble using oracle 10g client. It just hangs and returns TNS connection closed error. I do not see any information in the Oracle Listener log.

 

THis code is also based on the sample code from F5 on the setting up database behind F5.

 

Any help in figuring out the issues with 10g client is appreciated.

 

 

Thanks

 

Jayant

 

---------------------------------

 

 

when CLIENT_ACCEPTED {

 

TCP::collect 250

 

set last_service ""

 

}

 

 

when CLIENT_DATA {

 

TCP::collect

 

set strpay [TCP::payload]

 

log local0.debug "1.0 First Step : $strpay"

 

log local0.debug "Original TCP packet length ([TCP::payload length])"

 

set connect_data_length [string length [findstr [TCP::payload] "(DESCRIPTION=(CONNECT_DATA=" 0]]

 

if { $connect_data_length < 1 } {

 

set connect_data_length [string length [findstr [TCP::payload] "(DESCRIPTION=(ADDRESS=" 0]]

 

}

 

 

log local0.debug "Original Oracle Net connect data length ($connect_data_length)"

 

 

if { [TCP::payload] contains "(CONNECT_DATA" } {

 

if { [TCP::payload] contains "(SERVICE_NAME=" } {

 

Find and save the service name the user/client has provided.

 

set service_name [string tolower [findstr [TCP::payload] "(SERVICE_NAME=" 14 ")"]]

 

 

set service_name [substr $service_name 0 "."]

 

User supplied service name must exist in our map.

 

 

if { $service_name ne $last_service } {

 

set last_service $service_name

 

}

 

 

log local0.debug "Service = $service_name"

 

 

set service_match [regexp -all -inline -indices "$service_name" [TCP::payload]]

 

log local0.debug "Service Match RegExp = $service_match"

 

 

set destpool ""

 

if { [active_members dmspnyp1-pool] > 0 } {

 

log local0.debug "3.0 Pool member DMSPNYP1 active. Sending request there."

 

set destpool "dmspnyp1"

 

pool dmspnyp1-pool

 

}

 

else {

 

log local0.debug "10.0 No pool member active. Don't know where to send request.Closing Connection"

 

TCP::close

 

TCP::respond $oraclenet_error_packet

 

}

 

log local0.debug "Dest Pool = $destpool-pool"

 

 

foreach service $service_match {

 

set service_start [lindex $service 0]

 

set service_end [lindex $service 1]

 

TCP::payload replace $service_start [expr {$service_end - $service_start + 1}] "$destpool"

 

log local0.debug "Modyfying '(service_NAME=$service_name)' at byte $service_start"

 

 

TCP::payload replace 0 2 [binary format S1 [TCP::payload length]]

 

log local0.debug "Rewriting TCP packet length ([TCP::payload length])"

 

 

set connect_data_length [string length [findstr [TCP::payload] "(DESCRIPTION=(CONNECT_DATA=" 0]]

 

if { $connect_data_length < 1 } {

 

set connect_data_length [string length [findstr [TCP::payload] "(DESCRIPTION=(ADDRESS=" 0]]

 

}

 

TCP::payload replace 24 2 [binary format S1 $connect_data_length]

 

log local0.debug "Rewriting Oracle Net connect data length ($connect_data_length)"

 

}

 

pool $destpool-pool

 

 

log local0.debug "[TCP::payload]"

 

}

 

else {

 

log local0.debug "11.0 I did not see service_name in the packet."

 

}

 

 

TCP::release

 

If you don't want to process further packets, comment the

 

TCP::collect statement out. Remember though, if there is another

 

connect event, for the duration of this connection, you wouldn't be

 

able to act upon it.

 

log local0.debug "Finished processing connection. On to the database now"

 

TCP::collect

 

}

 

else {

 

log local0.debug "12.0 I did not see connect data in the packet."

 

 

TCP::release

 

If you don't want to process further packets, comment the

 

TCP::collect statement out. Remember though, if there is another

 

connect event, for the duration of this connection, you wouldn't be

 

able to act upon it.

 

TCP::collect

 

}

 

}

 

-----------------------------------------

 

No RepliesBe the first to reply