73 SCLogError(
"Failed to allocate OutputTx list");
123 if (t->
id * 2ULL > UINT32_MAX) {
142 const uint64_t tx_id,
AppLayerTxData *txd,
const bool tx_complete,
const bool ts_ready,
143 const bool tc_ready,
const bool ts_eof,
const bool tc_eof,
const bool eof)
146 uint8_t opposing_dir;
147 bool packet_dir_ready;
148 const bool opposing_dir_ready = eof;
149 bool opposing_tx_ready;
151 packet_dir = STREAM_TOSERVER;
152 opposing_dir = STREAM_TOCLIENT;
153 packet_dir_ready = eof | ts_ready | ts_eof;
154 opposing_tx_ready = tc_ready;
156 packet_dir = STREAM_TOCLIENT;
157 opposing_dir = STREAM_TOSERVER;
158 packet_dir_ready = eof | tc_ready | tc_eof;
159 opposing_tx_ready = ts_ready;
164 SCLogDebug(
"eof %d ts_ready %d ts_eof %d", eof, ts_ready, ts_eof);
165 SCLogDebug(
"eof %d tc_ready %d tc_eof %d", eof, tc_ready, tc_eof);
167 SCLogDebug(
"packet dir %s opposing %s packet_dir_ready %d opposing_dir_ready %d",
168 packet_dir == STREAM_TOSERVER ?
"TOSERVER" :
"TOCLIENT",
169 opposing_dir == STREAM_TOSERVER ?
"TOSERVER" :
"TOCLIENT", packet_dir_ready,
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",
386 const bool eof = last_pseudo || (ts_eof && tc_eof);
387 SCLogDebug(
"eof %d last_pseudo %d ts_eof %d tc_eof %d", eof, last_pseudo, ts_eof, tc_eof);
391 SCLogDebug(
"ts_disrupt_flags %02x tc_disrupt_flags %02x", ts_disrupt_flags, tc_disrupt_flags);
394 uint64_t max_id = tx_id;
400 SCLogDebug(
"pcap_cnt %" PRIu64
": tx_id %" PRIu64
" total_txs %" PRIu64, p->
pcap_cnt, tx_id,
405 memset(&state, 0,
sizeof(state));
407 const int complete_ts =
409 const int complete_tc =
413 if (ires.tx_ptr == NULL)
415 void *
const tx = ires.tx_ptr;
417 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,
430 if (file_logging_active) {
431 if (txd->file_tx != 0) {
433 const bool ts_ready = (tx_progress_ts == complete_ts);
434 const bool tc_ready = (tx_progress_tc == complete_tc);
435 SCLogDebug(
"ts_ready %d tc_ready %d", ts_ready, tc_ready);
437 const bool eval_files = ts_ready | tc_ready | tx_complete | ts_eof | tc_eof | eof;
439 SCLogDebug(
"eval_files: %u, ts_ready %u, tc_ready %u, tx_complete %u, ts_eof %u, "
441 eval_files, ts_ready, tc_ready, tx_complete, ts_eof, tc_eof, eof);
442 SCLogDebug(
"txd->file_tx & pkt_dir: %02x & %02x -> %02x", txd->file_tx, pkt_dir,
443 (txd->file_tx & pkt_dir));
448 if (eval_files || ((txd->file_tx & pkt_dir) != 0)) {
449 OutputTxLogFiles(
tv, op_thread_data->
file, op_thread_data->
filedata, p, f, tx,
450 tx_id, txd, tx_complete, ts_ready, tc_ready, ts_eof, tc_eof, eof);
452 }
else if (support_files) {
453 if (op_thread_data->
file) {
455 SCLogDebug(
"not a file_tx: setting LOGGER_FILE => %08x", txd->logged.flags);
459 SCLogDebug(
"not a file_tx: setting LOGGER_FILEDATA => %08x", txd->logged.flags);
463 SCLogDebug(
"logger: expect %08x, have %08x", logger_expectation, txd->logged.flags);
464 if (!txd->updated_tc && !txd->updated_ts && !(tx_progress_ts == complete_ts) &&
465 !(tx_progress_tc == complete_tc) && !ts_eof && !tc_eof) {
471 OutputTxLogList0(
tv, op_thread_data, p, f, tx, tx_id);
472 if (list[alproto] == NULL)
476 SCLogDebug(
"tx %p/%" PRIu64
" txd %p: log_flags %x logger_expectation %x", tx, tx_id, txd,
477 txd->config.log_flags, logger_expectation);
481 txd->logged.flags |= logger_expectation;
485 if (txd->logged.flags == logger_expectation) {
491 SCLogDebug(
"logger: expect %08x, have %08x", logger_expectation, txd->logged.flags);
494 struct Ctx ctx = { .tx_logged = txd->logged.flags, .tx_logged_old = txd->logged.flags };
495 SCLogDebug(
"logger: expect %08x, have %08x", logger_expectation,
ctx.tx_logged);
497 OutputTxLogCallLoggers(
tv, op_thread_data, logger, store, p, f, alstate, tx, tx_id, alproto,
498 eof, tx_progress_ts, tx_progress_tc, &
ctx);
500 SCLogDebug(
"logger: expect %08x, have %08x", logger_expectation,
ctx.tx_logged);
501 if (
ctx.tx_logged !=
ctx.tx_logged_old) {
502 SCLogDebug(
"logger: storing %08x (was %08x)",
ctx.tx_logged,
ctx.tx_logged_old);
504 txd->logged.flags |=
ctx.tx_logged;
513 if (!gap &&
ctx.tx_logged == logger_expectation) {
514 SCLogDebug(
"no gap %d, %08x == %08x", gap,
ctx.tx_logged, logger_expectation);
530 SCLogDebug(
"updating log tx_id %"PRIu64, max_id);
549 SCLogDebug(
"OutputTxLogThreadInit happy (*data %p)", *data);
561 ts->thread_data = retptr;
563 if (td->
store[alproto] == NULL) {
567 while (tmp->
next != NULL)
576 logger = logger->
next;
582 FatalError(
"failed to set up file thread data");
587 FatalError(
"failed to set up filedata thread data");
604 while (logger && store) {
612 logger = logger->
next;
616 if (op_thread_data->
file) {
627 static uint32_t OutputTxLoggerGetActiveCount(
void)
654 FatalError(
"Failed to allocate OutputTx list");
657 OutputTxLoggerGetActiveCount);
671 logger = next_logger;
673 list[alproto] = NULL;