1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-28 20:44:26 +01:00

Feature - Skipping ahead in TCP flows. (#163)

* Skipping forward in TCP streams, from an out-of-order callback.

- Added the ability to skip forward in a flow to a sequence number, with the intention of doing so in an out of order callback.
- Re-ordered Flow packet processing, to allow skipTo in out of order callback on stream start (flow sequence number is 0).
- Fixed missing seq_compare in flow code.

* Renamed skipTo to advance_sequence.
This commit is contained in:
Patrick Michel
2016-10-23 18:47:56 +02:00
committed by Matias Fontanini
parent 2e013847d9
commit aaba3dd46a
4 changed files with 75 additions and 14 deletions

View File

@@ -110,24 +110,27 @@ void Flow::process_packet(PDU& pdu) {
}
const uint32_t chunk_end = tcp->seq() + raw->payload_size();
const uint32_t current_seq = data_tracker_.sequence_number();
// If the end of the chunk ends after our current sequence number, process it.
if (seq_compare(chunk_end, current_seq) >= 0) {
uint32_t seq = tcp->seq();
// If we're going to buffer this and we have a buffering callback, execute it
if (seq > current_seq && on_out_of_order_callback_) {
on_out_of_order_callback_(*this, seq, raw->payload());
}
if (data_tracker_.process_payload(seq, move(raw->payload()))) {
if (on_data_callback_) {
on_data_callback_(*this);
}
// If the end of the chunk ends before the current sequence number or
// if we're going to buffer this and we have a buffering callback, execute it
if (seq_compare(chunk_end, current_seq) < 0 ||
seq_compare(tcp->seq(), current_seq) > 0){
if (on_out_of_order_callback_) {
on_out_of_order_callback_(*this, tcp->seq(), raw->payload());
}
}
else if (on_out_of_order_callback_) {
on_out_of_order_callback_(*this, tcp->seq(), raw->payload());
// can process either way, since it will abort immediately if not needed
if (data_tracker_.process_payload(tcp->seq(), move(raw->payload()))) {
if (on_data_callback_) {
on_data_callback_(*this);
}
}
}
void Flow::advance_sequence(uint32_t seq) {
data_tracker_.advance_sequence(seq);
}
void Flow::update_state(const TCP& tcp) {
if ((tcp.flags() & TCP::FIN) != 0) {
state_ = FIN_SENT;