From: Jason Ish Date: Mon, 13 Jul 2020 16:24:24 +0000 (-0600) Subject: applayer: add flags to parser registration struct X-Git-Tag: suricata-6.0.0-beta1~146 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53aa967e0b89417f2714fcbcbb6463be6ce8282e;p=thirdparty%2Fsuricata.git applayer: add flags to parser registration struct This will allow Rust parsers to register for gap handing from Rust (some Rust parsers do handle gaps, but they set the flag from C). --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 8c9bc521ae..40d9064aba 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -228,6 +228,8 @@ pub struct RustParser { // the requests and responses are not sharing tx. It is then up to // the implementation to make sure the config is applied correctly. pub apply_tx_config: Option, + + pub flags: u32, } /// Create a slice, given a buffer and a length diff --git a/rust/src/applayertemplate/template.rs b/rust/src/applayertemplate/template.rs index e356d3364a..1530046ef4 100644 --- a/rust/src/applayertemplate/template.rs +++ b/rust/src/applayertemplate/template.rs @@ -518,6 +518,7 @@ pub unsafe extern "C" fn rs_template_register_parser() { get_tx_iterator: Some(rs_template_state_get_tx_iterator), get_tx_data: rs_template_get_tx_data, apply_tx_config: None, + flags: 0, }; let ip_proto_str = CString::new("tcp").unwrap(); diff --git a/rust/src/dhcp/dhcp.rs b/rust/src/dhcp/dhcp.rs index 697cae680d..32e72e8de7 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_iterator : Some(rs_dhcp_state_get_tx_iterator), get_tx_data : rs_dhcp_get_tx_data, apply_tx_config : None, + flags : 0, }; let ip_proto_str = CString::new("udp").unwrap(); diff --git a/rust/src/dns/dns.rs b/rust/src/dns/dns.rs index e788106797..3d3ce4c953 100644 --- a/rust/src/dns/dns.rs +++ b/rust/src/dns/dns.rs @@ -1038,6 +1038,7 @@ pub unsafe extern "C" fn rs_dns_udp_register_parser() { set_de_state: rs_dns_state_set_tx_detect_state, get_tx_data: rs_dns_state_get_tx_data, apply_tx_config: Some(rs_dns_apply_tx_config), + flags: 0, }; let ip_proto_str = CString::new("udp").unwrap(); @@ -1083,6 +1084,7 @@ pub unsafe extern "C" fn rs_dns_tcp_register_parser() { set_de_state: rs_dns_state_set_tx_detect_state, get_tx_data: rs_dns_state_get_tx_data, apply_tx_config: Some(rs_dns_apply_tx_config), + flags: 0, }; let ip_proto_str = CString::new("tcp").unwrap(); diff --git a/rust/src/ikev2/ikev2.rs b/rust/src/ikev2/ikev2.rs index 25af1dc6e9..e1fbac57eb 100644 --- a/rust/src/ikev2/ikev2.rs +++ b/rust/src/ikev2/ikev2.rs @@ -712,6 +712,7 @@ pub unsafe extern "C" fn rs_register_ikev2_parser() { get_tx_iterator : None, get_tx_data : rs_ikev2_get_tx_data, apply_tx_config : None, + flags : 0, }; let ip_proto_str = CString::new("udp").unwrap(); diff --git a/rust/src/krb/krb5.rs b/rust/src/krb/krb5.rs index dd85db5daa..5e45505775 100644 --- a/rust/src/krb/krb5.rs +++ b/rust/src/krb/krb5.rs @@ -658,6 +658,7 @@ pub unsafe extern "C" fn rs_register_krb5_parser() { get_tx_iterator : None, get_tx_data : rs_krb5_get_tx_data, apply_tx_config : None, + flags : 0, }; // register UDP parser let ip_proto_str = CString::new("udp").unwrap(); diff --git a/rust/src/ntp/ntp.rs b/rust/src/ntp/ntp.rs index e045807548..27bf3a6296 100644 --- a/rust/src/ntp/ntp.rs +++ b/rust/src/ntp/ntp.rs @@ -408,6 +408,7 @@ pub unsafe extern "C" fn rs_register_ntp_parser() { get_tx_iterator : None, get_tx_data : rs_ntp_get_tx_data, apply_tx_config : None, + flags : 0, }; let ip_proto_str = CString::new("udp").unwrap(); diff --git a/rust/src/rdp/rdp.rs b/rust/src/rdp/rdp.rs index 3b0c66e9eb..b96da51226 100644 --- a/rust/src/rdp/rdp.rs +++ b/rust/src/rdp/rdp.rs @@ -534,6 +534,7 @@ pub unsafe extern "C" fn rs_rdp_register_parser() { get_tx_iterator: None, get_tx_data: rs_rdp_get_tx_data, apply_tx_config: None, + flags: 0, }; 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 77c2388d76..8cb251c724 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_iterator: Some(rs_rfb_state_get_tx_iterator), get_tx_data: rs_rfb_get_tx_data, apply_tx_config: None, + flags: 0, }; let ip_proto_str = CString::new("tcp").unwrap(); diff --git a/rust/src/sip/sip.rs b/rust/src/sip/sip.rs index 3d4be29112..eb642d700e 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_iterator: None, get_tx_data: rs_sip_get_tx_data, apply_tx_config: None, + flags: 0, }; let ip_proto_str = CString::new("udp").unwrap(); diff --git a/rust/src/snmp/snmp.rs b/rust/src/snmp/snmp.rs index bb07c5a27a..f71da30ab1 100644 --- a/rust/src/snmp/snmp.rs +++ b/rust/src/snmp/snmp.rs @@ -586,6 +586,7 @@ pub unsafe extern "C" fn rs_register_snmp_parser() { get_tx_iterator : None, get_tx_data : rs_snmp_get_tx_data, apply_tx_config : None, + flags : 0, }; 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 a801cd61e8..71e01f60d5 100644 --- a/rust/src/ssh/ssh.rs +++ b/rust/src/ssh/ssh.rs @@ -560,6 +560,7 @@ pub unsafe extern "C" fn rs_ssh_register_parser() { get_tx_iterator: None, get_tx_data: rs_ssh_get_tx_data, apply_tx_config: None, + flags: 0, }; let ip_proto_str = CString::new("tcp").unwrap(); diff --git a/src/app-layer-register.c b/src/app-layer-register.c index 961f0dfcb4..e999c67ef3 100644 --- a/src/app-layer-register.c +++ b/src/app-layer-register.c @@ -176,6 +176,12 @@ int AppLayerRegisterParser(const struct AppLayerParser *p, AppProto alproto) p->ApplyTxConfig); } + if (p->flags) { + AppLayerParserRegisterOptionFlags(p->ip_proto, alproto, + p->flags); + + } + return 0; } diff --git a/src/app-layer-register.h b/src/app-layer-register.h index 41f1d460c2..29aba9d417 100644 --- a/src/app-layer-register.h +++ b/src/app-layer-register.h @@ -68,6 +68,8 @@ typedef struct AppLayerParser { AppLayerTxData *(*GetTxData)(void *tx); bool (*ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig); + + uint32_t flags; } AppLayerParser; /**