From: Mike Stepanek (mstepane) Date: Tue, 1 Oct 2019 14:56:05 +0000 (-0400) Subject: Merge pull request #1774 in SNORT/snort3 from ~THOPETER/snort3:small_seg3 to master X-Git-Tag: 3.0.0-262~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87b4225b2b2f7a97cc8a066a87f7e15115978772;p=thirdparty%2Fsnort3.git Merge pull request #1774 in SNORT/snort3 from ~THOPETER/snort3:small_seg3 to master Squashed commit of the following: commit 48284a400a9d8f852f529a5439ab7bf4178756bb Author: Tom Peters Date: Fri Sep 27 15:26:18 2019 -0400 stream: clean up update_direction --- diff --git a/src/flow/session.h b/src/flow/session.h index 25979ebf0..c7fbec0eb 100644 --- a/src/flow/session.h +++ b/src/flow/session.h @@ -40,7 +40,11 @@ public: virtual ~Session() = default; virtual bool setup(snort::Packet*) { return true; } - virtual void update_direction(char /*dir*/, const snort::SfIp*, uint16_t /*port*/) { } + virtual void update_direction(char /*dir*/, const snort::SfIp*, uint16_t /*port*/) + { + // UDP is currently the only stream that implements this. Others should not be calling. + assert(false); + } virtual int process(snort::Packet*) { return 0; } virtual void restart(snort::Packet*) { } diff --git a/src/flow/test/session_test.cc b/src/flow/test/session_test.cc index 9020101f4..24830e0b8 100644 --- a/src/flow/test/session_test.cc +++ b/src/flow/test/session_test.cc @@ -51,7 +51,6 @@ TEST(session_test, seesion_class_test) Session *ssn = new DummySession(nullptr); CHECK(true == ssn->setup(nullptr)); - ssn->update_direction(1, nullptr, 1234); CHECK(0 == ssn->process(nullptr)); ssn->restart(nullptr); ssn->flush_client(nullptr); diff --git a/src/stream/icmp/icmp_session.cc b/src/stream/icmp/icmp_session.cc index 3c4d6b642..48d3d5a86 100644 --- a/src/stream/icmp/icmp_session.cc +++ b/src/stream/icmp/icmp_session.cc @@ -230,31 +230,3 @@ int IcmpSession::process(Packet* p) return status; } -#define icmp_sender_ip flow->client_ip -#define icmp_responder_ip flow->server_ip - -void IcmpSession::update_direction(char dir, const SfIp* ip, uint16_t) -{ - if (icmp_sender_ip.equals(*ip)) - { - if ((dir == SSN_DIR_FROM_CLIENT) && (flow->ssn_state.direction == FROM_CLIENT)) - { - /* Direction already set as SENDER */ - return; - } - } - else if (icmp_responder_ip.equals(*ip)) - { - if ((dir == SSN_DIR_FROM_SERVER) && (flow->ssn_state.direction == FROM_SERVER)) - { - /* Direction already set as RESPONDER */ - return; - } - } - - /* Swap them -- leave ssn->ssn_state.direction the same */ - SfIp tmpIp = icmp_sender_ip; - icmp_sender_ip = icmp_responder_ip; - icmp_responder_ip = tmpIp; -} - diff --git a/src/stream/icmp/icmp_session.h b/src/stream/icmp/icmp_session.h index e0d35612f..33b496933 100644 --- a/src/stream/icmp/icmp_session.h +++ b/src/stream/icmp/icmp_session.h @@ -29,7 +29,6 @@ public: ~IcmpSession() override; bool setup(snort::Packet*) override; - void update_direction(char dir, const snort::SfIp*, uint16_t port) override; int process(snort::Packet*) override; void clear() override; diff --git a/src/stream/libtcp/tcp_stream_session.cc b/src/stream/libtcp/tcp_stream_session.cc index f6619bf95..843b8ee9a 100644 --- a/src/stream/libtcp/tcp_stream_session.cc +++ b/src/stream/libtcp/tcp_stream_session.cc @@ -213,42 +213,6 @@ bool TcpStreamSession::are_packets_missing(uint8_t dir) return false; } -void TcpStreamSession::update_direction(char dir, const SfIp* ip, uint16_t port) -{ - SfIp tmpIp; - uint16_t tmpPort; - - if (flow->client_ip.equals(*ip) && (flow->client_port == port)) - { - if ((dir == SSN_DIR_FROM_CLIENT) && (flow->ssn_state.direction == FROM_CLIENT)) - { - /* Direction already set as client */ - return; - } - } - else if (flow->server_ip.equals(*ip) && (flow->server_port == port)) - { - if ((dir == SSN_DIR_FROM_SERVER) && (flow->ssn_state.direction == FROM_SERVER)) - { - /* Direction already set as server */ - return; - } - } - - /* Swap them -- leave flow->ssn_state.direction the same */ - tmpIp = flow->client_ip; - tmpPort = flow->client_port; - flow->client_ip = flow->server_ip; - flow->client_port = flow->server_port; - flow->server_ip = tmpIp; - flow->server_port = tmpPort; - - SwapPacketHeaderFoo( ); - TcpStreamTracker tracker = client; - client = server; - server = tracker; -} - // FIXIT-H add alert and check alerted go away when we finish // packet / PDU split because PDU rules won't run on raw packets bool TcpStreamSession::add_alert(Packet* p, uint32_t gid, uint32_t sid) diff --git a/src/stream/libtcp/tcp_stream_session.h b/src/stream/libtcp/tcp_stream_session.h index d09ae2be0..78994af4c 100644 --- a/src/stream/libtcp/tcp_stream_session.h +++ b/src/stream/libtcp/tcp_stream_session.h @@ -50,7 +50,6 @@ public: bool are_packets_missing(uint8_t /*dir*/) override; uint8_t get_reassembly_direction() override; uint8_t missing_in_reassembled(uint8_t /*dir*/) override; - void update_direction(char dir, const snort::SfIp*, uint16_t port) override; bool add_alert(snort::Packet*, uint32_t gid, uint32_t sid) override; bool check_alerted(snort::Packet*, uint32_t gid, uint32_t sid) override; int update_alert(snort::Packet*, uint32_t /*gid*/, uint32_t /*sid*/, diff --git a/src/stream/stream.cc b/src/stream/stream.cc index 13d9f0d02..3c051a65d 100644 --- a/src/stream/stream.cc +++ b/src/stream/stream.cc @@ -268,15 +268,6 @@ void Stream::resume_inspection(Flow* flow, char dir) } } -void Stream::update_direction( - Flow* flow, char dir, const SfIp* ip, uint16_t port) -{ - if (!flow) - return; - - flow->session->update_direction(dir, ip, port); -} - uint32_t Stream::get_packet_direction(Packet* p) { if (!p || !(p->flow)) diff --git a/src/stream/stream.h b/src/stream/stream.h index fa03fe236..ee68fd387 100644 --- a/src/stream/stream.h +++ b/src/stream/stream.h @@ -204,8 +204,6 @@ public: // Populate a session key from the Packet static void populate_flow_key(Packet*, FlowKey*); - static void update_direction(Flow*, char dir, const snort::SfIp* ip, uint16_t port); - static void set_snort_protocol_id( Flow*, const HostAttributeEntry*, int direction); diff --git a/src/stream/user/user_session.cc b/src/stream/user/user_session.cc index 8fc38a1f9..96e432a0a 100644 --- a/src/stream/user/user_session.cc +++ b/src/stream/user/user_session.cc @@ -516,8 +516,6 @@ int UserSession::process(Packet* p) // some will be deleted, some refactored, some implemented //------------------------------------------------------------------------- -void UserSession::update_direction(char /*dir*/, const SfIp*, uint16_t /*port*/) { } - bool UserSession::add_alert(Packet*, uint32_t /*gid*/, uint32_t /*sid*/) { return true; } bool UserSession::check_alerted(Packet*, uint32_t /*gid*/, uint32_t /*sid*/) { return false; } diff --git a/src/stream/user/user_session.h b/src/stream/user/user_session.h index 2f263f255..c27623415 100644 --- a/src/stream/user/user_session.h +++ b/src/stream/user/user_session.h @@ -101,8 +101,6 @@ private: void update(snort::Packet*, snort::Flow*); void end(snort::Packet*, snort::Flow*); - void update_direction(char dir, const snort::SfIp*, uint16_t port) override; - bool add_alert(snort::Packet*, uint32_t gid, uint32_t sid) override; bool check_alerted(snort::Packet*, uint32_t gid, uint32_t sid) override;