120 if (t->
id * 2ULL > UINT32_MAX) {
139 const uint64_t tx_id,
AppLayerTxData *txd,
const bool tx_complete,
const bool ts_ready,
140 const bool tc_ready,
const bool ts_eof,
const bool tc_eof,
const bool eof)
143 uint8_t opposing_dir;
144 bool packet_dir_ready;
145 const bool opposing_dir_ready = eof;
146 bool opposing_tx_ready;
148 packet_dir = STREAM_TOSERVER;
149 opposing_dir = STREAM_TOCLIENT;
150 packet_dir_ready = eof | ts_ready | ts_eof;
151 opposing_tx_ready = tc_ready;
153 packet_dir = STREAM_TOCLIENT;
154 opposing_dir = STREAM_TOSERVER;
155 packet_dir_ready = eof | tc_ready | tc_eof;
156 opposing_tx_ready = ts_ready;
161 SCLogDebug(
"eof %d ts_ready %d ts_eof %d", eof, ts_ready, ts_eof);
162 SCLogDebug(
"eof %d tc_ready %d tc_eof %d", eof, tc_ready, tc_eof);
164 SCLogDebug(
"packet dir %s opposing %s packet_dir_ready %d opposing_dir_ready %d",
165 packet_dir == STREAM_TOSERVER ?
"TOSERVER" :
"TOCLIENT",
166 opposing_dir == STREAM_TOSERVER ?
"TOSERVER" :
"TOCLIENT", packet_dir_ready,
176 bool opposing_finished =
177 ffc_opposing == NULL || (ffc_opposing->
head == NULL && opposing_tx_ready);
178 SCLogDebug(
"opposing_finished %d ffc_opposing %p ffc_opposing->head %p opposing_tx_ready %d",
179 opposing_finished, ffc_opposing, ffc_opposing ? ffc_opposing->
head : NULL,
182 if (ffc || ffc_opposing)
183 SCLogDebug(
"pcap_cnt %" PRIu64
" flow %p tx %p tx_id %" PRIu64
184 " ffc %p ffc_opposing %p tx_complete %d",
185 p->
pcap_cnt, f, tx, tx_id, ffc, ffc_opposing, tx_complete);
190 SCLogDebug(
"tx: calling files: ffc %p head %p file_close %d file_trunc %d", ffc, ffc->
head,
191 file_close, file_trunc);
192 if (filedata_td && txd->files_opened > txd->files_stored)
194 file_close, file_trunc, packet_dir);
195 if (file_td && txd->files_opened > txd->files_logged)
197 tv, file_td, p, ffc, tx, tx_id, txd, file_close, file_trunc, packet_dir);
200 if (opposing_dir_ready && ffc_opposing != NULL) {
203 opposing_finished =
true;
204 SCLogDebug(
"tx: calling for opposing direction files: file_close:%s file_trunc:%s",
205 file_close ?
"true" :
"false", file_trunc ?
"true" :
"false");
206 if (filedata_td && txd->files_opened > txd->files_stored)
208 opposing_dir, file_close, file_trunc, opposing_dir);
209 if (file_td && txd->files_opened > txd->files_logged)
210 OutputFileLogFfc(
tv, file_td, p, ffc_opposing, tx, tx_id, txd, file_close, file_trunc,
214 const bool tx_done = packet_dir_ready && opposing_finished;
215 SCLogDebug(
"tx_done %d packet_dir_ready %d opposing_finished %d", tx_done, packet_dir_ready,
219 const bool is_file_tx = (ffc != NULL || ffc_opposing != NULL);
220 if (!is_file_tx || tx_done) {
221 SCLogDebug(
"is_file_tx %d tx_done %d", is_file_tx, tx_done);
224 SCLogDebug(
"setting LOGGER_FILE => %08x", txd->logged.flags);
228 SCLogDebug(
"setting LOGGER_FILEDATA => %08x", txd->logged.flags);
231 SCLogDebug(
"pcap_cnt %" PRIu64
" flow %p tx %p tx_id %" PRIu64
232 " NOT SETTING FILE FLAGS ffc %p ffc_opposing %p tx_complete %d",
233 p->
pcap_cnt, f, tx, tx_id, ffc, ffc_opposing, tx_complete);
238 Flow *f,
void *tx,
const uint64_t tx_id)
247 while (logger && store) {
258 logger = logger->
next;
273 void *alstate,
void *tx,
const uint64_t tx_id,
const AppProto alproto,
const bool eof,
274 const int tx_progress_ts,
const int tx_progress_tc,
struct Ctx *
ctx)
280 while (logger && store) {
284 SCLogDebug(
"logger %p, Alproto %d LogCondition %p, ts_log_progress %d "
285 "tc_log_progress %d",
292 tx_id, logger->
logger_id, eof ?
"true" :
"false");
299 SCLogDebug(
"conditions not met, not logging");
303 if (tx_progress_tc < logger->tc_log_progress) {
304 SCLogDebug(
"progress not far enough, not logging");
308 if (tx_progress_ts < logger->ts_log_progress) {
309 SCLogDebug(
"progress not far enough, not logging");
324 logger = logger->
next;
340 SCLogDebug(
"not pseudo, no app update: skip");
346 SCLogDebug(
"pseudo, or app update: run output");
351 const uint8_t ipproto = f->
proto;
356 const bool file_logging_active = (op_thread_data->
file || op_thread_data->
filedata);
357 if (!file_logging_active) {
367 if (alstate == NULL) {
372 if (logger_expectation == 0) {
373 SCLogDebug(
"bail: logger_expectation %u. LOGGER_FILE %u LOGGER_FILEDATA %u",
383 const bool eof = last_pseudo || (ts_eof && tc_eof);
384 SCLogDebug(
"eof %d last_pseudo %d ts_eof %d tc_eof %d", eof, last_pseudo, ts_eof, tc_eof);
388 SCLogDebug(
"ts_disrupt_flags %02x tc_disrupt_flags %02x", ts_disrupt_flags, tc_disrupt_flags);
391 uint64_t max_id = tx_id;
397 SCLogDebug(
"pcap_cnt %" PRIu64
": tx_id %" PRIu64
" total_txs %" PRIu64, p->
pcap_cnt, tx_id,
402 memset(&state, 0,
sizeof(state));
404 const int complete_ts =
406 const int complete_tc =
409 AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, tx_id, total_txs, &state);
410 if (ires.tx_ptr == NULL)
412 void *
const tx = ires.tx_ptr;
414 SCLogDebug(
"STARTING tx_id %" PRIu64
", tx %p", tx_id, tx);
416 const int tx_progress_ts =
418 const int tx_progress_tc =
420 const bool tx_complete = (tx_progress_ts == complete_ts && tx_progress_tc == complete_tc);
422 SCLogDebug(
"file_thread_data %p filedata_thread_data %p", op_thread_data->
file,
434 if (file_logging_active) {
435 if (AppLayerParserIsFileTx(txd)) {
437 const bool ts_ready = (tx_progress_ts == complete_ts);
438 const bool tc_ready = (tx_progress_tc == complete_tc);
439 SCLogDebug(
"ts_ready %d tc_ready %d", ts_ready, tc_ready);
441 const bool eval_files = ts_ready | tc_ready | tx_complete | ts_eof | tc_eof | eof;
443 SCLogDebug(
"eval_files: %u, ts_ready %u, tc_ready %u, tx_complete %u, ts_eof %u, "
445 eval_files, ts_ready, tc_ready, tx_complete, ts_eof, tc_eof, eof);
446 SCLogDebug(
"txd->file_tx & pkt_dir: %02x & %02x -> %02x", txd->file_tx, pkt_dir,
447 (txd->file_tx & pkt_dir));
452 if (eval_files || AppLayerParserIsFileTxInDir(txd, pkt_dir)) {
453 OutputTxLogFiles(
tv, op_thread_data->
file, op_thread_data->
filedata, p, f, tx,
454 tx_id, txd, tx_complete, ts_ready, tc_ready, ts_eof, tc_eof, eof);
456 }
else if (support_files) {
457 if (op_thread_data->
file) {
459 SCLogDebug(
"not a file_tx: setting LOGGER_FILE => %08x", txd->logged.flags);
463 SCLogDebug(
"not a file_tx: setting LOGGER_FILEDATA => %08x", txd->logged.flags);
467 SCLogDebug(
"logger: expect %08x, have %08x", logger_expectation, txd->logged.flags);
470 OutputTxLogList0(
tv, op_thread_data, p, f, tx, tx_id);
471 if (list[alproto] == NULL)
475 SCLogDebug(
"tx %p/%" PRIu64
" txd %p: log_flags %x logger_expectation %x", tx, tx_id, txd,
476 txd->config.log_flags, logger_expectation);
480 txd->logged.flags |= logger_expectation;
484 if (txd->logged.flags == logger_expectation) {
490 SCLogDebug(
"logger: expect %08x, have %08x", logger_expectation, txd->logged.flags);
493 struct Ctx ctx = { .tx_logged = txd->logged.flags, .tx_logged_old = txd->logged.flags };
494 SCLogDebug(
"logger: expect %08x, have %08x", logger_expectation,
ctx.tx_logged);
496 OutputTxLogCallLoggers(
tv, op_thread_data, logger, store, p, f, alstate, tx, tx_id, alproto,
497 eof, tx_progress_ts, tx_progress_tc, &
ctx);
499 SCLogDebug(
"logger: expect %08x, have %08x", logger_expectation,
ctx.tx_logged);
500 if (
ctx.tx_logged !=
ctx.tx_logged_old) {
501 SCLogDebug(
"logger: storing %08x (was %08x)",
ctx.tx_logged,
ctx.tx_logged_old);
503 txd->logged.flags |=
ctx.tx_logged;
512 if (!gap &&
ctx.tx_logged == logger_expectation) {
513 SCLogDebug(
"no gap %d, %08x == %08x", gap,
ctx.tx_logged, logger_expectation);
529 SCLogDebug(
"updating log tx_id %"PRIu64, max_id);
548 SCLogDebug(
"OutputTxLogThreadInit happy (*data %p)", *data);
560 ts->thread_data = retptr;
562 if (td->
store[alproto] == NULL) {
566 while (tmp->
next != NULL)
575 logger = logger->
next;
581 FatalError(
"failed to set up file thread data");
586 FatalError(
"failed to set up filedata thread data");
603 while (logger && store) {
611 logger = logger->
next;
615 if (op_thread_data->
file) {
626 static void OutputTxLogExitPrintStats(
ThreadVars *
tv,
void *thread_data)
634 while (logger && store) {
639 logger = logger->
next;
645 static uint32_t OutputTxLoggerGetActiveCount(
void)
670 OutputTxLogExitPrintStats, OutputTxLog, OutputTxLoggerGetActiveCount);
680 logger = next_logger;
682 list[alproto] = NULL;