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;
163 if (value >= PCAP_FILE_BUFFER_SIZE_MIN && value <= PCAP_FILE_BUFFER_SIZE_MAX) {
164 SCLogInfo(
"Pcap-file will use %u buffer size", value);
167 SCLogWarning(
"pcap-file.buffer-size value of %u is invalid. Valid range is %u-%u",
168 value, PCAP_FILE_BUFFER_SIZE_MIN, PCAP_FILE_BUFFER_SIZE_MAX);
174 TmEcode PcapFileExit(
TmEcode status,
struct timespec *last_processed)
190 SCLogError(
"pcap file reader thread failed to initialize");
221 SCLogDebug(
"Pcap file loop complete with status %u", status);
245 const char *tmpstring = NULL;
246 const char *tmp_bpf_string = NULL;
248 if (initdata == NULL) {
261 if (
SCConfGetInt(
"pcap-file.tenant-id", &tenant) == 1) {
262 if (tenant > 0 && tenant < UINT_MAX) {
270 if (
SCConfGet(
"bpf-filter", &(tmp_bpf_string)) != 1) {
271 SCLogDebug(
"could not get bpf or none specified");
277 CleanupPcapFileThreadVars(ptv);
285 DIR *directory = NULL;
286 SCLogDebug(
"checking file or directory %s", (
char*)initdata);
288 CleanupPcapFileThreadVars(ptv);
292 if(directory == NULL) {
293 SCLogDebug(
"argument %s was a file", (
char *)initdata);
298 CleanupPcapFileThreadVars(ptv);
302 pv->filename =
SCStrdup((
char *)initdata);
303 if (
unlikely(pv->filename == NULL)) {
306 CleanupPcapFileThreadVars(ptv);
310 pv->shared = &ptv->
shared;
316 SCLogWarning(
"Failed to init pcap file %s, skipping", pv->filename);
318 CleanupPcapFileThreadVars(ptv);
322 SCLogInfo(
"Argument %s was a directory", (
char *)initdata);
325 SCLogError(
"Failed to allocate directory vars");
327 CleanupPcapFileThreadVars(ptv);
336 CleanupPcapFileThreadVars(ptv);
342 if (
SCConfGetBool(
"pcap-file.recursive", &should_recurse) == 1) {
348 if (
SCConfGetBool(
"pcap-file.continuous", &should_loop) == 1) {
353 SCLogError(
"Error, --pcap-file-continuous and --pcap-file-recursive "
354 "cannot be used together.");
357 CleanupPcapFileThreadVars(ptv);
364 if (delay > 0 && delay < UINT_MAX) {
365 pv->
delay = (time_t)delay;
373 intmax_t poll_interval = 0;
374 if (
SCConfGetInt(
"pcap-file.poll-interval", &poll_interval) == 1) {
375 if (poll_interval > 0 && poll_interval < UINT_MAX) {
391 if (
SCConfGet(
"pcap-file.checksum-checks", &tmpstring) != 1) {
394 if (strcmp(tmpstring,
"auto") == 0) {
410 void ReceivePcapFileThreadExitStats(
ThreadVars *
tv,
void *data)
421 SCLogWarning(
"1/%" PRIu64
"th of packets have an invalid checksum,"
422 " consider setting pcap-file.checksum-checks variable to no"
423 " or use '-k none' option on command line.",
426 SCLogInfo(
"1/%" PRIu64
"th of packets have an invalid checksum",
429 SCLogNotice(
"read %" PRIu64
" file%s, %" PRIu64
" packets, %" PRIu64
" bytes",
445 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 SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
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
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)