Go to the documentation of this file.
63 static void ReceivePcapFileThreadExitStats(
ThreadVars *,
void *);
74 static TmEcode PcapFileExit(
TmEcode status,
struct timespec *last_processed);
79 if (
tv->is_directory == 0) {
80 tv->behavior.file = NULL;
87 if (
tv->is_directory == 1) {
88 tv->behavior.directory = NULL;
141 #if defined(HAVE_SETVBUF) && defined(OS_LINUX)
142 #define PCAP_FILE_BUFFER_SIZE_DEFAULT 131072U // 128 KiB
143 #define PCAP_FILE_BUFFER_SIZE_MIN 4096U // 4 KiB
144 #define PCAP_FILE_BUFFER_SIZE_MAX 67108864U // 64MiB
154 #if defined(HAVE_SETVBUF) && defined(OS_LINUX)
157 const char *
str = NULL;
161 SCLogWarning(
"failed to parse pcap-file.buffer-size %s; keeping default %u",
str,
162 PCAP_FILE_BUFFER_SIZE_DEFAULT);
163 }
else if (value == 0 ||
164 (value >= PCAP_FILE_BUFFER_SIZE_MIN && value <= PCAP_FILE_BUFFER_SIZE_MAX)) {
166 SCLogInfo(
"Pcap-file buffering disabled");
168 SCLogInfo(
"Pcap-file will use %u buffer size", value);
172 SCLogWarning(
"pcap-file.buffer-size value of %u is invalid. Valid values are 0 to "
173 "disable buffering, or %u-%u",
174 value, PCAP_FILE_BUFFER_SIZE_MIN, PCAP_FILE_BUFFER_SIZE_MAX);
180 TmEcode PcapFileExit(
TmEcode status,
struct timespec *last_processed)
196 SCLogError(
"pcap file reader thread failed to initialize");
227 SCLogDebug(
"Pcap file loop complete with status %u", status);
251 const char *tmpstring = NULL;
252 const char *tmp_bpf_string = NULL;
254 if (initdata == NULL) {
267 if (
SCConfGetInt(
"pcap-file.tenant-id", &tenant) == 1) {
268 if (tenant > 0 && tenant < UINT_MAX) {
277 SCLogDebug(
"could not get bpf or none specified");
283 CleanupPcapFileThreadVars(ptv);
291 DIR *directory = NULL;
292 SCLogDebug(
"checking file or directory %s", (
char*)initdata);
294 CleanupPcapFileThreadVars(ptv);
298 if(directory == NULL) {
299 SCLogDebug(
"argument %s was a file", (
char *)initdata);
304 CleanupPcapFileThreadVars(ptv);
308 pv->filename =
SCStrdup((
char *)initdata);
309 if (
unlikely(pv->filename == NULL)) {
312 CleanupPcapFileThreadVars(ptv);
316 pv->shared = &ptv->
shared;
322 SCLogWarning(
"Failed to init pcap file %s, skipping", pv->filename);
324 CleanupPcapFileThreadVars(ptv);
328 SCLogInfo(
"Argument %s was a directory", (
char *)initdata);
331 SCLogError(
"Failed to allocate directory vars");
333 CleanupPcapFileThreadVars(ptv);
342 CleanupPcapFileThreadVars(ptv);
348 if (
SCConfGetBool(
"pcap-file.recursive", &should_recurse) == 1) {
354 if (
SCConfGetBool(
"pcap-file.continuous", &should_loop) == 1) {
359 SCLogError(
"Error, --pcap-file-continuous and --pcap-file-recursive "
360 "cannot be used together.");
363 CleanupPcapFileThreadVars(ptv);
370 if (delay > 0 && delay < UINT_MAX) {
371 pv->
delay = (time_t)delay;
379 intmax_t poll_interval = 0;
380 if (
SCConfGetInt(
"pcap-file.poll-interval", &poll_interval) == 1) {
381 if (poll_interval > 0 && poll_interval < UINT_MAX) {
400 if (strcmp(tmpstring,
"auto") == 0) {
416 void ReceivePcapFileThreadExitStats(
ThreadVars *
tv,
void *data)
427 SCLogWarning(
"1/%" PRIu64
"th of packets have an invalid checksum,"
428 " consider setting pcap-file.checksum-checks variable to no"
429 " or use '-k none' option on command line.",
432 SCLogInfo(
"1/%" PRIu64
"th of packets have an invalid checksum",
435 SCLogNotice(
"read %" PRIu64
" file%s, %" PRIu64
" packets, %" PRIu64
" bytes",
451 CleanupPcapFileThreadVars(ptv);
int SCConfValIsTrue(const char *val)
Check if a value is true.
TmEcode PcapFileDispatch(PcapFileFileVars *ptv)
Main PCAP file reading Loop function.
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
TmEcode ValidateLinkType(int datalink, DecoderFunc *DecoderFn)
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
union PcapFileBehaviorVar_ PcapFileBehaviorVar
void TmThreadsSetFlag(ThreadVars *tv, uint32_t flag)
Set a thread flag.
struct PcapFileThreadVars_ PcapFileThreadVars
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
int(* DecoderFunc)(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
#define CHECKSUM_SAMPLE_COUNT
PcapFileDirectoryVars * directory
struct PcapFileFileVars_ PcapFileFileVars
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
int SCConfValIsFalse(const char *val)
Check if a value is false.
@ CHECKSUM_VALIDATION_DISABLE
void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Finalize decoding of a packet.
TmEcode PcapDetermineDirectoryOrFile(char *filename, DIR **directory)
TmEcode(* PktAcqLoop)(ThreadVars *, void *, void *)
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
void TmModuleDecodePcapFileRegister(void)
@ CHECKSUM_VALIDATION_ENABLE
void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
@ CHECKSUM_VALIDATION_AUTO
PcapFileGlobalVars pcap_g
TmEcode(* PktAcqBreakLoop)(ThreadVars *, void *)
void PcapFileSetCurrentPfv(PcapFileFileVars *pfv)
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
ChecksumValidationMode checksum_mode
int SCConfGetNonNull(const char *name, const char **vptr)
Retrieve the non-null value of a configuration node.
Per thread variable structure.
PcapFileBehaviorVar behavior
TmEcode(* Func)(ThreadVars *, Packet *, void *)
TmEcode InitPcapFile(PcapFileFileVars *pfv)
int RunModeUnixSocketIsActive(void)
#define SCLogWarning(...)
Macro used to log WARNING messages.
void TmModuleReceivePcapFileRegister(void)
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
void PcapFileInstallCaptureHooks(void)
#define TM_FLAG_DECODE_TM
TmModule tmm_modules[TMM_SIZE]
PcapFileSharedVars shared
uint32_t max_pending_packets
void PcapIncreaseInvalidChecksum(void)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define TM_FLAG_RECEIVE_TM
#define CHECKSUM_INVALID_RATIO
void DecodeThreadVarsFree(ThreadVars *tv, DecodeThreadVars *dtv)
void CleanupPcapFileDirectoryVars(PcapFileDirectoryVars *ptv)
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
TmEcode PcapDirectoryDispatch(PcapFileDirectoryVars *ptv)
void EngineStop(void)
make sure threads can stop the engine by calling this function. Purpose: pcap file mode needs to be a...
int ParseSizeStringU32(const char *size, uint32_t *res)
void(* ThreadExitPrintStats)(ThreadVars *, void *)
struct timespec last_processed
#define SCLogError(...)
Macro used to log ERROR messages.
ChecksumValidationMode conf_checksum_mode
Structure to hold thread specific data for all decode modules.
PcapFileSharedVars * shared
DecodeThreadVars * DecodeThreadVarsAlloc(ThreadVars *tv)
Alloc and setup DecodeThreadVars.
TmEcode UnixSocketPcapFile(TmEcode tm, struct timespec *last_processed)
void PcapFileGlobalInit(void)
PcapFileDeleteMode PcapFileParseDeleteMode(void)
struct TmSlot_ * slot_next
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
void CleanupPcapFileFileVars(PcapFileFileVars *pfv)
#define SCLogNotice(...)
Macro used to log NOTICE messages.
PcapFileDeleteMode delete_mode
#define DEBUG_VALIDATE_BUG_ON(exp)
uint32_t read_buffer_size
void DecodeUpdatePacketCounters(ThreadVars *tv, const DecodeThreadVars *dtv, const Packet *p)