121 if (t->
id * 2ULL > UINT32_MAX) {
140 const uint64_t tx_id,
AppLayerTxData *txd,
const bool tx_complete,
const bool ts_ready,
141 const bool tc_ready,
const bool ts_eof,
const bool tc_eof,
const bool eof)
144 uint8_t opposing_dir;
145 bool packet_dir_ready;
146 const bool opposing_dir_ready = eof;
147 bool opposing_tx_ready;
149 packet_dir = STREAM_TOSERVER;
150 opposing_dir = STREAM_TOCLIENT;
151 packet_dir_ready = eof | ts_ready | ts_eof;
152 opposing_tx_ready = tc_ready;
154 packet_dir = STREAM_TOCLIENT;
155 opposing_dir = STREAM_TOSERVER;
156 packet_dir_ready = eof | tc_ready | tc_eof;
157 opposing_tx_ready = ts_ready;
162 SCLogDebug(
"eof %d ts_ready %d ts_eof %d", eof, ts_ready, ts_eof);
163 SCLogDebug(
"eof %d tc_ready %d tc_eof %d", eof, tc_ready, tc_eof);
165 SCLogDebug(
"packet dir %s opposing %s packet_dir_ready %d opposing_dir_ready %d",
166 packet_dir == STREAM_TOSERVER ?
"TOSERVER" :
"TOCLIENT",
167 opposing_dir == STREAM_TOSERVER ?
"TOSERVER" :
"TOCLIENT", packet_dir_ready,
170 AppLayerGetFileState app_files =
173 AppLayerGetFileState app_files_opposing =
179 bool opposing_finished =
180 ffc_opposing == NULL || (ffc_opposing->
head == NULL && opposing_tx_ready);
181 SCLogDebug(
"opposing_finished %d ffc_opposing %p ffc_opposing->head %p opposing_tx_ready %d",
182 opposing_finished, ffc_opposing, ffc_opposing ? ffc_opposing->
head : NULL,
185 if (ffc || ffc_opposing)
186 SCLogDebug(
"pcap_cnt %" PRIu64
" flow %p tx %p tx_id %" PRIu64
187 " ffc %p ffc_opposing %p tx_complete %d",
188 p->
pcap_cnt, f, tx, tx_id, ffc, ffc_opposing, tx_complete);
193 SCLogDebug(
"tx: calling files: ffc %p head %p file_close %d file_trunc %d", ffc, ffc->
head,
194 file_close, file_trunc);
195 if (filedata_td && txd->files_opened > txd->files_stored)
197 file_close, file_trunc, packet_dir);
198 if (file_td && txd->files_opened > txd->files_logged)
200 tv, file_td, p, ffc, tx, tx_id, txd, file_close, file_trunc, packet_dir);
203 if (opposing_dir_ready && ffc_opposing != NULL) {
206 opposing_finished =
true;
207 SCLogDebug(
"tx: calling for opposing direction files: file_close:%s file_trunc:%s",
208 file_close ?
"true" :
"false", file_trunc ?
"true" :
"false");
209 if (filedata_td && txd->files_opened > txd->files_stored)
211 opposing_dir, file_close, file_trunc, opposing_dir);
212 if (file_td && txd->files_opened > txd->files_logged)
213 OutputFileLogFfc(
tv, file_td, p, ffc_opposing, tx, tx_id, txd, file_close, file_trunc,
217 const bool tx_done = packet_dir_ready && opposing_finished;
218 SCLogDebug(
"tx_done %d packet_dir_ready %d opposing_finished %d", tx_done, packet_dir_ready,
222 const bool is_file_tx = (ffc != NULL || ffc_opposing != NULL);
223 if (!is_file_tx || tx_done) {
224 SCLogDebug(
"is_file_tx %d tx_done %d", is_file_tx, tx_done);
227 SCLogDebug(
"setting LOGGER_FILE => %08x", txd->logged.flags);
231 SCLogDebug(
"setting LOGGER_FILEDATA => %08x", txd->logged.flags);
234 SCLogDebug(
"pcap_cnt %" PRIu64
" flow %p tx %p tx_id %" PRIu64
235 " NOT SETTING FILE FLAGS ffc %p ffc_opposing %p tx_complete %d",
236 p->
pcap_cnt, f, tx, tx_id, ffc, ffc_opposing, tx_complete);
241 Flow *f,
void *tx,
const uint64_t tx_id)
250 while (logger && store) {
261 logger = logger->
next;
276 void *alstate,
void *tx,
const uint64_t tx_id,
const AppProto alproto,
const bool eof,
277 const int tx_progress_ts,
const int tx_progress_tc,
struct Ctx *ctx)
283 while (logger && store) {
287 SCLogDebug(
"logger %p, Alproto %d LogCondition %p, ts_log_progress %d "
288 "tc_log_progress %d",
295 tx_id, logger->
logger_id, eof ?
"true" :
"false");
302 SCLogDebug(
"conditions not met, not logging");
306 if (tx_progress_tc < logger->tc_log_progress) {
307 SCLogDebug(
"progress not far enough, not logging");
311 if (tx_progress_ts < logger->ts_log_progress) {
312 SCLogDebug(
"progress not far enough, not logging");
327 logger = logger->
next;
343 SCLogDebug(
"not pseudo, no app update: skip");
349 SCLogDebug(
"pseudo, or app update: run output");
354 const uint8_t ipproto = f->
proto;
359 const bool file_logging_active = (op_thread_data->
file || op_thread_data->
filedata);
360 if (!file_logging_active) {
370 if (alstate == NULL) {
375 if (logger_expectation == 0) {
376 SCLogDebug(
"bail: logger_expectation %u. LOGGER_FILE %u LOGGER_FILEDATA %u",
388 const bool eof = last_pseudo || (ts_eof && tc_eof);
389 SCLogDebug(
"eof %d last_pseudo %d ts_eof %d tc_eof %d", eof, last_pseudo, ts_eof, tc_eof);
393 SCLogDebug(
"ts_disrupt_flags %02x tc_disrupt_flags %02x", ts_disrupt_flags, tc_disrupt_flags);
396 uint64_t max_id = tx_id;
402 SCLogDebug(
"pcap_cnt %" PRIu64
": tx_id %" PRIu64
" total_txs %" PRIu64, p->
pcap_cnt, tx_id,
407 memset(&state, 0,
sizeof(state));
409 const int complete_ts =
411 const int complete_tc =
414 AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, tx_id, total_txs, &state);
415 if (ires.tx_ptr == NULL)
417 void *
const tx = ires.tx_ptr;
419 SCLogDebug(
"STARTING tx_id %" PRIu64
", tx %p", tx_id, tx);
421 const int tx_progress_ts =
423 const int tx_progress_tc =
425 const bool tx_complete = (tx_progress_ts == complete_ts && tx_progress_tc == complete_tc);
427 SCLogDebug(
"file_thread_data %p filedata_thread_data %p", op_thread_data->
file,
439 if (file_logging_active) {
440 if (AppLayerParserIsFileTx(txd)) {
442 const bool ts_ready = (tx_progress_ts == complete_ts);
443 const bool tc_ready = (tx_progress_tc == complete_tc);
444 SCLogDebug(
"ts_ready %d tc_ready %d", ts_ready, tc_ready);
446 const bool eval_files = ts_ready | tc_ready | tx_complete | ts_eof | tc_eof | eof;
448 SCLogDebug(
"eval_files: %u, ts_ready %u, tc_ready %u, tx_complete %u, ts_eof %u, "
450 eval_files, ts_ready, tc_ready, tx_complete, ts_eof, tc_eof, eof);
451 SCLogDebug(
"txd->file_tx & pkt_dir: %02x & %02x -> %02x", txd->file_tx, pkt_dir,
452 (txd->file_tx & pkt_dir));
457 if (eval_files || AppLayerParserIsFileTxInDir(txd, pkt_dir)) {
458 OutputTxLogFiles(
tv, op_thread_data->
file, op_thread_data->
filedata, p, f, tx,
459 tx_id, txd, tx_complete, ts_ready, tc_ready, ts_eof, tc_eof, eof);
461 }
else if (support_files) {
462 if (op_thread_data->
file) {
464 SCLogDebug(
"not a file_tx: setting LOGGER_FILE => %08x", txd->logged.flags);
468 SCLogDebug(
"not a file_tx: setting LOGGER_FILEDATA => %08x", txd->logged.flags);
472 SCLogDebug(
"logger: expect %08x, have %08x", logger_expectation, txd->logged.flags);
475 OutputTxLogList0(
tv, op_thread_data, p, f, tx, tx_id);
476 if (list[alproto] == NULL)
480 SCLogDebug(
"tx %p/%" PRIu64
" txd %p: log_flags %x logger_expectation %x", tx, tx_id, txd,
481 txd->config.log_flags, logger_expectation);
485 txd->logged.flags |= logger_expectation;
489 if (txd->logged.flags == logger_expectation) {
495 SCLogDebug(
"logger: expect %08x, have %08x", logger_expectation, txd->logged.flags);
498 struct Ctx ctx = { .
tx_logged = txd->logged.flags, .tx_logged_old = txd->logged.flags };
501 OutputTxLogCallLoggers(
tv, op_thread_data, logger, store, p, f, alstate, tx, tx_id, alproto,
502 eof, tx_progress_ts, tx_progress_tc, &ctx);
517 if (!gap && ctx.
tx_logged == logger_expectation) {
534 SCLogDebug(
"updating log tx_id %"PRIu64, max_id);
552 SCLogDebug(
"OutputTxLogThreadInit happy (*data %p)", *data);
564 ts->thread_data = retptr;
566 if (td->
store[alproto] == NULL) {
570 while (tmp->
next != NULL)
579 logger = logger->
next;
585 FatalError(
"failed to set up file thread data");
590 FatalError(
"failed to set up filedata thread data");
607 while (logger && store) {
615 logger = logger->
next;
619 if (op_thread_data->
file) {
630 static void OutputTxLogExitPrintStats(
ThreadVars *
tv,
void *thread_data)
638 while (logger && store) {
643 logger = logger->
next;
649 static uint32_t OutputTxLoggerGetActiveCount(
void)
674 OutputTxLogExitPrintStats, OutputTxLog, OutputTxLoggerGetActiveCount);
684 logger = next_logger;
686 list[alproto] = NULL;