Go to the documentation of this file.
62 static void ReceivePcapFileThreadExitStats(
ThreadVars *,
void *);
73 static TmEcode PcapFileExit(
TmEcode status,
struct timespec *last_processed);
78 if (
tv->is_directory == 0) {
79 tv->behavior.file = NULL;
86 if (
tv->is_directory == 1) {
87 tv->behavior.directory = NULL;
140 #define PCAP_FILE_BUFFER_SIZE_DEFAULT 131072U // 128 KiB
141 #define PCAP_FILE_BUFFER_SIZE_MIN 4096U // 4 KiB
142 #define PCAP_FILE_BUFFER_SIZE_MAX 67108864U // 64MiB
149 #if defined(HAVE_SETVBUF) && defined(OS_LINUX)
152 const char *
str = NULL;
153 if (
ConfGet(
"pcap-file.buffer-size", &
str) == 1) {
159 SCLogInfo(
"Pcap-file will use %u buffer size", value);
162 SCLogWarning(
"pcap-file.buffer-size value of %u is invalid. Valid range is %u-%u",
169 TmEcode PcapFileExit(
TmEcode status,
struct timespec *last_processed)
185 SCLogError(
"pcap file reader thread failed to initialize");
213 SCLogDebug(
"Pcap file loop complete with status %u", status);
224 const char *tmpstring = NULL;
225 const char *tmp_bpf_string = NULL;
227 if (initdata == NULL) {
240 if (
ConfGetInt(
"pcap-file.tenant-id", &tenant) == 1) {
241 if (tenant > 0 && tenant < UINT_MAX) {
249 if (
ConfGet(
"bpf-filter", &(tmp_bpf_string)) != 1) {
250 SCLogDebug(
"could not get bpf or none specified");
256 CleanupPcapFileThreadVars(ptv);
262 int should_delete = 0;
264 if (
ConfGetBool(
"pcap-file.delete-when-done", &should_delete) == 1) {
268 DIR *directory = NULL;
269 SCLogDebug(
"checking file or directory %s", (
char*)initdata);
271 CleanupPcapFileThreadVars(ptv);
275 if(directory == NULL) {
276 SCLogDebug(
"argument %s was a file", (
char *)initdata);
281 CleanupPcapFileThreadVars(ptv);
285 pv->filename =
SCStrdup((
char *)initdata);
286 if (
unlikely(pv->filename == NULL)) {
289 CleanupPcapFileThreadVars(ptv);
293 pv->shared = &ptv->
shared;
299 SCLogWarning(
"Failed to init pcap file %s, skipping", pv->filename);
301 CleanupPcapFileThreadVars(ptv);
305 SCLogInfo(
"Argument %s was a directory", (
char *)initdata);
308 SCLogError(
"Failed to allocate directory vars");
310 CleanupPcapFileThreadVars(ptv);
319 CleanupPcapFileThreadVars(ptv);
326 if (
ConfGetBool(
"pcap-file.recursive", &should_recurse) == 1) {
332 if (
ConfGetBool(
"pcap-file.continuous", &should_loop) == 1) {
337 SCLogError(
"Error, --pcap-file-continuous and --pcap-file-recursive "
338 "cannot be used together.");
341 CleanupPcapFileThreadVars(ptv);
347 if (
ConfGetInt(
"pcap-file.delay", &delay) == 1) {
348 if (delay > 0 && delay < UINT_MAX) {
349 pv->
delay = (time_t)delay;
357 intmax_t poll_interval = 0;
358 if (
ConfGetInt(
"pcap-file.poll-interval", &poll_interval) == 1) {
359 if (poll_interval > 0 && poll_interval < UINT_MAX) {
375 if (
ConfGet(
"pcap-file.checksum-checks", &tmpstring) != 1) {
378 if (strcmp(tmpstring,
"auto") == 0) {
394 void ReceivePcapFileThreadExitStats(
ThreadVars *
tv,
void *data)
405 SCLogWarning(
"1/%" PRIu64
"th of packets have an invalid checksum,"
406 " consider setting pcap-file.checksum-checks variable to no"
407 " or use '-k none' option on command line.",
410 SCLogInfo(
"1/%" PRIu64
"th of packets have an invalid checksum",
413 SCLogNotice(
"read %" PRIu64
" file%s, %" PRIu64
" packets, %" PRIu64
" bytes",
424 CleanupPcapFileThreadVars(ptv);
int ConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
TmEcode PcapFileDispatch(PcapFileFileVars *ptv)
Main PCAP file reading Loop function.
#define PCAP_FILE_BUFFER_SIZE_MAX
#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
int ConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
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
#define PCAP_FILE_BUFFER_SIZE_DEFAULT
PcapFileDirectoryVars * directory
struct PcapFileFileVars_ PcapFileFileVars
@ CHECKSUM_VALIDATION_DISABLE
void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Finalize decoding of a packet.
int ConfValIsTrue(const char *val)
Check if a value is true.
TmEcode PcapDetermineDirectoryOrFile(char *filename, DIR **directory)
TmEcode(* PktAcqLoop)(ThreadVars *, void *, void *)
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
void TmModuleDecodePcapFileRegister(void)
@ CHECKSUM_VALIDATION_ENABLE
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
@ CHECKSUM_VALIDATION_AUTO
PcapFileGlobalVars pcap_g
TmEcode(* PktAcqBreakLoop)(ThreadVars *, void *)
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 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 PCAP_FILE_BUFFER_SIZE_MIN
#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.
int ConfValIsFalse(const char *val)
Check if a value is false.
PcapFileSharedVars * shared
DecodeThreadVars * DecodeThreadVarsAlloc(ThreadVars *tv)
Alloc and setup DecodeThreadVars.
TmEcode UnixSocketPcapFile(TmEcode tm, struct timespec *last_processed)
void PcapFileGlobalInit(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.
uint32_t read_buffer_size
void DecodeUpdatePacketCounters(ThreadVars *tv, const DecodeThreadVars *dtv, const Packet *p)