suricata
source-netmap.c
Go to the documentation of this file.
1 /* Copyright (C) 2011-2021 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 * \defgroup netmap Netmap running mode
20 *
21 * @{
22 */
23 
24 /**
25  * \file
26  *
27  * \author Aleksey Katargin <gureedo@gmail.com>
28  * \author Victor Julien <victor@inliniac.net>
29  * \author Bill Meeks <billmeeks8@gmail.com>
30  *
31  * Netmap socket acquisition support
32  *
33  * Many thanks to Luigi Rizzo for guidance and support.
34  *
35  */
36 
37 #include "suricata.h"
38 #include "suricata-common.h"
39 #include "tm-threads.h"
40 #include "util-bpf.h"
41 #include "util-privs.h"
42 #include "util-validate.h"
43 #include "util-datalink.h"
44 
45 #include "source-netmap.h"
46 
47 #ifdef HAVE_NETMAP
48 
49 #define NETMAP_WITH_LIBS
50 #ifdef DEBUG
51 #define DEBUG_NETMAP_USER
52 #endif
53 
54 #include <net/netmap_user.h>
55 #include <libnetmap.h>
56 
57 #endif /* HAVE_NETMAP */
58 
59 #include "util-ioctl.h"
60 
61 #ifndef HAVE_NETMAP
62 
63 /**
64 * \brief this function prints an error message and exits.
65 */
66 static TmEcode NoNetmapSupportExit(ThreadVars *tv, const void *initdata, void **data)
67 {
69  "Error creating thread %s: Netmap is not enabled. "
70  "Make sure to pass --enable-netmap to configure when building.",
71  tv->name);
72 }
73 
75 {
76  tmm_modules[TMM_RECEIVENETMAP].name = "ReceiveNetmap";
77  tmm_modules[TMM_RECEIVENETMAP].ThreadInit = NoNetmapSupportExit;
79 }
80 
81 /**
82 * \brief Registration Function for DecodeNetmap.
83 */
85 {
86  tmm_modules[TMM_DECODENETMAP].name = "DecodeNetmap";
87  tmm_modules[TMM_DECODENETMAP].ThreadInit = NoNetmapSupportExit;
89 }
90 
91 #else /* We have NETMAP support */
92 
93 #define POLL_TIMEOUT 100
94 
95 #if defined(__linux__)
96 #define POLL_EVENTS (POLLHUP|POLLRDHUP|POLLERR|POLLNVAL)
97 
98 #ifndef IFF_PPROMISC
99 #define IFF_PPROMISC IFF_PROMISC
100 #endif
101 
102 #else
103 #define POLL_EVENTS (POLLHUP|POLLERR|POLLNVAL)
104 #endif
105 
106 enum { NETMAP_FLAG_ZERO_COPY = 1, NETMAP_FLAG_EXCL_RING_ACCESS = 2 };
107 
108 /**
109  * \brief Netmap device instance. Each ring for each device gets its own
110  * device.
111  */
112 typedef struct NetmapDevice_
113 {
114  struct nmport_d *nmd;
115  unsigned int ref;
116  SC_ATOMIC_DECLARE(unsigned int, threads_run);
117  TAILQ_ENTRY(NetmapDevice_) next;
118  // actual ifname can only be 16, but we store a bit more,
119  // like the options string and a 'netmap:' prefix.
120  char ifname[32];
121  int ring;
122  int direction; // 0 rx, 1 tx
123 
124  // autofp: Used to lock a destination ring while we are sending data.
125  SCMutex netmap_dev_lock;
126 } NetmapDevice;
127 
128 /**
129  * \brief Module thread local variables.
130  */
131 typedef struct NetmapThreadVars_
132 {
133  /* receive interface */
134  NetmapDevice *ifsrc;
135  /* dst interface for IPS mode */
136  NetmapDevice *ifdst;
137 
138  int flags;
139  struct bpf_program bpf_prog;
140 
141  /* suricata internals */
142  TmSlot *slot;
143  ThreadVars *tv;
144  LiveDevice *livedev;
145 
146  /* copy from config */
147  int copy_mode;
148  ChecksumValidationMode checksum_mode;
149 
150  /* counters */
151  uint64_t pkts;
152  uint64_t bytes;
153  uint64_t drops;
154  uint16_t capture_kernel_packets;
155  uint16_t capture_kernel_drops;
156 } NetmapThreadVars;
157 
158 typedef TAILQ_HEAD(NetmapDeviceList_, NetmapDevice_) NetmapDeviceList;
159 
160 static NetmapDeviceList netmap_devlist = TAILQ_HEAD_INITIALIZER(netmap_devlist);
161 static SCMutex netmap_devlist_lock = SCMUTEX_INITIALIZER;
162 
163 /** \brief get RSS RX-queue count
164  * \retval rx_rings RSS RX queue count or 0 on error
165  */
166 int NetmapGetRSSCount(const char *ifname)
167 {
168  struct nmreq_port_info_get req;
169  struct nmreq_header hdr;
170  int rx_rings = 0;
171 
172  /* we need the base interface name to query queues */
173  char base_name[IFNAMSIZ];
174  strlcpy(base_name, ifname, sizeof(base_name));
175  if (strlen(base_name) > 0 &&
176  (base_name[strlen(base_name) - 1] == '^' || base_name[strlen(base_name) - 1] == '*')) {
177  base_name[strlen(base_name) - 1] = '\0';
178  }
179 
180  SCMutexLock(&netmap_devlist_lock);
181 
182  /* open netmap device */
183  int fd = open("/dev/netmap", O_RDWR);
184  if (fd == -1) {
186  "Couldn't open netmap device, error %s",
187  strerror(errno));
188  goto error_open;
189  }
190 
191  /* query netmap interface info */
192  memset(&req, 0, sizeof(req));
193  memset(&hdr, 0, sizeof(hdr));
194  hdr.nr_version = NETMAP_API;
195  hdr.nr_reqtype = NETMAP_REQ_PORT_INFO_GET;
196  hdr.nr_body = (uintptr_t)&req;
197  strlcpy(hdr.nr_name, base_name, sizeof(hdr.nr_name));
198 
199  if (ioctl(fd, NIOCCTRL, &hdr) != 0) {
200  SCLogError(SC_ERR_NETMAP_CREATE, "Couldn't query netmap for info about %s, error %s",
201  ifname, strerror(errno));
202  goto error_fd;
203  };
204 
205  /* return RX rings count if it equals TX rings count */
206  if (req.nr_rx_rings == req.nr_tx_rings) {
207  rx_rings = req.nr_rx_rings;
208  }
209 
210 error_fd:
211  close(fd);
212 error_open:
213  SCMutexUnlock(&netmap_devlist_lock);
214  return rx_rings;
215 }
216 
217 static void NetmapDestroyDevice(NetmapDevice *pdev)
218 {
219  nmport_close(pdev->nmd);
220  SCMutexDestroy(&pdev->netmap_dev_lock);
221  SCFree(pdev);
222 }
223 
224 /**
225  * \brief Close or dereference netmap device instance.
226  * \param dev Netmap device instance.
227  * \return Zero on success.
228  */
229 static int NetmapClose(NetmapDevice *dev)
230 {
231  NetmapDevice *pdev, *tmp;
232 
233  SCMutexLock(&netmap_devlist_lock);
234 
235  TAILQ_FOREACH_SAFE (pdev, &netmap_devlist, next, tmp) {
236  if (pdev == dev) {
237  pdev->ref--;
238  if (!pdev->ref) {
239  NetmapDestroyDevice(pdev);
240  }
241  SCMutexUnlock(&netmap_devlist_lock);
242  return 0;
243  }
244  }
245 
246  SCMutexUnlock(&netmap_devlist_lock);
247  return -1;
248 }
249 
250 /**
251  * \brief Close all open netmap device instances.
252  */
253 static void NetmapCloseAll(void)
254 {
255  NetmapDevice *pdev, *tmp;
256 
257  SCMutexLock(&netmap_devlist_lock);
258 
259  TAILQ_FOREACH_SAFE (pdev, &netmap_devlist, next, tmp) {
260  NetmapDestroyDevice(pdev);
261  }
262 
263  SCMutexUnlock(&netmap_devlist_lock);
264 }
265 
266 /**
267  * \brief Open interface in netmap mode.
268  * \param ifname Interface name.
269  * \param promisc Enable promiscuous mode.
270  * \param dev Pointer to requested netmap device instance.
271  * \param verbose Verbose error logging.
272  * \param read Indicates direction: RX or TX
273  * \param zerocopy 1 if zerocopy access requested
274  * \param soft Use Host stack (software) interface
275  * \return Zero on success.
276  */
277 static int NetmapOpen(NetmapIfaceSettings *ns, NetmapDevice **pdevice, int verbose, int read,
278  bool zerocopy, bool soft)
279 {
280  SCEnter();
281  SCLogDebug("ifname %s", ns->iface);
282 
283  char base_name[IFNAMSIZ];
284  strlcpy(base_name, ns->iface, sizeof(base_name));
285  if (strlen(base_name) > 0 &&
286  (base_name[strlen(base_name)-1] == '^' ||
287  base_name[strlen(base_name)-1] == '*'))
288  {
289  base_name[strlen(base_name)-1] = '\0';
290  }
291 
292  if (ns->real) {
293  /* check interface is up */
294  int if_flags = GetIfaceFlags(base_name);
295  if (if_flags == -1) {
296  if (verbose) {
297  SCLogError(SC_ERR_NETMAP_CREATE, "Cannot access network interface '%s' (%s)",
298  base_name, ns->iface);
299  }
300  goto error;
301  }
302 
303  /* bring iface up if it is down */
304  if ((if_flags & IFF_UP) == 0) {
305  SCLogError(SC_ERR_NETMAP_CREATE, "interface '%s' (%s) is down", base_name, ns->iface);
306  goto error;
307  }
308  /* if needed, try to set iface in promisc mode */
309  if (ns->promisc && (if_flags & (IFF_PROMISC|IFF_PPROMISC)) == 0) {
310  if_flags |= IFF_PPROMISC;
311  SetIfaceFlags(base_name, if_flags); // TODO reset at exit
312  // TODO move to parse config?
313  }
314  }
315  NetmapDevice *pdev = NULL, *spdev = NULL;
316  pdev = SCCalloc(1, sizeof(*pdev));
317  if (unlikely(pdev == NULL)) {
318  SCLogError(SC_ERR_MEM_ALLOC, "Memory allocation failed");
319  goto error;
320  }
321  SC_ATOMIC_INIT(pdev->threads_run);
322 
323  SCMutexLock(&netmap_devlist_lock);
324 
325  const int direction = (read != 1);
326  int ring = 0;
327  /* Search for interface in our already opened list. */
328  /* We will find it when opening multiple rings on */
329  /* the device when it exposes multiple RSS queues. */
330  TAILQ_FOREACH(spdev, &netmap_devlist, next) {
331  SCLogDebug("spdev %s", spdev->ifname);
332  if (direction == spdev->direction && strcmp(ns->iface, spdev->ifname) == 0) {
333  ring = spdev->ring + 1;
334  }
335  }
336  SCLogDebug("netmap/%s: using ring %d", ns->iface, ring);
337 
338  const char *opt_R = "R";
339  const char *opt_T = "T";
340  const char *opt_x = "x"; // not for IPS
341  const char *opt_z = "z"; // zero copy, not for IPS
342 
343  /* assemble options string */
344  char optstr[16];
345  if (ns->ips)
346  opt_x = "";
347  // z seems to not play well with multiple opens of a real dev on linux
348  opt_z = "";
349 
350  /*
351  * How netmap endpoint names are selected:
352  *
353  * The following logic within the "retry" loop builds endpoint names.
354  *
355  * IPS Mode:
356  * There are two endpoints: one hardware NIC and either a hardware NIC or host stack "NIC".
357  *
358  * IDS Mode:
359  * One endpoint -- usually a hardware NIC.
360  *
361  * IPS mode -- with one endpoint a host stack "NIC":
362  * When using multiple rings/threads, then the open of the initial Ring 0 MUST
363  * instruct netmap to open multiple Host Stack rings (as the default is to open only a single
364  * pair). This is also critical for the HW NIC endpoint. This is done by adding
365  * “@conf:host-rings=x” suffix option (where “x” is the number of host rings desired)
366  * to BOTH endpoint nmport_open_desc() calls for ring 0 (hardware and host stack).
367  * For subsequent additional ring open calls, omit the suffix option specifying host ring count.
368  *
369  * IPS mode -- both endpoints are hardware NICs:
370  * Do NOT pass any suffix option (even for Ring 0). You do not need to tell netmap how many
371  * rings, because it already knows the correct value from the NIC driver itself. Specifying a
372  * desired ring count when both ends are Hardware NICs confuses netmap, and it seems to default
373  * to using only a single hardware ring. In this scenario, specify only the specific ring number
374  * being opened.
375  */
376 
377  // loop to retry opening if unsupported options are used
378 retry:
379  snprintf(optstr, sizeof(optstr), "%s%s%s", opt_z, opt_x, direction == 0 ? opt_R : opt_T);
380 
381  char devname[128];
382  if (strncmp(ns->iface, "netmap:", 7) == 0) {
383  snprintf(devname, sizeof(devname), "%s}%d%s%s",
384  ns->iface, ring, strlen(optstr) ? "/" : "", optstr);
385  } else if (strlen(ns->iface) > 5 && strncmp(ns->iface, "vale", 4) == 0 && isdigit(ns->iface[4])) {
386  snprintf(devname, sizeof(devname), "%s", ns->iface);
387  } else if (ring == 0 && ns->threads == 1) {
388  /* just a single thread and ring, so don't use ring param */
389  snprintf(devname, sizeof(devname), "netmap:%s%s%s",
390  ns->iface, strlen(optstr) ? "/" : "", optstr);
391  SCLogDebug("device with %s-ring enabled (devname): %s", soft ? "SW" : "HW", devname);
392  } else {
393  /* Going to be using multiple threads and rings */
394  if (ns->sw_ring) {
395  /* Opening a host stack interface */
396  if (ring == 0) {
397  /* Ring 0, so tell netmap how many host rings we want created */
398  snprintf(devname, sizeof(devname), "netmap:%s%d%s%s@conf:host-rings=%d", ns->iface,
399  ring, strlen(optstr) ? "/" : "", optstr, ns->threads);
400  } else {
401  /* Software (host) ring, but not initial open of ring 0 */
402  snprintf(devname, sizeof(devname), "netmap:%s%d%s%s", ns->iface, ring,
403  strlen(optstr) ? "/" : "", optstr);
404  }
405  SCLogDebug("device with SW-ring enabled (devname): %s", devname);
406  } else if (ring == 0 && soft) {
407  /* Ring 0 of HW endpoint, and other endpoint is SW stack,
408  * so request SW host stack rings to match HW rings count.
409  */
410  snprintf(devname, sizeof(devname), "netmap:%s-%d%s%s@conf:host-rings=%d", ns->iface,
411  ring, strlen(optstr) ? "/" : "", optstr, ns->threads);
412  SCLogDebug("device with HW-ring enabled (devname): %s", devname);
413  } else {
414  /* Hardware ring other than ring 0, or both endpoints are HW
415  * and there is no host stack (SW) endpoint */
416  snprintf(devname, sizeof(devname), "netmap:%s-%d%s%s", ns->iface, ring,
417  strlen(optstr) ? "/" : "", optstr);
418  SCLogDebug("device with HW-ring enabled (devname): %s", devname);
419  }
420  }
421 
422  strlcpy(pdev->ifname, ns->iface, sizeof(pdev->ifname));
423 
424  /* have the netmap API parse device name and prepare the port descriptor for us */
425  pdev->nmd = nmport_prepare(devname);
426 
427  if (pdev->nmd != NULL) {
428  /* For RX devices, set the nr_mode flag we need on the netmap port TX rings prior to opening
429  */
430  if (read) {
431  pdev->nmd->reg.nr_flags |= NR_NO_TX_POLL;
432  }
433 
434  /* Now attempt to actually open the netmap port descriptor */
435  if (nmport_open_desc(pdev->nmd) < 0) {
436  /* the open failed, so clean-up the descriptor and fall through to error handler */
437  nmport_close(pdev->nmd);
438  pdev->nmd = NULL;
439  }
440  }
441 
442  if (pdev->nmd == NULL) {
443  if (errno == EINVAL) {
444  if (opt_z[0] == 'z') {
445  SCLogNotice("got '%s' EINVAL: going to retry without 'z'", devname);
446  opt_z = "";
447  goto retry;
448  } else if (opt_x[0] == 'x') {
449  SCLogNotice("dev '%s' got EINVAL: going to retry without 'x'", devname);
450  opt_x = "";
451  goto retry;
452  }
453  }
454 
455  NetmapCloseAll();
456  FatalError(SC_ERR_FATAL, "opening devname %s failed: %s", devname, strerror(errno));
457  }
458 
459  /* Work around bug in libnetmap library where "cur_{r,t}x_ring" values not initialized */
460  SCLogDebug("%s -- cur rings: [%d, %d] first rings: [%d, %d]", devname, pdev->nmd->cur_rx_ring,
461  pdev->nmd->cur_tx_ring, pdev->nmd->first_rx_ring, pdev->nmd->first_tx_ring);
462  pdev->nmd->cur_rx_ring = pdev->nmd->first_rx_ring;
463  pdev->nmd->cur_tx_ring = pdev->nmd->first_tx_ring;
464 
465  SCLogInfo("devname [fd: %d] %s %s opened", pdev->nmd->fd, devname, ns->iface);
466 
467  pdev->direction = direction;
468  pdev->ring = ring;
469  SCMutexInit(&pdev->netmap_dev_lock, NULL);
470  TAILQ_INSERT_TAIL(&netmap_devlist, pdev, next);
471 
472  SCMutexUnlock(&netmap_devlist_lock);
473  *pdevice = pdev;
474 
475  return 0;
476 error:
477  return -1;
478 }
479 
480 /**
481  * \brief PcapDumpCounters
482  * \param ntv
483  */
484 static inline void NetmapDumpCounters(NetmapThreadVars *ntv)
485 {
486  StatsAddUI64(ntv->tv, ntv->capture_kernel_packets, ntv->pkts);
487  StatsAddUI64(ntv->tv, ntv->capture_kernel_drops, ntv->drops);
488  (void) SC_ATOMIC_ADD(ntv->livedev->drop, ntv->drops);
489  (void) SC_ATOMIC_ADD(ntv->livedev->pkts, ntv->pkts);
490  ntv->drops = 0;
491  ntv->pkts = 0;
492 }
493 
494 /**
495  * \brief Init function for ReceiveNetmap.
496  * \param tv pointer to ThreadVars
497  * \param initdata pointer to the interface passed from the user
498  * \param data pointer gets populated with NetmapThreadVars
499  */
500 static TmEcode ReceiveNetmapThreadInit(ThreadVars *tv, const void *initdata, void **data)
501 {
502  SCEnter();
503 
504  NetmapIfaceConfig *aconf = (NetmapIfaceConfig *)initdata;
505  if (initdata == NULL) {
506  SCLogError(SC_ERR_INVALID_ARGUMENT, "initdata == NULL");
508  }
509 
510  NetmapThreadVars *ntv = SCCalloc(1, sizeof(*ntv));
511  if (unlikely(ntv == NULL)) {
512  SCLogError(SC_ERR_MEM_ALLOC, "Memory allocation failed");
513  goto error;
514  }
515 
516  ntv->livedev = LiveGetDevice(aconf->iface_name);
517  if (ntv->livedev == NULL) {
518  SCLogError(SC_ERR_INVALID_VALUE, "Unable to find Live device");
519  goto error_ntv;
520  }
521 
522  ntv->tv = tv;
523  ntv->checksum_mode = aconf->in.checksum_mode;
524  ntv->copy_mode = aconf->in.copy_mode;
525 
526  /* enable zero-copy mode for workers runmode */
527  char const *active_runmode = RunmodeGetActive();
528  if (strcmp("workers", active_runmode) == 0) {
529  ntv->flags |= NETMAP_FLAG_ZERO_COPY;
530  SCLogDebug("Enabling zero copy mode for %s", aconf->in.iface);
531  } else if (strcmp("autofp", active_runmode) == 0) {
532  ntv->flags |= NETMAP_FLAG_EXCL_RING_ACCESS;
533  }
534 
535  /* Need to insure open of ring 0 conveys requested ring count for open */
536  bool soft = aconf->in.sw_ring || aconf->out.sw_ring;
537  if (NetmapOpen(&aconf->in, &ntv->ifsrc, 1, 1, (ntv->flags & NETMAP_FLAG_ZERO_COPY) != 0,
538  soft) != 0) {
539  goto error_ntv;
540  }
541 
542  if (aconf->in.copy_mode != NETMAP_COPY_MODE_NONE) {
543  if (NetmapOpen(&aconf->out, &ntv->ifdst, 1, 0, (ntv->flags & NETMAP_FLAG_ZERO_COPY) != 0,
544  soft) != 0) {
545  goto error_src;
546  }
547  }
548 
549  /* basic counters */
550  ntv->capture_kernel_packets = StatsRegisterCounter("capture.kernel_packets",
551  ntv->tv);
552  ntv->capture_kernel_drops = StatsRegisterCounter("capture.kernel_drops",
553  ntv->tv);
554 
555  if (aconf->in.bpf_filter) {
556  SCLogConfig("Using BPF '%s' on iface '%s'",
557  aconf->in.bpf_filter, ntv->ifsrc->ifname);
558  char errbuf[PCAP_ERRBUF_SIZE];
559  if (SCBPFCompile(default_packet_size, /* snaplen_arg */
560  LINKTYPE_ETHERNET, /* linktype_arg */
561  &ntv->bpf_prog, /* program */
562  aconf->in.bpf_filter, /* const char *buf */
563  1, /* optimize */
564  PCAP_NETMASK_UNKNOWN, /* mask */
565  errbuf,
566  sizeof(errbuf)) == -1)
567  {
568  SCLogError(SC_ERR_NETMAP_CREATE, "Failed to compile BPF \"%s\": %s",
569  aconf->in.bpf_filter,
570  errbuf);
571  goto error_dst;
572  }
573  }
574 
575  SCLogDebug("thread: %s polling on fd: %d", tv->name, ntv->ifsrc->nmd->fd);
576 
578 
579  *data = (void *)ntv;
580  aconf->DerefFunc(aconf);
582 
583 error_dst:
584  if (aconf->in.copy_mode != NETMAP_COPY_MODE_NONE) {
585  NetmapClose(ntv->ifdst);
586  }
587 
588 error_src:
589  NetmapClose(ntv->ifsrc);
590 
591 error_ntv:
592  SCFree(ntv);
593 
594 error:
595  aconf->DerefFunc(aconf);
597 }
598 
599 /**
600  * \brief Output packet to destination interface or drop.
601  * \param ntv Thread local variables.
602  * \param p Source packet.
603  */
604 static TmEcode NetmapWritePacket(NetmapThreadVars *ntv, Packet *p)
605 {
606  if (ntv->copy_mode == NETMAP_COPY_MODE_IPS) {
607  if (PacketTestAction(p, ACTION_DROP)) {
608  return TM_ECODE_OK;
609  }
610  }
611  DEBUG_VALIDATE_BUG_ON(ntv->ifdst == NULL);
612 
613  /* Lock the destination netmap ring while writing to it */
614  if (ntv->flags & NETMAP_FLAG_EXCL_RING_ACCESS) {
615  SCMutexLock(&ntv->ifdst->netmap_dev_lock);
616  }
617 
618  /* attempt to write the packet into the netmap ring buffer(s) */
619  if (nmport_inject(ntv->ifdst->nmd, GET_PKT_DATA(p), GET_PKT_LEN(p)) == 0) {
620  if (ntv->flags & NETMAP_FLAG_EXCL_RING_ACCESS) {
621  SCMutexUnlock(&ntv->ifdst->netmap_dev_lock);
622  }
623  SCLogDebug("failed to send %s -> %s", ntv->ifsrc->ifname, ntv->ifdst->ifname);
624  ntv->drops++;
625  return TM_ECODE_FAILED;
626  }
627 
628  SCLogDebug("sent successfully: %s(%d)->%s(%d) (%u)", ntv->ifsrc->ifname, ntv->ifsrc->ring,
629  ntv->ifdst->ifname, ntv->ifdst->ring, GET_PKT_LEN(p));
630 
631  /* Instruct netmap to push the data on the TX ring on the destination port */
632  ioctl(ntv->ifdst->nmd->fd, NIOCTXSYNC, 0);
633  if (ntv->flags & NETMAP_FLAG_EXCL_RING_ACCESS) {
634  SCMutexUnlock(&ntv->ifdst->netmap_dev_lock);
635  }
636  return TM_ECODE_OK;
637 }
638 
639 /**
640  * \brief Packet release routine.
641  * \param p Packet.
642  */
643 static void NetmapReleasePacket(Packet *p)
644 {
645  NetmapThreadVars *ntv = (NetmapThreadVars *)p->netmap_v.ntv;
646 
647  if ((ntv->copy_mode != NETMAP_COPY_MODE_NONE) && !PKT_IS_PSEUDOPKT(p)) {
648  NetmapWritePacket(ntv, p);
649  }
650 
652 }
653 
654 static void NetmapProcessPacket(NetmapThreadVars *ntv, const struct nm_pkthdr *ph)
655 {
656  if (ntv->bpf_prog.bf_len) {
657  struct pcap_pkthdr pkthdr = { {0, 0}, ph->len, ph->len };
658  if (pcap_offline_filter(&ntv->bpf_prog, &pkthdr, ph->buf) == 0) {
659  return;
660  }
661  }
662 
664  if (unlikely(p == NULL)) {
665  return;
666  }
667 
669  p->livedev = ntv->livedev;
671  p->ts = ph->ts;
672  ntv->pkts++;
673  ntv->bytes += ph->len;
674 
675  if (ntv->flags & NETMAP_FLAG_ZERO_COPY) {
676  if (PacketSetData(p, (uint8_t *)ph->buf, ph->len) == -1) {
677  TmqhOutputPacketpool(ntv->tv, p);
678  return;
679  }
680  } else {
681  if (PacketCopyData(p, (uint8_t *)ph->buf, ph->len) == -1) {
682  TmqhOutputPacketpool(ntv->tv, p);
683  return;
684  }
685  }
686 
687  p->ReleasePacket = NetmapReleasePacket;
688  p->netmap_v.ntv = ntv;
689 
690  SCLogDebug("pktlen: %" PRIu32 " (pkt %p, pkt data %p)",
691  GET_PKT_LEN(p), p, GET_PKT_DATA(p));
692 
693  (void)TmThreadsSlotProcessPkt(ntv->tv, ntv->slot, p);
694 }
695 
696 /**
697  * \brief Copy netmap rings data into Packet structures.
698  * \param *d nmport_d (or nm_desc) netmap if structure.
699  * \param cnt int count of packets to read (-1 = all).
700  * \param *ntv NetmapThreadVars.
701  */
702 static TmEcode NetmapReadPackets(struct nmport_d *d, int cnt, NetmapThreadVars *ntv)
703 {
704  struct nm_pkthdr hdr;
705  int last_ring = d->last_rx_ring - d->first_rx_ring + 1;
706  int cur_ring, got = 0, cur_rx_ring = d->cur_rx_ring;
707 
708  memset(&hdr, 0, sizeof(hdr));
709  hdr.flags = NM_MORE_PKTS;
710 
711  if (cnt == 0)
712  cnt = -1;
713 
714  for (cur_ring = 0; cur_ring < last_ring && cnt != got; cur_ring++, cur_rx_ring++) {
715  struct netmap_ring *ring;
716 
717  if (cur_rx_ring > d->last_rx_ring)
718  cur_rx_ring = d->first_rx_ring;
719 
720  ring = NETMAP_RXRING(d->nifp, cur_rx_ring);
721 
722  /* cycle through the non-empty ring slots to fetch their data */
723  for (; !nm_ring_empty(ring) && cnt != got; got++) {
724  u_int idx, i;
725  u_char *oldbuf;
726  struct netmap_slot *slot;
727 
728  if (hdr.buf) { /* from previous round */
729  NetmapProcessPacket(ntv, &hdr);
730  }
731 
732  i = ring->cur;
733  slot = &ring->slot[i];
734  idx = slot->buf_idx;
735  d->cur_rx_ring = cur_rx_ring;
736  hdr.slot = slot;
737  oldbuf = hdr.buf = (u_char *)NETMAP_BUF(ring, idx);
738  hdr.len = hdr.caplen = slot->len;
739 
740  /* loop through the ring slots to get packet data */
741  while (slot->flags & NS_MOREFRAG) {
742  /* packet can be fragmented across multiple slots, */
743  /* so loop until we find the slot with the flag */
744  /* cleared, signalling the end of the packet data. */
745  u_char *nbuf;
746  u_int oldlen = slot->len;
747  i = nm_ring_next(ring, i);
748  slot = &ring->slot[i];
749  hdr.len += slot->len;
750  nbuf = (u_char *)NETMAP_BUF(ring, slot->buf_idx);
751 
752  if (oldbuf != NULL && nbuf - oldbuf == ring->nr_buf_size &&
753  oldlen == ring->nr_buf_size) {
754  hdr.caplen += slot->len;
755  oldbuf = nbuf;
756  } else {
757  oldbuf = NULL;
758  }
759  }
760 
761  hdr.ts = ring->ts;
762  ring->head = ring->cur = nm_ring_next(ring, i);
763  }
764  }
765 
766  if (hdr.buf) { /* from previous round */
767  hdr.flags = 0;
768  NetmapProcessPacket(ntv, &hdr);
769  }
770  return got;
771 }
772 
773 /**
774  * \brief Main netmap reading loop function
775  */
776 static TmEcode ReceiveNetmapLoop(ThreadVars *tv, void *data, void *slot)
777 {
778  SCEnter();
779 
780  TmSlot *s = (TmSlot *)slot;
781  NetmapThreadVars *ntv = (NetmapThreadVars *)data;
782  struct pollfd fds;
783 
784  ntv->slot = s->slot_next;
785  fds.fd = ntv->ifsrc->nmd->fd;
786  fds.events = POLLIN;
787 
788  SCLogDebug("thread %s polling on %d", tv->name, fds.fd);
789  for(;;) {
790  if (unlikely(suricata_ctl_flags != 0)) {
791  break;
792  }
793 
794  /* make sure we have at least one packet in the packet pool,
795  * to prevent us from alloc'ing packets at line rate */
796  PacketPoolWait();
797 
798  int r = poll(&fds, 1, POLL_TIMEOUT);
799 
800  if (r < 0) {
801  /* error */
802  if (errno != EINTR)
804  "Error polling netmap from iface '%s': (%d" PRIu32 ") %s",
805  ntv->ifsrc->ifname, errno, strerror(errno));
806  continue;
807 
808  } else if (r == 0) {
809  /* no events, timeout */
810  /* sync counters */
811  NetmapDumpCounters(ntv);
813 
814  /* poll timed out, lets handle the timeout */
815  TmThreadsCaptureHandleTimeout(tv, NULL);
816  continue;
817  }
818 
819  if (unlikely(fds.revents & POLL_EVENTS)) {
820  if (fds.revents & POLLERR) {
822  "Error reading netmap data via polling from iface '%s': (%d" PRIu32 ") %s",
823  ntv->ifsrc->ifname, errno, strerror(errno));
824  } else if (fds.revents & POLLNVAL) {
825  SCLogError(SC_ERR_NETMAP_READ, "Invalid polling request");
826  }
827  continue;
828  }
829 
830  if (likely(fds.revents & POLLIN)) {
831  /* have data on RX ring, so copy to Packet for processing */
832  NetmapReadPackets(ntv->ifsrc->nmd, -1, ntv);
833  }
834 
835  NetmapDumpCounters(ntv);
837  }
838 
839  NetmapDumpCounters(ntv);
842 }
843 
844 /**
845  * \brief This function prints stats to the screen at exit.
846  * \param tv pointer to ThreadVars
847  * \param data pointer that gets cast into NetmapThreadVars for ntv
848  */
849 static void ReceiveNetmapThreadExitStats(ThreadVars *tv, void *data)
850 {
851  SCEnter();
852  NetmapThreadVars *ntv = (NetmapThreadVars *)data;
853 
854  NetmapDumpCounters(ntv);
855  SCLogPerf("(%s) Kernel: Packets %" PRIu64 ", dropped %" PRIu64 ", bytes %" PRIu64 "",
856  tv->name,
857  StatsGetLocalCounterValue(tv, ntv->capture_kernel_packets),
858  StatsGetLocalCounterValue(tv, ntv->capture_kernel_drops),
859  ntv->bytes);
860 }
861 
862 /**
863  * \brief
864  * \param tv
865  * \param data Pointer to NetmapThreadVars.
866  */
867 static TmEcode ReceiveNetmapThreadDeinit(ThreadVars *tv, void *data)
868 {
869  SCEnter();
870 
871  NetmapThreadVars *ntv = (NetmapThreadVars *)data;
872 
873  if (ntv->ifsrc) {
874  NetmapClose(ntv->ifsrc);
875  ntv->ifsrc = NULL;
876  }
877  if (ntv->ifdst) {
878  NetmapClose(ntv->ifdst);
879  ntv->ifdst = NULL;
880  }
881  if (ntv->bpf_prog.bf_insns) {
882  SCBPFFree(&ntv->bpf_prog);
883  }
884 
885  SCFree(ntv);
886 
888 }
889 
890 /**
891  * \brief Prepare netmap decode thread.
892  * \param tv Thread local variables.
893  * \param initdata Thread config.
894  * \param data Pointer to DecodeThreadVars placed here.
895  */
896 static TmEcode DecodeNetmapThreadInit(ThreadVars *tv, const void *initdata, void **data)
897 {
898  SCEnter();
899 
901  if (dtv == NULL)
903 
905 
906  *data = (void *)dtv;
907 
909 }
910 
911 /**
912  * \brief This function passes off to link type decoders.
913  *
914  * \param t pointer to ThreadVars
915  * \param p pointer to the current packet
916  * \param data pointer that gets cast into NetmapThreadVars for ntv
917  */
918 static TmEcode DecodeNetmap(ThreadVars *tv, Packet *p, void *data)
919 {
920  SCEnter();
921 
923 
925 
926  /* update counters */
928 
930 
932 
934 }
935 
936 /**
937  * \brief
938  * \param tv
939  * \param data Pointer to DecodeThreadVars.
940  */
941 static TmEcode DecodeNetmapThreadDeinit(ThreadVars *tv, void *data)
942 {
943  SCEnter();
944 
945  if (data != NULL)
946  DecodeThreadVarsFree(tv, data);
947 
949 }
950 
951 /**
952  * \brief Registration Function for ReceiveNetmap.
953  */
955 {
956  tmm_modules[TMM_RECEIVENETMAP].name = "ReceiveNetmap";
957  tmm_modules[TMM_RECEIVENETMAP].ThreadInit = ReceiveNetmapThreadInit;
958  tmm_modules[TMM_RECEIVENETMAP].PktAcqLoop = ReceiveNetmapLoop;
959  tmm_modules[TMM_RECEIVENETMAP].ThreadExitPrintStats = ReceiveNetmapThreadExitStats;
960  tmm_modules[TMM_RECEIVENETMAP].ThreadDeinit = ReceiveNetmapThreadDeinit;
963 }
964 
965 /**
966  * \brief Registration Function for DecodeNetmap.
967  */
969 {
970  tmm_modules[TMM_DECODENETMAP].name = "DecodeNetmap";
971  tmm_modules[TMM_DECODENETMAP].ThreadInit = DecodeNetmapThreadInit;
972  tmm_modules[TMM_DECODENETMAP].Func = DecodeNetmap;
973  tmm_modules[TMM_DECODENETMAP].ThreadDeinit = DecodeNetmapThreadDeinit;
976 }
977 
978 #endif /* HAVE_NETMAP */
979 
980 /**
981 * @}
982 */
TmModule_::cap_flags
uint8_t cap_flags
Definition: tm-modules.h:67
tm-threads.h
ThreadVars_::name
char name[16]
Definition: threadvars.h:63
PacketFreeOrRelease
void PacketFreeOrRelease(Packet *p)
Return a packet to where it was allocated.
Definition: decode.c:197
SC_ERR_INVALID_VALUE
@ SC_ERR_INVALID_VALUE
Definition: util-error.h:160
SC_ATOMIC_INIT
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
Definition: util-atomic.h:315
PacketCopyData
int PacketCopyData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
Copy data to Packet payload and set packet length.
Definition: decode.c:298
PKT_IS_PSEUDOPKT
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition: decode.h:1229
util-bpf.h
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
NetmapIfaceSettings_::checksum_mode
ChecksumValidationMode checksum_mode
Definition: source-netmap.h:51
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:296
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
LiveDevice_
Definition: util-device.h:39
SC_ATOMIC_ADD
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Definition: util-atomic.h:333
SC_ERR_NETMAP_CREATE
@ SC_ERR_NETMAP_CREATE
Definition: util-error.h:295
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:252
SCMutexLock
#define SCMutexLock(mut)
Definition: threads-debug.h:117
NetmapIfaceConfig_::out
NetmapIfaceSettings out
Definition: source-netmap.h:64
util-privs.h
StatsSyncCountersIfSignalled
#define StatsSyncCountersIfSignalled(tv)
Definition: counters.h:138
SCMUTEX_INITIALIZER
#define SCMUTEX_INITIALIZER
Definition: threads-debug.h:121
TAILQ_INSERT_TAIL
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:294
PacketDecodeFinalize
void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Finalize decoding of a packet.
Definition: decode.c:150
RunmodeGetActive
char * RunmodeGetActive(void)
Definition: runmodes.c:213
TmModuleReceiveNetmapRegister
void TmModuleReceiveNetmapRegister(void)
Definition: source-netmap.c:74
TmqhOutputPacketpool
void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
Definition: tmqh-packetpool.c:375
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:83
NetmapIfaceSettings_::iface
char iface[NETMAP_IFACE_NAME_LENGTH]
Definition: source-netmap.h:40
NetmapIfaceSettings_::ips
bool ips
Definition: source-netmap.h:46
NETMAP_COPY_MODE_NONE
@ NETMAP_COPY_MODE_NONE
Definition: source-netmap.h:30
TmModule_::PktAcqLoop
TmEcode(* PktAcqLoop)(ThreadVars *, void *, void *)
Definition: tm-modules.h:54
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:82
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
TmModule_::ThreadDeinit
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition: tm-modules.h:49
TAILQ_ENTRY
#define TAILQ_ENTRY(type)
Definition: queue.h:239
Packet_::datalink
int datalink
Definition: decode.h:607
NetmapGetRSSCount
int NetmapGetRSSCount(const char *ifname)
PKT_SET_SRC
#define PKT_SET_SRC(p, src_val)
Definition: decode.h:1232
DecodeRegisterPerfCounters
void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
Definition: decode.c:526
TAILQ_HEAD_INITIALIZER
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:236
TmModuleDecodeNetmapRegister
void TmModuleDecodeNetmapRegister(void)
Registration Function for DecodeNetmap.
Definition: source-netmap.c:84
NetmapIfaceConfig_::DerefFunc
void(* DerefFunc)(void *)
Definition: source-netmap.h:67
PKT_SRC_WIRE
@ PKT_SRC_WIRE
Definition: decode.h:54
NetmapIfaceSettings_::real
bool real
Definition: source-netmap.h:45
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:119
NetmapIfaceSettings_::sw_ring
bool sw_ring
Definition: source-netmap.h:43
LiveGetDevice
LiveDevice * LiveGetDevice(const char *name)
Get a pointer to the device at idx.
Definition: util-device.c:279
SCEnter
#define SCEnter(...)
Definition: util-debug.h:298
GET_PKT_DATA
#define GET_PKT_DATA(p)
Definition: decode.h:227
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:56
TmModule_::Func
TmEcode(* Func)(ThreadVars *, Packet *, void *)
Definition: tm-modules.h:52
SC_ERR_INVALID_ARGUMENT
@ SC_ERR_INVALID_ARGUMENT
Definition: util-error.h:43
NetmapIfaceSettings_
Definition: source-netmap.h:38
TMM_DECODENETMAP
@ TMM_DECODENETMAP
Definition: tm-threads-common.h:59
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:281
NetmapIfaceSettings_::threads
uint16_t threads
Definition: source-netmap.h:49
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
SC_ATOMIC_DECLARE
#define SC_ATOMIC_DECLARE(type, name)
wrapper for declaring atomic variables.
Definition: util-atomic.h:281
PacketPoolWait
void PacketPoolWait(void)
Definition: tmqh-packetpool.c:84
Packet_
Definition: decode.h:433
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
GET_PKT_LEN
#define GET_PKT_LEN(p)
Definition: decode.h:226
source-netmap.h
TmSlot_
Definition: tm-threads.h:52
Packet_::livedev
struct LiveDevice_ * livedev
Definition: decode.h:586
TmEcode
TmEcode
Definition: tm-threads-common.h:81
NetmapIfaceSettings_::promisc
bool promisc
Definition: source-netmap.h:44
SC_ERR_NETMAP_READ
@ SC_ERR_NETMAP_READ
Definition: util-error.h:296
TmModule_::name
const char * name
Definition: tm-modules.h:44
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:215
TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:329
SCMutexInit
#define SCMutexInit(mut, mutattrs)
Definition: threads-debug.h:116
TM_FLAG_RECEIVE_TM
#define TM_FLAG_RECEIVE_TM
Definition: tm-modules.h:31
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:32
default_packet_size
uint32_t default_packet_size
Definition: decode.c:75
Packet_::ReleasePacket
void(* ReleasePacket)(struct Packet_ *)
Definition: decode.h:515
NetmapIfaceSettings_::bpf_filter
const char * bpf_filter
Definition: source-netmap.h:52
flags
uint8_t flags
Definition: decode-gre.h:0
DecodeThreadVarsFree
void DecodeThreadVarsFree(ThreadVars *tv, DecodeThreadVars *dtv)
Definition: decode.c:706
NetmapIfaceConfig_
Definition: source-netmap.h:56
Packet_::ts
struct timeval ts
Definition: decode.h:476
ChecksumValidationMode
ChecksumValidationMode
Definition: decode.h:45
suricata-common.h
ACTION_DROP
#define ACTION_DROP
Definition: action-globals.h:30
SCLogPerf
#define SCLogPerf(...)
Definition: util-debug.h:222
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:255
SCBPFFree
void SCBPFFree(struct bpf_program *program)
Definition: util-bpf.c:34
TmModule_::ThreadInit
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:47
FatalError
#define FatalError(x,...)
Definition: util-debug.h:530
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:31
TmModule_::ThreadExitPrintStats
void(* ThreadExitPrintStats)(ThreadVars *, void *)
Definition: tm-modules.h:48
NETMAP_COPY_MODE_IPS
@ NETMAP_COPY_MODE_IPS
Definition: source-netmap.h:32
util-validate.h
TMM_RECEIVENETMAP
@ TMM_RECEIVENETMAP
Definition: tm-threads-common.h:58
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
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
POLL_TIMEOUT
#define POLL_TIMEOUT
Definition: source-af-packet.c:172
SC_ERR_NO_NETMAP
@ SC_ERR_NO_NETMAP
Definition: util-error.h:294
SCFree
#define SCFree(p)
Definition: util-mem.h:61
NetmapIfaceConfig_::iface_name
char iface_name[NETMAP_IFACE_NAME_LENGTH]
Definition: source-netmap.h:58
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:663
NetmapIfaceSettings_::copy_mode
int copy_mode
Definition: source-netmap.h:50
SC_ERR_FATAL
@ SC_ERR_FATAL
Definition: util-error.h:203
bpf_program
Definition: source-af-packet.c:79
util-ioctl.h
DecodeThreadVarsAlloc
DecodeThreadVars * DecodeThreadVarsAlloc(ThreadVars *tv)
Alloc and setup DecodeThreadVars.
Definition: decode.c:687
TAILQ_HEAD
#define TAILQ_HEAD(name, type)
Definition: queue.h:230
PacketSetData
int PacketSetData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
Set data for Packet and set length when zero copy is used.
Definition: decode.c:726
PacketPoolGetPacket
Packet * PacketPoolGetPacket(void)
Get a new packet from the packet pool.
Definition: tmqh-packetpool.c:185
SCBPFCompile
int SCBPFCompile(int snaplen_arg, int linktype_arg, struct bpf_program *program, const char *buf, int optimize, uint32_t mask, char *errbuf, size_t errbuf_len)
Definition: util-bpf.c:40
SC_ERR_MEM_ALLOC
@ SC_ERR_MEM_ALLOC
Definition: util-error.h:31
NetmapIfaceConfig_::in
NetmapIfaceSettings in
Definition: source-netmap.h:61
suricata.h
likely
#define likely(expr)
Definition: util-optimize.h:32
TmSlot_::slot_next
struct TmSlot_ * slot_next
Definition: tm-threads.h:61
SCLogNotice
#define SCLogNotice(...)
Macro used to log NOTICE messages.
Definition: util-debug.h:230
StatsRegisterCounter
uint16_t StatsRegisterCounter(const char *name, struct ThreadVars_ *tv)
Registers a normal, unqualified counter.
Definition: counters.c:956
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:302
SCMutexDestroy
#define SCMutexDestroy
Definition: threads-debug.h:120
SCMutex
#define SCMutex
Definition: threads-debug.h:114
SC_CAP_NET_RAW
#define SC_CAP_NET_RAW
Definition: util-privs.h:32
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:111
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:653
LINKTYPE_ETHERNET
#define LINKTYPE_ETHERNET
Definition: decode.h:1145
suricata_ctl_flags
volatile uint8_t suricata_ctl_flags
Definition: suricata.c:206