use crate::applayer;
use std::os::raw::{c_void,c_char,c_int};
+#[repr(C)]
+#[derive(Debug,PartialEq)]
+pub struct AppLayerTxConfig {
+ /// config: log flags
+ log_flags: u8,
+}
+
+impl AppLayerTxConfig {
+ pub fn new() -> Self {
+ Self {
+ log_flags: 0,
+ }
+ }
+
+ pub fn add_log_flags(&mut self, flags: u8) {
+ self.log_flags |= flags;
+ }
+ pub fn set_log_flags(&mut self, flags: u8) {
+ self.log_flags = flags;
+ }
+ pub fn get_log_flags(&self) -> u8 {
+ self.log_flags
+ }
+}
+
+#[repr(C)]
+#[derive(Debug,PartialEq)]
+pub struct AppLayerTxData {
+ /// config: log flags
+ pub config: AppLayerTxConfig,
+}
+
+impl AppLayerTxData {
+ pub fn new() -> Self {
+ Self {
+ config: AppLayerTxConfig::new(),
+ }
+ }
+}
+
+#[macro_export]
+macro_rules!export_tx_data_get {
+ ($name:ident, $type:ty) => {
+ #[no_mangle]
+ pub unsafe extern "C" fn $name(tx: *mut std::os::raw::c_void)
+ -> *mut crate::applayer::AppLayerTxData
+ {
+ let tx = &mut *(tx as *mut $type);
+ &mut tx.tx_data
+ }
+ }
+}
+
#[repr(C)]
#[derive(Debug,PartialEq,Copy,Clone)]
pub struct AppLayerResult {
// Function to get TX detect flags.
pub get_tx_detect_flags: Option<GetTxDetectFlagsFn>,
+
+ pub get_tx_data: Option<GetTxDataFn>,
}
/// Create a slice, given a buffer and a length
-> AppLayerGetTxIterTuple;
pub type GetTxDetectFlagsFn = unsafe extern "C" fn(*mut c_void, u8) -> u64;
pub type SetTxDetectFlagsFn = unsafe extern "C" fn(*mut c_void, u8, u64);
+pub type GetTxDataFn = unsafe extern "C" fn(*mut c_void) -> *mut AppLayerTxData;
// Defined in app-layer-register.h
extern {
get_tx_iterator: Some(rs_template_state_get_tx_iterator),
get_tx_detect_flags: None,
set_tx_detect_flags: None,
+ get_tx_data: None,
};
let ip_proto_str = CString::new("tcp").unwrap();
get_tx_iterator : Some(rs_dhcp_state_get_tx_iterator),
set_tx_detect_flags: None,
get_tx_detect_flags: None,
+ get_tx_data : None,
};
let ip_proto_str = CString::new("udp").unwrap();
pub logged: LoggerFlags,
pub de_state: Option<*mut core::DetectEngineState>,
pub events: *mut core::AppLayerDecoderEvents,
+ pub tx_data: AppLayerTxData,
}
impl DNSTransaction {
logged: LoggerFlags::new(),
de_state: None,
events: std::ptr::null_mut(),
+ tx_data: AppLayerTxData::new(),
}
}
return tx.events;
}
+#[no_mangle]
+pub extern "C" fn rs_dns_state_get_tx_data(
+ tx: *mut std::os::raw::c_void)
+ -> *mut AppLayerTxData
+{
+ let tx = cast_pointer!(tx, DNSTransaction);
+ return &mut tx.tx_data;
+}
+
#[no_mangle]
pub extern "C" fn rs_dns_tx_get_query_name(tx: &mut DNSTransaction,
i: u16,
set_tx_detect_flags: Some(rs_dns_tx_set_detect_flags),
get_de_state: rs_dns_state_get_tx_detect_state,
set_de_state: rs_dns_state_set_tx_detect_state,
+ get_tx_data: Some(rs_dns_state_get_tx_data),
};
let ip_proto_str = CString::new("udp").unwrap();
set_tx_detect_flags: Some(rs_dns_tx_set_detect_flags),
get_de_state: rs_dns_state_get_tx_detect_state,
set_de_state: rs_dns_state_set_tx_detect_state,
+ get_tx_data: Some(rs_dns_state_get_tx_data),
};
let ip_proto_str = CString::new("tcp").unwrap();
get_tx_iterator : None,
get_tx_detect_flags: None,
set_tx_detect_flags: None,
+ get_tx_data : None,
};
let ip_proto_str = CString::new("udp").unwrap();
get_tx_iterator : None,
get_tx_detect_flags: Some(rs_krb5_tx_detect_flags_get),
set_tx_detect_flags: Some(rs_krb5_tx_detect_flags_set),
+ get_tx_data : None,
};
// register UDP parser
let ip_proto_str = CString::new("udp").unwrap();
get_tx_iterator : None,
get_tx_detect_flags: None,
set_tx_detect_flags: None,
+ get_tx_data : None,
};
let ip_proto_str = CString::new("udp").unwrap();
get_tx_iterator: None,
get_tx_detect_flags: None,
set_tx_detect_flags: None,
+ get_tx_data: None,
};
let ip_proto_str = std::ffi::CString::new("tcp").unwrap();
get_tx_iterator: Some(rs_rfb_state_get_tx_iterator),
get_tx_detect_flags: Some(rs_rfb_get_tx_detect_flags),
set_tx_detect_flags: Some(rs_rfb_set_tx_detect_flags),
+ get_tx_data: None,
};
let ip_proto_str = CString::new("tcp").unwrap();
get_tx_iterator: None,
get_tx_detect_flags: None,
set_tx_detect_flags: None,
+ get_tx_data: None,
};
let ip_proto_str = CString::new("udp").unwrap();
get_tx_iterator : None,
get_tx_detect_flags: Some(rs_snmp_get_tx_detect_flags),
set_tx_detect_flags: Some(rs_snmp_set_tx_detect_flags),
+ get_tx_data : None,
};
let ip_proto_str = CString::new("udp").unwrap();
if AppLayerProtoDetectConfProtoDetectionEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
get_tx_iterator: None,
get_tx_detect_flags: Some(rs_ssh_get_tx_detect_flags),
set_tx_detect_flags: Some(rs_ssh_set_tx_detect_flags),
+ get_tx_data: None,
};
let ip_proto_str = CString::new("tcp").unwrap();
uint64_t (*GetTxDetectFlags)(void *tx, uint8_t dir);
void (*SetTxDetectFlags)(void *tx, uint8_t dir, uint64_t);
+ AppLayerTxData *(*GetTxData)(void *tx);
void (*SetStreamDepthFlag)(void *tx, uint8_t flags);
SCReturn;
}
+void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto,
+ AppLayerTxData *(*GetTxData)(void *tx))
+{
+ SCEnter();
+
+ alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxData = GetTxData;
+
+ SCReturn;
+}
+
void AppLayerParserRegisterSetStreamDepthFlag(uint8_t ipproto, AppProto alproto,
void (*SetStreamDepthFlag)(void *tx, uint8_t flags))
{
SCReturn;
}
+AppLayerTxData *AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
+{
+ SCEnter();
+ if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxData) {
+ AppLayerTxData *d = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxData(tx);
+ SCReturnPtr(d, "AppLayerTxData");
+ }
+ SCReturnPtr(NULL, "AppLayerTxData");
+}
+
/***** General *****/
/** \retval int -1 in case of unrecoverable error. App-layer tracking stops for this flow.
void AppLayerParserRegisterSetStreamDepthFlag(uint8_t ipproto, AppProto alproto,
void (*SetStreamDepthFlag)(void *tx, uint8_t flags));
+void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto,
+ AppLayerTxData *(*GetTxData)(void *tx));
+
/***** Get and transaction functions *****/
AppLayerGetTxIteratorFunc AppLayerGetTxIterator(const uint8_t ipproto,
void AppLayerParserSetTxDetectFlags(uint8_t ipproto, AppProto alproto, void *tx, uint8_t dir, uint64_t);
bool AppLayerParserSupportsTxDetectFlags(AppProto alproto);
+AppLayerTxData *AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx);
+
/***** General *****/
int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *tctx, Flow *f, AppProto alproto,
p->GetTxDetectFlags, p->SetTxDetectFlags);
}
+ if (p->GetTxData) {
+ AppLayerParserRegisterTxDataFunc(p->ip_proto, alproto,
+ p->GetTxData);
+ }
+
return 0;
}
void (*SetTxDetectFlags)(void *, uint8_t, uint64_t);
uint64_t (*GetTxDetectFlags)(void *, uint8_t);
+
+ AppLayerTxData *(*GetTxData)(void *tx);
} AppLayerParser;
/**