suricata
source-pcap-file-helper.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2020 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Danny Browning <danny.browning@protectwise.com>
22  */
23 
24 #include "suricata-common.h"
25 #include "tm-threads.h"
26 
27 #ifndef SURICATA_SOURCE_PCAP_FILE_HELPER_H
28 #define SURICATA_SOURCE_PCAP_FILE_HELPER_H
29 
30 typedef struct PcapFileGlobalVars_ {
31  uint64_t cnt; /** packet counter */
34  SC_ATOMIC_DECLARE(unsigned int, invalid_checksums);
35  uint32_t read_buffer_size;
37 
38 /**
39  * Data that is shared amongst File, Directory, and Thread level vars
40  */
41 typedef struct PcapFileSharedVars_
42 {
43  char *bpf_string;
44 
45  uint32_t tenant_id;
46 
47  struct timespec last_processed;
48 
50 
53 
54  /* counters */
55  uint64_t pkts;
56  uint64_t bytes;
57  uint64_t files;
58 
59  uint8_t done;
60  uint32_t errs;
61 
62  /** callback result -- set if one of the thread module failed. */
63  int cb_result;
65 
66 /**
67  * Data specific to a single pcap file
68  */
69 typedef struct PcapFileFileVars_
70 {
71  char *filename;
72  pcap_t *pcap_handle;
73 
74  int datalink;
75  struct bpf_program filter;
76 
78 
79  /* fields used to get the first packet's timestamp early,
80  * so it can be used to setup the time subsys. */
81  const u_char *first_pkt_data;
82  struct pcap_pkthdr *first_pkt_hdr;
83  struct timeval first_pkt_ts;
84 
85  /** flex array member for the libc io read buffer. Size controlled by
86  * PcapFileGlobalVars::read_buffer_size. */
87 #if defined(HAVE_SETVBUF) && defined(OS_LINUX)
88  char buffer[];
89 #endif
91 
92 /**
93  * Dispatch a file for processing, where the information necessary to process that
94  * file is as PcapFileFileVars object.
95  * @param ptv PcapFileFileVars object to be processed
96  * @return
97  */
99 
100 /**
101  * From a PcapFileFileVars, prepare the filename for processing by setting
102  * pcap_handle, datalink, and filter
103  * @param pfv PcapFileFileVars object to populate
104  * @return
105  */
107 
108 /**
109  * Cleanup resources associated with a PcapFileFileVars object.
110  * @param pfv Object to be cleaned up
111  */
113 
114 /**
115  * Determine if a datalink type is valid, setting a decoder function if valid.
116  * @param datalink Datalink type to validate
117  * @param decoder Pointer to decoder to set if valid
118  * @return TM_ECODE_OK if valid datalink type and decoder has been set.
119  */
120 TmEcode ValidateLinkType(int datalink, DecoderFunc *decoder);
121 
122 const char *PcapFileGetFilename(void);
123 
124 #endif /* SURICATA_SOURCE_PCAP_FILE_HELPER_H */
PcapFileSharedVars_::slot
TmSlot * slot
Definition: source-pcap-file-helper.h:52
tm-threads.h
PcapFileFileVars_::filename
char * filename
Definition: source-pcap-file-helper.h:71
PcapFileSharedVars_
Definition: source-pcap-file-helper.h:42
PcapFileGlobalVars_
Definition: source-pcap-file-helper.h:30
PcapFileFileVars_::first_pkt_data
const u_char * first_pkt_data
Definition: source-pcap-file-helper.h:81
PcapFileFileVars_::datalink
int datalink
Definition: source-pcap-file-helper.h:74
PcapFileFileVars_::shared
PcapFileSharedVars * shared
Definition: source-pcap-file-helper.h:77
CleanupPcapFileFileVars
void CleanupPcapFileFileVars(PcapFileFileVars *pfv)
Definition: source-pcap-file-helper.c:39
PcapFileSharedVars_::should_delete
bool should_delete
Definition: source-pcap-file-helper.h:49
DecoderFunc
int(* DecoderFunc)(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Definition: decode.h:1144
PcapFileFileVars
struct PcapFileFileVars_ PcapFileFileVars
PcapFileSharedVars_::cb_result
int cb_result
Definition: source-pcap-file-helper.h:63
PcapFileSharedVars
struct PcapFileSharedVars_ PcapFileSharedVars
PcapFileSharedVars_::done
uint8_t done
Definition: source-pcap-file-helper.h:59
InitPcapFile
TmEcode InitPcapFile(PcapFileFileVars *pfv)
Definition: source-pcap-file-helper.c:196
PcapFileSharedVars_::files
uint64_t files
Definition: source-pcap-file-helper.h:57
PcapFileGlobalVars
struct PcapFileGlobalVars_ PcapFileGlobalVars
PcapFileGlobalVars_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(unsigned int, invalid_checksums)
PcapFileGlobalVars_::cnt
uint64_t cnt
Definition: source-pcap-file-helper.h:31
PcapFileGlobalVars_::checksum_mode
ChecksumValidationMode checksum_mode
Definition: source-pcap-file-helper.h:33
PcapFileDispatch
TmEcode PcapFileDispatch(PcapFileFileVars *ptv)
Main PCAP file reading Loop function.
Definition: source-pcap-file-helper.c:126
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
TmSlot_
Definition: tm-threads.h:53
PcapFileFileVars_
Definition: source-pcap-file-helper.h:70
TmEcode
TmEcode
Definition: tm-threads-common.h:79
PcapFileGetFilename
const char * PcapFileGetFilename(void)
Definition: source-pcap-file-helper.c:118
PcapFileSharedVars_::bpf_string
char * bpf_string
Definition: source-pcap-file-helper.h:43
ChecksumValidationMode
ChecksumValidationMode
Definition: decode.h:41
suricata-common.h
PcapFileSharedVars_::tenant_id
uint32_t tenant_id
Definition: source-pcap-file-helper.h:45
PcapFileFileVars_::first_pkt_ts
struct timeval first_pkt_ts
Definition: source-pcap-file-helper.h:83
ValidateLinkType
TmEcode ValidateLinkType(int datalink, DecoderFunc *decoder)
Definition: source-pcap-file-helper.c:251
PcapFileSharedVars_::last_processed
struct timespec last_processed
Definition: source-pcap-file-helper.h:47
PcapFileGlobalVars_::conf_checksum_mode
ChecksumValidationMode conf_checksum_mode
Definition: source-pcap-file-helper.h:32
PcapFileFileVars_::pcap_handle
pcap_t * pcap_handle
Definition: source-pcap-file-helper.h:72
PcapFileFileVars_::first_pkt_hdr
struct pcap_pkthdr * first_pkt_hdr
Definition: source-pcap-file-helper.h:82
PcapFileFileVars_::filter
struct bpf_program filter
Definition: source-pcap-file-helper.h:75
PcapFileSharedVars_::bytes
uint64_t bytes
Definition: source-pcap-file-helper.h:56
PcapFileSharedVars_::tv
ThreadVars * tv
Definition: source-pcap-file-helper.h:51
PcapFileSharedVars_::errs
uint32_t errs
Definition: source-pcap-file-helper.h:60
PcapFileGlobalVars_::read_buffer_size
uint32_t read_buffer_size
Definition: source-pcap-file-helper.h:35
PcapFileSharedVars_::pkts
uint64_t pkts
Definition: source-pcap-file-helper.h:55