//! Parser registration functions and common interface
use std;
-use crate::core::{STREAM_TOSERVER};
use crate::core::{DetectEngineState,Flow,AppLayerEventType,AppLayerDecoderEvents,AppProto};
use crate::filecontainer::FileContainer;
use crate::applayer;
}
)
}
-
-#[derive(Debug,Default)]
-pub struct TxDetectFlags {
- ts: u64,
- tc: u64,
-}
-
-impl TxDetectFlags {
- pub fn set(&mut self, direction: u8, flags: u64) {
- if direction & STREAM_TOSERVER != 0 {
- self.ts = flags;
- } else {
- self.tc = flags;
- }
- }
-
- pub fn get(&self, direction: u8) -> u64 {
- if (direction & STREAM_TOSERVER) != 0 {
- self.ts
- } else {
- self.tc
- }
- }
-}
-
-#[macro_export]
-macro_rules!export_tx_detect_flags_set {
- ($name:ident, $type:ty) => {
- #[no_mangle]
- pub unsafe extern "C" fn $name(tx: *mut std::os::raw::c_void, direction: u8, flags: u64) {
- let tx = &mut *(tx as *mut $type);
- tx.detect_flags.set(direction, flags);
- }
- }
-}
-
-#[macro_export]
-macro_rules!export_tx_detect_flags_get {
- ($name:ident, $type:ty) => {
- #[no_mangle]
- pub unsafe extern "C" fn $name(tx: *mut std::os::raw::c_void, direction: u8) -> u64 {
- let tx = &mut *(tx as *mut $type);
- return tx.detect_flags.get(direction);
- }
- }
-}
DetectEngineState *(*GetTxDetectState)(void *tx);
int (*SetTxDetectState)(void *tx, DetectEngineState *);
- uint64_t (*GetTxDetectFlags)(void *tx, uint8_t dir);
- void (*SetTxDetectFlags)(void *tx, uint8_t dir, uint64_t);
AppLayerTxData *(*GetTxData)(void *tx);
bool (*ApplyTxConfig)(void *state, void *tx, int mode, AppLayerTxConfig);
SCReturn;
}
-void AppLayerParserRegisterDetectFlagsFuncs(uint8_t ipproto, AppProto alproto,
- uint64_t(*GetTxDetectFlags)(void *tx, uint8_t dir),
- void (*SetTxDetectFlags)(void *tx, uint8_t dir, uint64_t))
-{
- SCEnter();
-
- alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxDetectFlags = GetTxDetectFlags;
- alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].SetTxDetectFlags = SetTxDetectFlags;
-
- SCReturn;
-}
-
void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto,
AppLayerTxData *(*GetTxData)(void *tx))
{
if (txd != NULL) {
detect_flags = (dir & STREAM_TOSERVER) ? txd->detect_flags_ts : txd->detect_flags_tc;
} else {
- detect_flags = AppLayerParserGetTxDetectFlags(ipproto, alproto, tx, dir);
+ detect_flags = 0;
}
return detect_flags;
}
} else {
txd->detect_flags_tc = detect_flags;
}
- } else {
- AppLayerParserSetTxDetectFlags(ipproto, alproto, tx, dir, detect_flags);
}
}
if (unlikely(p->StateTransactionFree == NULL))
SCReturn;
- const bool has_tx_detect_flags = (p->GetTxDetectFlags != NULL || p->GetTxData != NULL);
+ const bool has_tx_detect_flags = (p->GetTxData != NULL);
const uint8_t ipproto = f->proto;
const AppProto alproto = f->alproto;
void * const alstate = f->alstate;
{
SCEnter();
for (uint8_t p = 0; p < FLOW_PROTO_APPLAYER_MAX; p++) {
- if (alp_ctx.ctxs[p][alproto].GetTxDetectFlags != NULL) {
- SCReturnBool(true);
- }
if (alp_ctx.ctxs[p][alproto].GetTxData != NULL) {
SCReturnBool(true);
}
SCReturnBool(false);
}
-uint64_t AppLayerParserGetTxDetectFlags(uint8_t ipproto, AppProto alproto, void *tx, uint8_t dir)
-{
- SCEnter();
- uint64_t flags = 0;
- if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxDetectFlags != NULL) {
- flags = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxDetectFlags(tx, dir);
- }
- SCReturnUInt(flags);
-}
-
-void AppLayerParserSetTxDetectFlags(uint8_t ipproto, AppProto alproto, void *tx, uint8_t dir, uint64_t flags)
-{
- SCEnter();
- if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].SetTxDetectFlags != NULL) {
- alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].SetTxDetectFlags(tx, dir, flags);
- }
- SCReturn;
-}
-
AppLayerTxData *AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
{
SCEnter();
if (!(BOTH_SET_OR_BOTH_UNSET(ctx->GetTxDetectState, ctx->SetTxDetectState))) {
goto bad;
}
- if (!(BOTH_SET_OR_BOTH_UNSET(ctx->GetTxDetectFlags, ctx->SetTxDetectFlags))) {
- goto bad;
- }
return;
bad:
void AppLayerParserRegisterGetStreamDepth(uint8_t ipproto,
AppProto alproto,
uint32_t (*GetStreamDepth)(void));
-void AppLayerParserRegisterDetectFlagsFuncs(uint8_t ipproto, AppProto alproto,
- uint64_t(*GetTxDetectFlags)(void *tx, uint8_t dir),
- void (*SetTxDetectFlags)(void *tx, uint8_t dir, uint64_t));
void AppLayerParserRegisterSetStreamDepthFlag(uint8_t ipproto, AppProto alproto,
void (*SetStreamDepthFlag)(void *tx, uint8_t flags));
DetectEngineState *AppLayerParserGetTxDetectState(uint8_t ipproto, AppProto alproto, void *tx);
int AppLayerParserSetTxDetectState(const Flow *f, void *tx, DetectEngineState *s);
-uint64_t AppLayerParserGetTxDetectFlags(uint8_t ipproto, AppProto alproto, void *tx, uint8_t dir);
-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);
p->GetTxIterator);
}
- if (p->SetTxDetectFlags && p->GetTxDetectFlags) {
- AppLayerParserRegisterDetectFlagsFuncs(p->ip_proto, alproto,
- p->GetTxDetectFlags, p->SetTxDetectFlags);
- }
-
if (p->GetTxData) {
AppLayerParserRegisterTxDataFunc(p->ip_proto, alproto,
p->GetTxData);
if (txd != NULL) {
detect_flags = (flow_flags & STREAM_TOSERVER) ? txd->detect_flags_ts : txd->detect_flags_tc;
} else {
- detect_flags = AppLayerParserGetTxDetectFlags(ipproto, alproto, tx_ptr, flow_flags);
+ detect_flags = 0;
}
if (detect_flags & APP_LAYER_TX_INSPECTED_FLAG) {
SCLogDebug("%"PRIu64" tx already fully inspected for %s. Flags %016"PRIx64,
} else {
txd->detect_flags_tc = detect_flags;
}
- } else {
- AppLayerParserSetTxDetectFlags(ipproto, alproto, tx->tx_ptr,
- flow_flags, detect_flags);
}
}