From ebdeb038bb7f13efad526dbabd2cacae679f2b4c Mon Sep 17 00:00:00 2001 From: "Davis McPherson (davmcphe)" Date: Tue, 30 Jul 2019 15:16:43 -0400 Subject: [PATCH] Merge pull request #1686 in SNORT/snort3 from ~SBAIGAL/snort3:noack_api to master Squashed commit of the following: commit aae5c979ba07cd80103d0a5c05acbefca4840bfe Author: Steven Baigal (sbaigal) Date: Thu Jul 18 15:30:44 2019 -0400 stream_tcp: add API for switching no_ack mode add assert to make sure the session is tcp --- src/stream/libtcp/tcp_stream_session.h | 5 +++++ src/stream/stream.cc | 8 ++++++++ src/stream/stream.h | 1 + src/stream/tcp/tcp_session.cc | 3 +++ src/stream/tcp/tcp_state_established.cc | 4 ++-- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/stream/libtcp/tcp_stream_session.h b/src/stream/libtcp/tcp_stream_session.h index 9c0979236..d09ae2be0 100644 --- a/src/stream/libtcp/tcp_stream_session.h +++ b/src/stream/libtcp/tcp_stream_session.h @@ -67,6 +67,8 @@ public: void SetPacketHeaderFoo(const snort::Packet* p); void GetPacketHeaderFoo(DAQ_PktHdr_t* pkth, uint32_t dir); void SwapPacketHeaderFoo(); + void set_no_ack(bool b) { no_ack = b; } + bool no_ack_mode_enabled() { return no_ack; } virtual void update_perf_base_state(char) { } virtual void clear_session( @@ -148,6 +150,9 @@ public: TcpStreamConfig* config = nullptr; TcpEventLogger tel; +private: + bool no_ack = false; + protected: TcpStreamSession(snort::Flow*); virtual void set_os_policy() = 0; diff --git a/src/stream/stream.cc b/src/stream/stream.cc index 405b941f5..0e3ee4fab 100644 --- a/src/stream/stream.cc +++ b/src/stream/stream.cc @@ -810,6 +810,14 @@ bool Stream::set_packet_action_to_hold(Packet* p) return p->flow->session->set_packet_action_to_hold(p); } +void Stream::set_no_ack_mode(Flow* flow, bool on_off) +{ + assert(flow and flow->session and flow->pkt_type == PktType::TCP); + + TcpStreamSession* tcp_session = (TcpStreamSession*)flow->session; + tcp_session->set_no_ack(on_off); +} + #ifdef UNIT_TEST TEST_CASE("Stream API", "[stream_api][stream]") diff --git a/src/stream/stream.h b/src/stream/stream.h index 4168f4d18..fa03fe236 100644 --- a/src/stream/stream.h +++ b/src/stream/stream.h @@ -233,6 +233,7 @@ public: static uint8_t get_tcp_options_len(Flow*, bool to_server); static bool set_packet_action_to_hold(Packet*); + static void set_no_ack_mode(Flow*, bool); private: static void set_ip_protocol(Flow*); diff --git a/src/stream/tcp/tcp_session.cc b/src/stream/tcp/tcp_session.cc index 5700889c5..5abc53534 100644 --- a/src/stream/tcp/tcp_session.cc +++ b/src/stream/tcp/tcp_session.cc @@ -1023,7 +1023,10 @@ int TcpSession::process(Packet* p) // FIXIT-H need to do something here to handle check for need to swap trackers?? if ( !config ) + { config = get_tcp_cfg(flow->ssn_server); + set_no_ack(config->no_ack); + } if( !tcp_init ) set_os_policy( ); diff --git a/src/stream/tcp/tcp_state_established.cc b/src/stream/tcp/tcp_state_established.cc index ad97cb3b1..cde765901 100644 --- a/src/stream/tcp/tcp_state_established.cc +++ b/src/stream/tcp/tcp_state_established.cc @@ -79,7 +79,7 @@ bool TcpStateEstablished::ack_recv(TcpSegmentDescriptor& tsd, TcpStreamTracker& bool TcpStateEstablished::data_seg_sent(TcpSegmentDescriptor& tsd, TcpStreamTracker& trk) { trk.update_tracker_ack_sent(tsd); - if ( trk.session->config->no_ack ) + if ( trk.session->no_ack_mode_enabled() ) trk.update_tracker_no_ack_recv(tsd); return true; } @@ -88,7 +88,7 @@ bool TcpStateEstablished::data_seg_recv(TcpSegmentDescriptor& tsd, TcpStreamTrac { trk.update_tracker_ack_recv(tsd); trk.session->handle_data_segment(tsd); - if ( trk.session->config->no_ack ) + if ( trk.session->no_ack_mode_enabled() ) trk.update_tracker_no_ack_sent(tsd); return true; } -- 2.47.3