33 #if defined(HAVE_DIRENT_H) && defined(HAVE_FNMATCH_H)
34 #define INIT_RING_BUFFER
58 #define DEFAULT_LOG_FILENAME "pcaplog"
59 #define MODULE_NAME "PcapLog"
60 #define MIN_LIMIT 4 * 1024 * 1024
61 #define DEFAULT_LIMIT 100 * 1024 * 1024
62 #define DEFAULT_FILE_LIMIT 0
64 #define LOGMODE_NORMAL 0
65 #define LOGMODE_MULTI 1
73 #define RING_BUFFER_MODE_DISABLED 0
74 #define RING_BUFFER_MODE_ENABLED 1
76 #define TS_FORMAT_SEC 0
77 #define TS_FORMAT_USEC 1
79 #define USE_STREAM_DEPTH_DISABLED 0
80 #define USE_STREAM_DEPTH_ENABLED 1
82 #define HONOR_PASS_RULES_DISABLED 0
83 #define HONOR_PASS_RULES_ENABLED 1
85 #define PCAP_SNAPLEN 262144
86 #define PCAP_BUFFER_TIMEOUT 1000000 // microseconds
87 #define PCAP_PKTHDR_SIZE 16
90 #ifndef PCAP_NETMASK_UNKNOWN
91 #define PCAP_NETMASK_UNKNOWN 0xffffffff
118 #define MAX_FILENAMELEN 513
130 LZ4F_compressionContext_t lz4f_context;
131 LZ4F_preferences_t lz4f_prefs;
132 FILE *pcap_buf_wrapper;
151 struct pcap_pkthdr *
h;
177 uint32_t thread_number;
179 int timestamp_format;
186 int filename_part_cnt;
187 struct timeval last_pcap_dump;
203 static const char timestamp_pattern[] =
".*?(\\d+)(\\.(\\d+))?";
204 static pcre2_code *pcre_timestamp_code = NULL;
205 static pcre2_match_data *pcre_timestamp_match = NULL;
215 static void PcapLogFileDeInitCtx(
OutputCtx *);
224 .ConditionFunc = PcapLogCondition,
225 .ThreadInitFunc = PcapLogDataInit,
226 .ThreadDeinitFunc = PcapLogDataDeinit,
227 .ThreadExitPrintStatsFunc = NULL,
236 #define PCAPLOG_PROFILE_START \
237 uint64_t pcaplog_profile_ticks = UtilCpuGetTicks()
239 #define PCAPLOG_PROFILE_END(prof) \
240 (prof).total += (UtilCpuGetTicks() - pcaplog_profile_ticks); \
261 return !PacketIsTunnelChild(
p);
280 comp->pcap_buf_wrapper = NULL;
297 uint64_t bytes_written = LZ4F_compressEnd(comp->lz4f_context,
299 if (LZ4F_isError(bytes_written)) {
300 SCLogError(
"LZ4F_compressEnd: %s", LZ4F_getErrorName(bytes_written));
303 if (fwrite(comp->
buffer, 1, bytes_written, comp->
file) < bytes_written) {
304 SCLogError(
"fwrite failed: %s", strerror(errno));
346 if (PcapLogCloseFile(t,pl) < 0) {
363 PcapFileNameFree(pf);
367 if (PcapLogOpenFileCtx(pl) < 0) {
368 SCLogError(
"opening new pcap log file failed");
383 if (PacketIsTunnelChild(
p)) {
388 SCLogDebug(
"Setting pcap-log link type to %u", datalink);
395 struct bpf_program bpfp;
402 if (pl->
bpfp == NULL) {
403 FatalError(
"Failed to allocate memory for BPF filter, aborting");
414 if (!pl->pcap_open_err) {
416 pl->pcap_open_err =
true;
420 pl->pcap_open_err =
false;
428 if (comp->
file == NULL) {
429 if (errno != pl->fopen_err) {
430 SCLogError(
"Error opening file for compressed output: %s", strerror(errno));
431 pl->fopen_err = errno;
439 if (comp->pcap_buf_wrapper == NULL) {
446 if (!pl->pcap_open_err) {
448 pl->pcap_open_err =
true;
452 fclose(comp->pcap_buf_wrapper);
453 comp->pcap_buf_wrapper = NULL;
456 pl->pcap_open_err =
false;
459 uint64_t bytes_written = LZ4F_compressBegin(comp->lz4f_context,
461 if (LZ4F_isError(bytes_written)) {
462 SCLogError(
"LZ4F_compressBegin: %s", LZ4F_getErrorName(bytes_written));
465 if (fwrite(comp->
buffer, 1, bytes_written, comp->
file) < bytes_written) {
466 SCLogError(
"fwrite failed: %s", strerror(errno));
503 static inline int PcapWrite(
506 struct timeval current_dump;
507 gettimeofday(¤t_dump, NULL);
511 if (pcap_offline_filter(pl->
bpfp, pl->
h, data) == 0) {
512 SCLogDebug(
"Packet doesn't match filter, will not be logged.");
528 long in_size = ftell(comp->pcap_buf_wrapper);
530 SCLogError(
"ftell failed with: %s", strerror(errno));
533 uint64_t out_size = LZ4F_compressUpdate(comp->lz4f_context, comp->
buffer, comp->
buffer_size,
534 comp->
pcap_buf, (uint64_t)in_size, NULL);
535 if (LZ4F_isError(
len)) {
536 SCLogError(
"LZ4F_compressUpdate: %s", LZ4F_getErrorName(
len));
539 if (fseek(comp->pcap_buf_wrapper, 0, SEEK_SET) != 0) {
540 SCLogError(
"fseek failed: %s", strerror(errno));
543 if (fwrite(comp->
buffer, 1, out_size, comp->
file) < out_size) {
544 SCLogError(
"fwrite failed: %s", strerror(errno));
558 pl->last_pcap_dump = current_dump;
567 static int PcapLogSegmentCallback(
568 const Packet *
p,
TcpSegment *seg,
void *data,
const uint8_t *buf, uint32_t buflen)
579 MemBufferReset(pctx->
td->
buf);
627 if (PacketIsTunnelChild(
p)) {
639 ret = PcapLogOpenFileCtx(pl);
650 if (PcapLogRotateFile(
tv, pl) < 0) {
666 if (PcapLogRotateFile(
tv, pl) < 0) {
689 if (PacketIsTCP(
p)) {
691 PcapLogDumpSegments(
tv,
td,
p);
701 if (PacketIsTunnelChild(
p)) {
714 if (PacketIsTunnelChild(
p)) {
729 SCLogDebug(
"pl->size_current %"PRIu64
", pl->size_limit %"PRIu64,
750 copy->prefix =
SCStrdup(pl->prefix);
751 if (
unlikely(copy->prefix == NULL)) {
757 copy->suffix = pl->suffix;
763 copy->use_ringbuffer = pl->use_ringbuffer;
764 copy->timestamp_format = pl->timestamp_format;
780 copy_comp->lz4f_prefs = comp->lz4f_prefs;
785 if (copy_comp->
buffer == NULL) {
786 SCLogError(
"SCMalloc failed: %s", strerror(errno));
794 SCLogError(
"SCMalloc failed: %s", strerror(errno));
803 if (copy_comp->pcap_buf_wrapper == NULL) {
804 SCLogError(
"SCFmemopen failed: %s", strerror(errno));
815 LZ4F_errorCode_t errcode =
816 LZ4F_createCompressionContext(©_comp->lz4f_context, 1);
817 if (LZ4F_isError(errcode)) {
818 SCLogError(
"LZ4F_createCompressionContext failed: %s", LZ4F_getErrorName(errcode));
819 fclose(copy_comp->pcap_buf_wrapper);
830 copy_comp->
file = NULL;
838 strlcpy(copy->dir, pl->dir,
sizeof(copy->dir));
840 for (
int i = 0; i < pl->filename_part_cnt && i <
MAX_TOKS; i++)
841 copy->filename_parts[i] = pl->filename_parts[i];
842 copy->filename_part_cnt = pl->filename_part_cnt;
851 #ifdef INIT_RING_BUFFER
852 static int PcapLogGetTimeOfFile(
const char *filename, uint64_t *secs,
858 int n = pcre2_match(pcre_timestamp_code, (PCRE2_SPTR8)filename, strlen(filename), 0, 0,
859 pcre_timestamp_match, NULL);
860 if (n != 2 && n != 4) {
867 copylen =
sizeof(buf);
868 if (pcre2_substring_copy_bynumber(pcre_timestamp_match, 1, (PCRE2_UCHAR8 *)buf, ©len) <
878 copylen =
sizeof(buf);
879 if (pcre2_substring_copy_bynumber(pcre_timestamp_match, 3, (PCRE2_UCHAR8 *)buf, ©len) <
893 char pattern[PATH_MAX];
895 SCLogInfo(
"Initializing PCAP ring buffer for %s/%s.",
896 pl->dir, pl->prefix);
898 strlcpy(pattern, pl->dir, PATH_MAX);
899 if (pattern[strlen(pattern) - 1] !=
'/') {
900 strlcat(pattern,
"/", PATH_MAX);
903 for (
int i = 0; i < pl->filename_part_cnt; i++) {
904 char *part = pl->filename_parts[i];
905 if (part == NULL || strlen(part) == 0) {
908 if (part[0] !=
'%' || strlen(part) < 2) {
909 strlcat(pattern, part, PATH_MAX);
914 SCLogError(
"Thread ID not allowed in ring buffer mode.");
918 snprintf(tmp, PATH_MAX,
"%"PRIu32, pl->thread_number);
919 strlcat(pattern, tmp, PATH_MAX);
923 strlcat(pattern,
"*", PATH_MAX);
926 SCLogError(
"Unsupported format character: %%%s", part);
931 strlcat(pattern, pl->prefix, PATH_MAX);
932 strlcat(pattern,
".*", PATH_MAX);
934 strlcat(pattern, pl->suffix, PATH_MAX);
936 char *basename = strrchr(pattern,
'/');
940 DIR *dir = opendir(pattern);
942 SCLogWarning(
"Failed to open directory %s: %s", pattern, strerror(errno));
947 struct dirent *entry = readdir(dir);
951 if (fnmatch(basename, entry->d_name, 0) != 0) {
958 if (!PcapLogGetTimeOfFile(entry->d_name, &secs, &usecs)) {
969 if (
PathMerge(path,
sizeof(path), pattern, entry->d_name) < 0)
1025 PcapFileNameFree(pf);
1041 static TmEcode PcapLogDataInit(
ThreadVars *t,
const void *initdata,
void **data)
1043 if (initdata == NULL) {
1044 SCLogDebug(
"Error getting context for LogPcap. \"initdata\" argument NULL");
1058 td->
pcap_log = PcapLogDataCopy(pl);
1065 FatalError(
"Pcap logging with multiple link type is not supported.");
1076 FatalError(
"Can't have multiple link types in pcap conditional mode.");
1079 SCLogWarning(
"Using multiple link types can result in invalid pcap output");
1115 #ifdef INIT_RING_BUFFER
1120 SCLogInfo(
"Unable to initialize ring buffer on this platform.");
1131 PcapLogOpenFileCtx(pl);
1141 dst->profile_open.total +=
src->profile_open.total;
1142 dst->profile_open.cnt +=
src->profile_open.cnt;
1144 dst->profile_close.total +=
src->profile_close.total;
1145 dst->profile_close.cnt +=
src->profile_close.cnt;
1147 dst->profile_write.total +=
src->profile_write.total;
1148 dst->profile_write.cnt +=
src->profile_write.cnt;
1150 dst->profile_rotate.total +=
src->profile_rotate.total;
1151 dst->profile_rotate.cnt +=
src->profile_rotate.cnt;
1153 dst->profile_handles.total +=
src->profile_handles.total;
1154 dst->profile_handles.cnt +=
src->profile_handles.cnt;
1156 dst->profile_lock.total +=
src->profile_lock.total;
1157 dst->profile_lock.cnt +=
src->profile_lock.cnt;
1159 dst->profile_unlock.total +=
src->profile_unlock.total;
1160 dst->profile_unlock.cnt +=
src->profile_unlock.cnt;
1162 dst->profile_data_size +=
src->profile_data_size;
1169 while ((pf =
TAILQ_FIRST(&pl->pcap_file_list)) != NULL) {
1172 PcapFileNameFree(pf);
1174 if (pl == g_pcap_data) {
1175 for (
int i = 0; i <
MAX_TOKS; i++) {
1176 if (pl->filename_parts[i] != NULL) {
1177 SCFree(pl->filename_parts[i]);
1190 pcap_freecode(pl->
bpfp);
1196 SCFree(pl->compression.buffer);
1197 if (pl->compression.pcap_buf_wrapper)
1198 fclose(pl->compression.pcap_buf_wrapper);
1199 SCFree(pl->compression.pcap_buf);
1200 LZ4F_errorCode_t errcode =
1201 LZ4F_freeCompressionContext(pl->compression.lz4f_context);
1202 if (LZ4F_isError(errcode)) {
1231 StatsMerge(g_pcap_data, pl);
1232 g_pcap_data->reported++;
1233 if (g_pcap_data->threads == g_pcap_data->reported)
1234 PcapLogProfilingDump(g_pcap_data);
1237 if (pl->reported == 0) {
1238 PcapLogProfilingDump(pl);
1243 if (pl != g_pcap_data) {
1244 PcapLogDataFree(pl);
1255 static int ParseFilename(
PcapLogData *pl,
const char *filename)
1262 size_t filename_len = 0;
1265 filename_len = strlen(filename);
1271 for (
int i = 0; i < (int)strlen(filename); i++) {
1273 SCLogError(
"invalid filename option. Max 2 %%-sign options");
1277 str[s++] = filename[i];
1279 if (filename[i] ==
'%') {
1290 if (i+1 < (
int)strlen(filename)) {
1292 SCLogError(
"invalid filename option. Max 2 %%-sign options");
1296 if (filename[i+1] !=
'n' && filename[i+1] !=
't' && filename[i+1] !=
'i') {
1298 "invalid filename option. Valid %%-sign options: %%n, %%i and %%t");
1302 str[1] = filename[i+1];
1314 SCLogError(
"Invalid filename for multimode. Need at least one %%-sign option");
1320 SCLogError(
"invalid filename option. Max 3 %%-sign options");
1332 for (
int i = 0; i < tok; i++) {
1333 if (toks[i] == NULL)
1337 pl->filename_parts[i] = toks[i];
1339 pl->filename_part_cnt = tok;
1343 for (
int x = 0; x <
MAX_TOKS; x++) {
1344 if (toks[x] != NULL)
1361 FatalError(
"A pcap-log instance is already active, only one can be enabled.");
1366 FatalError(
"Failed to allocate Memory for PcapLogData");
1370 if (pl->
h == NULL) {
1371 FatalError(
"Failed to allocate Memory for pcap header struct");
1388 pcre_timestamp_code =
1389 pcre2_compile((PCRE2_SPTR8)timestamp_pattern, PCRE2_ZERO_TERMINATED, 0, &en, &eo, NULL);
1390 if (pcre_timestamp_code == NULL) {
1391 PCRE2_UCHAR errbuffer[256];
1392 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
1394 "Failed to compile \"%s\" at offset %d: %s", timestamp_pattern, (
int)eo, errbuffer);
1396 pcre_timestamp_match = pcre2_match_data_create_from_pattern(pcre_timestamp_code, NULL);
1400 const char *filename = NULL;
1406 if (filename == NULL)
1409 if ((pl->prefix =
SCStrdup(filename)) == NULL) {
1417 const char *s_limit = NULL;
1419 if (s_limit != NULL) {
1421 SCLogError(
"Failed to initialize pcap output, invalid limit: %s", s_limit);
1425 SCLogInfo(
"pcap-log \"limit\" value of %"PRIu64
" assumed to be pre-1.2 "
1427 uint64_t size = pl->
size_limit * 1024 * 1024;
1430 FatalError(
"Fail to initialize pcap-log output, limit less than "
1431 "allowed minimum of %d bytes.",
1438 const char *s_mode = NULL;
1440 if (s_mode != NULL) {
1441 if (strcasecmp(s_mode,
"multi") == 0) {
1443 }
else if (strcasecmp(s_mode,
"normal") != 0) {
1444 FatalError(
"log-pcap: invalid mode \"%s\". Valid options: \"normal\""
1445 "or \"multi\" mode ",
1450 const char *s_dir = NULL;
1452 if (s_dir == NULL) {
1453 const char *log_dir = NULL;
1456 strlcpy(pl->dir, log_dir,
sizeof(pl->dir));
1461 s_dir,
sizeof(pl->dir));
1463 const char *log_dir = NULL;
1466 snprintf(pl->dir,
sizeof(pl->dir),
"%s/%s",
1470 struct stat stat_buf;
1471 if (stat(pl->dir, &stat_buf) != 0) {
1473 "supplied doesn't exist. Shutting down the engine",
1482 if (compression_str == NULL || strcmp(compression_str,
"none") == 0) {
1490 comp->pcap_buf_wrapper = NULL;
1492 }
else if (strcmp(compression_str,
"lz4") == 0) {
1502 SCLogError(
"SCMalloc failed: %s", strerror(errno));
1507 if (comp->pcap_buf_wrapper == NULL) {
1508 SCLogError(
"SCFmemopen failed: %s", strerror(errno));
1514 memset(&comp->lz4f_prefs,
'\0',
sizeof(comp->lz4f_prefs));
1515 comp->lz4f_prefs.frameInfo.blockSizeID = LZ4F_max4MB;
1516 comp->lz4f_prefs.frameInfo.blockMode = LZ4F_blockLinked;
1518 comp->lz4f_prefs.frameInfo.contentChecksumFlag = 1;
1520 comp->lz4f_prefs.frameInfo.contentChecksumFlag = 0;
1526 }
else if (lvl < 0) {
1532 comp->lz4f_prefs.compressionLevel = (int)lvl;
1536 LZ4F_errorCode_t errcode =
1537 LZ4F_createCompressionContext(&pl->compression.lz4f_context, 1);
1539 if (LZ4F_isError(errcode)) {
1540 SCLogError(
"LZ4F_createCompressionContext failed: %s", LZ4F_getErrorName(errcode));
1552 "lz4 output buffer.");
1559 pl->suffix =
".lz4";
1562 "in pcap-log, but suricata was not compiled with lz4 "
1564 PcapLogDataFree(pl);
1570 "compression format: %s",
1572 PcapLogDataFree(pl);
1576 SCLogInfo(
"Selected pcap-log compression method: %s",
1577 compression_str ? compression_str :
"none");
1580 if (s_conditional != NULL) {
1581 if (strcasecmp(s_conditional,
"alerts") == 0) {
1584 }
else if (strcasecmp(s_conditional,
"tag") == 0) {
1587 }
else if (strcasecmp(s_conditional,
"all") != 0) {
1588 FatalError(
"log-pcap: invalid conditional \"%s\". Valid options: \"all\", "
1589 "\"alerts\", or \"tag\" mode ",
1595 "Selected pcap-log conditional logging: %s", s_conditional ? s_conditional :
"all");
1598 if (ParseFilename(pl, filename) != 0)
1605 const char *max_number_of_files_s = NULL;
1607 if (max_number_of_files_s != NULL) {
1609 max_number_of_files_s) == -1) {
1611 "pcap-log output, invalid number of files limit: %s",
1612 max_number_of_files_s);
1614 }
else if (max_file_limit < 1) {
1615 FatalError(
"Failed to initialize pcap-log output, limit less than "
1616 "allowed minimum.");
1624 const char *ts_format = NULL;
1628 if (ts_format != NULL) {
1629 if (strcasecmp(ts_format,
"usec") == 0) {
1631 }
else if (strcasecmp(ts_format,
"sec") != 0) {
1632 SCLogError(
"log-pcap ts_format specified %s is invalid must be"
1633 " \"sec\" or \"usec\"",
1639 const char *use_stream_depth = NULL;
1643 if (use_stream_depth != NULL) {
1649 FatalError(
"log-pcap use_stream_depth specified is invalid must be");
1653 const char *honor_pass_rules = NULL;
1657 if (honor_pass_rules != NULL) {
1663 FatalError(
"log-pcap honor-pass-rules specified is invalid");
1672 if (
unlikely(output_ctx == NULL)) {
1673 FatalError(
"Failed to allocate memory for OutputCtx.");
1675 output_ctx->
data = pl;
1676 output_ctx->
DeInit = PcapLogFileDeInitCtx;
1679 result.
ctx = output_ctx;
1684 static void PcapLogFileDeInitCtx(
OutputCtx *output_ctx)
1686 if (output_ctx == NULL)
1695 PcapLogDataFree(pl);
1698 pcre2_code_free(pcre_timestamp_code);
1699 pcre2_match_data_free(pcre_timestamp_match);
1735 char file[PATH_MAX] =
"";
1740 ret = snprintf(file,
sizeof(file),
"%s.%" PRIu32
"%s", pl->prefix,
1743 ret = snprintf(file,
sizeof(file),
"%s.%" PRIu32
".%" PRIu32
"%s", pl->prefix,
1746 if (ret < 0 || (
size_t)ret >= PATH_MAX) {
1751 if (pl->filename_part_cnt > 0) {
1754 for (
int i = 0; i < pl->filename_part_cnt; i++) {
1755 if (pl->filename_parts[i] == NULL ||strlen(pl->filename_parts[i]) == 0)
1759 if (pl->filename_parts[i][0] ==
'%') {
1761 if (strlen(pl->filename_parts[i]) < 2)
1764 switch(pl->filename_parts[i][1]) {
1766 snprintf(
str,
sizeof(
str),
"%u", pl->thread_number);
1771 snprintf(
str,
sizeof(
str),
"%"PRIu64, (uint64_t)thread_id);
1779 snprintf(
str,
sizeof(
str),
"%" PRIu32
".%" PRIu32,
1787 strlcat(file, pl->filename_parts[i],
sizeof(file));
1790 strlcat(file, pl->suffix,
sizeof(file));
1795 ret = snprintf(file,
sizeof(file),
"%s.%u.%" PRIu32
"%s", pl->prefix,
1798 ret = snprintf(file,
sizeof(file),
"%s.%u.%" PRIu32
".%" PRIu32
"%s", pl->prefix,
1802 if (ret < 0 || (
size_t)ret >= PATH_MAX) {
1809 if (
PathMerge(path, PATH_MAX, pl->dir, file) < 0) {
1815 SCLogError(
"Error allocating memory. For filename");
1828 PcapFileNameFree(pf);
1841 static int profiling_pcaplog_enabled = 0;
1842 static int profiling_pcaplog_output_to_file = 0;
1843 static char *profiling_pcaplog_file_name = NULL;
1844 static const char *profiling_pcaplog_file_mode =
"a";
1846 static void FormatNumber(uint64_t num,
char *
str,
size_t size)
1849 snprintf(
str, size,
"%"PRIu64, num);
1850 else if (num < 1000000UL)
1851 snprintf(
str, size,
"%3.1fk", (
float)num/1000UL);
1852 else if (num < 1000000000UL)
1853 snprintf(
str, size,
"%3.1fm", (
float)num/1000000UL);
1855 snprintf(
str, size,
"%3.1fb", (
float)num/1000000000UL);
1860 char ticks_str[32] =
"n/a";
1861 char cnt_str[32] =
"n/a";
1862 char avg_str[32] =
"n/a";
1864 FormatNumber((uint64_t)
p->cnt, cnt_str,
sizeof(cnt_str));
1865 FormatNumber((uint64_t)
p->total, ticks_str,
sizeof(ticks_str));
1866 if (
p->cnt &&
p->total)
1867 FormatNumber((uint64_t)(
p->total/
p->cnt), avg_str,
sizeof(avg_str));
1869 fprintf(fp,
"%-28s %-10s %-10s %-10s\n",
name, cnt_str, avg_str, ticks_str);
1872 static void ProfileReport(FILE *fp,
const PcapLogData *pl)
1877 ProfileReportPair(fp,
"rotate (incl open/close)", &pl->
profile_rotate);
1883 static void FormatBytes(uint64_t num,
char *
str,
size_t size)
1886 snprintf(
str, size,
"%"PRIu64, num);
1887 else if (num < 1048576UL)
1888 snprintf(
str, size,
"%3.1fKiB", (
float)num/1000UL);
1889 else if (num < 1073741824UL)
1890 snprintf(
str, size,
"%3.1fMiB", (
float)num/1000000UL);
1892 snprintf(
str, size,
"%3.1fGiB", (
float)num/1000000000UL);
1895 static void DoDump(
const PcapLogData *pl, FILE *fp)
1898 fprintf(fp,
"\n\nOperation Cnt Avg ticks Total ticks\n");
1899 fprintf(fp,
"---------------------------- ---------- ---------- -----------\n");
1901 ProfileReport(fp, pl);
1908 fprintf(fp,
"\nOverall: %"PRIu64
" bytes written, average %d bytes per write.\n",
1911 fprintf(fp,
" PCAP data structure overhead: %"PRIuMAX
" per write.\n",
1912 (uintmax_t)
sizeof(
struct pcap_pkthdr));
1917 fprintf(fp,
" Size written: %s\n", bytes_str);
1920 uint64_t ticks_per_mib = 0, ticks_per_gib = 0;
1923 ticks_per_mib = total/mib;
1924 char ticks_per_mib_str[32] =
"n/a";
1925 if (ticks_per_mib > 0)
1926 FormatNumber(ticks_per_mib, ticks_per_mib_str,
sizeof(ticks_per_mib_str));
1927 fprintf(fp,
" Ticks per MiB: %s\n", ticks_per_mib_str);
1931 ticks_per_gib = total/gib;
1932 char ticks_per_gib_str[32] =
"n/a";
1933 if (ticks_per_gib > 0)
1934 FormatNumber(ticks_per_gib, ticks_per_gib_str,
sizeof(ticks_per_gib_str));
1935 fprintf(fp,
" Ticks per GiB: %s\n", ticks_per_gib_str);
1940 if (profiling_pcaplog_enabled == 0)
1943 if (profiling_pcaplog_output_to_file == 1) {
1944 FILE *fp = fopen(profiling_pcaplog_file_name, profiling_pcaplog_file_mode);
1946 SCLogError(
"failed to open %s: %s", profiling_pcaplog_file_name, strerror(errno));
1960 profiling_pcaplog_enabled = 1;
1961 SCLogInfo(
"pcap-log profiling enabled");
1964 if (filename != NULL) {
1965 const char *log_dir;
1968 profiling_pcaplog_file_name =
SCMalloc(PATH_MAX);
1969 if (
unlikely(profiling_pcaplog_file_name == NULL)) {
1973 snprintf(profiling_pcaplog_file_name, PATH_MAX,
"%s/%s", log_dir, filename);
1977 profiling_pcaplog_file_mode =
"a";
1979 profiling_pcaplog_file_mode =
"w";
1982 profiling_pcaplog_output_to_file = 1;
1983 SCLogInfo(
"pcap-log profiling output goes to %s (mode %s)",
1984 profiling_pcaplog_file_name, profiling_pcaplog_file_mode);