app-layer: trunc parser per direction

pull/7957/head
Victor Julien 4 years ago
parent ff9d1807f9
commit 01e64d80da

@ -430,6 +430,8 @@ pub const APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD : u16 = BIT_U16!(3);
pub const APP_LAYER_PARSER_BYPASS_READY : u16 = BIT_U16!(4); pub const APP_LAYER_PARSER_BYPASS_READY : u16 = BIT_U16!(4);
pub const APP_LAYER_PARSER_EOF_TS : u16 = BIT_U16!(5); pub const APP_LAYER_PARSER_EOF_TS : u16 = BIT_U16!(5);
pub const APP_LAYER_PARSER_EOF_TC : u16 = BIT_U16!(6); pub const APP_LAYER_PARSER_EOF_TC : u16 = BIT_U16!(6);
pub const APP_LAYER_PARSER_TRUNC_TS : u16 = BIT_U16!(7);
pub const APP_LAYER_PARSER_TRUNC_TC : u16 = BIT_U16!(8);
pub const APP_LAYER_PARSER_OPT_ACCEPT_GAPS: u32 = BIT_U32!(0); pub const APP_LAYER_PARSER_OPT_ACCEPT_GAPS: u32 = BIT_U32!(0);
pub const APP_LAYER_PARSER_OPT_UNIDIR_TXS: u32 = BIT_U32!(1); pub const APP_LAYER_PARSER_OPT_UNIDIR_TXS: u32 = BIT_U32!(1);

@ -226,6 +226,9 @@ FramesContainer *AppLayerFramesSetupContainer(Flow *f)
return f->alparser->frames; return f->alparser->frames;
} }
static inline void AppLayerParserStreamTruncated(AppLayerParserState *pstate, const uint8_t ipproto,
const AppProto alproto, void *alstate, const uint8_t direction);
#ifdef UNITTESTS #ifdef UNITTESTS
void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min) void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min)
{ {
@ -1290,8 +1293,7 @@ int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow
if (!(p->option_flags & APP_LAYER_PARSER_OPT_ACCEPT_GAPS)) { if (!(p->option_flags & APP_LAYER_PARSER_OPT_ACCEPT_GAPS)) {
SCLogDebug("app-layer parser does not accept gaps"); SCLogDebug("app-layer parser does not accept gaps");
if (f->alstate != NULL && !FlowChangeProto(f)) { if (f->alstate != NULL && !FlowChangeProto(f)) {
AppLayerParserStreamTruncated(f->proto, alproto, f->alstate, AppLayerParserStreamTruncated(pstate, f->proto, alproto, f->alstate, flags);
flags);
} }
AppLayerIncGapErrorCounter(tv, f); AppLayerIncGapErrorCounter(tv, f);
goto error; goto error;
@ -1437,7 +1439,7 @@ int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow
/* stream truncated, inform app layer */ /* stream truncated, inform app layer */
if (flags & STREAM_DEPTH) if (flags & STREAM_DEPTH)
AppLayerParserStreamTruncated(f->proto, alproto, alstate, flags); AppLayerParserStreamTruncated(pstate, f->proto, alproto, f->alstate, flags);
end: end:
/* update app progress */ /* update app progress */
@ -1755,14 +1757,20 @@ uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag
SCReturnUInt(pstate->flags & flag); SCReturnUInt(pstate->flags & flag);
} }
static inline void AppLayerParserStreamTruncated(AppLayerParserState *pstate, const uint8_t ipproto,
void AppLayerParserStreamTruncated(uint8_t ipproto, AppProto alproto, void *alstate, const AppProto alproto, void *alstate, const uint8_t direction)
uint8_t direction)
{ {
SCEnter(); SCEnter();
if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate != NULL) if (direction & STREAM_TOSERVER) {
AppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_TRUNC_TS);
} else {
AppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_TRUNC_TC);
}
if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate != NULL) {
alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate(alstate, direction); alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate(alstate, direction);
}
SCReturn; SCReturn;
} }

@ -38,6 +38,8 @@
#define APP_LAYER_PARSER_BYPASS_READY BIT_U16(4) #define APP_LAYER_PARSER_BYPASS_READY BIT_U16(4)
#define APP_LAYER_PARSER_EOF_TS BIT_U16(5) #define APP_LAYER_PARSER_EOF_TS BIT_U16(5)
#define APP_LAYER_PARSER_EOF_TC BIT_U16(6) #define APP_LAYER_PARSER_EOF_TC BIT_U16(6)
#define APP_LAYER_PARSER_TRUNC_TS BIT_U16(7)
#define APP_LAYER_PARSER_TRUNC_TC BIT_U16(8)
/* Flags for AppLayerParserProtoCtx. */ /* Flags for AppLayerParserProtoCtx. */
#define APP_LAYER_PARSER_OPT_ACCEPT_GAPS BIT_U32(0) #define APP_LAYER_PARSER_OPT_ACCEPT_GAPS BIT_U32(0)
@ -289,9 +291,6 @@ void AppLayerParserRegisterProtocolParsers(void);
void AppLayerParserStateSetFlag(AppLayerParserState *pstate, uint16_t flag); void AppLayerParserStateSetFlag(AppLayerParserState *pstate, uint16_t flag);
uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag); uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag);
void AppLayerParserStreamTruncated(uint8_t ipproto, AppProto alproto, void *alstate,
uint8_t direction);
AppLayerParserState *AppLayerParserStateAlloc(void); AppLayerParserState *AppLayerParserStateAlloc(void);
void AppLayerParserStateFree(AppLayerParserState *pstate); void AppLayerParserStateFree(AppLayerParserState *pstate);

Loading…
Cancel
Save