use std;
use std::os::raw::c_void;
use suricata_sys::sys::{AppProto, AppProtoEnum, SCLogLevel};
use crate::filecontainer::*;
use crate::flow::Flow;
pub enum DetectEngineState {}
pub enum AppLayerDecoderEvents {}
pub enum GenericVar {}
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[allow(non_camel_case_types)]
pub enum AppLayerEventType {
APP_LAYER_EVENT_TYPE_TRANSACTION = 1,
APP_LAYER_EVENT_TYPE_PACKET = 2,
}
pub const STREAM_START: u8 = 0x01;
pub const STREAM_EOF: u8 = 0x02;
pub const STREAM_TOSERVER: u8 = 0x04;
pub const STREAM_TOCLIENT: u8 = 0x08;
pub const STREAM_GAP: u8 = 0x10;
pub const STREAM_DEPTH: u8 = 0x20;
pub const STREAM_MIDSTREAM:u8 = 0x40;
pub const ALPROTO_UNKNOWN : AppProto = AppProtoEnum::ALPROTO_UNKNOWN as AppProto;
pub const ALPROTO_FAILED : AppProto = AppProtoEnum::ALPROTO_FAILED as AppProto;
pub const IPPROTO_TCP : u8 = 6;
pub const IPPROTO_UDP : u8 = 17;
macro_rules!BIT_U8 {
($x:expr) => (1 << $x);
}
macro_rules!BIT_U16 {
($x:expr) => (1 << $x);
}
macro_rules!BIT_U32 {
($x:expr) => (1 << $x);
}
macro_rules!BIT_U64 {
($x:expr) => (1 << $x);
}
extern "C" {
pub fn MpmAddPatternCI(
ctx: *const c_void, pat: *const libc::c_char, pat_len: u16, _offset: u16,
_depth: u16, id: u32, rule_id: u32, _flags: u8,
) -> c_void;
}
#[allow(non_snake_case)]
pub type SCLogMessageFunc =
extern "C" fn(level: SCLogLevel,
filename: *const std::os::raw::c_char,
line: std::os::raw::c_uint,
function: *const std::os::raw::c_char,
subsystem: *const std::os::raw::c_char,
message: *const std::os::raw::c_char) -> std::os::raw::c_int;
pub type DetectEngineStateFreeFunc =
extern "C" fn(state: *mut DetectEngineState);
pub type AppLayerParserTriggerRawStreamInspectionFunc =
extern "C" fn (flow: *mut Flow, direction: i32);
pub type AppLayerDecoderEventsSetEventRawFunc =
extern "C" fn (events: *mut *mut AppLayerDecoderEvents,
event: u8);
pub type AppLayerDecoderEventsFreeEventsFunc =
extern "C" fn (events: *mut *mut AppLayerDecoderEvents);
pub enum StreamingBufferConfig {}
pub enum HttpRangeContainerBlock {}
pub type SCHttpRangeFreeBlock = extern "C" fn (
c: *mut HttpRangeContainerBlock);
pub type SCHTPFileCloseHandleRange = extern "C" fn (
sbcfg: &StreamingBufferConfig,
fc: *mut FileContainer,
flags: u16,
c: *mut HttpRangeContainerBlock,
data: *const u8,
data_len: u32) -> bool;
pub type SCFileOpenFileWithId = extern "C" fn (
file_container: &FileContainer,
sbcfg: &StreamingBufferConfig,
track_id: u32,
name: *const u8, name_len: u16,
data: *const u8, data_len: u32,
flags: u16) -> i32;
pub type SCFileCloseFileById = extern "C" fn (
file_container: &FileContainer,
sbcfg: &StreamingBufferConfig,
track_id: u32,
data: *const u8, data_len: u32,
flags: u16) -> i32;
pub type SCFileAppendDataById = extern "C" fn (
file_container: &FileContainer,
sbcfg: &StreamingBufferConfig,
track_id: u32,
data: *const u8, data_len: u32) -> i32;
pub type SCFileAppendGAPById = extern "C" fn (
file_container: &FileContainer,
sbcfg: &StreamingBufferConfig,
track_id: u32,
data: *const u8, data_len: u32) -> i32;
pub type SCFileContainerRecycle = extern "C" fn (
file_container: &FileContainer,
sbcfg: &StreamingBufferConfig);
pub type GenericVarFreeFunc =
extern "C" fn(gvar: *mut GenericVar);
#[allow(non_snake_case)]
#[repr(C)]
pub struct SuricataContext {
pub SCLogMessage: SCLogMessageFunc,
DetectEngineStateFree: DetectEngineStateFreeFunc,
AppLayerDecoderEventsSetEventRaw: AppLayerDecoderEventsSetEventRawFunc,
AppLayerDecoderEventsFreeEvents: AppLayerDecoderEventsFreeEventsFunc,
pub AppLayerParserTriggerRawStreamInspection: AppLayerParserTriggerRawStreamInspectionFunc,
pub HttpRangeFreeBlock: SCHttpRangeFreeBlock,
pub HTPFileCloseHandleRange: SCHTPFileCloseHandleRange,
pub FileOpenFile: SCFileOpenFileWithId,
pub FileCloseFile: SCFileCloseFileById,
pub FileAppendData: SCFileAppendDataById,
pub FileAppendGAP: SCFileAppendGAPById,
pub FileContainerRecycle: SCFileContainerRecycle,
GenericVarFree: GenericVarFreeFunc,
}
#[allow(non_snake_case)]
#[repr(C)]
pub struct SuricataFileContext {
pub files_sbcfg: &'static StreamingBufferConfig,
}
extern "C" {
pub fn SCGetContext() -> &'static mut SuricataContext;
}
pub static mut SC: Option<&'static SuricataContext> = None;
pub fn init_ffi(context: &'static SuricataContext)
{
unsafe {
SC = Some(context);
}
}
#[no_mangle]
pub extern "C" fn SCRustInit(context: &'static SuricataContext)
{
init_ffi(context);
}
pub fn sc_detect_engine_state_free(state: *mut DetectEngineState)
{
unsafe {
if let Some(c) = SC {
(c.DetectEngineStateFree)(state);
}
}
}
pub fn sc_generic_var_free(gvar: *mut GenericVar)
{
unsafe {
if let Some(c) = SC {
(c.GenericVarFree)(gvar);
}
}
}
pub fn sc_app_layer_parser_trigger_raw_stream_inspection(flow: *mut Flow, direction: i32) {
unsafe {
if let Some(c) = SC {
(c.AppLayerParserTriggerRawStreamInspection)(flow, direction);
}
}
}
pub fn sc_app_layer_decoder_events_set_event_raw(
events: *mut *mut AppLayerDecoderEvents, event: u8)
{
unsafe {
if let Some(c) = SC {
(c.AppLayerDecoderEventsSetEventRaw)(events, event);
}
}
}
pub fn sc_app_layer_decoder_events_free_events(
events: *mut *mut AppLayerDecoderEvents)
{
unsafe {
if let Some(c) = SC {
(c.AppLayerDecoderEventsFreeEvents)(events);
}
}
}