From: Mike Stepanek (mstepane) Date: Fri, 27 Sep 2019 16:32:18 +0000 (-0400) Subject: Merge pull request #1769 in SNORT/snort3 from ~THOPETER/snort3:small_seg2 to master X-Git-Tag: 3.0.0-262~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0a012699b81e85f79bb76742c5ac0b70c36e322;p=thirdparty%2Fsnort3.git Merge pull request #1769 in SNORT/snort3 from ~THOPETER/snort3:small_seg2 to master Squashed commit of the following: commit 9e8b9922d6aa9046b0eaa320af3d35679698060a Author: Tom Peters Date: Thu Sep 19 17:04:44 2019 -0400 stream: cleanup --- diff --git a/src/stream/libtcp/tcp_segment_descriptor.cc b/src/stream/libtcp/tcp_segment_descriptor.cc index 5986dc92f..443bd9a9a 100644 --- a/src/stream/libtcp/tcp_segment_descriptor.cc +++ b/src/stream/libtcp/tcp_segment_descriptor.cc @@ -31,18 +31,17 @@ using namespace snort; -TcpSegmentDescriptor::TcpSegmentDescriptor(Flow* flow, Packet* pkt, TcpEventLogger& tel) : - flow(flow), pkt(pkt) +TcpSegmentDescriptor::TcpSegmentDescriptor(Flow* flow_, Packet* pkt_, TcpEventLogger& tel) : + flow(flow_), + pkt(pkt_), + tcph(pkt->ptrs.tcph), + src_port(tcph->src_port()), + dst_port(tcph->dst_port()), + seg_seq(tcph->seq()), + seg_ack(tcph->ack()), + seg_wnd(tcph->win()), + end_seq(seg_seq + (uint32_t)pkt->dsize) { - tcph = pkt->ptrs.tcph; - src_port = tcph->src_port(); - dst_port = tcph->dst_port(); - seg_seq = tcph->seq(); - seg_ack = tcph->ack(); - seg_wnd = tcph->win(); - end_seq = seg_seq + (uint32_t)pkt->dsize; - ts = 0; - // don't bump end_seq for fin here we will bump if/when fin is processed if ( tcph->is_syn() ) { diff --git a/src/stream/libtcp/tcp_segment_descriptor.h b/src/stream/libtcp/tcp_segment_descriptor.h index 30c5181df..7e2fe2035 100644 --- a/src/stream/libtcp/tcp_segment_descriptor.h +++ b/src/stream/libtcp/tcp_segment_descriptor.h @@ -54,7 +54,7 @@ public: void set_seg_seq(uint32_t seq) { - this->seg_seq = seq; + seg_seq = seq; } void update_seg_seq(int32_t offset) @@ -94,7 +94,7 @@ public: void scale_seg_wnd(uint16_t wscale) { - this->seg_wnd <<= wscale; + seg_wnd <<= wscale; } uint32_t get_seg_wnd() const @@ -124,11 +124,13 @@ public: void set_seg_len(uint16_t seg_len) { + // Reset segment size to seg_len pkt->dsize = seg_len; } void update_seg_len(int32_t offset) { + // Increase segment size by offset pkt->dsize += offset; } @@ -139,23 +141,24 @@ public: void slide_segment_in_rcv_window(int32_t offset) { + // This actually deletes the first offset bytes of the segment, no sliding involved seg_seq += offset; pkt->data += offset; pkt->dsize -= offset; } private: - snort::Flow* flow; - snort::Packet* pkt; + snort::Flow* const flow; + snort::Packet* const pkt; - const snort::tcp::TCPHdr* tcph; - uint16_t src_port; - uint16_t dst_port; + const snort::tcp::TCPHdr* const tcph; + const uint16_t src_port; + const uint16_t dst_port; uint32_t seg_seq; - uint32_t seg_ack; + const uint32_t seg_ack; uint32_t seg_wnd; uint32_t end_seq; - uint32_t ts; + uint32_t ts = 0; }; #endif diff --git a/src/stream/libtcp/tcp_state_machine.cc b/src/stream/libtcp/tcp_state_machine.cc index 9b1d88794..a8bbdd653 100644 --- a/src/stream/libtcp/tcp_state_machine.cc +++ b/src/stream/libtcp/tcp_state_machine.cc @@ -47,17 +47,17 @@ void TcpStateMachine::register_state_handler(TcpStreamTracker::TcpState state, bool TcpStateMachine::eval(TcpSegmentDescriptor& tsd, TcpStreamTracker& talker, TcpStreamTracker& listener) { - TcpStreamTracker::TcpState tcp_state = talker.get_tcp_state( ); + const TcpStreamTracker::TcpState talker_state = talker.get_tcp_state( ); talker.set_tcp_event(tsd); - if ( tcp_state_handlers[ tcp_state ]->do_pre_sm_packet_actions(tsd, talker) ) + if ( tcp_state_handlers[ talker_state ]->do_pre_sm_packet_actions(tsd, talker) ) { - if ( tcp_state_handlers[ tcp_state ]->eval(tsd, talker) ) + if ( tcp_state_handlers[ talker_state ]->eval(tsd, talker) ) { - tcp_state = listener.get_tcp_state( ); + const TcpStreamTracker::TcpState listener_state = listener.get_tcp_state( ); listener.set_tcp_event(tsd); - tcp_state_handlers[ tcp_state ]->eval(tsd, listener); - tcp_state_handlers[ tcp_state ]->do_post_sm_packet_actions(tsd, listener); + tcp_state_handlers[ listener_state ]->eval(tsd, listener); + tcp_state_handlers[ listener_state ]->do_post_sm_packet_actions(tsd, listener); return true; } diff --git a/src/stream/libtcp/tcp_stream_session.cc b/src/stream/libtcp/tcp_stream_session.cc index 9da3ba3aa..f6619bf95 100644 --- a/src/stream/libtcp/tcp_stream_session.cc +++ b/src/stream/libtcp/tcp_stream_session.cc @@ -244,7 +244,7 @@ void TcpStreamSession::update_direction(char dir, const SfIp* ip, uint16_t port) flow->server_port = tmpPort; SwapPacketHeaderFoo( ); - TcpStreamTracker& tracker = client; + TcpStreamTracker tracker = client; client = server; server = tracker; } diff --git a/src/stream/libtcp/tcp_stream_tracker.h b/src/stream/libtcp/tcp_stream_tracker.h index 50104c608..fd26b6846 100644 --- a/src/stream/libtcp/tcp_stream_tracker.h +++ b/src/stream/libtcp/tcp_stream_tracker.h @@ -121,7 +121,7 @@ public: { return rcv_nxt; } void set_rcv_nxt(uint32_t rcv_nxt) - { this->rcv_nxt = rcv_nxt; } + { this->rcv_nxt = rcv_nxt; } uint32_t get_rcv_wnd() const { return rcv_wnd; } @@ -200,9 +200,8 @@ public: bool is_ack_valid(uint32_t cur) { - // FIXIT-H do we need this check? we've always seen something by the time we get here // If we haven't seen anything, ie, low & high are 0, return true - if ( ( snd_una == 0 ) && ( snd_una == snd_nxt ) ) + if ( ( snd_una == 0 ) && ( snd_nxt == 0 ) ) return true; return ( SEQ_GEQ(cur, snd_una) && SEQ_LEQ(cur, snd_nxt) ); diff --git a/src/stream/tcp/stream_tcp.cc b/src/stream/tcp/stream_tcp.cc index b973ab7e8..8dedb1960 100644 --- a/src/stream/tcp/stream_tcp.cc +++ b/src/stream/tcp/stream_tcp.cc @@ -49,13 +49,10 @@ public: NORETURN_ASSERT void eval(Packet*) override; public: - TcpStreamConfig* config; + TcpStreamConfig* const config; }; -StreamTcp::StreamTcp (TcpStreamConfig* c) -{ - config = c; -} +StreamTcp::StreamTcp (TcpStreamConfig* c) : config(c) {} StreamTcp::~StreamTcp() { diff --git a/src/stream/tcp/tcp_session.cc b/src/stream/tcp/tcp_session.cc index 269f4b18c..e09fa3764 100644 --- a/src/stream/tcp/tcp_session.cc +++ b/src/stream/tcp/tcp_session.cc @@ -96,7 +96,7 @@ bool TcpSession::setup(Packet* p) TcpStreamSession::setup(p); splitter_init = false; - TcpStreamConfig* pc = get_tcp_cfg(flow->ssn_server); + const TcpStreamConfig* pc = get_tcp_cfg(flow->ssn_server); flow->set_default_session_timeout(pc->session_timeout, false); SESSION_STATS_ADD(tcpStats); diff --git a/src/stream/tcp/tcp_stream_config.cc b/src/stream/tcp/tcp_stream_config.cc index c62fea4c8..f3383a9cf 100644 --- a/src/stream/tcp/tcp_stream_config.cc +++ b/src/stream/tcp/tcp_stream_config.cc @@ -35,12 +35,12 @@ static const char* const reassembly_policy_names[] = TcpStreamConfig::TcpStreamConfig() = default; -void TcpStreamConfig::show_config() +void TcpStreamConfig::show_config() const { TcpStreamConfig::show_config(this); } -void TcpStreamConfig::show_config(TcpStreamConfig* config) +void TcpStreamConfig::show_config(const TcpStreamConfig* config) { LogMessage("Stream TCP Policy config:\n"); LogMessage(" Reassembly Policy: %s\n", diff --git a/src/stream/tcp/tcp_stream_config.h b/src/stream/tcp/tcp_stream_config.h index 6409ad5a5..b30dccfec 100644 --- a/src/stream/tcp/tcp_stream_config.h +++ b/src/stream/tcp/tcp_stream_config.h @@ -50,8 +50,8 @@ public: return false; } - void show_config(); - static void show_config(TcpStreamConfig*); + void show_config() const; + static void show_config(const TcpStreamConfig*); StreamPolicy policy = StreamPolicy::OS_DEFAULT; ReassemblyPolicy reassembly_policy = ReassemblyPolicy::OS_DEFAULT; diff --git a/src/stream/tcp/tcp_stream_state_machine.h b/src/stream/tcp/tcp_stream_state_machine.h index b9271f09d..45ccda06c 100644 --- a/src/stream/tcp/tcp_stream_state_machine.h +++ b/src/stream/tcp/tcp_stream_state_machine.h @@ -35,7 +35,6 @@ public: private: TcpStreamStateMachine(); - }; #endif diff --git a/src/stream/udp/udp_session.cc b/src/stream/udp/udp_session.cc index df1fe1ca4..cb81e4064 100644 --- a/src/stream/udp/udp_session.cc +++ b/src/stream/udp/udp_session.cc @@ -152,7 +152,7 @@ void UdpSession::update_direction( { if ((dir == SSN_DIR_FROM_CLIENT) && (flow->ssn_state.direction == FROM_CLIENT)) { - /* Direction already set as CLIENT */ + // Direction already set as CLIENT return; } } @@ -160,12 +160,12 @@ void UdpSession::update_direction( { if ((dir == SSN_DIR_FROM_SERVER) && (flow->ssn_state.direction == FROM_SERVER)) { - /* Direction already set as SERVER */ + // Direction already set as SERVER return; } } - /* Swap them -- leave flow->ssn_state.direction the same */ + // Swap them -- leave flow->ssn_state.direction the same tmpIp = flow->client_ip; tmpPort = flow->client_port; flow->client_ip = flow->server_ip;