]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
applayer/rust: expose truncate callback
authorVictor Julien <victor@inliniac.net>
Sat, 19 Sep 2020 18:25:05 +0000 (20:25 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 25 Sep 2020 05:24:59 +0000 (07:24 +0200)
16 files changed:
rust/src/applayer.rs
rust/src/applayertemplate/template.rs
rust/src/dhcp/dhcp.rs
rust/src/dns/dns.rs
rust/src/http2/http2.rs
rust/src/ikev2/ikev2.rs
rust/src/krb/krb5.rs
rust/src/mqtt/mqtt.rs
rust/src/ntp/ntp.rs
rust/src/rdp/rdp.rs
rust/src/rfb/rfb.rs
rust/src/sip/sip.rs
rust/src/snmp/snmp.rs
rust/src/ssh/ssh.rs
src/app-layer-register.c
src/app-layer-register.h

index d1086c7bc0cfc87e8c5f19d784013787775de2c7..8eacadcc00894e029063814bc586d33c3da3fb7f 100644 (file)
@@ -230,6 +230,10 @@ pub struct RustParser {
     pub apply_tx_config: Option<ApplyTxConfigFn>,
 
     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>,
 }
 
 /// Create a slice, given a buffer and a length
@@ -279,6 +283,8 @@ pub type GetTxIteratorFn    = extern "C" fn (ipproto: u8, alproto: AppProto,
                                              -> AppLayerGetTxIterTuple;
 pub type GetTxDataFn = unsafe extern "C" fn(*mut c_void) -> *mut AppLayerTxData;
 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);
+
 
 // Defined in app-layer-register.h
 extern {
index 09a57fb806fb762c8854a121ff032400846d27c9..25576b51c49d65cf187c1edcf1116d4de2b15437 100644 (file)
@@ -549,6 +549,7 @@ pub unsafe extern "C" fn rs_template_register_parser() {
         get_tx_data: rs_template_get_tx_data,
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
+        truncate: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index 6db2e5cf0cf880a4035c504824e2a59a64559a73..07cc702bbd7907691db38f95746b29fd2cd231d9 100644 (file)
@@ -437,6 +437,7 @@ pub unsafe extern "C" fn rs_dhcp_register_parser() {
         get_tx_data        : rs_dhcp_get_tx_data,
         apply_tx_config    : None,
         flags              : 0,
+        truncate           : None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
index c1824cb8006cb68677ac9004d5e47ed4892f4729..89f32e8e6703aa1d159ab2ca773d7da9e675cedb 100644 (file)
@@ -1086,6 +1086,7 @@ pub unsafe extern "C" fn rs_dns_udp_register_parser() {
         get_tx_data: rs_dns_state_get_tx_data,
         apply_tx_config: Some(rs_dns_apply_tx_config),
         flags: APP_LAYER_PARSER_OPT_UNIDIR_TXS,
+        truncate: None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
@@ -1130,6 +1131,7 @@ pub unsafe extern "C" fn rs_dns_tcp_register_parser() {
         get_tx_data: rs_dns_state_get_tx_data,
         apply_tx_config: Some(rs_dns_apply_tx_config),
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS | APP_LAYER_PARSER_OPT_UNIDIR_TXS,
+        truncate: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index 055fbfe7be45128039589e703ca7676494aaca79..ece5d990f71a6a9118f4474b29139626faf26501 100644 (file)
@@ -1108,6 +1108,7 @@ pub unsafe extern "C" fn rs_http2_register_parser() {
         get_tx_data: rs_http2_get_tx_data,
         apply_tx_config: None,
         flags: 0,
+        truncate: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index f027c584c95ed47341ed74b5ded58d76410a8a8a..5aafea1db7553d38e6fd9279a491deebceb9a3ab 100644 (file)
@@ -711,6 +711,7 @@ pub unsafe extern "C" fn rs_register_ikev2_parser() {
         get_tx_data        : rs_ikev2_get_tx_data,
         apply_tx_config    : None,
         flags              : 0,
+        truncate           : None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
index 84b8187f2be84cbc207223ed3509f78d6dba6ae7..620e11b0319b2b073782bc2ceb154bd5aba59afd 100644 (file)
@@ -657,6 +657,7 @@ pub unsafe extern "C" fn rs_register_krb5_parser() {
         get_tx_data        : rs_krb5_get_tx_data,
         apply_tx_config    : None,
         flags              : 0,
+        truncate           : None,
     };
     // register UDP parser
     let ip_proto_str = CString::new("udp").unwrap();
index 0da856e1c1d37f4665f046d962d33e28def2dc37..96b11af235d086d6ab191d84c9f9adf85d5a99a1 100644 (file)
@@ -829,6 +829,7 @@ pub unsafe extern "C" fn rs_mqtt_register_parser(cfg_max_msg_len: u32) {
         get_tx_data: rs_mqtt_get_tx_data,
         apply_tx_config: None,
         flags: 0,
+        truncate: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index b76e9237c75c39175acf309405a555c070738501..8dee98f0a01d93644d23cee6231947e18d881a84 100644 (file)
@@ -407,6 +407,7 @@ pub unsafe extern "C" fn rs_register_ntp_parser() {
         get_tx_data        : rs_ntp_get_tx_data,
         apply_tx_config    : None,
         flags              : 0,
+        truncate           : None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
index 8b8d1345661f2077f1b3ce8f882839871962e871..976ff71b37b67d0ae42ac972f8943c71e9539afc 100644 (file)
@@ -488,6 +488,7 @@ pub unsafe extern "C" fn rs_rdp_register_parser() {
         get_tx_data: rs_rdp_get_tx_data,
         apply_tx_config: None,
         flags: 0,
+        truncate: None,
     };
 
     let ip_proto_str = std::ffi::CString::new("tcp").unwrap();
index bdd0dd784d9bbf4a9c749285f536f51add6b93eb..aa18ab5d4021b110f5a5e3f41d7f2d1c9b077b88 100644 (file)
@@ -700,6 +700,7 @@ pub unsafe extern "C" fn rs_rfb_register_parser() {
         get_tx_data: rs_rfb_get_tx_data,
         apply_tx_config: None,
         flags: 0,
+        truncate: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index b44461d84e95759654df6ddd4f6618b73c924d2f..986a15fce8c72aa4ce968dc70c65c80e7991ed8c 100755 (executable)
@@ -393,6 +393,7 @@ pub unsafe extern "C" fn rs_sip_register_parser() {
         get_tx_data: rs_sip_get_tx_data,
         apply_tx_config: None,
         flags: 0,
+        truncate: None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
index a96e4a25dc8036cb205d6d5f586071c635d99985..1171db8ea9e7e05611cbebac6735ae92d449a4e8 100644 (file)
@@ -585,6 +585,7 @@ pub unsafe extern "C" fn rs_register_snmp_parser() {
         get_tx_data        : rs_snmp_get_tx_data,
         apply_tx_config    : None,
         flags              : 0,
+        truncate           : None,
     };
     let ip_proto_str = CString::new("udp").unwrap();
     if AppLayerProtoDetectConfProtoDetectionEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
index 34e62bf763afef8aa4dc598d437081cdaa12a288..c58c4b47cd17753663e1e32ed66f645ba4b509ed 100644 (file)
@@ -566,6 +566,7 @@ pub unsafe extern "C" fn rs_ssh_register_parser() {
         get_tx_data: rs_ssh_get_tx_data,
         apply_tx_config: None,
         flags: 0,
+        truncate: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index 8da006f0f9540ba25e98714d90257c8021221166..234246b527e711791d734f5a06b2c270c3f737b1 100644 (file)
@@ -182,6 +182,10 @@ int AppLayerRegisterParser(const struct AppLayerParser *p, AppProto alproto)
 
     }
 
+    if (p->Truncate) {
+        AppLayerParserRegisterTruncateFunc(p->ip_proto, alproto, p->Truncate);
+    }
+
     return 0;
 }
 
index 7e5ef8c1f191fec4633a3037ce2c03f848f0b5d9..47da98dadef082d07e030084fd02352d597c7c6c 100644 (file)
@@ -70,6 +70,9 @@ typedef struct AppLayerParser {
     bool (*ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig);
 
     uint32_t flags;
+
+    void (*Truncate)(void *state, uint8_t direction);
+
 } AppLayerParser;
 
 /**