From: Russ Combs (rucombs) Date: Tue, 24 May 2022 17:49:09 +0000 (+0000) Subject: Pull request #3438: appid: do not delete third-party connection when third-party... X-Git-Tag: 3.1.31.0~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37472d77d4b51b6e207270bb955b9c6275520980;p=thirdparty%2Fsnort3.git Pull request #3438: appid: do not delete third-party connection when third-party reload is in progress and the context swap is not complete Merge in SNORT/snort3 from ~SATHIRKA/snort3:reload_tp_conn_delete to master Squashed commit of the following: commit 25910d3f6cce13f41c8115013306b588bbd50afe Author: Sreeja Athirkandathil Narayanan Date: Thu May 19 18:21:37 2022 -0400 appid: do not delete third-party connection when third-party reload is in progress and the context swap is not complete --- diff --git a/src/network_inspectors/appid/appid_discovery.cc b/src/network_inspectors/appid/appid_discovery.cc index 1aa54d6aa..9a982fb75 100644 --- a/src/network_inspectors/appid/appid_discovery.cc +++ b/src/network_inspectors/appid/appid_discovery.cc @@ -493,8 +493,7 @@ bool AppIdDiscovery::do_host_port_based_discovery(Packet* p, AppIdSession& asd, asd.client_disco_state = APPID_DISCO_STATE_FINISHED; asd.set_session_flags(APPID_SESSION_SERVICE_DETECTED); - if (asd.tpsession and tp_appid_ctxt and - (asd.tpsession->get_ctxt_version() == tp_appid_ctxt->get_version())) + if (asd.tpsession and asd.need_to_delete_tp_conn(tp_appid_ctxt)) asd.tpsession->reset(); else if (asd.tpsession) asd.tpsession->set_state(TP_STATE_TERMINATED); diff --git a/src/network_inspectors/appid/appid_session.cc b/src/network_inspectors/appid/appid_session.cc index 7e4cf57a6..b6fc19d58 100644 --- a/src/network_inspectors/appid/appid_session.cc +++ b/src/network_inspectors/appid/appid_session.cc @@ -165,9 +165,7 @@ AppIdSession::~AppIdSession() if (tpsession) { - if (pkt_thread_tp_appid_ctxt and - ((tpsession->get_ctxt_version() == pkt_thread_tp_appid_ctxt->get_version()) and - !ThirdPartyAppIdContext::get_tp_reload_in_progress())) + if (need_to_delete_tp_conn(pkt_thread_tp_appid_ctxt)) tpsession->delete_with_ctxt(); else delete tpsession; @@ -309,8 +307,7 @@ void AppIdSession::reinit_session_data(AppidChangeBits& change_bits, free_flow_data_by_mask(APPID_SESSION_DATA_CLIENT_MODSTATE_BIT); //3rd party cleaning - if (tpsession and curr_tp_appid_ctxt and - (tpsession->get_ctxt_version() == curr_tp_appid_ctxt->get_version())) + if (tpsession and need_to_delete_tp_conn(curr_tp_appid_ctxt)) tpsession->reset(); else if (tpsession) tpsession->set_state(TP_STATE_TERMINATED); @@ -963,8 +960,7 @@ void AppIdSession::reset_session_data(AppidChangeBits& change_bits) tp_payload_app_id = APP_ID_UNKNOWN; tp_app_id = APP_ID_UNKNOWN; - if (tpsession and pkt_thread_tp_appid_ctxt and - (tpsession->get_ctxt_version() == pkt_thread_tp_appid_ctxt->get_version())) + if (tpsession and need_to_delete_tp_conn(pkt_thread_tp_appid_ctxt)) tpsession->reset(); else if (tpsession) tpsession->set_state(TP_STATE_TERMINATED); @@ -1072,6 +1068,15 @@ bool AppIdSession::is_tp_appid_available() const return true; } +bool AppIdSession::need_to_delete_tp_conn(ThirdPartyAppIdContext* curr_tp_appid_ctxt) const +{ + // do not delete a third-party connection when reload third-party is in progress, and + // third-party context swap isn't complete; since all open connections will be deleted + // as part of the third-party reload pruning process. + return (curr_tp_appid_ctxt and ((tpsession->get_ctxt_version() == curr_tp_appid_ctxt->get_version()) and + !ThirdPartyAppIdContext::get_tp_reload_in_progress())); +} + void AppIdSession::set_tp_app_id(const Packet& p, AppidSessionDirection dir, AppId app_id, AppidChangeBits& change_bits) { diff --git a/src/network_inspectors/appid/appid_session.h b/src/network_inspectors/appid/appid_session.h index 792deb0d8..3c456a661 100644 --- a/src/network_inspectors/appid/appid_session.h +++ b/src/network_inspectors/appid/appid_session.h @@ -374,6 +374,8 @@ public: void publish_appid_event(AppidChangeBits&, const snort::Packet&, bool is_http2 = false, uint32_t http2_stream_index = 0); + bool need_to_delete_tp_conn(ThirdPartyAppIdContext*) const; + inline void set_tp_app_id(AppId app_id) { if (tp_app_id != app_id) diff --git a/src/network_inspectors/appid/test/appid_discovery_test.cc b/src/network_inspectors/appid/test/appid_discovery_test.cc index 39fdcc59e..418ef9c34 100644 --- a/src/network_inspectors/appid/test/appid_discovery_test.cc +++ b/src/network_inspectors/appid/test/appid_discovery_test.cc @@ -219,6 +219,7 @@ void AppIdSession::examine_ssl_metadata(AppidChangeBits&) {} void AppIdSession::update_encrypted_app_id(AppId) {} bool AppIdSession::is_tp_processing_done() const {return false;} AppId AppIdSession::pick_ss_payload_app_id(AppId) const { return get_payload_id(); } +bool AppIdSession::need_to_delete_tp_conn(ThirdPartyAppIdContext*) const { return true; } AppIdSession* AppIdSession::allocate_session(const Packet*, IpProtocol, AppidSessionDirection, AppIdInspector&, OdpContext&) {