Forum Discussion
wenhu_Tang_7610
Nimbostratus
Jul 26, 2005iRules for TCP break up
Hi,
I want to write an iRules to route a TCP packet according to the payload of the packet, but I fail, could you tell whether it is possible and how to achive?
my iRules:
when CLIENT_ACCEPTED {
log "TCP client accepted..."
TCP::collect
}
when CLIENT_DATA {
log "TCP client data received..."
set seq [findstr [TCP::payload] "rtsp:" 0 "\r"]
log "seq=$seq"
TCP::collect
}
I have done a test, I use a TCP clent to send TCP packet including "rtsp:" in it's content, it seems that the CLIENT_DATA event can only be triggered when the first TCP packet is received after creation of TCP connection.
- wenhu_Tang_7610
Nimbostratus
thanks, it works after I add TCP::release. - unRuleY_95363Historic F5 AccountYes, with one caveat - in order to cause the proxy to re-load balance you will first need to call LB::detach.
- James_Yang_9987Historic F5 AccountWhat LB::detach means and where can I found detailed document about this type of commands?
- david_wang_2073Historic F5 AccountI tested following irule, it should work. Here if the payload contain 4, the request will be directed to the 192.168.2.200:3434, otherwise will be directed to the default pool.
when CLIENT_ACCEPTED { set index0 1 TCP::collect log local0. "client_accepted" } when CLIENT_DATA { log local0. "client_data to be realesae [TCP::payload]" if { [TCP::payload] contains "4" } { log local0. "contain 4" use node "192.168.2.200" "3434" } TCP::release TCP::collect log local0. "client data collect after release [TCP::payload] --length [TCP::payload length]" } when SERVER_CONNECTED { TCP::collect log local0. "server connected" } when SERVER_DATA { if { $index0 == 10 } { log local0. " idnex0 = 10 " } log local0. "release server data [TCP::payload] --length [TCP::payload length]" TCP::release TCP::collect log local0. "collect after release server data [TCP::payload] --length [TCP::payload length]" TCP::notify response log local0. "notity response" } when USER_RESPONSE { log local0. "detach" LB::detach }
- unRuleY_95363Historic F5 AccountWhat LB::detach means and where can I found detailed document about this type of commands?
- unRuleY_95363Historic F5 AccountBut I was told, by setting the virtual server with oneconnect profile, the connection to the node can be retained. I have not get time to try it.
- david_wang_2073Historic F5 AccountI used following rule to break a tcp connection, it seems work for synchronization model, which means that the traffic should following the sequence of "request->response->request->response". For each connection, the total transcation time can be been reduced by this way.
when CLIENT_ACCEPTED { set command_length 0 set oper_code 0 set status 0 TCP::collect } when CLIENT_DATA { if {([TCP::payload length] >= 38)} { binary scan [TCP::payload 16] Ia8a4 command_length oper_code status log local. "client data: length $command_length, oper_code $oper_code, status $status" TCP::release command_length } else { log local0. "request lenght less than 38" } } when SERVER_CONNECTED { TCP::collect } when SERVER_DATA { if {([TCP::payload length] >= 38)} { scan [TCP::payload 4] %d command_length binary scan [TCP::payload 16] @4a8a4 oper_code status log local. "server [IP::remote_addr] data: length $command_length, oper_code $oper_code, status $status" TCP::release command_length if { $oper_code contains "08020101" } { binding log local0. "after first binding" } else { TCP::notify resonse } } else { log local0. "request lenght less than 38" } } when USER_RESPONSE { log local0. "server detach" LB::detach } }
when CLIENT_ACCEPTED { set command_length 0 set oper_code 0 set status 0 TCP::collect } when CLIENT_DATA { if {([TCP::payload length] >= 38)} { binary scan [TCP::payload 16] Ia8a4 command_length oper_code status log local. "client data: length $command_length, oper_code $oper_code, status $status" TCP::release command_length if { $oper_code contains "08010101" } { #"08020101"为服务器对binding的第一次请求的代码“ log local0. "after first binding" } else { TCP::notify request } } else { log local0. "request lenght less than 38" } } when SERVER_CONNECTED { TCP::collect } when SERVER_DATA { if {([TCP::payload length] >= 38)} { binary scan [TCP::payload 16] Ia8a4 command_length oper_code status log local. "server [IP::remote_addr] data: length $command_length, oper_code $oper_code, status $status" TCP::release command_length } else { log local0. "request lenght less than 38" } } when USER_REQUEST { log local0. "server detach" LB::detach } }
- unRuleY_95363Historic F5 AccountYou should probably not detach (issue the notify request) until after you have received the response from the server. Your rule currently issues the notify request at the beginning of the next request which potentially causes the detach before a response may have been received from the server. The only course I believe you have is to buffer or delay processing of the next request until you have received a response from the currently connected server. Though we have talked about designing a multiplexor where you could service multiple back-end connections at the same time (either repeating or load-balancing), this is not currently available. One-connect provides an already established connection to save the cost/time of establishing a new connection. It doesn't provide a means of concurrently sending data to multiple servers and then reaping the responses from all the servers it sent requests to. Sorry, but you'll have to stick with your first rule implementation.
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