suricata
source-erf-dag.c
Go to the documentation of this file.
1 /* Copyright (C) 2010-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 Endace Technology Limited.
22  * \author Jason MacLulich <jason.maclulich@endace.com>
23  *
24  * Support for reading ERF records from a DAG card.
25  *
26  * Only ethernet supported at this time.
27  */
28 
29 #include "suricata-common.h"
30 #include "suricata.h"
31 #include "tm-threads.h"
32 
33 #include "util-privs.h"
34 #include "util-datalink.h"
35 #include "util-device.h"
36 #include "tmqh-packetpool.h"
37 #include "source-erf-dag.h"
38 
39 #ifndef HAVE_DAG
40 
41 TmEcode NoErfDagSupportExit(ThreadVars *, const void *, void **);
42 
43 void
45 {
46  tmm_modules[TMM_RECEIVEERFDAG].name = "ReceiveErfDag";
47  tmm_modules[TMM_RECEIVEERFDAG].ThreadInit = NoErfDagSupportExit;
53 }
54 
55 void
57 {
58  tmm_modules[TMM_DECODEERFDAG].name = "DecodeErfDag";
59  tmm_modules[TMM_DECODEERFDAG].ThreadInit = NoErfDagSupportExit;
65 }
66 
67 TmEcode
68 NoErfDagSupportExit(ThreadVars *tv, const void *initdata, void **data)
69 {
71  "Error creating thread %s: you do not have support for DAG cards "
72  "enabled please recompile with --enable-dag", tv->name);
73  exit(EXIT_FAILURE);
74 }
75 
76 #else /* Implied we do have DAG support */
77 
78 #include <dagapi.h>
79 
80 /* Minimum amount of data to read from the DAG at a time. */
81 #define MINDATA 32768
82 
83 /* Maximum time (us) to wait for MINDATA to be read. */
84 #define MAXWAIT 20000
85 
86 /* Poll interval in microseconds. */
87 #define POLL_INTERVAL 1000;
88 
89 /* Number of bytes per loop to process before fetching more data. */
90 #define BYTES_PER_LOOP (4 * 1024 * 1024) /* 4 MB */
91 
92 extern int max_pending_packets;
93 
94 typedef struct ErfDagThreadVars_ {
97 
98  int dagfd;
99  int dagstream;
100  char dagname[DAGNAME_BUFSIZE];
101 
102  struct timeval maxwait, poll; /* Could possibly be made static */
103 
105 
106  uint64_t bytes;
107  uint16_t packets;
108  uint16_t drops;
109 
110  /* Current location in the DAG stream input buffer.
111  */
112  uint8_t *top;
113  uint8_t *btm;
114 
116 
117 static inline TmEcode ProcessErfDagRecords(ErfDagThreadVars *ewtn, uint8_t *top,
118  uint32_t *pkts_read);
119 static inline TmEcode ProcessErfDagRecord(ErfDagThreadVars *ewtn, char *prec);
120 TmEcode ReceiveErfDagLoop(ThreadVars *, void *data, void *slot);
121 TmEcode ReceiveErfDagThreadInit(ThreadVars *, void *, void **);
124 TmEcode DecodeErfDagThreadInit(ThreadVars *, void *, void **);
126 TmEcode DecodeErfDag(ThreadVars *, Packet *, void *);
127 void ReceiveErfDagCloseStream(int dagfd, int stream);
128 
129 /**
130  * \brief Register the ERF file receiver (reader) module.
131  */
132 void
134 {
135  tmm_modules[TMM_RECEIVEERFDAG].name = "ReceiveErfDag";
145 }
146 
147 /**
148  * \brief Register the ERF file decoder module.
149  */
150 void
152 {
153  tmm_modules[TMM_DECODEERFDAG].name = "DecodeErfDag";
160 }
161 
162 /**
163  * \brief Initialize the ERF receiver thread, generate a single
164  * ErfDagThreadVar structure for each thread, this will
165  * contain a DAG file descriptor which is read when the
166  * thread executes.
167  *
168  * \param tv Thread variable to ThreadVars
169  * \param initdata Initial data to the interface passed from the user,
170  * this is processed by the user.
171  *
172  * We assume that we have only a single name for the DAG
173  * interface.
174  *
175  * \param data data pointer gets populated with
176  *
177  */
178 TmEcode
179 ReceiveErfDagThreadInit(ThreadVars *tv, void *initdata, void **data)
180 {
181  SCEnter();
182  int stream_count = 0;
183 
184  if (initdata == NULL) {
186  "Error: No DAG interface provided.");
188  }
189 
190  ErfDagThreadVars *ewtn = SCMalloc(sizeof(ErfDagThreadVars));
191  if (unlikely(ewtn == NULL)) {
193  "Failed to allocate memory for ERF DAG thread vars.");
194  }
195 
196  memset(ewtn, 0, sizeof(*ewtn));
197 
198  /* dag_parse_name will return a DAG device name and stream number
199  * to open for this thread.
200  */
201  if (dag_parse_name(initdata, ewtn->dagname, DAGNAME_BUFSIZE,
202  &ewtn->dagstream) < 0) {
204  "Failed to parse DAG interface: %s",
205  (char*)initdata);
206  SCFree(ewtn);
207  exit(EXIT_FAILURE);
208  }
209 
210  ewtn->livedev = LiveGetDevice(initdata);
211  if (ewtn->livedev == NULL) {
212  SCLogError(SC_ERR_INVALID_VALUE, "Unable to get %s live device",
213  (char *)initdata);
214  SCFree(ewtn);
216  }
217 
218  SCLogInfo("Opening DAG: %s on stream: %d for processing",
219  ewtn->dagname, ewtn->dagstream);
220 
221  if ((ewtn->dagfd = dag_open(ewtn->dagname)) < 0) {
222  SCLogError(SC_ERR_ERF_DAG_OPEN_FAILED, "Failed to open DAG: %s",
223  ewtn->dagname);
224  SCFree(ewtn);
226  }
227 
228  /* Check to make sure the card has enough available streams to
229  * support reading from the one specified.
230  */
231  if ((stream_count = dag_rx_get_stream_count(ewtn->dagfd)) < 0) {
233  "Failed to open stream: %d, DAG: %s, could not query stream count",
234  ewtn->dagstream, ewtn->dagname);
235  SCFree(ewtn);
237  }
238 
239  /* Check to make sure we have enough rx streams to open the stream
240  * the user is asking for.
241  */
242  if (ewtn->dagstream > stream_count * 2) {
244  "Failed to open stream: %d, DAG: %s, insufficient streams: %d",
245  ewtn->dagstream, ewtn->dagname, stream_count);
246  SCFree(ewtn);
248  }
249 
250  /* If we are transmitting into a soft DAG card then set the stream
251  * to act in reverse mode.
252  */
253  if (0 != (ewtn->dagstream & 0x01)) {
254  /* Setting reverse mode for using with soft dag from daemon side */
255  if (dag_set_mode(ewtn->dagfd, ewtn->dagstream, DAG_REVERSE_MODE)) {
257  "Failed to set mode to DAG_REVERSE_MODE on stream: %d, DAG: %s",
258  ewtn->dagstream, ewtn->dagname);
259  SCFree(ewtn);
261  }
262  }
263 
264  if (dag_attach_stream(ewtn->dagfd, ewtn->dagstream, 0, 0) < 0) {
266  "Failed to open DAG stream: %d, DAG: %s",
267  ewtn->dagstream, ewtn->dagname);
268  SCFree(ewtn);
270  }
271 
272  if (dag_start_stream(ewtn->dagfd, ewtn->dagstream) < 0) {
274  "Failed to start DAG stream: %d, DAG: %s",
275  ewtn->dagstream, ewtn->dagname);
276  SCFree(ewtn);
278  }
279 
280  SCLogInfo("Attached and started stream: %d on DAG: %s",
281  ewtn->dagstream, ewtn->dagname);
282 
283  /*
284  * Initialise DAG Polling parameters.
285  */
286  timerclear(&ewtn->maxwait);
287  ewtn->maxwait.tv_usec = MAXWAIT;
288  timerclear(&ewtn->poll);
289  ewtn->poll.tv_usec = POLL_INTERVAL;
290 
291  /* 32kB minimum data to return -- we still restrict the number of
292  * pkts that are processed to a maximum of dag_max_read_packets.
293  */
294  if (dag_set_stream_poll(ewtn->dagfd, ewtn->dagstream, MINDATA,
295  &(ewtn->maxwait), &(ewtn->poll)) < 0) {
297  "Failed to set poll parameters for stream: %d, DAG: %s",
298  ewtn->dagstream, ewtn->dagname);
299  SCFree(ewtn);
301  }
302 
303  ewtn->packets = StatsRegisterCounter("capture.dag_packets", tv);
304  ewtn->drops = StatsRegisterCounter("capture.dag_drops", tv);
305 
306  ewtn->tv = tv;
307  *data = (void *)ewtn;
308 
310 
311  SCLogInfo("Starting processing packets from stream: %d on DAG: %s",
312  ewtn->dagstream, ewtn->dagname);
313 
315 }
316 
317 /**
318  * \brief Receives packets from a DAG interface.
319  *
320  * \param tv pointer to ThreadVars
321  * \param data pointer to ErfDagThreadVars
322  * \param slot slot containing task information
323  *
324  * \retval TM_ECODE_OK on success
325  * \retval TM_ECODE_FAILED on failure
326  */
327 TmEcode
328 ReceiveErfDagLoop(ThreadVars *tv, void *data, void *slot)
329 {
330  SCEnter();
331 
333  uint32_t diff = 0;
334  int err;
335  uint8_t *top = NULL;
336  uint32_t pkts_read = 0;
337  TmSlot *s = (TmSlot *)slot;
338 
339  dtv->slot = s->slot_next;
340 
341  while (1) {
344  }
345 
346  top = dag_advance_stream(dtv->dagfd, dtv->dagstream, &(dtv->btm));
347  if (top == NULL) {
348  if (errno == EAGAIN) {
349  if (dtv->dagstream & 0x1) {
350  TmThreadsCaptureHandleTimeout(tv, NULL);
351  usleep(10 * 1000);
352  dtv->btm = dtv->top;
353  }
354  continue;
355  } else {
357  "Failed to read from stream: %d, DAG: %s when "
358  "using dag_advance_stream",
359  dtv->dagstream, dtv->dagname);
361  }
362  }
363 
364  diff = top - dtv->btm;
365  if (diff == 0) {
366  continue;
367  }
368 
369  assert(diff >= dag_record_size);
370 
371  err = ProcessErfDagRecords(dtv, top, &pkts_read);
372 
373  if (err == TM_ECODE_FAILED) {
375  "Failed to read from stream: %d, DAG: %s",
376  dtv->dagstream, dtv->dagname);
377  ReceiveErfDagCloseStream(dtv->dagfd, dtv->dagstream);
379  }
380 
382 
383  SCLogDebug("Read %d records from stream: %d, DAG: %s",
384  pkts_read, dtv->dagstream, dtv->dagname);
385  }
386 
388 }
389 
390 /**
391  * \brief Process a chunk of records read from a DAG interface.
392  *
393  * This function takes a pointer to buffer read from the DAG interface
394  * and processes it individual records.
395  */
396 static inline TmEcode
397 ProcessErfDagRecords(ErfDagThreadVars *ewtn, uint8_t *top, uint32_t *pkts_read)
398 {
399  SCEnter();
400 
401  int err = 0;
402  dag_record_t *dr = NULL;
403  char *prec = NULL;
404  int rlen;
405  char hdr_type = 0;
406  int processed = 0;
407 
408  *pkts_read = 0;
409 
410  while (((top - ewtn->btm) >= dag_record_size) &&
411  ((processed + dag_record_size) < BYTES_PER_LOOP)) {
412 
413  /* Make sure we have at least one packet in the packet pool,
414  * to prevent us from alloc'ing packets at line rate. */
415  PacketPoolWait();
416 
417  prec = (char *)ewtn->btm;
418  dr = (dag_record_t*)prec;
419  rlen = SCNtohs(dr->rlen);
420  hdr_type = dr->type;
421 
422  /* If we don't have enough data to finish processing this ERF
423  * record return and maybe next time we will.
424  */
425  if ((top - ewtn->btm) < rlen)
427 
428  ewtn->btm += rlen;
429  processed += rlen;
430 
431  /* Only support ethernet at this time. */
432  switch (hdr_type & 0x7f) {
433  case ERF_TYPE_PAD:
434  case ERF_TYPE_META:
435  /* Skip. */
436  continue;
437  case ERF_TYPE_DSM_COLOR_ETH:
438  case ERF_TYPE_COLOR_ETH:
439  case ERF_TYPE_COLOR_HASH_ETH:
440  /* In these types the color value overwrites the lctr
441  * (drop count). */
442  break;
443  case ERF_TYPE_ETH:
444  if (dr->lctr) {
445  StatsAddUI64(ewtn->tv, ewtn->drops, SCNtohs(dr->lctr));
446  }
447  break;
448  default:
450  "Processing of DAG record type: %d not implemented.", dr->type);
452  }
453 
454  err = ProcessErfDagRecord(ewtn, prec);
455  if (err != TM_ECODE_OK) {
457  }
458 
459  (*pkts_read)++;
460  }
461 
463 }
464 
465 /**
466  * \brief Process a DAG record into a TM packet buffer.
467  * \param prec pointer to a DAG record.
468  * \param
469  */
470 static inline TmEcode
471 ProcessErfDagRecord(ErfDagThreadVars *ewtn, char *prec)
472 {
473  SCEnter();
474 
475  int wlen = 0;
476  int rlen = 0;
477  int hdr_num = 0;
478  char hdr_type = 0;
479  dag_record_t *dr = (dag_record_t*)prec;
480  erf_payload_t *pload;
481  Packet *p;
482 
483  hdr_type = dr->type;
484  wlen = SCNtohs(dr->wlen);
485  rlen = SCNtohs(dr->rlen);
486 
487  /* count extension headers */
488  while (hdr_type & 0x80) {
489  if (rlen < (dag_record_size + (hdr_num * 8))) {
491  "Insufficient captured packet length.");
493  }
494  hdr_type = prec[(dag_record_size + (hdr_num * 8))];
495  hdr_num++;
496  }
497 
498  /* Check that the whole frame was captured */
499  if (rlen < (dag_record_size + (8 * hdr_num) + 2 + wlen)) {
500  SCLogInfo("Incomplete frame captured.");
502  }
503 
504  /* skip over extension headers */
505  pload = (erf_payload_t *)(prec + dag_record_size + (8 * hdr_num));
506 
508  if (p == NULL) {
510  "Failed to allocate a Packet on stream: %d, DAG: %s",
511  ewtn->dagstream, ewtn->dagname);
513  }
515 
516  SET_PKT_LEN(p, wlen);
518 
519  /* Take into account for link type Ethernet ETH frame starts
520  * after ther ERF header + pad.
521  */
522  if (unlikely(PacketCopyData(p, pload->eth.dst, GET_PKT_LEN(p)))) {
523  TmqhOutputPacketpool(ewtn->tv, p);
525  }
526 
527  /* Convert ERF time to timeval - from libpcap. */
528  uint64_t ts = dr->ts;
529  p->ts.tv_sec = ts >> 32;
530  ts = (ts & 0xffffffffULL) * 1000000;
531  ts += 0x80000000; /* rounding */
532  p->ts.tv_usec = ts >> 32;
533  if (p->ts.tv_usec >= 1000000) {
534  p->ts.tv_usec -= 1000000;
535  p->ts.tv_sec++;
536  }
537 
538  StatsIncr(ewtn->tv, ewtn->packets);
539  ewtn->bytes += wlen;
540 
541  if (TmThreadsSlotProcessPkt(ewtn->tv, ewtn->slot, p) != TM_ECODE_OK) {
543  }
544 
546 }
547 
548 /**
549  * \brief Print some stats to the log at program exit.
550  *
551  * \param tv Pointer to ThreadVars.
552  * \param data Pointer to data, ErfFileThreadVars.
553  */
554 void
556 {
557  ErfDagThreadVars *ewtn = (ErfDagThreadVars *)data;
558 
559  (void)SC_ATOMIC_SET(ewtn->livedev->pkts,
561  (void)SC_ATOMIC_SET(ewtn->livedev->drop,
563 
564  SCLogInfo("Stream: %d; Bytes: %"PRIu64"; Packets: %"PRIu64
565  "; Drops: %"PRIu64,
566  ewtn->dagstream,
567  ewtn->bytes,
570 }
571 
572 /**
573  * \brief Deinitializes the DAG card.
574  * \param tv pointer to ThreadVars
575  * \param data pointer that gets cast into PcapThreadVars for ptv
576  */
577 TmEcode
579 {
580  SCEnter();
581 
582  ErfDagThreadVars *ewtn = (ErfDagThreadVars *)data;
583 
585 
587 }
588 
589 void
590 ReceiveErfDagCloseStream(int dagfd, int stream)
591 {
592  dag_stop_stream(dagfd, stream);
593  dag_detach_stream(dagfd, stream);
594  dag_close(dagfd);
595 }
596 
597 /** Decode ErfDag */
598 
599 /**
600  * \brief This function passes off to link type decoders.
601  *
602  * DecodeErfDag decodes packets from DAG and passes
603  * them off to the proper link type decoder.
604  *
605  * \param t pointer to ThreadVars
606  * \param p pointer to the current packet
607  * \param data pointer that gets cast into PcapThreadVars for ptv
608  */
609 TmEcode
610 DecodeErfDag(ThreadVars *tv, Packet *p, void *data)
611 {
612  SCEnter();
614 
616 
617  /* update counters */
619 
620  /* call the decoder */
621  switch(p->datalink) {
622  case LINKTYPE_ETHERNET:
624  break;
625  default:
627  "Error: datalink type %" PRId32
628  " not yet supported in module DecodeErfDag",
629  p->datalink);
630  break;
631  }
632 
634 
636 }
637 
638 TmEcode
639 DecodeErfDagThreadInit(ThreadVars *tv, void *initdata, void **data)
640 {
641  SCEnter();
642  DecodeThreadVars *dtv = NULL;
643 
645 
646  if (dtv == NULL)
648 
650 
651  *data = (void *)dtv;
652 
654 }
655 
656 TmEcode
658 {
659  if (data != NULL)
660  DecodeThreadVarsFree(tv, data);
662 }
663 
664 #endif /* HAVE_DAG */
TmModule_::cap_flags
uint8_t cap_flags
Definition: tm-modules.h:67
tm-threads.h
ts
uint64_t ts
Definition: source-erf-file.c:55
BYTES_PER_LOOP
#define BYTES_PER_LOOP
Definition: source-erf-dag.c:90
max_pending_packets
int max_pending_packets
Definition: suricata.c:216
StatsIncr
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
Definition: counters.c:169
TMM_RECEIVEERFDAG
@ TMM_RECEIVEERFDAG
Definition: tm-threads-common.h:52
ThreadVars_::name
char name[16]
Definition: threadvars.h:65
SC_ERR_INVALID_VALUE
@ SC_ERR_INVALID_VALUE
Definition: util-error.h:160
PacketCopyData
int PacketCopyData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
Copy data to Packet payload and set packet length.
Definition: decode.c:295
PKT_IS_PSEUDOPKT
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition: decode.h:1238
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:387
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
SC_ERR_ERF_DAG_STREAM_START_FAILED
@ SC_ERR_ERF_DAG_STREAM_START_FAILED
Definition: util-error.h:197
DecodeErfDagThreadInit
TmEcode DecodeErfDagThreadInit(ThreadVars *, void *, void **)
Definition: source-erf-dag.c:639
ErfDagThreadVars_::btm
uint8_t * btm
Definition: source-erf-dag.c:113
LiveDevice_
Definition: util-device.h:40
SURICATA_STOP
#define SURICATA_STOP
Definition: suricata.h:90
ErfDagThreadVars_::bytes
uint64_t bytes
Definition: source-erf-dag.c:106
util-privs.h
StatsSyncCountersIfSignalled
#define StatsSyncCountersIfSignalled(tv)
Definition: counters.h:138
ErfDagThreadVars_::top
uint8_t * top
Definition: source-erf-dag.c:112
PacketDecodeFinalize
void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Finalize decoding of a packet.
Definition: decode.c:147
TmqhOutputPacketpool
void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
Definition: tmqh-packetpool.c:375
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:83
tmqh-packetpool.h
TmModule_::PktAcqLoop
TmEcode(* PktAcqLoop)(ThreadVars *, void *, void *)
Definition: tm-modules.h:54
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:82
MINDATA
#define MINDATA
Definition: source-erf-dag.c:81
ErfDagThreadVars_::dagname
char dagname[DAGNAME_BUFSIZE]
Definition: source-erf-dag.c:100
TmModule_::ThreadDeinit
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition: tm-modules.h:49
Packet_::datalink
int datalink
Definition: decode.h:616
source-erf-dag.h
PKT_SET_SRC
#define PKT_SET_SRC(p, src_val)
Definition: decode.h:1241
DecodeRegisterPerfCounters
void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
Definition: decode.c:523
SC_ERR_ERF_DAG_OPEN_FAILED
@ SC_ERR_ERF_DAG_OPEN_FAILED
Definition: util-error.h:195
SET_PKT_LEN
#define SET_PKT_LEN(p, len)
Definition: decode.h:240
util-device.h
PKT_SRC_WIRE
@ PKT_SRC_WIRE
Definition: decode.h:51
TmModule_::PktAcqBreakLoop
TmEcode(* PktAcqBreakLoop)(ThreadVars *, void *)
Definition: tm-modules.h:57
LiveGetDevice
LiveDevice * LiveGetDevice(const char *name)
Get a pointer to the device at idx.
Definition: util-device.c:279
MAXWAIT
#define MAXWAIT
Definition: source-erf-dag.c:84
SCEnter
#define SCEnter(...)
Definition: util-debug.h:300
GET_PKT_DATA
#define GET_PKT_DATA(p)
Definition: decode.h:236
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
TmModule_::Func
TmEcode(* Func)(ThreadVars *, Packet *, void *)
Definition: tm-modules.h:52
ErfDagThreadVars_::livedev
LiveDevice * livedev
Definition: source-erf-dag.c:104
ReceiveErfDagThreadExitStats
void ReceiveErfDagThreadExitStats(ThreadVars *, void *)
Print some stats to the log at program exit.
Definition: source-erf-dag.c:555
ReceiveErfDagCloseStream
void ReceiveErfDagCloseStream(int dagfd, int stream)
Definition: source-erf-dag.c:590
ErfDagThreadVars_::packets
uint16_t packets
Definition: source-erf-dag.c:107
SC_CAP_NET_ADMIN
#define SC_CAP_NET_ADMIN
Definition: util-privs.h:31
SC_ERR_INVALID_ARGUMENT
@ SC_ERR_INVALID_ARGUMENT
Definition: util-error.h:43
ErfDagThreadVars_::dagfd
int dagfd
Definition: source-erf-dag.c:98
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:281
StatsGetLocalCounterValue
uint64_t StatsGetLocalCounterValue(ThreadVars *tv, uint16_t id)
Get the value of the local copy of the counter that hold this id.
Definition: counters.c:1257
PacketPoolWait
void PacketPoolWait(void)
Definition: tmqh-packetpool.c:84
TMM_DECODEERFDAG
@ TMM_DECODEERFDAG
Definition: tm-threads-common.h:53
SC_ERR_DAG_NOSUPPORT
@ SC_ERR_DAG_NOSUPPORT
Definition: util-error.h:202
Packet_
Definition: decode.h:442
TM_FLAG_DECODE_TM
#define TM_FLAG_DECODE_TM
Definition: tm-modules.h:32
tmm_modules
TmModule tmm_modules[TMM_SIZE]
Definition: tm-modules.c:33
wlen
uint16_t wlen
Definition: source-erf-file.c:60
GET_PKT_LEN
#define GET_PKT_LEN(p)
Definition: decode.h:235
TmSlot_
Definition: tm-threads.h:52
DecodeErfDag
TmEcode DecodeErfDag(ThreadVars *, Packet *, void *)
This function passes off to link type decoders.
Definition: source-erf-dag.c:610
TmEcode
TmEcode
Definition: tm-threads-common.h:81
TmModuleDecodeErfDagRegister
void TmModuleDecodeErfDagRegister(void)
Register the ERF file decoder module.
Definition: source-erf-dag.c:151
TmModule_::name
const char * name
Definition: tm-modules.h:44
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:217
TM_FLAG_RECEIVE_TM
#define TM_FLAG_RECEIVE_TM
Definition: tm-modules.h:31
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:30
POLL_INTERVAL
#define POLL_INTERVAL
Definition: source-erf-dag.c:87
ReceiveErfDagThreadInit
TmEcode ReceiveErfDagThreadInit(ThreadVars *, void *, void **)
Initialize the ERF receiver thread, generate a single ErfDagThreadVar structure for each thread,...
Definition: source-erf-dag.c:179
ErfDagThreadVars_::poll
struct timeval maxwait poll
Definition: source-erf-dag.c:102
DecodeThreadVarsFree
void DecodeThreadVarsFree(ThreadVars *tv, DecodeThreadVars *dtv)
Definition: decode.c:703
Packet_::ts
struct timeval ts
Definition: decode.h:485
SCNtohs
#define SCNtohs(x)
Definition: suricata-common.h:395
suricata-common.h
ErfDagThreadVars_::tv
ThreadVars * tv
Definition: source-erf-dag.c:95
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
TmModule_::ThreadInit
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:47
FatalError
#define FatalError(x,...)
Definition: util-debug.h:532
ErfDagThreadVars_::dagstream
int dagstream
Definition: source-erf-dag.c:99
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
SC_ERR_UNIMPLEMENTED
@ SC_ERR_UNIMPLEMENTED
Definition: util-error.h:118
TmModuleReceiveErfDagRegister
void TmModuleReceiveErfDagRegister(void)
Register the ERF file receiver (reader) module.
Definition: source-erf-dag.c:133
TmModule_::ThreadExitPrintStats
void(* ThreadExitPrintStats)(ThreadVars *, void *)
Definition: tm-modules.h:48
StatsAddUI64
void StatsAddUI64(ThreadVars *tv, uint16_t id, uint64_t x)
Adds a value of type uint64_t to the local counter.
Definition: counters.c:148
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
ErfDagThreadVars_::drops
uint16_t drops
Definition: source-erf-dag.c:108
ErfDagThreadVars_::slot
TmSlot * slot
Definition: source-erf-dag.c:96
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SC_ERR_ERF_DAG_STREAM_OPEN_FAILED
@ SC_ERR_ERF_DAG_STREAM_OPEN_FAILED
Definition: util-error.h:196
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:672
SC_ERR_FATAL
@ SC_ERR_FATAL
Definition: util-error.h:203
DecodeThreadVarsAlloc
DecodeThreadVars * DecodeThreadVarsAlloc(ThreadVars *tv)
Alloc and setup DecodeThreadVars.
Definition: decode.c:684
SC_ERR_ERF_DAG_STREAM_READ_FAILED
@ SC_ERR_ERF_DAG_STREAM_READ_FAILED
Definition: util-error.h:199
SC_ERR_DATALINK_UNIMPLEMENTED
@ SC_ERR_DATALINK_UNIMPLEMENTED
Definition: util-error.h:68
ReceiveErfDagThreadDeinit
TmEcode ReceiveErfDagThreadDeinit(ThreadVars *, void *)
Deinitializes the DAG card.
Definition: source-erf-dag.c:578
DecodeErfDagThreadDeinit
TmEcode DecodeErfDagThreadDeinit(ThreadVars *tv, void *data)
Definition: source-erf-dag.c:657
ReceiveErfDagLoop
TmEcode ReceiveErfDagLoop(ThreadVars *, void *data, void *slot)
Receives packets from a DAG interface.
Definition: source-erf-dag.c:328
SC_ERR_MEM_ALLOC
@ SC_ERR_MEM_ALLOC
Definition: util-error.h:31
suricata.h
TmSlot_::slot_next
struct TmSlot_ * slot_next
Definition: tm-threads.h:61
StatsRegisterCounter
uint16_t StatsRegisterCounter(const char *name, struct ThreadVars_ *tv)
Registers a normal, unqualified counter.
Definition: counters.c:956
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:304
Packet_::type
uint8_t type
Definition: decode.h:452
SC_ERR_ERF_DAG_STREAM_SET_FAILED
@ SC_ERR_ERF_DAG_STREAM_SET_FAILED
Definition: util-error.h:198
ErfDagThreadVars
struct ErfDagThreadVars_ ErfDagThreadVars
PacketGetFromQueueOrAlloc
Packet * PacketGetFromQueueOrAlloc(void)
Get a packet. We try to get a packet from the packetpool first, but if that is empty we alloc a packe...
Definition: decode.c:211
DecodeEthernet
int DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Definition: decode-ethernet.c:42
TmModule_::flags
uint8_t flags
Definition: tm-modules.h:70
DecodeUpdatePacketCounters
void DecodeUpdatePacketCounters(ThreadVars *tv, const DecodeThreadVars *dtv, const Packet *p)
Definition: decode.c:650
LINKTYPE_ETHERNET
#define LINKTYPE_ETHERNET
Definition: decode.h:1154
suricata_ctl_flags
volatile uint8_t suricata_ctl_flags
Definition: suricata.c:202
ErfDagThreadVars_
Definition: source-erf-dag.c:94
rlen
uint16_t rlen
Definition: source-erf-file.c:58