rust: move AppLayerStateData definition to C

and bindgen it to rust, and use default trait instead of new

Will make easier the bindgen of RustParser structure which uses
a callback which uses AppLayerStateData
pull/14758/head
Philippe Antoine 6 months ago committed by Victor Julien
parent 76efb8af4d
commit 64d29fcd1c

@ -148,6 +148,7 @@ if HAVE_BINDGEN
--allowlist-type 'AppLayerEventType' \
--allowlist-type 'AppLayerGetFileState' \
--allowlist-type 'AppLayerGetTxIterState' \
--allowlist-type 'AppLayerStateData' \
--allowlist-function 'SC.*' \
--allowlist-var 'SC.*' \
--opaque-type 'SCConfNode' \

@ -31,7 +31,8 @@ use suricata_sys::sys::{
AppLayerDecoderEvents, AppLayerGetTxIterState, AppLayerParserState, AppProto,
DetectEngineState, GenericVar,
};
pub use suricata_sys::sys::AppLayerGetFileState;
pub use suricata_sys::sys::{AppLayerGetFileState, AppLayerStateData};
#[cfg(not(test))]
use suricata_sys::sys::{
SCAppLayerDecoderEventsFreeEvents, SCAppLayerDecoderEventsSetEventRaw, SCDetectEngineStateFree,
@ -299,20 +300,6 @@ macro_rules!export_tx_data_get {
}
}
#[repr(C)]
#[derive(Default,Debug,PartialEq, Eq,Copy,Clone)]
pub struct AppLayerStateData {
pub file_flags: u16,
}
impl AppLayerStateData {
pub fn new() -> Self {
Self {
file_flags: 0,
}
}
}
#[macro_export]
macro_rules!export_state_data_get {
($name:ident, $type:ty) => {

@ -596,7 +596,7 @@ impl Default for HTTP2State {
impl HTTP2State {
pub fn new() -> Self {
Self {
state_data: AppLayerStateData::new(),
state_data: AppLayerStateData::default(),
tx_id: 0,
request_frame_size: 0,
response_frame_size: 0,

@ -114,7 +114,7 @@ impl Default for KRB5State {
impl KRB5State {
pub fn new() -> KRB5State {
Self {
state_data: AppLayerStateData::new(),
state_data: AppLayerStateData::default(),
req_id: 0,
record_ts: 0,
defrag_buf_ts: Vec::new(),

@ -120,7 +120,7 @@ impl State<LdapTransaction> for LdapState {
impl LdapState {
pub fn new() -> Self {
Self {
state_data: AppLayerStateData::new(),
state_data: AppLayerStateData::default(),
tx_id: 0,
transactions: VecDeque::new(),
request_frame: None,

@ -139,7 +139,7 @@ impl Default for MQTTState {
impl MQTTState {
pub fn new() -> Self {
Self {
state_data: AppLayerStateData::new(),
state_data: AppLayerStateData::default(),
tx_id: 0,
protocol_version: 0,
transactions: VecDeque::new(),

@ -417,7 +417,7 @@ impl NFSState {
/// Allocation function for a new TLS parser instance
pub fn new() -> NFSState {
NFSState {
state_data: AppLayerStateData::new(),
state_data: AppLayerStateData::default(),
requestmap: HashMap::new(),
namemap: HashMap::new(),
transactions: Vec::new(),

@ -183,7 +183,7 @@ impl Default for PgsqlState {
impl PgsqlState {
fn new() -> Self {
Self {
state_data: AppLayerStateData::new(),
state_data: AppLayerStateData::default(),
tx_id: 0,
transactions: VecDeque::new(),
request_gap: false,

@ -141,7 +141,7 @@ pub struct QuicState {
impl Default for QuicState {
fn default() -> Self {
Self {
state_data: AppLayerStateData::new(),
state_data: AppLayerStateData::default(),
max_tx_id: 0,
keys: None,
crypto_frag_tc: Vec::new(),

@ -132,7 +132,7 @@ impl State<RdpTransaction> for RdpState {
impl RdpState {
fn new() -> Self {
Self {
state_data: AppLayerStateData::new(),
state_data: AppLayerStateData::default(),
next_id: 0,
transactions: VecDeque::new(),
tls_parsing: false,

@ -137,7 +137,7 @@ impl Default for RFBState {
impl RFBState {
pub fn new() -> Self {
Self {
state_data: AppLayerStateData::new(),
state_data: AppLayerStateData::default(),
tx_id: 0,
transactions: Vec::new(),
state: parser::RFBGlobalState::TCServerProtocolVersion,

@ -797,7 +797,7 @@ impl SMBState {
/// Allocation function for a new TLS parser instance
pub fn new() -> Self {
Self {
state_data:AppLayerStateData::new(),
state_data:AppLayerStateData::default(),
ssn2vec_cache:LruCache::new(NonZeroUsize::new(unsafe { SMB_CFG_MAX_SSN2VEC_CACHE_SIZE }).unwrap()),
guid2name_cache:LruCache::new(NonZeroUsize::new(unsafe { SMB_CFG_MAX_GUID_CACHE_SIZE }).unwrap()),
read_offset_cache:LruCache::new(NonZeroUsize::new(unsafe { SMB_CFG_MAX_READ_OFFSET_CACHE_SIZE }).unwrap()),

@ -98,7 +98,7 @@ impl Default for TelnetState {
impl TelnetState {
pub fn new() -> Self {
Self {
state_data: AppLayerStateData::new(),
state_data: AppLayerStateData::default(),
tx_id: 0,
transactions: Vec::new(),
request_gap: false,

@ -89,7 +89,7 @@ impl TFTPTransaction {
#[no_mangle]
pub extern "C" fn SCTftpStateAlloc() -> *mut std::os::raw::c_void {
let state = TFTPState { state_data: AppLayerStateData::new(), transactions : Vec::new(), tx_id: 0, };
let state = TFTPState { state_data: AppLayerStateData::default(), transactions : Vec::new(), tx_id: 0, };
let boxed = Box::new(state);
return Box::into_raw(boxed) as *mut _;
}

@ -1034,6 +1034,11 @@ impl Default for AppLayerGetTxIterState {
}
}
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
pub struct AppLayerStateData {
pub file_flags: u16,
}
extern "C" {
pub fn SCAppLayerParserReallocCtx(alproto: AppProto) -> ::std::os::raw::c_int;
}

@ -25,6 +25,7 @@
#define SURICATA_APP_LAYER_DNP3_H
#include "rust.h"
#include "app-layer-parser.h"
#if __BYTE_ORDER == __BIG_ENDIAN
#include "util-byte.h"
#endif

@ -26,6 +26,7 @@
#define SURICATA_APP_LAYER_FTP_H
#include "rust.h"
#include "app-layer-parser.h"
struct FtpCommand;

@ -34,6 +34,7 @@
#define SURICATA_APP_LAYER_HTP_H
#include "rust.h"
#include "app-layer-parser.h"
#include "app-layer-frames.h"
#include "htp/htp_rs.h"

@ -41,7 +41,6 @@ typedef struct AppLayerResult AppLayerResult;
typedef struct AppLayerGetTxIterTuple AppLayerGetTxIterTuple;
typedef struct AppLayerGetFileState AppLayerGetFileState;
typedef struct AppLayerTxData AppLayerTxData;
typedef struct AppLayerStateData AppLayerStateData;
typedef struct AppLayerTxConfig AppLayerTxConfig;
/* Flags for AppLayerParserState. */
@ -138,6 +137,10 @@ typedef struct AppLayerGetTxIterState {
} un;
} AppLayerGetTxIterState;
typedef struct AppLayerStateData {
uint16_t file_flags;
} AppLayerStateData;
/** \brief tx iterator prototype */
typedef AppLayerGetTxIterTuple (*AppLayerGetTxIteratorFunc)
(const uint8_t ipproto, const AppProto alproto,

@ -25,6 +25,7 @@
#define SURICATA_APP_LAYER_SMTP_H
#include "rust.h"
#include "app-layer-parser.h"
#include "app-layer-frames.h"
#include "util-streaming-buffer.h"

@ -28,6 +28,7 @@
#include "util-ja3.h"
#include "rust.h"
#include "app-layer-parser.h"
enum TlsFrameTypes {
TLS_FRAME_PDU = 0, /**< whole PDU, so header + data */

@ -24,6 +24,7 @@ typedef struct Dataset Dataset;
typedef struct DetectEngineState_ DetectEngineState;
typedef enum AppLayerEventType AppLayerEventType;
typedef struct AppLayerStateData AppLayerStateData;
// may be improved by smaller include
#include "detect.h"

Loading…
Cancel
Save