|
|
|
|
@ -18,11 +18,10 @@
|
|
|
|
|
//! Parser registration functions and common interface module.
|
|
|
|
|
|
|
|
|
|
use std;
|
|
|
|
|
use crate::core::{self,AppLayerEventType, STREAM_TOSERVER};
|
|
|
|
|
use crate::core::STREAM_TOSERVER;
|
|
|
|
|
use crate::direction::Direction;
|
|
|
|
|
use crate::flow::Flow;
|
|
|
|
|
use std::os::raw::{c_void,c_char,c_int};
|
|
|
|
|
use std::ffi::CStr;
|
|
|
|
|
|
|
|
|
|
// Make the AppLayerEvent derive macro available to users importing
|
|
|
|
|
// AppLayerEvent from this module.
|
|
|
|
|
@ -134,7 +133,7 @@ pub unsafe extern "C" fn SCTxDataUpdateFileFlags(txd: &mut suricata_sys::sys::Ap
|
|
|
|
|
|
|
|
|
|
pub use suricata_ffi::{export_tx_data_get, export_state_data_get};
|
|
|
|
|
|
|
|
|
|
pub use suricata_ffi::applayer::{AppLayerResultRust, StreamSliceRust};
|
|
|
|
|
pub use suricata_ffi::applayer::{AppLayerEvent, AppLayerEventType, AppLayerResultRust, StreamSliceRust};
|
|
|
|
|
|
|
|
|
|
/// Rust parser declaration
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
@ -329,86 +328,6 @@ pub const _APP_LAYER_TX_INSPECTED_TS: u8 = BIT_U8!(2);
|
|
|
|
|
pub const _APP_LAYER_TX_INSPECTED_TC: u8 = BIT_U8!(3);
|
|
|
|
|
pub const APP_LAYER_TX_ACCEPT: u8 = BIT_U8!(4);
|
|
|
|
|
|
|
|
|
|
/// AppLayerEvent trait that will be implemented on enums that
|
|
|
|
|
/// derive AppLayerEvent.
|
|
|
|
|
pub trait AppLayerEvent {
|
|
|
|
|
/// Return the enum variant of the given ID.
|
|
|
|
|
fn from_id(id: u8) -> Option<Self> where Self: std::marker::Sized;
|
|
|
|
|
|
|
|
|
|
/// Convert the enum variant to a C-style string (suffixed with \0).
|
|
|
|
|
fn to_cstring(&self) -> &str;
|
|
|
|
|
|
|
|
|
|
/// Return the enum variant for the given name.
|
|
|
|
|
fn from_string(s: &str) -> Option<Self> where Self: std::marker::Sized;
|
|
|
|
|
|
|
|
|
|
/// Return the ID value of the enum variant.
|
|
|
|
|
fn as_u8(&self) -> u8;
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn get_event_info(
|
|
|
|
|
event_name: *const std::os::raw::c_char,
|
|
|
|
|
event_id: *mut u8,
|
|
|
|
|
event_type: *mut core::AppLayerEventType,
|
|
|
|
|
) -> std::os::raw::c_int;
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn get_event_info_by_id(
|
|
|
|
|
event_id: u8,
|
|
|
|
|
event_name: *mut *const std::os::raw::c_char,
|
|
|
|
|
event_type: *mut core::AppLayerEventType,
|
|
|
|
|
) -> std::os::raw::c_int;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Generic `get_info_info` implementation for enums implementing
|
|
|
|
|
/// AppLayerEvent.
|
|
|
|
|
///
|
|
|
|
|
/// Normally usage of this function will be generated by
|
|
|
|
|
/// derive(AppLayerEvent), for example:
|
|
|
|
|
///
|
|
|
|
|
/// ```rust,ignore
|
|
|
|
|
/// #[derive(AppLayerEvent)]
|
|
|
|
|
/// enum AppEvent {
|
|
|
|
|
/// EventOne,
|
|
|
|
|
/// EventTwo,
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// get_event_info::<AppEvent>(...)
|
|
|
|
|
/// ```
|
|
|
|
|
#[inline(always)]
|
|
|
|
|
pub unsafe fn get_event_info<T: AppLayerEvent>(
|
|
|
|
|
event_name: *const std::os::raw::c_char,
|
|
|
|
|
event_id: *mut u8,
|
|
|
|
|
event_type: *mut core::AppLayerEventType,
|
|
|
|
|
) -> std::os::raw::c_int {
|
|
|
|
|
if event_name.is_null() {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let event = match CStr::from_ptr(event_name).to_str().map(T::from_string) {
|
|
|
|
|
Ok(Some(event)) => event.as_u8(),
|
|
|
|
|
_ => {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
*event_type = core::AppLayerEventType::APP_LAYER_EVENT_TYPE_TRANSACTION;
|
|
|
|
|
*event_id = event;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Generic `get_info_info_by_id` implementation for enums implementing
|
|
|
|
|
/// AppLayerEvent.
|
|
|
|
|
#[inline(always)]
|
|
|
|
|
pub unsafe fn get_event_info_by_id<T: AppLayerEvent>(
|
|
|
|
|
event_id: u8,
|
|
|
|
|
event_name: *mut *const std::os::raw::c_char,
|
|
|
|
|
event_type: *mut core::AppLayerEventType,
|
|
|
|
|
) -> std::os::raw::c_int {
|
|
|
|
|
if let Some(e) = T::from_id(event_id) {
|
|
|
|
|
*event_name = e.to_cstring().as_ptr() as *const std::os::raw::c_char;
|
|
|
|
|
*event_type = core::AppLayerEventType::APP_LAYER_EVENT_TYPE_TRANSACTION;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub use suricata_ffi::applayer::{state_get_tx_iterator, State, Transaction};
|
|
|
|
|
|
|
|
|
|
/// AppLayerFrameType trait.
|
|
|
|
|
|