From 428b06426ceb99fb09d398523ce4d1a5687610fe Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Mon, 13 Jul 2020 10:24:24 -0600 Subject: [PATCH] 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). (cherry picked from commit 53aa967e0b89417f2714fcbcbb6463be6ce8282e) --- rust/src/applayertemplate/template.rs | 1 + rust/src/dhcp/dhcp.rs | 1 + rust/src/ikev2/ikev2.rs | 1 + rust/src/krb/krb5.rs | 1 + rust/src/ntp/ntp.rs | 1 + rust/src/parser.rs | 2 ++ rust/src/rdp/rdp.rs | 1 + rust/src/sip/sip.rs | 1 + rust/src/snmp/snmp.rs | 1 + src/app-layer-register.c | 6 ++++++ src/app-layer-register.h | 2 ++ 11 files changed, 18 insertions(+) diff --git a/rust/src/applayertemplate/template.rs b/rust/src/applayertemplate/template.rs index bb02267f6c..760e67ced3 100644 --- a/rust/src/applayertemplate/template.rs +++ b/rust/src/applayertemplate/template.rs @@ -546,6 +546,7 @@ pub unsafe extern "C" fn rs_template_register_parser() { get_tx_iterator: Some(rs_template_state_get_tx_iterator), get_tx_detect_flags: None, set_tx_detect_flags: 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 6aa576669d..d09db6d1d8 100644 --- a/rust/src/dhcp/dhcp.rs +++ b/rust/src/dhcp/dhcp.rs @@ -454,6 +454,7 @@ pub unsafe extern "C" fn rs_dhcp_register_parser() { get_tx_iterator : Some(rs_dhcp_state_get_tx_iterator), set_tx_detect_flags: None, get_tx_detect_flags: None, + flags : 0, }; let ip_proto_str = CString::new("udp").unwrap(); diff --git a/rust/src/ikev2/ikev2.rs b/rust/src/ikev2/ikev2.rs index 0eaf9bcf9d..cac0a743a6 100644 --- a/rust/src/ikev2/ikev2.rs +++ b/rust/src/ikev2/ikev2.rs @@ -732,6 +732,7 @@ pub unsafe extern "C" fn rs_register_ikev2_parser() { get_tx_iterator : None, get_tx_detect_flags: None, set_tx_detect_flags: 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 4efb7719fe..0537d338bd 100644 --- a/rust/src/krb/krb5.rs +++ b/rust/src/krb/krb5.rs @@ -681,6 +681,7 @@ pub unsafe extern "C" fn rs_register_krb5_parser() { get_tx_iterator : None, get_tx_detect_flags: Some(rs_krb5_tx_detect_flags_get), set_tx_detect_flags: Some(rs_krb5_tx_detect_flags_set), + 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 ad3b519e9c..b6cda16534 100644 --- a/rust/src/ntp/ntp.rs +++ b/rust/src/ntp/ntp.rs @@ -431,6 +431,7 @@ pub unsafe extern "C" fn rs_register_ntp_parser() { get_tx_iterator : None, get_tx_detect_flags: None, set_tx_detect_flags: None, + flags : 0, }; let ip_proto_str = CString::new("udp").unwrap(); diff --git a/rust/src/parser.rs b/rust/src/parser.rs index 5dec9f2c32..b518c0623e 100644 --- a/rust/src/parser.rs +++ b/rust/src/parser.rs @@ -106,6 +106,8 @@ pub struct RustParser { // Function to get TX detect flags. pub get_tx_detect_flags: Option, + + pub flags: u32, } diff --git a/rust/src/rdp/rdp.rs b/rust/src/rdp/rdp.rs index 3b66935413..d97315b0bc 100644 --- a/rust/src/rdp/rdp.rs +++ b/rust/src/rdp/rdp.rs @@ -533,6 +533,7 @@ pub unsafe extern "C" fn rs_rdp_register_parser() { get_tx_iterator: None, get_tx_detect_flags: None, set_tx_detect_flags: None, + flags: 0, }; /* For 5.0 we want this disabled by default, so check that it diff --git a/rust/src/sip/sip.rs b/rust/src/sip/sip.rs index b33526003d..81caa3f237 100755 --- a/rust/src/sip/sip.rs +++ b/rust/src/sip/sip.rs @@ -424,6 +424,7 @@ pub unsafe extern "C" fn rs_sip_register_parser() { get_tx_iterator: None, get_tx_detect_flags: None, set_tx_detect_flags: None, + flags: 0, }; /* For 5.0 we want this disabled by default, so check that it diff --git a/rust/src/snmp/snmp.rs b/rust/src/snmp/snmp.rs index a3c5307c28..7b8dbeb0c3 100644 --- a/rust/src/snmp/snmp.rs +++ b/rust/src/snmp/snmp.rs @@ -614,6 +614,7 @@ pub unsafe extern "C" fn rs_register_snmp_parser() { get_tx_iterator : None, get_tx_detect_flags: Some(rs_snmp_get_tx_detect_flags), set_tx_detect_flags: Some(rs_snmp_set_tx_detect_flags), + flags : 0, }; let ip_proto_str = CString::new("udp").unwrap(); if AppLayerProtoDetectConfProtoDetectionEnabled(ip_proto_str.as_ptr(), parser.name) != 0 { diff --git a/src/app-layer-register.c b/src/app-layer-register.c index 3fd73c46d7..410f67b54e 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->GetTxDetectFlags, p->SetTxDetectFlags); } + 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 fbba2f3303..7f9765eeb9 100644 --- a/src/app-layer-register.h +++ b/src/app-layer-register.h @@ -74,6 +74,8 @@ typedef struct AppLayerParser { void (*SetTxDetectFlags)(void *, uint8_t, uint64_t); uint64_t (*GetTxDetectFlags)(void *, uint8_t); + + uint32_t flags; } AppLayerParser; /** -- 2.47.2