rust: bindgen SCAppLayerRegisterProtocolDetection

Ticket: 7662

Changing the struct passed to it to have the minimal number
of useful fields.
pull/14462/head
Philippe Antoine 9 months ago committed by Victor Julien
parent 91c9e34419
commit b4d8aea0ae

@ -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);

@ -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::<Self>::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,

@ -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;

@ -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.

Loading…
Cancel
Save