diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index c7a434c60e..da8def4a9e 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -534,10 +534,24 @@ pub type GetStateNameById = unsafe extern "C" fn(c_int, u8) -> *const c_char; #[allow(unused_doc_comments)] /// cbindgen:ignore extern "C" { - pub fn AppLayerRegisterProtocolDetection(parser: *const RustParser, enable_default: c_int) -> AppProto; pub fn AppLayerRegisterParser(parser: *const RustParser, alproto: AppProto) -> c_int; } +use suricata_sys::sys::{AppLayerProtocolDetect, SCAppLayerRegisterProtocolDetection}; + +pub fn AppLayerRegisterProtocolDetection(parser: &RustParser, enable_default: c_int) -> AppProto { + let det = AppLayerProtocolDetect{ + name: parser.name, + default_port: parser.default_port, + ip_proto: parser.ipproto, + ProbeTS: parser.probe_ts, + ProbeTC: parser.probe_tc, + min_depth: parser.min_depth, + max_depth: parser.max_depth, + }; + unsafe {SCAppLayerRegisterProtocolDetection(&det, enable_default) } +} + // Defined in app-layer-parser.h pub const APP_LAYER_PARSER_NO_INSPECTION : u16 = BIT_U16!(1); diff --git a/rust/sys/src/sys.rs b/rust/sys/src/sys.rs index fed5b460b7..3cf71e047b 100644 --- a/rust/sys/src/sys.rs +++ b/rust/sys/src/sys.rs @@ -939,6 +939,38 @@ extern "C" { extern "C" { pub fn FileApplyTxFlags(txd: *const AppLayerTxData, direction: u8, file: *mut File); } +#[doc = " First part of AppLayerParser, needed only for protocol detection"] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct AppLayerProtocolDetect { + #[doc = " name of the app-layer"] + pub name: *const ::std::os::raw::c_char, + #[doc = " default port(s)"] + pub default_port: *const ::std::os::raw::c_char, + #[doc = " ip protocol : TCP or UDP"] + pub ip_proto: u8, + #[doc = " probing parser to server"] + pub ProbeTS: ProbingParserFPtr, + #[doc = " probing parser to client"] + pub ProbeTC: ProbingParserFPtr, + pub min_depth: u16, + pub max_depth: u16, +} +impl Default for AppLayerProtocolDetect { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +extern "C" { + #[doc = " \\brief App layer protocol detection function.\n\n \\param parser The parser declaration structure.\n \\param enable_default A boolean to indicate if default port configuration should be used if none given\n\n \\retval The AppProto constant if successful. On error, this function never returns."] + pub fn SCAppLayerRegisterProtocolDetection( + parser: *const AppLayerProtocolDetect, enable_default: ::std::os::raw::c_int, + ) -> AppProto; +} extern "C" { pub fn SCAppLayerRegisterParserAlias( proto_name: *const ::std::os::raw::c_char, proto_alias: *const ::std::os::raw::c_char, diff --git a/src/app-layer-register.c b/src/app-layer-register.c index 48c8442b22..a69caa4b70 100644 --- a/src/app-layer-register.c +++ b/src/app-layer-register.c @@ -36,7 +36,8 @@ static const char * IpProtoToString(int ip_proto); -AppProto AppLayerRegisterProtocolDetection(const struct AppLayerParser *p, int enable_default) +AppProto SCAppLayerRegisterProtocolDetection( + const struct AppLayerProtocolDetect *p, int enable_default) { AppProto alproto; const char *ip_proto_str = NULL; diff --git a/src/app-layer-register.h b/src/app-layer-register.h index 6294496c1a..33cd49a22d 100644 --- a/src/app-layer-register.h +++ b/src/app-layer-register.h @@ -78,6 +78,22 @@ typedef struct AppLayerParser { AppLayerParserGetStateNameByIdFn GetStateNameById; } AppLayerParser; +/// First part of AppLayerParser, needed only for protocol detection +typedef struct AppLayerProtocolDetect { + /// name of the app-layer + const char *name; + /// default port(s) + const char *default_port; + /// ip protocol : TCP or UDP + uint8_t ip_proto; + /// probing parser to server + ProbingParserFPtr ProbeTS; + /// probing parser to client + ProbingParserFPtr ProbeTC; + uint16_t min_depth; + uint16_t max_depth; +} AppLayerProtocolDetect; + /** * \brief App layer protocol detection function. * @@ -86,7 +102,8 @@ typedef struct AppLayerParser { * * \retval The AppProto constant if successful. On error, this function never returns. */ -AppProto AppLayerRegisterProtocolDetection(const struct AppLayerParser *parser, int enable_default); +AppProto SCAppLayerRegisterProtocolDetection( + const struct AppLayerProtocolDetect *parser, int enable_default); /** * \brief App layer protocol registration function.