]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
src: remove truncate fn and glue code
authorShivani Bhardwaj <shivani@oisf.net>
Fri, 5 Jul 2024 11:59:45 +0000 (17:29 +0530)
committerVictor Julien <victor@inliniac.net>
Fri, 12 Jul 2024 08:47:46 +0000 (10:47 +0200)
truncate fn is only active and used by dcerpc and smb parsers. In case
stream depth is reached for any side, truncate fn is supposed to set the
tx entity (request/response) in the same direction as complete so the
other side is not forever waiting for data.

However, whether the stream depth is reached is already checked by
AppLayerParserGetStateProgress fn which is called by:
- DetectTx
- DetectEngineInspectBufferGeneric
- AppLayerParserSetTransactionInspectId
- OutputTxLog
- AppLayerParserTransactionsCleanup

and, in such a case, StateGetProgressCompletionStatus is returned for
the respective direction. This fn following efc9a7a, always returns 1
as long as the direction is valid meaning that the progress for the
current direction is marked complete. So, there is no need for the additional
callback to mark the entities as done in case of depth or a gap.
Remove all such glue code and callbacks for truncate fns.

Bug 7044

29 files changed:
rust/src/applayer.rs
rust/src/applayertemplate/template.rs
rust/src/bittorrent_dht/bittorrent_dht.rs
rust/src/dcerpc/dcerpc.rs
rust/src/dcerpc/dcerpc_udp.rs
rust/src/dhcp/dhcp.rs
rust/src/dns/dns.rs
rust/src/enip/enip.rs
rust/src/http2/http2.rs
rust/src/ike/ike.rs
rust/src/krb/krb5.rs
rust/src/modbus/modbus.rs
rust/src/mqtt/mqtt.rs
rust/src/nfs/nfs.rs
rust/src/ntp/ntp.rs
rust/src/pgsql/pgsql.rs
rust/src/quic/quic.rs
rust/src/rdp/rdp.rs
rust/src/rfb/rfb.rs
rust/src/sip/sip.rs
rust/src/smb/smb.rs
rust/src/snmp/snmp.rs
rust/src/ssh/ssh.rs
rust/src/telnet/telnet.rs
rust/src/websocket/websocket.rs
src/app-layer-parser.c
src/app-layer-parser.h
src/app-layer-register.c
src/app-layer-register.h

index 46fbbd55604fbcebdd720e8e311ca4bcb6be4413..187245917ab63351248d12aed332c4d1e2054ee0 100644 (file)
@@ -394,10 +394,6 @@ pub struct RustParser {
 
     pub flags: u32,
 
-    /// Function to handle the end of data coming on one of the sides
-    /// due to the stream reaching its 'depth' limit.
-    pub truncate: Option<TruncateFn>,
-
     pub get_frame_id_by_name: Option<GetFrameIdByName>,
     pub get_frame_name_by_id: Option<GetFrameNameById>,
 }
@@ -458,7 +454,6 @@ pub type GetTxIteratorFn    = unsafe extern "C" fn (ipproto: u8, alproto: AppPro
 pub type GetTxDataFn = unsafe extern "C" fn(*mut c_void) -> *mut AppLayerTxData;
 pub type GetStateDataFn = unsafe extern "C" fn(*mut c_void) -> *mut AppLayerStateData;
 pub type ApplyTxConfigFn = unsafe extern "C" fn (*mut c_void, *mut c_void, c_int, AppLayerTxConfig);
-pub type TruncateFn = unsafe extern "C" fn (*mut c_void, u8);
 pub type GetFrameIdByName = unsafe extern "C" fn(*const c_char) -> c_int;
 pub type GetFrameNameById = unsafe extern "C" fn(u8) -> *const c_char;
 
index e8cdc27dfe912596f3f9348b6184c11aab9b2f3f..43a8bf940006451f680e20e26ffaf462babe71f8 100644 (file)
@@ -427,7 +427,6 @@ pub unsafe extern "C" fn rs_template_register_parser() {
         get_state_data: rs_template_get_state_data,
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
-        truncate: None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index 61eefb9e29af792d529be8c8262aa6640163c412..f48cb3d2bf28cea330816b5f611a44f3eb001e65 100644 (file)
@@ -282,7 +282,6 @@ pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() {
         get_state_data: rs_bittorrent_dht_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index 3a1af7df5316fe0060890162b810347dc4a28ee1..bb82ad33be43565bfbb538b2771b55930a64c64a 100644 (file)
@@ -322,8 +322,6 @@ pub struct DCERPCState {
     pub tc_gap: bool,
     pub ts_ssn_gap: bool,
     pub tc_ssn_gap: bool,
-    pub ts_ssn_trunc: bool, /// true if Truncated in this direction
-    pub tc_ssn_trunc: bool,
     pub flow: Option<*const core::Flow>,
     state_data: AppLayerStateData,
 }
@@ -354,8 +352,6 @@ impl DCERPCState {
         tx.call_id = call_id;
         tx.endianness = endianness;
         self.tx_id += 1;
-        tx.req_done = self.ts_ssn_trunc;
-        tx.resp_done = self.tc_ssn_trunc;
         if self.transactions.len() > unsafe { DCERPC_MAX_TX } {
             let mut index = self.tx_index_completed;
             for tx_old in &mut self.transactions.range_mut(self.tx_index_completed..) {
@@ -1187,33 +1183,6 @@ pub unsafe extern "C" fn rs_dcerpc_state_transaction_free(state: *mut std::os::r
     dce_state.free_tx(tx_id);
 }
 
-#[no_mangle]
-pub unsafe extern "C" fn rs_dcerpc_state_trunc(state: *mut std::os::raw::c_void, direction: u8) {
-    let dce_state = cast_pointer!(state, DCERPCState);
-    match direction.into() {
-        Direction::ToServer =>  {
-            dce_state.ts_ssn_trunc = true;
-            for tx in &mut dce_state.transactions {
-                tx.req_done = true;
-                if let Some(flow) = dce_state.flow {
-                    sc_app_layer_parser_trigger_raw_stream_reassembly(flow, Direction::ToServer as i32);
-                }
-            }
-            SCLogDebug!("dce_state.ts_ssn_trunc = true; txs {}", dce_state.transactions.len());
-        }
-        Direction::ToClient => {
-            dce_state.tc_ssn_trunc = true;
-            for tx in &mut dce_state.transactions {
-                tx.resp_done = true;
-                if let Some(flow) = dce_state.flow {
-                    sc_app_layer_parser_trigger_raw_stream_reassembly(flow, Direction::ToClient as i32);
-                }
-            }
-            SCLogDebug!("dce_state.tc_ssn_trunc = true; txs {}", dce_state.transactions.len());
-        }
-    }
-}
-
 #[no_mangle]
 pub unsafe extern "C" fn rs_dcerpc_get_tx(
     vtx: *mut std::os::raw::c_void, tx_id: u64,
@@ -1367,7 +1336,6 @@ pub unsafe extern "C" fn rs_dcerpc_register_parser() {
         get_state_data: rs_dcerpc_get_state_data,
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
-        truncate: None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index 2007c867bfae090e97e766727830a1da4007c85c..ab7f65cafbadf8935fb6197212734cd6caa73a84 100644 (file)
@@ -374,7 +374,6 @@ pub unsafe extern "C" fn rs_dcerpc_udp_register_parser() {
         get_state_data: rs_dcerpc_udp_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index e43d4e863a6045b26dc9af0c1f2042fb6141956f..5b6f4b4a085ae9c401ee606bcfcb7aae5cfc359a 100644 (file)
@@ -298,7 +298,6 @@ pub unsafe extern "C" fn rs_dhcp_register_parser() {
         get_state_data     : rs_dhcp_get_state_data,
         apply_tx_config    : None,
         flags              : 0,
-        truncate           : None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index ea12b43ac3aab4188fa5fec4c9882a48483095b4..1c1358a9f352a45136155e52f73269207bcc863f 100644 (file)
@@ -995,7 +995,6 @@ pub unsafe extern "C" fn SCRegisterDnsUdpParser() {
         get_state_data: rs_dns_get_state_data,
         apply_tx_config: Some(apply_tx_config),
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: Some(DnsFrameType::ffi_id_from_name),
         get_frame_name_by_id: Some(DnsFrameType::ffi_name_from_id),
     };
@@ -1041,7 +1040,6 @@ pub unsafe extern "C" fn SCRegisterDnsTcpParser() {
         get_state_data: rs_dns_get_state_data,
         apply_tx_config: Some(apply_tx_config),
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
-        truncate: None,
         get_frame_id_by_name: Some(DnsFrameType::ffi_id_from_name),
         get_frame_name_by_id: Some(DnsFrameType::ffi_name_from_id),
     };
index 26f11140dc3a84f23132a3b78488aaa00bdede09..05ec13a670d9e4d13c759816b1daa7d03cde06dc 100644 (file)
@@ -612,7 +612,6 @@ pub unsafe extern "C" fn SCEnipRegisterParsers() {
         get_state_data: SCEnipTxGetState_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: Some(EnipFrameType::ffi_id_from_name),
         get_frame_name_by_id: Some(EnipFrameType::ffi_name_from_id),
     };
index 6a5b3936c981eea9946e862f953ea5b9a15146cf..2e41c2967aa7c34e11cf567d32955899b2ccd11b 100644 (file)
@@ -1366,7 +1366,6 @@ pub unsafe extern "C" fn rs_http2_register_parser() {
         get_state_data: rs_http2_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index 2a5448ab27cfeb0a5f06371d4611f8cb259ed5ec..df62c19cb4ffd241583bba58d6f8eecf80def2db 100644 (file)
@@ -424,7 +424,6 @@ pub unsafe extern "C" fn rs_ike_register_parser() {
         get_state_data: rs_ike_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index aceeb86d2b470a4395c819dc8013847e7c78a859..51b215ca30d1317898a4880518bb140245bec7ed 100644 (file)
@@ -609,7 +609,6 @@ pub unsafe extern "C" fn rs_register_krb5_parser() {
         get_state_data     : rs_krb5_get_state_data,
         apply_tx_config    : None,
         flags              : 0,
-        truncate           : None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index 02e2bcfd035dabede24b3737c47d7aa3df19bf88..0d0c73371ef03ab033d3db7fa87656ec8bccaf59 100644 (file)
@@ -407,7 +407,6 @@ pub unsafe extern "C" fn rs_modbus_register_parser() {
         get_state_data: rs_modbus_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index 1fa6280c6da822e512599ca9cadc428eee94c08d..c52802625ee68dd22c950d569d29736c33527d09 100644 (file)
@@ -790,7 +790,6 @@ pub unsafe extern "C" fn SCMqttRegisterParser() {
         get_state_data: rs_mqtt_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: Some(MQTTFrameType::ffi_id_from_name),
         get_frame_name_by_id: Some(MQTTFrameType::ffi_name_from_id),
     };
index 19d8d93cecce4ee87a238d9f3a1dbbbd9b51bd42..d4b472e1f69c4f55ecec1d14bb77c275aa3028b5 100644 (file)
@@ -1989,7 +1989,6 @@ pub unsafe extern "C" fn rs_nfs_register_parser() {
         get_state_data: rs_nfs_get_state_data,
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
-        truncate: None,
         get_frame_id_by_name: Some(NFSFrameType::ffi_id_from_name),
         get_frame_name_by_id: Some(NFSFrameType::ffi_name_from_id),
     };
@@ -2067,7 +2066,6 @@ pub unsafe extern "C" fn rs_nfs_udp_register_parser() {
         get_state_data: rs_nfs_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: Some(NFSFrameType::ffi_id_from_name),
         get_frame_name_by_id: Some(NFSFrameType::ffi_name_from_id),
     };
index 3a06cfb8b14a6ec20defcbf4f40809a8b3ed60d9..ae723bbb21cd1bd9aa5f005bcae3b89cd7ad26fd 100644 (file)
@@ -300,7 +300,6 @@ pub unsafe extern "C" fn rs_register_ntp_parser() {
         get_state_data     : rs_ntp_get_state_data,
         apply_tx_config    : None,
         flags              : 0,
-        truncate           : None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index bd76346f80ec7ca36aafac25cc835a8e0995f779..1873be5a75322c64151be25238d7e7bfb08f7b49 100644 (file)
@@ -761,7 +761,6 @@ pub unsafe extern "C" fn rs_pgsql_register_parser() {
         get_state_data: rs_pgsql_get_state_data,
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
-        truncate: None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index 330b0f8d379d0e37e677e0efca1321692ba92c49..bc58afe21974524a992b62468b45d09f1644b764 100644 (file)
@@ -508,7 +508,6 @@ pub unsafe extern "C" fn rs_quic_register_parser() {
         get_state_data: rs_quic_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index 2899f99c182400c428bec9f99f26032f60641002..25b5ee381a63bb1a0a71619707ac79f737547ecf 100644 (file)
@@ -493,7 +493,6 @@ pub unsafe extern "C" fn rs_rdp_register_parser() {
         get_state_data: rs_rdp_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index c17455bc06544f3f03b31ee2742168f31e2e877e..6e923cab55ce74fb3796c074d625c7a4c5dcc5da 100644 (file)
@@ -860,7 +860,6 @@ pub unsafe extern "C" fn rs_rfb_register_parser() {
         get_state_data: rs_rfb_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: Some(RFBFrameType::ffi_id_from_name),
         get_frame_name_by_id: Some(RFBFrameType::ffi_name_from_id),
     };
index 6d38c8fd7e4f8c67e658acf908c864e518fdc7a9..38f76fb277ac30569922e521881cdb91a20e899d 100755 (executable)
@@ -570,7 +570,6 @@ pub unsafe extern "C" fn rs_sip_register_parser() {
         get_state_data: rs_sip_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: Some(SIPFrameType::ffi_id_from_name),
         get_frame_name_by_id: Some(SIPFrameType::ffi_name_from_id),
     };
index 56e1685e307902206326e8f028521d081cf3a5d0..0d35d6debb3eb19eed0c54766277d3d1ca0bd738 100644 (file)
@@ -2201,23 +2201,6 @@ pub unsafe extern "C" fn rs_smb_get_tx_data(
     return &mut tx.tx_data;
 }
 
-
-#[no_mangle]
-pub unsafe extern "C" fn rs_smb_state_truncate(
-        state: *mut std::ffi::c_void,
-        direction: u8)
-{
-    let state = cast_pointer!(state, SMBState);
-    match direction.into() {
-        Direction::ToServer => {
-            state.trunc_ts();
-        }
-        Direction::ToClient => {
-            state.trunc_tc();
-        }
-    }
-}
-
 #[no_mangle]
 pub unsafe extern "C" fn rs_smb_state_get_event_info_by_id(
     event_id: std::os::raw::c_int,
@@ -2327,7 +2310,6 @@ pub unsafe extern "C" fn rs_smb_register_parser() {
         get_state_data: rs_smb_get_state_data,
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
-        truncate: Some(rs_smb_state_truncate),
         get_frame_id_by_name: Some(SMBFrameType::ffi_id_from_name),
         get_frame_name_by_id: Some(SMBFrameType::ffi_name_from_id),
     };
index b4bb6321a3ec3871f20a90e71d43629d7f159496..4e1afd0566e37581a3ffd43ff0af4ae2a9a96c98 100644 (file)
@@ -406,7 +406,6 @@ pub unsafe extern "C" fn rs_register_snmp_parser() {
         get_state_data     : rs_snmp_get_state_data,
         apply_tx_config    : None,
         flags              : 0,
-        truncate           : None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index c1f08a904c4da81faf9ca2ae4f50d3d1fbd7f408..d5341a2cfb19b34a6d0826697c366eb50d087c54 100644 (file)
@@ -464,7 +464,6 @@ pub unsafe extern "C" fn rs_ssh_register_parser() {
         get_state_data: rs_ssh_get_state_data,
         apply_tx_config: None,
         flags: 0,
-        truncate: None,
         get_frame_id_by_name: None,
         get_frame_name_by_id: None,
     };
index 2a63b73321358892ffc98db99bb05f6522f958a1..29b02a9b7f417e1b829d50a15460fbd059c3a69c 100644 (file)
@@ -537,7 +537,6 @@ pub unsafe extern "C" fn rs_telnet_register_parser() {
         get_state_data: rs_telnet_get_state_data,
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
-        truncate: None,
         get_frame_id_by_name: Some(TelnetFrameType::ffi_id_from_name),
         get_frame_name_by_id: Some(TelnetFrameType::ffi_name_from_id),
 
index 26747525fbb2df8d02e508eeb82984a6058e47fd..ebbe901a53b0e1c3544e3bdaca7b33218f48c228 100644 (file)
@@ -366,7 +366,6 @@ pub unsafe extern "C" fn rs_websocket_register_parser() {
         get_state_data: rs_websocket_get_state_data,
         apply_tx_config: None,
         flags: 0, // do not accept gaps as there is no good way to resync
-        truncate: None,
         get_frame_id_by_name: Some(WebSocketFrameType::ffi_id_from_name),
         get_frame_name_by_id: Some(WebSocketFrameType::ffi_name_from_id),
     };
index 90533268437a475d894dad7e3722db9fe268c0cb..cbd42c9015ee37f39600106cb1ca631df4465150 100644 (file)
@@ -83,8 +83,6 @@ typedef struct AppLayerParserProtoCtx_
     void *(*LocalStorageAlloc)(void);
     void (*LocalStorageFree)(void *);
 
-    void (*Truncate)(void *, uint8_t);
-
     /** get FileContainer reference from the TX. MUST return a non-NULL reference if the TX
      *  has or may have files in the requested direction at some point. */
     AppLayerGetFileState (*GetTxFiles)(void *, uint8_t);
@@ -465,16 +463,6 @@ void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
     SCReturn;
 }
 
-void AppLayerParserRegisterTruncateFunc(uint8_t ipproto, AppProto alproto,
-                                        void (*Truncate)(void *, uint8_t))
-{
-    SCEnter();
-
-    alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate = Truncate;
-
-    SCReturn;
-}
-
 void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto,
     int (*StateGetProgress)(void *alstate, uint8_t direction))
 {
index 540d4a2b06ff0578db727dbc0f7f6de3372b53c3..18f5cce70f588a452343dd6e3f0207cb661a9026 100644 (file)
@@ -182,8 +182,6 @@ void AppLayerParserRegisterGetTxFilesFunc(
         uint8_t ipproto, AppProto alproto, AppLayerGetFileState (*GetTxFiles)(void *, uint8_t));
 void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto);
 void AppLayerParserRegisterLoggerBits(uint8_t ipproto, AppProto alproto, LoggerId bits);
-void AppLayerParserRegisterTruncateFunc(uint8_t ipproto, AppProto alproto,
-                             void (*Truncate)(void *, uint8_t));
 void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto,
     int (*StateGetStateProgress)(void *alstate, uint8_t direction));
 void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto,
index c4441d9f7c5b48c29d514a0a75a48c546129659e..1e4986b361ea4d37ac1424693ec0f79cd07ba207 100644 (file)
@@ -183,10 +183,6 @@ int AppLayerRegisterParser(const struct AppLayerParser *p, AppProto alproto)
 
     }
 
-    if (p->Truncate) {
-        AppLayerParserRegisterTruncateFunc(p->ip_proto, alproto, p->Truncate);
-    }
-
     if (p->GetFrameIdByName && p->GetFrameNameById) {
         AppLayerParserRegisterGetFrameFuncs(
                 p->ip_proto, alproto, p->GetFrameIdByName, p->GetFrameNameById);
index eda9628f9890734753c2dd042cee1d6363139ce5..78eff7d8e4cefae50a3a56e9105648ac5a571c89 100644 (file)
@@ -71,8 +71,6 @@ typedef struct AppLayerParser {
 
     uint32_t flags;
 
-    void (*Truncate)(void *state, uint8_t direction);
-
     AppLayerParserGetFrameIdByNameFn GetFrameIdByName;
     AppLayerParserGetFrameNameByIdFn GetFrameNameById;