Forum Discussion
Tiaan_92076
Nimbostratus
Aug 18, 2009How to determine last segment in reaseembled TCP packet
I need to detach the load balancing decision after a transaction is completed on a member in the pool. The transaction occasionally spans multiple TCP segments causing the SERVER_DATA event to be raised more than once for the same transaction. With "LB::detach" in the "SERVER_DATA" event the transaction fails when this happens.
Implementing the "if" statement to check if the payload ends with a certain string and then calling "TCP::notify response" to run "LB::detach" in the "USER_RESPONSE" event solves the problem. Example below from the documentation.
when SERVER_DATA {
log local0.debug "Received SERVER response ... [TCP::payload]"
if { [TCP::payload] ends_with $EOT } {
TCP::notify response
}
TCP::release
TCP::collect
}
when USER_RESPONSE {
LB::detach
log local0.debug "Detaches server connection ... "
if {[TCP::payload length] > 0} {
%TODO%
Process additional client requests here ...
}
}
Can the same be done without checking the payload ? Possibly an event fired when the last segment is received ? I could not find this in the documentation though.
Thanks
18 Replies
Sort By
- spark_86682Historic F5 AccountWithout being able to parse the protocol, there's no way for the LTM to know which segment is last. If you are able to figure out how many bytes are in the response (e.g., from parsing the protocol headers), then you can just TCP::collect that many bytes, and SERVER_DATA will only fire when it has the entire response.
- Tiaan_92076
Nimbostratus
So Wireshark can reassemble the packet because it understands the protocol, GIOP in this case, and already have all the TCP segments ? - spark_86682Historic F5 AccountLooking briefly at the protocol spec, yes, that probably would be more expensive than checking to see if you've got the end-of-transaction marker. If it works for you, then you probably already have the best solution.
- Tiaan_92076
Nimbostratus
I've got the following problem with my iRule when a client uses multiple threads using the same source port for all the threads.when RULE_INIT { set ::eot "Marker" set ::eot_found 0 } when SERVER_CONNECTED { TCP::collect } when SERVER_DATA { set payload [TCP::payload] log -noname local0. "iRule: Request from [IP::client_addr]:[TCP::client_port] load balanced to [LB::server addr]" if { $payload ends_with $::eot } { set ::eot_found 1 } TCP::release TCP::collect TCP::notify response } when USER_RESPONSE { if { $::eot_found eq 1 } { set ::eot_found 0 LB::detach } }
- spark_86682Historic F5 AccountI'm not 100% sure that I understand why you'd get that error just by adding that log statement, but to answer your stated question: LB::detach severs the relationship between the client<->LTM connection and the LTM<->server connection. That's what it's there for; that's what "detaching" is. So once you've detached, well, there is no more clientside connection for this server connection, so that's why you get that error when you ask for the client's address.
- Tiaan_92076
Nimbostratus
That is not how I understood the LB::detach command, the documentation says it only disconnects the server side connection? - spark_86682Historic F5 AccountYes, it disconnects it from the client side connection. It doesn't close either the server or client side connections, it just severs the relationship between them. It disconnects them from each other.
- Tiaan_92076
Nimbostratus
Is it that multiple requests are outstanding on the same TCP connection when it is? - Tiaan_92076
Nimbostratus
I've tested the iRule on a v10 device and noticed not all of my "log" entries were written to the log.when SERVER_CONNECTED { TCP::collect } when SERVER_DATA { log -noname local0. "iRule: Received Server Data" TCP::collect TCP::release }
- hoolio
Cirrostratus
The is probably from syslog-ng suppressing duplicate messages:http://devcentral.f5.com/wiki/default.aspx/iRules/log
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