rust: bindgen GenericVarFree

Ticket: 7667
pull/13884/head
Philippe Antoine 1 year ago committed by Victor Julien
parent b00788af8b
commit cc845dccdb

@ -18,7 +18,7 @@
//! Parser registration functions and common interface module.
use std;
use crate::core::{self,AppLayerEventType, GenericVar, STREAM_TOSERVER};
use crate::core::{self,AppLayerEventType, STREAM_TOSERVER};
use crate::direction::Direction;
use crate::filecontainer::FileContainer;
use crate::flow::Flow;
@ -29,9 +29,14 @@ use crate::core::StreamingBufferConfig;
// Make the AppLayerEvent derive macro available to users importing
// AppLayerEvent from this module.
pub use suricata_derive::AppLayerEvent;
use suricata_sys::sys::{AppLayerParserState, AppProto, DetectEngineState, AppLayerDecoderEvents};
use suricata_sys::sys::{
AppLayerDecoderEvents, AppLayerParserState, AppProto, DetectEngineState, GenericVar,
};
#[cfg(not(test))]
use suricata_sys::sys::{SCDetectEngineStateFree, SCAppLayerDecoderEventsFreeEvents, SCAppLayerDecoderEventsSetEventRaw};
use suricata_sys::sys::{
SCAppLayerDecoderEventsFreeEvents, SCAppLayerDecoderEventsSetEventRaw, SCDetectEngineStateFree,
SCGenericVarFree,
};
/// Cast pointer to a variable, as a mutable reference to an object
///
@ -171,24 +176,28 @@ pub unsafe extern "C" fn SCAppLayerTxDataCleanup(txd: *mut AppLayerTxData) {
}
impl AppLayerTxData {
#[cfg(not(test))]
pub fn cleanup(&mut self) {
#[cfg(not(test))]
if !self.de_state.is_null() {
unsafe {
SCDetectEngineStateFree(self.de_state);
}
}
#[cfg(not(test))]
if !self.events.is_null() {
unsafe {
SCAppLayerDecoderEventsFreeEvents(&mut self.events);
}
}
if !self.txbits.is_null() {
core::sc_generic_var_free(self.txbits);
unsafe {
SCGenericVarFree(self.txbits);
}
}
}
#[cfg(test)]
pub fn cleanup(&mut self) {}
/// Create new AppLayerTxData for a transaction that covers both
/// directions.
pub fn new() -> Self {

@ -25,9 +25,6 @@ use suricata_sys::sys::SCAppLayerParserTriggerRawStreamInspection;
use crate::filecontainer::*;
use crate::flow::Flow;
/// Opaque C types.
pub enum GenericVar {}
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[allow(non_camel_case_types)]
@ -122,9 +119,6 @@ pub type SCFileContainerRecycle = extern "C" fn (
file_container: &FileContainer,
sbcfg: &StreamingBufferConfig);
pub type GenericVarFreeFunc =
extern "C" fn(gvar: *mut GenericVar);
// A Suricata context that is passed in from C. This is alternative to
// using functions from Suricata directly, so they can be wrapped so
// Rust unit tests will still compile when they are not linked
@ -145,8 +139,6 @@ pub struct SuricataContext {
pub FileAppendData: SCFileAppendDataById,
pub FileAppendGAP: SCFileAppendGAPById,
pub FileContainerRecycle: SCFileContainerRecycle,
GenericVarFree: GenericVarFreeFunc,
}
#[allow(non_snake_case)]
@ -176,16 +168,6 @@ pub extern "C" fn SCRustInit(context: &'static SuricataContext)
init_ffi(context);
}
/// GenericVarFree wrapper.
pub fn sc_generic_var_free(gvar: *mut GenericVar)
{
unsafe {
if let Some(c) = SC {
(c.GenericVarFree)(gvar);
}
}
}
/// SCAppLayerParserTriggerRawStreamInspection wrapper
#[cfg(not(test))]
pub(crate) fn sc_app_layer_parser_trigger_raw_stream_inspection(flow: *mut Flow, direction: i32) {

@ -846,6 +846,19 @@ extern "C" {
extern "C" {
pub fn SCFileFlowFlagsToFlags(flow_file_flags: u16, direction: u8) -> u16;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct GenericVar_ {
#[doc = "< variable type, uses detection sm_type"]
pub type_: u16,
pub pad: [u8; 2usize],
pub idx: u32,
pub next: *mut GenericVar_,
}
pub type GenericVar = GenericVar_;
extern "C" {
pub fn SCGenericVarFree(arg1: *mut GenericVar);
}
extern "C" {
pub fn SCFlowGetLastTimeAsParts(flow: *const Flow, secs: *mut u64, usecs: *mut u64);
}

@ -54,6 +54,7 @@
#include "util-mpm.h"
#include "util-file.h"
#include "util-var.h"
#include "flow-bindgen.h"

@ -984,7 +984,7 @@ static DetectRunScratchpad DetectRunSetup(const DetectEngineCtx *de_ctx,
pflow->sgh_toclient = NULL;
pflow->de_ctx_version = de_ctx->version;
GenericVarFree(pflow->flowvar);
SCGenericVarFree(pflow->flowvar);
pflow->flowvar = NULL;
DetectEngineStateResetTxs(pflow);

@ -161,7 +161,7 @@ static int FlowBitTest01 (void)
FlowBit *fb = FlowBitGet(&f, 0);
FAIL_IF_NULL(fb);
GenericVarFree(f.flowvar);
SCGenericVarFree(f.flowvar);
PASS;
}
@ -173,7 +173,7 @@ static int FlowBitTest02 (void)
FlowBit *fb = FlowBitGet(&f, 0);
FAIL_IF_NOT_NULL(fb);
GenericVarFree(f.flowvar);
SCGenericVarFree(f.flowvar);
PASS;
}
@ -192,7 +192,7 @@ static int FlowBitTest03 (void)
fb = FlowBitGet(&f, 0);
FAIL_IF_NOT_NULL(fb);
GenericVarFree(f.flowvar);
SCGenericVarFree(f.flowvar);
PASS;
}
@ -209,7 +209,7 @@ static int FlowBitTest04 (void)
FlowBit *fb = FlowBitGet(&f, 0);
FAIL_IF_NULL(fb);
GenericVarFree(f.flowvar);
SCGenericVarFree(f.flowvar);
PASS;
}
@ -226,7 +226,7 @@ static int FlowBitTest05 (void)
FlowBit *fb = FlowBitGet(&f, 1);
FAIL_IF_NULL(fb);
GenericVarFree(f.flowvar);
SCGenericVarFree(f.flowvar);
PASS;
}
@ -243,7 +243,7 @@ static int FlowBitTest06 (void)
FlowBit *fb = FlowBitGet(&f, 2);
FAIL_IF_NULL(fb);
GenericVarFree(f.flowvar);
SCGenericVarFree(f.flowvar);
PASS;
}
@ -260,7 +260,7 @@ static int FlowBitTest07 (void)
FlowBit *fb = FlowBitGet(&f, 3);
FAIL_IF_NULL(fb);
GenericVarFree(f.flowvar);
SCGenericVarFree(f.flowvar);
PASS;
}
@ -282,7 +282,7 @@ static int FlowBitTest08 (void)
fb = FlowBitGet(&f, 0);
FAIL_IF_NOT_NULL(fb);
GenericVarFree(f.flowvar);
SCGenericVarFree(f.flowvar);
PASS;
}
@ -304,7 +304,7 @@ static int FlowBitTest09 (void)
fb = FlowBitGet(&f, 1);
FAIL_IF_NOT_NULL(fb);
GenericVarFree(f.flowvar);
SCGenericVarFree(f.flowvar);
PASS;
}
@ -326,7 +326,7 @@ static int FlowBitTest10 (void)
fb = FlowBitGet(&f, 2);
FAIL_IF_NOT_NULL(fb);
GenericVarFree(f.flowvar);
SCGenericVarFree(f.flowvar);
PASS;
}
@ -348,7 +348,7 @@ static int FlowBitTest11 (void)
fb = FlowBitGet(&f, 3);
FAIL_IF_NOT_NULL(fb);
GenericVarFree(f.flowvar);
SCGenericVarFree(f.flowvar);
PASS;
}

@ -111,7 +111,7 @@
(f)->thread_id[1] = 0; \
(f)->sgh_toserver = NULL; \
(f)->sgh_toclient = NULL; \
GenericVarFree((f)->flowvar); \
SCGenericVarFree((f)->flowvar); \
(f)->flowvar = NULL; \
RESET_COUNTERS((f)); \
} while (0)
@ -121,7 +121,7 @@
FlowCleanupAppLayer((f)); \
\
FLOWLOCK_DESTROY((f)); \
GenericVarFree((f)->flowvar); \
SCGenericVarFree((f)->flowvar); \
} while (0)
/** \brief check if a memory alloc would fit in the memcap

@ -43,7 +43,7 @@ static HostStorageId host_bit_id = { .id = -1 }; /**< Host storage id for bits *
static void HostBitFreeAll(void *store)
{
GenericVar *gv = store;
GenericVarFree(gv);
SCGenericVarFree(gv);
}
void HostBitInitCtx(void)

@ -43,7 +43,7 @@ static IPPairStorageId g_ippair_bit_storage_id = { .id = -1 }; /**< IPPair stora
static void XBitFreeAll(void *store)
{
GenericVar *gv = store;
GenericVarFree(gv);
SCGenericVarFree(gv);
}
void IPPairBitInitCtx(void)

@ -35,8 +35,6 @@ const SuricataContext suricata_context = {
FileAppendDataById,
FileAppendGAPById,
FileContainerRecycle,
GenericVarFree,
};
const SuricataContext *SCGetContext(void)

@ -52,8 +52,6 @@ typedef struct SuricataContext_ {
int (*FileAppendGAPById)(FileContainer *, const StreamingBufferConfig *, uint32_t track_id,
const uint8_t *data, uint32_t data_len);
void (*FileContainerRecycle)(FileContainer *ffc, const StreamingBufferConfig *);
void (*GenericVarFree)(GenericVar *);
} SuricataContext;
extern const SuricataContext suricata_context;

@ -45,7 +45,7 @@ void XBitFree(XBit *fb)
SCFree(fb);
}
void GenericVarFree(GenericVar *gv)
void SCGenericVarFree(GenericVar *gv)
{
if (gv == NULL)
return;
@ -57,14 +57,14 @@ void GenericVarFree(GenericVar *gv)
case DETECT_FLOWBITS:
{
FlowBit *fb = (FlowBit *)gv;
//printf("GenericVarFree: fb %p, removing\n", fb);
// printf("SCGenericVarFree: fb %p, removing\n", fb);
FlowBitFree(fb);
break;
}
case DETECT_XBITS:
{
XBit *fb = (XBit *)gv;
//printf("GenericVarFree: fb %p, removing\n", fb);
// printf("SCGenericVarFree: fb %p, removing\n", fb);
XBitFree(fb);
break;
}
@ -86,13 +86,13 @@ void GenericVarFree(GenericVar *gv)
}
default:
{
SCLogDebug("GenericVarFree unknown type %" PRIu32, gv->type);
SCLogDebug("SCGenericVarFree unknown type %" PRIu32, gv->type);
DEBUG_VALIDATE_BUG_ON(1);
break;
}
}
GenericVarFree(next_gv);
SCGenericVarFree(next_gv);
}
void GenericVarAppend(GenericVar **list, GenericVar *gv)

@ -57,6 +57,7 @@ typedef struct GenericVar_ {
struct GenericVar_ *next;
} GenericVar;
#ifndef SURICATA_BINDGEN_H
typedef struct XBit_ {
uint16_t type; /* type, DETECT_XBITS in this case */
uint8_t pad[2];
@ -66,6 +67,7 @@ typedef struct XBit_ {
} XBit;
void XBitFree(XBit *);
#endif
// A list of variables we try to resolve while parsing configuration file.
// Helps to detect recursive declarations.
@ -76,7 +78,7 @@ typedef struct ResolvedVariable_ {
typedef TAILQ_HEAD(, ResolvedVariable_) ResolvedVariablesList;
void GenericVarFree(GenericVar *);
void SCGenericVarFree(GenericVar *);
void GenericVarAppend(GenericVar **, GenericVar *);
void GenericVarRemove(GenericVar **, GenericVar *);

Loading…
Cancel
Save