rust: bindgen more file functions

Ticket: 7762
pull/14387/head
Philippe Antoine 9 months ago committed by Victor Julien
parent 327b8b04a9
commit cddbd0b906

@ -142,7 +142,7 @@ if HAVE_BINDGEN
--with-derive-default \
--allowlist-type 'AppProto.*' \
--allowlist-function 'AppProto.*' \
--allowlist-function 'FileAppendData' \
--allowlist-function 'File.*' \
--allowlist-type 'SC.*' \
--allowlist-function 'SC.*' \
--allowlist-var 'SC.*' \

@ -17,54 +17,16 @@
//! This module handles file container operations (open, append, close).
use std::os::raw::c_void;
use std::ptr;
use crate::core::*;
#[repr(C)]
#[derive(Debug)]
pub struct FileContainer {
head: *mut c_void,
tail: *mut c_void,
}
impl Default for FileContainer {
fn default() -> Self {
Self {
head: ptr::null_mut(),
tail: ptr::null_mut(),
}
}
}
// Defined in util-file.h
#[allow(unused_doc_comments)]
/// cbindgen:ignore
extern "C" {
#[cfg(not(test))]
pub fn FileContainerRecycle(file_container: &mut FileContainer, sbcfg: &StreamingBufferConfig);
#[cfg(not(test))]
pub fn FileAppendGAPById(
file_container: &mut FileContainer, sbcfg: &StreamingBufferConfig, track_id: u32,
data: *const u8, data_len: u32,
) -> i32;
#[cfg(not(test))]
pub fn FileAppendDataById(
file_container: &mut FileContainer, sbcfg: &StreamingBufferConfig, track_id: u32,
data: *const u8, data_len: u32,
) -> i32;
#[cfg(not(test))]
pub fn FileCloseFileById(
file_container: &mut FileContainer, sbcfg: &StreamingBufferConfig, track_id: u32,
data: *const u8, data_len: u32, flags: u16,
) -> i32;
#[cfg(not(test))]
pub fn FileOpenFileWithId(
file_container: &mut FileContainer, sbcfg: &StreamingBufferConfig, track_id: u32,
name: *const u8, name_len: u16, data: *const u8, data_len: u32, flags: u16,
) -> i32;
}
pub use suricata_sys::sys::FileContainer;
#[cfg(not(test))]
use suricata_sys::sys::{
FileAppendDataById, FileAppendGAPById, FileCloseFileById, FileContainerRecycle,
FileOpenFileWithId,
};
#[cfg(test)]
#[allow(non_snake_case)]
@ -103,15 +65,26 @@ pub(super) unsafe fn FileOpenFileWithId(
0
}
impl FileContainer {
pub fn free(&mut self, cfg: &'static SuricataFileContext) {
pub trait FileContainerWrapper {
fn free(&mut self, cfg: &'static SuricataFileContext);
fn file_open(
&mut self, cfg: &'static SuricataFileContext, track_id: u32, name: &[u8], flags: u16,
) -> i32;
fn file_append(
&mut self, cfg: &'static SuricataFileContext, track_id: &u32, data: &[u8], is_gap: bool,
) -> i32;
fn file_close(&mut self, cfg: &'static SuricataFileContext, track_id: &u32, flags: u16) -> i32;
}
impl FileContainerWrapper for FileContainer {
fn free(&mut self, cfg: &'static SuricataFileContext) {
SCLogDebug!("freeing self");
unsafe {
FileContainerRecycle(self, cfg.files_sbcfg);
}
}
pub fn file_open(
fn file_open(
&mut self, cfg: &'static SuricataFileContext, track_id: u32, name: &[u8], flags: u16,
) -> i32 {
SCLogDebug!("FILE {:p} OPEN flags {:04X}", &self, flags);
@ -130,7 +103,7 @@ impl FileContainer {
}
}
pub fn file_append(
fn file_append(
&mut self, cfg: &'static SuricataFileContext, track_id: &u32, data: &[u8], is_gap: bool,
) -> i32 {
SCLogDebug!("FILECONTAINER: append {}", data.len());
@ -166,9 +139,7 @@ impl FileContainer {
res
}
pub fn file_close(
&mut self, cfg: &'static SuricataFileContext, track_id: &u32, flags: u16,
) -> i32 {
fn file_close(&mut self, cfg: &'static SuricataFileContext, track_id: &u32, flags: u16) -> i32 {
SCLogDebug!("FILECONTAINER: CLOSEing");
unsafe { FileCloseFileById(self, cfg.files_sbcfg, *track_id, ptr::null(), 0u32, flags) }

@ -26,6 +26,7 @@ use crate::conf::conf_get;
use crate::core::*;
use crate::direction::Direction;
use crate::dns::dns::DnsVariant;
use crate::filecontainer::FileContainerWrapper;
use crate::filetracker::*;
use crate::flow::Flow;
use crate::frames::Frame;

@ -36,6 +36,7 @@ use crate::core::*;
use crate::direction::Direction;
use crate::direction::DIR_BOTH;
use crate::filetracker::*;
use crate::filecontainer::FileContainerWrapper;
use crate::flow::{Flow, flow_get_last_time};
use crate::frames::*;

@ -50,6 +50,7 @@ use crate::flow::{Flow, FLOW_DIR_REVERSED, flow_get_flags, flow_get_last_time, f
use crate::frames::*;
use crate::conf::*;
use crate::applayer::{AppLayerResult, AppLayerTxData, AppLayerEvent};
use crate::filecontainer::FileContainerWrapper;
use crate::smb::nbss_records::*;
use crate::smb::smb1_records::*;

@ -897,6 +897,11 @@ pub struct File_ {
_unused: [u8; 0],
}
pub type File = File_;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct AppLayerTxData {
_unused: [u8; 0],
}
extern "C" {
#[doc = " \\brief Given a protocol name, checks if the parser is enabled in\n the conf file.\n\n \\param alproto_name Name of the app layer protocol.\n\n \\retval 1 If enabled.\n \\retval 0 If disabled."]
pub fn SCAppLayerParserConfParserEnabled(
@ -928,6 +933,9 @@ extern "C" {
extern "C" {
pub fn SCAppLayerParserStateIssetFlag(pstate: *mut AppLayerParserState, flag: u16) -> u16;
}
extern "C" {
pub fn FileApplyTxFlags(txd: *const AppLayerTxData, direction: u8, file: *mut File);
}
extern "C" {
pub fn SCAppLayerRegisterParserAlias(
proto_name: *const ::std::os::raw::c_char, proto_alias: *const ::std::os::raw::c_char,
@ -1041,6 +1049,34 @@ extern "C" {
data_len: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
#[doc = " \\brief Open a new File\n\n \\param ffc flow container\n \\param sbcfg buffer config\n \\param name filename character array\n \\param name_len filename len\n \\param data initial data\n \\param data_len initial data len\n \\param flags open flags\n\n \\retval ff flowfile object\n\n \\note filename is not a string, so it's not nul terminated.\n\n If flags contains the FILE_USE_DETECT bit, the pruning code will\n consider not just the content_stored tracker, but also content_inspected.\n It's the responsibility of the API user to make sure this tracker is\n properly updated."]
pub fn FileOpenFileWithId(
arg1: *mut FileContainer, arg2: *const StreamingBufferConfig, track_id: u32,
name: *const u8, name_len: u16, data: *const u8, data_len: u32, flags: u16,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn FileAppendDataById(
arg1: *mut FileContainer, sbcfg: *const StreamingBufferConfig, track_id: u32,
data: *const u8, data_len: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn FileAppendGAPById(
ffc: *mut FileContainer, sbcfg: *const StreamingBufferConfig, track_id: u32,
data: *const u8, data_len: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn FileCloseFileById(
arg1: *mut FileContainer, sbcfg: *const StreamingBufferConfig, track_id: u32,
data: *const u8, data_len: u32, flags: u16,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn FileContainerRecycle(arg1: *mut FileContainer, cfg: *const StreamingBufferConfig);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct HttpRangeContainerBuffer {
@ -1095,12 +1131,6 @@ extern "C" {
len: u32,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn SCHTPFileCloseHandleRange(
sbcfg: *const StreamingBufferConfig, arg1: *mut FileContainer, arg2: u16,
arg3: *mut HttpRangeContainerBlock, arg4: *const u8, arg5: u32,
) -> bool;
}
pub type FrameId = i64;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]

@ -53,6 +53,38 @@ typedef struct FileContainer_ {
int FileAppendData(FileContainer *, const StreamingBufferConfig *sbcfg, const uint8_t *data,
uint32_t data_len);
/**
* \brief Open a new File
*
* \param ffc flow container
* \param sbcfg buffer config
* \param name filename character array
* \param name_len filename len
* \param data initial data
* \param data_len initial data len
* \param flags open flags
*
* \retval ff flowfile object
*
* \note filename is not a string, so it's not nul terminated.
*
* If flags contains the FILE_USE_DETECT bit, the pruning code will
* consider not just the content_stored tracker, but also content_inspected.
* It's the responsibility of the API user to make sure this tracker is
* properly updated.
*/
int FileOpenFileWithId(FileContainer *, const StreamingBufferConfig *, uint32_t track_id,
const uint8_t *name, uint16_t name_len, const uint8_t *data, uint32_t data_len,
uint16_t flags);
int FileAppendDataById(FileContainer *, const StreamingBufferConfig *sbcfg, uint32_t track_id,
const uint8_t *data, uint32_t data_len);
int FileAppendGAPById(FileContainer *ffc, const StreamingBufferConfig *sbcfg, uint32_t track_id,
const uint8_t *data, uint32_t data_len);
int FileCloseFileById(FileContainer *, const StreamingBufferConfig *sbcfg, uint32_t track_id,
const uint8_t *data, uint32_t data_len, uint16_t flags);
void FileContainerRecycle(FileContainer *, const StreamingBufferConfig *cfg);
#ifndef SURICATA_BINDGEN_H
#include "flow.h"
@ -141,34 +173,8 @@ typedef struct File_ {
FileContainer *FileContainerAlloc(void);
void FileContainerFree(FileContainer *, const StreamingBufferConfig *cfg);
void FileContainerRecycle(FileContainer *, const StreamingBufferConfig *cfg);
void FileContainerAdd(FileContainer *, File *);
/**
* \brief Open a new File
*
* \param ffc flow container
* \param sbcfg buffer config
* \param name filename character array
* \param name_len filename len
* \param data initial data
* \param data_len initial data len
* \param flags open flags
*
* \retval ff flowfile object
*
* \note filename is not a string, so it's not nul terminated.
*
* If flags contains the FILE_USE_DETECT bit, the pruning code will
* consider not just the content_stored tracker, but also content_inspected.
* It's the responsibility of the API user to make sure this tracker is
* properly updated.
*/
int FileOpenFileWithId(FileContainer *, const StreamingBufferConfig *,
uint32_t track_id, const uint8_t *name, uint16_t name_len,
const uint8_t *data, uint32_t data_len, uint16_t flags);
/**
* \brief Close a File
*
@ -182,16 +188,9 @@ int FileOpenFileWithId(FileContainer *, const StreamingBufferConfig *,
*/
int FileCloseFile(FileContainer *, const StreamingBufferConfig *sbcfg, const uint8_t *data,
uint32_t data_len, uint16_t flags);
int FileCloseFileById(FileContainer *, const StreamingBufferConfig *sbcfg, uint32_t track_id,
const uint8_t *data, uint32_t data_len, uint16_t flags);
int FileCloseFilePtr(File *ff, const StreamingBufferConfig *sbcfg, const uint8_t *data,
uint32_t data_len, uint16_t flags);
int FileAppendDataById(FileContainer *, const StreamingBufferConfig *sbcfg, uint32_t track_id,
const uint8_t *data, uint32_t data_len);
int FileAppendGAPById(FileContainer *ffc, const StreamingBufferConfig *sbcfg, uint32_t track_id,
const uint8_t *data, uint32_t data_len);
void FileSetInspectSizes(File *file, const uint32_t win, const uint32_t min);
/**

Loading…
Cancel
Save