From: Victor Julien Date: Sat, 19 Sep 2020 18:25:05 +0000 (+0200) Subject: applayer/rust: expose truncate callback X-Git-Tag: suricata-6.0.0~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4da0d9bdea50f75f302e16038ad9a31ed79ad008;p=thirdparty%2Fsuricata.git applayer/rust: expose truncate callback --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index d1086c7bc0..8eacadcc00 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -230,6 +230,10 @@ pub struct RustParser { pub apply_tx_config: Option, 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, } /// 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 { diff --git a/rust/src/applayertemplate/template.rs b/rust/src/applayertemplate/template.rs index 09a57fb806..25576b51c4 100644 --- a/rust/src/applayertemplate/template.rs +++ b/rust/src/applayertemplate/template.rs @@ -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(); diff --git a/rust/src/dhcp/dhcp.rs b/rust/src/dhcp/dhcp.rs index 6db2e5cf0c..07cc702bbd 100644 --- a/rust/src/dhcp/dhcp.rs +++ b/rust/src/dhcp/dhcp.rs @@ -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(); diff --git a/rust/src/dns/dns.rs b/rust/src/dns/dns.rs index c1824cb800..89f32e8e67 100644 --- a/rust/src/dns/dns.rs +++ b/rust/src/dns/dns.rs @@ -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(); diff --git a/rust/src/http2/http2.rs b/rust/src/http2/http2.rs index 055fbfe7be..ece5d990f7 100644 --- a/rust/src/http2/http2.rs +++ b/rust/src/http2/http2.rs @@ -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(); diff --git a/rust/src/ikev2/ikev2.rs b/rust/src/ikev2/ikev2.rs index f027c584c9..5aafea1db7 100644 --- a/rust/src/ikev2/ikev2.rs +++ b/rust/src/ikev2/ikev2.rs @@ -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(); diff --git a/rust/src/krb/krb5.rs b/rust/src/krb/krb5.rs index 84b8187f2b..620e11b031 100644 --- a/rust/src/krb/krb5.rs +++ b/rust/src/krb/krb5.rs @@ -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(); diff --git a/rust/src/mqtt/mqtt.rs b/rust/src/mqtt/mqtt.rs index 0da856e1c1..96b11af235 100644 --- a/rust/src/mqtt/mqtt.rs +++ b/rust/src/mqtt/mqtt.rs @@ -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(); diff --git a/rust/src/ntp/ntp.rs b/rust/src/ntp/ntp.rs index b76e9237c7..8dee98f0a0 100644 --- a/rust/src/ntp/ntp.rs +++ b/rust/src/ntp/ntp.rs @@ -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(); diff --git a/rust/src/rdp/rdp.rs b/rust/src/rdp/rdp.rs index 8b8d134566..976ff71b37 100644 --- a/rust/src/rdp/rdp.rs +++ b/rust/src/rdp/rdp.rs @@ -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(); diff --git a/rust/src/rfb/rfb.rs b/rust/src/rfb/rfb.rs index bdd0dd784d..aa18ab5d40 100644 --- a/rust/src/rfb/rfb.rs +++ b/rust/src/rfb/rfb.rs @@ -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(); diff --git a/rust/src/sip/sip.rs b/rust/src/sip/sip.rs index b44461d84e..986a15fce8 100755 --- a/rust/src/sip/sip.rs +++ b/rust/src/sip/sip.rs @@ -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(); diff --git a/rust/src/snmp/snmp.rs b/rust/src/snmp/snmp.rs index a96e4a25dc..1171db8ea9 100644 --- a/rust/src/snmp/snmp.rs +++ b/rust/src/snmp/snmp.rs @@ -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 { diff --git a/rust/src/ssh/ssh.rs b/rust/src/ssh/ssh.rs index 34e62bf763..c58c4b47cd 100644 --- a/rust/src/ssh/ssh.rs +++ b/rust/src/ssh/ssh.rs @@ -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(); diff --git a/src/app-layer-register.c b/src/app-layer-register.c index 8da006f0f9..234246b527 100644 --- a/src/app-layer-register.c +++ b/src/app-layer-register.c @@ -182,6 +182,10 @@ int AppLayerRegisterParser(const struct AppLayerParser *p, AppProto alproto) } + if (p->Truncate) { + AppLayerParserRegisterTruncateFunc(p->ip_proto, alproto, p->Truncate); + } + return 0; } diff --git a/src/app-layer-register.h b/src/app-layer-register.h index 7e5ef8c1f1..47da98dade 100644 --- a/src/app-layer-register.h +++ b/src/app-layer-register.h @@ -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; /**