app-layer: remove DetectFlags API. Replaced by AppLayerTxData

pull/5169/head
Victor Julien 5 years ago
parent 88dd0abb38
commit 8fe9faecb2

@ -18,7 +18,6 @@
//! 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;
@ -408,49 +407,3 @@ macro_rules!export_tx_set_detect_state {
}
)
}
#[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);
}
}
}

@ -120,8 +120,6 @@ typedef struct AppLayerParserProtoCtx_
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);
@ -566,18 +564,6 @@ void AppLayerParserRegisterDetectStateFuncs(uint8_t ipproto, AppProto alproto,
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))
{
@ -717,7 +703,7 @@ static inline uint64_t GetTxDetectFlags(const uint8_t ipproto, const AppProto al
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;
}
@ -731,8 +717,6 @@ static inline void SetTxDetectFlags(const uint8_t ipproto, const AppProto alprot
} else {
txd->detect_flags_tc = detect_flags;
}
} else {
AppLayerParserSetTxDetectFlags(ipproto, alproto, tx, dir, detect_flags);
}
}
@ -895,7 +879,7 @@ void AppLayerParserTransactionsCleanup(Flow *f)
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;
@ -1144,9 +1128,6 @@ bool AppLayerParserSupportsTxDetectFlags(AppProto alproto)
{
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);
}
@ -1154,25 +1135,6 @@ bool AppLayerParserSupportsTxDetectFlags(AppProto alproto)
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();
@ -1543,9 +1505,6 @@ static void ValidateParserProto(AppProto alproto, uint8_t ipproto)
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:

@ -182,9 +182,6 @@ void AppLayerParserRegisterDetectStateFuncs(uint8_t ipproto, AppProto alproto,
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));
@ -234,8 +231,6 @@ int AppLayerParserHasTxDetectState(uint8_t ipproto, AppProto alproto, void *alst
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);

@ -166,11 +166,6 @@ int AppLayerRegisterParser(const struct AppLayerParser *p, AppProto alproto)
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);

@ -1238,7 +1238,7 @@ static DetectTransaction GetDetectTx(const uint8_t ipproto, const AppProto alpro
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,
@ -1278,9 +1278,6 @@ static inline void StoreDetectFlags(DetectTransaction *tx, const uint8_t flow_fl
} else {
txd->detect_flags_tc = detect_flags;
}
} else {
AppLayerParserSetTxDetectFlags(ipproto, alproto, tx->tx_ptr,
flow_flags, detect_flags);
}
}

Loading…
Cancel
Save