33 #if defined(HAVE_DIRENT_H) && defined(HAVE_FNMATCH_H)
34 #define INIT_RING_BUFFER
59 #define DEFAULT_LOG_FILENAME "pcaplog"
60 #define MODULE_NAME "PcapLog"
61 #define MIN_LIMIT 4 * 1024 * 1024
62 #define DEFAULT_LIMIT 100 * 1024 * 1024
63 #define DEFAULT_FILE_LIMIT 0
65 #define LOGMODE_NORMAL 0
66 #define LOGMODE_SGUIL 1
67 #define LOGMODE_MULTI 2
75 #define RING_BUFFER_MODE_DISABLED 0
76 #define RING_BUFFER_MODE_ENABLED 1
78 #define TS_FORMAT_SEC 0
79 #define TS_FORMAT_USEC 1
81 #define USE_STREAM_DEPTH_DISABLED 0
82 #define USE_STREAM_DEPTH_ENABLED 1
84 #define HONOR_PASS_RULES_DISABLED 0
85 #define HONOR_PASS_RULES_ENABLED 1
87 #define PCAP_SNAPLEN 262144
88 #define PCAP_BUFFER_TIMEOUT 1000000 // microseconds
114 #define MAX_FILENAMELEN 513
126 LZ4F_compressionContext_t lz4f_context;
127 LZ4F_preferences_t lz4f_prefs;
147 struct pcap_pkthdr *
h;
171 uint32_t thread_number;
173 int timestamp_format;
180 int filename_part_cnt;
181 struct timeval last_pcap_dump;
194 static const char timestamp_pattern[] =
".*?(\\d+)(\\.(\\d+))?";
195 static pcre2_code *pcre_timestamp_code = NULL;
196 static pcre2_match_data *pcre_timestamp_match = NULL;
206 static void PcapLogFileDeInitCtx(
OutputCtx *);
214 PcapLogInitCtx, PcapLog, PcapLogCondition, PcapLogDataInit,
215 PcapLogDataDeinit, NULL);
222 #define PCAPLOG_PROFILE_START \
223 uint64_t pcaplog_profile_ticks = UtilCpuGetTicks()
225 #define PCAPLOG_PROFILE_END(prof) \
226 (prof).total += (UtilCpuGetTicks() - pcaplog_profile_ticks); \
285 SCLogError(
"SCFmemopen failed: %s", strerror(errno));
304 uint64_t bytes_written = LZ4F_compressEnd(comp->lz4f_context,
306 if (LZ4F_isError(bytes_written)) {
307 SCLogError(
"LZ4F_compressEnd: %s", LZ4F_getErrorName(bytes_written));
310 if (fwrite(comp->
buffer, 1, bytes_written, comp->
file) < bytes_written) {
311 SCLogError(
"fwrite failed: %s", strerror(errno));
356 if (PcapLogCloseFile(t,pl) < 0) {
376 SCLogDebug(
"Current entry dir %s and next entry %s "
377 "are equal: not removing dir",
381 "not equal: removing dir",
384 if (remove(pf->
dirname) != 0) {
391 PcapFileNameFree(pf);
395 if (PcapLogOpenFileCtx(pl) < 0) {
396 SCLogError(
"opening new pcap log file failed");
416 SCLogDebug(
"Setting pcap-log link type to %u", datalink);
427 if (!pl->pcap_open_err) {
429 pl->pcap_open_err =
true;
433 pl->pcap_open_err =
false;
441 if (comp->
file == NULL) {
442 if (errno != pl->fopen_err) {
443 SCLogError(
"Error opening file for compressed output: %s", strerror(errno));
444 pl->fopen_err = errno;
453 if (!pl->pcap_open_err) {
455 pl->pcap_open_err =
true;
461 pl->pcap_open_err =
false;
464 uint64_t bytes_written = LZ4F_compressBegin(comp->lz4f_context,
466 if (LZ4F_isError(bytes_written)) {
467 SCLogError(
"LZ4F_compressBegin: %s", LZ4F_getErrorName(bytes_written));
470 if (fwrite(comp->
buffer, 1, bytes_written, comp->
file) < bytes_written) {
471 SCLogError(
"fwrite failed: %s", strerror(errno));
508 static inline int PcapWrite(
511 struct timeval current_dump;
512 gettimeofday(¤t_dump, NULL);
522 SCLogError(
"ftell failed with: %s", strerror(errno));
525 uint64_t out_size = LZ4F_compressUpdate(comp->lz4f_context, comp->
buffer, comp->
buffer_size,
526 comp->
pcap_buf, (uint64_t)in_size, NULL);
527 if (LZ4F_isError(
len)) {
528 SCLogError(
"LZ4F_compressUpdate: %s", LZ4F_getErrorName(
len));
531 if (fseek(pl->compression.pcap_buf_wrapper, 0, SEEK_SET) != 0) {
532 SCLogError(
"fseek failed: %s", strerror(errno));
535 if (fwrite(comp->
buffer, 1, out_size, comp->
file) < out_size) {
536 SCLogError(
"fwrite failed: %s", strerror(errno));
550 pl->last_pcap_dump = current_dump;
560 static int PcapLogSegmentCallback(
561 const Packet *p,
TcpSegment *seg,
void *data,
const uint8_t *buf, uint32_t buflen)
579 static void PcapLogDumpSegments(
632 ret = PcapLogOpenFileCtx(
pl);
652 if (PcapLogRotateFile(t,pl) < 0) {
669 if (PcapLogRotateFile(t,pl) < 0) {
695 PcapLogDumpSegments(td, comp, p);
697 PcapLogDumpSegments(td, NULL, p);
743 SCLogDebug(
"pl->size_current %"PRIu64
", pl->size_limit %"PRIu64,
764 copy->prefix =
SCStrdup(pl->prefix);
765 if (
unlikely(copy->prefix == NULL)) {
771 copy->suffix = pl->suffix;
777 copy->use_ringbuffer = pl->use_ringbuffer;
778 copy->timestamp_format = pl->timestamp_format;
793 copy_comp->lz4f_prefs = comp->lz4f_prefs;
798 if (copy_comp->
buffer == NULL) {
799 SCLogError(
"SCMalloc failed: %s", strerror(errno));
806 SCLogError(
"SCMalloc failed: %s", strerror(errno));
815 SCLogError(
"SCFmemopen failed: %s", strerror(errno));
825 LZ4F_errorCode_t errcode =
826 LZ4F_createCompressionContext(©_comp->lz4f_context, 1);
827 if (LZ4F_isError(errcode)) {
828 SCLogError(
"LZ4F_createCompressionContext failed: %s", LZ4F_getErrorName(errcode));
839 copy_comp->
file = NULL;
847 strlcpy(copy->dir, pl->dir,
sizeof(copy->dir));
850 for (i = 0; i < pl->filename_part_cnt && i <
MAX_TOKS; i++)
851 copy->filename_parts[i] = pl->filename_parts[i];
852 copy->filename_part_cnt = pl->filename_part_cnt;
861 #ifdef INIT_RING_BUFFER
862 static int PcapLogGetTimeOfFile(
const char *filename, uint64_t *secs,
868 int n = pcre2_match(pcre_timestamp_code, (PCRE2_SPTR8)filename, strlen(filename), 0, 0,
869 pcre_timestamp_match, NULL);
870 if (n != 2 && n != 4) {
877 copylen =
sizeof(buf);
878 if (pcre2_substring_copy_bynumber(pcre_timestamp_match, 1, (PCRE2_UCHAR8 *)buf, ©len) <
888 copylen =
sizeof(buf);
889 if (pcre2_substring_copy_bynumber(pcre_timestamp_match, 3, (PCRE2_UCHAR8 *)buf, ©len) <
903 char pattern[PATH_MAX];
905 SCLogInfo(
"Initializing PCAP ring buffer for %s/%s.",
906 pl->dir, pl->prefix);
908 strlcpy(pattern, pl->dir, PATH_MAX);
909 if (pattern[strlen(pattern) - 1] !=
'/') {
910 strlcat(pattern,
"/", PATH_MAX);
913 for (
int i = 0; i < pl->filename_part_cnt; i++) {
914 char *part = pl->filename_parts[i];
915 if (part == NULL || strlen(part) == 0) {
918 if (part[0] !=
'%' || strlen(part) < 2) {
919 strlcat(pattern, part, PATH_MAX);
924 SCLogError(
"Thread ID not allowed in ring buffer mode.");
928 snprintf(tmp, PATH_MAX,
"%"PRIu32, pl->thread_number);
929 strlcat(pattern, tmp, PATH_MAX);
933 strlcat(pattern,
"*", PATH_MAX);
936 SCLogError(
"Unsupported format character: %%%s", part);
941 strlcat(pattern, pl->prefix, PATH_MAX);
942 strlcat(pattern,
".*", PATH_MAX);
944 strlcat(pattern, pl->suffix, PATH_MAX);
946 char *basename = strrchr(pattern,
'/');
950 DIR *dir = opendir(pattern);
952 SCLogWarning(
"Failed to open directory %s: %s", pattern, strerror(errno));
957 struct dirent *entry = readdir(dir);
961 if (fnmatch(basename, entry->d_name, 0) != 0) {
968 if (!PcapLogGetTimeOfFile(entry->d_name, &secs, &usecs)) {
979 if (snprintf(path, PATH_MAX,
"%s/%s", pattern, entry->d_name) == PATH_MAX)
1034 PcapFileNameFree(pf);
1050 static TmEcode PcapLogDataInit(
ThreadVars *t,
const void *initdata,
void **data)
1052 if (initdata == NULL) {
1053 SCLogDebug(
"Error getting context for LogPcap. \"initdata\" argument NULL");
1064 td->
pcap_log = PcapLogDataCopy(pl);
1071 FatalError(
"Pcap logging with multiple link type is not supported.");
1082 FatalError(
"Can't have multiple link types in pcap conditional mode.");
1085 SCLogWarning(
"Using multiple link types can result in invalid pcap output");
1121 #ifdef INIT_RING_BUFFER
1126 SCLogInfo(
"Unable to initialize ring buffer on this platform.");
1137 PcapLogOpenFileCtx(pl);
1147 dst->profile_open.total +=
src->profile_open.total;
1148 dst->profile_open.cnt +=
src->profile_open.cnt;
1150 dst->profile_close.total +=
src->profile_close.total;
1151 dst->profile_close.cnt +=
src->profile_close.cnt;
1153 dst->profile_write.total +=
src->profile_write.total;
1154 dst->profile_write.cnt +=
src->profile_write.cnt;
1156 dst->profile_rotate.total +=
src->profile_rotate.total;
1157 dst->profile_rotate.cnt +=
src->profile_rotate.cnt;
1159 dst->profile_handles.total +=
src->profile_handles.total;
1160 dst->profile_handles.cnt +=
src->profile_handles.cnt;
1162 dst->profile_lock.total +=
src->profile_lock.total;
1163 dst->profile_lock.cnt +=
src->profile_lock.cnt;
1165 dst->profile_unlock.total +=
src->profile_unlock.total;
1166 dst->profile_unlock.cnt +=
src->profile_unlock.cnt;
1168 dst->profile_data_size +=
src->profile_data_size;
1175 while ((pf =
TAILQ_FIRST(&pl->pcap_file_list)) != NULL) {
1177 PcapFileNameFree(pf);
1179 if (pl == g_pcap_data) {
1180 for (
int i = 0; i <
MAX_TOKS; i++) {
1181 if (pl->filename_parts[i] != NULL) {
1182 SCFree(pl->filename_parts[i]);
1196 SCFree(pl->compression.buffer);
1197 fclose(pl->compression.pcap_buf_wrapper);
1198 SCFree(pl->compression.pcap_buf);
1199 LZ4F_errorCode_t errcode =
1200 LZ4F_freeCompressionContext(pl->compression.lz4f_context);
1201 if (LZ4F_isError(errcode)) {
1223 if (PcapLogCloseFile(t,pl) < 0) {
1230 StatsMerge(g_pcap_data, pl);
1231 g_pcap_data->reported++;
1232 if (g_pcap_data->threads == g_pcap_data->reported)
1233 PcapLogProfilingDump(g_pcap_data);
1236 if (pl->reported == 0) {
1237 PcapLogProfilingDump(pl);
1242 if (pl != g_pcap_data) {
1243 PcapLogDataFree(pl);
1254 static int ParseFilename(
PcapLogData *pl,
const char *filename)
1262 size_t filename_len = 0;
1265 filename_len = strlen(filename);
1271 for (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 (i = 0; i < tok; i++) {
1333 if (toks[i] == NULL)
1337 pl->filename_parts[i] = toks[i];
1339 pl->filename_part_cnt = tok;
1344 if (toks[x] != NULL)
1362 FatalError(
"Failed to allocate Memory for PcapLogData");
1367 if (pl->
h == NULL) {
1368 FatalError(
"Failed to allocate Memory for pcap header struct");
1385 pcre_timestamp_code =
1386 pcre2_compile((PCRE2_SPTR8)timestamp_pattern, PCRE2_ZERO_TERMINATED, 0, &en, &eo, NULL);
1387 if (pcre_timestamp_code == NULL) {
1388 PCRE2_UCHAR errbuffer[256];
1389 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
1391 "Failed to compile \"%s\" at offset %d: %s", timestamp_pattern, (
int)eo, errbuffer);
1393 pcre_timestamp_match = pcre2_match_data_create_from_pattern(pcre_timestamp_code, NULL);
1397 const char *filename = NULL;
1403 if (filename == NULL)
1406 if ((pl->prefix =
SCStrdup(filename)) == NULL) {
1414 const char *s_limit = NULL;
1416 if (s_limit != NULL) {
1418 SCLogError(
"Failed to initialize pcap output, invalid limit: %s", s_limit);
1422 SCLogInfo(
"pcap-log \"limit\" value of %"PRIu64
" assumed to be pre-1.2 "
1424 uint64_t size = pl->
size_limit * 1024 * 1024;
1427 FatalError(
"Fail to initialize pcap-log output, limit less than "
1428 "allowed minimum of %d bytes.",
1435 const char *s_mode = NULL;
1437 if (s_mode != NULL) {
1438 if (strcasecmp(s_mode,
"sguil") == 0) {
1440 }
else if (strcasecmp(s_mode,
"multi") == 0) {
1442 }
else if (strcasecmp(s_mode,
"normal") != 0) {
1443 SCLogError(
"log-pcap: invalid mode \"%s\". Valid options: \"normal\", "
1444 "\"sguil\", or \"multi\" mode ",
1450 const char *s_dir = NULL;
1452 if (s_dir == NULL) {
1455 if (s_dir == NULL) {
1457 FatalError(
"log-pcap \"sguil\" mode requires \"sguil-base-dir\" "
1458 "option to be set.");
1460 const char *log_dir = NULL;
1464 log_dir,
sizeof(pl->dir));
1470 s_dir,
sizeof(pl->dir));
1472 const char *log_dir = NULL;
1475 snprintf(pl->dir,
sizeof(pl->dir),
"%s/%s",
1479 struct stat stat_buf;
1480 if (stat(pl->dir, &stat_buf) != 0) {
1481 SCLogError(
"The sguil-base-dir directory \"%s\" "
1482 "supplied doesn't exist. Shutting down the engine",
1493 if (compression_str == NULL || strcmp(compression_str,
"none") == 0) {
1501 }
else if (strcmp(compression_str,
"lz4") == 0) {
1505 "logs are not possible in sguil mode");
1518 SCLogError(
"SCMalloc failed: %s", strerror(errno));
1524 SCLogError(
"SCFmemopen failed: %s", strerror(errno));
1530 memset(&comp->lz4f_prefs,
'\0',
sizeof(comp->lz4f_prefs));
1531 comp->lz4f_prefs.frameInfo.blockSizeID = LZ4F_max4MB;
1532 comp->lz4f_prefs.frameInfo.blockMode = LZ4F_blockLinked;
1534 comp->lz4f_prefs.frameInfo.contentChecksumFlag = 1;
1537 comp->lz4f_prefs.frameInfo.contentChecksumFlag = 0;
1543 }
else if (lvl < 0) {
1549 comp->lz4f_prefs.compressionLevel = lvl;
1553 LZ4F_errorCode_t errcode =
1554 LZ4F_createCompressionContext(&pl->compression.lz4f_context, 1);
1556 if (LZ4F_isError(errcode)) {
1557 SCLogError(
"LZ4F_createCompressionContext failed: %s", LZ4F_getErrorName(errcode));
1569 "lz4 output buffer.");
1576 pl->suffix =
".lz4";
1579 "in pcap-log, but suricata was not compiled with lz4 "
1581 PcapLogDataFree(pl);
1587 "compression format: %s",
1589 PcapLogDataFree(pl);
1593 SCLogInfo(
"Selected pcap-log compression method: %s",
1594 compression_str ? compression_str :
"none");
1597 if (s_conditional != NULL) {
1598 if (strcasecmp(s_conditional,
"alerts") == 0) {
1601 }
else if (strcasecmp(s_conditional,
"tag") == 0) {
1604 }
else if (strcasecmp(s_conditional,
"all") != 0) {
1605 FatalError(
"log-pcap: invalid conditional \"%s\". Valid options: \"all\", "
1606 "\"alerts\", or \"tag\" mode ",
1612 "Selected pcap-log conditional logging: %s", s_conditional ? s_conditional :
"all");
1615 if (ParseFilename(pl, filename) != 0)
1623 const char *max_number_of_files_s = NULL;
1625 if (max_number_of_files_s != NULL) {
1627 max_number_of_files_s) == -1) {
1629 "pcap-log output, invalid number of files limit: %s",
1630 max_number_of_files_s);
1632 }
else if (max_file_limit < 1) {
1633 FatalError(
"Failed to initialize pcap-log output, limit less than "
1634 "allowed minimum.");
1642 const char *ts_format = NULL;
1646 if (ts_format != NULL) {
1647 if (strcasecmp(ts_format,
"usec") == 0) {
1649 }
else if (strcasecmp(ts_format,
"sec") != 0) {
1650 SCLogError(
"log-pcap ts_format specified %s is invalid must be"
1651 " \"sec\" or \"usec\"",
1657 const char *use_stream_depth = NULL;
1661 if (use_stream_depth != NULL) {
1667 FatalError(
"log-pcap use_stream_depth specified is invalid must be");
1671 const char *honor_pass_rules = NULL;
1675 if (honor_pass_rules != NULL) {
1681 FatalError(
"log-pcap honor-pass-rules specified is invalid");
1688 if (
unlikely(output_ctx == NULL)) {
1689 FatalError(
"Failed to allocate memory for OutputCtx.");
1691 output_ctx->
data = pl;
1692 output_ctx->
DeInit = PcapLogFileDeInitCtx;
1695 result.
ctx = output_ctx;
1700 static void PcapLogFileDeInitCtx(
OutputCtx *output_ctx)
1702 if (output_ctx == NULL)
1711 PcapLogDataFree(pl);
1714 pcre2_code_free(pcre_timestamp_code);
1715 pcre2_match_data_free(pcre_timestamp_match);
1730 char *filename = NULL;
1758 char dirname[32], dirfull[PATH_MAX] =
"";
1760 snprintf(dirname,
sizeof(dirname),
"%04d-%02d-%02d",
1761 tms->tm_year + 1900, tms->tm_mon + 1, tms->tm_mday);
1764 int ret = snprintf(dirfull,
sizeof(dirfull),
"%s/%s", pl->dir, dirname);
1765 if (ret < 0 || (
size_t)ret >=
sizeof(dirfull)) {
1781 written = snprintf(filename, PATH_MAX,
"%s/%s.%" PRIu32
"%s", dirfull, pl->prefix,
1784 written = snprintf(filename, PATH_MAX,
"%s/%s.%" PRIu32
".%" PRIu32
"%s", dirfull,
1787 if (written == PATH_MAX) {
1795 ret = snprintf(filename, PATH_MAX,
"%s/%s.%" PRIu32
"%s", pl->dir, pl->prefix,
1798 ret = snprintf(filename, PATH_MAX,
"%s/%s.%" PRIu32
".%" PRIu32
"%s", pl->dir,
1801 if (ret < 0 || (
size_t)ret >= PATH_MAX) {
1806 if (pl->filename_part_cnt > 0) {
1809 strlcpy(filename, pl->dir, PATH_MAX);
1810 strlcat(filename,
"/", PATH_MAX);
1813 for (i = 0; i < pl->filename_part_cnt; i++) {
1814 if (pl->filename_parts[i] == NULL ||strlen(pl->filename_parts[i]) == 0)
1818 if (pl->filename_parts[i][0] ==
'%') {
1820 if (strlen(pl->filename_parts[i]) < 2)
1823 switch(pl->filename_parts[i][1]) {
1825 snprintf(
str,
sizeof(
str),
"%u", pl->thread_number);
1830 snprintf(
str,
sizeof(
str),
"%"PRIu64, (uint64_t)thread_id);
1838 snprintf(
str,
sizeof(
str),
"%" PRIu32
".%" PRIu32,
1846 strlcat(filename, pl->filename_parts[i], PATH_MAX);
1849 strlcat(filename, pl->suffix, PATH_MAX);
1854 ret = snprintf(filename, PATH_MAX,
"%s/%s.%u.%" PRIu32
"%s", pl->dir, pl->prefix,
1857 ret = snprintf(filename, PATH_MAX,
"%s/%s.%u.%" PRIu32
".%" PRIu32
"%s", pl->dir,
1861 if (ret < 0 || (
size_t)ret >= PATH_MAX) {
1866 SCLogDebug(
"multi-mode: filename %s", filename);
1870 SCLogError(
"Error allocating memory. For filename");
1883 PcapFileNameFree(pf);
1896 static int profiling_pcaplog_enabled = 0;
1897 static int profiling_pcaplog_output_to_file = 0;
1898 static char *profiling_pcaplog_file_name = NULL;
1899 static const char *profiling_pcaplog_file_mode =
"a";
1901 static void FormatNumber(uint64_t num,
char *
str,
size_t size)
1904 snprintf(
str, size,
"%"PRIu64, num);
1905 else if (num < 1000000UL)
1906 snprintf(
str, size,
"%3.1fk", (
float)num/1000UL);
1907 else if (num < 1000000000UL)
1908 snprintf(
str, size,
"%3.1fm", (
float)num/1000000UL);
1910 snprintf(
str, size,
"%3.1fb", (
float)num/1000000000UL);
1915 char ticks_str[32] =
"n/a";
1916 char cnt_str[32] =
"n/a";
1917 char avg_str[32] =
"n/a";
1919 FormatNumber((uint64_t)p->
cnt, cnt_str,
sizeof(cnt_str));
1920 FormatNumber((uint64_t)p->
total, ticks_str,
sizeof(ticks_str));
1922 FormatNumber((uint64_t)(p->
total/p->
cnt), avg_str,
sizeof(avg_str));
1924 fprintf(fp,
"%-28s %-10s %-10s %-10s\n", name, cnt_str, avg_str, ticks_str);
1927 static void ProfileReport(FILE *fp,
PcapLogData *pl)
1932 ProfileReportPair(fp,
"rotate (incl open/close)", &pl->
profile_rotate);
1938 static void FormatBytes(uint64_t num,
char *
str,
size_t size)
1941 snprintf(
str, size,
"%"PRIu64, num);
1942 else if (num < 1048576UL)
1943 snprintf(
str, size,
"%3.1fKiB", (
float)num/1000UL);
1944 else if (num < 1073741824UL)
1945 snprintf(
str, size,
"%3.1fMiB", (
float)num/1000000UL);
1947 snprintf(
str, size,
"%3.1fGiB", (
float)num/1000000000UL);
1954 if (profiling_pcaplog_enabled == 0)
1957 if (profiling_pcaplog_output_to_file == 1) {
1958 fp = fopen(profiling_pcaplog_file_name, profiling_pcaplog_file_mode);
1960 SCLogError(
"failed to open %s: %s", profiling_pcaplog_file_name, strerror(errno));
1968 fprintf(fp,
"\n\nOperation Cnt Avg ticks Total ticks\n");
1969 fprintf(fp,
"---------------------------- ---------- ---------- -----------\n");
1971 ProfileReport(fp, pl);
1978 fprintf(fp,
"\nOverall: %"PRIu64
" bytes written, average %d bytes per write.\n",
1981 fprintf(fp,
" PCAP data structure overhead: %"PRIuMAX
" per write.\n",
1982 (uintmax_t)
sizeof(
struct pcap_pkthdr));
1987 fprintf(fp,
" Size written: %s\n", bytes_str);
1990 uint64_t ticks_per_mib = 0, ticks_per_gib = 0;
1993 ticks_per_mib = total/mib;
1994 char ticks_per_mib_str[32] =
"n/a";
1995 if (ticks_per_mib > 0)
1996 FormatNumber(ticks_per_mib, ticks_per_mib_str,
sizeof(ticks_per_mib_str));
1997 fprintf(fp,
" Ticks per MiB: %s\n", ticks_per_mib_str);
2001 ticks_per_gib = total/gib;
2002 char ticks_per_gib_str[32] =
"n/a";
2003 if (ticks_per_gib > 0)
2004 FormatNumber(ticks_per_gib, ticks_per_gib_str,
sizeof(ticks_per_gib_str));
2005 fprintf(fp,
" Ticks per GiB: %s\n", ticks_per_gib_str);
2015 profiling_pcaplog_enabled = 1;
2016 SCLogInfo(
"pcap-log profiling enabled");
2019 if (filename != NULL) {
2020 const char *log_dir;
2023 profiling_pcaplog_file_name =
SCMalloc(PATH_MAX);
2024 if (
unlikely(profiling_pcaplog_file_name == NULL)) {
2028 snprintf(profiling_pcaplog_file_name, PATH_MAX,
"%s/%s", log_dir, filename);
2032 profiling_pcaplog_file_mode =
"a";
2034 profiling_pcaplog_file_mode =
"w";
2037 profiling_pcaplog_output_to_file = 1;
2038 SCLogInfo(
"pcap-log profiling output goes to %s (mode %s)",
2039 profiling_pcaplog_file_name, profiling_pcaplog_file_mode);