Skip to content

Commit

Permalink
applayer: remove truncation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inashivb committed Jun 28, 2024
1 parent 5bd1793 commit 5510e09
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 37 deletions.
2 changes: 0 additions & 2 deletions rust/src/applayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,6 @@ 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_EOF_TS : u16 = BIT_U16!(5);
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);

Expand Down
33 changes: 4 additions & 29 deletions src/app-layer-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ FramesContainer *AppLayerFramesSetupContainer(Flow *f)
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
void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min)
{
Expand Down Expand Up @@ -947,11 +944,7 @@ void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir)
AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
if (txd != NULL && AppLayerParserHasFilesInDir(txd, pkt_dir)) {
if (pkt_dir_trunc == -1)
pkt_dir_trunc =
AppLayerParserStateIssetFlag(f->alparser,
(pkt_dir == STREAM_TOSERVER) ? APP_LAYER_PARSER_TRUNC_TS
: APP_LAYER_PARSER_TRUNC_TC) != 0;

pkt_dir_trunc = IS_DISRUPTED((pkt_dir == STREAM_TOSERVER) ? ts_disrupt_flags : tc_disrupt_flags);
AppLayerParserFileTxHousekeeping(f, tx, pkt_dir, (bool)pkt_dir_trunc);
}

Expand Down Expand Up @@ -1308,7 +1301,7 @@ int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow
if (!(p->option_flags & APP_LAYER_PARSER_OPT_ACCEPT_GAPS)) {
SCLogDebug("app-layer parser does not accept gaps");
if (f->alstate != NULL && !FlowChangeProto(f)) {
AppLayerParserStreamTruncated(pstate, f->proto, alproto, f->alstate, flags);
AppLayerParserTriggerRawStreamReassembly(f, direction);
}
AppLayerIncGapErrorCounter(tv, f);
goto error;
Expand Down Expand Up @@ -1468,9 +1461,9 @@ int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow
AppLayerIncTxCounter(tv, f, cur_tx_cnt - p_tx_cnt);
}

/* stream truncated, inform app layer */
/* stream truncated, trigger raw stream reassembly */
if (flags & STREAM_DEPTH)
AppLayerParserStreamTruncated(pstate, f->proto, alproto, f->alstate, flags);
AppLayerParserTriggerRawStreamReassembly(f, direction);

end:
/* update app progress */
Expand Down Expand Up @@ -1796,24 +1789,6 @@ uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag
SCReturnUInt(pstate->flags & flag);
}

static inline void AppLayerParserStreamTruncated(AppLayerParserState *pstate, const uint8_t ipproto,
const AppProto alproto, void *alstate, const uint8_t direction)
{
SCEnter();

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);
}

SCReturn;
}

/***** Unittests *****/

#ifdef UNITTESTS
Expand Down
3 changes: 1 addition & 2 deletions src/app-layer-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
#define APP_LAYER_PARSER_BYPASS_READY BIT_U16(4)
#define APP_LAYER_PARSER_EOF_TS BIT_U16(5)
#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)
/* 2x vacancy */
#define APP_LAYER_PARSER_SFRAME_TS BIT_U16(9)
#define APP_LAYER_PARSER_SFRAME_TC BIT_U16(10)

Expand Down
6 changes: 2 additions & 4 deletions src/output-tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,8 @@ static TmEcode OutputTxLog(ThreadVars *tv, Packet *p, void *thread_data)
SCLogDebug("pcap_cnt %" PRIu64, p->pcap_cnt);

const bool last_pseudo = (p->flowflags & FLOW_PKT_LAST_PSEUDO) != 0;
const bool ts_eof = AppLayerParserStateIssetFlag(f->alparser,
(APP_LAYER_PARSER_EOF_TS | APP_LAYER_PARSER_TRUNC_TS)) != 0;
const bool tc_eof = AppLayerParserStateIssetFlag(f->alparser,
(APP_LAYER_PARSER_EOF_TC | APP_LAYER_PARSER_TRUNC_TC)) != 0;
const bool ts_eof = AppLayerParserStateIssetFlag(f->alparser, APP_LAYER_PARSER_EOF_TS) != 0;
const bool tc_eof = AppLayerParserStateIssetFlag(f->alparser, APP_LAYER_PARSER_EOF_TC) != 0;

const bool eof = last_pseudo || (ts_eof && tc_eof);
SCLogDebug("eof %d last_pseudo %d ts_eof %d tc_eof %d", eof, last_pseudo, ts_eof, tc_eof);
Expand Down

0 comments on commit 5510e09

Please sign in to comment.